From patchwork Thu Apr 18 18:54:03 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: PranavkumarSawargaonkar X-Patchwork-Id: 16251 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vc0-f200.google.com (mail-vc0-f200.google.com [209.85.220.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 62B5D23974 for ; Thu, 18 Apr 2013 18:55:22 +0000 (UTC) Received: by mail-vc0-f200.google.com with SMTP id hz11sf5502237vcb.11 for ; Thu, 18 Apr 2013 11:54:44 -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=yAcqy0iug3Sx/jt9fjRMwLZFEnbI9F/zF+FaF+lBkVQ=; b=OctbGjH4YdqNmkDPNJRwKLj4Bdj8lSd13AY4MJ1+KrXJA+QV5/ZvyktQex4PbG5AkJ H5yE1usbdvqjlYzBrqiYmxIiOhPMbl17w8PX9UtSboAifrEmmhAHOR88SH2Gm1+bfM3W mdJWZYinmtMgguQnii6YZQw1uYU4RDBOojp7ltSaO43zbqpMsAOMBzl4OSyOwwK9QGMe 9PaGSEcMOsj8vHk+hNUL/6/ckL0ar0chmKTkF1UiZZsXUmhGhb/6QAvcbbiCEhqHx4GE xN3sMUDNGKlkP4xskkeHu6mEqm2B2OJA3DXEsUs6B1pJzxMX37HhFk2jiB3f9pYMMkld nsUg== X-Received: by 10.236.110.109 with SMTP id t73mr5927171yhg.20.1366311284489; Thu, 18 Apr 2013 11:54:44 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.24.230 with SMTP id x6ls1763606qef.31.gmail; Thu, 18 Apr 2013 11:54:44 -0700 (PDT) X-Received: by 10.58.76.3 with SMTP id g3mr9032429vew.58.1366311284153; Thu, 18 Apr 2013 11:54:44 -0700 (PDT) Received: from mail-vb0-x233.google.com (mail-vb0-x233.google.com [2607:f8b0:400c:c02::233]) by mx.google.com with ESMTPS id pq1si7282046vec.20.2013.04.18.11.54.43 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 18 Apr 2013 11:54:44 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400c:c02::233 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=2607:f8b0:400c:c02::233; Received: by mail-vb0-f51.google.com with SMTP id x19so2840487vbf.10 for ; Thu, 18 Apr 2013 11:54:43 -0700 (PDT) X-Received: by 10.220.175.3 with SMTP id v3mr9154162vcz.8.1366311283812; Thu, 18 Apr 2013 11:54:43 -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 nf2csp143956veb; Thu, 18 Apr 2013 11:54:43 -0700 (PDT) X-Received: by 10.66.120.173 with SMTP id ld13mr14537725pab.187.1366311282678; Thu, 18 Apr 2013 11:54:42 -0700 (PDT) Received: from mail-pa0-f51.google.com (mail-pa0-f51.google.com [209.85.220.51]) by mx.google.com with ESMTPS id dj6si10496088pad.76.2013.04.18.11.54.42 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 18 Apr 2013 11:54:42 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.51 is neither permitted nor denied by best guess record for domain of pranavkumar@linaro.org) client-ip=209.85.220.51; Received: by mail-pa0-f51.google.com with SMTP id jh10so1771517pab.24 for ; Thu, 18 Apr 2013 11:54:42 -0700 (PDT) X-Received: by 10.68.180.4 with SMTP id dk4mr14863080pbc.104.1366311282226; Thu, 18 Apr 2013 11:54:42 -0700 (PDT) Received: from pnqlab006.amcc.com ([122.170.124.90]) by mx.google.com with ESMTPS id bs3sm10689622pbb.36.2013.04.18.11.54.39 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 18 Apr 2013 11:54:41 -0700 (PDT) From: PranavkumarSawargaonkar To: kvmarm@lists.cs.columbia.edu Cc: linaro-kernel@lists.linaro.org, patches@linaro.org, rusty@rustcorp.com.au, marc.zyngier@arm.com, "Pranavkumar Sawargaonkar" , Anup Patel Subject: [RFC] KVMTOOL: Early printk support for virtio-mmio console. Date: Fri, 19 Apr 2013 00:24:03 +0530 Message-Id: <1366311243-6731-1-git-send-email-pranavkumar@linaro.org> X-Mailer: git-send-email 1.7.9.5 X-Gm-Message-State: ALoCoQnfj5M84LBcsmNwZm89ReABSm32NN/eyIsdvm+raVVNSSo00n+Dnr1Myg6cegSQ0qtMTaA1 X-Original-Sender: pranavkumar@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 2607:f8b0:400c:c02::233 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 is a counterpart implementation of virtio-mmio console early printk support in kvmtool for a rfc i posted today on kvm-arm i.e. ([RFC] arm64: Early printk support for virtio-mmio console devices) This is initial reference version (might not be very clean). This allows guest to print early printk on virtio-mmio console. Signed-off-by: Anup Patel --- tools/kvm/include/kvm/virtio-console.h | 5 +++++ tools/kvm/virtio/console.c | 30 +++++++++++++++++++++++++++++- tools/kvm/virtio/mmio.c | 24 +++++++++++++++++++----- 3 files changed, 53 insertions(+), 6 deletions(-) diff --git a/tools/kvm/include/kvm/virtio-console.h b/tools/kvm/include/kvm/virtio-console.h index 8980920..063c8bb 100644 --- a/tools/kvm/include/kvm/virtio-console.h +++ b/tools/kvm/include/kvm/virtio-console.h @@ -1,10 +1,15 @@ #ifndef KVM__CONSOLE_VIRTIO_H #define KVM__CONSOLE_VIRTIO_H +#include + struct kvm; int virtio_console__init(struct kvm *kvm); void virtio_console__inject_interrupt(struct kvm *kvm); int virtio_console__exit(struct kvm *kvm); +void console_write_config(struct kvm *kvm, void *dev, u64 addr, u32 i, u8 *data); +void console_read_config(struct kvm *kvm, void *dev, u64 addr, u32 i, u8 *data); + #endif /* KVM__CONSOLE_VIRTIO_H */ diff --git a/tools/kvm/virtio/console.c b/tools/kvm/virtio/console.c index b18d3a9..47ae890 100644 --- a/tools/kvm/virtio/console.c +++ b/tools/kvm/virtio/console.c @@ -118,9 +118,37 @@ static u8 *get_config(struct kvm *kvm, void *dev) return ((u8 *)(&cdev->config)); } +void console_write_config(struct kvm *kvm, void *dev, u64 addr, u32 i, u8 *data) +{ + struct con_dev *cdev = dev; + u8 *p; + + if (addr != offsetof(struct virtio_console_config, early_rw)) { + p = ((u8 *)(&cdev->config)); + p[addr + i] = *(u8 *)data + i; + + } else { + /* early_rw write */ + term_putc((char *) (data + i), 1, 0); + } +} + +void console_read_config(struct kvm *kvm, void *dev, u64 addr, u32 i, u8 *data) +{ + struct con_dev *cdev = dev; + u8 *p; + + if (addr != offsetof(struct virtio_console_config, early_rw)) { + p = ((u8 *)(&cdev->config)); + data[i] = p[addr + i]; + } else { + /* TBD: implement early_rw read with the help of term_getc */ + } +} + static u32 get_host_features(struct kvm *kvm, void *dev) { - return 0; + return (1 << VIRTIO_CONSOLE_F_EARLY_WRITE); } static void set_guest_features(struct kvm *kvm, void *dev, u32 features) diff --git a/tools/kvm/virtio/mmio.c b/tools/kvm/virtio/mmio.c index bd30f37..6b116e9 100644 --- a/tools/kvm/virtio/mmio.c +++ b/tools/kvm/virtio/mmio.c @@ -3,9 +3,11 @@ #include "kvm/ioeventfd.h" #include "kvm/ioport.h" #include "kvm/virtio.h" +#include "kvm/virtio-console.h" #include "kvm/kvm.h" #include "kvm/irq.h" +#include #include #include @@ -94,12 +96,24 @@ static void virtio_mmio_device_specific(u64 addr, u8 *data, u32 len, u32 i; for (i = 0; i < len; i++) { - if (is_write) - vdev->ops->get_config(vmmio->kvm, vmmio->dev)[addr + i] = - *(u8 *)data + i; - else - data[i] = vdev->ops->get_config(vmmio->kvm, + if (is_write) { + if (vmmio->hdr.device_id == VIRTIO_ID_CONSOLE) { + console_write_config(vmmio->kvm, vmmio->dev, + addr, i, data); + } else { + vdev->ops->get_config(vmmio->kvm, + vmmio->dev)[addr + i] = + *(u8 *)data + i; + } + } else { + if (vmmio->hdr.device_id == VIRTIO_ID_CONSOLE) { + console_read_config(vmmio->kvm, vmmio->dev, + addr, i, data); + } else { + data[i] = vdev->ops->get_config(vmmio->kvm, vmmio->dev)[addr + i]; + } + } } }