Skip to contentSkip to conversation

qom: dynamic properties and composition tree (v2)

PATCH Superseded Anthony Liguori 4 participants 74 messages Dec 12, 2011 – Dec 13, 2011 Kbuild

lore
Share & tools
lore
#0 lore raw

v3 cover qom: dynamic properties and composition tree (v2)

This is a follow up to my previous series to get us started in the QOM direction. A few things are different this time around. Most notably:

1) Devices no longer have names. Instead, path names are always used to identify devices.

2) In order to support (1), dynamic properties are now supported.

3) The concept of a "root device" has been introduced. The root device is roughly modelling the motherboard of a machine. This type is a container type and it's best to think of it as something like a PCB board I guess.

To try it out, here's an example session:

Launch:

anthony@titi:~/build/qemu$ x86_64-softmmu/qemu-system-x86_64 -hda ~/images/linux.img -snapshot -device virtio-balloon-pci,id=foo -qmp unix:/tmp/server.sock,server,nowait

Explore the object model:

anthony@titi:~/git/qemu/QMP$ ./qom-list /
peripheral/
i440fx/
anthony@titi:~/git/qemu/QMP$ ./qom-list /i440fx/
piix3/
anthony@titi:~/git/qemu/QMP$ ./qom-list /i440fx/piix3
rtc/
anthony@titi:~/git/qemu/QMP$ ./qom-list /i440fx/piix3/rtc
date
base_year
anthony@titi:~/git/qemu/QMP$ ./qom-get /i440fx/piix3/rtc.date
tm_sec: 33
tm_hour: 21
tm_mday: 30
tm_year: 111
tm_mon: 10
tm_min: 2
anthony@titi:~/git/qemu/QMP$ ./qom-get rtc.date
tm_sec: 38
tm_hour: 21
tm_mday: 30
tm_year: 111
tm_mon: 10
tm_min: 2
anthony@titi:~/git/qemu/QMP$ ./qom-list /peripheral
foo/
anthony@titi:~/git/qemu/QMP$ ./qom-list /peripheral/foo
event_idx
indirect_desc

Anthony Liguori (197):
qom: add a reference count to qdev objects
qom: add new dynamic property infrastructure based on Visitors (v2)
qom: register legacy properties as new style properties (v2)
qom: introduce root device
qdev: provide an interface to return canonical path from root (v2)
qdev: provide a path resolution (v2)
qom: add child properties (composition) (v2)
qom: add link properties (v2)
qapi: allow a 'gen' key to suppress code generation
qmp: add qom-list command
qom: qom_{get,set} monitor commands (v2)
qdev: add explicitly named devices to the root complex
dev: add an anonymous peripheral container
rtc: make piix3 set the rtc as a child (v2)
rtc: add a dynamic property for retrieving the date
qom: optimize qdev_get_canonical_path using a parent link
qmp: make qmp.py easier to use
qom: add test tools (v2)
bug fix spotted by paolo
qom: add vga node to the pc composition tree
qom: add string property type
qdev: add a qdev_get_type() function and expose as a 'type' property
pc: fill out most of the composition tree
i440fx: split out piix3 device
i440fx: rename piix_pci -> i440fx
qom: add qobject
rename qobject -> object
more renames
Start integration of qom w/qdev.
qdev: move qdev->info to class
qdev: don't access name through info
qdev: user a wrapper to access reset and promote reset to a class
method
a little better approach to this
qdev: add isa-device as a subclass of device
isa: more isa stuff
qom: make pcidevice part of the hierarchy
get rid of DO_UPCAST
ccid card and usb
virtio-serial-port
get rid of more DO_UPCAST
add class_init to deviceinfo
isa: move methods from isadeviceinfo to isadeviceclass kill off ISADeviceInfo
usb: don't access dev->info directly
usb: get rid of info pointer
usb: promote all of the methods for USBDevice to class methods
usb: use a factory instead of doing silly things for legacy
usb: kill USBDeviceInfo
usb-hid: simply class initialization a bit
accessors for scsideviceinfo
drop info link in SCSIDeviceInfo
move methods out of SCSIDeviceInfo into SCSIDeviceClass kill off SCSIDeviceInfo
get rid of CCIDCardInfo
rename i2c_slave -> I2CSlave
add I2CSlave to the type hierarchy
add SMBusDevice to the type hiearchy
fixup type registration
kill off SMBusDeviceInfo
add guards
killall I2CSlaveInfo
killall HDACodecDeviceInfo
make spapr a bit more patch monkey friendly
killall VIOsPAPRDeviceInfo
qxl: be more patch monkey friendly
make es1370 more script monkey friendly
remove arrays of PCIDeviceInfo
Patch monkey PCIDeviceInfo conversion
patch monkey, that funky monkey
fixup for patch monkey
Mr. Patch Monkey at it again
Get rid of PCIDeviceInfo
More cleanups from PCIDeviceInfo removal
Make sysbus a QOM type
Remove SysBusDeviceInfo
fixup some pci issues
fixup some ehci issues
fixup rtl8139
fixups for patch monkey
Here comes the monkey...
little fix
pm fix
patch monkey
pm fixups
patch monkey
little fix
little fix
prep virtio-9p for the monkey
stoopid monkey
Get rid of VirtIOSerialPortInfo
patch monkey
virtio-console is doing something bad
small fix to virtioserialportinfo removal
killall SSIDeviceInfo
patch monkey
fixup unin_pci.c
fixup some network devices
fixup patch monkey problem with I2CSlave
fixup killall ssislaveinfo
bump version to enable Werror
prep_pci is busted
macio is busted
fix mips malta after piix4 pm refactoring
networking fix
hack to fix marvell audio
fixup patch monkey bug
networking fix
fixup patch monkey problem
fixup networking
fixup patch monkey problem
ppc4xx_pci is busted
openpic is busted
fixup of spapr
remove evil hack
networking fixup
1
2
Separate out legacy usb registration
fixup usb_qdev_register
convert sysbus_register_withprop
convert spapr
scsi
pci_qdev_register
isadevice conversion
hda-codec
i2c_register_slave
checkpoint the pm
Update patch monkey
pm
pm
qdev: make DeviceInfo private
qdev: remove info from class
drop IDEDeviceInfo
allow classes to overload qdev functions
killall isa_qdev_register
killall hda_codec_register
killall pci_qdev_register
add object_class_by_name
Refactor device creation
make device_info_list private
killall scsi_qdev_register
killall spapr_vio_bus_register_withprop
killall sysbus_register_withprop
killall usb_qdev_register
killall ccid_card_qdev_register & virtio_serial_port_qdev_register killall ide_qdev_register
killall i2c_register_slave_subclass
killall qdev_register
fix info qdm
kill off device list
add pm2 script
convert SSISlave to QOM
add type_register_static_alias
fixup pm2
add proper impl of alias
first round of QOM conversions
cleanup
killall smbus_register_device
round2
round3
make more pm friendly
round4
round5
round7
get rid of DeviceInfo
convert ide
remove dead call
usb-linux
9pfs
qdev: move property creation to instance_init
qdev: refactor properties
pci: use base class to add properties
move scsi device properties
i2c properties
hda_codec_device
spapr_vio_device
usb_device
ccid-card
virtio-serial-port
ide-device
split out setting parent_bus
make parent_bus optional
qdev: split out monitor functionality
qdev: move all of the remaining monitor bits to qdev-monitor.c split out serial.h
serial through composition
add uart as a child
isa-serial: split out
split out mm-serial
fix isa-serial bug
add copyrights and clean some things up
more serial cleanup
more cleanups
more cleanups
more cleanups
more cleanups
more cleanup

 Makefile.objs              |   10 +-
 Makefile.target            |    3 +-
 QMP/qmp.py                 |    6 +
 QMP/qom-get                |   26 +
 QMP/qom-list               |   30 ++
 QMP/qom-set                |   21 +
 VERSION                    |    2 +-
 hw/9pfs/virtio-9p-device.c |   46 ++-
 hw/a9mpcore.c              |   29 +-
 hw/ac97.c                  |   43 ++-
 hw/acpi_piix4.c            |   70 ++--
 hw/ads7846.c               |   20 +-
 hw/alpha_dp264.c           |    7 +-
 hw/alpha_typhoon.c         |   21 +-
 hw/apb_pci.c               |   82 +++--
 hw/apic.c                  |   37 +-
 hw/applesmc.c              |   34 +-
 hw/arm11mpcore.c           |   58 ++-
 hw/arm_sysctl.c            |   35 +-
 hw/arm_timer.c             |   32 ++-
 hw/armv7m.c                |   29 +-
 hw/armv7m_nvic.c           |   16 +-
 hw/bitbang_i2c.c           |   21 +-
 hw/bonito.c                |   55 ++-
 hw/ccid-card-emulated.c    |   48 ++-
 hw/ccid-card-passthru.c    |   41 +-
 hw/ccid.h                  |   27 +-
 hw/cirrus_vga.c            |   45 ++-
 hw/container.c             |   29 ++
 hw/cs4231.c                |   31 +-
 hw/cs4231a.c               |   36 +-
 hw/debugcon.c              |   32 +-
 hw/dec_pci.c               |   82 +++-
 hw/ds1225y.c               |   33 +-
 hw/ds1338.c                |   34 +-
 hw/e1000.c                 |   49 ++-
 hw/eccmemctl.c             |   33 +-
 hw/eepro100.c              |    6 +-
 hw/empty_slot.c            |   18 +-
 hw/es1370.c                |   40 +-
 hw/escc.c                  |   51 ++-
 hw/esp.c                   |   31 +-
 hw/etraxfs_eth.c           |   37 +-
 hw/etraxfs_pic.c           |   29 +-
 hw/etraxfs_ser.c           |   21 +-
 hw/etraxfs_timer.c         |   17 +-
 hw/fdc.c                   |  110 +++--
 hw/fw_cfg.c                |   37 +-
 hw/g364fb.c                |   37 +-
 hw/grackle_pci.c           |   45 ++-
 hw/grlib_apbuart.c         |   29 +-
 hw/grlib_gptimer.c         |   35 +-
 hw/grlib_irqmp.c           |   33 +-
 hw/gt64xxx.c               |   43 ++-
 hw/gus.c                   |   38 +-
 hw/hda-audio.c             |   64 ++-
 hw/hpet.c                  |   37 +-
 hw/hw.h                    |    4 +-
 hw/i2c.c                   |  131 ++++--
 hw/i2c.h                   |   47 +-
 hw/i440fx.c                |  395 ++++++++++++++++
 hw/i8254.c                 |   36 +-
 hw/i8259.c                 |   40 +-
 hw/ide/cmd646.c            |   43 +-
 hw/ide/ich.c               |   40 +-
 hw/ide/internal.h          |   20 +-
 hw/ide/isa.c               |   36 +-
 hw/ide/pci.c               |   11 +-
 hw/ide/piix.c              |  101 +++--
 hw/ide/qdev.c              |  153 ++++---
 hw/ide/via.c               |   31 +-
 hw/integratorcp.c          |   45 ++-
 hw/intel-hda.c             |  124 ++++--
 hw/intel-hda.h             |   25 +-
 hw/ioapic.c                |   25 +-
 hw/ioh3420.c               |   63 ++--
 hw/isa-bus.c               |   63 ++-
 hw/isa-serial.c            |  157 +++++++
 hw/isa-serial.h            |   82 ++++
 hw/isa.h                   |   21 +-
 hw/ivshmem.c               |   51 ++-
 hw/kvmclock.c              |   28 +-
 hw/kvmclock.h              |    5 +-
 hw/lan9118.c               |   33 +-
 hw/lance.c                 |   37 +-
 hw/lm32_juart.c            |   23 +-
 hw/lm32_pic.c              |   23 +-
 hw/lm32_sys.c              |   33 +-
 hw/lm32_timer.c            |   35 +-
 hw/lm32_uart.c             |   23 +-
 hw/lm832x.c                |   37 +-
 hw/lsi53c895a.c            |   38 +-
 hw/m48t59.c                |   71 ++-
 hw/macio.c                 |    5 +
 hw/marvell_88w8618_audio.c |   39 +-
 hw/max111x.c               |   40 ++-
 hw/max7310.c               |   39 +-
 hw/mc146818rtc.c           |   59 ++-
 hw/milkymist-ac97.c        |   23 +-
 hw/milkymist-hpdmc.c       |   23 +-
 hw/milkymist-memcard.c     |   23 +-
 hw/milkymist-minimac2.c    |   41 +-
 hw/milkymist-pfpu.c        |   23 +-
 hw/milkymist-softusb.c     |   47 +-
 hw/milkymist-sysctl.c      |   47 ++-
 hw/milkymist-tmu2.c        |   23 +-
 hw/milkymist-uart.c        |   23 +-
 hw/milkymist-vgafb.c       |   35 +-
 hw/mips_fulong2e.c         |    5 +-
 hw/mips_jazz.c             |    1 +
 hw/mips_malta.c            |   13 +-
 hw/mips_mipssim.c          |   11 +-
 hw/mips_r4k.c              |    6 +-
 hw/mipsnet.c               |   37 +-
 hw/mm-serial.c             |  129 ++++++
 hw/mm-serial.h             |   60 +++
 hw/mpc8544_guts.c          |   18 +-
 hw/mst_fpga.c              |   23 +-
 hw/musicpal.c              |  183 ++++++---
 hw/nand.c                  |   37 +-
 hw/ne2000-isa.c            |   34 +-
 hw/ne2000.c                |   41 +-
 hw/object.c                |  515 +++++++++++++++++++++
 hw/object.h                |  499 ++++++++++++++++++++
 hw/omap_gpio.c             |   78 ++--
 hw/omap_intc.c             |   70 ++-
 hw/omap_uart.c             |    3 +-
 hw/onenand.c               |   39 +-
 hw/opencores_eth.c         |   35 +-
 hw/openpic.c               |    5 +
 hw/parallel.c              |   34 +-
 hw/pc.c                    |  101 +++--
 hw/pc.h                    |   70 +--
 hw/pc_piix.c               |   64 ++-
 hw/pci.c                   |  186 ++++----
 hw/pci.h                   |   80 ++--
 hw/pci_bridge.c            |    2 +-
 hw/pcie.c                  |    2 +-
 hw/pckbd.c                 |   22 +-
 hw/pcnet-pci.c             |   43 ++-
 hw/pcnet.c                 |    2 +-
 hw/petalogix_ml605_mmu.c   |    1 +
 hw/piix3.c                 |  198 ++++++++
 hw/piix3.h                 |   37 ++
 hw/piix4.c                 |   37 +-
 hw/piix_pci.c              |  568 -----------------------
 hw/pl011.c                 |   38 ++-
 hw/pl022.c                 |   16 +-
 hw/pl031.c                 |   23 +-
 hw/pl041.c                 |   38 +-
 hw/pl050.c                 |   42 ++-
 hw/pl061.c                 |   42 ++-
 hw/pl080.c                 |   46 ++-
 hw/pl110.c                 |   69 ++-
 hw/pl181.c                 |   16 +-
 hw/pl190.c                 |   25 +-
 hw/ppc405_uc.c             |    1 +
 hw/ppc440.c                |    1 +
 hw/ppc4xx_pci.c            |    5 +
 hw/ppc_prep.c              |    9 +-
 hw/ppce500_mpc8544ds.c     |    1 +
 hw/ppce500_pci.c           |   46 ++-
 hw/ppce500_spin.c          |   18 +-
 hw/prep_pci.c              |    5 +
 hw/pxa2xx.c                |  109 +++--
 hw/pxa2xx_dma.c            |   33 +-
 hw/pxa2xx_gpio.c           |   33 +-
 hw/pxa2xx_pic.c            |   23 +-
 hw/pxa2xx_timer.c          |   74 ++-
 hw/qdev-monitor.c          |  495 ++++++++++++++++++++
 hw/qdev-properties.c       |   50 +--
 hw/qdev.c                  | 1085 ++++++++++++++++++++++++--------------------
 hw/qdev.h                  |  370 ++++++++++++++--
 hw/qxl.c                   |   70 ++-
 hw/realview.c              |   18 +-
 hw/realview_gic.c          |   17 +-
 hw/rtl8139.c               |   47 ++-
 hw/s390-virtio-bus.c       |   25 +-
 hw/sb16.c                  |   40 +-
 hw/sbi.c                   |   23 +-
 hw/scsi-bus.c              |  125 ++++--
 hw/scsi-disk.c             |  177 +++++---
 hw/scsi-generic.c          |   41 +-
 hw/scsi.h                  |   30 +-
 hw/serial.c                |  366 +++-------------
 hw/serial.h                |  172 +++++++
 hw/sga.c                   |   20 +-
 hw/sh_pci.c                |   41 ++-
 hw/slavio_intctl.c         |   23 +-
 hw/slavio_misc.c           |   41 ++-
 hw/slavio_timer.c          |   33 +-
 hw/sm501.c                 |    1 +
 hw/smbus.c                 |   85 ++--
 hw/smbus.h                 |   39 +-
 hw/smbus_eeprom.c          |   39 +-
 hw/smc91c111.c             |   35 +-
 hw/spapr_llan.c            |   45 ++-
 hw/spapr_pci.c             |   37 ++-
 hw/spapr_vio.c             |  100 +++--
 hw/spapr_vio.h             |   39 +-
 hw/spapr_vscsi.c           |   39 +-
 hw/spapr_vty.c             |   41 ++-
 hw/sparc32_dma.c           |   35 +-
 hw/spitz.c                 |  110 +++--
 hw/ssd0303.c               |   37 +-
 hw/ssd0323.c               |   20 +-
 hw/ssi-sd.c                |   20 +-
 hw/ssi.c                   |   39 ++-
 hw/ssi.h                   |   18 +-
 hw/stellaris.c             |   71 +++-
 hw/stellaris_enet.c        |   31 +-
 hw/strongarm.c             |  148 +++++--
 hw/sun4c_intctl.c          |   23 +-
 hw/sun4m.c                 |   92 +++--
 hw/sun4m_iommu.c           |   33 +-
 hw/sun4u.c                 |   88 +++--
 hw/syborg_fb.c             |   31 +-
 hw/syborg_interrupt.c      |   29 +-
 hw/syborg_keyboard.c       |   29 +-
 hw/syborg_pointer.c        |   31 +-
 hw/syborg_rtc.c            |   16 +-
 hw/syborg_serial.c         |   31 +-
 hw/syborg_timer.c          |   29 +-
 hw/syborg_virtio.c         |   41 +-
 hw/sysbus.c                |   50 ++-
 hw/sysbus.h                |   23 +-
 hw/tcx.c                   |   41 +-
 hw/tmp105.c                |   41 +-
 hw/tosa.c                  |   54 ++-
 hw/tusb6010.c              |   21 +-
 hw/twl92230.c              |   39 +-
 hw/unin_pci.c              |  180 ++++++--
 hw/usb-bt.c                |   35 +-
 hw/usb-bus.c               |  203 +++++++--
 hw/usb-ccid.c              |  151 +++++--
 hw/usb-desc.c              |   18 +-
 hw/usb-ehci.c              |   67 ++-
 hw/usb-hid.c               |  116 +++--
 hw/usb-hub.c               |   37 +-
 hw/usb-msd.c               |   56 ++-
 hw/usb-net.c               |   52 ++-
 hw/usb-ohci.c              |   76 ++--
 hw/usb-serial.c            |   96 +++--
 hw/usb-uhci.c              |  205 ++++++---
 hw/usb-uhci.h              |    2 +-
 hw/usb-wacom.c             |   39 +-
 hw/usb.c                   |   24 +-
 hw/usb.h                   |   97 +++--
 hw/versatile_pci.c         |   58 ++-
 hw/versatilepb.c           |   23 +-
 hw/vga-isa.c               |   22 +-
 hw/vga-pci.c               |   36 +-
 hw/virtex_ml507.c          |    1 +
 hw/virtio-console.c        |   77 ++--
 hw/virtio-net.c            |    2 +-
 hw/virtio-pci.c            |  222 ++++++----
 hw/virtio-serial-bus.c     |   98 +++--
 hw/virtio-serial.h         |   84 ++--
 hw/vmmouse.c               |   34 +-
 hw/vmport.c                |   20 +-
 hw/vmware_vga.c            |   38 +-
 hw/vmware_vga.h            |    6 +-
 hw/vt82c686.c              |  136 ++++--
 hw/wdt_i6300esb.c          |   37 +-
 hw/wdt_ib700.c             |   22 +-
 hw/wm8750.c                |   41 +-
 hw/xen_platform.c          |   38 +-
 hw/xilinx_axidma.c         |   31 +-
 hw/xilinx_axienet.c        |   39 +-
 hw/xilinx_ethlite.c        |   35 +-
 hw/xilinx_intc.c           |   29 +-
 hw/xilinx_timer.c          |   31 +-
 hw/xilinx_uartlite.c       |   17 +-
 hw/xio3130_downstream.c    |   63 ++--
 hw/xio3130_upstream.c      |   57 ++-
 hw/z2.c                    |   60 ++-
 hw/zaurus.c                |   31 +-
 monitor.h                  |    4 +
 qapi-schema.json           |  107 +++++
 qemu-common.h              |    1 -
 qerror.c                   |    4 +
 qerror.h                   |    3 +
 qmp-commands.hx            |   18 +
 qmp.c                      |   93 ++++
 scripts/patch-monkey.py    |  130 ++++++
 scripts/pm2.py             |  176 +++++++
 scripts/qapi-commands.py   |    1 +
 scripts/qapi-types.py      |    1 +
 usb-bsd.c                  |   29 +-
 usb-linux.c                |   58 ++-
 usb-redir.c                |   33 +-
 291 files changed, 11875 insertions(+), 5338 deletions(-)
 create mode 100755 QMP/qom-get
 create mode 100755 QMP/qom-list
 create mode 100755 QMP/qom-set
 create mode 100644 hw/container.c
 create mode 100644 hw/i440fx.c
 create mode 100644 hw/isa-serial.c
 create mode 100644 hw/isa-serial.h
 create mode 100644 hw/mm-serial.c
 create mode 100644 hw/mm-serial.h
 create mode 100644 hw/object.c
 create mode 100644 hw/object.h
 create mode 100644 hw/piix3.c
 create mode 100644 hw/piix3.h
 delete mode 100644 hw/piix_pci.c
 create mode 100644 hw/qdev-monitor.c
 create mode 100644 hw/serial.h
 create mode 100644 scripts/patch-monkey.py
 create mode 100644 scripts/pm2.py
Signature · 1 line
1.7.4.1
#1 lore raw

PATCH v3 1/197 qom: add a reference count to qdev objects

To ensure that a device isn't removed from the graph until all of its links are broken.

---
 hw/qdev.c |   16 ++++++++++++++++
 hw/qdev.h |   26 ++++++++++++++++++++++++++
 2 files changed, 42 insertions(+), 0 deletions(-)
hw/qdev.c +16 -0
index 106407f..fdc9843 100644
@@ -323,6 +323,11 @@ int qdev_unplug(DeviceState *dev)
     }
     assert(dev->info->unplug != NULL);
 
+    if (dev->ref != 0) {
+        qerror_report(QERR_DEVICE_IN_USE, dev->id?:"");
+        return -1;
+    }
+
     qdev_hot_removed = true;
 
     return dev->info->unplug(dev);
@@ -962,3 +967,14 @@ char* qdev_get_fw_dev_path(DeviceState *dev)
 
     return strdup(path);
 }
+
+void qdev_ref(DeviceState *dev)
+{
+    dev->ref++;
+}
+
+void qdev_unref(DeviceState *dev)
+{
+    g_assert(dev->ref > 0);
+    dev->ref--;
+}
hw/qdev.h +26 -0
index 36a4198..2397b4e 100644
@@ -45,6 +45,12 @@ struct DeviceState {
     QTAILQ_ENTRY(DeviceState) sibling;
     int instance_id_alias;
     int alias_required_for_version;
+
+    /**
+     * This tracks the number of references between devices.  See @qdev_ref for
+     * more information.
+     */
+    uint32_t ref;
 };
 
 typedef void (*bus_dev_printfn)(Monitor *mon, DeviceState *dev, int indent);
@@ -329,4 +335,24 @@ char *qdev_get_fw_dev_path(DeviceState *dev);
 /* This is a nasty hack to allow passing a NULL bus to qdev_create.  */
 extern struct BusInfo system_bus_info;
 
+/**
+ * @qdev_ref
+ *
+ * Increase the reference count of a device.  A device cannot be freed as long
+ * as its reference count is greater than zero.
+ *
+ * @dev - the device
+ */
+void qdev_ref(DeviceState *dev);
+
+/**
+ * @qdef_unref
+ *
+ * Decrease the reference count of a device.  A device cannot be freed as long
+ * as its reference count is greater than zero.
+ *
+ * @dev - the device
+ */
+void qdev_unref(DeviceState *dev);
+
 #endif
Signature · 1 line
1.7.4.1
#2 lore raw

Re: [Qemu-devel] [PATCH v3 001/197] qom: add a reference count to qdev objects

Quoted 4 lines · Anthony Liguori

To ensure that a device isn't removed from the graph until all of its links are broken.

Sorry, my mail script went awry :-(

Ignore this series.

Regards,

Anthony Liguori

Quoted 78 lines
---
  hw/qdev.c |   16 ++++++++++++++++
  hw/qdev.h |   26 ++++++++++++++++++++++++++
  2 files changed, 42 insertions(+), 0 deletions(-)
hw/qdev.c +16 -0
index 106407f..fdc9843 100644
@@ -323,6 +323,11 @@ int qdev_unplug(DeviceState *dev)
      }
      assert(dev->info->unplug != NULL);
 
+    if (dev->ref != 0) {
+        qerror_report(QERR_DEVICE_IN_USE, dev->id?:"");
+        return -1;
+    }
+
      qdev_hot_removed = true;
 
      return dev->info->unplug(dev);
@@ -962,3 +967,14 @@ char* qdev_get_fw_dev_path(DeviceState *dev)
 
      return strdup(path);
  }
+
+void qdev_ref(DeviceState *dev)
+{
+    dev->ref++;
+}
+
+void qdev_unref(DeviceState *dev)
+{
+    g_assert(dev->ref>  0);
+    dev->ref--;
+}
hw/qdev.h +26 -0
index 36a4198..2397b4e 100644
@@ -45,6 +45,12 @@ struct DeviceState {
      QTAILQ_ENTRY(DeviceState) sibling;
      int instance_id_alias;
      int alias_required_for_version;
+
+    /**
+     * This tracks the number of references between devices.  See @qdev_ref for
+     * more information.
+     */
+    uint32_t ref;
  };
 
  typedef void (*bus_dev_printfn)(Monitor *mon, DeviceState *dev, int indent);
@@ -329,4 +335,24 @@ char *qdev_get_fw_dev_path(DeviceState *dev);
  /* This is a nasty hack to allow passing a NULL bus to qdev_create.  */
  extern struct BusInfo system_bus_info;
 
+/**
+ * @qdev_ref
+ *
+ * Increase the reference count of a device.  A device cannot be freed as long
+ * as its reference count is greater than zero.
+ *
+ * @dev - the device
+ */
+void qdev_ref(DeviceState *dev);
+
+/**
+ * @qdef_unref
+ *
+ * Decrease the reference count of a device.  A device cannot be freed as long
+ * as its reference count is greater than zero.
+ *
+ * @dev - the device
+ */
+void qdev_unref(DeviceState *dev);
+
  #endif
#3 lore raw

PATCH v3 2/197 qom: add new dynamic property infrastructure based on Visitors (v2)

In reply to Anthony Liguori

qdev properties are settable only during construction and static to classes. This isn't flexible enough for QOM.

This patch introduces a property interface for qdev that provides dynamic properties that are tied to objects, instead of classes. These properties are Visitor based instead of string based too.

---
v1 -> v2
- Etter -> Accessor (Stefan)
- spelling mistakes (Stefan)
- switch to qemu-queue (Kevin/Gerd)

---
 hw/qdev.c |   97 +++++++++++++++++++++++++++++++++++++++++++++++++
 hw/qdev.h |  120 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 qerror.c  |    4 ++
 qerror.h  |    3 ++
 4 files changed, 224 insertions(+), 0 deletions(-)
hw/qdev.c +97 -0
index fdc9843..94f14c1 100644
@@ -98,6 +98,7 @@ static DeviceState *qdev_create_from_info(BusState *bus, DeviceInfo *info)
         qdev_hot_added = true;
     }
     dev->instance_id_alias = -1;
+    QTAILQ_INIT(&dev->properties);
     dev->state = DEV_STATE_CREATED;
     return dev;
 }
@@ -395,12 +396,31 @@ void qdev_init_nofail(DeviceState *dev)
     }
 }
 
+static void qdev_property_del_all(DeviceState *dev)
+{
+    while (!QTAILQ_EMPTY(&dev->properties)) {
+        DeviceProperty *prop = QTAILQ_FIRST(&dev->properties);
+
+        QTAILQ_REMOVE(&dev->properties, prop, node);
+
+        if (prop->release) {
+            prop->release(dev, prop->name, prop->opaque);
+        }
+
+        g_free(prop->name);
+        g_free(prop->type);
+        g_free(prop);
+    }
+}
+
 /* Unlink device from bus and free the structure.  */
 void qdev_free(DeviceState *dev)
 {
     BusState *bus;
     Property *prop;
 
+    qdev_property_del_all(dev);
+
     if (dev->state == DEV_STATE_INITIALIZED) {
         while (dev->num_child_bus) {
             bus = QLIST_FIRST(&dev->child_bus);
@@ -978,3 +998,80 @@ void qdev_unref(DeviceState *dev)
     g_assert(dev->ref > 0);
     dev->ref--;
 }
+
+void qdev_property_add(DeviceState *dev, const char *name, const char *type,
+                       DevicePropertyAccessor *get, DevicePropertyAccessor *set,
+                       DevicePropertyRelease *release,
+                       void *opaque, Error **errp)
+{
+    DeviceProperty *prop = g_malloc0(sizeof(*prop));
+
+    prop->name = g_strdup(name);
+    prop->type = g_strdup(type);
+
+    prop->get = get;
+    prop->set = set;
+    prop->release = release;
+    prop->opaque = opaque;
+
+    QTAILQ_INSERT_TAIL(&dev->properties, prop, node);
+}
+
+static DeviceProperty *qdev_property_find(DeviceState *dev, const char *name)
+{
+    DeviceProperty *prop;
+
+    QTAILQ_FOREACH(prop, &dev->properties, node) {
+        if (strcmp(prop->name, name) == 0) {
+            return prop;
+        }
+    }
+
+    return NULL;
+}
+
+void qdev_property_get(DeviceState *dev, Visitor *v, const char *name,
+                       Error **errp)
+{
+    DeviceProperty *prop = qdev_property_find(dev, name);
+
+    if (prop == NULL) {
+        error_set(errp, QERR_PROPERTY_NOT_FOUND, dev->id?:"", name);
+        return;
+    }
+
+    if (!prop->get) {
+        error_set(errp, QERR_PERMISSION_DENIED);
+    } else {
+        prop->get(dev, v, prop->opaque, name, errp);
+    }
+}
+
+void qdev_property_set(DeviceState *dev, Visitor *v, const char *name,
+                       Error **errp)
+{
+    DeviceProperty *prop = qdev_property_find(dev, name);
+
+    if (prop == NULL) {
+        error_set(errp, QERR_PROPERTY_NOT_FOUND, dev->id?:"", name);
+        return;
+    }
+
+    if (!prop->set) {
+        error_set(errp, QERR_PERMISSION_DENIED);
+    } else {
+        prop->set(dev, prop->opaque, v, name, errp);
+    }
+}
+
+const char *qdev_property_get_type(DeviceState *dev, const char *name, Error **errp)
+{
+    DeviceProperty *prop = qdev_property_find(dev, name);
+
+    if (prop == NULL) {
+        error_set(errp, QERR_PROPERTY_NOT_FOUND, dev->id?:"", name);
+        return NULL;
+    }
+
+    return prop->type;
+}
hw/qdev.h +120 -0

142 lines not on this page · raw message

qerror.c +4 -0
index fdf62b9..dd0ee76 100644
@@ -178,6 +178,10 @@ static const QErrorStringTable qerror_table[] = {
         .desc      = "Could not open '%(filename)'",
     },
     {
+        .error_fmt = QERR_PERMISSION_DENIED,
+        .desc      = "Insufficient permission to perform this operation",
+    },
+    {
         .error_fmt = QERR_PROPERTY_NOT_FOUND,
         .desc      = "Property '%(device).%(property)' not found",
     },
qerror.h +3 -0
index 2d3d43b..2b1d743 100644
@@ -150,6 +150,9 @@ QError *qobject_to_qerror(const QObject *obj);
 #define QERR_OPEN_FILE_FAILED \
     "{ 'class': 'OpenFileFailed', 'data': { 'filename': %s } }"
 
+#define QERR_PERMISSION_DENIED \
+    "{ 'class': 'PermissionDenied', 'data': {} }"
+
 #define QERR_PROPERTY_NOT_FOUND \
     "{ 'class': 'PropertyNotFound', 'data': { 'device': %s, 'property': %s } }"
 
Signature · 1 line
1.7.4.1
#4 lore raw

PATCH v3 3/197 qom: register legacy properties as new style properties (v2)

In reply to Anthony Liguori

Expose all legacy properties through the new QOM property mechanism. The qdev property types are exposed through the 'legacy<>' namespace. They are always visited as strings since they do their own string parsing.

---
v1 -> v2
- add bus properties (Gerd)

---
 hw/qdev.c |   86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/qdev.h |    7 +++++
 2 files changed, 93 insertions(+), 0 deletions(-)
hw/qdev.c +86 -0
index 94f14c1..6f77af9 100644
@@ -83,6 +83,7 @@ static DeviceInfo *qdev_find_info(BusInfo *bus_info, const char *name)
 static DeviceState *qdev_create_from_info(BusState *bus, DeviceInfo *info)
 {
     DeviceState *dev;
+    Property *prop;
 
     assert(bus->info == info->bus_info);
     dev = g_malloc0(info->size);
@@ -100,6 +101,15 @@ static DeviceState *qdev_create_from_info(BusState *bus, DeviceInfo *info)
     dev->instance_id_alias = -1;
     QTAILQ_INIT(&dev->properties);
     dev->state = DEV_STATE_CREATED;
+
+    for (prop = dev->info->props; prop && prop->name; prop++) {
+        qdev_property_add_legacy(dev, prop, NULL);
+    }
+
+    for (prop = dev->info->bus_info->props; prop && prop->name; prop++) {
+        qdev_property_add_legacy(dev, prop, NULL);
+    }
+
     return dev;
 }
 
@@ -1075,3 +1085,79 @@ const char *qdev_property_get_type(DeviceState *dev, const char *name, Error **e
 
     return prop->type;
 }
+
+/**
+ * Legacy property handling
+ */
+
+static void qdev_get_legacy_property(DeviceState *dev, Visitor *v, void *opaque,
+                                     const char *name, Error **errp)
+{
+    Property *prop = opaque;
+
+    if (prop->info->print) {
+        char buffer[1024];
+        char *ptr = buffer;
+
+        prop->info->print(dev, prop, buffer, sizeof(buffer));
+        visit_type_str(v, &ptr, name, errp);
+    } else {
+        error_set(errp, QERR_PERMISSION_DENIED);
+    }
+}
+
+static void qdev_set_legacy_property(DeviceState *dev, Visitor *v, void *opaque,
+                                     const char *name, Error **errp)
+{
+    Property *prop = opaque;
+
+    if (dev->state != DEV_STATE_CREATED) {
+        error_set(errp, QERR_PERMISSION_DENIED);
+        return;
+    }
+
+    if (prop->info->parse) {
+        Error *local_err = NULL;
+        char *ptr = NULL;
+
+        visit_type_str(v, &ptr, name, &local_err);
+        if (!local_err) {
+            int ret;
+            ret = prop->info->parse(dev, prop, ptr);
+            if (ret != 0) {
+                error_set(errp, QERR_INVALID_PARAMETER_VALUE,
+                          name, prop->info->name);
+            }
+            g_free(ptr);
+        } else {
+            error_propagate(errp, local_err);
+        }
+    } else {
+        error_set(errp, QERR_PERMISSION_DENIED);
+    }
+}
+
+/**
+ * @qdev_add_legacy_property - adds a legacy property
+ *
+ * Do not use this is new code!  Properties added through this interface will
+ * be given types in the "legacy<>" type namespace.
+ *
+ * Legacy properties are always processed as strings.  The format of the string
+ * depends on the property type.
+ */
+void qdev_property_add_legacy(DeviceState *dev, Property *prop,
+                              Error **errp)
+{
+    gchar *type;
+
+    type = g_strdup_printf("legacy<%s>", prop->info->name);
+
+    qdev_property_add(dev, prop->name, type,
+                      qdev_get_legacy_property,
+                      qdev_set_legacy_property,
+                      NULL,
+                      prop, errp);
+
+    g_free(type);
+}
hw/qdev.h +7 -0
index 2df3bb7..3b629d4 100644
@@ -475,4 +475,11 @@ void qdev_property_set(DeviceState *dev, Visitor *v, const char *name,
 const char *qdev_property_get_type(DeviceState *dev, const char *name,
                                    Error **errp);
 
+/**
+ * @qdev_property_add_legacy - add a legacy @Property to a device
+ *
+ * DO NOT USE THIS IN NEW CODE!
+ */
+void qdev_property_add_legacy(DeviceState *dev, Property *prop, Error **errp);
+
 #endif
Signature · 1 line
1.7.4.1
#5 lore raw

PATCH v3 4/197 qom: introduce root device

In reply to Anthony Liguori

This is based on Jan's suggestion for how to do unique naming. The root device is the root of composition. All devices are reachable via child<> links from this device.

---
 Makefile.objs  |    2 +-
 hw/container.c |   20 ++++++++++++++++++++
 hw/qdev.c      |   12 ++++++++++++
 hw/qdev.h      |    8 ++++++++
 4 files changed, 41 insertions(+), 1 deletions(-)
 create mode 100644 hw/container.c
Makefile.objs +1 -1
index d7a6539..10e794c 100644
@@ -279,7 +279,7 @@ hw-obj-$(CONFIG_LSI_SCSI_PCI) += lsi53c895a.o
 hw-obj-$(CONFIG_ESP) += esp.o
 
 hw-obj-y += dma-helpers.o sysbus.o isa-bus.o
-hw-obj-y += qdev-addr.o
+hw-obj-y += qdev-addr.o container.o
 
 # VGA
 hw-obj-$(CONFIG_VGA_PCI) += vga-pci.o
hw/container.c new file +20 -0
new file mode 100644
index 0000000..9cbf399
@@ -0,0 +1,20 @@
+#include "sysbus.h"
+
+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_init(void)
+{
+    sysbus_register_withprop(&container_info);
+}
+
+device_init(container_init);
hw/qdev.c +12 -0
index 6f77af9..bb0b9f7 100644
@@ -1161,3 +1161,15 @@ void qdev_property_add_legacy(DeviceState *dev, Property *prop,
 
     g_free(type);
 }
+
+DeviceState *qdev_get_root(void)
+{
+    static DeviceState *qdev_root;
+
+    if (!qdev_root) {
+        qdev_root = qdev_create(NULL, "container");
+        qdev_init_nofail(qdev_root);
+    }
+
+    return qdev_root;
+}
hw/qdev.h +8 -0
index 3b629d4..52aadd2 100644
@@ -482,4 +482,12 @@ const char *qdev_property_get_type(DeviceState *dev, const char *name,
  */
 void qdev_property_add_legacy(DeviceState *dev, Property *prop, Error **errp);
 
+/**
+ * @qdev_get_root - returns the root device of the composition tree
+ *
+ * Returns:
+ *   The root of the composition tree.
+ */
+DeviceState *qdev_get_root(void);
+
 #endif
Signature · 1 line
1.7.4.1
#6 lore raw

PATCH v3 5/197 qdev: provide an interface to return canonical path from root (v2)

In reply to Anthony Liguori

The canonical path is the path in the composition tree from the root to the device. This is effectively the name of the device.

This is an incredibly unefficient implementation that will be optimized in a future patch.

---
v1 -> v2
- change from gslist to qemu-queue (Kevin/Gerd)

---
 hw/qdev.c |   48 ++++++++++++++++++++++++++++++++++++++++++++++++
 hw/qdev.h |    9 +++++++++
 2 files changed, 57 insertions(+), 0 deletions(-)
hw/qdev.c +48 -0
index bb0b9f7..79849c9 100644
@@ -1173,3 +1173,51 @@ DeviceState *qdev_get_root(void)
 
     return qdev_root;
 }
+
+static gchar *qdev_get_path_in(DeviceState *parent, DeviceState *dev)
+{
+    DeviceProperty *prop;
+
+    if (parent == dev) {
+        return g_strdup("");
+    }
+
+    QTAILQ_FOREACH(prop, &parent->properties, node) {
+        gchar *subpath;
+
+        if (!strstart(prop->type, "child<", NULL)) {
+            continue;
+        }
+
+        /* Check to see if the device is one of parent's children */
+        if (prop->opaque == dev) {
+            return g_strdup(prop->name);
+        }
+
+        /* Check to see if the device is a child of our child */
+        subpath = qdev_get_path_in(prop->opaque, dev);
+        if (subpath) {
+            gchar *path;
+
+            path = g_strdup_printf("%s/%s", prop->name, subpath);
+            g_free(subpath);
+
+            return path;
+        }
+    }
+
+    return NULL;
+}
+
+gchar *qdev_get_canonical_path(DeviceState *dev)
+{
+    gchar *path, *newpath;
+
+    path = qdev_get_path_in(qdev_get_root(), dev);
+    g_assert(path != NULL);
+
+    newpath = g_strdup_printf("/%s", path);
+    g_free(path);
+
+    return newpath;
+}
hw/qdev.h +9 -0
index 52aadd2..0f00497 100644
@@ -490,4 +490,13 @@ void qdev_property_add_legacy(DeviceState *dev, Property *prop, Error **errp);
  */
 DeviceState *qdev_get_root(void);
 
+/**
+ * @qdev_get_canonical_path - returns the canonical path for a device.  This
+ * is the path within the composition tree starting from the root.
+ *
+ * Returns:
+ *   The canonical path in the composition tree.
+ */
+gchar *qdev_get_canonical_path(DeviceState *dev);
+
 #endif
Signature · 1 line
1.7.4.1
#7 lore raw

PATCH v3 6/197 qdev: provide a path resolution (v2)

In reply to Anthony Liguori

There are two types of supported paths--absolute paths and partial paths.

Absolute paths are derived from the root device and can follow child<> or link<> properties. Since they can follow link<> properties, they can be arbitrarily long. Absolute paths look like absolute filenames and are prefixed with a leading slash.

Partial paths are look like relative filenames. They do not begin with a prefix. The matching rules for partial paths are subtle but designed to make specifying devices easy. At each level of the composition tree, the partial path is matched as an absolute path. The first match is not returned. At least two matches are searched for. A successful result is only returned if only one match is founded. If more than one match is found, a flag is returned to indicate that the match was ambiguous.

At the end of the day, partial path support means that if you create a device called 'ide0', you can just say 'ide0' as the path name and it will Just Work. If we internally create a device called 'i440fx', you can just say 'i440fx' and it will Just Work and long as you don't do anything silly.

A management tool should probably always use absolute paths since then they don't have to deal with the possibility of ambiguity.

---
v1 -> v2
- fix comments (Stefan)
- always initialize ambiguous to false (Stefan)
- change from gslist to qemu-queue (Kevin/Gerd)

---
 hw/qdev.c |  103 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/qdev.h |   28 ++++++++++++++++
 2 files changed, 131 insertions(+), 0 deletions(-)
hw/qdev.c +103 -0
index 79849c9..2519f00 100644
@@ -1221,3 +1221,106 @@ gchar *qdev_get_canonical_path(DeviceState *dev)
 
     return newpath;
 }
+
+static DeviceState *qdev_resolve_abs_path(DeviceState *parent,
+                                          gchar **parts,
+                                          int index)
+{
+    DeviceProperty *prop;
+    DeviceState *child;
+
+    if (parts[index] == NULL) {
+        return parent;
+    }
+
+    if (strcmp(parts[index], "") == 0) {
+        return qdev_resolve_abs_path(parent, parts, index + 1);
+    }
+
+    prop = qdev_property_find(parent, parts[index]);
+    if (prop == NULL) {
+        return NULL;
+    }
+
+    child = NULL;
+    if (strstart(prop->type, "link<", NULL)) {
+        DeviceState **pchild = prop->opaque;
+        if (*pchild) {
+            child = *pchild;
+        }
+    } else if (strstart(prop->type, "child<", NULL)) {
+        child = prop->opaque;
+    }
+
+    if (!child) {
+        return NULL;
+    }
+
+    return qdev_resolve_abs_path(child, parts, index + 1);
+}
+
+static DeviceState *qdev_resolve_partial_path(DeviceState *parent,
+                                              gchar **parts,
+                                              bool *ambiguous)
+{
+    DeviceState *dev;
+    DeviceProperty *prop;
+
+    dev = qdev_resolve_abs_path(parent, parts, 0);
+
+    QTAILQ_FOREACH(prop, &parent->properties, node) {
+        DeviceState *found;
+
+        if (!strstart(prop->type, "child<", NULL)) {
+            continue;
+        }
+
+        found = qdev_resolve_partial_path(prop->opaque, parts, ambiguous);
+        if (found) {
+            if (dev) {
+                if (ambiguous) {
+                    *ambiguous = true;
+                }
+                return NULL;
+            }
+            dev = found;
+        }
+
+        if (ambiguous && *ambiguous) {
+            return NULL;
+        }
+    }
+
+    return dev;
+}
+
+DeviceState *qdev_resolve_path(const char *path, bool *ambiguous)
+{
+    bool partial_path = true;
+    DeviceState *dev;
+    gchar **parts;
+
+    parts = g_strsplit(path, "/", 0);
+    if (parts == NULL || parts[0] == NULL) {
+        g_strfreev(parts);
+        return qdev_get_root();
+    }
+
+    if (strcmp(parts[0], "") == 0) {
+        partial_path = false;
+    }
+
+    if (partial_path) {
+        if (ambiguous) {
+            *ambiguous = false;
+        }
+        dev = qdev_resolve_partial_path(qdev_get_root(), parts, ambiguous);
+    } else {
+        dev = qdev_resolve_abs_path(qdev_get_root(), parts, 1);
+    }
+
+    g_strfreev(parts);
+
+    return dev;
+}
+
hw/qdev.h +28 -0
index 0f00497..641d134 100644
@@ -499,4 +499,32 @@ DeviceState *qdev_get_root(void);
  */
 gchar *qdev_get_canonical_path(DeviceState *dev);
 
+/**
+ * @qdev_resolve_path - resolves a path returning a device
+ *
+ * There are two types of supported paths--absolute paths and partial paths.
+ * 
+ * Absolute paths are derived from the root device and can follow child<> or
+ * link<> properties.  Since they can follow link<> properties, they can be
+ * arbitrarily long.  Absolute paths look like absolute filenames and are
+ * prefixed with a leading slash.
+ * 
+ * Partial paths look like relative filenames.  They do not begin with a
+ * prefix.  The matching rules for partial paths are subtle but designed to make
+ * specifying devices easy.  At each level of the composition tree, the partial
+ * path is matched as an absolute path.  The first match is not returned.  At
+ * least two matches are searched for.  A successful result is only returned if
+ * only one match is founded.  If more than one match is found, a flag is
+ * return to indicate that the match was ambiguous.
+ *
+ * @path - the path to resolve
+ *
+ * @ambiguous - returns true if the path resolution failed because of an
+ *              ambiguous match
+ *
+ * Returns:
+ *   The matched device or NULL on path lookup failure.
+ */
+DeviceState *qdev_resolve_path(const char *path, bool *ambiguous);
+
 #endif
Signature · 1 line
1.7.4.1
#8 lore raw

PATCH v3 7/197 qom: add child properties (composition) (v2)

In reply to Anthony Liguori

Child properties express a relationship of composition.

---
v1 -> v2
- fix comments (Kevin)
- add a reference when adding a child property (Kevin)

---
 hw/qdev.c |   26 ++++++++++++++++++++++++++
 hw/qdev.h |   20 ++++++++++++++++++++
 2 files changed, 46 insertions(+), 0 deletions(-)
hw/qdev.c +26 -0
index 2519f00..fa6b489 100644
@@ -1174,6 +1174,32 @@ DeviceState *qdev_get_root(void)
     return qdev_root;
 }
 
+static void qdev_get_child_property(DeviceState *dev, Visitor *v, void *opaque,
+                                    const char *name, Error **errp)
+{
+    DeviceState *child = opaque;
+    gchar *path;
+
+    path = qdev_get_canonical_path(child);
+    visit_type_str(v, &path, name, errp);
+    g_free(path);
+}
+
+void qdev_property_add_child(DeviceState *dev, const char *name,
+                             DeviceState *child, Error **errp)
+{
+    gchar *type;
+
+    type = g_strdup_printf("child<%s>", child->info->name);
+
+    qdev_property_add(dev, name, type, qdev_get_child_property,
+                      NULL, NULL, child, errp);
+
+    qdev_ref(dev);
+
+    g_free(type);
+}
+
 static gchar *qdev_get_path_in(DeviceState *parent, DeviceState *dev)
 {
     DeviceProperty *prop;
hw/qdev.h +20 -0
index 641d134..38b36e8 100644
@@ -527,4 +527,24 @@ gchar *qdev_get_canonical_path(DeviceState *dev);
  */
 DeviceState *qdev_resolve_path(const char *path, bool *ambiguous);
 
+/**
+ * @qdev_property_add_child - Add a child property to a device
+ *
+ * Child properties form the composition tree.  All devices need to be a child
+ * of another device.  Devices can only be a child of one device.
+ *
+ * There is no way for a child to determine what its parent is.  It is not
+ * a bidirectional relationship.  This is by design.
+ *
+ * @dev - the device to add a property to
+ *
+ * @name - the name of the property
+ *
+ * @child - the child device
+ *
+ * @errp - if an error occurs, a pointer to an area to store the area
+ */
+void qdev_property_add_child(DeviceState *dev, const char *name,
+                             DeviceState *child, Error **errp);
+
 #endif
Signature · 1 line
1.7.4.1
#9 lore raw

PATCH v3 8/197 qom: add link properties (v2)

In reply to Anthony Liguori

Links represent an ephemeral relationship between devices. They are meant to replace the qdev concept of busses by allowing more informal relationships between devices.

Links are fairly limited in their usefulness without implementing QOM-style subclassing and interfaces.

---
v1 -> v2
- comments (Stefan)
- maintain a reference when adding/removing a link property (Kevin)

---
 hw/qdev.c |   74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/qdev.h |   23 +++++++++++++++++++
 2 files changed, 97 insertions(+), 0 deletions(-)
hw/qdev.c +74 -0
index fa6b489..42430fa 100644
@@ -1200,6 +1200,80 @@ void qdev_property_add_child(DeviceState *dev, const char *name,
     g_free(type);
 }
 
+static void qdev_get_link_property(DeviceState *dev, Visitor *v, void *opaque,
+                                   const char *name, Error **errp)
+{
+    DeviceState **child = opaque;
+    gchar *path;
+
+    if (*child) {
+        path = qdev_get_canonical_path(*child);
+        visit_type_str(v, &path, name, errp);
+        g_free(path);
+    } else {
+        path = (gchar *)"";
+        visit_type_str(v, &path, name, errp);
+    }
+}
+
+static void qdev_set_link_property(DeviceState *dev, Visitor *v, void *opaque,
+                                   const char *name, Error **errp)
+{
+    DeviceState **child = opaque;
+    bool ambiguous = false;
+    const char *type;
+    char *path;
+
+    type = qdev_property_get_type(dev, name, NULL);
+
+    visit_type_str(v, &path, name, errp);
+
+    if (*child) {
+        qdev_unref(*child);
+    }
+
+    if (strcmp(path, "") != 0) {
+        DeviceState *target;
+
+        target = qdev_resolve_path(path, &ambiguous);
+        if (target) {
+            gchar *target_type;
+
+            target_type = g_strdup_printf("link<%s>", target->info->name);
+            if (strcmp(target_type, type) == 0) {
+                *child = target;
+                qdev_ref(target);
+            } else {
+                error_set(errp, QERR_INVALID_PARAMETER_TYPE, name, type);
+            }
+
+            g_free(target_type);
+        } else {
+            error_set(errp, QERR_DEVICE_NOT_FOUND, path);
+        }
+    } else {
+        *child = NULL;
+    }
+
+    g_free(path);
+}
+
+void qdev_property_add_link(DeviceState *dev, const char *name,
+                            const char *type, DeviceState **child,
+                            Error **errp)
+{
+    gchar *full_type;
+
+    full_type = g_strdup_printf("link<%s>", type);
+
+    qdev_property_add(dev, name, full_type,
+                      qdev_get_link_property,
+                      qdev_set_link_property,
+                      NULL, child, errp);
+
+    g_free(full_type);
+}
+
 static gchar *qdev_get_path_in(DeviceState *parent, DeviceState *dev)
 {
     DeviceProperty *prop;
hw/qdev.h +23 -0
index 38b36e8..4351e2e 100644
@@ -547,4 +547,27 @@ DeviceState *qdev_resolve_path(const char *path, bool *ambiguous);
 void qdev_property_add_child(DeviceState *dev, const char *name,
                              DeviceState *child, Error **errp);
 
+/**
+ * @qdev_property_add_link - Add a link property to a device
+ *
+ * Links establish relationships between devices.  Links are unidirectional
+ * although two links can be combined to form a bidirectional relationship
+ * between devices.
+ *
+ * Links form the graph in the device model.
+ *
+ * @dev - the device to add a property to
+ *
+ * @name - the name of the property
+ *
+ * @type - the qdev type of the link
+ *
+ * @child - a pointer to where the link device reference is stored
+ *
+ * @errp - if an error occurs, a pointer to an area to store the area
+ */
+void qdev_property_add_link(DeviceState *dev, const char *name,
+                            const char *type, DeviceState **child,
+                            Error **errp);
+
 #endif
Signature · 1 line
1.7.4.1
#10 lore raw

PATCH v3 9/197 qapi: allow a 'gen' key to suppress code generation

In reply to Anthony Liguori
---
 scripts/qapi-commands.py |    1 +
 scripts/qapi-types.py    |    1 +
 2 files changed, 2 insertions(+), 0 deletions(-)
scripts/qapi-commands.py +1 -0
index f7def16..54d1f5d 100644
@@ -405,6 +405,7 @@ except os.error, e:
 
 exprs = parse_schema(sys.stdin)
 commands = filter(lambda expr: expr.has_key('command'), exprs)
+commands = filter(lambda expr: not expr.has_key('gen'), commands)
 
 if dispatch_type == "sync":
     fdecl = open(h_file, 'w')
scripts/qapi-types.py +1 -0
index f64d84c..267cb49 100644
@@ -238,6 +238,7 @@ fdecl.write(mcgen('''
                   guard=guardname(h_file)))
 
 exprs = parse_schema(sys.stdin)
+exprs = filter(lambda expr: not expr.has_key('gen'), exprs)
 
 for expr in exprs:
     ret = "\n"
Signature · 1 line
1.7.4.1
#11 lore raw

PATCH v3 10/197 qmp: add qom-list command

In reply to Anthony Liguori

This can be used to list properties in the device model.

---
 qapi-schema.json |   48 ++++++++++++++++++++++++++++++++++++++++++++++++
 qmp-commands.hx  |    6 ++++++
 qmp.c            |   28 ++++++++++++++++++++++++++++
 3 files changed, 82 insertions(+), 0 deletions(-)
qapi-schema.json +48 -0
index cb1ba77..276b7c3 100644
@@ -887,3 +887,51 @@
 # Notes: Do not use this command.
 ##
 { 'command': 'cpu', 'data': {'index': 'int'} }
+
+##
+# @DevicePropertyInfo:
+#
+# @name: the name of the property
+#
+# @type: the type of the property.  This will typically come in one of four
+#        forms:
+#
+#        1) A primitive type such as 'u8', 'u16', 'bool', 'str', or 'double'.
+#           These types are mapped to the appropriate JSON type.
+#
+#        2) A legacy type in the form 'legacy<subtype>' where subtype is the
+#           legacy qdev typename.  These types are always treated as strings.
+#
+#        3) A child type in the form 'child<subtype>' where subtype is a qdev
+#           device type name.  Child properties create the composition tree.
+#
+#        4) A link type in the form 'link<subtype>' where subtype is a qdev
+#           device type name.  Link properties form the device model graph.
+#
+# Since: 1.1
+#
+# Notes: This type is experimental.  Its syntax may change in future releases.
+##
+{ 'type': 'DevicePropertyInfo',
+  'data': { 'name': 'str', 'type': 'str' } }
+
+##
+# @qom-list:
+#
+# This command will list any properties of a device given a path in the device
+# model.
+#
+# @path: the path within the device model.  See @qom-get for a description of
+#        this parameter.
+#
+# Returns: a list of @DevicePropertyInfo that describe the properties of the
+#          device.
+#
+# Since: 1.1
+#
+# Notes: This command is experimental.  It's syntax may change in future
+#        releases.
+##
+{ 'command': 'qom-list',
+  'data': { 'path': 'str' },
+  'returns': [ 'DevicePropertyInfo' ] }
qmp-commands.hx +6 -0
index 97975a5..d6ff466 100644
@@ -2001,3 +2001,9 @@ EQMP
         .args_type  = "",
         .mhandler.cmd_new = qmp_marshal_input_query_balloon,
     },
+
+    {
+        .name       = "qom-list",
+        .args_type  = "path:s",
+        .mhandler.cmd_new = qmp_marshal_input_qom_list,
+    },
qmp.c +28 -0
index 511dd62..06ae569 100644
@@ -16,6 +16,7 @@
 #include "qmp-commands.h"
 #include "kvm.h"
 #include "arch_init.h"
+#include "hw/qdev.h"
 
 NameInfo *qmp_query_name(Error **errp)
 {
@@ -117,3 +118,30 @@ SpiceInfo *qmp_query_spice(Error **errp)
     return NULL;
 };
 #endif
+
+DevicePropertyInfoList *qmp_qom_list(const char *path, Error **errp)
+{
+    DeviceState *dev;
+    bool ambiguous = false;
+    DevicePropertyInfoList *props = NULL;
+    DeviceProperty *prop;
+
+    dev = qdev_resolve_path(path, &ambiguous);
+    if (dev == NULL) {
+        error_set(errp, QERR_DEVICE_NOT_FOUND, path);
+        return NULL;
+    }
+
+    QTAILQ_FOREACH(prop, &dev->properties, node) {
+        DevicePropertyInfoList *entry = g_malloc0(sizeof(*entry));
+
+        entry->value = g_malloc0(sizeof(DevicePropertyInfo));
+        entry->next = props;
+        props = entry;
+
+        entry->value->name = g_strdup(prop->name);
+        entry->value->type = g_strdup(prop->type);
+    }
+
+    return props;
+}
Signature · 1 line
1.7.4.1
#12 lore raw

PATCH v3 11/197 qom: qom_{get, set} monitor commands (v2)

In reply to Anthony Liguori

This allows clients to read and write device model properties through QMP. QAPI doesn't support Visitor types yet and these commands are special in that they don't work with fixed types.

I've added a documentation stub to qapi-schema.json so we can keep consistency there.

---
v1 -> v2
- comments (Stefan)

---
 monitor.h        |    4 +++
 qapi-schema.json |   59 +++++++++++++++++++++++++++++++++++++++++++++++++
 qmp-commands.hx  |   12 ++++++++++
 qmp.c            |   65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 140 insertions(+), 0 deletions(-)
monitor.h +4 -0
index e76795f..efc76c7 100644
@@ -64,4 +64,8 @@ typedef void (MonitorCompletion)(void *opaque, QObject *ret_data);
 
 void monitor_set_error(Monitor *mon, QError *qerror);
 
+int qmp_qom_set(Monitor *mon, const QDict *qdict, QObject **ret);
+
+int qmp_qom_get(Monitor *mon, const QDict *qdict, QObject **ret);
+
 #endif /* !MONITOR_H */
qapi-schema.json +59 -0

62 lines not on this page · raw message

qmp-commands.hx +12 -0
index d6ff466..027189a 100644
@@ -2007,3 +2007,15 @@ EQMP
         .args_type  = "path:s",
         .mhandler.cmd_new = qmp_marshal_input_qom_list,
     },
+
+    {
+        .name       = "qom-set",
+	.args_type  = "path:s,property:s,opts:O",
+	.mhandler.cmd_new = qmp_qom_set,
+    },
+
+    {
+        .name       = "qom-get",
+	.args_type  = "path:s,property:s",
+	.mhandler.cmd_new = qmp_qom_get,
+    },
qmp.c +65 -0

74 lines not on this page · raw message

Signature · 1 line
1.7.4.1
#13 lore raw

PATCH v3 12/197 qdev: add explicitly named devices to the root complex

In reply to Anthony Liguori

We first add a 'peripheral' container to the root device that we add user created devices to. This provides all user created devices with a unique and isolated namespace.

---
 hw/qdev.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)
hw/qdev.c +14 -0
index 42430fa..af4c6a2 100644
@@ -227,6 +227,19 @@ int qdev_device_help(QemuOpts *opts)
     return 1;
 }
 
+static DeviceState *qdev_get_peripheral(void)
+{
+    static DeviceState *dev;
+
+    if (dev == NULL) {
+        dev = qdev_create(NULL, "container");
+        qdev_property_add_child(qdev_get_root(), "peripheral", dev, NULL);
+        qdev_init_nofail(dev);
+    }
+
+    return dev;
+}
+
 DeviceState *qdev_device_add(QemuOpts *opts)
 {
     const char *driver, *path, *id;
@@ -278,6 +291,7 @@ DeviceState *qdev_device_add(QemuOpts *opts)
     id = qemu_opts_id(opts);
     if (id) {
         qdev->id = id;
+        qdev_property_add_child(qdev_get_peripheral(), qdev->id, qdev, NULL);
     }
     if (qemu_opt_foreach(opts, set_property, qdev, 1) != 0) {
         qdev_free(qdev);
Signature · 1 line
1.7.4.1
#14 lore raw

PATCH v3 13/197 dev: add an anonymous peripheral container

In reply to Anthony Liguori
---
 hw/qdev.c |   21 ++++++++++++++++++++-
 1 files changed, 20 insertions(+), 1 deletions(-)
hw/qdev.c +20 -1
index af4c6a2..5348f26 100644
@@ -240,6 +240,19 @@ static DeviceState *qdev_get_peripheral(void)
     return dev;
 }
 
+static DeviceState *qdev_get_peripheral_anon(void)
+{
+    static DeviceState *dev;
+
+    if (dev == NULL) {
+        dev = qdev_create(NULL, "container");
+        qdev_property_add_child(qdev_get_root(), "peripheral-anon", dev, NULL);
+        qdev_init_nofail(dev);
+    }
+
+    return dev;
+}
+
 DeviceState *qdev_device_add(QemuOpts *opts)
 {
     const char *driver, *path, *id;
@@ -292,7 +305,13 @@ DeviceState *qdev_device_add(QemuOpts *opts)
     if (id) {
         qdev->id = id;
         qdev_property_add_child(qdev_get_peripheral(), qdev->id, qdev, NULL);
-    }
+    } else {
+        static int anon_count;
+        gchar *name = g_strdup_printf("device[%d]", anon_count++);
+        qdev_property_add_child(qdev_get_peripheral_anon(), name,
+                                qdev, NULL);
+        g_free(name);
+    }        
     if (qemu_opt_foreach(opts, set_property, qdev, 1) != 0) {
         qdev_free(qdev);
         return NULL;
Signature · 1 line
1.7.4.1
#15 lore raw

PATCH v3 14/197 rtc: make piix3 set the rtc as a child (v2)

In reply to Anthony Liguori

---
v1 -> v2
- comments (Stefan)

---
 hw/pc_piix.c  |   11 +++++++++++
 hw/piix_pci.c |    3 +++
 2 files changed, 14 insertions(+), 0 deletions(-)
hw/pc_piix.c +11 -0
index 970f43c..2d5ea2c 100644
@@ -205,6 +205,17 @@ static void pc_init1(MemoryRegion *system_memory,
         }
     }
 
+    /* FIXME there's some major spaghetti here.  Somehow we create the devices
+     * on the PIIX before we actually create it.  We create the PIIX3 deep in
+     * the recess of the i440fx creation too and then lose the DeviceState.
+     *
+     * For now, let's "fix" this by making judicious use of paths.  This is not
+     * generally the right way to do this.
+     */
+
+    qdev_property_add_child(qdev_resolve_path("/i440fx/piix3", NULL),
+                            "rtc", (DeviceState *)rtc_state, NULL);
+
     audio_init(gsi, pci_enabled ? pci_bus : NULL);
 
     pc_cmos_init(below_4g_mem_size, above_4g_mem_size, boot_device,
hw/piix_pci.c +3 -0
index d183443..d785d4b 100644
@@ -288,6 +288,7 @@ static PCIBus *i440fx_common_init(const char *device_name,
                     address_space_io, 0);
     s->bus = b;
     qdev_init_nofail(dev);
+    qdev_property_add_child(qdev_get_root(), "i440fx", dev, NULL);
 
     d = pci_create_simple(b, 0, device_name);
     *pi440fx_state = DO_UPCAST(PCII440FXState, dev, d);
@@ -323,6 +324,8 @@ static PCIBus *i440fx_common_init(const char *device_name,
                 pci_create_simple_multifunction(b, -1, true, "PIIX3"));
         pci_bus_irqs(b, piix3_set_irq, pci_slot_get_pirq, piix3,
                 PIIX_NUM_PIRQS);
+
+        qdev_property_add_child(dev, "piix3", &piix3->dev.qdev, NULL);
     }
     piix3->pic = pic;
 
Signature · 1 line
1.7.4.1
#16 lore raw

PATCH v3 15/197 rtc: add a dynamic property for retrieving the date

In reply to Anthony Liguori

This really shows the power of dynamic object properties compared to qdev static properties.

This property represents a complex structure who's format is preserved over the wire. This is enabled by visitors.

It also shows an entirely synthetic property that is not tied to device state.

---
 hw/mc146818rtc.c |   27 +++++++++++++++++++++++++++
 1 files changed, 27 insertions(+), 0 deletions(-)
hw/mc146818rtc.c +27 -0
index 2aaca2f..0c23cb0 100644
@@ -614,6 +614,29 @@ static const MemoryRegionOps cmos_ops = {
     .old_portio = cmos_portio
 };
 
+// FIXME add int32 visitor
+static void visit_type_int32(Visitor *v, int *value, const char *name, Error **errp)
+{
+    int64_t val = *value;
+    visit_type_int(v, &val, name, errp);
+}
+
+static void rtc_get_date(DeviceState *dev, Visitor *v, void *opaque,
+                         const char *name, Error **errp)
+{
+    ISADevice *isa = DO_UPCAST(ISADevice, qdev, dev);
+    RTCState *s = DO_UPCAST(RTCState, dev, isa);
+
+    visit_start_struct(v, NULL, "struct tm", name, 0, errp);
+    visit_type_int32(v, &s->current_tm.tm_year, "tm_year", errp);
+    visit_type_int32(v, &s->current_tm.tm_mon, "tm_mon", errp);
+    visit_type_int32(v, &s->current_tm.tm_mday, "tm_mday", errp);
+    visit_type_int32(v, &s->current_tm.tm_hour, "tm_hour", errp);
+    visit_type_int32(v, &s->current_tm.tm_min, "tm_min", errp);
+    visit_type_int32(v, &s->current_tm.tm_sec, "tm_sec", errp);
+    visit_end_struct(v, errp);
+}
+
 static int rtc_initfn(ISADevice *dev)
 {
     RTCState *s = DO_UPCAST(RTCState, dev, dev);
@@ -647,6 +670,10 @@ static int rtc_initfn(ISADevice *dev)
 
     qdev_set_legacy_instance_id(&dev->qdev, base, 2);
     qemu_register_reset(rtc_reset, s);
+
+    qdev_property_add(&s->dev.qdev, "date", "struct tm",
+                      rtc_get_date, NULL, NULL, s, NULL);
+
     return 0;
 }
 
Signature · 1 line
1.7.4.1
#17 lore raw

PATCH v3 16/197 qom: optimize qdev_get_canonical_path using a parent link

In reply to Anthony Liguori

The full tree search was a bit unreasonable.

---
 hw/qdev.c |   56 ++++++++++++++++++++++++--------------------------------
 hw/qdev.h |    4 ++++
 2 files changed, 28 insertions(+), 32 deletions(-)
hw/qdev.c +24 -32
index 5348f26..1102efd 100644
@@ -1229,6 +1229,8 @@ void qdev_property_add_child(DeviceState *dev, const char *name,
                       NULL, NULL, child, errp);
 
     qdev_ref(dev);
+    g_assert(child->parent == NULL);
+    child->parent = dev;
 
     g_free(type);
 }
@@ -1307,48 +1309,38 @@ void qdev_property_add_link(DeviceState *dev, const char *name,
     g_free(full_type);
 }
 
-static gchar *qdev_get_path_in(DeviceState *parent, DeviceState *dev)
+gchar *qdev_get_canonical_path(DeviceState *dev)
 {
-    DeviceProperty *prop;
+    DeviceState *root = qdev_get_root();
+    char *newpath = NULL, *path = NULL;
 
-    if (parent == dev) {
-        return g_strdup("");
-    }
+    while (dev != root) {
+        DeviceProperty *prop = NULL;
 
-    QTAILQ_FOREACH(prop, &parent->properties, node) {
-        gchar *subpath;
+        g_assert(dev->parent != NULL);
 
-        if (!strstart(prop->type, "child<", NULL)) {
-            continue;
-        }
+        QTAILQ_FOREACH(prop, &dev->parent->properties, node) {
+            if (!strstart(prop->type, "child<", NULL)) {
+                continue;
+            }
 
-        /* Check to see if the device is one of parent's children */
-        if (prop->opaque == dev) {
-            return g_strdup(prop->name);
+            if (prop->opaque == dev) {
+                if (path) {
+                    newpath = g_strdup_printf("%s/%s", prop->name, path);
+                    g_free(path);
+                    path = newpath;
+                } else {
+                    path = g_strdup(prop->name);
+                }
+                break;
+            }
         }
 
-        /* Check to see if the device is a child of our child */
-        subpath = qdev_get_path_in(prop->opaque, dev);
-        if (subpath) {
-            gchar *path;
+        g_assert(prop != NULL);
 
-            path = g_strdup_printf("%s/%s", prop->name, subpath);
-            g_free(subpath);
-
-            return path;
-        }
+        dev = dev->parent;
     }
 
-    return NULL;
-}
-
-gchar *qdev_get_canonical_path(DeviceState *dev)
-{
-    gchar *path, *newpath;
-
-    path = qdev_get_path_in(qdev_get_root(), dev);
-    g_assert(path != NULL);
-
     newpath = g_strdup_printf("/%s", path);
     g_free(path);
 
hw/qdev.h +4 -0
index 4351e2e..fdab848 100644
@@ -92,6 +92,10 @@ struct DeviceState {
     uint32_t ref;
 
     QTAILQ_HEAD(, DeviceProperty) properties;
+
+    /* Do not, under any circumstance, use this parent link below anywhere
+     * outside of qdev.c.  You have been warned. */
+    DeviceState *parent;
 };
 
 typedef void (*bus_dev_printfn)(Monitor *mon, DeviceState *dev, int indent);
Signature · 1 line
1.7.4.1
#18 lore raw

PATCH v3 17/197 qmp: make qmp.py easier to use

In reply to Anthony Liguori
---
 QMP/qmp.py |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
QMP/qmp.py +6 -0
index c7dbea0..36ecc1d 100644
@@ -128,6 +128,12 @@ class QEMUMonitorProtocol:
             qmp_cmd['id'] = id
         return self.cmd_obj(qmp_cmd)
 
+    def command(self, cmd, **kwds):
+        ret = self.cmd(cmd, kwds)
+        if ret.has_key('error'):
+            raise Exception(ret['error']['desc'])
+        return ret['return']
+
     def get_events(self, wait=False):
         """
         Get a list of available QMP events.
Signature · 1 line
1.7.4.1
#19 lore raw

PATCH v3 18/197 qom: add test tools (v2)

In reply to Anthony Liguori

---
v1 -> v2
- fix comments (Stefan)

---
 QMP/qom-get  |   26 ++++++++++++++++++++++++++
 QMP/qom-list |   30 ++++++++++++++++++++++++++++++
 QMP/qom-set  |   21 +++++++++++++++++++++
 3 files changed, 77 insertions(+), 0 deletions(-)
 create mode 100755 QMP/qom-get
 create mode 100755 QMP/qom-list
 create mode 100755 QMP/qom-set
QMP/qom-get new file +26 -0
new file mode 100755
index 0000000..e6c063a
@@ -0,0 +1,26 @@
+#!/usr/bin/python
+##
+# QEMU Object Model test tools
+#
+# Copyright IBM, Corp. 2011
+#
+# Authors:
+#  Anthony Liguori   <[email protected]>
+#
+# This work is licensed under the terms of the GNU GPL, version 2 or later.  See
+# the COPYING file in the top-level directory.
+##
+
+import sys
+from qmp import QEMUMonitorProtocol
+
+srv = QEMUMonitorProtocol('/tmp/server.sock')
+srv.connect()
+
+path, prop = sys.argv[1].rsplit('.', 1)
+rsp = srv.command('qom-get', path=path, property=prop)
+if type(rsp) == dict:
+    for i in rsp.keys():
+        print '%s: %s' % (i, rsp[i])
+else:
+    print rsp
QMP/qom-list new file +30 -0
new file mode 100755
index 0000000..b91f814
@@ -0,0 +1,30 @@
+#!/usr/bin/python
+##
+# QEMU Object Model test tools
+#
+# Copyright IBM, Corp. 2011
+#
+# Authors:
+#  Anthony Liguori   <[email protected]>
+#
+# This work is licensed under the terms of the GNU GPL, version 2 or later.  See
+# the COPYING file in the top-level directory.
+##
+
+import sys
+from qmp import QEMUMonitorProtocol
+
+srv = QEMUMonitorProtocol('/tmp/server.sock')
+srv.connect()
+
+if len(sys.argv) == 1:
+    print '/'
+    sys.exit(0)
+
+for item in srv.command('qom-list', path=sys.argv[1]):
+    if item['type'].startswith('child<'):
+        print '%s/' % item['name']
+    elif item['type'].startswith('link<'):
+        print '@%s/' % item['name']
+    else:
+        print '%s' % item['name']
QMP/qom-set new file +21 -0
new file mode 100755
index 0000000..c5589d8
@@ -0,0 +1,21 @@
+#!/usr/bin/python
+##
+# QEMU Object Model test tools
+#
+# Copyright IBM, Corp. 2011
+#
+# Authors:
+#  Anthony Liguori   <[email protected]>
+#
+# This work is licensed under the terms of the GNU GPL, version 2 or later.  See
+# the COPYING file in the top-level directory.
+##
+
+import sys
+from qmp import QEMUMonitorProtocol
+
+srv = QEMUMonitorProtocol('/tmp/server.sock')
+srv.connect()
+
+path, prop = sys.argv[1].rsplit('.', 1)
+print srv.command('qom-set', path=path, property=prop, value=sys.argv[2])
Signature · 1 line
1.7.4.1
#20 lore raw

PATCH v3 19/197 bug fix spotted by paolo

In reply to Anthony Liguori
---
 hw/qdev.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
hw/qdev.c +1 -1
index 1102efd..4004860 100644
@@ -1228,7 +1228,7 @@ void qdev_property_add_child(DeviceState *dev, const char *name,
     qdev_property_add(dev, name, type, qdev_get_child_property,
                       NULL, NULL, child, errp);
 
-    qdev_ref(dev);
+    qdev_ref(child);
     g_assert(child->parent == NULL);
     child->parent = dev;
 
Signature · 1 line
1.7.4.1
#21 lore raw

PATCH v3 20/197 qom: add vga node to the pc composition tree

In reply to Anthony Liguori
---
 hw/cirrus_vga.c |    8 +++++---
 hw/pc.c         |   26 ++++++++++++++++----------
 hw/pc.h         |   14 +++++++-------
 hw/pc_piix.c    |    6 +++++-
 hw/vga-pci.c    |    5 ++---
 hw/vmware_vga.h |    6 +++---
 6 files changed, 38 insertions(+), 27 deletions(-)
hw/cirrus_vga.c +5 -3
index c7e365b..c0db315 100644
@@ -2899,7 +2899,7 @@ static void cirrus_init_common(CirrusVGAState * s, int device_id, int is_pci,
  *
  ***************************************/
 
-void isa_cirrus_vga_init(MemoryRegion *system_memory)
+DeviceState *isa_cirrus_vga_init(MemoryRegion *system_memory)
 {
     CirrusVGAState *s;
 
@@ -2913,6 +2913,8 @@ void isa_cirrus_vga_init(MemoryRegion *system_memory)
     vmstate_register(NULL, 0, &vmstate_cirrus_vga, s);
     rom_add_vga(VGABIOS_CIRRUS_FILENAME);
     /* XXX ISA-LFB support */
+    /* FIXME not qdev yet */
+    return NULL;
 }
 
 /***************************************
@@ -2955,9 +2957,9 @@ static int pci_cirrus_vga_initfn(PCIDevice *dev)
      return 0;
 }
 
-void pci_cirrus_vga_init(PCIBus *bus)
+DeviceState *pci_cirrus_vga_init(PCIBus *bus)
 {
-    pci_create_simple(bus, -1, "cirrus-vga");
+    return &pci_create_simple(bus, -1, "cirrus-vga")->qdev;
 }
 
 static PCIDeviceInfo cirrus_vga_info = {
hw/pc.c +16 -10
index 33778fe..2fd124a 100644
@@ -1069,38 +1069,44 @@ qemu_irq *pc_allocate_cpu_irq(void)
     return qemu_allocate_irqs(pic_irq_request, NULL, 1);
 }
 
-void pc_vga_init(PCIBus *pci_bus)
+DeviceState *pc_vga_init(PCIBus *pci_bus)
 {
+    DeviceState *dev = NULL;
+
     if (cirrus_vga_enabled) {
         if (pci_bus) {
-            pci_cirrus_vga_init(pci_bus);
+            dev = pci_cirrus_vga_init(pci_bus);
         } else {
-            isa_cirrus_vga_init(get_system_memory());
+            dev = isa_cirrus_vga_init(get_system_memory());
         }
     } else if (vmsvga_enabled) {
         if (pci_bus) {
-            if (!pci_vmsvga_init(pci_bus)) {
+            dev = pci_vmsvga_init(pci_bus);
+            if (!dev) {
                 fprintf(stderr, "Warning: vmware_vga not available,"
                         " using standard VGA instead\n");
-                pci_vga_init(pci_bus);
+                dev = pci_vga_init(pci_bus);
             }
         } else {
             fprintf(stderr, "%s: vmware_vga: no PCI bus\n", __FUNCTION__);
         }
 #ifdef CONFIG_SPICE
     } else if (qxl_enabled) {
-        if (pci_bus)
-            pci_create_simple(pci_bus, -1, "qxl-vga");
-        else
+        if (pci_bus) {
+            dev = &pci_create_simple(pci_bus, -1, "qxl-vga")->qdev;
+        } else {
             fprintf(stderr, "%s: qxl: no PCI bus\n", __FUNCTION__);
+        }
 #endif
     } else if (std_vga_enabled) {
         if (pci_bus) {
-            pci_vga_init(pci_bus);
+            dev = pci_vga_init(pci_bus);
         } else {
-            isa_vga_init();
+            dev = isa_vga_init();
         }
     }
+
+    return dev;
 }
 
 static void cpu_request_exit(void *opaque, int irq, int level)
hw/pc.h +7 -7
index 4515006..8d2e553 100644
@@ -139,7 +139,7 @@ void pc_memory_init(MemoryRegion *system_memory,
                     MemoryRegion *rom_memory,
                     MemoryRegion **ram_memory);
 qemu_irq *pc_allocate_cpu_irq(void);
-void pc_vga_init(PCIBus *pci_bus);
+DeviceState *pc_vga_init(PCIBus *pci_bus);
 void pc_basic_device_init(qemu_irq *gsi,
                           ISADevice **rtc_state,
                           ISADevice **floppy,
@@ -204,27 +204,27 @@ enum vga_retrace_method {
 
 extern enum vga_retrace_method vga_retrace_method;
 
-static inline int isa_vga_init(void)
+static inline DeviceState *isa_vga_init(void)
 {
     ISADevice *dev;
 
     dev = isa_try_create("isa-vga");
     if (!dev) {
         fprintf(stderr, "Warning: isa-vga not available\n");
-        return 0;
+        return NULL;
     }
     qdev_init_nofail(&dev->qdev);
-    return 1;
+    return &dev->qdev;
 }
 
-int pci_vga_init(PCIBus *bus);
+DeviceState *pci_vga_init(PCIBus *bus);
 int isa_vga_mm_init(target_phys_addr_t vram_base,
                     target_phys_addr_t ctrl_base, int it_shift,
                     MemoryRegion *address_space);
 
 /* cirrus_vga.c */
-void pci_cirrus_vga_init(PCIBus *bus);
-void isa_cirrus_vga_init(MemoryRegion *address_space);
+DeviceState *pci_cirrus_vga_init(PCIBus *bus);
+DeviceState *isa_cirrus_vga_init(MemoryRegion *address_space);
 
 /* ne2000.c */
 static inline bool isa_ne2000_init(int base, int irq, NICInfo *nd)
hw/pc_piix.c +5 -1
index 2d5ea2c..166c2fc 100644
@@ -99,6 +99,7 @@ static void pc_init1(MemoryRegion *system_memory,
     MemoryRegion *ram_memory;
     MemoryRegion *pci_memory;
     MemoryRegion *rom_memory;
+    DeviceState *dev;
 
     pc_cpus_init(cpu_model);
 
@@ -168,7 +169,10 @@ static void pc_init1(MemoryRegion *system_memory,
 
     pc_register_ferr_irq(gsi[13]);
 
-    pc_vga_init(pci_enabled? pci_bus: NULL);
+    dev = pc_vga_init(pci_enabled? pci_bus: NULL);
+    if (dev) {
+        qdev_property_add_child(qdev_get_root(), "vga", dev, NULL);
+    }
 
     if (xen_enabled()) {
         pci_create_simple(pci_bus, -1, "xen-platform");
hw/vga-pci.c +2 -3
index 14bfadb..a75dbf3 100644
@@ -70,10 +70,9 @@ static int pci_vga_initfn(PCIDevice *dev)
      return 0;
 }
 
-int pci_vga_init(PCIBus *bus)
+DeviceState *pci_vga_init(PCIBus *bus)
 {
-    pci_create_simple(bus, -1, "VGA");
-    return 0;
+    return &pci_create_simple(bus, -1, "VGA")->qdev;
 }
 
 static PCIDeviceInfo vga_info = {
hw/vmware_vga.h +3 -3
index 5132573..db11cbf 100644
@@ -4,15 +4,15 @@
 #include "qemu-common.h"
 
 /* vmware_vga.c */
-static inline bool pci_vmsvga_init(PCIBus *bus)
+static inline DeviceState *pci_vmsvga_init(PCIBus *bus)
 {
     PCIDevice *dev;
 
     dev = pci_try_create(bus, -1, "vmware-svga");
     if (!dev || qdev_init(&dev->qdev) < 0) {
-        return false;
+        return NULL;
     } else {
-        return true;
+        return &dev->qdev;
     }
 }
 
Signature · 1 line
1.7.4.1
#22 lore raw

PATCH v3 21/197 qom: add string property type

In reply to Anthony Liguori
---
 hw/qdev.c |   59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/qdev.h |   22 ++++++++++++++++++++++
 2 files changed, 81 insertions(+), 0 deletions(-)
hw/qdev.c +59 -0
index 4004860..0fc20fc 100644
@@ -1449,3 +1449,62 @@ DeviceState *qdev_resolve_path(const char *path, bool *ambiguous)
     return dev;
 }
 
+typedef struct StringProperty
+{
+    char *(*get)(DeviceState *, Error **);
+    void (*set)(DeviceState *, const char *, Error **);
+} StringProperty;
+
+static void qdev_property_get_str(DeviceState *dev, Visitor *v, void *opaque,
+                                  const char *name, Error **errp)
+{
+    StringProperty *prop = opaque;
+    char *value;
+
+    value = prop->get(dev, errp);
+    if (value) {
+        visit_type_str(v, &value, name, errp);
+        g_free(value);
+    }
+}
+
+static void qdev_property_set_str(DeviceState *dev, Visitor *v, void *opaque,
+                                  const char *name, Error **errp)
+{
+    StringProperty *prop = opaque;
+    char *value;
+    Error *local_err = NULL;
+
+    visit_type_str(v, &value, name, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        return;
+    }
+
+    prop->set(dev, value, errp);
+    g_free(value);
+}
+
+static void qdev_property_release_str(DeviceState *dev, const char *name,
+                                      void *opaque)
+{
+    StringProperty *prop = opaque;
+    g_free(prop);
+}
+
+void qdev_property_add_str(DeviceState *dev, const char *name,
+                           char *(*get)(DeviceState *, Error **),
+                           void (*set)(DeviceState *, const char *, Error **),
+                           Error **errp)
+{
+    StringProperty *prop = g_malloc0(sizeof(*prop));
+
+    prop->get = get;
+    prop->set = set;
+
+    qdev_property_add(dev, name, "string",
+                      get ? qdev_property_get_str : NULL,
+                      set ? qdev_property_set_str : NULL,
+                      qdev_property_release_str,
+                      prop, errp);
+}
hw/qdev.h +22 -0
index fdab848..9faf2ee 100644
@@ -574,4 +574,26 @@ void qdev_property_add_link(DeviceState *dev, const char *name,
                             const char *type, DeviceState **child,
                             Error **errp);
 
+/**
+ * @qdev_property_add_str
+ *
+ * Add a string property using getters/setters.  This function will add a
+ * property of type 'string'.
+ *
+ * @dev - the device to add a property to
+ *
+ * @name - the name of the property
+ *
+ * @get - the getter or NULL if the property is write-only.  This function must
+ *        return a string to be freed by @g_free().
+ *
+ * @set - the setter or NULL if the property is read-only
+ *
+ * @errp - if an error occurs, a pointer to an area to store the error
+ */
+void qdev_property_add_str(DeviceState *dev, const char *name,
+                           char *(*get)(DeviceState *, Error **),
+                           void (*set)(DeviceState *, const char *, Error **),
+                           Error **errp);
+
 #endif
Signature · 1 line
1.7.4.1
#23 lore raw

PATCH v3 22/197 qdev: add a qdev_get_type() function and expose as a 'type' property

In reply to Anthony Liguori
---
 hw/qdev.c |    7 +++++++
 hw/qdev.h |   14 ++++++++++++++
 2 files changed, 21 insertions(+), 0 deletions(-)
hw/qdev.c +7 -0
index 0fc20fc..83913c7 100644
@@ -110,6 +110,8 @@ static DeviceState *qdev_create_from_info(BusState *bus, DeviceInfo *info)
         qdev_property_add_legacy(dev, prop, NULL);
     }
 
+    qdev_property_add_str(dev, "type", qdev_get_type, NULL, NULL);
+
     return dev;
 }
 
@@ -1031,6 +1033,11 @@ char* qdev_get_fw_dev_path(DeviceState *dev)
     return strdup(path);
 }
 
+char *qdev_get_type(DeviceState *dev, Error **errp)
+{
+    return g_strdup(dev->info->name);
+}
+
 void qdev_ref(DeviceState *dev)
 {
     dev->ref++;
hw/qdev.h +14 -0
index 9faf2ee..6e18427 100644
@@ -596,4 +596,18 @@ void qdev_property_add_str(DeviceState *dev, const char *name,
                            void (*set)(DeviceState *, const char *, Error **),
                            Error **errp);
 
+/**
+ * @qdev_get_type
+ *
+ * Returns the string representation of the type of this object.
+ *
+ * @dev - the device
+ *
+ * @errp - if an error occurs, a pointer to an area to store the error
+ *
+ * Returns: a string representing the type.  This must be freed by the caller
+ *          with g_free().
+ */
+char *qdev_get_type(DeviceState *dev, Error **errp);
+
 #endif
Signature · 1 line
1.7.4.1
#24 lore raw

PATCH v3 23/197 pc: fill out most of the composition tree

In reply to Anthony Liguori
---
 hw/acpi_piix4.c |    7 +++--
 hw/ide/pci.c    |   11 +++++++-
 hw/kvmclock.c   |    5 ++-
 hw/kvmclock.h   |    5 ++-
 hw/pc.c         |   49 ++++++++++++++++++++++++++++++++-------
 hw/pc.h         |   37 ++++++++++++++++-------------
 hw/pc_piix.c    |   68 ++++++++++++++++++++++++++++++++++--------------------
 hw/piix_pci.c   |   12 +++++++--
 hw/usb-uhci.c   |    4 +-
 hw/usb-uhci.h   |    2 +-
 10 files changed, 134 insertions(+), 66 deletions(-)
hw/acpi_piix4.c +4 -3
index d9075e6..401baaa 100644
@@ -372,14 +372,15 @@ static int piix4_pm_initfn(PCIDevice *dev)
     return 0;
 }
 
-i2c_bus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
-                       qemu_irq sci_irq, qemu_irq cmos_s3, qemu_irq smi_irq,
-                       int kvm_enabled)
+i2c_bus *piix4_pm_init(PCIBus *bus, DeviceState **pdev, int devfn,
+                       uint32_t smb_io_base, qemu_irq sci_irq,
+                       qemu_irq cmos_s3, qemu_irq smi_irq, int kvm_enabled)
 {
     PCIDevice *dev;
     PIIX4PMState *s;
 
     dev = pci_create(bus, devfn, "PIIX4_PM");
+    *pdev = &dev->qdev;
     qdev_prop_set_uint32(&dev->qdev, "smb_io_base", smb_io_base);
 
     s = DO_UPCAST(PIIX4PMState, dev, dev);
hw/ide/pci.c +9 -2
index 49b823d..897bca2 100644
@@ -498,9 +498,16 @@ void pci_ide_create_devs(PCIDevice *dev, DriveInfo **hd_table)
     int i;
 
     for (i = 0; i < 4; i++) {
-        if (hd_table[i] == NULL)
+        char name[32];
+        IDEDevice *c;
+
+        if (hd_table[i] == NULL) {
             continue;
-        ide_create_drive(d->bus+bus[i], unit[i], hd_table[i]);
+        }
+
+        c = ide_create_drive(d->bus+bus[i], unit[i], hd_table[i]);
+        snprintf(name, sizeof(name), "drive[%d]", i);
+        qdev_property_add_child(&dev->qdev, name, &c->qdev, NULL);
     }
 }
 
hw/kvmclock.c +3 -2
index 5388bc4..ddfaf3c 100644
@@ -99,13 +99,14 @@ static SysBusDeviceInfo kvmclock_info = {
 };
 
 /* Note: Must be called after VCPU initialization. */
-void kvmclock_create(void)
+DeviceState *kvmclock_create(void)
 {
     if (kvm_enabled() &&
         first_cpu->cpuid_kvm_features & ((1ULL << KVM_FEATURE_CLOCKSOURCE) |
                                          (1ULL << KVM_FEATURE_CLOCKSOURCE2))) {
-        sysbus_create_simple("kvmclock", -1, NULL);
+        return sysbus_create_simple("kvmclock", -1, NULL);
     }
+    return NULL;
 }
 
 static void kvmclock_register_device(void)
hw/kvmclock.h +3 -2
index 252ea13..40dda86 100644
@@ -13,12 +13,13 @@
 
 #ifdef CONFIG_KVM
 
-void kvmclock_create(void);
+DeviceState *kvmclock_create(void);
 
 #else /* CONFIG_KVM */
 
-static inline void kvmclock_create(void)
+static inline DeviceState *kvmclock_create(void)
 {
+    return NULL;
 }
 
 #endif /* !CONFIG_KVM */
hw/pc.c +40 -9

118 lines not on this page · raw message

hw/pc.h +20 -17
index 8d2e553..cd64755 100644
@@ -20,39 +20,39 @@ SerialState *serial_mm_init(MemoryRegion *address_space,
                             target_phys_addr_t base, int it_shift,
                             qemu_irq irq, int baudbase,
                             CharDriverState *chr, enum device_endian);
-static inline bool serial_isa_init(int index, CharDriverState *chr)
+static inline DeviceState *serial_isa_init(int index, CharDriverState *chr)
 {
     ISADevice *dev;
 
     dev = isa_try_create("isa-serial");
     if (!dev) {
-        return false;
+        return NULL;
     }
     qdev_prop_set_uint32(&dev->qdev, "index", index);
     qdev_prop_set_chr(&dev->qdev, "chardev", chr);
     if (qdev_init(&dev->qdev) < 0) {
-        return false;
+        return NULL;
     }
-    return true;
+    return &dev->qdev;
 }
 
 void serial_set_frequency(SerialState *s, uint32_t frequency);
 
 /* parallel.c */
-static inline bool parallel_init(int index, CharDriverState *chr)
+static inline DeviceState *parallel_init(int index, CharDriverState *chr)
 {
     ISADevice *dev;
 
     dev = isa_try_create("isa-parallel");
     if (!dev) {
-        return false;
+        return NULL;
     }
     qdev_prop_set_uint32(&dev->qdev, "index", index);
     qdev_prop_set_chr(&dev->qdev, "chardev", chr);
     if (qdev_init(&dev->qdev) < 0) {
-        return false;
+        return NULL;
     }
-    return true;
+    return &dev->qdev;
 }
 
 bool parallel_mm_init(target_phys_addr_t base, int it_shift, qemu_irq irq,
@@ -140,16 +140,18 @@ void pc_memory_init(MemoryRegion *system_memory,
                     MemoryRegion **ram_memory);
 qemu_irq *pc_allocate_cpu_irq(void);
 DeviceState *pc_vga_init(PCIBus *pci_bus);
-void pc_basic_device_init(qemu_irq *gsi,
+void pc_basic_device_init(DeviceState *board,
+                          DeviceState *superio,
+                          qemu_irq *gsi,
                           ISADevice **rtc_state,
                           ISADevice **floppy,
                           bool no_vmport);
-void pc_init_ne2k_isa(NICInfo *nd);
+DeviceState *pc_init_ne2k_isa(NICInfo *nd);
 void pc_cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size,
                   const char *boot_device,
                   ISADevice *floppy, BusState *ide0, BusState *ide1,
                   ISADevice *s);
-void pc_pci_device_init(PCIBus *pci_bus);
+void pc_pci_device_init(PCIBus *pci_bus, DeviceState *board);
 
 typedef void (*cpu_set_smm_t)(int smm, void *arg);
 void cpu_smm_register(cpu_set_smm_t callback, void *arg);
@@ -164,9 +166,9 @@ int acpi_table_add(const char *table_desc);
 
 /* acpi_piix.c */
 
-i2c_bus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
-                       qemu_irq sci_irq, qemu_irq cmos_s3, qemu_irq smi_irq,
-                       int kvm_enabled);
+i2c_bus *piix4_pm_init(PCIBus *bus, DeviceState **pdev, int devfn,
+                       uint32_t smb_io_base, qemu_irq sci_irq,
+                       qemu_irq cmos_s3, qemu_irq smi_irq, int kvm_enabled);
 void piix4_smbus_register_device(SMBusDevice *dev, uint8_t addr);
 
 /* hpet.c */
@@ -181,6 +183,7 @@ struct PCII440FXState;
 typedef struct PCII440FXState PCII440FXState;
 
 PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix_devfn,
+                    DeviceState **i440fx, DeviceState **piix3,
                     qemu_irq *pic,
                     MemoryRegion *address_space_mem,
                     MemoryRegion *address_space_io,
@@ -227,7 +230,7 @@ DeviceState *pci_cirrus_vga_init(PCIBus *bus);
 DeviceState *isa_cirrus_vga_init(MemoryRegion *address_space);
 
 /* ne2000.c */
-static inline bool isa_ne2000_init(int base, int irq, NICInfo *nd)
+static inline DeviceState *isa_ne2000_init(int base, int irq, NICInfo *nd)
 {
     ISADevice *dev;
 
@@ -235,13 +238,13 @@ static inline bool isa_ne2000_init(int base, int irq, NICInfo *nd)
 
     dev = isa_try_create("ne2k_isa");
     if (!dev) {
-        return false;
+        return NULL;
     }
     qdev_prop_set_uint32(&dev->qdev, "iobase", base);
     qdev_prop_set_uint32(&dev->qdev, "irq",    irq);
     qdev_set_nic_properties(&dev->qdev, nd);
     qdev_init_nofail(&dev->qdev);
-    return true;
+    return &dev->qdev;
 }
 
 /* e820 types */
hw/pc_piix.c +43 -25

158 lines not on this page · raw message

hw/piix_pci.c +9 -3
index d785d4b..e690ee1 100644
@@ -262,6 +262,7 @@ static int i440fx_initfn(PCIDevice *dev)
 
 static PCIBus *i440fx_common_init(const char *device_name,
                                   PCII440FXState **pi440fx_state,
+                                  DeviceState **i440fx,
                                   int *piix3_devfn,
                                   qemu_irq *pic,
                                   MemoryRegion *address_space_mem,
@@ -288,7 +289,7 @@ static PCIBus *i440fx_common_init(const char *device_name,
                     address_space_io, 0);
     s->bus = b;
     qdev_init_nofail(dev);
-    qdev_property_add_child(qdev_get_root(), "i440fx", dev, NULL);
+    *i440fx = dev;
 
     d = pci_create_simple(b, 0, device_name);
     *pi440fx_state = DO_UPCAST(PCII440FXState, dev, d);
@@ -296,6 +297,9 @@ static PCIBus *i440fx_common_init(const char *device_name,
     f->system_memory = address_space_mem;
     f->pci_address_space = pci_address_space;
     f->ram_memory = ram_memory;
+
+    qdev_property_add_child(dev, "i440fx", &d->qdev, NULL);
+
     memory_region_init_alias(&f->pci_hole, "pci-hole", f->pci_address_space,
                              pci_hole_start, pci_hole_size);
     memory_region_add_subregion(f->system_memory, pci_hole_start, &f->pci_hole);
@@ -325,7 +329,7 @@ static PCIBus *i440fx_common_init(const char *device_name,
         pci_bus_irqs(b, piix3_set_irq, pci_slot_get_pirq, piix3,
                 PIIX_NUM_PIRQS);
 
-        qdev_property_add_child(dev, "piix3", &piix3->dev.qdev, NULL);
+        qdev_property_add_child(&d->qdev, "piix3", &piix3->dev.qdev, NULL);
     }
     piix3->pic = pic;
 
@@ -344,6 +348,7 @@ static PCIBus *i440fx_common_init(const char *device_name,
 }
 
 PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix3_devfn,
+                    DeviceState **i440fx, DeviceState **piix3,
                     qemu_irq *pic,
                     MemoryRegion *address_space_mem,
                     MemoryRegion *address_space_io,
@@ -357,11 +362,12 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix3_devfn,
 {
     PCIBus *b;
 
-    b = i440fx_common_init("i440FX", pi440fx_state, piix3_devfn, pic,
+    b = i440fx_common_init("i440FX", pi440fx_state, i440fx, piix3_devfn, pic,
                            address_space_mem, address_space_io, ram_size,
                            pci_hole_start, pci_hole_size,
                            pci_hole64_size, pci_hole64_size,
                            pci_memory, ram_memory);
+    *piix3 = &(*pi440fx_state)->piix3->dev.qdev;
     return b;
 }
 
hw/usb-uhci.c +2 -2
index f9e3ea5..3e4456a 100644
@@ -1269,9 +1269,9 @@ static void uhci_register(void)
 }
 device_init(uhci_register);
 
-void usb_uhci_piix3_init(PCIBus *bus, int devfn)
+DeviceState *usb_uhci_piix3_init(PCIBus *bus, int devfn)
 {
-    pci_create_simple(bus, devfn, "piix3-usb-uhci");
+    return &pci_create_simple(bus, devfn, "piix3-usb-uhci")->qdev;
 }
 
 void usb_uhci_piix4_init(PCIBus *bus, int devfn)
hw/usb-uhci.h +1 -1
index 3e4d377..1fef610 100644
@@ -3,7 +3,7 @@
 
 #include "qemu-common.h"
 
-void usb_uhci_piix3_init(PCIBus *bus, int devfn);
+DeviceState *usb_uhci_piix3_init(PCIBus *bus, int devfn);
 void usb_uhci_piix4_init(PCIBus *bus, int devfn);
 void usb_uhci_vt82c686b_init(PCIBus *bus, int devfn);
 
Signature · 1 line
1.7.4.1
#25 lore raw

PATCH v3 24/197 i440fx: split out piix3 device

In reply to Anthony Liguori
---
 Makefile.objs   |    3 +
 Makefile.target |    2 +-
 hw/piix3.c      |  181 ++++++++++++++++++++++++++++++++++++++++++
 hw/piix3.h      |   37 +++++++++
 hw/piix_pci.c   |  236 +++++--------------------------------------------------
 5 files changed, 242 insertions(+), 217 deletions(-)
 create mode 100644 hw/piix3.c
 create mode 100644 hw/piix3.h
Makefile.objs +3 -0
index 10e794c..bdc0e42 100644
@@ -293,6 +293,9 @@ hw-obj-$(CONFIG_DP8393X) += dp8393x.o
 hw-obj-$(CONFIG_DS1225Y) += ds1225y.o
 hw-obj-$(CONFIG_MIPSNET) += mipsnet.o
 
+# HW
+hw-obj-y += piix_pci.o piix3.o
+
 # Sound
 sound-obj-y =
 sound-obj-$(CONFIG_SB16) += sb16.o
Makefile.target +1 -1
index a111521..7f9cd30 100644
@@ -231,7 +231,7 @@ obj-$(CONFIG_IVSHMEM) += ivshmem.o
 # Hardware support
 obj-i386-y += vga.o
 obj-i386-y += mc146818rtc.o pc.o
-obj-i386-y += cirrus_vga.o sga.o apic.o ioapic.o piix_pci.o
+obj-i386-y += cirrus_vga.o sga.o apic.o ioapic.o
 obj-i386-y += vmport.o
 obj-i386-y += device-hotplug.o pci-hotplug.o smbios.o wdt_ib700.o
 obj-i386-y += debugcon.o multiboot.o
hw/piix3.c new file +181 -0

181 lines not on this page · raw message

hw/piix3.h new file +37 -0
new file mode 100644
index 0000000..73d4a6f
@@ -0,0 +1,37 @@
+#ifndef QEMU_PIIX3_H
+#define QEMU_PIIX3_H
+
+#include "hw/hw.h"
+#include "hw/pci.h"
+
+#define PIIX_NUM_PIC_IRQS       16      /* i8259 * 2 */
+#define PIIX_NUM_PIRQS          4ULL    /* PIRQ[A-D] */
+#define XEN_PIIX_NUM_PIRQS      128ULL
+#define PIIX_PIRQC              0x60
+
+typedef struct PIIX3State {
+    PCIDevice dev;
+
+    /*
+     * bitmap to track pic levels.
+     * The pic level is the logical OR of all the PCI irqs mapped to it
+     * So one PIC level is tracked by PIIX_NUM_PIRQS bits.
+     *
+     * PIRQ is mapped to PIC pins, we track it by
+     * PIIX_NUM_PIRQS * PIIX_NUM_PIC_IRQS = 64 bits with
+     * pic_irq * PIIX_NUM_PIRQS + pirq
+     */
+#if PIIX_NUM_PIC_IRQS * PIIX_NUM_PIRQS > 64
+#error "unable to encode pic state in 64bit in pic_levels."
+#endif
+    uint64_t pic_levels;
+
+    qemu_irq *pic;
+
+    /* This member isn't used. Just for save/load compatibility */
+    int32_t pci_irq_levels_vmstate[PIIX_NUM_PIRQS];
+} PIIX3State;
+
+void piix3_set_irq_level(PIIX3State *piix3, int pirq, int level);
+
+#endif
hw/piix_pci.c +20 -216

290 lines not on this page · raw message

Signature · 1 line
1.7.4.1
#26 lore raw

PATCH v3 25/197 i440fx: rename piix_pci -> i440fx

In reply to Anthony Liguori
---
 Makefile.objs |    2 +-
 hw/i440fx.c   |  381 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/piix_pci.c |  381 ---------------------------------------------------------
 3 files changed, 382 insertions(+), 382 deletions(-)
 create mode 100644 hw/i440fx.c
 delete mode 100644 hw/piix_pci.c
Makefile.objs +1 -1
index bdc0e42..67e1ae5 100644
@@ -294,7 +294,7 @@ hw-obj-$(CONFIG_DS1225Y) += ds1225y.o
 hw-obj-$(CONFIG_MIPSNET) += mipsnet.o
 
 # HW
-hw-obj-y += piix_pci.o piix3.o
+hw-obj-y += i440fx.o piix3.o
 
 # Sound
 sound-obj-y =
hw/i440fx.c new file +381 -0

381 lines not on this page · raw message

hw/piix_pci.c deleted +0 -381

381 lines not on this page · raw message

Signature · 1 line
1.7.4.1
#27 lore raw

PATCH v3 26/197 qom: add qobject

In reply to Anthony Liguori
---
 Makefile.objs |    2 +
 hw/qobject.c  |  463 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/qobject.h  |  471 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 936 insertions(+), 0 deletions(-)
 create mode 100644 hw/qobject.c
 create mode 100644 hw/qobject.h
Makefile.objs +2 -0
index 67e1ae5..8e629f1 100644
@@ -123,6 +123,8 @@ 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
 
+common-obj-y += qobject.o
+
 audio-obj-y = audio.o noaudio.o wavaudio.o mixeng.o
 audio-obj-$(CONFIG_SDL) += sdlaudio.o
 audio-obj-$(CONFIG_OSS) += ossaudio.o
hw/qobject.c new file +463 -0

463 lines not on this page · raw message

hw/qobject.h new file +471 -0

471 lines not on this page · raw message

Signature · 1 line
1.7.4.1
#28 lore raw

PATCH v3 27/197 rename qobject -> object

In reply to Anthony Liguori
---
 Makefile.objs |    2 +-
 hw/object.c   |  463 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/object.h   |  471 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/qdev.h     |    7 +
 hw/qobject.c  |  463 --------------------------------------------------------
 hw/qobject.h  |  471 ---------------------------------------------------------
 6 files changed, 942 insertions(+), 935 deletions(-)
 create mode 100644 hw/object.c
 create mode 100644 hw/object.h
 delete mode 100644 hw/qobject.c
 delete mode 100644 hw/qobject.h
Makefile.objs +1 -1
index 8e629f1..c77c0af 100644
@@ -123,7 +123,7 @@ 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
 
-common-obj-y += qobject.o
+common-obj-y += object.o
 
 audio-obj-y = audio.o noaudio.o wavaudio.o mixeng.o
 audio-obj-$(CONFIG_SDL) += sdlaudio.o
hw/object.c new file +463 -0

463 lines not on this page · raw message

hw/object.h new file +471 -0

471 lines not on this page · raw message

hw/qdev.h +7 -0
index 6e18427..0702b18 100644
@@ -6,6 +6,7 @@
 #include "qemu-char.h"
 #include "qemu-option.h"
 #include "qapi/qapi-visit-core.h"
+#include "qobject.h"
 
 typedef struct Property Property;
 
@@ -66,9 +67,15 @@ typedef struct DeviceProperty
     QTAILQ_ENTRY(DeviceProperty) node;
 } DeviceProperty;
 
+typedef struct DeviceClass {
+    QObjectClass 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 {
+    QObject parent_obj;
+
     const char *id;
     enum DevState state;
     QemuOpts *opts;
hw/qobject.c deleted +0 -463

463 lines not on this page · raw message

hw/qobject.h deleted +0 -471

471 lines not on this page · raw message

Signature · 1 line
1.7.4.1
#29 lore raw

PATCH v3 28/197 more renames

In reply to Anthony Liguori
---
 hw/object.h |    4 ++--
 hw/qdev.h   |    6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)
hw/object.h +2 -2
index 1ac2f92..834e89e 100644
@@ -11,8 +11,8 @@
  *
  */
 
-#ifndef QOBJECT_H
-#define QOBJECT_H
+#ifndef QEMU_OBJECT_H
+#define QEMU_OBJECT_H
 
 #include "qemu-common.h"
 
hw/qdev.h +3 -3
index 0702b18..aabaaa3 100644
@@ -6,7 +6,7 @@
 #include "qemu-char.h"
 #include "qemu-option.h"
 #include "qapi/qapi-visit-core.h"
-#include "qobject.h"
+#include "object.h"
 
 typedef struct Property Property;
 
@@ -68,13 +68,13 @@ typedef struct DeviceProperty
 } DeviceProperty;
 
 typedef struct DeviceClass {
-    QObjectClass parent_class;
+    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 {
-    QObject parent_obj;
+    Object parent_obj;
 
     const char *id;
     enum DevState state;
Signature · 1 line
1.7.4.1
#30 lore raw

PATCH v3 29/197 Start integration of qom w/qdev.

In reply to Anthony Liguori
---
 hw/object.c |   14 ++++++++++----
 hw/object.h |   16 +++++++++++++---
 hw/qdev.c   |   30 ++++++++++++++++++++++++++++--
 3 files changed, 51 insertions(+), 9 deletions(-)
hw/object.c +10 -4
index be61677..520591a 100644
@@ -17,7 +17,7 @@
 typedef struct InterfaceImpl
 {
     const char *parent;
-    void (*interface_initfn)(ObjectClass *class);
+    void (*interface_initfn)(ObjectClass *class, void *data);
     Type type;
 } InterfaceImpl;
 
@@ -33,8 +33,10 @@ typedef struct TypeImpl
     void (*base_init)(ObjectClass *klass);
     void (*base_finalize)(ObjectClass *klass);
 
-    void (*class_init)(ObjectClass *klass);
-    void (*class_finalize)(ObjectClass *klass);
+    void (*class_init)(ObjectClass *klass, void *data);
+    void (*class_finalize)(ObjectClass *klass, void *data);
+
+    void *class_data;
 
     void (*instance_init)(Object *obj);
     void (*instance_finalize)(Object *obj);
@@ -61,6 +63,8 @@ Type type_register_static(const TypeInfo *info)
 
     assert(info->name != NULL);
 
+    printf("Added type %s -> %s\n", info->name, info->parent);
+
     ti->name = info->name;
     ti->parent = info->parent;
     ti->type = type;
@@ -73,6 +77,7 @@ Type type_register_static(const TypeInfo *info)
 
     ti->class_init = info->class_init;
     ti->class_finalize = info->class_finalize;
+    ti->class_data = info->class_data;
 
     ti->instance_init = info->instance_init;
     ti->instance_finalize = info->instance_finalize;
@@ -114,6 +119,7 @@ static Type type_register_anonymous(const TypeInfo *info)
 
     ti->class_init = info->class_init;
     ti->class_finalize = info->class_finalize;
+    ti->class_data = info->class_data;
 
     ti->instance_init = info->instance_init;
     ti->instance_finalize = info->instance_finalize;
@@ -237,7 +243,7 @@ static void type_class_init(TypeImpl *ti)
     }
 
     if (ti->class_init) {
-        ti->class_init(ti->class);
+        ti->class_init(ti->class, ti->class_data);
     }
 }
 
hw/object.h +13 -3
index 834e89e..b02709e 100644
@@ -27,6 +27,8 @@ typedef struct InterfaceClass InterfaceClass;
 typedef struct Interface Interface;
 typedef struct InterfaceInfo InterfaceInfo;
 
+#define TYPE_OBJECT NULL
+
 /**
  * @ObjectClass:
  *
@@ -183,7 +185,7 @@ struct TypeInfo
      * to allow a class to set its default virtual method pointers.  This is
      * also the function to use to override virtual methods from a parent class.
      */
-    void (*class_init)(ObjectClass *klass);
+    void (*class_init)(ObjectClass *klass, void *data);
 
     /**
      * @class_finalize
@@ -191,7 +193,15 @@ struct TypeInfo
      * This function is called during class destruction and is meant to release
      * and dynamic parameters allocated by @class_init.
      */
-    void (*class_finalize)(ObjectClass *klass);
+    void (*class_finalize)(ObjectClass *klass, void *data);
+
+    /**
+     * @class_data
+     *
+     * Data to pass to the @class_init and @class_finalize functions.  This can
+     * be useful when building dynamic classes.
+     */
+    void *class_data;
 
     /**
      * Interfaces
@@ -306,7 +316,7 @@ struct InterfaceInfo
      * initialize any default virtual functions for a class and/or override
      * virtual functions in a parent class.
      */
-    void (*interface_initfn)(ObjectClass *class);
+    void (*interface_initfn)(ObjectClass *class, void *data);
 };
 
 #define TYPE_INTERFACE "interface"
hw/qdev.c +28 -2
index 83913c7..7a5aa9f 100644
@@ -44,12 +44,23 @@ static BusState *qbus_find_recursive(BusState *bus, const char *name,
                                      const BusInfo *info);
 static BusState *qbus_find(const char *path);
 
+#define TYPE_DEVICE "device"
+#define DEVICE(obj) OBJECT_CHECK(DeviceState, (obj), TYPE_DEVICE)
+
 /* 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;
 }
@@ -86,7 +97,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);
@@ -484,7 +495,7 @@ void qdev_free(DeviceState *dev)
             prop->info->free(dev, prop);
         }
     }
-    g_free(dev);
+    object_delete(OBJECT(dev));
 }
 
 void qdev_machine_creation_done(void)
@@ -1515,3 +1526,18 @@ void qdev_property_add_str(DeviceState *dev, const char *name,
                       qdev_property_release_str,
                       prop, errp);
 }
+
+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);
Signature · 1 line
1.7.4.1
#31 lore raw

PATCH v3 30/197 qdev: move qdev->info to class

In reply to Anthony Liguori

Use an accessor to let clients cope.

---
 hw/acpi_piix4.c        |    4 +-
 hw/cirrus_vga.c        |    2 +-
 hw/e1000.c             |    2 +-
 hw/eepro100.c          |    4 +-
 hw/hda-audio.c         |    2 +-
 hw/ide/piix.c          |    6 ++++
 hw/intel-hda.c         |    6 ++--
 hw/lsi53c895a.c        |    2 +-
 hw/ne2000-isa.c        |    2 +-
 hw/ne2000.c            |    2 +-
 hw/pci.c               |   14 ++++----
 hw/pcnet.c             |    2 +-
 hw/qdev-properties.c   |   20 ++++++------
 hw/qdev.c              |   72 ++++++++++++++++++++++++++++-------------------
 hw/qdev.h              |   14 ++++++++-
 hw/rtl8139.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 |    8 ++--
 23 files changed, 103 insertions(+), 73 deletions(-)
hw/acpi_piix4.c +2 -2
index 401baaa..697f0de 100644
@@ -277,7 +277,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);
 
@@ -489,7 +489,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/cirrus_vga.c +1 -1
index c0db315..d6d9d70 100644
@@ -2927,7 +2927,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 986ed9c..ce30ad8 100644
@@ -1175,7 +1175,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 29ec5b4..287d1f1 100644
@@ -1849,7 +1849,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"));
 
@@ -1879,7 +1879,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/ide/piix.c +6 -0
index 08cbbe2..7d8f2c7 100644
@@ -164,6 +164,7 @@ static int pci_piix_ide_initfn(PCIDevice *dev)
     return 0;
 }
 
+#if 0
 static int pci_piix3_xen_ide_unplug(DeviceState *dev)
 {
     PCIDevice *pci_dev;
@@ -189,13 +190,18 @@ static int pci_piix3_xen_ide_unplug(DeviceState *dev)
     qdev_reset_all(&(pci_ide->dev.qdev));
     return 0;
 }
+#endif
 
 PCIDevice *pci_piix3_xen_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn)
 {
     PCIDevice *dev;
 
     dev = pci_create_simple(bus, devfn, "piix3-ide-xen");
+    /* FIXME: BROKEN! */
+    abort();
+#if 0
     dev->qdev.info->unplug = pci_piix3_xen_ide_unplug;
+#endif
     pci_ide_create_devs(dev, hd_table);
     return dev;
 }
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/lsi53c895a.c +1 -1
index fcc27d7..b313f83 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/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/pci.c +7 -7
index 399227f..46b7dac 100644
@@ -161,7 +161,7 @@ void pci_device_reset(PCIDevice *dev)
     int r;
     /* TODO: call the below unconditionally once all pci devices
      * are qdevified */
-    if (dev->qdev.info) {
+    if (qdev_get_info(&dev->qdev)) {
         qdev_reset_all(&dev->qdev);
     }
 
@@ -844,7 +844,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)
@@ -1534,7 +1534,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);
@@ -1760,10 +1760,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, &pdev->qdev, name, size);
     ptr = memory_region_get_ram_ptr(&pdev->rom);
@@ -2002,7 +2002,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 cba253b..e58b195 100644
@@ -1718,7 +1718,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 f0b811c..f235a26 100644
@@ -597,7 +597,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;
 
@@ -627,7 +627,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);
@@ -635,16 +635,16 @@ int qdev_prop_parse(DeviceState *dev, const char *name, const char *value)
         switch (ret) {
         case -EEXIST:
             qerror_report(QERR_PROPERTY_VALUE_IN_USE,
-                          dev->info->name, name, value);
+                          qdev_get_info(dev)->name, name, value);
             break;
         default:
         case -EINVAL:
             qerror_report(QERR_PROPERTY_VALUE_BAD,
-                          dev->info->name, name, value);
+                          qdev_get_info(dev)->name, name, value);
             break;
         case -ENOENT:
             qerror_report(QERR_PROPERTY_VALUE_NOT_FOUND,
-                          dev->info->name, name, value);
+                          qdev_get_info(dev)->name, name, value);
             break;
         }
         return -1;
@@ -659,12 +659,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);
@@ -713,7 +713,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;
     }
@@ -785,8 +785,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 +43 -29

206 lines not on this page · raw message

hw/qdev.h +12 -2
index aabaaa3..01dd1d6 100644
@@ -69,6 +69,7 @@ typedef struct DeviceProperty
 
 typedef struct DeviceClass {
     ObjectClass parent_class;
+    DeviceInfo *info;
 } DeviceClass;
 
 /* This structure should not be accessed directly.  We declare it here
@@ -80,7 +81,6 @@ struct DeviceState {
     enum DevState state;
     QemuOpts *opts;
     int hotplugged;
-    DeviceInfo *info;
     BusState *parent_bus;
     int num_gpio_out;
     qemu_irq *gpio_out;
@@ -378,9 +378,19 @@ void qdev_prop_set_defaults(DeviceState *dev, Property *props);
 void qdev_prop_register_global_list(GlobalProperty *props);
 void qdev_prop_set_globals(DeviceState *dev);
 
+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 aa8ed0a..c087506 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/usb-bus.c +1 -1
index 8cafb76..e1bcab1 100644
@@ -251,7 +251,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 cd349f3..8a79729 100644
@@ -1122,7 +1122,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 a8b7c8d..5d7bfcf 100644
@@ -1350,7 +1350,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 c2981c5..51c96b7 100644
@@ -1775,7 +1775,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 d3351c8..f922400 100644
@@ -99,7 +99,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 +4 -4
index a4825b9..b9c8ca7 100644
@@ -135,7 +135,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;
@@ -358,7 +358,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:
@@ -470,7 +470,7 @@ static void handle_output(VirtIODevice *vdev, VirtQueue *vq)
 
     vser = DO_UPCAST(VirtIOSerial, vdev, vdev);
     port = find_port_by_vq(vser, vq);
-    info = port ? DO_UPCAST(VirtIOSerialPortInfo, qdev, port->dev.info) : NULL;
+    info = port ? DO_UPCAST(VirtIOSerialPortInfo, qdev, qdev_get_info(&port->dev)) : NULL;
 
     if (!port || !port->host_connected || !info->have_data) {
         discard_vq_data(vq, vdev);
@@ -809,7 +809,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
#32 lore raw

PATCH v3 31/197 qdev: don't access name through info

In reply to Anthony Liguori
---
 hw/e1000.c           |    2 +-
 hw/eepro100.c        |    2 +-
 hw/hda-audio.c       |    2 +-
 hw/intel-hda.c       |    2 +-
 hw/ne2000-isa.c      |    2 +-
 hw/ne2000.c          |    2 +-
 hw/pci.c             |    2 +-
 hw/pcnet.c           |    2 +-
 hw/qdev-properties.c |   16 ++++++++--------
 hw/qdev.c            |   16 ++++++++--------
 hw/rtl8139.c         |    2 +-
 hw/usb-bus.c         |    2 +-
 hw/usb-net.c         |    2 +-
 hw/usb-ohci.c        |    2 +-
 hw/virtio-net.c      |    2 +-
 15 files changed, 29 insertions(+), 29 deletions(-)
hw/e1000.c +1 -1
index ce30ad8..2f495cd 100644
@@ -1175,7 +1175,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_type(OBJECT(d)), d->dev.qdev.id, d);
 
     qemu_format_nic_info_str(&d->nic->nc, macaddr);
 
hw/eepro100.c +1 -1
index 287d1f1..1f9f610 100644
@@ -1879,7 +1879,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_type(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/hda-audio.c +1 -1
index 0bc0a25..ffdd799 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_type(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..1b42e10 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_type(OBJECT(d));
 
     pci_config_set_interrupt_pin(conf, 1);
 
hw/ne2000-isa.c +1 -1
index 60dc333..9e89256 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_type(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..16dcee2 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_type(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/pci.c +1 -1
index 46b7dac..dd8aa48 100644
@@ -1763,7 +1763,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_type(OBJECT(pdev)));
     pdev->has_rom = true;
     memory_region_init_ram(&pdev->rom, &pdev->qdev, name, size);
     ptr = memory_region_get_ram_ptr(&pdev->rom);
hw/pcnet.c +1 -1
index e58b195..c3bf405 100644
@@ -1718,7 +1718,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_type(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 f235a26..ce8cb7c 100644
@@ -627,7 +627,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_type(OBJECT(dev)), name);
         return -1;
     }
     ret = prop->info->parse(dev, prop, value);
@@ -635,16 +635,16 @@ int qdev_prop_parse(DeviceState *dev, const char *name, const char *value)
         switch (ret) {
         case -EEXIST:
             qerror_report(QERR_PROPERTY_VALUE_IN_USE,
-                          qdev_get_info(dev)->name, name, value);
+                          object_get_type(OBJECT(dev)), name, value);
             break;
         default:
         case -EINVAL:
             qerror_report(QERR_PROPERTY_VALUE_BAD,
-                          qdev_get_info(dev)->name, name, value);
+                          object_get_type(OBJECT(dev)), name, value);
             break;
         case -ENOENT:
             qerror_report(QERR_PROPERTY_VALUE_NOT_FOUND,
-                          qdev_get_info(dev)->name, name, value);
+                          object_get_type(OBJECT(dev)), name, value);
             break;
         }
         return -1;
@@ -659,12 +659,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_type(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_type(OBJECT(dev)), name);
         abort();
     }
     qdev_prop_cpy(dev, prop, src);
@@ -713,7 +713,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_type(OBJECT(dev)),
                      name, strerror(-res));
         return -1;
     }
@@ -785,7 +785,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_type(OBJECT(dev)), prop->driver) != 0 &&
             strcmp(qdev_get_info(dev)->bus_info->name, prop->driver) != 0) {
             continue;
         }
hw/qdev.c +8 -8
index 2edbc61..18ff84e 100644
@@ -690,7 +690,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_type(OBJECT(dev)));
     QLIST_FOREACH(child, &dev->child_bus, sibling) {
         error_printf("%s\"%s\"", sep, child->name);
         sep = ", ";
@@ -705,7 +705,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_type(OBJECT(dev)));
         if (dev->id)
             error_printf("/\"%s\"", dev->id);
         sep = ", ";
@@ -741,7 +741,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_type(OBJECT(dev)), elem) == 0) {
             return dev;
         }
     }
@@ -948,7 +948,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_type(OBJECT(dev)),
                 dev->id ? dev->id : "");
     indent += 2;
     if (dev->num_gpio_in) {
@@ -1038,7 +1038,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_type(OBJECT(dev)));
         }
     }
     l += snprintf(p + l , size - l, "/");
@@ -1060,7 +1060,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_type(OBJECT(dev)));
 }
 
 void qdev_ref(DeviceState *dev)
@@ -1255,7 +1255,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_type(OBJECT(child)));
 
     qdev_property_add(dev, name, type, qdev_get_child_property,
                       NULL, NULL, child, errp);
@@ -1306,7 +1306,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_type(OBJECT(target)));
             if (strcmp(target_type, type) == 0) {
                 *child = target;
                 qdev_ref(target);
hw/rtl8139.c +1 -1
index c087506..0143fa2 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_type(OBJECT(dev)), dev->qdev.id, s);
     qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
 
     s->cplus_txbuffer = NULL;
hw/usb-bus.c +1 -1
index e1bcab1..fb532ab 100644
@@ -251,7 +251,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_type(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 5d7bfcf..c4b29a9 100644
@@ -1350,7 +1350,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_type(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 51c96b7..194c994 100644
@@ -1775,7 +1775,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_type(OBJECT(dev));
     usb_packet_init(&ohci->usb_packet);
 
     ohci->async_td = 0;
hw/virtio-net.c +1 -1
index 6c785d0..dd5da0b 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_type(OBJECT(dev)), dev->id, n);
 
     qemu_format_nic_info_str(&n->nic->nc, conf->macaddr.a);
 
Signature · 1 line
1.7.4.1
#33 lore raw

PATCH v3 32/197 qdev: user 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       |   27 +++++++++++++++++----------
 hw/qdev.h       |   10 +++++++++-
 4 files changed, 28 insertions(+), 15 deletions(-)
hw/intel-hda.c +1 -3
index 1b42e10..09459b8 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 b313f83..110ca44 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 -10
index 18ff84e..fed9848 100644
@@ -44,16 +44,16 @@ static BusState *qbus_find_recursive(BusState *bus, const char *name,
                                      const BusInfo *info);
 static BusState *qbus_find(const char *path);
 
-#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)
-
 /* Register a new device type.  */
 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)
@@ -372,8 +372,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;
 }
@@ -406,9 +406,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;
 }
@@ -1541,6 +1539,15 @@ void qdev_property_add_str(DeviceState *dev, const char *name,
                       prop, errp);
 }
 
+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 +9 -1
index 01dd1d6..cd2eaf2 100644
@@ -67,9 +67,15 @@ typedef struct DeviceProperty
     QTAILQ_ENTRY(DeviceProperty) node;
 } 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;
+    void (*reset)(DeviceState *dev);
 } DeviceClass;
 
 /* This structure should not be accessed directly.  We declare it here
@@ -390,7 +396,7 @@ static inline const char *qdev_fw_name(DeviceState *dev)
         return info->alias;
     }
 
-    return info->name;
+    return object_get_type(OBJECT(dev));
 }
 
 char *qdev_get_fw_dev_path(DeviceState *dev);
@@ -627,4 +633,6 @@ void qdev_property_add_str(DeviceState *dev, const char *name,
  */
 char *qdev_get_type(DeviceState *dev, Error **errp);
 
+void device_reset(DeviceState *dev);
+
 #endif
Signature · 1 line
1.7.4.1
#34 lore raw

PATCH v3 33/197 a little better approach to this

In reply to Anthony Liguori
---
 hw/pci.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
hw/pci.c +2 -2
index dd8aa48..16d676d 100644
@@ -161,8 +161,8 @@ void pci_device_reset(PCIDevice *dev)
     int r;
     /* TODO: call the below unconditionally once all pci devices
      * are qdevified */
-    if (qdev_get_info(&dev->qdev)) {
-        qdev_reset_all(&dev->qdev);
+    if (OBJECT(dev)->type != 0) {
+        qdev_reset_all(DEVICE(dev));
     }
 
     dev->irq_state = 0;
Signature · 1 line
1.7.4.1
#35 lore raw

PATCH v3 34/197 qdev: add isa-device as a subclass of device

In reply to Anthony Liguori
---
 hw/isa-bus.c |   11 ++++++++++-
 hw/isa.h     |   12 ++++++++++++
 hw/pci.c     |    2 +-
 hw/qdev.c    |    9 +++++++--
 hw/qdev.h    |    1 +
 5 files changed, 31 insertions(+), 4 deletions(-)
hw/isa-bus.c +10 -1
index 7c2c261..0beb1bf 100644
@@ -126,7 +126,7 @@ void isa_qdev_register(ISADeviceInfo *info)
 {
     info->qdev.init = isa_qdev_init;
     info->qdev.bus_info = &isa_bus_info;
-    qdev_register(&info->qdev);
+    qdev_register_subclass(&info->qdev, TYPE_ISA_DEVICE);
 }
 
 ISADevice *isa_create(const char *name)
@@ -189,9 +189,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 +12 -0
index 5eb9c78..af7e3dc 100644
@@ -13,6 +13,18 @@ typedef struct ISABus ISABus;
 typedef struct ISADevice ISADevice;
 typedef struct ISADeviceInfo ISADeviceInfo;
 
+#define TYPE_ISA_DEVICE "isa-device"
+#define ISA_DEVICE(obj) \
+     OBJECT_CHECK(ISADeviceState, (obj), ISA_TYPE_DEVICE)
+#define ISA_DEVICE_CLASS(klass) \
+     OBJECT_CLASS_CHECK(ISADeviceClass, (klass), ISA_TYPE_DEVICE)
+#define ISA_DEVICE_GET_CLASS(obj) \
+     OBJECT_GET_CLASS(ISADeviceClass, (obj), ISA_TYPE_DEVICE)
+
+typedef struct ISADeviceClass {
+    DeviceClass parent_class;
+} ISADeviceClass;
+
 struct ISADevice {
     DeviceState qdev;
     uint32_t isairq[2];
hw/pci.c +1 -1
index 16d676d..9992ea2 100644
@@ -161,7 +161,7 @@ void pci_device_reset(PCIDevice *dev)
     int r;
     /* TODO: call the below unconditionally once all pci devices
      * are qdevified */
-    if (OBJECT(dev)->type != 0) {
+    if (OBJECT(dev)->class != NULL) {
         qdev_reset_all(DEVICE(dev));
     }
 
hw/qdev.c +7 -2
index fed9848..e0c4a40 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 cd2eaf2..aab8f42 100644
@@ -235,6 +235,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
#36 lore raw

PATCH v3 35/197 isa: more isa stuff

In reply to Anthony Liguori
---
 hw/isa-bus.c     |    8 ++++----
 hw/isa.h         |    6 +++---
 hw/mc146818rtc.c |    2 +-
 3 files changed, 8 insertions(+), 8 deletions(-)
hw/isa-bus.c +4 -4
index 0beb1bf..50131f7 100644
@@ -113,7 +113,7 @@ 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);
+    ISADevice *dev = ISA_DEVICE(qdev);
     ISADeviceInfo *info = DO_UPCAST(ISADeviceInfo, qdev, base);
 
     dev->isairq[0] = -1;
@@ -138,7 +138,7 @@ ISADevice *isa_create(const char *name)
                  name);
     }
     dev = qdev_create(&isabus->qbus, name);
-    return DO_UPCAST(ISADevice, qdev, dev);
+    return ISA_DEVICE(dev);
 }
 
 ISADevice *isa_try_create(const char *name)
@@ -150,7 +150,7 @@ ISADevice *isa_try_create(const char *name)
                  name);
     }
     dev = qdev_try_create(&isabus->qbus, name);
-    return DO_UPCAST(ISADevice, qdev, dev);
+    return ISA_DEVICE(dev);
 }
 
 ISADevice *isa_create_simple(const char *name)
@@ -164,7 +164,7 @@ ISADevice *isa_create_simple(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, "",
hw/isa.h +3 -3
index af7e3dc..d5fd7d7 100644
@@ -15,11 +15,11 @@ typedef struct ISADeviceInfo ISADeviceInfo;
 
 #define TYPE_ISA_DEVICE "isa-device"
 #define ISA_DEVICE(obj) \
-     OBJECT_CHECK(ISADeviceState, (obj), ISA_TYPE_DEVICE)
+     OBJECT_CHECK(ISADevice, (obj), TYPE_ISA_DEVICE)
 #define ISA_DEVICE_CLASS(klass) \
-     OBJECT_CLASS_CHECK(ISADeviceClass, (klass), ISA_TYPE_DEVICE)
+     OBJECT_CLASS_CHECK(ISADeviceClass, (klass), TYPE_ISA_DEVICE)
 #define ISA_DEVICE_GET_CLASS(obj) \
-     OBJECT_GET_CLASS(ISADeviceClass, (obj), ISA_TYPE_DEVICE)
+     OBJECT_GET_CLASS(ISADeviceClass, (obj), TYPE_ISA_DEVICE)
 
 typedef struct ISADeviceClass {
     DeviceClass parent_class;
hw/mc146818rtc.c +1 -1
index 0c23cb0..d5b737a 100644
@@ -624,7 +624,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);
Signature · 1 line
1.7.4.1
#37 lore raw

PATCH v3 36/197 qom: make pcidevice part of the hierarchy

In reply to Anthony Liguori
---
 hw/pci.c  |   18 ++++++++++++++++--
 hw/pci.h  |   12 ++++++++++++
 hw/qdev.c |    5 +++++
 3 files changed, 33 insertions(+), 2 deletions(-)
hw/pci.c +16 -2
index 9992ea2..04fd95f 100644
@@ -89,7 +89,6 @@ static const VMStateDescription vmstate_pcibus = {
         VMSTATE_END_OF_LIST()
     }
 };
-
 static int pci_bar(PCIDevice *d, int reg)
 {
     uint8_t type;
@@ -1550,7 +1549,7 @@ void pci_qdev_register(PCIDeviceInfo *info)
     info->qdev.unplug = pci_unplug_device;
     info->qdev.exit = pci_unregister_device;
     info->qdev.bus_info = &pci_bus_info;
-    qdev_register(&info->qdev);
+    qdev_register_subclass(&info->qdev, TYPE_PCI_DEVICE);
 }
 
 void pci_qdev_register_many(PCIDeviceInfo *info)
@@ -2038,3 +2037,18 @@ MemoryRegion *pci_address_space_io(PCIDevice *dev)
 {
     return dev->bus->address_space_io;
 }
+
+static TypeInfo pci_device_type_info = {
+    .name = TYPE_PCI_DEVICE,
+    .parent = TYPE_DEVICE,
+    .instance_size = sizeof(PCIDevice),
+    .abstract = true,
+    .class_size = sizeof(PCIDeviceClass),
+};
+
+static void pci_register_devices(void)
+{
+    type_register_static(&pci_device_type_info);
+}
+
+device_init(pci_register_devices);
hw/pci.h +12 -0
index 625e717..00c9897 100644
@@ -127,6 +127,18 @@ enum {
     QEMU_PCI_CAP_SERR = (1 << QEMU_PCI_CAP_SERR_BITNR),
 };
 
+#define TYPE_PCI_DEVICE "pci-device"
+#define PCI_DEVICE(obj) \
+     OBJECT_CHECK(PCIDevice, (obj), TYPE_PCI_DEVICE)
+#define PCI_DEVICE_CLASS(klass) \
+     OBJECT_CLASS_CHECK(PCIDeviceClass, (klass), TYPE_PCI_DEVICE)
+#define PCI_DEVICE_GET_CLASS(obj) \
+     OBJECT_GET_CLASS(PCIDeviceClass, (obj), TYPE_PCI_DEVICE)
+
+typedef struct PCIDeviceClass {
+    DeviceClass parent_class;
+} PCIDeviceClass;
+
 struct PCIDevice {
     DeviceState qdev;
     /* PCI config space */
hw/qdev.c +5 -0
index e0c4a40..09f8b4c 100644
@@ -111,6 +111,11 @@ static DeviceInfo *qdev_find_info(BusInfo *bus_info, const char *name)
     return NULL;
 }
 
+/* FIXME: need to figure out somethign to do with bus.
+ *
+ * The general problem is that we don't want to take a bus argument on
+ * create.  there's simply no way to pass it to instance init.
+ */
 static DeviceState *qdev_create_from_info(BusState *bus, DeviceInfo *info)
 {
     DeviceState *dev;
Signature · 1 line
1.7.4.1
#38 lore raw

PATCH v3 39/197 virtio-serial-port

In reply to Anthony Liguori
---
 hw/virtio-serial-bus.c |   17 ++++++++++++++++-
 hw/virtio-serial.h     |   12 ++++++++++++
 2 files changed, 28 insertions(+), 1 deletions(-)
hw/virtio-serial-bus.c +16 -1
index b9c8ca7..a459e31 100644
@@ -829,7 +829,7 @@ void virtio_serial_port_qdev_register(VirtIOSerialPortInfo *info)
     info->qdev.bus_info = &virtser_bus_info;
     info->qdev.exit = virtser_port_qdev_exit;
     info->qdev.unplug = qdev_simple_unplug_cb;
-    qdev_register(&info->qdev);
+    qdev_register_subclass(&info->qdev, TYPE_VIRTIO_SERIAL_PORT);
 }
 
 VirtIODevice *virtio_serial_init(DeviceState *dev, virtio_serial_conf *conf)
@@ -925,3 +925,18 @@ void virtio_serial_exit(VirtIODevice *vdev)
 
     virtio_cleanup(vdev);
 }
+
+static TypeInfo virtio_serial_port_type_info = {
+    .name = TYPE_VIRTIO_SERIAL_PORT,
+    .parent = TYPE_DEVICE,
+    .instance_size = sizeof(VirtIOSerialPort),
+    .abstract = true,
+    .class_size = sizeof(VirtIOSerialPortClass),
+};
+
+static void virtio_serial_register_devices(void)
+{
+    type_register_static(&virtio_serial_port_type_info);
+}
+
+device_init(virtio_serial_register_devices);
hw/virtio-serial.h +12 -0
index ab13803..86fae8d 100644
@@ -62,6 +62,18 @@ struct virtio_serial_conf {
 
 /* == In-qemu interface == */
 
+#define TYPE_VIRTIO_SERIAL_PORT "virtio-serial-port"
+#define VIRTIO_SERIAL_PORT(obj) \
+     OBJECT_CHECK(VirtIOSerialPort, (obj), TYPE_VIRTIO_SERIAL_PORT)
+#define VIRTIO_SERIAL_PORT_CLASS(klass) \
+     OBJECT_CLASS_CHECK(VirtIOSerialPortClass, (klass), TYPE_VIRTIO_SERIAL_PORT)
+#define VIRTIO_SERIAL_PORT_GET_CLASS(obj) \
+     OBJECT_GET_CLASS(VirtIOSerialPortClass, (obj), TYPE_VIRTIO_SERIAL_PORT)
+
+typedef struct VirtIOSerialPortClass {
+    DeviceClass parent_class;
+} VirtIOSerialPortClass;
+
 typedef struct VirtIOSerial VirtIOSerial;
 typedef struct VirtIOSerialBus VirtIOSerialBus;
 typedef struct VirtIOSerialPort VirtIOSerialPort;
Signature · 1 line
1.7.4.1
#39 lore raw

PATCH v3 40/197 get rid of more DO_UPCAST

In reply to Anthony Liguori
---
 hw/scsi-bus.c     |   14 +++++++-------
 hw/scsi-generic.c |    2 +-
 hw/usb-bus.c      |   12 ++++++------
 hw/usb-ccid.c     |    4 ++--
 4 files changed, 16 insertions(+), 16 deletions(-)
hw/scsi-bus.c +7 -7
index e8eb521..731c1f3 100644
@@ -81,7 +81,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);
+    SCSIDevice *dev = SCSI_DEVICE(qdev);
     SCSIDeviceInfo *info = DO_UPCAST(SCSIDeviceInfo, qdev, base);
     SCSIBus *bus = DO_UPCAST(SCSIBus, qbus, dev->qdev.parent_bus);
     SCSIDevice *d;
@@ -140,7 +140,7 @@ 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);
@@ -182,7 +182,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 +278,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 +300,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);
@@ -1367,7 +1367,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 +1382,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) {
hw/scsi-generic.c +1 -1
index e62044f..ef76e4b 100644
@@ -361,7 +361,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));
 }
hw/usb-bus.c +6 -6
index 80cf560..8924ac3 100644
@@ -67,7 +67,7 @@ USBBus *usb_bus_find(int busnr)
 
 static int usb_qdev_init(DeviceState *qdev, DeviceInfo *base)
 {
-    USBDevice *dev = DO_UPCAST(USBDevice, qdev, qdev);
+    USBDevice *dev = USB_DEVICE(qdev);
     USBDeviceInfo *info = DO_UPCAST(USBDeviceInfo, qdev, base);
     int rc;
 
@@ -98,7 +98,7 @@ err:
 
 static int usb_qdev_exit(DeviceState *qdev)
 {
-    USBDevice *dev = DO_UPCAST(USBDevice, qdev, qdev);
+    USBDevice *dev = USB_DEVICE(qdev);
 
     if (dev->attached) {
         usb_device_detach(dev);
@@ -145,7 +145,7 @@ USBDevice *usb_create(USBBus *bus, const char *name)
 #endif
 
     dev = qdev_create(&bus->qbus, name);
-    return DO_UPCAST(USBDevice, qdev, dev);
+    return USB_DEVICE(dev);
 }
 
 USBDevice *usb_create_simple(USBBus *bus, const char *name)
@@ -366,7 +366,7 @@ static const char *usb_speed(unsigned int speed)
 
 static void usb_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent)
 {
-    USBDevice *dev = DO_UPCAST(USBDevice, qdev, qdev);
+    USBDevice *dev = USB_DEVICE(qdev);
     USBBus *bus = usb_bus_from_device(dev);
 
     monitor_printf(mon, "%*saddr %d.%d, port %s, speed %s, name %s%s\n",
@@ -378,13 +378,13 @@ static void usb_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent)
 
 static char *usb_get_dev_path(DeviceState *qdev)
 {
-    USBDevice *dev = DO_UPCAST(USBDevice, qdev, qdev);
+    USBDevice *dev = USB_DEVICE(qdev);
     return g_strdup(dev->port->path);
 }
 
 static char *usb_get_fw_dev_path(DeviceState *qdev)
 {
-    USBDevice *dev = DO_UPCAST(USBDevice, qdev, qdev);
+    USBDevice *dev = USB_DEVICE(qdev);
     char *fw_path, *in;
     ssize_t pos = 0, fw_len;
     long nr;
hw/usb-ccid.c +2 -2
index 9bbef8c..997ef31 100644
@@ -1121,7 +1121,7 @@ void ccid_card_card_inserted(CCIDCardState *card)
 static int ccid_card_exit(DeviceState *qdev)
 {
     int ret = 0;
-    CCIDCardState *card = DO_UPCAST(CCIDCardState, qdev, qdev);
+    CCIDCardState *card = CCID_CARD(qdev);
     CCIDCardInfo *info = DO_UPCAST(CCIDCardInfo, qdev, qdev_get_info(qdev));
     USBCCIDState *s =
         DO_UPCAST(USBCCIDState, dev.qdev, card->qdev.parent_bus->parent);
@@ -1139,7 +1139,7 @@ static int ccid_card_exit(DeviceState *qdev)
 
 static int ccid_card_init(DeviceState *qdev, DeviceInfo *base)
 {
-    CCIDCardState *card = DO_UPCAST(CCIDCardState, qdev, qdev);
+    CCIDCardState *card = CCID_CARD(qdev);
     CCIDCardInfo *info = DO_UPCAST(CCIDCardInfo, qdev, base);
     USBCCIDState *s =
         DO_UPCAST(USBCCIDState, dev.qdev, card->qdev.parent_bus->parent);
Signature · 1 line
1.7.4.1
#40 lore raw

PATCH v3 41/197 add class_init to deviceinfo

In reply to Anthony Liguori
---
 hw/ccid.h |    2 +-
 hw/qdev.c |    4 ++++
 hw/qdev.h |    5 +++++
 3 files changed, 10 insertions(+), 1 deletions(-)
hw/ccid.h +1 -1
index ad055d3..d8e0485 100644
@@ -17,7 +17,7 @@ typedef struct CCIDCardInfo CCIDCardInfo;
 
 #define TYPE_CCID_CARD "ccid-card"
 #define CCID_CARD(obj) \
-     OBJECT_CHECK(CCIDCard, (obj), TYPE_CCID_CARD)
+     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) \
hw/qdev.c +4 -0
index 09f8b4c..d062470 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 aab8f42..6617a2b 100644
@@ -225,6 +225,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
#41 lore raw

PATCH v3 42/197 isa: move methods from isadeviceinfo to isadeviceclass

In reply to Anthony Liguori
---
 hw/applesmc.c    |    8 +++++++-
 hw/cs4231a.c     |    8 +++++++-
 hw/debugcon.c    |    8 +++++++-
 hw/fdc.c         |    8 +++++++-
 hw/gus.c         |    8 +++++++-
 hw/i8254.c       |    8 +++++++-
 hw/i8259.c       |    8 +++++++-
 hw/ide/isa.c     |    8 +++++++-
 hw/isa-bus.c     |    8 ++++++--
 hw/isa.h         |    3 +--
 hw/m48t59.c      |    8 +++++++-
 hw/mc146818rtc.c |    8 +++++++-
 hw/ne2000-isa.c  |    8 +++++++-
 hw/parallel.c    |    8 +++++++-
 hw/pc.c          |    8 +++++++-
 hw/pckbd.c       |    8 +++++++-
 hw/sb16.c        |    8 +++++++-
 hw/serial.c      |    8 +++++++-
 hw/sga.c         |    8 +++++++-
 hw/vga-isa.c     |    8 +++++++-
 hw/vmmouse.c     |    8 +++++++-
 hw/vmport.c      |    8 +++++++-
 hw/wdt_ib700.c   |    8 +++++++-
 23 files changed, 154 insertions(+), 25 deletions(-)
hw/applesmc.c +7 -1
index c47b592..279c4d3 100644
@@ -220,11 +220,17 @@ static int applesmc_isa_init(ISADevice *dev)
     return 0;
 }
 
+static void qdev_applesmc_class_init(ObjectClass *klass, void *data)
+{
+    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+    ic->init = applesmc_isa_init;
+}
+
 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.class_init = qdev_applesmc_class_init,
     .qdev.props = (Property[]) {
         DEFINE_PROP_HEX32("iobase", struct AppleSMCStatus, iobase,
                           APPLESMC_DEFAULT_IOBASE),
hw/cs4231a.c +7 -1
index a7e03a3..25af773 100644
@@ -665,12 +665,18 @@ int cs4231a_init (qemu_irq *pic)
     return 0;
 }
 
+static void cs4231a_class_initfn(ObjectClass *klass, void *data)
+{
+    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+    ic->init = cs4231a_initfn;
+}
+
 static ISADeviceInfo cs4231a_info = {
     .qdev.name     = "cs4231a",
     .qdev.desc     = "Crystal Semiconductor CS4231A",
     .qdev.size     = sizeof (CSState),
     .qdev.vmsd     = &vmstate_cs4231a,
-    .init          = cs4231a_initfn,
+    .qdev.class_init = cs4231a_class_initfn,
     .qdev.props    = (Property[]) {
         DEFINE_PROP_HEX32  ("iobase",  CSState, port, 0x534),
         DEFINE_PROP_UINT32 ("irq",     CSState, irq,  9),
hw/debugcon.c +7 -1
index c9ee6d9..1490bfa 100644
@@ -87,10 +87,16 @@ static int debugcon_isa_initfn(ISADevice *dev)
     return 0;
 }
 
+static void debugcon_isa_class_initfn(ObjectClass *klass, void *data)
+{
+    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+    ic->init = debugcon_isa_initfn;
+}
+
 static ISADeviceInfo debugcon_isa_info = {
     .qdev.name  = "isa-debugcon",
     .qdev.size  = sizeof(ISADebugconState),
-    .init       = debugcon_isa_initfn,
+    .qdev.class_init = debugcon_isa_class_initfn,
     .qdev.props = (Property[]) {
         DEFINE_PROP_HEX32("iobase", ISADebugconState, iobase, 0xe9),
         DEFINE_PROP_CHR("chardev",  ISADebugconState, state.chr),
hw/fdc.c +7 -1
index ecaad09..dfeb138 100644
@@ -1969,8 +1969,14 @@ static const VMStateDescription vmstate_isa_fdc ={
     }
 };
 
+static void isabus_fdc_class_init1(ObjectClass *klass, void *data)
+{
+    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+    ic->init = isabus_fdc_init1;
+}
+
 static ISADeviceInfo isa_fdc_info = {
-    .init = isabus_fdc_init1,
+    .qdev.class_init = isabus_fdc_class_init1,
     .qdev.name  = "isa-fdc",
     .qdev.fw_name  = "fdc",
     .qdev.size  = sizeof(FDCtrlISABus),
hw/gus.c +7 -1
index b5eb548..49e0d16 100644
@@ -299,12 +299,18 @@ int GUS_init (qemu_irq *pic)
     return 0;
 }
 
+static void gus_class_initfn(ObjectClass *klass, void *data)
+{
+    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+    ic->init = gus_initfn;
+}
+
 static ISADeviceInfo gus_info = {
     .qdev.name     = "gus",
     .qdev.desc     = "Gravis Ultrasound GF1",
     .qdev.size     = sizeof (GUSState),
     .qdev.vmsd     = &vmstate_gus,
-    .init          = gus_initfn,
+    .qdev.class_init          = gus_class_initfn,
     .qdev.props    = (Property[]) {
         DEFINE_PROP_UINT32 ("freq",    GUSState, freq,        44100),
         DEFINE_PROP_HEX32  ("iobase",  GUSState, port,        0x240),
hw/i8254.c +7 -1
index 12571ef..5d10206 100644
@@ -535,13 +535,19 @@ static int pit_initfn(ISADevice *dev)
     return 0;
 }
 
+static void pit_class_initfn(ObjectClass *klass, void *data)
+{
+    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+    ic->init = pit_initfn;
+}
+
 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.class_init          = pit_class_initfn,
     .qdev.props = (Property[]) {
         DEFINE_PROP_UINT32("irq", PITState, irq,  -1),
         DEFINE_PROP_HEX32("iobase", PITState, iobase,  -1),
hw/i8259.c +7 -1
index ab519de..da34f2b 100644
@@ -556,13 +556,19 @@ qemu_irq *i8259_init(qemu_irq parent_irq)
     return irq_set;
 }
 
+static void pic_class_initfn(ObjectClass *klass, void *data)
+{
+    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+    ic->init = pic_initfn;
+}
+
 static ISADeviceInfo i8259_info = {
     .qdev.name     = "isa-i8259",
     .qdev.size     = sizeof(PicState),
     .qdev.vmsd     = &vmstate_pic,
     .qdev.reset    = pic_reset,
     .qdev.no_user  = 1,
-    .init          = pic_initfn,
+    .qdev.class_init          = pic_class_initfn,
     .qdev.props = (Property[]) {
         DEFINE_PROP_HEX32("iobase", PicState, iobase,  -1),
         DEFINE_PROP_HEX32("elcr_addr", PicState, elcr_addr,  -1),
hw/ide/isa.c +7 -1
index 01a9e59..aeca96d 100644
@@ -94,11 +94,17 @@ ISADevice *isa_ide_init(int iobase, int iobase2, int isairq,
     return dev;
 }
 
+static void isa_ide_class_initfn(ObjectClass *klass, void *data)
+{
+    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+    ic->init = isa_ide_initfn;
+}
+
 static ISADeviceInfo isa_ide_info = {
     .qdev.name  = "isa-ide",
     .qdev.fw_name  = "ide",
     .qdev.size  = sizeof(ISAIDEState),
-    .init       = isa_ide_initfn,
+    .qdev.class_init       = isa_ide_class_initfn,
     .qdev.reset = isa_ide_reset,
     .qdev.props = (Property[]) {
         DEFINE_PROP_HEX32("iobase",  ISAIDEState, iobase,  0x1f0),
hw/isa-bus.c +6 -2
index 50131f7..9d02919 100644
@@ -114,12 +114,16 @@ void isa_register_portio_list(ISADevice *dev, uint16_t start,
 static int isa_qdev_init(DeviceState *qdev, DeviceInfo *base)
 {
     ISADevice *dev = ISA_DEVICE(qdev);
-    ISADeviceInfo *info = DO_UPCAST(ISADeviceInfo, qdev, base);
+    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(ISADeviceInfo *info)
hw/isa.h +1 -2
index d5fd7d7..a1afc7b 100644
@@ -23,6 +23,7 @@ typedef struct ISADeviceInfo ISADeviceInfo;
 
 typedef struct ISADeviceClass {
     DeviceClass parent_class;
+    int (*init)(ISADevice *dev);
 } ISADeviceClass;
 
 struct ISADevice {
@@ -32,10 +33,8 @@ 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);
hw/m48t59.c +7 -1
index a77937e..e58b48f 100644
@@ -724,8 +724,14 @@ static int m48t59_init1(SysBusDevice *dev)
     return 0;
 }
 
+static void m48t59_init_class_isa1(ObjectClass *klass, void *data)
+{
+    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+    ic->init = m48t59_init_isa1;
+}
+
 static ISADeviceInfo m48t59_isa_info = {
-    .init = m48t59_init_isa1,
+    .qdev.class_init = m48t59_init_class_isa1,
     .qdev.name = "m48t59_isa",
     .qdev.size = sizeof(M48t59ISAState),
     .qdev.reset = m48t59_reset_isa,
hw/mc146818rtc.c +7 -1
index d5b737a..e2acf12 100644
@@ -694,12 +694,18 @@ ISADevice *rtc_init(int base_year, qemu_irq intercept_irq)
     return dev;
 }
 
+static void rtc_class_initfn(ObjectClass *klass, void *data)
+{
+    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+    ic->init = rtc_initfn;
+}
+
 static ISADeviceInfo mc146818rtc_info = {
     .qdev.name     = "mc146818rtc",
     .qdev.size     = sizeof(RTCState),
     .qdev.no_user  = 1,
     .qdev.vmsd     = &vmstate_rtc,
-    .init          = rtc_initfn,
+    .qdev.class_init          = rtc_class_initfn,
     .qdev.props    = (Property[]) {
         DEFINE_PROP_INT32("base_year", RTCState, base_year, 1980),
         DEFINE_PROP_END_OF_LIST(),
hw/ne2000-isa.c +7 -1
index 9e89256..da86a61 100644
@@ -82,10 +82,16 @@ static int isa_ne2000_initfn(ISADevice *dev)
     return 0;
 }
 
+static void isa_ne2000_class_initfn(ObjectClass *klass, void *data)
+{
+    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+    ic->init = isa_ne2000_initfn;
+}
+
 static ISADeviceInfo ne2000_isa_info = {
     .qdev.name  = "ne2k_isa",
     .qdev.size  = sizeof(ISANE2000State),
-    .init       = isa_ne2000_initfn,
+    .qdev.class_init       = isa_ne2000_class_initfn,
     .qdev.props = (Property[]) {
         DEFINE_PROP_HEX32("iobase", ISANE2000State, iobase, 0x300),
         DEFINE_PROP_UINT32("irq",   ISANE2000State, isairq, 9),
hw/parallel.c +7 -1
index 8494d94..ac7dc46 100644
@@ -586,10 +586,16 @@ bool parallel_mm_init(target_phys_addr_t base, int it_shift, qemu_irq irq,
     return true;
 }
 
+static void parallel_isa_class_initfn(ObjectClass *klass, void *data)
+{
+    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+    ic->init = parallel_isa_initfn;
+}
+
 static ISADeviceInfo parallel_isa_info = {
     .qdev.name  = "isa-parallel",
     .qdev.size  = sizeof(ISAParallelState),
-    .init       = parallel_isa_initfn,
+    .qdev.class_init       = parallel_isa_class_initfn,
     .qdev.props = (Property[]) {
         DEFINE_PROP_UINT32("index", ISAParallelState, index,   -1),
         DEFINE_PROP_HEX32("iobase", ISAParallelState, iobase,  -1),
hw/pc.c +7 -1
index 47e6fb9..4e4dc6d 100644
@@ -496,13 +496,19 @@ static int port92_initfn(ISADevice *dev)
     return 0;
 }
 
+static void port92_class_initfn(ObjectClass *klass, void *data)
+{
+    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+    ic->init = port92_initfn;
+}
+
 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,
+    .qdev.class_init          = port92_class_initfn,
 };
 
 static void port92_register(void)
hw/pckbd.c +7 -1
index 06b40c5..fe5cc6e 100644
@@ -497,12 +497,18 @@ static int i8042_initfn(ISADevice *dev)
     return 0;
 }
 
+static void i8042_class_initfn(ObjectClass *klass, void *data)
+{
+    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+    ic->init = i8042_initfn;
+}
+
 static ISADeviceInfo i8042_info = {
     .qdev.name     = "i8042",
     .qdev.size     = sizeof(ISAKBDState),
     .qdev.vmsd     = &vmstate_kbd_isa,
     .qdev.no_user  = 1,
-    .init          = i8042_initfn,
+    .qdev.class_init          = i8042_class_initfn,
 };
 
 static void i8042_register(void)
hw/sb16.c +7 -1
index f0658ac..f7a6b7e 100644
@@ -1391,12 +1391,18 @@ int SB16_init (qemu_irq *pic)
     return 0;
 }
 
+static void sb16_class_initfn(ObjectClass *klass, void *data)
+{
+    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+    ic->init = sb16_initfn;
+}
+
 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.class_init          = sb16_class_initfn,
     .qdev.props    = (Property[]) {
         DEFINE_PROP_HEX32  ("version", SB16State, ver,  0x0405), /* 4.5 */
         DEFINE_PROP_HEX32  ("iobase",  SB16State, port, 0x220),
hw/serial.c +7 -1
index d35c7a9..74ed5fe 100644
@@ -879,11 +879,17 @@ SerialState *serial_mm_init(MemoryRegion *address_space,
     return s;
 }
 
+static void serial_isa_class_initfn(ObjectClass *klass, void *data)
+{
+    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+    ic->init = serial_isa_initfn;
+}
+
 static ISADeviceInfo serial_isa_info = {
     .qdev.name  = "isa-serial",
     .qdev.size  = sizeof(ISASerialState),
     .qdev.vmsd  = &vmstate_isa_serial,
-    .init       = serial_isa_initfn,
+    .qdev.class_init       = serial_isa_class_initfn,
     .qdev.props = (Property[]) {
         DEFINE_PROP_UINT32("index", ISASerialState, index,   -1),
         DEFINE_PROP_HEX32("iobase", ISASerialState, iobase,  -1),
hw/sga.c +7 -1
index 7ef750a..6801995 100644
@@ -41,11 +41,17 @@ static int isa_cirrus_vga_initfn(ISADevice *dev)
     return 0;
 }
 
+static void isa_cirrus_vga_class_initfn(ObjectClass *klass, void *data)
+{
+    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+    ic->init = isa_cirrus_vga_initfn;
+}
+
 static ISADeviceInfo sga_info = {
     .qdev.name    = "sga",
     .qdev.desc    = "Serial Graphics Adapter",
     .qdev.size    = sizeof(ISASGAState),
-    .init         = isa_cirrus_vga_initfn,
+    .qdev.class_init         = isa_cirrus_vga_class_initfn,
 };
 
 static void sga_register(void)
hw/vga-isa.c +7 -1
index 4825313..ba7f9bf 100644
@@ -69,12 +69,18 @@ static int vga_initfn(ISADevice *dev)
     return 0;
 }
 
+static void vga_class_initfn(ObjectClass *klass, void *data)
+{
+    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+    ic->init = vga_initfn;
+}
+
 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,
+    .qdev.class_init          = vga_class_initfn,
 };
 
 static void vga_register(void)
hw/vmmouse.c +7 -1
index 1113f33..f936089 100644
@@ -269,8 +269,14 @@ static int vmmouse_initfn(ISADevice *dev)
     return 0;
 }
 
+static void vmmouse_class_initfn(ObjectClass *klass, void *data)
+{
+    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+    ic->init = vmmouse_initfn;
+}
+
 static ISADeviceInfo vmmouse_info = {
-    .init          = vmmouse_initfn,
+    .qdev.class_init          = vmmouse_class_initfn,
     .qdev.name     = "vmmouse",
     .qdev.size     = sizeof(VMMouseState),
     .qdev.vmsd     = &vmstate_vmmouse,
hw/vmport.c +7 -1
index b5c6fa1..7468812 100644
@@ -144,11 +144,17 @@ static int vmport_initfn(ISADevice *dev)
     return 0;
 }
 
+static void vmport_class_initfn(ObjectClass *klass, void *data)
+{
+    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+    ic->init = vmport_initfn;
+}
+
 static ISADeviceInfo vmport_info = {
     .qdev.name     = "vmport",
     .qdev.size     = sizeof(VMPortState),
     .qdev.no_user  = 1,
-    .init          = vmport_initfn,
+    .qdev.class_init          = vmport_class_initfn,
 };
 
 static void vmport_dev_register(void)
hw/wdt_ib700.c +7 -1
index 81f22d0..3869e91 100644
@@ -120,12 +120,18 @@ static WatchdogTimerModel model = {
     .wdt_description = "iBASE 700",
 };
 
+static void wdt_ib700_class_init(ObjectClass *klass, void *data)
+{
+    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+    ic->init = wdt_ib700_init;
+}
+
 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,
+    .qdev.class_init       = wdt_ib700_class_init,
 };
 
 static void wdt_ib700_register_devices(void)
Signature · 1 line
1.7.4.1
#42 lore raw

PATCH v3 43/197 kill off ISADeviceInfo

In reply to Anthony Liguori
---
 hw/applesmc.c    |   12 ++++++------
 hw/cs4231a.c     |   14 +++++++-------
 hw/debugcon.c    |   10 +++++-----
 hw/fdc.c         |   18 +++++++++---------
 hw/gus.c         |   14 +++++++-------
 hw/i8254.c       |   16 ++++++++--------
 hw/i8259.c       |   16 ++++++++--------
 hw/ide/isa.c     |   14 +++++++-------
 hw/isa-bus.c     |    8 ++++----
 hw/isa.h         |    7 +------
 hw/m48t59.c      |   14 +++++++-------
 hw/mc146818rtc.c |   14 +++++++-------
 hw/ne2000-isa.c  |   10 +++++-----
 hw/parallel.c    |   10 +++++-----
 hw/pc.c          |   14 +++++++-------
 hw/pckbd.c       |   12 ++++++------
 hw/sb16.c        |   14 +++++++-------
 hw/serial.c      |   12 ++++++------
 hw/sga.c         |   10 +++++-----
 hw/vga-isa.c     |   12 ++++++------
 hw/vmmouse.c     |   16 ++++++++--------
 hw/vmport.c      |   10 +++++-----
 hw/wdt_ib700.c   |   12 ++++++------
 23 files changed, 142 insertions(+), 147 deletions(-)
hw/applesmc.c +6 -6
index 279c4d3..a6e88bc 100644
@@ -226,12 +226,12 @@ static void qdev_applesmc_class_init(ObjectClass *klass, void *data)
     ic->init = applesmc_isa_init;
 }
 
-static ISADeviceInfo applesmc_isa_info = {
-    .qdev.name  = "isa-applesmc",
-    .qdev.size  = sizeof(struct AppleSMCStatus),
-    .qdev.reset = qdev_applesmc_isa_reset,
-    .qdev.class_init = qdev_applesmc_class_init,
-    .qdev.props = (Property[]) {
+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/cs4231a.c +7 -7
index 25af773..3474aec 100644
@@ -671,13 +671,13 @@ static void cs4231a_class_initfn(ObjectClass *klass, void *data)
     ic->init = cs4231a_initfn;
 }
 
-static ISADeviceInfo cs4231a_info = {
-    .qdev.name     = "cs4231a",
-    .qdev.desc     = "Crystal Semiconductor CS4231A",
-    .qdev.size     = sizeof (CSState),
-    .qdev.vmsd     = &vmstate_cs4231a,
-    .qdev.class_init = cs4231a_class_initfn,
-    .qdev.props    = (Property[]) {
+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 +5 -5
index 1490bfa..f290122 100644
@@ -93,11 +93,11 @@ static void debugcon_isa_class_initfn(ObjectClass *klass, void *data)
     ic->init = debugcon_isa_initfn;
 }
 
-static ISADeviceInfo debugcon_isa_info = {
-    .qdev.name  = "isa-debugcon",
-    .qdev.size  = sizeof(ISADebugconState),
-    .qdev.class_init = debugcon_isa_class_initfn,
-    .qdev.props = (Property[]) {
+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 +9 -9
index dfeb138..7223033 100644
@@ -1975,15 +1975,15 @@ static void isabus_fdc_class_init1(ObjectClass *klass, void *data)
     ic->init = isabus_fdc_init1;
 }
 
-static ISADeviceInfo isa_fdc_info = {
-    .qdev.class_init = isabus_fdc_class_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 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 +7 -7
index 49e0d16..1675cf5 100644
@@ -305,13 +305,13 @@ static void gus_class_initfn(ObjectClass *klass, void *data)
     ic->init = gus_initfn;
 }
 
-static ISADeviceInfo gus_info = {
-    .qdev.name     = "gus",
-    .qdev.desc     = "Gravis Ultrasound GF1",
-    .qdev.size     = sizeof (GUSState),
-    .qdev.vmsd     = &vmstate_gus,
-    .qdev.class_init          = gus_class_initfn,
-    .qdev.props    = (Property[]) {
+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/i8254.c +8 -8
index 5d10206..7766ce2 100644
@@ -541,14 +541,14 @@ static void pit_class_initfn(ObjectClass *klass, void *data)
     ic->init = pit_initfn;
 }
 
-static ISADeviceInfo pit_info = {
-    .qdev.name     = "isa-pit",
-    .qdev.size     = sizeof(PITState),
-    .qdev.vmsd     = &vmstate_pit,
-    .qdev.reset    = pit_reset,
-    .qdev.no_user  = 1,
-    .qdev.class_init          = pit_class_initfn,
-    .qdev.props = (Property[]) {
+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 +8 -8
index da34f2b..12cd269 100644
@@ -562,14 +562,14 @@ static void pic_class_initfn(ObjectClass *klass, void *data)
     ic->init = pic_initfn;
 }
 
-static ISADeviceInfo i8259_info = {
-    .qdev.name     = "isa-i8259",
-    .qdev.size     = sizeof(PicState),
-    .qdev.vmsd     = &vmstate_pic,
-    .qdev.reset    = pic_reset,
-    .qdev.no_user  = 1,
-    .qdev.class_init          = pic_class_initfn,
-    .qdev.props = (Property[]) {
+static DeviceInfo i8259_info = {
+    .name     = "isa-i8259",
+    .size     = sizeof(PicState),
+    .vmsd     = &vmstate_pic,
+    .reset    = pic_reset,
+    .no_user  = 1,
+    .class_init          = pic_class_initfn,
+    .props = (Property[]) {
         DEFINE_PROP_HEX32("iobase", PicState, iobase,  -1),
         DEFINE_PROP_HEX32("elcr_addr", PicState, elcr_addr,  -1),
         DEFINE_PROP_HEX8("elcr_mask", PicState, elcr_mask,  -1),
hw/ide/isa.c +7 -7
index aeca96d..3c1b479 100644
@@ -100,13 +100,13 @@ static void isa_ide_class_initfn(ObjectClass *klass, void *data)
     ic->init = isa_ide_initfn;
 }
 
-static ISADeviceInfo isa_ide_info = {
-    .qdev.name  = "isa-ide",
-    .qdev.fw_name  = "ide",
-    .qdev.size  = sizeof(ISAIDEState),
-    .qdev.class_init       = isa_ide_class_initfn,
-    .qdev.reset = isa_ide_reset,
-    .qdev.props = (Property[]) {
+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 +4 -4
index 9d02919..e3d67fe 100644
@@ -126,11 +126,11 @@ static int isa_qdev_init(DeviceState *qdev, DeviceInfo *base)
     return 0;
 }
 
-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_subclass(&info->qdev, TYPE_ISA_DEVICE);
+    info->init = isa_qdev_init;
+    info->bus_info = &isa_bus_info;
+    qdev_register_subclass(info, TYPE_ISA_DEVICE);
 }
 
 ISADevice *isa_create(const char *name)
hw/isa.h +1 -6
index a1afc7b..08a24da 100644
@@ -11,7 +11,6 @@
 
 typedef struct ISABus ISABus;
 typedef struct ISADevice ISADevice;
-typedef struct ISADeviceInfo ISADeviceInfo;
 
 #define TYPE_ISA_DEVICE "isa-device"
 #define ISA_DEVICE(obj) \
@@ -33,15 +32,11 @@ struct ISADevice {
     int ioport_id;
 };
 
-struct ISADeviceInfo {
-    DeviceInfo qdev;
-};
-
 ISABus *isa_bus_new(DeviceState *dev, MemoryRegion *address_space_io);
 void isa_bus_irqs(qemu_irq *irqs);
 qemu_irq isa_get_irq(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);
 MemoryRegion *isa_address_space(ISADevice *dev);
 ISADevice *isa_create(const char *name);
 ISADevice *isa_try_create(const char *name);
hw/m48t59.c +7 -7
index e58b48f..760ccdd 100644
@@ -730,13 +730,13 @@ static void m48t59_init_class_isa1(ObjectClass *klass, void *data)
     ic->init = m48t59_init_isa1;
 }
 
-static ISADeviceInfo m48t59_isa_info = {
-    .qdev.class_init = m48t59_init_class_isa1,
-    .qdev.name = "m48t59_isa",
-    .qdev.size = sizeof(M48t59ISAState),
-    .qdev.reset = m48t59_reset_isa,
-    .qdev.no_user = 1,
-    .qdev.props = (Property[]) {
+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 +7 -7
index e2acf12..0674e06 100644
@@ -700,13 +700,13 @@ static void rtc_class_initfn(ObjectClass *klass, void *data)
     ic->init = rtc_initfn;
 }
 
-static ISADeviceInfo mc146818rtc_info = {
-    .qdev.name     = "mc146818rtc",
-    .qdev.size     = sizeof(RTCState),
-    .qdev.no_user  = 1,
-    .qdev.vmsd     = &vmstate_rtc,
-    .qdev.class_init          = rtc_class_initfn,
-    .qdev.props    = (Property[]) {
+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 +5 -5
index da86a61..e1d1603 100644
@@ -88,11 +88,11 @@ static void isa_ne2000_class_initfn(ObjectClass *klass, void *data)
     ic->init = isa_ne2000_initfn;
 }
 
-static ISADeviceInfo ne2000_isa_info = {
-    .qdev.name  = "ne2k_isa",
-    .qdev.size  = sizeof(ISANE2000State),
-    .qdev.class_init       = isa_ne2000_class_initfn,
-    .qdev.props = (Property[]) {
+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 +5 -5
index ac7dc46..622e4d2 100644
@@ -592,11 +592,11 @@ static void parallel_isa_class_initfn(ObjectClass *klass, void *data)
     ic->init = parallel_isa_initfn;
 }
 
-static ISADeviceInfo parallel_isa_info = {
-    .qdev.name  = "isa-parallel",
-    .qdev.size  = sizeof(ISAParallelState),
-    .qdev.class_init       = parallel_isa_class_initfn,
-    .qdev.props = (Property[]) {
+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 +7 -7
index 4e4dc6d..2d69208 100644
@@ -502,13 +502,13 @@ static void port92_class_initfn(ObjectClass *klass, void *data)
     ic->init = port92_initfn;
 }
 
-static ISADeviceInfo port92_info = {
-    .qdev.name     = "port92",
-    .qdev.size     = sizeof(Port92State),
-    .qdev.vmsd     = &vmstate_port92_isa,
-    .qdev.no_user  = 1,
-    .qdev.reset    = port92_reset,
-    .qdev.class_init          = port92_class_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 +6 -6
index fe5cc6e..2ebe1c5 100644
@@ -503,12 +503,12 @@ static void i8042_class_initfn(ObjectClass *klass, void *data)
     ic->init = i8042_initfn;
 }
 
-static ISADeviceInfo i8042_info = {
-    .qdev.name     = "i8042",
-    .qdev.size     = sizeof(ISAKBDState),
-    .qdev.vmsd     = &vmstate_kbd_isa,
-    .qdev.no_user  = 1,
-    .qdev.class_init          = i8042_class_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 +7 -7
index f7a6b7e..1e28f66 100644
@@ -1397,13 +1397,13 @@ static void sb16_class_initfn(ObjectClass *klass, void *data)
     ic->init = sb16_initfn;
 }
 
-static ISADeviceInfo sb16_info = {
-    .qdev.name     = "sb16",
-    .qdev.desc     = "Creative Sound Blaster 16",
-    .qdev.size     = sizeof (SB16State),
-    .qdev.vmsd     = &vmstate_sb16,
-    .qdev.class_init          = sb16_class_initfn,
-    .qdev.props    = (Property[]) {
+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 +6 -6
index 74ed5fe..2644b13 100644
@@ -885,12 +885,12 @@ static void serial_isa_class_initfn(ObjectClass *klass, void *data)
     ic->init = serial_isa_initfn;
 }
 
-static ISADeviceInfo serial_isa_info = {
-    .qdev.name  = "isa-serial",
-    .qdev.size  = sizeof(ISASerialState),
-    .qdev.vmsd  = &vmstate_isa_serial,
-    .qdev.class_init       = serial_isa_class_initfn,
-    .qdev.props = (Property[]) {
+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 +5 -5
index 6801995..07ed2d0 100644
@@ -47,11 +47,11 @@ static void isa_cirrus_vga_class_initfn(ObjectClass *klass, void *data)
     ic->init = isa_cirrus_vga_initfn;
 }
 
-static ISADeviceInfo sga_info = {
-    .qdev.name    = "sga",
-    .qdev.desc    = "Serial Graphics Adapter",
-    .qdev.size    = sizeof(ISASGAState),
-    .qdev.class_init         = isa_cirrus_vga_class_initfn,
+static DeviceInfo sga_info = {
+    .name    = "sga",
+    .desc    = "Serial Graphics Adapter",
+    .size    = sizeof(ISASGAState),
+    .class_init         = isa_cirrus_vga_class_initfn,
 };
 
 static void sga_register(void)
hw/vga-isa.c +6 -6
index ba7f9bf..cb6af91 100644
@@ -75,12 +75,12 @@ static void vga_class_initfn(ObjectClass *klass, void *data)
     ic->init = vga_initfn;
 }
 
-static ISADeviceInfo vga_info = {
-    .qdev.name     = "isa-vga",
-    .qdev.size     = sizeof(ISAVGAState),
-    .qdev.vmsd     = &vmstate_vga_common,
-    .qdev.reset     = vga_reset_isa,
-    .qdev.class_init          = vga_class_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 +8 -8
index f936089..da2ea32 100644
@@ -275,14 +275,14 @@ static void vmmouse_class_initfn(ObjectClass *klass, void *data)
     ic->init = vmmouse_initfn;
 }
 
-static ISADeviceInfo vmmouse_info = {
-    .qdev.class_init          = vmmouse_class_initfn,
-    .qdev.name     = "vmmouse",
-    .qdev.size     = sizeof(VMMouseState),
-    .qdev.vmsd     = &vmstate_vmmouse,
-    .qdev.no_user  = 1,
-    .qdev.reset    = vmmouse_reset,
-    .qdev.props = (Property[]) {
+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 +5 -5
index 7468812..ffea73d 100644
@@ -150,11 +150,11 @@ static void vmport_class_initfn(ObjectClass *klass, void *data)
     ic->init = vmport_initfn;
 }
 
-static ISADeviceInfo vmport_info = {
-    .qdev.name     = "vmport",
-    .qdev.size     = sizeof(VMPortState),
-    .qdev.no_user  = 1,
-    .qdev.class_init          = vmport_class_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 +6 -6
index 3869e91..68965d6 100644
@@ -126,12 +126,12 @@ static void wdt_ib700_class_init(ObjectClass *klass, void *data)
     ic->init = wdt_ib700_init;
 }
 
-static ISADeviceInfo wdt_ib700_info = {
-    .qdev.name  = "ib700",
-    .qdev.size  = sizeof(IB700State),
-    .qdev.vmsd  = &vmstate_ib700,
-    .qdev.reset = wdt_ib700_reset,
-    .qdev.class_init       = wdt_ib700_class_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
#43 lore raw

PATCH v3 44/197 usb: don't access dev->info directly

In reply to Anthony Liguori
---
 hw/usb-bus.c  |   81 +++++++++++++++++++++++++++++++++++++++++++++++++++++---
 hw/usb-desc.c |   18 ++++++------
 hw/usb.c      |   24 +++++++----------
 hw/usb.h      |   22 +++++++++++++++
 4 files changed, 117 insertions(+), 28 deletions(-)
hw/usb-bus.c +76 -5
index 8924ac3..24a805d 100644
@@ -65,13 +65,22 @@ USBBus *usb_bus_find(int busnr)
     return NULL;
 }
 
+static int usb_device_init(USBDevice *dev)
+{
+    if (dev->info->init) {
+        return dev->info->init(dev);
+    }
+    return 0;
+}
+
 static int usb_qdev_init(DeviceState *qdev, DeviceInfo *base)
 {
     USBDevice *dev = USB_DEVICE(qdev);
     USBDeviceInfo *info = DO_UPCAST(USBDeviceInfo, qdev, base);
     int rc;
 
-    pstrcpy(dev->product_desc, sizeof(dev->product_desc), info->product_desc);
+    pstrcpy(dev->product_desc, sizeof(dev->product_desc),
+            usb_device_get_product_desc(dev));
     dev->info = info;
     dev->auto_attach = 1;
     QLIST_INIT(&dev->strings);
@@ -79,7 +88,7 @@ static int usb_qdev_init(DeviceState *qdev, DeviceInfo *base)
     if (rc != 0) {
         goto err;
     }
-    rc = dev->info->init(dev);
+    rc = usb_device_init(dev);
     if (rc != 0) {
         goto err;
     }
@@ -96,6 +105,13 @@ err:
     return rc;
 }
 
+static void usb_device_handle_destroy(USBDevice *dev)
+{
+    if (dev->info->handle_destroy) {
+        dev->info->handle_destroy(dev);
+    }
+}
+
 static int usb_qdev_exit(DeviceState *qdev)
 {
     USBDevice *dev = USB_DEVICE(qdev);
@@ -103,9 +119,7 @@ static int usb_qdev_exit(DeviceState *qdev)
     if (dev->attached) {
         usb_device_detach(dev);
     }
-    if (dev->info->handle_destroy) {
-        dev->info->handle_destroy(dev);
-    }
+    usb_device_handle_destroy(dev);
     if (dev->port) {
         usb_release_port(dev);
     }
@@ -481,6 +495,63 @@ USBDevice *usbdevice_create(const char *cmdline)
     return usb->usbdevice_init(params);
 }
 
+int usb_device_handle_packet(USBDevice *dev, USBPacket *p)
+{
+    if (dev->info->handle_packet) {
+        return dev->info->handle_packet(dev, p);
+    }
+    return -ENOSYS;
+}
+
+void usb_device_cancel_packet(USBDevice *dev, USBPacket *p)
+{
+    if (dev->info->cancel_packet) {
+        dev->info->cancel_packet(dev, p);
+    }
+}
+
+void usb_device_handle_attach(USBDevice *dev)
+{
+    if (dev->info->handle_attach) {
+        dev->info->handle_attach(dev);
+    }
+}
+
+void usb_device_handle_reset(USBDevice *dev)
+{
+    if (dev->info->handle_reset) {
+        dev->info->handle_reset(dev);
+    }
+}
+
+int usb_device_handle_control(USBDevice *dev, USBPacket *p, int request,
+                              int value, int index, int length, uint8_t *data)
+{
+    if (dev->info->handle_control) {
+        return dev->info->handle_control(dev, p, request, value, index, length,
+                                         data);
+    }
+    return -ENOSYS;
+}
+
+int usb_device_handle_data(USBDevice *dev, USBPacket *p)
+{
+    if (dev->info->handle_data) {
+        return dev->info->handle_data(dev, p);
+    }
+    return -ENOSYS;
+}
+
+const char *usb_device_get_product_desc(USBDevice *dev)
+{
+    return dev->info->product_desc;
+}
+
+const USBDesc *usb_device_get_usb_desc(USBDevice *dev)
+{
+    return dev->info->usb_desc;
+}
+
 static TypeInfo usb_device_type_info = {
     .name = TYPE_USB_DEVICE,
     .parent = TYPE_DEVICE,
hw/usb-desc.c +9 -9
index ae2d384..1f5fc7a 100644
@@ -225,7 +225,7 @@ int usb_desc_other(const USBDescOther *desc, uint8_t *dest, size_t len)
 
 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) {
@@ -242,7 +242,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;
@@ -258,7 +258,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)) {
@@ -267,7 +267,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);
@@ -323,7 +323,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;
         }
@@ -342,7 +342,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;
@@ -350,9 +350,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) {
@@ -407,7 +407,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 i, ret = -1;
 
     assert(desc != NULL);
hw/usb.c +10 -14
index 2216efe..e1cbfec 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 = dev;
@@ -357,7 +353,7 @@ void usb_packet_complete(USBDevice *dev, USBPacket *p)
 void usb_cancel_packet(USBPacket * p)
 {
     assert(p->owner != NULL);
-    p->owner->info->cancel_packet(p->owner, p);
+    usb_device_cancel_packet(p->owner, p);
     p->owner = NULL;
 }
 
hw/usb.h +22 -0
index 5445927..e05c00d 100644
@@ -1,3 +1,6 @@
+#ifndef QEMU_USB_H
+#define QEMU_USB_H
+
 /*
  * QEMU USB API
  *
@@ -404,3 +407,22 @@ static inline USBBus *usb_bus_from_device(USBDevice *d)
 {
     return DO_UPCAST(USBBus, qbus, d->qdev.parent_bus);
 }
+
+int usb_device_handle_packet(USBDevice *dev, USBPacket *p);
+
+void usb_device_cancel_packet(USBDevice *dev, USBPacket *p);
+
+void usb_device_handle_attach(USBDevice *dev);
+
+void usb_device_handle_reset(USBDevice *dev);
+
+int usb_device_handle_control(USBDevice *dev, USBPacket *p, int request, int value,
+                              int index, int length, uint8_t *data);
+
+int usb_device_handle_data(USBDevice *dev, USBPacket *p);
+
+const char *usb_device_get_product_desc(USBDevice *dev);
+
+const USBDesc *usb_device_get_usb_desc(USBDevice *dev);
+
+#endif
Signature · 1 line
1.7.4.1
#44 lore raw

PATCH v3 45/197 usb: get rid of info pointer

In reply to Anthony Liguori
---
 hw/usb-bus.c |  154 ++++++++++++++++++++++++++++++++-------------------------
 hw/usb.h     |    1 -
 2 files changed, 86 insertions(+), 69 deletions(-)
hw/usb-bus.c +86 -68
index 24a805d..8d9c82d 100644
@@ -67,21 +67,103 @@ USBBus *usb_bus_find(int busnr)
 
 static int usb_device_init(USBDevice *dev)
 {
-    if (dev->info->init) {
-        return dev->info->init(dev);
+    USBDeviceInfo *info = DO_UPCAST(USBDeviceInfo, qdev,
+                                    qdev_get_info(DEVICE(dev)));
+    if (info->init) {
+        return info->init(dev);
     }
     return 0;
 }
 
+static void usb_device_handle_destroy(USBDevice *dev)
+{
+    USBDeviceInfo *info = DO_UPCAST(USBDeviceInfo, qdev,
+                                    qdev_get_info(DEVICE(dev)));
+    if (info->handle_destroy) {
+        info->handle_destroy(dev);
+    }
+}
+
+int usb_device_handle_packet(USBDevice *dev, USBPacket *p)
+{
+    USBDeviceInfo *info = DO_UPCAST(USBDeviceInfo, qdev,
+                                    qdev_get_info(DEVICE(dev)));
+    if (info->handle_packet) {
+        return info->handle_packet(dev, p);
+    }
+    return -ENOSYS;
+}
+
+void usb_device_cancel_packet(USBDevice *dev, USBPacket *p)
+{
+    USBDeviceInfo *info = DO_UPCAST(USBDeviceInfo, qdev,
+                                    qdev_get_info(DEVICE(dev)));
+    if (info->cancel_packet) {
+        info->cancel_packet(dev, p);
+    }
+}
+
+void usb_device_handle_attach(USBDevice *dev)
+{
+    USBDeviceInfo *info = DO_UPCAST(USBDeviceInfo, qdev,
+                                    qdev_get_info(DEVICE(dev)));
+    if (info->handle_attach) {
+        info->handle_attach(dev);
+    }
+}
+
+void usb_device_handle_reset(USBDevice *dev)
+{
+    USBDeviceInfo *info = DO_UPCAST(USBDeviceInfo, qdev,
+                                    qdev_get_info(DEVICE(dev)));
+    if (info->handle_reset) {
+        info->handle_reset(dev);
+    }
+}
+
+int usb_device_handle_control(USBDevice *dev, USBPacket *p, int request,
+                              int value, int index, int length, uint8_t *data)
+{
+    USBDeviceInfo *info = DO_UPCAST(USBDeviceInfo, qdev,
+                                    qdev_get_info(DEVICE(dev)));
+    if (info->handle_control) {
+        return info->handle_control(dev, p, request, value, index, length,
+                                         data);
+    }
+    return -ENOSYS;
+}
+
+int usb_device_handle_data(USBDevice *dev, USBPacket *p)
+{
+    USBDeviceInfo *info = DO_UPCAST(USBDeviceInfo, qdev,
+                                    qdev_get_info(DEVICE(dev)));
+    if (info->handle_data) {
+        return info->handle_data(dev, p);
+    }
+    return -ENOSYS;
+}
+
+const char *usb_device_get_product_desc(USBDevice *dev)
+{
+    USBDeviceInfo *info = DO_UPCAST(USBDeviceInfo, qdev,
+                                    qdev_get_info(DEVICE(dev)));
+    return info->product_desc;
+}
+
+const USBDesc *usb_device_get_usb_desc(USBDevice *dev)
+{
+    USBDeviceInfo *info = DO_UPCAST(USBDeviceInfo, qdev,
+                                    qdev_get_info(DEVICE(dev)));
+    return info->usb_desc;
+}
+
 static int usb_qdev_init(DeviceState *qdev, DeviceInfo *base)
 {
     USBDevice *dev = USB_DEVICE(qdev);
-    USBDeviceInfo *info = DO_UPCAST(USBDeviceInfo, qdev, base);
     int rc;
 
     pstrcpy(dev->product_desc, sizeof(dev->product_desc),
             usb_device_get_product_desc(dev));
-    dev->info = info;
     dev->auto_attach = 1;
     QLIST_INIT(&dev->strings);
     rc = usb_claim_port(dev);
@@ -105,13 +187,6 @@ err:
     return rc;
 }
 
-static void usb_device_handle_destroy(USBDevice *dev)
-{
-    if (dev->info->handle_destroy) {
-        dev->info->handle_destroy(dev);
-    }
-}
-
 static int usb_qdev_exit(DeviceState *qdev)
 {
     USBDevice *dev = USB_DEVICE(qdev);
@@ -495,63 +570,6 @@ USBDevice *usbdevice_create(const char *cmdline)
     return usb->usbdevice_init(params);
 }
 
-int usb_device_handle_packet(USBDevice *dev, USBPacket *p)
-{
-    if (dev->info->handle_packet) {
-        return dev->info->handle_packet(dev, p);
-    }
-    return -ENOSYS;
-}
-
-void usb_device_cancel_packet(USBDevice *dev, USBPacket *p)
-{
-    if (dev->info->cancel_packet) {
-        dev->info->cancel_packet(dev, p);
-    }
-}
-
-void usb_device_handle_attach(USBDevice *dev)
-{
-    if (dev->info->handle_attach) {
-        dev->info->handle_attach(dev);
-    }
-}
-
-void usb_device_handle_reset(USBDevice *dev)
-{
-    if (dev->info->handle_reset) {
-        dev->info->handle_reset(dev);
-    }
-}
-
-int usb_device_handle_control(USBDevice *dev, USBPacket *p, int request,
-                              int value, int index, int length, uint8_t *data)
-{
-    if (dev->info->handle_control) {
-        return dev->info->handle_control(dev, p, request, value, index, length,
-                                         data);
-    }
-    return -ENOSYS;
-}
-
-int usb_device_handle_data(USBDevice *dev, USBPacket *p)
-{
-    if (dev->info->handle_data) {
-        return dev->info->handle_data(dev, p);
-    }
-    return -ENOSYS;
-}
-
-const char *usb_device_get_product_desc(USBDevice *dev)
-{
-    return dev->info->product_desc;
-}
-
-const USBDesc *usb_device_get_usb_desc(USBDevice *dev)
-{
-    return dev->info->usb_desc;
-}
-
 static TypeInfo usb_device_type_info = {
     .name = TYPE_USB_DEVICE,
     .parent = TYPE_DEVICE,
hw/usb.h +0 -1
index e05c00d..ee780b0 100644
@@ -179,7 +179,6 @@ typedef struct USBDeviceClass {
 /* definition of a USB device */
 struct USBDevice {
     DeviceState qdev;
-    USBDeviceInfo *info;
     USBPort *port;
     char *port_path;
     void *opaque;
Signature · 1 line
1.7.4.1
#45 lore raw

PATCH v3 46/197 usb: promote all of the methods for USBDevice to class methods

In reply to Anthony Liguori
---
 hw/usb-bt.c     |   23 +++++++++++------
 hw/usb-bus.c    |   66 ++++++++++++++++++++----------------------------
 hw/usb-ccid.c   |   27 ++++++++++++-------
 hw/usb-hid.c    |   75 +++++++++++++++++++++++++++++++++++-------------------
 hw/usb-hub.c    |   25 +++++++++++------
 hw/usb-msd.c    |   31 ++++++++++++++---------
 hw/usb-net.c    |   32 ++++++++++++++---------
 hw/usb-serial.c |   55 +++++++++++++++++++++++++--------------
 hw/usb-wacom.c  |   25 +++++++++++------
 hw/usb.h        |   64 +++++++++++++++++++++++-----------------------
 usb-linux.c     |   27 ++++++++++++-------
 11 files changed, 263 insertions(+), 187 deletions(-)
hw/usb-bt.c +15 -8
index f30eec1..fd71f1f 100644
@@ -549,18 +549,25 @@ static const VMStateDescription vmstate_usb_bt = {
     .unmigratable = 1,
 };
 
+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 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,
+    .qdev.class_init= usb_bt_class_initfn,
 };
 
 static void usb_bt_register_devices(void)
hw/usb-bus.c +28 -38

121 lines not on this page · raw message

hw/usb-ccid.c +17 -10
index 997ef31..db67837 100644
@@ -1294,24 +1294,31 @@ static VMStateDescription ccid_vmstate = {
     }
 };
 
+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 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.class_init= ccid_class_initfn,
+    .qdev.vmsd      = &ccid_vmstate,
     .qdev.props     = (Property[]) {
         DEFINE_PROP_UINT8("debug", USBCCIDState, debug, 0),
         DEFINE_PROP_END_OF_LIST(),
     },
-    .qdev.vmsd      = &ccid_vmstate,
+    .usbdevice_name = "ccid",
 };
 
 static TypeInfo ccid_card_type_info = {
hw/usb-hid.c +48 -27

94 lines not on this page · raw message

hw/usb-hub.c +16 -9
index e195937..5a52964 100644
@@ -540,19 +540,26 @@ static const VMStateDescription vmstate_usb_hub = {
     }
 };
 
+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 USBDeviceInfo hub_info = {
-    .product_desc   = "QEMU USB Hub",
     .qdev.name      = "usb-hub",
-    .qdev.fw_name    = "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,
+    .qdev.class_init= usb_hub_class_initfn,
 };
 
 static void usb_hub_register_devices(void)
hw/usb-msd.c +19 -12
index 4c06950..bb63a6a 100644
@@ -634,28 +634,35 @@ static const VMStateDescription vmstate_usb_msd = {
     }
 };
 
+static void usb_msd_class_initfn(ObjectClass *klass, void *data)
+{
+    USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
+
+    uc->init           = usb_msd_initfn;
+    uc->product_desc   = "QEMU USB MSD";
+    uc->usb_desc       = &desc;
+    uc->handle_packet  = usb_generic_handle_packet;
+    uc->cancel_packet  = usb_msd_cancel_io;
+    uc->handle_attach  = usb_desc_attach;
+    uc->handle_reset   = usb_msd_handle_reset;
+    uc->handle_control = usb_msd_handle_control;
+    uc->handle_data    = usb_msd_handle_data;
+}
+
 static struct USBDeviceInfo msd_info = {
-    .product_desc   = "QEMU USB MSD",
     .qdev.name      = "usb-storage",
-    .qdev.fw_name      = "storage",
+    .qdev.fw_name   = "storage",
     .qdev.size      = sizeof(MSDState),
     .qdev.vmsd      = &vmstate_usb_msd,
-    .usb_desc       = &desc,
-    .init           = usb_msd_initfn,
-    .handle_packet  = usb_generic_handle_packet,
-    .cancel_packet  = usb_msd_cancel_io,
-    .handle_attach  = usb_desc_attach,
-    .handle_reset   = usb_msd_handle_reset,
-    .handle_control = usb_msd_handle_control,
-    .handle_data    = usb_msd_handle_data,
-    .usbdevice_name = "disk",
-    .usbdevice_init = usb_msd_init,
+    .qdev.class_init= usb_msd_class_initfn,
     .qdev.props     = (Property[]) {
         DEFINE_BLOCK_PROPERTIES(MSDState, conf),
         DEFINE_PROP_STRING("serial", MSDState, serial),
         DEFINE_PROP_BIT("removable", MSDState, removable, 0, false),
         DEFINE_PROP_END_OF_LIST(),
     },
+    .usbdevice_name = "disk",
+    .usbdevice_init = usb_msd_init,
 };
 
 static void usb_msd_register_devices(void)
hw/usb-net.c +20 -12
index c4b29a9..50c66d7 100644
@@ -1398,25 +1398,33 @@ static const VMStateDescription vmstate_usb_net = {
     .unmigratable = 1,
 };
 
+static void usb_net_class_initfn(ObjectClass *klass, void *data)
+{
+    USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
+
+    uc->init           = usb_net_initfn;
+    uc->product_desc   = "QEMU USB Network Interface";
+    uc->usb_desc       = &desc_net;
+    uc->handle_packet  = usb_generic_handle_packet;
+    uc->handle_reset   = usb_net_handle_reset;
+    uc->handle_control = usb_net_handle_control;
+    uc->handle_data    = usb_net_handle_data;
+    uc->handle_destroy = usb_net_handle_destroy;
+}
+
 static struct USBDeviceInfo net_info = {
-    .product_desc   = "QEMU USB Network Interface",
     .qdev.name      = "usb-net",
-    .qdev.fw_name    = "network",
+    .qdev.fw_name   = "network",
     .qdev.size      = sizeof(USBNetState),
     .qdev.vmsd      = &vmstate_usb_net,
-    .usb_desc       = &desc_net,
-    .init           = usb_net_initfn,
-    .handle_packet  = usb_generic_handle_packet,
-    .handle_reset   = usb_net_handle_reset,
-    .handle_control = usb_net_handle_control,
-    .handle_data    = usb_net_handle_data,
-    .handle_destroy = usb_net_handle_destroy,
-    .usbdevice_name = "net",
-    .usbdevice_init = usb_net_init,
+    .qdev.class_init= usb_net_class_initfn,
     .qdev.props     = (Property[]) {
         DEFINE_NIC_PROPERTIES(USBNetState, conf),
         DEFINE_PROP_END_OF_LIST(),
-    }
+    },
+
+    .usbdevice_name = "net",
+    .usbdevice_init = usb_net_init,
 };
 
 static void usb_net_register_devices(void)
hw/usb-serial.c +35 -20

79 lines not on this page · raw message

hw/usb-wacom.c +16 -9
index 2558006..448b8f2 100644
@@ -356,20 +356,27 @@ static const VMStateDescription vmstate_usb_wacom = {
     .unmigratable = 1,
 };
 
+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 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,
+    .qdev.class_init= usb_wacom_class_init,
+    .usbdevice_name = "wacom-tablet",
 };
 
 static void usb_wacom_register_devices(void)
hw/usb.h +32 -32

78 lines not on this page · raw message

usb-linux.c +17 -10
index ab4c693..15e3d5e 100644
@@ -1428,20 +1428,25 @@ static const VMStateDescription vmstate_usb_host = {
     .unmigratable = 1,
 };
 
+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 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.class_init= usb_host_class_initfn,
     .qdev.props     = (Property[]) {
         DEFINE_PROP_UINT32("hostbus",  USBHostDevice, match.bus_num,    0),
         DEFINE_PROP_UINT32("hostaddr", USBHostDevice, match.addr,       0),
@@ -1451,6 +1456,8 @@ static struct USBDeviceInfo usb_host_dev_info = {
         DEFINE_PROP_UINT32("isobufs",  USBHostDevice, iso_urb_count,    4),
         DEFINE_PROP_END_OF_LIST(),
     },
+    .usbdevice_name = "host",
+    .usbdevice_init = usb_host_device_open,
 };
 
 static void usb_host_register_devices(void)
Signature · 1 line
1.7.4.1
#46 lore raw

PATCH v3 47/197 usb: use a factory instead of doing silly things for legacy

In reply to Anthony Liguori
---
 hw/usb-bt.c     |    2 +-
 hw/usb-bus.c    |   51 +++++++++++++++++++++++++++++----------------------
 hw/usb-ccid.c   |    3 +--
 hw/usb-hid.c    |   45 ++++++++++++++++++++++-----------------------
 hw/usb-hub.c    |    2 +-
 hw/usb-msd.c    |    4 +---
 hw/usb-net.c    |    5 +----
 hw/usb-serial.c |    9 ++-------
 hw/usb-wacom.c  |    3 +--
 hw/usb.h        |    8 +++-----
 usb-bsd.c       |   23 +++++++++++++++--------
 usb-linux.c     |    4 +---
 usb-redir.c     |   25 ++++++++++++++++---------
 13 files changed, 94 insertions(+), 90 deletions(-)
hw/usb-bt.c +1 -1
index fd71f1f..8dea574 100644
@@ -572,6 +572,6 @@ static struct USBDeviceInfo bt_info = {
 
 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 +29 -22

88 lines not on this page · raw message

hw/usb-ccid.c +1 -2
index db67837..24b1a1f 100644
@@ -1318,7 +1318,6 @@ static struct USBDeviceInfo ccid_info = {
         DEFINE_PROP_UINT8("debug", USBCCIDState, debug, 0),
         DEFINE_PROP_END_OF_LIST(),
     },
-    .usbdevice_name = "ccid",
 };
 
 static TypeInfo ccid_card_type_info = {
@@ -1332,6 +1331,6 @@ static TypeInfo ccid_card_type_info = {
 static void ccid_register_devices(void)
 {
     type_register_static(&ccid_card_type_info);
-    usb_qdev_register(&ccid_info);
+    usb_qdev_register(&ccid_info, "ccid", NULL);
 }
 device_init(ccid_register_devices)
hw/usb-hid.c +22 -23

66 lines not on this page · raw message

hw/usb-hub.c +1 -1
index 5a52964..b5114dd 100644
@@ -564,6 +564,6 @@ static struct USBDeviceInfo hub_info = {
 
 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 +1 -3
index bb63a6a..a6226b4 100644
@@ -661,12 +661,10 @@ static struct USBDeviceInfo msd_info = {
         DEFINE_PROP_BIT("removable", MSDState, removable, 0, false),
         DEFINE_PROP_END_OF_LIST(),
     },
-    .usbdevice_name = "disk",
-    .usbdevice_init = usb_msd_init,
 };
 
 static void usb_msd_register_devices(void)
 {
-    usb_qdev_register(&msd_info);
+    usb_qdev_register(&msd_info, "disk", usb_msd_init);
 }
 device_init(usb_msd_register_devices)
hw/usb-net.c +1 -4
index 50c66d7..1f14b27 100644
@@ -1422,13 +1422,10 @@ static struct USBDeviceInfo net_info = {
         DEFINE_NIC_PROPERTIES(USBNetState, conf),
         DEFINE_PROP_END_OF_LIST(),
     },
-
-    .usbdevice_name = "net",
-    .usbdevice_init = usb_net_init,
 };
 
 static void usb_net_register_devices(void)
 {
-    usb_qdev_register(&net_info);
+    usb_qdev_register(&net_info, "net", usb_net_init);
 }
 device_init(usb_net_register_devices)
hw/usb-serial.c +2 -7
index 33d6163..407ca72 100644
@@ -600,9 +600,6 @@ static struct USBDeviceInfo serial_info = {
         DEFINE_PROP_CHR("chardev", USBSerialState, cs),
         DEFINE_PROP_END_OF_LIST(),
     },
-
-    .usbdevice_name = "serial",
-    .usbdevice_init = usb_serial_init,
 };
 
 static void usb_braille_class_initfn(ObjectClass *klass, void *data)
@@ -628,13 +625,11 @@ static struct USBDeviceInfo braille_info = {
         DEFINE_PROP_CHR("chardev", USBSerialState, cs),
         DEFINE_PROP_END_OF_LIST(),
     },
-    .usbdevice_name = "braille",
-    .usbdevice_init = usb_braille_init,
 };
 
 static void usb_serial_register_devices(void)
 {
-    usb_qdev_register(&serial_info);
-    usb_qdev_register(&braille_info);
+    usb_qdev_register(&serial_info, "serial", usb_serial_init);
+    usb_qdev_register(&braille_info, "braille", usb_braille_init);
 }
 device_init(usb_serial_register_devices)
hw/usb-wacom.c +1 -2
index 448b8f2..4a671ef 100644
@@ -376,11 +376,10 @@ static struct USBDeviceInfo wacom_info = {
     .qdev.size      = sizeof(USBWacomState),
     .qdev.vmsd      = &vmstate_usb_wacom,
     .qdev.class_init= usb_wacom_class_init,
-    .usbdevice_name = "wacom-tablet",
 };
 
 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.h +3 -5
index 602ddb9..eac0bf5 100644
@@ -258,9 +258,6 @@ struct USBDevice {
 
 struct USBDeviceInfo {
     DeviceInfo qdev;
-    /* handle legacy -usbdevice command line options */
-    const char *usbdevice_name;
-    USBDevice *(*usbdevice_init)(const char *params);
 };
 
 typedef struct USBPortOps {
@@ -384,8 +381,9 @@ struct USBBusOps {
 
 void usb_bus_new(USBBus *bus, USBBusOps *ops, DeviceState *host);
 USBBus *usb_bus_find(int busnr);
-void usb_qdev_register(USBDeviceInfo *info);
-void usb_qdev_register_many(USBDeviceInfo *info);
+void usb_qdev_register(USBDeviceInfo *info,
+                       const char *usbdevice_name,
+                       USBDevice *(*usbdevice_init)(const char *params));
 USBDevice *usb_create(USBBus *bus, const char *name);
 USBDevice *usb_create_simple(USBBus *bus, const char *name);
 USBDevice *usbdevice_create(const char *cmdline);
usb-bsd.c +15 -8
index 1187552..8637c77 100644
@@ -397,21 +397,28 @@ fail:
     return ret;
 }
 
+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 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,
+    .qdev.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 +1 -3
index 15e3d5e..6dbcf2a 100644
@@ -1456,13 +1456,11 @@ static struct USBDeviceInfo usb_host_dev_info = {
         DEFINE_PROP_UINT32("isobufs",  USBHostDevice, iso_urb_count,    4),
         DEFINE_PROP_END_OF_LIST(),
     },
-    .usbdevice_name = "host",
-    .usbdevice_init = usb_host_device_open,
 };
 
 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 +16 -9
index fb91c92..a297501 100644
@@ -1227,17 +1227,24 @@ static void usbredir_interrupt_packet(void *priv, uint32_t id,
     }
 }
 
+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 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.class_init= usbredir_class_initfn,
     .qdev.props     = (Property[]) {
         DEFINE_PROP_CHR("chardev", USBRedirDevice, cs),
         DEFINE_PROP_UINT8("debug", USBRedirDevice, debug, 0),
@@ -1247,6 +1254,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
#47 lore raw

PATCH v3 48/197 usb: kill USBDeviceInfo

In reply to Anthony Liguori
---
 hw/usb-bt.c     |   10 +++++-----
 hw/usb-bus.c    |   14 +++++++-------
 hw/usb-ccid.c   |   14 +++++++-------
 hw/usb-hid.c    |   30 +++++++++++++++---------------
 hw/usb-hub.c    |   12 ++++++------
 hw/usb-msd.c    |   14 +++++++-------
 hw/usb-net.c    |   14 +++++++-------
 hw/usb-serial.c |   24 ++++++++++++------------
 hw/usb-wacom.c  |   12 ++++++------
 hw/usb.h        |    7 +------
 usb-bsd.c       |    8 ++++----
 usb-linux.c     |   12 ++++++------
 usb-redir.c     |   10 +++++-----
 13 files changed, 88 insertions(+), 93 deletions(-)
hw/usb-bt.c +5 -5
index 8dea574..6e210ac 100644
@@ -563,11 +563,11 @@ static void usb_bt_class_initfn(ObjectClass *klass, void *data)
     uc->handle_destroy = usb_bt_handle_destroy;
 }
 
-static struct USBDeviceInfo bt_info = {
-    .qdev.name      = "usb-bt-dongle",
-    .qdev.size      = sizeof(struct USBBtState),
-    .qdev.vmsd      = &vmstate_usb_bt,
-    .qdev.class_init= usb_bt_class_initfn,
+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)
hw/usb-bus.c +7 -7
index b86d6c8..0e635c2 100644
@@ -200,19 +200,19 @@ typedef struct LegacyUSBFactory
 
 static GSList *legacy_usb_factory;
 
-void usb_qdev_register(USBDeviceInfo *info,
+void usb_qdev_register(DeviceInfo *info,
                        const char *usbdevice_name,
                        USBDevice *(*usbdevice_init)(const char *params))
 {
-    info->qdev.bus_info = &usb_bus_info;
-    info->qdev.init     = usb_qdev_init;
-    info->qdev.unplug   = qdev_simple_unplug_cb;
-    info->qdev.exit     = usb_qdev_exit;
-    qdev_register_subclass(&info->qdev, TYPE_USB_DEVICE);
+    info->bus_info = &usb_bus_info;
+    info->init     = usb_qdev_init;
+    info->unplug   = qdev_simple_unplug_cb;
+    info->exit     = usb_qdev_exit;
+    qdev_register_subclass(info, TYPE_USB_DEVICE);
 
     if (usbdevice_name) {
         LegacyUSBFactory *f = g_malloc0(sizeof(*f));
-        f->name = info->qdev.name;
+        f->name = info->name;
         f->usbdevice_name = usbdevice_name;
         f->usbdevice_init = usbdevice_init;
         legacy_usb_factory = g_slist_append(legacy_usb_factory, f);
hw/usb-ccid.c +7 -7
index 24b1a1f..41a53aa 100644
@@ -1308,13 +1308,13 @@ static void ccid_class_initfn(ObjectClass *klass, void *data)
     uc->handle_destroy = ccid_handle_destroy;
 }
 
-static struct USBDeviceInfo ccid_info = {
-    .qdev.name      = CCID_DEV_NAME,
-    .qdev.desc      = "CCID Rev 1.1 smartcard reader",
-    .qdev.size      = sizeof(USBCCIDState),
-    .qdev.class_init= ccid_class_initfn,
-    .qdev.vmsd      = &ccid_vmstate,
-    .qdev.props     = (Property[]) {
+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(),
     },
hw/usb-hid.c +15 -15
index 75642cf..2538b9c 100644
@@ -574,11 +574,11 @@ static void usb_tablet_class_initfn(ObjectClass *klass, void *data)
     uc->handle_destroy = usb_hid_handle_destroy;
 }
 
-static struct USBDeviceInfo usb_tablet_info = {
-    .qdev.name      = "usb-tablet",
-    .qdev.size      = sizeof(USBHIDState),
-    .qdev.vmsd      = &vmstate_usb_ptr,
-    .qdev.class_init= usb_tablet_class_initfn,
+static struct DeviceInfo usb_tablet_info = {
+    .name      = "usb-tablet",
+    .size      = sizeof(USBHIDState),
+    .vmsd      = &vmstate_usb_ptr,
+    .class_init= usb_tablet_class_initfn,
 };
 
 static void usb_mouse_class_initfn(ObjectClass *klass, void *data)
@@ -595,11 +595,11 @@ static void usb_mouse_class_initfn(ObjectClass *klass, void *data)
     uc->handle_destroy = usb_hid_handle_destroy;
 }
 
-static struct USBDeviceInfo usb_mouse_info = {
-    .qdev.name      = "usb-mouse",
-    .qdev.size      = sizeof(USBHIDState),
-    .qdev.vmsd      = &vmstate_usb_ptr,
-    .qdev.class_init= usb_mouse_class_initfn,
+static struct DeviceInfo usb_mouse_info = {
+    .name      = "usb-mouse",
+    .size      = sizeof(USBHIDState),
+    .vmsd      = &vmstate_usb_ptr,
+    .class_init= usb_mouse_class_initfn,
 };
 
 static void usb_keyboard_class_initfn(ObjectClass *klass, void *data)
@@ -616,11 +616,11 @@ static void usb_keyboard_class_initfn(ObjectClass *klass, void *data)
     uc->handle_destroy = usb_hid_handle_destroy;
 }
 
-static struct USBDeviceInfo usb_keyboard_info = {
-    .qdev.name      = "usb-kbd",
-    .qdev.size      = sizeof(USBHIDState),
-    .qdev.vmsd      = &vmstate_usb_kbd,
-    .qdev.class_init= usb_keyboard_class_initfn,
+static struct DeviceInfo usb_keyboard_info = {
+    .name      = "usb-kbd",
+    .size      = sizeof(USBHIDState),
+    .vmsd      = &vmstate_usb_kbd,
+    .class_init= usb_keyboard_class_initfn,
 };
 
 static void usb_hid_register_devices(void)
hw/usb-hub.c +6 -6
index b5114dd..f997152 100644
@@ -554,12 +554,12 @@ static void  usb_hub_class_initfn(ObjectClass *klass, void *data)
     uc->handle_destroy = usb_hub_handle_destroy;
 }
 
-static struct USBDeviceInfo hub_info = {
-    .qdev.name      = "usb-hub",
-    .qdev.fw_name   = "hub",
-    .qdev.size      = sizeof(USBHubState),
-    .qdev.vmsd      = &vmstate_usb_hub,
-    .qdev.class_init= usb_hub_class_initfn,
+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)
hw/usb-msd.c +7 -7
index a6226b4..e4a1e4e 100644
@@ -649,13 +649,13 @@ static void usb_msd_class_initfn(ObjectClass *klass, void *data)
     uc->handle_data    = usb_msd_handle_data;
 }
 
-static struct USBDeviceInfo msd_info = {
-    .qdev.name      = "usb-storage",
-    .qdev.fw_name   = "storage",
-    .qdev.size      = sizeof(MSDState),
-    .qdev.vmsd      = &vmstate_usb_msd,
-    .qdev.class_init= usb_msd_class_initfn,
-    .qdev.props     = (Property[]) {
+static struct DeviceInfo msd_info = {
+    .name      = "usb-storage",
+    .fw_name   = "storage",
+    .size      = sizeof(MSDState),
+    .vmsd      = &vmstate_usb_msd,
+    .class_init= usb_msd_class_initfn,
+    .props     = (Property[]) {
         DEFINE_BLOCK_PROPERTIES(MSDState, conf),
         DEFINE_PROP_STRING("serial", MSDState, serial),
         DEFINE_PROP_BIT("removable", MSDState, removable, 0, false),
hw/usb-net.c +7 -7
index 1f14b27..61a8e86 100644
@@ -1412,13 +1412,13 @@ static void usb_net_class_initfn(ObjectClass *klass, void *data)
     uc->handle_destroy = usb_net_handle_destroy;
 }
 
-static struct USBDeviceInfo net_info = {
-    .qdev.name      = "usb-net",
-    .qdev.fw_name   = "network",
-    .qdev.size      = sizeof(USBNetState),
-    .qdev.vmsd      = &vmstate_usb_net,
-    .qdev.class_init= usb_net_class_initfn,
-    .qdev.props     = (Property[]) {
+static struct DeviceInfo net_info = {
+    .name      = "usb-net",
+    .fw_name   = "network",
+    .size      = sizeof(USBNetState),
+    .vmsd      = &vmstate_usb_net,
+    .class_init= usb_net_class_initfn,
+    .props     = (Property[]) {
         DEFINE_NIC_PROPERTIES(USBNetState, conf),
         DEFINE_PROP_END_OF_LIST(),
     },
hw/usb-serial.c +12 -12
index 407ca72..73bb80b 100644
@@ -591,12 +591,12 @@ static void usb_serial_class_initfn(ObjectClass *klass, void *data)
     uc->handle_destroy = usb_serial_handle_destroy;
 }
 
-static struct USBDeviceInfo serial_info = {
-    .qdev.name      = "usb-serial",
-    .qdev.size      = sizeof(USBSerialState),
-    .qdev.vmsd      = &vmstate_usb_serial,
-    .qdev.class_init= usb_serial_class_initfn,
-    .qdev.props     = (Property[]) {
+static struct DeviceInfo serial_info = {
+    .name      = "usb-serial",
+    .size      = sizeof(USBSerialState),
+    .vmsd      = &vmstate_usb_serial,
+    .class_init= usb_serial_class_initfn,
+    .props     = (Property[]) {
         DEFINE_PROP_CHR("chardev", USBSerialState, cs),
         DEFINE_PROP_END_OF_LIST(),
     },
@@ -616,12 +616,12 @@ static void usb_braille_class_initfn(ObjectClass *klass, void *data)
     uc->handle_destroy = usb_serial_handle_destroy;
 }
 
-static struct USBDeviceInfo braille_info = {
-    .qdev.name      = "usb-braille",
-    .qdev.size      = sizeof(USBSerialState),
-    .qdev.vmsd      = &vmstate_usb_serial,
-    .qdev.class_init= usb_braille_class_initfn,
-    .qdev.props     = (Property[]) {
+static struct DeviceInfo braille_info = {
+    .name      = "usb-braille",
+    .size      = sizeof(USBSerialState),
+    .vmsd      = &vmstate_usb_serial,
+    .class_init= usb_braille_class_initfn,
+    .props     = (Property[]) {
         DEFINE_PROP_CHR("chardev", USBSerialState, cs),
         DEFINE_PROP_END_OF_LIST(),
     },
hw/usb-wacom.c +6 -6
index 4a671ef..12c949f 100644
@@ -370,12 +370,12 @@ static void usb_wacom_class_init(ObjectClass *class, void *data)
     uc->handle_destroy = usb_wacom_handle_destroy;
 }
 
-static struct USBDeviceInfo wacom_info = {
-    .qdev.name      = "usb-wacom-tablet",
-    .qdev.desc      = "QEMU PenPartner Tablet",
-    .qdev.size      = sizeof(USBWacomState),
-    .qdev.vmsd      = &vmstate_usb_wacom,
-    .qdev.class_init= usb_wacom_class_init,
+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)
hw/usb.h +1 -6
index eac0bf5..2bbfb0a 100644
@@ -145,7 +145,6 @@ typedef struct USBBus USBBus;
 typedef struct USBBusOps USBBusOps;
 typedef struct USBPort USBPort;
 typedef struct USBDevice USBDevice;
-typedef struct USBDeviceInfo USBDeviceInfo;
 typedef struct USBPacket USBPacket;
 
 typedef struct USBDesc USBDesc;
@@ -256,10 +255,6 @@ struct USBDevice {
     const USBDescConfig *config;
 };
 
-struct USBDeviceInfo {
-    DeviceInfo qdev;
-};
-
 typedef struct USBPortOps {
     void (*attach)(USBPort *port);
     void (*detach)(USBPort *port);
@@ -381,7 +376,7 @@ struct USBBusOps {
 
 void usb_bus_new(USBBus *bus, USBBusOps *ops, DeviceState *host);
 USBBus *usb_bus_find(int busnr);
-void usb_qdev_register(USBDeviceInfo *info,
+void usb_qdev_register(DeviceInfo *info,
                        const char *usbdevice_name,
                        USBDevice *(*usbdevice_init)(const char *params));
 USBDevice *usb_create(USBBus *bus, const char *name);
usb-bsd.c +4 -4
index 8637c77..2c6afc8 100644
@@ -410,10 +410,10 @@ static void usb_host_class_initfn(ObjectClass *klass, void *data)
     uc->handle_destroy = usb_host_handle_destroy;
 }
 
-static struct USBDeviceInfo usb_host_dev_info = {
-    .qdev.name      = "usb-host",
-    .qdev.size      = sizeof(USBHostDevice),
-    .qdev.class_init= usb_host_initfn,
+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-linux.c +6 -6
index 6dbcf2a..82d7e7e 100644
@@ -1442,12 +1442,12 @@ static void usb_host_class_initfn(ObjectClass *klass, void *data)
     uc->handle_destroy = usb_host_handle_destroy;
 }
 
-static struct USBDeviceInfo usb_host_dev_info = {
-    .qdev.name      = "usb-host",
-    .qdev.size      = sizeof(USBHostDevice),
-    .qdev.vmsd      = &vmstate_usb_host,
-    .qdev.class_init= usb_host_class_initfn,
-    .qdev.props     = (Property[]) {
+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),
usb-redir.c +5 -5
index a297501..09dc7e6 100644
@@ -1241,11 +1241,11 @@ static void usbredir_class_initfn(ObjectClass *klass, void *data)
     uc->handle_control = usbredir_handle_control;
 }
 
-static struct USBDeviceInfo usbredir_dev_info = {
-    .qdev.name      = "usb-redir",
-    .qdev.size      = sizeof(USBRedirDevice),
-    .qdev.class_init= usbredir_class_initfn,
-    .qdev.props     = (Property[]) {
+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(),
Signature · 1 line
1.7.4.1
#48 lore raw

PATCH v3 49/197 usb-hid: simply class initialization a bit

In reply to Anthony Liguori
---
 hw/usb-hid.c |   27 +++++++++++++--------------
 1 files changed, 13 insertions(+), 14 deletions(-)
hw/usb-hid.c +13 -14
index 2538b9c..3a587c4 100644
@@ -560,13 +560,10 @@ static const VMStateDescription vmstate_usb_kbd = {
     }
 };
 
-static void usb_tablet_class_initfn(ObjectClass *klass, void *data)
+static void usb_hid_class_initfn(ObjectClass *klass, void *data)
 {
     USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
 
-    uc->init           = usb_tablet_initfn;
-    uc->product_desc   = "QEMU USB Tablet";
-    uc->usb_desc       = &desc_tablet;
     uc->handle_packet  = usb_generic_handle_packet;
     uc->handle_reset   = usb_hid_handle_reset;
     uc->handle_control = usb_hid_handle_control;
@@ -574,6 +571,16 @@ static void usb_tablet_class_initfn(ObjectClass *klass, void *data)
     uc->handle_destroy = usb_hid_handle_destroy;
 }
 
+static void usb_tablet_class_initfn(ObjectClass *klass, void *data)
+{
+    USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
+
+    usb_hid_class_initfn(klass, data);
+    uc->init           = usb_tablet_initfn;
+    uc->product_desc   = "QEMU USB Tablet";
+    uc->usb_desc       = &desc_tablet;
+}
+
 static struct DeviceInfo usb_tablet_info = {
     .name      = "usb-tablet",
     .size      = sizeof(USBHIDState),
@@ -585,14 +592,10 @@ static void usb_mouse_class_initfn(ObjectClass *klass, void *data)
 {
     USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
 
+    usb_hid_class_initfn(klass, data);
     uc->init           = usb_mouse_initfn;
     uc->product_desc   = "QEMU USB Mouse";
     uc->usb_desc       = &desc_mouse;
-    uc->handle_packet  = usb_generic_handle_packet;
-    uc->handle_reset   = usb_hid_handle_reset;
-    uc->handle_control = usb_hid_handle_control;
-    uc->handle_data    = usb_hid_handle_data;
-    uc->handle_destroy = usb_hid_handle_destroy;
 }
 
 static struct DeviceInfo usb_mouse_info = {
@@ -606,14 +609,10 @@ static void usb_keyboard_class_initfn(ObjectClass *klass, void *data)
 {
     USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
 
+    usb_hid_class_initfn(klass, data);
     uc->init           = usb_keyboard_initfn;
     uc->product_desc   = "QEMU USB Keyboard";
     uc->usb_desc       = &desc_keyboard;
-    uc->handle_packet  = usb_generic_handle_packet;
-    uc->handle_reset   = usb_hid_handle_reset;
-    uc->handle_control = usb_hid_handle_control;
-    uc->handle_data    = usb_hid_handle_data;
-    uc->handle_destroy = usb_hid_handle_destroy;
 }
 
 static struct DeviceInfo usb_keyboard_info = {
Signature · 1 line
1.7.4.1
#49 lore raw

PATCH v3 50/197 accessors for scsideviceinfo

In reply to Anthony Liguori
---
 hw/scsi-bus.c |   48 +++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 37 insertions(+), 11 deletions(-)
hw/scsi-bus.c +37 -11
index 731c1f3..a054324 100644
@@ -23,6 +23,38 @@ static struct BusInfo scsi_bus_info = {
 };
 static int next_scsi_bus;
 
+static int scsi_device_init(SCSIDevice *dev)
+{
+    if (dev->info->init) {
+        return dev->info->init(dev);
+    }
+    return 0;
+}
+
+static void scsi_device_destroy(SCSIDevice *s)
+{
+    if (s->info->destroy) {
+        s->info->destroy(s);
+    }
+}
+
+static SCSIRequest *scsi_device_alloc_req(SCSIDevice *s, uint32_t tag, uint32_t lun,
+                                          uint8_t *buf, void *hba_private)
+{
+    if (s->info->alloc_req) {
+        return s->info->alloc_req(s, tag, lun, buf, hba_private);
+    }
+
+    return NULL;
+}
+
+static void scsi_device_unit_attention_reported(SCSIDevice *s)
+{
+    if (s->info->unit_attention_reported) {
+        s->info->unit_attention_reported(s);
+    }
+}
+
 /* Create a scsi bus, and attach devices to it.  */
 void scsi_bus_new(SCSIBus *bus, DeviceState *host, const SCSIBusInfo *info)
 {
@@ -128,7 +160,7 @@ 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);
@@ -145,9 +177,7 @@ static int scsi_qdev_exit(DeviceState *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;
 }
 
@@ -398,9 +428,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 +535,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 +625,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;
     }
Signature · 1 line
1.7.4.1
#50 lore raw

PATCH v3 51/197 drop info link in SCSIDeviceInfo

In reply to Anthony Liguori
---
 hw/scsi-bus.c |   26 ++++++++++++++++----------
 hw/scsi.h     |    1 -
 2 files changed, 16 insertions(+), 11 deletions(-)
hw/scsi-bus.c +16 -10
index a054324..8f0d7e6 100644
@@ -25,24 +25,30 @@ static int next_scsi_bus;
 
 static int scsi_device_init(SCSIDevice *dev)
 {
-    if (dev->info->init) {
-        return dev->info->init(dev);
+    SCSIDeviceInfo *info = DO_UPCAST(SCSIDeviceInfo, qdev,
+                                     qdev_get_info(DEVICE(dev)));
+    if (info->init) {
+        return info->init(dev);
     }
     return 0;
 }
 
 static void scsi_device_destroy(SCSIDevice *s)
 {
-    if (s->info->destroy) {
-        s->info->destroy(s);
+    SCSIDeviceInfo *info = DO_UPCAST(SCSIDeviceInfo, qdev,
+                                     qdev_get_info(DEVICE(s)));
+    if (info->destroy) {
+        info->destroy(s);
     }
 }
 
 static SCSIRequest *scsi_device_alloc_req(SCSIDevice *s, uint32_t tag, uint32_t lun,
                                           uint8_t *buf, void *hba_private)
 {
-    if (s->info->alloc_req) {
-        return s->info->alloc_req(s, tag, lun, buf, hba_private);
+    SCSIDeviceInfo *info = DO_UPCAST(SCSIDeviceInfo, qdev,
+                                     qdev_get_info(DEVICE(s)));
+    if (info->alloc_req) {
+        return info->alloc_req(s, tag, lun, buf, hba_private);
     }
 
     return NULL;
@@ -50,8 +56,10 @@ static SCSIRequest *scsi_device_alloc_req(SCSIDevice *s, uint32_t tag, uint32_t
 
 static void scsi_device_unit_attention_reported(SCSIDevice *s)
 {
-    if (s->info->unit_attention_reported) {
-        s->info->unit_attention_reported(s);
+    SCSIDeviceInfo *info = DO_UPCAST(SCSIDeviceInfo, qdev,
+                                     qdev_get_info(DEVICE(s)));
+    if (info->unit_attention_reported) {
+        info->unit_attention_reported(s);
     }
 }
 
@@ -114,7 +122,6 @@ static void scsi_dma_restart_cb(void *opaque, int running, RunState state)
 static int scsi_qdev_init(DeviceState *qdev, DeviceInfo *base)
 {
     SCSIDevice *dev = SCSI_DEVICE(qdev);
-    SCSIDeviceInfo *info = DO_UPCAST(SCSIDeviceInfo, qdev, base);
     SCSIBus *bus = DO_UPCAST(SCSIBus, qbus, dev->qdev.parent_bus);
     SCSIDevice *d;
     int rc = -1;
@@ -158,7 +165,6 @@ static int scsi_qdev_init(DeviceState *qdev, DeviceInfo *base)
         }
     }
 
-    dev->info = info;
     QTAILQ_INIT(&dev->requests);
     rc = scsi_device_init(dev);
     if (rc == 0) {
hw/scsi.h +0 -1
index 282cebd..0d24d41 100644
@@ -77,7 +77,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];
Signature · 1 line
1.7.4.1
#51 lore raw

PATCH v3 52/197 move methods out of SCSIDeviceInfo into SCSIDeviceClass

In reply to Anthony Liguori
---
 hw/scsi-bus.c     |   30 ++++------
 hw/scsi-disk.c    |  159 ++++++++++++++++++++++++++++++++---------------------
 hw/scsi-generic.c |   13 +++-
 hw/scsi.h         |   11 ++--
 4 files changed, 124 insertions(+), 89 deletions(-)
hw/scsi-bus.c +13 -17
index 8f0d7e6..cabdb3c 100644
@@ -23,32 +23,29 @@ static struct BusInfo scsi_bus_info = {
 };
 static int next_scsi_bus;
 
-static int scsi_device_init(SCSIDevice *dev)
+static int scsi_device_init(SCSIDevice *s)
 {
-    SCSIDeviceInfo *info = DO_UPCAST(SCSIDeviceInfo, qdev,
-                                     qdev_get_info(DEVICE(dev)));
-    if (info->init) {
-        return info->init(dev);
+    SCSIDeviceClass *sc = SCSI_DEVICE_GET_CLASS(s);
+    if (sc->init) {
+        return sc->init(s);
     }
     return 0;
 }
 
 static void scsi_device_destroy(SCSIDevice *s)
 {
-    SCSIDeviceInfo *info = DO_UPCAST(SCSIDeviceInfo, qdev,
-                                     qdev_get_info(DEVICE(s)));
-    if (info->destroy) {
-        info->destroy(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)
 {
-    SCSIDeviceInfo *info = DO_UPCAST(SCSIDeviceInfo, qdev,
-                                     qdev_get_info(DEVICE(s)));
-    if (info->alloc_req) {
-        return info->alloc_req(s, tag, lun, buf, 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;
@@ -56,10 +53,9 @@ static SCSIRequest *scsi_device_alloc_req(SCSIDevice *s, uint32_t tag, uint32_t
 
 static void scsi_device_unit_attention_reported(SCSIDevice *s)
 {
-    SCSIDeviceInfo *info = DO_UPCAST(SCSIDeviceInfo, qdev,
-                                     qdev_get_info(DEVICE(s)));
-    if (info->unit_attention_reported) {
-        info->unit_attention_reported(s);
+    SCSIDeviceClass *sc = SCSI_DEVICE_GET_CLASS(s);
+    if (sc->unit_attention_reported) {
+        sc->unit_attention_reported(s);
     }
 }
 
hw/scsi-disk.c +96 -63

171 lines not on this page · raw message

hw/scsi-generic.c +10 -3
index ef76e4b..9fb2a09 100644
@@ -461,15 +461,22 @@ static SCSIRequest *scsi_new_request(SCSIDevice *d, uint32_t tag, uint32_t lun,
     return req;
 }
 
+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 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.class_init = scsi_generic_class_initfn,
     .qdev.props   = (Property[]) {
         DEFINE_BLOCK_PROPERTIES(SCSIDevice, conf),
         DEFINE_PROP_END_OF_LIST(),
hw/scsi.h +5 -6
index 0d24d41..41501f2 100644
@@ -68,6 +68,11 @@ struct SCSIRequest {
 
 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
@@ -104,14 +109,8 @@ 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 {
Signature · 1 line
1.7.4.1
#52 lore raw

PATCH v3 53/197 kill off SCSIDeviceInfo

In reply to Anthony Liguori
---
 hw/scsi-bus.c     |   12 +++++-----
 hw/scsi-disk.c    |   64 ++++++++++++++++++++++++++--------------------------
 hw/scsi-generic.c |   16 ++++++------
 hw/scsi.h         |    7 +-----
 4 files changed, 47 insertions(+), 52 deletions(-)
hw/scsi-bus.c +6 -6
index cabdb3c..d017ece 100644
@@ -183,13 +183,13 @@ static int scsi_qdev_exit(DeviceState *qdev)
     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_subclass(&info->qdev, TYPE_SCSI_DEVICE);
+    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 */
hw/scsi-disk.c +32 -32

88 lines not on this page · raw message

hw/scsi-generic.c +8 -8
index 9fb2a09..8d7a8f3 100644
@@ -470,14 +470,14 @@ static void scsi_generic_class_initfn(ObjectClass *klass, void *data)
     sc->alloc_req    = scsi_new_request;
 }
 
-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,
-    .qdev.class_init = scsi_generic_class_initfn,
-    .qdev.props   = (Property[]) {
+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 +1 -6
index 41501f2..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;
 
@@ -109,10 +108,6 @@ struct SCSIReqOps {
     uint8_t *(*get_buf)(SCSIRequest *req);
 };
 
-struct SCSIDeviceInfo {
-    DeviceInfo qdev;
-};
-
 struct SCSIBusInfo {
     int tcq;
     int max_channel, max_target, max_lun;
@@ -130,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
#53 lore raw

PATCH v3 54/197 get rid of CCIDCardInfo

In reply to Anthony Liguori
---
 hw/ccid-card-emulated.c |   27 ++++++++++++-------
 hw/ccid-card-passthru.c |   27 ++++++++++++-------
 hw/ccid.h               |   26 ++++++++-----------
 hw/usb-ccid.c           |   63 ++++++++++++++++++++++++++++++++++------------
 4 files changed, 91 insertions(+), 52 deletions(-)
hw/ccid-card-emulated.c +17 -10
index 092301b..2748fd8 100644
@@ -567,16 +567,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 +11 -15
index d8e0485..9e4979c 100644
@@ -23,30 +23,26 @@ typedef struct CCIDCardInfo CCIDCardInfo;
 #define CCID_CARD_GET_CLASS(obj) \
      OBJECT_GET_CLASS(CCIDCardClass, (obj), TYPE_CCID_CARD)
 
-typedef struct CCIDCardClass {
-    DeviceClass parent_class;
-} 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. */
-};
-
 /*
  * 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. */
 };
 
 /*
@@ -58,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 +46 -17

125 lines not on this page · raw message

Signature · 1 line
1.7.4.1
#54 lore raw

PATCH v3 55/197 rename i2c_slave -> I2CSlave

In reply to Anthony Liguori
---
 hw/ds1338.c   |   10 +++++-----
 hw/hw.h       |    4 ++--
 hw/i2c.c      |   30 +++++++++++++++---------------
 hw/i2c.h      |   18 ++++++++++--------
 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 +++++-----
 16 files changed, 88 insertions(+), 86 deletions(-)
hw/ds1338.c +5 -5
index 3522af5..88d6d18 100644
@@ -10,7 +10,7 @@
 #include "i2c.h"
 
 typedef struct {
-    i2c_slave i2c;
+    I2CSlave i2c;
     time_t offset;
     struct tm now;
     uint8_t nvram[56];
@@ -18,7 +18,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);
 
@@ -48,7 +48,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;
@@ -58,7 +58,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) {
@@ -110,7 +110,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/hw.h +2 -2
index ed20f5a..545eed3 100644
@@ -662,10 +662,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),   \
 }
 
 extern const VMStateDescription vmstate_usb_device;
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 +10 -8
index 9381d01..28401f0 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);
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 e9a507e..d18eb04 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 23f9d41..31d17f2 100644
@@ -714,7 +714,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 401fdf5..45ae513 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 b992b99..76c8629 100644
@@ -130,12 +130,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;
@@ -154,7 +154,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;
@@ -177,13 +177,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 39383f4..edb7dbf 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 a03bb33..5a70307 100644
@@ -180,12 +180,12 @@ static SSISlaveInfo 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;
@@ -203,7 +203,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) {
@@ -222,7 +222,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);
@@ -245,7 +245,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
#55 lore raw

PATCH v3 56/197 add I2CSlave to the type hierarchy

In reply to Anthony Liguori
---
 hw/i2c.c |   15 +++++++++++++++
 hw/i2c.h |   13 +++++++++++++
 2 files changed, 28 insertions(+), 0 deletions(-)
hw/i2c.c +15 -0
index 9efe70c..cdf88f2 100644
@@ -194,3 +194,18 @@ DeviceState *i2c_create_slave(i2c_bus *bus, const char *name, uint8_t addr)
     qdev_init_nofail(dev);
     return dev;
 }
+
+static TypeInfo i2c_slave_type_info = {
+    .name = TYPE_I2C_SLAVE,
+    .parent = TYPE_DEVICE,
+    .instance_size = sizeof(I2CSlave),
+    .abstract = true,
+    .class_size = sizeof(I2CSlaveClass),
+};
+
+static void i2c_slave_register_devices(void)
+{
+    type_register_static(&i2c_slave_type_info);
+}
+
+device_init(i2c_slave_register_devices);
hw/i2c.h +13 -0
index 28401f0..cc4d76b 100644
@@ -26,6 +26,19 @@ typedef void (*i2c_event_cb)(I2CSlave *s, enum i2c_event event);
 
 typedef int (*i2c_slave_initfn)(I2CSlave *dev);
 
+#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;
+} I2CSlaveClass;
+
 typedef struct {
     DeviceInfo qdev;
 
Signature · 1 line
1.7.4.1
#56 lore raw

PATCH v3 57/197 add SMBusDevice to the type hiearchy

In reply to Anthony Liguori
---
 hw/smbus.c |   15 +++++++++++++++
 hw/smbus.h |   13 +++++++++++++
 2 files changed, 28 insertions(+), 0 deletions(-)
hw/smbus.c +15 -0
index 0cb3566..a75d404 100644
@@ -316,3 +316,18 @@ void smbus_write_block(i2c_bus *bus, uint8_t addr, uint8_t command, uint8_t *dat
         i2c_send(bus, data[i]);
     i2c_end_transfer(bus);
 }
+
+static TypeInfo smbus_device_type_info = {
+    .name = TYPE_SMBUS_DEVICE,
+    .parent = TYPE_I2C_SLAVE,
+    .instance_size = sizeof(SMBusDevice),
+    .abstract = true,
+    .class_size = sizeof(SMBusDeviceClass),
+};
+
+static void smbus_device_register_devices(void)
+{
+    type_register_static(&smbus_device_type_info);
+}
+
+device_init(smbus_device_register_devices);
hw/smbus.h +13 -0
index 2f2d49e..9dd055c 100644
@@ -24,6 +24,19 @@
 
 #include "i2c.h"
 
+#define TYPE_SMBUS_DEVICE "smbus-device"
+#define SMBUS_DEVICE(obj) \
+     OBJECT_CHECK(SMBUSDevice, (obj), TYPE_SMBUS_DEVICE)
+#define SMBUS_DEVICE_CLASS(klass) \
+     OBJECT_CLASS_CHECK(SMBUSDeviceClass, (klass), TYPE_SMBUS_DEVICE)
+#define SMBUS_DEVICE_GET_CLASS(obj) \
+     OBJECT_GET_CLASS(SMBUSDeviceClass, (obj), TYPE_SMBUS_DEVICE)
+
+typedef struct SMBusDeviceClass
+{
+    I2CSlaveClass parent_class;
+} SMBusDeviceClass;
+
 struct SMBusDevice {
     /* The SMBus protocol is implemented on top of I2C.  */
     I2CSlave i2c;
Signature · 1 line
1.7.4.1
#57 lore raw

PATCH v3 58/197 fixup type registration

In reply to Anthony Liguori
---
 hw/i2c.c   |    9 +++++++--
 hw/i2c.h   |    1 +
 hw/smbus.c |    2 +-
 3 files changed, 9 insertions(+), 3 deletions(-)
hw/i2c.c +7 -2
index cdf88f2..fcb7269 100644
@@ -177,12 +177,17 @@ static int i2c_slave_qdev_init(DeviceState *dev, DeviceInfo *base)
     return info->init(s);
 }
 
-void i2c_register_slave(I2CSlaveInfo *info)
+void i2c_register_slave_subclass(I2CSlaveInfo *info, const char *parent)
 {
     assert(info->qdev.size >= sizeof(I2CSlave));
     info->qdev.init = i2c_slave_qdev_init;
     info->qdev.bus_info = &i2c_bus_info;
-    qdev_register(&info->qdev);
+    qdev_register_subclass(&info->qdev, parent);
+}
+
+void i2c_register_slave(I2CSlaveInfo *info)
+{
+    i2c_register_slave_subclass(info, TYPE_I2C_SLAVE);
 }
 
 DeviceState *i2c_create_slave(i2c_bus *bus, const char *name, uint8_t addr)
hw/i2c.h +1 -0
index cc4d76b..0c6f2ac 100644
@@ -71,6 +71,7 @@ int i2c_recv(i2c_bus *bus);
 #define FROM_I2C_SLAVE(type, dev) DO_UPCAST(type, i2c, dev)
 
 void i2c_register_slave(I2CSlaveInfo *type);
+void i2c_register_slave_subclass(I2CSlaveInfo *info, const char *parent);
 
 DeviceState *i2c_create_slave(i2c_bus *bus, const char *name, uint8_t addr);
 
hw/smbus.c +1 -1
index a75d404..2711229 100644
@@ -213,7 +213,7 @@ void smbus_register_device(SMBusDeviceInfo *info)
     info->i2c.event = smbus_i2c_event;
     info->i2c.recv = smbus_i2c_recv;
     info->i2c.send = smbus_i2c_send;
-    i2c_register_slave(&info->i2c);
+    i2c_register_slave_subclass(&info->i2c, TYPE_SMBUS_DEVICE);
 }
 
 /* Master device commands.  */
Signature · 1 line
1.7.4.1
#58 lore raw

PATCH v3 59/197 kill off SMBusDeviceInfo

In reply to Anthony Liguori
---
 hw/smbus.c        |   55 +++++++++++++++++++++++++++--------------------------
 hw/smbus.h        |   35 +++++++++++++++------------------
 hw/smbus_eeprom.c |   27 ++++++++++++++++---------
 3 files changed, 61 insertions(+), 56 deletions(-)
hw/smbus.c +28 -27
index 2711229..3f2d1f4 100644
@@ -37,37 +37,38 @@ enum {
 
 static void smbus_do_quick_cmd(SMBusDevice *dev, int recv)
 {
-    SMBusDeviceInfo *t = container_of(dev->i2c.info, SMBusDeviceInfo, i2c);
+    SMBusDeviceClass *sc = SMBUS_DEVICE_GET_CLASS(dev);
 
     DPRINTF("Quick Command %d\n", recv);
-    if (t->quick_cmd)
-        t->quick_cmd(dev, recv);
+    if (sc->quick_cmd) {
+        sc->quick_cmd(dev, recv);
+    }
 }
 
 static void smbus_do_write(SMBusDevice *dev)
 {
-    SMBusDeviceInfo *t = container_of(dev->i2c.info, SMBusDeviceInfo, i2c);
+    SMBusDeviceClass *sc = SMBUS_DEVICE_GET_CLASS(dev);
 
     if (dev->data_len == 0) {
         smbus_do_quick_cmd(dev, 0);
     } else if (dev->data_len == 1) {
         DPRINTF("Send Byte\n");
-        if (t->send_byte) {
-            t->send_byte(dev, dev->data_buf[0]);
+        if (sc->send_byte) {
+            sc->send_byte(dev, dev->data_buf[0]);
         }
     } else {
         dev->command = dev->data_buf[0];
         DPRINTF("Command %d len %d\n", dev->command, dev->data_len - 1);
-        if (t->write_data) {
-            t->write_data(dev, dev->command, dev->data_buf + 1,
-                          dev->data_len - 1);
+        if (sc->write_data) {
+            sc->write_data(dev, dev->command, dev->data_buf + 1,
+                           dev->data_len - 1);
         }
     }
 }
 
 static void smbus_i2c_event(I2CSlave *s, enum i2c_event event)
 {
-    SMBusDevice *dev = FROM_I2C_SLAVE(SMBusDevice, s);
+    SMBusDevice *dev = SMBUS_DEVICE(s);
 
     switch (event) {
     case I2C_START_SEND:
@@ -150,14 +151,14 @@ static void smbus_i2c_event(I2CSlave *s, enum i2c_event event)
 
 static int smbus_i2c_recv(I2CSlave *s)
 {
-    SMBusDeviceInfo *t = container_of(s->info, SMBusDeviceInfo, i2c);
-    SMBusDevice *dev = FROM_I2C_SLAVE(SMBusDevice, s);
+    SMBusDevice *dev = SMBUS_DEVICE(s);
+    SMBusDeviceClass *sc = SMBUS_DEVICE_GET_CLASS(dev);
     int ret;
 
     switch (dev->mode) {
     case SMBUS_RECV_BYTE:
-        if (t->receive_byte) {
-            ret = t->receive_byte(dev);
+        if (sc->receive_byte) {
+            ret = sc->receive_byte(dev);
         } else {
             ret = 0;
         }
@@ -165,8 +166,8 @@ static int smbus_i2c_recv(I2CSlave *s)
         dev->mode = SMBUS_DONE;
         break;
     case SMBUS_READ_DATA:
-        if (t->read_data) {
-            ret = t->read_data(dev, dev->command, dev->data_len);
+        if (sc->read_data) {
+            ret = sc->read_data(dev, dev->command, dev->data_len);
             dev->data_len++;
         } else {
             ret = 0;
@@ -184,7 +185,7 @@ static int smbus_i2c_recv(I2CSlave *s)
 
 static int smbus_i2c_send(I2CSlave *s, uint8_t data)
 {
-    SMBusDevice *dev = FROM_I2C_SLAVE(SMBusDevice, s);
+    SMBusDevice *dev = SMBUS_DEVICE(s);
 
     switch (dev->mode) {
     case SMBUS_WRITE_DATA:
@@ -200,20 +201,20 @@ static int smbus_i2c_send(I2CSlave *s, uint8_t data)
 
 static int smbus_device_init(I2CSlave *i2c)
 {
-    SMBusDeviceInfo *t = container_of(i2c->info, SMBusDeviceInfo, i2c);
-    SMBusDevice *dev = FROM_I2C_SLAVE(SMBusDevice, i2c);
+    SMBusDevice *dev = SMBUS_DEVICE(i2c);
+    SMBusDeviceClass *sc = SMBUS_DEVICE_GET_CLASS(dev);
 
-    return t->init(dev);
+    return sc->init(dev);
 }
 
-void smbus_register_device(SMBusDeviceInfo *info)
+void smbus_register_device(I2CSlaveInfo *info)
 {
-    assert(info->i2c.qdev.size >= sizeof(SMBusDevice));
-    info->i2c.init = smbus_device_init;
-    info->i2c.event = smbus_i2c_event;
-    info->i2c.recv = smbus_i2c_recv;
-    info->i2c.send = smbus_i2c_send;
-    i2c_register_slave_subclass(&info->i2c, TYPE_SMBUS_DEVICE);
+    assert(info->qdev.size >= sizeof(SMBusDevice));
+    info->init = smbus_device_init;
+    info->event = smbus_i2c_event;
+    info->recv = smbus_i2c_recv;
+    info->send = smbus_i2c_send;
+    i2c_register_slave_subclass(info, TYPE_SMBUS_DEVICE);
 }
 
 /* Master device commands.  */
hw/smbus.h +16 -19
index 9dd055c..fa9088a 100644
@@ -26,30 +26,16 @@
 
 #define TYPE_SMBUS_DEVICE "smbus-device"
 #define SMBUS_DEVICE(obj) \
-     OBJECT_CHECK(SMBUSDevice, (obj), TYPE_SMBUS_DEVICE)
+     OBJECT_CHECK(SMBusDevice, (obj), TYPE_SMBUS_DEVICE)
 #define SMBUS_DEVICE_CLASS(klass) \
-     OBJECT_CLASS_CHECK(SMBUSDeviceClass, (klass), TYPE_SMBUS_DEVICE)
+     OBJECT_CLASS_CHECK(SMBusDeviceClass, (klass), TYPE_SMBUS_DEVICE)
 #define SMBUS_DEVICE_GET_CLASS(obj) \
-     OBJECT_GET_CLASS(SMBUSDeviceClass, (obj), TYPE_SMBUS_DEVICE)
+     OBJECT_GET_CLASS(SMBusDeviceClass, (obj), TYPE_SMBUS_DEVICE)
 
 typedef struct SMBusDeviceClass
 {
     I2CSlaveClass parent_class;
-} SMBusDeviceClass;
-
-struct SMBusDevice {
-    /* The SMBus protocol is implemented on top of I2C.  */
-    I2CSlave i2c;
-
-    /* Remaining fields for internal use only.  */
-    int mode;
-    int data_len;
-    uint8_t data_buf[34]; /* command + len + 32 bytes of data.  */
-    uint8_t command;
-};
 
-typedef struct {
-    I2CSlaveInfo i2c;
     int (*init)(SMBusDevice *dev);
     void (*quick_cmd)(SMBusDevice *dev, uint8_t read);
     void (*send_byte)(SMBusDevice *dev, uint8_t val);
@@ -64,9 +50,20 @@ typedef struct {
        byte at a time.  The device is responsible for adding the length
        byte on block reads.  */
     uint8_t (*read_data)(SMBusDevice *dev, uint8_t cmd, int n);
-} SMBusDeviceInfo;
+} SMBusDeviceClass;
+
+struct SMBusDevice {
+    /* The SMBus protocol is implemented on top of I2C.  */
+    I2CSlave i2c;
+
+    /* Remaining fields for internal use only.  */
+    int mode;
+    int data_len;
+    uint8_t data_buf[34]; /* command + len + 32 bytes of data.  */
+    uint8_t command;
+};
 
-void smbus_register_device(SMBusDeviceInfo *info);
+void smbus_register_device(I2CSlaveInfo *info);
 
 /* Master device commands.  */
 void smbus_quick_command(i2c_bus *bus, uint8_t addr, int read);
hw/smbus_eeprom.c +17 -10
index 5d080ab..2e8329f 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 I2CSlaveInfo smbus_eeprom_info = {
+    .qdev.name = "smbus-eeprom",
+    .qdev.size = sizeof(SMBusEEPROMDevice),
+    .qdev.class_init = smbus_eeprom_class_initfn,
+    .qdev.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)
Signature · 1 line
1.7.4.1
#59 lore raw

PATCH v3 60/197 add guards

In reply to Anthony Liguori
---
 hw/smbus.h |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
hw/smbus.h +5 -0
index fa9088a..7fa63f9 100644
@@ -1,3 +1,6 @@
+#ifndef QEMU_SMBUS_H
+#define QEMU_SMBUS_H
+
 /*
  * QEMU SMBus API
  *
@@ -79,3 +82,5 @@ void smbus_write_block(i2c_bus *bus, uint8_t addr, uint8_t command, uint8_t *dat
 
 void smbus_eeprom_init(i2c_bus *smbus, int nb_eeprom,
                        const uint8_t *eeprom_spd, int size);
+
+#endif
Signature · 1 line
1.7.4.1
#60 lore raw

PATCH v3 61/197 killall I2CSlaveInfo

In reply to Anthony Liguori

This was partially written by the Patch Monkey.

---
 hw/ds1338.c       |   21 +++++++++++-----
 hw/i2c.c          |   67 +++++++++++++++++++++++++++++++++++++---------------
 hw/i2c.h          |   34 ++++++++++----------------
 hw/lm832x.c       |   23 ++++++++++++------
 hw/max7310.c      |   25 ++++++++++++-------
 hw/pxa2xx.c       |   21 +++++++++++-----
 hw/smbus.c        |   19 ++++++++++----
 hw/smbus.h        |    2 +-
 hw/smbus_eeprom.c |   10 ++++----
 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, 227 insertions(+), 131 deletions(-)
hw/ds1338.c +14 -7
index 88d6d18..d604f82 100644
@@ -115,13 +115,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_INFO(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 +47 -20

131 lines not on this page · raw message

hw/i2c.h +13 -21
index 0c6f2ac..178351a 100644
@@ -17,15 +17,6 @@ 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);
-
-typedef int (*i2c_slave_initfn)(I2CSlave *dev);
-
 #define TYPE_I2C_SLAVE "i2c-slave"
 #define I2C_SLAVE(obj) \
      OBJECT_CHECK(I2CSlave, (obj), TYPE_I2C_SLAVE)
@@ -37,22 +28,23 @@ typedef int (*i2c_slave_initfn)(I2CSlave *dev);
 typedef struct I2CSlaveClass
 {
     DeviceClass parent_class;
-} I2CSlaveClass;
-
-typedef struct {
-    DeviceInfo qdev;
 
     /* Callbacks provided by the device.  */
-    i2c_slave_initfn init;
-    i2c_event_cb event;
-    i2c_recv_cb recv;
-    i2c_send_cb send;
-} I2CSlaveInfo;
+    int (*init)(I2CSlave *dev);
+
+    /* Master to slave.  */
+    int (*send)(I2CSlave *s, uint8_t data);
+
+    /* Slave to master.  */
+    int (*recv)(I2CSlave *s);
+
+    /* 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;
@@ -70,8 +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_subclass(I2CSlaveInfo *info, const char *parent);
+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..49a0873 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_INFO(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..2615c77 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_INFO(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 d18eb04..903f798 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 pxa2xx_i2c_slave_class_init(ObjectClass *klass, void *data)
+{
+    I2CSlaveClass *k = I2C_SLAVE_INFO(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 = pxa2xx_i2c_slave_class_init,
 };
 
 PXA2xxI2CState *pxa2xx_i2c_init(target_phys_addr_t base,
hw/smbus.c +13 -6
index 3f2d1f4..ed31a59 100644
@@ -207,13 +207,9 @@ static int smbus_device_init(I2CSlave *i2c)
     return sc->init(dev);
 }
 
-void smbus_register_device(I2CSlaveInfo *info)
+void smbus_register_device(DeviceInfo *info)
 {
-    assert(info->qdev.size >= sizeof(SMBusDevice));
-    info->init = smbus_device_init;
-    info->event = smbus_i2c_event;
-    info->recv = smbus_i2c_recv;
-    info->send = smbus_i2c_send;
+    assert(info->size >= sizeof(SMBusDevice));
     i2c_register_slave_subclass(info, TYPE_SMBUS_DEVICE);
 }
 
@@ -318,12 +314,23 @@ void smbus_write_block(i2c_bus *bus, uint8_t addr, uint8_t command, uint8_t *dat
     i2c_end_transfer(bus);
 }
 
+static void smbus_device_class_init(ObjectClass *klass, void *data)
+{
+    I2CSlaveClass *sc = I2C_SLAVE_CLASS(klass);
+
+    sc->init = smbus_device_init;
+    sc->event = smbus_i2c_event;
+    sc->recv = smbus_i2c_recv;
+    sc->send = smbus_i2c_send;
+}
+
 static TypeInfo smbus_device_type_info = {
     .name = TYPE_SMBUS_DEVICE,
     .parent = TYPE_I2C_SLAVE,
     .instance_size = sizeof(SMBusDevice),
     .abstract = true,
     .class_size = sizeof(SMBusDeviceClass),
+    .class_init = smbus_device_class_init,
 };
 
 static void smbus_device_register_devices(void)
hw/smbus.h +1 -1
index 7fa63f9..5f01f5d 100644
@@ -66,7 +66,7 @@ struct SMBusDevice {
     uint8_t command;
 };
 
-void smbus_register_device(I2CSlaveInfo *info);
+void smbus_register_device(DeviceInfo *info);
 
 /* Master device commands.  */
 void smbus_quick_command(i2c_bus *bus, uint8_t addr, int read);
hw/smbus_eeprom.c +5 -5
index 2e8329f..401dff5 100644
@@ -116,11 +116,11 @@ static void smbus_eeprom_class_initfn(ObjectClass *klass, void *data)
     sc->read_data = eeprom_read_data;
 }
 
-static I2CSlaveInfo smbus_eeprom_info = {
-    .qdev.name = "smbus-eeprom",
-    .qdev.size = sizeof(SMBusEEPROMDevice),
-    .qdev.class_init = smbus_eeprom_class_initfn,
-    .qdev.props = (Property[]) {
+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(),
     },
hw/ssd0303.c +15 -8
index 45ae513..ec77978 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_INFO(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..a9181bd 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_INFO(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 76c8629..2a305cf 100644
@@ -253,13 +253,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_INFO(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 SSISlaveInfo tosa_ssp_info = {
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 edb7dbf..31e48f3 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 5a70307..10f929a 100644
@@ -263,14 +263,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 *sc = I2C_SLAVE_CLASS(klass);
+
+    sc->init = aer915_init;
+    sc->event = aer915_event;
+    sc->recv = aer915_recv;
+    sc->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
#61 lore raw

PATCH v3 62/197 killall HDACodecDeviceInfo

In reply to Anthony Liguori
---
 hw/hda-audio.c |   58 ++++++++++++++++++++++++++++++++++---------------------
 hw/intel-hda.c |   43 +++++++++++++++++++++++++++--------------
 hw/intel-hda.h |   26 ++++++++++++++++--------
 3 files changed, 81 insertions(+), 46 deletions(-)
hw/hda-audio.c +36 -22
index ffdd799..71831a3 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 +28 -15

94 lines not on this page · raw message

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
#62 lore raw

PATCH v3 63/197 make spapr a bit more patch monkey friendly

In reply to Anthony Liguori
---
 hw/spapr_llan.c  |    4 ++--
 hw/spapr_vscsi.c |    4 ++--
 hw/spapr_vty.c   |    4 ++--
 3 files changed, 6 insertions(+), 6 deletions(-)
hw/spapr_llan.c +2 -2
index abe1297..958702c 100644
@@ -484,7 +484,7 @@ static void vlan_hcalls(VIOsPAPRBus *bus)
     spapr_register_hypercall(H_MULTICAST_CTRL, h_multicast_ctrl);
 }
 
-static VIOsPAPRDeviceInfo spapr_vlan = {
+static VIOsPAPRDeviceInfo spapr_vlan_info = {
     .init = spapr_vlan_init,
     .devnode = spapr_vlan_devnode,
     .dt_name = "l-lan",
@@ -503,6 +503,6 @@ static VIOsPAPRDeviceInfo spapr_vlan = {
 
 static void spapr_vlan_register(void)
 {
-    spapr_vio_bus_register_withprop(&spapr_vlan);
+    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 +2 -2
index f23cc36..fddecd8 100644
@@ -141,7 +141,7 @@ static void vty_hcalls(VIOsPAPRBus *bus)
     spapr_register_hypercall(H_GET_TERM_CHAR, h_get_term_char);
 }
 
-static VIOsPAPRDeviceInfo spapr_vty = {
+static VIOsPAPRDeviceInfo spapr_vty_info = {
     .init = spapr_vty_init,
     .dt_name = "vty",
     .dt_type = "serial",
@@ -181,6 +181,6 @@ static VIOsPAPRDevice *vty_lookup(sPAPREnvironment *spapr, target_ulong reg)
 
 static void spapr_vty_register(void)
 {
-    spapr_vio_bus_register_withprop(&spapr_vty);
+    spapr_vio_bus_register_withprop(&spapr_vty_info);
 }
 device_init(spapr_vty_register);
Signature · 1 line
1.7.4.1
#63 lore raw

PATCH v3 64/197 killall VIOsPAPRDeviceInfo

In reply to Anthony Liguori

This was doing something evil building a dt tree so we broke the device.

---
 hw/spapr_llan.c  |   39 ++++++++++++++++++++++++---------------
 hw/spapr_vio.c   |   52 +++++++++++++++++++++++++++++++++-------------------
 hw/spapr_vio.h   |   29 +++++++++++++++++++----------
 hw/spapr_vscsi.c |   35 ++++++++++++++++++++++-------------
 hw/spapr_vty.c   |   35 ++++++++++++++++++++++-------------
 5 files changed, 120 insertions(+), 70 deletions(-)
hw/spapr_llan.c +24 -15
index 958702c..b06b274 100644
@@ -484,21 +484,30 @@ static void vlan_hcalls(VIOsPAPRBus *bus)
     spapr_register_hypercall(H_MULTICAST_CTRL, h_multicast_ctrl);
 }
 
-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,
-    .hcalls = vlan_hcalls,
-    .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;
+    k->hcalls = vlan_hcalls;
+}
+
+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 -19

138 lines not on this page · raw message

hw/spapr_vio.h +19 -10
index a325a5f..89438a2 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,6 +55,16 @@ typedef struct VIOsPAPR_CRQ {
     int(*SendFunc)(struct VIOsPAPRDevice *vdev, uint8_t *crq);
 } VIOsPAPR_CRQ;
 
+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;
+
 typedef struct VIOsPAPRDevice {
     DeviceState qdev;
     uint32_t reg;
@@ -70,18 +88,9 @@ typedef 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);
-    void (*hcalls)(VIOsPAPRBus *bus);
-    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_vio_signal(VIOsPAPRDevice *dev, target_ulong mode);
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 fddecd8..466c4f0 100644
@@ -141,19 +141,28 @@ static void vty_hcalls(VIOsPAPRBus *bus)
     spapr_register_hypercall(H_GET_TERM_CHAR, h_get_term_char);
 }
 
-static VIOsPAPRDeviceInfo spapr_vty_info = {
-    .init = spapr_vty_init,
-    .dt_name = "vty",
-    .dt_type = "serial",
-    .dt_compatible = "hvterm1",
-    .hcalls = vty_hcalls,
-    .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";
+    k->hcalls = vty_hcalls;
+}
+
+static DeviceInfo spapr_vty_info = {
+    .name = "spapr-vty",
+    .size = sizeof(VIOsPAPRVTYDevice),
+    .props = spapr_vty_properties,
+    .class_init = spapr_vty_class_init,
 };
 
 static VIOsPAPRDevice *vty_lookup(sPAPREnvironment *spapr, target_ulong reg)
Signature · 1 line
1.7.4.1
#64 lore raw

Re: [Qemu-devel] [PATCH v3 064/197] killall VIOsPAPRDeviceInfo

hw/spapr_vio.c VIOsPAPRBus *spapr_vio_bus_init(void) · line 715

Quoted 8 lines · Anthony Liguori

This was doing something evil building a dt tree so we broke the device.

hw/spapr_vio.c +2 -0
@@ -711,8 +711,12 @@ VIOsPAPRBus *spapr_vio_bus_init(void)
     spapr_rtas_register("ibm,set-tce-bypass", rtas_set_tce_bypass);
     spapr_rtas_register("quiesce", rtas_quiesce);
 
+#if 0
+    /* Evil and broken */

By which you mean: works fine, broken by your patch?

hw/spapr_vio.c VIOsPAPRBus *spapr_vio_bus_init(void) · line 729

Quoted 12 lines
hw/spapr_vio.c +3 -0
+
     for (qinfo = device_info_list; qinfo; qinfo = qinfo->next) {
         VIOsPAPRDeviceInfo *info = (VIOsPAPRDeviceInfo *)qinfo;
+        VIOsPAPRDeviceClass *pc = VIO_SPAPR_DEVICE_GET_CLASS(dev);
 
         if (qinfo->bus_info != &spapr_vio_bus_info) {
             continue;
@@ -722,6 +726,7 @@ VIOsPAPRBus *spapr_vio_bus_init(void)
             info->hcalls(bus);
         }
     }
+#endif

It's registering hcalls for each class of device we find on the spapr vio bus. I don't understand why that is evil, but what do you suggest we do instead?

cheers

#65 lore raw

Re: [Qemu-devel] [PATCH v3 064/197] killall VIOsPAPRDeviceInfo

Quoted 11 lines · Michael Ellerman

hw/spapr_vio.c VIOsPAPRBus *spapr_vio_bus_init(void) · line 715

Quoted 8 lines · Anthony Liguori

This was doing something evil building a dt tree so we broke the device.

hw/spapr_vio.c +2 -0
@@ -711,8 +711,12 @@ VIOsPAPRBus *spapr_vio_bus_init(void)
      spapr_rtas_register("ibm,set-tce-bypass", rtas_set_tce_bypass);
      spapr_rtas_register("quiesce", rtas_quiesce);
 
+#if 0
+    /* Evil and broken */

By which you mean: works fine, broken by your patch?

These patches were never supposed to go out. Ignore this series entirely.

Quoted 6 lines
Quoted 6 lines
hw/spapr_vio.c +2 -0
+
      for (qinfo = device_info_list; qinfo; qinfo = qinfo->next) {
          VIOsPAPRDeviceInfo *info = (VIOsPAPRDeviceInfo *)qinfo;
+        VIOsPAPRDeviceClass *pc = VIO_SPAPR_DEVICE_GET_CLASS(dev);
 
Quoted 11 lines

hw/spapr_vio.c VIOsPAPRBus *spapr_vio_bus_init(void) · line 729

Quoted 7 lines
hw/spapr_vio.c +1 -0
          if (qinfo->bus_info !=&spapr_vio_bus_info) {
              continue;
@@ -722,6 +726,7 @@ VIOsPAPRBus *spapr_vio_bus_init(void)
              info->hcalls(bus);
          }
      }
+#endif

It's registering hcalls for each class of device we find on the spapr vio bus. I don't understand why that is evil, but what do you suggest we do instead?

I talked to David about this, the hcalls can just be registered as part the device_init entry points.

If you must initialize them via a per-device callback, then you should walk it from the bus's children, not by walking the entire device model. That was the bit that I was referring to as evil. It's a layering violation.

Regards,

Anthony Liguori

Quoted 3 lines

cheers

#66 lore raw

Re: [Qemu-devel] [PATCH v3 064/197] killall VIOsPAPRDeviceInfo

Quoted 8 lines · Anthony Liguori
Quoted 7 lines · Michael Ellerman
Quoted 6 lines · Anthony Liguori

This was doing something evil building a dt tree so we broke the device.

hw/spapr_vio.c +0 -0
@@ -711,8 +711,12 @@ VIOsPAPRBus *spapr_vio_bus_init(void)
      spapr_rtas_register("ibm,set-tce-bypass", rtas_set_tce_bypass);
      spapr_rtas_register("quiesce", rtas_quiesce);
 
Quoted 6 lines
Quoted 4 lines

hw/spapr_vio.c VIOsPAPRBus *spapr_vio_bus_init(void) · line 715

Quoted 2 lines
hw/spapr_vio.c +2 -0
+#if 0
+    /* Evil and broken */

By which you mean: works fine, broken by your patch?

These patches were never supposed to go out. Ignore this series entirely.

But I just read all 197 of them ! ;)

Quoted 16 lines
Quoted 4 lines
Quoted 4 lines
hw/spapr_vio.c +1 -0
      for (qinfo = device_info_list; qinfo; qinfo = qinfo->next) {
          VIOsPAPRDeviceInfo *info = (VIOsPAPRDeviceInfo *)qinfo;
+        VIOsPAPRDeviceClass *pc = VIO_SPAPR_DEVICE_GET_CLASS(dev);
 
Quoted 11 lines

hw/spapr_vio.c VIOsPAPRBus *spapr_vio_bus_init(void) · line 729

Quoted 7 lines
hw/spapr_vio.c +1 -0
          if (qinfo->bus_info !=&spapr_vio_bus_info) {
              continue;
@@ -722,6 +726,7 @@ VIOsPAPRBus *spapr_vio_bus_init(void)
              info->hcalls(bus);
          }
      }
+#endif

It's registering hcalls for each class of device we find on the spapr vio bus. I don't understand why that is evil, but what do you suggest we do instead?

Quoted 2 lines

I talked to David about this, the hcalls can just be registered as part the device_init entry points.

OK I'll talk to him about it. I don't think device_init() works, because we only want to register the hcalls if an instance of the device is instantiated. But I guess we'll come up with something.

cheers

#67 lore raw

Re: [Qemu-devel] [PATCH v3 064/197] killall VIOsPAPRDeviceInfo

Quoted 34 lines · Michael Ellerman
Quoted 8 lines · Anthony Liguori
Quoted 7 lines · Michael Ellerman
Quoted 6 lines · Anthony Liguori

This was doing something evil building a dt tree so we broke the device.

hw/spapr_vio.c +0 -0
@@ -711,8 +711,12 @@ VIOsPAPRBus *spapr_vio_bus_init(void)
       spapr_rtas_register("ibm,set-tce-bypass", rtas_set_tce_bypass);
       spapr_rtas_register("quiesce", rtas_quiesce);
 
Quoted 6 lines
Quoted 4 lines

hw/spapr_vio.c VIOsPAPRBus *spapr_vio_bus_init(void) · line 715

Quoted 2 lines
hw/spapr_vio.c +2 -0
+#if 0
+    /* Evil and broken */

By which you mean: works fine, broken by your patch?

These patches were never supposed to go out. Ignore this series entirely.

But I just read all 197 of them ! ;)

Quoted 16 lines
Quoted 15 lines

hw/spapr_vio.c VIOsPAPRBus *spapr_vio_bus_init(void) · line 729

Quoted 11 lines
hw/spapr_vio.c +2 -0
       for (qinfo = device_info_list; qinfo; qinfo = qinfo->next) {
           VIOsPAPRDeviceInfo *info = (VIOsPAPRDeviceInfo *)qinfo;
+        VIOsPAPRDeviceClass *pc = VIO_SPAPR_DEVICE_GET_CLASS(dev);
 
           if (qinfo->bus_info !=&spapr_vio_bus_info) {
               continue;
@@ -722,6 +726,7 @@ VIOsPAPRBus *spapr_vio_bus_init(void)
               info->hcalls(bus);
           }
       }
+#endif

It's registering hcalls for each class of device we find on the spapr vio bus. I don't understand why that is evil, but what do you suggest we do instead?

Quoted 6 lines
Quoted 2 lines

I talked to David about this, the hcalls can just be registered as part the device_init entry points.

OK I'll talk to him about it. I don't think device_init() works, because we only want to register the hcalls if an instance of the device is instantiated. But I guess we'll come up with something.

Since the hcalls are well known and CPUState doesn't get touched at all, why not register all of the possible hcalls in the VIO bus and then use a higher level interface to dispatch to devices? I think that conceptionally makes more sense than the devices directly registering hcalls themselves.

I know you're dealing with an existing virtual I/O model, but it's strange to have an hcall dispatched directly to a device without going through any type of controller/bus hierarchy. It doesn't fit how hardware works very well.

Regards,

Anthony Liguori

Quoted 3 lines

cheers

#68 lore raw

Re: [Qemu-devel] [PATCH v3 064/197] killall VIOsPAPRDeviceInfo

Quoted 6 lines · Anthony Liguori
Quoted 5 lines · Michael Ellerman
Quoted 4 lines · Anthony Liguori
Quoted 3 lines · Michael Ellerman
Quoted 1 line · Anthony Liguori

This was doing something evil building a dt tree so we broke the device.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

hw/spapr_vio.c VIOsPAPRBus *spapr_vio_bus_init(void) · line 715

Quoted 6 lines
hw/spapr_vio.c +2 -0
@@ -711,8 +711,12 @@ VIOsPAPRBus *spapr_vio_bus_init(void)
      spapr_rtas_register("ibm,set-tce-bypass", rtas_set_tce_bypass);
      spapr_rtas_register("quiesce", rtas_quiesce);
 
+#if 0
+    /* Evil and broken */

By which you mean: works fine, broken by your patch?

Um, yeah. It may have been evil, but it wasn't broken, whereas it certainly is broken by this patch.

Quoted 1 line
Quoted 1 line
Quoted 1 line

These patches were never supposed to go out. Ignore this series entirely.

Phew.

Quoted 18 lines
Quoted 18 lines

But I just read all 197 of them ! ;)

Quoted 16 lines
Quoted 15 lines

hw/spapr_vio.c VIOsPAPRBus *spapr_vio_bus_init(void) · line 729

Quoted 11 lines
hw/spapr_vio.c +2 -0
      for (qinfo = device_info_list; qinfo; qinfo = qinfo->next) {
          VIOsPAPRDeviceInfo *info = (VIOsPAPRDeviceInfo *)qinfo;
+        VIOsPAPRDeviceClass *pc = VIO_SPAPR_DEVICE_GET_CLASS(dev);
 
          if (qinfo->bus_info !=&spapr_vio_bus_info) {
              continue;
@@ -722,6 +726,7 @@ VIOsPAPRBus *spapr_vio_bus_init(void)
              info->hcalls(bus);
          }
      }
+#endif

It's registering hcalls for each class of device we find on the spapr vio bus. I don't understand why that is evil, but what do you suggest we do instead?

Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

I talked to David about this, the hcalls can just be registered as part the device_init entry points.

OK I'll talk to him about it. I don't think device_init() works, because we only want to register the hcalls if an instance of the device is instantiated. But I guess we'll come up with something.

Hm, no, actually. The reason we're stepping through the device infos rather than vio devices is so that hcalls are registered per device type rather than per device instance.

Quoted 5 lines

Since the hcalls are well known and CPUState doesn't get touched at all, why not register all of the possible hcalls in the VIO bus and then use a higher level interface to dispatch to devices? I think that conceptionally makes more sense than the devices directly registering hcalls themselves.

No, not really. It means spapr_vio.c has to contain knowledge of every possible VIO device.

Quoted 4 lines

I know you're dealing with an existing virtual I/O model, but it's strange to have an hcall dispatched directly to a device without going through any type of controller/bus hierarchy. It doesn't fit how hardware works very well.

But VIO devices don't work much like real hardware. Other than the CRQ and a few other hcalls, which are already handled at the bus level, there is *no* common processing we can do for the device specific hcalls. Routing them through spapr_vio.c would just be pointless redirection.

Anyway, I'll make a [atch to move the hypercall registrations to device_init functions.

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#69 lore raw

PATCH v3 65/197 qxl: be more patch monkey friendly

In reply to Anthony Liguori
---
 hw/qxl.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
hw/qxl.c +4 -4
index 41500e9..5f30525 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);
Signature · 1 line
1.7.4.1
#70 lore raw

PATCH v3 66/197 make es1370 more script monkey friendly

In reply to Anthony Liguori
---
 hw/es1370.c |    5 -----
 1 files changed, 0 insertions(+), 5 deletions(-)
hw/es1370.c +0 -5
index c5c16b0..8a7ca65 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.4.1
#71 lore raw

PATCH v3 67/197 remove arrays of PCIDeviceInfo

In reply to Anthony Liguori
---
 hw/i440fx.c     |   32 +++++------
 hw/piix4.c      |   29 ++++-----
 hw/usb-ehci.c   |   49 ++++++++--------
 hw/usb-uhci.c   |  107 +++++++++++++++++++---------------
 hw/virtio-pci.c |  174 +++++++++++++++++++++++++++----------------------------
 5 files changed, 196 insertions(+), 195 deletions(-)
hw/i440fx.c +14 -18
index e0600dd..db15ce8 100644
@@ -345,23 +345,19 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix3_devfn,
     return b;
 }
 
-static PCIDeviceInfo i440fx_info[] = {
-    {
-        .qdev.name    = "i440FX",
-        .qdev.desc    = "Host bridge",
-        .qdev.size    = sizeof(PCII440FXState),
-        .qdev.vmsd    = &vmstate_i440fx,
-        .qdev.no_user = 1,
-        .no_hotplug   = 1,
-        .init         = i440fx_initfn,
-        .config_write = i440fx_write_config,
-        .vendor_id    = PCI_VENDOR_ID_INTEL,
-        .device_id    = PCI_DEVICE_ID_INTEL_82441,
-        .revision     = 0x02,
-        .class_id     = PCI_CLASS_BRIDGE_HOST,
-    },{
-        /* end of list */
-    }
+static PCIDeviceInfo i440fx_info = {
+    .qdev.name    = "i440FX",
+    .qdev.desc    = "Host bridge",
+    .qdev.size    = sizeof(PCII440FXState),
+    .qdev.vmsd    = &vmstate_i440fx,
+    .qdev.no_user = 1,
+    .no_hotplug   = 1,
+    .init         = i440fx_initfn,
+    .config_write = i440fx_write_config,
+    .vendor_id    = PCI_VENDOR_ID_INTEL,
+    .device_id    = PCI_DEVICE_ID_INTEL_82441,
+    .revision     = 0x02,
+    .class_id     = PCI_CLASS_BRIDGE_HOST,
 };
 
 static SysBusDeviceInfo i440fx_pcihost_info = {
@@ -375,7 +371,7 @@ static SysBusDeviceInfo i440fx_pcihost_info = {
 static void i440fx_register(void)
 {
     sysbus_register_withprop(&i440fx_pcihost_info);
-    pci_qdev_register_many(i440fx_info);
+    pci_qdev_register(i440fx_info);
 }
 
 device_init(i440fx_register);
hw/piix4.c +13 -16
index 2fd1171..1e959c6 100644
@@ -101,25 +101,22 @@ int piix4_init(PCIBus *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/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
#72 lore raw

PATCH v3 68/197 Patch monkey PCIDeviceInfo conversion

In reply to Anthony Liguori
---
 hw/ac97.c               |   39 +++++++++------
 hw/acpi_piix4.c         |   43 ++++++++++-------
 hw/apb_pci.c            |   54 +++++++++++++--------
 hw/bonito.c             |   30 +++++++-----
 hw/cirrus_vga.c         |   29 +++++++----
 hw/dec_pci.c            |   56 ++++++++++++++--------
 hw/e1000.c              |   43 ++++++++++-------
 hw/es1370.c             |   31 +++++++-----
 hw/grackle_pci.c        |   23 ++++++---
 hw/gt64xxx.c            |   23 ++++++---
 hw/intel-hda.c          |   45 +++++++++++-------
 hw/ioh3420.c            |   57 ++++++++++++----------
 hw/ivshmem.c            |   47 +++++++++++-------
 hw/lsi53c895a.c         |   31 +++++++-----
 hw/ne2000.c             |   35 +++++++++-----
 hw/pcnet-pci.c          |   39 +++++++++------
 hw/ppce500_pci.c        |   21 ++++++---
 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-ohci.c           |   37 +++++++++------
 hw/versatile_pci.c      |   22 ++++++---
 hw/vga-pci.c            |   27 ++++++----
 hw/vmware_vga.c         |   34 ++++++++------
 hw/vt82c686.c           |  120 +++++++++++++++++++++++++++++------------------
 hw/wdt_i6300esb.c       |   31 +++++++-----
 hw/xen_platform.c       |   34 ++++++++------
 hw/xio3130_downstream.c |   57 ++++++++++++----------
 hw/xio3130_upstream.c   |   51 +++++++++++---------
 32 files changed, 806 insertions(+), 505 deletions(-)
hw/ac97.c +24 -15
index 0dbba3b..3f8075a 100644
@@ -1341,21 +1341,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 +26 -17

49 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 fdb8198..a23182d 100644
@@ -788,18 +788,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 +18 -11
index d6d9d70..5718ba7 100644
@@ -2962,17 +2962,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 +35 -21

68 lines not on this page · raw message

hw/e1000.c +26 -17

49 lines not on this page · raw message

hw/es1370.c +19 -12
index 8a7ca65..32a9b8e 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 +15 -8
index 94a608e..0d6a71c 100644
@@ -121,14 +121,21 @@ static int grackle_pci_host_init(PCIDevice *d)
     return 0;
 }
 
-static PCIDeviceInfo grackle_pci_host_info = {
-    .qdev.name = "grackle",
-    .qdev.size = sizeof(PCIDevice),
-    .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_host_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_host_info = {
+    .name = "grackle",
+    .size = sizeof(PCIDevice),
+    .class_init = grackle_pci_host_class_init,
 };
 
 static void grackle_register_devices(void)
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/intel-hda.c +27 -18

51 lines not on this page · raw message

hw/ioh3420.c +32 -25

63 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 110ca44..025c85b 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/ne2000.c +22 -13
index 16dcee2..6484aef 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/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/ppce500_pci.c +14 -7
index 960a5d0..622cd72 100644
@@ -360,13 +360,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/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 36f3930..d2a4130 100644
@@ -168,12 +168,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 f456501..a5bddda 100644
@@ -190,10 +190,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 eaaefe3..f3240a6 100644
@@ -557,14 +557,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-ohci.c +23 -14
index 194c994..3378fc0 100644
@@ -1834,20 +1834,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/versatile_pci.c +14 -8
index 8a88696..5710177 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/vmware_vga.c +20 -14
index af70bde..e2791cb 100644
@@ -1198,20 +1198,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

144 lines not on this page · raw message

hw/wdt_i6300esb.c +19 -12
index 205c32b..a6ceff8 100644
@@ -425,18 +425,25 @@ static WatchdogTimerModel model = {
     .wdt_description = "Intel 6300ESB",
 };
 
-static PCIDeviceInfo i6300esb_info = {
-    .qdev.name    = "i6300esb",
-    .qdev.size    = sizeof(I6300State),
-    .qdev.vmsd    = &vmstate_i6300esb,
-    .qdev.reset   = i6300esb_reset,
-    .config_read  = i6300esb_config_read,
-    .config_write = i6300esb_config_write,
-    .init         = i6300esb_init,
-    .exit         = i6300esb_exit,
-    .vendor_id    = PCI_VENDOR_ID_INTEL,
-    .device_id    = PCI_DEVICE_ID_INTEL_ESB_9,
-    .class_id     = PCI_CLASS_SYSTEM_OTHER,
+static void i6300esb_class_init(ObjectClass *klass, void *data)
+{
+    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+    k->config_read = i6300esb_config_read;
+    k->config_write = i6300esb_config_write;
+    k->init = i6300esb_init;
+    k->exit = i6300esb_exit;
+    k->vendor_id = PCI_VENDOR_ID_INTEL;
+    k->device_id = PCI_DEVICE_ID_INTEL_ESB_9;
+    k->class_id = PCI_CLASS_SYSTEM_OTHER;
+}
+
+static DeviceInfo i6300esb_info = {
+    .name = "i6300esb",
+    .size = sizeof(I6300State),
+    .vmsd = &vmstate_i6300esb,
+    .reset = i6300esb_reset,
+    .class_init = i6300esb_class_init,
 };
 
 static void i6300esb_register_devices(void)
hw/xen_platform.c +20 -14
index 5e792f5..6535c1b 100644
@@ -372,20 +372,26 @@ static void platform_reset(DeviceState *dev)
     platform_fixed_ioport_reset(s);
 }
 
-static PCIDeviceInfo xen_platform_info = {
-    .init = xen_platform_initfn,
-    .qdev.name = "xen-platform",
-    .qdev.desc = "XEN platform pci device",
-    .qdev.size = sizeof(PCIXenPlatformState),
-    .qdev.vmsd = &vmstate_xen_platform,
-    .qdev.reset = platform_reset,
-
-    .vendor_id    =  PCI_VENDOR_ID_XEN,
-    .device_id    = PCI_DEVICE_ID_XEN_PLATFORM,
-    .class_id     = PCI_CLASS_OTHERS << 8 | 0x80,
-    .subsystem_vendor_id = PCI_VENDOR_ID_XEN,
-    .subsystem_id = PCI_DEVICE_ID_XEN_PLATFORM,
-    .revision = 1,
+static void xen_platform_class_init(ObjectClass *klass, void *data)
+{
+    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+    k->init = xen_platform_initfn;
+    k->vendor_id = PCI_VENDOR_ID_XEN;
+    k->device_id = PCI_DEVICE_ID_XEN_PLATFORM;
+    k->class_id = PCI_CLASS_OTHERS << 8 | 0x80;
+    k->subsystem_vendor_id = PCI_VENDOR_ID_XEN;
+    k->subsystem_id = PCI_DEVICE_ID_XEN_PLATFORM;
+    k->revision = 1;
+}
+
+static DeviceInfo xen_platform_info = {
+    .name = "xen-platform",
+    .desc = "XEN platform pci device",
+    .size = sizeof(PCIXenPlatformState),
+    .vmsd = &vmstate_xen_platform,
+    .reset = platform_reset,
+    .class_init = xen_platform_class_init,
 };
 
 static void xen_platform_register(void)
hw/xio3130_downstream.c +32 -25

63 lines not on this page · raw message

hw/xio3130_upstream.c +29 -22

57 lines not on this page · raw message

Signature · 1 line
1.7.4.1
#73 lore raw

PATCH v3 69/197 patch monkey, that funky monkey

In reply to Anthony Liguori
---
 hw/i440fx.c     |   33 ++++++----
 hw/piix3.c      |   71 ++++++++++++---------
 hw/piix4.c      |   30 +++++----
 hw/usb-ehci.c   |   54 ++++++++++------
 hw/usb-uhci.c   |  168 +++++++++++++++++++++++++++++++------------------
 hw/virtio-pci.c |  188 +++++++++++++++++++++++++++++++++----------------------
 6 files changed, 331 insertions(+), 213 deletions(-)
hw/i440fx.c +20 -13
index db15ce8..2910ef6 100644
@@ -345,19 +345,26 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix3_devfn,
     return b;
 }
 
-static PCIDeviceInfo i440fx_info = {
-    .qdev.name    = "i440FX",
-    .qdev.desc    = "Host bridge",
-    .qdev.size    = sizeof(PCII440FXState),
-    .qdev.vmsd    = &vmstate_i440fx,
-    .qdev.no_user = 1,
-    .no_hotplug   = 1,
-    .init         = i440fx_initfn,
-    .config_write = i440fx_write_config,
-    .vendor_id    = PCI_VENDOR_ID_INTEL,
-    .device_id    = PCI_DEVICE_ID_INTEL_82441,
-    .revision     = 0x02,
-    .class_id     = PCI_CLASS_BRIDGE_HOST,
+static void i440fx_class_init(ObjectClass *klass, void *data)
+{
+    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+    k->no_hotplug = 1;
+    k->init = i440fx_initfn;
+    k->config_write = i440fx_write_config;
+    k->vendor_id = PCI_VENDOR_ID_INTEL;
+    k->device_id = PCI_DEVICE_ID_INTEL_82441;
+    k->revision = 0x02;
+    k->class_id = PCI_CLASS_BRIDGE_HOST;
+}
+
+static DeviceInfo i440fx_info = {
+    .name = "i440FX",
+    .desc = "Host bridge",
+    .size = sizeof(PCII440FXState),
+    .vmsd = &vmstate_i440fx,
+    .no_user = 1,
+    .class_init = i440fx_class_init,
 };
 
 static SysBusDeviceInfo i440fx_pcihost_info = {
hw/piix3.c +42 -29

81 lines not on this page · raw message

hw/piix4.c +18 -12
index 1e959c6..dd76123 100644
@@ -101,18 +101,24 @@ int piix4_init(PCIBus *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/usb-ehci.c +34 -20

62 lines not on this page · raw message

hw/usb-uhci.c +105 -63

184 lines not on this page · raw message

hw/virtio-pci.c +112 -76

200 lines not on this page · raw message

Signature · 1 line
1.7.4.1