qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 2/8] qdev/pci: make pci_create return DeviceState in


From: Gerd Hoffmann
Subject: [Qemu-devel] [PATCH 2/8] qdev/pci: make pci_create return DeviceState instead of PCIDevice.
Date: Wed, 1 Jul 2009 10:57:14 +0200

Rationale: wanna use it as callback in qdev code.

Signed-off-by: Gerd Hoffmann <address@hidden>
---
 hw/pc.c                |   12 ++++++------
 hw/pci-hotplug.c       |    6 +++---
 hw/pci.c               |   10 ++++------
 hw/pci.h               |    2 +-
 hw/ppc440_bamboo.c     |    6 +++---
 hw/ppce500_mpc8544ds.c |    6 +++---
 6 files changed, 20 insertions(+), 22 deletions(-)

diff --git a/hw/pc.c b/hw/pc.c
index bdcec52..2b89356 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -1094,7 +1094,7 @@ static void pc_init1(ram_addr_t ram_size,
     ram_addr_t below_4g_mem_size, above_4g_mem_size = 0;
     int bios_size, isa_bios_size, oprom_area_size;
     PCIBus *pci_bus;
-    PCIDevice *pci_dev;
+    DeviceState *qdev;
     int piix3_devfn = -1;
     CPUState *env;
     qemu_irq *cpu_irq;
@@ -1400,17 +1400,17 @@ static void pc_init1(ram_addr_t ram_size,
         int unit_id = 0;
 
         while ((index = drive_get_index(IF_VIRTIO, 0, unit_id)) != -1) {
-            pci_dev = pci_create("virtio-blk-pci",
-                                 drives_table[index].devaddr);
-            qdev_init(&pci_dev->qdev);
+            qdev = pci_create("virtio-blk-pci",
+                              drives_table[index].devaddr);
+            qdev_init(qdev);
             unit_id++;
         }
     }
 
     /* Add virtio balloon device */
     if (pci_enabled && virtio_balloon) {
-        pci_dev = pci_create("virtio-balloon-pci", virtio_balloon_devaddr);
-        qdev_init(&pci_dev->qdev);
+        qdev = pci_create("virtio-balloon-pci", virtio_balloon_devaddr);
+        qdev_init(qdev);
     }
 
     /* Add virtio console devices */
diff --git a/hw/pci-hotplug.c b/hw/pci-hotplug.c
index d0f2911..0781b52 100644
--- a/hw/pci-hotplug.c
+++ b/hw/pci-hotplug.c
@@ -97,7 +97,7 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon,
                                            const char *devaddr,
                                            const char *opts)
 {
-    PCIDevice *dev;
+    DeviceState *dev;
     int type = -1, drive_idx = -1;
     char buf[128];
 
@@ -139,8 +139,8 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon,
         dev = NULL;
     }
     if (dev)
-        qdev_init(&dev->qdev);
-    return dev;
+        qdev_init(dev);
+    return DO_UPCAST(PCIDevice, qdev, dev);
 }
 
 void pci_device_hot_add(Monitor *mon, const char *pci_addr, const char *type,
diff --git a/hw/pci.c b/hw/pci.c
index 0952d9b..3c20aa2 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -763,7 +763,7 @@ void pci_info(Monitor *mon)
     pci_for_each_device(0, pci_info_device);
 }
 
-PCIDevice *pci_create(const char *name, const char *devaddr)
+DeviceState *pci_create(const char *name, const char *devaddr)
 {
     PCIBus *bus;
     int devfn;
@@ -778,7 +778,7 @@ PCIDevice *pci_create(const char *name, const char *devaddr)
 
     dev = qdev_create(&bus->qbus, name);
     qdev_prop_set_uint32(dev, "devfn", devfn);
-    return (PCIDevice *)dev;
+    return dev;
 }
 
 static const char * const pci_nic_models[] = {
@@ -810,7 +810,6 @@ PCIDevice *pci_nic_init(NICInfo *nd, const char 
*default_model,
                         const char *default_devaddr)
 {
     const char *devaddr = nd->devaddr ? nd->devaddr : default_devaddr;
-    PCIDevice *pci_dev;
     DeviceState *dev;
     int i;
 
@@ -818,12 +817,11 @@ PCIDevice *pci_nic_init(NICInfo *nd, const char 
*default_model,
 
     for (i = 0; pci_nic_models[i]; i++) {
         if (strcmp(nd->model, pci_nic_models[i]) == 0) {
-            pci_dev = pci_create(pci_nic_names[i], devaddr);
-            dev = &pci_dev->qdev;
+            dev = pci_create(pci_nic_names[i], devaddr);
             dev->nd = nd;
             qdev_init(dev);
             nd->private = dev;
-            return pci_dev;
+            return DO_UPCAST(PCIDevice, qdev, dev);
         }
     }
 
diff --git a/hw/pci.h b/hw/pci.h
index cbfea6a..17563ed 100644
--- a/hw/pci.h
+++ b/hw/pci.h
@@ -324,7 +324,7 @@ typedef struct {
 void pci_qdev_register(PCIDeviceInfo *info);
 void pci_qdev_register_many(PCIDeviceInfo *info);
 
-PCIDevice *pci_create(const char *name, const char *devaddr);
+DeviceState *pci_create(const char *name, const char *devaddr);
 PCIDevice *pci_create_simple(PCIBus *bus, int devfn, const char *name);
 
 /* lsi53c895a.c */
diff --git a/hw/ppc440_bamboo.c b/hw/ppc440_bamboo.c
index d9ef3ec..b6b8f8a 100644
--- a/hw/ppc440_bamboo.c
+++ b/hw/ppc440_bamboo.c
@@ -90,7 +90,7 @@ static void bamboo_init(ram_addr_t ram_size,
 {
     unsigned int pci_irq_nrs[4] = { 28, 27, 26, 25 };
     PCIBus *pcibus;
-    PCIDevice *pci_dev;
+    DeviceState *qdev;
     CPUState *env;
     uint64_t elf_entry;
     uint64_t elf_lowaddr;
@@ -111,8 +111,8 @@ static void bamboo_init(ram_addr_t ram_size,
 
         /* Add virtio block devices. */
         while ((i = drive_get_index(IF_VIRTIO, 0, unit_id)) != -1) {
-            pci_dev = pci_create("virtio-blk-pci", drives_table[i].devaddr);
-            qdev_init(&pci_dev->qdev);
+            qdev = pci_create("virtio-blk-pci", drives_table[i].devaddr);
+            qdev_init(qdev);
             unit_id++;
         }
 
diff --git a/hw/ppce500_mpc8544ds.c b/hw/ppce500_mpc8544ds.c
index c0e367d..d21eb95 100644
--- a/hw/ppce500_mpc8544ds.c
+++ b/hw/ppce500_mpc8544ds.c
@@ -157,7 +157,7 @@ static void mpc8544ds_init(ram_addr_t ram_size,
                          const char *cpu_model)
 {
     PCIBus *pci_bus;
-    PCIDevice *pci_dev;
+    DeviceState *qdev;
     CPUState *env;
     uint64_t elf_entry;
     uint64_t elf_lowaddr;
@@ -220,8 +220,8 @@ static void mpc8544ds_init(ram_addr_t ram_size,
 
         /* Add virtio block devices. */
         while ((i = drive_get_index(IF_VIRTIO, 0, unit_id)) != -1) {
-            pci_dev = pci_create("virtio-blk-pci", drives_table[i].devaddr);
-            qdev_init(&pci_dev->qdev);
+            qdev = pci_create("virtio-blk-pci", drives_table[i].devaddr);
+            qdev_init(qdev);
             unit_id++;
         }
 
-- 
1.6.2.5





reply via email to

[Prev in Thread] Current Thread [Next in Thread]