From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MEJZC-00063j-M4 for qemu-devel@nongnu.org; Wed, 10 Jun 2009 04:53:54 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MEJZ8-00061s-Tz for qemu-devel@nongnu.org; Wed, 10 Jun 2009 04:53:54 -0400 Received: from [199.232.76.173] (port=41498 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MEJZ8-00061o-Os for qemu-devel@nongnu.org; Wed, 10 Jun 2009 04:53:50 -0400 Received: from mx2.redhat.com ([66.187.237.31]:44419) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MEJHN-00084X-1m for qemu-devel@nongnu.org; Wed, 10 Jun 2009 04:35:29 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n5A8ZS1U016608 for ; Wed, 10 Jun 2009 04:35:28 -0400 From: Gerd Hoffmann Date: Wed, 10 Jun 2009 10:35:22 +0200 Message-Id: <1244622922-21051-1-git-send-email-kraxel@redhat.com> Subject: [Qemu-devel] [PATCH] qdev: update pci device registration. List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org 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 --- 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 +++++++++++++++++++++-------- hw/xenner_platform_pci.c | 9 +++++++-- 11 files changed, 103 insertions(+), 40 deletions(-) diff --git a/hw/e1000.c b/hw/e1000.c index 2665792..cf77e0a 100644 --- a/hw/e1000.c +++ b/hw/e1000.c @@ -1116,9 +1116,15 @@ static void pci_e1000_init(PCIDevice *pci_dev) d->dev.unregister = pci_e1000_uninit; } +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 fcb091c..411daea 100644 --- a/hw/eepro100.c +++ b/hw/eepro100.c @@ -1791,14 +1791,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 2af0d10..af4eeb6 100644 --- a/hw/ne2000.c +++ b/hw/ne2000.c @@ -829,9 +829,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 2c4b3fd..f7de7f3 100644 --- a/hw/pci.c +++ b/hw/pci.c @@ -906,11 +906,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; @@ -921,23 +916,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 0405837..03e13dc 100644 --- a/hw/pci.h +++ b/hw/pci.h @@ -222,7 +222,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 c44ba7e..30b7c20 100644 --- a/hw/pcnet.c +++ b/hw/pcnet.c @@ -2140,9 +2140,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 d99f35c..a5e2f5c 100644 --- a/hw/rtl8139.c +++ b/hw/rtl8139.c @@ -3494,9 +3494,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) diff --git a/hw/xenner_platform_pci.c b/hw/xenner_platform_pci.c index 2b668c7..2df3f08 100644 --- a/hw/xenner_platform_pci.c +++ b/hw/xenner_platform_pci.c @@ -117,10 +117,15 @@ static void pci_xenner_platform_initcb(PCIDevice *pci_dev) register_savevm("xenner-platform", -1, 1, xenner_pci_save, xenner_pci_load, d); } +static PCIDeviceInfo xenner_platform_info = { + .qdev.name = "xenner-platform", + .qdev.size = sizeof(PCIXennerPlatformState), + .init = pci_xenner_platform_initcb, +}; + void pci_xenner_platform_init(PCIBus *bus) { assert(xen_mode == XEN_EMULATE); - pci_qdev_register("xenner-platform", sizeof(PCIXennerPlatformState), - pci_xenner_platform_initcb); + pci_qdev_register(&xenner_platform_info, 1); pci_create_simple(bus, -1, "xenner-platform"); } -- 1.6.2.2