linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: pranavkumar@linaro.org (PranavkumarSawargaonkar)
To: linux-arm-kernel@lists.infradead.org
Subject: [RFC] arm64: Early printk support for virtio-mmio console devices.
Date: Thu, 18 Apr 2013 11:22:24 +0530	[thread overview]
Message-ID: <1366264344-28025-1-git-send-email-pranavkumar@linaro.org> (raw)

From: Pranavkumar Sawargaonkar <pranavkumar@linaro.org>

This patch implements early printk support for virtio-mmio console devices without using any hypercalls.

The current virtio early printk code in kernel expects that hypervisor will provide some mechanism generally a hypercall to support early printk. This patch does not break existing hypercall based early print support.

This implementation adds:
1. Early read-write register named early_rw in virtio console's config space.
2. Two host feature flags namely VIRTIO_CONSOLE_F_EARLY_READ and VIRTIO_CONSOLE_F_EARLY_WRITE for telling guest about early-read and early-write capability in console device.

Early write mechanism:
1. When a guest wants to out some character, it has to simply write the character to early_rw register in config space of virtio console device.

Early read mechanism:
1. When a guest wants to in some character, it has to simply read the early_rw register in config space of virtio console device. Lets say we get 32-bit value X.
2. If most significant bit of X is set (i.e. X & 0x80000000 == 0x80000000) then least significant 8 bits of X represents input charaacter else guest need to try again reading early_rw register.

Note: This patch only includes kernel side changes for early printk, the host/hypervisor side emulation of early_rw register is out of scope here.

Signed-off-by: Anup Patel <anup.patel@linaro.org>
---
 arch/arm64/kernel/early_printk.c    |   24 ++++++++++++++++++++++++
 include/uapi/linux/virtio_console.h |    4 ++++
 2 files changed, 28 insertions(+)

diff --git a/arch/arm64/kernel/early_printk.c b/arch/arm64/kernel/early_printk.c
index ac974f4..a82b5aa 100644
--- a/arch/arm64/kernel/early_printk.c
+++ b/arch/arm64/kernel/early_printk.c
@@ -25,6 +25,9 @@
 
 #include <linux/amba/serial.h>
 #include <linux/serial_reg.h>
+#include <linux/virtio_ids.h>
+#include <linux/virtio_mmio.h>
+#include <linux/virtio_console.h>
 
 static void __iomem *early_base;
 static void (*printch)(char ch);
@@ -53,6 +56,26 @@ static void smh_printch(char ch)
 }
 
 /*
+ * VIRTIO MMIO based debug console.
+ */
+static void virtio_console_early_printch(char ch)
+{
+	u32 tmp;
+	struct virtio_console_config *p = early_base + VIRTIO_MMIO_CONFIG;
+
+	tmp = readl_relaxed(early_base + VIRTIO_MMIO_DEVICE_ID);
+	if (tmp != VIRTIO_ID_CONSOLE) {
+		return;
+	}
+
+	tmp = readl_relaxed(early_base + VIRTIO_MMIO_HOST_FEATURES);
+	if (!(tmp & (1 << VIRTIO_CONSOLE_F_EARLY_WRITE))) {
+		return;
+	}
+	writeb_relaxed(ch, &p->early_rw);
+}
+
+/*
  * 8250/16550 (8-bit aligned registers) single character TX.
  */
 static void uart8250_8bit_printch(char ch)
@@ -82,6 +105,7 @@ static const struct earlycon_match earlycon_match[] __initconst = {
 	{ .name = "smh", .printch = smh_printch, },
 	{ .name = "uart8250-8bit", .printch = uart8250_8bit_printch, },
 	{ .name = "uart8250-32bit", .printch = uart8250_32bit_printch, },
+	{ .name = "virtio-console", .printch = virtio_console_early_printch, },
 	{}
 };
 
diff --git a/include/uapi/linux/virtio_console.h b/include/uapi/linux/virtio_console.h
index ee13ab6..1171cb4 100644
--- a/include/uapi/linux/virtio_console.h
+++ b/include/uapi/linux/virtio_console.h
@@ -38,6 +38,8 @@
 /* Feature bits */
 #define VIRTIO_CONSOLE_F_SIZE	0	/* Does host provide console size? */
 #define VIRTIO_CONSOLE_F_MULTIPORT 1	/* Does host provide multiple ports? */
+#define VIRTIO_CONSOLE_F_EARLY_READ 2	/* Does host support early read? */
+#define VIRTIO_CONSOLE_F_EARLY_WRITE 3	/* Does host support early write? */
 
 #define VIRTIO_CONSOLE_BAD_ID		(~(u32)0)
 
@@ -48,6 +50,8 @@ struct virtio_console_config {
 	__u16 rows;
 	/* max. number of ports this device can hold */
 	__u32 max_nr_ports;
+	/* early read/write register */
+	__u32 early_rw;
 } __attribute__((packed));
 
 /*
-- 
1.7.9.5

             reply	other threads:[~2013-04-18  5:52 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-18  5:52 PranavkumarSawargaonkar [this message]
2013-04-18  6:49 ` [RFC] arm64: Early printk support for virtio-mmio console devices Marc Zyngier
2013-04-18  7:24   ` Pranavkumar Sawargaonkar
     [not found]   ` <CAAHg+HhajHFC=1nh6YQNgpf=Na2FqcsYJ=t+ag9QiTg6TxUz9w@mail.gmail.com>
2013-04-18  7:36     ` Marc Zyngier
2013-04-18  8:48       ` Pranavkumar Sawargaonkar
2013-04-18  8:53         ` Alexander Graf
2013-04-19  9:05         ` Will Deacon
2013-04-19  9:25           ` Pranavkumar Sawargaonkar
2013-04-19  9:27             ` Will Deacon
2013-04-19  9:30               ` Peter Maydell
2013-04-19  9:34                 ` Pranavkumar Sawargaonkar
2013-04-19  9:39                   ` Will Deacon
2013-04-19 10:05                     ` Peter Maydell
2013-04-19 16:12                       ` Catalin Marinas
2013-04-19 16:14                         ` Peter Maydell
2013-04-19 16:22                           ` Catalin Marinas
2013-04-19 16:33                             ` Peter Maydell
2013-04-19 17:14                               ` Catalin Marinas
2013-04-19 17:40                                 ` Peter Maydell
2013-04-19  9:36                 ` Will Deacon
2013-04-18 19:06       ` Pranavkumar Sawargaonkar
2013-04-18  8:30   ` Peter Maydell
2013-04-18  8:51     ` Alexander Graf
2013-04-18  8:51     ` Marc Zyngier
2013-04-18  6:51 ` Rusty Russell
2013-04-18  7:32   ` Pranavkumar Sawargaonkar
2013-04-18  8:44     ` Alexander Graf
2013-04-18  8:55       ` Pranavkumar Sawargaonkar
2013-04-18 10:01     ` Jean-Christophe PLAGNIOL-VILLARD
2013-04-22  1:21     ` Rusty Russell
2013-04-22  3:10       ` Anup Patel
2013-04-22  5:15         ` Rusty Russell
2013-04-23  5:53           ` Pranavkumar Sawargaonkar
2013-04-22 14:50         ` Alexander Graf
2013-04-18 15:25 ` Christopher Covington
2013-04-18 15:59   ` Marc Zyngier
2013-04-18 18:59     ` Pranavkumar Sawargaonkar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1366264344-28025-1-git-send-email-pranavkumar@linaro.org \
    --to=pranavkumar@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).