From patchwork Thu Apr 18 05:52:24 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: PranavkumarSawargaonkar X-Patchwork-Id: 2457481 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) by patchwork2.kernel.org (Postfix) with ESMTP id 5DAC4DF2E5 for ; Thu, 18 Apr 2013 05:53:33 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UShme-0003jU-Op; Thu, 18 Apr 2013 05:53:24 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UShmc-0004U4-AP; Thu, 18 Apr 2013 05:53:22 +0000 Received: from mail-pa0-f45.google.com ([209.85.220.45]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UShmZ-0004Tk-0P for linux-arm-kernel@lists.infradead.org; Thu, 18 Apr 2013 05:53:19 +0000 Received: by mail-pa0-f45.google.com with SMTP id kl13so1359206pab.4 for ; Wed, 17 Apr 2013 22:53:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer :x-gm-message-state; bh=CAhdT73bs8qZuzHEeBTgIiyxtF+Z+JeUD09gBnE0sng=; b=oyE/HX4W5IhG2Rrijyz4kkRrZNcp3hv2ZrTjKuYxPFt/RHfHp5eGgjugplpG0J2RWB TozGZi1fe6XiregyzLqg5ofUugLROPBJZQz5KjFdk7lJYvQGu3ZqECEqFh2uj7BZNJZO rl1et7uzKlJswShgdzlO90qUCTLpdSvJuyNMy4ZXs6z7NrQPleiMuAYla25ND9Q4o3Zx bhXjixriJJdoNn3VwQ1OogimUEHJIazUdABnF/T3NRAu0MEcswnu5vWw6xXoXdcGx531 MZMmYWRCcw1AKvJKadrjEmQAgTCP+p1iS6fGesxDCLLrJk3L8MUUkpNMJVUtmKJHxY3E Mnkw== X-Received: by 10.66.8.69 with SMTP id p5mr11955897paa.57.1366264396264; Wed, 17 Apr 2013 22:53:16 -0700 (PDT) Received: from pnqlab006.amcc.com ([122.170.124.90]) by mx.google.com with ESMTPS id ky10sm9590720pab.23.2013.04.17.22.53.12 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 17 Apr 2013 22:53:15 -0700 (PDT) From: PranavkumarSawargaonkar To: kvmarm@lists.cs.columbia.edu Subject: [RFC] arm64: Early printk support for virtio-mmio console devices. Date: Thu, 18 Apr 2013 11:22:24 +0530 Message-Id: <1366264344-28025-1-git-send-email-pranavkumar@linaro.org> X-Mailer: git-send-email 1.7.9.5 X-Gm-Message-State: ALoCoQnS5dHXAXAQSQNNfiYMfU1J2oZT3jwidwXvdPjtWGV8Jy1dmj/UNM+/dBdc8yIiiIV7cRLf X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130418_015319_150473_ACFDAD9C X-CRM114-Status: GOOD ( 16.62 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.220.45 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: linaro-kernel@lists.linaro.org, Anup Patel , patches@linaro.org, rusty@rustcorp.com.au, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Pranavkumar Sawargaonkar X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Pranavkumar Sawargaonkar 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 --- 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 #include +#include +#include +#include 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)); /*