All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/4] qdev patches.
@ 2009-06-12  9:28 Gerd Hoffmann
  2009-06-12  9:28 ` [Qemu-devel] [PATCH 1/4] qdev: update pci device registration Gerd Hoffmann
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Gerd Hoffmann @ 2009-06-12  9:28 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

  Hi,

This is a respin of my qdev patches.  They are rebased to the latest
master, the merged patch is dropped, some stray xen bits sprinkled in
here and there leading to rejects when applying are killed.  A new patch
converting i440fx to qdev is added.

Can also be pulled from
	git://git.et.redhat.com/qemu-kraxel.git (branch qdev.v2).

cheers,
  Gerd

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Qemu-devel] [PATCH 1/4] qdev: update pci device registration.
  2009-06-12  9:28 [Qemu-devel] [PATCH 0/4] qdev patches Gerd Hoffmann
@ 2009-06-12  9:28 ` Gerd Hoffmann
  2009-06-12  9:28 ` [Qemu-devel] [PATCH 2/4] qdev: replace bus_type enum with bus_info struct Gerd Hoffmann
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Gerd Hoffmann @ 2009-06-12  9:28 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

Makes pci_qdev_register take a PCIDeviceInfo struct instead of a bunch
of parameters.  Also adds config_read and config_write callbacks to
PCIDeviceInfo, so drivers needing these can be converted to the qdev
device API too.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/e1000.c         |    8 +++++++-
 hw/eepro100.c      |   23 +++++++++++++++++------
 hw/lsi53c895a.c    |    8 +++++++-
 hw/ne2000.c        |    8 +++++++-
 hw/pci.c           |   24 ++++++++----------------
 hw/pci.h           |    9 ++++++++-
 hw/pcnet.c         |    8 +++++++-
 hw/rtl8139.c       |    8 +++++++-
 hw/versatile_pci.c |    9 +++++++--
 hw/virtio-pci.c    |   29 +++++++++++++++++++++--------
 10 files changed, 96 insertions(+), 38 deletions(-)

diff --git a/hw/e1000.c b/hw/e1000.c
index eed02a6..0372276 100644
--- a/hw/e1000.c
+++ b/hw/e1000.c
@@ -1133,9 +1133,15 @@ static void pci_e1000_init(PCIDevice *pci_dev)
     e1000_reset(d);
 }
 
+static PCIDeviceInfo e1000_info = {
+    .qdev.name = "e1000",
+    .qdev.size = sizeof(E1000State),
+    .init      = pci_e1000_init,
+};
+
 static void e1000_register_devices(void)
 {
-    pci_qdev_register("e1000", sizeof(E1000State), pci_e1000_init);
+    pci_qdev_register(&e1000_info, 1);
 }
 
 device_init(e1000_register_devices)
diff --git a/hw/eepro100.c b/hw/eepro100.c
index a6355dc..fc0e022 100644
--- a/hw/eepro100.c
+++ b/hw/eepro100.c
@@ -1792,14 +1792,25 @@ static void pci_i82559er_init(PCIDevice *dev)
     nic_init(dev, i82559ER);
 }
 
+static PCIDeviceInfo eepro100_info[] = {
+    {
+        .qdev.name = "i82551",
+        .qdev.size = sizeof(PCIEEPRO100State),
+        .init      = pci_i82551_init,
+    },{
+        .qdev.name = "i82557b",
+        .qdev.size = sizeof(PCIEEPRO100State),
+        .init      = pci_i82557b_init,
+    },{
+        .qdev.name = "i82559er",
+        .qdev.size = sizeof(PCIEEPRO100State),
+        .init      = pci_i82559er_init,
+    }
+};
+
 static void eepro100_register_devices(void)
 {
-    pci_qdev_register("i82551", sizeof(PCIEEPRO100State),
-                      pci_i82551_init);
-    pci_qdev_register("i82557b", sizeof(PCIEEPRO100State),
-                      pci_i82557b_init);
-    pci_qdev_register("i82559er", sizeof(PCIEEPRO100State),
-                      pci_i82559er_init);
+    pci_qdev_register(eepro100_info, ARRAY_SIZE(eepro100_info));
 }
 
 device_init(eepro100_register_devices)
diff --git a/hw/lsi53c895a.c b/hw/lsi53c895a.c
index 9b9f761..03cd763 100644
--- a/hw/lsi53c895a.c
+++ b/hw/lsi53c895a.c
@@ -2019,9 +2019,15 @@ static void lsi_scsi_init(PCIDevice *dev)
     scsi_bus_new(&dev->qdev, lsi_scsi_attach);
 }
 
+static PCIDeviceInfo lsi_info = {
+    .qdev.name = "lsi53c895a",
+    .qdev.size = sizeof(LSIState),
+    .init      = lsi_scsi_init,
+};
+
 static void lsi53c895a_register_devices(void)
 {
-    pci_qdev_register("lsi53c895a", sizeof(LSIState), lsi_scsi_init);
+    pci_qdev_register(&lsi_info, 1);
 }
 
 device_init(lsi53c895a_register_devices);
diff --git a/hw/ne2000.c b/hw/ne2000.c
index f5ae9d7..570377f 100644
--- a/hw/ne2000.c
+++ b/hw/ne2000.c
@@ -832,9 +832,15 @@ static void pci_ne2000_init(PCIDevice *pci_dev)
     register_savevm("ne2000", -1, 3, ne2000_save, ne2000_load, s);
 }
 
+static PCIDeviceInfo ne2000_info = {
+    .qdev.name = "ne2k_pci",
+    .qdev.size = sizeof(PCINE2000State),
+    .init      = pci_ne2000_init,
+};
+
 static void ne2000_register_devices(void)
 {
-    pci_qdev_register("ne2k_pci", sizeof(PCINE2000State), pci_ne2000_init);
+    pci_qdev_register(&ne2000_info, 1);
 }
 
 device_init(ne2000_register_devices)
diff --git a/hw/pci.c b/hw/pci.c
index a3af3b5..aaea683 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -899,11 +899,6 @@ PCIBus *pci_bridge_init(PCIBus *bus, int devfn, uint16_t vid, uint16_t did,
     return s->bus;
 }
 
-typedef struct {
-    DeviceInfo qdev;
-    pci_qdev_initfn init;
-} PCIDeviceInfo;
-
 static void pci_qdev_init(DeviceState *qdev, DeviceInfo *base)
 {
     PCIDevice *pci_dev = (PCIDevice *)qdev;
@@ -914,23 +909,20 @@ static void pci_qdev_init(DeviceState *qdev, DeviceInfo *base)
     bus = FROM_QBUS(PCIBus, qdev_get_parent_bus(qdev));
     devfn = qdev_get_prop_int(qdev, "devfn", -1);
     pci_dev = do_pci_register_device(pci_dev, bus, "FIXME", devfn,
-                                     NULL, NULL);//FIXME:config_read, config_write);
+                                     info->config_read, info->config_write);
     assert(pci_dev);
     info->init(pci_dev);
 }
 
-void pci_qdev_register(const char *name, int size, pci_qdev_initfn init)
+void pci_qdev_register(PCIDeviceInfo *info, int count)
 {
-    PCIDeviceInfo *info;
-
-    info = qemu_mallocz(sizeof(*info));
-    info->qdev.name = qemu_strdup(name);
-    info->qdev.size = size;
-    info->init = init;
-    info->qdev.init = pci_qdev_init;
-    info->qdev.bus_type = BUS_TYPE_PCI;
+    int i;
 
-    qdev_register(&info->qdev);
+    for (i = 0; i < count; i++, info++) {
+        info->qdev.init = pci_qdev_init;
+        info->qdev.bus_type = BUS_TYPE_PCI;
+        qdev_register(&info->qdev);
+    }
 }
 
 PCIDevice *pci_create_simple(PCIBus *bus, int devfn, const char *name)
diff --git a/hw/pci.h b/hw/pci.h
index af6c8fd..aeb4539 100644
--- a/hw/pci.h
+++ b/hw/pci.h
@@ -218,7 +218,14 @@ pci_config_set_class(uint8_t *pci_config, uint16_t val)
 }
 
 typedef void (*pci_qdev_initfn)(PCIDevice *dev);
-void pci_qdev_register(const char *name, int size, pci_qdev_initfn init);
+typedef struct {
+    DeviceInfo qdev;
+    pci_qdev_initfn init;
+    PCIConfigReadFunc *config_read;
+    PCIConfigWriteFunc *config_write;
+} PCIDeviceInfo;
+
+void pci_qdev_register(PCIDeviceInfo *info, int count);
 
 PCIDevice *pci_create_simple(PCIBus *bus, int devfn, const char *name);
 
diff --git a/hw/pcnet.c b/hw/pcnet.c
index b5793ff..4c06f23 100644
--- a/hw/pcnet.c
+++ b/hw/pcnet.c
@@ -2143,9 +2143,15 @@ static void lance_init(SysBusDevice *dev)
 }
 #endif /* TARGET_SPARC */
 
+static PCIDeviceInfo pcnet_info = {
+    .qdev.name = "pcnet",
+    .qdev.size = sizeof(PCIPCNetState),
+    .init      = pci_pcnet_init,
+};
+
 static void pcnet_register_devices(void)
 {
-    pci_qdev_register("pcnet", sizeof(PCIPCNetState), pci_pcnet_init);
+    pci_qdev_register(&pcnet_info, 1);
 #if defined (TARGET_SPARC) && !defined(TARGET_SPARC64)
     sysbus_register_dev("lance", sizeof(SysBusPCNetState), lance_init);
 #endif
diff --git a/hw/rtl8139.c b/hw/rtl8139.c
index de5a68f..9ea18da 100644
--- a/hw/rtl8139.c
+++ b/hw/rtl8139.c
@@ -3501,9 +3501,15 @@ static void pci_rtl8139_init(PCIDevice *dev)
 #endif /* RTL8139_ONBOARD_TIMER */
 }
 
+static PCIDeviceInfo rtl8139_info = {
+    .qdev.name = "rtl8139",
+    .qdev.size = sizeof(PCIRTL8139State),
+    .init      = pci_rtl8139_init,
+};
+
 static void rtl8139_register_devices(void)
 {
-    pci_qdev_register("rtl8139", sizeof(PCIRTL8139State), pci_rtl8139_init);
+    pci_qdev_register(&rtl8139_info, 1);
 }
 
 device_init(rtl8139_register_devices)
diff --git a/hw/versatile_pci.c b/hw/versatile_pci.c
index e454d49..a980bf0 100644
--- a/hw/versatile_pci.c
+++ b/hw/versatile_pci.c
@@ -153,13 +153,18 @@ static void versatile_pci_host_init(PCIDevice *d)
     d->config[0x0D] = 0x10; // latency_timer
 }
 
+static PCIDeviceInfo versatile_pci_host_info = {
+    .qdev.name = "versatile_pci_host",
+    .qdev.size = sizeof(PCIDevice),
+    .init      = versatile_pci_host_init,
+};
+
 static void versatile_pci_register_devices(void)
 {
     sysbus_register_dev("versatile_pci", sizeof(PCIVPBState), pci_vpb_init);
     sysbus_register_dev("realview_pci", sizeof(PCIVPBState),
                         pci_realview_init);
-    pci_qdev_register("versatile_pci_host", sizeof(PCIDevice),
-                      versatile_pci_host_init);
+    pci_qdev_register(&versatile_pci_host_info, 1);
 }
 
 device_init(versatile_pci_register_devices)
diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index c072423..ae0dda5 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -334,16 +334,29 @@ static void virtio_balloon_init_pci(PCIDevice *pci_dev)
                     0x00);
 }
 
+static PCIDeviceInfo virtio_info[] = {
+    {
+        .qdev.name = "virtio-blk-pci",
+        .qdev.size = sizeof(VirtIOPCIProxy),
+        .init      = virtio_blk_init_pci,
+    },{
+        .qdev.name = "virtio-net-pci",
+        .qdev.size = sizeof(VirtIOPCIProxy),
+        .init      = virtio_net_init_pci,
+    },{
+        .qdev.name = "virtio-console-pci",
+        .qdev.size = sizeof(VirtIOPCIProxy),
+        .init      = virtio_console_init_pci,
+    },{
+        .qdev.name = "virtio-balloon-pci",
+        .qdev.size = sizeof(VirtIOPCIProxy),
+        .init      = virtio_balloon_init_pci,
+    }
+};
+
 static void virtio_pci_register_devices(void)
 {
-    pci_qdev_register("virtio-blk-pci", sizeof(VirtIOPCIProxy),
-                      virtio_blk_init_pci);
-    pci_qdev_register("virtio-net-pci", sizeof(VirtIOPCIProxy),
-                      virtio_net_init_pci);
-    pci_qdev_register("virtio-console-pci", sizeof(VirtIOPCIProxy),
-                      virtio_console_init_pci);
-    pci_qdev_register("virtio-balloon-pci", sizeof(VirtIOPCIProxy),
-                      virtio_balloon_init_pci);
+    pci_qdev_register(virtio_info, ARRAY_SIZE(virtio_info));
 }
 
 device_init(virtio_pci_register_devices)
-- 
1.6.2.2

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [Qemu-devel] [PATCH 2/4] qdev: replace bus_type enum with bus_info struct.
  2009-06-12  9:28 [Qemu-devel] [PATCH 0/4] qdev patches Gerd Hoffmann
  2009-06-12  9:28 ` [Qemu-devel] [PATCH 1/4] qdev: update pci device registration Gerd Hoffmann
@ 2009-06-12  9:28 ` Gerd Hoffmann
  2009-06-12  9:28 ` [Qemu-devel] [PATCH 3/4] qdev: very first cut of scsi bus support Gerd Hoffmann
  2009-06-12  9:28 ` [Qemu-devel] [PATCH 4/4] qdev: hook up i440fx Gerd Hoffmann
  3 siblings, 0 replies; 7+ messages in thread
From: Gerd Hoffmann @ 2009-06-12  9:28 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

BusInfo is filled with name and size (pretty much like I did for
DeviceInfo as well).  There is also a function pointer to print
bus-specific device information to the monitor.  sysbus is hooked
up there, I've also added a print function for PCI.

Device creation is slightly modified as well:  The device type search
loop now also checks the bus type while scanning the list instead of
complaining thereafter in case of a mismatch.  This effectively gives
each bus a private namespace for device names.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/i2c.c    |   10 +++++++---
 hw/pci.c    |   53 ++++++++++++++++++++++++++++++++++++++++++++++++-----
 hw/qdev.c   |   58 ++++++++++++++++++++--------------------------------------
 hw/qdev.h   |   23 +++++++++++------------
 hw/ssi.c    |    9 +++++++--
 hw/sysbus.c |   12 ++++++++++--
 6 files changed, 103 insertions(+), 62 deletions(-)

diff --git a/hw/i2c.c b/hw/i2c.c
index 838f40f..98aa7fc 100644
--- a/hw/i2c.c
+++ b/hw/i2c.c
@@ -17,6 +17,11 @@ struct i2c_bus
     int saved_address;
 };
 
+static struct BusInfo i2c_bus_info = {
+    .name = "I2C",
+    .size = sizeof(i2c_bus),
+};
+
 static void i2c_bus_save(QEMUFile *f, void *opaque)
 {
     i2c_bus *bus = (i2c_bus *)opaque;
@@ -44,8 +49,7 @@ i2c_bus *i2c_init_bus(DeviceState *parent, const char *name)
 {
     i2c_bus *bus;
 
-    bus = FROM_QBUS(i2c_bus, qbus_create(BUS_TYPE_I2C, sizeof(i2c_bus),
-                                         parent, name));
+    bus = FROM_QBUS(i2c_bus, qbus_create(&i2c_bus_info, parent, name));
     register_savevm("i2c_bus", -1, 1, i2c_bus_save, i2c_bus_load, bus);
     return bus;
 }
@@ -156,7 +160,7 @@ void i2c_register_slave(I2CSlaveInfo *info)
 {
     assert(info->qdev.size >= sizeof(i2c_slave));
     info->qdev.init = i2c_slave_qdev_init;
-    info->qdev.bus_type = BUS_TYPE_I2C;
+    info->qdev.bus_info = &i2c_bus_info;
     qdev_register(&info->qdev);
 }
 
diff --git a/hw/pci.c b/hw/pci.c
index aaea683..4ce1419 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -45,7 +45,15 @@ struct PCIBus {
     /* The bus IRQ state is the logical OR of the connected devices.
        Keep a count of the number of devices with raised IRQs.  */
     int nirq;
-    int irq_count[];
+    int *irq_count;
+};
+
+static void pcibus_dev_print(Monitor *mon, DeviceState *dev, int indent);
+
+static struct BusInfo pci_bus_info = {
+    .name  = "PCI",
+    .size  = sizeof(PCIBus),
+    .print = pcibus_dev_print,
 };
 
 static void pci_update_mappings(PCIDevice *d);
@@ -94,14 +102,13 @@ PCIBus *pci_register_bus(DeviceState *parent, const char *name,
     PCIBus *bus;
     static int nbus = 0;
 
-    bus = FROM_QBUS(PCIBus, qbus_create(BUS_TYPE_PCI,
-                                        sizeof(PCIBus) + (nirq * sizeof(int)),
-                                        parent, name));
+    bus = FROM_QBUS(PCIBus, qbus_create(&pci_bus_info, parent, name));
     bus->set_irq = set_irq;
     bus->map_irq = map_irq;
     bus->irq_opaque = pic;
     bus->devfn_min = devfn_min;
     bus->nirq = nirq;
+    bus->irq_count = qemu_malloc(nirq * sizeof(bus->irq_count[0]));
     bus->next = first_bus;
     first_bus = bus;
     register_savevm("PCIBUS", nbus++, 1, pcibus_save, pcibus_load, bus);
@@ -920,7 +927,7 @@ void pci_qdev_register(PCIDeviceInfo *info, int count)
 
     for (i = 0; i < count; i++, info++) {
         info->qdev.init = pci_qdev_init;
-        info->qdev.bus_type = BUS_TYPE_PCI;
+        info->qdev.bus_info = &pci_bus_info;
         qdev_register(&info->qdev);
     }
 }
@@ -935,3 +942,39 @@ PCIDevice *pci_create_simple(PCIBus *bus, int devfn, const char *name)
 
     return (PCIDevice *)dev;
 }
+
+static void pcibus_dev_print(Monitor *mon, DeviceState *dev, int indent)
+{
+    PCIDevice *d = (PCIDevice *)dev;
+    const pci_class_desc *desc;
+    char ctxt[64];
+    PCIIORegion *r;
+    int i, class;
+
+    class = le16_to_cpu(*((uint16_t *)(d->config + PCI_CLASS_DEVICE)));
+    desc = pci_class_descriptions;
+    while (desc->desc && class != desc->class)
+        desc++;
+    if (desc->desc) {
+        snprintf(ctxt, sizeof(ctxt), "%s", desc->desc);
+    } else {
+        snprintf(ctxt, sizeof(ctxt), "Class %04x", class);
+    }
+
+    monitor_printf(mon, "%*sclass %s, addr %02x:%02x.%x, "
+                   "pci id %04x:%04x (sub %04x:%04x)\n",
+                   indent, "", ctxt,
+                   d->bus->bus_num, d->devfn >> 3, d->devfn & 7,
+                   le16_to_cpu(*((uint16_t *)(d->config + PCI_VENDOR_ID))),
+                   le16_to_cpu(*((uint16_t *)(d->config + PCI_DEVICE_ID))),
+                   le16_to_cpu(*((uint16_t *)(d->config + PCI_SUBSYSTEM_VENDOR_ID))),
+                   le16_to_cpu(*((uint16_t *)(d->config + PCI_SUBSYSTEM_ID))));
+    for (i = 0; i < PCI_NUM_REGIONS; i++) {
+        r = &d->io_regions[i];
+        if (!r->size)
+            continue;
+        monitor_printf(mon, "%*sbar %d: %s at 0x%x [0x%x]\n", indent, "",
+                       i, r->type & PCI_ADDRESS_SPACE_IO ? "i/o" : "mem",
+                       r->addr, r->addr + r->size - 1);
+    }
+}
diff --git a/hw/qdev.c b/hw/qdev.c
index 385e709..93e417d 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -48,6 +48,7 @@ struct DeviceType {
 
 /* This is a nasty hack to allow passing a NULL bus to qdev_create.  */
 static BusState *main_system_bus;
+extern struct BusInfo system_bus_info;
 
 static DeviceType *device_type_list;
 
@@ -72,31 +73,26 @@ DeviceState *qdev_create(BusState *bus, const char *name)
     DeviceType *t;
     DeviceState *dev;
 
-    for (t = device_type_list; t; t = t->next) {
-        if (strcmp(t->info->name, name) == 0) {
-            break;
+    if (!bus) {
+        if (!main_system_bus) {
+            main_system_bus = qbus_create(&system_bus_info, NULL, "main-system-bus");
         }
+        bus = main_system_bus;
+    }
+
+    for (t = device_type_list; t; t = t->next) {
+        if (t->info->bus_info != bus->info)
+            continue;
+        if (strcmp(t->info->name, name) != 0)
+            continue;
+        break;
     }
     if (!t) {
-        hw_error("Unknown device '%s'\n", name);
+        hw_error("Unknown device '%s' for bus '%s'\n", name, bus->info->name);
     }
 
     dev = qemu_mallocz(t->info->size);
     dev->type = t;
-
-    if (!bus) {
-        /* ???: This assumes system busses have no additional state.  */
-        if (!main_system_bus) {
-            main_system_bus = qbus_create(BUS_TYPE_SYSTEM, sizeof(BusState),
-                                          NULL, "main-system-bus");
-        }
-        bus = main_system_bus;
-    }
-    if (t->info->bus_type != bus->type) {
-        /* TODO: Print bus type names.  */
-        hw_error("Device '%s' on wrong bus type (%d/%d)", name,
-                 t->info->bus_type, bus->type);
-    }
     dev->parent_bus = bus;
     LIST_INSERT_HEAD(&bus->children, dev, sibling);
     return dev;
@@ -320,13 +316,12 @@ void scsi_bus_new(DeviceState *host, SCSIAttachFn attach)
    }
 }
 
-BusState *qbus_create(BusType type, size_t size,
-                      DeviceState *parent, const char *name)
+BusState *qbus_create(BusInfo *info, DeviceState *parent, const char *name)
 {
     BusState *bus;
 
-    bus = qemu_mallocz(size);
-    bus->type = type;
+    bus = qemu_mallocz(info->size);
+    bus->info = info;
     bus->parent = parent;
     bus->name = qemu_strdup(name);
     LIST_INIT(&bus->children);
@@ -336,14 +331,6 @@ BusState *qbus_create(BusType type, size_t size,
     return bus;
 }
 
-static const char *bus_type_names[] = {
-    [ BUS_TYPE_SYSTEM ] = "System",
-    [ BUS_TYPE_PCI ]    = "PCI",
-    [ BUS_TYPE_SCSI ]   = "SCSI",
-    [ BUS_TYPE_I2C ]    = "I2C",
-    [ BUS_TYPE_SSI ]    = "SSI",
-};
-
 #define qdev_printf(fmt, ...) monitor_printf(mon, "%*s" fmt, indent, "", ## __VA_ARGS__)
 static void qbus_print(Monitor *mon, BusState *bus, int indent);
 
@@ -377,13 +364,8 @@ static void qdev_print(Monitor *mon, DeviceState *dev, int indent)
             break;
         }
     }
-    switch (dev->parent_bus->type) {
-    case BUS_TYPE_SYSTEM:
-        sysbus_dev_print(mon, dev, indent);
-        break;
-    default:
-        break;
-    }
+    if (dev->parent_bus->info->print)
+        dev->parent_bus->info->print(mon, dev, indent);
     LIST_FOREACH(child, &dev->child_bus, sibling) {
         qbus_print(mon, child, indent);
     }
@@ -395,7 +377,7 @@ static void qbus_print(Monitor *mon, BusState *bus, int indent)
 
     qdev_printf("bus: %s\n", bus->name);
     indent += 2;
-    qdev_printf("type %s\n", bus_type_names[bus->type]);
+    qdev_printf("type %s\n", bus->info->name);
     LIST_FOREACH(dev, &bus->children, sibling) {
         qdev_print(mon, dev, indent);
     }
diff --git a/hw/qdev.h b/hw/qdev.h
index ad10499..8b238d5 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -10,6 +10,8 @@ typedef struct DeviceProperty DeviceProperty;
 
 typedef struct BusState BusState;
 
+typedef struct BusInfo BusInfo;
+
 /* This structure should not be accessed directly.  We declare it here
    so that it can be embedded in individual device state structures.  */
 struct DeviceState {
@@ -25,18 +27,17 @@ struct DeviceState {
     LIST_ENTRY(DeviceState) sibling;
 };
 
-typedef enum {
-    BUS_TYPE_SYSTEM,
-    BUS_TYPE_PCI,
-    BUS_TYPE_SCSI,
-    BUS_TYPE_I2C,
-    BUS_TYPE_SSI
-} BusType;
+typedef void (*bus_dev_print)(Monitor *mon, DeviceState *dev, int indent);
+struct BusInfo {
+    const char *name;
+    size_t size;
+    bus_dev_print print;
+};
 
 struct BusState {
     DeviceState *parent;
+    BusInfo *info;
     const char *name;
-    BusType type;
     LIST_HEAD(, DeviceState) children;
     LIST_ENTRY(BusState) sibling;
 };
@@ -84,7 +85,7 @@ struct DeviceInfo {
 
     /* Private to qdev / bus.  */
     qdev_initfn init;
-    BusType bus_type;
+    BusInfo *bus_info;
 };
 
 void qdev_register(DeviceInfo *info);
@@ -116,14 +117,12 @@ void *qdev_get_prop_ptr(DeviceState *dev, const char *name);
 
 /*** BUS API. ***/
 
-BusState *qbus_create(BusType type, size_t size,
-                      DeviceState *parent, const char *name);
+BusState *qbus_create(BusInfo *info, DeviceState *parent, const char *name);
 
 #define FROM_QBUS(type, dev) DO_UPCAST(type, qbus, dev)
 
 /*** monitor commands ***/
 
 void do_info_qtree(Monitor *mon);
-void sysbus_dev_print(Monitor *mon, DeviceState *dev, int indent);
 
 #endif
diff --git a/hw/ssi.c b/hw/ssi.c
index b0bcf97..a5133be 100644
--- a/hw/ssi.c
+++ b/hw/ssi.c
@@ -13,6 +13,11 @@ struct SSIBus {
     BusState qbus;
 };
 
+static struct BusInfo ssi_bus_info = {
+    .name = "SSI",
+    .size = sizeof(SSIBus),
+};
+
 static void ssi_slave_init(DeviceState *dev, DeviceInfo *base_info)
 {
     SSISlaveInfo *info = container_of(base_info, SSISlaveInfo, qdev);
@@ -33,7 +38,7 @@ void ssi_register_slave(SSISlaveInfo *info)
 {
     assert(info->qdev.size >= sizeof(SSISlave));
     info->qdev.init = ssi_slave_init;
-    info->qdev.bus_type = BUS_TYPE_SSI;
+    info->qdev.bus_info = &ssi_bus_info;
     qdev_register(&info->qdev);
 }
 
@@ -48,7 +53,7 @@ DeviceState *ssi_create_slave(SSIBus *bus, const char *name)
 SSIBus *ssi_create_bus(DeviceState *parent, const char *name)
 {
     BusState *bus;
-    bus = qbus_create(BUS_TYPE_SSI, sizeof(SSIBus), parent, name);
+    bus = qbus_create(&ssi_bus_info, parent, name);
     return FROM_QBUS(SSIBus, bus);
 }
 
diff --git a/hw/sysbus.c b/hw/sysbus.c
index ef3a701..13e563b 100644
--- a/hw/sysbus.c
+++ b/hw/sysbus.c
@@ -22,6 +22,14 @@
 #include "sysemu.h"
 #include "monitor.h"
 
+static void sysbus_dev_print(Monitor *mon, DeviceState *dev, int indent);
+
+struct BusInfo system_bus_info = {
+    .name  = "System",
+    .size  = sizeof(BusState),
+    .print = sysbus_dev_print,
+};
+
 void sysbus_connect_irq(SysBusDevice *dev, int n, qemu_irq irq)
 {
     assert(n >= 0 && n < dev->num_irq);
@@ -108,7 +116,7 @@ static void sysbus_device_init(DeviceState *dev, DeviceInfo *base)
 void sysbus_register_withprop(SysBusDeviceInfo *info)
 {
     info->qdev.init = sysbus_device_init;
-    info->qdev.bus_type = BUS_TYPE_SYSTEM;
+    info->qdev.bus_info = &system_bus_info;
 
     assert(info->qdev.size >= sizeof(SysBusDevice));
     qdev_register(&info->qdev);
@@ -153,7 +161,7 @@ DeviceState *sysbus_create_varargs(const char *name,
     return dev;
 }
 
-void sysbus_dev_print(Monitor *mon, DeviceState *dev, int indent)
+static void sysbus_dev_print(Monitor *mon, DeviceState *dev, int indent)
 {
     SysBusDevice *s = sysbus_from_qdev(dev);
     int i;
-- 
1.6.2.2

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [Qemu-devel] [PATCH 3/4] qdev: very first cut of scsi bus support.
  2009-06-12  9:28 [Qemu-devel] [PATCH 0/4] qdev patches Gerd Hoffmann
  2009-06-12  9:28 ` [Qemu-devel] [PATCH 1/4] qdev: update pci device registration Gerd Hoffmann
  2009-06-12  9:28 ` [Qemu-devel] [PATCH 2/4] qdev: replace bus_type enum with bus_info struct Gerd Hoffmann
@ 2009-06-12  9:28 ` Gerd Hoffmann
  2009-06-12 11:22   ` Paul Brook
  2009-06-12  9:28 ` [Qemu-devel] [PATCH 4/4] qdev: hook up i440fx Gerd Hoffmann
  3 siblings, 1 reply; 7+ messages in thread
From: Gerd Hoffmann @ 2009-06-12  9:28 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann


Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 Makefile          |    2 +-
 hw/esp.c          |    8 ++++--
 hw/lsi53c895a.c   |    9 +++++--
 hw/qdev.c         |   19 ---------------
 hw/qdev.h         |    4 ---
 hw/scsi-bus.c     |   66 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/scsi-disk.c    |   27 ++++++++++++++++++++-
 hw/scsi-disk.h    |   22 ++++++++++++++++-
 hw/scsi-generic.c |   24 +++++++++++++++++--
 hw/usb-msd.c      |    2 +-
 10 files changed, 145 insertions(+), 38 deletions(-)
 create mode 100644 hw/scsi-bus.c

diff --git a/Makefile b/Makefile
index 3177616..a1d8a76 100644
--- a/Makefile
+++ b/Makefile
@@ -98,7 +98,7 @@ OBJS+=i2c.o smbus.o smbus_eeprom.o max7310.o max111x.o wm8750.o
 OBJS+=ssd0303.o ssd0323.o ads7846.o stellaris_input.o twl92230.o
 OBJS+=tmp105.o lm832x.o eeprom93xx.o tsc2005.o
 OBJS+=scsi-disk.o cdrom.o
-OBJS+=scsi-generic.o
+OBJS+=scsi-generic.o scsi-bus.o
 OBJS+=usb.o usb-hub.o usb-$(HOST_USB).o usb-hid.o usb-msd.o usb-wacom.o
 OBJS+=usb-serial.o usb-net.o
 OBJS+=sd.o ssi-sd.o
diff --git a/hw/esp.c b/hw/esp.c
index ffb2225..cfb90a9 100644
--- a/hw/esp.c
+++ b/hw/esp.c
@@ -63,6 +63,7 @@ struct ESPState {
     uint8_t ti_buf[TI_BUFSZ];
     uint32_t sense;
     uint32_t dma;
+    SCSIBus *bus;
     SCSIDevice *scsi_dev[ESP_MAX_DEVS];
     SCSIDevice *current_dev;
     uint8_t cmdbuf[TI_BUFSZ];
@@ -640,9 +641,9 @@ static void esp_scsi_attach(DeviceState *host, BlockDriverState *bd, int id)
     }
     DPRINTF("Attaching block device %d\n", id);
     /* Command queueing is not implemented.  */
-    s->scsi_dev[id] = scsi_generic_init(bd, 0, esp_command_complete, s);
+    s->scsi_dev[id] = scsi_generic_init(s->bus, bd, 0, esp_command_complete, s);
     if (s->scsi_dev[id] == NULL)
-        s->scsi_dev[id] = scsi_disk_init(bd, 0, esp_command_complete, s);
+        s->scsi_dev[id] = scsi_disk_init(s->bus, bd, 0, esp_command_complete, s);
 }
 
 void esp_init(target_phys_addr_t espaddr, int it_shift,
@@ -686,7 +687,8 @@ static void esp_init1(SysBusDevice *dev)
 
     qdev_init_gpio_in(&dev->qdev, parent_esp_reset, 1);
 
-    scsi_bus_new(&dev->qdev, esp_scsi_attach);
+    s->bus = scsi_bus_new(&dev->qdev, esp_scsi_attach);
+    scsi_bus_attach_cmdline(s->bus);
 }
 
 static void esp_register_devices(void)
diff --git a/hw/lsi53c895a.c b/hw/lsi53c895a.c
index 03cd763..c5d9275 100644
--- a/hw/lsi53c895a.c
+++ b/hw/lsi53c895a.c
@@ -12,6 +12,7 @@
 
 #include "hw.h"
 #include "pci.h"
+#include "scsi.h"
 #include "scsi-disk.h"
 #include "block_int.h"
 
@@ -190,6 +191,7 @@ typedef struct {
      * 2 if processing DMA from lsi_execute_script.
      * 3 if a DMA operation is in progress.  */
     int waiting;
+    SCSIBus *bus;
     SCSIDevice *scsi_dev[LSI_MAX_DEVS];
     SCSIDevice *current_dev;
     int current_lun;
@@ -1959,9 +1961,9 @@ void lsi_scsi_attach(DeviceState *host, BlockDriverState *bd, int id)
         s->scsi_dev[id]->destroy(s->scsi_dev[id]);
     }
     DPRINTF("Attaching block device %d\n", id);
-    s->scsi_dev[id] = scsi_generic_init(bd, 1, lsi_command_complete, s);
+    s->scsi_dev[id] = scsi_generic_init(s->bus, bd, 1, lsi_command_complete, s);
     if (s->scsi_dev[id] == NULL)
-        s->scsi_dev[id] = scsi_disk_init(bd, 1, lsi_command_complete, s);
+        s->scsi_dev[id] = scsi_disk_init(s->bus, bd, 1, lsi_command_complete, s);
     bd->private = &s->pci_dev;
 }
 
@@ -2016,7 +2018,8 @@ static void lsi_scsi_init(PCIDevice *dev)
 
     lsi_soft_reset(s);
 
-    scsi_bus_new(&dev->qdev, lsi_scsi_attach);
+    s->bus = scsi_bus_new(&dev->qdev, lsi_scsi_attach);
+    scsi_bus_attach_cmdline(s->bus);
 }
 
 static PCIDeviceInfo lsi_info = {
diff --git a/hw/qdev.c b/hw/qdev.c
index 93e417d..18f03ed 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -297,25 +297,6 @@ BusState *qdev_get_child_bus(DeviceState *dev, const char *name)
     return NULL;
 }
 
-static int next_scsi_bus;
-
-/* Create a scsi bus, and attach devices to it.  */
-/* TODO: Actually create a scsi bus for hotplug to use.  */
-void scsi_bus_new(DeviceState *host, SCSIAttachFn attach)
-{
-   int bus = next_scsi_bus++;
-   int unit;
-   int index;
-
-   for (unit = 0; unit < MAX_SCSI_DEVS; unit++) {
-       index = drive_get_index(IF_SCSI, bus, unit);
-       if (index == -1) {
-           continue;
-       }
-       attach(host, drives_table[index].bdrv, unit);
-   }
-}
-
 BusState *qbus_create(BusInfo *info, DeviceState *parent, const char *name)
 {
     BusState *bus;
diff --git a/hw/qdev.h b/hw/qdev.h
index 8b238d5..7f4236d 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -75,8 +75,6 @@ typedef struct {
 typedef struct DeviceInfo DeviceInfo;
 
 typedef void (*qdev_initfn)(DeviceState *dev, DeviceInfo *info);
-typedef void (*SCSIAttachFn)(DeviceState *host, BlockDriverState *bdrv,
-              int unit);
 
 struct DeviceInfo {
     const char *name;
@@ -95,8 +93,6 @@ void qdev_register(DeviceInfo *info);
 void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n);
 void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n);
 
-void scsi_bus_new(DeviceState *host, SCSIAttachFn attach);
-
 CharDriverState *qdev_init_chardev(DeviceState *dev);
 
 BusState *qdev_get_parent_bus(DeviceState *dev);
diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c
new file mode 100644
index 0000000..7743b22
--- /dev/null
+++ b/hw/scsi-bus.c
@@ -0,0 +1,66 @@
+#include "hw.h"
+#include "sysemu.h"
+#include "scsi-disk.h"
+#include "qdev.h"
+
+struct SCSIBus {
+    BusState qbus;
+    int busnr;
+    SCSIAttachFn attach;
+};
+
+static struct BusInfo scsi_bus_info = {
+    .name  = "SCSI",
+    .size  = sizeof(SCSIBus),
+};
+static int next_scsi_bus;
+
+/* Create a scsi bus, and attach devices to it.  */
+/* TODO: Actually create a scsi bus for hotplug to use.  */
+SCSIBus *scsi_bus_new(DeviceState *host, SCSIAttachFn attach)
+{
+    SCSIBus *bus;
+
+    bus = FROM_QBUS(SCSIBus, qbus_create(&scsi_bus_info, host, "scsi"));
+    bus->busnr = next_scsi_bus++;
+    bus->attach = attach;
+    return bus;
+}
+
+void scsi_bus_attach_cmdline(SCSIBus *bus)
+{
+    int unit;
+    int index;
+
+    for (unit = 0; unit < MAX_SCSI_DEVS; unit++) {
+        index = drive_get_index(IF_SCSI, bus->busnr, unit);
+        if (index == -1) {
+            continue;
+        }
+        bus->attach(bus->qbus.parent, drives_table[index].bdrv, unit);
+    }
+}
+
+static void scsi_qdev_init(DeviceState *qdev, DeviceInfo *base)
+{
+    SCSIDevice *dev = DO_UPCAST(SCSIDevice, qdev, qdev);
+    SCSIDeviceInfo *info = DO_UPCAST(SCSIDeviceInfo, qdev, base);
+
+    info->init(dev);
+}
+
+void scsi_qdev_register(SCSIDeviceInfo *info)
+{
+    info->qdev.bus_info = &scsi_bus_info;
+    info->qdev.init     = scsi_qdev_init;
+    qdev_register(&info->qdev);
+}
+
+SCSIDevice *scsi_create_simple(SCSIBus *bus, const char *name)
+{
+    DeviceState *dev;
+
+    dev = qdev_create(&bus->qbus, name);
+    qdev_init(dev);
+    return DO_UPCAST(SCSIDevice, qdev, dev);
+}
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index a0485db..05e3db5 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -926,7 +926,7 @@ static void scsi_destroy(SCSIDevice *d)
     qemu_free(d);
 }
 
-SCSIDevice *scsi_disk_init(BlockDriverState *bdrv, int tcq,
+SCSIDevice *scsi_disk_init(SCSIBus *bus, BlockDriverState *bdrv, int tcq,
                            scsi_completionfn completion, void *opaque)
 {
     SCSIDevice *d;
@@ -953,7 +953,13 @@ SCSIDevice *scsi_disk_init(BlockDriverState *bdrv, int tcq,
     if (strlen(s->drive_serial_str) == 0)
         pstrcpy(s->drive_serial_str, sizeof(s->drive_serial_str), "0");
     qemu_add_vm_change_state_handler(scsi_dma_restart_cb, s);
-    d = (SCSIDevice *)qemu_mallocz(sizeof(SCSIDevice));
+
+    if (bus) {
+        d = scsi_create_simple(bus, "scsi-disk");
+    } else {
+        /* temporary until usb is qdev-ified */
+        d = (SCSIDevice *)qemu_mallocz(sizeof(SCSIDevice));
+    }
     d->state = s;
     d->destroy = scsi_destroy;
     d->send_command = scsi_send_command;
@@ -964,3 +970,20 @@ SCSIDevice *scsi_disk_init(BlockDriverState *bdrv, int tcq,
 
     return d;
 }
+
+static void scsi_disk_initfn(SCSIDevice *dev)
+{
+    /* TODO */
+}
+
+static SCSIDeviceInfo scsi_disk_info = {
+    .qdev.name = "scsi-disk",
+    .qdev.size = sizeof(SCSIDevice),
+    .init      = scsi_disk_initfn,
+};
+
+static void scsi_disk_register_devices(void)
+{
+    scsi_qdev_register(&scsi_disk_info);
+}
+device_init(scsi_disk_register_devices)
diff --git a/hw/scsi-disk.h b/hw/scsi-disk.h
index f42212b..666131f 100644
--- a/hw/scsi-disk.h
+++ b/hw/scsi-disk.h
@@ -1,12 +1,15 @@
 #ifndef SCSI_DISK_H
 #define SCSI_DISK_H
 
+#include "qdev.h"
+
 /* scsi-disk.c */
 enum scsi_reason {
     SCSI_REASON_DONE, /* Command complete.  */
     SCSI_REASON_DATA  /* Transfer complete, more data required.  */
 };
 
+typedef struct SCSIBus SCSIBus;
 typedef struct SCSIDeviceState SCSIDeviceState;
 typedef struct SCSIDevice SCSIDevice;
 typedef void (*scsi_completionfn)(void *opaque, int reason, uint32_t tag,
@@ -14,6 +17,7 @@ typedef void (*scsi_completionfn)(void *opaque, int reason, uint32_t tag,
 
 struct SCSIDevice
 {
+    DeviceState qdev;
     SCSIDeviceState *state;
     void (*destroy)(SCSIDevice *s);
     int32_t (*send_command)(SCSIDevice *s, uint32_t tag, uint8_t *buf,
@@ -24,13 +28,27 @@ struct SCSIDevice
     uint8_t *(*get_buf)(SCSIDevice *s, uint32_t tag);
 };
 
-SCSIDevice *scsi_disk_init(BlockDriverState *bdrv, int tcq,
+SCSIDevice *scsi_disk_init(SCSIBus *bus, BlockDriverState *bdrv, int tcq,
                            scsi_completionfn completion, void *opaque);
-SCSIDevice *scsi_generic_init(BlockDriverState *bdrv, int tcq,
+SCSIDevice *scsi_generic_init(SCSIBus *bus, BlockDriverState *bdrv, int tcq,
                            scsi_completionfn completion, void *opaque);
 
 /* cdrom.c */
 int cdrom_read_toc(int nb_sectors, uint8_t *buf, int msf, int start_track);
 int cdrom_read_toc_raw(int nb_sectors, uint8_t *buf, int msf, int session_num);
 
+/* scsi-bus.c */
+typedef void (*scsi_qdev_initfn)(SCSIDevice *dev);
+typedef struct {
+    DeviceInfo qdev;
+    scsi_qdev_initfn init;
+} SCSIDeviceInfo;
+
+typedef void (*SCSIAttachFn)(DeviceState *host, BlockDriverState *bdrv,
+              int unit);
+SCSIBus *scsi_bus_new(DeviceState *host, SCSIAttachFn attach);
+void scsi_bus_attach_cmdline(SCSIBus *bus);
+void scsi_qdev_register(SCSIDeviceInfo *info);
+SCSIDevice *scsi_create_simple(SCSIBus *bus, const char *name);
+
 #endif
diff --git a/hw/scsi-generic.c b/hw/scsi-generic.c
index c827c04..022110f 100644
--- a/hw/scsi-generic.c
+++ b/hw/scsi-generic.c
@@ -17,7 +17,7 @@
 
 #ifndef __linux__
 
-SCSIDevice *scsi_generic_init(BlockDriverState *bdrv, int tcq,
+SCSIDevice *scsi_generic_init(SCSIBus *bus, BlockDriverState *bdrv, int tcq,
                               scsi_completionfn completion, void *opaque)
 {
     return NULL;
@@ -675,7 +675,7 @@ static void scsi_destroy(SCSIDevice *d)
     qemu_free(d);
 }
 
-SCSIDevice *scsi_generic_init(BlockDriverState *bdrv, int tcq,
+SCSIDevice *scsi_generic_init(SCSIBus *bus, BlockDriverState *bdrv, int tcq,
                               scsi_completionfn completion, void *opaque)
 {
     int sg_version;
@@ -730,7 +730,7 @@ SCSIDevice *scsi_generic_init(BlockDriverState *bdrv, int tcq,
 
     /* define function to manage device */
 
-    d = (SCSIDevice *)qemu_mallocz(sizeof(SCSIDevice));
+    d = scsi_create_simple(bus, "scsi-generic");
     d->state = s;
     d->destroy = scsi_destroy;
     d->send_command = scsi_send_command;
@@ -741,4 +741,22 @@ SCSIDevice *scsi_generic_init(BlockDriverState *bdrv, int tcq,
 
     return d;
 }
+
+static void scsi_generic_initfn(SCSIDevice *dev)
+{
+    /* TODO */
+}
+
+static SCSIDeviceInfo scsi_generic_info = {
+    .qdev.name = "scsi-generic",
+    .qdev.size = sizeof(SCSIDevice),
+    .init      = scsi_generic_initfn,
+};
+
+static void scsi_generic_register_devices(void)
+{
+    scsi_qdev_register(&scsi_generic_info);
+}
+device_init(scsi_generic_register_devices)
+
 #endif /* __linux__ */
diff --git a/hw/usb-msd.c b/hw/usb-msd.c
index 3a3eb4a..36872e3 100644
--- a/hw/usb-msd.c
+++ b/hw/usb-msd.c
@@ -566,7 +566,7 @@ USBDevice *usb_msd_init(const char *filename)
     snprintf(s->dev.devname, sizeof(s->dev.devname), "QEMU USB MSD(%.16s)",
              filename);
 
-    s->scsi_dev = scsi_disk_init(bdrv, 0, usb_msd_command_complete, s);
+    s->scsi_dev = scsi_disk_init(NULL, bdrv, 0, usb_msd_command_complete, s);
     usb_msd_handle_reset((USBDevice *)s);
     return (USBDevice *)s;
  fail:
-- 
1.6.2.2

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [Qemu-devel] [PATCH 4/4] qdev: hook up i440fx.
  2009-06-12  9:28 [Qemu-devel] [PATCH 0/4] qdev patches Gerd Hoffmann
                   ` (2 preceding siblings ...)
  2009-06-12  9:28 ` [Qemu-devel] [PATCH 3/4] qdev: very first cut of scsi bus support Gerd Hoffmann
@ 2009-06-12  9:28 ` Gerd Hoffmann
  3 siblings, 0 replies; 7+ messages in thread
From: Gerd Hoffmann @ 2009-06-12  9:28 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

Hook i44fx pcihost into sysbus.
Convert Host bridge and ISA bridge pci devices to qdev.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/pci_host.h |    3 ++
 hw/piix_pci.c |   93 +++++++++++++++++++++++++++++++++++++++++----------------
 2 files changed, 70 insertions(+), 26 deletions(-)

diff --git a/hw/pci_host.h b/hw/pci_host.h
index 757b0e2..48862b5 100644
--- a/hw/pci_host.h
+++ b/hw/pci_host.h
@@ -28,6 +28,8 @@
 /* debug PCI */
 //#define DEBUG_PCI
 
+#include "sysbus.h"
+
 #ifdef DEBUG_PCI
 #define PCI_DPRINTF(fmt, ...) \
 do { printf("pci_host_data: " fmt , ## __VA_ARGS__); } while (0)
@@ -36,6 +38,7 @@ do { printf("pci_host_data: " fmt , ## __VA_ARGS__); } while (0)
 #endif
 
 typedef struct {
+    SysBusDevice busdev;
     uint32_t config_reg;
     PCIBus *bus;
 } PCIHostState;
diff --git a/hw/piix_pci.c b/hw/piix_pci.c
index 914a65a..d525f8b 100644
--- a/hw/piix_pci.c
+++ b/hw/piix_pci.c
@@ -25,6 +25,7 @@
 #include "hw.h"
 #include "pc.h"
 #include "pci.h"
+#include "sysbus.h"
 
 typedef uint32_t pci_addr_t;
 #include "pci_host.h"
@@ -169,16 +170,9 @@ static int i440fx_load(QEMUFile* f, void *opaque, int version_id)
     return 0;
 }
 
-PCIBus *i440fx_init(PCIDevice **pi440fx_state, qemu_irq *pic)
+static void i440fx_pcihost_initfn(SysBusDevice *dev)
 {
-    PCIBus *b;
-    PCIDevice *d;
-    I440FXState *s;
-
-    s = qemu_mallocz(sizeof(I440FXState));
-    b = pci_register_bus(NULL, "pci", 
-                         piix3_set_irq, pci_slot_get_pirq, pic, 0, 4);
-    s->bus = b;
+    I440FXState *s = FROM_SYSBUS(I440FXState, dev);
 
     register_ioport_write(0xcf8, 4, 4, i440fx_addr_writel, s);
     register_ioport_read(0xcf8, 4, 4, i440fx_addr_readl, s);
@@ -189,10 +183,10 @@ PCIBus *i440fx_init(PCIDevice **pi440fx_state, qemu_irq *pic)
     register_ioport_read(0xcfc, 4, 1, pci_host_data_readb, s);
     register_ioport_read(0xcfc, 4, 2, pci_host_data_readw, s);
     register_ioport_read(0xcfc, 4, 4, pci_host_data_readl, s);
+}
 
-    d = pci_register_device(b, "i440FX", sizeof(PCIDevice), 0,
-                            NULL, i440fx_write_config);
-
+static void i440fx_initfn(PCIDevice *d)
+{
     pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_INTEL);
     pci_config_set_device_id(d->config, PCI_DEVICE_ID_INTEL_82441);
     d->config[0x08] = 0x02; // revision
@@ -202,7 +196,25 @@ PCIBus *i440fx_init(PCIDevice **pi440fx_state, qemu_irq *pic)
     d->config[0x72] = 0x02; /* SMRAM */
 
     register_savevm("I440FX", 0, 2, i440fx_save, i440fx_load, d);
+}
+
+PCIBus *i440fx_init(PCIDevice **pi440fx_state, qemu_irq *pic)
+{
+    DeviceState *dev;
+    PCIBus *b;
+    PCIDevice *d;
+    I440FXState *s;
+
+    dev = qdev_create(NULL, "i440FX-pcihost");
+    s = FROM_SYSBUS(I440FXState, sysbus_from_qdev(dev));
+    b = pci_register_bus(&s->busdev.qdev, "pci", 
+                         piix3_set_irq, pci_slot_get_pirq, pic, 0, 4);
+    s->bus = b;
+    qdev_init(dev);
+
+    d = pci_create_simple(b, 0, "i440FX");
     *pi440fx_state = d;
+
     return b;
 }
 
@@ -320,47 +332,76 @@ static int piix_load(QEMUFile* f, void *opaque, int version_id)
     return pci_device_load(d, f);
 }
 
-int piix3_init(PCIBus *bus, int devfn)
+static void piix3_initfn(PCIDevice *d)
 {
-    PCIDevice *d;
     uint8_t *pci_conf;
 
-    d = pci_register_device(bus, "PIIX3", sizeof(PCIDevice),
-                                    devfn, NULL, NULL);
     register_savevm("PIIX3", 0, 2, piix_save, piix_load, d);
 
-    piix3_dev = d;
     pci_conf = d->config;
-
     pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_INTEL);
     pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82371SB_0); // 82371SB PIIX3 PCI-to-ISA bridge (Step A1)
     pci_config_set_class(pci_conf, PCI_CLASS_BRIDGE_ISA);
     pci_conf[PCI_HEADER_TYPE] =
         PCI_HEADER_TYPE_NORMAL | PCI_HEADER_TYPE_MULTI_FUNCTION; // header_type = PCI_multifunction, generic
 
+    piix3_dev = d;
     piix3_reset(d);
-    return d->devfn;
 }
 
-int piix4_init(PCIBus *bus, int devfn)
+static void piix4_initfn(PCIDevice *d)
 {
-    PCIDevice *d;
     uint8_t *pci_conf;
 
-    d = pci_register_device(bus, "PIIX4", sizeof(PCIDevice),
-                                    devfn, NULL, NULL);
     register_savevm("PIIX4", 0, 2, piix_save, piix_load, d);
 
-    piix4_dev = d;
     pci_conf = d->config;
-
     pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_INTEL);
     pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82371AB_0); // 82371AB/EB/MB PIIX4 PCI-to-ISA bridge
     pci_config_set_class(pci_conf, PCI_CLASS_BRIDGE_ISA);
     pci_conf[PCI_HEADER_TYPE] =
         PCI_HEADER_TYPE_NORMAL | PCI_HEADER_TYPE_MULTI_FUNCTION; // header_type = PCI_multifunction, generic
 
-
+    piix4_dev = d;
     piix4_reset(d);
+}
+
+int piix3_init(PCIBus *bus, int devfn)
+{
+    PCIDevice *d;
+
+    d = pci_create_simple(bus, devfn, "PIIX3");
     return d->devfn;
 }
+
+int piix4_init(PCIBus *bus, int devfn)
+{
+    PCIDevice *d;
+
+    d = pci_create_simple(bus, devfn, "PIIX4");
+    return d->devfn;
+}
+
+static PCIDeviceInfo i440fx_info[] = {
+    {
+        .qdev.name    = "i440FX",
+        .qdev.size    = sizeof(PCIDevice),
+        .init         = i440fx_initfn,
+        .config_write = i440fx_write_config,
+    },{
+        .qdev.name    = "PIIX3",
+        .qdev.size    = sizeof(PCIDevice),
+        .init         = piix3_initfn,
+    },{
+        .qdev.name    = "PIIX4",
+        .qdev.size    = sizeof(PCIDevice),
+        .init         = piix4_initfn,
+    }
+};
+
+static void i440fx_register(void)
+{
+    sysbus_register_dev("i440FX-pcihost", sizeof(I440FXState), i440fx_pcihost_initfn);
+    pci_qdev_register(i440fx_info, ARRAY_SIZE(i440fx_info));
+}
+device_init(i440fx_register);
-- 
1.6.2.2

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [Qemu-devel] [PATCH 3/4] qdev: very first cut of scsi bus support.
  2009-06-12  9:28 ` [Qemu-devel] [PATCH 3/4] qdev: very first cut of scsi bus support Gerd Hoffmann
@ 2009-06-12 11:22   ` Paul Brook
  2009-06-12 14:58     ` Gerd Hoffmann
  0 siblings, 1 reply; 7+ messages in thread
From: Paul Brook @ 2009-06-12 11:22 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

On Friday 12 June 2009, Gerd Hoffmann wrote:
> +
> +    if (bus) {
> +        d = scsi_create_simple(bus, "scsi-disk");
> +    } else {
> +        /* temporary until usb is qdev-ified */
> +        d = (SCSIDevice *)qemu_mallocz(sizeof(SCSIDevice));

>+static void scsi_disk_initfn(SCSIDevice *dev)
>+{
>+    /* TODO */
>+}

These are both fairly good indicators that this patch is nowhere near ready 
for integration. The whole point of the qdev API is to abstract device 
creation from individual device implementation details. Your implementation 
has the abstraction layers completely backwards.

The I2C code is an example of how a secondary bus should work.

Paul

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Qemu-devel] [PATCH 3/4] qdev: very first cut of scsi bus support.
  2009-06-12 11:22   ` Paul Brook
@ 2009-06-12 14:58     ` Gerd Hoffmann
  0 siblings, 0 replies; 7+ messages in thread
From: Gerd Hoffmann @ 2009-06-12 14:58 UTC (permalink / raw)
  To: Paul Brook; +Cc: qemu-devel

On 06/12/09 13:22, Paul Brook wrote:
> On Friday 12 June 2009, Gerd Hoffmann wrote:
>> +
>> +    if (bus) {
>> +        d = scsi_create_simple(bus, "scsi-disk");
>> +    } else {
>> +        /* temporary until usb is qdev-ified */
>> +        d = (SCSIDevice *)qemu_mallocz(sizeof(SCSIDevice));
>
>> +static void scsi_disk_initfn(SCSIDevice *dev)
>> +{
>> +    /* TODO */
>> +}
>
> These are both fairly good indicators that this patch is nowhere near ready
> for integration. The whole point of the qdev API is to abstract device
> creation from individual device implementation details.

I know.  It is tagged "very first cut" for a reason ;)
Just skip it for now if you prefer to wait for something more complete.

> Your implementation
> has the abstraction layers completely backwards.

Yes, but this is how it works in qemu today.
Changing that without breaking stuff isn't that easy though.
Guess I'll first have a look at usb anyway, so I can make sure 
usb-storage is covered too.

cheers,
   Gerd

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2009-06-12 15:01 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-12  9:28 [Qemu-devel] [PATCH 0/4] qdev patches Gerd Hoffmann
2009-06-12  9:28 ` [Qemu-devel] [PATCH 1/4] qdev: update pci device registration Gerd Hoffmann
2009-06-12  9:28 ` [Qemu-devel] [PATCH 2/4] qdev: replace bus_type enum with bus_info struct Gerd Hoffmann
2009-06-12  9:28 ` [Qemu-devel] [PATCH 3/4] qdev: very first cut of scsi bus support Gerd Hoffmann
2009-06-12 11:22   ` Paul Brook
2009-06-12 14:58     ` Gerd Hoffmann
2009-06-12  9:28 ` [Qemu-devel] [PATCH 4/4] qdev: hook up i440fx Gerd Hoffmann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.