From patchwork Wed May 1 15:50:13 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 2507961 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id E0D81DF230 for ; Wed, 1 May 2013 15:50:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1761531Ab3EAPuv (ORCPT ); Wed, 1 May 2013 11:50:51 -0400 Received: from cam-admin0.cambridge.arm.com ([217.140.96.50]:42929 "EHLO cam-admin0.cambridge.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755217Ab3EAPue (ORCPT ); Wed, 1 May 2013 11:50:34 -0400 Received: from mudshark.cambridge.arm.com (mudshark.cambridge.arm.com [10.1.203.36]) by cam-admin0.cambridge.arm.com (8.12.6/8.12.6) with ESMTP id r41FoLki024152; Wed, 1 May 2013 16:50:21 +0100 (BST) Received: by mudshark.cambridge.arm.com (Postfix, from userid 1000) id 0BEDAC2B1A; Wed, 1 May 2013 16:50:18 +0100 (BST) From: Will Deacon To: kvm@vger.kernel.org Cc: penberg@kernel.org, marc.zyngier@arm.com, anup@brainfault.org, rusty@rustcorp.com.au, pranavkumar@linaro.org, michael@ellerman.id.au, Will Deacon Subject: [RFC PATCH 08/11] kvm tools: 8250: add fdt node generation Date: Wed, 1 May 2013 16:50:13 +0100 Message-Id: <1367423416-24640-9-git-send-email-will.deacon@arm.com> X-Mailer: git-send-email 1.8.0 In-Reply-To: <1367423416-24640-1-git-send-email-will.deacon@arm.com> References: <1367423416-24640-1-git-send-email-will.deacon@arm.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This patch adds fdt node generation to the 8250 emulation. The serial8250_device is now stashed inside the ioport priv field, so that it can be retrieved from the ioport passed back to the generation code. Signed-off-by: Will Deacon --- tools/kvm/hw/serial.c | 55 +++++++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/tools/kvm/hw/serial.c b/tools/kvm/hw/serial.c index 384ee37..523a767 100644 --- a/tools/kvm/hw/serial.c +++ b/tools/kvm/hw/serial.c @@ -6,6 +6,7 @@ #include "kvm/util.h" #include "kvm/term.h" #include "kvm/kvm.h" +#include "kvm/fdt.h" #include #include @@ -226,31 +227,14 @@ void serial8250__inject_sysrq(struct kvm *kvm, char sysrq) sysrq_pending = sysrq; } -static struct serial8250_device *find_device(u16 port) -{ - unsigned int i; - - for (i = 0; i < ARRAY_SIZE(devices); i++) { - struct serial8250_device *dev = &devices[i]; - - if (dev->iobase == (port & ~0x7)) - return dev; - } - return NULL; -} - static bool serial8250_out(struct ioport *ioport, struct kvm *kvm, u16 port, void *data, int size) { - struct serial8250_device *dev; + struct serial8250_device *dev = ioport->priv; u16 offset; bool ret = true; char *addr = data; - dev = find_device(port); - if (!dev) - return false; - mutex_lock(&dev->mutex); offset = port - dev->iobase; @@ -338,14 +322,10 @@ static void serial8250_rx(struct serial8250_device *dev, void *data) static bool serial8250_in(struct ioport *ioport, struct kvm *kvm, u16 port, void *data, int size) { - struct serial8250_device *dev; + struct serial8250_device *dev = ioport->priv; u16 offset; bool ret = true; - dev = find_device(port); - if (!dev) - return false; - mutex_lock(&dev->mutex); offset = port - dev->iobase; @@ -393,9 +373,32 @@ static bool serial8250_in(struct ioport *ioport, struct kvm *kvm, u16 port, void return ret; } +#ifdef CONFIG_HAS_LIBFDT +static void serial8250_generate_fdt_node(struct ioport *ioport, void *fdt, + void (*generate_irq_prop)(void *fdt, + u8 irq)) +{ + struct serial8250_device *dev = ioport->priv; + u64 reg_prop[] = { + cpu_to_fdt64(KVM_IOPORT_AREA + dev->iobase), + cpu_to_fdt64(8), + }; + + _FDT(fdt_begin_node(fdt, "U6_16550A")); + _FDT(fdt_property_string(fdt, "compatible", "ns16550a")); + _FDT(fdt_property(fdt, "reg", reg_prop, sizeof(reg_prop))); + generate_irq_prop(fdt, dev->irq); + _FDT(fdt_property_cell(fdt, "clock-frequency", 1843200)); + _FDT(fdt_end_node(fdt)); +} +#else +#define serial8250_generate_fdt_node NULL +#endif + static struct ioport_operations serial8250_ops = { - .io_in = serial8250_in, - .io_out = serial8250_out, + .io_in = serial8250_in, + .io_out = serial8250_out, + .generate_fdt_node = serial8250_generate_fdt_node, }; static int serial8250__device_init(struct kvm *kvm, struct serial8250_device *dev) @@ -403,7 +406,7 @@ static int serial8250__device_init(struct kvm *kvm, struct serial8250_device *de int r; ioport__map_irq(&dev->irq); - r = ioport__register(kvm, dev->iobase, &serial8250_ops, 8, NULL); + r = ioport__register(kvm, dev->iobase, &serial8250_ops, 8, dev); kvm__irq_line(kvm, dev->irq, 0); return r;