From 02e2da45c4601909d5105838323d5c529ec7010b Mon Sep 17 00:00:00 2001 From: Paul Brook Date: Sat, 23 May 2009 00:05:19 +0100 Subject: Add common BusState Implement and use a common device bus state. The main side-effect is that creating a bus and attaching it to a parent device are no longer separate operations. For legacy code we allow a NULL parent, but that should go away eventually. Also tweak creation code to veriry theat a device in on the right bus. Signed-off-by: Paul Brook --- hw/sysbus.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'hw/sysbus.c') diff --git a/hw/sysbus.c b/hw/sysbus.c index e6cb7dd78b..13d81f541f 100644 --- a/hw/sysbus.c +++ b/hw/sysbus.c @@ -21,6 +21,11 @@ #include "sysbus.h" #include "sysemu.h" +typedef struct { + DeviceInfo qdev; + sysbus_initfn init; +} SysBusDeviceInfo; + void sysbus_connect_irq(SysBusDevice *dev, int n, qemu_irq irq) { assert(n >= 0 && n < dev->num_irq); @@ -97,17 +102,24 @@ void sysbus_init_mmio_cb(SysBusDevice *dev, target_phys_addr_t size, dev->mmio[n].cb = cb; } -static void sysbus_device_init(DeviceState *dev, void *opaque) +static void sysbus_device_init(DeviceState *dev, DeviceInfo *base) { - sysbus_initfn init = (sysbus_initfn)opaque; + SysBusDeviceInfo *info = container_of(base, SysBusDeviceInfo, qdev); - init(sysbus_from_qdev(dev)); + info->init(sysbus_from_qdev(dev)); } void sysbus_register_dev(const char *name, size_t size, sysbus_initfn init) { + SysBusDeviceInfo *info; + + info = qemu_mallocz(sizeof(*info)); + info->init = init; + info->qdev.init = sysbus_device_init; + info->qdev.bus_type = BUS_TYPE_SYSTEM; + assert(size >= sizeof(SysBusDevice)); - qdev_register(name, size, sysbus_device_init, init); + qdev_register(name, size, &info->qdev); } DeviceState *sysbus_create_varargs(const char *name, -- cgit v1.2.3-55-g7522