qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Gerd Hoffmann <kraxel@redhat.com>
To: Avi Kivity <avi@redhat.com>
Cc: Paul Brook <paul@codesourcery.com>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] Re: [PATCH 0/10] qdev patches.
Date: Mon, 22 Jun 2009 13:25:40 +0200	[thread overview]
Message-ID: <4A3F6A34.5050109@redhat.com> (raw)
In-Reply-To: <4A3F5583.90700@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 454 bytes --]

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

[-- Attachment #2: rfc.diff --]
[-- Type: text/plain, Size: 8478 bytes --]

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);

  reply	other threads:[~2009-06-22 11:27 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-17 12:59 [Qemu-devel] [PATCH 0/10] qdev patches Gerd Hoffmann
2009-06-17 12:59 ` [Qemu-devel] [PATCH 01/10] qdev: update pci device registration Gerd Hoffmann
2009-06-17 12:59 ` [Qemu-devel] [PATCH 02/10] qdev: replace bus_type enum with bus_info struct Gerd Hoffmann
2009-06-17 12:59 ` [Qemu-devel] [PATCH 03/10] qdev: remove DeviceType Gerd Hoffmann
2009-06-17 12:59 ` [Qemu-devel] [PATCH 04/10] qdev/pci: bus name Gerd Hoffmann
2009-06-17 12:59 ` [Qemu-devel] [PATCH 05/10] qdev: hook up i440fx Gerd Hoffmann
2009-06-17 12:59 ` [Qemu-devel] [PATCH 06/10] qdev: convert piix-ide, first step Gerd Hoffmann
2009-06-17 12:59 ` [Qemu-devel] [PATCH 07/10] qdev-ify: piix acpi Gerd Hoffmann
2009-06-17 12:59 ` [Qemu-devel] [PATCH 08/10] qdev-ify: uhci Gerd Hoffmann
2009-06-17 12:59 ` [Qemu-devel] [PATCH 09/10] qdev-ify: usb Gerd Hoffmann
2009-06-17 12:59 ` [Qemu-devel] [PATCH 10/10] qdev-ify: scsi Gerd Hoffmann
2009-06-18 14:39 ` [Qemu-devel] Re: [PATCH 0/10] qdev patches Gerd Hoffmann
2009-06-19 15:59   ` Gerd Hoffmann
2009-06-19 17:51     ` Paul Brook
2009-06-22  9:15       ` Gerd Hoffmann
2009-06-22  9:36         ` Avi Kivity
2009-06-22  9:57           ` Gerd Hoffmann
2009-06-22 11:25             ` Gerd Hoffmann [this message]
2009-06-22 11:29               ` Avi Kivity
2009-06-22 14:02         ` Gerd Hoffmann
2009-06-22 13:45       ` Gerd Hoffmann
2009-06-19 16:26 ` [Qemu-devel] " Paul Brook
2009-06-26 21:16   ` Markus Armbruster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4A3F6A34.5050109@redhat.com \
    --to=kraxel@redhat.com \
    --cc=avi@redhat.com \
    --cc=paul@codesourcery.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).