From patchwork Thu Aug 25 06:41:13 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Peter A. G. Crosthwaite" X-Patchwork-Id: 111476 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id D8D24B6F64 for ; Thu, 25 Aug 2011 16:52:43 +1000 (EST) Received: from localhost ([::1]:45211 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QwTff-0002Pd-PU for incoming@patchwork.ozlabs.org; Thu, 25 Aug 2011 02:44:11 -0400 Received: from eggs.gnu.org ([140.186.70.92]:46996) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QwTfL-0001MP-IM for qemu-devel@nongnu.org; Thu, 25 Aug 2011 02:43:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QwTfK-00040w-4s for qemu-devel@nongnu.org; Thu, 25 Aug 2011 02:43:51 -0400 Received: from mail-gx0-f173.google.com ([209.85.161.173]:43091) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QwTfK-00040Q-1I for qemu-devel@nongnu.org; Thu, 25 Aug 2011 02:43:50 -0400 Received: by gxk26 with SMTP id 26so1693111gxk.4 for ; Wed, 24 Aug 2011 23:43:44 -0700 (PDT) Received: by 10.236.176.226 with SMTP id b62mr196946yhm.78.1314254624533; Wed, 24 Aug 2011 23:43:44 -0700 (PDT) Received: from localhost ([124.148.20.9]) by mx.google.com with ESMTPS id f48sm479315yhh.14.2011.08.24.23.43.41 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 24 Aug 2011 23:43:44 -0700 (PDT) From: "Peter A. G. Crosthwaite" To: qemu-devel@nongnu.org, stefanha@linux.vnet.ibm.com, edgar.iglesias@gmail.com, john.williams@petalogix.com, michal.simek@petalogix.com Date: Thu, 25 Aug 2011 16:41:13 +1000 Message-Id: <1314254480-22438-8-git-send-email-peter.crosthwaite@petalogix.com> X-Mailer: git-send-email 1.7.3.2 In-Reply-To: <1314254480-22438-1-git-send-email-peter.crosthwaite@petalogix.com> References: <1314254480-22438-1-git-send-email-peter.crosthwaite@petalogix.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.161.173 Cc: "Peter A. G. Crosthwaite" Subject: [Qemu-devel] [RFC PATCH V1 07/14] fdt_generic_qdev: first revision X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Support for setting up qdev models for use by the fdt-generic framwork. A single fdt init function is shared by all qdev models and the qdev model registers a handler function that maps fdt properties to qdev properties. Support for basic interrupt controllers and nics is there. Signed-off-by: Peter A. G. Crosthwaite --- Makefile.objs | 1 + hw/fdt_generic_qdev.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++ hw/fdt_generic_qdev.h | 46 ++++++++++++++++++++++++++++++ 3 files changed, 122 insertions(+), 0 deletions(-) create mode 100644 hw/fdt_generic_qdev.c create mode 100644 hw/fdt_generic_qdev.h diff --git a/Makefile.objs b/Makefile.objs index 9fd18ff..9d5100a 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -222,6 +222,7 @@ hw-obj-$(CONFIG_USB_REDIR) += usb-redir.o hw-obj-$(CONFIG_FDT) += fdt_generic.o hw-obj-$(CONFIG_FDT) += fdt_generic_util.o +hw-obj-$(CONFIG_FDT) += fdt_generic_qdev.o # PPC devices hw-obj-$(CONFIG_OPENPIC) += openpic.o diff --git a/hw/fdt_generic_qdev.c b/hw/fdt_generic_qdev.c new file mode 100644 index 0000000..53b32ab --- /dev/null +++ b/hw/fdt_generic_qdev.c @@ -0,0 +1,75 @@ +#include "fdt_generic_qdev.h" +#include "fdt_generic_util.h" +#include "net.h" + +#define D(a) + +int fdt_init_qdev(char *node_path, FDTMachineInfo *fdti, void *opaque) +{ + int err; + qemu_irq irq; + target_phys_addr_t base; + DeviceState *dev; + FDTQDevOps *ops = opaque; + struct FDTQDevPropMapping *props = + (ops && ops->map) ? ops->map(node_path, fdti) : NULL; + struct FDTQDevPropMapping *propsi; + + /* create the device */ + if (!ops || !ops->dev_name) { + return 1; + } + dev = qdev_create(NULL, ops->dev_name); + D(fprintf(stderr, "FDT: Creating QDEV model %s %s %d\n", + ops->dev_name, ops->is_nic ? "(nic)" : "", ops->is_intc);) + /* connect nic if appropriate */ + if (ops->is_nic) { + qemu_check_nic_model(&nd_table[0], ops->dev_name); + qdev_set_nic_properties(dev, &nd_table[0]); + } + /* connect custom properties */ + for (propsi = props; propsi && propsi->name; propsi++) { + enum PropertyType type; + if (!qdev_prop_get_type(dev, propsi->name, &type)) { + qdev_prop_set(dev, propsi->name, &propsi->src, type); + D(fprintf(stderr, "\tFDT: setting qdev prop %s %d (u32) %p (p)\n", + propsi->name, propsi->src.u32, propsi->src.p);) + } + if (propsi->freesrc) { + g_free(propsi->src.p); + } + } + qdev_init_nofail(dev); + /* map slave attachment */ + base = qemu_devtree_getprop(fdti->fdt, NULL, node_path, "reg", 0, 0); + sysbus_mmio_map(sysbus_from_qdev(dev), 0, base); + /* connect irq */ + { + char irq_info[1024]; + /* FIXME: add support for multiple IRQs */ + irq = fdt_get_irq_info(fdti, node_path, 0, &err, irq_info); + /* INTCs inferr their top level, if no IRQ connection specified */ + if (err && ops->is_intc) { + irq = fdti->irq_base[0]; + err = 0; + } + if (!err) { + sysbus_connect_irq(sysbus_from_qdev(dev), 0, irq); + fprintf(stderr, "FDT: (%s) connected irq %s\n", ops->dev_name, irq_info); + } + } + /* create interrupt controller connections if appropriate */ + if (ops->is_intc) { + int i; + qemu_irq *irqs = g_malloc0(sizeof(*irqs) * ops->is_intc); + for (i = 0; i < ops->is_intc; i++) { + irqs[i] = qdev_get_gpio_in(dev, i); + } + fdt_init_set_opaque(fdti, node_path, irqs); + } + + if (props) { + g_free(props); + } + return 0; +} diff --git a/hw/fdt_generic_qdev.h b/hw/fdt_generic_qdev.h new file mode 100644 index 0000000..fe140b3 --- /dev/null +++ b/hw/fdt_generic_qdev.h @@ -0,0 +1,46 @@ +#ifndef FDT_GENERIC_QDEV_H +#define FDT_GENERIC_QDEV_H + +#include "fdt_generic.h" +#include "qdev.h" + +typedef struct FDTQDevPropMapping { + const char *name; + union { + /* TODO: add support for structure type QDEV props */ + uint8_t u8; + uint16_t u16; + uint32_t u32; + void *p; + } src; + int freesrc; +} FDTQDevPropMapping; + +typedef FDTQDevPropMapping* (*FDTQDevMapFn)(char *, FDTMachineInfo *); + +typedef struct FDTQDevOps { + const char *dev_name; + /* TODO: implement */ + const int *irq_map; + const int is_nic; + /* FIXME: Add mechanism for dynamically chnginging number of intc IRQs */ + const int is_intc; + FDTQDevMapFn map; +} FDTQDevOps; + +/* FDT init functions for qdev models */ + +int fdt_init_qdev(char *, FDTMachineInfo *, void *); + +/* statically register a FDTQDevMapFn as being associate with a compatibility */ + +#define fdt_qdev_register_compatibility_n(ops, compat, n) \ +static void __attribute__((constructor)) \ +function ## n ## _register_imp (void) { \ + add_to_compat_table(fdt_init_qdev, compat, ops); \ +} + +#define fdt_qdev_register_compatibility(ops, compat) \ +fdt_qdev_register_compatibility_n(ops, compat, 0); + +#endif /* FDT_GENERIC_QDEV_H */