Skip to contentSkip to conversation

qom: add QEMU Object Model type hierarchy to qdev

PATCH In review Anthony Liguori 13 participants 74 messages Jan 24, 2012 – Mar 6, 2012 Page 1 of 2

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v3 cover qom: add QEMU Object Model type hierarchy to qdev

This series makes qdev a proper Object and converts qdev's type inheritance to QOM inheritance.

The first half of the series are manual cleanups/refactorings. The second half is mostly scripted conversion, separated out into reviewable and bisectable chunks.

I've tested this series extensively for the pc target including bisectability. I have not tested any other targets yet so your mileage may vary.

Since the original RFC, I've fixed any of the not-for-upstream issues. This also includes some uni-north patches that are in ppc-next.

Paolo and Andreas have asked that I declare a date when I'll merge this so that people can be prepared for the rebase fall out. I will merge this on Friday unless there is a major problem found in review.

This is also available at:

https://github.com/aliguori/qemu/tree/qom-upstream.10

For full context, the whole tree is located at:

https://github.com/aliguori/qemu/commits/qom-rebase.7

git diffstat origin/master HEAD

 Makefile                   |    2 
 Makefile.hw                |    1 
 Makefile.objs              |    3 
 Makefile.target            |    2 
 configure                  |    2 
 hw/9pfs/virtio-9p-device.c |   44 ++--
 hw/a9mpcore.c              |   21 +
 hw/ac97.c                  |   39 ++-
 hw/acpi_piix4.c            |   59 +++--
 hw/ads7846.c               |   17 +
 hw/alpha_typhoon.c         |   17 +
 hw/apb_pci.c               |   71 ++++--
 hw/apic.c                  |   21 +
 hw/apic_common.c           |   88 +++++---
 hw/apic_internal.h         |   32 +-
 hw/applesmc.c              |   18 +
 hw/arm11mpcore.c           |   68 +++---
 hw/arm_l2x0.c              |   25 +-
 hw/arm_mptimer.c           |   23 +-
 hw/arm_sysctl.c            |   31 +-
 hw/arm_timer.c             |   46 +++-
 hw/armv7m.c                |   25 +-
 hw/armv7m_nvic.c           |   21 +
 hw/bitbang_i2c.c           |   17 +
 hw/bonito.c                |   47 ++--
 hw/ccid-card-emulated.c    |   27 +-
 hw/ccid-card-passthru.c    |   27 +-
 hw/ccid.h                  |   28 +-
 hw/cirrus_vga.c            |   50 ++--
 hw/container.c             |   17 +
 hw/cs4231.c                |   27 +-
 hw/cs4231a.c               |   20 +
 hw/debugcon.c              |   16 +
 hw/dec_pci.c               |   74 ++++--
 hw/ds1225y.c               |   29 +-
 hw/ds1338.c                |   31 +-
 hw/e1000.c                 |   45 ++--
 hw/eccmemctl.c             |   29 +-
 hw/eepro100.c              |  202 +++++++++++-------
 hw/empty_slot.c            |   15 +
 hw/es1370.c                |   36 +--
 hw/escc.c                  |   43 ++-
 hw/esp.c                   |   27 +-
 hw/etraxfs_eth.c           |   33 +--
 hw/etraxfs_pic.c           |   25 +-
 hw/etraxfs_ser.c           |   17 +
 hw/etraxfs_timer.c         |   16 +
 hw/fdc.c                   |   84 +++++--
 hw/fw_cfg.c                |   33 +--
 hw/g364fb.c                |   33 +--
 hw/grackle_pci.c           |   44 ++--
 hw/grlib_apbuart.c         |   25 +-
 hw/grlib_gptimer.c         |   31 +-
 hw/grlib_irqmp.c           |   29 +-
 hw/gt64xxx.c               |   39 ++-
 hw/gus.c                   |   20 +
 hw/hda-audio.c             |   60 +++--
 hw/hpet.c                  |   33 +--
 hw/i2c.c                   |  111 +++++++---
 hw/i2c.h                   |   52 ++--
 hw/i82374.c                |   19 +
 hw/i82378.c                |   31 +-
 hw/i8254.c                 |   22 +-
 hw/i8259.c                 |   15 +
 hw/i8259_common.c          |   45 ++--
 hw/i8259_internal.h        |   27 +-
 hw/ide/cmd646.c            |   41 ++-
 hw/ide/ich.c               |   37 +--
 hw/ide/internal.h          |   20 +
 hw/ide/isa.c               |   20 +
 hw/ide/piix.c              |   91 +++++---
 hw/ide/qdev.c              |  111 ++++++----
 hw/ide/via.c               |   27 +-
 hw/integratorcp.c          |   40 ++-
 hw/intel-hda.c             |   91 +++++---
 hw/intel-hda.h             |   26 +-
 hw/ioapic.c                |   17 +
 hw/ioapic_common.c         |   49 +++-
 hw/ioapic_internal.h       |   26 +-
 hw/ioh3420.c               |   59 +++--
 hw/isa-bus.c               |   57 +++--
 hw/isa.h                   |   23 +-
 hw/ivshmem.c               |   47 ++--
 hw/kvm/apic.c              |   19 +
 hw/kvm/clock.c             |   19 +
 hw/kvm/i8259.c             |   19 +
 hw/kvm/ioapic.c            |   23 +-
 hw/lan9118.c               |   31 +-
 hw/lance.c                 |   33 +--
 hw/lm32_juart.c            |   19 +
 hw/lm32_pic.c              |   19 +
 hw/lm32_sys.c              |   29 +-
 hw/lm32_timer.c            |   31 +-
 hw/lm32_uart.c             |   19 +
 hw/lm832x.c                |   33 +--
 hw/lsi53c895a.c            |   33 +--
 hw/m48t59.c                |   51 +++-
 hw/macio.c                 |   50 +++-
 hw/marvell_88w8618_audio.c |   35 +--
 hw/max111x.c               |   34 ++-
 hw/max7310.c               |   35 +--
 hw/mc146818rtc.c           |   22 +-
 hw/milkymist-ac97.c        |   19 +
 hw/milkymist-hpdmc.c       |   19 +
 hw/milkymist-memcard.c     |   19 +
 hw/milkymist-minimac2.c    |   37 ++-
 hw/milkymist-pfpu.c        |   19 +
 hw/milkymist-softusb.c     |   43 ++-
 hw/milkymist-sysctl.c      |   43 ++-
 hw/milkymist-tmu2.c        |   19 +
 hw/milkymist-uart.c        |   19 +
 hw/milkymist-vgafb.c       |   31 +-
 hw/mips_malta.c            |   19 +
 hw/mipsnet.c               |   33 +--
 hw/mpc8544_guts.c          |   15 +
 hw/mst_fpga.c              |   19 +
 hw/musicpal.c              |  153 ++++++++++----
 hw/nand.c                  |   33 +--
 hw/ne2000-isa.c            |   18 +
 hw/ne2000.c                |   37 ++-
 hw/omap_gpio.c             |   70 ++++--
 hw/omap_intc.c             |   62 +++--
 hw/onenand.c               |   35 ++-
 hw/opencores_eth.c         |   31 +-
 hw/openpic.c               |   30 --
 hw/openpic.h               |    2 
 hw/parallel.c              |   16 +
 hw/pc.c                    |   20 +
 hw/pci.c                   |  140 +++++-------
 hw/pci.h                   |   80 +++----
 hw/pci_bridge.c            |    2 
 hw/pcie.c                  |    2 
 hw/pckbd.c                 |   18 +
 hw/pcnet-pci.c             |   39 ++-
 hw/pcnet.c                 |    2 
 hw/piix4.c                 |   35 +--
 hw/piix_pci.c              |  126 +++++++----
 hw/pl011.c                 |   36 ++-
 hw/pl022.c                 |   15 +
 hw/pl031.c                 |   19 +
 hw/pl041.c                 |   34 +--
 hw/pl050.c                 |   34 ++-
 hw/pl061.c                 |   34 ++-
 hw/pl080.c                 |   38 ++-
 hw/pl110.c                 |   57 +++--
 hw/pl181.c                 |   23 +-
 hw/pl190.c                 |   21 +
 hw/ppc4xx_pci.c            |   38 ++-
 hw/ppc_newworld.c          |    2 
 hw/ppce500_pci.c           |   38 ++-
 hw/ppce500_spin.c          |   15 +
 hw/prep_pci.c              |   52 ++--
 hw/pxa2xx.c                |   96 ++++++--
 hw/pxa2xx_dma.c            |   29 +-
 hw/pxa2xx_gpio.c           |   29 +-
 hw/pxa2xx_pic.c            |   19 +
 hw/pxa2xx_timer.c          |   66 +++---
 hw/qdev-properties.c       |   20 -
 hw/qdev.c                  |  123 ++++++++---
 hw/qdev.h                  |   40 +++
 hw/qxl.c                   |   66 +++---
 hw/realview.c              |   15 +
 hw/realview_gic.c          |   16 +
 hw/rtl8139.c               |   43 ++-
 hw/s390-virtio-bus.c       |  110 +++++++---
 hw/sb16.c                  |   20 +
 hw/sbi.c                   |   19 +
 hw/scsi-bus.c              |   95 ++++++--
 hw/scsi-disk.c             |  159 ++++++++------
 hw/scsi-generic.c          |   29 +-
 hw/scsi.h                  |   31 +-
 hw/serial.c                |   18 +
 hw/sga.c                   |   15 -
 hw/sh_pci.c                |   37 ++-
 hw/slavio_intctl.c         |   19 +
 hw/slavio_misc.c           |   34 ++-
 hw/slavio_timer.c          |   29 +-
 hw/smbus.c                 |   85 +++++--
 hw/smbus.h                 |   42 ++-
 hw/smbus_eeprom.c          |   27 +-
 hw/smc91c111.c             |   31 +-
 hw/spapr_llan.c            |   41 ++-
 hw/spapr_pci.c             |   31 ++
 hw/spapr_vio.c             |   72 ++++--
 hw/spapr_vio.h             |   35 ++-
 hw/spapr_vscsi.c           |   37 ++-
 hw/spapr_vty.c             |   37 ++-
 hw/sparc32_dma.c           |   31 +-
 hw/spitz.c                 |   94 +++++---
 hw/ssd0303.c               |   33 +--
 hw/ssd0323.c               |   17 +
 hw/ssi-sd.c                |   17 +
 hw/ssi.c                   |   23 +-
 hw/ssi.h                   |   18 +
 hw/stellaris.c             |   65 +++++-
 hw/stellaris_enet.c        |   27 +-
 hw/strongarm.c             |  124 +++++++----
 hw/sun4c_intctl.c          |   19 +
 hw/sun4m.c                 |   78 +++++--
 hw/sun4m_iommu.c           |   29 +-
 hw/sun4u.c                 |   71 ++++--
 hw/sysbus.c                |   40 ++-
 hw/sysbus.h                |   25 +-
 hw/tcx.c                   |   37 ++-
 hw/tmp105.c                |   37 ++-
 hw/tosa.c                  |   50 ++--
 hw/tusb6010.c              |   17 +
 hw/twl92230.c              |   35 +--
 hw/unin_pci.c              |  204 +++++++++++++-----
 hw/usb-audio.c             |   38 ++-
 hw/usb-bt.c                |   33 +--
 hw/usb-bus.c               |  190 +++++++++++++----
 hw/usb-ccid.c              |  114 +++++++---
 hw/usb-desc.c              |   22 +-
 hw/usb-ehci.c              |   63 +++--
 hw/usb-hid.c               |  108 +++++-----
 hw/usb-hub.c               |   35 +--
 hw/usb-msd.c               |   41 ++-
 hw/usb-net.c               |   43 ++-
 hw/usb-ohci.c              |   58 +++--
 hw/usb-serial.c            |   74 +++---
 hw/usb-uhci.c              |  189 +++++++++++------
 hw/usb-wacom.c             |   36 +--
 hw/usb-xhci.c              |   37 ++-
 hw/usb.c                   |   24 --
 hw/usb.h                   |   50 +++-
 hw/versatile_pci.c         |   53 +++-
 hw/versatilepb.c           |   19 +
 hw/vga-isa.c               |   18 +
 hw/vga-pci.c               |   27 +-
 hw/virtio-console.c        |   69 +++---
 hw/virtio-net.c            |    2 
 hw/virtio-pci.c            |  210 +++++++++++--------
 hw/virtio-serial-bus.c     |   68 +++---
 hw/virtio-serial.h         |   81 ++++---
 hw/vmmouse.c               |   22 +-
 hw/vmport.c                |   16 +
 hw/vmware_vga.c            |   34 +--
 hw/vt82c686.c              |  120 ++++++-----
 hw/wdt_i6300esb.c          |   33 +--
 hw/wdt_ib700.c             |   18 +
 hw/wm8750.c                |   37 ++-
 hw/xen_platform.c          |   34 +--
 hw/xilinx_axidma.c         |   27 +-
 hw/xilinx_axienet.c        |   35 ++-
 hw/xilinx_ethlite.c        |   31 +-
 hw/xilinx_intc.c           |   25 +-
 hw/xilinx_timer.c          |   27 +-
 hw/xilinx_uartlite.c       |   16 +
 hw/xio3130_downstream.c    |   59 +++--
 hw/xio3130_upstream.c      |   53 ++--
 hw/z2.c                    |   52 +++-
 hw/zaurus.c                |   27 +-
 include/qemu/object.h      |  436 ++++++++++++++++++++++++++++++++++++++++
 qom/Makefile               |    1 
 qom/object.c               |  485 +++++++++++++++++++++++++++++++++++++++++++++
 usb-bsd.c                  |   29 +-
 usb-linux.c                |   37 +--
 usb-redir.c                |   33 +--
 259 files changed, 7764 insertions(+), 3755 deletions(-)
#1 lore raw

PATCH v3 1/28 macio: convert to qdev

This is a "shallow", half hearted, and untested conversion.

---
 hw/macio.c |   43 ++++++++++++++++++++++++++++++-------------
 1 files changed, 30 insertions(+), 13 deletions(-)
hw/macio.c +30 -13
index cc6ae40..357e0ea 100644
@@ -27,8 +27,9 @@
 #include "pci.h"
 #include "escc.h"
 
-typedef struct macio_state_t macio_state_t;
-struct macio_state_t {
+typedef struct MacIOState
+{
+    PCIDevice parent;
     int is_oldworld;
     MemoryRegion bar;
     MemoryRegion *pic_mem;
@@ -38,9 +39,9 @@ struct macio_state_t {
     void *nvram;
     int nb_ide;
     MemoryRegion *ide_mem[4];
-};
+} MacIOState;
 
-static void macio_bar_setup(macio_state_t *macio_state)
+static void macio_bar_setup(MacIOState *macio_state)
 {
     int i;
     MemoryRegion *bar = &macio_state->bar;
@@ -74,6 +75,27 @@ static void macio_bar_setup(macio_state_t *macio_state)
         macio_nvram_setup_bar(macio_state->nvram, bar, 0x60000);
 }
 
+static int macio_initfn(PCIDevice *d)
+{
+    d->config[0x3d] = 0x01; // interrupt on pin 1
+    return 0;
+}
+
+static PCIDeviceInfo macio_info = {
+    .qdev.name = "macio",
+    .qdev.size = sizeof(MacIOState),
+    .init = macio_initfn,
+    .vendor_id = PCI_VENDOR_ID_APPLE,
+    .class_id = PCI_CLASS_OTHERS << 8,
+};
+
+static void macio_register(void)
+{
+    pci_qdev_register(&macio_info);
+}
+
+device_init(macio_register);
+
 void macio_init (PCIBus *bus, int device_id, int is_oldworld,
                  MemoryRegion *pic_mem, MemoryRegion *dbdma_mem,
                  MemoryRegion *cuda_mem, void *nvram,
@@ -81,13 +103,12 @@ void macio_init (PCIBus *bus, int device_id, int is_oldworld,
                  MemoryRegion *escc_mem)
 {
     PCIDevice *d;
-    macio_state_t *macio_state;
+    MacIOState *macio_state;
     int i;
 
-    d = pci_register_device(bus, "macio",
-                            sizeof(PCIDevice) + sizeof(macio_state_t),
-                            -1, NULL, NULL);
-    macio_state = (macio_state_t *)(d + 1);
+    d = pci_create_simple(bus, -1, "macio");
+
+    macio_state = DO_UPCAST(MacIOState, parent, d);
     macio_state->is_oldworld = is_oldworld;
     macio_state->pic_mem = pic_mem;
     macio_state->dbdma_mem = dbdma_mem;
@@ -104,11 +125,7 @@ void macio_init (PCIBus *bus, int device_id, int is_oldworld,
     /* Note: this code is strongly inspirated from the corresponding code
        in PearPC */
 
-    pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_APPLE);
     pci_config_set_device_id(d->config, device_id);
-    pci_config_set_class(d->config, PCI_CLASS_OTHERS << 8);
-
-    d->config[0x3d] = 0x01; // interrupt on pin 1
 
     macio_bar_setup(macio_state);
     pci_register_bar(d, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, &macio_state->bar);
Signature · 1 line
1.7.4.1
#2 lore raw

PATCH 1/1 macio: Convert to qdev

From: Anthony Liguori <[email protected]>

Split macio into two PCIDevices with declarative device ID, macio-oldworld and macio-newworld. Drop is_oldworld state in favor of two separate init functions and deferred creation.

---
Anthony, I've extended and tested your patch, please consider using this version. (In that case feel free to move your Signed-off-by down.)

Alex, please ack. We could inline macio_init() and get rid of is_oldworld but would have to move MacIOState into ppc_mac.h then.

 hw/macio.c        |  114 +++++++++++++++++++++++++++++++++++++---------------
 hw/ppc_mac.h      |    8 ++--
 hw/ppc_newworld.c |    2 +-
 hw/ppc_oldworld.c |    2 +-
 4 files changed, 87 insertions(+), 39 deletions(-)
hw/macio.c +81 -33
index cc6ae40..3fb49fb 100644
@@ -27,9 +27,8 @@
 #include "pci.h"
 #include "escc.h"
 
-typedef struct macio_state_t macio_state_t;
-struct macio_state_t {
-    int is_oldworld;
+typedef struct MacIOState {
+    PCIDevice parent;
     MemoryRegion bar;
     MemoryRegion *pic_mem;
     MemoryRegion *dbdma_mem;
@@ -38,23 +37,14 @@ struct macio_state_t {
     void *nvram;
     int nb_ide;
     MemoryRegion *ide_mem[4];
-};
+} MacIOState;
 
-static void macio_bar_setup(macio_state_t *macio_state)
+static void macio_bar_setup(MacIOState *macio_state)
 {
     int i;
     MemoryRegion *bar = &macio_state->bar;
 
     memory_region_init(bar, "macio", 0x80000);
-    if (macio_state->pic_mem) {
-        if (macio_state->is_oldworld) {
-            /* Heathrow PIC */
-            memory_region_add_subregion(bar, 0x00000, macio_state->pic_mem);
-        } else {
-            /* OpenPIC */
-            memory_region_add_subregion(bar, 0x40000, macio_state->pic_mem);
-        }
-    }
     if (macio_state->dbdma_mem) {
         memory_region_add_subregion(bar, 0x08000, macio_state->dbdma_mem);
     }
@@ -70,25 +60,82 @@ static void macio_bar_setup(macio_state_t *macio_state)
                                         macio_state->ide_mem[i]);
         }
     }
-    if (macio_state->nvram != NULL)
+    if (macio_state->nvram != NULL) {
         macio_nvram_setup_bar(macio_state->nvram, bar, 0x60000);
+    }
+}
+
+static void macio_common_init(MacIOState *macio_state)
+{
+    PCIDevice *d = &macio_state->parent;
+
+    d->config[PCI_INTERRUPT_PIN] = 0x01; /* interrupt on pin 1 */
+
+    macio_bar_setup(macio_state);
+    pci_register_bar(d, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, &macio_state->bar);
+}
+
+static int macio_oldworld_initfn(PCIDevice *d)
+{
+    MacIOState *s = DO_UPCAST(MacIOState, parent, d);
+
+    macio_common_init(s);
+
+    if (s->pic_mem != NULL) {
+        /* Heathrow PIC */
+        memory_region_add_subregion(&s->bar, 0x00000, s->pic_mem);
+    }
+    return 0;
 }
 
-void macio_init (PCIBus *bus, int device_id, int is_oldworld,
-                 MemoryRegion *pic_mem, MemoryRegion *dbdma_mem,
-                 MemoryRegion *cuda_mem, void *nvram,
-                 int nb_ide, MemoryRegion **ide_mem,
-                 MemoryRegion *escc_mem)
+static int macio_newworld_initfn(PCIDevice *d)
+{
+    MacIOState *s = DO_UPCAST(MacIOState, parent, d);
+
+    macio_common_init(s);
+
+    if (s->pic_mem != NULL) {
+        /* OpenPIC */
+        memory_region_add_subregion(&s->bar, 0x40000, s->pic_mem);
+    }
+    return 0;
+}
+
+static PCIDeviceInfo macio_oldworld_info = {
+    .qdev.name = "macio-oldworld",
+    .qdev.size = sizeof(MacIOState),
+    .qdev.no_user = 1,
+    .no_hotplug = 1,
+    .init = macio_oldworld_initfn,
+    .vendor_id = PCI_VENDOR_ID_APPLE,
+    .device_id = PCI_DEVICE_ID_APPLE_343S1201,
+    .class_id = PCI_CLASS_OTHERS << 8,
+};
+
+static PCIDeviceInfo macio_newworld_info = {
+    .qdev.name = "macio-newworld",
+    .qdev.size = sizeof(MacIOState),
+    .qdev.no_user = 1,
+    .no_hotplug = 1,
+    .init = macio_newworld_initfn,
+    .vendor_id = PCI_VENDOR_ID_APPLE,
+    .device_id = PCI_DEVICE_ID_APPLE_UNI_N_KEYL,
+    .class_id = PCI_CLASS_OTHERS << 8,
+};
+
+void macio_init(PCIBus *bus, bool is_oldworld,
+                MemoryRegion *pic_mem, MemoryRegion *dbdma_mem,
+                MemoryRegion *cuda_mem, void *nvram,
+                int nb_ide, MemoryRegion **ide_mem,
+                MemoryRegion *escc_mem)
 {
     PCIDevice *d;
-    macio_state_t *macio_state;
+    MacIOState *macio_state;
     int i;
 
-    d = pci_register_device(bus, "macio",
-                            sizeof(PCIDevice) + sizeof(macio_state_t),
-                            -1, NULL, NULL);
-    macio_state = (macio_state_t *)(d + 1);
-    macio_state->is_oldworld = is_oldworld;
+    d = pci_create(bus, -1, is_oldworld ? "macio-oldworld" : "macio-newworld");
+
+    macio_state = DO_UPCAST(MacIOState, parent, d);
     macio_state->pic_mem = pic_mem;
     macio_state->dbdma_mem = dbdma_mem;
     macio_state->cuda_mem = cuda_mem;
@@ -104,12 +151,13 @@ void macio_init (PCIBus *bus, int device_id, int is_oldworld,
     /* Note: this code is strongly inspirated from the corresponding code
        in PearPC */
 
-    pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_APPLE);
-    pci_config_set_device_id(d->config, device_id);
-    pci_config_set_class(d->config, PCI_CLASS_OTHERS << 8);
-
-    d->config[0x3d] = 0x01; // interrupt on pin 1
+    qdev_init_nofail(&d->qdev);
+}
 
-    macio_bar_setup(macio_state);
-    pci_register_bar(d, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, &macio_state->bar);
+static void macio_register(void)
+{
+    pci_qdev_register(&macio_oldworld_info);
+    pci_qdev_register(&macio_newworld_info);
 }
+
+device_init(macio_register)
hw/ppc_mac.h +4 -4
index af75e45..c165096 100644
@@ -45,10 +45,10 @@
 void cuda_init (MemoryRegion **cuda_mem, qemu_irq irq);
 
 /* MacIO */
-void macio_init (PCIBus *bus, int device_id, int is_oldworld,
-                 MemoryRegion *pic_mem, MemoryRegion *dbdma_mem,
-                 MemoryRegion *cuda_mem, void *nvram,
-                 int nb_ide, MemoryRegion **ide_mem, MemoryRegion *escc_mem);
+void macio_init(PCIBus *bus, bool is_oldworld,
+                MemoryRegion *pic_mem, MemoryRegion *dbdma_mem,
+                MemoryRegion *cuda_mem, void *nvram,
+                int nb_ide, MemoryRegion **ide_mem, MemoryRegion *escc_mem);
 
 /* Heathrow PIC */
 qemu_irq *heathrow_pic_init(MemoryRegion **pmem,
hw/ppc_newworld.c +1 -1
index a746c9c..83c09fa 100644
@@ -348,7 +348,7 @@ static void ppc_core99_init (ram_addr_t ram_size,
     adb_kbd_init(&adb_bus);
     adb_mouse_init(&adb_bus);
 
-    macio_init(pci_bus, PCI_DEVICE_ID_APPLE_UNI_N_KEYL, 0, pic_mem,
+    macio_init(pci_bus, false, pic_mem,
                dbdma_mem, cuda_mem, NULL, 3, ide_mem, escc_bar);
 
     if (usb_enabled) {
hw/ppc_oldworld.c +1 -1
index 9295a34..7a74b61 100644
@@ -274,7 +274,7 @@ static void ppc_heathrow_init (ram_addr_t ram_size,
     nvr = macio_nvram_init(0x2000, 4);
     pmac_format_nvram_partition(nvr, 0x2000);
 
-    macio_init(pci_bus, PCI_DEVICE_ID_APPLE_343S1201, 1, pic_mem,
+    macio_init(pci_bus, true, pic_mem,
                dbdma_mem, cuda_mem, nvr, 2, ide_mem, escc_bar);
 
     if (usb_enabled) {
Signature · 1 line
1.7.7
#3 lore raw

Re: [Qemu-devel] [PATCH] macio: Convert to qdev

Quoted 8 lines · Andreas Färber

From: Anthony Liguori <[email protected]>

Split macio into two PCIDevices with declarative device ID, macio-oldworld and macio-newworld. Drop is_oldworld state in favor of two separate init functions and deferred creation.

Quoted 8 lines

---
Anthony, I've extended and tested your patch, please consider using this version. (In that case feel free to move your Signed-off-by down.)

Alex, please ack. We could inline macio_init() and get rid of is_oldworld but would have to move MacIOState into ppc_mac.h then.

I don't see anything obviously wrong with the patch, but this is the type of thing that you just have to shove through testing and if it works, it works :).

Alex

#4 lore raw

PATCH v3 2/28 openpic: remove dead code to make a PCI device version

In reply to Anthony Liguori

bus is always NULL so the code in this if clause is dead (and therefore untested).

---
 hw/openpic.c      |   30 +++---------------------------
 hw/openpic.h      |    2 +-
 hw/ppc_newworld.c |    2 +-
 3 files changed, 5 insertions(+), 29 deletions(-)
hw/openpic.c +3 -27
index 22fc275..280b7a9 100644
@@ -1181,41 +1181,17 @@ static void openpic_irq_raise(openpic_t *opp, int n_CPU, IRQ_src_t *src)
     qemu_irq_raise(opp->dst[n_CPU].irqs[OPENPIC_OUTPUT_INT]);
 }
 
-qemu_irq *openpic_init (PCIBus *bus, MemoryRegion **pmem, int nb_cpus,
+qemu_irq *openpic_init (MemoryRegion **pmem, int nb_cpus,
                         qemu_irq **irqs, qemu_irq irq_out)
 {
     openpic_t *opp;
-    uint8_t *pci_conf;
     int i, m;
 
     /* XXX: for now, only one CPU is supported */
     if (nb_cpus != 1)
         return NULL;
-    if (bus) {
-        opp = (openpic_t *)pci_register_device(bus, "OpenPIC", sizeof(openpic_t),
-                                               -1, NULL, NULL);
-        pci_conf = opp->pci_dev.config;
-        pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_IBM);
-        pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_IBM_OPENPIC2);
-        pci_config_set_class(pci_conf, PCI_CLASS_SYSTEM_OTHER); // FIXME?
-        pci_conf[0x3d] = 0x00; // no interrupt pin
-
-        memory_region_init_io(&opp->mem, &openpic_ops, opp, "openpic", 0x40000);
-#if 0 // Don't implement ISU for now
-        opp_io_memory = cpu_register_io_memory(openpic_src_read,
-                                               openpic_src_write, NULL
-                                               DEVICE_NATIVE_ENDIAN);
-        cpu_register_physical_memory(isu_base, 0x20 * (EXT_IRQ + 2),
-                                     opp_io_memory);
-#endif
-
-        /* Register I/O spaces */
-        pci_register_bar(&opp->pci_dev, 0,
-                         PCI_BASE_ADDRESS_SPACE_MEMORY, &opp->mem);
-    } else {
-        opp = g_malloc0(sizeof(openpic_t));
-        memory_region_init_io(&opp->mem, &openpic_ops, opp, "openpic", 0x40000);
-    }
+    opp = g_malloc0(sizeof(openpic_t));
+    memory_region_init_io(&opp->mem, &openpic_ops, opp, "openpic", 0x40000);
 
     //    isu_base &= 0xFFFC0000;
     opp->nb_cpus = nb_cpus;
hw/openpic.h +1 -1
index 715f084..8556030 100644
@@ -11,7 +11,7 @@ enum {
     OPENPIC_OUTPUT_NB,
 };
 
-qemu_irq *openpic_init (PCIBus *bus, MemoryRegion **pmem, int nb_cpus,
+qemu_irq *openpic_init (MemoryRegion **pmem, int nb_cpus,
                         qemu_irq **irqs, qemu_irq irq_out);
 qemu_irq *mpic_init (MemoryRegion *address_space, target_phys_addr_t base,
                      int nb_cpus, qemu_irq **irqs, qemu_irq irq_out);
hw/ppc_newworld.c +1 -1
index a746c9c..506187b 100644
@@ -311,7 +311,7 @@ static void ppc_core99_init (ram_addr_t ram_size,
             exit(1);
         }
     }
-    pic = openpic_init(NULL, &pic_mem, smp_cpus, openpic_irqs, NULL);
+    pic = openpic_init(&pic_mem, smp_cpus, openpic_irqs, NULL);
     if (PPC_INPUT(env) == PPC_FLAGS_INPUT_970) {
         /* 970 gets a U3 bus */
         pci_bus = pci_pmac_u3_init(pic, get_system_memory(), get_system_io());
Signature · 1 line
1.7.4.1
Reviewed-by on v3 2/28
#5 lore raw

Re: [Qemu-devel] [PATCH 02/28] openpic: remove dead code to make a PCI device version

Am 24.01.2012 20:32, schrieb Anthony Liguori:

Quoted 15 lines

bus is always NULL so the code in this if clause is dead (and therefore untested).

---
 hw/openpic.c      |   30 +++---------------------------
 hw/openpic.h      |    2 +-
 hw/ppc_newworld.c |    2 +-
 3 files changed, 5 insertions(+), 29 deletions(-)
hw/openpic.c +0 -0
index 22fc275..280b7a9 100644

hw/openpic.c static void openpic_irq_raise(openpic_t *opp, int n_CPU, IRQ_src_t *src) · line 1185

Quoted 6 lines
hw/openpic.c +1 -1
@@ -1181,41 +1181,17 @@ static void openpic_irq_raise(openpic_t *opp, int n_CPU, IRQ_src_t *src)
     qemu_irq_raise(opp->dst[n_CPU].irqs[OPENPIC_OUTPUT_INT]);
 }
 
-qemu_irq *openpic_init (PCIBus *bus, MemoryRegion **pmem, int nb_cpus,
+qemu_irq *openpic_init (MemoryRegion **pmem, int nb_cpus,
                         qemu_irq **irqs, qemu_irq irq_out)

Here a reindentation (space) would've been nice.

Quoted 6 lines
hw/openpic.c +0 -1
 {
     openpic_t *opp;
-    uint8_t *pci_conf;
     int i, m;
 
     /* XXX: for now, only one CPU is supported */

hw/openpic.c static void openpic_irq_raise(openpic_t *opp, int n_CPU, IRQ_src_t *src) · line 1201

Quoted 10 lines
hw/openpic.c +0 -8
     if (nb_cpus != 1)
         return NULL;
-    if (bus) {
-        opp = (openpic_t *)pci_register_device(bus, "OpenPIC", sizeof(openpic_t),
-                                               -1, NULL, NULL);
-        pci_conf = opp->pci_dev.config;
-        pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_IBM);
-        pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_IBM_OPENPIC2);
-        pci_config_set_class(pci_conf, PCI_CLASS_SYSTEM_OTHER); // FIXME?
-        pci_conf[0x3d] = 0x00; // no interrupt pin

I'm not too fond of losing PCI device infos from dead code, but registering an unused PCIDeviceInfo doesn't seem right either...

AFAIU this function implements a PCI and a non-PCI version of the device. The PCI version is unused and is now being ripped out.

Quoted 8 lines
hw/openpic.c +0 -8
-
-        memory_region_init_io(&opp->mem, &openpic_ops, opp, "openpic", 0x40000);
-#if 0 // Don't implement ISU for now
-        opp_io_memory = cpu_register_io_memory(openpic_src_read,
-                                               openpic_src_write, NULL
-                                               DEVICE_NATIVE_ENDIAN);
-        cpu_register_physical_memory(isu_base, 0x20 * (EXT_IRQ + 2),
-                                     opp_io_memory);

hw/openpic.c static void openpic_irq_raise(openpic_t *opp, int n_CPU, IRQ_src_t *src) · line 1193

Quoted 10 lines
hw/openpic.c +1 -9
-#endif
-
-        /* Register I/O spaces */
-        pci_register_bar(&opp->pci_dev, 0,
-                         PCI_BASE_ADDRESS_SPACE_MEMORY, &opp->mem);
-    } else {
-        opp = g_malloc0(sizeof(openpic_t));
-        memory_region_init_io(&opp->mem, &openpic_ops, opp, "openpic", 0x40000);
-    }
+    opp = g_malloc0(sizeof(openpic_t));

Ugh. But just moved around.
(More non-qdev'ified code lurking in that file.)

Quoted 9 lines
hw/openpic.c +1 -0
+    memory_region_init_io(&opp->mem, &openpic_ops, opp, "openpic", 0x40000);
 
     //    isu_base &= 0xFFFC0000;
     opp->nb_cpus = nb_cpus;
hw/openpic.h +0 -0
index 715f084..8556030 100644

hw/openpic.h enum { · line 15

Quoted 6 lines
hw/openpic.h +1 -1
@@ -11,7 +11,7 @@ enum {
     OPENPIC_OUTPUT_NB,
 };
 
-qemu_irq *openpic_init (PCIBus *bus, MemoryRegion **pmem, int nb_cpus,
+qemu_irq *openpic_init (MemoryRegion **pmem, int nb_cpus,
                         qemu_irq **irqs, qemu_irq irq_out);

Space.

Quoted 7 lines
hw/openpic.h +0 -0
 qemu_irq *mpic_init (MemoryRegion *address_space, target_phys_addr_t base,
                      int nb_cpus, qemu_irq **irqs, qemu_irq irq_out);
hw/ppc_newworld.c +0 -0
index a746c9c..506187b 100644

hw/ppc_newworld.c static void ppc_core99_init (ram_addr_t ram_size, · line 317

Quoted 8 lines
hw/ppc_newworld.c +1 -1
@@ -311,7 +311,7 @@ static void ppc_core99_init (ram_addr_t ram_size,
             exit(1);
         }
     }
-    pic = openpic_init(NULL, &pic_mem, smp_cpus, openpic_irqs, NULL);
+    pic = openpic_init(&pic_mem, smp_cpus, openpic_irqs, NULL);
     if (PPC_INPUT(env) == PPC_FLAGS_INPUT_970) {
         /* 970 gets a U3 bus */
         pci_bus = pci_pmac_u3_init(pic, get_system_memory(), get_system_io());

Anyway, to keep moving forward,

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#6 lore raw

PATCH v3 3/28 pci: call reset unconditionally

In reply to Anthony Liguori

Because now all PCI devices are converted to qdev.

---
 hw/pci.c |    7 ++-----
 1 files changed, 2 insertions(+), 5 deletions(-)
hw/pci.c +2 -5
index 54400ac..ab3b53d 100644
@@ -159,11 +159,8 @@ void pci_device_deassert_intx(PCIDevice *dev)
 void pci_device_reset(PCIDevice *dev)
 {
     int r;
-    /* TODO: call the below unconditionally once all pci devices
-     * are qdevified */
-    if (dev->qdev.info) {
-        qdev_reset_all(&dev->qdev);
-    }
+
+    qdev_reset_all(&dev->qdev);
 
     dev->irq_state = 0;
     pci_update_irq_status(dev);
Signature · 1 line
1.7.4.1
#7 lore raw

Re: [Qemu-devel] [PATCH 03/28] pci: call reset unconditionally

Quoted 3 lines · Anthony Liguori

Because now all PCI devices are converted to qdev.

Finally!

Quoted 24 lines
---
 hw/pci.c |    7 ++-----
 1 files changed, 2 insertions(+), 5 deletions(-)
hw/pci.c +2 -5
index 54400ac..ab3b53d 100644
@@ -159,11 +159,8 @@ void pci_device_deassert_intx(PCIDevice *dev)
 void pci_device_reset(PCIDevice *dev)
 {
     int r;
-    /* TODO: call the below unconditionally once all pci devices
-     * are qdevified */
-    if (dev->qdev.info) {
-        qdev_reset_all(&dev->qdev);
-    }
+
+    qdev_reset_all(&dev->qdev);
 
     dev->irq_state = 0;
     pci_update_irq_status(dev);
Signature · 1 line
1.7.4.1
#8 lore raw

Re: [Qemu-devel] [PATCH 03/28] pci: call reset unconditionally

Quoted 6 lines · Michael S. Tsirkin
Quoted 3 lines · Anthony Liguori

Because now all PCI devices are converted to qdev.

Finally!

Yeah, I hope there's more cleanup that can come out of this.

Regards,

Anthony Liguori

Quoted 26 lines
Quoted 25 lines
---
  hw/pci.c |    7 ++-----
  1 files changed, 2 insertions(+), 5 deletions(-)
hw/pci.c +2 -6
index 54400ac..ab3b53d 100644
@@ -159,11 +159,8 @@ void pci_device_deassert_intx(PCIDevice *dev)
  void pci_device_reset(PCIDevice *dev)
  {
      int r;
-    /* TODO: call the below unconditionally once all pci devices
-     * are qdevified */
-    if (dev->qdev.info) {
-        qdev_reset_all(&dev->qdev);
-    }
+
+    qdev_reset_all(&dev->qdev);
 
      dev->irq_state = 0;
      pci_update_irq_status(dev);
--

1.7.4.1

#9 lore raw

PATCH v3 4/28 qom: add the base Object class (v2)

In reply to Anthony Liguori

This class provides the main building block for QEMU Object Model and is extensively documented in the header file. It is largely inspired by GObject.

---
v1 -> v2
- remove printf() in type registration
- fix typo in comment (Paolo)
- make Interface private
- move object into a new directory and move header into include/qemu/
- don't make object.h depend on qemu-common.h
- remove Type and replace it with TypeImpl * (Paolo)
- use hash table to store types (Paolo)
- aggressively cache parent type (Paolo)
- make a type_register and use it with interfaces (Paolo)
- fix interface cast comment (Paolo)
- add a few more functions required in later series

---
 Makefile              |    2 +
 Makefile.hw           |    1 +
 Makefile.objs         |    3 +
 Makefile.target       |    2 +
 configure             |    2 +-
 include/qemu/object.h |  436 ++++++++++++++++++++++++++++++++++++++++++++
 qom/Makefile          |    1 +
 qom/object.c          |  485 +++++++++++++++++++++++++++++++++++++++++++++++++
 8 files changed, 931 insertions(+), 1 deletions(-)
 create mode 100644 include/qemu/object.h
 create mode 100644 qom/Makefile
 create mode 100644 qom/object.c
Makefile +2 -0
index 917fb9b..d172cbf 100644
@@ -114,6 +114,8 @@ QEMU_CFLAGS+=$(CURL_CFLAGS)
 
 QEMU_CFLAGS+=$(GLIB_CFLAGS)
 
+QEMU_CFLAGS += -I$(SRC_PATH)/include
+
 ui/cocoa.o: ui/cocoa.m
 
 ui/sdl.o audio/sdlaudio.o ui/sdl_zoom.o baum.o: QEMU_CFLAGS += $(SDL_CFLAGS)
Makefile.hw +1 -0
index 63eb7e4..7b8d068 100644
@@ -11,6 +11,7 @@ $(call set-vpath, $(SRC_PATH):$(SRC_PATH)/hw)
 
 QEMU_CFLAGS+=-I..
 QEMU_CFLAGS += $(GLIB_CFLAGS)
+QEMU_CFLAGS += -I$(SRC_PATH)/include
 
 include $(SRC_PATH)/Makefile.objs
 
Makefile.objs +3 -0
index 04a1d1b..a7bd3d9 100644
@@ -122,6 +122,9 @@ common-obj-$(CONFIG_WIN32) += version.o
 
 common-obj-$(CONFIG_SPICE) += ui/spice-core.o ui/spice-input.o ui/spice-display.o spice-qemu-char.o
 
+include $(SRC_PATH)/qom/Makefile
+common-obj-y += $(addprefix qom/, $(qom-y))
+
 audio-obj-y = audio.o noaudio.o wavaudio.o mixeng.o
 audio-obj-$(CONFIG_SDL) += sdlaudio.o
 audio-obj-$(CONFIG_OSS) += ossaudio.o
Makefile.target +2 -0
index 092565a..2c763a1 100644
@@ -22,6 +22,8 @@ QEMU_CFLAGS += -I.. -I$(TARGET_PATH) -DNEED_CPU_H
 
 include $(SRC_PATH)/Makefile.objs
 
+QEMU_CFLAGS+=-I$(SRC_PATH)/include
+
 ifdef CONFIG_USER_ONLY
 # user emulator name
 QEMU_PROG=qemu-$(TARGET_ARCH2)
configure +1 -1
index 9d5175b..8f4eda0 100755
@@ -3781,7 +3781,7 @@ DIRS="$DIRS pc-bios/spapr-rtas"
 DIRS="$DIRS roms/seabios roms/vgabios"
 DIRS="$DIRS fsdev ui"
 DIRS="$DIRS qapi qapi-generated"
-DIRS="$DIRS qga trace"
+DIRS="$DIRS qga trace qom"
 FILES="Makefile tests/tcg/Makefile qdict-test-data.txt"
 FILES="$FILES tests/tcg/cris/Makefile tests/tcg/cris/.gdbinit"
 FILES="$FILES pc-bios/optionrom/Makefile pc-bios/keymaps"
include/qemu/object.h new file +436 -0

436 lines not on this page · raw message

qom/Makefile new file +1 -0
new file mode 100644
index 0000000..a3c7892
@@ -0,0 +1 @@
+qom-y = object.o
qom/object.c new file +485 -0

485 lines not on this page · raw message

Signature · 1 line
1.7.4.1
#10 lore raw

Re: [Qemu-devel] [PATCH 04/28] qom: add the base Object class (v2)

Am 24.01.2012 20:32, schrieb Anthony Liguori:

Quoted 10 lines

This class provides the main building block for QEMU Object Model and is extensively documented in the header file. It is largely inspired by GObject.

---
v1 -> v2
- remove printf() in type registration
- fix typo in comment (Paolo)
- make Interface private
- move object into a new directory and move header into include/qemu/

Some of us had expressed concerns over introducing include/. Any particular reason you're doing it still?

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#11 lore raw

Re: [Qemu-devel] [PATCH 04/28] qom: add the base Object class (v2)

Quoted 12 lines · Andreas Färber

Am 24.01.2012 20:32, schrieb Anthony Liguori:

Quoted 10 lines

This class provides the main building block for QEMU Object Model and is extensively documented in the header file. It is largely inspired by GObject.

---
v1 -> v2
- remove printf() in type registration
- fix typo in comment (Paolo)
- make Interface private
- move object into a new directory and move header into include/qemu/

Quoted 2 lines

Some of us had expressed concerns over introducing include/. Any particular reason you're doing it still?

Because it's a great idea and I thought everyone loved it?

Can you point me to the concerns raised, I'll go back and look. I didn't think it was contentious...

To summarize my rationale for it:

1) It avoids all of the non-sense with conflicting system headers (because we
-Iinclude and the headers live in include/qemu)

2) It establishes what are public functions for use in other parts of qemu vs.
private headers (which we currently use based on ad-hoc naming schemes like block_int.h).

3) I think the kernel serves as an existence proof that this method to manage
headers works really well in practice.

Regards,

Anthony Liguori

Quoted 3 lines

Andreas

#12 lore raw

Re: [Qemu-devel] [PATCH 04/28] qom: add the base Object class (v2)

Quoted 27 lines · Anthony Liguori
Quoted 13 lines · Andreas Färber

Am 24.01.2012 20:32, schrieb Anthony Liguori:

Quoted 11 lines

This class provides the main building block for QEMU Object Model and is extensively documented in the header file. It is largely inspired by GObject.

---
v1 -> v2
- remove printf() in type registration
- fix typo in comment (Paolo)
- make Interface private
- move object into a new directory and move header into include/qemu/

Quoted 2 lines

Some of us had expressed concerns over introducing include/. Any particular reason you're doing it still?

Because it's a great idea and I thought everyone loved it?

Can you point me to the concerns raised, I'll go back and look. I didn't think it was contentious...

To summarize my rationale for it:

1) It avoids all of the non-sense with conflicting system headers (because we -Iinclude and the headers live in include/qemu)

Quoted 6 lines

2) It establishes what are public functions for use in other parts of qemu vs. private headers (which we currently use based on ad-hoc naming schemes like block_int.h).

3) I think the kernel serves as an existence proof that this method to manage headers works really well in practice.

4) Because it's easy enough to complete the transition with a few "git mv", so there's hope not to be stuck with 2 headers in include/ for 5 years.

Paolo

#13 lore raw

Re: [Qemu-devel] [PATCH 04/28] qom: add the base Object class (v2)

In reply to Anthony Liguori

Am 25.01.2012 22:37, schrieb Anthony Liguori:

Quoted 14 lines · Andreas Färber
Quoted 13 lines

Am 24.01.2012 20:32, schrieb Anthony Liguori:

Quoted 11 lines

This class provides the main building block for QEMU Object Model and is extensively documented in the header file. It is largely inspired by GObject.

---
v1 -> v2
- remove printf() in type registration
- fix typo in comment (Paolo)
- make Interface private
- move object into a new directory and move header into include/qemu/

Quoted 7 lines
Quoted 2 lines

Some of us had expressed concerns over introducing include/. Any particular reason you're doing it still?

Because it's a great idea and I thought everyone loved it?

Can you point me to the concerns raised, I'll go back and look. I didn't think it was contentious...

Can't find it right now (stupid search keyword!) but I remember having a discussion around whether these are actually "public" APIs because to date we have always claimed that all APIs are internal and no guarantees are made. IMO moving headers to an include/ dir marks a change of that policy because header in include/ usually get installed alongside a library so if we do it we should do it conciously.

Thing is, headers that are private to one part of code are public to another. It's not black and white. E.g., hw -> IDE -> AHCI -> ICH9. Whenever there's multiple subclasses code needs to be shared; it shouldn't usually be poked at from the outside though in favor of qdev/QOM properties.

Personally, I find it more handy to find pci_dec.c and pci_dec.h in the same directory in Nautilus/gedit/whatever (but bad example because I'm working on making that header go away). On the other hand compared to like r955 we have seen a huge inflation in hw/ files.
I can live with it either way, and as Paolo says, it can easily be changed later with git-mv. And #include "qemu/foo.h" sounds fair.

For these new "public" headers I'd be interested in finding a solution where we can all easily collaborate on the documentation though. Right now we need to trust you to get the markup right.

Andreas

Quoted 15 lines

To summarize my rationale for it:

1) It avoids all of the non-sense with conflicting system headers
(because we -Iinclude and the headers live in include/qemu)

2) It establishes what are public functions for use in other parts of
qemu vs. private headers (which we currently use based on ad-hoc naming schemes like block_int.h).

3) I think the kernel serves as an existence proof that this method to
manage headers works really well in practice.

Regards,

Anthony Liguori

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#14 lore raw

Re: [Qemu-devel] [PATCH 04/28] qom: add the base Object class (v2)

Quoted 18 lines · Andreas Färber

Am 25.01.2012 22:37, schrieb Anthony Liguori:

Quoted 17 lines · Andreas Färber
Quoted 15 lines

Am 24.01.2012 20:32, schrieb Anthony Liguori:

Quoted 11 lines

This class provides the main building block for QEMU Object Model and is extensively documented in the header file. It is largely inspired by GObject.

---
v1 -> v2
- remove printf() in type registration
- fix typo in comment (Paolo)
- make Interface private
- move object into a new directory and move header into include/qemu/

Some of us had expressed concerns over introducing include/. Any particular reason you're doing it still?

Quoted 6 lines
Quoted 4 lines

Because it's a great idea and I thought everyone loved it?

Can you point me to the concerns raised, I'll go back and look. I didn't think it was contentious...

Can't find it right now (stupid search keyword!)

No problem.

Quoted 13 lines

but I remember having a
discussion around whether these are actually "public" APIs because to date we have always claimed that all APIs are internal and no guarantees are made. IMO moving headers to an include/ dir marks a change of that policy because header in include/ usually get installed alongside a library so if we do it we should do it conciously.

Thing is, headers that are private to one part of code are public to another. It's not black and white. E.g., hw -> IDE -> AHCI -> ICH9. Whenever there's multiple subclasses code needs to be shared; it shouldn't usually be poked at from the outside though in favor of qdev/QOM properties.

Quoted 6 lines

Personally, I find it more handy to find pci_dec.c and pci_dec.h in the same directory in Nautilus/gedit/whatever (but bad example because I'm working on making that header go away). On the other hand compared to like r955 we have seen a huge inflation in hw/ files.
I can live with it either way, and as Paolo says, it can easily be changed later with git-mv. And #include "qemu/foo.h" sounds fair.

When I think of include/, I think of "internally public" headers. IOW, things that are meant to be shared in other parts of QEMU. For instance, something like qemu-queue.h.

In fact, there are 25 header files in $SRCDIR that are in the form qemu-$file.h.
They could (and should) probably be moved to include/qemu/$file.h

As we introduce more directory structure, having a single include directory will be very handy. For instance, pci_dec.c may move to drivers/ppc/pci_dec.c. But having pci_dec.h in include/qemu means that we don't have to worry about very long #include paths.

Regards,

Anthony Liguori

Quoted 23 lines

For these new "public" headers I'd be interested in finding a solution where we can all easily collaborate on the documentation though. Right now we need to trust you to get the markup right.

Andreas

Quoted 15 lines

To summarize my rationale for it:

1) It avoids all of the non-sense with conflicting system headers
(because we -Iinclude and the headers live in include/qemu)

2) It establishes what are public functions for use in other parts of
qemu vs. private headers (which we currently use based on ad-hoc naming schemes like block_int.h).

3) I think the kernel serves as an existence proof that this method to
manage headers works really well in practice.

Regards,

Anthony Liguori

#15 lore raw

Re: [Qemu-devel] [PATCH 04/28] qom: add the base Object class (v2)

Am 27.01.2012 16:42, schrieb Anthony Liguori:

Quoted 50 lines · Andreas Färber
Quoted 20 lines

Am 25.01.2012 22:37, schrieb Anthony Liguori:

Quoted 19 lines · Andreas Färber
Quoted 17 lines

Am 24.01.2012 20:32, schrieb Anthony Liguori:

Quoted 5 lines

This class provides the main building block for QEMU Object Model and is
extensively documented in the header file. It is largely inspired by GObject.

Quoted 8 lines

---
v1 -> v2
- remove printf() in type registration
- fix typo in comment (Paolo)
- make Interface private
- move object into a new directory and move header into
include/qemu/

Some of us had expressed concerns over introducing include/. Any particular reason you're doing it still?

Quoted 6 lines
Quoted 4 lines

Because it's a great idea and I thought everyone loved it?

Can you point me to the concerns raised, I'll go back and look. I didn't think it was contentious...

Can't find it right now (stupid search keyword!)

No problem.

Quoted 13 lines

but I remember having a
discussion around whether these are actually "public" APIs because to date we have always claimed that all APIs are internal and no guarantees are made. IMO moving headers to an include/ dir marks a change of that policy because header in include/ usually get installed alongside a library so if we do it we should do it conciously.

Thing is, headers that are private to one part of code are public to another. It's not black and white. E.g., hw -> IDE -> AHCI -> ICH9. Whenever there's multiple subclasses code needs to be shared; it shouldn't usually be poked at from the outside though in favor of qdev/QOM properties.

Quoted 6 lines

Personally, I find it more handy to find pci_dec.c and pci_dec.h in the same directory in Nautilus/gedit/whatever (but bad example because I'm working on making that header go away). On the other hand compared to like r955 we have seen a huge inflation in hw/ files.
I can live with it either way, and as Paolo says, it can easily be changed later with git-mv. And #include "qemu/foo.h" sounds fair.

Quoted 7 lines

When I think of include/, I think of "internally public" headers. IOW, things that are meant to be shared in other parts of QEMU. For instance, something like qemu-queue.h.

In fact, there are 25 header files in $SRCDIR that are in the form qemu-$file.h. They could (and should) probably be moved to include/qemu/$file.h

Okay, agree.

Regards,
Andreas

Quoted 34 lines

As we introduce more directory structure, having a single include directory will be very handy. For instance, pci_dec.c may move to drivers/ppc/pci_dec.c. But having pci_dec.h in include/qemu means that we don't have to worry about very long #include paths.

Regards,

Anthony Liguori

Quoted 23 lines

For these new "public" headers I'd be interested in finding a solution where we can all easily collaborate on the documentation though. Right now we need to trust you to get the markup right.

Andreas

Quoted 15 lines

To summarize my rationale for it:

1) It avoids all of the non-sense with conflicting system headers
(because we -Iinclude and the headers live in include/qemu)

2) It establishes what are public functions for use in other parts of
qemu vs. private headers (which we currently use based on ad-hoc naming schemes like block_int.h).

3) I think the kernel serves as an existence proof that this method to
manage headers works really well in practice.

Regards,

Anthony Liguori

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#16 lore raw

PATCH v3 5/28 qdev: integrate with QEMU Object Model (v2)

In reply to Anthony Liguori

This is a very shallow integration. We register a TYPE_DEVICE but only use QOM as basically a memory allocator. This will make all devices show up as QOM objects but they will all carry the TYPE_DEVICE.

---
v1 -> v2
- update for new location of object.h

---
 hw/qdev.c |   27 +++++++++++++++++++++++++--
 hw/qdev.h |   10 ++++++++++
 2 files changed, 35 insertions(+), 2 deletions(-)
hw/qdev.c +25 -2
index 5a75668..3bc9166 100644
@@ -47,9 +47,17 @@ static BusState *qbus_find(const char *path);
 /* Register a new device type.  */
 void qdev_register(DeviceInfo *info)
 {
+    TypeInfo type_info = {};
+
     assert(info->size >= sizeof(DeviceState));
     assert(!info->next);
 
+    type_info.name = info->name;
+    type_info.parent = TYPE_DEVICE;
+    type_info.instance_size = info->size;
+
+    type_register_static(&type_info);
+
     info->next = device_info_list;
     device_info_list = info;
 }
@@ -93,7 +101,7 @@ static DeviceState *qdev_create_from_info(BusState *bus, DeviceInfo *info)
     Property *prop;
 
     assert(bus->info == info->bus_info);
-    dev = g_malloc0(info->size);
+    dev = DEVICE(object_new(info->name));
     dev->info = info;
     dev->parent_bus = bus;
     qdev_prop_set_defaults(dev, dev->info->props);
@@ -519,7 +527,7 @@ void qdev_free(DeviceState *dev)
     if (dev->ref != 0) {
         qerror_report(QERR_DEVICE_IN_USE, dev->id?:"");
     }
-    g_free(dev);
+    object_delete(OBJECT(dev));
 }
 
 void qdev_machine_creation_done(void)
@@ -1572,3 +1580,18 @@ void qdev_machine_init(void)
     qdev_get_peripheral_anon();
     qdev_get_peripheral();
 }
+
+static TypeInfo device_type_info = {
+    .name = TYPE_DEVICE,
+    .parent = TYPE_OBJECT,
+    .instance_size = sizeof(DeviceState),
+    .abstract = true,
+    .class_size = sizeof(DeviceClass),
+};
+
+static void init_qdev(void)
+{
+    type_register_static(&device_type_info);
+}
+
+device_init(init_qdev);
hw/qdev.h +10 -0
index 6b58dd8..1e01a04 100644
@@ -6,6 +6,7 @@
 #include "qemu-char.h"
 #include "qemu-option.h"
 #include "qapi/qapi-visit-core.h"
+#include "qemu/object.h"
 
 typedef struct Property Property;
 
@@ -66,9 +67,18 @@ typedef struct DeviceProperty
     QTAILQ_ENTRY(DeviceProperty) node;
 } DeviceProperty;
 
+#define TYPE_DEVICE "device"
+#define DEVICE(obj) OBJECT_CHECK(DeviceState, (obj), TYPE_DEVICE)
+
+typedef struct DeviceClass {
+    ObjectClass parent_class;
+} DeviceClass;
+
 /* This structure should not be accessed directly.  We declare it here
    so that it can be embedded in individual device state structures.  */
 struct DeviceState {
+    Object parent_obj;
+
     const char *id;
     enum DevState state;
     QemuOpts *opts;
Signature · 1 line
1.7.4.1
#17 lore raw

PATCH v3 6/28 qdev: move qdev->info to class

In reply to Anthony Liguori

Right now, DeviceInfo acts as the class for qdev. In order to switch to a proper ObjectClass derivative, we need to ween all of the callers off of interacting directly with the info pointer.

---
 hw/acpi_piix4.c        |    4 +-
 hw/apic_common.c       |   10 +++---
 hw/cirrus_vga.c        |    2 +-
 hw/e1000.c             |    2 +-
 hw/eepro100.c          |    4 +-
 hw/hda-audio.c         |    2 +-
 hw/i8259_common.c      |    6 ++--
 hw/ide/piix.c          |    2 +-
 hw/intel-hda.c         |    6 ++--
 hw/ioapic_common.c     |    6 ++--
 hw/lan9118.c           |    2 +-
 hw/lsi53c895a.c        |    2 +-
 hw/mipsnet.c           |    2 +-
 hw/ne2000-isa.c        |    2 +-
 hw/ne2000.c            |    2 +-
 hw/opencores_eth.c     |    2 +-
 hw/pci.c               |   16 ++++++-----
 hw/pcnet.c             |    2 +-
 hw/qdev-properties.c   |   20 +++++++-------
 hw/qdev.c              |   70 ++++++++++++++++++++++++++++--------------------
 hw/qdev.h              |   16 +++++++++-
 hw/rtl8139.c           |    2 +-
 hw/smc91c111.c         |    2 +-
 hw/spapr_vio.c         |    6 ++--
 hw/spapr_vty.c         |    2 +-
 hw/usb-bus.c           |    2 +-
 hw/usb-ccid.c          |    2 +-
 hw/usb-net.c           |    2 +-
 hw/usb-ohci.c          |    2 +-
 hw/virtio-console.c    |    2 +-
 hw/virtio-net.c        |    2 +-
 hw/virtio-serial-bus.c |    6 ++--
 32 files changed, 118 insertions(+), 92 deletions(-)
hw/acpi_piix4.c +2 -2
index bdc55a1..4d0b390 100644
@@ -280,7 +280,7 @@ static void piix4_update_hotplug(PIIX4PMState *s)
     s->pci0_hotplug_enable = ~0;
 
     QTAILQ_FOREACH_SAFE(qdev, &bus->children, sibling, next) {
-        PCIDeviceInfo *info = container_of(qdev->info, PCIDeviceInfo, qdev);
+        PCIDeviceInfo *info = container_of(qdev_get_info(qdev), PCIDeviceInfo, qdev);
         PCIDevice *pdev = DO_UPCAST(PCIDevice, qdev, qdev);
         int slot = PCI_SLOT(pdev->devfn);
 
@@ -491,7 +491,7 @@ static void pciej_write(void *opaque, uint32_t addr, uint32_t val)
 
     QTAILQ_FOREACH_SAFE(qdev, &bus->children, sibling, next) {
         dev = DO_UPCAST(PCIDevice, qdev, qdev);
-        info = container_of(qdev->info, PCIDeviceInfo, qdev);
+        info = container_of(qdev_get_info(qdev), PCIDeviceInfo, qdev);
         if (PCI_SLOT(dev->devfn) == slot && !info->no_hotplug) {
             qdev_free(qdev);
         }
hw/apic_common.c +5 -5
index e05369c..ac06147 100644
@@ -31,7 +31,7 @@ void cpu_set_apic_base(DeviceState *d, uint64_t val)
     trace_cpu_set_apic_base(val);
 
     if (s) {
-        info = DO_UPCAST(APICCommonInfo, busdev.qdev, s->busdev.qdev.info);
+        info = DO_UPCAST(APICCommonInfo, busdev.qdev, qdev_get_info(&s->busdev.qdev));
         info->set_base(s, val);
     }
 }
@@ -51,7 +51,7 @@ void cpu_set_apic_tpr(DeviceState *d, uint8_t val)
     APICCommonInfo *info;
 
     if (s) {
-        info = DO_UPCAST(APICCommonInfo, busdev.qdev, s->busdev.qdev.info);
+        info = DO_UPCAST(APICCommonInfo, busdev.qdev, qdev_get_info(&s->busdev.qdev));
         info->set_tpr(s, val);
     }
 }
@@ -89,7 +89,7 @@ void apic_deliver_nmi(DeviceState *d)
     APICCommonState *s = DO_UPCAST(APICCommonState, busdev.qdev, d);
     APICCommonInfo *info;
 
-    info = DO_UPCAST(APICCommonInfo, busdev.qdev, s->busdev.qdev.info);
+    info = DO_UPCAST(APICCommonInfo, busdev.qdev, qdev_get_info(&s->busdev.qdev));
     info->external_nmi(s);
 }
 
@@ -232,7 +232,7 @@ static int apic_init_common(SysBusDevice *dev)
     }
     s->idx = apic_no++;
 
-    info = DO_UPCAST(APICCommonInfo, busdev.qdev, s->busdev.qdev.info);
+    info = DO_UPCAST(APICCommonInfo, busdev.qdev, qdev_get_info(&s->busdev.qdev));
     info->init(s);
 
     sysbus_init_mmio(&s->busdev, &s->io_memory);
@@ -243,7 +243,7 @@ static int apic_dispatch_post_load(void *opaque, int version_id)
 {
     APICCommonState *s = opaque;
     APICCommonInfo *info =
-        DO_UPCAST(APICCommonInfo, busdev.qdev, s->busdev.qdev.info);
+        DO_UPCAST(APICCommonInfo, busdev.qdev, qdev_get_info(&s->busdev.qdev));
 
     if (info->post_load) {
         info->post_load(s);
hw/cirrus_vga.c +1 -1
index 8506bb5..5594bde 100644
@@ -2928,7 +2928,7 @@ static int pci_cirrus_vga_initfn(PCIDevice *dev)
 {
      PCICirrusVGAState *d = DO_UPCAST(PCICirrusVGAState, dev, dev);
      CirrusVGAState *s = &d->cirrus_vga;
-     PCIDeviceInfo *info = DO_UPCAST(PCIDeviceInfo, qdev, dev->qdev.info);
+     PCIDeviceInfo *info = DO_UPCAST(PCIDeviceInfo, qdev, qdev_get_info(&dev->qdev));
      int16_t device_id = info->device_id;
 
      /* setup VGA */
hw/e1000.c +1 -1
index 86c5416..f7f72ac 100644
@@ -1177,7 +1177,7 @@ static int pci_e1000_init(PCIDevice *pci_dev)
     d->eeprom_data[EEPROM_CHECKSUM_REG] = checksum;
 
     d->nic = qemu_new_nic(&net_e1000_info, &d->conf,
-                          d->dev.qdev.info->name, d->dev.qdev.id, d);
+                          qdev_get_info(&d->dev.qdev)->name, d->dev.qdev.id, d);
 
     qemu_format_nic_info_str(&d->nic->nc, macaddr);
 
hw/eepro100.c +2 -2
index 6a162f6..81a32b8 100644
@@ -1848,7 +1848,7 @@ static int e100_nic_init(PCIDevice *pci_dev)
 {
     EEPRO100State *s = DO_UPCAST(EEPRO100State, dev, pci_dev);
     E100PCIDeviceInfo *e100_device = DO_UPCAST(E100PCIDeviceInfo, pci.qdev,
-                                               pci_dev->qdev.info);
+                                               qdev_get_info(&pci_dev->qdev));
 
     TRACE(OTHER, logout("\n"));
 
@@ -1878,7 +1878,7 @@ static int e100_nic_init(PCIDevice *pci_dev)
     nic_reset(s);
 
     s->nic = qemu_new_nic(&net_eepro100_info, &s->conf,
-                          pci_dev->qdev.info->name, pci_dev->qdev.id, s);
+                          qdev_get_info(&pci_dev->qdev)->name, pci_dev->qdev.id, s);
 
     qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
     TRACE(OTHER, logout("%s\n", s->nic->nc.info_str));
hw/hda-audio.c +1 -1
index 9b089e6..0bc0a25 100644
@@ -777,7 +777,7 @@ static int hda_audio_init(HDACodecDevice *hda, const struct desc_codec *desc)
     uint32_t i, type;
 
     a->desc = desc;
-    a->name = a->hda.qdev.info->name;
+    a->name = qdev_get_info(&a->hda.qdev)->name;
     dprint(a, 1, "%s: cad %d\n", __FUNCTION__, a->hda.cad);
 
     AUD_register_card("hda", &a->card);
hw/i8259_common.c +3 -3
index e515876..7536897 100644
@@ -49,7 +49,7 @@ static void pic_dispatch_pre_save(void *opaque)
 {
     PICCommonState *s = opaque;
     PICCommonInfo *info =
-        DO_UPCAST(PICCommonInfo, isadev.qdev, s->dev.qdev.info);
+        DO_UPCAST(PICCommonInfo, isadev.qdev, qdev_get_info(&s->dev.qdev));
 
     if (info->pre_save) {
         info->pre_save(s);
@@ -60,7 +60,7 @@ static int pic_dispatch_post_load(void *opaque, int version_id)
 {
     PICCommonState *s = opaque;
     PICCommonInfo *info =
-        DO_UPCAST(PICCommonInfo, isadev.qdev, s->dev.qdev.info);
+        DO_UPCAST(PICCommonInfo, isadev.qdev, qdev_get_info(&s->dev.qdev));
 
     if (info->post_load) {
         info->post_load(s);
@@ -72,7 +72,7 @@ static int pic_init_common(ISADevice *dev)
 {
     PICCommonState *s = DO_UPCAST(PICCommonState, dev, dev);
     PICCommonInfo *info =
-        DO_UPCAST(PICCommonInfo, isadev.qdev, dev->qdev.info);
+        DO_UPCAST(PICCommonInfo, isadev.qdev, qdev_get_info(&dev->qdev));
 
     info->init(s);
 
hw/ide/piix.c +1 -1
index 3473345..c0e3450 100644
@@ -195,7 +195,6 @@ PCIDevice *pci_piix3_xen_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn)
     PCIDevice *dev;
 
     dev = pci_create_simple(bus, devfn, "piix3-ide-xen");
-    dev->qdev.info->unplug = pci_piix3_xen_ide_unplug;
     pci_ide_create_devs(dev, hd_table);
     return dev;
 }
@@ -253,6 +252,7 @@ static PCIDeviceInfo piix_ide_info[] = {
         .qdev.name    = "piix3-ide-xen",
         .qdev.size    = sizeof(PCIIDEState),
         .qdev.no_user = 1,
+        .qdev.unplug  = pci_piix3_xen_ide_unplug,
         .init         = pci_piix_ide_initfn,
         .vendor_id    = PCI_VENDOR_ID_INTEL,
         .device_id    = PCI_DEVICE_ID_INTEL_82371SB_1,
hw/intel-hda.c +3 -3
index 10769e0..12dcc84 100644
@@ -1116,8 +1116,8 @@ static void intel_hda_reset(DeviceState *dev)
     /* reset codecs */
     QTAILQ_FOREACH(qdev, &d->codecs.qbus.children, sibling) {
         cdev = DO_UPCAST(HDACodecDevice, qdev, qdev);
-        if (qdev->info->reset) {
-            qdev->info->reset(qdev);
+        if (qdev_get_info(qdev)->reset) {
+            qdev_get_info(qdev)->reset(qdev);
         }
         d->state_sts |= (1 << cdev->cad);
     }
@@ -1129,7 +1129,7 @@ static int intel_hda_init(PCIDevice *pci)
     IntelHDAState *d = DO_UPCAST(IntelHDAState, pci, pci);
     uint8_t *conf = d->pci.config;
 
-    d->name = d->pci.qdev.info->name;
+    d->name = qdev_get_info(&d->pci.qdev)->name;
 
     pci_config_set_interrupt_pin(conf, 1);
 
hw/ioapic_common.c +3 -3
index 3aa9a1c..4a7624c 100644
@@ -40,7 +40,7 @@ static void ioapic_dispatch_pre_save(void *opaque)
 {
     IOAPICCommonState *s = opaque;
     IOAPICCommonInfo *info =
-        DO_UPCAST(IOAPICCommonInfo, busdev.qdev, s->busdev.qdev.info);
+        DO_UPCAST(IOAPICCommonInfo, busdev.qdev, qdev_get_info(&s->busdev.qdev));
 
     if (info->pre_save) {
         info->pre_save(s);
@@ -51,7 +51,7 @@ static int ioapic_dispatch_post_load(void *opaque, int version_id)
 {
     IOAPICCommonState *s = opaque;
     IOAPICCommonInfo *info =
-        DO_UPCAST(IOAPICCommonInfo, busdev.qdev, s->busdev.qdev.info);
+        DO_UPCAST(IOAPICCommonInfo, busdev.qdev, qdev_get_info(&s->busdev.qdev));
 
     if (info->post_load) {
         info->post_load(s);
@@ -69,7 +69,7 @@ static int ioapic_init_common(SysBusDevice *dev)
         return -1;
     }
 
-    info = DO_UPCAST(IOAPICCommonInfo, busdev.qdev, s->busdev.qdev.info);
+    info = DO_UPCAST(IOAPICCommonInfo, busdev.qdev, qdev_get_info(&s->busdev.qdev));
     info->init(s, ioapic_no);
 
     sysbus_init_mmio(&s->busdev, &s->io_memory);
hw/lan9118.c +1 -1
index 9b199d0..d1b244e 100644
@@ -1221,7 +1221,7 @@ static int lan9118_init1(SysBusDevice *dev)
     qemu_macaddr_default_if_unset(&s->conf.macaddr);
 
     s->nic = qemu_new_nic(&net_lan9118_info, &s->conf,
-                          dev->qdev.info->name, dev->qdev.id, s);
+                          qdev_get_info(&dev->qdev)->name, dev->qdev.id, s);
     qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
     s->eeprom[0] = 0xa5;
     for (i = 0; i < 6; i++) {
hw/lsi53c895a.c +1 -1
index 0d3a101..9f475e0 100644
@@ -1681,7 +1681,7 @@ static void lsi_reg_writeb(LSIState *s, int offset, uint8_t val)
                 DeviceState *dev;
 
                 QTAILQ_FOREACH(dev, &s->bus.qbus.children, sibling) {
-                    dev->info->reset(dev);
+                    qdev_get_info(dev)->reset(dev);
                 }
                 s->sstat0 |= LSI_SSTAT0_RST;
                 lsi_script_scsi_interrupt(s, LSI_SIST0_RST, 0);
hw/mipsnet.c +1 -1
index b1234b8..1486833 100644
@@ -240,7 +240,7 @@ static int mipsnet_sysbus_init(SysBusDevice *dev)
     sysbus_init_irq(dev, &s->irq);
 
     s->nic = qemu_new_nic(&net_mipsnet_info, &s->conf,
-                          dev->qdev.info->name, dev->qdev.id, s);
+                          qdev_get_info(&dev->qdev)->name, dev->qdev.id, s);
     qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
 
     return 0;
hw/ne2000-isa.c +1 -1
index 11ffee7..60dc333 100644
@@ -76,7 +76,7 @@ static int isa_ne2000_initfn(ISADevice *dev)
     ne2000_reset(s);
 
     s->nic = qemu_new_nic(&net_ne2000_isa_info, &s->c,
-                          dev->qdev.info->name, dev->qdev.id, s);
+                          qdev_get_info(&dev->qdev)->name, dev->qdev.id, s);
     qemu_format_nic_info_str(&s->nic->nc, s->c.macaddr.a);
 
     return 0;
hw/ne2000.c +1 -1
index 62e082f..d016b8e 100644
@@ -760,7 +760,7 @@ static int pci_ne2000_init(PCIDevice *pci_dev)
     ne2000_reset(s);
 
     s->nic = qemu_new_nic(&net_ne2000_info, &s->c,
-                          pci_dev->qdev.info->name, pci_dev->qdev.id, s);
+                          qdev_get_info(&pci_dev->qdev)->name, pci_dev->qdev.id, s);
     qemu_format_nic_info_str(&s->nic->nc, s->c.macaddr.a);
 
     if (!pci_dev->qdev.hotplugged) {
hw/opencores_eth.c +1 -1
index f7cc1b4..d4d3529 100644
@@ -717,7 +717,7 @@ static int sysbus_open_eth_init(SysBusDevice *dev)
     sysbus_init_irq(dev, &s->irq);
 
     s->nic = qemu_new_nic(&net_open_eth_info, &s->conf,
-                          s->dev.qdev.info->name, s->dev.qdev.id, s);
+                          qdev_get_info(&s->dev.qdev)->name, s->dev.qdev.id, s);
     return 0;
 }
 
hw/pci.c +9 -7
index ab3b53d..5345079 100644
@@ -841,7 +841,7 @@ static void pci_unregister_io_regions(PCIDevice *pci_dev)
 static int pci_unregister_device(DeviceState *dev)
 {
     PCIDevice *pci_dev = DO_UPCAST(PCIDevice, qdev, dev);
-    PCIDeviceInfo *info = DO_UPCAST(PCIDeviceInfo, qdev, dev->info);
+    PCIDeviceInfo *info = DO_UPCAST(PCIDeviceInfo, qdev, qdev_get_info(dev));
     int ret = 0;
 
     if (info->exit)
@@ -1531,7 +1531,7 @@ static int pci_qdev_init(DeviceState *qdev, DeviceInfo *base)
 static int pci_unplug_device(DeviceState *qdev)
 {
     PCIDevice *dev = DO_UPCAST(PCIDevice, qdev, qdev);
-    PCIDeviceInfo *info = container_of(qdev->info, PCIDeviceInfo, qdev);
+    PCIDeviceInfo *info = container_of(qdev_get_info(qdev), PCIDeviceInfo, qdev);
 
     if (info->no_hotplug) {
         qerror_report(QERR_DEVICE_NO_HOTPLUG, info->qdev.name);
@@ -1544,7 +1544,9 @@ static int pci_unplug_device(DeviceState *qdev)
 void pci_qdev_register(PCIDeviceInfo *info)
 {
     info->qdev.init = pci_qdev_init;
-    info->qdev.unplug = pci_unplug_device;
+    if (!info->qdev.unplug) {
+        info->qdev.unplug = pci_unplug_device;
+    }
     info->qdev.exit = pci_unregister_device;
     info->qdev.bus_info = &pci_bus_info;
     qdev_register(&info->qdev);
@@ -1737,10 +1739,10 @@ static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom)
         size = 1 << qemu_fls(size);
     }
 
-    if (pdev->qdev.info->vmsd)
-        snprintf(name, sizeof(name), "%s.rom", pdev->qdev.info->vmsd->name);
+    if (qdev_get_info(&pdev->qdev)->vmsd)
+        snprintf(name, sizeof(name), "%s.rom", qdev_get_info(&pdev->qdev)->vmsd->name);
     else
-        snprintf(name, sizeof(name), "%s.rom", pdev->qdev.info->name);
+        snprintf(name, sizeof(name), "%s.rom", qdev_get_info(&pdev->qdev)->name);
     pdev->has_rom = true;
     memory_region_init_ram(&pdev->rom, name, size);
     vmstate_register_ram(&pdev->rom, &pdev->qdev);
@@ -1981,7 +1983,7 @@ static int pci_qdev_find_recursive(PCIBus *bus,
     }
 
     /* roughly check if given qdev is pci device */
-    if (qdev->info->init == &pci_qdev_init &&
+    if (qdev_get_info(qdev)->init == &pci_qdev_init &&
         qdev->parent_bus->info == &pci_bus_info) {
         *pdev = DO_UPCAST(PCIDevice, qdev, qdev);
         return 0;
hw/pcnet.c +1 -1
index 306dc6e..1b5d678 100644
@@ -1719,7 +1719,7 @@ int pcnet_common_init(DeviceState *dev, PCNetState *s, NetClientInfo *info)
     s->poll_timer = qemu_new_timer_ns(vm_clock, pcnet_poll_timer, s);
 
     qemu_macaddr_default_if_unset(&s->conf.macaddr);
-    s->nic = qemu_new_nic(info, &s->conf, dev->info->name, dev->id, s);
+    s->nic = qemu_new_nic(info, &s->conf, qdev_get_info(dev)->name, dev->id, s);
     qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
 
     add_boot_device_path(s->conf.bootindex, dev, "/ethernet-phy@0");
hw/qdev-properties.c +10 -10
index 02f0dae..4610c3d 100644
@@ -966,7 +966,7 @@ static Property *qdev_prop_find(DeviceState *dev, const char *name)
     Property *prop;
 
     /* device properties */
-    prop = qdev_prop_walk(dev->info->props, name);
+    prop = qdev_prop_walk(qdev_get_info(dev)->props, name);
     if (prop)
         return prop;
 
@@ -989,16 +989,16 @@ void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev,
     switch (ret) {
     case -EEXIST:
         error_set(errp, QERR_PROPERTY_VALUE_IN_USE,
-                  dev->info->name, prop->name, value);
+                  qdev_get_info(dev)->name, prop->name, value);
         break;
     default:
     case -EINVAL:
         error_set(errp, QERR_PROPERTY_VALUE_BAD,
-                  dev->info->name, prop->name, value);
+                  qdev_get_info(dev)->name, prop->name, value);
         break;
     case -ENOENT:
         error_set(errp, QERR_PROPERTY_VALUE_NOT_FOUND,
-                  dev->info->name, prop->name, value);
+                  qdev_get_info(dev)->name, prop->name, value);
         break;
     case 0:
         break;
@@ -1018,7 +1018,7 @@ int qdev_prop_parse(DeviceState *dev, const char *name, const char *value)
      * removed along with it.
      */
     if (!prop || !prop->info->parse) {
-        qerror_report(QERR_PROPERTY_NOT_FOUND, dev->info->name, name);
+        qerror_report(QERR_PROPERTY_NOT_FOUND, qdev_get_info(dev)->name, name);
         return -1;
     }
     ret = prop->info->parse(dev, prop, value);
@@ -1039,12 +1039,12 @@ void qdev_prop_set(DeviceState *dev, const char *name, void *src, enum PropertyT
     prop = qdev_prop_find(dev, name);
     if (!prop) {
         fprintf(stderr, "%s: property \"%s.%s\" not found\n",
-                __FUNCTION__, dev->info->name, name);
+                __FUNCTION__, qdev_get_info(dev)->name, name);
         abort();
     }
     if (prop->info->type != type) {
         fprintf(stderr, "%s: property \"%s.%s\" type mismatch\n",
-                __FUNCTION__, dev->info->name, name);
+                __FUNCTION__, qdev_get_info(dev)->name, name);
         abort();
     }
     qdev_prop_cpy(dev, prop, src);
@@ -1093,7 +1093,7 @@ int qdev_prop_set_drive(DeviceState *dev, const char *name, BlockDriverState *va
     if (res < 0) {
         error_report("Can't attach drive %s to %s.%s: %s",
                      bdrv_get_device_name(value),
-                     dev->id ? dev->id : dev->info->name,
+                     dev->id ? dev->id : qdev_get_info(dev)->name,
                      name, strerror(-res));
         return -1;
     }
@@ -1165,8 +1165,8 @@ void qdev_prop_set_globals(DeviceState *dev)
     GlobalProperty *prop;
 
     QTAILQ_FOREACH(prop, &global_props, next) {
-        if (strcmp(dev->info->name, prop->driver) != 0 &&
-            strcmp(dev->info->bus_info->name, prop->driver) != 0) {
+        if (strcmp(qdev_get_info(dev)->name, prop->driver) != 0 &&
+            strcmp(qdev_get_info(dev)->bus_info->name, prop->driver) != 0) {
             continue;
         }
         if (qdev_prop_parse(dev, prop->property, prop->value) != 0) {
hw/qdev.c +41 -29

200 lines not on this page · raw message

hw/qdev.h +14 -2
index 1e01a04..e13111f 100644
@@ -69,9 +69,12 @@ typedef struct DeviceProperty
 
 #define TYPE_DEVICE "device"
 #define DEVICE(obj) OBJECT_CHECK(DeviceState, (obj), TYPE_DEVICE)
+#define DEVICE_CLASS(klass) OBJECT_CLASS_CHECK(DeviceClass, (klass), TYPE_DEVICE)
+#define DEVICE_GET_CLASS(obj) OBJECT_GET_CLASS(DeviceClass, (obj), TYPE_DEVICE)
 
 typedef struct DeviceClass {
     ObjectClass parent_class;
+    DeviceInfo *info;
 } DeviceClass;
 
 /* This structure should not be accessed directly.  We declare it here
@@ -83,7 +86,6 @@ struct DeviceState {
     enum DevState state;
     QemuOpts *opts;
     int hotplugged;
-    DeviceInfo *info;
     BusState *parent_bus;
     int num_gpio_out;
     qemu_irq *gpio_out;
@@ -389,9 +391,19 @@ void qdev_prop_set_globals(DeviceState *dev);
 void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev,
                                     Property *prop, const char *value);
 
+DeviceInfo *qdev_get_info(DeviceState *dev);
+
 static inline const char *qdev_fw_name(DeviceState *dev)
 {
-    return dev->info->fw_name ? : dev->info->alias ? : dev->info->name;
+    DeviceInfo *info = qdev_get_info(dev);
+
+    if (info->fw_name) {
+        return info->fw_name;
+    } else if (info->alias) {
+        return info->alias;
+    }
+
+    return info->name;
 }
 
 char *qdev_get_fw_dev_path(DeviceState *dev);
hw/rtl8139.c +1 -1
index 0ae9f57..16d948e 100644
@@ -3478,7 +3478,7 @@ static int pci_rtl8139_init(PCIDevice *dev)
     s->eeprom.contents[9] = s->conf.macaddr.a[4] | s->conf.macaddr.a[5] << 8;
 
     s->nic = qemu_new_nic(&net_rtl8139_info, &s->conf,
-                          dev->qdev.info->name, dev->qdev.id, s);
+                          qdev_get_info(&dev->qdev)->name, dev->qdev.id, s);
     qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
 
     s->cplus_txbuffer = NULL;
hw/smc91c111.c +1 -1
index 82b8811..b83a893 100644
@@ -752,7 +752,7 @@ static int smc91c111_init1(SysBusDevice *dev)
     sysbus_init_irq(dev, &s->irq);
     qemu_macaddr_default_if_unset(&s->conf.macaddr);
     s->nic = qemu_new_nic(&net_smc91c111_info, &s->conf,
-                          dev->qdev.info->name, dev->qdev.id, s);
+                          qdev_get_info(&dev->qdev)->name, dev->qdev.id, s);
     qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
     /* ??? Save/restore.  */
     return 0;
hw/spapr_vio.c +3 -3
index 7a86dc8..0159413 100644
@@ -75,7 +75,7 @@ VIOsPAPRDevice *spapr_vio_find_by_reg(VIOsPAPRBus *bus, uint32_t reg)
 
 static char *vio_format_dev_name(VIOsPAPRDevice *dev)
 {
-    VIOsPAPRDeviceInfo *info = (VIOsPAPRDeviceInfo *)dev->qdev.info;
+    VIOsPAPRDeviceInfo *info = (VIOsPAPRDeviceInfo *)qdev_get_info(&dev->qdev);
     char *name;
 
     /* Device tree style name device@reg */
@@ -90,7 +90,7 @@ static char *vio_format_dev_name(VIOsPAPRDevice *dev)
 static int vio_make_devnode(VIOsPAPRDevice *dev,
                             void *fdt)
 {
-    VIOsPAPRDeviceInfo *info = (VIOsPAPRDeviceInfo *)dev->qdev.info;
+    VIOsPAPRDeviceInfo *info = (VIOsPAPRDeviceInfo *)qdev_get_info(&dev->qdev);
     int vdevice_off, node_off, ret;
     char *dt_name;
 
@@ -700,7 +700,7 @@ static target_ulong h_vio_signal(CPUState *env, sPAPREnvironment *spapr,
         return H_PARAMETER;
     }
 
-    info = (VIOsPAPRDeviceInfo *)dev->qdev.info;
+    info = (VIOsPAPRDeviceInfo *)qdev_get_info(&dev->qdev);
 
     if (mode & ~info->signal_mask) {
         return H_PARAMETER;
hw/spapr_vty.c +1 -1
index c5fb096..181dd0e 100644
@@ -163,7 +163,7 @@ VIOsPAPRDevice *spapr_vty_get_default(VIOsPAPRBus *bus)
     selected = NULL;
     QTAILQ_FOREACH(iter, &bus->bus.children, sibling) {
         /* Only look at VTY devices */
-        if (iter->info != &spapr_vty.qdev) {
+        if (qdev_get_info(iter) != &spapr_vty.qdev) {
             continue;
         }
 
hw/usb-bus.c +1 -1
index 016a3f2..3b80d5e 100644
@@ -250,7 +250,7 @@ int usb_claim_port(USBDevice *dev)
             return -1;
         }
     } else {
-        if (bus->nfree == 1 && strcmp(dev->qdev.info->name, "usb-hub") != 0) {
+        if (bus->nfree == 1 && strcmp(qdev_get_info(&dev->qdev)->name, "usb-hub") != 0) {
             /* Create a new hub and chain it on */
             usb_create_simple(bus, "usb-hub");
         }
hw/usb-ccid.c +1 -1
index e9935ad..3b7f95d 100644
@@ -1114,7 +1114,7 @@ static int ccid_card_exit(DeviceState *qdev)
 {
     int ret = 0;
     CCIDCardState *card = DO_UPCAST(CCIDCardState, qdev, qdev);
-    CCIDCardInfo *info = DO_UPCAST(CCIDCardInfo, qdev, qdev->info);
+    CCIDCardInfo *info = DO_UPCAST(CCIDCardInfo, qdev, qdev_get_info(qdev));
     USBCCIDState *s =
         DO_UPCAST(USBCCIDState, dev.qdev, card->qdev.parent_bus->parent);
 
hw/usb-net.c +1 -1
index 2f527a8..086aa7e 100644
@@ -1337,7 +1337,7 @@ static int usb_net_initfn(USBDevice *dev)
 
     qemu_macaddr_default_if_unset(&s->conf.macaddr);
     s->nic = qemu_new_nic(&net_usbnet_info, &s->conf,
-                          s->dev.qdev.info->name, s->dev.qdev.id, s);
+                          qdev_get_info(&s->dev.qdev)->name, s->dev.qdev.id, s);
     qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
     snprintf(s->usbstring_mac, sizeof(s->usbstring_mac),
              "%02x%02x%02x%02x%02x%02x",
hw/usb-ohci.c +1 -1
index 69463d2..afa3274 100644
@@ -1777,7 +1777,7 @@ static int usb_ohci_init(OHCIState *ohci, DeviceState *dev,
     memory_region_init_io(&ohci->mem, &ohci_mem_ops, ohci, "ohci", 256);
     ohci->localmem_base = localmem_base;
 
-    ohci->name = dev->info->name;
+    ohci->name = qdev_get_info(dev)->name;
     usb_packet_init(&ohci->usb_packet);
 
     ohci->async_td = 0;
hw/virtio-console.c +1 -1
index 0b28a30..f25adc4 100644
@@ -110,7 +110,7 @@ static int virtconsole_initfn(VirtIOSerialPort *port)
 {
     VirtConsole *vcon = DO_UPCAST(VirtConsole, port, port);
     VirtIOSerialPortInfo *info = DO_UPCAST(VirtIOSerialPortInfo, qdev,
-                                           vcon->port.dev.info);
+                                           qdev_get_info(&vcon->port.dev));
 
     if (port->id == 0 && !info->is_console) {
         error_report("Port number 0 on virtio-serial devices reserved for virtconsole devices for backward compatibility.");
hw/virtio-net.c +1 -1
index 8c2f460..6c785d0 100644
@@ -1030,7 +1030,7 @@ VirtIODevice *virtio_net_init(DeviceState *dev, NICConf *conf,
     memcpy(&n->mac[0], &conf->macaddr, sizeof(n->mac));
     n->status = VIRTIO_NET_S_LINK_UP;
 
-    n->nic = qemu_new_nic(&net_virtio_info, conf, dev->info->name, dev->id, n);
+    n->nic = qemu_new_nic(&net_virtio_info, conf, qdev_get_info(dev)->name, dev->id, n);
 
     qemu_format_nic_info_str(&n->nic->nc, conf->macaddr.a);
 
hw/virtio-serial-bus.c +3 -3
index 32e46e9..982ffbf 100644
@@ -138,7 +138,7 @@ static void do_flush_queued_data(VirtIOSerialPort *port, VirtQueue *vq,
     assert(port);
     assert(virtio_queue_ready(vq));
 
-    info = DO_UPCAST(VirtIOSerialPortInfo, qdev, port->dev.info);
+    info = DO_UPCAST(VirtIOSerialPortInfo, qdev, qdev_get_info(&port->dev));
 
     while (!port->throttled) {
         unsigned int i;
@@ -373,7 +373,7 @@ static void handle_control_message(VirtIOSerial *vser, void *buf, size_t len)
 
     trace_virtio_serial_handle_control_message_port(port->id);
 
-    info = DO_UPCAST(VirtIOSerialPortInfo, qdev, port->dev.info);
+    info = DO_UPCAST(VirtIOSerialPortInfo, qdev, qdev_get_info(&port->dev));
 
     switch(cpkt.event) {
     case VIRTIO_CONSOLE_PORT_READY:
@@ -824,7 +824,7 @@ static int virtser_port_qdev_exit(DeviceState *qdev)
 {
     VirtIOSerialPort *port = DO_UPCAST(VirtIOSerialPort, dev, qdev);
     VirtIOSerialPortInfo *info = DO_UPCAST(VirtIOSerialPortInfo, qdev,
-                                           port->dev.info);
+                                           qdev_get_info(&port->dev));
     VirtIOSerial *vser = port->vser;
 
     qemu_bh_delete(port->bh);
Signature · 1 line
1.7.4.1
#18 lore raw

PATCH v3 7/28 qdev: don't access name through info

In reply to Anthony Liguori

We already have a QOM interface for this so let's use it.

---
 hw/e1000.c              |    2 +-
 hw/eepro100.c           |    2 +-
 hw/etraxfs_eth.c        |    2 +-
 hw/hda-audio.c          |    2 +-
 hw/intel-hda.c          |    2 +-
 hw/lan9118.c            |    2 +-
 hw/milkymist-minimac2.c |    2 +-
 hw/mipsnet.c            |    2 +-
 hw/musicpal.c           |    2 +-
 hw/ne2000-isa.c         |    2 +-
 hw/ne2000.c             |    2 +-
 hw/opencores_eth.c      |    2 +-
 hw/pci.c                |    6 +++---
 hw/pcnet.c              |    2 +-
 hw/qdev-properties.c    |   16 ++++++++--------
 hw/qdev.c               |   16 ++++++++--------
 hw/qdev.h               |    2 +-
 hw/rtl8139.c            |    2 +-
 hw/smc91c111.c          |    2 +-
 hw/spapr_llan.c         |    2 +-
 hw/stellaris_enet.c     |    2 +-
 hw/usb-bus.c            |    2 +-
 hw/usb-net.c            |    2 +-
 hw/usb-ohci.c           |    2 +-
 hw/virtio-net.c         |    2 +-
 hw/xilinx_axienet.c     |    2 +-
 hw/xilinx_ethlite.c     |    2 +-
 27 files changed, 43 insertions(+), 43 deletions(-)
hw/e1000.c +1 -1
index f7f72ac..6bab54e 100644
@@ -1177,7 +1177,7 @@ static int pci_e1000_init(PCIDevice *pci_dev)
     d->eeprom_data[EEPROM_CHECKSUM_REG] = checksum;
 
     d->nic = qemu_new_nic(&net_e1000_info, &d->conf,
-                          qdev_get_info(&d->dev.qdev)->name, d->dev.qdev.id, d);
+                          object_get_typename(OBJECT(d)), d->dev.qdev.id, d);
 
     qemu_format_nic_info_str(&d->nic->nc, macaddr);
 
hw/eepro100.c +1 -1
index 81a32b8..f0059c6 100644
@@ -1878,7 +1878,7 @@ static int e100_nic_init(PCIDevice *pci_dev)
     nic_reset(s);
 
     s->nic = qemu_new_nic(&net_eepro100_info, &s->conf,
-                          qdev_get_info(&pci_dev->qdev)->name, pci_dev->qdev.id, s);
+                          object_get_typename(OBJECT(pci_dev)), pci_dev->qdev.id, s);
 
     qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
     TRACE(OTHER, logout("%s\n", s->nic->nc.info_str));
hw/etraxfs_eth.c +1 -1
index 5afa55f..1b6b71d 100644
@@ -605,7 +605,7 @@ static int fs_eth_init(SysBusDevice *dev)
 
 	qemu_macaddr_default_if_unset(&s->conf.macaddr);
 	s->nic = qemu_new_nic(&net_etraxfs_info, &s->conf,
-			      dev->qdev.info->name, dev->qdev.id, s);
+			      object_get_typename(OBJECT(s)), dev->qdev.id, s);
 	qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
 
 	tdk_init(&s->phy);
hw/hda-audio.c +1 -1
index 0bc0a25..8053c74 100644
@@ -777,7 +777,7 @@ static int hda_audio_init(HDACodecDevice *hda, const struct desc_codec *desc)
     uint32_t i, type;
 
     a->desc = desc;
-    a->name = qdev_get_info(&a->hda.qdev)->name;
+    a->name = object_get_typename(OBJECT(a));
     dprint(a, 1, "%s: cad %d\n", __FUNCTION__, a->hda.cad);
 
     AUD_register_card("hda", &a->card);
hw/intel-hda.c +1 -1
index 12dcc84..8cb92d3 100644
@@ -1129,7 +1129,7 @@ static int intel_hda_init(PCIDevice *pci)
     IntelHDAState *d = DO_UPCAST(IntelHDAState, pci, pci);
     uint8_t *conf = d->pci.config;
 
-    d->name = qdev_get_info(&d->pci.qdev)->name;
+    d->name = object_get_typename(OBJECT(d));
 
     pci_config_set_interrupt_pin(conf, 1);
 
hw/lan9118.c +1 -1
index d1b244e..93e1896 100644
@@ -1221,7 +1221,7 @@ static int lan9118_init1(SysBusDevice *dev)
     qemu_macaddr_default_if_unset(&s->conf.macaddr);
 
     s->nic = qemu_new_nic(&net_lan9118_info, &s->conf,
-                          qdev_get_info(&dev->qdev)->name, dev->qdev.id, s);
+                          object_get_typename(OBJECT(dev)), dev->qdev.id, s);
     qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
     s->eeprom[0] = 0xa5;
     for (i = 0; i < 6; i++) {
hw/milkymist-minimac2.c +1 -1
index 7006d29..107ba65 100644
@@ -479,7 +479,7 @@ static int milkymist_minimac2_init(SysBusDevice *dev)
 
     qemu_macaddr_default_if_unset(&s->conf.macaddr);
     s->nic = qemu_new_nic(&net_milkymist_minimac2_info, &s->conf,
-                          dev->qdev.info->name, dev->qdev.id, s);
+                          object_get_typename(OBJECT(dev)), dev->qdev.id, s);
     qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
 
     return 0;
hw/mipsnet.c +1 -1
index 1486833..0f80cfe 100644
@@ -240,7 +240,7 @@ static int mipsnet_sysbus_init(SysBusDevice *dev)
     sysbus_init_irq(dev, &s->irq);
 
     s->nic = qemu_new_nic(&net_mipsnet_info, &s->conf,
-                          qdev_get_info(&dev->qdev)->name, dev->qdev.id, s);
+                          object_get_typename(OBJECT(dev)), dev->qdev.id, s);
     qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
 
     return 0;
hw/musicpal.c +1 -1
index 977ffb6..bca5ee9 100644
@@ -387,7 +387,7 @@ static int mv88w8618_eth_init(SysBusDevice *dev)
 
     sysbus_init_irq(dev, &s->irq);
     s->nic = qemu_new_nic(&net_mv88w8618_info, &s->conf,
-                          dev->qdev.info->name, dev->qdev.id, s);
+                          object_get_typename(OBJECT(dev)), dev->qdev.id, s);
     memory_region_init_io(&s->iomem, &mv88w8618_eth_ops, s, "mv88w8618-eth",
                           MP_ETH_SIZE);
     sysbus_init_mmio(dev, &s->iomem);
hw/ne2000-isa.c +1 -1
index 60dc333..5bc5f2a 100644
@@ -76,7 +76,7 @@ static int isa_ne2000_initfn(ISADevice *dev)
     ne2000_reset(s);
 
     s->nic = qemu_new_nic(&net_ne2000_isa_info, &s->c,
-                          qdev_get_info(&dev->qdev)->name, dev->qdev.id, s);
+                          object_get_typename(OBJECT(dev)), dev->qdev.id, s);
     qemu_format_nic_info_str(&s->nic->nc, s->c.macaddr.a);
 
     return 0;
hw/ne2000.c +1 -1
index d016b8e..b44eab1 100644
@@ -760,7 +760,7 @@ static int pci_ne2000_init(PCIDevice *pci_dev)
     ne2000_reset(s);
 
     s->nic = qemu_new_nic(&net_ne2000_info, &s->c,
-                          qdev_get_info(&pci_dev->qdev)->name, pci_dev->qdev.id, s);
+                          object_get_typename(OBJECT(pci_dev)), pci_dev->qdev.id, s);
     qemu_format_nic_info_str(&s->nic->nc, s->c.macaddr.a);
 
     if (!pci_dev->qdev.hotplugged) {
hw/opencores_eth.c +1 -1
index d4d3529..5161b0c 100644
@@ -717,7 +717,7 @@ static int sysbus_open_eth_init(SysBusDevice *dev)
     sysbus_init_irq(dev, &s->irq);
 
     s->nic = qemu_new_nic(&net_open_eth_info, &s->conf,
-                          qdev_get_info(&s->dev.qdev)->name, s->dev.qdev.id, s);
+                          object_get_typename(OBJECT(s)), s->dev.qdev.id, s);
     return 0;
 }
 
hw/pci.c +3 -3
index 5345079..516da08 100644
@@ -1493,7 +1493,7 @@ static int pci_qdev_init(DeviceState *qdev, DeviceInfo *base)
     if (pci_dev == NULL)
         return -1;
     if (qdev->hotplugged && info->no_hotplug) {
-        qerror_report(QERR_DEVICE_NO_HOTPLUG, info->qdev.name);
+        qerror_report(QERR_DEVICE_NO_HOTPLUG, object_get_typename(OBJECT(pci_dev)));
         do_pci_unregister_device(pci_dev);
         return -1;
     }
@@ -1534,7 +1534,7 @@ static int pci_unplug_device(DeviceState *qdev)
     PCIDeviceInfo *info = container_of(qdev_get_info(qdev), PCIDeviceInfo, qdev);
 
     if (info->no_hotplug) {
-        qerror_report(QERR_DEVICE_NO_HOTPLUG, info->qdev.name);
+        qerror_report(QERR_DEVICE_NO_HOTPLUG, object_get_typename(OBJECT(dev)));
         return -1;
     }
     return dev->bus->hotplug(dev->bus->hotplug_qdev, dev,
@@ -1742,7 +1742,7 @@ static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom)
     if (qdev_get_info(&pdev->qdev)->vmsd)
         snprintf(name, sizeof(name), "%s.rom", qdev_get_info(&pdev->qdev)->vmsd->name);
     else
-        snprintf(name, sizeof(name), "%s.rom", qdev_get_info(&pdev->qdev)->name);
+        snprintf(name, sizeof(name), "%s.rom", object_get_typename(OBJECT(pdev)));
     pdev->has_rom = true;
     memory_region_init_ram(&pdev->rom, name, size);
     vmstate_register_ram(&pdev->rom, &pdev->qdev);
hw/pcnet.c +1 -1
index 1b5d678..41d1ae48 100644
@@ -1719,7 +1719,7 @@ int pcnet_common_init(DeviceState *dev, PCNetState *s, NetClientInfo *info)
     s->poll_timer = qemu_new_timer_ns(vm_clock, pcnet_poll_timer, s);
 
     qemu_macaddr_default_if_unset(&s->conf.macaddr);
-    s->nic = qemu_new_nic(info, &s->conf, qdev_get_info(dev)->name, dev->id, s);
+    s->nic = qemu_new_nic(info, &s->conf, object_get_typename(OBJECT(dev)), dev->id, s);
     qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
 
     add_boot_device_path(s->conf.bootindex, dev, "/ethernet-phy@0");
hw/qdev-properties.c +8 -8
index 4610c3d..89a3e97 100644
@@ -989,16 +989,16 @@ void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev,
     switch (ret) {
     case -EEXIST:
         error_set(errp, QERR_PROPERTY_VALUE_IN_USE,
-                  qdev_get_info(dev)->name, prop->name, value);
+                  object_get_typename(OBJECT(dev)), prop->name, value);
         break;
     default:
     case -EINVAL:
         error_set(errp, QERR_PROPERTY_VALUE_BAD,
-                  qdev_get_info(dev)->name, prop->name, value);
+                  object_get_typename(OBJECT(dev)), prop->name, value);
         break;
     case -ENOENT:
         error_set(errp, QERR_PROPERTY_VALUE_NOT_FOUND,
-                  qdev_get_info(dev)->name, prop->name, value);
+                  object_get_typename(OBJECT(dev)), prop->name, value);
         break;
     case 0:
         break;
@@ -1018,7 +1018,7 @@ int qdev_prop_parse(DeviceState *dev, const char *name, const char *value)
      * removed along with it.
      */
     if (!prop || !prop->info->parse) {
-        qerror_report(QERR_PROPERTY_NOT_FOUND, qdev_get_info(dev)->name, name);
+        qerror_report(QERR_PROPERTY_NOT_FOUND, object_get_typename(OBJECT(dev)), name);
         return -1;
     }
     ret = prop->info->parse(dev, prop, value);
@@ -1039,12 +1039,12 @@ void qdev_prop_set(DeviceState *dev, const char *name, void *src, enum PropertyT
     prop = qdev_prop_find(dev, name);
     if (!prop) {
         fprintf(stderr, "%s: property \"%s.%s\" not found\n",
-                __FUNCTION__, qdev_get_info(dev)->name, name);
+                __FUNCTION__, object_get_typename(OBJECT(dev)), name);
         abort();
     }
     if (prop->info->type != type) {
         fprintf(stderr, "%s: property \"%s.%s\" type mismatch\n",
-                __FUNCTION__, qdev_get_info(dev)->name, name);
+                __FUNCTION__, object_get_typename(OBJECT(dev)), name);
         abort();
     }
     qdev_prop_cpy(dev, prop, src);
@@ -1093,7 +1093,7 @@ int qdev_prop_set_drive(DeviceState *dev, const char *name, BlockDriverState *va
     if (res < 0) {
         error_report("Can't attach drive %s to %s.%s: %s",
                      bdrv_get_device_name(value),
-                     dev->id ? dev->id : qdev_get_info(dev)->name,
+                     dev->id ? dev->id : object_get_typename(OBJECT(dev)),
                      name, strerror(-res));
         return -1;
     }
@@ -1165,7 +1165,7 @@ void qdev_prop_set_globals(DeviceState *dev)
     GlobalProperty *prop;
 
     QTAILQ_FOREACH(prop, &global_props, next) {
-        if (strcmp(qdev_get_info(dev)->name, prop->driver) != 0 &&
+        if (strcmp(object_get_typename(OBJECT(dev)), prop->driver) != 0 &&
             strcmp(qdev_get_info(dev)->bus_info->name, prop->driver) != 0) {
             continue;
         }
hw/qdev.c +8 -8
index 49d26a2..5da94a8 100644
@@ -720,7 +720,7 @@ static void qbus_list_bus(DeviceState *dev)
     const char *sep = " ";
 
     error_printf("child busses at \"%s\":",
-                 dev->id ? dev->id : qdev_get_info(dev)->name);
+                 dev->id ? dev->id : object_get_typename(OBJECT(dev)));
     QLIST_FOREACH(child, &dev->child_bus, sibling) {
         error_printf("%s\"%s\"", sep, child->name);
         sep = ", ";
@@ -735,7 +735,7 @@ static void qbus_list_dev(BusState *bus)
 
     error_printf("devices at \"%s\":", bus->name);
     QTAILQ_FOREACH(dev, &bus->children, sibling) {
-        error_printf("%s\"%s\"", sep, qdev_get_info(dev)->name);
+        error_printf("%s\"%s\"", sep, object_get_typename(OBJECT(dev)));
         if (dev->id)
             error_printf("/\"%s\"", dev->id);
         sep = ", ";
@@ -771,7 +771,7 @@ static DeviceState *qbus_find_dev(BusState *bus, char *elem)
         }
     }
     QTAILQ_FOREACH(dev, &bus->children, sibling) {
-        if (strcmp(qdev_get_info(dev)->name, elem) == 0) {
+        if (strcmp(object_get_typename(OBJECT(dev)), elem) == 0) {
             return dev;
         }
     }
@@ -978,7 +978,7 @@ static void qdev_print_props(Monitor *mon, DeviceState *dev, Property *props,
 static void qdev_print(Monitor *mon, DeviceState *dev, int indent)
 {
     BusState *child;
-    qdev_printf("dev: %s, id \"%s\"\n", qdev_get_info(dev)->name,
+    qdev_printf("dev: %s, id \"%s\"\n", object_get_typename(OBJECT(dev)),
                 dev->id ? dev->id : "");
     indent += 2;
     if (dev->num_gpio_in) {
@@ -1068,7 +1068,7 @@ static int qdev_get_fw_dev_path_helper(DeviceState *dev, char *p, int size)
             l += snprintf(p + l, size - l, "%s", d);
             g_free(d);
         } else {
-            l += snprintf(p + l, size - l, "%s", qdev_get_info(dev)->name);
+            l += snprintf(p + l, size - l, "%s", object_get_typename(OBJECT(dev)));
         }
     }
     l += snprintf(p + l , size - l, "/");
@@ -1090,7 +1090,7 @@ char* qdev_get_fw_dev_path(DeviceState *dev)
 
 char *qdev_get_type(DeviceState *dev, Error **errp)
 {
-    return g_strdup(qdev_get_info(dev)->name);
+    return g_strdup(object_get_typename(OBJECT(dev)));
 }
 
 void qdev_ref(DeviceState *dev)
@@ -1300,7 +1300,7 @@ void qdev_property_add_child(DeviceState *dev, const char *name,
 {
     gchar *type;
 
-    type = g_strdup_printf("child<%s>", qdev_get_info(child)->name);
+    type = g_strdup_printf("child<%s>", object_get_typename(OBJECT(child)));
 
     qdev_property_add(dev, name, type, qdev_get_child_property,
                       NULL, qdev_release_child_property,
@@ -1352,7 +1352,7 @@ static void qdev_set_link_property(DeviceState *dev, Visitor *v, void *opaque,
         if (target) {
             gchar *target_type;
 
-            target_type = g_strdup_printf("link<%s>", qdev_get_info(target)->name);
+            target_type = g_strdup_printf("link<%s>", object_get_typename(OBJECT(target)));
             if (strcmp(target_type, type) == 0) {
                 *child = target;
                 qdev_ref(target);
hw/qdev.h +1 -1
index e13111f..a6af632 100644
@@ -403,7 +403,7 @@ static inline const char *qdev_fw_name(DeviceState *dev)
         return info->alias;
     }
 
-    return info->name;
+    return object_get_typename(OBJECT(dev));
 }
 
 char *qdev_get_fw_dev_path(DeviceState *dev);
hw/rtl8139.c +1 -1
index 16d948e..2b55c7f 100644
@@ -3478,7 +3478,7 @@ static int pci_rtl8139_init(PCIDevice *dev)
     s->eeprom.contents[9] = s->conf.macaddr.a[4] | s->conf.macaddr.a[5] << 8;
 
     s->nic = qemu_new_nic(&net_rtl8139_info, &s->conf,
-                          qdev_get_info(&dev->qdev)->name, dev->qdev.id, s);
+                          object_get_typename(OBJECT(dev)), dev->qdev.id, s);
     qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
 
     s->cplus_txbuffer = NULL;
hw/smc91c111.c +1 -1
index b83a893..4a68f6b 100644
@@ -752,7 +752,7 @@ static int smc91c111_init1(SysBusDevice *dev)
     sysbus_init_irq(dev, &s->irq);
     qemu_macaddr_default_if_unset(&s->conf.macaddr);
     s->nic = qemu_new_nic(&net_smc91c111_info, &s->conf,
-                          qdev_get_info(&dev->qdev)->name, dev->qdev.id, s);
+                          object_get_typename(OBJECT(dev)), dev->qdev.id, s);
     qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
     /* ??? Save/restore.  */
     return 0;
hw/spapr_llan.c +1 -1
index 45674c4..91003cc 100644
@@ -189,7 +189,7 @@ static int spapr_vlan_init(VIOsPAPRDevice *sdev)
     qemu_macaddr_default_if_unset(&dev->nicconf.macaddr);
 
     dev->nic = qemu_new_nic(&net_spapr_vlan_info, &dev->nicconf,
-                            sdev->qdev.info->name, sdev->qdev.id, dev);
+                            object_get_typename(OBJECT(sdev)), sdev->qdev.id, dev);
     qemu_format_nic_info_str(&dev->nic->nc, dev->nicconf.macaddr.a);
 
     return 0;
hw/stellaris_enet.c +1 -1
index 866c9a2..ecd750c 100644
@@ -411,7 +411,7 @@ static int stellaris_enet_init(SysBusDevice *dev)
     qemu_macaddr_default_if_unset(&s->conf.macaddr);
 
     s->nic = qemu_new_nic(&net_stellaris_enet_info, &s->conf,
-                          dev->qdev.info->name, dev->qdev.id, s);
+                          object_get_typename(OBJECT(dev)), dev->qdev.id, s);
     qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
 
     stellaris_enet_reset(s);
hw/usb-bus.c +1 -1
index 3b80d5e..9b67f18 100644
@@ -250,7 +250,7 @@ int usb_claim_port(USBDevice *dev)
             return -1;
         }
     } else {
-        if (bus->nfree == 1 && strcmp(qdev_get_info(&dev->qdev)->name, "usb-hub") != 0) {
+        if (bus->nfree == 1 && strcmp(object_get_typename(OBJECT(dev)), "usb-hub") != 0) {
             /* Create a new hub and chain it on */
             usb_create_simple(bus, "usb-hub");
         }
hw/usb-net.c +1 -1
index 086aa7e..fd4106b 100644
@@ -1337,7 +1337,7 @@ static int usb_net_initfn(USBDevice *dev)
 
     qemu_macaddr_default_if_unset(&s->conf.macaddr);
     s->nic = qemu_new_nic(&net_usbnet_info, &s->conf,
-                          qdev_get_info(&s->dev.qdev)->name, s->dev.qdev.id, s);
+                          object_get_typename(OBJECT(s)), s->dev.qdev.id, s);
     qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
     snprintf(s->usbstring_mac, sizeof(s->usbstring_mac),
              "%02x%02x%02x%02x%02x%02x",
hw/usb-ohci.c +1 -1
index afa3274..2df6a6e 100644
@@ -1777,7 +1777,7 @@ static int usb_ohci_init(OHCIState *ohci, DeviceState *dev,
     memory_region_init_io(&ohci->mem, &ohci_mem_ops, ohci, "ohci", 256);
     ohci->localmem_base = localmem_base;
 
-    ohci->name = qdev_get_info(dev)->name;
+    ohci->name = object_get_typename(OBJECT(dev));
     usb_packet_init(&ohci->usb_packet);
 
     ohci->async_td = 0;
hw/virtio-net.c +1 -1
index 6c785d0..bc5e3a8 100644
@@ -1030,7 +1030,7 @@ VirtIODevice *virtio_net_init(DeviceState *dev, NICConf *conf,
     memcpy(&n->mac[0], &conf->macaddr, sizeof(n->mac));
     n->status = VIRTIO_NET_S_LINK_UP;
 
-    n->nic = qemu_new_nic(&net_virtio_info, conf, qdev_get_info(dev)->name, dev->id, n);
+    n->nic = qemu_new_nic(&net_virtio_info, conf, object_get_typename(OBJECT(dev)), dev->id, n);
 
     qemu_format_nic_info_str(&n->nic->nc, conf->macaddr.a);
 
hw/xilinx_axienet.c +1 -1
index a2eb3e6..e713248 100644
@@ -856,7 +856,7 @@ static int xilinx_enet_init(SysBusDevice *dev)
 
     qemu_macaddr_default_if_unset(&s->conf.macaddr);
     s->nic = qemu_new_nic(&net_xilinx_enet_info, &s->conf,
-                          dev->qdev.info->name, dev->qdev.id, s);
+                          object_get_typename(OBJECT(dev)), dev->qdev.id, s);
     qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
 
     tdk_init(&s->TEMAC.phy);
hw/xilinx_ethlite.c +1 -1
index 6777254..de595f4 100644
@@ -221,7 +221,7 @@ static int xilinx_ethlite_init(SysBusDevice *dev)
 
     qemu_macaddr_default_if_unset(&s->conf.macaddr);
     s->nic = qemu_new_nic(&net_xilinx_ethlite_info, &s->conf,
-                          dev->qdev.info->name, dev->qdev.id, s);
+                          object_get_typename(OBJECT(dev)), dev->qdev.id, s);
     qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
     return 0;
 }
Signature · 1 line
1.7.4.1
#19 lore raw

PATCH v3 8/28 qdev: use a wrapper to access reset and promote reset to a class method

In reply to Anthony Liguori
---
 hw/intel-hda.c  |    4 +---
 hw/lsi53c895a.c |    2 +-
 hw/qdev.c       |   22 +++++++++++++++++-----
 hw/qdev.h       |    8 ++++++++
 4 files changed, 27 insertions(+), 9 deletions(-)
hw/intel-hda.c +1 -3
index 8cb92d3..6e1c5de 100644
@@ -1116,9 +1116,7 @@ static void intel_hda_reset(DeviceState *dev)
     /* reset codecs */
     QTAILQ_FOREACH(qdev, &d->codecs.qbus.children, sibling) {
         cdev = DO_UPCAST(HDACodecDevice, qdev, qdev);
-        if (qdev_get_info(qdev)->reset) {
-            qdev_get_info(qdev)->reset(qdev);
-        }
+        device_reset(DEVICE(cdev));
         d->state_sts |= (1 << cdev->cad);
     }
     intel_hda_update_irq(d);
hw/lsi53c895a.c +1 -1
index 9f475e0..3a87171 100644
@@ -1681,7 +1681,7 @@ static void lsi_reg_writeb(LSIState *s, int offset, uint8_t val)
                 DeviceState *dev;
 
                 QTAILQ_FOREACH(dev, &s->bus.qbus.children, sibling) {
-                    qdev_get_info(dev)->reset(dev);
+                    device_reset(dev);
                 }
                 s->sstat0 |= LSI_SSTAT0_RST;
                 lsi_script_scsi_interrupt(s, LSI_SIST0_RST, 0);
hw/qdev.c +17 -5
index 5da94a8..a80ca7c 100644
@@ -48,7 +48,12 @@ static BusState *qbus_find(const char *path);
 static void qdev_subclass_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
+
     dc->info = data;
+    dc->reset = dc->info->reset;
+
+    /* Poison to try to detect future uses */
+    dc->info->reset = NULL;
 }
 
 DeviceInfo *qdev_get_info(DeviceState *dev)
@@ -378,8 +383,8 @@ int qdev_init(DeviceState *dev)
                                        dev->alias_required_for_version);
     }
     dev->state = DEV_STATE_INITIALIZED;
-    if (dev->hotplugged && qdev_get_info(dev)->reset) {
-        qdev_get_info(dev)->reset(dev);
+    if (dev->hotplugged) {
+        device_reset(dev);
     }
     return 0;
 }
@@ -407,9 +412,7 @@ int qdev_unplug(DeviceState *dev)
 
 static int qdev_reset_one(DeviceState *dev, void *opaque)
 {
-    if (qdev_get_info(dev)->reset) {
-        qdev_get_info(dev)->reset(dev);
-    }
+    device_reset(dev);
 
     return 0;
 }
@@ -1593,6 +1596,15 @@ void qdev_machine_init(void)
     qdev_get_peripheral();
 }
 
+void device_reset(DeviceState *dev)
+{
+    DeviceClass *klass = DEVICE_GET_CLASS(dev);
+
+    if (klass->reset) {
+        klass->reset(dev);
+    }
+}
+
 static TypeInfo device_type_info = {
     .name = TYPE_DEVICE,
     .parent = TYPE_OBJECT,
hw/qdev.h +8 -0
index a6af632..f3c9219 100644
@@ -75,6 +75,7 @@ typedef struct DeviceProperty
 typedef struct DeviceClass {
     ObjectClass parent_class;
     DeviceInfo *info;
+    void (*reset)(DeviceState *dev);
 } DeviceClass;
 
 /* This structure should not be accessed directly.  We declare it here
@@ -647,4 +648,11 @@ char *qdev_get_type(DeviceState *dev, Error **errp);
  */
 void qdev_machine_init(void);
 
+/**
+ * @device_reset
+ *
+ * Reset a single device (by calling the reset method).
+ */
+void device_reset(DeviceState *dev);
+
 #endif
Signature · 1 line
1.7.4.1
#20 lore raw

PATCH v3 9/28 qdev: add a interface to register subclasses

In reply to Anthony Liguori

In order to introduce inheritance while still using the qdev registration interfaces, we need to be able to use a parent other than TYPE_DEVICE. Add a new interface that allows this.

---
 hw/qdev.c |    9 +++++++--
 hw/qdev.h |    1 +
 2 files changed, 8 insertions(+), 2 deletions(-)
hw/qdev.c +7 -2
index a80ca7c..c4b5284 100644
@@ -61,7 +61,7 @@ DeviceInfo *qdev_get_info(DeviceState *dev)
     return DEVICE_GET_CLASS(dev)->info;
 }
 
-void qdev_register(DeviceInfo *info)
+void qdev_register_subclass(DeviceInfo *info, const char *parent)
 {
     TypeInfo type_info = {};
 
@@ -69,7 +69,7 @@ void qdev_register(DeviceInfo *info)
     assert(!info->next);
 
     type_info.name = info->name;
-    type_info.parent = TYPE_DEVICE;
+    type_info.parent = parent;
     type_info.instance_size = info->size;
     type_info.class_init = qdev_subclass_init;
     type_info.class_data = info;
@@ -80,6 +80,11 @@ void qdev_register(DeviceInfo *info)
     device_info_list = info;
 }
 
+void qdev_register(DeviceInfo *info)
+{
+    qdev_register_subclass(info, TYPE_DEVICE);
+}
+
 static DeviceInfo *qdev_find_info(BusInfo *bus_info, const char *name)
 {
     DeviceInfo *info;
hw/qdev.h +1 -0
index f3c9219..48f80a5 100644
@@ -241,6 +241,7 @@ struct DeviceInfo {
 extern DeviceInfo *device_info_list;
 
 void qdev_register(DeviceInfo *info);
+void qdev_register_subclass(DeviceInfo *info, const char *parent);
 
 /* Register device properties.  */
 /* GPIO inputs also double as IRQ sinks.  */
Signature · 1 line
1.7.4.1
#21 lore raw

PATCH v3 10/28 qdev: add class_init to DeviceInfo

In reply to Anthony Liguori

Since we are still dynamically creating TypeInfo, we need to chain the class_init function in order to be able to make use of it within subclasses of TYPE_DEVICE.

This will disappear once we register TypeInfos directly.

---
 hw/qdev.c |    4 ++++
 hw/qdev.h |    5 +++++
 2 files changed, 9 insertions(+), 0 deletions(-)
hw/qdev.c +4 -0
index c4b5284..81996bb 100644
@@ -54,6 +54,10 @@ static void qdev_subclass_init(ObjectClass *klass, void *data)
 
     /* Poison to try to detect future uses */
     dc->info->reset = NULL;
+
+    if (dc->info->class_init) {
+        dc->info->class_init(klass, data);
+    }
 }
 
 DeviceInfo *qdev_get_info(DeviceState *dev)
hw/qdev.h +5 -0
index 48f80a5..c9572a5 100644
@@ -231,6 +231,11 @@ struct DeviceInfo {
     /* device state */
     const VMStateDescription *vmsd;
 
+    /**
+     * See #TypeInfo::class_init()
+     */
+    void (*class_init)(ObjectClass *klass, void *data);
+
     /* Private to qdev / bus.  */
     qdev_initfn init;
     qdev_event unplug;
Signature · 1 line
1.7.4.1
#22 lore raw

PATCH v3 11/28 qdev: prepare source tree for code conversion

In reply to Anthony Liguori

These are various small stylistic changes which help make things more consistent such that the automated conversion script can be simpler.

It's not necessary to agree or disagree with these style changes because all of this code is going to be rewritten by the patch monkey script anyway.

---
 hw/9pfs/virtio-9p-device.c |    3 +-
 hw/es1370.c                |    5 -
 hw/ide/cmd646.c            |   33 ++++-----
 hw/ide/ich.c               |   30 +++----
 hw/ide/piix.c              |   70 +++++++++---------
 hw/marvell_88w8618_audio.c |    8 +--
 hw/piix4.c                 |   29 +++----
 hw/piix_pci.c              |   86 +++++++++++-----------
 hw/qxl.c                   |    8 +-
 hw/spapr_llan.c            |    4 +-
 hw/spapr_vscsi.c           |    4 +-
 hw/spapr_vty.c             |    6 +-
 hw/usb-ehci.c              |   49 ++++++------
 hw/usb-uhci.c              |  107 +++++++++++++++------------
 hw/virtio-pci.c            |  174 ++++++++++++++++++++++----------------------
 15 files changed, 304 insertions(+), 312 deletions(-)
hw/9pfs/virtio-9p-device.c +1 -2
index 642d5e2..1325f2f 100644
@@ -172,8 +172,7 @@ static PCIDeviceInfo virtio_9p_info = {
     .revision  = VIRTIO_PCI_ABI_VERSION,
     .class_id  = 0x2,
     .qdev.props = (Property[]) {
-        DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
-                        VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
+        DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
         DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
         DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
         DEFINE_PROP_STRING("mount_tag", VirtIOPCIProxy, fsconf.tag),
hw/es1370.c +0 -5
index 6a3ba55..3527eb6 100644
@@ -1041,13 +1041,8 @@ static PCIDeviceInfo es1370_info = {
     .vendor_id    = PCI_VENDOR_ID_ENSONIQ,
     .device_id    = PCI_DEVICE_ID_ENSONIQ_ES1370,
     .class_id     = PCI_CLASS_MULTIMEDIA_AUDIO,
-#if 1
     .subsystem_vendor_id = 0x4942,
     .subsystem_id = 0x4c4c,
-#else
-    .subsystem_vendor_id = 0x1274,
-    .subsystem_id = 0x1371,
-#endif
 };
 
 static void es1370_register (void)
hw/ide/cmd646.c +15 -18
index 5fe98b1..99e7e6f 100644
@@ -325,27 +325,24 @@ void pci_cmd646_ide_init(PCIBus *bus, DriveInfo **hd_table,
     pci_ide_create_devs(dev, hd_table);
 }
 
-static PCIDeviceInfo cmd646_ide_info[] = {
-    {
-        .qdev.name    = "cmd646-ide",
-        .qdev.size    = sizeof(PCIIDEState),
-        .init         = pci_cmd646_ide_initfn,
-        .exit         = pci_cmd646_ide_exitfn,
-        .vendor_id    = PCI_VENDOR_ID_CMD,
-        .device_id    = PCI_DEVICE_ID_CMD_646,
-        .revision     = 0x07, // IDE controller revision
-        .class_id     = PCI_CLASS_STORAGE_IDE,
-        .qdev.props   = (Property[]) {
-            DEFINE_PROP_UINT32("secondary", PCIIDEState, secondary, 0),
-            DEFINE_PROP_END_OF_LIST(),
-        },
-    },{
-        /* end of list */
-    }
+static PCIDeviceInfo cmd646_ide_info = {
+    .qdev.name    = "cmd646-ide",
+    .qdev.size    = sizeof(PCIIDEState),
+    .init         = pci_cmd646_ide_initfn,
+    .exit         = pci_cmd646_ide_exitfn,
+    .vendor_id    = PCI_VENDOR_ID_CMD,
+    .device_id    = PCI_DEVICE_ID_CMD_646,
+    /* IDE controller revision */
+    .revision     = 0x07,
+    .class_id     = PCI_CLASS_STORAGE_IDE,
+    .qdev.props   = (Property[]) {
+        DEFINE_PROP_UINT32("secondary", PCIIDEState, secondary, 0),
+        DEFINE_PROP_END_OF_LIST(),
+    },
 };
 
 static void cmd646_ide_register(void)
 {
-    pci_qdev_register_many(cmd646_ide_info);
+    pci_qdev_register(&cmd646_ide_info);
 }
 device_init(cmd646_ide_register);
hw/ide/ich.c +13 -17
index 3f7510f..e6421e2 100644
@@ -146,26 +146,22 @@ static void pci_ich9_write_config(PCIDevice *pci, uint32_t addr,
     msi_write_config(pci, addr, val, len);
 }
 
-static PCIDeviceInfo ich_ahci_info[] = {
-    {
-        .qdev.name    = "ich9-ahci",
-        .qdev.alias   = "ahci",
-        .qdev.size    = sizeof(AHCIPCIState),
-        .qdev.vmsd    = &vmstate_ahci,
-        .init         = pci_ich9_ahci_init,
-        .exit         = pci_ich9_uninit,
-        .config_write = pci_ich9_write_config,
-        .vendor_id    = PCI_VENDOR_ID_INTEL,
-        .device_id    = PCI_DEVICE_ID_INTEL_82801IR,
-        .revision     = 0x02,
-        .class_id     = PCI_CLASS_STORAGE_SATA,
-    },{
-        /* end of list */
-    }
+static PCIDeviceInfo ich_ahci_info = {
+    .qdev.name    = "ich9-ahci",
+    .qdev.alias   = "ahci",
+    .qdev.size    = sizeof(AHCIPCIState),
+    .qdev.vmsd    = &vmstate_ahci,
+    .init         = pci_ich9_ahci_init,
+    .exit         = pci_ich9_uninit,
+    .config_write = pci_ich9_write_config,
+    .vendor_id    = PCI_VENDOR_ID_INTEL,
+    .device_id    = PCI_DEVICE_ID_INTEL_82801IR,
+    .revision     = 0x02,
+    .class_id     = PCI_CLASS_STORAGE_SATA,
 };
 
 static void ich_ahci_register(void)
 {
-    pci_qdev_register_many(ich_ahci_info);
+    pci_qdev_register(&ich_ahci_info);
 }
 device_init(ich_ahci_register);
hw/ide/piix.c +36 -34

79 lines not on this page · raw message

hw/marvell_88w8618_audio.c +2 -6
index 0cd8410..409b1eb 100644
@@ -50,7 +50,7 @@ typedef struct mv88w8618_audio_state {
     uint32_t play_pos;
     uint32_t last_free;
     uint32_t clock_div;
-    DeviceState *wm;
+    void *wm;
 } mv88w8618_audio_state;
 
 static void mv88w8618_audio_callback(void *opaque, int free_out, int free_in)
@@ -279,11 +279,7 @@ static SysBusDeviceInfo mv88w8618_audio_info = {
     .qdev.reset = mv88w8618_audio_reset,
     .qdev.vmsd  = &mv88w8618_audio_vmsd,
     .qdev.props = (Property[]) {
-        {
-            .name   = "wm8750",
-            .info   = &qdev_prop_ptr,
-            .offset = offsetof(mv88w8618_audio_state, wm),
-        },
+        DEFINE_PROP_PTR("wm8750", mv88w8618_audio_state, wm),
         {/* end of list */}
     }
 };
hw/piix4.c +13 -16
index 51af459..130dfd1 100644
@@ -102,25 +102,22 @@ int piix4_init(PCIBus *bus, ISABus **isa_bus, int devfn)
     return d->devfn;
 }
 
-static PCIDeviceInfo piix4_info[] = {
-    {
-        .qdev.name    = "PIIX4",
-        .qdev.desc    = "ISA bridge",
-        .qdev.size    = sizeof(PIIX4State),
-        .qdev.vmsd    = &vmstate_piix4,
-        .qdev.no_user = 1,
-        .no_hotplug   = 1,
-        .init         = piix4_initfn,
-        .vendor_id    = PCI_VENDOR_ID_INTEL,
-        .device_id    = PCI_DEVICE_ID_INTEL_82371AB_0, // 82371AB/EB/MB PIIX4 PCI-to-ISA bridge
-        .class_id     = PCI_CLASS_BRIDGE_ISA,
-    },{
-        /* end of list */
-    }
+static PCIDeviceInfo piix4_info = {
+    .qdev.name    = "PIIX4",
+    .qdev.desc    = "ISA bridge",
+    .qdev.size    = sizeof(PIIX4State),
+    .qdev.vmsd    = &vmstate_piix4,
+    .qdev.no_user = 1,
+    .no_hotplug   = 1,
+    .init         = piix4_initfn,
+    .vendor_id    = PCI_VENDOR_ID_INTEL,
+    /* 82371AB/EB/MB PIIX4 PCI-to-ISA bridge */
+    .device_id    = PCI_DEVICE_ID_INTEL_82371AB_0,
+    .class_id     = PCI_CLASS_BRIDGE_ISA,
 };
 
 static void piix4_register(void)
 {
-    pci_qdev_register_many(piix4_info);
+    pci_qdev_register(&piix4_info);
 }
 device_init(piix4_register);
hw/piix_pci.c +44 -42

98 lines not on this page · raw message

hw/qxl.c +4 -4
index bdd36f9..2a716bf 100644
@@ -1827,7 +1827,7 @@ static Property qxl_properties[] = {
         DEFINE_PROP_END_OF_LIST(),
 };
 
-static PCIDeviceInfo qxl_info_primary = {
+static PCIDeviceInfo qxl_primary_info = {
     .qdev.name    = "qxl-vga",
     .qdev.desc    = "Spice QXL GPU (primary, vga compatible)",
     .qdev.size    = sizeof(PCIQXLDevice),
@@ -1842,7 +1842,7 @@ static PCIDeviceInfo qxl_info_primary = {
     .qdev.props   = qxl_properties,
 };
 
-static PCIDeviceInfo qxl_info_secondary = {
+static PCIDeviceInfo qxl_secondary_info = {
     .qdev.name    = "qxl",
     .qdev.desc    = "Spice QXL GPU (secondary)",
     .qdev.size    = sizeof(PCIQXLDevice),
@@ -1857,8 +1857,8 @@ static PCIDeviceInfo qxl_info_secondary = {
 
 static void qxl_register(void)
 {
-    pci_qdev_register(&qxl_info_primary);
-    pci_qdev_register(&qxl_info_secondary);
+    pci_qdev_register(&qxl_primary_info);
+    pci_qdev_register(&qxl_secondary_info);
 }
 
 device_init(qxl_register);
hw/spapr_llan.c +2 -2
index 91003cc..b9a5afc 100644
@@ -474,7 +474,7 @@ static target_ulong h_multicast_ctrl(CPUState *env, sPAPREnvironment *spapr,
     return H_SUCCESS;
 }
 
-static VIOsPAPRDeviceInfo spapr_vlan = {
+static VIOsPAPRDeviceInfo spapr_vlan_info = {
     .init = spapr_vlan_init,
     .devnode = spapr_vlan_devnode,
     .dt_name = "l-lan",
@@ -492,12 +492,12 @@ static VIOsPAPRDeviceInfo spapr_vlan = {
 
 static void spapr_vlan_register(void)
 {
-    spapr_vio_bus_register_withprop(&spapr_vlan);
     spapr_register_hypercall(H_REGISTER_LOGICAL_LAN, h_register_logical_lan);
     spapr_register_hypercall(H_FREE_LOGICAL_LAN, h_free_logical_lan);
     spapr_register_hypercall(H_SEND_LOGICAL_LAN, h_send_logical_lan);
     spapr_register_hypercall(H_ADD_LOGICAL_LAN_BUFFER,
                              h_add_logical_lan_buffer);
     spapr_register_hypercall(H_MULTICAST_CTRL, h_multicast_ctrl);
+    spapr_vio_bus_register_withprop(&spapr_vlan_info);
 }
 device_init(spapr_vlan_register);
hw/spapr_vscsi.c +2 -2
index 00e2d2d..21d946e 100644
@@ -947,7 +947,7 @@ static int spapr_vscsi_devnode(VIOsPAPRDevice *dev, void *fdt, int node_off)
     return 0;
 }
 
-static VIOsPAPRDeviceInfo spapr_vscsi = {
+static VIOsPAPRDeviceInfo spapr_vscsi_info = {
     .init = spapr_vscsi_init,
     .devnode = spapr_vscsi_devnode,
     .dt_name = "v-scsi",
@@ -964,6 +964,6 @@ static VIOsPAPRDeviceInfo spapr_vscsi = {
 
 static void spapr_vscsi_register(void)
 {
-    spapr_vio_bus_register_withprop(&spapr_vscsi);
+    spapr_vio_bus_register_withprop(&spapr_vscsi_info);
 }
 device_init(spapr_vscsi_register);
hw/spapr_vty.c +3 -3
index 181dd0e..3d5c579 100644
@@ -135,7 +135,7 @@ void spapr_vty_create(VIOsPAPRBus *bus, uint32_t reg, CharDriverState *chardev)
     qdev_init_nofail(dev);
 }
 
-static VIOsPAPRDeviceInfo spapr_vty = {
+static VIOsPAPRDeviceInfo spapr_vty_info = {
     .init = spapr_vty_init,
     .dt_name = "vty",
     .dt_type = "serial",
@@ -163,7 +163,7 @@ VIOsPAPRDevice *spapr_vty_get_default(VIOsPAPRBus *bus)
     selected = NULL;
     QTAILQ_FOREACH(iter, &bus->bus.children, sibling) {
         /* Only look at VTY devices */
-        if (qdev_get_info(iter) != &spapr_vty.qdev) {
+        if (qdev_get_info(iter) != &spapr_vty_info.qdev) {
             continue;
         }
 
@@ -203,8 +203,8 @@ static VIOsPAPRDevice *vty_lookup(sPAPREnvironment *spapr, target_ulong reg)
 
 static void spapr_vty_register(void)
 {
-    spapr_vio_bus_register_withprop(&spapr_vty);
     spapr_register_hypercall(H_PUT_TERM_CHAR, h_put_term_char);
     spapr_register_hypercall(H_GET_TERM_CHAR, h_get_term_char);
+    spapr_vio_bus_register_withprop(&spapr_vty_info);
 }
 device_init(spapr_vty_register);
hw/usb-ehci.c +24 -25

61 lines not on this page · raw message

hw/usb-uhci.c +59 -48

129 lines not on this page · raw message

hw/virtio-pci.c +86 -88

184 lines not on this page · raw message

Signature · 1 line
1.7.4.1
#23 lore raw

PATCH 1/3 es1370: Drop dead code

---
Anthony, as requested before, please pull these out of the stylistic changes.

 hw/es1370.c |    5 -----
 1 files changed, 0 insertions(+), 5 deletions(-)
hw/es1370.c +0 -5
index 6a3ba55..3527eb6 100644
@@ -1041,13 +1041,8 @@ static PCIDeviceInfo es1370_info = {
     .vendor_id    = PCI_VENDOR_ID_ENSONIQ,
     .device_id    = PCI_DEVICE_ID_ENSONIQ_ES1370,
     .class_id     = PCI_CLASS_MULTIMEDIA_AUDIO,
-#if 1
     .subsystem_vendor_id = 0x4942,
     .subsystem_id = 0x4c4c,
-#else
-    .subsystem_vendor_id = 0x1274,
-    .subsystem_id = 0x1371,
-#endif
 };
 
 static void es1370_register (void)
Signature · 1 line
1.7.7
#24 lore raw

PATCH 2/3 marvell_88w8618_audio: Use DEFINE_PROP_* macros

[AF: Use DEFINE_PROP_END_OF_LIST() as well]

---
If we're touching it, let's do it right. Causes a trivial merge conflict in [PATCH 27/28] sysbus: apic: ioapic: convert to QEMU Object Model.

 hw/marvell_88w8618_audio.c |   10 +++-------
 1 files changed, 3 insertions(+), 7 deletions(-)
hw/marvell_88w8618_audio.c +3 -7
index 0cd8410..8b6a5c0 100644
@@ -50,7 +50,7 @@ typedef struct mv88w8618_audio_state {
     uint32_t play_pos;
     uint32_t last_free;
     uint32_t clock_div;
-    DeviceState *wm;
+    void *wm;
 } mv88w8618_audio_state;
 
 static void mv88w8618_audio_callback(void *opaque, int free_out, int free_in)
@@ -279,12 +279,8 @@ static SysBusDeviceInfo mv88w8618_audio_info = {
     .qdev.reset = mv88w8618_audio_reset,
     .qdev.vmsd  = &mv88w8618_audio_vmsd,
     .qdev.props = (Property[]) {
-        {
-            .name   = "wm8750",
-            .info   = &qdev_prop_ptr,
-            .offset = offsetof(mv88w8618_audio_state, wm),
-        },
-        {/* end of list */}
+        DEFINE_PROP_PTR("wm8750", mv88w8618_audio_state, wm),
+        DEFINE_PROP_END_OF_LIST()
     }
 };
 
Signature · 1 line
1.7.7
#25 lore raw

PATCH 3/3 qdev: prepare source tree for code conversion

In reply to Andreas Färber

From: Anthony Liguori <[email protected]>

These are various small stylistic changes which help make things more consistent such that the automated conversion script can be simpler.

It's not necessary to agree or disagree with these style changes because all of this code is going to be rewritten by the patch monkey script anyway.

---
 hw/9pfs/virtio-9p-device.c |    3 +-
 hw/ide/cmd646.c            |   33 ++++-----
 hw/ide/ich.c               |   30 +++----
 hw/ide/piix.c              |   70 +++++++++---------
 hw/piix4.c                 |   29 +++----
 hw/piix_pci.c              |   86 +++++++++++-----------
 hw/qxl.c                   |    8 +-
 hw/spapr_llan.c            |    4 +-
 hw/spapr_vscsi.c           |    4 +-
 hw/spapr_vty.c             |    6 +-
 hw/usb-ehci.c              |   49 ++++++------
 hw/usb-uhci.c              |  107 +++++++++++++++------------
 hw/virtio-pci.c            |  174 ++++++++++++++++++++++----------------------
 13 files changed, 302 insertions(+), 301 deletions(-)
hw/9pfs/virtio-9p-device.c +1 -2
index 642d5e2..1325f2f 100644
@@ -172,8 +172,7 @@ static PCIDeviceInfo virtio_9p_info = {
     .revision  = VIRTIO_PCI_ABI_VERSION,
     .class_id  = 0x2,
     .qdev.props = (Property[]) {
-        DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
-                        VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
+        DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
         DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
         DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
         DEFINE_PROP_STRING("mount_tag", VirtIOPCIProxy, fsconf.tag),
hw/ide/cmd646.c +15 -18
index 5fe98b1..99e7e6f 100644
@@ -325,27 +325,24 @@ void pci_cmd646_ide_init(PCIBus *bus, DriveInfo **hd_table,
     pci_ide_create_devs(dev, hd_table);
 }
 
-static PCIDeviceInfo cmd646_ide_info[] = {
-    {
-        .qdev.name    = "cmd646-ide",
-        .qdev.size    = sizeof(PCIIDEState),
-        .init         = pci_cmd646_ide_initfn,
-        .exit         = pci_cmd646_ide_exitfn,
-        .vendor_id    = PCI_VENDOR_ID_CMD,
-        .device_id    = PCI_DEVICE_ID_CMD_646,
-        .revision     = 0x07, // IDE controller revision
-        .class_id     = PCI_CLASS_STORAGE_IDE,
-        .qdev.props   = (Property[]) {
-            DEFINE_PROP_UINT32("secondary", PCIIDEState, secondary, 0),
-            DEFINE_PROP_END_OF_LIST(),
-        },
-    },{
-        /* end of list */
-    }
+static PCIDeviceInfo cmd646_ide_info = {
+    .qdev.name    = "cmd646-ide",
+    .qdev.size    = sizeof(PCIIDEState),
+    .init         = pci_cmd646_ide_initfn,
+    .exit         = pci_cmd646_ide_exitfn,
+    .vendor_id    = PCI_VENDOR_ID_CMD,
+    .device_id    = PCI_DEVICE_ID_CMD_646,
+    /* IDE controller revision */
+    .revision     = 0x07,
+    .class_id     = PCI_CLASS_STORAGE_IDE,
+    .qdev.props   = (Property[]) {
+        DEFINE_PROP_UINT32("secondary", PCIIDEState, secondary, 0),
+        DEFINE_PROP_END_OF_LIST(),
+    },
 };
 
 static void cmd646_ide_register(void)
 {
-    pci_qdev_register_many(cmd646_ide_info);
+    pci_qdev_register(&cmd646_ide_info);
 }
 device_init(cmd646_ide_register);
hw/ide/ich.c +13 -17
index 3f7510f..e6421e2 100644
@@ -146,26 +146,22 @@ static void pci_ich9_write_config(PCIDevice *pci, uint32_t addr,
     msi_write_config(pci, addr, val, len);
 }
 
-static PCIDeviceInfo ich_ahci_info[] = {
-    {
-        .qdev.name    = "ich9-ahci",
-        .qdev.alias   = "ahci",
-        .qdev.size    = sizeof(AHCIPCIState),
-        .qdev.vmsd    = &vmstate_ahci,
-        .init         = pci_ich9_ahci_init,
-        .exit         = pci_ich9_uninit,
-        .config_write = pci_ich9_write_config,
-        .vendor_id    = PCI_VENDOR_ID_INTEL,
-        .device_id    = PCI_DEVICE_ID_INTEL_82801IR,
-        .revision     = 0x02,
-        .class_id     = PCI_CLASS_STORAGE_SATA,
-    },{
-        /* end of list */
-    }
+static PCIDeviceInfo ich_ahci_info = {
+    .qdev.name    = "ich9-ahci",
+    .qdev.alias   = "ahci",
+    .qdev.size    = sizeof(AHCIPCIState),
+    .qdev.vmsd    = &vmstate_ahci,
+    .init         = pci_ich9_ahci_init,
+    .exit         = pci_ich9_uninit,
+    .config_write = pci_ich9_write_config,
+    .vendor_id    = PCI_VENDOR_ID_INTEL,
+    .device_id    = PCI_DEVICE_ID_INTEL_82801IR,
+    .revision     = 0x02,
+    .class_id     = PCI_CLASS_STORAGE_SATA,
 };
 
 static void ich_ahci_register(void)
 {
-    pci_qdev_register_many(ich_ahci_info);
+    pci_qdev_register(&ich_ahci_info);
 }
 device_init(ich_ahci_register);
hw/ide/piix.c +36 -34

79 lines not on this page · raw message

hw/piix4.c +13 -16
index 51af459..130dfd1 100644
@@ -102,25 +102,22 @@ int piix4_init(PCIBus *bus, ISABus **isa_bus, int devfn)
     return d->devfn;
 }
 
-static PCIDeviceInfo piix4_info[] = {
-    {
-        .qdev.name    = "PIIX4",
-        .qdev.desc    = "ISA bridge",
-        .qdev.size    = sizeof(PIIX4State),
-        .qdev.vmsd    = &vmstate_piix4,
-        .qdev.no_user = 1,
-        .no_hotplug   = 1,
-        .init         = piix4_initfn,
-        .vendor_id    = PCI_VENDOR_ID_INTEL,
-        .device_id    = PCI_DEVICE_ID_INTEL_82371AB_0, // 82371AB/EB/MB PIIX4 PCI-to-ISA bridge
-        .class_id     = PCI_CLASS_BRIDGE_ISA,
-    },{
-        /* end of list */
-    }
+static PCIDeviceInfo piix4_info = {
+    .qdev.name    = "PIIX4",
+    .qdev.desc    = "ISA bridge",
+    .qdev.size    = sizeof(PIIX4State),
+    .qdev.vmsd    = &vmstate_piix4,
+    .qdev.no_user = 1,
+    .no_hotplug   = 1,
+    .init         = piix4_initfn,
+    .vendor_id    = PCI_VENDOR_ID_INTEL,
+    /* 82371AB/EB/MB PIIX4 PCI-to-ISA bridge */
+    .device_id    = PCI_DEVICE_ID_INTEL_82371AB_0,
+    .class_id     = PCI_CLASS_BRIDGE_ISA,
 };
 
 static void piix4_register(void)
 {
-    pci_qdev_register_many(piix4_info);
+    pci_qdev_register(&piix4_info);
 }
 device_init(piix4_register);
hw/piix_pci.c +44 -42

98 lines not on this page · raw message

hw/qxl.c +4 -4
index 6442193..a00dc33 100644
@@ -1824,7 +1824,7 @@ static Property qxl_properties[] = {
         DEFINE_PROP_END_OF_LIST(),
 };
 
-static PCIDeviceInfo qxl_info_primary = {
+static PCIDeviceInfo qxl_primary_info = {
     .qdev.name    = "qxl-vga",
     .qdev.desc    = "Spice QXL GPU (primary, vga compatible)",
     .qdev.size    = sizeof(PCIQXLDevice),
@@ -1839,7 +1839,7 @@ static PCIDeviceInfo qxl_info_primary = {
     .qdev.props   = qxl_properties,
 };
 
-static PCIDeviceInfo qxl_info_secondary = {
+static PCIDeviceInfo qxl_secondary_info = {
     .qdev.name    = "qxl",
     .qdev.desc    = "Spice QXL GPU (secondary)",
     .qdev.size    = sizeof(PCIQXLDevice),
@@ -1854,8 +1854,8 @@ static PCIDeviceInfo qxl_info_secondary = {
 
 static void qxl_register(void)
 {
-    pci_qdev_register(&qxl_info_primary);
-    pci_qdev_register(&qxl_info_secondary);
+    pci_qdev_register(&qxl_primary_info);
+    pci_qdev_register(&qxl_secondary_info);
 }
 
 device_init(qxl_register);
hw/spapr_llan.c +2 -2
index 91003cc..b9a5afc 100644
@@ -474,7 +474,7 @@ static target_ulong h_multicast_ctrl(CPUState *env, sPAPREnvironment *spapr,
     return H_SUCCESS;
 }
 
-static VIOsPAPRDeviceInfo spapr_vlan = {
+static VIOsPAPRDeviceInfo spapr_vlan_info = {
     .init = spapr_vlan_init,
     .devnode = spapr_vlan_devnode,
     .dt_name = "l-lan",
@@ -492,12 +492,12 @@ static VIOsPAPRDeviceInfo spapr_vlan = {
 
 static void spapr_vlan_register(void)
 {
-    spapr_vio_bus_register_withprop(&spapr_vlan);
     spapr_register_hypercall(H_REGISTER_LOGICAL_LAN, h_register_logical_lan);
     spapr_register_hypercall(H_FREE_LOGICAL_LAN, h_free_logical_lan);
     spapr_register_hypercall(H_SEND_LOGICAL_LAN, h_send_logical_lan);
     spapr_register_hypercall(H_ADD_LOGICAL_LAN_BUFFER,
                              h_add_logical_lan_buffer);
     spapr_register_hypercall(H_MULTICAST_CTRL, h_multicast_ctrl);
+    spapr_vio_bus_register_withprop(&spapr_vlan_info);
 }
 device_init(spapr_vlan_register);
hw/spapr_vscsi.c +2 -2
index 00e2d2d..21d946e 100644
@@ -947,7 +947,7 @@ static int spapr_vscsi_devnode(VIOsPAPRDevice *dev, void *fdt, int node_off)
     return 0;
 }
 
-static VIOsPAPRDeviceInfo spapr_vscsi = {
+static VIOsPAPRDeviceInfo spapr_vscsi_info = {
     .init = spapr_vscsi_init,
     .devnode = spapr_vscsi_devnode,
     .dt_name = "v-scsi",
@@ -964,6 +964,6 @@ static VIOsPAPRDeviceInfo spapr_vscsi = {
 
 static void spapr_vscsi_register(void)
 {
-    spapr_vio_bus_register_withprop(&spapr_vscsi);
+    spapr_vio_bus_register_withprop(&spapr_vscsi_info);
 }
 device_init(spapr_vscsi_register);
hw/spapr_vty.c +3 -3
index 181dd0e..3d5c579 100644
@@ -135,7 +135,7 @@ void spapr_vty_create(VIOsPAPRBus *bus, uint32_t reg, CharDriverState *chardev)
     qdev_init_nofail(dev);
 }
 
-static VIOsPAPRDeviceInfo spapr_vty = {
+static VIOsPAPRDeviceInfo spapr_vty_info = {
     .init = spapr_vty_init,
     .dt_name = "vty",
     .dt_type = "serial",
@@ -163,7 +163,7 @@ VIOsPAPRDevice *spapr_vty_get_default(VIOsPAPRBus *bus)
     selected = NULL;
     QTAILQ_FOREACH(iter, &bus->bus.children, sibling) {
         /* Only look at VTY devices */
-        if (qdev_get_info(iter) != &spapr_vty.qdev) {
+        if (qdev_get_info(iter) != &spapr_vty_info.qdev) {
             continue;
         }
 
@@ -203,8 +203,8 @@ static VIOsPAPRDevice *vty_lookup(sPAPREnvironment *spapr, target_ulong reg)
 
 static void spapr_vty_register(void)
 {
-    spapr_vio_bus_register_withprop(&spapr_vty);
     spapr_register_hypercall(H_PUT_TERM_CHAR, h_put_term_char);
     spapr_register_hypercall(H_GET_TERM_CHAR, h_get_term_char);
+    spapr_vio_bus_register_withprop(&spapr_vty_info);
 }
 device_init(spapr_vty_register);
hw/usb-ehci.c +24 -25

61 lines not on this page · raw message

hw/usb-uhci.c +59 -48

129 lines not on this page · raw message

hw/virtio-pci.c +86 -88

184 lines not on this page · raw message

Signature · 1 line
1.7.7
#26 lore raw

PATCH v3 12/28 isa: pic: convert to QEMU Object Model

In reply to Anthony Liguori

This converts two devices at once because PIC subclasses ISA and converting subclasses independently is extremely hard.

---
 hw/applesmc.c       |   18 ++++++++++++------
 hw/cirrus_vga.c     |   17 ++++++++++++-----
 hw/cs4231a.c        |   20 +++++++++++++-------
 hw/debugcon.c       |   16 +++++++++++-----
 hw/fdc.c            |   24 +++++++++++++++---------
 hw/gus.c            |   20 +++++++++++++-------
 hw/i82374.c         |   19 +++++++++++++------
 hw/i8254.c          |   22 ++++++++++++++--------
 hw/i8259.c          |   15 +++++++++++----
 hw/i8259_common.c   |   45 ++++++++++++++++++++++++++++++++-------------
 hw/i8259_internal.h |   27 +++++++++++++++++----------
 hw/ide/isa.c        |   20 +++++++++++++-------
 hw/isa-bus.c        |   38 ++++++++++++++++++++++++++++----------
 hw/isa.h            |   23 +++++++++++++++--------
 hw/kvm/i8259.c      |   19 +++++++++++++------
 hw/m48t59.c         |   20 +++++++++++++-------
 hw/mc146818rtc.c    |   22 ++++++++++++++--------
 hw/ne2000-isa.c     |   16 +++++++++++-----
 hw/parallel.c       |   16 +++++++++++-----
 hw/pc.c             |   20 +++++++++++++-------
 hw/pckbd.c          |   18 ++++++++++++------
 hw/sb16.c           |   20 +++++++++++++-------
 hw/serial.c         |   18 ++++++++++++------
 hw/sga.c            |   15 ++++++++++-----
 hw/vga-isa.c        |   18 ++++++++++++------
 hw/vmmouse.c        |   22 ++++++++++++++--------
 hw/vmport.c         |   16 +++++++++++-----
 hw/wdt_ib700.c      |   18 ++++++++++++------
 28 files changed, 390 insertions(+), 192 deletions(-)
hw/applesmc.c +12 -6
index c47b592..a6e88bc 100644
@@ -220,12 +220,18 @@ static int applesmc_isa_init(ISADevice *dev)
     return 0;
 }
 
-static ISADeviceInfo applesmc_isa_info = {
-    .qdev.name  = "isa-applesmc",
-    .qdev.size  = sizeof(struct AppleSMCStatus),
-    .qdev.reset = qdev_applesmc_isa_reset,
-    .init       = applesmc_isa_init,
-    .qdev.props = (Property[]) {
+static void qdev_applesmc_class_init(ObjectClass *klass, void *data)
+{
+    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+    ic->init = applesmc_isa_init;
+}
+
+static DeviceInfo applesmc_isa_info = {
+    .name  = "isa-applesmc",
+    .size  = sizeof(struct AppleSMCStatus),
+    .reset = qdev_applesmc_isa_reset,
+    .class_init = qdev_applesmc_class_init,
+    .props = (Property[]) {
         DEFINE_PROP_HEX32("iobase", struct AppleSMCStatus, iobase,
                           APPLESMC_DEFAULT_IOBASE),
         DEFINE_PROP_STRING("osk", struct AppleSMCStatus, osk),
hw/cirrus_vga.c +12 -5
index 5594bde..1d0aadf 100644
@@ -2905,11 +2905,18 @@ static int vga_initfn(ISADevice *dev)
     return 0;
 }
 
-static ISADeviceInfo isa_cirrus_vga_info = {
-    .qdev.name     = "isa-cirrus-vga",
-    .qdev.size     = sizeof(ISACirrusVGAState),
-    .qdev.vmsd     = &vmstate_cirrus_vga,
-    .init          = vga_initfn,
+static void isa_cirrus_vga_class_init(ObjectClass *klass, void *data)
+{
+    ISADeviceClass *k = ISA_DEVICE_CLASS(klass);
+
+    k->init          = vga_initfn;
+}
+
+static DeviceInfo isa_cirrus_vga_info = {
+    .name     = "isa-cirrus-vga",
+    .size     = sizeof(ISACirrusVGAState),
+    .vmsd     = &vmstate_cirrus_vga,
+    .class_init = isa_cirrus_vga_class_init,
 };
 
 static void isa_cirrus_vga_register(void)
hw/cs4231a.c +13 -7
index dc77a3a..811c76b 100644
@@ -665,13 +665,19 @@ int cs4231a_init (ISABus *bus)
     return 0;
 }
 
-static ISADeviceInfo cs4231a_info = {
-    .qdev.name     = "cs4231a",
-    .qdev.desc     = "Crystal Semiconductor CS4231A",
-    .qdev.size     = sizeof (CSState),
-    .qdev.vmsd     = &vmstate_cs4231a,
-    .init          = cs4231a_initfn,
-    .qdev.props    = (Property[]) {
+static void cs4231a_class_initfn(ObjectClass *klass, void *data)
+{
+    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+    ic->init = cs4231a_initfn;
+}
+
+static DeviceInfo cs4231a_info = {
+    .name     = "cs4231a",
+    .desc     = "Crystal Semiconductor CS4231A",
+    .size     = sizeof (CSState),
+    .vmsd     = &vmstate_cs4231a,
+    .class_init = cs4231a_class_initfn,
+    .props    = (Property[]) {
         DEFINE_PROP_HEX32  ("iobase",  CSState, port, 0x534),
         DEFINE_PROP_UINT32 ("irq",     CSState, irq,  9),
         DEFINE_PROP_UINT32 ("dma",     CSState, dma,  3),
hw/debugcon.c +11 -5
index c9ee6d9..f290122 100644
@@ -87,11 +87,17 @@ static int debugcon_isa_initfn(ISADevice *dev)
     return 0;
 }
 
-static ISADeviceInfo debugcon_isa_info = {
-    .qdev.name  = "isa-debugcon",
-    .qdev.size  = sizeof(ISADebugconState),
-    .init       = debugcon_isa_initfn,
-    .qdev.props = (Property[]) {
+static void debugcon_isa_class_initfn(ObjectClass *klass, void *data)
+{
+    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+    ic->init = debugcon_isa_initfn;
+}
+
+static DeviceInfo debugcon_isa_info = {
+    .name  = "isa-debugcon",
+    .size  = sizeof(ISADebugconState),
+    .class_init = debugcon_isa_class_initfn,
+    .props = (Property[]) {
         DEFINE_PROP_HEX32("iobase", ISADebugconState, iobase, 0xe9),
         DEFINE_PROP_CHR("chardev",  ISADebugconState, state.chr),
         DEFINE_PROP_HEX32("readback", ISADebugconState, state.readback, 0xe9),
hw/fdc.c +15 -9
index 70aa5c7..f761221 100644
@@ -1959,15 +1959,21 @@ static const VMStateDescription vmstate_isa_fdc ={
     }
 };
 
-static ISADeviceInfo isa_fdc_info = {
-    .init = isabus_fdc_init1,
-    .qdev.name  = "isa-fdc",
-    .qdev.fw_name  = "fdc",
-    .qdev.size  = sizeof(FDCtrlISABus),
-    .qdev.no_user = 1,
-    .qdev.vmsd  = &vmstate_isa_fdc,
-    .qdev.reset = fdctrl_external_reset_isa,
-    .qdev.props = (Property[]) {
+static void isabus_fdc_class_init1(ObjectClass *klass, void *data)
+{
+    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+    ic->init = isabus_fdc_init1;
+}
+
+static DeviceInfo isa_fdc_info = {
+    .class_init = isabus_fdc_class_init1,
+    .name  = "isa-fdc",
+    .fw_name  = "fdc",
+    .size  = sizeof(FDCtrlISABus),
+    .no_user = 1,
+    .vmsd  = &vmstate_isa_fdc,
+    .reset = fdctrl_external_reset_isa,
+    .props = (Property[]) {
         DEFINE_PROP_DRIVE("driveA", FDCtrlISABus, state.drives[0].bs),
         DEFINE_PROP_DRIVE("driveB", FDCtrlISABus, state.drives[1].bs),
         DEFINE_PROP_INT32("bootindexA", FDCtrlISABus, bootindexA, -1),
hw/gus.c +13 -7
index ab872d8..6603aab 100644
@@ -299,13 +299,19 @@ int GUS_init (ISABus *bus)
     return 0;
 }
 
-static ISADeviceInfo gus_info = {
-    .qdev.name     = "gus",
-    .qdev.desc     = "Gravis Ultrasound GF1",
-    .qdev.size     = sizeof (GUSState),
-    .qdev.vmsd     = &vmstate_gus,
-    .init          = gus_initfn,
-    .qdev.props    = (Property[]) {
+static void gus_class_initfn(ObjectClass *klass, void *data)
+{
+    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+    ic->init = gus_initfn;
+}
+
+static DeviceInfo gus_info = {
+    .name     = "gus",
+    .desc     = "Gravis Ultrasound GF1",
+    .size     = sizeof (GUSState),
+    .vmsd     = &vmstate_gus,
+    .class_init          = gus_class_initfn,
+    .props    = (Property[]) {
         DEFINE_PROP_UINT32 ("freq",    GUSState, freq,        44100),
         DEFINE_PROP_HEX32  ("iobase",  GUSState, port,        0x240),
         DEFINE_PROP_UINT32 ("irq",     GUSState, emu.gusirq,  7),
hw/i82374.c +13 -6
index 616d1fc..2814379 100644
@@ -135,12 +135,19 @@ static int i82374_isa_init(ISADevice *dev)
     return 0;
 }
 
-static ISADeviceInfo i82374_isa_info = {
-    .qdev.name  = "i82374",
-    .qdev.size  = sizeof(ISAi82374State),
-    .qdev.vmsd  = &vmstate_isa_i82374,
-    .init       = i82374_isa_init,
-    .qdev.props = (Property[]) {
+static void i82374_class_init(ObjectClass *klass, void *data)
+{
+    ISADeviceClass *k = ISA_DEVICE_CLASS(klass);
+    
+    k->init       = i82374_isa_init;
+}
+
+static DeviceInfo i82374_isa_info = {
+    .name  = "i82374",
+    .size  = sizeof(ISAi82374State),
+    .vmsd  = &vmstate_isa_i82374,
+    .class_init = i82374_class_init,
+    .props = (Property[]) {
         DEFINE_PROP_HEX32("iobase", ISAi82374State, iobase, 0x400),
         DEFINE_PROP_END_OF_LIST()
     },
hw/i8254.c +14 -8
index cf9ed2f..add1fab 100644
@@ -535,14 +535,20 @@ static int pit_initfn(ISADevice *dev)
     return 0;
 }
 
-static ISADeviceInfo pit_info = {
-    .qdev.name     = "isa-pit",
-    .qdev.size     = sizeof(PITState),
-    .qdev.vmsd     = &vmstate_pit,
-    .qdev.reset    = pit_reset,
-    .qdev.no_user  = 1,
-    .init          = pit_initfn,
-    .qdev.props = (Property[]) {
+static void pit_class_initfn(ObjectClass *klass, void *data)
+{
+    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+    ic->init = pit_initfn;
+}
+
+static DeviceInfo pit_info = {
+    .name     = "isa-pit",
+    .size     = sizeof(PITState),
+    .vmsd     = &vmstate_pit,
+    .reset    = pit_reset,
+    .no_user  = 1,
+    .class_init          = pit_class_initfn,
+    .props = (Property[]) {
         DEFINE_PROP_UINT32("irq", PITState, irq,  -1),
         DEFINE_PROP_HEX32("iobase", PITState, iobase,  -1),
         DEFINE_PROP_END_OF_LIST(),
hw/i8259.c +11 -4
index 3005ce2..e083bb6 100644
@@ -472,10 +472,17 @@ qemu_irq *i8259_init(ISABus *bus, qemu_irq parent_irq)
     return irq_set;
 }
 
-static PICCommonInfo i8259_info = {
-    .isadev.qdev.name  = "isa-i8259",
-    .isadev.qdev.reset = pic_reset,
-    .init              = pic_init,
+static void i8259_class_init(ObjectClass *klass, void *data)
+{
+    PICCommonClass *k = PIC_COMMON_CLASS(klass);
+
+    k->init = pic_init;
+}
+
+static DeviceInfo i8259_info = {
+    .name  = "isa-i8259",
+    .reset = pic_reset,
+    .class_init = i8259_class_init,
 };
 
 static void pic_register(void)
hw/i8259_common.c +32 -13

68 lines not on this page · raw message

hw/i8259_internal.h +17 -10
index 13deb14..e9d1732 100644
@@ -31,6 +31,22 @@
 
 typedef struct PICCommonState PICCommonState;
 
+#define TYPE_PIC_COMMON "pic-common"
+#define PIC_COMMON(obj) \
+     OBJECT_CHECK(PICCommon, (obj), TYPE_PIC_COMMON)
+#define PIC_COMMON_CLASS(klass) \
+     OBJECT_CLASS_CHECK(PICCommonClass, (klass), TYPE_PIC_COMMON)
+#define PIC_COMMON_GET_CLASS(obj) \
+     OBJECT_GET_CLASS(PICCommonClass, (obj), TYPE_PIC_COMMON)
+
+typedef struct PICCommonClass
+{
+    ISADeviceClass parent_class;
+    void (*init)(PICCommonState *s);
+    void (*pre_save)(PICCommonState *s);
+    void (*post_load)(PICCommonState *s);
+} PICCommonClass;
+
 struct PICCommonState {
     ISADevice dev;
     uint8_t last_irr; /* edge detection */
@@ -58,19 +74,10 @@ struct PICCommonState {
     MemoryRegion elcr_io;
 };
 
-typedef struct PICCommonInfo PICCommonInfo;
-
-struct PICCommonInfo {
-    ISADeviceInfo isadev;
-    void (*init)(PICCommonState *s);
-    void (*pre_save)(PICCommonState *s);
-    void (*post_load)(PICCommonState *s);
-};
-
 void pic_reset_common(PICCommonState *s);
 
 ISADevice *i8259_init_chip(const char *name, ISABus *bus, bool master);
 
-void pic_qdev_register(PICCommonInfo *info);
+void pic_qdev_register(DeviceInfo *info);
 
 #endif /* !QEMU_I8259_INTERNAL_H */
hw/ide/isa.c +13 -7
index 219f3a4..464473a 100644
@@ -94,13 +94,19 @@ ISADevice *isa_ide_init(ISABus *bus, int iobase, int iobase2, int isairq,
     return dev;
 }
 
-static ISADeviceInfo isa_ide_info = {
-    .qdev.name  = "isa-ide",
-    .qdev.fw_name  = "ide",
-    .qdev.size  = sizeof(ISAIDEState),
-    .init       = isa_ide_initfn,
-    .qdev.reset = isa_ide_reset,
-    .qdev.props = (Property[]) {
+static void isa_ide_class_initfn(ObjectClass *klass, void *data)
+{
+    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+    ic->init = isa_ide_initfn;
+}
+
+static DeviceInfo isa_ide_info = {
+    .name  = "isa-ide",
+    .fw_name  = "ide",
+    .size  = sizeof(ISAIDEState),
+    .class_init       = isa_ide_class_initfn,
+    .reset = isa_ide_reset,
+    .props = (Property[]) {
         DEFINE_PROP_HEX32("iobase",  ISAIDEState, iobase,  0x1f0),
         DEFINE_PROP_HEX32("iobase2", ISAIDEState, iobase2, 0x3f6),
         DEFINE_PROP_UINT32("irq",    ISAIDEState, isairq,  14),
hw/isa-bus.c +28 -10
index 5af790b..6943194 100644
@@ -112,20 +112,29 @@ void isa_register_portio_list(ISADevice *dev, uint16_t start,
 
 static int isa_qdev_init(DeviceState *qdev, DeviceInfo *base)
 {
-    ISADevice *dev = DO_UPCAST(ISADevice, qdev, qdev);
-    ISADeviceInfo *info = DO_UPCAST(ISADeviceInfo, qdev, base);
+    ISADevice *dev = ISA_DEVICE(qdev);
+    ISADeviceClass *klass = ISA_DEVICE_GET_CLASS(dev);
 
     dev->isairq[0] = -1;
     dev->isairq[1] = -1;
 
-    return info->init(dev);
+    if (klass->init) {
+        return klass->init(dev);
+    }
+
+    return 0;
+}
+
+void isa_qdev_register_subclass(DeviceInfo *info, const char *parent)
+{
+    info->init = isa_qdev_init;
+    info->bus_info = &isa_bus_info;
+    qdev_register_subclass(info, parent);
 }
 
-void isa_qdev_register(ISADeviceInfo *info)
+void isa_qdev_register(DeviceInfo *info)
 {
-    info->qdev.init = isa_qdev_init;
-    info->qdev.bus_info = &isa_bus_info;
-    qdev_register(&info->qdev);
+    isa_qdev_register_subclass(info, TYPE_ISA_DEVICE);
 }
 
 ISADevice *isa_create(ISABus *bus, const char *name)
@@ -137,7 +146,7 @@ ISADevice *isa_create(ISABus *bus, const char *name)
                  name);
     }
     dev = qdev_create(&bus->qbus, name);
-    return DO_UPCAST(ISADevice, qdev, dev);
+    return ISA_DEVICE(dev);
 }
 
 ISADevice *isa_try_create(ISABus *bus, const char *name)
@@ -149,7 +158,7 @@ ISADevice *isa_try_create(ISABus *bus, const char *name)
                  name);
     }
     dev = qdev_try_create(&bus->qbus, name);
-    return DO_UPCAST(ISADevice, qdev, dev);
+    return ISA_DEVICE(dev);
 }
 
 ISADevice *isa_create_simple(ISABus *bus, const char *name)
@@ -163,7 +172,7 @@ ISADevice *isa_create_simple(ISABus *bus, const char *name)
 
 static void isabus_dev_print(Monitor *mon, DeviceState *dev, int indent)
 {
-    ISADevice *d = DO_UPCAST(ISADevice, qdev, dev);
+    ISADevice *d = ISA_DEVICE(dev);
 
     if (d->isairq[1] != -1) {
         monitor_printf(mon, "%*sisa irqs %d,%d\n", indent, "",
@@ -188,9 +197,18 @@ static SysBusDeviceInfo isabus_bridge_info = {
     .qdev.no_user = 1,
 };
 
+static TypeInfo isa_device_type_info = {
+    .name = TYPE_ISA_DEVICE,
+    .parent = TYPE_DEVICE,
+    .instance_size = sizeof(ISADevice),
+    .abstract = true,
+    .class_size = sizeof(ISADeviceClass),
+};
+
 static void isabus_register_devices(void)
 {
     sysbus_register_withprop(&isabus_bridge_info);
+    type_register_static(&isa_device_type_info);
 }
 
 static char *isabus_get_fw_dev_path(DeviceState *dev)
hw/isa.h +15 -8
index b11a0be..9f5d158 100644
@@ -10,7 +10,19 @@
 #define ISA_NUM_IRQS 16
 
 typedef struct ISADevice ISADevice;
-typedef struct ISADeviceInfo ISADeviceInfo;
+
+#define TYPE_ISA_DEVICE "isa-device"
+#define ISA_DEVICE(obj) \
+     OBJECT_CHECK(ISADevice, (obj), TYPE_ISA_DEVICE)
+#define ISA_DEVICE_CLASS(klass) \
+     OBJECT_CLASS_CHECK(ISADeviceClass, (klass), TYPE_ISA_DEVICE)
+#define ISA_DEVICE_GET_CLASS(obj) \
+     OBJECT_GET_CLASS(ISADeviceClass, (obj), TYPE_ISA_DEVICE)
+
+typedef struct ISADeviceClass {
+    DeviceClass parent_class;
+    int (*init)(ISADevice *dev);
+} ISADeviceClass;
 
 struct ISABus {
     BusState qbus;
@@ -25,17 +37,12 @@ struct ISADevice {
     int ioport_id;
 };
 
-typedef int (*isa_qdev_initfn)(ISADevice *dev);
-struct ISADeviceInfo {
-    DeviceInfo qdev;
-    isa_qdev_initfn init;
-};
-
 ISABus *isa_bus_new(DeviceState *dev, MemoryRegion *address_space_io);
 void isa_bus_irqs(ISABus *bus, qemu_irq *irqs);
 qemu_irq isa_get_irq(ISADevice *dev, int isairq);
 void isa_init_irq(ISADevice *dev, qemu_irq *p, int isairq);
-void isa_qdev_register(ISADeviceInfo *info);
+void isa_qdev_register(DeviceInfo *info);
+void isa_qdev_register_subclass(DeviceInfo *info, const char *parent);
 MemoryRegion *isa_address_space(ISADevice *dev);
 ISADevice *isa_create(ISABus *bus, const char *name);
 ISADevice *isa_try_create(ISABus *bus, const char *name);
hw/kvm/i8259.c +13 -6
index 64bb5c2..b34901c 100644
@@ -112,12 +112,19 @@ qemu_irq *kvm_i8259_init(ISABus *bus)
     return qemu_allocate_irqs(kvm_pic_set_irq, NULL, ISA_NUM_IRQS);
 }
 
-static PICCommonInfo kvm_i8259_info = {
-    .isadev.qdev.name  = "kvm-i8259",
-    .isadev.qdev.reset = kvm_pic_reset,
-    .init       = kvm_pic_init,
-    .pre_save   = kvm_pic_get,
-    .post_load  = kvm_pic_put,
+static void kvm_i8259_class_init(ObjectClass *klass, void *data)
+{
+    PICCommonClass *k = PIC_COMMON_CLASS(klass);
+
+    k->init       = kvm_pic_init;
+    k->pre_save   = kvm_pic_get;
+    k->post_load  = kvm_pic_put;
+}
+
+static DeviceInfo kvm_i8259_info = {
+    .name  = "kvm-i8259",
+    .reset = kvm_pic_reset,
+    .class_init = kvm_i8259_class_init,
 };
 
 static void kvm_pic_register(void)
hw/m48t59.c +13 -7
index c043996..5912cd6 100644
@@ -720,13 +720,19 @@ static int m48t59_init1(SysBusDevice *dev)
     return 0;
 }
 
-static ISADeviceInfo m48t59_isa_info = {
-    .init = m48t59_init_isa1,
-    .qdev.name = "m48t59_isa",
-    .qdev.size = sizeof(M48t59ISAState),
-    .qdev.reset = m48t59_reset_isa,
-    .qdev.no_user = 1,
-    .qdev.props = (Property[]) {
+static void m48t59_init_class_isa1(ObjectClass *klass, void *data)
+{
+    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+    ic->init = m48t59_init_isa1;
+}
+
+static DeviceInfo m48t59_isa_info = {
+    .class_init = m48t59_init_class_isa1,
+    .name = "m48t59_isa",
+    .size = sizeof(M48t59ISAState),
+    .reset = m48t59_reset_isa,
+    .no_user = 1,
+    .props = (Property[]) {
         DEFINE_PROP_UINT32("size",    M48t59ISAState, state.size,    -1),
         DEFINE_PROP_UINT32("type",    M48t59ISAState, state.type,    -1),
         DEFINE_PROP_HEX32( "io_base", M48t59ISAState, state.io_base,  0),
hw/mc146818rtc.c +14 -8
index 657fa10..685eb89 100644
@@ -629,7 +629,7 @@ static void visit_type_int32(Visitor *v, int *value, const char *name, Error **e
 static void rtc_get_date(DeviceState *dev, Visitor *v, void *opaque,
                          const char *name, Error **errp)
 {
-    ISADevice *isa = DO_UPCAST(ISADevice, qdev, dev);
+    ISADevice *isa = ISA_DEVICE(dev);
     RTCState *s = DO_UPCAST(RTCState, dev, isa);
 
     visit_start_struct(v, NULL, "struct tm", name, 0, errp);
@@ -699,13 +699,19 @@ ISADevice *rtc_init(ISABus *bus, int base_year, qemu_irq intercept_irq)
     return dev;
 }
 
-static ISADeviceInfo mc146818rtc_info = {
-    .qdev.name     = "mc146818rtc",
-    .qdev.size     = sizeof(RTCState),
-    .qdev.no_user  = 1,
-    .qdev.vmsd     = &vmstate_rtc,
-    .init          = rtc_initfn,
-    .qdev.props    = (Property[]) {
+static void rtc_class_initfn(ObjectClass *klass, void *data)
+{
+    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+    ic->init = rtc_initfn;
+}
+
+static DeviceInfo mc146818rtc_info = {
+    .name     = "mc146818rtc",
+    .size     = sizeof(RTCState),
+    .no_user  = 1,
+    .vmsd     = &vmstate_rtc,
+    .class_init          = rtc_class_initfn,
+    .props    = (Property[]) {
         DEFINE_PROP_INT32("base_year", RTCState, base_year, 1980),
         DEFINE_PROP_END_OF_LIST(),
     }
hw/ne2000-isa.c +11 -5
index 5bc5f2a..25a7a31 100644
@@ -82,11 +82,17 @@ static int isa_ne2000_initfn(ISADevice *dev)
     return 0;
 }
 
-static ISADeviceInfo ne2000_isa_info = {
-    .qdev.name  = "ne2k_isa",
-    .qdev.size  = sizeof(ISANE2000State),
-    .init       = isa_ne2000_initfn,
-    .qdev.props = (Property[]) {
+static void isa_ne2000_class_initfn(ObjectClass *klass, void *data)
+{
+    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+    ic->init = isa_ne2000_initfn;
+}
+
+static DeviceInfo ne2000_isa_info = {
+    .name  = "ne2k_isa",
+    .size  = sizeof(ISANE2000State),
+    .class_init       = isa_ne2000_class_initfn,
+    .props = (Property[]) {
         DEFINE_PROP_HEX32("iobase", ISANE2000State, iobase, 0x300),
         DEFINE_PROP_UINT32("irq",   ISANE2000State, isairq, 9),
         DEFINE_NIC_PROPERTIES(ISANE2000State, ne2000.c),
hw/parallel.c +11 -5
index c4c5dbe..cadcffb 100644
@@ -583,11 +583,17 @@ bool parallel_mm_init(MemoryRegion *address_space,
     return true;
 }
 
-static ISADeviceInfo parallel_isa_info = {
-    .qdev.name  = "isa-parallel",
-    .qdev.size  = sizeof(ISAParallelState),
-    .init       = parallel_isa_initfn,
-    .qdev.props = (Property[]) {
+static void parallel_isa_class_initfn(ObjectClass *klass, void *data)
+{
+    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+    ic->init = parallel_isa_initfn;
+}
+
+static DeviceInfo parallel_isa_info = {
+    .name  = "isa-parallel",
+    .size  = sizeof(ISAParallelState),
+    .class_init       = parallel_isa_class_initfn,
+    .props = (Property[]) {
         DEFINE_PROP_UINT32("index", ISAParallelState, index,   -1),
         DEFINE_PROP_HEX32("iobase", ISAParallelState, iobase,  -1),
         DEFINE_PROP_UINT32("irq",   ISAParallelState, isairq,  7),
hw/pc.c +13 -7
index f3124d3..31608d3 100644
@@ -497,13 +497,19 @@ static int port92_initfn(ISADevice *dev)
     return 0;
 }
 
-static ISADeviceInfo port92_info = {
-    .qdev.name     = "port92",
-    .qdev.size     = sizeof(Port92State),
-    .qdev.vmsd     = &vmstate_port92_isa,
-    .qdev.no_user  = 1,
-    .qdev.reset    = port92_reset,
-    .init          = port92_initfn,
+static void port92_class_initfn(ObjectClass *klass, void *data)
+{
+    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+    ic->init = port92_initfn;
+}
+
+static DeviceInfo port92_info = {
+    .name     = "port92",
+    .size     = sizeof(Port92State),
+    .vmsd     = &vmstate_port92_isa,
+    .no_user  = 1,
+    .reset    = port92_reset,
+    .class_init          = port92_class_initfn,
 };
 
 static void port92_register(void)
hw/pckbd.c +12 -6
index 06b40c5..2ebe1c5 100644
@@ -497,12 +497,18 @@ static int i8042_initfn(ISADevice *dev)
     return 0;
 }
 
-static ISADeviceInfo i8042_info = {
-    .qdev.name     = "i8042",
-    .qdev.size     = sizeof(ISAKBDState),
-    .qdev.vmsd     = &vmstate_kbd_isa,
-    .qdev.no_user  = 1,
-    .init          = i8042_initfn,
+static void i8042_class_initfn(ObjectClass *klass, void *data)
+{
+    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+    ic->init = i8042_initfn;
+}
+
+static DeviceInfo i8042_info = {
+    .name     = "i8042",
+    .size     = sizeof(ISAKBDState),
+    .vmsd     = &vmstate_kbd_isa,
+    .no_user  = 1,
+    .class_init          = i8042_class_initfn,
 };
 
 static void i8042_register(void)
hw/sb16.c +13 -7
index 887b32e..67357ce 100644
@@ -1391,13 +1391,19 @@ int SB16_init (ISABus *bus)
     return 0;
 }
 
-static ISADeviceInfo sb16_info = {
-    .qdev.name     = "sb16",
-    .qdev.desc     = "Creative Sound Blaster 16",
-    .qdev.size     = sizeof (SB16State),
-    .qdev.vmsd     = &vmstate_sb16,
-    .init          = sb16_initfn,
-    .qdev.props    = (Property[]) {
+static void sb16_class_initfn(ObjectClass *klass, void *data)
+{
+    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+    ic->init = sb16_initfn;
+}
+
+static DeviceInfo sb16_info = {
+    .name     = "sb16",
+    .desc     = "Creative Sound Blaster 16",
+    .size     = sizeof (SB16State),
+    .vmsd     = &vmstate_sb16,
+    .class_init          = sb16_class_initfn,
+    .props    = (Property[]) {
         DEFINE_PROP_HEX32  ("version", SB16State, ver,  0x0405), /* 4.5 */
         DEFINE_PROP_HEX32  ("iobase",  SB16State, port, 0x220),
         DEFINE_PROP_UINT32 ("irq",     SB16State, irq,  5),
hw/serial.c +12 -6
index d35c7a9..2644b13 100644
@@ -879,12 +879,18 @@ SerialState *serial_mm_init(MemoryRegion *address_space,
     return s;
 }
 
-static ISADeviceInfo serial_isa_info = {
-    .qdev.name  = "isa-serial",
-    .qdev.size  = sizeof(ISASerialState),
-    .qdev.vmsd  = &vmstate_isa_serial,
-    .init       = serial_isa_initfn,
-    .qdev.props = (Property[]) {
+static void serial_isa_class_initfn(ObjectClass *klass, void *data)
+{
+    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+    ic->init = serial_isa_initfn;
+}
+
+static DeviceInfo serial_isa_info = {
+    .name  = "isa-serial",
+    .size  = sizeof(ISASerialState),
+    .vmsd  = &vmstate_isa_serial,
+    .class_init       = serial_isa_class_initfn,
+    .props = (Property[]) {
         DEFINE_PROP_UINT32("index", ISASerialState, index,   -1),
         DEFINE_PROP_HEX32("iobase", ISASerialState, iobase,  -1),
         DEFINE_PROP_UINT32("irq",   ISASerialState, isairq,  -1),
hw/sga.c +10 -5
index ea11937..d612cb6 100644
@@ -40,12 +40,17 @@ static int sga_initfn(ISADevice *dev)
     rom_add_vga(SGABIOS_FILENAME);
     return 0;
 }
+static void sga_class_initfn(ObjectClass *klass, void *data)
+{
+    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+    ic->init = sga_initfn;
+}
 
-static ISADeviceInfo sga_info = {
-    .qdev.name    = "sga",
-    .qdev.desc    = "Serial Graphics Adapter",
-    .qdev.size    = sizeof(ISASGAState),
-    .init         = sga_initfn,
+static DeviceInfo sga_info = {
+    .name    = "sga",
+    .desc    = "Serial Graphics Adapter",
+    .size    = sizeof(ISASGAState),
+    .class_init         = sga_class_initfn,
 };
 
 static void sga_register(void)
hw/vga-isa.c +12 -6
index 4825313..cb6af91 100644
@@ -69,12 +69,18 @@ static int vga_initfn(ISADevice *dev)
     return 0;
 }
 
-static ISADeviceInfo vga_info = {
-    .qdev.name     = "isa-vga",
-    .qdev.size     = sizeof(ISAVGAState),
-    .qdev.vmsd     = &vmstate_vga_common,
-    .qdev.reset     = vga_reset_isa,
-    .init          = vga_initfn,
+static void vga_class_initfn(ObjectClass *klass, void *data)
+{
+    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+    ic->init = vga_initfn;
+}
+
+static DeviceInfo vga_info = {
+    .name     = "isa-vga",
+    .size     = sizeof(ISAVGAState),
+    .vmsd     = &vmstate_vga_common,
+    .reset     = vga_reset_isa,
+    .class_init          = vga_class_initfn,
 };
 
 static void vga_register(void)
hw/vmmouse.c +14 -8
index 1113f33..da2ea32 100644
@@ -269,14 +269,20 @@ static int vmmouse_initfn(ISADevice *dev)
     return 0;
 }
 
-static ISADeviceInfo vmmouse_info = {
-    .init          = vmmouse_initfn,
-    .qdev.name     = "vmmouse",
-    .qdev.size     = sizeof(VMMouseState),
-    .qdev.vmsd     = &vmstate_vmmouse,
-    .qdev.no_user  = 1,
-    .qdev.reset    = vmmouse_reset,
-    .qdev.props = (Property[]) {
+static void vmmouse_class_initfn(ObjectClass *klass, void *data)
+{
+    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+    ic->init = vmmouse_initfn;
+}
+
+static DeviceInfo vmmouse_info = {
+    .class_init          = vmmouse_class_initfn,
+    .name     = "vmmouse",
+    .size     = sizeof(VMMouseState),
+    .vmsd     = &vmstate_vmmouse,
+    .no_user  = 1,
+    .reset    = vmmouse_reset,
+    .props = (Property[]) {
         DEFINE_PROP_PTR("ps2_mouse", VMMouseState, ps2_mouse),
         DEFINE_PROP_END_OF_LIST(),
     }
hw/vmport.c +11 -5
index 0a3dbc5..c4582d6 100644
@@ -144,11 +144,17 @@ static int vmport_initfn(ISADevice *dev)
     return 0;
 }
 
-static ISADeviceInfo vmport_info = {
-    .qdev.name     = "vmport",
-    .qdev.size     = sizeof(VMPortState),
-    .qdev.no_user  = 1,
-    .init          = vmport_initfn,
+static void vmport_class_initfn(ObjectClass *klass, void *data)
+{
+    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+    ic->init = vmport_initfn;
+}
+
+static DeviceInfo vmport_info = {
+    .name     = "vmport",
+    .size     = sizeof(VMPortState),
+    .no_user  = 1,
+    .class_init          = vmport_class_initfn,
 };
 
 static void vmport_dev_register(void)
hw/wdt_ib700.c +12 -6
index ba1d92d..6deb0de 100644
@@ -120,12 +120,18 @@ static WatchdogTimerModel model = {
     .wdt_description = "iBASE 700",
 };
 
-static ISADeviceInfo wdt_ib700_info = {
-    .qdev.name  = "ib700",
-    .qdev.size  = sizeof(IB700State),
-    .qdev.vmsd  = &vmstate_ib700,
-    .qdev.reset = wdt_ib700_reset,
-    .init       = wdt_ib700_init,
+static void wdt_ib700_class_init(ObjectClass *klass, void *data)
+{
+    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+    ic->init = wdt_ib700_init;
+}
+
+static DeviceInfo wdt_ib700_info = {
+    .name  = "ib700",
+    .size  = sizeof(IB700State),
+    .vmsd  = &vmstate_ib700,
+    .reset = wdt_ib700_reset,
+    .class_init       = wdt_ib700_class_init,
 };
 
 static void wdt_ib700_register_devices(void)
Signature · 1 line
1.7.4.1
#27 lore raw

PATCH v3 13/28 usb: convert to QEMU Object Model

In reply to Anthony Liguori
---
 hw/usb-audio.c  |   38 +++++++-----
 hw/usb-bt.c     |   33 ++++++----
 hw/usb-bus.c    |  188 +++++++++++++++++++++++++++++++++++++++++++-----------
 hw/usb-ccid.c   |   38 +++++++-----
 hw/usb-desc.c   |   22 +++---
 hw/usb-hid.c    |  108 +++++++++++++++++++-------------
 hw/usb-hub.c    |   35 ++++++----
 hw/usb-msd.c    |   41 +++++++-----
 hw/usb-net.c    |   41 +++++++-----
 hw/usb-serial.c |   74 ++++++++++++---------
 hw/usb-wacom.c  |   36 ++++++-----
 hw/usb-xhci.c   |    4 +-
 hw/usb.c        |   24 +++----
 hw/usb.h        |   50 +++++++++++---
 usb-bsd.c       |   29 +++++---
 usb-linux.c     |   37 ++++++-----
 usb-redir.c     |   33 ++++++----
 17 files changed, 528 insertions(+), 303 deletions(-)
hw/usb-audio.c +22 -16
index b22d578..561ae31 100644
@@ -674,21 +674,27 @@ static const VMStateDescription vmstate_usb_audio = {
     .unmigratable = 1,
 };
 
-static struct USBDeviceInfo usb_audio_info = {
-    .product_desc   = "QEMU USB Audio Interface",
-    .usbdevice_name = "audio",
-    .qdev.name      = "usb-audio",
-    .qdev.size      = sizeof(USBAudioState),
-    .qdev.vmsd      = &vmstate_usb_audio,
-    .usb_desc       = &desc_audio,
-    .init           = usb_audio_initfn,
-    .handle_packet  = usb_generic_handle_packet,
-    .handle_reset   = usb_audio_handle_reset,
-    .handle_control = usb_audio_handle_control,
-    .handle_data    = usb_audio_handle_data,
-    .handle_destroy = usb_audio_handle_destroy,
-    .set_interface  = usb_audio_set_interface,
-    .qdev.props = (Property[]) {
+static void usb_audio_class_init(ObjectClass *klass, void *data)
+{
+    USBDeviceClass *k = USB_DEVICE_CLASS(klass);
+
+    k->product_desc   = "QEMU USB Audio Interface";
+    k->usb_desc       = &desc_audio;
+    k->init           = usb_audio_initfn;
+    k->handle_packet  = usb_generic_handle_packet;
+    k->handle_reset   = usb_audio_handle_reset;
+    k->handle_control = usb_audio_handle_control;
+    k->handle_data    = usb_audio_handle_data;
+    k->handle_destroy = usb_audio_handle_destroy;
+    k->set_interface  = usb_audio_set_interface;
+}
+
+static struct DeviceInfo usb_audio_info = {
+    .name      = "usb-audio",
+    .size      = sizeof(USBAudioState),
+    .vmsd      = &vmstate_usb_audio,
+    .class_init = usb_audio_class_init,
+    .props = (Property[]) {
         DEFINE_PROP_UINT32("debug", USBAudioState, debug, 0),
         DEFINE_PROP_UINT32("buffer", USBAudioState, buffer,
                            8 * USBAUDIO_PACKET_SIZE),
@@ -698,7 +704,7 @@ static struct USBDeviceInfo usb_audio_info = {
 
 static void usb_audio_register_devices(void)
 {
-    usb_qdev_register(&usb_audio_info);
+    usb_qdev_register(&usb_audio_info, "audio", NULL);
 }
 
 device_init(usb_audio_register_devices)
hw/usb-bt.c +20 -13
index 0c1270b..bf8c470 100644
@@ -527,22 +527,29 @@ static const VMStateDescription vmstate_usb_bt = {
     .unmigratable = 1,
 };
 
-static struct USBDeviceInfo bt_info = {
-    .product_desc   = "QEMU BT dongle",
-    .qdev.name      = "usb-bt-dongle",
-    .qdev.size      = sizeof(struct USBBtState),
-    .qdev.vmsd      = &vmstate_usb_bt,
-    .usb_desc       = &desc_bluetooth,
-    .init           = usb_bt_initfn,
-    .handle_packet  = usb_generic_handle_packet,
-    .handle_reset   = usb_bt_handle_reset,
-    .handle_control = usb_bt_handle_control,
-    .handle_data    = usb_bt_handle_data,
-    .handle_destroy = usb_bt_handle_destroy,
+static void usb_bt_class_initfn(ObjectClass *klass, void *data)
+{
+    USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
+
+    uc->init           = usb_bt_initfn;
+    uc->product_desc   = "QEMU BT dongle";
+    uc->usb_desc       = &desc_bluetooth;
+    uc->handle_packet  = usb_generic_handle_packet;
+    uc->handle_reset   = usb_bt_handle_reset;
+    uc->handle_control = usb_bt_handle_control;
+    uc->handle_data    = usb_bt_handle_data;
+    uc->handle_destroy = usb_bt_handle_destroy;
+}
+
+static struct DeviceInfo bt_info = {
+    .name      = "usb-bt-dongle",
+    .size      = sizeof(struct USBBtState),
+    .vmsd      = &vmstate_usb_bt,
+    .class_init= usb_bt_class_initfn,
 };
 
 static void usb_bt_register_devices(void)
 {
-    usb_qdev_register(&bt_info);
+    usb_qdev_register(&bt_info, NULL, NULL);
 }
 device_init(usb_bt_register_devices)
hw/usb-bus.c +149 -39

268 lines not on this page · raw message

hw/usb-ccid.c +22 -16
index 3b7f95d..eb63dfc 100644
@@ -1286,28 +1286,34 @@ static VMStateDescription ccid_vmstate = {
     }
 };
 
-static struct USBDeviceInfo ccid_info = {
-    .product_desc   = "QEMU USB CCID",
-    .qdev.name      = CCID_DEV_NAME,
-    .qdev.desc      = "CCID Rev 1.1 smartcard reader",
-    .qdev.size      = sizeof(USBCCIDState),
-    .init           = ccid_initfn,
-    .usb_desc       = &desc_ccid,
-    .handle_packet  = usb_generic_handle_packet,
-    .handle_reset   = ccid_handle_reset,
-    .handle_control = ccid_handle_control,
-    .handle_data    = ccid_handle_data,
-    .handle_destroy = ccid_handle_destroy,
-    .usbdevice_name = "ccid",
-    .qdev.props     = (Property[]) {
+static void ccid_class_initfn(ObjectClass *klass, void *data)
+{
+    USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
+
+    uc->init           = ccid_initfn;
+    uc->product_desc   = "QEMU USB CCID";
+    uc->usb_desc       = &desc_ccid;
+    uc->handle_packet  = usb_generic_handle_packet;
+    uc->handle_reset   = ccid_handle_reset;
+    uc->handle_control = ccid_handle_control;
+    uc->handle_data    = ccid_handle_data;
+    uc->handle_destroy = ccid_handle_destroy;
+}
+
+static struct DeviceInfo ccid_info = {
+    .name      = CCID_DEV_NAME,
+    .desc      = "CCID Rev 1.1 smartcard reader",
+    .size      = sizeof(USBCCIDState),
+    .class_init= ccid_class_initfn,
+    .vmsd      = &ccid_vmstate,
+    .props     = (Property[]) {
         DEFINE_PROP_UINT8("debug", USBCCIDState, debug, 0),
         DEFINE_PROP_END_OF_LIST(),
     },
-    .qdev.vmsd      = &ccid_vmstate,
 };
 
 static void ccid_register_devices(void)
 {
-    usb_qdev_register(&ccid_info);
+    usb_qdev_register(&ccid_info, "ccid", NULL);
 }
 device_init(ccid_register_devices)
hw/usb-desc.c +11 -11
index b3eb97b..3c3ed6a 100644
@@ -297,8 +297,8 @@ static int usb_desc_set_interface(USBDevice *dev, int index, int value)
     dev->ifaces[index] = iface;
     usb_desc_ep_init(dev);
 
-    if (dev->info->set_interface && old != value) {
-        dev->info->set_interface(dev, index, old, value);
+    if (old != value) {
+        usb_device_set_interface(dev, index, old, value);
     }
     return 0;
 }
@@ -338,7 +338,7 @@ static int usb_desc_set_config(USBDevice *dev, int value)
 
 static void usb_desc_setdefaults(USBDevice *dev)
 {
-    const USBDesc *desc = dev->info->usb_desc;
+    const USBDesc *desc = usb_device_get_usb_desc(dev);
 
     assert(desc != NULL);
     switch (dev->speed) {
@@ -355,7 +355,7 @@ static void usb_desc_setdefaults(USBDevice *dev)
 
 void usb_desc_init(USBDevice *dev)
 {
-    const USBDesc *desc = dev->info->usb_desc;
+    const USBDesc *desc = usb_device_get_usb_desc(dev);
 
     assert(desc != NULL);
     dev->speed = USB_SPEED_FULL;
@@ -371,7 +371,7 @@ void usb_desc_init(USBDevice *dev)
 
 void usb_desc_attach(USBDevice *dev)
 {
-    const USBDesc *desc = dev->info->usb_desc;
+    const USBDesc *desc = usb_device_get_usb_desc(dev);
 
     assert(desc != NULL);
     if (desc->high && (dev->port->speedmask & USB_SPEED_MASK_HIGH)) {
@@ -380,7 +380,7 @@ void usb_desc_attach(USBDevice *dev)
         dev->speed = USB_SPEED_FULL;
     } else {
         fprintf(stderr, "usb: port/device speed mismatch for \"%s\"\n",
-                dev->info->product_desc);
+                usb_device_get_product_desc(dev));
         return;
     }
     usb_desc_setdefaults(dev);
@@ -436,7 +436,7 @@ int usb_desc_string(USBDevice *dev, int index, uint8_t *dest, size_t len)
 
     str = usb_desc_get_string(dev, index);
     if (str == NULL) {
-        str = dev->info->usb_desc->str[index];
+        str = usb_device_get_usb_desc(dev)->str[index];
         if (str == NULL) {
             return 0;
         }
@@ -455,7 +455,7 @@ int usb_desc_string(USBDevice *dev, int index, uint8_t *dest, size_t len)
 
 int usb_desc_get_descriptor(USBDevice *dev, int value, uint8_t *dest, size_t len)
 {
-    const USBDesc *desc = dev->info->usb_desc;
+    const USBDesc *desc = usb_device_get_usb_desc(dev);
     const USBDescDevice *other_dev;
     uint8_t buf[256];
     uint8_t type = value >> 8;
@@ -463,9 +463,9 @@ int usb_desc_get_descriptor(USBDevice *dev, int value, uint8_t *dest, size_t len
     int ret = -1;
 
     if (dev->speed == USB_SPEED_HIGH) {
-        other_dev = dev->info->usb_desc->full;
+        other_dev = usb_device_get_usb_desc(dev)->full;
     } else {
-        other_dev = dev->info->usb_desc->high;
+        other_dev = usb_device_get_usb_desc(dev)->high;
     }
 
     switch(type) {
@@ -520,7 +520,7 @@ int usb_desc_get_descriptor(USBDevice *dev, int value, uint8_t *dest, size_t len
 int usb_desc_handle_control(USBDevice *dev, USBPacket *p,
         int request, int value, int index, int length, uint8_t *data)
 {
-    const USBDesc *desc = dev->info->usb_desc;
+    const USBDesc *desc = usb_device_get_usb_desc(dev);
     int ret = -1;
 
     assert(desc != NULL);
hw/usb-hid.c +64 -44

117 lines not on this page · raw message

hw/usb-hub.c +21 -14
index 069611b..ee4e6a6 100644
@@ -533,23 +533,30 @@ static const VMStateDescription vmstate_usb_hub = {
     }
 };
 
-static struct USBDeviceInfo hub_info = {
-    .product_desc   = "QEMU USB Hub",
-    .qdev.name      = "usb-hub",
-    .qdev.fw_name    = "hub",
-    .qdev.size      = sizeof(USBHubState),
-    .qdev.vmsd      = &vmstate_usb_hub,
-    .usb_desc       = &desc_hub,
-    .init           = usb_hub_initfn,
-    .handle_packet  = usb_hub_handle_packet,
-    .handle_reset   = usb_hub_handle_reset,
-    .handle_control = usb_hub_handle_control,
-    .handle_data    = usb_hub_handle_data,
-    .handle_destroy = usb_hub_handle_destroy,
+static void  usb_hub_class_initfn(ObjectClass *klass, void *data)
+{
+    USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
+
+    uc->init           = usb_hub_initfn;
+    uc->product_desc   = "QEMU USB Hub";
+    uc->usb_desc       = &desc_hub;
+    uc->handle_packet  = usb_hub_handle_packet;
+    uc->handle_reset   = usb_hub_handle_reset;
+    uc->handle_control = usb_hub_handle_control;
+    uc->handle_data    = usb_hub_handle_data;
+    uc->handle_destroy = usb_hub_handle_destroy;
+}
+
+static struct DeviceInfo hub_info = {
+    .name      = "usb-hub",
+    .fw_name   = "hub",
+    .size      = sizeof(USBHubState),
+    .vmsd      = &vmstate_usb_hub,
+    .class_init= usb_hub_class_initfn,
 };
 
 static void usb_hub_register_devices(void)
 {
-    usb_qdev_register(&hub_info);
+    usb_qdev_register(&hub_info, NULL, NULL);
 }
 device_init(usb_hub_register_devices)
hw/usb-msd.c +23 -18

52 lines not on this page · raw message

hw/usb-net.c +23 -18

52 lines not on this page · raw message

hw/usb-serial.c +42 -32

90 lines not on this page · raw message

hw/usb-wacom.c +21 -15
index 61d5b18..9b20a31 100644
@@ -349,24 +349,30 @@ static const VMStateDescription vmstate_usb_wacom = {
     .unmigratable = 1,
 };
 
-static struct USBDeviceInfo wacom_info = {
-    .product_desc   = "QEMU PenPartner Tablet",
-    .qdev.name      = "usb-wacom-tablet",
-    .qdev.desc      = "QEMU PenPartner Tablet",
-    .usbdevice_name = "wacom-tablet",
-    .usb_desc       = &desc_wacom,
-    .qdev.size      = sizeof(USBWacomState),
-    .qdev.vmsd      = &vmstate_usb_wacom,
-    .init           = usb_wacom_initfn,
-    .handle_packet  = usb_generic_handle_packet,
-    .handle_reset   = usb_wacom_handle_reset,
-    .handle_control = usb_wacom_handle_control,
-    .handle_data    = usb_wacom_handle_data,
-    .handle_destroy = usb_wacom_handle_destroy,
+static void usb_wacom_class_init(ObjectClass *class, void *data)
+{
+    USBDeviceClass *uc = USB_DEVICE_CLASS(class);
+
+    uc->product_desc   = "QEMU PenPartner Tablet";
+    uc->usb_desc       = &desc_wacom;
+    uc->init           = usb_wacom_initfn;
+    uc->handle_packet  = usb_generic_handle_packet;
+    uc->handle_reset   = usb_wacom_handle_reset;
+    uc->handle_control = usb_wacom_handle_control;
+    uc->handle_data    = usb_wacom_handle_data;
+    uc->handle_destroy = usb_wacom_handle_destroy;
+}
+
+static struct DeviceInfo wacom_info = {
+    .name      = "usb-wacom-tablet",
+    .desc      = "QEMU PenPartner Tablet",
+    .size      = sizeof(USBWacomState),
+    .vmsd      = &vmstate_usb_wacom,
+    .class_init= usb_wacom_class_init,
 };
 
 static void usb_wacom_register_devices(void)
 {
-    usb_qdev_register(&wacom_info);
+    usb_qdev_register(&wacom_info, "wacom-tablet", NULL);
 }
 device_init(usb_wacom_register_devices)
hw/usb-xhci.c +2 -2
index 28fe9de..95bf010 100644
@@ -1458,7 +1458,7 @@ static int xhci_fire_ctl_transfer(XHCIState *xhci, XHCITransfer *xfer)
     if (!xfer->in_xfer) {
         xhci_xfer_data(xfer, xfer->data, wLength, 0, 1, 0);
     }
-    ret = dev->info->handle_control(dev, &xfer->packet,
+    ret = usb_device_handle_control(dev, &xfer->packet,
                                     (bmRequestType << 8) | bRequest,
                                     wValue, wIndex, wLength, xfer->data);
 
@@ -1767,7 +1767,7 @@ static TRBCCode xhci_address_slot(XHCIState *xhci, unsigned int slotid,
         slot->devaddr = xhci->devaddr++;
         slot_ctx[3] = (SLOT_ADDRESSED << SLOT_STATE_SHIFT) | slot->devaddr;
         DPRINTF("xhci: device address is %d\n", slot->devaddr);
-        dev->info->handle_control(dev, NULL,
+        usb_device_handle_control(dev, NULL,
                                   DeviceOutRequest | USB_REQ_SET_ADDRESS,
                                   slot->devaddr, 0, 0, NULL);
     }
hw/usb.c +10 -14
index 860538a..c3ff5b7 100644
@@ -95,8 +95,8 @@ static int do_token_setup(USBDevice *s, USBPacket *p)
     index   = (s->setup_buf[5] << 8) | s->setup_buf[4];
 
     if (s->setup_buf[0] & USB_DIR_IN) {
-        ret = s->info->handle_control(s, p, request, value, index,
-                                      s->setup_len, s->data_buf);
+        ret = usb_device_handle_control(s, p, request, value, index,
+                                        s->setup_len, s->data_buf);
         if (ret == USB_RET_ASYNC) {
              s->setup_state = SETUP_STATE_SETUP;
              return USB_RET_ASYNC;
@@ -129,7 +129,7 @@ static int do_token_in(USBDevice *s, USBPacket *p)
     int ret = 0;
 
     if (p->devep != 0)
-        return s->info->handle_data(s, p);
+        return usb_device_handle_data(s, p);
 
     request = (s->setup_buf[0] << 8) | s->setup_buf[1];
     value   = (s->setup_buf[3] << 8) | s->setup_buf[2];
@@ -138,8 +138,8 @@ static int do_token_in(USBDevice *s, USBPacket *p)
     switch(s->setup_state) {
     case SETUP_STATE_ACK:
         if (!(s->setup_buf[0] & USB_DIR_IN)) {
-            ret = s->info->handle_control(s, p, request, value, index,
-                                          s->setup_len, s->data_buf);
+            ret = usb_device_handle_control(s, p, request, value, index,
+                                            s->setup_len, s->data_buf);
             if (ret == USB_RET_ASYNC) {
                 return USB_RET_ASYNC;
             }
@@ -176,7 +176,7 @@ static int do_token_in(USBDevice *s, USBPacket *p)
 static int do_token_out(USBDevice *s, USBPacket *p)
 {
     if (p->devep != 0)
-        return s->info->handle_data(s, p);
+        return usb_device_handle_data(s, p);
 
     switch(s->setup_state) {
     case SETUP_STATE_ACK:
@@ -220,9 +220,7 @@ int usb_generic_handle_packet(USBDevice *s, USBPacket *p)
     switch(p->pid) {
     case USB_MSG_ATTACH:
         s->state = USB_STATE_ATTACHED;
-        if (s->info->handle_attach) {
-            s->info->handle_attach(s);
-        }
+        usb_device_handle_attach(s);
         return 0;
 
     case USB_MSG_DETACH:
@@ -233,9 +231,7 @@ int usb_generic_handle_packet(USBDevice *s, USBPacket *p)
         s->remote_wakeup = 0;
         s->addr = 0;
         s->state = USB_STATE_DEFAULT;
-        if (s->info->handle_reset) {
-            s->info->handle_reset(s);
-        }
+        usb_device_handle_reset(s);
         return 0;
     }
 
@@ -326,7 +322,7 @@ int usb_handle_packet(USBDevice *dev, USBPacket *p)
     int ret;
 
     assert(p->owner == NULL);
-    ret = dev->info->handle_packet(dev, p);
+    ret = usb_device_handle_packet(dev, p);
     if (ret == USB_RET_ASYNC) {
         if (p->owner == NULL) {
             p->owner = usb_ep_get(dev, p->pid, p->devep);
@@ -357,7 +353,7 @@ void usb_packet_complete(USBDevice *dev, USBPacket *p)
 void usb_cancel_packet(USBPacket * p)
 {
     assert(p->owner != NULL);
-    p->owner->dev->info->cancel_packet(p->owner->dev, p);
+    usb_device_cancel_packet(p->owner->dev, p);
     p->owner = NULL;
 }
 
hw/usb.h +39 -11

87 lines not on this page · raw message

usb-bsd.c +18 -11
index 1187552..2c6afc8 100644
@@ -397,21 +397,28 @@ fail:
     return ret;
 }
 
-static struct USBDeviceInfo usb_host_dev_info = {
-    .product_desc   = "USB Host Device",
-    .qdev.name      = "usb-host",
-    .qdev.size      = sizeof(USBHostDevice),
-    .init           = usb_host_initfn,
-    .handle_packet  = usb_generic_handle_packet,
-    .handle_reset   = usb_host_handle_reset,
-    .handle_control = usb_host_handle_control,
-    .handle_data    = usb_host_handle_data,
-    .handle_destroy = usb_host_handle_destroy,
+static void usb_host_class_initfn(ObjectClass *klass, void *data)
+{
+    USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
+
+    uc->product_desc   = "USB Host Device";
+    uc->init           = usb_host_initfn;
+    uc->handle_packet  = usb_generic_handle_packet;
+    uc->handle_reset   = usb_host_handle_reset;
+    uc->handle_control = usb_host_handle_control;
+    uc->handle_data    = usb_host_handle_data;
+    uc->handle_destroy = usb_host_handle_destroy;
+}
+
+static struct DeviceInfo usb_host_dev_info = {
+    .name      = "usb-host",
+    .size      = sizeof(USBHostDevice),
+    .class_init= usb_host_initfn,
 };
 
 static void usb_host_register_devices(void)
 {
-    usb_qdev_register(&usb_host_dev_info);
+    usb_qdev_register(&usb_host_dev_info, NULL, NULL);
 }
 device_init(usb_host_register_devices)
 
usb-linux.c +21 -16
index 56898dd..31810f6 100644
@@ -1402,21 +1402,26 @@ static const VMStateDescription vmstate_usb_host = {
     .unmigratable = 1,
 };
 
-static struct USBDeviceInfo usb_host_dev_info = {
-    .product_desc   = "USB Host Device",
-    .qdev.name      = "usb-host",
-    .qdev.size      = sizeof(USBHostDevice),
-    .qdev.vmsd      = &vmstate_usb_host,
-    .init           = usb_host_initfn,
-    .handle_packet  = usb_generic_handle_packet,
-    .cancel_packet  = usb_host_async_cancel,
-    .handle_data    = usb_host_handle_data,
-    .handle_control = usb_host_handle_control,
-    .handle_reset   = usb_host_handle_reset,
-    .handle_destroy = usb_host_handle_destroy,
-    .usbdevice_name = "host",
-    .usbdevice_init = usb_host_device_open,
-    .qdev.props     = (Property[]) {
+static void usb_host_class_initfn(ObjectClass *klass, void *data)
+{
+    USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
+
+    uc->init           = usb_host_initfn;
+    uc->product_desc   = "USB Host Device";
+    uc->handle_packet  = usb_generic_handle_packet;
+    uc->cancel_packet  = usb_host_async_cancel;
+    uc->handle_data    = usb_host_handle_data;
+    uc->handle_control = usb_host_handle_control;
+    uc->handle_reset   = usb_host_handle_reset;
+    uc->handle_destroy = usb_host_handle_destroy;
+}
+
+static struct DeviceInfo usb_host_dev_info = {
+    .name      = "usb-host",
+    .size      = sizeof(USBHostDevice),
+    .vmsd      = &vmstate_usb_host,
+    .class_init= usb_host_class_initfn,
+    .props     = (Property[]) {
         DEFINE_PROP_UINT32("hostbus",  USBHostDevice, match.bus_num,    0),
         DEFINE_PROP_UINT32("hostaddr", USBHostDevice, match.addr,       0),
         DEFINE_PROP_STRING("hostport", USBHostDevice, match.port),
@@ -1429,7 +1434,7 @@ static struct USBDeviceInfo usb_host_dev_info = {
 
 static void usb_host_register_devices(void)
 {
-    usb_qdev_register(&usb_host_dev_info);
+    usb_qdev_register(&usb_host_dev_info, "host", usb_host_device_open);
 }
 device_init(usb_host_register_devices)
 
usb-redir.c +20 -13
index 79d29ec..8f4a29a 100644
@@ -1315,18 +1315,25 @@ static void usbredir_interrupt_packet(void *priv, uint32_t id,
     }
 }
 
-static struct USBDeviceInfo usbredir_dev_info = {
-    .product_desc   = "USB Redirection Device",
-    .qdev.name      = "usb-redir",
-    .qdev.size      = sizeof(USBRedirDevice),
-    .init           = usbredir_initfn,
-    .handle_destroy = usbredir_handle_destroy,
-    .handle_packet  = usb_generic_handle_packet,
-    .cancel_packet  = usbredir_cancel_packet,
-    .handle_reset   = usbredir_handle_reset,
-    .handle_data    = usbredir_handle_data,
-    .handle_control = usbredir_handle_control,
-    .qdev.props     = (Property[]) {
+static void usbredir_class_initfn(ObjectClass *klass, void *data)
+{
+    USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
+
+    uc->init           = usbredir_initfn;
+    uc->product_desc   = "USB Redirection Device";
+    uc->handle_destroy = usbredir_handle_destroy;
+    uc->handle_packet  = usb_generic_handle_packet;
+    uc->cancel_packet  = usbredir_cancel_packet;
+    uc->handle_reset   = usbredir_handle_reset;
+    uc->handle_data    = usbredir_handle_data;
+    uc->handle_control = usbredir_handle_control;
+}
+
+static struct DeviceInfo usbredir_dev_info = {
+    .name      = "usb-redir",
+    .size      = sizeof(USBRedirDevice),
+    .class_init= usbredir_class_initfn,
+    .props     = (Property[]) {
         DEFINE_PROP_CHR("chardev", USBRedirDevice, cs),
         DEFINE_PROP_UINT8("debug", USBRedirDevice, debug, 0),
         DEFINE_PROP_END_OF_LIST(),
@@ -1335,6 +1342,6 @@ static struct USBDeviceInfo usbredir_dev_info = {
 
 static void usbredir_register_devices(void)
 {
-    usb_qdev_register(&usbredir_dev_info);
+    usb_qdev_register(&usbredir_dev_info, NULL, NULL);
 }
 device_init(usbredir_register_devices);
Signature · 1 line
1.7.4.1
#28 lore raw

PATCH v3 14/28 ccid: convert to QEMU Object Model

In reply to Anthony Liguori
---
 hw/ccid-card-emulated.c |   27 ++++++++++------
 hw/ccid-card-passthru.c |   27 ++++++++++------
 hw/ccid.h               |   28 +++++++++++------
 hw/usb-ccid.c           |   76 +++++++++++++++++++++++++++++++++++------------
 4 files changed, 109 insertions(+), 49 deletions(-)
hw/ccid-card-emulated.c +17 -10
index 2d2ebce..6dabe7a 100644
@@ -564,16 +564,23 @@ static int emulated_exitfn(CCIDCardState *base)
     return 0;
 }
 
-static CCIDCardInfo emulated_card_info = {
-    .qdev.name = EMULATED_DEV_NAME,
-    .qdev.desc = "emulated smartcard",
-    .qdev.size = sizeof(EmulatedState),
-    .initfn = emulated_initfn,
-    .exitfn = emulated_exitfn,
-    .get_atr = emulated_get_atr,
-    .apdu_from_guest = emulated_apdu_from_guest,
-    .qdev.unplug    = qdev_simple_unplug_cb,
-    .qdev.props     = (Property[]) {
+static void emulated_class_initfn(ObjectClass *klass, void *data)
+{
+    CCIDCardClass *cc = CCID_CARD_CLASS(klass);
+
+    cc->initfn = emulated_initfn;
+    cc->exitfn = emulated_exitfn;
+    cc->get_atr = emulated_get_atr;
+    cc->apdu_from_guest = emulated_apdu_from_guest;
+}
+
+static DeviceInfo emulated_card_info = {
+    .name = EMULATED_DEV_NAME,
+    .desc = "emulated smartcard",
+    .size = sizeof(EmulatedState),
+    .unplug    = qdev_simple_unplug_cb,
+    .class_init = emulated_class_initfn,
+    .props     = (Property[]) {
         DEFINE_PROP_STRING("backend", EmulatedState, backend_str),
         DEFINE_PROP_STRING("cert1", EmulatedState, cert1),
         DEFINE_PROP_STRING("cert2", EmulatedState, cert2),
hw/ccid-card-passthru.c +17 -10
index 9f51c6c..f563d97 100644
@@ -316,16 +316,23 @@ static VMStateDescription passthru_vmstate = {
     }
 };
 
-static CCIDCardInfo passthru_card_info = {
-    .qdev.name = PASSTHRU_DEV_NAME,
-    .qdev.desc = "passthrough smartcard",
-    .qdev.size = sizeof(PassthruState),
-    .qdev.vmsd = &passthru_vmstate,
-    .initfn = passthru_initfn,
-    .exitfn = passthru_exitfn,
-    .get_atr = passthru_get_atr,
-    .apdu_from_guest = passthru_apdu_from_guest,
-    .qdev.props     = (Property[]) {
+static void passthru_class_initfn(ObjectClass *klass, void *data)
+{
+    CCIDCardClass *cc = CCID_CARD_CLASS(klass);
+
+    cc->initfn = passthru_initfn;
+    cc->exitfn = passthru_exitfn;
+    cc->get_atr = passthru_get_atr;
+    cc->apdu_from_guest = passthru_apdu_from_guest;
+}
+
+static DeviceInfo passthru_card_info = {
+    .name = PASSTHRU_DEV_NAME,
+    .desc = "passthrough smartcard",
+    .size = sizeof(PassthruState),
+    .vmsd = &passthru_vmstate,
+    .class_init = passthru_class_initfn,
+    .props     = (Property[]) {
         DEFINE_PROP_CHR("chardev", PassthruState, cs),
         DEFINE_PROP_UINT8("debug", PassthruState, debug, 0),
         DEFINE_PROP_END_OF_LIST(),
hw/ccid.h +18 -10
index 9e3abe1..9e4979c 100644
@@ -15,26 +15,34 @@
 typedef struct CCIDCardState CCIDCardState;
 typedef struct CCIDCardInfo CCIDCardInfo;
 
-/*
- * state of the CCID Card device (i.e. hw/ccid-card-*.c)
- */
-struct CCIDCardState {
-    DeviceState qdev;
-    uint32_t    slot; /* For future use with multiple slot reader. */
-};
+#define TYPE_CCID_CARD "ccid-card"
+#define CCID_CARD(obj) \
+     OBJECT_CHECK(CCIDCardState, (obj), TYPE_CCID_CARD)
+#define CCID_CARD_CLASS(klass) \
+     OBJECT_CLASS_CHECK(CCIDCardClass, (klass), TYPE_CCID_CARD)
+#define CCID_CARD_GET_CLASS(obj) \
+     OBJECT_GET_CLASS(CCIDCardClass, (obj), TYPE_CCID_CARD)
 
 /*
  * callbacks to be used by the CCID device (hw/usb-ccid.c) to call
  * into the smartcard device (hw/ccid-card-*.c)
  */
-struct CCIDCardInfo {
-    DeviceInfo qdev;
+typedef struct CCIDCardClass {
+    DeviceClass parent_class;
     const uint8_t *(*get_atr)(CCIDCardState *card, uint32_t *len);
     void (*apdu_from_guest)(CCIDCardState *card,
                             const uint8_t *apdu,
                             uint32_t len);
     int (*exitfn)(CCIDCardState *card);
     int (*initfn)(CCIDCardState *card);
+} CCIDCardClass;
+
+/*
+ * state of the CCID Card device (i.e. hw/ccid-card-*.c)
+ */
+struct CCIDCardState {
+    DeviceState qdev;
+    uint32_t    slot; /* For future use with multiple slot reader. */
 };
 
 /*
@@ -46,7 +54,7 @@ void ccid_card_send_apdu_to_guest(CCIDCardState *card,
 void ccid_card_card_removed(CCIDCardState *card);
 void ccid_card_card_inserted(CCIDCardState *card);
 void ccid_card_card_error(CCIDCardState *card, uint64_t error);
-void ccid_card_qdev_register(CCIDCardInfo *card);
+void ccid_card_qdev_register(DeviceInfo *card);
 
 /*
  * support guest visible insertion/removal of ccid devices based on actual
hw/usb-ccid.c +57 -19

145 lines not on this page · raw message

Signature · 1 line
1.7.4.1
#29 lore raw

PATCH v3 15/28 ssi: convert to QEMU Object Model

In reply to Anthony Liguori
---
 hw/ads7846.c   |   17 ++++++++++++-----
 hw/max111x.c   |   34 ++++++++++++++++++++++++----------
 hw/spitz.c     |   39 +++++++++++++++++++++++++++------------
 hw/ssd0323.c   |   17 ++++++++++++-----
 hw/ssi-sd.c    |   17 ++++++++++++-----
 hw/ssi.c       |   23 ++++++++++++-----------
 hw/ssi.h       |   18 +++++++++++++-----
 hw/stellaris.c |   17 ++++++++++++-----
 hw/tosa.c      |   19 +++++++++++++------
 hw/z2.c        |   19 +++++++++++++------
 10 files changed, 150 insertions(+), 70 deletions(-)
hw/ads7846.c +12 -5
index de3f7af..c1b894e 100644
@@ -153,11 +153,18 @@ static int ads7846_init(SSISlave *dev)
     return 0;
 }
 
-static SSISlaveInfo ads7846_info = {
-    .qdev.name ="ads7846",
-    .qdev.size = sizeof(ADS7846State),
-    .init = ads7846_init,
-    .transfer = ads7846_transfer
+static void ads7846_class_init(ObjectClass *klass, void *data)
+{
+    SSISlaveClass *k = SSI_SLAVE_CLASS(klass);
+
+    k->init = ads7846_init;
+    k->transfer = ads7846_transfer;
+}
+
+static DeviceInfo ads7846_info = {
+    .name = "ads7846",
+    .size = sizeof(ADS7846State),
+    .class_init = ads7846_class_init,
 };
 
 static void ads7846_register_devices(void)
hw/max111x.c +24 -10
index fc79814..db17842 100644
@@ -153,18 +153,32 @@ void max111x_set_input(DeviceState *dev, int line, uint8_t value)
     s->input[line] = value;
 }
 
-static SSISlaveInfo max1110_info = {
-    .qdev.name = "max1110",
-    .qdev.size = sizeof(MAX111xState),
-    .init = max1110_init,
-    .transfer = max111x_transfer
+static void max1110_class_init(ObjectClass *klass, void *data)
+{
+    SSISlaveClass *k = SSI_SLAVE_CLASS(klass);
+
+    k->init = max1110_init;
+    k->transfer = max111x_transfer;
+}
+
+static DeviceInfo max1110_info = {
+    .name = "max1110",
+    .size = sizeof(MAX111xState),
+    .class_init = max1110_class_init,
 };
 
-static SSISlaveInfo max1111_info = {
-    .qdev.name = "max1111",
-    .qdev.size = sizeof(MAX111xState),
-    .init = max1111_init,
-    .transfer = max111x_transfer
+static void max1111_class_init(ObjectClass *klass, void *data)
+{
+    SSISlaveClass *k = SSI_SLAVE_CLASS(klass);
+
+    k->init = max1111_init;
+    k->transfer = max111x_transfer;
+}
+
+static DeviceInfo max1111_info = {
+    .name = "max1111",
+    .size = sizeof(MAX111xState),
+    .class_init = max1111_class_init,
 };
 
 static void max111x_register_devices(void)
hw/spitz.c +27 -12
index 9d129c2..0f63139 100644
@@ -1070,12 +1070,20 @@ static const VMStateDescription vmstate_corgi_ssp_regs = {
     }
 };
 
-static SSISlaveInfo corgi_ssp_info = {
-    .qdev.name = "corgi-ssp",
-    .qdev.size = sizeof(CorgiSSPState),
-    .qdev.vmsd = &vmstate_corgi_ssp_regs,
-    .init = corgi_ssp_init,
-    .transfer = corgi_ssp_transfer
+static void corgi_ssp_class_init(ObjectClass *klass, void *data)
+{
+    SSISlaveClass *k = SSI_SLAVE_CLASS(klass);
+
+    k->init = corgi_ssp_init;
+    k->transfer = corgi_ssp_transfer;
+}
+
+
+static DeviceInfo corgi_ssp_info = {
+    .name = "corgi-ssp",
+    .size = sizeof(CorgiSSPState),
+    .vmsd = &vmstate_corgi_ssp_regs,
+    .class_init = corgi_ssp_class_init,
 };
 
 static const VMStateDescription vmstate_spitz_lcdtg_regs = {
@@ -1090,12 +1098,19 @@ static const VMStateDescription vmstate_spitz_lcdtg_regs = {
     }
 };
 
-static SSISlaveInfo spitz_lcdtg_info = {
-    .qdev.name = "spitz-lcdtg",
-    .qdev.size = sizeof(SpitzLCDTG),
-    .qdev.vmsd = &vmstate_spitz_lcdtg_regs,
-    .init = spitz_lcdtg_init,
-    .transfer = spitz_lcdtg_transfer
+static void spitz_lcdtg_class_init(ObjectClass *klass, void *data)
+{
+    SSISlaveClass *k = SSI_SLAVE_CLASS(klass);
+
+    k->init = spitz_lcdtg_init;
+    k->transfer = spitz_lcdtg_transfer;
+}
+
+static DeviceInfo spitz_lcdtg_info = {
+    .name = "spitz-lcdtg",
+    .size = sizeof(SpitzLCDTG),
+    .vmsd = &vmstate_spitz_lcdtg_regs,
+    .class_init = spitz_lcdtg_class_init,
 };
 
 static void spitz_register_devices(void)
hw/ssd0323.c +12 -5
index 1eb3823..8e2fac8 100644
@@ -340,11 +340,18 @@ static int ssd0323_init(SSISlave *dev)
     return 0;
 }
 
-static SSISlaveInfo ssd0323_info = {
-    .qdev.name = "ssd0323",
-    .qdev.size = sizeof(ssd0323_state),
-    .init = ssd0323_init,
-    .transfer = ssd0323_transfer
+static void ssd0323_class_init(ObjectClass *klass, void *data)
+{
+    SSISlaveClass *k = SSI_SLAVE_CLASS(klass);
+
+    k->init = ssd0323_init;
+    k->transfer = ssd0323_transfer;
+}
+
+static DeviceInfo ssd0323_info = {
+    .name = "ssd0323",
+    .size = sizeof(ssd0323_state),
+    .class_init = ssd0323_class_init,
 };
 
 static void ssd03232_register_devices(void)
hw/ssi-sd.c +12 -5
index 2d89cfe..2738cf9 100644
@@ -244,11 +244,18 @@ static int ssi_sd_init(SSISlave *dev)
     return 0;
 }
 
-static SSISlaveInfo ssi_sd_info = {
-    .qdev.name = "ssi-sd",
-    .qdev.size = sizeof(ssi_sd_state),
-    .init = ssi_sd_init,
-    .transfer = ssi_sd_transfer
+static void ssi_sd_class_init(ObjectClass *klass, void *data)
+{
+    SSISlaveClass *k = SSI_SLAVE_CLASS(klass);
+
+    k->init = ssi_sd_init;
+    k->transfer = ssi_sd_transfer;
+}
+
+static DeviceInfo ssi_sd_info = {
+    .name = "ssi-sd",
+    .size = sizeof(ssi_sd_state),
+    .class_init = ssi_sd_class_init,
 };
 
 static void ssi_sd_register_devices(void)
hw/ssi.c +12 -11
index b47953a..99a0616 100644
@@ -23,8 +23,8 @@ static struct BusInfo ssi_bus_info = {
 
 static int ssi_slave_init(DeviceState *dev, DeviceInfo *base_info)
 {
-    SSISlaveInfo *info = container_of(base_info, SSISlaveInfo, qdev);
-    SSISlave *s = SSI_SLAVE_FROM_QDEV(dev);
+    SSISlave *s = SSI_SLAVE(dev);
+    SSISlaveClass *ssc = SSI_SLAVE_GET_CLASS(s);
     SSIBus *bus;
 
     bus = FROM_QBUS(SSIBus, qdev_get_parent_bus(dev));
@@ -33,16 +33,15 @@ static int ssi_slave_init(DeviceState *dev, DeviceInfo *base_info)
         hw_error("Too many devices on SSI bus");
     }
 
-    s->info = info;
-    return info->init(s);
+    return ssc->init(s);
 }
 
-void ssi_register_slave(SSISlaveInfo *info)
+void ssi_register_slave(DeviceInfo *info)
 {
-    assert(info->qdev.size >= sizeof(SSISlave));
-    info->qdev.init = ssi_slave_init;
-    info->qdev.bus_info = &ssi_bus_info;
-    qdev_register(&info->qdev);
+    assert(info->size >= sizeof(SSISlave));
+    info->init = ssi_slave_init;
+    info->bus_info = &ssi_bus_info;
+    qdev_register(info);
 }
 
 DeviceState *ssi_create_slave(SSIBus *bus, const char *name)
@@ -64,10 +63,12 @@ uint32_t ssi_transfer(SSIBus *bus, uint32_t val)
 {
     DeviceState *dev;
     SSISlave *slave;
+    SSISlaveClass *ssc;
     dev = QTAILQ_FIRST(&bus->qbus.children);
     if (!dev) {
         return 0;
     }
-    slave = SSI_SLAVE_FROM_QDEV(dev);
-    return slave->info->transfer(slave, val);
+    slave = SSI_SLAVE(dev);
+    ssc = SSI_SLAVE_GET_CLASS(slave);
+    return ssc->transfer(slave, val);
 }
hw/ssi.h +13 -5
index 24610a8..97aefa7 100644
@@ -15,22 +15,30 @@
 
 typedef struct SSISlave SSISlave;
 
+#define TYPE_SSI_SLAVE "ssi-slave"
+#define SSI_SLAVE(obj) \
+     OBJECT_CHECK(SSISlave, (obj), TYPE_SSI_SLAVE)
+#define SSI_SLAVE_CLASS(klass) \
+     OBJECT_CLASS_CHECK(SSISlaveClass, (klass), TYPE_SSI_SLAVE)
+#define SSI_SLAVE_GET_CLASS(obj) \
+     OBJECT_GET_CLASS(SSISlaveClass, (obj), TYPE_SSI_SLAVE)
+
 /* Slave devices.  */
-typedef struct {
-    DeviceInfo qdev;
+typedef struct SSISlaveClass {
+    DeviceClass parent_class;
+
     int (*init)(SSISlave *dev);
     uint32_t (*transfer)(SSISlave *dev, uint32_t val);
-} SSISlaveInfo;
+} SSISlaveClass;
 
 struct SSISlave {
     DeviceState qdev;
-    SSISlaveInfo *info;
 };
 
 #define SSI_SLAVE_FROM_QDEV(dev) DO_UPCAST(SSISlave, qdev, dev)
 #define FROM_SSI_SLAVE(type, dev) DO_UPCAST(type, ssidev, dev)
 
-void ssi_register_slave(SSISlaveInfo *info);
+void ssi_register_slave(DeviceInfo *info);
 
 DeviceState *ssi_create_slave(SSIBus *bus, const char *name);
 
hw/stellaris.c +12 -5
index 7a73074..a1620cb 100644
@@ -1394,11 +1394,18 @@ static void stellaris_machine_init(void)
 
 machine_init(stellaris_machine_init);
 
-static SSISlaveInfo stellaris_ssi_bus_info = {
-    .qdev.name = "evb6965-ssi",
-    .qdev.size = sizeof(stellaris_ssi_bus_state),
-    .init = stellaris_ssi_bus_init,
-    .transfer = stellaris_ssi_bus_transfer
+static void stellaris_ssi_bus_class_init(ObjectClass *klass, void *data)
+{
+    SSISlaveClass *k = SSI_SLAVE_CLASS(klass);
+
+    k->init = stellaris_ssi_bus_init;
+    k->transfer = stellaris_ssi_bus_transfer;
+}
+
+static DeviceInfo stellaris_ssi_bus_info = {
+    .name = "evb6965-ssi",
+    .size = sizeof(stellaris_ssi_bus_state),
+    .class_init = stellaris_ssi_bus_class_init,
 };
 
 static void stellaris_register_devices(void)
hw/tosa.c +13 -6
index 0caba79..ade4cf6 100644
@@ -266,13 +266,20 @@ static I2CSlaveInfo tosa_dac_info = {
     .event = tosa_dac_event,
     .recv = tosa_dac_recv,
     .send = tosa_dac_send
-};
+ };
+
+static void tosa_ssp_class_init(ObjectClass *klass, void *data)
+{
+    SSISlaveClass *k = SSI_SLAVE_CLASS(klass);
+
+    k->init = tosa_ssp_init;
+    k->transfer = tosa_ssp_tansfer;
+}
 
-static SSISlaveInfo tosa_ssp_info = {
-    .qdev.name = "tosa-ssp",
-    .qdev.size = sizeof(SSISlave),
-    .init = tosa_ssp_init,
-    .transfer = tosa_ssp_tansfer
+static DeviceInfo tosa_ssp_info = {
+    .name = "tosa-ssp",
+    .size = sizeof(SSISlave),
+    .class_init = tosa_ssp_class_init,
 };
 
 static void tosa_register_devices(void)
hw/z2.c +13 -6
index 8d48488..f895892 100644
@@ -174,12 +174,19 @@ static VMStateDescription vmstate_zipit_lcd_state = {
     }
 };
 
-static SSISlaveInfo zipit_lcd_info = {
-    .qdev.name = "zipit-lcd",
-    .qdev.size = sizeof(ZipitLCD),
-    .qdev.vmsd = &vmstate_zipit_lcd_state,
-    .init = zipit_lcd_init,
-    .transfer = zipit_lcd_transfer
+static void zipit_lcd_class_init(ObjectClass *klass, void *data)
+{
+    SSISlaveClass *k = SSI_SLAVE_CLASS(klass);
+
+    k->init = zipit_lcd_init;
+    k->transfer = zipit_lcd_transfer;
+}
+
+static DeviceInfo zipit_lcd_info = {
+    .name = "zipit-lcd",
+    .size = sizeof(ZipitLCD),
+    .vmsd = &vmstate_zipit_lcd_state,
+    .class_init = zipit_lcd_class_init,
 };
 
 typedef struct {
Signature · 1 line
1.7.4.1
#30 lore raw

PATCH v3 16/28 i2c: rename i2c_slave -> I2CSlave

In reply to Anthony Liguori
---
 hw/ds1338.c   |   10 +++++-----
 hw/i2c.c      |   30 +++++++++++++++---------------
 hw/i2c.h      |   22 ++++++++++++----------
 hw/lm832x.c   |   10 +++++-----
 hw/max7310.c  |   10 +++++-----
 hw/pxa2xx.c   |   10 +++++-----
 hw/smbus.c    |    8 ++++----
 hw/smbus.h    |    2 +-
 hw/spitz.c    |    2 +-
 hw/ssd0303.c  |   10 +++++-----
 hw/tmp105.c   |   14 +++++++-------
 hw/tosa.c     |   10 +++++-----
 hw/twl92230.c |   12 ++++++------
 hw/wm8750.c   |   14 +++++++-------
 hw/z2.c       |   10 +++++-----
 15 files changed, 88 insertions(+), 86 deletions(-)
hw/ds1338.c +5 -5
index f754cb7..1c4ba9f 100644
@@ -13,7 +13,7 @@
 #include "i2c.h"
 
 typedef struct {
-    i2c_slave i2c;
+    I2CSlave i2c;
     time_t offset;
     struct tm now;
     uint8_t nvram[56];
@@ -21,7 +21,7 @@ typedef struct {
     int addr_byte;
 } DS1338State;
 
-static void ds1338_event(i2c_slave *i2c, enum i2c_event event)
+static void ds1338_event(I2CSlave *i2c, enum i2c_event event)
 {
     DS1338State *s = FROM_I2C_SLAVE(DS1338State, i2c);
 
@@ -51,7 +51,7 @@ static void ds1338_event(i2c_slave *i2c, enum i2c_event event)
     }
 }
 
-static int ds1338_recv(i2c_slave *i2c)
+static int ds1338_recv(I2CSlave *i2c)
 {
     DS1338State *s = FROM_I2C_SLAVE(DS1338State, i2c);
     uint8_t res;
@@ -61,7 +61,7 @@ static int ds1338_recv(i2c_slave *i2c)
     return res;
 }
 
-static int ds1338_send(i2c_slave *i2c, uint8_t data)
+static int ds1338_send(I2CSlave *i2c, uint8_t data)
 {
     DS1338State *s = FROM_I2C_SLAVE(DS1338State, i2c);
     if (s->addr_byte) {
@@ -113,7 +113,7 @@ static int ds1338_send(i2c_slave *i2c, uint8_t data)
     return 0;
 }
 
-static int ds1338_init(i2c_slave *i2c)
+static int ds1338_init(I2CSlave *i2c)
 {
     return 0;
 }
hw/i2c.c +15 -15
index 9bcf3e1..9efe70c 100644
@@ -12,8 +12,8 @@
 struct i2c_bus
 {
     BusState qbus;
-    i2c_slave *current_dev;
-    i2c_slave *dev;
+    I2CSlave *current_dev;
+    I2CSlave *dev;
     uint8_t saved_address;
 };
 
@@ -21,7 +21,7 @@ static struct BusInfo i2c_bus_info = {
     .name = "I2C",
     .size = sizeof(i2c_bus),
     .props = (Property[]) {
-        DEFINE_PROP_UINT8("address", struct i2c_slave, address, 0),
+        DEFINE_PROP_UINT8("address", struct I2CSlave, address, 0),
         DEFINE_PROP_END_OF_LIST(),
     }
 };
@@ -66,7 +66,7 @@ i2c_bus *i2c_init_bus(DeviceState *parent, const char *name)
     return bus;
 }
 
-void i2c_set_slave_address(i2c_slave *dev, uint8_t address)
+void i2c_set_slave_address(I2CSlave *dev, uint8_t address)
 {
     dev->address = address;
 }
@@ -82,10 +82,10 @@ int i2c_bus_busy(i2c_bus *bus)
 int i2c_start_transfer(i2c_bus *bus, uint8_t address, int recv)
 {
     DeviceState *qdev;
-    i2c_slave *slave = NULL;
+    I2CSlave *slave = NULL;
 
     QTAILQ_FOREACH(qdev, &bus->qbus.children, sibling) {
-        i2c_slave *candidate = I2C_SLAVE_FROM_QDEV(qdev);
+        I2CSlave *candidate = I2C_SLAVE_FROM_QDEV(qdev);
         if (candidate->address == address) {
             slave = candidate;
             break;
@@ -104,7 +104,7 @@ int i2c_start_transfer(i2c_bus *bus, uint8_t address, int recv)
 
 void i2c_end_transfer(i2c_bus *bus)
 {
-    i2c_slave *dev = bus->current_dev;
+    I2CSlave *dev = bus->current_dev;
 
     if (!dev)
         return;
@@ -116,7 +116,7 @@ void i2c_end_transfer(i2c_bus *bus)
 
 int i2c_send(i2c_bus *bus, uint8_t data)
 {
-    i2c_slave *dev = bus->current_dev;
+    I2CSlave *dev = bus->current_dev;
 
     if (!dev)
         return -1;
@@ -126,7 +126,7 @@ int i2c_send(i2c_bus *bus, uint8_t data)
 
 int i2c_recv(i2c_bus *bus)
 {
-    i2c_slave *dev = bus->current_dev;
+    I2CSlave *dev = bus->current_dev;
 
     if (!dev)
         return -1;
@@ -136,7 +136,7 @@ int i2c_recv(i2c_bus *bus)
 
 void i2c_nack(i2c_bus *bus)
 {
-    i2c_slave *dev = bus->current_dev;
+    I2CSlave *dev = bus->current_dev;
 
     if (!dev)
         return;
@@ -146,7 +146,7 @@ void i2c_nack(i2c_bus *bus)
 
 static int i2c_slave_post_load(void *opaque, int version_id)
 {
-    i2c_slave *dev = opaque;
+    I2CSlave *dev = opaque;
     i2c_bus *bus;
     bus = FROM_QBUS(i2c_bus, qdev_get_parent_bus(&dev->qdev));
     if (bus->saved_address == dev->address) {
@@ -156,13 +156,13 @@ static int i2c_slave_post_load(void *opaque, int version_id)
 }
 
 const VMStateDescription vmstate_i2c_slave = {
-    .name = "i2c_slave",
+    .name = "I2CSlave",
     .version_id = 1,
     .minimum_version_id = 1,
     .minimum_version_id_old = 1,
     .post_load = i2c_slave_post_load,
     .fields      = (VMStateField []) {
-        VMSTATE_UINT8(address, i2c_slave),
+        VMSTATE_UINT8(address, I2CSlave),
         VMSTATE_END_OF_LIST()
     }
 };
@@ -170,7 +170,7 @@ const VMStateDescription vmstate_i2c_slave = {
 static int i2c_slave_qdev_init(DeviceState *dev, DeviceInfo *base)
 {
     I2CSlaveInfo *info = container_of(base, I2CSlaveInfo, qdev);
-    i2c_slave *s = I2C_SLAVE_FROM_QDEV(dev);
+    I2CSlave *s = I2C_SLAVE_FROM_QDEV(dev);
 
     s->info = info;
 
@@ -179,7 +179,7 @@ static int i2c_slave_qdev_init(DeviceState *dev, DeviceInfo *base)
 
 void i2c_register_slave(I2CSlaveInfo *info)
 {
-    assert(info->qdev.size >= sizeof(i2c_slave));
+    assert(info->qdev.size >= sizeof(I2CSlave));
     info->qdev.init = i2c_slave_qdev_init;
     info->qdev.bus_info = &i2c_bus_info;
     qdev_register(&info->qdev);
hw/i2c.h +12 -10
index a3383ff..d45cdad 100644
@@ -15,14 +15,16 @@ enum i2c_event {
     I2C_NACK /* Masker NACKed a receive byte.  */
 };
 
+typedef struct I2CSlave I2CSlave;
+
 /* Master to slave.  */
-typedef int (*i2c_send_cb)(i2c_slave *s, uint8_t data);
+typedef int (*i2c_send_cb)(I2CSlave *s, uint8_t data);
 /* Slave to master.  */
-typedef int (*i2c_recv_cb)(i2c_slave *s);
+typedef int (*i2c_recv_cb)(I2CSlave *s);
 /* Notify the slave of a bus state change.  */
-typedef void (*i2c_event_cb)(i2c_slave *s, enum i2c_event event);
+typedef void (*i2c_event_cb)(I2CSlave *s, enum i2c_event event);
 
-typedef int (*i2c_slave_initfn)(i2c_slave *dev);
+typedef int (*i2c_slave_initfn)(I2CSlave *dev);
 
 typedef struct {
     DeviceInfo qdev;
@@ -34,7 +36,7 @@ typedef struct {
     i2c_send_cb send;
 } I2CSlaveInfo;
 
-struct i2c_slave
+struct I2CSlave
 {
     DeviceState qdev;
     I2CSlaveInfo *info;
@@ -44,7 +46,7 @@ struct i2c_slave
 };
 
 i2c_bus *i2c_init_bus(DeviceState *parent, const char *name);
-void i2c_set_slave_address(i2c_slave *dev, uint8_t address);
+void i2c_set_slave_address(I2CSlave *dev, uint8_t address);
 int i2c_bus_busy(i2c_bus *bus);
 int i2c_start_transfer(i2c_bus *bus, uint8_t address, int recv);
 void i2c_end_transfer(i2c_bus *bus);
@@ -52,7 +54,7 @@ void i2c_nack(i2c_bus *bus);
 int i2c_send(i2c_bus *bus, uint8_t data);
 int i2c_recv(i2c_bus *bus);
 
-#define I2C_SLAVE_FROM_QDEV(dev) DO_UPCAST(i2c_slave, qdev, dev)
+#define I2C_SLAVE_FROM_QDEV(dev) DO_UPCAST(I2CSlave, qdev, dev)
 #define FROM_I2C_SLAVE(type, dev) DO_UPCAST(type, i2c, dev)
 
 void i2c_register_slave(I2CSlaveInfo *type);
@@ -69,7 +71,7 @@ void wm8750_dac_commit(void *opaque);
 void wm8750_set_bclk_in(void *opaque, int new_hz);
 
 /* tmp105.c */
-void tmp105_set(i2c_slave *i2c, int temp);
+void tmp105_set(I2CSlave *i2c, int temp);
 
 /* lm832x.c */
 void lm832x_key_event(DeviceState *dev, int key, int state);
@@ -78,10 +80,10 @@ extern const VMStateDescription vmstate_i2c_slave;
 
 #define VMSTATE_I2C_SLAVE(_field, _state) {                          \
     .name       = (stringify(_field)),                               \
-    .size       = sizeof(i2c_slave),                                 \
+    .size       = sizeof(I2CSlave),                                  \
     .vmsd       = &vmstate_i2c_slave,                                \
     .flags      = VMS_STRUCT,                                        \
-    .offset     = vmstate_offset_value(_state, _field, i2c_slave),   \
+    .offset     = vmstate_offset_value(_state, _field, I2CSlave),    \
 }
 
 #endif
hw/lm832x.c +5 -5
index 992ce49..9e53cb3 100644
@@ -24,7 +24,7 @@
 #include "console.h"
 
 typedef struct {
-    i2c_slave i2c;
+    I2CSlave i2c;
     uint8_t i2c_dir;
     uint8_t i2c_cycle;
     uint8_t reg;
@@ -378,7 +378,7 @@ static void lm_kbd_write(LM823KbdState *s, int reg, int byte, uint8_t value)
     }
 }
 
-static void lm_i2c_event(i2c_slave *i2c, enum i2c_event event)
+static void lm_i2c_event(I2CSlave *i2c, enum i2c_event event)
 {
     LM823KbdState *s = FROM_I2C_SLAVE(LM823KbdState, i2c);
 
@@ -394,14 +394,14 @@ static void lm_i2c_event(i2c_slave *i2c, enum i2c_event event)
     }
 }
 
-static int lm_i2c_rx(i2c_slave *i2c)
+static int lm_i2c_rx(I2CSlave *i2c)
 {
     LM823KbdState *s = FROM_I2C_SLAVE(LM823KbdState, i2c);
 
     return lm_kbd_read(s, s->reg, s->i2c_cycle ++);
 }
 
-static int lm_i2c_tx(i2c_slave *i2c, uint8_t data)
+static int lm_i2c_tx(I2CSlave *i2c, uint8_t data)
 {
     LM823KbdState *s = (LM823KbdState *) i2c;
 
@@ -458,7 +458,7 @@ static const VMStateDescription vmstate_lm_kbd = {
 };
 
 
-static int lm8323_init(i2c_slave *i2c)
+static int lm8323_init(I2CSlave *i2c)
 {
     LM823KbdState *s = FROM_I2C_SLAVE(LM823KbdState, i2c);
 
hw/max7310.c +5 -5
index c1bdb2e..a955236 100644
@@ -10,7 +10,7 @@
 #include "i2c.h"
 
 typedef struct {
-    i2c_slave i2c;
+    I2CSlave i2c;
     int i2c_command_byte;
     int len;
 
@@ -33,7 +33,7 @@ static void max7310_reset(DeviceState *dev)
     s->command = 0x00;
 }
 
-static int max7310_rx(i2c_slave *i2c)
+static int max7310_rx(I2CSlave *i2c)
 {
     MAX7310State *s = (MAX7310State *) i2c;
 
@@ -68,7 +68,7 @@ static int max7310_rx(i2c_slave *i2c)
     return 0xff;
 }
 
-static int max7310_tx(i2c_slave *i2c, uint8_t data)
+static int max7310_tx(I2CSlave *i2c, uint8_t data)
 {
     MAX7310State *s = (MAX7310State *) i2c;
     uint8_t diff;
@@ -123,7 +123,7 @@ static int max7310_tx(i2c_slave *i2c, uint8_t data)
     return 0;
 }
 
-static void max7310_event(i2c_slave *i2c, enum i2c_event event)
+static void max7310_event(I2CSlave *i2c, enum i2c_event event)
 {
     MAX7310State *s = (MAX7310State *) i2c;
     s->len = 0;
@@ -175,7 +175,7 @@ static void max7310_gpio_set(void *opaque, int line, int level)
 
 /* MAX7310 is SMBus-compatible (can be used with only SMBus protocols),
  * but also accepts sequences that are not SMBus so return an I2C device.  */
-static int max7310_init(i2c_slave *i2c)
+static int max7310_init(I2CSlave *i2c)
 {
     MAX7310State *s = FROM_I2C_SLAVE(MAX7310State, i2c);
 
hw/pxa2xx.c +5 -5
index 6ddd500..895fb3f 100644
@@ -1243,7 +1243,7 @@ static SysBusDeviceInfo pxa2xx_rtc_sysbus_info = {
 
 /* I2C Interface */
 typedef struct {
-    i2c_slave i2c;
+    I2CSlave i2c;
     PXA2xxI2CState *host;
 } PXA2xxI2CSlaveState;
 
@@ -1279,7 +1279,7 @@ static void pxa2xx_i2c_update(PXA2xxI2CState *s)
 }
 
 /* These are only stubs now.  */
-static void pxa2xx_i2c_event(i2c_slave *i2c, enum i2c_event event)
+static void pxa2xx_i2c_event(I2CSlave *i2c, enum i2c_event event)
 {
     PXA2xxI2CSlaveState *slave = FROM_I2C_SLAVE(PXA2xxI2CSlaveState, i2c);
     PXA2xxI2CState *s = slave->host;
@@ -1303,7 +1303,7 @@ static void pxa2xx_i2c_event(i2c_slave *i2c, enum i2c_event event)
     pxa2xx_i2c_update(s);
 }
 
-static int pxa2xx_i2c_rx(i2c_slave *i2c)
+static int pxa2xx_i2c_rx(I2CSlave *i2c)
 {
     PXA2xxI2CSlaveState *slave = FROM_I2C_SLAVE(PXA2xxI2CSlaveState, i2c);
     PXA2xxI2CState *s = slave->host;
@@ -1318,7 +1318,7 @@ static int pxa2xx_i2c_rx(i2c_slave *i2c)
     return s->data;
 }
 
-static int pxa2xx_i2c_tx(i2c_slave *i2c, uint8_t data)
+static int pxa2xx_i2c_tx(I2CSlave *i2c, uint8_t data)
 {
     PXA2xxI2CSlaveState *slave = FROM_I2C_SLAVE(PXA2xxI2CSlaveState, i2c);
     PXA2xxI2CState *s = slave->host;
@@ -1466,7 +1466,7 @@ static const VMStateDescription vmstate_pxa2xx_i2c = {
     }
 };
 
-static int pxa2xx_i2c_slave_init(i2c_slave *i2c)
+static int pxa2xx_i2c_slave_init(I2CSlave *i2c)
 {
     /* Nothing to do.  */
     return 0;
hw/smbus.c +4 -4
index ff027c8..0cb3566 100644
@@ -65,7 +65,7 @@ static void smbus_do_write(SMBusDevice *dev)
     }
 }
 
-static void smbus_i2c_event(i2c_slave *s, enum i2c_event event)
+static void smbus_i2c_event(I2CSlave *s, enum i2c_event event)
 {
     SMBusDevice *dev = FROM_I2C_SLAVE(SMBusDevice, s);
 
@@ -148,7 +148,7 @@ static void smbus_i2c_event(i2c_slave *s, enum i2c_event event)
     }
 }
 
-static int smbus_i2c_recv(i2c_slave *s)
+static int smbus_i2c_recv(I2CSlave *s)
 {
     SMBusDeviceInfo *t = container_of(s->info, SMBusDeviceInfo, i2c);
     SMBusDevice *dev = FROM_I2C_SLAVE(SMBusDevice, s);
@@ -182,7 +182,7 @@ static int smbus_i2c_recv(i2c_slave *s)
     return ret;
 }
 
-static int smbus_i2c_send(i2c_slave *s, uint8_t data)
+static int smbus_i2c_send(I2CSlave *s, uint8_t data)
 {
     SMBusDevice *dev = FROM_I2C_SLAVE(SMBusDevice, s);
 
@@ -198,7 +198,7 @@ static int smbus_i2c_send(i2c_slave *s, uint8_t data)
     return 0;
 }
 
-static int smbus_device_init(i2c_slave *i2c)
+static int smbus_device_init(I2CSlave *i2c)
 {
     SMBusDeviceInfo *t = container_of(i2c->info, SMBusDeviceInfo, i2c);
     SMBusDevice *dev = FROM_I2C_SLAVE(SMBusDevice, i2c);
hw/smbus.h +1 -1
index a398715..2f2d49e 100644
@@ -26,7 +26,7 @@
 
 struct SMBusDevice {
     /* The SMBus protocol is implemented on top of I2C.  */
-    i2c_slave i2c;
+    I2CSlave i2c;
 
     /* Remaining fields for internal use only.  */
     int mode;
hw/spitz.c +1 -1
index 0f63139..a2a778f 100644
@@ -717,7 +717,7 @@ static void spitz_microdrive_attach(PXA2xxState *cpu, int slot)
 
 static void spitz_wm8750_addr(void *opaque, int line, int level)
 {
-    i2c_slave *wm = (i2c_slave *) opaque;
+    I2CSlave *wm = (I2CSlave *) opaque;
     if (level)
         i2c_set_slave_address(wm, SPITZ_WM_ADDRH);
     else
hw/ssd0303.c +5 -5
index bcad7bf..6a9a8a7 100644
@@ -42,7 +42,7 @@ enum ssd0303_cmd {
 };
 
 typedef struct {
-    i2c_slave i2c;
+    I2CSlave i2c;
     DisplayState *ds;
     int row;
     int col;
@@ -57,13 +57,13 @@ typedef struct {
     uint8_t framebuffer[132*8];
 } ssd0303_state;
 
-static int ssd0303_recv(i2c_slave *i2c)
+static int ssd0303_recv(I2CSlave *i2c)
 {
     BADF("Reads not implemented\n");
     return -1;
 }
 
-static int ssd0303_send(i2c_slave *i2c, uint8_t data)
+static int ssd0303_send(I2CSlave *i2c, uint8_t data)
 {
     ssd0303_state *s = (ssd0303_state *)i2c;
     enum ssd0303_cmd old_cmd_state;
@@ -173,7 +173,7 @@ static int ssd0303_send(i2c_slave *i2c, uint8_t data)
     return 0;
 }
 
-static void ssd0303_event(i2c_slave *i2c, enum i2c_event event)
+static void ssd0303_event(I2CSlave *i2c, enum i2c_event event)
 {
     ssd0303_state *s = (ssd0303_state *)i2c;
     switch (event) {
@@ -283,7 +283,7 @@ static const VMStateDescription vmstate_ssd0303 = {
     }
 };
 
-static int ssd0303_init(i2c_slave *i2c)
+static int ssd0303_init(I2CSlave *i2c)
 {
     ssd0303_state *s = FROM_I2C_SLAVE(ssd0303_state, i2c);
 
hw/tmp105.c +7 -7
index f7e6f2b..ed8a0f3 100644
@@ -22,7 +22,7 @@
 #include "i2c.h"
 
 typedef struct {
-    i2c_slave i2c;
+    I2CSlave i2c;
     uint8_t len;
     uint8_t buf[2];
     qemu_irq pin;
@@ -65,7 +65,7 @@ static void tmp105_alarm_update(TMP105State *s)
 }
 
 /* Units are 0.001 centigrades relative to 0 C.  */
-void tmp105_set(i2c_slave *i2c, int temp)
+void tmp105_set(I2CSlave *i2c, int temp)
 {
     TMP105State *s = (TMP105State *) i2c;
 
@@ -138,7 +138,7 @@ static void tmp105_write(TMP105State *s)
     }
 }
 
-static int tmp105_rx(i2c_slave *i2c)
+static int tmp105_rx(I2CSlave *i2c)
 {
     TMP105State *s = (TMP105State *) i2c;
 
@@ -148,7 +148,7 @@ static int tmp105_rx(i2c_slave *i2c)
         return 0xff;
 }
 
-static int tmp105_tx(i2c_slave *i2c, uint8_t data)
+static int tmp105_tx(I2CSlave *i2c, uint8_t data)
 {
     TMP105State *s = (TMP105State *) i2c;
 
@@ -163,7 +163,7 @@ static int tmp105_tx(i2c_slave *i2c, uint8_t data)
     return 0;
 }
 
-static void tmp105_event(i2c_slave *i2c, enum i2c_event event)
+static void tmp105_event(I2CSlave *i2c, enum i2c_event event)
 {
     TMP105State *s = (TMP105State *) i2c;
 
@@ -202,7 +202,7 @@ static const VMStateDescription vmstate_tmp105 = {
     }
 };
 
-static void tmp105_reset(i2c_slave *i2c)
+static void tmp105_reset(I2CSlave *i2c)
 {
     TMP105State *s = (TMP105State *) i2c;
 
@@ -215,7 +215,7 @@ static void tmp105_reset(i2c_slave *i2c)
     tmp105_interrupt_update(s);
 }
 
-static int tmp105_init(i2c_slave *i2c)
+static int tmp105_init(I2CSlave *i2c)
 {
     TMP105State *s = FROM_I2C_SLAVE(TMP105State, i2c);
 
hw/tosa.c +5 -5
index ade4cf6..5f4968d 100644
@@ -133,12 +133,12 @@ static int tosa_ssp_init(SSISlave *dev)
 }
 
 typedef struct {
-    i2c_slave i2c;
+    I2CSlave i2c;
     int len;
     char buf[3];
 } TosaDACState;
 
-static int tosa_dac_send(i2c_slave *i2c, uint8_t data)
+static int tosa_dac_send(I2CSlave *i2c, uint8_t data)
 {
     TosaDACState *s = FROM_I2C_SLAVE(TosaDACState, i2c);
     s->buf[s->len] = data;
@@ -157,7 +157,7 @@ static int tosa_dac_send(i2c_slave *i2c, uint8_t data)
     return 0;
 }
 
-static void tosa_dac_event(i2c_slave *i2c, enum i2c_event event)
+static void tosa_dac_event(I2CSlave *i2c, enum i2c_event event)
 {
     TosaDACState *s = FROM_I2C_SLAVE(TosaDACState, i2c);
     s->len = 0;
@@ -180,13 +180,13 @@ static void tosa_dac_event(i2c_slave *i2c, enum i2c_event event)
     }
 }
 
-static int tosa_dac_recv(i2c_slave *s)
+static int tosa_dac_recv(I2CSlave *s)
 {
     printf("%s: recv not supported!!!\n", __FUNCTION__);
     return -1;
 }
 
-static int tosa_dac_init(i2c_slave *i2c)
+static int tosa_dac_init(I2CSlave *i2c)
 {
     /* Nothing to do.  */
     return 0;
hw/twl92230.c +6 -6
index a75448f..ced705c 100644
@@ -27,7 +27,7 @@
 #define VERBOSE 1
 
 typedef struct {
-    i2c_slave i2c;
+    I2CSlave i2c;
 
     int firstbyte;
     uint8_t reg;
@@ -126,7 +126,7 @@ static void menelaus_rtc_hz(void *opaque)
     menelaus_update(s);
 }
 
-static void menelaus_reset(i2c_slave *i2c)
+static void menelaus_reset(I2CSlave *i2c)
 {
     MenelausState *s = (MenelausState *) i2c;
     s->reg = 0x00;
@@ -709,7 +709,7 @@ static void menelaus_write(void *opaque, uint8_t addr, uint8_t value)
     }
 }
 
-static void menelaus_event(i2c_slave *i2c, enum i2c_event event)
+static void menelaus_event(I2CSlave *i2c, enum i2c_event event)
 {
     MenelausState *s = (MenelausState *) i2c;
 
@@ -717,7 +717,7 @@ static void menelaus_event(i2c_slave *i2c, enum i2c_event event)
         s->firstbyte = 1;
 }
 
-static int menelaus_tx(i2c_slave *i2c, uint8_t data)
+static int menelaus_tx(I2CSlave *i2c, uint8_t data)
 {
     MenelausState *s = (MenelausState *) i2c;
     /* Interpret register address byte */
@@ -730,7 +730,7 @@ static int menelaus_tx(i2c_slave *i2c, uint8_t data)
     return 0;
 }
 
-static int menelaus_rx(i2c_slave *i2c)
+static int menelaus_rx(I2CSlave *i2c)
 {
     MenelausState *s = (MenelausState *) i2c;
 
@@ -842,7 +842,7 @@ static const VMStateDescription vmstate_menelaus = {
     }
 };
 
-static int twl92230_init(i2c_slave *i2c)
+static int twl92230_init(I2CSlave *i2c)
 {
     MenelausState *s = FROM_I2C_SLAVE(MenelausState, i2c);
 
hw/wm8750.c +7 -7
index 9fbdf3d..5526bc4 100644
@@ -24,7 +24,7 @@ typedef struct {
 } WMRate;
 
 typedef struct {
-    i2c_slave i2c;
+    I2CSlave i2c;
     uint8_t i2c_data[2];
     int i2c_len;
     QEMUSoundCard card;
@@ -254,7 +254,7 @@ static void wm8750_clk_update(WM8750State *s, int ext)
     }
 }
 
-static void wm8750_reset(i2c_slave *i2c)
+static void wm8750_reset(I2CSlave *i2c)
 {
     WM8750State *s = (WM8750State *) i2c;
     s->rate = &wm_rate_table[0];
@@ -297,7 +297,7 @@ static void wm8750_reset(i2c_slave *i2c)
     s->i2c_len = 0;
 }
 
-static void wm8750_event(i2c_slave *i2c, enum i2c_event event)
+static void wm8750_event(I2CSlave *i2c, enum i2c_event event)
 {
     WM8750State *s = (WM8750State *) i2c;
 
@@ -354,7 +354,7 @@ static void wm8750_event(i2c_slave *i2c, enum i2c_event event)
 #define WM8750_ROUT2V	0x29
 #define WM8750_MOUTV	0x2a
 
-static int wm8750_tx(i2c_slave *i2c, uint8_t data)
+static int wm8750_tx(I2CSlave *i2c, uint8_t data)
 {
     WM8750State *s = (WM8750State *) i2c;
     uint8_t cmd;
@@ -554,7 +554,7 @@ static int wm8750_tx(i2c_slave *i2c, uint8_t data)
     return 0;
 }
 
-static int wm8750_rx(i2c_slave *i2c)
+static int wm8750_rx(I2CSlave *i2c)
 {
     return 0x00;
 }
@@ -609,7 +609,7 @@ static const VMStateDescription vmstate_wm8750 = {
     }
 };
 
-static int wm8750_init(i2c_slave *i2c)
+static int wm8750_init(I2CSlave *i2c)
 {
     WM8750State *s = FROM_I2C_SLAVE(WM8750State, i2c);
 
@@ -620,7 +620,7 @@ static int wm8750_init(i2c_slave *i2c)
 }
 
 #if 0
-static void wm8750_fini(i2c_slave *i2c)
+static void wm8750_fini(I2CSlave *i2c)
 {
     WM8750State *s = (WM8750State *) i2c;
     wm8750_reset(&s->i2c);
hw/z2.c +5 -5
index f895892..2984a60 100644
@@ -190,12 +190,12 @@ static DeviceInfo zipit_lcd_info = {
 };
 
 typedef struct {
-    i2c_slave i2c;
+    I2CSlave i2c;
     int len;
     uint8_t buf[3];
 } AER915State;
 
-static int aer915_send(i2c_slave *i2c, uint8_t data)
+static int aer915_send(I2CSlave *i2c, uint8_t data)
 {
     AER915State *s = FROM_I2C_SLAVE(AER915State, i2c);
     s->buf[s->len] = data;
@@ -213,7 +213,7 @@ static int aer915_send(i2c_slave *i2c, uint8_t data)
     return 0;
 }
 
-static void aer915_event(i2c_slave *i2c, enum i2c_event event)
+static void aer915_event(I2CSlave *i2c, enum i2c_event event)
 {
     AER915State *s = FROM_I2C_SLAVE(AER915State, i2c);
     switch (event) {
@@ -232,7 +232,7 @@ static void aer915_event(i2c_slave *i2c, enum i2c_event event)
     }
 }
 
-static int aer915_recv(i2c_slave *slave)
+static int aer915_recv(I2CSlave *slave)
 {
     int retval = 0x00;
     AER915State *s = FROM_I2C_SLAVE(AER915State, slave);
@@ -255,7 +255,7 @@ static int aer915_recv(i2c_slave *slave)
     return retval;
 }
 
-static int aer915_init(i2c_slave *i2c)
+static int aer915_init(I2CSlave *i2c)
 {
     /* Nothing to do.  */
     return 0;
Signature · 1 line
1.7.4.1
#31 lore raw

PATCH v3 17/28 i2c: smbus: convert to QEMU Object Model

In reply to Anthony Liguori

This converts two types because smbus is implemented as a subclass of i2c. It's extremely difficult to convert these two independently.

---
 hw/ds1338.c       |   21 +++++++++----
 hw/i2c.c          |   83 +++++++++++++++++++++++++++++++++++++++++-----------
 hw/i2c.h          |   40 ++++++++++++++-----------
 hw/lm832x.c       |   23 +++++++++-----
 hw/max7310.c      |   25 ++++++++++------
 hw/pxa2xx.c       |   21 +++++++++----
 hw/smbus.c        |   77 ++++++++++++++++++++++++++++++++-----------------
 hw/smbus.h        |   42 ++++++++++++++++++---------
 hw/smbus_eeprom.c |   27 +++++++++++------
 hw/ssd0303.c      |   23 +++++++++-----
 hw/tmp105.c       |   23 +++++++++-----
 hw/tosa.c         |   21 +++++++++----
 hw/twl92230.c     |   23 +++++++++-----
 hw/wm8750.c       |   23 +++++++++-----
 hw/z2.c           |   23 +++++++++-----
 15 files changed, 331 insertions(+), 164 deletions(-)
hw/ds1338.c +14 -7
index 1c4ba9f..4e09efe 100644
@@ -118,13 +118,20 @@ static int ds1338_init(I2CSlave *i2c)
     return 0;
 }
 
-static I2CSlaveInfo ds1338_info = {
-    .qdev.name = "ds1338",
-    .qdev.size = sizeof(DS1338State),
-    .init = ds1338_init,
-    .event = ds1338_event,
-    .recv = ds1338_recv,
-    .send = ds1338_send,
+static void ds1338_class_init(ObjectClass *klass, void *data)
+{
+    I2CSlaveClass *k = I2C_SLAVE_CLASS(klass);
+
+    k->init = ds1338_init;
+    k->event = ds1338_event;
+    k->recv = ds1338_recv;
+    k->send = ds1338_send;
+}
+
+static DeviceInfo ds1338_info = {
+    .name = "ds1338",
+    .size = sizeof(DS1338State),
+    .class_init = ds1338_class_init,
 };
 
 static void ds1338_register_devices(void)
hw/i2c.c +65 -18

149 lines not on this page · raw message

hw/i2c.h +23 -17
index d45cdad..31fd59c 100644
@@ -17,29 +17,34 @@ enum i2c_event {
 
 typedef struct I2CSlave I2CSlave;
 
-/* Master to slave.  */
-typedef int (*i2c_send_cb)(I2CSlave *s, uint8_t data);
-/* Slave to master.  */
-typedef int (*i2c_recv_cb)(I2CSlave *s);
-/* Notify the slave of a bus state change.  */
-typedef void (*i2c_event_cb)(I2CSlave *s, enum i2c_event event);
+#define TYPE_I2C_SLAVE "i2c-slave"
+#define I2C_SLAVE(obj) \
+     OBJECT_CHECK(I2CSlave, (obj), TYPE_I2C_SLAVE)
+#define I2C_SLAVE_CLASS(klass) \
+     OBJECT_CLASS_CHECK(I2CSlaveClass, (klass), TYPE_I2C_SLAVE)
+#define I2C_SLAVE_GET_CLASS(obj) \
+     OBJECT_GET_CLASS(I2CSlaveClass, (obj), TYPE_I2C_SLAVE)
+
+typedef struct I2CSlaveClass
+{
+    DeviceClass parent_class;
+
+    /* Callbacks provided by the device.  */
+    int (*init)(I2CSlave *dev);
 
-typedef int (*i2c_slave_initfn)(I2CSlave *dev);
+    /* Master to slave.  */
+    int (*send)(I2CSlave *s, uint8_t data);
 
-typedef struct {
-    DeviceInfo qdev;
+    /* Slave to master.  */
+    int (*recv)(I2CSlave *s);
 
-    /* Callbacks provided by the device.  */
-    i2c_slave_initfn init;
-    i2c_event_cb event;
-    i2c_recv_cb recv;
-    i2c_send_cb send;
-} I2CSlaveInfo;
+    /* Notify the slave of a bus state change.  */
+    void (*event)(I2CSlave *s, enum i2c_event event);
+} I2CSlaveClass;
 
 struct I2CSlave
 {
     DeviceState qdev;
-    I2CSlaveInfo *info;
 
     /* Remaining fields for internal use by the I2C code.  */
     uint8_t address;
@@ -57,7 +62,8 @@ int i2c_recv(i2c_bus *bus);
 #define I2C_SLAVE_FROM_QDEV(dev) DO_UPCAST(I2CSlave, qdev, dev)
 #define FROM_I2C_SLAVE(type, dev) DO_UPCAST(type, i2c, dev)
 
-void i2c_register_slave(I2CSlaveInfo *type);
+void i2c_register_slave(DeviceInfo *type);
+void i2c_register_slave_subclass(DeviceInfo *info, const char *parent);
 
 DeviceState *i2c_create_slave(i2c_bus *bus, const char *name, uint8_t addr);
 
hw/lm832x.c +15 -8
index 9e53cb3..84f81fe 100644
@@ -494,14 +494,21 @@ void lm832x_key_event(DeviceState *dev, int key, int state)
     lm_kbd_irq_update(s);
 }
 
-static I2CSlaveInfo lm8323_info = {
-    .qdev.name = "lm8323",
-    .qdev.size = sizeof(LM823KbdState),
-    .qdev.vmsd = &vmstate_lm_kbd,
-    .init = lm8323_init,
-    .event = lm_i2c_event,
-    .recv = lm_i2c_rx,
-    .send = lm_i2c_tx
+static void lm8323_class_init(ObjectClass *klass, void *data)
+{
+    I2CSlaveClass *k = I2C_SLAVE_CLASS(klass);
+
+    k->init = lm8323_init;
+    k->event = lm_i2c_event;
+    k->recv = lm_i2c_rx;
+    k->send = lm_i2c_tx;
+}
+
+static DeviceInfo lm8323_info = {
+    .name = "lm8323",
+    .size = sizeof(LM823KbdState),
+    .vmsd = &vmstate_lm_kbd,
+    .class_init = lm8323_class_init,
 };
 
 static void lm832x_register_devices(void)
hw/max7310.c +16 -9
index a955236..0cc3219 100644
@@ -185,15 +185,22 @@ static int max7310_init(I2CSlave *i2c)
     return 0;
 }
 
-static I2CSlaveInfo max7310_info = {
-    .qdev.name = "max7310",
-    .qdev.size = sizeof(MAX7310State),
-    .qdev.vmsd = &vmstate_max7310,
-    .qdev.reset = max7310_reset,
-    .init = max7310_init,
-    .event = max7310_event,
-    .recv = max7310_rx,
-    .send = max7310_tx
+static void max7310_class_init(ObjectClass *klass, void *data)
+{
+    I2CSlaveClass *k = I2C_SLAVE_CLASS(klass);
+
+    k->init = max7310_init;
+    k->event = max7310_event;
+    k->recv = max7310_rx;
+    k->send = max7310_tx;
+}
+
+static DeviceInfo max7310_info = {
+    .name = "max7310",
+    .size = sizeof(MAX7310State),
+    .vmsd = &vmstate_max7310,
+    .reset = max7310_reset,
+    .class_init = max7310_class_init,
 };
 
 static void max7310_register_devices(void)
hw/pxa2xx.c +14 -7
index 895fb3f..2ebb739 100644
@@ -1472,13 +1472,20 @@ static int pxa2xx_i2c_slave_init(I2CSlave *i2c)
     return 0;
 }
 
-static I2CSlaveInfo pxa2xx_i2c_slave_info = {
-    .qdev.name = "pxa2xx-i2c-slave",
-    .qdev.size = sizeof(PXA2xxI2CSlaveState),
-    .init = pxa2xx_i2c_slave_init,
-    .event = pxa2xx_i2c_event,
-    .recv = pxa2xx_i2c_rx,
-    .send = pxa2xx_i2c_tx
+static void pxapxa2xx_i2c_slave_class_init(ObjectClass *klass, void *data)
+{
+    I2CSlaveClass *k = I2C_SLAVE_CLASS(klass);
+
+    k->init = pxa2xx_i2c_slave_init;
+    k->event = pxa2xx_i2c_event;
+    k->recv = pxa2xx_i2c_rx;
+    k->send = pxa2xx_i2c_tx;
+}
+
+static DeviceInfo pxa2xx_i2c_slave_info = {
+    .name = "pxa2xx-i2c-slave",
+    .size = sizeof(PXA2xxI2CSlaveState),
+    .class_init = pxapxa2xx_i2c_slave_class_init,
 };
 
 PXA2xxI2CState *pxa2xx_i2c_init(target_phys_addr_t base,
hw/smbus.c +50 -27

139 lines not on this page · raw message

hw/smbus.h +28 -14

62 lines not on this page · raw message

hw/smbus_eeprom.c +17 -10
index 5d080ab..401dff5 100644
@@ -104,19 +104,26 @@ static int smbus_eeprom_initfn(SMBusDevice *dev)
     return 0;
 }
 
-static SMBusDeviceInfo smbus_eeprom_info = {
-    .i2c.qdev.name = "smbus-eeprom",
-    .i2c.qdev.size = sizeof(SMBusEEPROMDevice),
-    .i2c.qdev.props = (Property[]) {
+static void smbus_eeprom_class_initfn(ObjectClass *klass, void *data)
+{
+    SMBusDeviceClass *sc = SMBUS_DEVICE_CLASS(klass);
+
+    sc->init = smbus_eeprom_initfn;
+    sc->quick_cmd = eeprom_quick_cmd;
+    sc->send_byte = eeprom_send_byte;
+    sc->receive_byte = eeprom_receive_byte;
+    sc->write_data = eeprom_write_data;
+    sc->read_data = eeprom_read_data;
+}
+
+static DeviceInfo smbus_eeprom_info = {
+    .name = "smbus-eeprom",
+    .size = sizeof(SMBusEEPROMDevice),
+    .class_init = smbus_eeprom_class_initfn,
+    .props = (Property[]) {
         DEFINE_PROP_PTR("data", SMBusEEPROMDevice, data),
         DEFINE_PROP_END_OF_LIST(),
     },
-    .init = smbus_eeprom_initfn,
-    .quick_cmd = eeprom_quick_cmd,
-    .send_byte = eeprom_send_byte,
-    .receive_byte = eeprom_receive_byte,
-    .write_data = eeprom_write_data,
-    .read_data = eeprom_read_data
 };
 
 static void smbus_eeprom_register_devices(void)
hw/ssd0303.c +15 -8
index 6a9a8a7..acf027f 100644
@@ -294,14 +294,21 @@ static int ssd0303_init(I2CSlave *i2c)
     return 0;
 }
 
-static I2CSlaveInfo ssd0303_info = {
-    .qdev.name = "ssd0303",
-    .qdev.size = sizeof(ssd0303_state),
-    .qdev.vmsd = &vmstate_ssd0303,
-    .init = ssd0303_init,
-    .event = ssd0303_event,
-    .recv = ssd0303_recv,
-    .send = ssd0303_send
+static void ssd0303_class_init(ObjectClass *klass, void *data)
+{
+    I2CSlaveClass *k = I2C_SLAVE_CLASS(klass);
+
+    k->init = ssd0303_init;
+    k->event = ssd0303_event;
+    k->recv = ssd0303_recv;
+    k->send = ssd0303_send;
+}
+
+static DeviceInfo ssd0303_info = {
+    .name = "ssd0303",
+    .size = sizeof(ssd0303_state),
+    .vmsd = &vmstate_ssd0303,
+    .class_init = ssd0303_class_init,
 };
 
 static void ssd0303_register_devices(void)
hw/tmp105.c +15 -8
index ed8a0f3..12fe60d 100644
@@ -226,14 +226,21 @@ static int tmp105_init(I2CSlave *i2c)
     return 0;
 }
 
-static I2CSlaveInfo tmp105_info = {
-    .qdev.name = "tmp105",
-    .qdev.size = sizeof(TMP105State),
-    .qdev.vmsd = &vmstate_tmp105,
-    .init = tmp105_init,
-    .event = tmp105_event,
-    .recv = tmp105_rx,
-    .send = tmp105_tx
+static void tmp105_class_init(ObjectClass *klass, void *data)
+{
+    I2CSlaveClass *k = I2C_SLAVE_CLASS(klass);
+
+    k->init = tmp105_init;
+    k->event = tmp105_event;
+    k->recv = tmp105_rx;
+    k->send = tmp105_tx;
+}
+
+static DeviceInfo tmp105_info = {
+    .name = "tmp105",
+    .size = sizeof(TMP105State),
+    .vmsd = &vmstate_tmp105,
+    .class_init = tmp105_class_init,
 };
 
 static void tmp105_register_devices(void)
hw/tosa.c +14 -7
index 5f4968d..9f112b1 100644
@@ -259,13 +259,20 @@ static void tosapda_machine_init(void)
 
 machine_init(tosapda_machine_init);
 
-static I2CSlaveInfo tosa_dac_info = {
-    .qdev.name = "tosa_dac",
-    .qdev.size = sizeof(TosaDACState),
-    .init = tosa_dac_init,
-    .event = tosa_dac_event,
-    .recv = tosa_dac_recv,
-    .send = tosa_dac_send
+static void tosa_dac_class_init(ObjectClass *klass, void *data)
+{
+    I2CSlaveClass *k = I2C_SLAVE_CLASS(klass);
+
+    k->init = tosa_dac_init;
+    k->event = tosa_dac_event;
+    k->recv = tosa_dac_recv;
+    k->send = tosa_dac_send;
+}
+
+static DeviceInfo tosa_dac_info = {
+    .name = "tosa_dac",
+    .size = sizeof(TosaDACState),
+    .class_init = tosa_dac_class_init,
  };
 
 static void tosa_ssp_class_init(ObjectClass *klass, void *data)
hw/twl92230.c +15 -8
index ced705c..ba4f8aa 100644
@@ -857,14 +857,21 @@ static int twl92230_init(I2CSlave *i2c)
     return 0;
 }
 
-static I2CSlaveInfo twl92230_info = {
-    .qdev.name ="twl92230",
-    .qdev.size = sizeof(MenelausState),
-    .qdev.vmsd = &vmstate_menelaus,
-    .init = twl92230_init,
-    .event = menelaus_event,
-    .recv = menelaus_rx,
-    .send = menelaus_tx
+static void twl92230_class_init(ObjectClass *klass, void *data)
+{
+    I2CSlaveClass *sc = I2C_SLAVE_CLASS(klass);
+
+    sc->init = twl92230_init;
+    sc->event = menelaus_event;
+    sc->recv = menelaus_rx;
+    sc->send = menelaus_tx;
+}
+
+static DeviceInfo twl92230_info = {
+    .name ="twl92230",
+    .size = sizeof(MenelausState),
+    .vmsd = &vmstate_menelaus,
+    .class_init = twl92230_class_init,
 };
 
 static void twl92230_register_devices(void)
hw/wm8750.c +15 -8
index 5526bc4..33bce0d 100644
@@ -689,14 +689,21 @@ void wm8750_set_bclk_in(void *opaque, int new_hz)
     wm8750_clk_update(s, 1);
 }
 
-static I2CSlaveInfo wm8750_info = {
-    .qdev.name = "wm8750",
-    .qdev.size = sizeof(WM8750State),
-    .qdev.vmsd = &vmstate_wm8750,
-    .init = wm8750_init,
-    .event = wm8750_event,
-    .recv = wm8750_rx,
-    .send = wm8750_tx
+static void wm8750_class_init(ObjectClass *klass, void *data)
+{
+    I2CSlaveClass *sc = I2C_SLAVE_CLASS(klass);
+
+    sc->init = wm8750_init;
+    sc->event = wm8750_event;
+    sc->recv = wm8750_rx;
+    sc->send = wm8750_tx;
+}
+
+static DeviceInfo wm8750_info = {
+    .name = "wm8750",
+    .size = sizeof(WM8750State),
+    .vmsd = &vmstate_wm8750,
+    .class_init = wm8750_class_init,
 };
 
 static void wm8750_register_devices(void)
hw/z2.c +15 -8
index 2984a60..b12f974 100644
@@ -273,14 +273,21 @@ static VMStateDescription vmstate_aer915_state = {
     }
 };
 
-static I2CSlaveInfo aer915_info = {
-    .qdev.name = "aer915",
-    .qdev.size = sizeof(AER915State),
-    .qdev.vmsd = &vmstate_aer915_state,
-    .init = aer915_init,
-    .event = aer915_event,
-    .recv = aer915_recv,
-    .send = aer915_send
+static void aer915_class_init(ObjectClass *klass, void *data)
+{
+    I2CSlaveClass *k = I2C_SLAVE_CLASS(klass);
+
+    k->init = aer915_init;
+    k->event = aer915_event;
+    k->recv = aer915_recv;
+    k->send = aer915_send;
+}
+
+static DeviceInfo aer915_info = {
+    .name = "aer915",
+    .size = sizeof(AER915State),
+    .vmsd = &vmstate_aer915_state,
+    .class_init = aer915_class_init,
 };
 
 static void z2_init(ram_addr_t ram_size,
Signature · 1 line
1.7.4.1
#32 lore raw

PATCH v3 18/28 hda-codec: convert to QEMU Object Model

In reply to Anthony Liguori
---
 hw/hda-audio.c |   58 ++++++++++++++++++++++++++++++++++---------------------
 hw/intel-hda.c |   31 +++++++++++++++++------------
 hw/intel-hda.h |   26 ++++++++++++++++--------
 3 files changed, 71 insertions(+), 44 deletions(-)
hw/hda-audio.c +36 -22
index 8053c74..2b3ce2f 100644
@@ -906,33 +906,47 @@ static int hda_audio_init_duplex(HDACodecDevice *hda)
     return hda_audio_init(hda, &duplex);
 }
 
-static HDACodecDeviceInfo hda_audio_info_output = {
-    .qdev.name    = "hda-output",
-    .qdev.desc    = "HDA Audio Codec, output-only",
-    .qdev.size    = sizeof(HDAAudioState),
-    .qdev.vmsd    = &vmstate_hda_audio,
-    .qdev.props   = hda_audio_properties,
-    .init         = hda_audio_init_output,
-    .exit         = hda_audio_exit,
-    .command      = hda_audio_command,
-    .stream       = hda_audio_stream,
+static void hda_audio_output_class_init(ObjectClass *klass, void *data)
+{
+    HDACodecDeviceClass *k = HDA_CODEC_DEVICE_CLASS(klass);
+
+    k->init = hda_audio_init_output;
+    k->exit = hda_audio_exit;
+    k->command = hda_audio_command;
+    k->stream = hda_audio_stream;
+}
+
+static DeviceInfo hda_audio_output_info = {
+    .name = "hda-output",
+    .desc = "HDA Audio Codec, output-only",
+    .size = sizeof(HDAAudioState),
+    .vmsd = &vmstate_hda_audio,
+    .props = hda_audio_properties,
+    .class_init = hda_audio_output_class_init,
 };
 
-static HDACodecDeviceInfo hda_audio_info_duplex = {
-    .qdev.name    = "hda-duplex",
-    .qdev.desc    = "HDA Audio Codec, duplex",
-    .qdev.size    = sizeof(HDAAudioState),
-    .qdev.vmsd    = &vmstate_hda_audio,
-    .qdev.props   = hda_audio_properties,
-    .init         = hda_audio_init_duplex,
-    .exit         = hda_audio_exit,
-    .command      = hda_audio_command,
-    .stream       = hda_audio_stream,
+static void hda_audio_duplex_class_init(ObjectClass *klass, void *data)
+{
+    HDACodecDeviceClass *k = HDA_CODEC_DEVICE_CLASS(klass);
+
+    k->init = hda_audio_init_duplex;
+    k->exit = hda_audio_exit;
+    k->command = hda_audio_command;
+    k->stream = hda_audio_stream;
+}
+
+static DeviceInfo hda_audio_duplex_info = {
+    .name = "hda-duplex",
+    .desc = "HDA Audio Codec, duplex",
+    .size = sizeof(HDAAudioState),
+    .vmsd = &vmstate_hda_audio,
+    .props = hda_audio_properties,
+    .class_init = hda_audio_duplex_class_init,
 };
 
 static void hda_audio_register(void)
 {
-    hda_codec_register(&hda_audio_info_output);
-    hda_codec_register(&hda_audio_info_duplex);
+    hda_codec_register(&hda_audio_output_info);
+    hda_codec_register(&hda_audio_duplex_info);
 }
 device_init(hda_audio_register);
hw/intel-hda.c +18 -13
index 6e1c5de..f727c22 100644
@@ -51,9 +51,8 @@ static int hda_codec_dev_init(DeviceState *qdev, DeviceInfo *base)
 {
     HDACodecBus *bus = DO_UPCAST(HDACodecBus, qbus, qdev->parent_bus);
     HDACodecDevice *dev = DO_UPCAST(HDACodecDevice, qdev, qdev);
-    HDACodecDeviceInfo *info = DO_UPCAST(HDACodecDeviceInfo, qdev, base);
+    HDACodecDeviceClass *cdc = HDA_CODEC_DEVICE_GET_CLASS(dev);
 
-    dev->info = info;
     if (dev->cad == -1) {
         dev->cad = bus->next_cad;
     }
@@ -61,25 +60,26 @@ static int hda_codec_dev_init(DeviceState *qdev, DeviceInfo *base)
         return -1;
     }
     bus->next_cad = dev->cad + 1;
-    return info->init(dev);
+    return cdc->init(dev);
 }
 
 static int hda_codec_dev_exit(DeviceState *qdev)
 {
     HDACodecDevice *dev = DO_UPCAST(HDACodecDevice, qdev, qdev);
+    HDACodecDeviceClass *cdc = HDA_CODEC_DEVICE_GET_CLASS(dev);
 
-    if (dev->info->exit) {
-        dev->info->exit(dev);
+    if (cdc->exit) {
+        cdc->exit(dev);
     }
     return 0;
 }
 
-void hda_codec_register(HDACodecDeviceInfo *info)
+void hda_codec_register(DeviceInfo *info)
 {
-    info->qdev.init = hda_codec_dev_init;
-    info->qdev.exit = hda_codec_dev_exit;
-    info->qdev.bus_info = &hda_codec_bus_info;
-    qdev_register(&info->qdev);
+    info->init = hda_codec_dev_init;
+    info->exit = hda_codec_dev_exit;
+    info->bus_info = &hda_codec_bus_info;
+    qdev_register(info);
 }
 
 HDACodecDevice *hda_codec_find(HDACodecBus *bus, uint32_t cad)
@@ -283,6 +283,7 @@ static int intel_hda_send_command(IntelHDAState *d, uint32_t verb)
 {
     uint32_t cad, nid, data;
     HDACodecDevice *codec;
+    HDACodecDeviceClass *cdc;
 
     cad = (verb >> 28) & 0x0f;
     if (verb & (1 << 27)) {
@@ -298,7 +299,8 @@ static int intel_hda_send_command(IntelHDAState *d, uint32_t verb)
         dprint(d, 1, "%s: addressed non-existing codec\n", __FUNCTION__);
         return -1;
     }
-    codec->info->command(codec, nid, data);
+    cdc = HDA_CODEC_DEVICE_GET_CLASS(codec);
+    cdc->command(codec, nid, data);
     return 0;
 }
 
@@ -491,9 +493,12 @@ static void intel_hda_notify_codecs(IntelHDAState *d, uint32_t stream, bool runn
     HDACodecDevice *cdev;
 
     QTAILQ_FOREACH(qdev, &d->codecs.qbus.children, sibling) {
+        HDACodecDeviceClass *cdc;
+
         cdev = DO_UPCAST(HDACodecDevice, qdev, qdev);
-        if (cdev->info->stream) {
-            cdev->info->stream(cdev, stream, running, output);
+        cdc = HDA_CODEC_DEVICE_GET_CLASS(cdev);
+        if (cdc->stream) {
+            cdc->stream(cdev, stream, running, output);
         }
     }
 }
hw/intel-hda.h +17 -9
index 65fd2a8..f523587 100644
@@ -6,9 +6,16 @@
 /* --------------------------------------------------------------------- */
 /* hda bus                                                               */
 
+#define TYPE_HDA_CODEC_DEVICE "hda-codec"
+#define HDA_CODEC_DEVICE(obj) \
+     OBJECT_CHECK(HDACodecDevice, (obj), TYPE_HDA_CODEC_DEVICE)
+#define HDA_CODEC_DEVICE_CLASS(klass) \
+     OBJECT_CLASS_CHECK(HDACodecDeviceClass, (klass), TYPE_HDA_CODEC_DEVICE)
+#define HDA_CODEC_DEVICE_GET_CLASS(obj) \
+     OBJECT_GET_CLASS(HDACodecDeviceClass, (obj), TYPE_HDA_CODEC_DEVICE)
+
 typedef struct HDACodecBus HDACodecBus;
 typedef struct HDACodecDevice HDACodecDevice;
-typedef struct HDACodecDeviceInfo HDACodecDeviceInfo;
 
 typedef void (*hda_codec_response_func)(HDACodecDevice *dev,
                                         bool solicited, uint32_t response);
@@ -23,24 +30,25 @@ struct HDACodecBus {
     hda_codec_xfer_func xfer;
 };
 
-struct HDACodecDevice {
-    DeviceState         qdev;
-    HDACodecDeviceInfo  *info;
-    uint32_t            cad;    /* codec address */
-};
+typedef struct HDACodecDeviceClass
+{
+    DeviceClass parent_class;
 
-struct HDACodecDeviceInfo {
-    DeviceInfo qdev;
     int (*init)(HDACodecDevice *dev);
     int (*exit)(HDACodecDevice *dev);
     void (*command)(HDACodecDevice *dev, uint32_t nid, uint32_t data);
     void (*stream)(HDACodecDevice *dev, uint32_t stnr, bool running, bool output);
+} HDACodecDeviceClass;
+
+struct HDACodecDevice {
+    DeviceState         qdev;
+    uint32_t            cad;    /* codec address */
 };
 
 void hda_codec_bus_init(DeviceState *dev, HDACodecBus *bus,
                         hda_codec_response_func response,
                         hda_codec_xfer_func xfer);
-void hda_codec_register(HDACodecDeviceInfo *info);
+void hda_codec_register(DeviceInfo *info);
 HDACodecDevice *hda_codec_find(HDACodecBus *bus, uint32_t cad);
 
 void hda_codec_response(HDACodecDevice *dev, bool solicited, uint32_t response);
Signature · 1 line
1.7.4.1
#33 lore raw

PATCH v3 19/28 ide: convert to QEMU Object Model

In reply to Anthony Liguori
---
 hw/ide/internal.h |   20 ++++++---
 hw/ide/qdev.c     |  111 +++++++++++++++++++++++++++++++++--------------------
 2 files changed, 82 insertions(+), 49 deletions(-)
hw/ide/internal.h +13 -7
index 00b28df..c808a0d 100644
@@ -21,7 +21,6 @@
 
 typedef struct IDEBus IDEBus;
 typedef struct IDEDevice IDEDevice;
-typedef struct IDEDeviceInfo IDEDeviceInfo;
 typedef struct IDEState IDEState;
 typedef struct IDEDMA IDEDMA;
 typedef struct IDEDMAOps IDEDMAOps;
@@ -450,6 +449,19 @@ struct IDEBus {
     int error_status;
 };
 
+#define TYPE_IDE_DEVICE "ide-device"
+#define IDE_DEVICE(obj) \
+     OBJECT_CHECK(IDEDevice, (obj), TYPE_IDE_DEVICE)
+#define IDE_DEVICE_CLASS(klass) \
+     OBJECT_CLASS_CHECK(IDEDeviceClass, (klass), TYPE_IDE_DEVICE)
+#define IDE_DEVICE_GET_CLASS(obj) \
+     OBJECT_GET_CLASS(IDEDeviceClass, (obj), TYPE_IDE_DEVICE)
+
+typedef struct IDEDeviceClass {
+    DeviceClass parent_class;
+    int (*init)(IDEDevice *dev);
+} IDEDeviceClass;
+
 struct IDEDevice {
     DeviceState qdev;
     uint32_t unit;
@@ -458,12 +470,6 @@ struct IDEDevice {
     char *serial;
 };
 
-typedef int (*ide_qdev_initfn)(IDEDevice *dev);
-struct IDEDeviceInfo {
-    DeviceInfo qdev;
-    ide_qdev_initfn init;
-};
-
 #define BM_STATUS_DMAING 0x01
 #define BM_STATUS_ERROR  0x02
 #define BM_STATUS_INT    0x04
hw/ide/qdev.c +69 -42

140 lines not on this page · raw message

Signature · 1 line
1.7.4.1
#34 lore raw

PATCH v3 20/28 scsi: convert to QEMU Object Model

In reply to Anthony Liguori
---
 hw/scsi-bus.c     |   95 +++++++++++++++++++++++---------
 hw/scsi-disk.c    |  159 ++++++++++++++++++++++++++++++++---------------------
 hw/scsi-generic.c |   29 ++++++----
 hw/scsi.h         |   31 ++++++----
 4 files changed, 201 insertions(+), 113 deletions(-)
hw/scsi-bus.c +69 -26
index 64e709e..d017ece 100644
@@ -23,6 +23,42 @@ static struct BusInfo scsi_bus_info = {
 };
 static int next_scsi_bus;
 
+static int scsi_device_init(SCSIDevice *s)
+{
+    SCSIDeviceClass *sc = SCSI_DEVICE_GET_CLASS(s);
+    if (sc->init) {
+        return sc->init(s);
+    }
+    return 0;
+}
+
+static void scsi_device_destroy(SCSIDevice *s)
+{
+    SCSIDeviceClass *sc = SCSI_DEVICE_GET_CLASS(s);
+    if (sc->destroy) {
+        sc->destroy(s);
+    }
+}
+
+static SCSIRequest *scsi_device_alloc_req(SCSIDevice *s, uint32_t tag, uint32_t lun,
+                                          uint8_t *buf, void *hba_private)
+{
+    SCSIDeviceClass *sc = SCSI_DEVICE_GET_CLASS(s);
+    if (sc->alloc_req) {
+        return sc->alloc_req(s, tag, lun, buf, hba_private);
+    }
+
+    return NULL;
+}
+
+static void scsi_device_unit_attention_reported(SCSIDevice *s)
+{
+    SCSIDeviceClass *sc = SCSI_DEVICE_GET_CLASS(s);
+    if (sc->unit_attention_reported) {
+        sc->unit_attention_reported(s);
+    }
+}
+
 /* Create a scsi bus, and attach devices to it.  */
 void scsi_bus_new(SCSIBus *bus, DeviceState *host, const SCSIBusInfo *info)
 {
@@ -81,8 +117,7 @@ static void scsi_dma_restart_cb(void *opaque, int running, RunState state)
 
 static int scsi_qdev_init(DeviceState *qdev, DeviceInfo *base)
 {
-    SCSIDevice *dev = DO_UPCAST(SCSIDevice, qdev, qdev);
-    SCSIDeviceInfo *info = DO_UPCAST(SCSIDeviceInfo, qdev, base);
+    SCSIDevice *dev = SCSI_DEVICE(qdev);
     SCSIBus *bus = DO_UPCAST(SCSIBus, qbus, dev->qdev.parent_bus);
     SCSIDevice *d;
     int rc = -1;
@@ -126,9 +161,8 @@ static int scsi_qdev_init(DeviceState *qdev, DeviceInfo *base)
         }
     }
 
-    dev->info = info;
     QTAILQ_INIT(&dev->requests);
-    rc = dev->info->init(dev);
+    rc = scsi_device_init(dev);
     if (rc == 0) {
         dev->vmsentry = qemu_add_vm_change_state_handler(scsi_dma_restart_cb,
                                                          dev);
@@ -140,24 +174,22 @@ err:
 
 static int scsi_qdev_exit(DeviceState *qdev)
 {
-    SCSIDevice *dev = DO_UPCAST(SCSIDevice, qdev, qdev);
+    SCSIDevice *dev = SCSI_DEVICE(qdev);
 
     if (dev->vmsentry) {
         qemu_del_vm_change_state_handler(dev->vmsentry);
     }
-    if (dev->info->destroy) {
-        dev->info->destroy(dev);
-    }
+    scsi_device_destroy(dev);
     return 0;
 }
 
-void scsi_qdev_register(SCSIDeviceInfo *info)
+void scsi_qdev_register(DeviceInfo *info)
 {
-    info->qdev.bus_info = &scsi_bus_info;
-    info->qdev.init     = scsi_qdev_init;
-    info->qdev.unplug   = qdev_simple_unplug_cb;
-    info->qdev.exit     = scsi_qdev_exit;
-    qdev_register(&info->qdev);
+    info->bus_info = &scsi_bus_info;
+    info->init     = scsi_qdev_init;
+    info->unplug   = qdev_simple_unplug_cb;
+    info->exit     = scsi_qdev_exit;
+    qdev_register_subclass(info, TYPE_SCSI_DEVICE);
 }
 
 /* handle legacy '-drive if=scsi,...' cmd line args */
@@ -182,7 +214,7 @@ SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv,
     }
     if (qdev_init(dev) < 0)
         return NULL;
-    return DO_UPCAST(SCSIDevice, qdev, dev);
+    return SCSI_DEVICE(dev);
 }
 
 int scsi_bus_legacy_handle_cmdline(SCSIBus *bus)
@@ -278,7 +310,7 @@ static bool scsi_target_emulate_report_luns(SCSITargetReq *r)
     found_lun0 = false;
     n = 0;
     QTAILQ_FOREACH(qdev, &r->req.bus->qbus.children, sibling) {
-        SCSIDevice *dev = DO_UPCAST(SCSIDevice, qdev, qdev);
+        SCSIDevice *dev = SCSI_DEVICE(qdev);
 
         if (dev->channel == channel && dev->id == id) {
             if (dev->lun == 0) {
@@ -300,7 +332,7 @@ static bool scsi_target_emulate_report_luns(SCSITargetReq *r)
     stl_be_p(&r->buf, n);
     i = found_lun0 ? 8 : 16;
     QTAILQ_FOREACH(qdev, &r->req.bus->qbus.children, sibling) {
-        SCSIDevice *dev = DO_UPCAST(SCSIDevice, qdev, qdev);
+        SCSIDevice *dev = SCSI_DEVICE(qdev);
 
         if (dev->channel == channel && dev->id == id) {
             store_lun(&r->buf[i], dev->lun);
@@ -398,9 +430,7 @@ static int32_t scsi_target_send_command(SCSIRequest *req, uint8_t *buf)
                                        MIN(req->cmd.xfer, sizeof r->buf),
                                        (req->cmd.buf[1] & 1) == 0);
         if (r->req.dev->sense_is_ua) {
-            if (r->req.dev->info->unit_attention_reported) {
-                r->req.dev->info->unit_attention_reported(req->dev);
-            }
+            scsi_device_unit_attention_reported(req->dev);
             r->req.dev->sense_len = 0;
             r->req.dev->sense_is_ua = false;
         }
@@ -507,7 +537,7 @@ SCSIRequest *scsi_req_new(SCSIDevice *d, uint32_t tag, uint32_t lun,
             req = scsi_req_alloc(&reqops_target_command, d, tag, lun,
                                  hba_private);
         } else {
-            req = d->info->alloc_req(d, tag, lun, buf, hba_private);
+            req = scsi_device_alloc_req(d, tag, lun, buf, hba_private);
         }
     }
 
@@ -597,9 +627,7 @@ int scsi_req_get_sense(SCSIRequest *req, uint8_t *buf, int len)
      * Here we handle unit attention clearing for UA_INTLCK_CTRL == 00b.
      */
     if (req->dev->sense_is_ua) {
-        if (req->dev->info->unit_attention_reported) {
-            req->dev->info->unit_attention_reported(req->dev);
-        }
+        scsi_device_unit_attention_reported(req->dev);
         req->dev->sense_len = 0;
         req->dev->sense_is_ua = false;
     }
@@ -1367,7 +1395,7 @@ void scsi_device_purge_requests(SCSIDevice *sdev, SCSISense sense)
 
 static char *scsibus_get_fw_dev_path(DeviceState *dev)
 {
-    SCSIDevice *d = DO_UPCAST(SCSIDevice, qdev, dev);
+    SCSIDevice *d = SCSI_DEVICE(dev);
     char path[100];
 
     snprintf(path, sizeof(path), "channel@%x/%s@%x,%x", d->channel,
@@ -1382,7 +1410,7 @@ SCSIDevice *scsi_device_find(SCSIBus *bus, int channel, int id, int lun)
     SCSIDevice *target_dev = NULL;
 
     QTAILQ_FOREACH_REVERSE(qdev, &bus->qbus.children, ChildrenHead, sibling) {
-        SCSIDevice *dev = DO_UPCAST(SCSIDevice, qdev, qdev);
+        SCSIDevice *dev = SCSI_DEVICE(qdev);
 
         if (dev->channel == channel && dev->id == id) {
             if (dev->lun == lun) {
@@ -1393,3 +1421,18 @@ SCSIDevice *scsi_device_find(SCSIBus *bus, int channel, int id, int lun)
     }
     return target_dev;
 }
+
+static TypeInfo scsi_device_type_info = {
+    .name = TYPE_SCSI_DEVICE,
+    .parent = TYPE_DEVICE,
+    .instance_size = sizeof(SCSIDevice),
+    .abstract = true,
+    .class_size = sizeof(SCSIDeviceClass),
+};
+
+static void scsi_register_devices(void)
+{
+    type_register_static(&scsi_device_type_info);
+}
+
+device_init(scsi_register_devices);
hw/scsi-disk.c +96 -63

171 lines not on this page · raw message

hw/scsi-generic.c +18 -11
index 0aebcdd..5cf4005 100644
@@ -357,7 +357,7 @@ static int get_stream_blocksize(BlockDriverState *bdrv)
 
 static void scsi_generic_reset(DeviceState *dev)
 {
-    SCSIDevice *s = DO_UPCAST(SCSIDevice, qdev, dev);
+    SCSIDevice *s = SCSI_DEVICE(dev);
 
     scsi_device_purge_requests(s, SENSE_CODE(RESET));
 }
@@ -457,16 +457,23 @@ static SCSIRequest *scsi_new_request(SCSIDevice *d, uint32_t tag, uint32_t lun,
     return req;
 }
 
-static SCSIDeviceInfo scsi_generic_info = {
-    .qdev.name    = "scsi-generic",
-    .qdev.fw_name = "disk",
-    .qdev.desc    = "pass through generic scsi device (/dev/sg*)",
-    .qdev.size    = sizeof(SCSIDevice),
-    .qdev.reset   = scsi_generic_reset,
-    .init         = scsi_generic_initfn,
-    .destroy      = scsi_destroy,
-    .alloc_req    = scsi_new_request,
-    .qdev.props   = (Property[]) {
+static void scsi_generic_class_initfn(ObjectClass *klass, void *data)
+{
+    SCSIDeviceClass *sc = SCSI_DEVICE_CLASS(klass);
+
+    sc->init         = scsi_generic_initfn;
+    sc->destroy      = scsi_destroy;
+    sc->alloc_req    = scsi_new_request;
+}
+
+static DeviceInfo scsi_generic_info = {
+    .name    = "scsi-generic",
+    .fw_name = "disk",
+    .desc    = "pass through generic scsi device (/dev/sg*)",
+    .size    = sizeof(SCSIDevice),
+    .reset   = scsi_generic_reset,
+    .class_init = scsi_generic_class_initfn,
+    .props   = (Property[]) {
         DEFINE_BLOCK_PROPERTIES(SCSIDevice, conf),
         DEFINE_PROP_END_OF_LIST(),
     },
hw/scsi.h +18 -13
index ab6e952..4290b20 100644
@@ -13,7 +13,6 @@ typedef struct SCSIBus SCSIBus;
 typedef struct SCSIBusInfo SCSIBusInfo;
 typedef struct SCSICommand SCSICommand;
 typedef struct SCSIDevice SCSIDevice;
-typedef struct SCSIDeviceInfo SCSIDeviceInfo;
 typedef struct SCSIRequest SCSIRequest;
 typedef struct SCSIReqOps SCSIReqOps;
 
@@ -58,6 +57,23 @@ struct SCSIRequest {
     QTAILQ_ENTRY(SCSIRequest) next;
 };
 
+#define TYPE_SCSI_DEVICE "scsi-device"
+#define SCSI_DEVICE(obj) \
+     OBJECT_CHECK(SCSIDevice, (obj), TYPE_SCSI_DEVICE)
+#define SCSI_DEVICE_CLASS(klass) \
+     OBJECT_CLASS_CHECK(SCSIDeviceClass, (klass), TYPE_SCSI_DEVICE)
+#define SCSI_DEVICE_GET_CLASS(obj) \
+     OBJECT_GET_CLASS(SCSIDeviceClass, (obj), TYPE_SCSI_DEVICE)
+
+typedef struct SCSIDeviceClass {
+    DeviceClass parent_class;
+    int (*init)(SCSIDevice *dev);
+    void (*destroy)(SCSIDevice *s);
+    SCSIRequest *(*alloc_req)(SCSIDevice *s, uint32_t tag, uint32_t lun,
+                              uint8_t *buf, void *hba_private);
+    void (*unit_attention_reported)(SCSIDevice *s);
+} SCSIDeviceClass;
+
 struct SCSIDevice
 {
     DeviceState qdev;
@@ -65,7 +81,6 @@ struct SCSIDevice
     QEMUBH *bh;
     uint32_t id;
     BlockConf conf;
-    SCSIDeviceInfo *info;
     SCSISense unit_attention;
     bool sense_is_ua;
     uint8_t sense[SCSI_SENSE_BUF_SIZE];
@@ -93,16 +108,6 @@ struct SCSIReqOps {
     uint8_t *(*get_buf)(SCSIRequest *req);
 };
 
-typedef int (*scsi_qdev_initfn)(SCSIDevice *dev);
-struct SCSIDeviceInfo {
-    DeviceInfo qdev;
-    scsi_qdev_initfn init;
-    void (*destroy)(SCSIDevice *s);
-    SCSIRequest *(*alloc_req)(SCSIDevice *s, uint32_t tag, uint32_t lun,
-                              uint8_t *buf, void *hba_private);
-    void (*unit_attention_reported)(SCSIDevice *s);
-};
-
 struct SCSIBusInfo {
     int tcq;
     int max_channel, max_target, max_lun;
@@ -120,7 +125,7 @@ struct SCSIBus {
 };
 
 void scsi_bus_new(SCSIBus *bus, DeviceState *host, const SCSIBusInfo *info);
-void scsi_qdev_register(SCSIDeviceInfo *info);
+void scsi_qdev_register(DeviceInfo *info);
 
 static inline SCSIBus *scsi_bus_from_device(SCSIDevice *d)
 {
Signature · 1 line
1.7.4.1
#35 lore raw

PATCH v3 21/28 spapr: convert to QEMU Object Model (v2)

In reply to Anthony Liguori

---
v1 -> v2
- use QOM to check for the default console

---
 hw/spapr_llan.c  |   37 ++++++++++++++++++++++-------------
 hw/spapr_vio.c   |   55 ++++++++++++++++++++++++++++++++---------------------
 hw/spapr_vio.h   |   35 +++++++++++++++++++++++++--------
 hw/spapr_vscsi.c |   35 +++++++++++++++++++++------------
 hw/spapr_vty.c   |   35 +++++++++++++++++++++------------
 5 files changed, 126 insertions(+), 71 deletions(-)
hw/spapr_llan.c +23 -14
index b9a5afc..0fb176a 100644
@@ -474,20 +474,29 @@ static target_ulong h_multicast_ctrl(CPUState *env, sPAPREnvironment *spapr,
     return H_SUCCESS;
 }
 
-static VIOsPAPRDeviceInfo spapr_vlan_info = {
-    .init = spapr_vlan_init,
-    .devnode = spapr_vlan_devnode,
-    .dt_name = "l-lan",
-    .dt_type = "network",
-    .dt_compatible = "IBM,l-lan",
-    .signal_mask = 0x1,
-    .qdev.name = "spapr-vlan",
-    .qdev.size = sizeof(VIOsPAPRVLANDevice),
-    .qdev.props = (Property[]) {
-        DEFINE_SPAPR_PROPERTIES(VIOsPAPRVLANDevice, sdev, 0x1000, 0x10000000),
-        DEFINE_NIC_PROPERTIES(VIOsPAPRVLANDevice, nicconf),
-        DEFINE_PROP_END_OF_LIST(),
-    },
+static Property spapr_vlan_properties[] = {
+    DEFINE_SPAPR_PROPERTIES(VIOsPAPRVLANDevice, sdev, 0x1000, 0x10000000),
+    DEFINE_NIC_PROPERTIES(VIOsPAPRVLANDevice, nicconf),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void spapr_vlan_class_init(ObjectClass *klass, void *data)
+{
+    VIOsPAPRDeviceClass *k = VIO_SPAPR_DEVICE_CLASS(klass);
+
+    k->init = spapr_vlan_init;
+    k->devnode = spapr_vlan_devnode;
+    k->dt_name = "l-lan";
+    k->dt_type = "network";
+    k->dt_compatible = "IBM,l-lan";
+    k->signal_mask = 0x1;
+}
+
+static DeviceInfo spapr_vlan_info = {
+    .name = "spapr-vlan",
+    .size = sizeof(VIOsPAPRVLANDevice),
+    .props = spapr_vlan_properties,
+    .class_init = spapr_vlan_class_init,
 };
 
 static void spapr_vlan_register(void)
hw/spapr_vio.c +33 -22

142 lines not on this page · raw message

hw/spapr_vio.h +26 -9
index 0984d55..7d1155a 100644
@@ -34,6 +34,14 @@ enum VIOsPAPR_TCEAccess {
 
 #define SPAPR_VTY_BASE_ADDRESS     0x30000000
 
+#define TYPE_VIO_SPAPR_DEVICE "vio-spapr-device"
+#define VIO_SPAPR_DEVICE(obj) \
+     OBJECT_CHECK(VIOsPAPRDevice, (obj), TYPE_VIO_SPAPR_DEVICE)
+#define VIO_SPAPR_DEVICE_CLASS(klass) \
+     OBJECT_CLASS_CHECK(VIOsPAPRDeviceClass, (klass), TYPE_VIO_SPAPR_DEVICE)
+#define VIO_SPAPR_DEVICE_GET_CLASS(obj) \
+     OBJECT_GET_CLASS(VIOsPAPRDeviceClass, (obj), TYPE_VIO_SPAPR_DEVICE)
+
 struct VIOsPAPRDevice;
 
 typedef struct VIOsPAPR_RTCE {
@@ -47,7 +55,20 @@ typedef struct VIOsPAPR_CRQ {
     int(*SendFunc)(struct VIOsPAPRDevice *vdev, uint8_t *crq);
 } VIOsPAPR_CRQ;
 
-typedef struct VIOsPAPRDevice {
+typedef struct VIOsPAPRDevice VIOsPAPRDevice;
+typedef struct VIOsPAPRBus VIOsPAPRBus;
+
+typedef struct VIOsPAPRDeviceClass {
+    DeviceClass parent_class;
+
+    const char *dt_name, *dt_type, *dt_compatible;
+    target_ulong signal_mask;
+    int (*init)(VIOsPAPRDevice *dev);
+    void (*hcalls)(VIOsPAPRBus *bus);
+    int (*devnode)(VIOsPAPRDevice *dev, void *fdt, int node_off);
+} VIOsPAPRDeviceClass;
+
+struct VIOsPAPRDevice {
     DeviceState qdev;
     uint32_t reg;
     uint32_t flags;
@@ -59,28 +80,24 @@ typedef struct VIOsPAPRDevice {
     VIOsPAPR_RTCE *rtce_table;
     int kvmtce_fd;
     VIOsPAPR_CRQ crq;
-} VIOsPAPRDevice;
+};
 
 #define DEFINE_SPAPR_PROPERTIES(type, field, default_reg, default_dma_window) \
         DEFINE_PROP_UINT32("reg", type, field.reg, default_reg), \
         DEFINE_PROP_UINT32("dma-window", type, field.rtce_window_size, \
                            default_dma_window)
 
-typedef struct VIOsPAPRBus {
+struct VIOsPAPRBus {
     BusState bus;
-} VIOsPAPRBus;
-
-typedef struct {
-    DeviceInfo qdev;
     const char *dt_name, *dt_type, *dt_compatible;
     target_ulong signal_mask;
     int (*init)(VIOsPAPRDevice *dev);
     int (*devnode)(VIOsPAPRDevice *dev, void *fdt, int node_off);
-} VIOsPAPRDeviceInfo;
+};
 
 extern VIOsPAPRBus *spapr_vio_bus_init(void);
 extern VIOsPAPRDevice *spapr_vio_find_by_reg(VIOsPAPRBus *bus, uint32_t reg);
-extern void spapr_vio_bus_register_withprop(VIOsPAPRDeviceInfo *info);
+extern void spapr_vio_bus_register_withprop(DeviceInfo *info);
 extern int spapr_populate_vdevice(VIOsPAPRBus *bus, void *fdt);
 extern int spapr_populate_chosen_stdout(void *fdt, VIOsPAPRBus *bus);
 
hw/spapr_vscsi.c +22 -13
index 21d946e..b83bb7f 100644
@@ -947,19 +947,28 @@ static int spapr_vscsi_devnode(VIOsPAPRDevice *dev, void *fdt, int node_off)
     return 0;
 }
 
-static VIOsPAPRDeviceInfo spapr_vscsi_info = {
-    .init = spapr_vscsi_init,
-    .devnode = spapr_vscsi_devnode,
-    .dt_name = "v-scsi",
-    .dt_type = "vscsi",
-    .dt_compatible = "IBM,v-scsi",
-    .signal_mask = 0x00000001,
-    .qdev.name = "spapr-vscsi",
-    .qdev.size = sizeof(VSCSIState),
-    .qdev.props = (Property[]) {
-        DEFINE_SPAPR_PROPERTIES(VSCSIState, vdev, 0x2000, 0x10000000),
-        DEFINE_PROP_END_OF_LIST(),
-    },
+static Property spapr_vscsi_properties[] = {
+    DEFINE_SPAPR_PROPERTIES(VSCSIState, vdev, 0x2000, 0x10000000),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void spapr_vscsi_class_init(ObjectClass *klass, void *data)
+{
+    VIOsPAPRDeviceClass *k = VIO_SPAPR_DEVICE_CLASS(klass);
+
+    k->init = spapr_vscsi_init;
+    k->devnode = spapr_vscsi_devnode;
+    k->dt_name = "v-scsi";
+    k->dt_type = "vscsi";
+    k->dt_compatible = "IBM,v-scsi";
+    k->signal_mask = 0x00000001;
+}
+
+static DeviceInfo spapr_vscsi_info = {
+    .name = "spapr-vscsi",
+    .size = sizeof(VSCSIState),
+    .props = spapr_vscsi_properties,
+    .class_init = spapr_vscsi_class_init,
 };
 
 static void spapr_vscsi_register(void)
hw/spapr_vty.c +22 -13
index 3d5c579..1780ffe 100644
@@ -135,18 +135,27 @@ void spapr_vty_create(VIOsPAPRBus *bus, uint32_t reg, CharDriverState *chardev)
     qdev_init_nofail(dev);
 }
 
-static VIOsPAPRDeviceInfo spapr_vty_info = {
-    .init = spapr_vty_init,
-    .dt_name = "vty",
-    .dt_type = "serial",
-    .dt_compatible = "hvterm1",
-    .qdev.name = "spapr-vty",
-    .qdev.size = sizeof(VIOsPAPRVTYDevice),
-    .qdev.props = (Property[]) {
-        DEFINE_SPAPR_PROPERTIES(VIOsPAPRVTYDevice, sdev, SPAPR_VTY_BASE_ADDRESS, 0),
-        DEFINE_PROP_CHR("chardev", VIOsPAPRVTYDevice, chardev),
-        DEFINE_PROP_END_OF_LIST(),
-    },
+static Property spapr_vty_properties[] = {
+    DEFINE_SPAPR_PROPERTIES(VIOsPAPRVTYDevice, sdev, SPAPR_VTY_BASE_ADDRESS, 0),
+    DEFINE_PROP_CHR("chardev", VIOsPAPRVTYDevice, chardev),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void spapr_vty_class_init(ObjectClass *klass, void *data)
+{
+    VIOsPAPRDeviceClass *k = VIO_SPAPR_DEVICE_CLASS(klass);
+
+    k->init = spapr_vty_init;
+    k->dt_name = "vty";
+    k->dt_type = "serial";
+    k->dt_compatible = "hvterm1";
+}
+
+static DeviceInfo spapr_vty_info = {
+    .name = "spapr-vty",
+    .size = sizeof(VIOsPAPRVTYDevice),
+    .props = spapr_vty_properties,
+    .class_init = spapr_vty_class_init,
 };
 
 VIOsPAPRDevice *spapr_vty_get_default(VIOsPAPRBus *bus)
@@ -163,7 +172,7 @@ VIOsPAPRDevice *spapr_vty_get_default(VIOsPAPRBus *bus)
     selected = NULL;
     QTAILQ_FOREACH(iter, &bus->bus.children, sibling) {
         /* Only look at VTY devices */
-        if (qdev_get_info(iter) != &spapr_vty_info.qdev) {
+        if (!object_dynamic_cast(OBJECT(iter), "spapr-vty")) {
             continue;
         }
 
Signature · 1 line
1.7.4.1
#36 lore raw

PATCH v3 22/28 virtio-serial: convert to QEMU Object Model

In reply to Anthony Liguori
---
 hw/virtio-console.c    |   69 +++++++++++++++++++++++++---------------
 hw/virtio-serial-bus.c |   68 ++++++++++++++++++++++++----------------
 hw/virtio-serial.h     |   81 ++++++++++++++++++++++++++----------------------
 3 files changed, 128 insertions(+), 90 deletions(-)
hw/virtio-console.c +43 -26
index f25adc4..73c3935 100644
@@ -109,10 +109,9 @@ static void chr_event(void *opaque, int event)
 static int virtconsole_initfn(VirtIOSerialPort *port)
 {
     VirtConsole *vcon = DO_UPCAST(VirtConsole, port, port);
-    VirtIOSerialPortInfo *info = DO_UPCAST(VirtIOSerialPortInfo, qdev,
-                                           qdev_get_info(&vcon->port.dev));
+    VirtIOSerialPortClass *k = VIRTIO_SERIAL_PORT_GET_CLASS(port);
 
-    if (port->id == 0 && !info->is_console) {
+    if (port->id == 0 && !k->is_console) {
         error_report("Port number 0 on virtio-serial devices reserved for virtconsole devices for backward compatibility.");
         return -1;
     }
@@ -125,18 +124,27 @@ static int virtconsole_initfn(VirtIOSerialPort *port)
     return 0;
 }
 
-static VirtIOSerialPortInfo virtconsole_info = {
-    .qdev.name     = "virtconsole",
-    .qdev.size     = sizeof(VirtConsole),
-    .is_console    = true,
-    .init          = virtconsole_initfn,
-    .have_data     = flush_buf,
-    .guest_open    = guest_open,
-    .guest_close   = guest_close,
-    .qdev.props = (Property[]) {
-        DEFINE_PROP_CHR("chardev", VirtConsole, chr),
-        DEFINE_PROP_END_OF_LIST(),
-    },
+static Property virtconsole_properties[] = {
+    DEFINE_PROP_CHR("chardev", VirtConsole, chr),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void virtconsole_class_init(ObjectClass *klass, void *data)
+{
+    VirtIOSerialPortClass *k = VIRTIO_SERIAL_PORT_CLASS(klass);
+
+    k->is_console = true;
+    k->init = virtconsole_initfn;
+    k->have_data = flush_buf;
+    k->guest_open = guest_open;
+    k->guest_close = guest_close;
+}
+
+static DeviceInfo virtconsole_info = {
+    .name = "virtconsole",
+    .size = sizeof(VirtConsole),
+    .props = virtconsole_properties,
+    .class_init = virtconsole_class_init,
 };
 
 static void virtconsole_register(void)
@@ -145,17 +153,26 @@ static void virtconsole_register(void)
 }
 device_init(virtconsole_register)
 
-static VirtIOSerialPortInfo virtserialport_info = {
-    .qdev.name     = "virtserialport",
-    .qdev.size     = sizeof(VirtConsole),
-    .init          = virtconsole_initfn,
-    .have_data     = flush_buf,
-    .guest_open    = guest_open,
-    .guest_close   = guest_close,
-    .qdev.props = (Property[]) {
-        DEFINE_PROP_CHR("chardev", VirtConsole, chr),
-        DEFINE_PROP_END_OF_LIST(),
-    },
+static Property virtserialport_properties[] = {
+    DEFINE_PROP_CHR("chardev", VirtConsole, chr),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void virtserialport_class_init(ObjectClass *klass, void *data)
+{
+    VirtIOSerialPortClass *k = VIRTIO_SERIAL_PORT_CLASS(klass);
+
+    k->init = virtconsole_initfn;
+    k->have_data = flush_buf;
+    k->guest_open = guest_open;
+    k->guest_close = guest_close;
+}
+
+static DeviceInfo virtserialport_info = {
+    .name = "virtserialport",
+    .size = sizeof(VirtConsole),
+    .props = virtserialport_properties,
+    .class_init = virtserialport_class_init,
 };
 
 static void virtserialport_register(void)
hw/virtio-serial-bus.c +41 -27

167 lines not on this page · raw message

hw/virtio-serial.h +44 -37

102 lines not on this page · raw message

Signature · 1 line
1.7.4.1
#37 lore raw

Re: [Qemu-devel] [PATCH 22/28] virtio-serial: convert to QEMU Object Model

Quoted 7 lines · Anthony Liguori
hw/virtio-serial-bus.c +0 -0
index 982ffbf..edf54d7 100644

hw/virtio-serial-bus.c static void do_flush_queued_data(VirtIOSerialPort *port, VirtQueue *vq, · line 163

Quoted 8 lines
hw/virtio-serial-bus.c +1 -1
@@ -157,7 +157,7 @@ static void do_flush_queued_data(VirtIOSerialPort *port, VirtQueue *vq,
             ssize_t ret;
 
             buf_size = port->elem.out_sg[i].iov_len - port->iov_offset;
-            ret = info->have_data(port,
+            ret = vsc->have_data(port,
                                   port->elem.out_sg[i].iov_base
                                   + port->iov_offset,
                                   buf_size);

Would be nice if everything was re-indented.

hw/virtio-serial-bus.c static void do_flush_queued_data(VirtIOSerialPort *port, VirtQueue *vq, · line 182

Quoted 9 lines
hw/virtio-serial-bus.c +1 -1
@@ -176,7 +176,7 @@ static void do_flush_queued_data(VirtIOSerialPort *port, VirtQueue *vq,
                  * 1: chardevs can notify frondends
                  * 2: the guest driver does not spin in these cases
                  */
-                if (!info->is_console) {
+                if (vsc->is_console) {
                     virtio_serial_throttle_port(port, true);
                 }
                 port->iov_idx = i;

This change is wrong, reverses the if condition. Was this done manually or via a script? If the latter, it would be worthwhile to check all the conversions.

hw/virtio-serial-bus.c static int virtser_port_qdev_exit(DeviceState *qdev) · line 840

Quoted 2 lines
hw/virtio-serial-bus.c +1 -1
-void virtio_serial_port_qdev_register(VirtIOSerialPortInfo *info)
+void virtio_serial_port_qdev_register(DeviceInfo *info)

Should the fn be renamed (replace qdev)?

Amit

#38 lore raw

Re: [Qemu-devel] [PATCH 22/28] virtio-serial: convert to QEMU Object Model

Quoted 11 lines · Amit Shah
Quoted 9 lines · Anthony Liguori
hw/virtio-serial-bus.c +0 -0
index 982ffbf..edf54d7 100644
@@ -157,7 +157,7 @@ static void do_flush_queued_data(VirtIOSerialPort *port, VirtQueue *vq,
              ssize_t ret;
 
Quoted 8 lines

hw/virtio-serial-bus.c static void do_flush_queued_data(VirtIOSerialPort *port, VirtQueue *vq, · line 163

Quoted 6 lines
hw/virtio-serial-bus.c +1 -1
              buf_size = port->elem.out_sg[i].iov_len - port->iov_offset;
-            ret = info->have_data(port,
+            ret = vsc->have_data(port,
                                    port->elem.out_sg[i].iov_base
                                    + port->iov_offset,
                                    buf_size);

Would be nice if everything was re-indented.

That'll need to be a follow-on. This was mostly scripted.

Quoted 14 lines

hw/virtio-serial-bus.c static void do_flush_queued_data(VirtIOSerialPort *port, VirtQueue *vq, · line 182

Quoted 10 lines
hw/virtio-serial-bus.c +1 -1
@@ -176,7 +176,7 @@ static void do_flush_queued_data(VirtIOSerialPort *port, VirtQueue *vq,
                   * 1: chardevs can notify frondends
                   * 2: the guest driver does not spin in these cases
                   */
-                if (!info->is_console) {
+                if (vsc->is_console) {
                      virtio_serial_throttle_port(port, true);
                  }
                  port->iov_idx = i;

This change is wrong, reverses the if condition. Was this done manually or via a script? If the latter, it would be worthwhile to check all the conversions.

This was a manual rebase conflict resolution change on my part. I'll fix.

Quoted 5 lines

hw/virtio-serial-bus.c static int virtser_port_qdev_exit(DeviceState *qdev) · line 840

Quoted 3 lines
hw/virtio-serial-bus.c +1 -1
-void virtio_serial_port_qdev_register(VirtIOSerialPortInfo *info)
+void virtio_serial_port_qdev_register(DeviceInfo *info)

Should the fn be renamed (replace qdev)?

It'll go away entirely in 3/3 which I'll post in a couple days.

Regards,

Anthony Liguori

Quoted 3 lines

Amit

#39 lore raw

PATCH v3 23/28 unin_pci: Clean up qdev names

In reply to Anthony Liguori

From: Andreas Färber <[email protected]>

Add -pcihost to SysBus devices to resolve name conflicts, and clarify PCI vs. Internal PCI.

---
 hw/unin_pci.c |   54 +++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 39 insertions(+), 15 deletions(-)
hw/unin_pci.c +39 -15
index 14d9914..be0e98c 100644
@@ -213,7 +213,7 @@ PCIBus *pci_pmac_init(qemu_irq *pic,
 
     /* Use values found on a real PowerMac */
     /* Uninorth main bus */
-    dev = qdev_create(NULL, "uni-north");
+    dev = qdev_create(NULL, "uni-north-pci-pcihost");
     qdev_init_nofail(dev);
     s = sysbus_from_qdev(dev);
     d = FROM_SYSBUS(UNINState, s);
@@ -245,7 +245,7 @@ PCIBus *pci_pmac_init(qemu_irq *pic,
 
     /* Uninorth AGP bus */
     pci_create_simple(d->host_state.bus, PCI_DEVFN(11, 0), "uni-north-agp");
-    dev = qdev_create(NULL, "uni-north-agp");
+    dev = qdev_create(NULL, "uni-north-agp-pcihost");
     qdev_init_nofail(dev);
     s = sysbus_from_qdev(dev);
     sysbus_mmio_map(s, 0, 0xf0800000);
@@ -254,8 +254,9 @@ PCIBus *pci_pmac_init(qemu_irq *pic,
     /* Uninorth internal bus */
 #if 0
     /* XXX: not needed for now */
-    pci_create_simple(d->host_state.bus, PCI_DEVFN(14, 0), "uni-north-pci");
-    dev = qdev_create(NULL, "uni-north-pci");
+    pci_create_simple(d->host_state.bus, PCI_DEVFN(14, 0),
+                      "uni-north-internal-pci");
+    dev = qdev_create(NULL, "uni-north-internal-pci-pcihost");
     qdev_init_nofail(dev);
     s = sysbus_from_qdev(dev);
     sysbus_mmio_map(s, 0, 0xf4800000);
@@ -275,7 +276,7 @@ PCIBus *pci_pmac_u3_init(qemu_irq *pic,
 
     /* Uninorth AGP bus */
 
-    dev = qdev_create(NULL, "u3-agp");
+    dev = qdev_create(NULL, "u3-agp-pcihost");
     qdev_init_nofail(dev);
     s = sysbus_from_qdev(dev);
     d = FROM_SYSBUS(UNINState, s);
@@ -335,7 +336,7 @@ static int unin_internal_pci_host_init(PCIDevice *d)
 }
 
 static PCIDeviceInfo unin_main_pci_host_info = {
-    .qdev.name = "uni-north",
+    .qdev.name = "uni-north-pci",
     .qdev.size = sizeof(PCIDevice),
     .init      = unin_main_pci_host_init,
     .vendor_id = PCI_VENDOR_ID_APPLE,
@@ -365,7 +366,7 @@ static PCIDeviceInfo unin_agp_pci_host_info = {
 };
 
 static PCIDeviceInfo unin_internal_pci_host_info = {
-    .qdev.name = "uni-north-pci",
+    .qdev.name = "uni-north-internal-pci",
     .qdev.size = sizeof(PCIDevice),
     .init      = unin_internal_pci_host_init,
     .vendor_id = PCI_VENDOR_ID_APPLE,
@@ -374,19 +375,42 @@ static PCIDeviceInfo unin_internal_pci_host_info = {
     .class_id  = PCI_CLASS_BRIDGE_HOST,
 };
 
+static SysBusDeviceInfo sysbus_unin_pci_host_info = {
+    .qdev.name = "uni-north-pci-pcihost",
+    .qdev.size = sizeof(UNINState),
+    .init      = pci_unin_main_init_device,
+};
+
+static SysBusDeviceInfo sysbus_u3_agp_pci_host_info = {
+    .qdev.name = "u3-agp-pcihost",
+    .qdev.size = sizeof(UNINState),
+    .init      = pci_u3_agp_init_device,
+};
+
+static SysBusDeviceInfo sysbus_unin_agp_pci_host_info = {
+    .qdev.name = "uni-north-agp-pcihost",
+    .qdev.size = sizeof(UNINState),
+    .init      = pci_unin_agp_init_device,
+};
+
+static SysBusDeviceInfo sysbus_unin_internal_pci_host_info = {
+    .qdev.name = "uni-north-internal-pci-pcihost",
+    .qdev.size = sizeof(UNINState),
+    .init      = pci_unin_internal_init_device,
+};
+
 static void unin_register_devices(void)
 {
-    sysbus_register_dev("uni-north", sizeof(UNINState),
-                        pci_unin_main_init_device);
+    sysbus_register_withprop(&sysbus_unin_pci_host_info);
     pci_qdev_register(&unin_main_pci_host_info);
-    sysbus_register_dev("u3-agp", sizeof(UNINState),
-                        pci_u3_agp_init_device);
+
+    sysbus_register_withprop(&sysbus_u3_agp_pci_host_info);
     pci_qdev_register(&u3_agp_pci_host_info);
-    sysbus_register_dev("uni-north-agp", sizeof(UNINState),
-                        pci_unin_agp_init_device);
+
+    sysbus_register_withprop(&sysbus_unin_agp_pci_host_info);
     pci_qdev_register(&unin_agp_pci_host_info);
-    sysbus_register_dev("uni-north-pci", sizeof(UNINState),
-                        pci_unin_internal_init_device);
+
+    sysbus_register_withprop(&sysbus_unin_internal_pci_host_info);
     pci_qdev_register(&unin_internal_pci_host_info);
 }
 
Signature · 1 line
1.7.4.1
#40 lore raw

PATCH v3 24/28 unin_pci: Drop duplicate busdev

In reply to Anthony Liguori

From: Andreas Färber <[email protected]>

PCIHostState already has a busdev.

---
 hw/unin_pci.c |   29 ++++++++++++++++++++---------
 1 files changed, 20 insertions(+), 9 deletions(-)
hw/unin_pci.c +20 -9
index be0e98c..8c03cb0 100644
@@ -39,7 +39,6 @@
 static const int unin_irq_line[] = { 0x1b, 0x1c, 0x1d, 0x1e };
 
 typedef struct UNINState {
-    SysBusDevice busdev;
     PCIHostState host_state;
     MemoryRegion pci_mmio;
     MemoryRegion pci_hole;
@@ -134,11 +133,13 @@ static const MemoryRegionOps unin_data_ops = {
 
 static int pci_unin_main_init_device(SysBusDevice *dev)
 {
+    PCIHostState *h;
     UNINState *s;
 
     /* Use values found on a real PowerMac */
     /* Uninorth main bus */
-    s = FROM_SYSBUS(UNINState, dev);
+    h = FROM_SYSBUS(PCIHostState, dev);
+    s = DO_UPCAST(UNINState, host_state, h);
 
     memory_region_init_io(&s->host_state.conf_mem, &pci_host_conf_le_ops,
                           &s->host_state, "pci-conf-idx", 0x1000);
@@ -154,10 +155,12 @@ static int pci_unin_main_init_device(SysBusDevice *dev)
 
 static int pci_u3_agp_init_device(SysBusDevice *dev)
 {
+    PCIHostState *h;
     UNINState *s;
 
     /* Uninorth U3 AGP bus */
-    s = FROM_SYSBUS(UNINState, dev);
+    h = FROM_SYSBUS(PCIHostState, dev);
+    s = DO_UPCAST(UNINState, host_state, h);
 
     memory_region_init_io(&s->host_state.conf_mem, &pci_host_conf_le_ops,
                           &s->host_state, "pci-conf-idx", 0x1000);
@@ -173,10 +176,12 @@ static int pci_u3_agp_init_device(SysBusDevice *dev)
 
 static int pci_unin_agp_init_device(SysBusDevice *dev)
 {
+    PCIHostState *h;
     UNINState *s;
 
     /* Uninorth AGP bus */
-    s = FROM_SYSBUS(UNINState, dev);
+    h = FROM_SYSBUS(PCIHostState, dev);
+    s = DO_UPCAST(UNINState, host_state, h);
 
     memory_region_init_io(&s->host_state.conf_mem, &pci_host_conf_le_ops,
                           &s->host_state, "pci-conf-idx", 0x1000);
@@ -189,10 +194,12 @@ static int pci_unin_agp_init_device(SysBusDevice *dev)
 
 static int pci_unin_internal_init_device(SysBusDevice *dev)
 {
+    PCIHostState *h;
     UNINState *s;
 
     /* Uninorth internal bus */
-    s = FROM_SYSBUS(UNINState, dev);
+    h = FROM_SYSBUS(PCIHostState, dev);
+    s = DO_UPCAST(UNINState, host_state, h);
 
     memory_region_init_io(&s->host_state.conf_mem, &pci_host_conf_le_ops,
                           &s->host_state, "pci-conf-idx", 0x1000);
@@ -209,6 +216,7 @@ PCIBus *pci_pmac_init(qemu_irq *pic,
 {
     DeviceState *dev;
     SysBusDevice *s;
+    PCIHostState *h;
     UNINState *d;
 
     /* Use values found on a real PowerMac */
@@ -216,14 +224,15 @@ PCIBus *pci_pmac_init(qemu_irq *pic,
     dev = qdev_create(NULL, "uni-north-pci-pcihost");
     qdev_init_nofail(dev);
     s = sysbus_from_qdev(dev);
-    d = FROM_SYSBUS(UNINState, s);
+    h = FROM_SYSBUS(PCIHostState, s);
+    d = DO_UPCAST(UNINState, host_state, h);
     memory_region_init(&d->pci_mmio, "pci-mmio", 0x100000000ULL);
     memory_region_init_alias(&d->pci_hole, "pci-hole", &d->pci_mmio,
                              0x80000000ULL, 0x70000000ULL);
     memory_region_add_subregion(address_space_mem, 0x80000000ULL,
                                 &d->pci_hole);
 
-    d->host_state.bus = pci_register_bus(&d->busdev.qdev, "pci",
+    d->host_state.bus = pci_register_bus(dev, "pci",
                                          pci_unin_set_irq, pci_unin_map_irq,
                                          pic,
                                          &d->pci_mmio,
@@ -272,6 +281,7 @@ PCIBus *pci_pmac_u3_init(qemu_irq *pic,
 {
     DeviceState *dev;
     SysBusDevice *s;
+    PCIHostState *h;
     UNINState *d;
 
     /* Uninorth AGP bus */
@@ -279,7 +289,8 @@ PCIBus *pci_pmac_u3_init(qemu_irq *pic,
     dev = qdev_create(NULL, "u3-agp-pcihost");
     qdev_init_nofail(dev);
     s = sysbus_from_qdev(dev);
-    d = FROM_SYSBUS(UNINState, s);
+    h = FROM_SYSBUS(PCIHostState, s);
+    d = DO_UPCAST(UNINState, host_state, h);
 
     memory_region_init(&d->pci_mmio, "pci-mmio", 0x100000000ULL);
     memory_region_init_alias(&d->pci_hole, "pci-hole", &d->pci_mmio,
@@ -287,7 +298,7 @@ PCIBus *pci_pmac_u3_init(qemu_irq *pic,
     memory_region_add_subregion(address_space_mem, 0x80000000ULL,
                                 &d->pci_hole);
 
-    d->host_state.bus = pci_register_bus(&d->busdev.qdev, "pci",
+    d->host_state.bus = pci_register_bus(dev, "pci",
                                          pci_unin_set_irq, pci_unin_map_irq,
                                          pic,
                                          &d->pci_mmio,
Signature · 1 line
1.7.4.1
#41 lore raw

PATCH v3 25/28 unin_pci: Drop unused reset handler

In reply to Anthony Liguori

From: Andreas Färber <[email protected]>

---
 hw/unin_pci.c |    7 -------
 1 files changed, 0 insertions(+), 7 deletions(-)
hw/unin_pci.c +0 -7
index 8c03cb0..6a10013 100644
@@ -63,10 +63,6 @@ static void pci_unin_set_irq(void *opaque, int irq_num, int level)
     qemu_set_irq(pic[unin_irq_line[irq_num]], level);
 }
 
-static void pci_unin_reset(void *opaque)
-{
-}
-
 static uint32_t unin_get_config_reg(uint32_t reg, uint32_t addr)
 {
     uint32_t retval;
@@ -148,7 +144,6 @@ static int pci_unin_main_init_device(SysBusDevice *dev)
     sysbus_init_mmio(dev, &s->host_state.conf_mem);
     sysbus_init_mmio(dev, &s->host_state.data_mem);
 
-    qemu_register_reset(pci_unin_reset, &s->host_state);
     return 0;
 }
 
@@ -169,8 +164,6 @@ static int pci_u3_agp_init_device(SysBusDevice *dev)
     sysbus_init_mmio(dev, &s->host_state.conf_mem);
     sysbus_init_mmio(dev, &s->host_state.data_mem);
 
-    qemu_register_reset(pci_unin_reset, &s->host_state);
-
     return 0;
 }
 
Signature · 1 line
1.7.4.1
#42 lore raw

PATCH v3 26/28 pci: convert to QEMU Object Model

In reply to Anthony Liguori
---
 hw/9pfs/virtio-9p-device.c |   43 ++++++----
 hw/ac97.c                  |   39 +++++----
 hw/acpi_piix4.c            |   59 +++++++------
 hw/apb_pci.c               |   54 ++++++++-----
 hw/bonito.c                |   30 ++++---
 hw/cirrus_vga.c            |   33 +++++---
 hw/dec_pci.c               |   57 ++++++++-----
 hw/e1000.c                 |   43 ++++++----
 hw/eepro100.c              |  200 +++++++++++++++++++++++++++----------------
 hw/es1370.c                |   31 ++++---
 hw/grackle_pci.c           |   25 ++++--
 hw/gt64xxx.c               |   23 ++++--
 hw/i82378.c                |   31 ++++---
 hw/ide/cmd646.c            |   36 +++++---
 hw/ide/ich.c               |   31 ++++---
 hw/ide/piix.c              |   79 +++++++++++-------
 hw/ide/via.c               |   27 ++++--
 hw/intel-hda.c             |   56 ++++++++----
 hw/ioh3420.c               |   59 +++++++------
 hw/ivshmem.c               |   47 ++++++----
 hw/lsi53c895a.c            |   31 ++++---
 hw/macio.c                 |   19 +++--
 hw/ne2000.c                |   35 +++++---
 hw/pci.c                   |  123 ++++++++++++---------------
 hw/pci.h                   |   80 +++++++++---------
 hw/pci_bridge.c            |    2 +-
 hw/pcie.c                  |    2 +-
 hw/pcnet-pci.c             |   39 +++++----
 hw/piix4.c                 |   30 ++++---
 hw/piix_pci.c              |   95 +++++++++++++--------
 hw/ppc4xx_pci.c            |   21 +++--
 hw/ppce500_pci.c           |   21 +++--
 hw/prep_pci.c              |   33 ++++----
 hw/qdev.c                  |    1 +
 hw/qxl.c                   |   62 ++++++++-----
 hw/rtl8139.c               |   41 ++++++----
 hw/sh_pci.c                |   19 +++--
 hw/spapr_pci.c             |   15 +++-
 hw/sun4u.c                 |   23 ++++--
 hw/unin_pci.c              |   92 +++++++++++++-------
 hw/usb-ehci.c              |   54 ++++++++-----
 hw/usb-ohci.c              |   37 +++++---
 hw/usb-uhci.c              |  168 +++++++++++++++++++++++--------------
 hw/usb-xhci.c              |   33 +++++---
 hw/versatile_pci.c         |   22 +++--
 hw/vga-pci.c               |   27 ++++---
 hw/virtio-pci.c            |  188 ++++++++++++++++++++++++-----------------
 hw/vmware_vga.c            |   34 +++++---
 hw/vt82c686.c              |  120 ++++++++++++++++----------
 hw/wdt_i6300esb.c          |   33 +++++---
 hw/xen_platform.c          |   34 +++++---
 hw/xio3130_downstream.c    |   59 +++++++------
 hw/xio3130_upstream.c      |   53 +++++++-----
 53 files changed, 1599 insertions(+), 1050 deletions(-)
hw/9pfs/virtio-9p-device.c +26 -17
index 1325f2f..aded048 100644
@@ -163,23 +163,32 @@ static int virtio_9p_init_pci(PCIDevice *pci_dev)
     return 0;
 }
 
-static PCIDeviceInfo virtio_9p_info = {
-    .qdev.name = "virtio-9p-pci",
-    .qdev.size = sizeof(VirtIOPCIProxy),
-    .init      = virtio_9p_init_pci,
-    .vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET,
-    .device_id = 0x1009,
-    .revision  = VIRTIO_PCI_ABI_VERSION,
-    .class_id  = 0x2,
-    .qdev.props = (Property[]) {
-        DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
-        DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
-        DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
-        DEFINE_PROP_STRING("mount_tag", VirtIOPCIProxy, fsconf.tag),
-        DEFINE_PROP_STRING("fsdev", VirtIOPCIProxy, fsconf.fsdev_id),
-        DEFINE_PROP_END_OF_LIST(),
-    },
-    .qdev.reset = virtio_pci_reset,
+static Property virtio_9p_properties[] = {
+    DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
+    DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
+    DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
+    DEFINE_PROP_STRING("mount_tag", VirtIOPCIProxy, fsconf.tag),
+    DEFINE_PROP_STRING("fsdev", VirtIOPCIProxy, fsconf.fsdev_id),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void virtio_9p_class_init(ObjectClass *klass, void *data)
+{
+    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+    k->init = virtio_9p_init_pci;
+    k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
+    k->device_id = 0x1009;
+    k->revision = VIRTIO_PCI_ABI_VERSION;
+    k->class_id = 0x2;
+}
+
+static DeviceInfo virtio_9p_info = {
+    .name = "virtio-9p-pci",
+    .size = sizeof(VirtIOPCIProxy),
+    .props = virtio_9p_properties,
+    .class_init = virtio_9p_class_init,
+    .reset = virtio_pci_reset,
 };
 
 static void virtio_9p_register_devices(void)
hw/ac97.c +24 -15
index 03be99b..33b85f5 100644
@@ -1344,21 +1344,30 @@ int ac97_init (PCIBus *bus)
     return 0;
 }
 
-static PCIDeviceInfo ac97_info = {
-    .qdev.name    = "AC97",
-    .qdev.desc    = "Intel 82801AA AC97 Audio",
-    .qdev.size    = sizeof (AC97LinkState),
-    .qdev.vmsd    = &vmstate_ac97,
-    .init         = ac97_initfn,
-    .exit         = ac97_exitfn,
-    .vendor_id    = PCI_VENDOR_ID_INTEL,
-    .device_id    = PCI_DEVICE_ID_INTEL_82801AA_5,
-    .revision     = 0x01,
-    .class_id     = PCI_CLASS_MULTIMEDIA_AUDIO,
-    .qdev.props   = (Property[]) {
-        DEFINE_PROP_UINT32("use_broken_id", AC97LinkState, use_broken_id, 0),
-        DEFINE_PROP_END_OF_LIST(),
-    }
+static Property ac97_properties[] = {
+    DEFINE_PROP_UINT32("use_broken_id", AC97LinkState, use_broken_id, 0),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void ac97_class_init(ObjectClass *klass, void *data)
+{
+    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+    k->init = ac97_initfn;
+    k->exit = ac97_exitfn;
+    k->vendor_id = PCI_VENDOR_ID_INTEL;
+    k->device_id = PCI_DEVICE_ID_INTEL_82801AA_5;
+    k->revision = 0x01;
+    k->class_id = PCI_CLASS_MULTIMEDIA_AUDIO;
+}
+
+static DeviceInfo ac97_info = {
+    .name = "AC97",
+    .desc = "Intel 82801AA AC97 Audio",
+    .size = sizeof (AC97LinkState),
+    .vmsd = &vmstate_ac97,
+    .props = ac97_properties,
+    .class_init = ac97_class_init,
 };
 
 static void ac97_register (void)
hw/acpi_piix4.c +33 -26

88 lines not on this page · raw message

hw/apb_pci.c +34 -20

66 lines not on this page · raw message

hw/bonito.c +18 -12
index f2c7837..23384ec 100644
@@ -766,18 +766,24 @@ PCIBus *bonito_init(qemu_irq *pic)
     return b;
 }
 
-static PCIDeviceInfo bonito_info = {
-    .qdev.name    = "Bonito",
-    .qdev.desc    = "Host bridge",
-    .qdev.size    = sizeof(PCIBonitoState),
-    .qdev.vmsd    = &vmstate_bonito,
-    .qdev.no_user = 1,
-    .init         = bonito_initfn,
-    /*Bonito North Bridge, built on FPGA, VENDOR_ID/DEVICE_ID are "undefined"*/
-    .vendor_id    = 0xdf53,
-    .device_id    = 0x00d5,
-    .revision     = 0x01,
-    .class_id     = PCI_CLASS_BRIDGE_HOST,
+static void bonito_class_init(ObjectClass *klass, void *data)
+{
+    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+    k->init = bonito_initfn;
+    k->vendor_id = 0xdf53;
+    k->device_id = 0x00d5;
+    k->revision = 0x01;
+    k->class_id = PCI_CLASS_BRIDGE_HOST;
+}
+
+static DeviceInfo bonito_info = {
+    .name = "Bonito",
+    .desc = "Host bridge",
+    .size = sizeof(PCIBonitoState),
+    .vmsd = &vmstate_bonito,
+    .no_user = 1,
+    .class_init = bonito_class_init,
 };
 
 static SysBusDeviceInfo bonito_pcihost_info = {
hw/cirrus_vga.c +20 -13
index 1d0aadf..3fac2ee 100644
@@ -2935,8 +2935,8 @@ static int pci_cirrus_vga_initfn(PCIDevice *dev)
 {
      PCICirrusVGAState *d = DO_UPCAST(PCICirrusVGAState, dev, dev);
      CirrusVGAState *s = &d->cirrus_vga;
-     PCIDeviceInfo *info = DO_UPCAST(PCIDeviceInfo, qdev, qdev_get_info(&dev->qdev));
-     int16_t device_id = info->device_id;
+     PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev);
+     int16_t device_id = pc->device_id;
 
      /* setup VGA */
      vga_common_init(&s->vga, VGA_RAM_SIZE);
@@ -2970,17 +2970,24 @@ DeviceState *pci_cirrus_vga_init(PCIBus *bus)
     return &pci_create_simple(bus, -1, "cirrus-vga")->qdev;
 }
 
-static PCIDeviceInfo cirrus_vga_info = {
-    .qdev.name    = "cirrus-vga",
-    .qdev.desc    = "Cirrus CLGD 54xx VGA",
-    .qdev.size    = sizeof(PCICirrusVGAState),
-    .qdev.vmsd    = &vmstate_pci_cirrus_vga,
-    .no_hotplug   = 1,
-    .init         = pci_cirrus_vga_initfn,
-    .romfile      = VGABIOS_CIRRUS_FILENAME,
-    .vendor_id    = PCI_VENDOR_ID_CIRRUS,
-    .device_id    = CIRRUS_ID_CLGD5446,
-    .class_id     = PCI_CLASS_DISPLAY_VGA,
+static void cirrus_vga_class_init(ObjectClass *klass, void *data)
+{
+    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+    k->no_hotplug = 1;
+    k->init = pci_cirrus_vga_initfn;
+    k->romfile = VGABIOS_CIRRUS_FILENAME;
+    k->vendor_id = PCI_VENDOR_ID_CIRRUS;
+    k->device_id = CIRRUS_ID_CLGD5446;
+    k->class_id = PCI_CLASS_DISPLAY_VGA;
+}
+
+static DeviceInfo cirrus_vga_info = {
+    .name = "cirrus-vga",
+    .desc = "Cirrus CLGD 54xx VGA",
+    .size = sizeof(PCICirrusVGAState),
+    .vmsd = &vmstate_pci_cirrus_vga,
+    .class_init = cirrus_vga_class_init,
 };
 
 static void cirrus_vga_register(void)
hw/dec_pci.c +36 -21

75 lines not on this page · raw message

hw/e1000.c +26 -17

49 lines not on this page · raw message

hw/eepro100.c +125 -75

328 lines not on this page · raw message

hw/es1370.c +19 -12
index 3527eb6..205bed7 100644
@@ -1031,18 +1031,25 @@ int es1370_init (PCIBus *bus)
     return 0;
 }
 
-static PCIDeviceInfo es1370_info = {
-    .qdev.name    = "ES1370",
-    .qdev.desc    = "ENSONIQ AudioPCI ES1370",
-    .qdev.size    = sizeof (ES1370State),
-    .qdev.vmsd    = &vmstate_es1370,
-    .init         = es1370_initfn,
-    .exit         = es1370_exitfn,
-    .vendor_id    = PCI_VENDOR_ID_ENSONIQ,
-    .device_id    = PCI_DEVICE_ID_ENSONIQ_ES1370,
-    .class_id     = PCI_CLASS_MULTIMEDIA_AUDIO,
-    .subsystem_vendor_id = 0x4942,
-    .subsystem_id = 0x4c4c,
+static void es1370_class_init(ObjectClass *klass, void *data)
+{
+    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+    k->init = es1370_initfn;
+    k->exit = es1370_exitfn;
+    k->vendor_id = PCI_VENDOR_ID_ENSONIQ;
+    k->device_id = PCI_DEVICE_ID_ENSONIQ_ES1370;
+    k->class_id = PCI_CLASS_MULTIMEDIA_AUDIO;
+    k->subsystem_vendor_id = 0x4942;
+    k->subsystem_id = 0x4c4c;
+}
+
+static DeviceInfo es1370_info = {
+    .name = "ES1370",
+    .desc = "ENSONIQ AudioPCI ES1370",
+    .size = sizeof (ES1370State),
+    .vmsd = &vmstate_es1370,
+    .class_init = es1370_class_init,
 };
 
 static void es1370_register (void)
hw/grackle_pci.c +16 -9
index be10a6d..a790f97 100644
@@ -121,15 +121,22 @@ static int grackle_pci_host_init(PCIDevice *d)
     return 0;
 }
 
-static PCIDeviceInfo grackle_pci_info = {
-    .qdev.name = "grackle",
-    .qdev.size = sizeof(PCIDevice),
-    .qdev.no_user = 1,
-    .init      = grackle_pci_host_init,
-    .vendor_id = PCI_VENDOR_ID_MOTOROLA,
-    .device_id = PCI_DEVICE_ID_MOTOROLA_MPC106,
-    .revision  = 0x00,
-    .class_id  = PCI_CLASS_BRIDGE_HOST,
+static void grackle_pci_class_init(ObjectClass *klass, void *data)
+{
+    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+    k->init      = grackle_pci_host_init;
+    k->vendor_id = PCI_VENDOR_ID_MOTOROLA;
+    k->device_id = PCI_DEVICE_ID_MOTOROLA_MPC106;
+    k->revision  = 0x00;
+    k->class_id  = PCI_CLASS_BRIDGE_HOST;
+}
+
+static DeviceInfo grackle_pci_info = {
+    .name = "grackle",
+    .size = sizeof(PCIDevice),
+    .no_user = 1,
+    .class_init = grackle_pci_class_init,
 };
 
 static SysBusDeviceInfo grackle_pci_host_info = {
hw/gt64xxx.c +15 -8
index 432683a..9fc51f2 100644
@@ -1136,14 +1136,21 @@ static int gt64120_pci_init(PCIDevice *d)
     return 0;
 }
 
-static PCIDeviceInfo gt64120_pci_info = {
-    .qdev.name = "gt64120_pci",
-    .qdev.size = sizeof(PCIDevice),
-    .init      = gt64120_pci_init,
-    .vendor_id = PCI_VENDOR_ID_MARVELL,
-    .device_id = PCI_DEVICE_ID_MARVELL_GT6412X,
-    .revision  = 0x10,
-    .class_id  = PCI_CLASS_BRIDGE_HOST,
+static void gt64120_pci_class_init(ObjectClass *klass, void *data)
+{
+    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+    k->init = gt64120_pci_init;
+    k->vendor_id = PCI_VENDOR_ID_MARVELL;
+    k->device_id = PCI_DEVICE_ID_MARVELL_GT6412X;
+    k->revision = 0x10;
+    k->class_id = PCI_CLASS_BRIDGE_HOST;
+}
+
+static DeviceInfo gt64120_pci_info = {
+    .name = "gt64120_pci",
+    .size = sizeof(PCIDevice),
+    .class_init = gt64120_pci_class_init,
 };
 
 static void gt64120_pci_register_devices(void)
hw/i82378.c +19 -12
index 95ae274..99b453a 100644
@@ -238,18 +238,25 @@ static int pci_i82378_init(PCIDevice *dev)
     return 0;
 }
 
-static PCIDeviceInfo pci_i82378_info = {
-    .init = pci_i82378_init,
-    .qdev.name = "i82378",
-    .qdev.size = sizeof(PCIi82378State),
-    .qdev.vmsd = &vmstate_pci_i82378,
-    .vendor_id = PCI_VENDOR_ID_INTEL,
-    .device_id = PCI_DEVICE_ID_INTEL_82378,
-    .revision = 0x03,
-    .class_id = PCI_CLASS_BRIDGE_ISA,
-    .subsystem_vendor_id = 0x0,
-    .subsystem_id = 0x0,
-    .qdev.props = (Property[]) {
+static void pci_i82378_class_init(ObjectClass *klass, void *data)
+{
+    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+    k->init = pci_i82378_init;
+    k->vendor_id = PCI_VENDOR_ID_INTEL;
+    k->device_id = PCI_DEVICE_ID_INTEL_82378;
+    k->revision = 0x03;
+    k->class_id = PCI_CLASS_BRIDGE_ISA;
+    k->subsystem_vendor_id = 0x0;
+    k->subsystem_id = 0x0;
+}
+
+static DeviceInfo pci_i82378_info = {
+    .name = "i82378",
+    .size = sizeof(PCIi82378State),
+    .vmsd = &vmstate_pci_i82378,
+    .class_init = pci_i82378_class_init,
+    .props = (Property[]) {
         DEFINE_PROP_HEX32("iobase", PCIi82378State, isa_io_base, 0x80000000),
         DEFINE_PROP_HEX32("membase", PCIi82378State, isa_mem_base, 0xc0000000),
         DEFINE_PROP_END_OF_LIST()
hw/ide/cmd646.c +22 -14
index 99e7e6f..9c673bb 100644
@@ -325,20 +325,28 @@ void pci_cmd646_ide_init(PCIBus *bus, DriveInfo **hd_table,
     pci_ide_create_devs(dev, hd_table);
 }
 
-static PCIDeviceInfo cmd646_ide_info = {
-    .qdev.name    = "cmd646-ide",
-    .qdev.size    = sizeof(PCIIDEState),
-    .init         = pci_cmd646_ide_initfn,
-    .exit         = pci_cmd646_ide_exitfn,
-    .vendor_id    = PCI_VENDOR_ID_CMD,
-    .device_id    = PCI_DEVICE_ID_CMD_646,
-    /* IDE controller revision */
-    .revision     = 0x07,
-    .class_id     = PCI_CLASS_STORAGE_IDE,
-    .qdev.props   = (Property[]) {
-        DEFINE_PROP_UINT32("secondary", PCIIDEState, secondary, 0),
-        DEFINE_PROP_END_OF_LIST(),
-    },
+static Property cmd646_ide_properties[] = {
+    DEFINE_PROP_UINT32("secondary", PCIIDEState, secondary, 0),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void cmd646_ide_class_init(ObjectClass *klass, void *data)
+{
+    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+    k->init = pci_cmd646_ide_initfn;
+    k->exit = pci_cmd646_ide_exitfn;
+    k->vendor_id = PCI_VENDOR_ID_CMD;
+    k->device_id = PCI_DEVICE_ID_CMD_646;
+    k->revision = 0x07;
+    k->class_id = PCI_CLASS_STORAGE_IDE;
+}
+
+static DeviceInfo cmd646_ide_info = {
+    .name = "cmd646-ide",
+    .size = sizeof(PCIIDEState),
+    .props = cmd646_ide_properties,
+    .class_init = cmd646_ide_class_init,
 };
 
 static void cmd646_ide_register(void)
hw/ide/ich.c +19 -12
index e6421e2..1cae9f1 100644
@@ -146,18 +146,25 @@ static void pci_ich9_write_config(PCIDevice *pci, uint32_t addr,
     msi_write_config(pci, addr, val, len);
 }
 
-static PCIDeviceInfo ich_ahci_info = {
-    .qdev.name    = "ich9-ahci",
-    .qdev.alias   = "ahci",
-    .qdev.size    = sizeof(AHCIPCIState),
-    .qdev.vmsd    = &vmstate_ahci,
-    .init         = pci_ich9_ahci_init,
-    .exit         = pci_ich9_uninit,
-    .config_write = pci_ich9_write_config,
-    .vendor_id    = PCI_VENDOR_ID_INTEL,
-    .device_id    = PCI_DEVICE_ID_INTEL_82801IR,
-    .revision     = 0x02,
-    .class_id     = PCI_CLASS_STORAGE_SATA,
+static void ich_ahci_class_init(ObjectClass *klass, void *data)
+{
+    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+    k->init = pci_ich9_ahci_init;
+    k->exit = pci_ich9_uninit;
+    k->config_write = pci_ich9_write_config;
+    k->vendor_id = PCI_VENDOR_ID_INTEL;
+    k->device_id = PCI_DEVICE_ID_INTEL_82801IR;
+    k->revision = 0x02;
+    k->class_id = PCI_CLASS_STORAGE_SATA;
+}
+
+static DeviceInfo ich_ahci_info = {
+    .name = "ich9-ahci",
+    .alias = "ahci",
+    .size = sizeof(AHCIPCIState),
+    .vmsd = &vmstate_ahci,
+    .class_init = ich_ahci_class_init,
 };
 
 static void ich_ahci_register(void)
hw/ide/piix.c +50 -29

89 lines not on this page · raw message

hw/ide/via.c +17 -10
index 4ea2064..ef70864 100644
@@ -213,16 +213,23 @@ void vt82c686b_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn)
     pci_ide_create_devs(dev, hd_table);
 }
 
-static PCIDeviceInfo via_ide_info = {
-    .qdev.name    = "via-ide",
-    .qdev.size    = sizeof(PCIIDEState),
-    .qdev.no_user = 1,
-    .init         = vt82c686b_ide_initfn,
-    .exit         = vt82c686b_ide_exitfn,
-    .vendor_id    = PCI_VENDOR_ID_VIA,
-    .device_id    = PCI_DEVICE_ID_VIA_IDE,
-    .revision     = 0x06,
-    .class_id     = PCI_CLASS_STORAGE_IDE,
+static void via_ide_class_init(ObjectClass *klass, void *data)
+{
+    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+    k->init = vt82c686b_ide_initfn;
+    k->exit = vt82c686b_ide_exitfn;
+    k->vendor_id = PCI_VENDOR_ID_VIA;
+    k->device_id = PCI_DEVICE_ID_VIA_IDE;
+    k->revision = 0x06;
+    k->class_id = PCI_CLASS_STORAGE_IDE;
+}
+
+static DeviceInfo via_ide_info = {
+    .name = "via-ide",
+    .size = sizeof(PCIIDEState),
+    .no_user = 1,
+    .class_init = via_ide_class_init,
 };
 
 static void via_ide_register(void)
hw/intel-hda.c +37 -19

73 lines not on this page · raw message

hw/ioh3420.c +33 -26

71 lines not on this page · raw message

hw/ivshmem.c +28 -19

53 lines not on this page · raw message

hw/lsi53c895a.c +19 -12
index 3a87171..3571588 100644
@@ -2120,18 +2120,25 @@ static int lsi_scsi_init(PCIDevice *dev)
     return 0;
 }
 
-static PCIDeviceInfo lsi_info = {
-    .qdev.name  = "lsi53c895a",
-    .qdev.alias = "lsi",
-    .qdev.size  = sizeof(LSIState),
-    .qdev.reset = lsi_scsi_reset,
-    .qdev.vmsd  = &vmstate_lsi_scsi,
-    .init       = lsi_scsi_init,
-    .exit       = lsi_scsi_uninit,
-    .vendor_id  = PCI_VENDOR_ID_LSI_LOGIC,
-    .device_id  = PCI_DEVICE_ID_LSI_53C895A,
-    .class_id   = PCI_CLASS_STORAGE_SCSI,
-    .subsystem_id = 0x1000,
+static void lsi_class_init(ObjectClass *klass, void *data)
+{
+    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+    k->init = lsi_scsi_init;
+    k->exit = lsi_scsi_uninit;
+    k->vendor_id = PCI_VENDOR_ID_LSI_LOGIC;
+    k->device_id = PCI_DEVICE_ID_LSI_53C895A;
+    k->class_id = PCI_CLASS_STORAGE_SCSI;
+    k->subsystem_id = 0x1000;
+}
+
+static DeviceInfo lsi_info = {
+    .name = "lsi53c895a",
+    .alias = "lsi",
+    .size = sizeof(LSIState),
+    .reset = lsi_scsi_reset,
+    .vmsd = &vmstate_lsi_scsi,
+    .class_init = lsi_class_init,
 };
 
 static void lsi53c895a_register_devices(void)
hw/macio.c +13 -6
index 357e0ea..ae9db08 100644
@@ -81,12 +81,19 @@ static int macio_initfn(PCIDevice *d)
     return 0;
 }
 
-static PCIDeviceInfo macio_info = {
-    .qdev.name = "macio",
-    .qdev.size = sizeof(MacIOState),
-    .init = macio_initfn,
-    .vendor_id = PCI_VENDOR_ID_APPLE,
-    .class_id = PCI_CLASS_OTHERS << 8,
+static void macio_class_init(ObjectClass *klass, void *data)
+{
+    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+    k->init = macio_initfn;
+    k->vendor_id = PCI_VENDOR_ID_APPLE;
+    k->class_id = PCI_CLASS_OTHERS << 8;
+}
+
+static DeviceInfo macio_info = {
+    .name = "macio",
+    .size = sizeof(MacIOState),
+    .class_init = macio_class_init,
 };
 
 static void macio_register(void)
hw/ne2000.c +22 -13
index b44eab1..138479a 100644
@@ -786,19 +786,28 @@ static int pci_ne2000_exit(PCIDevice *pci_dev)
     return 0;
 }
 
-static PCIDeviceInfo ne2000_info = {
-    .qdev.name  = "ne2k_pci",
-    .qdev.size  = sizeof(PCINE2000State),
-    .qdev.vmsd  = &vmstate_pci_ne2000,
-    .init       = pci_ne2000_init,
-    .exit       = pci_ne2000_exit,
-    .vendor_id  = PCI_VENDOR_ID_REALTEK,
-    .device_id  = PCI_DEVICE_ID_REALTEK_8029,
-    .class_id   = PCI_CLASS_NETWORK_ETHERNET,
-    .qdev.props = (Property[]) {
-        DEFINE_NIC_PROPERTIES(PCINE2000State, ne2000.c),
-        DEFINE_PROP_END_OF_LIST(),
-    }
+static Property ne2000_properties[] = {
+    DEFINE_NIC_PROPERTIES(PCINE2000State, ne2000.c),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void ne2000_class_init(ObjectClass *klass, void *data)
+{
+    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+    k->init = pci_ne2000_init;
+    k->exit = pci_ne2000_exit;
+    k->vendor_id = PCI_VENDOR_ID_REALTEK;
+    k->device_id = PCI_DEVICE_ID_REALTEK_8029;
+    k->class_id = PCI_CLASS_NETWORK_ETHERNET;
+}
+
+static DeviceInfo ne2000_info = {
+    .name = "ne2k_pci",
+    .size = sizeof(PCINE2000State),
+    .vmsd = &vmstate_pci_ne2000,
+    .props = ne2000_properties,
+    .class_init = ne2000_class_init,
 };
 
 static void ne2000_register_devices(void)
hw/pci.c +54 -69

225 lines not on this page · raw message

hw/pci.h +41 -39

98 lines not on this page · raw message

hw/pci_bridge.c +1 -1
index 650d165..1ed4339 100644
@@ -294,7 +294,7 @@ void pci_bridge_reset_reg(PCIDevice *dev)
 /* default reset function for PCI-to-PCI bridge */
 void pci_bridge_reset(DeviceState *qdev)
 {
-    PCIDevice *dev = DO_UPCAST(PCIDevice, qdev, qdev);
+    PCIDevice *dev = PCI_DEVICE(qdev);
     pci_bridge_reset_reg(dev);
 }
 
hw/pcie.c +1 -1
index 5c9eb2f..7c92f19 100644
@@ -203,7 +203,7 @@ static void pcie_cap_slot_event(PCIDevice *dev, PCIExpressHotPlugEvent event)
 static int pcie_cap_slot_hotplug(DeviceState *qdev,
                                  PCIDevice *pci_dev, PCIHotplugState state)
 {
-    PCIDevice *d = DO_UPCAST(PCIDevice, qdev, qdev);
+    PCIDevice *d = PCI_DEVICE(qdev);
     uint8_t *exp_cap = d->config + d->exp.exp_cap;
     uint16_t sltsta = pci_get_word(exp_cap + PCI_EXP_SLTSTA);
 
hw/pcnet-pci.c +24 -15
index 4e164da..be3bd79 100644
@@ -348,21 +348,30 @@ static void pci_reset(DeviceState *dev)
     pcnet_h_reset(&d->state);
 }
 
-static PCIDeviceInfo pcnet_info = {
-    .qdev.name  = "pcnet",
-    .qdev.size  = sizeof(PCIPCNetState),
-    .qdev.reset = pci_reset,
-    .qdev.vmsd  = &vmstate_pci_pcnet,
-    .init       = pci_pcnet_init,
-    .exit       = pci_pcnet_uninit,
-    .vendor_id  = PCI_VENDOR_ID_AMD,
-    .device_id  = PCI_DEVICE_ID_AMD_LANCE,
-    .revision   = 0x10,
-    .class_id   = PCI_CLASS_NETWORK_ETHERNET,
-    .qdev.props = (Property[]) {
-        DEFINE_NIC_PROPERTIES(PCIPCNetState, state.conf),
-        DEFINE_PROP_END_OF_LIST(),
-    }
+static Property pcnet_properties[] = {
+    DEFINE_NIC_PROPERTIES(PCIPCNetState, state.conf),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void pcnet_class_init(ObjectClass *klass, void *data)
+{
+    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+    k->init = pci_pcnet_init;
+    k->exit = pci_pcnet_uninit;
+    k->vendor_id = PCI_VENDOR_ID_AMD;
+    k->device_id = PCI_DEVICE_ID_AMD_LANCE;
+    k->revision = 0x10;
+    k->class_id = PCI_CLASS_NETWORK_ETHERNET;
+}
+
+static DeviceInfo pcnet_info = {
+    .name = "pcnet",
+    .size = sizeof(PCIPCNetState),
+    .reset = pci_reset,
+    .vmsd = &vmstate_pci_pcnet,
+    .props = pcnet_properties,
+    .class_init = pcnet_class_init,
 };
 
 static void pci_pcnet_register_devices(void)
hw/piix4.c +18 -12
index 130dfd1..88be535 100644
@@ -102,18 +102,24 @@ int piix4_init(PCIBus *bus, ISABus **isa_bus, int devfn)
     return d->devfn;
 }
 
-static PCIDeviceInfo piix4_info = {
-    .qdev.name    = "PIIX4",
-    .qdev.desc    = "ISA bridge",
-    .qdev.size    = sizeof(PIIX4State),
-    .qdev.vmsd    = &vmstate_piix4,
-    .qdev.no_user = 1,
-    .no_hotplug   = 1,
-    .init         = piix4_initfn,
-    .vendor_id    = PCI_VENDOR_ID_INTEL,
-    /* 82371AB/EB/MB PIIX4 PCI-to-ISA bridge */
-    .device_id    = PCI_DEVICE_ID_INTEL_82371AB_0,
-    .class_id     = PCI_CLASS_BRIDGE_ISA,
+static void piix4_class_init(ObjectClass *klass, void *data)
+{
+    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+    k->no_hotplug = 1;
+    k->init = piix4_initfn;
+    k->vendor_id = PCI_VENDOR_ID_INTEL;
+    k->device_id = PCI_DEVICE_ID_INTEL_82371AB_0;
+    k->class_id = PCI_CLASS_BRIDGE_ISA;
+}
+
+static DeviceInfo piix4_info = {
+    .name = "PIIX4",
+    .desc = "ISA bridge",
+    .size = sizeof(PIIX4State),
+    .vmsd = &vmstate_piix4,
+    .no_user = 1,
+    .class_init = piix4_class_init,
 };
 
 static void piix4_register(void)
hw/piix_pci.c +58 -37

105 lines not on this page · raw message

hw/ppc4xx_pci.c +14 -7
index 26de007..b38840e 100644
@@ -366,13 +366,20 @@ static int ppc4xx_pcihost_initfn(SysBusDevice *dev)
     return 0;
 }
 
-static PCIDeviceInfo ppc4xx_host_bridge_info = {
-    .qdev.name    = "ppc4xx-host-bridge",
-    .qdev.desc    = "Host bridge",
-    .qdev.size    = sizeof(PCIDevice),
-    .vendor_id    = PCI_VENDOR_ID_IBM,
-    .device_id    = PCI_DEVICE_ID_IBM_440GX,
-    .class_id     = PCI_CLASS_BRIDGE_OTHER,
+static void ppc4xx_host_bridge_class_init(ObjectClass *klass, void *data)
+{
+    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+    k->vendor_id    = PCI_VENDOR_ID_IBM;
+    k->device_id    = PCI_DEVICE_ID_IBM_440GX;
+    k->class_id     = PCI_CLASS_BRIDGE_OTHER;
+}
+
+static DeviceInfo ppc4xx_host_bridge_info = {
+    .name    = "ppc4xx-host-bridge",
+    .desc    = "Host bridge",
+    .size    = sizeof(PCIDevice),
+    .class_init = ppc4xx_host_bridge_class_init,
 };
 
 static SysBusDeviceInfo ppc4xx_pcihost_info = {
hw/ppce500_pci.c +14 -7
index b606206..bc783bf 100644
@@ -339,13 +339,20 @@ static int e500_pcihost_initfn(SysBusDevice *dev)
     return 0;
 }
 
-static PCIDeviceInfo e500_host_bridge_info = {
-    .qdev.name    = "e500-host-bridge",
-    .qdev.desc    = "Host bridge",
-    .qdev.size    = sizeof(PCIDevice),
-    .vendor_id    = PCI_VENDOR_ID_FREESCALE,
-    .device_id    = PCI_DEVICE_ID_MPC8533E,
-    .class_id     = PCI_CLASS_PROCESSOR_POWERPC,
+static void e500_host_bridge_class_init(ObjectClass *klass, void *data)
+{
+    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+    k->vendor_id = PCI_VENDOR_ID_FREESCALE;
+    k->device_id = PCI_DEVICE_ID_MPC8533E;
+    k->class_id = PCI_CLASS_PROCESSOR_POWERPC;
+}
+
+static DeviceInfo e500_host_bridge_info = {
+    .name = "e500-host-bridge",
+    .desc = "Host bridge",
+    .size = sizeof(PCIDevice),
+    .class_init = e500_host_bridge_class_init,
 };
 
 static SysBusDeviceInfo e500_pcihost_info = {
hw/prep_pci.c +18 -15
index 4961eed..4ff1049 100644
@@ -134,21 +134,24 @@ static const VMStateDescription vmstate_raven = {
     },
 };
 
-static PCIDeviceInfo raven_info = {
-    .qdev.name = "raven",
-    .qdev.desc = "PReP Host Bridge - Motorola Raven",
-    .qdev.size = sizeof(RavenPCIState),
-    .qdev.vmsd = &vmstate_raven,
-    .qdev.no_user = 1,
-    .no_hotplug = 1,
-    .init = raven_init,
-    .vendor_id = PCI_VENDOR_ID_MOTOROLA,
-    .device_id = PCI_DEVICE_ID_MOTOROLA_RAVEN,
-    .revision = 0x00,
-    .class_id = PCI_CLASS_BRIDGE_HOST,
-    .qdev.props = (Property[]) {
-        DEFINE_PROP_END_OF_LIST()
-    },
+static void raven_class_init(ObjectClass *klass, void *data)
+{
+    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+    k->init = raven_init;
+    k->vendor_id = PCI_VENDOR_ID_MOTOROLA;
+    k->device_id = PCI_DEVICE_ID_MOTOROLA_RAVEN;
+    k->revision = 0x00;
+    k->class_id = PCI_CLASS_BRIDGE_HOST;
+}
+
+static DeviceInfo raven_info = {
+    .name = "raven",
+    .desc = "PReP Host Bridge - Motorola Raven",
+    .size = sizeof(RavenPCIState),
+    .vmsd = &vmstate_raven,
+    .no_user = 1,
+    .class_init = raven_class_init,
 };
 
 static SysBusDeviceInfo raven_pcihost_info = {
hw/qdev.c +1 -0
index 81996bb..a8c24de 100644
@@ -119,6 +119,7 @@ bool qdev_exists(const char *name)
 {
     return !!qdev_find_info(NULL, name);
 }
+
 static void qdev_property_add_legacy(DeviceState *dev, Property *prop,
                                      Error **errp);
 
hw/qxl.c +38 -24

70 lines not on this page · raw message

hw/rtl8139.c +25 -16

47 lines not on this page · raw message

hw/sh_pci.c +13 -6
index d4d028d..baeab9e 100644
@@ -147,12 +147,19 @@ static int sh_pci_host_init(PCIDevice *d)
     return 0;
 }
 
-static PCIDeviceInfo sh_pci_host_info = {
-    .qdev.name = "sh_pci_host",
-    .qdev.size = sizeof(PCIDevice),
-    .init      = sh_pci_host_init,
-    .vendor_id = PCI_VENDOR_ID_HITACHI,
-    .device_id = PCI_DEVICE_ID_HITACHI_SH7751R,
+static void sh_pci_host_class_init(ObjectClass *klass, void *data)
+{
+    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+    k->init = sh_pci_host_init;
+    k->vendor_id = PCI_VENDOR_ID_HITACHI;
+    k->device_id = PCI_DEVICE_ID_HITACHI_SH7751R;
+}
+
+static DeviceInfo sh_pci_host_info = {
+    .name = "sh_pci_host",
+    .size = sizeof(PCIDevice),
+    .class_init = sh_pci_host_class_init,
 };
 
 static void sh_pci_register_devices(void)
hw/spapr_pci.c +11 -4
index 2c95faa..8a39f8f 100644
@@ -214,10 +214,17 @@ static int spapr_main_pci_host_init(PCIDevice *d)
     return 0;
 }
 
-static PCIDeviceInfo spapr_main_pci_host_info = {
-    .qdev.name = "spapr-pci-host-bridge",
-    .qdev.size = sizeof(PCIDevice),
-    .init      = spapr_main_pci_host_init,
+static void spapr_main_pci_host_class_init(ObjectClass *klass, void *data)
+{
+    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+    k->init = spapr_main_pci_host_init;
+}
+
+static DeviceInfo spapr_main_pci_host_info = {
+    .name = "spapr-pci-host-bridge",
+    .size = sizeof(PCIDevice),
+    .class_init = spapr_main_pci_host_class_init,
 };
 
 static void spapr_register_devices(void)
hw/sun4u.c +15 -8
index 2dc3d04..6d9fdf6 100644
@@ -562,14 +562,21 @@ pci_ebus_init1(PCIDevice *pci_dev)
     return 0;
 }
 
-static PCIDeviceInfo ebus_info = {
-    .qdev.name = "ebus",
-    .qdev.size = sizeof(EbusState),
-    .init = pci_ebus_init1,
-    .vendor_id = PCI_VENDOR_ID_SUN,
-    .device_id = PCI_DEVICE_ID_SUN_EBUS,
-    .revision = 0x01,
-    .class_id = PCI_CLASS_BRIDGE_OTHER,
+static void ebus_class_init(ObjectClass *klass, void *data)
+{
+    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+    k->init = pci_ebus_init1;
+    k->vendor_id = PCI_VENDOR_ID_SUN;
+    k->device_id = PCI_DEVICE_ID_SUN_EBUS;
+    k->revision = 0x01;
+    k->class_id = PCI_CLASS_BRIDGE_OTHER;
+}
+
+static DeviceInfo ebus_info = {
+    .name = "ebus",
+    .size = sizeof(EbusState),
+    .class_init = ebus_class_init,
 };
 
 static void pci_ebus_register(void)
hw/unin_pci.c +60 -32

104 lines not on this page · raw message

hw/usb-ehci.c +34 -20

62 lines not on this page · raw message

hw/usb-ohci.c +23 -14
index 2df6a6e..b9b37d5 100644
@@ -1836,20 +1836,29 @@ static int ohci_init_pxa(SysBusDevice *dev)
     return 0;
 }
 
-static PCIDeviceInfo ohci_pci_info = {
-    .qdev.name    = "pci-ohci",
-    .qdev.desc    = "Apple USB Controller",
-    .qdev.size    = sizeof(OHCIPCIState),
-    .init         = usb_ohci_initfn_pci,
-    .vendor_id    = PCI_VENDOR_ID_APPLE,
-    .device_id    = PCI_DEVICE_ID_APPLE_IPID_USB,
-    .class_id     = PCI_CLASS_SERIAL_USB,
-    .qdev.props   = (Property[]) {
-        DEFINE_PROP_STRING("masterbus", OHCIPCIState, masterbus),
-        DEFINE_PROP_UINT32("num-ports", OHCIPCIState, num_ports, 3),
-        DEFINE_PROP_UINT32("firstport", OHCIPCIState, firstport, 0),
-        DEFINE_PROP_END_OF_LIST(),
-    },
+static Property ohci_pci_properties[] = {
+    DEFINE_PROP_STRING("masterbus", OHCIPCIState, masterbus),
+    DEFINE_PROP_UINT32("num-ports", OHCIPCIState, num_ports, 3),
+    DEFINE_PROP_UINT32("firstport", OHCIPCIState, firstport, 0),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void ohci_pci_class_init(ObjectClass *klass, void *data)
+{
+    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+    k->init = usb_ohci_initfn_pci;
+    k->vendor_id = PCI_VENDOR_ID_APPLE;
+    k->device_id = PCI_DEVICE_ID_APPLE_IPID_USB;
+    k->class_id = PCI_CLASS_SERIAL_USB;
+}
+
+static DeviceInfo ohci_pci_info = {
+    .name = "pci-ohci",
+    .desc = "Apple USB Controller",
+    .size = sizeof(OHCIPCIState),
+    .props = ohci_pci_properties,
+    .class_init = ohci_pci_class_init,
 };
 
 static SysBusDeviceInfo ohci_sysbus_info = {
hw/usb-uhci.c +105 -63

184 lines not on this page · raw message

hw/usb-xhci.c +20 -13
index 95bf010..fba2de3 100644
@@ -2724,19 +2724,26 @@ static const VMStateDescription vmstate_xhci = {
     .unmigratable = 1,
 };
 
-static PCIDeviceInfo xhci_info = {
-    .qdev.name    = "nec-usb-xhci",
-    .qdev.alias   = "xhci",
-    .qdev.size    = sizeof(XHCIState),
-    .qdev.vmsd    = &vmstate_xhci,
-    .init         = usb_xhci_initfn,
-    .vendor_id    = PCI_VENDOR_ID_NEC,
-    .device_id    = PCI_DEVICE_ID_NEC_UPD720200,
-    .class_id     = PCI_CLASS_SERIAL_USB,
-    .revision     = 0x03,
-    .is_express   = 1,
-    .config_write = xhci_write_config,
-    .qdev.props   = (Property[]) {
+static void xhci_class_init(ObjectClass *klass, void *data)
+{
+    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+    k->init         = usb_xhci_initfn;
+    k->vendor_id    = PCI_VENDOR_ID_NEC;
+    k->device_id    = PCI_DEVICE_ID_NEC_UPD720200;
+    k->class_id     = PCI_CLASS_SERIAL_USB;
+    k->revision     = 0x03;
+    k->is_express   = 1;
+    k->config_write = xhci_write_config;
+}
+
+static DeviceInfo xhci_info = {
+    .name    = "nec-usb-xhci",
+    .alias   = "xhci",
+    .size    = sizeof(XHCIState),
+    .vmsd    = &vmstate_xhci,
+    .class_init   = xhci_class_init,
+    .props   = (Property[]) {
         DEFINE_PROP_UINT32("msi", XHCIState, msi, 0),
         DEFINE_PROP_END_OF_LIST(),
     }
hw/versatile_pci.c +14 -8
index a285f7f..0eb7d32 100644
@@ -109,14 +109,20 @@ static int versatile_pci_host_init(PCIDevice *d)
     return 0;
 }
 
-static PCIDeviceInfo versatile_pci_host_info = {
-    .qdev.name = "versatile_pci_host",
-    .qdev.size = sizeof(PCIDevice),
-    .init      = versatile_pci_host_init,
-    .vendor_id = PCI_VENDOR_ID_XILINX,
-    /* Both boards have the same device ID.  Oh well.  */
-    .device_id = PCI_DEVICE_ID_XILINX_XC2VP30,
-    .class_id  = PCI_CLASS_PROCESSOR_CO,
+static void versatile_pci_host_class_init(ObjectClass *klass, void *data)
+{
+    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+    k->init = versatile_pci_host_init;
+    k->vendor_id = PCI_VENDOR_ID_XILINX;
+    k->device_id = PCI_DEVICE_ID_XILINX_XC2VP30;
+    k->class_id = PCI_CLASS_PROCESSOR_CO;
+}
+
+static DeviceInfo versatile_pci_host_info = {
+    .name = "versatile_pci_host",
+    .size = sizeof(PCIDevice),
+    .class_init = versatile_pci_host_class_init,
 };
 
 static void versatile_pci_register_devices(void)
hw/vga-pci.c +16 -11
index a75dbf3..ef9f8a5 100644
@@ -75,18 +75,23 @@ DeviceState *pci_vga_init(PCIBus *bus)
     return &pci_create_simple(bus, -1, "VGA")->qdev;
 }
 
-static PCIDeviceInfo vga_info = {
-    .qdev.name    = "VGA",
-    .qdev.size    = sizeof(PCIVGAState),
-    .qdev.vmsd    = &vmstate_vga_pci,
-    .no_hotplug   = 1,
-    .init         = pci_vga_initfn,
-    .romfile      = "vgabios-stdvga.bin",
+static void vga_class_init(ObjectClass *klass, void *data)
+{
+    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+    k->no_hotplug = 1;
+    k->init = pci_vga_initfn;
+    k->romfile = "vgabios-stdvga.bin";
+    k->vendor_id = PCI_VENDOR_ID_QEMU;
+    k->device_id = PCI_DEVICE_ID_QEMU_VGA;
+    k->class_id = PCI_CLASS_DISPLAY_VGA;
+}
 
-    /* dummy VGA (same as Bochs ID) */
-    .vendor_id    = PCI_VENDOR_ID_QEMU,
-    .device_id    = PCI_DEVICE_ID_QEMU_VGA,
-    .class_id     = PCI_CLASS_DISPLAY_VGA,
+static DeviceInfo vga_info = {
+    .name = "VGA",
+    .size = sizeof(PCIVGAState),
+    .vmsd = &vmstate_vga_pci,
+    .class_init = vga_class_init,
 };
 
 static void vga_register(void)
hw/virtio-pci.c +112 -76

200 lines not on this page · raw message

hw/vmware_vga.c +20 -14
index b1885c3..e7bbf7c 100644
@@ -1199,20 +1199,26 @@ static int pci_vmsvga_initfn(PCIDevice *dev)
     return 0;
 }
 
-static PCIDeviceInfo vmsvga_info = {
-    .qdev.name    = "vmware-svga",
-    .qdev.size    = sizeof(struct pci_vmsvga_state_s),
-    .qdev.vmsd    = &vmstate_vmware_vga,
-    .qdev.reset   = vmsvga_reset,
-    .no_hotplug   = 1,
-    .init         = pci_vmsvga_initfn,
-    .romfile      = "vgabios-vmware.bin",
-
-    .vendor_id    =  PCI_VENDOR_ID_VMWARE,
-    .device_id    = SVGA_PCI_DEVICE_ID,
-    .class_id     = PCI_CLASS_DISPLAY_VGA,
-    .subsystem_vendor_id = PCI_VENDOR_ID_VMWARE,
-    .subsystem_id = SVGA_PCI_DEVICE_ID,
+static void vmsvga_class_init(ObjectClass *klass, void *data)
+{
+    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+    k->no_hotplug = 1;
+    k->init = pci_vmsvga_initfn;
+    k->romfile = "vgabios-vmware.bin";
+    k->vendor_id = PCI_VENDOR_ID_VMWARE;
+    k->device_id = SVGA_PCI_DEVICE_ID;
+    k->class_id = PCI_CLASS_DISPLAY_VGA;
+    k->subsystem_vendor_id = PCI_VENDOR_ID_VMWARE;
+    k->subsystem_id = SVGA_PCI_DEVICE_ID;
+}
+
+static DeviceInfo vmsvga_info = {
+    .name = "vmware-svga",
+    .size = sizeof(struct pci_vmsvga_state_s),
+    .vmsd = &vmstate_vmware_vga,
+    .reset = vmsvga_reset,
+    .class_init = vmsvga_class_init,
 };
 
 static void vmsvga_register(void)
hw/vt82c686.c +75 -45

33 lines not on this page · raw message

hw/wdt_i6300esb.c +20 -13
index 20d8673..a6ceff8 100644

Lines of this file are not shown. View the raw message.

hw/xen_platform.c +20 -14
index e62eaef..40687fb 100644

Lines of this file are not shown. View the raw message.

hw/xio3130_downstream.c +33 -26

59 lines not on this page · raw message

hw/xio3130_upstream.c +30 -23

53 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
1.7.4.1

Part of the diff is not shown here. View the raw message.

#43 lore raw

Re: [Qemu-devel] [PATCH 26/28] pci: convert to QEMU Object Model

Quoted 40 lines · Anthony Liguori
hw/ac97.c +17 -15
index 03be99b..33b85f5 100644
@@ -1344,21 +1344,30 @@ int ac97_init (PCIBus *bus)
     return 0;
 }
 
-static PCIDeviceInfo ac97_info = {
-    .qdev.name    = "AC97",
-    .qdev.desc    = "Intel 82801AA AC97 Audio",
-    .qdev.size    = sizeof (AC97LinkState),
-    .qdev.vmsd    = &vmstate_ac97,
-    .init         = ac97_initfn,
-    .exit         = ac97_exitfn,
-    .vendor_id    = PCI_VENDOR_ID_INTEL,
-    .device_id    = PCI_DEVICE_ID_INTEL_82801AA_5,
-    .revision     = 0x01,
-    .class_id     = PCI_CLASS_MULTIMEDIA_AUDIO,
-    .qdev.props   = (Property[]) {
-        DEFINE_PROP_UINT32("use_broken_id", AC97LinkState, use_broken_id, 0),
-        DEFINE_PROP_END_OF_LIST(),
-    }
+static Property ac97_properties[] = {
+    DEFINE_PROP_UINT32("use_broken_id", AC97LinkState, use_broken_id, 0),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void ac97_class_init(ObjectClass *klass, void *data)
+{
+    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+    k->init = ac97_initfn;
+    k->exit = ac97_exitfn;
+    k->vendor_id = PCI_VENDOR_ID_INTEL;
+    k->device_id = PCI_DEVICE_ID_INTEL_82801AA_5;
+    k->revision = 0x01;
+    k->class_id = PCI_CLASS_MULTIMEDIA_AUDIO;
+}
+

hw/ac97.c int ac97_init (PCIBus *bus) · line 1373

Quoted 10 lines
hw/ac97.c +7 -0
+static DeviceInfo ac97_info = {
+    .name = "AC97",
+    .desc = "Intel 82801AA AC97 Audio",
+    .size = sizeof (AC97LinkState),
+    .vmsd = &vmstate_ac97,
+    .props = ac97_properties,
+    .class_init = ac97_class_init,
 };
 
 static void ac97_register (void)

So I have a question on this: the whole reason
we moved class, vendor id etc away from device init functions to a table was to make it possible
to perform queries, like list all available sound device types, or sort devices based on type, based on these tables.

Another purpose was to remove the manually written description/name, embedding pci id database in qemu instead, and performing lookups based on device/vendor id.

We never got these patches but it sounds like a genuinely useful functionality.

Is this no longer possible?

Signature · 1 line
MST
#44 lore raw

Re: [Qemu-devel] [PATCH 26/28] pci: convert to QEMU Object Model

Quoted 58 lines · Michael S. Tsirkin
Quoted 40 lines · Anthony Liguori
hw/ac97.c +17 -15
index 03be99b..33b85f5 100644
@@ -1344,21 +1344,30 @@ int ac97_init (PCIBus *bus)
      return 0;
  }
 
-static PCIDeviceInfo ac97_info = {
-    .qdev.name    = "AC97",
-    .qdev.desc    = "Intel 82801AA AC97 Audio",
-    .qdev.size    = sizeof (AC97LinkState),
-    .qdev.vmsd    =&vmstate_ac97,
-    .init         = ac97_initfn,
-    .exit         = ac97_exitfn,
-    .vendor_id    = PCI_VENDOR_ID_INTEL,
-    .device_id    = PCI_DEVICE_ID_INTEL_82801AA_5,
-    .revision     = 0x01,
-    .class_id     = PCI_CLASS_MULTIMEDIA_AUDIO,
-    .qdev.props   = (Property[]) {
-        DEFINE_PROP_UINT32("use_broken_id", AC97LinkState, use_broken_id, 0),
-        DEFINE_PROP_END_OF_LIST(),
-    }
+static Property ac97_properties[] = {
+    DEFINE_PROP_UINT32("use_broken_id", AC97LinkState, use_broken_id, 0),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void ac97_class_init(ObjectClass *klass, void *data)
+{
+    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+    k->init = ac97_initfn;
+    k->exit = ac97_exitfn;
+    k->vendor_id = PCI_VENDOR_ID_INTEL;
+    k->device_id = PCI_DEVICE_ID_INTEL_82801AA_5;
+    k->revision = 0x01;
+    k->class_id = PCI_CLASS_MULTIMEDIA_AUDIO;
+}
+

hw/ac97.c int ac97_init (PCIBus *bus) · line 1373

Quoted 10 lines
hw/ac97.c +7 -0
+static DeviceInfo ac97_info = {
+    .name = "AC97",
+    .desc = "Intel 82801AA AC97 Audio",
+    .size = sizeof (AC97LinkState),
+    .vmsd =&vmstate_ac97,
+    .props = ac97_properties,
+    .class_init = ac97_class_init,
  };
 
  static void ac97_register (void)

So I have a question on this: the whole reason
we moved class, vendor id etc away from device init functions to a table was to make it possible
to perform queries, like list all available sound device types, or sort devices based on type, based on these tables.

Quoted 8 lines

Another purpose was to remove the manually written description/name, embedding pci id database in qemu instead, and performing lookups based on device/vendor id.

We never got these patches but it sounds like a genuinely useful functionality.

Is this no longer possible?

There is one class instance per type. It's initialized lazily but the types are always known. IOW, ac97_class_init() is called once on the global PCIDeviceClass object, most likely very early during init.

These class objects can be searched and interacted with independently of any existing object. What you're after is:

static void show_pci_device(ObjectClass *klass, void *opaque)

{
    PCIDeviceClass *pc = PCI_DEVICE_CLASS(klass);

    printf("Device %s is %02x:%02x\n",
           object_class_get_name(klass), pc->vendor_id, pc->device_id);
}
{
    ...
    object_class_foreach(show_pci_device, TYPE_PCI_DEVICE, false, NULL);
}

Regards,

Anthony Liguori

#45 lore raw

PATCH v3 27/28 sysbus: apic: ioapic: convert to QEMU Object Model

In reply to Anthony Liguori

This converts three devices because apic and ioapic are subclasses of sysbus. Converting subclasses independently of their base class is prohibitively hard.

---
 hw/a9mpcore.c              |   21 ++++--
 hw/alpha_typhoon.c         |   17 ++++--
 hw/apb_pci.c               |   17 ++++--
 hw/apic.c                  |   21 ++++--
 hw/apic_common.c           |   88 ++++++++++++++++---------
 hw/apic_internal.h         |   32 ++++++----
 hw/arm11mpcore.c           |   68 +++++++++++++-------
 hw/arm_l2x0.c              |   25 +++++---
 hw/arm_mptimer.c           |   23 +++++---
 hw/arm_sysctl.c            |   31 ++++++---
 hw/arm_timer.c             |   46 ++++++++++----
 hw/armv7m.c                |   25 +++++---
 hw/armv7m_nvic.c           |   21 ++++--
 hw/bitbang_i2c.c           |   17 ++++--
 hw/bonito.c                |   17 ++++--
 hw/container.c             |   17 ++++--
 hw/cs4231.c                |   27 +++++---
 hw/dec_pci.c               |   19 +++++-
 hw/ds1225y.c               |   29 ++++++---
 hw/eccmemctl.c             |   29 ++++++---
 hw/empty_slot.c            |   15 +++-
 hw/escc.c                  |   43 ++++++++-----
 hw/esp.c                   |   27 +++++---
 hw/etraxfs_eth.c           |   31 ++++++---
 hw/etraxfs_pic.c           |   25 +++++---
 hw/etraxfs_ser.c           |   17 ++++--
 hw/etraxfs_timer.c         |   16 ++++-
 hw/fdc.c                   |   60 +++++++++++------
 hw/fw_cfg.c                |   33 ++++++----
 hw/g364fb.c                |   33 ++++++----
 hw/grackle_pci.c           |   19 ++++--
 hw/grlib_apbuart.c         |   25 +++++---
 hw/grlib_gptimer.c         |   31 ++++++---
 hw/grlib_irqmp.c           |   29 ++++++---
 hw/gt64xxx.c               |   16 ++++-
 hw/hpet.c                  |   33 ++++++----
 hw/integratorcp.c          |   40 +++++++++---
 hw/ioapic.c                |   17 ++++--
 hw/ioapic_common.c         |   49 ++++++++++----
 hw/ioapic_internal.h       |   26 +++++---
 hw/isa-bus.c               |   19 ++++--
 hw/kvm/apic.c              |   19 ++++--
 hw/kvm/clock.c             |   19 ++++--
 hw/kvm/ioapic.c            |   23 +++++---
 hw/lan9118.c               |   29 ++++++---
 hw/lance.c                 |   33 ++++++----
 hw/lm32_juart.c            |   19 ++++--
 hw/lm32_pic.c              |   19 ++++--
 hw/lm32_sys.c              |   29 ++++++---
 hw/lm32_timer.c            |   31 ++++++----
 hw/lm32_uart.c             |   19 ++++--
 hw/m48t59.c                |   31 ++++++---
 hw/marvell_88w8618_audio.c |   29 ++++++---
 hw/milkymist-ac97.c        |   19 ++++--
 hw/milkymist-hpdmc.c       |   19 ++++--
 hw/milkymist-memcard.c     |   19 ++++--
 hw/milkymist-minimac2.c    |   35 +++++++----
 hw/milkymist-pfpu.c        |   19 ++++--
 hw/milkymist-softusb.c     |   43 +++++++------
 hw/milkymist-sysctl.c      |   43 ++++++++-----
 hw/milkymist-tmu2.c        |   19 ++++--
 hw/milkymist-uart.c        |   19 ++++--
 hw/milkymist-vgafb.c       |   31 ++++++---
 hw/mips_malta.c            |   19 ++++--
 hw/mipsnet.c               |   31 ++++++---
 hw/mpc8544_guts.c          |   15 +++-
 hw/mst_fpga.c              |   19 ++++--
 hw/musicpal.c              |  151 +++++++++++++++++++++++++++++++-------------
 hw/nand.c                  |   33 ++++++----
 hw/omap_gpio.c             |   70 +++++++++++++--------
 hw/omap_intc.c             |   62 ++++++++++++-------
 hw/onenand.c               |   35 +++++++----
 hw/opencores_eth.c         |   29 ++++++---
 hw/piix_pci.c              |   19 ++++--
 hw/pl011.c                 |   36 +++++++++--
 hw/pl022.c                 |   15 ++++-
 hw/pl031.c                 |   19 ++++--
 hw/pl041.c                 |   34 ++++++----
 hw/pl050.c                 |   34 +++++++---
 hw/pl061.c                 |   34 +++++++---
 hw/pl080.c                 |   38 ++++++++----
 hw/pl110.c                 |   57 +++++++++++-----
 hw/pl181.c                 |   23 +++++---
 hw/pl190.c                 |   21 ++++--
 hw/ppc4xx_pci.c            |   17 ++++--
 hw/ppce500_pci.c           |   17 ++++--
 hw/ppce500_spin.c          |   15 +++-
 hw/prep_pci.c              |   19 ++++--
 hw/pxa2xx.c                |   69 ++++++++++++++------
 hw/pxa2xx_dma.c            |   29 ++++++---
 hw/pxa2xx_gpio.c           |   29 ++++++---
 hw/pxa2xx_pic.c            |   19 ++++--
 hw/pxa2xx_timer.c          |   66 ++++++++++++-------
 hw/realview.c              |   15 +++-
 hw/realview_gic.c          |   16 ++++-
 hw/s390-virtio-bus.c       |   17 ++++--
 hw/sbi.c                   |   19 ++++--
 hw/sh_pci.c                |   18 +++++-
 hw/slavio_intctl.c         |   19 ++++--
 hw/slavio_misc.c           |   34 +++++++---
 hw/slavio_timer.c          |   29 ++++++---
 hw/smc91c111.c             |   29 ++++++---
 hw/spapr_pci.c             |   16 ++++-
 hw/spapr_vio.c             |   17 ++++--
 hw/sparc32_dma.c           |   31 ++++++---
 hw/spitz.c                 |   55 +++++++++++------
 hw/stellaris.c             |   48 ++++++++++++--
 hw/stellaris_enet.c        |   25 +++++---
 hw/strongarm.c             |  124 ++++++++++++++++++++++++------------
 hw/sun4c_intctl.c          |   19 ++++--
 hw/sun4m.c                 |   78 ++++++++++++++++-------
 hw/sun4m_iommu.c           |   29 ++++++---
 hw/sun4u.c                 |   48 ++++++++++-----
 hw/sysbus.c                |   40 +++++++-----
 hw/sysbus.h                |   25 +++++---
 hw/tcx.c                   |   37 +++++++----
 hw/tusb6010.c              |   17 ++++--
 hw/unin_pci.c              |   72 ++++++++++++++-------
 hw/usb-ohci.c              |   19 ++++--
 hw/versatile_pci.c         |   31 ++++++++-
 hw/versatilepb.c           |   19 ++++--
 hw/xilinx_axidma.c         |   27 +++++---
 hw/xilinx_axienet.c        |   33 ++++++----
 hw/xilinx_ethlite.c        |   29 ++++++---
 hw/xilinx_intc.c           |   25 +++++---
 hw/xilinx_timer.c          |   27 +++++---
 hw/xilinx_uartlite.c       |   16 ++++-
 hw/zaurus.c                |   27 +++++---
 128 files changed, 2691 insertions(+), 1273 deletions(-)
hw/a9mpcore.c +14 -7
index 521b8cc..b42c475 100644
@@ -208,13 +208,20 @@ static const VMStateDescription vmstate_a9mp_priv = {
     }
 };
 
-static SysBusDeviceInfo a9mp_priv_info = {
-    .init = a9mp_priv_init,
-    .qdev.name  = "a9mpcore_priv",
-    .qdev.size  = sizeof(a9mp_priv_state),
-    .qdev.vmsd = &vmstate_a9mp_priv,
-    .qdev.reset = a9mp_priv_reset,
-    .qdev.props = (Property[]) {
+static void a9mp_priv_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = a9mp_priv_init;
+}
+
+static DeviceInfo a9mp_priv_info = {
+    .name = "a9mpcore_priv",
+    .size  = sizeof(a9mp_priv_state),
+    .vmsd = &vmstate_a9mp_priv,
+    .reset = a9mp_priv_reset,
+    .class_init = a9mp_priv_class_init,
+    .props = (Property[]) {
         DEFINE_PROP_UINT32("num-cpu", a9mp_priv_state, num_cpu, 1),
         /* The Cortex-A9MP may have anything from 0 to 224 external interrupt
          * IRQ lines (with another 32 internal). We default to 64+32, which
hw/alpha_typhoon.c +12 -5
index 7d924a3..8a68c7c 100644
@@ -808,11 +808,18 @@ static int typhoon_pcihost_init(SysBusDevice *dev)
     return 0;
 }
 
-static SysBusDeviceInfo typhoon_pcihost_info = {
-    .init = typhoon_pcihost_init,
-    .qdev.name = "typhoon-pcihost",
-    .qdev.size = sizeof(TyphoonState),
-    .qdev.no_user = 1
+static void typhoon_pcihost_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = typhoon_pcihost_init;
+}
+
+static DeviceInfo typhoon_pcihost_info = {
+    .name = "typhoon-pcihost",
+    .size = sizeof(TyphoonState),
+    .no_user = 1,
+    .class_init = typhoon_pcihost_class_init,
 };
 
 static void typhoon_register(void)
hw/apb_pci.c +12 -5
index 70cfc77..173dab3 100644
@@ -453,11 +453,18 @@ static DeviceInfo pbm_pci_host_info = {
     .class_init = pbm_pci_host_class_init,
 };
 
-static SysBusDeviceInfo pbm_host_info = {
-    .qdev.name = "pbm",
-    .qdev.size = sizeof(APBState),
-    .qdev.reset = pci_pbm_reset,
-    .init = pci_pbm_init_device,
+static void pbm_host_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = pci_pbm_init_device;
+}
+
+static DeviceInfo pbm_host_info = {
+    .name = "pbm",
+    .size = sizeof(APBState),
+    .reset = pci_pbm_reset,
+    .class_init = pbm_host_class_init,
 };
 
 static void pbm_pci_bridge_class_init(ObjectClass *klass, void *data)
hw/apic.c +14 -7
index e59c964..353119d 100644
@@ -763,13 +763,20 @@ static void apic_init(APICCommonState *s)
     local_apics[s->idx] = s;
 }
 
-static APICCommonInfo apic_info = {
-    .busdev.qdev.name = "apic",
-    .init = apic_init,
-    .set_base = apic_set_base,
-    .set_tpr = apic_set_tpr,
-    .external_nmi = apic_external_nmi,
-    .post_load = apic_post_load,
+static void apic_class_init(ObjectClass *klass, void *data)
+{
+    APICCommonClass *k = APIC_COMMON_CLASS(klass);
+
+    k->init = apic_init;
+    k->set_base = apic_set_base;
+    k->set_tpr = apic_set_tpr;
+    k->external_nmi = apic_external_nmi;
+    k->post_load = apic_post_load;
+}
+
+static DeviceInfo apic_info = {
+    .name = "apic",
+    .class_init = apic_class_init,
 };
 
 static void apic_register_devices(void)
hw/apic_common.c +56 -32

139 lines not on this page · raw message

hw/apic_internal.h +20 -12
index 1db4f06..1c6971c 100644
@@ -67,6 +67,25 @@
 
 typedef struct APICCommonState APICCommonState;
 
+#define TYPE_APIC_COMMON "apic-common"
+#define APIC_COMMON(obj) \
+     OBJECT_CHECK(APICCommonState, (obj), TYPE_APIC_COMMON)
+#define APIC_COMMON_CLASS(klass) \
+     OBJECT_CLASS_CHECK(APICCommonClass, (klass), TYPE_APIC_COMMON)
+#define APIC_COMMON_GET_CLASS(obj) \
+     OBJECT_GET_CLASS(APICCommonClass, (obj), TYPE_APIC_COMMON)
+
+typedef struct APICCommonClass
+{
+    SysBusDeviceClass parent_class;
+
+    void (*init)(APICCommonState *s);
+    void (*set_base)(APICCommonState *s, uint64_t val);
+    void (*set_tpr)(APICCommonState *s, uint8_t val);
+    void (*external_nmi)(APICCommonState *s);
+    void (*post_load)(APICCommonState *s);
+} APICCommonClass;
+
 struct APICCommonState {
     SysBusDevice busdev;
     MemoryRegion io_memory;
@@ -97,19 +116,8 @@ struct APICCommonState {
     int wait_for_sipi;
 };
 
-typedef struct APICCommonInfo APICCommonInfo;
-
-struct APICCommonInfo {
-    SysBusDeviceInfo busdev;
-    void (*init)(APICCommonState *s);
-    void (*set_base)(APICCommonState *s, uint64_t val);
-    void (*set_tpr)(APICCommonState *s, uint8_t val);
-    void (*external_nmi)(APICCommonState *s);
-    void (*post_load)(APICCommonState *s);
-};
-
 void apic_report_irq_delivered(int delivered);
-void apic_qdev_register(APICCommonInfo *info);
+void apic_qdev_register(DeviceInfo *info);
 bool apic_next_timer(APICCommonState *s, int64_t current_time);
 
 #endif /* !QEMU_APIC_INTERNAL_H */
hw/arm11mpcore.c +43 -25

76 lines not on this page · raw message

hw/arm_l2x0.c +16 -9
index 2faed39..7c5fe32 100644
@@ -160,22 +160,29 @@ static int l2x0_priv_init(SysBusDevice *dev)
     return 0;
 }
 
-static SysBusDeviceInfo l2x0_info = {
-    .init = l2x0_priv_init,
-    .qdev.name = "l2x0",
-    .qdev.size = sizeof(l2x0_state),
-    .qdev.vmsd = &vmstate_l2x0,
-    .qdev.no_user = 1,
-    .qdev.props = (Property[]) {
+static void l2x0_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = l2x0_priv_init;
+}
+
+static DeviceInfo l2x0_info = {
+    .name = "l2x0",
+    .size = sizeof(l2x0_state),
+    .vmsd = &vmstate_l2x0,
+    .no_user = 1,
+    .props = (Property[]) {
         DEFINE_PROP_UINT32("type", l2x0_state, cache_type, 0x1c100100),
         DEFINE_PROP_END_OF_LIST(),
     },
-    .qdev.reset = l2x0_priv_reset,
+    .reset = l2x0_priv_reset,
+    .class_init = l2x0_class_init,
 };
 
 static void l2x0_register_device(void)
 {
-    sysbus_register_withprop(&l2x0_info);
+    sysbus_qdev_register(&l2x0_info);
 }
 
 device_init(l2x0_register_device)
hw/arm_mptimer.c +15 -8
index 455a0aa..06319c2 100644
@@ -311,14 +311,21 @@ static const VMStateDescription vmstate_arm_mptimer = {
     }
 };
 
-static SysBusDeviceInfo arm_mptimer_info = {
-    .init = arm_mptimer_init,
-    .qdev.name = "arm_mptimer",
-    .qdev.size = sizeof(arm_mptimer_state),
-    .qdev.vmsd = &vmstate_arm_mptimer,
-    .qdev.reset = arm_mptimer_reset,
-    .qdev.no_user = 1,
-    .qdev.props = (Property[]) {
+static void arm_mptimer_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *sbc = SYS_BUS_DEVICE_CLASS(klass);
+
+    sbc->init = arm_mptimer_init;
+}
+
+static DeviceInfo arm_mptimer_info = {
+    .name = "arm_mptimer",
+    .size = sizeof(arm_mptimer_state),
+    .vmsd = &vmstate_arm_mptimer,
+    .reset = arm_mptimer_reset,
+    .no_user = 1,
+    .class_init = arm_mptimer_class_init,
+    .props = (Property[]) {
         DEFINE_PROP_UINT32("num-cpu", arm_mptimer_state, num_cpu, 0),
         DEFINE_PROP_END_OF_LIST()
     }
hw/arm_sysctl.c +20 -11
index 4b88648..08fb443 100644
@@ -401,17 +401,26 @@ void arm_sysctl_init(uint32_t base, uint32_t sys_id, uint32_t proc_id)
     sysbus_mmio_map(sysbus_from_qdev(dev), 0, base);
 }
 
-static SysBusDeviceInfo arm_sysctl_info = {
-    .init = arm_sysctl_init1,
-    .qdev.name  = "realview_sysctl",
-    .qdev.size  = sizeof(arm_sysctl_state),
-    .qdev.vmsd = &vmstate_arm_sysctl,
-    .qdev.reset = arm_sysctl_reset,
-    .qdev.props = (Property[]) {
-        DEFINE_PROP_UINT32("sys_id", arm_sysctl_state, sys_id, 0),
-        DEFINE_PROP_UINT32("proc_id", arm_sysctl_state, proc_id, 0),
-        DEFINE_PROP_END_OF_LIST(),
-    }
+static Property arm_sysctl_properties[] = {
+    DEFINE_PROP_UINT32("sys_id", arm_sysctl_state, sys_id, 0),
+    DEFINE_PROP_UINT32("proc_id", arm_sysctl_state, proc_id, 0),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void arm_sysctl_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = arm_sysctl_init1;
+}
+
+static DeviceInfo arm_sysctl_info = {
+    .name = "realview_sysctl",
+    .size = sizeof(arm_sysctl_state),
+    .vmsd = &vmstate_arm_sysctl,
+    .reset = arm_sysctl_reset,
+    .props = arm_sysctl_properties,
+    .class_init = arm_sysctl_class_init,
 };
 
 static void arm_sysctl_register_devices(void)
hw/arm_timer.c +33 -13

60 lines not on this page · raw message

hw/armv7m.c +17 -8
index 5c7a950..884fc90 100644
@@ -245,14 +245,23 @@ qemu_irq *armv7m_init(MemoryRegion *address_space_mem,
     return pic;
 }
 
-static SysBusDeviceInfo bitband_info = {
-    .init = bitband_init,
-    .qdev.name  = "ARM,bitband-memory",
-    .qdev.size  = sizeof(BitBandState),
-    .qdev.props = (Property[]) {
-        DEFINE_PROP_UINT32("base", BitBandState, base, 0),
-        DEFINE_PROP_END_OF_LIST(),
-    }
+static Property bitband_properties[] = {
+    DEFINE_PROP_UINT32("base", BitBandState, base, 0),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void bitband_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = bitband_init;
+}
+
+static DeviceInfo bitband_info = {
+    .name = "ARM,bitband-memory",
+    .size = sizeof(BitBandState),
+    .props = bitband_properties,
+    .class_init = bitband_class_init,
 };
 
 static void armv7m_register_devices(void)
hw/armv7m_nvic.c +14 -7
index 28f36ba..2bb94e8 100644
@@ -391,12 +391,19 @@ static int armv7m_nvic_init(SysBusDevice *dev)
     return 0;
 }
 
-static SysBusDeviceInfo armv7m_nvic_priv_info = {
-    .init = armv7m_nvic_init,
-    .qdev.name  = "armv7m_nvic",
-    .qdev.size  = sizeof(nvic_state),
-    .qdev.vmsd  = &vmstate_nvic,
-    .qdev.props = (Property[]) {
+static void armv7m_nvic_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);
+
+    sdc->init = armv7m_nvic_init;
+}
+
+static DeviceInfo armv7m_nvic_priv_info = {
+    .name = "armv7m_nvic",
+    .size = sizeof(nvic_state),
+    .vmsd  = &vmstate_nvic,
+    .class_init = armv7m_nvic_class_init,
+    .props = (Property[]) {
         /* The ARM v7m may have anything from 0 to 496 external interrupt
          * IRQ lines. We default to 64. Other boards may differ and should
          * set this property appropriately.
@@ -408,7 +415,7 @@ static SysBusDeviceInfo armv7m_nvic_priv_info = {
 
 static void armv7m_nvic_register_devices(void)
 {
-    sysbus_register_withprop(&armv7m_nvic_priv_info);
+    sysbus_qdev_register(&armv7m_nvic_priv_info);
 }
 
 device_init(armv7m_nvic_register_devices)
hw/bitbang_i2c.c +12 -5
index 93fb2ed..da9e5cf 100644
@@ -221,11 +221,18 @@ static int gpio_i2c_init(SysBusDevice *dev)
     return 0;
 }
 
-static SysBusDeviceInfo gpio_i2c_info = {
-    .init = gpio_i2c_init,
-    .qdev.name  = "gpio_i2c",
-    .qdev.desc  = "Virtual GPIO to I2C bridge",
-    .qdev.size  = sizeof(GPIOI2CState),
+static void gpio_i2c_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = gpio_i2c_init;
+}
+
+static DeviceInfo gpio_i2c_info = {
+    .name = "gpio_i2c",
+    .desc = "Virtual GPIO to I2C bridge",
+    .size = sizeof(GPIOI2CState),
+    .class_init = gpio_i2c_class_init,
 };
 
 static void bitbang_i2c_register(void)
hw/bonito.c +12 -5
index 23384ec..0333a2e 100644
@@ -786,11 +786,18 @@ static DeviceInfo bonito_info = {
     .class_init = bonito_class_init,
 };
 
-static SysBusDeviceInfo bonito_pcihost_info = {
-    .init         = bonito_pcihost_initfn,
-    .qdev.name    = "Bonito-pcihost",
-    .qdev.size    = sizeof(BonitoState),
-    .qdev.no_user = 1,
+static void bonito_pcihost_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = bonito_pcihost_initfn;
+}
+
+static DeviceInfo bonito_pcihost_info = {
+    .name = "Bonito-pcihost",
+    .size = sizeof(BonitoState),
+    .no_user = 1,
+    .class_init = bonito_pcihost_class_init,
 };
 
 static void bonito_register(void)
hw/container.c +12 -5
index 9cbf399..73f94c5 100644
@@ -5,11 +5,18 @@ static int container_initfn(SysBusDevice *dev)
     return 0;
 }
 
-static SysBusDeviceInfo container_info = {
-    .init = container_initfn,
-    .qdev.name = "container",
-    .qdev.size = sizeof(SysBusDevice),
-    .qdev.no_user = 1,
+static void container_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = container_initfn;
+}
+
+static DeviceInfo container_info = {
+    .name = "container",
+    .size = sizeof(SysBusDevice),
+    .no_user = 1,
+    .class_init = container_class_init,
 };
 
 static void container_init(void)
hw/cs4231.c +18 -9
index 2dfb708..87c4eb9 100644
@@ -151,15 +151,24 @@ static int cs4231_init1(SysBusDevice *dev)
     return 0;
 }
 
-static SysBusDeviceInfo cs4231_info = {
-    .init = cs4231_init1,
-    .qdev.name  = "SUNW,CS4231",
-    .qdev.size  = sizeof(CSState),
-    .qdev.vmsd  = &vmstate_cs4231,
-    .qdev.reset = cs_reset,
-    .qdev.props = (Property[]) {
-        {.name = NULL}
-    }
+static Property cs4231_properties[] = {
+    {.name = NULL},
+};
+
+static void cs4231_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = cs4231_init1;
+}
+
+static DeviceInfo cs4231_info = {
+    .name = "SUNW,CS4231",
+    .size = sizeof(CSState),
+    .vmsd = &vmstate_cs4231,
+    .reset = cs_reset,
+    .props = cs4231_properties,
+    .class_init = cs4231_class_init,
 };
 
 static void cs4231_register_devices(void)
hw/dec_pci.c +15 -4
index 7c3f50e..f0ecaff 100644
@@ -84,7 +84,7 @@ PCIBus *pci_dec_21154_init(PCIBus *parent_bus, int devfn)
     return pci_bridge_get_sec_bus(br);
 }
 
-static int pci_dec_21154_init_device(SysBusDevice *dev)
+static int pci_dec_21154_device_init(SysBusDevice *dev)
 {
     DECState *s;
 
@@ -123,11 +123,22 @@ static DeviceInfo dec_21154_pci_host_info = {
     .class_init = dec_21154_pci_host_class_init,
 };
 
-static void dec_register_devices(void)
+static void pci_dec_21154_device_class_init(ObjectClass *klass, void *data)
 {
-    sysbus_register_dev("dec-21154", sizeof(DECState),
-                        pci_dec_21154_init_device);
+    SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);
+
+    sdc->init = pci_dec_21154_device_init;
+}
+
+static DeviceInfo pci_dec_21154_device_info = {
+    .name = "dec-21154",
+    .size = sizeof(DECState),
+    .class_init = pci_dec_21154_device_class_init,
+};
 
+static void dec_register_devices(void)
+{
+    sysbus_qdev_register(&pci_dec_21154_device_info);
     pci_qdev_register(&dec_21154_pci_host_info);
     pci_qdev_register(&dec_21154_pci_bridge_info);
 }
hw/ds1225y.c +19 -10
index 7aa0832..5890b16 100644
@@ -134,16 +134,25 @@ static int nvram_sysbus_initfn(SysBusDevice *dev)
     return 0;
 }
 
-static SysBusDeviceInfo nvram_sysbus_info = {
-    .qdev.name  = "ds1225y",
-    .qdev.size  = sizeof(SysBusNvRamState),
-    .qdev.vmsd  = &vmstate_nvram,
-    .init       = nvram_sysbus_initfn,
-    .qdev.props = (Property[]) {
-        DEFINE_PROP_UINT32("size", SysBusNvRamState, nvram.chip_size, 0x2000),
-        DEFINE_PROP_STRING("filename", SysBusNvRamState, nvram.filename),
-        DEFINE_PROP_END_OF_LIST(),
-    },
+static Property nvram_sysbus_properties[] = {
+    DEFINE_PROP_UINT32("size", SysBusNvRamState, nvram.chip_size, 0x2000),
+    DEFINE_PROP_STRING("filename", SysBusNvRamState, nvram.filename),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void nvram_sysbus_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = nvram_sysbus_initfn;
+}
+
+static DeviceInfo nvram_sysbus_info = {
+    .name = "ds1225y",
+    .size = sizeof(SysBusNvRamState),
+    .vmsd = &vmstate_nvram,
+    .props = nvram_sysbus_properties,
+    .class_init = nvram_sysbus_class_init,
 };
 
 static void nvram_register(void)
hw/eccmemctl.c +19 -10
index 7743465..2d82c48 100644
@@ -308,16 +308,25 @@ static int ecc_init1(SysBusDevice *dev)
     return 0;
 }
 
-static SysBusDeviceInfo ecc_info = {
-    .init = ecc_init1,
-    .qdev.name  = "eccmemctl",
-    .qdev.size  = sizeof(ECCState),
-    .qdev.vmsd  = &vmstate_ecc,
-    .qdev.reset = ecc_reset,
-    .qdev.props = (Property[]) {
-        DEFINE_PROP_HEX32("version", ECCState, version, -1),
-        DEFINE_PROP_END_OF_LIST(),
-    }
+static Property ecc_properties[] = {
+    DEFINE_PROP_HEX32("version", ECCState, version, -1),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void ecc_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = ecc_init1;
+}
+
+static DeviceInfo ecc_info = {
+    .name = "eccmemctl",
+    .size = sizeof(ECCState),
+    .vmsd = &vmstate_ecc,
+    .reset = ecc_reset,
+    .props = ecc_properties,
+    .class_init = ecc_class_init,
 };
 
 
hw/empty_slot.c +11 -4
index 8b734f2..70e45d0 100644
@@ -76,10 +76,17 @@ static int empty_slot_init1(SysBusDevice *dev)
     return 0;
 }
 
-static SysBusDeviceInfo empty_slot_info = {
-    .init = empty_slot_init1,
-    .qdev.name  = "empty_slot",
-    .qdev.size  = sizeof(EmptySlot),
+static void empty_slot_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = empty_slot_init1;
+}
+
+static DeviceInfo empty_slot_info = {
+    .name = "empty_slot",
+    .size = sizeof(EmptySlot),
+    .class_init = empty_slot_class_init,
 };
 
 static void empty_slot_register_devices(void)
hw/escc.c +26 -17

49 lines not on this page · raw message

hw/esp.c +18 -9
index 9551c78..71d3e70 100644
@@ -753,15 +753,24 @@ static int esp_init1(SysBusDevice *dev)
     return scsi_bus_legacy_handle_cmdline(&s->bus);
 }
 
-static SysBusDeviceInfo esp_info = {
-    .init = esp_init1,
-    .qdev.name  = "esp",
-    .qdev.size  = sizeof(ESPState),
-    .qdev.vmsd  = &vmstate_esp,
-    .qdev.reset = esp_hard_reset,
-    .qdev.props = (Property[]) {
-        {.name = NULL}
-    }
+static Property esp_properties[] = {
+    {.name = NULL},
+};
+
+static void esp_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = esp_init1;
+}
+
+static DeviceInfo esp_info = {
+    .name = "esp",
+    .size = sizeof(ESPState),
+    .vmsd = &vmstate_esp,
+    .reset = esp_hard_reset,
+    .props = esp_properties,
+    .class_init = esp_class_init,
 };
 
 static void esp_register_devices(void)
hw/etraxfs_eth.c +20 -11
index 1b6b71d..92c822b 100644
@@ -613,17 +613,26 @@ static int fs_eth_init(SysBusDevice *dev)
 	return 0;
 }
 
-static SysBusDeviceInfo etraxfs_eth_info = {
-	.init = fs_eth_init,
-	.qdev.name  = "etraxfs-eth",
-	.qdev.size  = sizeof(struct fs_eth),
-	.qdev.props = (Property[]) {
-		DEFINE_PROP_UINT32("phyaddr", struct fs_eth, phyaddr, 1),
-		DEFINE_PROP_PTR("dma_out", struct fs_eth, vdma_out),
-		DEFINE_PROP_PTR("dma_in", struct fs_eth, vdma_in),
-		DEFINE_NIC_PROPERTIES(struct fs_eth, conf),
-		DEFINE_PROP_END_OF_LIST(),
-	}
+static Property etraxfs_eth_properties[] = {
+    DEFINE_PROP_UINT32("phyaddr", struct fs_eth, phyaddr, 1),
+    DEFINE_PROP_PTR("dma_out", struct fs_eth, vdma_out),
+    DEFINE_PROP_PTR("dma_in", struct fs_eth, vdma_in),
+    DEFINE_NIC_PROPERTIES(struct fs_eth, conf),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void etraxfs_eth_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = fs_eth_init;
+}
+
+static DeviceInfo etraxfs_eth_info = {
+    .name = "etraxfs-eth",
+    .size = sizeof(struct fs_eth),
+    .props = etraxfs_eth_properties,
+    .class_init = etraxfs_eth_class_init,
 };
 
 static void etraxfs_eth_register(void)
hw/etraxfs_pic.c +17 -8
index 993d6a8..8acf01e 100644
@@ -151,14 +151,23 @@ static int etraxfs_pic_init(SysBusDevice *dev)
     return 0;
 }
 
-static SysBusDeviceInfo etraxfs_pic_info = {
-    .init = etraxfs_pic_init,
-    .qdev.name  = "etraxfs,pic",
-    .qdev.size  = sizeof(struct etrax_pic),
-    .qdev.props = (Property[]) {
-        DEFINE_PROP_PTR("interrupt_vector", struct etrax_pic, interrupt_vector),
-        DEFINE_PROP_END_OF_LIST(),
-    }
+static Property etraxfs_pic_properties[] = {
+    DEFINE_PROP_PTR("interrupt_vector", struct etrax_pic, interrupt_vector),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void etraxfs_pic_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = etraxfs_pic_init;
+}
+
+static DeviceInfo etraxfs_pic_info = {
+    .name = "etraxfs,pic",
+    .size = sizeof(struct etrax_pic),
+    .props = etraxfs_pic_properties,
+    .class_init = etraxfs_pic_class_init,
 };
 
 static void etraxfs_pic_register(void)
hw/etraxfs_ser.c +12 -5
index 2623dab..a487805 100644
@@ -224,11 +224,18 @@ static int etraxfs_ser_init(SysBusDevice *dev)
     return 0;
 }
 
-static SysBusDeviceInfo etraxfs_ser_info = {
-    .init = etraxfs_ser_init,
-    .qdev.name  = "etraxfs,serial",
-    .qdev.size  = sizeof(struct etrax_serial),
-    .qdev.reset = etraxfs_ser_reset,
+static void etraxfs_ser_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = etraxfs_ser_init;
+}
+
+static DeviceInfo etraxfs_ser_info = {
+    .name = "etraxfs,serial",
+    .size = sizeof(struct etrax_serial),
+    .reset = etraxfs_ser_reset,
+    .class_init = etraxfs_ser_class_init,
 };
 
 static void etraxfs_serial_register(void)
hw/etraxfs_timer.c +14 -2
index 2dfdb30..c33058c 100644
@@ -329,10 +329,22 @@ static int etraxfs_timer_init(SysBusDevice *dev)
     return 0;
 }
 
+static void etraxfs_timer_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);
+
+    sdc->init = etraxfs_timer_init;
+}
+
+static DeviceInfo etraxfs_timer_info = {
+    .name = "etraxfs,timer",
+    .size = sizeof (struct etrax_timer),
+    .class_init = etraxfs_timer_class_init,
+};
+
 static void etraxfs_timer_register(void)
 {
-    sysbus_register_dev("etraxfs,timer", sizeof (struct etrax_timer),
-                        etraxfs_timer_init);
+    sysbus_qdev_register(&etraxfs_timer_info);
 }
 
 device_init(etraxfs_timer_register)
hw/fdc.c +39 -21

68 lines not on this page · raw message

hw/fw_cfg.c +21 -12
index f953532..e669ed4 100644
@@ -531,18 +531,27 @@ static int fw_cfg_init1(SysBusDevice *dev)
     return 0;
 }
 
-static SysBusDeviceInfo fw_cfg_info = {
-    .init = fw_cfg_init1,
-    .qdev.name = "fw_cfg",
-    .qdev.size = sizeof(FWCfgState),
-    .qdev.vmsd = &vmstate_fw_cfg,
-    .qdev.reset = fw_cfg_reset,
-    .qdev.no_user = 1,
-    .qdev.props = (Property[]) {
-        DEFINE_PROP_HEX32("ctl_iobase", FWCfgState, ctl_iobase, -1),
-        DEFINE_PROP_HEX32("data_iobase", FWCfgState, data_iobase, -1),
-        DEFINE_PROP_END_OF_LIST(),
-    },
+static Property fw_cfg_properties[] = {
+    DEFINE_PROP_HEX32("ctl_iobase", FWCfgState, ctl_iobase, -1),
+    DEFINE_PROP_HEX32("data_iobase", FWCfgState, data_iobase, -1),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void fw_cfg_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = fw_cfg_init1;
+}
+
+static DeviceInfo fw_cfg_info = {
+    .name = "fw_cfg",
+    .size = sizeof(FWCfgState),
+    .vmsd = &vmstate_fw_cfg,
+    .reset = fw_cfg_reset,
+    .no_user = 1,
+    .props = fw_cfg_properties,
+    .class_init = fw_cfg_class_init,
 };
 
 static void fw_cfg_register_devices(void)
hw/g364fb.c +21 -12
index 33ec149..8d6bfac 100644
@@ -553,18 +553,27 @@ static void g364fb_sysbus_reset(DeviceState *d)
     g364fb_reset(&s->g364);
 }
 
-static SysBusDeviceInfo g364fb_sysbus_info = {
-    .init = g364fb_sysbus_init,
-    .qdev.name = "sysbus-g364",
-    .qdev.desc = "G364 framebuffer",
-    .qdev.size = sizeof(G364SysBusState),
-    .qdev.vmsd = &vmstate_g364fb,
-    .qdev.reset = g364fb_sysbus_reset,
-    .qdev.props = (Property[]) {
-        DEFINE_PROP_HEX32("vram_size", G364SysBusState, g364.vram_size,
-                          8 * 1024 * 1024),
-        DEFINE_PROP_END_OF_LIST(),
-    }
+static Property g364fb_sysbus_properties[] = {
+    DEFINE_PROP_HEX32("vram_size", G364SysBusState, g364.vram_size,
+    8 * 1024 * 1024),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void g364fb_sysbus_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = g364fb_sysbus_init;
+}
+
+static DeviceInfo g364fb_sysbus_info = {
+    .name = "sysbus-g364",
+    .desc = "G364 framebuffer",
+    .size = sizeof(G364SysBusState),
+    .vmsd = &vmstate_g364fb,
+    .reset = g364fb_sysbus_reset,
+    .props = g364fb_sysbus_properties,
+    .class_init = g364fb_sysbus_class_init,
 };
 
 static void g364fb_register(void)
hw/grackle_pci.c +13 -6
index a790f97..549859d 100644
@@ -139,16 +139,23 @@ static DeviceInfo grackle_pci_info = {
     .class_init = grackle_pci_class_init,
 };
 
-static SysBusDeviceInfo grackle_pci_host_info = {
-    .qdev.name = "grackle-pcihost",
-    .qdev.size = sizeof(GrackleState),
-    .qdev.no_user = 1,
-    .init = pci_grackle_init_device,
+static void pci_grackle_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = pci_grackle_init_device;
+}
+
+static DeviceInfo grackle_pci_host_info = {
+    .name = "grackle-pcihost",
+    .size = sizeof(GrackleState),
+    .no_user = 1,
+    .class_init = pci_grackle_class_init,
 };
 
 static void grackle_register_devices(void)
 {
-    sysbus_register_withprop(&grackle_pci_host_info);
+    sysbus_qdev_register(&grackle_pci_host_info);
     pci_qdev_register(&grackle_pci_info);
 }
 
hw/grlib_apbuart.c +17 -8
index f8a64e1..dc12d58 100644
@@ -170,14 +170,23 @@ static int grlib_apbuart_init(SysBusDevice *dev)
     return 0;
 }
 
-static SysBusDeviceInfo grlib_gptimer_info = {
-    .init       = grlib_apbuart_init,
-    .qdev.name  = "grlib,apbuart",
-    .qdev.size  = sizeof(UART),
-    .qdev.props = (Property[]) {
-        DEFINE_PROP_CHR("chrdev", UART, chr),
-        DEFINE_PROP_END_OF_LIST()
-    }
+static Property grlib_gptimer_properties[] = {
+    DEFINE_PROP_CHR("chrdev", UART, chr),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void grlib_gptimer_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = grlib_apbuart_init;
+}
+
+static DeviceInfo grlib_gptimer_info = {
+    .name = "grlib,apbuart",
+    .size = sizeof(UART),
+    .props = grlib_gptimer_properties,
+    .class_init = grlib_gptimer_class_init,
 };
 
 static void grlib_gptimer_register(void)
hw/grlib_gptimer.c +20 -11
index 9c98a83..219009e 100644
@@ -372,17 +372,26 @@ static int grlib_gptimer_init(SysBusDevice *dev)
     return 0;
 }
 
-static SysBusDeviceInfo grlib_gptimer_info = {
-    .init       = grlib_gptimer_init,
-    .qdev.name  = "grlib,gptimer",
-    .qdev.reset = grlib_gptimer_reset,
-    .qdev.size  = sizeof(GPTimerUnit),
-    .qdev.props = (Property[]) {
-        DEFINE_PROP_UINT32("frequency", GPTimerUnit, freq_hz,   40000000),
-        DEFINE_PROP_UINT32("irq-line",  GPTimerUnit, irq_line,  8),
-        DEFINE_PROP_UINT32("nr-timers", GPTimerUnit, nr_timers, 2),
-        DEFINE_PROP_END_OF_LIST()
-    }
+static Property grlib_gptimer_properties[] = {
+    DEFINE_PROP_UINT32("frequency", GPTimerUnit, freq_hz,   40000000),
+    DEFINE_PROP_UINT32("irq-line",  GPTimerUnit, irq_line,  8),
+    DEFINE_PROP_UINT32("nr-timers", GPTimerUnit, nr_timers, 2),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void grlib_gptimer_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = grlib_gptimer_init;
+}
+
+static DeviceInfo grlib_gptimer_info = {
+    .name = "grlib,gptimer",
+    .reset = grlib_gptimer_reset,
+    .size = sizeof(GPTimerUnit),
+    .props = grlib_gptimer_properties,
+    .class_init = grlib_gptimer_class_init,
 };
 
 static void grlib_gptimer_register(void)
hw/grlib_irqmp.c +19 -10
index 2872556..1ccddfb 100644
@@ -354,16 +354,25 @@ static int grlib_irqmp_init(SysBusDevice *dev)
     return 0;
 }
 
-static SysBusDeviceInfo grlib_irqmp_info = {
-    .init = grlib_irqmp_init,
-    .qdev.name  = "grlib,irqmp",
-    .qdev.reset = grlib_irqmp_reset,
-    .qdev.size  = sizeof(IRQMP),
-    .qdev.props = (Property[]) {
-        DEFINE_PROP_PTR("set_pil_in", IRQMP, set_pil_in),
-        DEFINE_PROP_PTR("set_pil_in_opaque", IRQMP, set_pil_in_opaque),
-        DEFINE_PROP_END_OF_LIST(),
-    }
+static Property grlib_irqmp_properties[] = {
+    DEFINE_PROP_PTR("set_pil_in", IRQMP, set_pil_in),
+    DEFINE_PROP_PTR("set_pil_in_opaque", IRQMP, set_pil_in_opaque),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void grlib_irqmp_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = grlib_irqmp_init;
+}
+
+static DeviceInfo grlib_irqmp_info = {
+    .name = "grlib,irqmp",
+    .reset = grlib_irqmp_reset,
+    .size = sizeof(IRQMP),
+    .props = grlib_irqmp_properties,
+    .class_init = grlib_irqmp_class_init,
 };
 
 static void grlib_irqmp_register(void)
hw/gt64xxx.c +14 -2
index 9fc51f2..79d2dfb 100644
@@ -1153,10 +1153,22 @@ static DeviceInfo gt64120_pci_info = {
     .class_init = gt64120_pci_class_init,
 };
 
+static void gt64120_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);
+
+    sdc->init = gt64120_init;
+}
+
+static DeviceInfo gt64120_info = {
+    .name = "gt64120",
+    .size = sizeof(GT64120State),
+    .class_init = gt64120_class_init,
+};
+
 static void gt64120_pci_register_devices(void)
 {
-    sysbus_register_dev("gt64120", sizeof(GT64120State),
-                        gt64120_init);
+    sysbus_qdev_register(&gt64120_info);
     pci_qdev_register(&gt64120_pci_info);
 }
 
hw/hpet.c +21 -12
index 5312df7..aba9ea9 100644
@@ -695,18 +695,27 @@ static int hpet_init(SysBusDevice *dev)
     return 0;
 }
 
-static SysBusDeviceInfo hpet_device_info = {
-    .qdev.name    = "hpet",
-    .qdev.size    = sizeof(HPETState),
-    .qdev.no_user = 1,
-    .qdev.vmsd    = &vmstate_hpet,
-    .qdev.reset   = hpet_reset,
-    .init         = hpet_init,
-    .qdev.props = (Property[]) {
-        DEFINE_PROP_UINT8("timers", HPETState, num_timers, HPET_MIN_TIMERS),
-        DEFINE_PROP_BIT("msi", HPETState, flags, HPET_MSI_SUPPORT, false),
-        DEFINE_PROP_END_OF_LIST(),
-    },
+static Property hpet_device_properties[] = {
+    DEFINE_PROP_UINT8("timers", HPETState, num_timers, HPET_MIN_TIMERS),
+    DEFINE_PROP_BIT("msi", HPETState, flags, HPET_MSI_SUPPORT, false),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void hpet_device_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = hpet_init;
+}
+
+static DeviceInfo hpet_device_info = {
+    .name = "hpet",
+    .size = sizeof(HPETState),
+    .no_user = 1,
+    .vmsd = &vmstate_hpet,
+    .reset = hpet_reset,
+    .props = hpet_device_properties,
+    .class_init = hpet_device_class_init,
 };
 
 static void hpet_register_device(void)
hw/integratorcp.c +31 -9
index e5712fc..130accf 100644
@@ -518,19 +518,41 @@ static void integratorcp_machine_init(void)
 
 machine_init(integratorcp_machine_init);
 
-static SysBusDeviceInfo core_info = {
-    .init = integratorcm_init,
-    .qdev.name  = "integrator_core",
-    .qdev.size  = sizeof(integratorcm_state),
-    .qdev.props = (Property[]) {
-        DEFINE_PROP_UINT32("memsz", integratorcm_state, memsz, 0),
-        DEFINE_PROP_END_OF_LIST(),
-    }
+static Property core_properties[] = {
+    DEFINE_PROP_UINT32("memsz", integratorcm_state, memsz, 0),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void core_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = integratorcm_init;
+}
+
+static DeviceInfo core_info = {
+    .name = "integrator_core",
+    .size = sizeof(integratorcm_state),
+    .props = core_properties,
+    .class_init = core_class_init,
+};
+
+static void icp_pic_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);
+
+    sdc->init = icp_pic_init;
+}
+
+static DeviceInfo icp_pic_info = {
+    .name = "integrator_pic",
+    .size = sizeof(icp_pic_state),
+    .class_init = icp_pic_class_init,
 };
 
 static void integratorcp_register_devices(void)
 {
-    sysbus_register_dev("integrator_pic", sizeof(icp_pic_state), icp_pic_init);
+    sysbus_qdev_register(&icp_pic_info);
     sysbus_register_withprop(&core_info);
 }
 
hw/ioapic.c +12 -5
index 0c8be50..0939009 100644
@@ -235,11 +235,18 @@ static void ioapic_init(IOAPICCommonState *s, int instance_no)
     ioapics[instance_no] = s;
 }
 
-static IOAPICCommonInfo ioapic_info = {
-    .busdev.qdev.name = "ioapic",
-    .busdev.qdev.size = sizeof(IOAPICCommonState),
-    .busdev.qdev.reset = ioapic_reset_common,
-    .init = ioapic_init,
+static void ioapic_class_init(ObjectClass *klass, void *data)
+{
+    IOAPICCommonClass *k = IOAPIC_COMMON_CLASS(klass);
+
+    k->init = ioapic_init;
+}
+
+static DeviceInfo ioapic_info = {
+    .name = "ioapic",
+    .size = sizeof(IOAPICCommonState),
+    .reset = ioapic_reset_common,
+    .class_init = ioapic_class_init,
 };
 
 static void ioapic_register_devices(void)
hw/ioapic_common.c +35 -14

84 lines not on this page · raw message

hw/ioapic_internal.h +16 -10
index f8d90c0..9dff1a7 100644
@@ -73,6 +73,21 @@
 
 typedef struct IOAPICCommonState IOAPICCommonState;
 
+#define TYPE_IOAPIC_COMMON "ioapic-common"
+#define IOAPIC_COMMON(obj) \
+     OBJECT_CHECK(IOAPICCommonState, (obj), TYPE_IOAPIC_COMMON)
+#define IOAPIC_COMMON_CLASS(klass) \
+     OBJECT_CLASS_CHECK(IOAPICCommonClass, (klass), TYPE_IOAPIC_COMMON)
+#define IOAPIC_COMMON_GET_CLASS(obj) \
+     OBJECT_GET_CLASS(IOAPICCommonClass, (obj), TYPE_IOAPIC_COMMON)
+
+typedef struct IOAPICCommonClass {
+    SysBusDeviceClass parent_class;
+    void (*init)(IOAPICCommonState *s, int instance_no);
+    void (*pre_save)(IOAPICCommonState *s);
+    void (*post_load)(IOAPICCommonState *s);
+} IOAPICCommonClass;
+
 struct IOAPICCommonState {
     SysBusDevice busdev;
     MemoryRegion io_memory;
@@ -82,16 +97,7 @@ struct IOAPICCommonState {
     uint64_t ioredtbl[IOAPIC_NUM_PINS];
 };
 
-typedef struct IOAPICCommonInfo IOAPICCommonInfo;
-
-struct IOAPICCommonInfo {
-    SysBusDeviceInfo busdev;
-    void (*init)(IOAPICCommonState *s, int instance_no);
-    void (*pre_save)(IOAPICCommonState *s);
-    void (*post_load)(IOAPICCommonState *s);
-};
-
-void ioapic_qdev_register(IOAPICCommonInfo *info);
+void ioapic_qdev_register(DeviceInfo *info);
 void ioapic_reset_common(DeviceState *dev);
 
 #endif /* !QEMU_IOAPIC_INTERNAL_H */
hw/isa-bus.c +13 -6
index 6943194..92d8882 100644
@@ -189,12 +189,19 @@ static int isabus_bridge_init(SysBusDevice *dev)
     return 0;
 }
 
-static SysBusDeviceInfo isabus_bridge_info = {
-    .init = isabus_bridge_init,
-    .qdev.name  = "isabus-bridge",
-    .qdev.fw_name  = "isa",
-    .qdev.size  = sizeof(SysBusDevice),
-    .qdev.no_user = 1,
+static void isabus_bridge_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = isabus_bridge_init;
+}
+
+static DeviceInfo isabus_bridge_info = {
+    .name = "isabus-bridge",
+    .fw_name = "isa",
+    .size = sizeof(SysBusDevice),
+    .no_user = 1,
+    .class_init = isabus_bridge_class_init,
 };
 
 static TypeInfo isa_device_type_info = {
hw/kvm/apic.c +13 -6
index 6300695..bc80ae4 100644
@@ -122,12 +122,19 @@ static void kvm_apic_init(APICCommonState *s)
                                    MSI_SPACE_SIZE);
 }
 
-static APICCommonInfo kvm_apic_info = {
-    .busdev.qdev.name = "kvm-apic",
-    .init = kvm_apic_init,
-    .set_base = kvm_apic_set_base,
-    .set_tpr = kvm_apic_set_tpr,
-    .external_nmi = kvm_apic_external_nmi,
+static void kvm_apic_class_init(ObjectClass *klass, void *data)
+{
+    APICCommonClass *k = APIC_COMMON_CLASS(klass);
+
+    k->init = kvm_apic_init;
+    k->set_base = kvm_apic_set_base;
+    k->set_tpr = kvm_apic_set_tpr;
+    k->external_nmi = kvm_apic_external_nmi;
+}
+
+static DeviceInfo kvm_apic_info = {
+    .name = "kvm-apic",
+    .class_init = kvm_apic_class_init,
 };
 
 static void kvm_apic_register_device(void)
hw/kvm/clock.c +13 -6
index bb28c08..b997d2a 100644
@@ -92,12 +92,19 @@ static const VMStateDescription kvmclock_vmsd = {
     }
 };
 
-static SysBusDeviceInfo kvmclock_info = {
-    .qdev.name = "kvmclock",
-    .qdev.size = sizeof(KVMClockState),
-    .qdev.vmsd = &kvmclock_vmsd,
-    .qdev.no_user = 1,
-    .init = kvmclock_init,
+static void kvmclock_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = kvmclock_init;
+}
+
+static DeviceInfo kvmclock_info = {
+    .name = "kvmclock",
+    .size = sizeof(KVMClockState),
+    .vmsd = &kvmclock_vmsd,
+    .no_user = 1,
+    .class_init = kvmclock_class_init,
 };
 
 /* Note: Must be called after VCPU initialization. */
hw/kvm/ioapic.c +15 -8
index 10ffdd4..f8ea0cc 100644
@@ -93,17 +93,24 @@ static void kvm_ioapic_init(IOAPICCommonState *s, int instance_no)
     qdev_init_gpio_in(&s->busdev.qdev, kvm_ioapic_set_irq, IOAPIC_NUM_PINS);
 }
 
-static IOAPICCommonInfo kvm_ioapic_info = {
-    .busdev.qdev.name  = "kvm-ioapic",
-    .busdev.qdev.size = sizeof(KVMIOAPICState),
-    .busdev.qdev.reset = kvm_ioapic_reset,
-    .busdev.qdev.props = (Property[]) {
+static void kvm_ioapic_class_init(ObjectClass *klass, void *data)
+{
+    IOAPICCommonClass *k = IOAPIC_COMMON_CLASS(klass);
+
+    k->init      = kvm_ioapic_init;
+    k->pre_save  = kvm_ioapic_get;
+    k->post_load = kvm_ioapic_put;
+}
+
+static DeviceInfo kvm_ioapic_info = {
+    .name  = "kvm-ioapic",
+    .size = sizeof(KVMIOAPICState),
+    .reset = kvm_ioapic_reset,
+    .class_init = kvm_ioapic_class_init,
+    .props = (Property[]) {
         DEFINE_PROP_UINT32("gsi_base", KVMIOAPICState, kvm_gsi_base, 0),
         DEFINE_PROP_END_OF_LIST()
     },
-    .init      = kvm_ioapic_init,
-    .pre_save  = kvm_ioapic_get,
-    .post_load = kvm_ioapic_put,
 };
 
 static void kvm_ioapic_register_device(void)
hw/lan9118.c +19 -10
index 93e1896..3925b04 100644
@@ -1238,16 +1238,25 @@ static int lan9118_init1(SysBusDevice *dev)
     return 0;
 }
 
-static SysBusDeviceInfo lan9118_info = {
-    .init = lan9118_init1,
-    .qdev.name  = "lan9118",
-    .qdev.size  = sizeof(lan9118_state),
-    .qdev.reset = lan9118_reset,
-    .qdev.vmsd = &vmstate_lan9118,
-    .qdev.props = (Property[]) {
-        DEFINE_NIC_PROPERTIES(lan9118_state, conf),
-        DEFINE_PROP_END_OF_LIST(),
-    }
+static Property lan9118_properties[] = {
+    DEFINE_NIC_PROPERTIES(lan9118_state, conf),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void lan9118_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = lan9118_init1;
+}
+
+static DeviceInfo lan9118_info = {
+    .name = "lan9118",
+    .size = sizeof(lan9118_state),
+    .reset = lan9118_reset,
+    .vmsd = &vmstate_lan9118,
+    .props = lan9118_properties,
+    .class_init = lan9118_class_init,
 };
 
 static void lan9118_register_devices(void)
hw/lance.c +21 -12
index 7164700..969d766 100644
@@ -137,18 +137,27 @@ static void lance_reset(DeviceState *dev)
     pcnet_h_reset(&d->state);
 }
 
-static SysBusDeviceInfo lance_info = {
-    .init       = lance_init,
-    .qdev.name  = "lance",
-    .qdev.fw_name  = "ethernet",
-    .qdev.size  = sizeof(SysBusPCNetState),
-    .qdev.reset = lance_reset,
-    .qdev.vmsd  = &vmstate_lance,
-    .qdev.props = (Property[]) {
-        DEFINE_PROP_PTR("dma", SysBusPCNetState, state.dma_opaque),
-        DEFINE_NIC_PROPERTIES(SysBusPCNetState, state.conf),
-        DEFINE_PROP_END_OF_LIST(),
-    }
+static Property lance_properties[] = {
+    DEFINE_PROP_PTR("dma", SysBusPCNetState, state.dma_opaque),
+    DEFINE_NIC_PROPERTIES(SysBusPCNetState, state.conf),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void lance_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = lance_init;
+}
+
+static DeviceInfo lance_info = {
+    .name = "lance",
+    .fw_name = "ethernet",
+    .size = sizeof(SysBusPCNetState),
+    .reset = lance_reset,
+    .vmsd = &vmstate_lance,
+    .props = lance_properties,
+    .class_init = lance_class_init,
 };
 
 static void lance_register_devices(void)
hw/lm32_juart.c +13 -6
index 5454aa4..e25a409 100644
@@ -134,12 +134,19 @@ static const VMStateDescription vmstate_lm32_juart = {
     }
 };
 
-static SysBusDeviceInfo lm32_juart_info = {
-    .init = lm32_juart_init,
-    .qdev.name  = "lm32-juart",
-    .qdev.size  = sizeof(LM32JuartState),
-    .qdev.vmsd  = &vmstate_lm32_juart,
-    .qdev.reset = juart_reset,
+static void lm32_juart_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = lm32_juart_init;
+}
+
+static DeviceInfo lm32_juart_info = {
+    .name = "lm32-juart",
+    .size = sizeof(LM32JuartState),
+    .vmsd = &vmstate_lm32_juart,
+    .reset = juart_reset,
+    .class_init = lm32_juart_class_init,
 };
 
 static void lm32_juart_register(void)
hw/lm32_pic.c +13 -6
index 8dd0050..b7b1886 100644
@@ -174,12 +174,19 @@ static const VMStateDescription vmstate_lm32_pic = {
     }
 };
 
-static SysBusDeviceInfo lm32_pic_info = {
-    .init = lm32_pic_init,
-    .qdev.name  = "lm32-pic",
-    .qdev.size  = sizeof(LM32PicState),
-    .qdev.vmsd  = &vmstate_lm32_pic,
-    .qdev.reset = pic_reset,
+static void lm32_pic_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = lm32_pic_init;
+}
+
+static DeviceInfo lm32_pic_info = {
+    .name = "lm32-pic",
+    .size = sizeof(LM32PicState),
+    .vmsd = &vmstate_lm32_pic,
+    .reset = pic_reset,
+    .class_init = lm32_pic_class_init,
 };
 
 static void lm32_pic_register(void)
hw/lm32_sys.c +19 -10
index 83974ee..c83809e 100644
@@ -141,16 +141,25 @@ static const VMStateDescription vmstate_lm32_sys = {
     }
 };
 
-static SysBusDeviceInfo lm32_sys_info = {
-    .init = lm32_sys_init,
-    .qdev.name  = "lm32-sys",
-    .qdev.size  = sizeof(LM32SysState),
-    .qdev.vmsd  = &vmstate_lm32_sys,
-    .qdev.reset = sys_reset,
-    .qdev.props = (Property[]) {
-        DEFINE_PROP_UINT32("base", LM32SysState, base, 0xffff0000),
-        DEFINE_PROP_END_OF_LIST(),
-    }
+static Property lm32_sys_properties[] = {
+    DEFINE_PROP_UINT32("base", LM32SysState, base, 0xffff0000),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void lm32_sys_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = lm32_sys_init;
+}
+
+static DeviceInfo lm32_sys_info = {
+    .name = "lm32-sys",
+    .size = sizeof(LM32SysState),
+    .vmsd = &vmstate_lm32_sys,
+    .reset = sys_reset,
+    .props = lm32_sys_properties,
+    .class_init = lm32_sys_class_init,
 };
 
 static void lm32_sys_register(void)
hw/lm32_timer.c +19 -12
index 115e1e9..932c1f0 100644
@@ -199,18 +199,25 @@ static const VMStateDescription vmstate_lm32_timer = {
     }
 };
 
-static SysBusDeviceInfo lm32_timer_info = {
-    .init = lm32_timer_init,
-    .qdev.name  = "lm32-timer",
-    .qdev.size  = sizeof(LM32TimerState),
-    .qdev.vmsd  = &vmstate_lm32_timer,
-    .qdev.reset = timer_reset,
-    .qdev.props = (Property[]) {
-        DEFINE_PROP_UINT32(
-                "frequency", LM32TimerState, freq_hz, DEFAULT_FREQUENCY
-        ),
-        DEFINE_PROP_END_OF_LIST(),
-    }
+static Property lm32_timer_properties[] = {
+    DEFINE_PROP_UINT32("frequency", LM32TimerState, freq_hz, DEFAULT_FREQUENCY),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void lm32_timer_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = lm32_timer_init;
+}
+
+static DeviceInfo lm32_timer_info = {
+    .name = "lm32-timer",
+    .size = sizeof(LM32TimerState),
+    .vmsd = &vmstate_lm32_timer,
+    .reset = timer_reset,
+    .props = lm32_timer_properties,
+    .class_init = lm32_timer_class_init,
 };
 
 static void lm32_timer_register(void)
hw/lm32_uart.c +13 -6
index d013abd..ea7d00e 100644
@@ -271,12 +271,19 @@ static const VMStateDescription vmstate_lm32_uart = {
     }
 };
 
-static SysBusDeviceInfo lm32_uart_info = {
-    .init = lm32_uart_init,
-    .qdev.name  = "lm32-uart",
-    .qdev.size  = sizeof(LM32UartState),
-    .qdev.vmsd  = &vmstate_lm32_uart,
-    .qdev.reset = uart_reset,
+static void lm32_uart_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = lm32_uart_init;
+}
+
+static DeviceInfo lm32_uart_info = {
+    .name = "lm32-uart",
+    .size = sizeof(LM32UartState),
+    .vmsd = &vmstate_lm32_uart,
+    .reset = uart_reset,
+    .class_init = lm32_uart_class_init,
 };
 
 static void lm32_uart_register(void)
hw/m48t59.c +20 -11
index 5912cd6..262cfb8 100644
@@ -740,17 +740,26 @@ static DeviceInfo m48t59_isa_info = {
     }
 };
 
-static SysBusDeviceInfo m48t59_info = {
-    .init = m48t59_init1,
-    .qdev.name  = "m48t59",
-    .qdev.size = sizeof(M48t59SysBusState),
-    .qdev.reset = m48t59_reset_sysbus,
-    .qdev.props = (Property[]) {
-        DEFINE_PROP_UINT32("size",    M48t59SysBusState, state.size,    -1),
-        DEFINE_PROP_UINT32("type",    M48t59SysBusState, state.type,    -1),
-        DEFINE_PROP_HEX32( "io_base", M48t59SysBusState, state.io_base,  0),
-        DEFINE_PROP_END_OF_LIST(),
-    }
+static Property m48t59_properties[] = {
+    DEFINE_PROP_UINT32("size",    M48t59SysBusState, state.size,    -1),
+    DEFINE_PROP_UINT32("type",    M48t59SysBusState, state.type,    -1),
+    DEFINE_PROP_HEX32( "io_base", M48t59SysBusState, state.io_base,  0),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void m48t59_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = m48t59_init1;
+}
+
+static DeviceInfo m48t59_info = {
+    .name = "m48t59",
+    .size = sizeof(M48t59SysBusState),
+    .reset = m48t59_reset_sysbus,
+    .props = m48t59_properties,
+    .class_init = m48t59_class_init,
 };
 
 static void m48t59_register_devices(void)
hw/marvell_88w8618_audio.c +19 -10
index 409b1eb..355e492 100644
@@ -272,16 +272,25 @@ static const VMStateDescription mv88w8618_audio_vmsd = {
     }
 };
 
-static SysBusDeviceInfo mv88w8618_audio_info = {
-    .init = mv88w8618_audio_init,
-    .qdev.name  = "mv88w8618_audio",
-    .qdev.size  = sizeof(mv88w8618_audio_state),
-    .qdev.reset = mv88w8618_audio_reset,
-    .qdev.vmsd  = &mv88w8618_audio_vmsd,
-    .qdev.props = (Property[]) {
-        DEFINE_PROP_PTR("wm8750", mv88w8618_audio_state, wm),
-        {/* end of list */}
-    }
+static Property mv88w8618_audio_properties[] = {
+    DEFINE_PROP_PTR("wm8750", mv88w8618_audio_state, wm),
+    {/* end of list */},
+};
+
+static void mv88w8618_audio_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = mv88w8618_audio_init;
+}
+
+static DeviceInfo mv88w8618_audio_info = {
+    .name = "mv88w8618_audio",
+    .size = sizeof(mv88w8618_audio_state),
+    .reset = mv88w8618_audio_reset,
+    .vmsd = &mv88w8618_audio_vmsd,
+    .props = mv88w8618_audio_properties,
+    .class_init = mv88w8618_audio_class_init,
 };
 
 static void mv88w8618_register_devices(void)
hw/milkymist-ac97.c +13 -6
index e824a49..7dce5bc 100644
@@ -319,12 +319,19 @@ static const VMStateDescription vmstate_milkymist_ac97 = {
     }
 };
 
-static SysBusDeviceInfo milkymist_ac97_info = {
-    .init = milkymist_ac97_init,
-    .qdev.name  = "milkymist-ac97",
-    .qdev.size  = sizeof(MilkymistAC97State),
-    .qdev.vmsd  = &vmstate_milkymist_ac97,
-    .qdev.reset = milkymist_ac97_reset,
+static void milkymist_ac97_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = milkymist_ac97_init;
+}
+
+static DeviceInfo milkymist_ac97_info = {
+    .name = "milkymist-ac97",
+    .size = sizeof(MilkymistAC97State),
+    .vmsd = &vmstate_milkymist_ac97,
+    .reset = milkymist_ac97_reset,
+    .class_init = milkymist_ac97_class_init,
 };
 
 static void milkymist_ac97_register(void)
hw/milkymist-hpdmc.c +13 -6
index be575c9..46e8ae6 100644
@@ -145,12 +145,19 @@ static const VMStateDescription vmstate_milkymist_hpdmc = {
     }
 };
 
-static SysBusDeviceInfo milkymist_hpdmc_info = {
-    .init = milkymist_hpdmc_init,
-    .qdev.name  = "milkymist-hpdmc",
-    .qdev.size  = sizeof(MilkymistHpdmcState),
-    .qdev.vmsd  = &vmstate_milkymist_hpdmc,
-    .qdev.reset = milkymist_hpdmc_reset,
+static void milkymist_hpdmc_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = milkymist_hpdmc_init;
+}
+
+static DeviceInfo milkymist_hpdmc_info = {
+    .name = "milkymist-hpdmc",
+    .size = sizeof(MilkymistHpdmcState),
+    .vmsd = &vmstate_milkymist_hpdmc,
+    .reset = milkymist_hpdmc_reset,
+    .class_init = milkymist_hpdmc_class_init,
 };
 
 static void milkymist_hpdmc_register(void)
hw/milkymist-memcard.c +13 -6
index 865a46c..97eb793 100644
@@ -278,12 +278,19 @@ static const VMStateDescription vmstate_milkymist_memcard = {
     }
 };
 
-static SysBusDeviceInfo milkymist_memcard_info = {
-    .init = milkymist_memcard_init,
-    .qdev.name  = "milkymist-memcard",
-    .qdev.size  = sizeof(MilkymistMemcardState),
-    .qdev.vmsd  = &vmstate_milkymist_memcard,
-    .qdev.reset = milkymist_memcard_reset,
+static void milkymist_memcard_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = milkymist_memcard_init;
+}
+
+static DeviceInfo milkymist_memcard_info = {
+    .name = "milkymist-memcard",
+    .size = sizeof(MilkymistMemcardState),
+    .vmsd = &vmstate_milkymist_memcard,
+    .reset = milkymist_memcard_reset,
+    .class_init = milkymist_memcard_class_init,
 };
 
 static void milkymist_memcard_register(void)
hw/milkymist-minimac2.c +22 -13
index 107ba65..1ac6c6a 100644
@@ -516,19 +516,28 @@ static const VMStateDescription vmstate_milkymist_minimac2 = {
     }
 };
 
-static SysBusDeviceInfo milkymist_minimac2_info = {
-    .init = milkymist_minimac2_init,
-    .qdev.name  = "milkymist-minimac2",
-    .qdev.size  = sizeof(MilkymistMinimac2State),
-    .qdev.vmsd  = &vmstate_milkymist_minimac2,
-    .qdev.reset = milkymist_minimac2_reset,
-    .qdev.props = (Property[]) {
-        DEFINE_PROP_TADDR("buffers_base", MilkymistMinimac2State,
-                buffers_base, 0),
-        DEFINE_NIC_PROPERTIES(MilkymistMinimac2State, conf),
-        DEFINE_PROP_STRING("phy_model", MilkymistMinimac2State, phy_model),
-        DEFINE_PROP_END_OF_LIST(),
-    }
+static Property milkymist_minimac2_properties[] = {
+    DEFINE_PROP_TADDR("buffers_base", MilkymistMinimac2State,
+    buffers_base, 0),
+    DEFINE_NIC_PROPERTIES(MilkymistMinimac2State, conf),
+    DEFINE_PROP_STRING("phy_model", MilkymistMinimac2State, phy_model),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void milkymist_minimac2_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = milkymist_minimac2_init;
+}
+
+static DeviceInfo milkymist_minimac2_info = {
+    .name = "milkymist-minimac2",
+    .size = sizeof(MilkymistMinimac2State),
+    .vmsd = &vmstate_milkymist_minimac2,
+    .reset = milkymist_minimac2_reset,
+    .props = milkymist_minimac2_properties,
+    .class_init = milkymist_minimac2_class_init,
 };
 
 static void milkymist_minimac2_register(void)
hw/milkymist-pfpu.c +13 -6
index dc92eb6..b6ade5a 100644
@@ -519,12 +519,19 @@ static const VMStateDescription vmstate_milkymist_pfpu = {
     }
 };
 
-static SysBusDeviceInfo milkymist_pfpu_info = {
-    .init = milkymist_pfpu_init,
-    .qdev.name  = "milkymist-pfpu",
-    .qdev.size  = sizeof(MilkymistPFPUState),
-    .qdev.vmsd  = &vmstate_milkymist_pfpu,
-    .qdev.reset = milkymist_pfpu_reset,
+static void milkymist_pfpu_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = milkymist_pfpu_init;
+}
+
+static DeviceInfo milkymist_pfpu_info = {
+    .name = "milkymist-pfpu",
+    .size = sizeof(MilkymistPFPUState),
+    .vmsd = &vmstate_milkymist_pfpu,
+    .reset = milkymist_pfpu_reset,
+    .class_init = milkymist_pfpu_class_init,
 };
 
 static void milkymist_pfpu_register(void)
hw/milkymist-softusb.c +22 -21

49 lines not on this page · raw message

hw/milkymist-sysctl.c +26 -17

49 lines not on this page · raw message

hw/milkymist-tmu2.c +13 -6
index 20110e5..4004a12 100644
@@ -465,12 +465,19 @@ static const VMStateDescription vmstate_milkymist_tmu2 = {
     }
 };
 
-static SysBusDeviceInfo milkymist_tmu2_info = {
-    .init = milkymist_tmu2_init,
-    .qdev.name  = "milkymist-tmu2",
-    .qdev.size  = sizeof(MilkymistTMU2State),
-    .qdev.vmsd  = &vmstate_milkymist_tmu2,
-    .qdev.reset = milkymist_tmu2_reset,
+static void milkymist_tmu2_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = milkymist_tmu2_init;
+}
+
+static DeviceInfo milkymist_tmu2_info = {
+    .name = "milkymist-tmu2",
+    .size = sizeof(MilkymistTMU2State),
+    .vmsd = &vmstate_milkymist_tmu2,
+    .reset = milkymist_tmu2_reset,
+    .class_init = milkymist_tmu2_class_init,
 };
 
 static void milkymist_tmu2_register(void)
hw/milkymist-uart.c +13 -6
index eaf1c0d..312976d 100644
@@ -218,12 +218,19 @@ static const VMStateDescription vmstate_milkymist_uart = {
     }
 };
 
-static SysBusDeviceInfo milkymist_uart_info = {
-    .init = milkymist_uart_init,
-    .qdev.name  = "milkymist-uart",
-    .qdev.size  = sizeof(MilkymistUartState),
-    .qdev.vmsd  = &vmstate_milkymist_uart,
-    .qdev.reset = milkymist_uart_reset,
+static void milkymist_uart_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = milkymist_uart_init;
+}
+
+static DeviceInfo milkymist_uart_info = {
+    .name = "milkymist-uart",
+    .size = sizeof(MilkymistUartState),
+    .vmsd = &vmstate_milkymist_uart,
+    .reset = milkymist_uart_reset,
+    .class_init = milkymist_uart_class_init,
 };
 
 static void milkymist_uart_register(void)
hw/milkymist-vgafb.c +20 -11
index 108115e..81d31fa 100644
@@ -299,17 +299,26 @@ static const VMStateDescription vmstate_milkymist_vgafb = {
     }
 };
 
-static SysBusDeviceInfo milkymist_vgafb_info = {
-    .init = milkymist_vgafb_init,
-    .qdev.name  = "milkymist-vgafb",
-    .qdev.size  = sizeof(MilkymistVgafbState),
-    .qdev.vmsd  = &vmstate_milkymist_vgafb,
-    .qdev.reset = milkymist_vgafb_reset,
-    .qdev.props = (Property[]) {
-        DEFINE_PROP_UINT32("fb_offset", MilkymistVgafbState, fb_offset, 0x0),
-        DEFINE_PROP_UINT32("fb_mask", MilkymistVgafbState, fb_mask, 0xffffffff),
-        DEFINE_PROP_END_OF_LIST(),
-    }
+static Property milkymist_vgafb_properties[] = {
+    DEFINE_PROP_UINT32("fb_offset", MilkymistVgafbState, fb_offset, 0x0),
+    DEFINE_PROP_UINT32("fb_mask", MilkymistVgafbState, fb_mask, 0xffffffff),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void milkymist_vgafb_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = milkymist_vgafb_init;
+}
+
+static DeviceInfo milkymist_vgafb_info = {
+    .name = "milkymist-vgafb",
+    .size = sizeof(MilkymistVgafbState),
+    .vmsd = &vmstate_milkymist_vgafb,
+    .reset = milkymist_vgafb_reset,
+    .props = milkymist_vgafb_properties,
+    .class_init = milkymist_vgafb_class_init,
 };
 
 static void milkymist_vgafb_register(void)
hw/mips_malta.c +13 -6
index 4a4f76d..64603ce 100644
@@ -1007,11 +1007,18 @@ static int mips_malta_sysbus_device_init(SysBusDevice *sysbusdev)
     return 0;
 }
 
-static SysBusDeviceInfo mips_malta_device = {
-    .init = mips_malta_sysbus_device_init,
-    .qdev.name  = "mips-malta",
-    .qdev.size  = sizeof(MaltaState),
-    .qdev.props = (Property[]) {
+static void mips_malta_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = mips_malta_sysbus_device_init;
+}
+
+static DeviceInfo mips_malta_device = {
+    .name  = "mips-malta",
+    .size  = sizeof(MaltaState),
+    .class_init = mips_malta_class_init,
+    .props = (Property[]) {
         DEFINE_PROP_END_OF_LIST(),
     }
 };
@@ -1026,7 +1033,7 @@ static QEMUMachine mips_malta_machine = {
 
 static void mips_malta_device_init(void)
 {
-    sysbus_register_withprop(&mips_malta_device);
+    sysbus_qdev_register(&mips_malta_device);
 }
 
 static void mips_malta_machine_init(void)
hw/mipsnet.c +20 -11
index 0f80cfe..8cf9161 100644
@@ -252,17 +252,26 @@ static void mipsnet_sysbus_reset(DeviceState *dev)
     mipsnet_reset(s);
 }
 
-static SysBusDeviceInfo mipsnet_info = {
-    .init = mipsnet_sysbus_init,
-    .qdev.name = "mipsnet",
-    .qdev.desc = "MIPS Simulator network device",
-    .qdev.size = sizeof(MIPSnetState),
-    .qdev.vmsd = &vmstate_mipsnet,
-    .qdev.reset = mipsnet_sysbus_reset,
-    .qdev.props = (Property[]) {
-        DEFINE_NIC_PROPERTIES(MIPSnetState, conf),
-        DEFINE_PROP_END_OF_LIST(),
-    }
+static Property mipsnet_properties[] = {
+    DEFINE_NIC_PROPERTIES(MIPSnetState, conf),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void mipsnet_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = mipsnet_sysbus_init;
+}
+
+static DeviceInfo mipsnet_info = {
+    .name = "mipsnet",
+    .desc = "MIPS Simulator network device",
+    .size = sizeof(MIPSnetState),
+    .vmsd = &vmstate_mipsnet,
+    .reset = mipsnet_sysbus_reset,
+    .props = mipsnet_properties,
+    .class_init = mipsnet_class_init,
 };
 
 static void mipsnet_register_devices(void)
hw/mpc8544_guts.c +11 -4
index f01b38c..ec6bb4f 100644
@@ -121,10 +121,17 @@ static int mpc8544_guts_initfn(SysBusDevice *dev)
     return 0;
 }
 
-static SysBusDeviceInfo mpc8544_guts_info = {
-    .init         = mpc8544_guts_initfn,
-    .qdev.name    = "mpc8544-guts",
-    .qdev.size    = sizeof(GutsState),
+static void mpc8544_guts_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = mpc8544_guts_initfn;
+}
+
+static DeviceInfo mpc8544_guts_info = {
+    .name = "mpc8544-guts",
+    .size = sizeof(GutsState),
+    .class_init = mpc8544_guts_class_init,
 };
 
 static void mpc8544_guts_register(void)
hw/mst_fpga.c +13 -6
index 8bfa5dd..513bfa6 100644
@@ -238,12 +238,19 @@ static VMStateDescription vmstate_mst_fpga_regs = {
 	},
 };
 
-static SysBusDeviceInfo mst_fpga_info = {
-	.init = mst_fpga_init,
-	.qdev.name = "mainstone-fpga",
-	.qdev.desc = "Mainstone II FPGA",
-	.qdev.size = sizeof(mst_irq_state),
-	.qdev.vmsd = &vmstate_mst_fpga_regs,
+static void mst_fpga_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = mst_fpga_init;
+}
+
+static DeviceInfo mst_fpga_info = {
+    .name = "mainstone-fpga",
+    .desc = "Mainstone II FPGA",
+    .size = sizeof(mst_irq_state),
+    .vmsd = &vmstate_mst_fpga_regs,
+    .class_init = mst_fpga_class_init,
 };
 
 static void mst_fpga_register(void)
hw/musicpal.c +107 -44

205 lines not on this page · raw message

hw/nand.c +21 -12
index 8597aa6..6248731 100644
@@ -417,18 +417,27 @@ static int nand_device_init(SysBusDevice *dev)
     return 0;
 }
 
-static SysBusDeviceInfo nand_info = {
-    .init = nand_device_init,
-    .qdev.name = "nand",
-    .qdev.size = sizeof(NANDFlashState),
-    .qdev.reset = nand_reset,
-    .qdev.vmsd = &vmstate_nand,
-    .qdev.props = (Property[]) {
-        DEFINE_PROP_UINT8("manufacturer_id", NANDFlashState, manf_id, 0),
-        DEFINE_PROP_UINT8("chip_id", NANDFlashState, chip_id, 0),
-        DEFINE_PROP_DRIVE("drive", NANDFlashState, bdrv),
-        DEFINE_PROP_END_OF_LIST()
-    }
+static Property nand_properties[] = {
+    DEFINE_PROP_UINT8("manufacturer_id", NANDFlashState, manf_id, 0),
+    DEFINE_PROP_UINT8("chip_id", NANDFlashState, chip_id, 0),
+    DEFINE_PROP_DRIVE("drive", NANDFlashState, bdrv),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void nand_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = nand_device_init;
+}
+
+static DeviceInfo nand_info = {
+    .name = "nand",
+    .size = sizeof(NANDFlashState),
+    .reset = nand_reset,
+    .vmsd = &vmstate_nand,
+    .props = nand_properties,
+    .class_init = nand_class_init,
 };
 
 static void nand_create_device(void)
hw/omap_gpio.c +44 -26

78 lines not on this page · raw message

hw/omap_intc.c +40 -22

74 lines not on this page · raw message

hw/onenand.c +22 -13
index 33c9718..e20d4d9 100644
@@ -802,19 +802,28 @@ static int onenand_initfn(SysBusDevice *dev)
     return 0;
 }
 
-static SysBusDeviceInfo onenand_info = {
-    .init = onenand_initfn,
-    .qdev.name = "onenand",
-    .qdev.size = sizeof(OneNANDState),
-    .qdev.reset = onenand_system_reset,
-    .qdev.props = (Property[]) {
-        DEFINE_PROP_UINT16("manufacturer_id", OneNANDState, id.man, 0),
-        DEFINE_PROP_UINT16("device_id", OneNANDState, id.dev, 0),
-        DEFINE_PROP_UINT16("version_id", OneNANDState, id.ver, 0),
-        DEFINE_PROP_INT32("shift", OneNANDState, shift, 0),
-        DEFINE_PROP_DRIVE("drive", OneNANDState, bdrv),
-        DEFINE_PROP_END_OF_LIST()
-    }
+static Property onenand_properties[] = {
+    DEFINE_PROP_UINT16("manufacturer_id", OneNANDState, id.man, 0),
+    DEFINE_PROP_UINT16("device_id", OneNANDState, id.dev, 0),
+    DEFINE_PROP_UINT16("version_id", OneNANDState, id.ver, 0),
+    DEFINE_PROP_INT32("shift", OneNANDState, shift, 0),
+    DEFINE_PROP_DRIVE("drive", OneNANDState, bdrv),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void onenand_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = onenand_initfn;
+}
+
+static DeviceInfo onenand_info = {
+    .name = "onenand",
+    .size = sizeof(OneNANDState),
+    .reset = onenand_system_reset,
+    .props = onenand_properties,
+    .class_init = onenand_class_init,
 };
 
 static void onenand_register_device(void)
hw/opencores_eth.c +19 -10
index 5161b0c..1f45506 100644
@@ -727,16 +727,25 @@ static void qdev_open_eth_reset(DeviceState *dev)
     open_eth_reset(d);
 }
 
-static SysBusDeviceInfo open_eth_info = {
-    .qdev.name  = "open_eth",
-    .qdev.desc  = "Opencores 10/100 Mbit Ethernet",
-    .qdev.size  = sizeof(OpenEthState),
-    .qdev.reset = qdev_open_eth_reset,
-    .init       = sysbus_open_eth_init,
-    .qdev.props = (Property[]) {
-        DEFINE_NIC_PROPERTIES(OpenEthState, conf),
-        DEFINE_PROP_END_OF_LIST(),
-    }
+static Property open_eth_properties[] = {
+    DEFINE_NIC_PROPERTIES(OpenEthState, conf),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void open_eth_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = sysbus_open_eth_init;
+}
+
+static DeviceInfo open_eth_info = {
+    .name = "open_eth",
+    .desc = "Opencores 10/100 Mbit Ethernet",
+    .size = sizeof(OpenEthState),
+    .reset = qdev_open_eth_reset,
+    .props = open_eth_properties,
+    .class_init = open_eth_class_init,
 };
 
 static void open_eth_register_devices(void)
hw/piix_pci.c +13 -6
index 787db4e..8b01782 100644
@@ -566,12 +566,19 @@ static DeviceInfo i440fx_info = {
     .class_init = i440fx_class_init,
 };
 
-static SysBusDeviceInfo i440fx_pcihost_info = {
-    .init         = i440fx_pcihost_initfn,
-    .qdev.name    = "i440FX-pcihost",
-    .qdev.fw_name = "pci",
-    .qdev.size    = sizeof(I440FXState),
-    .qdev.no_user = 1,
+static void i440fx_pcihost_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = i440fx_pcihost_initfn;
+}
+
+static DeviceInfo i440fx_pcihost_info = {
+    .name = "i440FX-pcihost",
+    .fw_name = "pci",
+    .size = sizeof(I440FXState),
+    .no_user = 1,
+    .class_init = i440fx_pcihost_class_init,
 };
 
 static void i440fx_register(void)
hw/pl011.c +30 -6
index 1b05d76..088aa44 100644
@@ -278,22 +278,46 @@ static int pl011_init(SysBusDevice *dev, const unsigned char *id)
     return 0;
 }
 
-static int pl011_init_arm(SysBusDevice *dev)
+static int pl011_arm_init(SysBusDevice *dev)
 {
     return pl011_init(dev, pl011_id_arm);
 }
 
-static int pl011_init_luminary(SysBusDevice *dev)
+static int pl011_luminary_init(SysBusDevice *dev)
 {
     return pl011_init(dev, pl011_id_luminary);
 }
 
+static void pl011_arm_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);
+
+    sdc->init = pl011_arm_init;
+}
+
+static DeviceInfo pl011_arm_info = {
+    .name = "pl011",
+    .size = sizeof(pl011_state),
+    .class_init = pl011_arm_class_init,
+};
+
+static void pl011_luminary_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);
+
+    sdc->init = pl011_luminary_init;
+}
+
+static DeviceInfo pl011_luminary_info = {
+    .name = "pl011_luminary",
+    .size = sizeof(pl011_state),
+    .class_init = pl011_luminary_class_init,
+};
+
 static void pl011_register_devices(void)
 {
-    sysbus_register_dev("pl011", sizeof(pl011_state),
-                        pl011_init_arm);
-    sysbus_register_dev("pl011_luminary", sizeof(pl011_state),
-                        pl011_init_luminary);
+    sysbus_qdev_register(&pl011_arm_info);
+    sysbus_qdev_register(&pl011_luminary_info);
 }
 
 device_init(pl011_register_devices)
hw/pl022.c +14 -1
index d43e4a2..4f62712 100644
@@ -285,9 +285,22 @@ static int pl022_init(SysBusDevice *dev)
     return 0;
 }
 
+static void pl022_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);
+
+    sdc->init = pl022_init;
+}
+
+static DeviceInfo pl022_info = {
+    .name = "pl022",
+    .size = sizeof(pl022_state),
+    .class_init = pl022_class_init,
+};
+
 static void pl022_register_devices(void)
 {
-    sysbus_register_dev("pl022", sizeof(pl022_state), pl022_init);
+    sysbus_qdev_register(&pl022_info);
 }
 
 device_init(pl022_register_devices)
hw/pl031.c +13 -6
index 2fb0c8e..4cb8528 100644
@@ -213,12 +213,19 @@ static int pl031_init(SysBusDevice *dev)
     return 0;
 }
 
-static SysBusDeviceInfo pl031_info = {
-    .init = pl031_init,
-    .qdev.name = "pl031",
-    .qdev.size = sizeof(pl031_state),
-    .qdev.vmsd = &vmstate_pl031,
-    .qdev.no_user = 1,
+static void pl031_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = pl031_init;
+}
+
+static DeviceInfo pl031_info = {
+    .name = "pl031",
+    .size = sizeof(pl031_state),
+    .vmsd = &vmstate_pl031,
+    .no_user = 1,
+    .class_init = pl031_class_init,
 };
 
 static void pl031_register_devices(void)
hw/pl041.c +21 -13
index 4585ccf..0482851 100644
@@ -613,19 +613,27 @@ static const VMStateDescription vmstate_pl041 = {
     }
 };
 
-static SysBusDeviceInfo pl041_device_info = {
-    .init = pl041_init,
-    .qdev.name = "pl041",
-    .qdev.size = sizeof(pl041_state),
-    .qdev.vmsd = &vmstate_pl041,
-    .qdev.reset = pl041_device_reset,
-    .qdev.no_user = 1,
-    .qdev.props = (Property[]) {
-        /* Non-compact FIFO depth property */
-        DEFINE_PROP_UINT32("nc_fifo_depth", pl041_state,
-                           fifo_depth, DEFAULT_FIFO_DEPTH),
-        DEFINE_PROP_END_OF_LIST(),
-    },
[… more lines in the raw message]

Lines of this file are not shown. View the raw message.

hw/pl050.c +24 -10
index 8182a1c..5f60508 100644

Lines of this file are not shown. View the raw message.

hw/pl061.c +24 -10
index f33ae84..9dc9406 100644

Lines of this file are not shown. View the raw message.

hw/pl080.c +26 -12
index e001df9..727bfa1 100644

Lines of this file are not shown. View the raw message.

hw/pl110.c +39 -18

57 lines not on this page · raw message

hw/pl181.c +15 -8
index b79aa41..973d3fc 100644

Lines of this file are not shown. View the raw message.

hw/pl190.c +14 -7
index 6fc2656..79322aa 100644

Lines of this file are not shown. View the raw message.

hw/ppc4xx_pci.c +12 -5
index b38840e..36fb9f9 100644

Lines of this file are not shown. View the raw message.

hw/ppce500_pci.c +12 -5
index bc783bf..f8c4f11 100644

Lines of this file are not shown. View the raw message.

hw/ppce500_spin.c +11 -4
index e7b1453..cb5bc97 100644

Lines of this file are not shown. View the raw message.

hw/prep_pci.c +13 -6
index 4ff1049..b3b85b7 100644

Lines of this file are not shown. View the raw message.

hw/pxa2xx.c +49 -20

69 lines not on this page · raw message

hw/pxa2xx_dma.c +19 -10
index cb28107..9ecec33 100644

Lines of this file are not shown. View the raw message.

hw/pxa2xx_gpio.c +19 -10
index cc58c40..7a1333f 100644

Lines of this file are not shown. View the raw message.

hw/pxa2xx_pic.c +13 -6
index 92effbc..d318e83 100644

Lines of this file are not shown. View the raw message.

hw/pxa2xx_timer.c +42 -24

66 lines not on this page · raw message

hw/realview.c +11 -4
index d2fde44..42a0f20 100644

Lines of this file are not shown. View the raw message.

hw/realview_gic.c +14 -2
index 7342ede..0ccf21a 100644

Lines of this file are not shown. View the raw message.

hw/s390-virtio-bus.c +12 -5
index 2efea9f..8e34a78 100644

Lines of this file are not shown. View the raw message.

hw/sbi.c +13 -6
index 8965a71..0a062fc 100644

Lines of this file are not shown. View the raw message.

hw/sh_pci.c +15 -3
index baeab9e..a849176 100644

Lines of this file are not shown. View the raw message.

hw/slavio_intctl.c +13 -6
index 9925e64..12ce342 100644

Lines of this file are not shown. View the raw message.

hw/slavio_misc.c +24 -10
index 484301c..39a5269 100644

Lines of this file are not shown. View the raw message.

hw/slavio_timer.c +19 -10
index 44b500a..a3bebcd 100644

Lines of this file are not shown. View the raw message.

hw/smc91c111.c +19 -10
index 4a68f6b..4220880 100644

Lines of this file are not shown. View the raw message.

hw/spapr_pci.c +14 -2
index 8a39f8f..b6ac0d4 100644

Lines of this file are not shown. View the raw message.

hw/spapr_vio.c +12 -5
index bc586bf..dc2e9c9 100644

Lines of this file are not shown. View the raw message.

hw/sparc32_dma.c +20 -11
index 035d2e2..582f2f0 100644

Lines of this file are not shown. View the raw message.

hw/spitz.c +36 -19

55 lines not on this page · raw message

hw/stellaris.c +42 -6

48 lines not on this page · raw message

hw/stellaris_enet.c +17 -8
index ecd750c..3d3ef66 100644

Lines of this file are not shown. View the raw message.

hw/strongarm.c +84 -40

124 lines not on this page · raw message

hw/sun4c_intctl.c +13 -6
index e15b167..111d31b 100644

Lines of this file are not shown. View the raw message.

hw/sun4m.c +55 -23

78 lines not on this page · raw message

hw/sun4m_iommu.c +19 -10
index ef7627c..823bfac 100644

Lines of this file are not shown. View the raw message.

hw/sun4u.c +33 -15

48 lines not on this page · raw message

hw/sysbus.c +25 -15
index 2e06fe8..7d122f9 100644

Lines of this file are not shown. View the raw message.

hw/sysbus.h +17 -8
index 7b8ca23..a406077 100644

Lines of this file are not shown. View the raw message.

hw/tcx.c +23 -14
index 75a28f2..7c8677b 100644

Lines of this file are not shown. View the raw message.

hw/tusb6010.c +12 -5
index 276300a..8e11c54 100644

Lines of this file are not shown. View the raw message.

hw/unin_pci.c +49 -23

72 lines not on this page · raw message

hw/usb-ohci.c +13 -6
index b9b37d5..3437da1 100644

Lines of this file are not shown. View the raw message.

hw/versatile_pci.c +28 -3
index 0eb7d32..c2eb4dd 100644

Lines of this file are not shown. View the raw message.

hw/versatilepb.c +13 -6
index 0312b75..3f7490c 100644

Lines of this file are not shown. View the raw message.

hw/xilinx_axidma.c +18 -9
index 0da20d9..0fbe415 100644

Lines of this file are not shown. View the raw message.

hw/xilinx_axienet.c +21 -12
index e713248..c7dbe00 100644

Lines of this file are not shown. View the raw message.

hw/xilinx_ethlite.c +19 -10
index de595f4..dc7c0c8 100644

Lines of this file are not shown. View the raw message.

hw/xilinx_intc.c +17 -8
index c567885..c26b4ea 100644

Lines of this file are not shown. View the raw message.

hw/xilinx_timer.c +18 -9
index adca53b..0755e1b 100644

Lines of this file are not shown. View the raw message.

hw/xilinx_uartlite.c +14 -2
index 6533df9..8baabc7 100644

Lines of this file are not shown. View the raw message.

hw/zaurus.c +18 -9
index c4bcd29..b14240c 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
1.7.4.1

Part of the diff is not shown here. View the raw message.

#46 lore raw

Re: [Qemu-devel] [PATCH 27/28] sysbus: apic: ioapic: convert to QEMU Object Model

Quoted 2 lines · Anthony Liguori

This converts three devices because apic and ioapic are subclasses of sysbus. Converting subclasses independently of their base class is prohibitively hard.

Hmm, I think that's more than three... Can you split up? At least per target or per board/machine.

Also, I see a lot of programmatic initialization and a lot of repeating patterns (specifically regarding trivial class initialization) - there is no better alternative?

Jan

#47 lore raw

Re: [Qemu-devel] [PATCH 27/28] sysbus: apic: ioapic: convert to QEMU Object Model

Quoted 6 lines · Jan Kiszka
Quoted 2 lines · Anthony Liguori

This converts three devices because apic and ioapic are subclasses of sysbus. Converting subclasses independently of their base class is prohibitively hard.

Hmm, I think that's more than three... Can you split up? At least per target or per board/machine.

I meant three classes of devices.

I don't see a reasonable way to split it up. I put an awful lot of work into just splitting things up at this level. I know it's a big patch but at the same time, the changes are entirely mechanical so reviewing shouldn't be that bad.

Quoted 4 lines

Also, I see a lot of programmatic initialization and a lot of repeating patterns (specifically regarding trivial class initialization) - there is no better alternative?

Not really, no. It looks bad now because you have DeviceInfo still. Once DeviceInfo goes away, all of the initialization will happen in the class_init function.

The design of QOM is such that a lot of what was previously done via declarative structures is now done imperatively. But the code bloat that came in this patch series will decrease significantly with the next series as we eliminate DeviceInfo.

Regards,

Anthony Liguori

Quoted 1 line

Jan

#48 lore raw

Re: [Qemu-devel] [PATCH 27/28] sysbus: apic: ioapic: convert to QEMU Object Model

Quoted 4 lines · Anthony Liguori
Quoted 3 lines

Also, I see a lot of programmatic initialization and a lot of repeating patterns (specifically regarding trivial class initialization) - there is no better alternative?

Quoted 8 lines

Not really, no. It looks bad now because you have DeviceInfo still. Once DeviceInfo goes away, all of the initialization will happen in the class_init function.

The design of QOM is such that a lot of what was previously done via declarative structures is now done imperatively. But the code bloat that came in this patch series will decrease significantly with the next series as we eliminate DeviceInfo.

Are there examples of fully converted devices to get an impression?

Jan

#49 lore raw

Re: [Qemu-devel] [PATCH 27/28] sysbus: apic: ioapic: convert to QEMU Object Model

Quoted 9 lines · Jan Kiszka
Quoted 8 lines · Anthony Liguori
Quoted 3 lines

Also, I see a lot of programmatic initialization and a lot of repeating patterns (specifically regarding trivial class initialization) - there is no better alternative?

Not really, no. It looks bad now because you have DeviceInfo still. Once DeviceInfo goes away, all of the initialization will happen in the class_init function.

Quoted 6 lines
Quoted 4 lines

The design of QOM is such that a lot of what was previously done via declarative structures is now done imperatively. But the code bloat that came in this patch series will decrease significantly with the next series as we eliminate DeviceInfo.

Are there examples of fully converted devices to get an impression?

https://github.com/aliguori/qemu/tree/qom-rebase.8

Has everything fully converted (including BusState).

If you look at qdev.[ch], you'll notice the remaining qdev infrastructure becomes greatly simplified.

Regards,

Anthony Liguori

Quoted 3 lines

Jan

#50 lore raw

Re: [Qemu-devel] [PATCH 27/28] sysbus: apic: ioapic: convert to QEMU Object Model

Quoted 15 lines · Anthony Liguori
Quoted 14 lines · Jan Kiszka
Quoted 12 lines · Anthony Liguori
Quoted 3 lines

Also, I see a lot of programmatic initialization and a lot of repeating patterns (specifically regarding trivial class initialization) - there is no better alternative?

Not really, no. It looks bad now because you have DeviceInfo still. Once DeviceInfo goes away, all of the initialization will happen in the class_init function.

The design of QOM is such that a lot of what was previously done via declarative structures is now done imperatively. But the code bloat that came in this patch series will decrease significantly with the next series as we eliminate DeviceInfo.

Quoted 8 lines
Quoted 1 line

Are there examples of fully converted devices to get an impression?

https://github.com/aliguori/qemu/tree/qom-rebase.8

Has everything fully converted (including BusState).

If you look at qdev.[ch], you'll notice the remaining qdev infrastructure becomes greatly simplified.

But I don't get yet why all these repeating initialization tasks need to be open-coded instead of remaining declarative.

Why can't a generic class init handler of TYPE_DEVICE not copy over all relevant fields from a, say, DeviceTypeInfo super-struct? And a sysbus class init handler could do the same from SysBusTypeInfo. That way you could define your device class again in a single struct instead of multiple ones + the init handler. If there are special needs, that handler would still be there.

Jan

#51 lore raw

Re: [Qemu-devel] [PATCH 27/28] sysbus: apic: ioapic: convert to QEMU Object Model

Quoted 20 lines · Jan Kiszka
Quoted 19 lines · Anthony Liguori
Quoted 9 lines · Jan Kiszka
Quoted 8 lines · Anthony Liguori
Quoted 3 lines

Also, I see a lot of programmatic initialization and a lot of repeating patterns (specifically regarding trivial class initialization) - there is no better alternative?

Not really, no. It looks bad now because you have DeviceInfo still. Once DeviceInfo goes away, all of the initialization will happen in the class_init function.

Quoted 6 lines
Quoted 4 lines

The design of QOM is such that a lot of what was previously done via declarative structures is now done imperatively. But the code bloat that came in this patch series will decrease significantly with the next series as we eliminate DeviceInfo.

Are there examples of fully converted devices to get an impression?

https://github.com/aliguori/qemu/tree/qom-rebase.8

Quoted 7 lines
Quoted 4 lines

Has everything fully converted (including BusState).

If you look at qdev.[ch], you'll notice the remaining qdev infrastructure becomes greatly simplified.

But I don't get yet why all these repeating initialization tasks need to be open-coded instead of remaining declarative.

It would look like:

static void device_generic_class_init(ObjectClass *klass, void *data)

{
    DeviceClass *dc = DEVICE_CLASS(klass);
    DeviceTypeInfo *ti = data;

    if (ti->reset) {
       dc->reset = ti->reset;
    }
    if (ti->vmsd) {
       dc->vmsd = ti->vmsd;
    }
}

void device_type_register_static(DeviceTypeInfo *ti)

{
    TypeInfo ti = {
      .class_init = device_generic_class_init,
      .class_data = ti,
      // ...
    }
    type_register_static(&ti);
}

But I don't like this. The problem is that the declarative syntax we have doesn't distinguish between "not-specified" and "zero-initialized". It's also tempting to just drop the if (ti->reset) check but that means that you unconditionally override the base class implementation even if it's not specified.

I don't see any tangible benefits to a declarative syntax except that it makes it harder to get right because you have to write per-base class initialization functions and it's very easy to get polymorphism wrong there.

We're not talking about a code size difference. It's a wash in terms of number of lines of code.

Imperative allows you to explicit zero-initialize, accept the previous version (from the base class), or override with a new value.

Regards,

Anthony Liguori

Quoted 3 lines

Jan

#52 lore raw

Re: [Qemu-devel] [PATCH 27/28] sysbus: apic: ioapic: convert to QEMU Object Model

Quoted 58 lines · Anthony Liguori
Quoted 24 lines · Jan Kiszka
Quoted 23 lines · Anthony Liguori
Quoted 12 lines · Jan Kiszka
Quoted 11 lines · Anthony Liguori
Quoted 5 lines

Also, I see a lot of programmatic initialization and a lot of repeating
patterns (specifically regarding trivial class initialization) - there
is no better alternative?

Not really, no. It looks bad now because you have DeviceInfo still. Once DeviceInfo goes away, all of the initialization will happen in the
class_init function.

Quoted 7 lines
Quoted 5 lines

The design of QOM is such that a lot of what was previously done via declarative structures is now done imperatively. But the code bloat that came in this patch series will decrease significantly with the next
series as we eliminate DeviceInfo.

Are there examples of fully converted devices to get an impression?

https://github.com/aliguori/qemu/tree/qom-rebase.8

Quoted 7 lines
Quoted 4 lines

Has everything fully converted (including BusState).

If you look at qdev.[ch], you'll notice the remaining qdev infrastructure becomes greatly simplified.

But I don't get yet why all these repeating initialization tasks need to be open-coded instead of remaining declarative.

It would look like:

static void device_generic_class_init(ObjectClass *klass, void *data)

{
    DeviceClass *dc = DEVICE_CLASS(klass);
    DeviceTypeInfo *ti = data;

    if (ti->reset) {
       dc->reset = ti->reset;
    }
    if (ti->vmsd) {
       dc->vmsd = ti->vmsd;
    }
}

void device_type_register_static(DeviceTypeInfo *ti)

{
    TypeInfo ti = {
      .class_init = device_generic_class_init,
      .class_data = ti,
      // ...
    }
    type_register_static(&ti);
}
Quoted 3 lines

But I don't like this. The problem is that the declarative syntax we have doesn't distinguish between "not-specified" and "zero-initialized".

That's surely solvable.

Quoted 3 lines

It's also tempting to just drop the if (ti->reset)
check but that means that you unconditionally override the base class implementation even if it's not specified.

That as well, just wrap this repeating pattern in a macro.

Quoted 5 lines

I don't see any tangible benefits to a declarative syntax except that it makes it harder to get right because you have to write per-base class initialization functions and it's very easy to get polymorphism wrong there.

Now you have to write way more derived class init functions - provided a base class is used more than once.

Quoted 3 lines

We're not talking about a code size difference. It's a wash in terms of number of lines of code.

We are. Code size will be smaller, so the number of lines. How much, that depends on the number of users per base class.

Quoted 3 lines

Imperative allows you to explicit zero-initialize, accept the previous version (from the base class), or override with a new value.

None of this is impossible with a declarative approach.

Jan

#53 lore raw

Re: [Qemu-devel] [PATCH 27/28] sysbus: apic: ioapic: convert to QEMU Object Model

Quoted 6 lines · Jan Kiszka
Quoted 3 lines · Anthony Liguori

But I don't like this. The problem is that the declarative syntax we have doesn't distinguish between "not-specified" and "zero-initialized".

That's surely solvable.

Please try :-)

I've spent a good chunk of time mulling this over and could not find an acceptable solution. I think the same is true for the GObject folks.

There is a declarative solution for this that I know of, a C++ class definition ;-)

Quoted 5 lines
Quoted 3 lines

It's also tempting to just drop the if (ti->reset)
check but that means that you unconditionally override the base class implementation even if it's not specified.

That as well, just wrap this repeating pattern in a macro.

I'm fairly certain that would be hideous.

Quoted 7 lines
Quoted 4 lines

I don't see any tangible benefits to a declarative syntax except that it makes it harder to get right because you have to write per-base class initialization functions and it's very easy to get polymorphism wrong there.

Now you have to write way more derived class init functions - provided a base class is used more than once.

I don't understand why that's a problem.

Quoted 5 lines
Quoted 2 lines

We're not talking about a code size difference. It's a wash in terms of number of lines of code.

We are. Code size will be smaller, so the number of lines. How much, that depends on the number of users per base class.

Compare:

static void my_device_class_init(ObjectClass *klass, void *data) {
DeviceClass *dc = DEVICE_CLASS(klass);
dc->reset = my_device_reset;
}

static TypeInfo my_device_type_info = {
.name = TYPE_MY_DEVICE,
.parent = TYPE_DEVICE,
.class_init = my_device_class_init,
};

static void register_devices(void)
{
type_register_static(&my_device_type_info);
}

To:

static DeviceTypeInfo my_device_ops = {
.reset = my_device_reset,
};

static TypeInfo my_device_type_info = {
.name = TYPE_MY_DEVICE,
.parent = TYPE_DEVICE,
.class_init = device_generic_init,
.class_data = my_device_ops,
};

static void register_devices(void)
{
type_register_static(&my_device_type_info);
}

They're exactly the same size (16 lines). If you embed TypeInfo into DeviceTypeInfo, and introduce a Device specific type registration function, then you could do:

static DeviceTypeInfo my_device_type_info = {
.type.name = TYPE_MY_DEVICE,
.type.parent = TYPE_PARENT_DEVICE,
.reset = my_device_reset,
};

static void register_devices(void)

{
    device_type_register_static(&my_device_type_info);
}

Which admittedly saves 6 lines, but also is a big step backwards IMHO. Now you've got a lot of one-off functions which means you loose the advantage of having everything work through the same infrastructure. The likelihood that someone is going to do something whacky in device_type_register_static is high IMHO. I think parent initialization (.type.name) is ugly.

Plus, if you do need a class_init function (if you want to save off the super class value for some function), then you need to revert back to style (1) anyway.

It'll never get better than this. The 6 line difference is fixed and is mostly whitespace/curly brackets.

Quoted 5 lines
Quoted 3 lines

Imperative allows you to explicit zero-initialize, accept the previous version (from the base class), or override with a new value.

None of this is impossible with a declarative approach.

The class_data method would allow for class initialization based on a declarative description so it will always be possible to add at some point if someone figures out the ultimate clever way to do it.

Regards,

Anthony Liguori

Quoted 3 lines

Jan

#54 lore raw

Re: [Qemu-devel] [PATCH 27/28] sysbus: apic: ioapic: convert to QEMU Object Model

Am 25.01.2012 00:03, schrieb Anthony Liguori:

Quoted 8 lines · Jan Kiszka
Quoted 6 lines · Anthony Liguori
Quoted 3 lines

But I don't like this. The problem is that the declarative syntax we have doesn't distinguish between "not-specified" and "zero-initialized".

That's surely solvable.

Quoted 7 lines

Please try :-)

I've spent a good chunk of time mulling this over and could not find an acceptable solution. I think the same is true for the GObject folks.

There is a declarative solution for this that I know of, a C++ class definition ;-)

So what's the reason not to go with one of the object-oriented, C-compatible languages GCC supports, like C++ or Objective-C/C++? (Objective-C has native reflection capabilities fwiw.)

Personally I disliked those trivial mini init functions in the initial 2/4 series, too, but I don't really mind an imperative approach either.

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#55 lore raw

Re: [Qemu-devel] [PATCH 27/28] sysbus: apic: ioapic: convert to QEMU Object Model

Quoted 7 lines · Andreas Färber
Quoted 3 lines

There is a declarative solution for this that I know of, a C++ class definition ;-)

So what's the reason not to go with one of the object-oriented, C-compatible languages GCC supports, like C++ or Objective-C/C++? (Objective-C has native reflection capabilities fwiw.)

I believe everyone except Anthony and myself is against it. But now we are three.

Signature · 1 line
error compiling committee.c: too many arguments to function
#56 lore raw

Re: [Qemu-devel] [PATCH 27/28] sysbus: apic: ioapic: convert to QEMU Object Model

In reply to Andreas Färber
Quoted 6 lines
Quoted 2 lines

There is a declarative solution for this that I know of, a C++ class definition ;-)

So what's the reason not to go with one of the object-oriented, C-compatible languages GCC supports, like C++ or Objective-C/C++? (Objective-C has native reflection capabilities fwiw.)

I'd avoid Objective-C as it has very little use (and thus real support/testing) outside of Apple. Even more so for Objective-C++.

I've no objection in principle to C++, though it does raise various practical issues. I'm suspicious of a plan that only converts some of the codebase to C++.

Paul

#57 lore raw

Re: [Qemu-devel] [PATCH 27/28] sysbus: apic: ioapic: convert to QEMU Object Model

In reply to Andreas Färber
Quoted 14 lines · Andreas Färber

Am 25.01.2012 00:03, schrieb Anthony Liguori:

Quoted 13 lines · Jan Kiszka
Quoted 6 lines · Anthony Liguori
Quoted 3 lines

But I don't like this. The problem is that the declarative syntax we have doesn't distinguish between "not-specified" and "zero-initialized".

That's surely solvable.

Please try :-)

I've spent a good chunk of time mulling this over and could not find an acceptable solution. I think the same is true for the GObject folks.

Quoted 6 lines
Quoted 2 lines

There is a declarative solution for this that I know of, a C++ class definition ;-)

So what's the reason not to go with one of the object-oriented, C-compatible languages GCC supports, like C++ or Objective-C/C++? (Objective-C has native reflection capabilities fwiw.)

I actually prefer C++ but much in the same fashion that I prefer 8-space indenting.

I think it's objectively better, but not significantly better enough to warrant the disruption of introducing it.

C++ makes polymorphism easier and declaring classes a little nicer, but it doesn't help significantly with factories, properties, or introspection.

Polymorphism in C is mostly a one-time cost so once you have the infrastructure (object.c), it's not really that bad.

Regards,

Anthony Liguori

Quoted 5 lines

Personally I disliked those trivial mini init functions in the initial 2/4 series, too, but I don't really mind an imperative approach either.

Andreas

#58 lore raw

Re: [Qemu-devel] [PATCH 27/28] sysbus: apic: ioapic: convert to QEMU Object Model

In reply to Anthony Liguori
Quoted 8 lines · Anthony Liguori

They're exactly the same size (16 lines). If you embed TypeInfo into DeviceTypeInfo, and introduce a Device specific type registration function, then you could do:

static DeviceTypeInfo my_device_type_info = {
.type.name = TYPE_MY_DEVICE,
.type.parent = TYPE_PARENT_DEVICE,
.reset = my_device_reset,

And if you introduce some

#define TYPE_UNIMPLEMENTED (void *)&dummy_variable

you can easily express

[.field = NULL] => use parent
.field = UNIMPLEMENTED => don't run any handler

Quoted 10 lines

};

static void register_devices(void)

{
    device_type_register_static(&my_device_type_info);
}

Which admittedly saves 6 lines, but also is a big step backwards IMHO. Now you've got a lot of one-off functions which means you loose the advantage of having everything work through the same infrastructure.

Can't follow. Four lines

[static inline] void device_type_register_static(DeviceTypeInfo *dt)

{
    type_register_static(&dt->type);
}

are neither ugly nor complex. Rather, this helps concentrating effort at _central_ places instead of decentralizing and duplicating lines like in your imperative approach. That's the whole point: keep the common case (derived classes) compact.

Jan

#59 lore raw

Re: [Qemu-devel] [PATCH 27/28] sysbus: apic: ioapic: convert to QEMU Object Model

Quoted 8 lines · Jan Kiszka
Quoted 8 lines
Quoted 8 lines

They're exactly the same size (16 lines). If you embed TypeInfo into DeviceTypeInfo, and introduce a Device specific type registration function, then you could do:

static DeviceTypeInfo my_device_type_info = {
.type.name = TYPE_MY_DEVICE,
.type.parent = TYPE_PARENT_DEVICE,
.reset = my_device_reset,

Quoted 9 lines

And if you introduce some

#define TYPE_UNIMPLEMENTED (void *)&dummy_variable

you can easily express

[.field = NULL] => use parent
.field = UNIMPLEMENTED => don't run any handler

I agree with Anthony, this would get really ugly where you are calling the functions and doing the class initialization. It's a different style from what we're used to, granted, but the difference in code size is not relevant (not enough to introduce a level of macro magic, at least) and the diffstat in this series is misleading because qdev is left with temporary duplication for now.

(I also complained with him about this a month ago or so).

Paolo

#60 lore raw

Re: [Qemu-devel] [PATCH 27/28] sysbus: apic: ioapic: convert to QEMU Object Model

Quoted 13 lines · Paolo Bonzini
Quoted 12 lines · Jan Kiszka
Quoted 8 lines
Quoted 8 lines

They're exactly the same size (16 lines). If you embed TypeInfo into DeviceTypeInfo, and introduce a Device specific type registration function, then you could do:

static DeviceTypeInfo my_device_type_info = {
.type.name = TYPE_MY_DEVICE,
.type.parent = TYPE_PARENT_DEVICE,
.reset = my_device_reset,

And if you introduce some

#define TYPE_UNIMPLEMENTED (void *)&dummy_variable

Quoted 8 lines
Quoted 5 lines

you can easily express

[.field = NULL] => use parent
.field = UNIMPLEMENTED => don't run any handler

I agree with Anthony, this would get really ugly where you are calling the functions and doing the class initialization.

I think we need to try it first.

There is a lot of repetition, and that gets boring at beat and ugly at worst when doing it for hundreds of devices - compared to the number of base classes we will have.

Quoted 5 lines

It's a different
style from what we're used to, granted, but the difference in code size is not relevant (not enough to introduce a level of macro magic, at least) and the diffstat in this series is misleading because qdev is left with temporary duplication for now.

I was looking at the final version Anthony pointed at.

Jan

#61 lore raw

Re: [Qemu-devel] [PATCH 27/28] sysbus: apic: ioapic: convert to QEMU Object Model

Quoted 8 lines · Jan Kiszka
Quoted 2 lines

I agree with Anthony, this would get really ugly where you are calling the functions and doing the class initialization.

I think we need to try it first.

There is a lot of repetition, and that gets boring at beat and ugly at worst when doing it for hundreds of devices - compared to the number of base classes we will have.

I think we have to trust Anthony's judgement that he tried it and didn't like it. Perhaps he didn't try _exactly_ the version that you gave, but I think it's not fair to say "please try redoing it this way---maybe" a month after the first version has been posted.

So far, we were always able to reach a compromise between Anthony's taste and others', and also on the order with which to do things. I understand this is a pretty major issue, but it's going to be one more such compromise (and one that I thought had already been settled).

Note that it's not impossible to change directions! QOM started with the idea of converting devices _last_. We are converting them _first_.
That was a very early change in plans, and very much against Anthony.
It's fair and natural that the balance swings in the other direction
now. As a reviewer, the later you join the party, the harder it will be to swallow the pill.

Quoted 7 lines
Quoted 5 lines

It's a different
style from what we're used to, granted, but the difference in code size is not relevant (not enough to introduce a level of macro magic, at least) and the diffstat in this series is misleading because qdev is left with temporary duplication for now.

I was looking at the final version Anthony pointed at.

There _are_ things that leave something to be desired in there. For example I don't like accessing the base class with a different name, as in:

    DeviceClass *dc = DEVICE_CLASS(klass);
    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);

    dc->props = e100_properties;
    dc->desc = info->desc;
    k->vendor_id = PCI_VENDOR_ID_INTEL;
    k->class_id = PCI_CLASS_NETWORK_ETHERNET;
    k->romfile = "pxe-eepro100.rom";
    ...

and a few more things that we'll discuss as soon as he posts the third instalment. I know we're all busy, but the only way to solve these problems is prompt review.

Paolo

#62 lore raw

Re: [Qemu-devel] [PATCH 27/28] sysbus: apic: ioapic: convert to QEMU Object Model

In reply to Jan Kiszka
Quoted 5 lines · Jan Kiszka
Quoted 4 lines · Anthony Liguori

They're exactly the same size (16 lines). If you embed TypeInfo into DeviceTypeInfo, and introduce a Device specific type registration function, then you could do:

Quoted 8 lines
Quoted 4 lines

static DeviceTypeInfo my_device_type_info = {
.type.name = TYPE_MY_DEVICE,
.type.parent = TYPE_PARENT_DEVICE,
.reset = my_device_reset,

And if you introduce some

#define TYPE_UNIMPLEMENTED (void *)&dummy_variable

(void *) isn't compatible with integers or function pointers (at least not in a portable way).

You would need to use type specific unimplemented mechanisms.

Quoted 20 lines

you can easily express

[.field = NULL] => use parent
.field = UNIMPLEMENTED => don't run any handler

Quoted 10 lines

};

static void register_devices(void)

{
     device_type_register_static(&my_device_type_info);
}

Which admittedly saves 6 lines, but also is a big step backwards IMHO. Now you've got a lot of one-off functions which means you loose the advantage of having everything work through the same infrastructure.

Can't follow. Four lines

[static inline] void device_type_register_static(DeviceTypeInfo *dt)

Quoted 8 lines
{
     type_register_static(&dt->type);
}

are neither ugly nor complex. Rather, this helps concentrating effort at _central_ places instead of decentralizing and duplicating lines like in your imperative approach. That's the whole point: keep the common case (derived classes) compact.

Send a patch. The infrastructure available should be enough to do whatever you need to.

I'm not being dismissive, I've already spent a lot of time trying to make it work and have convinced myself that it isn't workable.

If you can show a mechanism that works, I don't mind scripting a mass conversion. I'm also fairly confident that a workable solution is going to be better than what we have.

Regards,

Anthony Liguori

Quoted 3 lines

Jan

#63 lore raw

Re: [Qemu-devel] [PATCH 27/28] sysbus: apic: ioapic: convert to QEMU Object Model

Quoted 11 lines · Anthony Liguori
Quoted 10 lines · Jan Kiszka
Quoted 8 lines · Anthony Liguori

They're exactly the same size (16 lines). If you embed TypeInfo into DeviceTypeInfo, and introduce a Device specific type registration function, then you could do:

static DeviceTypeInfo my_device_type_info = {
.type.name = TYPE_MY_DEVICE,
.type.parent = TYPE_PARENT_DEVICE,
.reset = my_device_reset,

Quoted 6 lines
Quoted 3 lines

And if you introduce some

#define TYPE_UNIMPLEMENTED (void *)&dummy_variable

(void *) isn't compatible with integers or function pointers (at least not in a portable way).

The former is true, the latter not. However, if you use pointers in the TypeInfo structs consistently (const int * etc.), this issue should be solvable as well.

Quoted 35 lines

You would need to use type specific unimplemented mechanisms.

Quoted 20 lines

you can easily express

[.field = NULL] => use parent
.field = UNIMPLEMENTED => don't run any handler

Quoted 10 lines

};

static void register_devices(void)

{
     device_type_register_static(&my_device_type_info);
}

Which admittedly saves 6 lines, but also is a big step backwards IMHO. Now you've got a lot of one-off functions which means you loose the advantage of having everything work through the same infrastructure.

Can't follow. Four lines

[static inline] void device_type_register_static(DeviceTypeInfo *dt)

Quoted 8 lines
{
     type_register_static(&dt->type);
}

are neither ugly nor complex. Rather, this helps concentrating effort at _central_ places instead of decentralizing and duplicating lines like in your imperative approach. That's the whole point: keep the common case (derived classes) compact.

Send a patch. The infrastructure available should be enough to do whatever you need to.

Quoted 6 lines

I'm not being dismissive, I've already spent a lot of time trying to make it work and have convinced myself that it isn't workable.

If you can show a mechanism that works, I don't mind scripting a mass conversion. I'm also fairly confident that a workable solution is going to be better than what we have.

Well, I'm surely not happy having to go through all of the devices again, even if scripted (scripts tend to neglect some coding style rules e.g.). But if this change is in a hurry and my concern is the only one, then let it be.

Jan

#64 lore raw

Re: [Qemu-devel] [PATCH 27/28] sysbus: apic: ioapic: convert to QEMU Object Model

Quoted 12 lines · Jan Kiszka
Quoted 11 lines · Anthony Liguori
Quoted 10 lines · Jan Kiszka
Quoted 8 lines · Anthony Liguori

They're exactly the same size (16 lines). If you embed TypeInfo into DeviceTypeInfo, and introduce a Device specific type registration function, then you could do:

static DeviceTypeInfo my_device_type_info = {
.type.name = TYPE_MY_DEVICE,
.type.parent = TYPE_PARENT_DEVICE,
.reset = my_device_reset,

Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

And if you introduce some

#define TYPE_UNIMPLEMENTED (void *)&dummy_variable

(void *) isn't compatible with integers or function pointers (at least not in a portable way).

I don't see how they can be compatible since on some platforms sizeof(void (*)(void)) != sizeof(void *).

Quoted 4 lines

The former is true, the latter not. However, if you use pointers in the TypeInfo structs consistently (const int * etc.), this issue should be solvable as well.

How would you handle PCIDeviceInfo?

Quoted 11 lines
Quoted 6 lines

I'm not being dismissive, I've already spent a lot of time trying to make it work and have convinced myself that it isn't workable.

If you can show a mechanism that works, I don't mind scripting a mass conversion. I'm also fairly confident that a workable solution is going to be better than what we have.

Well, I'm surely not happy having to go through all of the devices again, even if scripted (scripts tend to neglect some coding style rules e.g.). But if this change is in a hurry and my concern is the only one, then let it be.

I wouldn't be happy with it either, but in the absence of a concrete counter proposal and given that I've spent a fair amount of time trying to figure this out, I strongly believe we won't need to make the change.

I'm happy to be proven wrong though.

Regards,

Anthony Liguori

Quoted 3 lines

Jan

#65 lore raw

Re: [Qemu-devel] [PATCH 27/28] sysbus: apic: ioapic: convert to QEMU Object Model

Am 25.01.2012 15:40, schrieb Anthony Liguori:

Quoted 15 lines · Jan Kiszka
Quoted 14 lines · Anthony Liguori
Quoted 13 lines · Jan Kiszka
Quoted 12 lines · Anthony Liguori
Quoted 8 lines

They're exactly the same size (16 lines). If you embed TypeInfo into DeviceTypeInfo, and introduce a Device specific type registration function, then you could do:

static DeviceTypeInfo my_device_type_info = {
.type.name = TYPE_MY_DEVICE,
.type.parent = TYPE_PARENT_DEVICE,
.reset = my_device_reset,

And if you introduce some

Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

#define TYPE_UNIMPLEMENTED (void *)&dummy_variable

(void *) isn't compatible with integers or function pointers (at least not in a portable way).

I don't see how they can be compatible since on some platforms sizeof(void (*)(void)) != sizeof(void *).

Do you have an example of a platform relevant to QEMU? Microcontrollers and DOS come to my mind.

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#66 lore raw

Re: [Qemu-devel] [PATCH 27/28] sysbus: apic: ioapic: convert to QEMU Object Model

In reply to Anthony Liguori
Quoted 6 lines · Anthony Liguori
Quoted 3 lines
Quoted 3 lines

(void *) isn't compatible with integers or function pointers (at least not in a portable way).

I don't see how they can be compatible since on some platforms sizeof(void (*)(void)) != sizeof(void *).

C99 says they are not required to be the same, but POSIX adds an additional requirement on top of C that all function pointers must be convertible to void* and back without loss of data. Pretty much any system where qemu can compile is probably already complying with that particular POSIX extension to C, even if it is not portable in practice to a pure C environment.

Signature · 2 lines
Eric Blake   [email protected]    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#67 lore raw

PATCH v3 28/28 virtio-s390: convert to QEMU Object Model

In reply to Anthony Liguori
---
 hw/s390-virtio-bus.c |   93 +++++++++++++++++++++++++++++++++++---------------
 1 files changed, 65 insertions(+), 28 deletions(-)
hw/s390-virtio-bus.c +65 -28
index 8e34a78..565941a 100644
@@ -50,11 +50,19 @@ struct BusInfo s390_virtio_bus_info = {
     .size       = sizeof(VirtIOS390Bus),
 };
 
-typedef struct {
-    DeviceInfo qdev;
+typedef struct VirtIOS390DeviceClass
+{
+    DeviceClass parent_class;
     int (*init)(VirtIOS390Device *dev);
-} VirtIOS390DeviceInfo;
+} VirtIOS390DeviceClass;
 
+#define TYPE_VIRTIO_S390_DEVICE "virtio-s390-device"
+#define VIRTIO_S390_DEVICE(obj) \
+     OBJECT_CHECK(VirtIOS390Device, (obj), TYPE_VIRTIO_S390_DEVICE)
+#define VIRTIO_S390_DEVICE_CLASS(klass) \
+     OBJECT_CLASS_CHECK(VirtIOS390DeviceClass, (klass), TYPE_VIRTIO_S390_DEVICE)
+#define VIRTIO_S390_DEVICE_GET_CLASS(obj) \
+    OBJECT_GET_CLASS(VirtIOS390DeviceClass, (obj), TYPE_VIRTIO_S390_DEVICE)
 
 static const VirtIOBindings virtio_s390_bindings;
 
@@ -343,12 +351,19 @@ static const VirtIOBindings virtio_s390_bindings = {
     .get_features = virtio_s390_get_features,
 };
 
-static VirtIOS390DeviceInfo s390_virtio_net = {
-    .init = s390_virtio_net_init,
-    .qdev.name = "virtio-net-s390",
-    .qdev.alias = "virtio-net",
-    .qdev.size = sizeof(VirtIOS390Device),
-    .qdev.props = (Property[]) {
+static void s390_virtio_net_class_init(ObjectClass *klass, void *data)
+{
+    VirtIOS390DeviceClass *dc = VIRTIO_S390_DEVICE_CLASS(klass);
+
+    dc->init = s390_virtio_net_init;
+}
+
+static DeviceInfo s390_virtio_net = {
+    .name = "virtio-net-s390",
+    .alias = "virtio-net",
+    .size = sizeof(VirtIOS390Device),
+    .class_init = s390_virtio_net_class_init,
+    .props = (Property[]) {
         DEFINE_NIC_PROPERTIES(VirtIOS390Device, nic),
         DEFINE_PROP_UINT32("x-txtimer", VirtIOS390Device,
                            net.txtimer, TX_TIMER_INTERVAL),
@@ -359,24 +374,38 @@ static VirtIOS390DeviceInfo s390_virtio_net = {
     },
 };
 
-static VirtIOS390DeviceInfo s390_virtio_blk = {
-    .init = s390_virtio_blk_init,
-    .qdev.name = "virtio-blk-s390",
-    .qdev.alias = "virtio-blk",
-    .qdev.size = sizeof(VirtIOS390Device),
-    .qdev.props = (Property[]) {
+static void s390_virtio_blk_class_init(ObjectClass *klass, void *data)
+{
+    VirtIOS390DeviceClass *dc = VIRTIO_S390_DEVICE_CLASS(klass);
+
+    dc->init = s390_virtio_blk_init;
+}
+
+static DeviceInfo s390_virtio_blk = {
+    .name = "virtio-blk-s390",
+    .alias = "virtio-blk",
+    .size = sizeof(VirtIOS390Device),
+    .class_init = s390_virtio_blk_class_init,
+    .props = (Property[]) {
         DEFINE_BLOCK_PROPERTIES(VirtIOS390Device, block),
         DEFINE_PROP_STRING("serial", VirtIOS390Device, block_serial),
         DEFINE_PROP_END_OF_LIST(),
     },
 };
 
-static VirtIOS390DeviceInfo s390_virtio_serial = {
-    .init = s390_virtio_serial_init,
-    .qdev.name = "virtio-serial-s390",
-    .qdev.alias = "virtio-serial",
-    .qdev.size = sizeof(VirtIOS390Device),
-    .qdev.props = (Property[]) {
+static void s390_virtio_serial_class_init(ObjectClass *klass, void *data)
+{
+    VirtIOS390DeviceClass *dc = VIRTIO_S390_DEVICE_CLASS(klass);
+
+    dc->init = s390_virtio_serial_init;
+}
+
+static DeviceInfo s390_virtio_serial = {
+    .name = "virtio-serial-s390",
+    .alias = "virtio-serial",
+    .size = sizeof(VirtIOS390Device),
+    .class_init = s390_virtio_serial_class_init,
+    .props = (Property[]) {
         DEFINE_PROP_UINT32("max_ports", VirtIOS390Device,
                            serial.max_virtserial_ports, 31),
         DEFINE_PROP_END_OF_LIST(),
@@ -385,24 +414,32 @@ static VirtIOS390DeviceInfo s390_virtio_serial = {
 
 static int s390_virtio_busdev_init(DeviceState *dev, DeviceInfo *info)
 {
-    VirtIOS390DeviceInfo *_info = (VirtIOS390DeviceInfo *)info;
     VirtIOS390Device *_dev = (VirtIOS390Device *)dev;
+    VirtIOS390DeviceClass *_info = VIRTIO_S390_DEVICE_GET_CLASS(dev);
 
     return _info->init(_dev);
 }
 
-static void s390_virtio_bus_register_withprop(VirtIOS390DeviceInfo *info)
+static void s390_virtio_bus_register_withprop(DeviceInfo *info)
 {
-    info->qdev.init = s390_virtio_busdev_init;
-    info->qdev.bus_info = &s390_virtio_bus_info;
-    info->qdev.unplug = qdev_simple_unplug_cb;
+    info->init = s390_virtio_busdev_init;
+    info->bus_info = &s390_virtio_bus_info;
+    info->unplug = qdev_simple_unplug_cb;
 
-    assert(info->qdev.size >= sizeof(VirtIOS390Device));
-    qdev_register(&info->qdev);
+    assert(info->size >= sizeof(VirtIOS390Device));
+    qdev_register_subclass(info, TYPE_VIRTIO_S390_DEVICE);
 }
 
+static TypeInfo virtio_s390_device_info = {
+    .name = TYPE_VIRTIO_S390_DEVICE,
+    .parent = TYPE_DEVICE,
+    .instance_size = sizeof(VirtIOS390Device),
+    .abstract = true,
+};
+
 static void s390_virtio_register(void)
 {
+    type_register_static(&virtio_s390_device_info);
     s390_virtio_bus_register_withprop(&s390_virtio_serial);
     s390_virtio_bus_register_withprop(&s390_virtio_blk);
     s390_virtio_bus_register_withprop(&s390_virtio_net);
Signature · 1 line
1.7.4.1
#68 lore raw
In reply to Anthony Liguori
Quoted 5 lines · Anthony Liguori

This series makes qdev a proper Object and converts qdev's type inheritance to QOM inheritance.

I've tested this series extensively for the pc target including bisectability. I have not tested any other targets yet so your mileage may vary.

I've tested the vexpress target (including serial, mouse, video, lan9118, sdcard),
seems to still work ok...

-- PMM

#69 lore raw
Quoted 10 lines · Peter Maydell
Quoted 5 lines · Anthony Liguori

This series makes qdev a proper Object and converts qdev's type inheritance to QOM inheritance.

I've tested this series extensively for the pc target including bisectability. I have not tested any other targets yet so your mileage may vary.

I've tested the vexpress target (including serial, mouse, video, lan9118, sdcard),
seems to still work ok...

Great, thanks! I was planning on running vexpress through qemu-test.

Regards,

Anthony Liguori

Quoted 3 lines

-- PMM

#70 lore raw
In reply to Anthony Liguori
Quoted 10 lines · Anthony Liguori

This series makes qdev a proper Object and converts qdev's type inheritance to QOM inheritance.

The first half of the series are manual cleanups/refactorings.  The second half is mostly scripted conversion, separated out into reviewable and bisectable chunks.

I've tested this series extensively for the pc target including bisectability. I have not tested any other targets yet so your mileage may vary.

Quoted 6 lines

Since the original RFC, I've fixed any of the not-for-upstream issues.  This also includes some uni-north patches that are in ppc-next.

Paolo and Andreas have asked that I declare a date when I'll merge this so that people can be prepared for the rebase fall out.  I will merge this on Friday unless there is a major problem found in review.

I get this with Sparc64:

$ qemu-system-sparc64
qemu-system-sparc64: PCI: slot 0 function 0 not available for pbm, in use by
qemu-system-sparc64: Initialization of device pbm failed

Maybe because device "pbm" exists for both as SysBusDevice and as PCIDevice. Text "in use by" is suspiciously clipped.

Sparc32, PPC32 and PPC64 seem to be OK.

Quoted 271 lines

This is also available at:

https://github.com/aliguori/qemu/tree/qom-upstream.10

For full context, the whole tree is located at:

https://github.com/aliguori/qemu/commits/qom-rebase.7

git diffstat origin/master HEAD
 Makefile                   |    2
 Makefile.hw                |    1
 Makefile.objs              |    3
 Makefile.target            |    2
 configure                  |    2
 hw/9pfs/virtio-9p-device.c |   44 ++--
 hw/a9mpcore.c              |   21 +
 hw/ac97.c                  |   39 ++-
 hw/acpi_piix4.c            |   59 +++--
 hw/ads7846.c               |   17 +
 hw/alpha_typhoon.c         |   17 +
 hw/apb_pci.c               |   71 ++++--
 hw/apic.c                  |   21 +
 hw/apic_common.c           |   88 +++++---
 hw/apic_internal.h         |   32 +-
 hw/applesmc.c              |   18 +
 hw/arm11mpcore.c           |   68 +++---
 hw/arm_l2x0.c              |   25 +-
 hw/arm_mptimer.c           |   23 +-
 hw/arm_sysctl.c            |   31 +-
 hw/arm_timer.c             |   46 +++-
 hw/armv7m.c                |   25 +-
 hw/armv7m_nvic.c           |   21 +
 hw/bitbang_i2c.c           |   17 +
 hw/bonito.c                |   47 ++--
 hw/ccid-card-emulated.c    |   27 +-
 hw/ccid-card-passthru.c    |   27 +-
 hw/ccid.h                  |   28 +-
 hw/cirrus_vga.c            |   50 ++--
 hw/container.c             |   17 +
 hw/cs4231.c                |   27 +-

 hw/cs4231a.c               |   20 +
 hw/debugcon.c              |   16 +
 hw/dec_pci.c               |   74 ++++--
 hw/ds1225y.c               |   29 +-

 hw/ds1338.c                |   31 +- hw/e1000.c                 |   45 ++-- hw/eccmemctl.c             |   29 +- hw/eepro100.c              |  202 +++++++++++------- hw/empty_slot.c            |   15 + hw/es1370.c                |   36 +-- hw/escc.c                  |   43 ++- hw/esp.c                   |   27 +-

 hw/etraxfs_eth.c           |   33 +--
 hw/etraxfs_pic.c           |   25 +-
 hw/etraxfs_ser.c           |   17 +

 hw/etraxfs_timer.c         |   16 +
 hw/fdc.c                   |   84 +++++--
 hw/fw_cfg.c                |   33 +--
 hw/g364fb.c                |   33 +--
 hw/grackle_pci.c           |   44 ++--
 hw/grlib_apbuart.c         |   25 +-
 hw/grlib_gptimer.c         |   31 +-
 hw/grlib_irqmp.c           |   29 +-
 hw/gt64xxx.c               |   39 ++-
 hw/gus.c                   |   20 +
 hw/hda-audio.c             |   60 +++--

 hw/hpet.c                  |   33 +--
 hw/i2c.c                   |  111 +++++++---
 hw/i2c.h                   |   52 ++--
 hw/i82374.c                |   19 +
 hw/i82378.c                |   31 +-
 hw/i8254.c                 |   22 +-
 hw/i8259.c                 |   15 +

 hw/i8259_common.c          |   45 ++--
 hw/i8259_internal.h        |   27 +-
 hw/ide/cmd646.c            |   41 ++-
 hw/ide/ich.c               |   37 +--
 hw/ide/internal.h          |   20 +

 hw/ide/isa.c               |   20 +
 hw/ide/piix.c              |   91 +++++---
 hw/ide/qdev.c              |  111 ++++++----
 hw/ide/via.c               |   27 +-

 hw/integratorcp.c          |   40 ++-
 hw/intel-hda.c             |   91 +++++---
 hw/intel-hda.h             |   26 +-
 hw/ioapic.c                |   17 +
 hw/ioapic_common.c         |   49 +++-
 hw/ioapic_internal.h       |   26 +-
 hw/ioh3420.c               |   59 +++--
 hw/isa-bus.c               |   57 +++--
 hw/isa.h                   |   23 +-
 hw/ivshmem.c               |   47 ++--
 hw/kvm/apic.c              |   19 +

 hw/kvm/clock.c             |   19 +
 hw/kvm/i8259.c             |   19 +
 hw/kvm/ioapic.c            |   23 +-

 hw/lan9118.c               |   31 +-
 hw/lance.c                 |   33 +--
 hw/lm32_juart.c            |   19 +
 hw/lm32_pic.c              |   19 +
 hw/lm32_sys.c              |   29 +-
 hw/lm32_timer.c            |   31 +-
 hw/lm32_uart.c             |   19 +
 hw/lm832x.c                |   33 +--
 hw/lsi53c895a.c            |   33 +--
 hw/m48t59.c                |   51 +++-
 hw/macio.c                 |   50 +++-
 hw/marvell_88w8618_audio.c |   35 +--
 hw/max111x.c               |   34 ++-
 hw/max7310.c               |   35 +--
 hw/mc146818rtc.c           |   22 +-
 hw/milkymist-ac97.c        |   19 +
 hw/milkymist-hpdmc.c       |   19 +
 hw/milkymist-memcard.c     |   19 +
 hw/milkymist-minimac2.c    |   37 ++-
 hw/milkymist-pfpu.c        |   19 +
 hw/milkymist-softusb.c     |   43 ++-
 hw/milkymist-sysctl.c      |   43 ++-
 hw/milkymist-tmu2.c        |   19 +
 hw/milkymist-uart.c        |   19 +
 hw/milkymist-vgafb.c       |   31 +-
 hw/mips_malta.c            |   19 +
 hw/mipsnet.c               |   33 +--
 hw/mpc8544_guts.c          |   15 +
 hw/mst_fpga.c              |   19 +
 hw/musicpal.c              |  153 ++++++++++----
 hw/nand.c                  |   33 +--
 hw/ne2000-isa.c            |   18 +
 hw/ne2000.c                |   37 ++-
 hw/omap_gpio.c             |   70 ++++--
 hw/omap_intc.c             |   62 +++--
 hw/onenand.c               |   35 ++-
 hw/opencores_eth.c         |   31 +-

 hw/openpic.c               |   30 --
 hw/openpic.h               |    2
 hw/parallel.c              |   16 +

 hw/pc.c                    |   20 +
 hw/pci.c                   |  140 +++++-------
 hw/pci.h                   |   80 +++----
 hw/pci_bridge.c            |    2
 hw/pcie.c                  |    2
 hw/pckbd.c                 |   18 +
 hw/pcnet-pci.c             |   39 ++-
 hw/pcnet.c                 |    2
 hw/piix4.c                 |   35 +--
 hw/piix_pci.c              |  126 +++++++----

 hw/pl011.c                 |   36 ++-
 hw/pl022.c                 |   15 +
 hw/pl031.c                 |   19 +
 hw/pl041.c                 |   34 +--
 hw/pl050.c                 |   34 ++-
 hw/pl061.c                 |   34 ++-
 hw/pl080.c                 |   38 ++-
 hw/pl110.c                 |   57 +++--
 hw/pl181.c                 |   23 +-
 hw/pl190.c                 |   21 +
 hw/ppc4xx_pci.c            |   38 ++-
 hw/ppc_newworld.c          |    2
 hw/ppce500_pci.c           |   38 ++-
 hw/ppce500_spin.c          |   15 +

 hw/prep_pci.c              |   52 ++--
 hw/pxa2xx.c                |   96 ++++++--
 hw/pxa2xx_dma.c            |   29 +-
 hw/pxa2xx_gpio.c           |   29 +-
 hw/pxa2xx_pic.c            |   19 +
 hw/pxa2xx_timer.c          |   66 +++---
 hw/qdev-properties.c       |   20 -

 hw/qdev.c                  |  123 ++++++++---
 hw/qdev.h                  |   40 +++
 hw/qxl.c                   |   66 +++---

 hw/realview.c              |   15 +
 hw/realview_gic.c          |   16 +
 hw/rtl8139.c               |   43 ++-
 hw/s390-virtio-bus.c       |  110 +++++++---
 hw/sb16.c                  |   20 +
 hw/sbi.c                   |   19 +
 hw/scsi-bus.c              |   95 ++++++--
 hw/scsi-disk.c             |  159 ++++++++------
 hw/scsi-generic.c          |   29 +-
 hw/scsi.h                  |   31 +-
 hw/serial.c                |   18 +
 hw/sga.c                   |   15 -
 hw/sh_pci.c                |   37 ++-
 hw/slavio_intctl.c         |   19 +
 hw/slavio_misc.c           |   34 ++-
 hw/slavio_timer.c          |   29 +-
 hw/smbus.c                 |   85 +++++--
 hw/smbus.h                 |   42 ++-
 hw/smbus_eeprom.c          |   27 +-

 hw/smc91c111.c             |   31 +-
 hw/spapr_llan.c            |   41 ++-
 hw/spapr_pci.c             |   31 ++
 hw/spapr_vio.c             |   72 ++++--
 hw/spapr_vio.h             |   35 ++-

 hw/spapr_vscsi.c           |   37 ++-
 hw/spapr_vty.c             |   37 ++-
 hw/sparc32_dma.c           |   31 +-
 hw/spitz.c                 |   94 +++++---
 hw/ssd0303.c               |   33 +--
 hw/ssd0323.c               |   17 +
 hw/ssi-sd.c                |   17 +
 hw/ssi.c                   |   23 +-
 hw/ssi.h                   |   18 +
 hw/stellaris.c             |   65 +++++-
 hw/stellaris_enet.c        |   27 +-
 hw/strongarm.c             |  124 +++++++----
 hw/sun4c_intctl.c          |   19 +
 hw/sun4m.c                 |   78 +++++--
 hw/sun4m_iommu.c           |   29 +-

 hw/sun4u.c                 |   71 ++++--
 hw/sysbus.c                |   40 ++-
 hw/sysbus.h                |   25 +-
 hw/tcx.c                   |   37 ++-
 hw/tmp105.c                |   37 ++-
 hw/tosa.c                  |   50 ++--
 hw/tusb6010.c              |   17 +
 hw/twl92230.c              |   35 +--
 hw/unin_pci.c              |  204 +++++++++++++-----
 hw/usb-audio.c             |   38 ++-
 hw/usb-bt.c                |   33 +--
 hw/usb-bus.c               |  190 +++++++++++++----
 hw/usb-ccid.c              |  114 +++++++---
 hw/usb-desc.c              |   22 +-
 hw/usb-ehci.c              |   63 +++--
 hw/usb-hid.c               |  108 +++++-----
 hw/usb-hub.c               |   35 +--
 hw/usb-msd.c               |   41 ++-
 hw/usb-net.c               |   43 ++-
 hw/usb-ohci.c              |   58 +++--

 hw/usb-serial.c            |   74 +++--- hw/usb-uhci.c              |  189 +++++++++++------ hw/usb-wacom.c             |   36 +-- hw/usb-xhci.c              |   37 ++- hw/usb.c                   |   24 -- hw/usb.h                   |   50 +++- hw/versatile_pci.c         |   53 +++- hw/versatilepb.c           |   19 + hw/vga-isa.c               |   18 + hw/vga-pci.c               |   27 +- hw/virtio-console.c        |   69 +++--- hw/virtio-net.c            |    2 hw/virtio-pci.c            |  210 +++++++++++-------- hw/virtio-serial-bus.c     |   68 +++--- hw/virtio-serial.h         |   81 ++++--- hw/vmmouse.c               |   22 +- hw/vmport.c                |   16 + hw/vmware_vga.c            |   34 +-- hw/vt82c686.c              |  120 ++++++----- hw/wdt_i6300esb.c          |   33 +-- hw/wdt_ib700.c             |   18 + hw/wm8750.c                |   37 ++- hw/xen_platform.c          |   34 +--

 hw/xilinx_axidma.c         |   27 +-
 hw/xilinx_axienet.c        |   35 ++-
 hw/xilinx_ethlite.c        |   31 +-

 hw/xilinx_intc.c           |   25 +-
 hw/xilinx_timer.c          |   27 +-
 hw/xilinx_uartlite.c       |   16 +
 hw/xio3130_downstream.c    |   59 +++--
 hw/xio3130_upstream.c      |   53 ++--
 hw/z2.c                    |   52 +++-
 hw/zaurus.c                |   27 +-
 include/qemu/object.h      |  436 ++++++++++++++++++++++++++++++++++++++++ qom/Makefile               |    1
 qom/object.c               |  485 +++++++++++++++++++++++++++++++++++++++++++++ usb-bsd.c                  |   29 +-
 usb-linux.c                |   37 +--
 usb-redir.c                |   33 +--

 259 files changed, 7764 insertions(+), 3755 deletions(-)