From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MIhgn-0008PG-Bx for qemu-devel@nongnu.org; Mon, 22 Jun 2009 07:27:53 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MIhgi-0008OA-JD for qemu-devel@nongnu.org; Mon, 22 Jun 2009 07:27:52 -0400 Received: from [199.232.76.173] (port=37621 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MIhgi-0008O5-9f for qemu-devel@nongnu.org; Mon, 22 Jun 2009 07:27:48 -0400 Received: from mx2.redhat.com ([66.187.237.31]:38115) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MIhgh-0005zm-I0 for qemu-devel@nongnu.org; Mon, 22 Jun 2009 07:27:48 -0400 Message-ID: <4A3F6A34.5050109@redhat.com> Date: Mon, 22 Jun 2009 13:25:40 +0200 From: Gerd Hoffmann MIME-Version: 1.0 Subject: Re: [Qemu-devel] Re: [PATCH 0/10] qdev patches. References: <1245243565-24807-1-git-send-email-kraxel@redhat.com> <4A3A51B9.90207@redhat.com> <4A3BB5F2.9050701@redhat.com> <200906191851.21563.paul@codesourcery.com> <4A3F4BB9.6060604@redhat.com> <4A3F50BA.2030103@redhat.com> <4A3F5583.90700@redhat.com> In-Reply-To: <4A3F5583.90700@redhat.com> Content-Type: multipart/mixed; boundary="------------080909090505070605050906" List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Avi Kivity Cc: Paul Brook , qemu-devel@nongnu.org This is a multi-part message in MIME format. --------------080909090505070605050906 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit On 06/22/09 11:57, Gerd Hoffmann wrote: > On 06/22/09 11:36, Avi Kivity wrote: >> There's a third alternative, zero terminating the array. >> >> If most calls register one qdev, I'd prefer pci_qdev_register() and >> pci_qdev_register_many(). > > Where register() takes a single instance and register_many() a > zero-terminated array I guess? Sounds good. i.e. something like the attached patch (incremental to the whole patch series). cheers, Gerd --------------080909090505070605050906 Content-Type: text/plain; name="rfc.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="rfc.diff" diff --git a/hw/ac97.c b/hw/ac97.c index bcd5ce1..6ae1524 100644 --- a/hw/ac97.c +++ b/hw/ac97.c @@ -1373,7 +1373,7 @@ static PCIDeviceInfo ac97_info = { static void ac97_register(void) { - pci_qdev_register(&ac97_info, 1); + pci_qdev_register(&ac97_info); } device_init(ac97_register); diff --git a/hw/acpi.c b/hw/acpi.c index 6b627cb..7562ef3 100644 --- a/hw/acpi.c +++ b/hw/acpi.c @@ -573,7 +573,7 @@ static PCIDeviceInfo acpi_info = { static void acpi_register(void) { - pci_qdev_register(&acpi_info, 1); + pci_qdev_register(&acpi_info); } device_init(acpi_register); diff --git a/hw/cirrus_vga.c b/hw/cirrus_vga.c index 065545e..19d3fd9 100644 --- a/hw/cirrus_vga.c +++ b/hw/cirrus_vga.c @@ -3350,6 +3350,6 @@ static PCIDeviceInfo cirrus_vga_info = { static void cirrus_vga_register(void) { - pci_qdev_register(&cirrus_vga_info, 1); + pci_qdev_register(&cirrus_vga_info); } device_init(cirrus_vga_register); diff --git a/hw/e1000.c b/hw/e1000.c index 2a9d3d7..9276968 100644 --- a/hw/e1000.c +++ b/hw/e1000.c @@ -1133,7 +1133,7 @@ static PCIDeviceInfo e1000_info = { static void e1000_register_devices(void) { - pci_qdev_register(&e1000_info, 1); + pci_qdev_register(&e1000_info); } device_init(e1000_register_devices) diff --git a/hw/eepro100.c b/hw/eepro100.c index df08826..d406716 100644 --- a/hw/eepro100.c +++ b/hw/eepro100.c @@ -1805,12 +1805,14 @@ static PCIDeviceInfo eepro100_info[] = { .qdev.name = "i82559er", .qdev.size = sizeof(PCIEEPRO100State), .init = pci_i82559er_init, + },{ + /* end of list */ } }; static void eepro100_register_devices(void) { - pci_qdev_register(eepro100_info, ARRAY_SIZE(eepro100_info)); + pci_qdev_register_many(eepro100_info); } device_init(eepro100_register_devices) diff --git a/hw/es1370.c b/hw/es1370.c index 6bc345d..ec1e540 100644 --- a/hw/es1370.c +++ b/hw/es1370.c @@ -1060,7 +1060,7 @@ static PCIDeviceInfo es1370_info = { static void es1370_register(void) { - pci_qdev_register(&es1370_info, 1); + pci_qdev_register(&es1370_info); } device_init(es1370_register); diff --git a/hw/ide.c b/hw/ide.c index 23f213d..3bc75fa 100644 --- a/hw/ide.c +++ b/hw/ide.c @@ -3456,12 +3456,14 @@ static PCIDeviceInfo piix_ide_info[] = { .qdev.name = "PIIX4 IDE", .qdev.size = sizeof(PCIIDEState), .init = pci_piix4_ide_initfn, + },{ + /* end of list */ } }; static void piix_ide_register(void) { - pci_qdev_register(piix_ide_info, ARRAY_SIZE(piix_ide_info)); + pci_qdev_register_many(piix_ide_info); } device_init(piix_ide_register); diff --git a/hw/lsi53c895a.c b/hw/lsi53c895a.c index 8c48e02..1c3d698 100644 --- a/hw/lsi53c895a.c +++ b/hw/lsi53c895a.c @@ -2046,7 +2046,7 @@ static PCIDeviceInfo lsi_info = { static void lsi53c895a_register_devices(void) { - pci_qdev_register(&lsi_info, 1); + pci_qdev_register(&lsi_info); } device_init(lsi53c895a_register_devices); diff --git a/hw/ne2000.c b/hw/ne2000.c index cff6053..66ff29d 100644 --- a/hw/ne2000.c +++ b/hw/ne2000.c @@ -840,7 +840,7 @@ static PCIDeviceInfo ne2000_info = { static void ne2000_register_devices(void) { - pci_qdev_register(&ne2000_info, 1); + pci_qdev_register(&ne2000_info); } device_init(ne2000_register_devices) diff --git a/hw/pci.c b/hw/pci.c index 30cd304..f13b6aa 100644 --- a/hw/pci.c +++ b/hw/pci.c @@ -921,14 +921,18 @@ static void pci_qdev_init(DeviceState *qdev, DeviceInfo *base) info->init(pci_dev); } -void pci_qdev_register(PCIDeviceInfo *info, int count) +void pci_qdev_register(PCIDeviceInfo *info) { - int i; + info->qdev.init = pci_qdev_init; + info->qdev.bus_info = &pci_bus_info; + qdev_register(&info->qdev); +} - for (i = 0; i < count; i++, info++) { - info->qdev.init = pci_qdev_init; - info->qdev.bus_info = &pci_bus_info; - qdev_register(&info->qdev); +void pci_qdev_register_many(PCIDeviceInfo *info) +{ + while (info->qdev.name) { + pci_qdev_register(info); + info++; } } diff --git a/hw/pci.h b/hw/pci.h index ba41867..5f7b301 100644 --- a/hw/pci.h +++ b/hw/pci.h @@ -225,7 +225,8 @@ typedef struct { PCIConfigWriteFunc *config_write; } PCIDeviceInfo; -void pci_qdev_register(PCIDeviceInfo *info, int count); +void pci_qdev_register(PCIDeviceInfo *info); +void pci_qdev_register_many(PCIDeviceInfo *info); PCIDevice *pci_create_simple(PCIBus *bus, int devfn, const char *name); diff --git a/hw/pcnet.c b/hw/pcnet.c index 0e63d1b..4519780 100644 --- a/hw/pcnet.c +++ b/hw/pcnet.c @@ -2151,7 +2151,7 @@ static PCIDeviceInfo pcnet_info = { static void pcnet_register_devices(void) { - pci_qdev_register(&pcnet_info, 1); + pci_qdev_register(&pcnet_info); #if defined (TARGET_SPARC) && !defined(TARGET_SPARC64) sysbus_register_dev("lance", sizeof(SysBusPCNetState), lance_init); #endif diff --git a/hw/piix_pci.c b/hw/piix_pci.c index cd63bf4..1cbc5c3 100644 --- a/hw/piix_pci.c +++ b/hw/piix_pci.c @@ -404,12 +404,14 @@ static PCIDeviceInfo i440fx_info[] = { .qdev.name = "PIIX4", .qdev.size = sizeof(PCIDevice), .init = piix4_initfn, + },{ + /* end of list */ } }; static void i440fx_register(void) { sysbus_register_dev("i440FX-pcihost", sizeof(I440FXState), i440fx_pcihost_initfn); - pci_qdev_register(i440fx_info, ARRAY_SIZE(i440fx_info)); + pci_qdev_register_many(i440fx_info); } device_init(i440fx_register); diff --git a/hw/rtl8139.c b/hw/rtl8139.c index 5e4ae8f..4ce7cb6 100644 --- a/hw/rtl8139.c +++ b/hw/rtl8139.c @@ -3507,7 +3507,7 @@ static PCIDeviceInfo rtl8139_info = { static void rtl8139_register_devices(void) { - pci_qdev_register(&rtl8139_info, 1); + pci_qdev_register(&rtl8139_info); } device_init(rtl8139_register_devices) diff --git a/hw/usb-ohci.c b/hw/usb-ohci.c index d2c8759..613104d 100644 --- a/hw/usb-ohci.c +++ b/hw/usb-ohci.c @@ -1771,6 +1771,6 @@ static PCIDeviceInfo ohci_info = { static void ohci_register(void) { - pci_qdev_register(&ohci_info, 1); + pci_qdev_register(&ohci_info); } device_init(ohci_register); diff --git a/hw/usb-uhci.c b/hw/usb-uhci.c index 6674290..ef72e6f 100644 --- a/hw/usb-uhci.c +++ b/hw/usb-uhci.c @@ -1129,12 +1129,14 @@ static PCIDeviceInfo uhci_info[] = { .qdev.name = "PIIX4 USB-UHCI", .qdev.size = sizeof(UHCIState), .init = usb_uhci_piix4_initfn, + },{ + /* end of list */ } }; static void uhci_register(void) { - pci_qdev_register(uhci_info, ARRAY_SIZE(uhci_info)); + pci_qdev_register_many(uhci_info); } device_init(uhci_register); diff --git a/hw/versatile_pci.c b/hw/versatile_pci.c index 92cf1d0..5eb2625 100644 --- a/hw/versatile_pci.c +++ b/hw/versatile_pci.c @@ -164,7 +164,7 @@ 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_info, 1); + pci_qdev_register(&versatile_pci_host_info); } device_init(versatile_pci_register_devices) diff --git a/hw/vga.c b/hw/vga.c index a6056c4..063fa5f 100644 --- a/hw/vga.c +++ b/hw/vga.c @@ -2538,7 +2538,7 @@ static PCIDeviceInfo vga_info = { static void vga_register(void) { - pci_qdev_register(&vga_info, 1); + pci_qdev_register(&vga_info); } device_init(vga_register); diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c index 231cc52..56be2b3 100644 --- a/hw/virtio-pci.c +++ b/hw/virtio-pci.c @@ -351,12 +351,14 @@ static PCIDeviceInfo virtio_info[] = { .qdev.name = "virtio-balloon-pci", .qdev.size = sizeof(VirtIOPCIProxy), .init = virtio_balloon_init_pci, + },{ + /* end of list */ } }; static void virtio_pci_register_devices(void) { - pci_qdev_register(virtio_info, ARRAY_SIZE(virtio_info)); + pci_qdev_register_many(virtio_info); } device_init(virtio_pci_register_devices) diff --git a/hw/vmware_vga.c b/hw/vmware_vga.c index 7499c95..5ceebf1 100644 --- a/hw/vmware_vga.c +++ b/hw/vmware_vga.c @@ -1251,6 +1251,6 @@ static PCIDeviceInfo vmsvga_info = { static void vmsvga_register(void) { - pci_qdev_register(&vmsvga_info, 1); + pci_qdev_register(&vmsvga_info); } device_init(vmsvga_register); --------------080909090505070605050906--