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: 16182 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qc0-f200.google.com (mail-qc0-f200.google.com [209.85.216.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id DB07D23A41 for ; Thu, 18 Apr 2013 05:53:55 +0000 (UTC) Received: by mail-qc0-f200.google.com with SMTP id j34sf3368494qco.7 for ; Wed, 17 Apr 2013 22:53:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:mime-version:x-beenthere:x-received:received-spf :x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:x-received:from:to:cc:subject:date:message-id:x-mailer :x-gm-message-state:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-google-group-id:list-post:list-help:list-archive:list-unsubscribe; bh=CAhdT73bs8qZuzHEeBTgIiyxtF+Z+JeUD09gBnE0sng=; b=YUBzNZ+yl1vc1UCIDw+piq+5+o44mAE03pcTLtIAPicARTwCXuKXrHQpJi+z+AokU+ ocmRKrg3YDTQmdb4VOZwJf0SvOx81Qsrj+3EdGA/Qh1ZczTo+oi8bXtoX7ztvHQLUt6J pw5nmhO6wOiPn0siH2DsvXbhrCxif1oGiBpJkHfm/EPOu34CWn18rz10iRxtJ2cb11SX wmdcuA4rUpRkJDxOsnJwR11QOXjv3HkDk4cCAMhph41ei56qKgC+xp/Yh58QUo9jDqct UKDc/m9siNI0pm5pgFigrdNGw/lMDbzQMh21XroeUFlp8matA/0PFWXLNV/GRT+cfEQP nIVw== X-Received: by 10.224.88.200 with SMTP id b8mr7038917qam.8.1366264399200; Wed, 17 Apr 2013 22:53:19 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.25.41 with SMTP id z9ls1181886qef.96.gmail; Wed, 17 Apr 2013 22:53:19 -0700 (PDT) X-Received: by 10.52.165.83 with SMTP id yw19mr6097381vdb.74.1366264398974; Wed, 17 Apr 2013 22:53:18 -0700 (PDT) Received: from mail-vc0-f170.google.com (mail-vc0-f170.google.com [209.85.220.170]) by mx.google.com with ESMTPS id sa4si5846727vdc.114.2013.04.17.22.53.18 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 17 Apr 2013 22:53:18 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.170 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.170; Received: by mail-vc0-f170.google.com with SMTP id lf10so2084734vcb.1 for ; Wed, 17 Apr 2013 22:53:18 -0700 (PDT) X-Received: by 10.52.163.231 with SMTP id yl7mr6133859vdb.57.1366264398297; Wed, 17 Apr 2013 22:53:18 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.58.127.98 with SMTP id nf2csp106368veb; Wed, 17 Apr 2013 22:53:17 -0700 (PDT) X-Received: by 10.66.250.230 with SMTP id zf6mr12167764pac.153.1366264396988; Wed, 17 Apr 2013 22:53:16 -0700 (PDT) Received: from mail-pd0-f170.google.com (mail-pd0-f170.google.com [209.85.192.170]) by mx.google.com with ESMTPS id hg4si8149134pbb.202.2013.04.17.22.53.16 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 17 Apr 2013 22:53:16 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.192.170 is neither permitted nor denied by best guess record for domain of pranavkumar@linaro.org) client-ip=209.85.192.170; Received: by mail-pd0-f170.google.com with SMTP id 10so1298178pdi.1 for ; Wed, 17 Apr 2013 22:53:16 -0700 (PDT) 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 Cc: linux-arm-kernel@lists.infradead.org, linaro-kernel@lists.linaro.org, patches@linaro.org, linux-kernel@vger.kernel.org, rusty@rustcorp.com.au, Pranavkumar Sawargaonkar , Anup Patel 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: ALoCoQkwOcs6DEIXT2y7qjcwyKIqjdJB4FFB/5wN7TwSzDporH/O/sS5E7osS11H8R3D2Hx9+8Di X-Original-Sender: pranavkumar@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.170 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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)); /*