* [Qemu-devel] [RFC 00/34] QOM realize, device-only plus ISA conversion
@ 2012-11-26 0:12 Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [PATCH 01/34] qdev: Eliminate qdev_free() in favor of QOM Andreas Färber
` (35 more replies)
0 siblings, 36 replies; 46+ messages in thread
From: Andreas Färber @ 2012-11-26 0:12 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Stefan Hajnoczi, Markus Armbruster,
Eduardo Habkost, Julien Grall, anthony, Igor Mammedov,
Cornelia Huck, Paolo Bonzini, Andreas Färber,
Frederic Konrad
Hello Anthony and Paolo,
As announced at KVM Forum, I have been preparing a new approach to incrementally
get us Anthony's QOM realizefn concept. A previous attempt by Paolo and me had
been turned down for making this available at Object-level and over questions
whether BlockDriverState may need its own three-stage realization model.
So here's an all-new patchset doing it at DeviceState-level only, adapting the
signature to void realize(DeviceState *, Error **).
CPUState is on a good way to get derived from DeviceState, so in the future
will benefit from this approach as well.
I've picked ISADevice as an example to showcase what semantic effects the
switch to QOM realizefn has (in the hopes the number of devices would be small):
As requested by Anthony for QOM CPUState reset and as seen with virtual methods
in object-oriented programming languages, it becomes the derived method's
responsibility to decide when and whether to call the parent class' method. In
lack of real vtables this requires to save the parent's method in case we want
to call it; classes and matching macros may need to be added for that.
Another point to note is that we should carefully distinguish what goes into
the qdev initfn / QOM realizefn and what can already go into a QOM initfn.
This series is rebased onto Julien's ioport cleanups (touching on ISA devices).
It starts by preparing the "realized" property, wrapping qdev's initfn (04).
This means setting realized to true will not yet affect its children, as seen
in Paolo's previous patches. That can be implemented later when the realizefns
have been reviewed not to create new devices that would mess with recursive
child realization. (In the previous series we had recursive realization but
on my request dropped the hook-up of qdev due to the aforementioned quirks.)
At that point there is a coexistence of QOM device realizefn and qdev initfn.
For the first time now I have set out to actually eliminate some qdev initfns,
that's what I chose ISA for. This consists of three parts, introducing
realizefns for ISADevices (28) and recursively for PITs (31) and for PICs (34).
As seen for the PCI host bridge series, I've extracted general QOM cleanups
from the main conversion patch to arrive at a clean QOM'ish state while
hopefully keeping the main patches readable.
This series also highlights an interesting find: Beyond the to-be-solved
CPUState, there is also a "realize" function for BusState (02), which is not
derived from DeviceState. :-)
With the device-centric approach taken here it would still be possible to add
"realized" properties to other types using their own infrastructure (e.g., a
hardcoded setter rather than a realizefn hook).
Posted as an RFC to encourage bikeshedding, in particular about the type names
and macros introduced. Adding new header files to move them out of the source
files for, e.g., vl.c is left for a follow-up, but for instance I was unsure
about TYPE_ISA_FDC (should this be TYPE_ISA_FLOPPY_DRIVE_CONTROLLER as with
PCI_HOST_BRIDGE rather than PHB?), and naming of type names and functions is
highly inconsistent (e.g., isa_vga vs. vga_isa, or pic vs. i8259).
Available for viewing/testing at:
https://github.com/afaerber/qemu-cpu/commits/realize-qdev
git://github.com/afaerber/qemu-cpu.git realize-qdev
Regards,
Andreas
Cc: Anthony Liguori <anthony@codemonkey.ws>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Julien Grall <julien.grall@citrix.com>
Cc: Frederic Konrad <fred.konrad@greensocs.com>
Cc: Peter Maydell <peter.maydell@linaro.org>
Cc: Cornelia Huck <cornelia.huck@de.ibm.com>
Cc: Kevin Wolf <kwolf@redhat.com>
Cc: Stefan Hajnoczi <stefanha@redhat.com>
Cc: Markus Armbruster <armbru@redhat.com>
Cc: Eduardo Habkost <ehabkost@redhat.com>
Cc: Igor Mammedov <imammedo@redhat.com>
Andreas Färber (34):
qdev: Eliminate qdev_free() in favor of QOM
qbus: QOM'ify qbus_realize()
qdev: Fold state enum into bool realized
qdev: Prepare "realized" property
isa: Split off instance_init for ISADevice
applesmc: QOM'ify
cirrus_vga: QOM'ify ISA Cirrus VGA
debugcon: QOM'ify ISA debug console
fdc: QOM'ify ISA floppy controller
i82374: QOM'ify
i8259: Fix PIC_COMMON() macro
i8259: QOM cleanups
ide: QOM'ify ISA IDE
m48t59: QOM'ify ISA M48T59 NVRAM
mc146818rtc: QOM'ify
ne2000-isa: QOM'ify
parallel: QOM'ify
pc: QOM'ify port 92
pckbd: QOM'ify
pcspk: QOM'ify
sb16: QOM'ify
serial: QOM'ify ISA serial
sga: QOM'ify
vga-isa: QOM'ify ISA VGA
vmmouse: QOM'ify
vmport: QOM'ify
wdt_ib700: QOM'ify
isa: Use realizefn for ISADevice
i8254: QOM'ify
kvm/i8254: QOM'ify some more
i8254: Convert PITCommonState to QOM realizefn
i8259: QOM'ify some more
kvm/i8259: QOM'ify some more
i8259: Convert PICCommonState to use QOM realizefn
hw/acpi_piix4.c | 2 +-
hw/applesmc.c | 45 +++++++++---------
hw/cirrus_vga.c | 27 ++++++-----
hw/debugcon.c | 34 +++++++++-----
hw/fdc.c | 45 ++++++++++--------
hw/fdc.h | 2 +
hw/i82374.c | 25 +++++-----
hw/i8254.c | 26 +++++++---
hw/i8254.h | 7 ++-
hw/i8254_common.c | 19 ++------
hw/i8254_internal.h | 1 -
hw/i8259.c | 64 +++++++++++++++++--------
hw/i8259_common.c | 20 +++-----
hw/i8259_internal.h | 7 +--
hw/ide/isa.c | 55 +++++++++++++---------
hw/isa-bus.c | 15 ++----
hw/isa.h | 1 -
hw/kvm/i8254.c | 59 +++++++++++++++--------
hw/kvm/i8259.c | 38 ++++++++++++---
hw/m48t59.c | 54 +++++++++++----------
hw/mc146818rtc.c | 56 ++++++++++++----------
hw/mc146818rtc.h | 2 +
hw/ne2000-isa.c | 27 ++++++-----
hw/parallel.c | 42 ++++++++++-------
hw/pc.c | 26 +++++-----
hw/pc_piix.c | 2 +-
hw/pci-hotplug.c | 2 +-
hw/pci_bridge.c | 2 +-
hw/pcie.c | 2 +-
hw/pckbd.c | 34 ++++++++------
hw/pcspk.c | 21 +++++----
hw/pcspk.h | 4 +-
hw/qdev-addr.c | 2 +-
hw/qdev-core.h | 12 ++---
hw/qdev-monitor.c | 2 +-
hw/qdev-properties.c | 28 +++++------
hw/qdev.c | 128 ++++++++++++++++++++++++++++++++++----------------
hw/sb16.c | 35 +++++++++-----
hw/scsi-bus.c | 4 +-
hw/serial-isa.c | 33 +++++++------
hw/serial-pci.c | 4 +-
hw/serial.c | 6 +--
hw/serial.h | 3 +-
hw/sga.c | 19 ++++----
hw/shpc.c | 2 +-
hw/usb/bus.c | 7 +--
hw/usb/dev-storage.c | 2 +-
hw/usb/host-linux.c | 2 +-
hw/vga-isa.c | 46 +++++++++---------
hw/vmmouse.c | 24 +++++-----
hw/vmport.c | 24 ++++++----
hw/wdt_ib700.c | 22 +++++----
hw/xen_platform.c | 2 +-
53 Dateien geändert, 692 Zeilen hinzugefügt(+), 481 Zeilen entfernt(-)
--
1.7.10.4
^ permalink raw reply [flat|nested] 46+ messages in thread
* [Qemu-devel] [PATCH 01/34] qdev: Eliminate qdev_free() in favor of QOM
2012-11-26 0:12 [Qemu-devel] [RFC 00/34] QOM realize, device-only plus ISA conversion Andreas Färber
@ 2012-11-26 0:12 ` Andreas Färber
2012-11-26 7:20 ` Paolo Bonzini
2012-11-26 0:12 ` [Qemu-devel] [RFC 02/34] qbus: QOM'ify qbus_realize() Andreas Färber
` (34 subsequent siblings)
35 siblings, 1 reply; 46+ messages in thread
From: Andreas Färber @ 2012-11-26 0:12 UTC (permalink / raw)
To: qemu-devel
Cc: open list:X86, Stefano Stabellini, Michael S. Tsirkin, anthony,
Paolo Bonzini, Andreas Färber
qdev_free() was trivially wrapping object_delete(). Inline it and drop
the wrapper as a further step to QOM'ify qdev.
Signed-off-by: Andreas Färber <afaerber@suse.de>
Cc: Paolo Bonzini <pbonzini@redhat.com>
---
hw/acpi_piix4.c | 2 +-
hw/pci-hotplug.c | 2 +-
hw/pci_bridge.c | 2 +-
hw/pcie.c | 2 +-
hw/qdev-core.h | 1 -
hw/qdev-monitor.c | 2 +-
hw/qdev.c | 12 +++---------
hw/scsi-bus.c | 4 ++--
hw/shpc.c | 2 +-
hw/usb/bus.c | 7 ++++---
hw/usb/dev-storage.c | 2 +-
hw/usb/host-linux.c | 2 +-
hw/xen_platform.c | 2 +-
13 Dateien geändert, 18 Zeilen hinzugefügt(+), 24 Zeilen entfernt(-)
diff --git a/hw/acpi_piix4.c b/hw/acpi_piix4.c
index 0fa4c98..e6d09be 100644
--- a/hw/acpi_piix4.c
+++ b/hw/acpi_piix4.c
@@ -361,7 +361,7 @@ static void acpi_piix_eject_slot(PIIX4PMState *s, unsigned slots)
if (pc->no_hotplug) {
slot_free = false;
} else {
- qdev_free(qdev);
+ object_delete(OBJECT(qdev));
}
}
}
diff --git a/hw/pci-hotplug.c b/hw/pci-hotplug.c
index e7fb780..d766eab 100644
--- a/hw/pci-hotplug.c
+++ b/hw/pci-hotplug.c
@@ -204,7 +204,7 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon,
}
dev = pci_create(bus, devfn, "virtio-blk-pci");
if (qdev_prop_set_drive(&dev->qdev, "drive", dinfo->bdrv) < 0) {
- qdev_free(&dev->qdev);
+ object_delete(OBJECT(dev));
dev = NULL;
break;
}
diff --git a/hw/pci_bridge.c b/hw/pci_bridge.c
index 4680501..3689502 100644
--- a/hw/pci_bridge.c
+++ b/hw/pci_bridge.c
@@ -347,7 +347,7 @@ void pci_bridge_exitfn(PCIDevice *pci_dev)
pci_bridge_region_cleanup(s, s->windows);
memory_region_destroy(&s->address_space_mem);
memory_region_destroy(&s->address_space_io);
- /* qbus_free() is called automatically by qdev_free() */
+ /* qbus_free() is called automatically by object_delete() */
}
/*
diff --git a/hw/pcie.c b/hw/pcie.c
index 7c92f19..24bfc95 100644
--- a/hw/pcie.c
+++ b/hw/pcie.c
@@ -235,7 +235,7 @@ static int pcie_cap_slot_hotplug(DeviceState *qdev,
PCI_EXP_SLTSTA_PDS);
pcie_cap_slot_event(d, PCI_EXP_HP_EV_PDC);
} else {
- qdev_free(&pci_dev->qdev);
+ object_delete(OBJECT(pci_dev));
pci_word_test_and_clear_mask(exp_cap + PCI_EXP_SLTSTA,
PCI_EXP_SLTSTA_PDS);
pcie_cap_slot_event(d, PCI_EXP_HP_EV_PDC);
diff --git a/hw/qdev-core.h b/hw/qdev-core.h
index fce9e22..36191e9 100644
--- a/hw/qdev-core.h
+++ b/hw/qdev-core.h
@@ -158,7 +158,6 @@ void qdev_init_nofail(DeviceState *dev);
void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id,
int required_for_version);
void qdev_unplug(DeviceState *dev, Error **errp);
-void qdev_free(DeviceState *dev);
int qdev_simple_unplug_cb(DeviceState *dev);
void qdev_machine_creation_done(void);
bool qdev_machine_modified(void);
diff --git a/hw/qdev-monitor.c b/hw/qdev-monitor.c
index 479eecd..d534b9d 100644
--- a/hw/qdev-monitor.c
+++ b/hw/qdev-monitor.c
@@ -466,7 +466,7 @@ DeviceState *qdev_device_add(QemuOpts *opts)
qdev->id = id;
}
if (qemu_opt_foreach(opts, set_property, qdev, 1) != 0) {
- qdev_free(qdev);
+ object_delete(OBJECT(qdev));
return NULL;
}
if (qdev->id) {
diff --git a/hw/qdev.c b/hw/qdev.c
index 7ddcd24..c2d9b48 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -154,7 +154,7 @@ int qdev_init(DeviceState *dev)
rc = dc->init(dev);
if (rc < 0) {
- qdev_free(dev);
+ object_delete(OBJECT(dev));
return rc;
}
@@ -237,7 +237,7 @@ void qbus_reset_all_fn(void *opaque)
int qdev_simple_unplug_cb(DeviceState *dev)
{
/* just zap it */
- qdev_free(dev);
+ object_delete(OBJECT(dev));
return 0;
}
@@ -259,12 +259,6 @@ void qdev_init_nofail(DeviceState *dev)
}
}
-/* Unlink device from bus and free the structure. */
-void qdev_free(DeviceState *dev)
-{
- object_delete(OBJECT(dev));
-}
-
void qdev_machine_creation_done(void)
{
/*
@@ -765,7 +759,7 @@ static void qbus_finalize(Object *obj)
while ((kid = QTAILQ_FIRST(&bus->children)) != NULL) {
DeviceState *dev = kid->child;
- qdev_free(dev);
+ object_delete(OBJECT(dev));
}
if (bus->parent) {
QLIST_REMOVE(bus, sibling);
diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c
index dfb2631..68a27eb 100644
--- a/hw/scsi-bus.c
+++ b/hw/scsi-bus.c
@@ -175,7 +175,7 @@ static int scsi_qdev_init(DeviceState *qdev)
d = scsi_device_find(bus, dev->channel, dev->id, dev->lun);
assert(d);
if (d->lun == dev->lun && dev != d) {
- qdev_free(&d->qdev);
+ object_delete(OBJECT(d));
}
}
@@ -222,7 +222,7 @@ SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv,
qdev_prop_set_bit(dev, "removable", removable);
}
if (qdev_prop_set_drive(dev, "drive", bdrv) < 0) {
- qdev_free(dev);
+ object_delete(OBJECT(dev));
return NULL;
}
if (qdev_init(dev) < 0)
diff --git a/hw/shpc.c b/hw/shpc.c
index 4597bbd..24bdfb8 100644
--- a/hw/shpc.c
+++ b/hw/shpc.c
@@ -253,7 +253,7 @@ static void shpc_free_devices_in_slot(SHPCDevice *shpc, int slot)
++devfn) {
PCIDevice *affected_dev = shpc->sec_bus->devices[devfn];
if (affected_dev) {
- qdev_free(&affected_dev->qdev);
+ object_delete(OBJECT(affected_dev));
}
}
}
diff --git a/hw/usb/bus.c b/hw/usb/bus.c
index 99aac7a..1675798 100644
--- a/hw/usb/bus.c
+++ b/hw/usb/bus.c
@@ -337,8 +337,9 @@ void usb_port_location(USBPort *downstream, USBPort *upstream, int portnr)
void usb_unregister_port(USBBus *bus, USBPort *port)
{
- if (port->dev)
- qdev_free(&port->dev->qdev);
+ if (port->dev) {
+ object_delete(OBJECT(port->dev));
+ }
QTAILQ_REMOVE(&bus->free, port, next);
bus->nfree--;
}
@@ -458,7 +459,7 @@ int usb_device_delete_addr(int busnr, int addr)
return -1;
dev = port->dev;
- qdev_free(&dev->qdev);
+ object_delete(OBJECT(dev));
return 0;
}
diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c
index 50af971..2efb4d5 100644
--- a/hw/usb/dev-storage.c
+++ b/hw/usb/dev-storage.c
@@ -664,7 +664,7 @@ static USBDevice *usb_msd_init(USBBus *bus, const char *filename)
return NULL;
}
if (qdev_prop_set_drive(&dev->qdev, "drive", dinfo->bdrv) < 0) {
- qdev_free(&dev->qdev);
+ object_delete(OBJECT(dev));
return NULL;
}
if (qdev_init(&dev->qdev) < 0)
diff --git a/hw/usb/host-linux.c b/hw/usb/host-linux.c
index aa77b77..a0417fc 100644
--- a/hw/usb/host-linux.c
+++ b/hw/usb/host-linux.c
@@ -1584,7 +1584,7 @@ USBDevice *usb_host_device_open(USBBus *bus, const char *devname)
return dev;
fail:
- qdev_free(&dev->qdev);
+ object_delete(OBJECT(dev));
return NULL;
}
diff --git a/hw/xen_platform.c b/hw/xen_platform.c
index a54e7a2..d56f3e5 100644
--- a/hw/xen_platform.c
+++ b/hw/xen_platform.c
@@ -89,7 +89,7 @@ static void unplug_nic(PCIBus *b, PCIDevice *d, void *o)
if (pci_get_word(d->config + PCI_CLASS_DEVICE) ==
PCI_CLASS_NETWORK_ETHERNET
&& strcmp(d->name, "xen-pci-passthrough") != 0) {
- qdev_free(&d->qdev);
+ object_delete(OBJECT(d));
}
}
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [Qemu-devel] [RFC 02/34] qbus: QOM'ify qbus_realize()
2012-11-26 0:12 [Qemu-devel] [RFC 00/34] QOM realize, device-only plus ISA conversion Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [PATCH 01/34] qdev: Eliminate qdev_free() in favor of QOM Andreas Färber
@ 2012-11-26 0:12 ` Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 03/34] qdev: Fold state enum into bool realized Andreas Färber
` (33 subsequent siblings)
35 siblings, 0 replies; 46+ messages in thread
From: Andreas Färber @ 2012-11-26 0:12 UTC (permalink / raw)
To: qemu-devel; +Cc: Andreas Färber, anthony
Add the designated Error-reporting argument, even if currently unused.
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
hw/qdev.c | 6 +++---
1 Datei geändert, 3 Zeilen hinzugefügt(+), 3 Zeilen entfernt(-)
diff --git a/hw/qdev.c b/hw/qdev.c
index c2d9b48..e7c9493 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -397,7 +397,7 @@ DeviceState *qdev_find_recursive(BusState *bus, const char *id)
return NULL;
}
-static void qbus_realize(BusState *bus)
+static void qbus_realize(BusState *bus, Error **err)
{
const char *typename = object_get_typename(OBJECT(bus));
char *buf;
@@ -440,7 +440,7 @@ void qbus_create_inplace(BusState *bus, const char *typename,
bus->parent = parent;
bus->name = name ? g_strdup(name) : NULL;
- qbus_realize(bus);
+ qbus_realize(bus, NULL);
}
BusState *qbus_create(const char *typename, DeviceState *parent, const char *name)
@@ -452,7 +452,7 @@ BusState *qbus_create(const char *typename, DeviceState *parent, const char *nam
bus->parent = parent;
bus->name = name ? g_strdup(name) : NULL;
- qbus_realize(bus);
+ qbus_realize(bus, NULL);
return bus;
}
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [Qemu-devel] [RFC 03/34] qdev: Fold state enum into bool realized
2012-11-26 0:12 [Qemu-devel] [RFC 00/34] QOM realize, device-only plus ISA conversion Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [PATCH 01/34] qdev: Eliminate qdev_free() in favor of QOM Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 02/34] qbus: QOM'ify qbus_realize() Andreas Färber
@ 2012-11-26 0:12 ` Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 04/34] qdev: Prepare "realized" property Andreas Färber
` (32 subsequent siblings)
35 siblings, 0 replies; 46+ messages in thread
From: Andreas Färber @ 2012-11-26 0:12 UTC (permalink / raw)
To: qemu-devel; +Cc: Andreas Färber, anthony
Whether the device was initialized or not is QOM-level information and
currently unused. Drop it from qdev. This leaves the boolean state of
whether or not DeviceClass::init was called or not, a.k.a. "realized".
Suggested-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
hw/qdev-addr.c | 2 +-
hw/qdev-core.h | 7 +------
hw/qdev-properties.c | 28 ++++++++++++++--------------
hw/qdev.c | 12 ++++++------
4 Dateien geändert, 22 Zeilen hinzugefügt(+), 27 Zeilen entfernt(-)
diff --git a/hw/qdev-addr.c b/hw/qdev-addr.c
index ea32c31..fb95798 100644
--- a/hw/qdev-addr.c
+++ b/hw/qdev-addr.c
@@ -40,7 +40,7 @@ static void set_taddr(Object *obj, Visitor *v, void *opaque,
Error *local_err = NULL;
int64_t value;
- if (dev->state != DEV_STATE_CREATED) {
+ if (dev->realized) {
error_set(errp, QERR_PERMISSION_DENIED);
return;
}
diff --git a/hw/qdev-core.h b/hw/qdev-core.h
index 36191e9..f0d3a5e 100644
--- a/hw/qdev-core.h
+++ b/hw/qdev-core.h
@@ -17,11 +17,6 @@ typedef struct BusState BusState;
typedef struct BusClass BusClass;
-enum DevState {
- DEV_STATE_CREATED = 1,
- DEV_STATE_INITIALIZED,
-};
-
enum {
DEV_NVECTORS_UNSPECIFIED = -1,
};
@@ -64,7 +59,7 @@ struct DeviceState {
Object parent_obj;
const char *id;
- enum DevState state;
+ bool realized;
QemuOpts *opts;
int hotplugged;
BusState *parent_bus;
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index 81d901c..773547b 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -36,7 +36,7 @@ static void set_pointer(Object *obj, Visitor *v, Property *prop,
char *str;
int ret;
- if (dev->state != DEV_STATE_CREATED) {
+ if (dev->realized) {
error_set(errp, QERR_PERMISSION_DENIED);
return;
}
@@ -74,7 +74,7 @@ static void set_enum(Object *obj, Visitor *v, void *opaque,
Property *prop = opaque;
int *ptr = qdev_get_prop_ptr(dev, prop);
- if (dev->state != DEV_STATE_CREATED) {
+ if (dev->realized) {
error_set(errp, QERR_PERMISSION_DENIED);
return;
}
@@ -126,7 +126,7 @@ static void set_bit(Object *obj, Visitor *v, void *opaque,
Error *local_err = NULL;
bool value;
- if (dev->state != DEV_STATE_CREATED) {
+ if (dev->realized) {
error_set(errp, QERR_PERMISSION_DENIED);
return;
}
@@ -166,7 +166,7 @@ static void set_uint8(Object *obj, Visitor *v, void *opaque,
Property *prop = opaque;
uint8_t *ptr = qdev_get_prop_ptr(dev, prop);
- if (dev->state != DEV_STATE_CREATED) {
+ if (dev->realized) {
error_set(errp, QERR_PERMISSION_DENIED);
return;
}
@@ -233,7 +233,7 @@ static void set_uint16(Object *obj, Visitor *v, void *opaque,
Property *prop = opaque;
uint16_t *ptr = qdev_get_prop_ptr(dev, prop);
- if (dev->state != DEV_STATE_CREATED) {
+ if (dev->realized) {
error_set(errp, QERR_PERMISSION_DENIED);
return;
}
@@ -266,7 +266,7 @@ static void set_uint32(Object *obj, Visitor *v, void *opaque,
Property *prop = opaque;
uint32_t *ptr = qdev_get_prop_ptr(dev, prop);
- if (dev->state != DEV_STATE_CREATED) {
+ if (dev->realized) {
error_set(errp, QERR_PERMISSION_DENIED);
return;
}
@@ -291,7 +291,7 @@ static void set_int32(Object *obj, Visitor *v, void *opaque,
Property *prop = opaque;
int32_t *ptr = qdev_get_prop_ptr(dev, prop);
- if (dev->state != DEV_STATE_CREATED) {
+ if (dev->realized) {
error_set(errp, QERR_PERMISSION_DENIED);
return;
}
@@ -364,7 +364,7 @@ static void set_uint64(Object *obj, Visitor *v, void *opaque,
Property *prop = opaque;
uint64_t *ptr = qdev_get_prop_ptr(dev, prop);
- if (dev->state != DEV_STATE_CREATED) {
+ if (dev->realized) {
error_set(errp, QERR_PERMISSION_DENIED);
return;
}
@@ -452,7 +452,7 @@ static void set_string(Object *obj, Visitor *v, void *opaque,
Error *local_err = NULL;
char *str;
- if (dev->state != DEV_STATE_CREATED) {
+ if (dev->realized) {
error_set(errp, QERR_PERMISSION_DENIED);
return;
}
@@ -666,7 +666,7 @@ static void set_vlan(Object *obj, Visitor *v, void *opaque,
int32_t id;
NetClientState *hubport;
- if (dev->state != DEV_STATE_CREATED) {
+ if (dev->realized) {
error_set(errp, QERR_PERMISSION_DENIED);
return;
}
@@ -737,7 +737,7 @@ static void set_mac(Object *obj, Visitor *v, void *opaque,
int i, pos;
char *str, *p;
- if (dev->state != DEV_STATE_CREATED) {
+ if (dev->realized) {
error_set(errp, QERR_PERMISSION_DENIED);
return;
}
@@ -825,7 +825,7 @@ static void set_pci_devfn(Object *obj, Visitor *v, void *opaque,
Error *local_err = NULL;
char *str;
- if (dev->state != DEV_STATE_CREATED) {
+ if (dev->realized) {
error_set(errp, QERR_PERMISSION_DENIED);
return;
}
@@ -895,7 +895,7 @@ static void set_blocksize(Object *obj, Visitor *v, void *opaque,
const int64_t min = 512;
const int64_t max = 32768;
- if (dev->state != DEV_STATE_CREATED) {
+ if (dev->realized) {
error_set(errp, QERR_PERMISSION_DENIED);
return;
}
@@ -963,7 +963,7 @@ static void set_pci_host_devaddr(Object *obj, Visitor *v, void *opaque,
unsigned long dom = 0, bus = 0;
unsigned int slot = 0, func = 0;
- if (dev->state != DEV_STATE_CREATED) {
+ if (dev->realized) {
error_set(errp, QERR_PERMISSION_DENIED);
return;
}
diff --git a/hw/qdev.c b/hw/qdev.c
index e7c9493..bce6ad5 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -150,7 +150,7 @@ int qdev_init(DeviceState *dev)
DeviceClass *dc = DEVICE_GET_CLASS(dev);
int rc;
- assert(dev->state == DEV_STATE_CREATED);
+ assert(!dev->realized);
rc = dc->init(dev);
if (rc < 0) {
@@ -173,7 +173,7 @@ int qdev_init(DeviceState *dev)
dev->instance_id_alias,
dev->alias_required_for_version);
}
- dev->state = DEV_STATE_INITIALIZED;
+ dev->realized = true;
if (dev->hotplugged) {
device_reset(dev);
}
@@ -183,7 +183,7 @@ int qdev_init(DeviceState *dev)
void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id,
int required_for_version)
{
- assert(dev->state == DEV_STATE_CREATED);
+ assert(!dev->realized);
dev->instance_id_alias = alias_id;
dev->alias_required_for_version = required_for_version;
}
@@ -554,7 +554,7 @@ static void qdev_set_legacy_property(Object *obj, Visitor *v, void *opaque,
char *ptr = NULL;
int ret;
- if (dev->state != DEV_STATE_CREATED) {
+ if (dev->realized) {
error_set(errp, QERR_PERMISSION_DENIED);
return;
}
@@ -661,7 +661,7 @@ static void device_initfn(Object *obj)
}
dev->instance_id_alias = -1;
- dev->state = DEV_STATE_CREATED;
+ dev->realized = false;
class = object_get_class(OBJECT(dev));
do {
@@ -684,7 +684,7 @@ static void device_finalize(Object *obj)
BusState *bus;
DeviceClass *dc = DEVICE_GET_CLASS(dev);
- if (dev->state == DEV_STATE_INITIALIZED) {
+ if (dev->realized) {
while (dev->num_child_bus) {
bus = QLIST_FIRST(&dev->child_bus);
qbus_free(bus);
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [Qemu-devel] [RFC 04/34] qdev: Prepare "realized" property
2012-11-26 0:12 [Qemu-devel] [RFC 00/34] QOM realize, device-only plus ISA conversion Andreas Färber
` (2 preceding siblings ...)
2012-11-26 0:12 ` [Qemu-devel] [RFC 03/34] qdev: Fold state enum into bool realized Andreas Färber
@ 2012-11-26 0:12 ` Andreas Färber
2012-12-12 14:29 ` Eduardo Habkost
2012-11-26 0:12 ` [Qemu-devel] [RFC 05/34] isa: Split off instance_init for ISADevice Andreas Färber
` (31 subsequent siblings)
35 siblings, 1 reply; 46+ messages in thread
From: Andreas Färber @ 2012-11-26 0:12 UTC (permalink / raw)
To: qemu-devel; +Cc: Paolo Bonzini, Andreas Färber, anthony
Based on earlier patches by Paolo and me, introduce the QOM realizefn at
device level only, as requested by Anthony.
For now this just wraps the qdev initfn.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
Cc: Anthony Liguori <anthony@codemonkey.ws>
---
hw/qdev-core.h | 4 +++
hw/qdev.c | 100 ++++++++++++++++++++++++++++++++++++++++++--------------
2 Dateien geändert, 80 Zeilen hinzugefügt(+), 24 Zeilen entfernt(-)
diff --git a/hw/qdev-core.h b/hw/qdev-core.h
index f0d3a5e..580a811 100644
--- a/hw/qdev-core.h
+++ b/hw/qdev-core.h
@@ -29,6 +29,8 @@ enum {
typedef int (*qdev_initfn)(DeviceState *dev);
typedef int (*qdev_event)(DeviceState *dev);
typedef void (*qdev_resetfn)(DeviceState *dev);
+typedef void (*DeviceRealize)(DeviceState *dev, Error **err);
+typedef void (*DeviceUnrealize)(DeviceState *dev, Error **err);
struct VMStateDescription;
@@ -47,6 +49,8 @@ typedef struct DeviceClass {
const struct VMStateDescription *vmsd;
/* Private to qdev / bus. */
+ DeviceRealize realize;
+ DeviceUnrealize unrealize;
qdev_initfn init;
qdev_event unplug;
qdev_event exit;
diff --git a/hw/qdev.c b/hw/qdev.c
index bce6ad5..d7b6320 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -147,37 +147,30 @@ DeviceState *qdev_try_create(BusState *bus, const char *type)
Return 0 on success. */
int qdev_init(DeviceState *dev)
{
- DeviceClass *dc = DEVICE_GET_CLASS(dev);
- int rc;
+ Error *local_err = NULL;
assert(!dev->realized);
- rc = dc->init(dev);
- if (rc < 0) {
+ object_property_set_bool(OBJECT(dev), true, "realized", &local_err);
+ if (local_err != NULL) {
+ error_free(local_err);
object_delete(OBJECT(dev));
- return rc;
+ return -1;
}
+ return 0;
+}
- if (!OBJECT(dev)->parent) {
- static int unattached_count = 0;
- gchar *name = g_strdup_printf("device[%d]", unattached_count++);
-
- object_property_add_child(container_get(qdev_get_machine(),
- "/unattached"),
- name, OBJECT(dev), NULL);
- g_free(name);
- }
+static void device_realize(DeviceState *dev, Error **err)
+{
+ DeviceClass *dc = DEVICE_GET_CLASS(dev);
- if (qdev_get_vmsd(dev)) {
- vmstate_register_with_alias_id(dev, -1, qdev_get_vmsd(dev), dev,
- dev->instance_id_alias,
- dev->alias_required_for_version);
- }
- dev->realized = true;
- if (dev->hotplugged) {
- device_reset(dev);
+ if (dc->init) {
+ int rc = dc->init(dev);
+ if (rc < 0) {
+ error_setg(err, "Device initialization failed.");
+ return;
+ }
}
- return 0;
}
void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id,
@@ -649,6 +642,55 @@ void qdev_property_add_static(DeviceState *dev, Property *prop,
assert_no_error(local_err);
}
+static bool device_get_realized(Object *obj, Error **err)
+{
+ DeviceState *dev = DEVICE(obj);
+ return dev->realized;
+}
+
+static void device_set_realized(Object *obj, bool value, Error **err)
+{
+ DeviceState *dev = DEVICE(obj);
+ DeviceClass *dc = DEVICE_GET_CLASS(dev);
+ Error *local_err = NULL;
+
+ if (value && !dev->realized) {
+ if (dc->realize) {
+ dc->realize(dev, &local_err);
+ }
+
+ if (!obj->parent && local_err == NULL) {
+ static int unattached_count;
+ gchar *name = g_strdup_printf("device[%d]", unattached_count++);
+
+ object_property_add_child(container_get(qdev_get_machine(),
+ "/unattached"),
+ name, obj, &local_err);
+ g_free(name);
+ }
+
+ if (qdev_get_vmsd(dev) && local_err == NULL) {
+ vmstate_register_with_alias_id(dev, -1, qdev_get_vmsd(dev), dev,
+ dev->instance_id_alias,
+ dev->alias_required_for_version);
+ }
+ if (dev->hotplugged && local_err == NULL) {
+ device_reset(dev);
+ }
+ } else if (!value && dev->realized) {
+ if (dc->unrealize) {
+ dc->unrealize(dev, &local_err);
+ }
+ }
+
+ if (local_err != NULL) {
+ error_propagate(err, local_err);
+ return;
+ }
+
+ dev->realized = value;
+}
+
static void device_initfn(Object *obj)
{
DeviceState *dev = DEVICE(obj);
@@ -663,6 +705,9 @@ static void device_initfn(Object *obj)
dev->instance_id_alias = -1;
dev->realized = false;
+ object_property_add_bool(obj, "realized",
+ device_get_realized, device_set_realized, NULL);
+
class = object_get_class(OBJECT(dev));
do {
for (prop = DEVICE_CLASS(class)->props; prop && prop->name; prop++) {
@@ -714,6 +759,12 @@ static void device_class_base_init(ObjectClass *class, void *data)
klass->props = NULL;
}
+static void device_class_init(ObjectClass *oc, void *data)
+{
+ DeviceClass *dc = DEVICE_CLASS(oc);
+ dc->realize = device_realize;
+}
+
void device_reset(DeviceState *dev)
{
DeviceClass *klass = DEVICE_GET_CLASS(dev);
@@ -734,13 +785,14 @@ Object *qdev_get_machine(void)
return dev;
}
-static TypeInfo device_type_info = {
+static const TypeInfo device_type_info = {
.name = TYPE_DEVICE,
.parent = TYPE_OBJECT,
.instance_size = sizeof(DeviceState),
.instance_init = device_initfn,
.instance_finalize = device_finalize,
.class_base_init = device_class_base_init,
+ .class_init = device_class_init,
.abstract = true,
.class_size = sizeof(DeviceClass),
};
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [Qemu-devel] [RFC 05/34] isa: Split off instance_init for ISADevice
2012-11-26 0:12 [Qemu-devel] [RFC 00/34] QOM realize, device-only plus ISA conversion Andreas Färber
` (3 preceding siblings ...)
2012-11-26 0:12 ` [Qemu-devel] [RFC 04/34] qdev: Prepare "realized" property Andreas Färber
@ 2012-11-26 0:12 ` Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 06/34] applesmc: QOM'ify Andreas Färber
` (30 subsequent siblings)
35 siblings, 0 replies; 46+ messages in thread
From: Andreas Färber @ 2012-11-26 0:12 UTC (permalink / raw)
To: qemu-devel; +Cc: Andreas Färber, anthony
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
hw/isa-bus.c | 14 ++++++++++----
1 Datei geändert, 10 Zeilen hinzugefügt(+), 4 Zeilen entfernt(-)
diff --git a/hw/isa-bus.c b/hw/isa-bus.c
index 144a88e..2b1fc40 100644
--- a/hw/isa-bus.c
+++ b/hw/isa-bus.c
@@ -124,9 +124,6 @@ static int isa_qdev_init(DeviceState *qdev)
ISADevice *dev = ISA_DEVICE(qdev);
ISADeviceClass *klass = ISA_DEVICE_GET_CLASS(dev);
- dev->isairq[0] = -1;
- dev->isairq[1] = -1;
-
if (klass->init) {
return klass->init(dev);
}
@@ -134,6 +131,14 @@ static int isa_qdev_init(DeviceState *qdev)
return 0;
}
+static void isa_device_init(Object *obj)
+{
+ ISADevice *dev = ISA_DEVICE(obj);
+
+ dev->isairq[0] = -1;
+ dev->isairq[1] = -1;
+}
+
ISADevice *isa_create(ISABus *bus, const char *name)
{
DeviceState *dev;
@@ -229,10 +234,11 @@ static void isa_device_class_init(ObjectClass *klass, void *data)
k->bus_type = TYPE_ISA_BUS;
}
-static TypeInfo isa_device_type_info = {
+static const TypeInfo isa_device_type_info = {
.name = TYPE_ISA_DEVICE,
.parent = TYPE_DEVICE,
.instance_size = sizeof(ISADevice),
+ .instance_init = isa_device_init,
.abstract = true,
.class_size = sizeof(ISADeviceClass),
.class_init = isa_device_class_init,
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [Qemu-devel] [RFC 06/34] applesmc: QOM'ify
2012-11-26 0:12 [Qemu-devel] [RFC 00/34] QOM realize, device-only plus ISA conversion Andreas Färber
` (4 preceding siblings ...)
2012-11-26 0:12 ` [Qemu-devel] [RFC 05/34] isa: Split off instance_init for ISADevice Andreas Färber
@ 2012-11-26 0:12 ` Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 07/34] cirrus_vga: QOM'ify ISA Cirrus VGA Andreas Färber
` (29 subsequent siblings)
35 siblings, 0 replies; 46+ messages in thread
From: Andreas Färber @ 2012-11-26 0:12 UTC (permalink / raw)
To: qemu-devel; +Cc: Andreas Färber, anthony
Add a typedef for the state struct and rename from Status to State.
Add type constant and cast macro to obsolete DO_UPCAST().
Prepares for ISA realizefn.
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
hw/applesmc.c | 35 ++++++++++++++++++++---------------
1 Datei geändert, 20 Zeilen hinzugefügt(+), 15 Zeilen entfernt(-)
diff --git a/hw/applesmc.c b/hw/applesmc.c
index 8bedaad..d6e556b 100644
--- a/hw/applesmc.c
+++ b/hw/applesmc.c
@@ -66,8 +66,13 @@ struct AppleSMCData {
QLIST_ENTRY(AppleSMCData) node;
};
-struct AppleSMCStatus {
- ISADevice dev;
+#define TYPE_APPLE_SMC "isa-applesmc"
+#define APPLE_SMC(obj) OBJECT_CHECK(AppleSMCState, (obj), TYPE_APPLE_SMC)
+
+typedef struct AppleSMCState AppleSMCState;
+struct AppleSMCState {
+ ISADevice parent_obj;
+
uint32_t iobase;
uint8_t cmd;
uint8_t status;
@@ -83,7 +88,7 @@ struct AppleSMCStatus {
static void applesmc_io_cmd_writeb(void *opaque, uint32_t addr, uint32_t val)
{
- struct AppleSMCStatus *s = opaque;
+ AppleSMCState *s = opaque;
smc_debug("CMD Write B: %#x = %#x\n", addr, val);
switch(val) {
@@ -96,7 +101,7 @@ static void applesmc_io_cmd_writeb(void *opaque, uint32_t addr, uint32_t val)
s->data_pos = 0;
}
-static void applesmc_fill_data(struct AppleSMCStatus *s)
+static void applesmc_fill_data(AppleSMCState *s)
{
struct AppleSMCData *d;
@@ -112,7 +117,7 @@ static void applesmc_fill_data(struct AppleSMCStatus *s)
static void applesmc_io_data_writeb(void *opaque, uint32_t addr, uint32_t val)
{
- struct AppleSMCStatus *s = opaque;
+ AppleSMCState *s = opaque;
smc_debug("DATA Write B: %#x = %#x\n", addr, val);
switch(s->cmd) {
@@ -135,7 +140,7 @@ static void applesmc_io_data_writeb(void *opaque, uint32_t addr, uint32_t val)
static uint32_t applesmc_io_data_readb(void *opaque, uint32_t addr1)
{
- struct AppleSMCStatus *s = opaque;
+ AppleSMCState *s = opaque;
uint8_t retval = 0;
switch(s->cmd) {
@@ -159,13 +164,13 @@ static uint32_t applesmc_io_data_readb(void *opaque, uint32_t addr1)
static uint32_t applesmc_io_cmd_readb(void *opaque, uint32_t addr1)
{
- struct AppleSMCStatus *s = opaque;
+ AppleSMCState *s = opaque;
smc_debug("CMD Read B: %#x\n", addr1);
return s->status;
}
-static void applesmc_add_key(struct AppleSMCStatus *s, const char *key,
+static void applesmc_add_key(AppleSMCState *s, const char *key,
int len, const char *data)
{
struct AppleSMCData *def;
@@ -180,7 +185,7 @@ static void applesmc_add_key(struct AppleSMCStatus *s, const char *key,
static void qdev_applesmc_isa_reset(DeviceState *dev)
{
- struct AppleSMCStatus *s = DO_UPCAST(struct AppleSMCStatus, dev.qdev, dev);
+ AppleSMCState *s = APPLE_SMC(dev);
struct AppleSMCData *d, *next;
/* Remove existing entries */
@@ -198,7 +203,7 @@ static void qdev_applesmc_isa_reset(DeviceState *dev)
static int applesmc_isa_init(ISADevice *dev)
{
- struct AppleSMCStatus *s = DO_UPCAST(struct AppleSMCStatus, dev, dev);
+ AppleSMCState *s = APPLE_SMC(dev);
register_ioport_read(s->iobase + APPLESMC_DATA_PORT, 4, 1,
applesmc_io_data_readb, s);
@@ -221,9 +226,9 @@ static int applesmc_isa_init(ISADevice *dev)
}
static Property applesmc_isa_properties[] = {
- DEFINE_PROP_HEX32("iobase", struct AppleSMCStatus, iobase,
+ DEFINE_PROP_HEX32("iobase", AppleSMCState, iobase,
APPLESMC_DEFAULT_IOBASE),
- DEFINE_PROP_STRING("osk", struct AppleSMCStatus, osk),
+ DEFINE_PROP_STRING("osk", AppleSMCState, osk),
DEFINE_PROP_END_OF_LIST(),
};
@@ -236,10 +241,10 @@ static void qdev_applesmc_class_init(ObjectClass *klass, void *data)
dc->props = applesmc_isa_properties;
}
-static TypeInfo applesmc_isa_info = {
- .name = "isa-applesmc",
+static const TypeInfo applesmc_isa_info = {
+ .name = TYPE_APPLE_SMC,
.parent = TYPE_ISA_DEVICE,
- .instance_size = sizeof(struct AppleSMCStatus),
+ .instance_size = sizeof(AppleSMCState),
.class_init = qdev_applesmc_class_init,
};
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [Qemu-devel] [RFC 07/34] cirrus_vga: QOM'ify ISA Cirrus VGA
2012-11-26 0:12 [Qemu-devel] [RFC 00/34] QOM realize, device-only plus ISA conversion Andreas Färber
` (5 preceding siblings ...)
2012-11-26 0:12 ` [Qemu-devel] [RFC 06/34] applesmc: QOM'ify Andreas Färber
@ 2012-11-26 0:12 ` Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 08/34] debugcon: QOM'ify ISA debug console Andreas Färber
` (28 subsequent siblings)
35 siblings, 0 replies; 46+ messages in thread
From: Andreas Färber @ 2012-11-26 0:12 UTC (permalink / raw)
To: qemu-devel; +Cc: Andreas Färber, anthony
Introduce type constant and cast macro to obsolete DO_UPCAST().
Prepares for ISA realizefn.
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
hw/cirrus_vga.c | 17 +++++++++++------
1 Datei geändert, 11 Zeilen hinzugefügt(+), 6 Zeilen entfernt(-)
diff --git a/hw/cirrus_vga.c b/hw/cirrus_vga.c
index 40efa8a..9687b6b 100644
--- a/hw/cirrus_vga.c
+++ b/hw/cirrus_vga.c
@@ -250,8 +250,13 @@ typedef struct PCICirrusVGAState {
CirrusVGAState cirrus_vga;
} PCICirrusVGAState;
+#define TYPE_ISA_CIRRUS_VGA "isa-cirrus-vga"
+#define ISA_CIRRUS_VGA(obj) \
+ OBJECT_CHECK(ISACirrusVGAState, (obj), TYPE_ISA_CIRRUS_VGA)
+
typedef struct ISACirrusVGAState {
- ISADevice dev;
+ ISADevice parent_obj;
+
CirrusVGAState cirrus_vga;
} ISACirrusVGAState;
@@ -2902,7 +2907,7 @@ static void cirrus_init_common(CirrusVGAState * s, int device_id, int is_pci,
static int vga_initfn(ISADevice *dev)
{
- ISACirrusVGAState *d = DO_UPCAST(ISACirrusVGAState, dev, dev);
+ ISACirrusVGAState *d = ISA_CIRRUS_VGA(dev);
VGACommonState *s = &d->cirrus_vga.vga;
vga_common_init(s);
@@ -2917,7 +2922,7 @@ static int vga_initfn(ISADevice *dev)
return 0;
}
-static Property isa_vga_cirrus_properties[] = {
+static Property isa_cirrus_vga_properties[] = {
DEFINE_PROP_UINT32("vgamem_mb", struct ISACirrusVGAState,
cirrus_vga.vga.vram_size_mb, 8),
DEFINE_PROP_END_OF_LIST(),
@@ -2930,11 +2935,11 @@ static void isa_cirrus_vga_class_init(ObjectClass *klass, void *data)
dc->vmsd = &vmstate_cirrus_vga;
k->init = vga_initfn;
- dc->props = isa_vga_cirrus_properties;
+ dc->props = isa_cirrus_vga_properties;
}
-static TypeInfo isa_cirrus_vga_info = {
- .name = "isa-cirrus-vga",
+static const TypeInfo isa_cirrus_vga_info = {
+ .name = TYPE_ISA_CIRRUS_VGA,
.parent = TYPE_ISA_DEVICE,
.instance_size = sizeof(ISACirrusVGAState),
.class_init = isa_cirrus_vga_class_init,
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [Qemu-devel] [RFC 08/34] debugcon: QOM'ify ISA debug console
2012-11-26 0:12 [Qemu-devel] [RFC 00/34] QOM realize, device-only plus ISA conversion Andreas Färber
` (6 preceding siblings ...)
2012-11-26 0:12 ` [Qemu-devel] [RFC 07/34] cirrus_vga: QOM'ify ISA Cirrus VGA Andreas Färber
@ 2012-11-26 0:12 ` Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 09/34] fdc: QOM'ify ISA floppy controller Andreas Färber
` (27 subsequent siblings)
35 siblings, 0 replies; 46+ messages in thread
From: Andreas Färber @ 2012-11-26 0:12 UTC (permalink / raw)
To: qemu-devel; +Cc: Andreas Färber, anthony
Introduce type constant and cast macro to obsolete DO_UPCAST().
Prepares for ISA realizefn.
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
hw/debugcon.c | 13 +++++++++----
1 Datei geändert, 9 Zeilen hinzugefügt(+), 4 Zeilen entfernt(-)
diff --git a/hw/debugcon.c b/hw/debugcon.c
index 14ab326..02846ed 100644
--- a/hw/debugcon.c
+++ b/hw/debugcon.c
@@ -36,8 +36,13 @@ typedef struct DebugconState {
uint32_t readback;
} DebugconState;
+#define TYPE_ISA_DEBUG_CONSOLE "isa-debugcon"
+#define ISA_DEBUG_CONSOLE(obj) \
+ OBJECT_CHECK(ISADebugconState, (obj), TYPE_ISA_DEBUG_CONSOLE)
+
typedef struct ISADebugconState {
- ISADevice dev;
+ ISADevice parent_obj;
+
uint32_t iobase;
DebugconState state;
} ISADebugconState;
@@ -78,7 +83,7 @@ static void debugcon_init_core(DebugconState *s)
static int debugcon_isa_initfn(ISADevice *dev)
{
- ISADebugconState *isa = DO_UPCAST(ISADebugconState, dev, dev);
+ ISADebugconState *isa = ISA_DEBUG_CONSOLE(dev);
DebugconState *s = &isa->state;
debugcon_init_core(s);
@@ -102,8 +107,8 @@ static void debugcon_isa_class_initfn(ObjectClass *klass, void *data)
dc->props = debugcon_isa_properties;
}
-static TypeInfo debugcon_isa_info = {
- .name = "isa-debugcon",
+static const TypeInfo debugcon_isa_info = {
+ .name = TYPE_ISA_DEBUG_CONSOLE,
.parent = TYPE_ISA_DEVICE,
.instance_size = sizeof(ISADebugconState),
.class_init = debugcon_isa_class_initfn,
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [Qemu-devel] [RFC 09/34] fdc: QOM'ify ISA floppy controller
2012-11-26 0:12 [Qemu-devel] [RFC 00/34] QOM realize, device-only plus ISA conversion Andreas Färber
` (7 preceding siblings ...)
2012-11-26 0:12 ` [Qemu-devel] [RFC 08/34] debugcon: QOM'ify ISA debug console Andreas Färber
@ 2012-11-26 0:12 ` Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 10/34] i82374: QOM'ify Andreas Färber
` (26 subsequent siblings)
35 siblings, 0 replies; 46+ messages in thread
From: Andreas Färber @ 2012-11-26 0:12 UTC (permalink / raw)
To: qemu-devel
Cc: Anthony Liguori, Andreas Färber, anthony, Markus Armbruster
Introduce type constant and cast macro to obsolete DO_UPCAST().
Reuse type constant for PC machine compatibility settings.
Prepares for ISA realizefn.
Signed-off-by: Andreas Färber <afaerber@suse.de>
Cc: Markus Armbruster <armbru@redhat.com>
---
hw/fdc.c | 23 +++++++++++++----------
hw/fdc.h | 2 ++
hw/pc_piix.c | 2 +-
3 Dateien geändert, 16 Zeilen hinzugefügt(+), 11 Zeilen entfernt(-)
diff --git a/hw/fdc.c b/hw/fdc.c
index 29b5449..edd7483 100644
--- a/hw/fdc.c
+++ b/hw/fdc.c
@@ -550,8 +550,11 @@ typedef struct FDCtrlSysBus {
struct FDCtrl state;
} FDCtrlSysBus;
+#define ISA_FDC(obj) OBJECT_CHECK(FDCtrlISABus, (obj), TYPE_ISA_FDC)
+
typedef struct FDCtrlISABus {
- ISADevice busdev;
+ ISADevice parent_obj;
+
uint32_t iobase;
uint32_t irq;
uint32_t dma;
@@ -779,7 +782,7 @@ static void fdctrl_external_reset_sysbus(DeviceState *d)
static void fdctrl_external_reset_isa(DeviceState *d)
{
- FDCtrlISABus *isa = container_of(d, FDCtrlISABus, busdev.qdev);
+ FDCtrlISABus *isa = ISA_FDC(d);
FDCtrl *s = &isa->state;
fdctrl_reset(s, 0);
@@ -2022,7 +2025,7 @@ ISADevice *fdctrl_init_isa(ISABus *bus, DriveInfo **fds)
{
ISADevice *dev;
- dev = isa_try_create(bus, "isa-fdc");
+ dev = isa_try_create(bus, TYPE_ISA_FDC);
if (!dev) {
return NULL;
}
@@ -2117,13 +2120,13 @@ static const MemoryRegionPortio fdc_portio_list[] = {
static int isabus_fdc_init1(ISADevice *dev)
{
- FDCtrlISABus *isa = DO_UPCAST(FDCtrlISABus, busdev, dev);
+ FDCtrlISABus *isa = ISA_FDC(dev);
FDCtrl *fdctrl = &isa->state;
int ret;
isa_register_portio_list(dev, isa->iobase, fdc_portio_list, fdctrl, "fdc");
- isa_init_irq(&isa->busdev, &fdctrl->irq, isa->irq);
+ isa_init_irq(dev, &fdctrl->irq, isa->irq);
fdctrl->dma_chann = isa->dma;
qdev_set_legacy_instance_id(&dev->qdev, isa->iobase, 2);
@@ -2170,7 +2173,7 @@ static int sun4m_fdc_init1(SysBusDevice *dev)
FDriveType isa_fdc_get_drive_type(ISADevice *fdc, int i)
{
- FDCtrlISABus *isa = DO_UPCAST(FDCtrlISABus, busdev, fdc);
+ FDCtrlISABus *isa = ISA_FDC(fdc);
return isa->state.drives[i].drive;
}
@@ -2198,7 +2201,7 @@ static Property isa_fdc_properties[] = {
DEFINE_PROP_END_OF_LIST(),
};
-static void isabus_fdc_class_init1(ObjectClass *klass, void *data)
+static void isabus_fdc_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
@@ -2210,11 +2213,11 @@ static void isabus_fdc_class_init1(ObjectClass *klass, void *data)
dc->props = isa_fdc_properties;
}
-static TypeInfo isa_fdc_info = {
- .name = "isa-fdc",
+static const TypeInfo isa_fdc_info = {
+ .name = TYPE_ISA_FDC,
.parent = TYPE_ISA_DEVICE,
.instance_size = sizeof(FDCtrlISABus),
- .class_init = isabus_fdc_class_init1,
+ .class_init = isabus_fdc_class_init,
};
static const VMStateDescription vmstate_sysbus_fdc ={
diff --git a/hw/fdc.h b/hw/fdc.h
index a8f6f7c..d48b2f8 100644
--- a/hw/fdc.h
+++ b/hw/fdc.h
@@ -13,6 +13,8 @@ typedef enum FDriveType {
FDRIVE_DRV_NONE = 0x03, /* No drive connected */
} FDriveType;
+#define TYPE_ISA_FDC "isa-fdc"
+
ISADevice *fdctrl_init_isa(ISABus *bus, DriveInfo **fds);
void fdctrl_init_sysbus(qemu_irq irq, int dma_chann,
hwaddr mmio_base, DriveInfo **fds);
diff --git a/hw/pc_piix.c b/hw/pc_piix.c
index cfa839c..7791e4a 100644
--- a/hw/pc_piix.c
+++ b/hw/pc_piix.c
@@ -449,7 +449,7 @@ static QEMUMachine pc_machine_v1_1 = {
.property = "rom_only",\
.value = stringify(1),\
}, {\
- .driver = "isa-fdc",\
+ .driver = TYPE_ISA_FDC,\
.property = "check_media_rate",\
.value = "off",\
}, {\
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [Qemu-devel] [RFC 10/34] i82374: QOM'ify
2012-11-26 0:12 [Qemu-devel] [RFC 00/34] QOM realize, device-only plus ISA conversion Andreas Färber
` (8 preceding siblings ...)
2012-11-26 0:12 ` [Qemu-devel] [RFC 09/34] fdc: QOM'ify ISA floppy controller Andreas Färber
@ 2012-11-26 0:12 ` Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [PATCH 11/34] i8259: Fix PIC_COMMON() macro Andreas Färber
` (25 subsequent siblings)
35 siblings, 0 replies; 46+ messages in thread
From: Andreas Färber @ 2012-11-26 0:12 UTC (permalink / raw)
To: qemu-devel; +Cc: Andreas Färber, anthony
Introduce type constant and cast macro to obsolete DO_UPCAST().
Prepares for ISA realizefn.
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
hw/i82374.c | 12 ++++++++----
1 Datei geändert, 8 Zeilen hinzugefügt(+), 4 Zeilen entfernt(-)
diff --git a/hw/i82374.c b/hw/i82374.c
index 4a922c3..82de0b0 100644
--- a/hw/i82374.c
+++ b/hw/i82374.c
@@ -104,8 +104,12 @@ static void i82374_init(I82374State *s)
memset(s->commands, 0, sizeof(s->commands));
}
+#define TYPE_I82374 "i82374"
+#define I82374(obj) OBJECT_CHECK(ISAi82374State, (obj), TYPE_I82374)
+
typedef struct ISAi82374State {
- ISADevice dev;
+ ISADevice parent_obj;
+
uint32_t iobase;
I82374State state;
} ISAi82374State;
@@ -122,7 +126,7 @@ static const VMStateDescription vmstate_isa_i82374 = {
static int i82374_isa_init(ISADevice *dev)
{
- ISAi82374State *isa = DO_UPCAST(ISAi82374State, dev, dev);
+ ISAi82374State *isa = I82374(dev);
I82374State *s = &isa->state;
register_ioport_read(isa->iobase + 0x0A, 1, 1, i82374_read_isr, s);
@@ -153,8 +157,8 @@ static void i82374_class_init(ObjectClass *klass, void *data)
dc->props = i82374_properties;
}
-static TypeInfo i82374_isa_info = {
- .name = "i82374",
+static const TypeInfo i82374_isa_info = {
+ .name = TYPE_I82374,
.parent = TYPE_ISA_DEVICE,
.instance_size = sizeof(ISAi82374State),
.class_init = i82374_class_init,
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [Qemu-devel] [PATCH 11/34] i8259: Fix PIC_COMMON() macro
2012-11-26 0:12 [Qemu-devel] [RFC 00/34] QOM realize, device-only plus ISA conversion Andreas Färber
` (9 preceding siblings ...)
2012-11-26 0:12 ` [Qemu-devel] [RFC 10/34] i82374: QOM'ify Andreas Färber
@ 2012-11-26 0:12 ` Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 12/34] i8259: QOM cleanups Andreas Färber
` (24 subsequent siblings)
35 siblings, 0 replies; 46+ messages in thread
From: Andreas Färber @ 2012-11-26 0:12 UTC (permalink / raw)
To: qemu-devel; +Cc: Andreas Färber, anthony
It used a wrong struct type name since its introduction in
8f04ee0882aec9fe91fb70f767edf5dacff59835 (isa: pic: convert to QEMU
Object Model), apparently it is unused so far.
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
hw/i8259_internal.h | 2 +-
1 Datei geändert, 1 Zeile hinzugefügt(+), 1 Zeile entfernt(-)
diff --git a/hw/i8259_internal.h b/hw/i8259_internal.h
index 4137b61..8785b1d 100644
--- a/hw/i8259_internal.h
+++ b/hw/i8259_internal.h
@@ -33,7 +33,7 @@ typedef struct PICCommonState PICCommonState;
#define TYPE_PIC_COMMON "pic-common"
#define PIC_COMMON(obj) \
- OBJECT_CHECK(PICCommon, (obj), TYPE_PIC_COMMON)
+ OBJECT_CHECK(PICCommonState, (obj), TYPE_PIC_COMMON)
#define PIC_COMMON_CLASS(klass) \
OBJECT_CLASS_CHECK(PICCommonClass, (klass), TYPE_PIC_COMMON)
#define PIC_COMMON_GET_CLASS(obj) \
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [Qemu-devel] [RFC 12/34] i8259: QOM cleanups
2012-11-26 0:12 [Qemu-devel] [RFC 00/34] QOM realize, device-only plus ISA conversion Andreas Färber
` (10 preceding siblings ...)
2012-11-26 0:12 ` [Qemu-devel] [PATCH 11/34] i8259: Fix PIC_COMMON() macro Andreas Färber
@ 2012-11-26 0:12 ` Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 13/34] ide: QOM'ify ISA IDE Andreas Färber
` (23 subsequent siblings)
35 siblings, 0 replies; 46+ messages in thread
From: Andreas Färber @ 2012-11-26 0:12 UTC (permalink / raw)
To: qemu-devel; +Cc: Andreas Färber, anthony
Eliminate DO_UPCAST() for PICCommonState. Prepares for ISA realizefn.
Also give the i8259_common type registration functions unique names
while at it.
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
hw/i8259.c | 18 ++++++++++--------
hw/i8259_common.c | 10 +++++-----
hw/i8259_internal.h | 3 ++-
hw/kvm/i8259.c | 4 ++--
4 Dateien geändert, 19 Zeilen hinzugefügt(+), 16 Zeilen entfernt(-)
diff --git a/hw/i8259.c b/hw/i8259.c
index af0ba4d..55c2cb9 100644
--- a/hw/i8259.c
+++ b/hw/i8259.c
@@ -182,7 +182,7 @@ static void pic_intack(PICCommonState *s, int irq)
int pic_read_irq(DeviceState *d)
{
- PICCommonState *s = DO_UPCAST(PICCommonState, dev.qdev, d);
+ PICCommonState *s = PIC_COMMON(d);
int irq, irq2, intno;
irq = pic_get_irq(s);
@@ -229,7 +229,7 @@ static void pic_init_reset(PICCommonState *s)
static void pic_reset(DeviceState *dev)
{
- PICCommonState *s = DO_UPCAST(PICCommonState, dev.qdev, dev);
+ PICCommonState *s = PIC_COMMON(dev);
s->elcr = 0;
pic_init_reset(s);
@@ -361,7 +361,7 @@ static uint64_t pic_ioport_read(void *opaque, hwaddr addr,
int pic_get_output(DeviceState *d)
{
- PICCommonState *s = DO_UPCAST(PICCommonState, dev.qdev, d);
+ PICCommonState *s = PIC_COMMON(d);
return (pic_get_irq(s) >= 0);
}
@@ -400,11 +400,13 @@ static const MemoryRegionOps pic_elcr_ioport_ops = {
static void pic_init(PICCommonState *s)
{
+ DeviceState *dev = DEVICE(s);
+
memory_region_init_io(&s->base_io, &pic_base_ioport_ops, s, "pic", 2);
memory_region_init_io(&s->elcr_io, &pic_elcr_ioport_ops, s, "elcr", 1);
- qdev_init_gpio_out(&s->dev.qdev, s->int_out, ARRAY_SIZE(s->int_out));
- qdev_init_gpio_in(&s->dev.qdev, pic_set_irq, 8);
+ qdev_init_gpio_out(dev, s->int_out, ARRAY_SIZE(s->int_out));
+ qdev_init_gpio_in(dev, pic_set_irq, 8);
}
void pic_info(Monitor *mon)
@@ -416,7 +418,7 @@ void pic_info(Monitor *mon)
return;
}
for (i = 0; i < 2; i++) {
- s = i == 0 ? DO_UPCAST(PICCommonState, dev.qdev, isa_pic) : slave_pic;
+ s = i == 0 ? PIC_COMMON(isa_pic) : slave_pic;
monitor_printf(mon, "pic%d: irr=%02x imr=%02x isr=%02x hprio=%d "
"irq_base=%02x rr_sel=%d elcr=%02x fnm=%d\n",
i, s->irr, s->imr, s->isr, s->priority_add,
@@ -467,7 +469,7 @@ qemu_irq *i8259_init(ISABus *bus, qemu_irq parent_irq)
irq_set[i + 8] = qdev_get_gpio_in(&dev->qdev, i);
}
- slave_pic = DO_UPCAST(PICCommonState, dev, dev);
+ slave_pic = PIC_COMMON(dev);
return irq_set;
}
@@ -481,7 +483,7 @@ static void i8259_class_init(ObjectClass *klass, void *data)
dc->reset = pic_reset;
}
-static TypeInfo i8259_info = {
+static const TypeInfo i8259_info = {
.name = "isa-i8259",
.instance_size = sizeof(PICCommonState),
.parent = TYPE_PIC_COMMON,
diff --git a/hw/i8259_common.c b/hw/i8259_common.c
index ab3d98b..418c485 100644
--- a/hw/i8259_common.c
+++ b/hw/i8259_common.c
@@ -68,7 +68,7 @@ static int pic_dispatch_post_load(void *opaque, int version_id)
static int pic_init_common(ISADevice *dev)
{
- PICCommonState *s = DO_UPCAST(PICCommonState, dev, dev);
+ PICCommonState *s = PIC_COMMON(dev);
PICCommonClass *info = PIC_COMMON_GET_CLASS(s);
info->init(s);
@@ -78,7 +78,7 @@ static int pic_init_common(ISADevice *dev)
isa_register_ioport(NULL, &s->elcr_io, s->elcr_addr);
}
- qdev_set_legacy_instance_id(&s->dev.qdev, s->iobase, 1);
+ qdev_set_legacy_instance_id(DEVICE(dev), s->iobase, 1);
return 0;
}
@@ -144,7 +144,7 @@ static void pic_common_class_init(ObjectClass *klass, void *data)
ic->init = pic_init_common;
}
-static TypeInfo pic_common_type = {
+static const TypeInfo pic_common_type = {
.name = TYPE_PIC_COMMON,
.parent = TYPE_ISA_DEVICE,
.instance_size = sizeof(PICCommonState),
@@ -153,9 +153,9 @@ static TypeInfo pic_common_type = {
.abstract = true,
};
-static void register_types(void)
+static void pic_common_register_types(void)
{
type_register_static(&pic_common_type);
}
-type_init(register_types);
+type_init(pic_common_register_types);
diff --git a/hw/i8259_internal.h b/hw/i8259_internal.h
index 8785b1d..32e48c3 100644
--- a/hw/i8259_internal.h
+++ b/hw/i8259_internal.h
@@ -48,7 +48,8 @@ typedef struct PICCommonClass
} PICCommonClass;
struct PICCommonState {
- ISADevice dev;
+ ISADevice parent_obj;
+
uint8_t last_irr; /* edge detection */
uint8_t irr; /* interrupt request register */
uint8_t imr; /* interrupt mask register */
diff --git a/hw/kvm/i8259.c b/hw/kvm/i8259.c
index 1e24cd4..2aaf14a 100644
--- a/hw/kvm/i8259.c
+++ b/hw/kvm/i8259.c
@@ -82,7 +82,7 @@ static void kvm_pic_put(PICCommonState *s)
static void kvm_pic_reset(DeviceState *dev)
{
- PICCommonState *s = DO_UPCAST(PICCommonState, dev.qdev, dev);
+ PICCommonState *s = PIC_COMMON(dev);
s->elcr = 0;
pic_reset_common(s);
@@ -123,7 +123,7 @@ static void kvm_i8259_class_init(ObjectClass *klass, void *data)
k->post_load = kvm_pic_put;
}
-static TypeInfo kvm_i8259_info = {
+static const TypeInfo kvm_i8259_info = {
.name = "kvm-i8259",
.parent = TYPE_PIC_COMMON,
.instance_size = sizeof(PICCommonState),
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [Qemu-devel] [RFC 13/34] ide: QOM'ify ISA IDE
2012-11-26 0:12 [Qemu-devel] [RFC 00/34] QOM realize, device-only plus ISA conversion Andreas Färber
` (11 preceding siblings ...)
2012-11-26 0:12 ` [Qemu-devel] [RFC 12/34] i8259: QOM cleanups Andreas Färber
@ 2012-11-26 0:12 ` Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 14/34] m48t59: QOM'ify ISA M48T59 NVRAM Andreas Färber
` (22 subsequent siblings)
35 siblings, 0 replies; 46+ messages in thread
From: Andreas Färber @ 2012-11-26 0:12 UTC (permalink / raw)
To: qemu-devel; +Cc: Kevin Wolf, Andreas Färber, anthony
Introduce type constant and cast macro to obsolete DO_UPCAST().
Add missing braces.
Prepares for ISA realizefn.
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
hw/ide/isa.c | 41 +++++++++++++++++++++++++----------------
1 Datei geändert, 25 Zeilen hinzugefügt(+), 16 Zeilen entfernt(-)
diff --git a/hw/ide/isa.c b/hw/ide/isa.c
index 8ab2718..4d55885 100644
--- a/hw/ide/isa.c
+++ b/hw/ide/isa.c
@@ -33,8 +33,12 @@
/***********************************************************/
/* ISA IDE definitions */
+#define TYPE_ISA_IDE "isa-ide"
+#define ISA_IDE(obj) OBJECT_CHECK(ISAIDEState, (obj), TYPE_ISA_IDE)
+
typedef struct ISAIDEState {
- ISADevice dev;
+ ISADevice parent_obj;
+
IDEBus bus;
uint32_t iobase;
uint32_t iobase2;
@@ -44,7 +48,7 @@ typedef struct ISAIDEState {
static void isa_ide_reset(DeviceState *d)
{
- ISAIDEState *s = container_of(d, ISAIDEState, dev.qdev);
+ ISAIDEState *s = ISA_IDE(d);
ide_bus_reset(&s->bus);
}
@@ -63,9 +67,9 @@ static const VMStateDescription vmstate_ide_isa = {
static int isa_ide_initfn(ISADevice *dev)
{
- ISAIDEState *s = DO_UPCAST(ISAIDEState, dev, dev);
+ ISAIDEState *s = ISA_IDE(dev);
- ide_bus_new(&s->bus, &s->dev.qdev, 0);
+ ide_bus_new(&s->bus, DEVICE(dev), 0);
ide_init_ioport(&s->bus, dev, s->iobase, s->iobase2);
isa_init_irq(dev, &s->irq, s->isairq);
ide_init2(&s->bus, s->irq);
@@ -76,22 +80,27 @@ static int isa_ide_initfn(ISADevice *dev)
ISADevice *isa_ide_init(ISABus *bus, int iobase, int iobase2, int isairq,
DriveInfo *hd0, DriveInfo *hd1)
{
- ISADevice *dev;
+ DeviceState *dev;
+ ISADevice *isadev;
ISAIDEState *s;
- dev = isa_create(bus, "isa-ide");
- qdev_prop_set_uint32(&dev->qdev, "iobase", iobase);
- qdev_prop_set_uint32(&dev->qdev, "iobase2", iobase2);
- qdev_prop_set_uint32(&dev->qdev, "irq", isairq);
- if (qdev_init(&dev->qdev) < 0)
+ isadev = isa_create(bus, TYPE_ISA_IDE);
+ dev = DEVICE(isadev);
+ qdev_prop_set_uint32(dev, "iobase", iobase);
+ qdev_prop_set_uint32(dev, "iobase2", iobase2);
+ qdev_prop_set_uint32(dev, "irq", isairq);
+ if (qdev_init(dev) < 0) {
return NULL;
+ }
- s = DO_UPCAST(ISAIDEState, dev, dev);
- if (hd0)
+ s = ISA_IDE(dev);
+ if (hd0) {
ide_create_drive(&s->bus, 0, hd0);
- if (hd1)
+ }
+ if (hd1) {
ide_create_drive(&s->bus, 1, hd1);
- return dev;
+ }
+ return isadev;
}
static Property isa_ide_properties[] = {
@@ -111,8 +120,8 @@ static void isa_ide_class_initfn(ObjectClass *klass, void *data)
dc->props = isa_ide_properties;
}
-static TypeInfo isa_ide_info = {
- .name = "isa-ide",
+static const TypeInfo isa_ide_info = {
+ .name = TYPE_ISA_IDE,
.parent = TYPE_ISA_DEVICE,
.instance_size = sizeof(ISAIDEState),
.class_init = isa_ide_class_initfn,
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [Qemu-devel] [RFC 14/34] m48t59: QOM'ify ISA M48T59 NVRAM
2012-11-26 0:12 [Qemu-devel] [RFC 00/34] QOM realize, device-only plus ISA conversion Andreas Färber
` (12 preceding siblings ...)
2012-11-26 0:12 ` [Qemu-devel] [RFC 13/34] ide: QOM'ify ISA IDE Andreas Färber
@ 2012-11-26 0:12 ` Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 15/34] mc146818rtc: QOM'ify Andreas Färber
` (21 subsequent siblings)
35 siblings, 0 replies; 46+ messages in thread
From: Andreas Färber @ 2012-11-26 0:12 UTC (permalink / raw)
To: qemu-devel; +Cc: Andreas Färber, anthony
Introduce type constant and cast macro to obsolete DO_UPCAST() and
container_of().
Prepares for ISA realizefn.
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
hw/m48t59.c | 37 ++++++++++++++++++++++---------------
1 Datei geändert, 22 Zeilen hinzugefügt(+), 15 Zeilen entfernt(-)
diff --git a/hw/m48t59.c b/hw/m48t59.c
index 7da7e7c..6d2f9cf 100644
--- a/hw/m48t59.c
+++ b/hw/m48t59.c
@@ -72,8 +72,13 @@ struct M48t59State {
uint8_t lock;
};
+#define TYPE_ISA_M48T59 "m48t59_isa"
+#define M48T59_ISA(obj) \
+ OBJECT_CHECK(M48t59ISAState, (obj), TYPE_ISA_M48T59)
+
typedef struct M48t59ISAState {
- ISADevice busdev;
+ ISADevice parent_obj;
+
M48t59State state;
MemoryRegion io;
} M48t59ISAState;
@@ -608,7 +613,7 @@ static void m48t59_reset_common(M48t59State *NVRAM)
static void m48t59_reset_isa(DeviceState *d)
{
- M48t59ISAState *isa = container_of(d, M48t59ISAState, busdev.qdev);
+ M48t59ISAState *isa = M48T59_ISA(d);
M48t59State *NVRAM = &isa->state;
m48t59_reset_common(NVRAM);
@@ -665,20 +670,22 @@ M48t59State *m48t59_init_isa(ISABus *bus, uint32_t io_base, uint16_t size,
int model)
{
M48t59ISAState *d;
- ISADevice *dev;
+ ISADevice *isadev;
+ DeviceState *dev;
M48t59State *s;
- dev = isa_create(bus, "m48t59_isa");
- qdev_prop_set_uint32(&dev->qdev, "model", model);
- qdev_prop_set_uint32(&dev->qdev, "size", size);
- qdev_prop_set_uint32(&dev->qdev, "io_base", io_base);
- qdev_init_nofail(&dev->qdev);
- d = DO_UPCAST(M48t59ISAState, busdev, dev);
+ isadev = isa_create(bus, TYPE_ISA_M48T59);
+ dev = DEVICE(isadev);
+ qdev_prop_set_uint32(dev, "model", model);
+ qdev_prop_set_uint32(dev, "size", size);
+ qdev_prop_set_uint32(dev, "io_base", io_base);
+ qdev_init_nofail(dev);
+ d = M48T59_ISA(isadev);
s = &d->state;
memory_region_init_io(&d->io, &m48t59_io_ops, s, "m48t59", 4);
if (io_base != 0) {
- isa_register_ioport(dev, &d->io, io_base);
+ isa_register_ioport(isadev, &d->io, io_base);
}
return s;
@@ -698,7 +705,7 @@ static void m48t59_init_common(M48t59State *s)
static int m48t59_init_isa1(ISADevice *dev)
{
- M48t59ISAState *d = DO_UPCAST(M48t59ISAState, busdev, dev);
+ M48t59ISAState *d = M48T59_ISA(dev);
M48t59State *s = &d->state;
isa_init_irq(dev, &s->IRQ, 8);
@@ -728,7 +735,7 @@ static Property m48t59_isa_properties[] = {
DEFINE_PROP_END_OF_LIST(),
};
-static void m48t59_init_class_isa1(ObjectClass *klass, void *data)
+static void m48t59_isa_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
@@ -738,11 +745,11 @@ static void m48t59_init_class_isa1(ObjectClass *klass, void *data)
dc->props = m48t59_isa_properties;
}
-static TypeInfo m48t59_isa_info = {
- .name = "m48t59_isa",
+static const TypeInfo m48t59_isa_info = {
+ .name = TYPE_ISA_M48T59,
.parent = TYPE_ISA_DEVICE,
.instance_size = sizeof(M48t59ISAState),
- .class_init = m48t59_init_class_isa1,
+ .class_init = m48t59_isa_class_init,
};
static Property m48t59_properties[] = {
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [Qemu-devel] [RFC 15/34] mc146818rtc: QOM'ify
2012-11-26 0:12 [Qemu-devel] [RFC 00/34] QOM realize, device-only plus ISA conversion Andreas Färber
` (13 preceding siblings ...)
2012-11-26 0:12 ` [Qemu-devel] [RFC 14/34] m48t59: QOM'ify ISA M48T59 NVRAM Andreas Färber
@ 2012-11-26 0:12 ` Andreas Färber
2013-04-22 15:42 ` Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 16/34] ne2000-isa: QOM'ify Andreas Färber
` (20 subsequent siblings)
35 siblings, 1 reply; 46+ messages in thread
From: Andreas Färber @ 2012-11-26 0:12 UTC (permalink / raw)
To: qemu-devel; +Cc: Andreas Färber, anthony
Introduce type constant and cast macro to obsolete DO_UPCAST().
Prepares for ISA realizefn.
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
hw/mc146818rtc.c | 38 +++++++++++++++++++++-----------------
hw/mc146818rtc.h | 2 ++
2 Dateien geändert, 23 Zeilen hinzugefügt(+), 17 Zeilen entfernt(-)
diff --git a/hw/mc146818rtc.c b/hw/mc146818rtc.c
index 7d84ce3..c87b7f6 100644
--- a/hw/mc146818rtc.c
+++ b/hw/mc146818rtc.c
@@ -57,8 +57,11 @@
#define RTC_CLOCK_RATE 32768
#define UIP_HOLD_LENGTH (8 * NSEC_PER_SEC / 32768)
+#define MC146818_RTC(obj) OBJECT_CHECK(RTCState, (obj), TYPE_MC146818_RTC)
+
typedef struct RTCState {
- ISADevice dev;
+ ISADevice parent_obj;
+
MemoryRegion io;
uint8_t cmos_data[128];
uint8_t cmos_index;
@@ -668,14 +671,14 @@ static uint64_t cmos_ioport_read(void *opaque, hwaddr addr,
void rtc_set_memory(ISADevice *dev, int addr, int val)
{
- RTCState *s = DO_UPCAST(RTCState, dev, dev);
+ RTCState *s = MC146818_RTC(dev);
if (addr >= 0 && addr <= 127)
s->cmos_data[addr] = val;
}
static void rtc_set_date_from_host(ISADevice *dev)
{
- RTCState *s = DO_UPCAST(RTCState, dev, dev);
+ RTCState *s = MC146818_RTC(dev);
struct tm tm;
qemu_get_timedate(&tm, 0);
@@ -737,7 +740,7 @@ static void rtc_notify_clock_reset(Notifier *notifier, void *data)
RTCState *s = container_of(notifier, RTCState, clock_reset_notifier);
int64_t now = *(int64_t *)data;
- rtc_set_date_from_host(&s->dev);
+ rtc_set_date_from_host(ISA_DEVICE(s));
periodic_timer_update(s, now);
check_update_timer(s);
#ifdef TARGET_I386
@@ -752,7 +755,7 @@ static void rtc_notify_clock_reset(Notifier *notifier, void *data)
static void rtc_notify_suspend(Notifier *notifier, void *data)
{
RTCState *s = container_of(notifier, RTCState, suspend_notifier);
- rtc_set_memory(&s->dev, 0xF, 0xFE);
+ rtc_set_memory(ISA_DEVICE(s), 0xF, 0xFE);
}
static void rtc_reset(void *opaque)
@@ -785,8 +788,7 @@ static const MemoryRegionOps cmos_ops = {
static void rtc_get_date(Object *obj, Visitor *v, void *opaque,
const char *name, Error **errp)
{
- ISADevice *isa = ISA_DEVICE(obj);
- RTCState *s = DO_UPCAST(RTCState, dev, isa);
+ RTCState *s = MC146818_RTC(obj);
struct tm current_tm;
rtc_update_time(s);
@@ -803,7 +805,7 @@ static void rtc_get_date(Object *obj, Visitor *v, void *opaque,
static int rtc_initfn(ISADevice *dev)
{
- RTCState *s = DO_UPCAST(RTCState, dev, dev);
+ RTCState *s = MC146818_RTC(dev);
int base = 0x70;
s->cmos_data[RTC_REG_A] = 0x26;
@@ -862,19 +864,21 @@ static int rtc_initfn(ISADevice *dev)
ISADevice *rtc_init(ISABus *bus, int base_year, qemu_irq intercept_irq)
{
- ISADevice *dev;
+ DeviceState *dev;
+ ISADevice *isadev;
RTCState *s;
- dev = isa_create(bus, "mc146818rtc");
- s = DO_UPCAST(RTCState, dev, dev);
- qdev_prop_set_int32(&dev->qdev, "base_year", base_year);
- qdev_init_nofail(&dev->qdev);
+ isadev = isa_create(bus, TYPE_MC146818_RTC);
+ dev = DEVICE(isadev);
+ s = MC146818_RTC(isadev);
+ qdev_prop_set_int32(dev, "base_year", base_year);
+ qdev_init_nofail(dev);
if (intercept_irq) {
s->irq = intercept_irq;
} else {
- isa_init_irq(dev, &s->irq, RTC_ISA_IRQ);
+ isa_init_irq(isadev, &s->irq, RTC_ISA_IRQ);
}
- return dev;
+ return isadev;
}
static Property mc146818rtc_properties[] = {
@@ -894,8 +898,8 @@ static void rtc_class_initfn(ObjectClass *klass, void *data)
dc->props = mc146818rtc_properties;
}
-static TypeInfo mc146818rtc_info = {
- .name = "mc146818rtc",
+static const TypeInfo mc146818rtc_info = {
+ .name = TYPE_MC146818_RTC,
.parent = TYPE_ISA_DEVICE,
.instance_size = sizeof(RTCState),
.class_init = rtc_class_initfn,
diff --git a/hw/mc146818rtc.h b/hw/mc146818rtc.h
index f286b6a..b00c794 100644
--- a/hw/mc146818rtc.h
+++ b/hw/mc146818rtc.h
@@ -4,6 +4,8 @@
#include "isa.h"
#include "mc146818rtc_regs.h"
+#define TYPE_MC146818_RTC "mc146818rtc"
+
ISADevice *rtc_init(ISABus *bus, int base_year, qemu_irq intercept_irq);
void rtc_set_memory(ISADevice *dev, int addr, int val);
void rtc_set_date(ISADevice *dev, const struct tm *tm);
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [Qemu-devel] [RFC 16/34] ne2000-isa: QOM'ify
2012-11-26 0:12 [Qemu-devel] [RFC 00/34] QOM realize, device-only plus ISA conversion Andreas Färber
` (14 preceding siblings ...)
2012-11-26 0:12 ` [Qemu-devel] [RFC 15/34] mc146818rtc: QOM'ify Andreas Färber
@ 2012-11-26 0:12 ` Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 17/34] parallel: QOM'ify Andreas Färber
` (19 subsequent siblings)
35 siblings, 0 replies; 46+ messages in thread
From: Andreas Färber @ 2012-11-26 0:12 UTC (permalink / raw)
To: qemu-devel; +Cc: Andreas Färber, anthony
Introduce type constant and cast macro to obsolete DO_UPCAST().
Prepares for ISA realizefn.
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
hw/ne2000-isa.c | 12 ++++++++----
1 Datei geändert, 8 Zeilen hinzugefügt(+), 4 Zeilen entfernt(-)
diff --git a/hw/ne2000-isa.c b/hw/ne2000-isa.c
index 69982a9..5aabe7c 100644
--- a/hw/ne2000-isa.c
+++ b/hw/ne2000-isa.c
@@ -29,8 +29,12 @@
#include "ne2000.h"
#include "exec-memory.h"
+#define TYPE_ISA_NE2000 "ne2k_isa"
+#define ISA_NE2000(obj) OBJECT_CHECK(ISANE2000State, (obj), TYPE_ISA_NE2000)
+
typedef struct ISANE2000State {
- ISADevice dev;
+ ISADevice parent_obj;
+
uint32_t iobase;
uint32_t isairq;
NE2000State ne2000;
@@ -64,7 +68,7 @@ static const VMStateDescription vmstate_isa_ne2000 = {
static int isa_ne2000_initfn(ISADevice *dev)
{
- ISANE2000State *isa = DO_UPCAST(ISANE2000State, dev, dev);
+ ISANE2000State *isa = ISA_NE2000(dev);
NE2000State *s = &isa->ne2000;
ne2000_setup_io(s, 0x20);
@@ -97,8 +101,8 @@ static void isa_ne2000_class_initfn(ObjectClass *klass, void *data)
dc->props = ne2000_isa_properties;
}
-static TypeInfo ne2000_isa_info = {
- .name = "ne2k_isa",
+static const TypeInfo ne2000_isa_info = {
+ .name = TYPE_ISA_NE2000,
.parent = TYPE_ISA_DEVICE,
.instance_size = sizeof(ISANE2000State),
.class_init = isa_ne2000_class_initfn,
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [Qemu-devel] [RFC 17/34] parallel: QOM'ify
2012-11-26 0:12 [Qemu-devel] [RFC 00/34] QOM realize, device-only plus ISA conversion Andreas Färber
` (15 preceding siblings ...)
2012-11-26 0:12 ` [Qemu-devel] [RFC 16/34] ne2000-isa: QOM'ify Andreas Färber
@ 2012-11-26 0:12 ` Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 18/34] pc: QOM'ify port 92 Andreas Färber
` (18 subsequent siblings)
35 siblings, 0 replies; 46+ messages in thread
From: Andreas Färber @ 2012-11-26 0:12 UTC (permalink / raw)
To: qemu-devel; +Cc: Andreas Färber, anthony
Introduce type constant and cast macro to obsolete DO_UPCAST().
Prepares for ISA realizefn.
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
hw/parallel.c | 13 +++++++++----
1 Datei geändert, 9 Zeilen hinzugefügt(+), 4 Zeilen entfernt(-)
diff --git a/hw/parallel.c b/hw/parallel.c
index c4705bc..65447d3 100644
--- a/hw/parallel.c
+++ b/hw/parallel.c
@@ -80,8 +80,13 @@ typedef struct ParallelState {
int it_shift;
} ParallelState;
+#define TYPE_ISA_PARALLEL "isa-parallel"
+#define ISA_PARALLEL(obj) \
+ OBJECT_CHECK(ISAParallelState, (obj), TYPE_ISA_PARALLEL)
+
typedef struct ISAParallelState {
- ISADevice dev;
+ ISADevice parent_obj;
+
uint32_t index;
uint32_t iobase;
uint32_t isairq;
@@ -475,7 +480,7 @@ static const MemoryRegionPortio isa_parallel_portio_sw_list[] = {
static int parallel_isa_initfn(ISADevice *dev)
{
static int index;
- ISAParallelState *isa = DO_UPCAST(ISAParallelState, dev, dev);
+ ISAParallelState *isa = ISA_PARALLEL(dev);
ParallelState *s = &isa->state;
int base;
uint8_t dummy;
@@ -599,8 +604,8 @@ static void parallel_isa_class_initfn(ObjectClass *klass, void *data)
dc->props = parallel_isa_properties;
}
-static TypeInfo parallel_isa_info = {
- .name = "isa-parallel",
+static const TypeInfo parallel_isa_info = {
+ .name = TYPE_ISA_PARALLEL,
.parent = TYPE_ISA_DEVICE,
.instance_size = sizeof(ISAParallelState),
.class_init = parallel_isa_class_initfn,
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [Qemu-devel] [RFC 18/34] pc: QOM'ify port 92
2012-11-26 0:12 [Qemu-devel] [RFC 00/34] QOM realize, device-only plus ISA conversion Andreas Färber
` (16 preceding siblings ...)
2012-11-26 0:12 ` [Qemu-devel] [RFC 17/34] parallel: QOM'ify Andreas Färber
@ 2012-11-26 0:12 ` Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 19/34] pckbd: QOM'ify Andreas Färber
` (17 subsequent siblings)
35 siblings, 0 replies; 46+ messages in thread
From: Andreas Färber @ 2012-11-26 0:12 UTC (permalink / raw)
To: qemu-devel; +Cc: Anthony Liguori, Andreas Färber, anthony
Introduce type constant and cast macro to obsolete DO_UPCAST().
Prepares for ISA realizefn.
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
hw/pc.c | 16 ++++++++++------
1 Datei geändert, 10 Zeilen hinzugefügt(+), 6 Zeilen entfernt(-)
diff --git a/hw/pc.c b/hw/pc.c
index 5fc2076..e878106 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -413,9 +413,13 @@ void pc_cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size,
qemu_register_reset(pc_cmos_init_late, &arg);
}
+#define TYPE_PORT92 "port92"
+#define PORT92(obj) OBJECT_CHECK(Port92State, (obj), TYPE_PORT92)
+
/* port 92 stuff: could be split off */
typedef struct Port92State {
- ISADevice dev;
+ ISADevice parent_obj;
+
MemoryRegion io;
uint8_t outport;
qemu_irq *a20_out;
@@ -447,7 +451,7 @@ static uint64_t port92_read(void *opaque, hwaddr addr,
static void port92_init(ISADevice *dev, qemu_irq *a20_out)
{
- Port92State *s = DO_UPCAST(Port92State, dev, dev);
+ Port92State *s = PORT92(dev);
s->a20_out = a20_out;
}
@@ -465,7 +469,7 @@ static const VMStateDescription vmstate_port92_isa = {
static void port92_reset(DeviceState *d)
{
- Port92State *s = container_of(d, Port92State, dev.qdev);
+ Port92State *s = PORT92(d);
s->outport &= ~1;
}
@@ -482,7 +486,7 @@ static const MemoryRegionOps port92_ops = {
static int port92_initfn(ISADevice *dev)
{
- Port92State *s = DO_UPCAST(Port92State, dev, dev);
+ Port92State *s = PORT92(dev);
memory_region_init_io(&s->io, &port92_ops, s, "port92", 1);
isa_register_ioport(dev, &s->io, 0x92);
@@ -501,8 +505,8 @@ static void port92_class_initfn(ObjectClass *klass, void *data)
dc->vmsd = &vmstate_port92_isa;
}
-static TypeInfo port92_info = {
- .name = "port92",
+static const TypeInfo port92_info = {
+ .name = TYPE_PORT92,
.parent = TYPE_ISA_DEVICE,
.instance_size = sizeof(Port92State),
.class_init = port92_class_initfn,
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [Qemu-devel] [RFC 19/34] pckbd: QOM'ify
2012-11-26 0:12 [Qemu-devel] [RFC 00/34] QOM realize, device-only plus ISA conversion Andreas Färber
` (17 preceding siblings ...)
2012-11-26 0:12 ` [Qemu-devel] [RFC 18/34] pc: QOM'ify port 92 Andreas Färber
@ 2012-11-26 0:12 ` Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 20/34] pcspk: QOM'ify Andreas Färber
` (16 subsequent siblings)
35 siblings, 0 replies; 46+ messages in thread
From: Andreas Färber @ 2012-11-26 0:12 UTC (permalink / raw)
To: qemu-devel; +Cc: Andreas Färber, anthony
Introduce type constant and cast macro to obsolete DO_UPCAST().
Prepares for ISA realizefn.
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
hw/pckbd.c | 18 ++++++++++++------
1 Datei geändert, 12 Zeilen hinzugefügt(+), 6 Zeilen entfernt(-)
diff --git a/hw/pckbd.c b/hw/pckbd.c
index 5bb3e0a..a3291ec 100644
--- a/hw/pckbd.c
+++ b/hw/pckbd.c
@@ -431,8 +431,12 @@ void i8042_mm_init(qemu_irq kbd_irq, qemu_irq mouse_irq,
qemu_register_reset(kbd_reset, s);
}
+#define TYPE_I8042 "i8042"
+#define I8042(obj) OBJECT_CHECK(ISAKBDState, (obj), TYPE_I8042)
+
typedef struct ISAKBDState {
- ISADevice dev;
+ ISADevice parent_obj;
+
KBDState kbd;
MemoryRegion io[2];
} ISAKBDState;
@@ -440,14 +444,16 @@ typedef struct ISAKBDState {
void i8042_isa_mouse_fake_event(void *opaque)
{
ISADevice *dev = opaque;
- KBDState *s = &(DO_UPCAST(ISAKBDState, dev, dev)->kbd);
+ ISAKBDState *isa = I8042(dev);
+ KBDState *s = &isa->kbd;
ps2_mouse_fake_event(s->mouse);
}
void i8042_setup_a20_line(ISADevice *dev, qemu_irq *a20_out)
{
- KBDState *s = &(DO_UPCAST(ISAKBDState, dev, dev)->kbd);
+ ISAKBDState *isa = I8042(dev);
+ KBDState *s = &isa->kbd;
s->a20_out = a20_out;
}
@@ -485,7 +491,7 @@ static const MemoryRegionOps i8042_cmd_ops = {
static int i8042_initfn(ISADevice *dev)
{
- ISAKBDState *isa_s = DO_UPCAST(ISAKBDState, dev, dev);
+ ISAKBDState *isa_s = I8042(dev);
KBDState *s = &isa_s->kbd;
isa_init_irq(dev, &s->irq_kbd, 1);
@@ -512,8 +518,8 @@ static void i8042_class_initfn(ObjectClass *klass, void *data)
dc->vmsd = &vmstate_kbd_isa;
}
-static TypeInfo i8042_info = {
- .name = "i8042",
+static const TypeInfo i8042_info = {
+ .name = TYPE_I8042,
.parent = TYPE_ISA_DEVICE,
.instance_size = sizeof(ISAKBDState),
.class_init = i8042_class_initfn,
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [Qemu-devel] [RFC 20/34] pcspk: QOM'ify
2012-11-26 0:12 [Qemu-devel] [RFC 00/34] QOM realize, device-only plus ISA conversion Andreas Färber
` (18 preceding siblings ...)
2012-11-26 0:12 ` [Qemu-devel] [RFC 19/34] pckbd: QOM'ify Andreas Färber
@ 2012-11-26 0:12 ` Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 21/34] sb16: QOM'ify Andreas Färber
` (15 subsequent siblings)
35 siblings, 0 replies; 46+ messages in thread
From: Andreas Färber @ 2012-11-26 0:12 UTC (permalink / raw)
To: qemu-devel; +Cc: Andreas Färber, anthony
Introduce type constant and cast macro to obsolete DO_UPCAST().
Prepares for ISA realizefn.
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
hw/pcspk.c | 11 +++++++----
hw/pcspk.h | 4 +++-
2 Dateien geändert, 10 Zeilen hinzugefügt(+), 5 Zeilen entfernt(-)
diff --git a/hw/pcspk.c b/hw/pcspk.c
index ad6491b..f800962 100644
--- a/hw/pcspk.c
+++ b/hw/pcspk.c
@@ -35,8 +35,11 @@
#define PCSPK_MAX_FREQ (PCSPK_SAMPLE_RATE >> 1)
#define PCSPK_MIN_COUNT ((PIT_FREQ + PCSPK_MAX_FREQ - 1) / PCSPK_MAX_FREQ)
+#define PC_SPEAKER(obj) OBJECT_CHECK(PCSpkState, (obj), TYPE_PC_SPEAKER)
+
typedef struct {
- ISADevice dev;
+ ISADevice parent_obj;
+
MemoryRegion ioport;
uint32_t iobase;
uint8_t sample_buf[PCSPK_BUF_LEN];
@@ -161,7 +164,7 @@ static const MemoryRegionOps pcspk_io_ops = {
static int pcspk_initfn(ISADevice *dev)
{
- PCSpkState *s = DO_UPCAST(PCSpkState, dev, dev);
+ PCSpkState *s = PC_SPEAKER(dev);
memory_region_init_io(&s->ioport, &pcspk_io_ops, s, "elcr", 1);
isa_register_ioport(dev, &s->ioport, s->iobase);
@@ -187,8 +190,8 @@ static void pcspk_class_initfn(ObjectClass *klass, void *data)
dc->props = pcspk_properties;
}
-static TypeInfo pcspk_info = {
- .name = "isa-pcspk",
+static const TypeInfo pcspk_info = {
+ .name = TYPE_PC_SPEAKER,
.parent = TYPE_ISA_DEVICE,
.instance_size = sizeof(PCSpkState),
.class_init = pcspk_class_initfn,
diff --git a/hw/pcspk.h b/hw/pcspk.h
index 7f42bac..1ec7c41 100644
--- a/hw/pcspk.h
+++ b/hw/pcspk.h
@@ -28,11 +28,13 @@
#include "hw.h"
#include "isa.h"
+#define TYPE_PC_SPEAKER "isa-pcspk"
+
static inline ISADevice *pcspk_init(ISABus *bus, ISADevice *pit)
{
ISADevice *dev;
- dev = isa_create(bus, "isa-pcspk");
+ dev = isa_create(bus, TYPE_PC_SPEAKER);
qdev_prop_set_uint32(&dev->qdev, "iobase", 0x61);
qdev_prop_set_ptr(&dev->qdev, "pit", pit);
qdev_init_nofail(&dev->qdev);
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [Qemu-devel] [RFC 21/34] sb16: QOM'ify
2012-11-26 0:12 [Qemu-devel] [RFC 00/34] QOM realize, device-only plus ISA conversion Andreas Färber
` (19 preceding siblings ...)
2012-11-26 0:12 ` [Qemu-devel] [RFC 20/34] pcspk: QOM'ify Andreas Färber
@ 2012-11-26 0:12 ` Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 22/34] serial: QOM'ify ISA serial Andreas Färber
` (14 subsequent siblings)
35 siblings, 0 replies; 46+ messages in thread
From: Andreas Färber @ 2012-11-26 0:12 UTC (permalink / raw)
To: qemu-devel; +Cc: Andreas Färber, anthony
Introduce type constant and cast macro to obsolete DO_UPCAST().
Prepares for ISA realizefn.
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
hw/sb16.c | 16 +++++++++-------
1 Datei geändert, 9 Zeilen hinzugefügt(+), 7 Zeilen entfernt(-)
diff --git a/hw/sb16.c b/hw/sb16.c
index 523ab0d..b7e93a4 100644
--- a/hw/sb16.c
+++ b/hw/sb16.c
@@ -47,8 +47,12 @@
static const char e3[] = "COPYRIGHT (C) CREATIVE TECHNOLOGY LTD, 1992.";
+#define TYPE_SB16 "sb16"
+#define SB16(obj) OBJECT_CHECK (SB16State, (obj), TYPE_SB16)
+
typedef struct SB16State {
- ISADevice dev;
+ ISADevice parent_obj;
+
QEMUSoundCard card;
qemu_irq pic;
uint32_t irq;
@@ -1354,9 +1358,7 @@ static const MemoryRegionPortio sb16_ioport_list[] = {
static int sb16_initfn (ISADevice *dev)
{
- SB16State *s;
-
- s = DO_UPCAST (SB16State, dev, dev);
+ SB16State *s = SB16 (dev);
s->cmd = -1;
isa_init_irq (dev, &s->pic, s->irq);
@@ -1386,7 +1388,7 @@ static int sb16_initfn (ISADevice *dev)
int SB16_init (ISABus *bus)
{
- isa_create_simple (bus, "sb16");
+ isa_create_simple (bus, TYPE_SB16);
return 0;
}
@@ -1409,8 +1411,8 @@ static void sb16_class_initfn (ObjectClass *klass, void *data)
dc->props = sb16_properties;
}
-static TypeInfo sb16_info = {
- .name = "sb16",
+static const TypeInfo sb16_info = {
+ .name = TYPE_SB16,
.parent = TYPE_ISA_DEVICE,
.instance_size = sizeof (SB16State),
.class_init = sb16_class_initfn,
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [Qemu-devel] [RFC 22/34] serial: QOM'ify ISA serial
2012-11-26 0:12 [Qemu-devel] [RFC 00/34] QOM realize, device-only plus ISA conversion Andreas Färber
` (20 preceding siblings ...)
2012-11-26 0:12 ` [Qemu-devel] [RFC 21/34] sb16: QOM'ify Andreas Färber
@ 2012-11-26 0:12 ` Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 23/34] sga: QOM'ify Andreas Färber
` (13 subsequent siblings)
35 siblings, 0 replies; 46+ messages in thread
From: Andreas Färber @ 2012-11-26 0:12 UTC (permalink / raw)
To: qemu-devel; +Cc: Andreas Färber, anthony
Introduce type constant and cast macro to obsolete DO_UPCAST().
Prepares for ISA realizefn.
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
hw/serial-isa.c | 13 ++++++++-----
hw/serial.h | 1 +
2 Dateien geändert, 9 Zeilen hinzugefügt(+), 5 Zeilen entfernt(-)
diff --git a/hw/serial-isa.c b/hw/serial-isa.c
index 96c78f7..904cc41 100644
--- a/hw/serial-isa.c
+++ b/hw/serial-isa.c
@@ -26,8 +26,11 @@
#include "serial.h"
#include "isa.h"
+#define ISA_SERIAL(obj) OBJECT_CHECK(ISASerialState, (obj), TYPE_ISA_SERIAL)
+
typedef struct ISASerialState {
- ISADevice dev;
+ ISADevice parent_obj;
+
uint32_t index;
uint32_t iobase;
uint32_t isairq;
@@ -44,7 +47,7 @@ static const int isa_serial_irq[MAX_SERIAL_PORTS] = {
static int serial_isa_initfn(ISADevice *dev)
{
static int index;
- ISASerialState *isa = DO_UPCAST(ISASerialState, dev, dev);
+ ISASerialState *isa = ISA_SERIAL(dev);
SerialState *s = &isa->state;
if (isa->index == -1) {
@@ -99,8 +102,8 @@ static void serial_isa_class_initfn(ObjectClass *klass, void *data)
dc->props = serial_isa_properties;
}
-static TypeInfo serial_isa_info = {
- .name = "isa-serial",
+static const TypeInfo serial_isa_info = {
+ .name = TYPE_ISA_SERIAL,
.parent = TYPE_ISA_DEVICE,
.instance_size = sizeof(ISASerialState),
.class_init = serial_isa_class_initfn,
@@ -117,7 +120,7 @@ bool serial_isa_init(ISABus *bus, int index, CharDriverState *chr)
{
ISADevice *dev;
- dev = isa_try_create(bus, "isa-serial");
+ dev = isa_try_create(bus, TYPE_ISA_SERIAL);
if (!dev) {
return false;
}
diff --git a/hw/serial.h b/hw/serial.h
index ed1a5cd..bb06366 100644
--- a/hw/serial.h
+++ b/hw/serial.h
@@ -96,4 +96,5 @@ SerialState *serial_mm_init(MemoryRegion *address_space,
CharDriverState *chr, enum device_endian end);
/* serial-isa.c */
+#define TYPE_ISA_SERIAL "isa-serial"
bool serial_isa_init(ISABus *bus, int index, CharDriverState *chr);
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [Qemu-devel] [RFC 23/34] sga: QOM'ify
2012-11-26 0:12 [Qemu-devel] [RFC 00/34] QOM realize, device-only plus ISA conversion Andreas Färber
` (21 preceding siblings ...)
2012-11-26 0:12 ` [Qemu-devel] [RFC 22/34] serial: QOM'ify ISA serial Andreas Färber
@ 2012-11-26 0:12 ` Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 24/34] vga-isa: QOM'ify ISA VGA Andreas Färber
` (12 subsequent siblings)
35 siblings, 0 replies; 46+ messages in thread
From: Andreas Färber @ 2012-11-26 0:12 UTC (permalink / raw)
To: qemu-devel; +Cc: Andreas Färber, anthony
Introduce type constant and cast macro.
Prepares for ISA realizefn.
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
hw/sga.c | 12 ++++++++----
1 Datei geändert, 8 Zeilen hinzugefügt(+), 4 Zeilen entfernt(-)
diff --git a/hw/sga.c b/hw/sga.c
index a666349..d828f45 100644
--- a/hw/sga.c
+++ b/hw/sga.c
@@ -31,8 +31,11 @@
#define SGABIOS_FILENAME "sgabios.bin"
-typedef struct ISAGAState {
- ISADevice dev;
+#define TYPE_SGA "sga"
+#define SGA(obj) OBJECT_CHECK(ISASGAState, (obj), TYPE_SGA)
+
+typedef struct ISASGAState {
+ ISADevice parent_obj;
} ISASGAState;
static int sga_initfn(ISADevice *dev)
@@ -40,6 +43,7 @@ static int sga_initfn(ISADevice *dev)
rom_add_vga(SGABIOS_FILENAME);
return 0;
}
+
static void sga_class_initfn(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
@@ -48,8 +52,8 @@ static void sga_class_initfn(ObjectClass *klass, void *data)
dc->desc = "Serial Graphics Adapter";
}
-static TypeInfo sga_info = {
- .name = "sga",
+static const TypeInfo sga_info = {
+ .name = TYPE_SGA,
.parent = TYPE_ISA_DEVICE,
.instance_size = sizeof(ISASGAState),
.class_init = sga_class_initfn,
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [Qemu-devel] [RFC 24/34] vga-isa: QOM'ify ISA VGA
2012-11-26 0:12 [Qemu-devel] [RFC 00/34] QOM realize, device-only plus ISA conversion Andreas Färber
` (22 preceding siblings ...)
2012-11-26 0:12 ` [Qemu-devel] [RFC 23/34] sga: QOM'ify Andreas Färber
@ 2012-11-26 0:12 ` Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 25/34] vmmouse: QOM'ify Andreas Färber
` (11 subsequent siblings)
35 siblings, 0 replies; 46+ messages in thread
From: Andreas Färber @ 2012-11-26 0:12 UTC (permalink / raw)
To: qemu-devel; +Cc: Andreas Färber, anthony
Introduce type constant and cast macro to obsolete DO_UPCAST() and
container_of(). Prepares for ISA realizefn.
Unify function naming scheme while at it.
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
hw/vga-isa.c | 29 +++++++++++++++++------------
1 Datei geändert, 17 Zeilen hinzugefügt(+), 12 Zeilen entfernt(-)
diff --git a/hw/vga-isa.c b/hw/vga-isa.c
index 046602b..f177c48 100644
--- a/hw/vga-isa.c
+++ b/hw/vga-isa.c
@@ -31,14 +31,18 @@
#include "qemu-timer.h"
#include "loader.h"
+#define TYPE_ISA_VGA "isa-vga"
+#define ISA_VGA(obj) OBJECT_CHECK(ISAVGAState, (obj), TYPE_ISA_VGA)
+
typedef struct ISAVGAState {
- ISADevice dev;
+ ISADevice parent_obj;
+
struct VGACommonState state;
} ISAVGAState;
-static void vga_reset_isa(DeviceState *dev)
+static void vga_isa_reset(DeviceState *dev)
{
- ISAVGAState *d = container_of(dev, ISAVGAState, dev.qdev);
+ ISAVGAState *d = ISA_VGA(dev);
VGACommonState *s = &d->state;
vga_common_reset(s);
@@ -46,7 +50,7 @@ static void vga_reset_isa(DeviceState *dev)
static int vga_initfn(ISADevice *dev)
{
- ISAVGAState *d = DO_UPCAST(ISAVGAState, dev, dev);
+ ISAVGAState *d = ISA_VGA(dev);
VGACommonState *s = &d->state;
MemoryRegion *vga_io_memory;
const MemoryRegionPortio *vga_ports, *vbe_ports;
@@ -76,26 +80,27 @@ static Property vga_isa_properties[] = {
DEFINE_PROP_END_OF_LIST(),
};
-static void vga_class_initfn(ObjectClass *klass, void *data)
+static void vga_isa_class_initfn(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+
ic->init = vga_initfn;
- dc->reset = vga_reset_isa;
+ dc->reset = vga_isa_reset;
dc->vmsd = &vmstate_vga_common;
dc->props = vga_isa_properties;
}
-static TypeInfo vga_info = {
- .name = "isa-vga",
+static const TypeInfo vga_isa_info = {
+ .name = TYPE_ISA_VGA,
.parent = TYPE_ISA_DEVICE,
.instance_size = sizeof(ISAVGAState),
- .class_init = vga_class_initfn,
+ .class_init = vga_isa_class_initfn,
};
-static void vga_register_types(void)
+static void vga_isa_register_types(void)
{
- type_register_static(&vga_info);
+ type_register_static(&vga_isa_info);
}
-type_init(vga_register_types)
+type_init(vga_isa_register_types)
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [Qemu-devel] [RFC 25/34] vmmouse: QOM'ify
2012-11-26 0:12 [Qemu-devel] [RFC 00/34] QOM realize, device-only plus ISA conversion Andreas Färber
` (23 preceding siblings ...)
2012-11-26 0:12 ` [Qemu-devel] [RFC 24/34] vga-isa: QOM'ify ISA VGA Andreas Färber
@ 2012-11-26 0:12 ` Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 26/34] vmport: QOM'ify Andreas Färber
` (10 subsequent siblings)
35 siblings, 0 replies; 46+ messages in thread
From: Andreas Färber @ 2012-11-26 0:12 UTC (permalink / raw)
To: qemu-devel; +Cc: Andreas Färber, anthony
Introduce type constant and cast macro to obsolete DO_UPCAST() and
container_of(). Prepares for ISA realizefn.
Remove reserved underscore from struct name while at it.
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
hw/vmmouse.c | 16 ++++++++++------
1 Datei geändert, 10 Zeilen hinzugefügt(+), 6 Zeilen entfernt(-)
diff --git a/hw/vmmouse.c b/hw/vmmouse.c
index 6338efa..7c7c4e4 100644
--- a/hw/vmmouse.c
+++ b/hw/vmmouse.c
@@ -51,9 +51,13 @@
#define DPRINTF(fmt, ...) do { } while (0)
#endif
-typedef struct _VMMouseState
+#define TYPE_VMMOUSE "vmmouse"
+#define VMMOUSE(obj) OBJECT_CHECK(VMMouseState, (obj), TYPE_VMMOUSE)
+
+typedef struct VMMouseState
{
- ISADevice dev;
+ ISADevice parent_obj;
+
uint32_t queue[VMMOUSE_QUEUE_SIZE];
int32_t queue_size;
uint16_t nb_queue;
@@ -250,7 +254,7 @@ static const VMStateDescription vmstate_vmmouse = {
static void vmmouse_reset(DeviceState *d)
{
- VMMouseState *s = container_of(d, VMMouseState, dev.qdev);
+ VMMouseState *s = VMMOUSE(d);
s->status = 0xffff;
s->queue_size = VMMOUSE_QUEUE_SIZE;
@@ -260,7 +264,7 @@ static void vmmouse_reset(DeviceState *d)
static int vmmouse_initfn(ISADevice *dev)
{
- VMMouseState *s = DO_UPCAST(VMMouseState, dev, dev);
+ VMMouseState *s = VMMOUSE(dev);
DPRINTF("vmmouse_init\n");
@@ -287,8 +291,8 @@ static void vmmouse_class_initfn(ObjectClass *klass, void *data)
dc->props = vmmouse_properties;
}
-static TypeInfo vmmouse_info = {
- .name = "vmmouse",
+static const TypeInfo vmmouse_info = {
+ .name = TYPE_VMMOUSE,
.parent = TYPE_ISA_DEVICE,
.instance_size = sizeof(VMMouseState),
.class_init = vmmouse_class_initfn,
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [Qemu-devel] [RFC 26/34] vmport: QOM'ify
2012-11-26 0:12 [Qemu-devel] [RFC 00/34] QOM realize, device-only plus ISA conversion Andreas Färber
` (24 preceding siblings ...)
2012-11-26 0:12 ` [Qemu-devel] [RFC 25/34] vmmouse: QOM'ify Andreas Färber
@ 2012-11-26 0:12 ` Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 27/34] wdt_ib700: QOM'ify Andreas Färber
` (9 subsequent siblings)
35 siblings, 0 replies; 46+ messages in thread
From: Andreas Färber @ 2012-11-26 0:12 UTC (permalink / raw)
To: qemu-devel; +Cc: Andreas Färber, anthony
Introduce type constant and cast macro to obsolete DO_UPCAST().
Prepares for ISA realizefn.
Drop reserved underscore from struct name while at it.
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
hw/vmport.c | 14 +++++++++-----
1 Datei geändert, 9 Zeilen hinzugefügt(+), 5 Zeilen entfernt(-)
diff --git a/hw/vmport.c b/hw/vmport.c
index 3ab3a14..ec36d47 100644
--- a/hw/vmport.c
+++ b/hw/vmport.c
@@ -35,9 +35,13 @@
#define VMPORT_ENTRIES 0x2c
#define VMPORT_MAGIC 0x564D5868
-typedef struct _VMPortState
+#define TYPE_VMPORT "vmport"
+#define VMPORT(obj) OBJECT_CHECK(VMPortState, (obj), TYPE_VMPORT)
+
+typedef struct VMPortState
{
- ISADevice dev;
+ ISADevice parent_obj;
+
MemoryRegion io;
IOPortReadFunc *func[VMPORT_ENTRIES];
void *opaque[VMPORT_ENTRIES];
@@ -135,7 +139,7 @@ static const MemoryRegionOps vmport_ops = {
static int vmport_initfn(ISADevice *dev)
{
- VMPortState *s = DO_UPCAST(VMPortState, dev, dev);
+ VMPortState *s = VMPORT(dev);
memory_region_init_io(&s->io, &vmport_ops, s, "vmport", 1);
isa_register_ioport(dev, &s->io, 0x5658);
@@ -155,8 +159,8 @@ static void vmport_class_initfn(ObjectClass *klass, void *data)
dc->no_user = 1;
}
-static TypeInfo vmport_info = {
- .name = "vmport",
+static const TypeInfo vmport_info = {
+ .name = TYPE_VMPORT,
.parent = TYPE_ISA_DEVICE,
.instance_size = sizeof(VMPortState),
.class_init = vmport_class_initfn,
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [Qemu-devel] [RFC 27/34] wdt_ib700: QOM'ify
2012-11-26 0:12 [Qemu-devel] [RFC 00/34] QOM realize, device-only plus ISA conversion Andreas Färber
` (25 preceding siblings ...)
2012-11-26 0:12 ` [Qemu-devel] [RFC 26/34] vmport: QOM'ify Andreas Färber
@ 2012-11-26 0:12 ` Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 28/34] isa: Use realizefn for ISADevice Andreas Färber
` (8 subsequent siblings)
35 siblings, 0 replies; 46+ messages in thread
From: Andreas Färber @ 2012-11-26 0:12 UTC (permalink / raw)
To: qemu-devel; +Cc: Andreas Färber, anthony
Introduce type constant and cast macro to obsolete DO_UPCAST().
Prepares for ISA realizefn.
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
hw/wdt_ib700.c | 14 +++++++++-----
1 Datei geändert, 9 Zeilen hinzugefügt(+), 5 Zeilen entfernt(-)
diff --git a/hw/wdt_ib700.c b/hw/wdt_ib700.c
index 7f6c21d..1365898 100644
--- a/hw/wdt_ib700.c
+++ b/hw/wdt_ib700.c
@@ -35,8 +35,12 @@
#define ib700_debug(fs,...)
#endif
+#define TYPE_IB700 "ib700"
+#define IB700(obj) OBJECT_CHECK(IB700State, (obj), TYPE_IB700)
+
typedef struct IB700state {
- ISADevice dev;
+ ISADevice parent_obj;
+
QEMUTimer *timer;
} IB700State;
@@ -95,7 +99,7 @@ static const VMStateDescription vmstate_ib700 = {
static int wdt_ib700_init(ISADevice *dev)
{
- IB700State *s = DO_UPCAST(IB700State, dev, dev);
+ IB700State *s = IB700(dev);
ib700_debug("watchdog init\n");
@@ -108,7 +112,7 @@ static int wdt_ib700_init(ISADevice *dev)
static void wdt_ib700_reset(DeviceState *dev)
{
- IB700State *s = DO_UPCAST(IB700State, dev.qdev, dev);
+ IB700State *s = IB700(dev);
ib700_debug("watchdog reset\n");
@@ -129,8 +133,8 @@ static void wdt_ib700_class_init(ObjectClass *klass, void *data)
dc->vmsd = &vmstate_ib700;
}
-static TypeInfo wdt_ib700_info = {
- .name = "ib700",
+static const TypeInfo wdt_ib700_info = {
+ .name = TYPE_IB700,
.parent = TYPE_ISA_DEVICE,
.instance_size = sizeof(IB700State),
.class_init = wdt_ib700_class_init,
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [Qemu-devel] [RFC 28/34] isa: Use realizefn for ISADevice
2012-11-26 0:12 [Qemu-devel] [RFC 00/34] QOM realize, device-only plus ISA conversion Andreas Färber
` (26 preceding siblings ...)
2012-11-26 0:12 ` [Qemu-devel] [RFC 27/34] wdt_ib700: QOM'ify Andreas Färber
@ 2012-11-26 0:12 ` Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 29/34] i8254: QOM'ify Andreas Färber
` (7 subsequent siblings)
35 siblings, 0 replies; 46+ messages in thread
From: Andreas Färber @ 2012-11-26 0:12 UTC (permalink / raw)
To: qemu-devel; +Cc: Kevin Wolf, Anthony Liguori, Andreas Färber, anthony
Drop ISADeviceClass::init and the resulting no-op initfn and let
children implement their own realizefn. Adapt error handling.
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
hw/applesmc.c | 10 ++++------
hw/cirrus_vga.c | 10 +++++-----
hw/debugcon.c | 21 +++++++++++++--------
hw/fdc.c | 24 ++++++++++++++----------
hw/i82374.c | 13 +++++--------
hw/i8254_common.c | 15 +++++++--------
hw/i8259_common.c | 9 +++------
hw/ide/isa.c | 16 ++++++++--------
hw/isa-bus.c | 13 -------------
hw/isa.h | 1 -
hw/m48t59.c | 17 ++++++++---------
hw/mc146818rtc.c | 18 +++++++++---------
hw/ne2000-isa.c | 15 +++++++--------
hw/parallel.c | 29 +++++++++++++++++------------
hw/pc.c | 10 +++++-----
hw/pckbd.c | 16 ++++++++--------
hw/pcspk.c | 10 ++++------
hw/sb16.c | 21 ++++++++++++++-------
hw/serial-isa.c | 20 +++++++++++---------
hw/serial-pci.c | 4 ++--
hw/serial.c | 6 +++---
hw/serial.h | 2 +-
hw/sga.c | 7 +++----
hw/vga-isa.c | 17 ++++++++---------
hw/vmmouse.c | 8 +++-----
hw/vmport.c | 10 +++++-----
hw/wdt_ib700.c | 8 +++-----
27 Dateien geändert, 170 Zeilen hinzugefügt(+), 180 Zeilen entfernt(-)
diff --git a/hw/applesmc.c b/hw/applesmc.c
index d6e556b..b7b32f2 100644
--- a/hw/applesmc.c
+++ b/hw/applesmc.c
@@ -201,7 +201,7 @@ static void qdev_applesmc_isa_reset(DeviceState *dev)
applesmc_add_key(s, "MSSD", 1, "\0x3");
}
-static int applesmc_isa_init(ISADevice *dev)
+static void applesmc_isa_realize(DeviceState *dev, Error **err)
{
AppleSMCState *s = APPLE_SMC(dev);
@@ -220,9 +220,7 @@ static int applesmc_isa_init(ISADevice *dev)
}
QLIST_INIT(&s->data_def);
- qdev_applesmc_isa_reset(&dev->qdev);
-
- return 0;
+ qdev_applesmc_isa_reset(dev);
}
static Property applesmc_isa_properties[] = {
@@ -235,8 +233,8 @@ static Property applesmc_isa_properties[] = {
static void qdev_applesmc_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
- ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
- ic->init = applesmc_isa_init;
+
+ dc->realize = applesmc_isa_realize;
dc->reset = qdev_applesmc_isa_reset;
dc->props = applesmc_isa_properties;
}
diff --git a/hw/cirrus_vga.c b/hw/cirrus_vga.c
index 9687b6b..d4128ce 100644
--- a/hw/cirrus_vga.c
+++ b/hw/cirrus_vga.c
@@ -2905,21 +2905,22 @@ static void cirrus_init_common(CirrusVGAState * s, int device_id, int is_pci,
*
***************************************/
-static int vga_initfn(ISADevice *dev)
+static void isa_cirrus_vga_realizefn(DeviceState *dev, Error **err)
{
+ ISADevice *isadev = ISA_DEVICE(dev);
ISACirrusVGAState *d = ISA_CIRRUS_VGA(dev);
VGACommonState *s = &d->cirrus_vga.vga;
vga_common_init(s);
cirrus_init_common(&d->cirrus_vga, CIRRUS_ID_CLGD5430, 0,
- isa_address_space(dev), isa_address_space_io(dev));
+ isa_address_space(isadev),
+ isa_address_space_io(isadev));
s->ds = graphic_console_init(s->update, s->invalidate,
s->screen_dump, s->text_update,
s);
rom_add_vga(VGABIOS_CIRRUS_FILENAME);
/* XXX ISA-LFB support */
/* FIXME not qdev yet */
- return 0;
}
static Property isa_cirrus_vga_properties[] = {
@@ -2930,11 +2931,10 @@ static Property isa_cirrus_vga_properties[] = {
static void isa_cirrus_vga_class_init(ObjectClass *klass, void *data)
{
- ISADeviceClass *k = ISA_DEVICE_CLASS(klass);
DeviceClass *dc = DEVICE_CLASS(klass);
dc->vmsd = &vmstate_cirrus_vga;
- k->init = vga_initfn;
+ dc->realize = isa_cirrus_vga_realizefn;
dc->props = isa_cirrus_vga_properties;
}
diff --git a/hw/debugcon.c b/hw/debugcon.c
index 02846ed..4cfc96e 100644
--- a/hw/debugcon.c
+++ b/hw/debugcon.c
@@ -71,25 +71,30 @@ static uint32_t debugcon_ioport_read(void *opaque, uint32_t addr)
return s->readback;
}
-static void debugcon_init_core(DebugconState *s)
+static void debugcon_realize_core(DebugconState *s, Error **err)
{
if (!s->chr) {
- fprintf(stderr, "Can't create debugcon device, empty char device\n");
- exit(1);
+ error_setg(err, "Can't create debugcon device, empty char device\n");
+ return;
}
qemu_chr_add_handlers(s->chr, NULL, NULL, NULL, s);
}
-static int debugcon_isa_initfn(ISADevice *dev)
+static void debugcon_isa_realizefn(DeviceState *dev, Error **err)
{
ISADebugconState *isa = ISA_DEBUG_CONSOLE(dev);
DebugconState *s = &isa->state;
+ Error *local_err = NULL;
- debugcon_init_core(s);
+ debugcon_realize_core(s, &local_err);
+ if (local_err != NULL) {
+ qerror_report_err(local_err);
+ error_propagate(err, local_err);
+ return;
+ }
register_ioport_write(isa->iobase, 1, 1, debugcon_ioport_write, s);
register_ioport_read(isa->iobase, 1, 1, debugcon_ioport_read, s);
- return 0;
}
static Property debugcon_isa_properties[] = {
@@ -102,8 +107,8 @@ static Property debugcon_isa_properties[] = {
static void debugcon_isa_class_initfn(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
- ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
- ic->init = debugcon_isa_initfn;
+
+ dc->realize = debugcon_isa_realizefn;
dc->props = debugcon_isa_properties;
}
diff --git a/hw/fdc.c b/hw/fdc.c
index edd7483..3ab3671 100644
--- a/hw/fdc.c
+++ b/hw/fdc.c
@@ -2118,24 +2118,28 @@ static const MemoryRegionPortio fdc_portio_list[] = {
PORTIO_END_OF_LIST(),
};
-static int isabus_fdc_init1(ISADevice *dev)
+static void isabus_fdc_realize(DeviceState *dev, Error **err)
{
+ ISADevice *isadev = ISA_DEVICE(dev);
FDCtrlISABus *isa = ISA_FDC(dev);
FDCtrl *fdctrl = &isa->state;
int ret;
- isa_register_portio_list(dev, isa->iobase, fdc_portio_list, fdctrl, "fdc");
+ isa_register_portio_list(isadev, isa->iobase, fdc_portio_list, fdctrl,
+ "fdc");
- isa_init_irq(dev, &fdctrl->irq, isa->irq);
+ isa_init_irq(isadev, &fdctrl->irq, isa->irq);
fdctrl->dma_chann = isa->dma;
- qdev_set_legacy_instance_id(&dev->qdev, isa->iobase, 2);
+ qdev_set_legacy_instance_id(dev, isa->iobase, 2);
ret = fdctrl_init_common(fdctrl);
+ if (ret < 0) {
+ error_setg(err, "Floppy init failed.");
+ return;
+ }
- add_boot_device_path(isa->bootindexA, &dev->qdev, "/floppy@0");
- add_boot_device_path(isa->bootindexB, &dev->qdev, "/floppy@1");
-
- return ret;
+ add_boot_device_path(isa->bootindexA, dev, "/floppy@0");
+ add_boot_device_path(isa->bootindexB, dev, "/floppy@1");
}
static int sysbus_fdc_init1(SysBusDevice *dev)
@@ -2204,8 +2208,8 @@ static Property isa_fdc_properties[] = {
static void isabus_fdc_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
- ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
- ic->init = isabus_fdc_init1;
+
+ dc->realize = isabus_fdc_realize;
dc->fw_name = "fdc";
dc->no_user = 1;
dc->reset = fdctrl_external_reset_isa;
diff --git a/hw/i82374.c b/hw/i82374.c
index 82de0b0..bf8b574 100644
--- a/hw/i82374.c
+++ b/hw/i82374.c
@@ -98,7 +98,7 @@ static uint32_t i82374_read_descriptor(void *opaque, uint32_t nport)
return val;
}
-static void i82374_init(I82374State *s)
+static void i82374_realize(I82374State *s, Error **err)
{
DMA_init(1, &s->out);
memset(s->commands, 0, sizeof(s->commands));
@@ -124,7 +124,7 @@ static const VMStateDescription vmstate_isa_i82374 = {
},
};
-static int i82374_isa_init(ISADevice *dev)
+static void i82374_isa_realize(DeviceState *dev, Error **err)
{
ISAi82374State *isa = I82374(dev);
I82374State *s = &isa->state;
@@ -135,11 +135,9 @@ static int i82374_isa_init(ISADevice *dev)
register_ioport_write(isa->iobase + 0x20, 0x20, 1, i82374_write_descriptor, s);
register_ioport_read(isa->iobase + 0x20, 0x20, 1, i82374_read_descriptor, s);
- i82374_init(s);
+ i82374_realize(s, err);
- qdev_init_gpio_out(&dev->qdev, &s->out, 1);
-
- return 0;
+ qdev_init_gpio_out(dev, &s->out, 1);
}
static Property i82374_properties[] = {
@@ -149,10 +147,9 @@ static Property i82374_properties[] = {
static void i82374_class_init(ObjectClass *klass, void *data)
{
- ISADeviceClass *k = ISA_DEVICE_CLASS(klass);
DeviceClass *dc = DEVICE_CLASS(klass);
- k->init = i82374_isa_init;
+ dc->realize = i82374_isa_realize;
dc->vmsd = &vmstate_isa_i82374;
dc->props = i82374_properties;
}
diff --git a/hw/i8254_common.c b/hw/i8254_common.c
index a03d7cd..1883405 100644
--- a/hw/i8254_common.c
+++ b/hw/i8254_common.c
@@ -166,22 +166,22 @@ void pit_reset_common(PITCommonState *pit)
}
}
-static int pit_init_common(ISADevice *dev)
+static void pit_common_realize(DeviceState *dev, Error **err)
{
+ ISADevice *isadev = ISA_DEVICE(dev);
PITCommonState *pit = PIT_COMMON(dev);
PITCommonClass *c = PIT_COMMON_GET_CLASS(pit);
int ret;
ret = c->init(pit);
if (ret < 0) {
- return ret;
+ error_setg(err, "PIT init failed.");
+ return;
}
- isa_register_ioport(dev, &pit->ioports, pit->iobase);
+ isa_register_ioport(isadev, &pit->ioports, pit->iobase);
- qdev_set_legacy_instance_id(&dev->qdev, pit->iobase, 2);
-
- return 0;
+ qdev_set_legacy_instance_id(dev, pit->iobase, 2);
}
static const VMStateDescription vmstate_pit_channel = {
@@ -286,10 +286,9 @@ static const VMStateDescription vmstate_pit_common = {
static void pit_common_class_init(ObjectClass *klass, void *data)
{
- ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
DeviceClass *dc = DEVICE_CLASS(klass);
- ic->init = pit_init_common;
+ dc->realize = pit_common_realize;
dc->vmsd = &vmstate_pit_common;
dc->no_user = 1;
}
diff --git a/hw/i8259_common.c b/hw/i8259_common.c
index 418c485..0b8aae1 100644
--- a/hw/i8259_common.c
+++ b/hw/i8259_common.c
@@ -66,7 +66,7 @@ static int pic_dispatch_post_load(void *opaque, int version_id)
return 0;
}
-static int pic_init_common(ISADevice *dev)
+static void pic_common_realize(DeviceState *dev, Error **err)
{
PICCommonState *s = PIC_COMMON(dev);
PICCommonClass *info = PIC_COMMON_GET_CLASS(s);
@@ -78,9 +78,7 @@ static int pic_init_common(ISADevice *dev)
isa_register_ioport(NULL, &s->elcr_io, s->elcr_addr);
}
- qdev_set_legacy_instance_id(DEVICE(dev), s->iobase, 1);
-
- return 0;
+ qdev_set_legacy_instance_id(dev, s->iobase, 1);
}
ISADevice *i8259_init_chip(const char *name, ISABus *bus, bool master)
@@ -135,13 +133,12 @@ static Property pic_properties_common[] = {
static void pic_common_class_init(ObjectClass *klass, void *data)
{
- ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
DeviceClass *dc = DEVICE_CLASS(klass);
dc->vmsd = &vmstate_pic_common;
dc->no_user = 1;
dc->props = pic_properties_common;
- ic->init = pic_init_common;
+ dc->realize = pic_common_realize;
}
static const TypeInfo pic_common_type = {
diff --git a/hw/ide/isa.c b/hw/ide/isa.c
index 4d55885..9e12a91 100644
--- a/hw/ide/isa.c
+++ b/hw/ide/isa.c
@@ -65,16 +65,16 @@ static const VMStateDescription vmstate_ide_isa = {
}
};
-static int isa_ide_initfn(ISADevice *dev)
+static void isa_ide_realizefn(DeviceState *dev, Error **err)
{
+ ISADevice *isadev = ISA_DEVICE(dev);
ISAIDEState *s = ISA_IDE(dev);
- ide_bus_new(&s->bus, DEVICE(dev), 0);
- ide_init_ioport(&s->bus, dev, s->iobase, s->iobase2);
- isa_init_irq(dev, &s->irq, s->isairq);
+ ide_bus_new(&s->bus, dev, 0);
+ ide_init_ioport(&s->bus, isadev, s->iobase, s->iobase2);
+ isa_init_irq(isadev, &s->irq, s->isairq);
ide_init2(&s->bus, s->irq);
- vmstate_register(&dev->qdev, 0, &vmstate_ide_isa, s);
- return 0;
+ vmstate_register(dev, 0, &vmstate_ide_isa, s);
};
ISADevice *isa_ide_init(ISABus *bus, int iobase, int iobase2, int isairq,
@@ -113,8 +113,8 @@ static Property isa_ide_properties[] = {
static void isa_ide_class_initfn(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
- ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
- ic->init = isa_ide_initfn;
+
+ dc->realize = isa_ide_realizefn;
dc->fw_name = "ide";
dc->reset = isa_ide_reset;
dc->props = isa_ide_properties;
diff --git a/hw/isa-bus.c b/hw/isa-bus.c
index 2b1fc40..bad0d05 100644
--- a/hw/isa-bus.c
+++ b/hw/isa-bus.c
@@ -119,18 +119,6 @@ void isa_register_portio_list(ISADevice *dev, uint16_t start,
portio_list_add(piolist, isabus->address_space_io, start);
}
-static int isa_qdev_init(DeviceState *qdev)
-{
- ISADevice *dev = ISA_DEVICE(qdev);
- ISADeviceClass *klass = ISA_DEVICE_GET_CLASS(dev);
-
- if (klass->init) {
- return klass->init(dev);
- }
-
- return 0;
-}
-
static void isa_device_init(Object *obj)
{
ISADevice *dev = ISA_DEVICE(obj);
@@ -230,7 +218,6 @@ static TypeInfo isabus_bridge_info = {
static void isa_device_class_init(ObjectClass *klass, void *data)
{
DeviceClass *k = DEVICE_CLASS(klass);
- k->init = isa_qdev_init;
k->bus_type = TYPE_ISA_BUS;
}
diff --git a/hw/isa.h b/hw/isa.h
index 9d719fa..04f3939 100644
--- a/hw/isa.h
+++ b/hw/isa.h
@@ -22,7 +22,6 @@
typedef struct ISADeviceClass {
DeviceClass parent_class;
- int (*init)(ISADevice *dev);
} ISADeviceClass;
struct ISABus {
diff --git a/hw/m48t59.c b/hw/m48t59.c
index 6d2f9cf..7dbff94 100644
--- a/hw/m48t59.c
+++ b/hw/m48t59.c
@@ -691,7 +691,7 @@ M48t59State *m48t59_init_isa(ISABus *bus, uint32_t io_base, uint16_t size,
return s;
}
-static void m48t59_init_common(M48t59State *s)
+static void m48t59_realize_common(M48t59State *s, Error **err)
{
s->buffer = g_malloc0(s->size);
if (s->model == 59) {
@@ -703,15 +703,14 @@ static void m48t59_init_common(M48t59State *s)
vmstate_register(NULL, -1, &vmstate_m48t59, s);
}
-static int m48t59_init_isa1(ISADevice *dev)
+static void m48t59_isa_realize(DeviceState *dev, Error **err)
{
+ ISADevice *isadev = ISA_DEVICE(dev);
M48t59ISAState *d = M48T59_ISA(dev);
M48t59State *s = &d->state;
- isa_init_irq(dev, &s->IRQ, 8);
- m48t59_init_common(s);
-
- return 0;
+ isa_init_irq(isadev, &s->IRQ, 8);
+ m48t59_realize_common(s, err);
}
static int m48t59_init1(SysBusDevice *dev)
@@ -723,7 +722,7 @@ static int m48t59_init1(SysBusDevice *dev)
memory_region_init_io(&s->iomem, &nvram_ops, s, "m48t59.nvram", s->size);
sysbus_init_mmio(dev, &s->iomem);
- m48t59_init_common(s);
+ m48t59_realize_common(s, NULL);
return 0;
}
@@ -738,8 +737,8 @@ static Property m48t59_isa_properties[] = {
static void m48t59_isa_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
- ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
- ic->init = m48t59_init_isa1;
+
+ dc->realize = m48t59_isa_realize;
dc->no_user = 1;
dc->reset = m48t59_reset_isa;
dc->props = m48t59_isa_properties;
diff --git a/hw/mc146818rtc.c b/hw/mc146818rtc.c
index c87b7f6..fa9c8ac 100644
--- a/hw/mc146818rtc.c
+++ b/hw/mc146818rtc.c
@@ -803,8 +803,9 @@ static void rtc_get_date(Object *obj, Visitor *v, void *opaque,
visit_end_struct(v, errp);
}
-static int rtc_initfn(ISADevice *dev)
+static void rtc_realizefn(DeviceState *dev, Error **err)
{
+ ISADevice *isadev = ISA_DEVICE(dev);
RTCState *s = MC146818_RTC(dev);
int base = 0x70;
@@ -825,7 +826,7 @@ static int rtc_initfn(ISADevice *dev)
s->base_year = 0;
}
- rtc_set_date_from_host(dev);
+ rtc_set_date_from_host(isadev);
#ifdef TARGET_I386
switch (s->lost_tick_policy) {
@@ -836,7 +837,8 @@ static int rtc_initfn(ISADevice *dev)
case LOST_TICK_DISCARD:
break;
default:
- return -EINVAL;
+ error_setg(err, "Invalid lost tick policy.");
+ return;
}
#endif
@@ -851,15 +853,13 @@ static int rtc_initfn(ISADevice *dev)
qemu_register_suspend_notifier(&s->suspend_notifier);
memory_region_init_io(&s->io, &cmos_ops, s, "rtc", 2);
- isa_register_ioport(dev, &s->io, base);
+ isa_register_ioport(isadev, &s->io, base);
- qdev_set_legacy_instance_id(&dev->qdev, base, 3);
+ qdev_set_legacy_instance_id(dev, base, 3);
qemu_register_reset(rtc_reset, s);
object_property_add(OBJECT(s), "date", "struct tm",
rtc_get_date, NULL, NULL, s, NULL);
-
- return 0;
}
ISADevice *rtc_init(ISABus *bus, int base_year, qemu_irq intercept_irq)
@@ -891,8 +891,8 @@ static Property mc146818rtc_properties[] = {
static void rtc_class_initfn(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
- ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
- ic->init = rtc_initfn;
+
+ dc->realize = rtc_realizefn;
dc->no_user = 1;
dc->vmsd = &vmstate_rtc;
dc->props = mc146818rtc_properties;
diff --git a/hw/ne2000-isa.c b/hw/ne2000-isa.c
index 5aabe7c..5fbf3cf 100644
--- a/hw/ne2000-isa.c
+++ b/hw/ne2000-isa.c
@@ -66,24 +66,23 @@ static const VMStateDescription vmstate_isa_ne2000 = {
}
};
-static int isa_ne2000_initfn(ISADevice *dev)
+static void isa_ne2000_realizefn(DeviceState *dev, Error **err)
{
+ ISADevice *isadev = ISA_DEVICE(dev);
ISANE2000State *isa = ISA_NE2000(dev);
NE2000State *s = &isa->ne2000;
ne2000_setup_io(s, 0x20);
- isa_register_ioport(dev, &s->io, isa->iobase);
+ isa_register_ioport(isadev, &s->io, isa->iobase);
- isa_init_irq(dev, &s->irq, isa->isairq);
+ isa_init_irq(isadev, &s->irq, isa->isairq);
qemu_macaddr_default_if_unset(&s->c.macaddr);
ne2000_reset(s);
s->nic = qemu_new_nic(&net_ne2000_isa_info, &s->c,
- object_get_typename(OBJECT(dev)), dev->qdev.id, s);
+ object_get_typename(OBJECT(dev)), dev->id, s);
qemu_format_nic_info_str(&s->nic->nc, s->c.macaddr.a);
-
- return 0;
}
static Property ne2000_isa_properties[] = {
@@ -96,8 +95,8 @@ static Property ne2000_isa_properties[] = {
static void isa_ne2000_class_initfn(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
- ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
- ic->init = isa_ne2000_initfn;
+
+ dc->realize = isa_ne2000_realizefn;
dc->props = ne2000_isa_properties;
}
diff --git a/hw/parallel.c b/hw/parallel.c
index 65447d3..a01f6e5 100644
--- a/hw/parallel.c
+++ b/hw/parallel.c
@@ -477,29 +477,35 @@ static const MemoryRegionPortio isa_parallel_portio_sw_list[] = {
PORTIO_END_OF_LIST(),
};
-static int parallel_isa_initfn(ISADevice *dev)
+static void parallel_isa_realizefn(DeviceState *dev, Error **err)
{
static int index;
+ ISADevice *isadev = ISA_DEVICE(dev);
ISAParallelState *isa = ISA_PARALLEL(dev);
ParallelState *s = &isa->state;
int base;
uint8_t dummy;
if (!s->chr) {
- fprintf(stderr, "Can't create parallel device, empty char device\n");
- exit(1);
+ error_setg(err, "Can't create parallel device, empty char device\n");
+ return;
}
- if (isa->index == -1)
+ if (isa->index == -1) {
isa->index = index;
- if (isa->index >= MAX_PARALLEL_PORTS)
- return -1;
- if (isa->iobase == -1)
+ }
+ if (isa->index >= MAX_PARALLEL_PORTS) {
+ error_setg(err, "Max. supported number of parallel ports is %d.",
+ MAX_PARALLEL_PORTS);
+ return;
+ }
+ if (isa->iobase == -1) {
isa->iobase = isa_parallel_io[isa->index];
+ }
index++;
base = isa->iobase;
- isa_init_irq(dev, &s->irq, isa->isairq);
+ isa_init_irq(isadev, &s->irq, isa->isairq);
qemu_register_reset(parallel_reset, s);
if (qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_PP_READ_STATUS, &dummy) == 0) {
@@ -507,12 +513,11 @@ static int parallel_isa_initfn(ISADevice *dev)
s->status = dummy;
}
- isa_register_portio_list(dev, base,
+ isa_register_portio_list(isadev, base,
(s->hw_driver
? &isa_parallel_portio_hw_list[0]
: &isa_parallel_portio_sw_list[0]),
s, "parallel");
- return 0;
}
/* Memory mapped interface */
@@ -599,8 +604,8 @@ static Property parallel_isa_properties[] = {
static void parallel_isa_class_initfn(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
- ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
- ic->init = parallel_isa_initfn;
+
+ dc->realize = parallel_isa_realizefn;
dc->props = parallel_isa_properties;
}
diff --git a/hw/pc.c b/hw/pc.c
index e878106..90915a7 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -484,22 +484,22 @@ static const MemoryRegionOps port92_ops = {
.endianness = DEVICE_LITTLE_ENDIAN,
};
-static int port92_initfn(ISADevice *dev)
+static void port92_realizefn(DeviceState *dev, Error **err)
{
+ ISADevice *isadev = ISA_DEVICE(dev);
Port92State *s = PORT92(dev);
memory_region_init_io(&s->io, &port92_ops, s, "port92", 1);
- isa_register_ioport(dev, &s->io, 0x92);
+ isa_register_ioport(isadev, &s->io, 0x92);
s->outport = 0;
- return 0;
}
static void port92_class_initfn(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
- ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
- ic->init = port92_initfn;
+
+ dc->realize = port92_realizefn;
dc->no_user = 1;
dc->reset = port92_reset;
dc->vmsd = &vmstate_port92_isa;
diff --git a/hw/pckbd.c b/hw/pckbd.c
index a3291ec..4b2b67b 100644
--- a/hw/pckbd.c
+++ b/hw/pckbd.c
@@ -489,31 +489,31 @@ static const MemoryRegionOps i8042_cmd_ops = {
.endianness = DEVICE_LITTLE_ENDIAN,
};
-static int i8042_initfn(ISADevice *dev)
+static void i8042_realizefn(DeviceState *dev, Error **err)
{
+ ISADevice *isadev = ISA_DEVICE(dev);
ISAKBDState *isa_s = I8042(dev);
KBDState *s = &isa_s->kbd;
- isa_init_irq(dev, &s->irq_kbd, 1);
- isa_init_irq(dev, &s->irq_mouse, 12);
+ isa_init_irq(isadev, &s->irq_kbd, 1);
+ isa_init_irq(isadev, &s->irq_mouse, 12);
memory_region_init_io(isa_s->io + 0, &i8042_data_ops, s, "i8042-data", 1);
- isa_register_ioport(dev, isa_s->io + 0, 0x60);
+ isa_register_ioport(isadev, isa_s->io + 0, 0x60);
memory_region_init_io(isa_s->io + 1, &i8042_cmd_ops, s, "i8042-cmd", 1);
- isa_register_ioport(dev, isa_s->io + 1, 0x64);
+ isa_register_ioport(isadev, isa_s->io + 1, 0x64);
s->kbd = ps2_kbd_init(kbd_update_kbd_irq, s);
s->mouse = ps2_mouse_init(kbd_update_aux_irq, s);
qemu_register_reset(kbd_reset, s);
- return 0;
}
static void i8042_class_initfn(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
- ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
- ic->init = i8042_initfn;
+
+ dc->realize = i8042_realizefn;
dc->no_user = 1;
dc->vmsd = &vmstate_kbd_isa;
}
diff --git a/hw/pcspk.c b/hw/pcspk.c
index f800962..abc72be 100644
--- a/hw/pcspk.c
+++ b/hw/pcspk.c
@@ -162,16 +162,15 @@ static const MemoryRegionOps pcspk_io_ops = {
},
};
-static int pcspk_initfn(ISADevice *dev)
+static void pcspk_realizefn(DeviceState *dev, Error **err)
{
+ ISADevice *isadev = ISA_DEVICE(dev);
PCSpkState *s = PC_SPEAKER(dev);
memory_region_init_io(&s->ioport, &pcspk_io_ops, s, "elcr", 1);
- isa_register_ioport(dev, &s->ioport, s->iobase);
+ isa_register_ioport(isadev, &s->ioport, s->iobase);
pcspk_state = s;
-
- return 0;
}
static Property pcspk_properties[] = {
@@ -183,9 +182,8 @@ static Property pcspk_properties[] = {
static void pcspk_class_initfn(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
- ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
- ic->init = pcspk_initfn;
+ dc->realize = pcspk_realizefn;
dc->no_user = 1;
dc->props = pcspk_properties;
}
diff --git a/hw/sb16.c b/hw/sb16.c
index b7e93a4..c72bbcb 100644
--- a/hw/sb16.c
+++ b/hw/sb16.c
@@ -1356,12 +1356,19 @@ static const MemoryRegionPortio sb16_ioport_list[] = {
};
-static int sb16_initfn (ISADevice *dev)
+static void sb16_initfn (Object *obj)
{
- SB16State *s = SB16 (dev);
+ SB16State *s = SB16 (obj);
s->cmd = -1;
- isa_init_irq (dev, &s->pic, s->irq);
+}
+
+static void sb16_realizefn (DeviceState *dev, Error **err)
+{
+ ISADevice *isadev = ISA_DEVICE (dev);
+ SB16State *s = SB16 (dev);
+
+ isa_init_irq (isadev, &s->pic, s->irq);
s->mixer_regs[0x80] = magic_of_irq (s->irq);
s->mixer_regs[0x81] = (1 << s->dma) | (1 << s->hdma);
@@ -1376,14 +1383,13 @@ static int sb16_initfn (ISADevice *dev)
dolog ("warning: Could not create auxiliary timer\n");
}
- isa_register_portio_list (dev, s->port, sb16_ioport_list, s, "sb16");
+ isa_register_portio_list (isadev, s->port, sb16_ioport_list, s, "sb16");
DMA_register_channel (s->hdma, SB_read_DMA, s);
DMA_register_channel (s->dma, SB_read_DMA, s);
s->can_write = 1;
AUD_register_card ("sb16", &s->card);
- return 0;
}
int SB16_init (ISABus *bus)
@@ -1404,8 +1410,8 @@ static Property sb16_properties[] = {
static void sb16_class_initfn (ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS (klass);
- ISADeviceClass *ic = ISA_DEVICE_CLASS (klass);
- ic->init = sb16_initfn;
+
+ dc->realize = sb16_realizefn;
dc->desc = "Creative Sound Blaster 16";
dc->vmsd = &vmstate_sb16;
dc->props = sb16_properties;
@@ -1415,6 +1421,7 @@ static const TypeInfo sb16_info = {
.name = TYPE_SB16,
.parent = TYPE_ISA_DEVICE,
.instance_size = sizeof (SB16State),
+ .instance_init = sb16_initfn,
.class_init = sb16_class_initfn,
};
diff --git a/hw/serial-isa.c b/hw/serial-isa.c
index 904cc41..455f07b 100644
--- a/hw/serial-isa.c
+++ b/hw/serial-isa.c
@@ -44,9 +44,10 @@ static const int isa_serial_irq[MAX_SERIAL_PORTS] = {
4, 3, 4, 3
};
-static int serial_isa_initfn(ISADevice *dev)
+static void serial_isa_realizefn(DeviceState *dev, Error **err)
{
static int index;
+ ISADevice *isadev = ISA_DEVICE(dev);
ISASerialState *isa = ISA_SERIAL(dev);
SerialState *s = &isa->state;
@@ -54,7 +55,9 @@ static int serial_isa_initfn(ISADevice *dev)
isa->index = index;
}
if (isa->index >= MAX_SERIAL_PORTS) {
- return -1;
+ error_setg(err, "Max. supported number of ISA serial ports is %d.",
+ MAX_SERIAL_PORTS);
+ return;
}
if (isa->iobase == -1) {
isa->iobase = isa_serial_io[isa->index];
@@ -65,13 +68,12 @@ static int serial_isa_initfn(ISADevice *dev)
index++;
s->baudbase = 115200;
- isa_init_irq(dev, &s->irq, isa->isairq);
- serial_init_core(s);
- qdev_set_legacy_instance_id(&dev->qdev, isa->iobase, 3);
+ isa_init_irq(isadev, &s->irq, isa->isairq);
+ serial_realize_core(s, err);
+ qdev_set_legacy_instance_id(dev, isa->iobase, 3);
memory_region_init_io(&s->io, &serial_io_ops, s, "serial", 8);
- isa_register_ioport(dev, &s->io, isa->iobase);
- return 0;
+ isa_register_ioport(isadev, &s->io, isa->iobase);
}
static const VMStateDescription vmstate_isa_serial = {
@@ -96,8 +98,8 @@ static Property serial_isa_properties[] = {
static void serial_isa_class_initfn(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
- ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
- ic->init = serial_isa_initfn;
+
+ dc->realize = serial_isa_realizefn;
dc->vmsd = &vmstate_isa_serial;
dc->props = serial_isa_properties;
}
diff --git a/hw/serial-pci.c b/hw/serial-pci.c
index 95dc5c8..25b4126 100644
--- a/hw/serial-pci.c
+++ b/hw/serial-pci.c
@@ -51,7 +51,7 @@ static int serial_pci_init(PCIDevice *dev)
SerialState *s = &pci->state;
s->baudbase = 115200;
- serial_init_core(s);
+ serial_realize_core(s, NULL);
pci->dev.config[PCI_INTERRUPT_PIN] = 0x01;
s->irq = pci->dev.irq[0];
@@ -102,7 +102,7 @@ static int multi_serial_pci_init(PCIDevice *dev)
for (i = 0; i < pci->ports; i++) {
s = pci->state + i;
s->baudbase = 115200;
- serial_init_core(s);
+ serial_realize_core(s, NULL);
s->irq = pci->irqs[i];
pci->name[i] = g_strdup_printf("uart #%d", i+1);
memory_region_init_io(&s->io, &serial_io_ops, s, pci->name[i], 8);
diff --git a/hw/serial.c b/hw/serial.c
index 07a2a11..0b30b99 100644
--- a/hw/serial.c
+++ b/hw/serial.c
@@ -676,7 +676,7 @@ static void serial_reset(void *opaque)
qemu_irq_lower(s->irq);
}
-void serial_init_core(SerialState *s)
+void serial_realize_core(SerialState *s, Error **err)
{
if (!s->chr) {
fprintf(stderr, "Can't create serial device, empty char device\n");
@@ -727,7 +727,7 @@ SerialState *serial_init(int base, qemu_irq irq, int baudbase,
s->irq = irq;
s->baudbase = baudbase;
s->chr = chr;
- serial_init_core(s);
+ serial_realize_core(s, NULL);
vmstate_register(NULL, base, &vmstate_serial, s);
@@ -785,7 +785,7 @@ SerialState *serial_mm_init(MemoryRegion *address_space,
s->baudbase = baudbase;
s->chr = chr;
- serial_init_core(s);
+ serial_realize_core(s, NULL);
vmstate_register(NULL, base, &vmstate_serial, s);
memory_region_init_io(&s->io, &serial_mm_ops[end], s,
diff --git a/hw/serial.h b/hw/serial.h
index bb06366..2d00554 100644
--- a/hw/serial.h
+++ b/hw/serial.h
@@ -83,7 +83,7 @@ struct SerialState {
extern const VMStateDescription vmstate_serial;
extern const MemoryRegionOps serial_io_ops;
-void serial_init_core(SerialState *s);
+void serial_realize_core(SerialState *s, Error **err);
void serial_exit_core(SerialState *s);
void serial_set_frequency(SerialState *s, uint32_t frequency);
diff --git a/hw/sga.c b/hw/sga.c
index d828f45..2f488d9 100644
--- a/hw/sga.c
+++ b/hw/sga.c
@@ -38,17 +38,16 @@ typedef struct ISASGAState {
ISADevice parent_obj;
} ISASGAState;
-static int sga_initfn(ISADevice *dev)
+static void sga_realizefn(DeviceState *dev, Error **err)
{
rom_add_vga(SGABIOS_FILENAME);
- return 0;
}
static void sga_class_initfn(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
- ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
- ic->init = sga_initfn;
+
+ dc->realize = sga_realizefn;
dc->desc = "Serial Graphics Adapter";
}
diff --git a/hw/vga-isa.c b/hw/vga-isa.c
index f177c48..19d6e99 100644
--- a/hw/vga-isa.c
+++ b/hw/vga-isa.c
@@ -48,31 +48,31 @@ static void vga_isa_reset(DeviceState *dev)
vga_common_reset(s);
}
-static int vga_initfn(ISADevice *dev)
+static void vga_isa_realizefn(DeviceState *dev, Error **err)
{
+ ISADevice *isadev = ISA_DEVICE(dev);
ISAVGAState *d = ISA_VGA(dev);
VGACommonState *s = &d->state;
MemoryRegion *vga_io_memory;
const MemoryRegionPortio *vga_ports, *vbe_ports;
vga_common_init(s);
- s->legacy_address_space = isa_address_space(dev);
+ s->legacy_address_space = isa_address_space(isadev);
vga_io_memory = vga_init_io(s, &vga_ports, &vbe_ports);
- isa_register_portio_list(dev, 0x3b0, vga_ports, s, "vga");
+ isa_register_portio_list(isadev, 0x3b0, vga_ports, s, "vga");
if (vbe_ports) {
- isa_register_portio_list(dev, 0x1ce, vbe_ports, s, "vbe");
+ isa_register_portio_list(isadev, 0x1ce, vbe_ports, s, "vbe");
}
- memory_region_add_subregion_overlap(isa_address_space(dev),
+ memory_region_add_subregion_overlap(isa_address_space(isadev),
isa_mem_base + 0x000a0000,
vga_io_memory, 1);
memory_region_set_coalescing(vga_io_memory);
s->ds = graphic_console_init(s->update, s->invalidate,
s->screen_dump, s->text_update, s);
- vga_init_vbe(s, isa_address_space(dev));
+ vga_init_vbe(s, isa_address_space(isadev));
/* ROM BIOS */
rom_add_vga(VGABIOS_FILENAME);
- return 0;
}
static Property vga_isa_properties[] = {
@@ -83,9 +83,8 @@ static Property vga_isa_properties[] = {
static void vga_isa_class_initfn(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
- ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
- ic->init = vga_initfn;
+ dc->realize = vga_isa_realizefn;
dc->reset = vga_isa_reset;
dc->vmsd = &vmstate_vga_common;
dc->props = vga_isa_properties;
diff --git a/hw/vmmouse.c b/hw/vmmouse.c
index 7c7c4e4..2e05ccb 100644
--- a/hw/vmmouse.c
+++ b/hw/vmmouse.c
@@ -262,7 +262,7 @@ static void vmmouse_reset(DeviceState *d)
vmmouse_disable(s);
}
-static int vmmouse_initfn(ISADevice *dev)
+static void vmmouse_realizefn(DeviceState *dev, Error **err)
{
VMMouseState *s = VMMOUSE(dev);
@@ -271,8 +271,6 @@ static int vmmouse_initfn(ISADevice *dev)
vmport_register(VMMOUSE_STATUS, vmmouse_ioport_read, s);
vmport_register(VMMOUSE_COMMAND, vmmouse_ioport_read, s);
vmport_register(VMMOUSE_DATA, vmmouse_ioport_read, s);
-
- return 0;
}
static Property vmmouse_properties[] = {
@@ -283,8 +281,8 @@ static Property vmmouse_properties[] = {
static void vmmouse_class_initfn(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
- ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
- ic->init = vmmouse_initfn;
+
+ dc->realize = vmmouse_realizefn;
dc->no_user = 1;
dc->reset = vmmouse_reset;
dc->vmsd = &vmstate_vmmouse;
diff --git a/hw/vmport.c b/hw/vmport.c
index ec36d47..70daffa 100644
--- a/hw/vmport.c
+++ b/hw/vmport.c
@@ -137,25 +137,25 @@ static const MemoryRegionOps vmport_ops = {
.endianness = DEVICE_LITTLE_ENDIAN,
};
-static int vmport_initfn(ISADevice *dev)
+static void vmport_realizefn(DeviceState *dev, Error **err)
{
+ ISADevice *isadev = ISA_DEVICE(dev);
VMPortState *s = VMPORT(dev);
memory_region_init_io(&s->io, &vmport_ops, s, "vmport", 1);
- isa_register_ioport(dev, &s->io, 0x5658);
+ isa_register_ioport(isadev, &s->io, 0x5658);
port_state = s;
/* Register some generic port commands */
vmport_register(VMPORT_CMD_GETVERSION, vmport_cmd_get_version, NULL);
vmport_register(VMPORT_CMD_GETRAMSIZE, vmport_cmd_ram_size, NULL);
- return 0;
}
static void vmport_class_initfn(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
- ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
- ic->init = vmport_initfn;
+
+ dc->realize = vmport_realizefn;
dc->no_user = 1;
}
diff --git a/hw/wdt_ib700.c b/hw/wdt_ib700.c
index 1365898..9209307 100644
--- a/hw/wdt_ib700.c
+++ b/hw/wdt_ib700.c
@@ -97,7 +97,7 @@ static const VMStateDescription vmstate_ib700 = {
}
};
-static int wdt_ib700_init(ISADevice *dev)
+static void wdt_ib700_realize(DeviceState *dev, Error **err)
{
IB700State *s = IB700(dev);
@@ -106,8 +106,6 @@ static int wdt_ib700_init(ISADevice *dev)
s->timer = qemu_new_timer_ns(vm_clock, ib700_timer_expired, s);
register_ioport_write(0x441, 2, 1, ib700_write_disable_reg, s);
register_ioport_write(0x443, 2, 1, ib700_write_enable_reg, s);
-
- return 0;
}
static void wdt_ib700_reset(DeviceState *dev)
@@ -127,8 +125,8 @@ static WatchdogTimerModel model = {
static void wdt_ib700_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
- ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
- ic->init = wdt_ib700_init;
+
+ dc->realize = wdt_ib700_realize;
dc->reset = wdt_ib700_reset;
dc->vmsd = &vmstate_ib700;
}
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [Qemu-devel] [RFC 29/34] i8254: QOM'ify
2012-11-26 0:12 [Qemu-devel] [RFC 00/34] QOM realize, device-only plus ISA conversion Andreas Färber
` (27 preceding siblings ...)
2012-11-26 0:12 ` [Qemu-devel] [RFC 28/34] isa: Use realizefn for ISADevice Andreas Färber
@ 2012-11-26 0:12 ` Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 30/34] kvm/i8254: QOM'ify some more Andreas Färber
` (6 subsequent siblings)
35 siblings, 0 replies; 46+ messages in thread
From: Andreas Färber @ 2012-11-26 0:12 UTC (permalink / raw)
To: qemu-devel; +Cc: Andreas Färber, anthony
Introduce type constant and avoid DO_UPCAST().
Prepares for PIT realizefn.
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
hw/i8254.c | 6 +++---
hw/i8254.h | 4 +++-
2 Dateien geändert, 6 Zeilen hinzugefügt(+), 4 Zeilen entfernt(-)
diff --git a/hw/i8254.c b/hw/i8254.c
index bea5f92..2a01217 100644
--- a/hw/i8254.c
+++ b/hw/i8254.c
@@ -265,7 +265,7 @@ static void pit_irq_timer(void *opaque)
static void pit_reset(DeviceState *dev)
{
- PITCommonState *pit = DO_UPCAST(PITCommonState, dev.qdev, dev);
+ PITCommonState *pit = PIT_COMMON(dev);
PITChannelState *s;
pit_reset_common(pit);
@@ -347,8 +347,8 @@ static void pit_class_initfn(ObjectClass *klass, void *data)
dc->props = pit_properties;
}
-static TypeInfo pit_info = {
- .name = "isa-pit",
+static const TypeInfo pit_info = {
+ .name = TYPE_I8254,
.parent = TYPE_PIT_COMMON,
.instance_size = sizeof(PITCommonState),
.class_init = pit_class_initfn,
diff --git a/hw/i8254.h b/hw/i8254.h
index ba6b598..2566bac 100644
--- a/hw/i8254.h
+++ b/hw/i8254.h
@@ -37,12 +37,14 @@ typedef struct PITChannelInfo {
int out;
} PITChannelInfo;
+#define TYPE_I8254 "isa-pit"
+
static inline ISADevice *pit_init(ISABus *bus, int base, int isa_irq,
qemu_irq alt_irq)
{
ISADevice *dev;
- dev = isa_create(bus, "isa-pit");
+ dev = isa_create(bus, TYPE_I8254);
qdev_prop_set_uint32(&dev->qdev, "iobase", base);
qdev_init_nofail(&dev->qdev);
qdev_connect_gpio_out(&dev->qdev, 0,
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [Qemu-devel] [RFC 30/34] kvm/i8254: QOM'ify some more
2012-11-26 0:12 [Qemu-devel] [RFC 00/34] QOM realize, device-only plus ISA conversion Andreas Färber
` (28 preceding siblings ...)
2012-11-26 0:12 ` [Qemu-devel] [RFC 29/34] i8254: QOM'ify Andreas Färber
@ 2012-11-26 0:12 ` Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 31/34] i8254: Convert PITCommonState to QOM realizefn Andreas Färber
` (5 subsequent siblings)
35 siblings, 0 replies; 46+ messages in thread
From: Andreas Färber @ 2012-11-26 0:12 UTC (permalink / raw)
To: qemu-devel; +Cc: Andreas Färber, anthony
Introduce type constant and cast macro to obsolete DO_UPCAST().
Prepares for PIT realizefn.
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
hw/i8254.h | 3 ++-
hw/kvm/i8254.c | 21 ++++++++++++---------
2 Dateien geändert, 14 Zeilen hinzugefügt(+), 10 Zeilen entfernt(-)
diff --git a/hw/i8254.h b/hw/i8254.h
index 2566bac..cfa8dc9 100644
--- a/hw/i8254.h
+++ b/hw/i8254.h
@@ -38,6 +38,7 @@ typedef struct PITChannelInfo {
} PITChannelInfo;
#define TYPE_I8254 "isa-pit"
+#define TYPE_KVM_I8254 "kvm-pit"
static inline ISADevice *pit_init(ISABus *bus, int base, int isa_irq,
qemu_irq alt_irq)
@@ -57,7 +58,7 @@ static inline ISADevice *kvm_pit_init(ISABus *bus, int base)
{
ISADevice *dev;
- dev = isa_create(bus, "kvm-pit");
+ dev = isa_create(bus, TYPE_KVM_I8254);
qdev_prop_set_uint32(&dev->qdev, "iobase", base);
qdev_init_nofail(&dev->qdev);
diff --git a/hw/kvm/i8254.c b/hw/kvm/i8254.c
index 53d13e3..420d5ad 100644
--- a/hw/kvm/i8254.c
+++ b/hw/kvm/i8254.c
@@ -32,8 +32,11 @@
#define CALIBRATION_ROUNDS 3
+#define KVM_PIT(obj) OBJECT_CHECK(KVMPITState, (obj), TYPE_KVM_I8254)
+
typedef struct KVMPITState {
- PITCommonState pit;
+ PITCommonState parent_obj;
+
LostTickPolicy lost_tick_policy;
bool vm_stopped;
int64_t kernel_clock_offset;
@@ -70,7 +73,7 @@ static void kvm_pit_update_clock_offset(KVMPITState *s)
static void kvm_pit_get(PITCommonState *pit)
{
- KVMPITState *s = DO_UPCAST(KVMPITState, pit, pit);
+ KVMPITState *s = KVM_PIT(pit);
struct kvm_pit_state2 kpit;
struct kvm_pit_channel_state *kchan;
struct PITChannelState *sc;
@@ -124,7 +127,7 @@ static void kvm_pit_get(PITCommonState *pit)
static void kvm_pit_put(PITCommonState *pit)
{
- KVMPITState *s = DO_UPCAST(KVMPITState, pit, pit);
+ KVMPITState *s = KVM_PIT(pit);
struct kvm_pit_state2 kpit;
struct kvm_pit_channel_state *kchan;
struct PITChannelState *sc;
@@ -200,7 +203,7 @@ static void kvm_pit_get_channel_info(PITCommonState *s, PITChannelState *sc,
static void kvm_pit_reset(DeviceState *dev)
{
- PITCommonState *s = DO_UPCAST(PITCommonState, dev.qdev, dev);
+ PITCommonState *s = PIT_COMMON(dev);
pit_reset_common(s);
@@ -229,14 +232,14 @@ static void kvm_pit_vm_state_change(void *opaque, int running,
s->vm_stopped = false;
} else {
kvm_pit_update_clock_offset(s);
- kvm_pit_get(&s->pit);
+ kvm_pit_get(PIT_COMMON(s));
s->vm_stopped = true;
}
}
static int kvm_pit_initfn(PITCommonState *pit)
{
- KVMPITState *s = DO_UPCAST(KVMPITState, pit, pit);
+ KVMPITState *s = KVM_PIT(pit);
struct kvm_pit_config config = {
.flags = 0,
};
@@ -282,7 +285,7 @@ static int kvm_pit_initfn(PITCommonState *pit)
}
static Property kvm_pit_properties[] = {
- DEFINE_PROP_HEX32("iobase", KVMPITState, pit.iobase, -1),
+ DEFINE_PROP_HEX32("iobase", PITCommonState, iobase, -1),
DEFINE_PROP_LOSTTICKPOLICY("lost_tick_policy", KVMPITState,
lost_tick_policy, LOST_TICK_DELAY),
DEFINE_PROP_END_OF_LIST(),
@@ -302,8 +305,8 @@ static void kvm_pit_class_init(ObjectClass *klass, void *data)
dc->props = kvm_pit_properties;
}
-static TypeInfo kvm_pit_info = {
- .name = "kvm-pit",
+static const TypeInfo kvm_pit_info = {
+ .name = TYPE_KVM_I8254,
.parent = TYPE_PIT_COMMON,
.instance_size = sizeof(KVMPITState),
.class_init = kvm_pit_class_init,
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [Qemu-devel] [RFC 31/34] i8254: Convert PITCommonState to QOM realizefn
2012-11-26 0:12 [Qemu-devel] [RFC 00/34] QOM realize, device-only plus ISA conversion Andreas Färber
` (29 preceding siblings ...)
2012-11-26 0:12 ` [Qemu-devel] [RFC 30/34] kvm/i8254: QOM'ify some more Andreas Färber
@ 2012-11-26 0:12 ` Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 32/34] i8259: QOM'ify some more Andreas Färber
` (4 subsequent siblings)
35 siblings, 0 replies; 46+ messages in thread
From: Andreas Färber @ 2012-11-26 0:12 UTC (permalink / raw)
To: qemu-devel; +Cc: Andreas Färber, anthony
Instead of having the parent provide PITCommonClass::init,
let the children override DeviceClass::realize themselves.
This pushes the responsibility for saving and calling the parent's
realizefn to the children.
Signed-off-by: Andreas Färber <afaerber@suse.de>
Cc: Anthony Liguori <anthony@codemonkey.ws>
---
hw/i8254.c | 20 +++++++++++++++++---
hw/i8254_common.c | 8 --------
hw/i8254_internal.h | 1 -
hw/kvm/i8254.c | 38 +++++++++++++++++++++++++++-----------
4 Dateien geändert, 44 Zeilen hinzugefügt(+), 23 Zeilen entfernt(-)
diff --git a/hw/i8254.c b/hw/i8254.c
index 2a01217..6fa4825 100644
--- a/hw/i8254.c
+++ b/hw/i8254.c
@@ -35,6 +35,15 @@
#define RW_STATE_WORD0 3
#define RW_STATE_WORD1 4
+#define PIT_CLASS(class) OBJECT_CLASS_CHECK(PITClass, (class), TYPE_I8254)
+#define PIT_GET_CLASS(obj) OBJECT_GET_CLASS(PITClass, (obj), TYPE_I8254)
+
+typedef struct PITClass {
+ PITCommonClass parent_class;
+
+ DeviceRealize parent_realize;
+} PITClass;
+
static void pit_irq_timer_update(PITChannelState *s, int64_t current_time);
static int pit_get_count(PITChannelState *s)
@@ -313,8 +322,10 @@ static void pit_post_load(PITCommonState *s)
}
}
-static int pit_initfn(PITCommonState *pit)
+static void pit_realizefn(DeviceState *dev, Error **err)
{
+ PITCommonState *pit = PIT_COMMON(dev);
+ PITClass *pc = PIT_GET_CLASS(dev);
PITChannelState *s;
s = &pit->channels[0];
@@ -326,7 +337,7 @@ static int pit_initfn(PITCommonState *pit)
qdev_init_gpio_in(&pit->dev.qdev, pit_irq_control, 1);
- return 0;
+ pc->parent_realize(dev, err);
}
static Property pit_properties[] = {
@@ -336,10 +347,12 @@ static Property pit_properties[] = {
static void pit_class_initfn(ObjectClass *klass, void *data)
{
+ PITClass *pc = PIT_CLASS(klass);
PITCommonClass *k = PIT_COMMON_CLASS(klass);
DeviceClass *dc = DEVICE_CLASS(klass);
- k->init = pit_initfn;
+ pc->parent_realize = dc->realize;
+ dc->realize = pit_realizefn;
k->set_channel_gate = pit_set_channel_gate;
k->get_channel_info = pit_get_channel_info_common;
k->post_load = pit_post_load;
@@ -352,6 +365,7 @@ static const TypeInfo pit_info = {
.parent = TYPE_PIT_COMMON,
.instance_size = sizeof(PITCommonState),
.class_init = pit_class_initfn,
+ .class_size = sizeof(PITClass),
};
static void pit_register_types(void)
diff --git a/hw/i8254_common.c b/hw/i8254_common.c
index 1883405..3beb2cd 100644
--- a/hw/i8254_common.c
+++ b/hw/i8254_common.c
@@ -170,14 +170,6 @@ static void pit_common_realize(DeviceState *dev, Error **err)
{
ISADevice *isadev = ISA_DEVICE(dev);
PITCommonState *pit = PIT_COMMON(dev);
- PITCommonClass *c = PIT_COMMON_GET_CLASS(pit);
- int ret;
-
- ret = c->init(pit);
- if (ret < 0) {
- error_setg(err, "PIT init failed.");
- return;
- }
isa_register_ioport(isadev, &pit->ioports, pit->iobase);
diff --git a/hw/i8254_internal.h b/hw/i8254_internal.h
index 686f0c2..8cd4faa 100644
--- a/hw/i8254_internal.h
+++ b/hw/i8254_internal.h
@@ -68,7 +68,6 @@ typedef struct PITCommonState {
typedef struct PITCommonClass {
ISADeviceClass parent_class;
- int (*init)(PITCommonState *s);
void (*set_channel_gate)(PITCommonState *s, PITChannelState *sc, int val);
void (*get_channel_info)(PITCommonState *s, PITChannelState *sc,
PITChannelInfo *info);
diff --git a/hw/kvm/i8254.c b/hw/kvm/i8254.c
index 420d5ad..72d84e8 100644
--- a/hw/kvm/i8254.c
+++ b/hw/kvm/i8254.c
@@ -33,6 +33,10 @@
#define CALIBRATION_ROUNDS 3
#define KVM_PIT(obj) OBJECT_CHECK(KVMPITState, (obj), TYPE_KVM_I8254)
+#define KVM_PIT_CLASS(class) \
+ OBJECT_CLASS_CHECK(KVMPITClass, (class), TYPE_KVM_I8254)
+#define KVM_PIT_GET_CLASS(obj) \
+ OBJECT_GET_CLASS(KVMPITClass, (obj), TYPE_KVM_I8254)
typedef struct KVMPITState {
PITCommonState parent_obj;
@@ -42,6 +46,12 @@ typedef struct KVMPITState {
int64_t kernel_clock_offset;
} KVMPITState;
+typedef struct KVMPITClass {
+ PITCommonClass parent_class;
+
+ DeviceRealize parent_realize;
+} KVMPITClass;
+
static int64_t abs64(int64_t v)
{
return v < 0 ? -v : v;
@@ -237,8 +247,10 @@ static void kvm_pit_vm_state_change(void *opaque, int running,
}
}
-static int kvm_pit_initfn(PITCommonState *pit)
+static void kvm_pit_realizefn(DeviceState *dev, Error **err)
{
+ PITCommonState *pit = PIT_COMMON(dev);
+ KVMPITClass *kpc = KVM_PIT_GET_CLASS(dev);
KVMPITState *s = KVM_PIT(pit);
struct kvm_pit_config config = {
.flags = 0,
@@ -251,9 +263,9 @@ static int kvm_pit_initfn(PITCommonState *pit)
ret = kvm_vm_ioctl(kvm_state, KVM_CREATE_PIT);
}
if (ret < 0) {
- fprintf(stderr, "Create kernel PIC irqchip failed: %s\n",
- strerror(ret));
- return ret;
+ error_setg(err, "Create kernel PIC irqchip failed: %s\n",
+ strerror(ret));
+ return;
}
switch (s->lost_tick_policy) {
case LOST_TICK_DELAY:
@@ -264,15 +276,16 @@ static int kvm_pit_initfn(PITCommonState *pit)
ret = kvm_vm_ioctl(kvm_state, KVM_REINJECT_CONTROL, &control);
if (ret < 0) {
- fprintf(stderr,
- "Can't disable in-kernel PIT reinjection: %s\n",
- strerror(ret));
- return ret;
+ error_setg(err,
+ "Can't disable in-kernel PIT reinjection: %s\n",
+ strerror(ret));
+ return;
}
}
break;
default:
- return -EINVAL;
+ error_setg(err, "Lost tick policy not supported.");
+ return;
}
memory_region_init_reservation(&pit->ioports, "kvm-pit", 4);
@@ -281,7 +294,7 @@ static int kvm_pit_initfn(PITCommonState *pit)
qemu_add_vm_change_state_handler(kvm_pit_vm_state_change, s);
- return 0;
+ kpc->parent_realize(dev, err);
}
static Property kvm_pit_properties[] = {
@@ -293,10 +306,12 @@ static Property kvm_pit_properties[] = {
static void kvm_pit_class_init(ObjectClass *klass, void *data)
{
+ KVMPITClass *kpc = KVM_PIT_CLASS(klass);
PITCommonClass *k = PIT_COMMON_CLASS(klass);
DeviceClass *dc = DEVICE_CLASS(klass);
- k->init = kvm_pit_initfn;
+ kpc->parent_realize = dc->realize;
+ dc->realize = kvm_pit_realizefn;
k->set_channel_gate = kvm_pit_set_gate;
k->get_channel_info = kvm_pit_get_channel_info;
k->pre_save = kvm_pit_get;
@@ -310,6 +325,7 @@ static const TypeInfo kvm_pit_info = {
.parent = TYPE_PIT_COMMON,
.instance_size = sizeof(KVMPITState),
.class_init = kvm_pit_class_init,
+ .class_size = sizeof(KVMPITClass),
};
static void kvm_pit_register(void)
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [Qemu-devel] [RFC 32/34] i8259: QOM'ify some more
2012-11-26 0:12 [Qemu-devel] [RFC 00/34] QOM realize, device-only plus ISA conversion Andreas Färber
` (30 preceding siblings ...)
2012-11-26 0:12 ` [Qemu-devel] [RFC 31/34] i8254: Convert PITCommonState to QOM realizefn Andreas Färber
@ 2012-11-26 0:12 ` Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 33/34] kvm/i8259: " Andreas Färber
` (3 subsequent siblings)
35 siblings, 0 replies; 46+ messages in thread
From: Andreas Färber @ 2012-11-26 0:12 UTC (permalink / raw)
To: qemu-devel; +Cc: Andreas Färber, anthony
Introduce type constant.
Prepares for PIC realizefn.
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
hw/i8259.c | 23 ++++++++++++++---------
1 Datei geändert, 14 Zeilen hinzugefügt(+), 9 Zeilen entfernt(-)
diff --git a/hw/i8259.c b/hw/i8259.c
index 55c2cb9..e03db77 100644
--- a/hw/i8259.c
+++ b/hw/i8259.c
@@ -41,6 +41,8 @@
//#define DEBUG_IRQ_LATENCY
//#define DEBUG_IRQ_COUNT
+#define TYPE_I8259 "isa-i8259"
+
#if defined(DEBUG_PIC) || defined(DEBUG_IRQ_COUNT)
static int irq_level[16];
#endif
@@ -448,25 +450,28 @@ void irq_info(Monitor *mon)
qemu_irq *i8259_init(ISABus *bus, qemu_irq parent_irq)
{
qemu_irq *irq_set;
- ISADevice *dev;
+ DeviceState *dev;
+ ISADevice *isadev;
int i;
irq_set = g_malloc(ISA_NUM_IRQS * sizeof(qemu_irq));
- dev = i8259_init_chip("isa-i8259", bus, true);
+ isadev = i8259_init_chip(TYPE_I8259, bus, true);
+ dev = DEVICE(isadev);
- qdev_connect_gpio_out(&dev->qdev, 0, parent_irq);
+ qdev_connect_gpio_out(dev, 0, parent_irq);
for (i = 0 ; i < 8; i++) {
- irq_set[i] = qdev_get_gpio_in(&dev->qdev, i);
+ irq_set[i] = qdev_get_gpio_in(dev, i);
}
- isa_pic = &dev->qdev;
+ isa_pic = dev;
- dev = i8259_init_chip("isa-i8259", bus, false);
+ isadev = i8259_init_chip(TYPE_I8259, bus, false);
+ dev = DEVICE(isadev);
- qdev_connect_gpio_out(&dev->qdev, 0, irq_set[2]);
+ qdev_connect_gpio_out(dev, 0, irq_set[2]);
for (i = 0 ; i < 8; i++) {
- irq_set[i + 8] = qdev_get_gpio_in(&dev->qdev, i);
+ irq_set[i + 8] = qdev_get_gpio_in(dev, i);
}
slave_pic = PIC_COMMON(dev);
@@ -484,7 +489,7 @@ static void i8259_class_init(ObjectClass *klass, void *data)
}
static const TypeInfo i8259_info = {
- .name = "isa-i8259",
+ .name = TYPE_I8259,
.instance_size = sizeof(PICCommonState),
.parent = TYPE_PIC_COMMON,
.class_init = i8259_class_init,
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [Qemu-devel] [RFC 33/34] kvm/i8259: QOM'ify some more
2012-11-26 0:12 [Qemu-devel] [RFC 00/34] QOM realize, device-only plus ISA conversion Andreas Färber
` (31 preceding siblings ...)
2012-11-26 0:12 ` [Qemu-devel] [RFC 32/34] i8259: QOM'ify some more Andreas Färber
@ 2012-11-26 0:12 ` Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 34/34] i8259: Convert PICCommonState to use QOM realizefn Andreas Färber
` (2 subsequent siblings)
35 siblings, 0 replies; 46+ messages in thread
From: Andreas Färber @ 2012-11-26 0:12 UTC (permalink / raw)
To: qemu-devel; +Cc: Andreas Färber, anthony
Introduce type constant.
Prepares for PIC realizefn.
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
hw/kvm/i8259.c | 8 +++++---
1 Datei geändert, 5 Zeilen hinzugefügt(+), 3 Zeilen entfernt(-)
diff --git a/hw/kvm/i8259.c b/hw/kvm/i8259.c
index 2aaf14a..973cc08 100644
--- a/hw/kvm/i8259.c
+++ b/hw/kvm/i8259.c
@@ -13,6 +13,8 @@
#include "hw/apic_internal.h"
#include "kvm.h"
+#define TYPE_KVM_I8259 "kvm-i8259"
+
static void kvm_pic_get(PICCommonState *s)
{
struct kvm_irqchip chip;
@@ -106,8 +108,8 @@ static void kvm_pic_init(PICCommonState *s)
qemu_irq *kvm_i8259_init(ISABus *bus)
{
- i8259_init_chip("kvm-i8259", bus, true);
- i8259_init_chip("kvm-i8259", bus, false);
+ i8259_init_chip(TYPE_KVM_I8259, bus, true);
+ i8259_init_chip(TYPE_KVM_I8259, bus, false);
return qemu_allocate_irqs(kvm_pic_set_irq, NULL, ISA_NUM_IRQS);
}
@@ -124,7 +126,7 @@ static void kvm_i8259_class_init(ObjectClass *klass, void *data)
}
static const TypeInfo kvm_i8259_info = {
- .name = "kvm-i8259",
+ .name = TYPE_KVM_I8259,
.parent = TYPE_PIC_COMMON,
.instance_size = sizeof(PICCommonState),
.class_init = kvm_i8259_class_init,
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [Qemu-devel] [RFC 34/34] i8259: Convert PICCommonState to use QOM realizefn
2012-11-26 0:12 [Qemu-devel] [RFC 00/34] QOM realize, device-only plus ISA conversion Andreas Färber
` (32 preceding siblings ...)
2012-11-26 0:12 ` [Qemu-devel] [RFC 33/34] kvm/i8259: " Andreas Färber
@ 2012-11-26 0:12 ` Andreas Färber
2012-12-04 22:19 ` [Qemu-devel] [RFC 00/34] QOM realize, device-only plus ISA conversion Andreas Färber
2013-01-02 14:48 ` Anthony Liguori
35 siblings, 0 replies; 46+ messages in thread
From: Andreas Färber @ 2012-11-26 0:12 UTC (permalink / raw)
To: qemu-devel; +Cc: Andreas Färber, anthony
Instead of having the parent provide PICCommonClass::init,
let the children override DeviceClass::realize themselves.
This pushes the responsibility of saving and calling the parent's
realizefn to the children.
Signed-off-by: Andreas Färber <afaerber@suse.de>
Cc: Anthony Liguori <anthony@codemonkey.ws>
---
hw/i8259.c | 25 +++++++++++++++++++++----
hw/i8259_common.c | 3 ---
hw/i8259_internal.h | 2 +-
hw/kvm/i8259.c | 26 ++++++++++++++++++++++++--
4 Dateien geändert, 46 Zeilen hinzugefügt(+), 10 Zeilen entfernt(-)
diff --git a/hw/i8259.c b/hw/i8259.c
index e03db77..95b79dc 100644
--- a/hw/i8259.c
+++ b/hw/i8259.c
@@ -42,6 +42,18 @@
//#define DEBUG_IRQ_COUNT
#define TYPE_I8259 "isa-i8259"
+#define PIC_CLASS(class) OBJECT_CLASS_CHECK(PICClass, (class), TYPE_I8259)
+#define PIC_GET_CLASS(obj) OBJECT_GET_CLASS(PICClass, (obj), TYPE_I8259)
+
+/**
+ * PICClass:
+ * @parent_realize: The parent's realizefn.
+ */
+typedef struct PICClass {
+ PICCommonClass parent_class;
+
+ DeviceRealize parent_realize;
+} PICClass;
#if defined(DEBUG_PIC) || defined(DEBUG_IRQ_COUNT)
static int irq_level[16];
@@ -400,15 +412,18 @@ static const MemoryRegionOps pic_elcr_ioport_ops = {
},
};
-static void pic_init(PICCommonState *s)
+static void pic_realize(DeviceState *dev, Error **err)
{
- DeviceState *dev = DEVICE(s);
+ PICCommonState *s = PIC_COMMON(dev);
+ PICClass *pc = PIC_GET_CLASS(dev);
memory_region_init_io(&s->base_io, &pic_base_ioport_ops, s, "pic", 2);
memory_region_init_io(&s->elcr_io, &pic_elcr_ioport_ops, s, "elcr", 1);
qdev_init_gpio_out(dev, s->int_out, ARRAY_SIZE(s->int_out));
qdev_init_gpio_in(dev, pic_set_irq, 8);
+
+ pc->parent_realize(dev, err);
}
void pic_info(Monitor *mon)
@@ -481,10 +496,11 @@ qemu_irq *i8259_init(ISABus *bus, qemu_irq parent_irq)
static void i8259_class_init(ObjectClass *klass, void *data)
{
- PICCommonClass *k = PIC_COMMON_CLASS(klass);
+ PICClass *k = PIC_CLASS(klass);
DeviceClass *dc = DEVICE_CLASS(klass);
- k->init = pic_init;
+ k->parent_realize = dc->realize;
+ dc->realize = pic_realize;
dc->reset = pic_reset;
}
@@ -493,6 +509,7 @@ static const TypeInfo i8259_info = {
.instance_size = sizeof(PICCommonState),
.parent = TYPE_PIC_COMMON,
.class_init = i8259_class_init,
+ .class_size = sizeof(PICClass),
};
static void pic_register_types(void)
diff --git a/hw/i8259_common.c b/hw/i8259_common.c
index 0b8aae1..1dae6a8 100644
--- a/hw/i8259_common.c
+++ b/hw/i8259_common.c
@@ -69,9 +69,6 @@ static int pic_dispatch_post_load(void *opaque, int version_id)
static void pic_common_realize(DeviceState *dev, Error **err)
{
PICCommonState *s = PIC_COMMON(dev);
- PICCommonClass *info = PIC_COMMON_GET_CLASS(s);
-
- info->init(s);
isa_register_ioport(NULL, &s->base_io, s->iobase);
if (s->elcr_addr != -1) {
diff --git a/hw/i8259_internal.h b/hw/i8259_internal.h
index 32e48c3..e94ab6f 100644
--- a/hw/i8259_internal.h
+++ b/hw/i8259_internal.h
@@ -42,7 +42,7 @@ typedef struct PICCommonState PICCommonState;
typedef struct PICCommonClass
{
ISADeviceClass parent_class;
- void (*init)(PICCommonState *s);
+
void (*pre_save)(PICCommonState *s);
void (*post_load)(PICCommonState *s);
} PICCommonClass;
diff --git a/hw/kvm/i8259.c b/hw/kvm/i8259.c
index 973cc08..e1e99aa 100644
--- a/hw/kvm/i8259.c
+++ b/hw/kvm/i8259.c
@@ -14,6 +14,20 @@
#include "kvm.h"
#define TYPE_KVM_I8259 "kvm-i8259"
+#define KVM_PIC_CLASS(class) \
+ OBJECT_CLASS_CHECK(KVMPICClass, (class), TYPE_KVM_I8259)
+#define KVM_PIC_GET_CLASS(obj) \
+ OBJECT_GET_CLASS(KVMPICClass, (obj), TYPE_KVM_I8259)
+
+/**
+ * KVMPICClass:
+ * @parent_realize: The parent's realizefn.
+ */
+typedef struct KVMPICClass {
+ PICCommonClass parent_class;
+
+ DeviceRealize parent_realize;
+} KVMPICClass;
static void kvm_pic_get(PICCommonState *s)
{
@@ -100,10 +114,15 @@ static void kvm_pic_set_irq(void *opaque, int irq, int level)
apic_report_irq_delivered(delivered);
}
-static void kvm_pic_init(PICCommonState *s)
+static void kvm_pic_realize(DeviceState *dev, Error **err)
{
+ PICCommonState *s = PIC_COMMON(dev);
+ KVMPICClass *kpc = KVM_PIC_GET_CLASS(dev);
+
memory_region_init_reservation(&s->base_io, "kvm-pic", 2);
memory_region_init_reservation(&s->elcr_io, "kvm-elcr", 1);
+
+ kpc->parent_realize(dev, err);
}
qemu_irq *kvm_i8259_init(ISABus *bus)
@@ -116,11 +135,13 @@ qemu_irq *kvm_i8259_init(ISABus *bus)
static void kvm_i8259_class_init(ObjectClass *klass, void *data)
{
+ KVMPICClass *kpc = KVM_PIC_CLASS(klass);
PICCommonClass *k = PIC_COMMON_CLASS(klass);
DeviceClass *dc = DEVICE_CLASS(klass);
dc->reset = kvm_pic_reset;
- k->init = kvm_pic_init;
+ kpc->parent_realize = dc->realize;
+ dc->realize = kvm_pic_realize;
k->pre_save = kvm_pic_get;
k->post_load = kvm_pic_put;
}
@@ -130,6 +151,7 @@ static const TypeInfo kvm_i8259_info = {
.parent = TYPE_PIC_COMMON,
.instance_size = sizeof(PICCommonState),
.class_init = kvm_i8259_class_init,
+ .class_size = sizeof(KVMPICClass),
};
static void kvm_pic_register_types(void)
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* Re: [Qemu-devel] [PATCH 01/34] qdev: Eliminate qdev_free() in favor of QOM
2012-11-26 0:12 ` [Qemu-devel] [PATCH 01/34] qdev: Eliminate qdev_free() in favor of QOM Andreas Färber
@ 2012-11-26 7:20 ` Paolo Bonzini
2012-11-26 11:52 ` Andreas Färber
0 siblings, 1 reply; 46+ messages in thread
From: Paolo Bonzini @ 2012-11-26 7:20 UTC (permalink / raw)
To: Andreas Färber
Cc: X86, Michael S. Tsirkin, qemu-devel, anthony, Stefano Stabellini
Il 26/11/2012 01:12, Andreas Färber ha scritto:
> qdev_free() was trivially wrapping object_delete(). Inline it and drop
> the wrapper as a further step to QOM'ify qdev.
The reference counts of devices and buses are completely disconnected
from reality, and that's why object_delete() works.
I'd prefer this patch not to be applied until this is straightened out...
Paolo
> Signed-off-by: Andreas Färber <afaerber@suse.de>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> ---
> hw/acpi_piix4.c | 2 +-
> hw/pci-hotplug.c | 2 +-
> hw/pci_bridge.c | 2 +-
> hw/pcie.c | 2 +-
> hw/qdev-core.h | 1 -
> hw/qdev-monitor.c | 2 +-
> hw/qdev.c | 12 +++---------
> hw/scsi-bus.c | 4 ++--
> hw/shpc.c | 2 +-
> hw/usb/bus.c | 7 ++++---
> hw/usb/dev-storage.c | 2 +-
> hw/usb/host-linux.c | 2 +-
> hw/xen_platform.c | 2 +-
> 13 Dateien geändert, 18 Zeilen hinzugefügt(+), 24 Zeilen entfernt(-)
>
> diff --git a/hw/acpi_piix4.c b/hw/acpi_piix4.c
> index 0fa4c98..e6d09be 100644
> --- a/hw/acpi_piix4.c
> +++ b/hw/acpi_piix4.c
> @@ -361,7 +361,7 @@ static void acpi_piix_eject_slot(PIIX4PMState *s, unsigned slots)
> if (pc->no_hotplug) {
> slot_free = false;
> } else {
> - qdev_free(qdev);
> + object_delete(OBJECT(qdev));
> }
> }
> }
> diff --git a/hw/pci-hotplug.c b/hw/pci-hotplug.c
> index e7fb780..d766eab 100644
> --- a/hw/pci-hotplug.c
> +++ b/hw/pci-hotplug.c
> @@ -204,7 +204,7 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon,
> }
> dev = pci_create(bus, devfn, "virtio-blk-pci");
> if (qdev_prop_set_drive(&dev->qdev, "drive", dinfo->bdrv) < 0) {
> - qdev_free(&dev->qdev);
> + object_delete(OBJECT(dev));
> dev = NULL;
> break;
> }
> diff --git a/hw/pci_bridge.c b/hw/pci_bridge.c
> index 4680501..3689502 100644
> --- a/hw/pci_bridge.c
> +++ b/hw/pci_bridge.c
> @@ -347,7 +347,7 @@ void pci_bridge_exitfn(PCIDevice *pci_dev)
> pci_bridge_region_cleanup(s, s->windows);
> memory_region_destroy(&s->address_space_mem);
> memory_region_destroy(&s->address_space_io);
> - /* qbus_free() is called automatically by qdev_free() */
> + /* qbus_free() is called automatically by object_delete() */
> }
>
> /*
> diff --git a/hw/pcie.c b/hw/pcie.c
> index 7c92f19..24bfc95 100644
> --- a/hw/pcie.c
> +++ b/hw/pcie.c
> @@ -235,7 +235,7 @@ static int pcie_cap_slot_hotplug(DeviceState *qdev,
> PCI_EXP_SLTSTA_PDS);
> pcie_cap_slot_event(d, PCI_EXP_HP_EV_PDC);
> } else {
> - qdev_free(&pci_dev->qdev);
> + object_delete(OBJECT(pci_dev));
> pci_word_test_and_clear_mask(exp_cap + PCI_EXP_SLTSTA,
> PCI_EXP_SLTSTA_PDS);
> pcie_cap_slot_event(d, PCI_EXP_HP_EV_PDC);
> diff --git a/hw/qdev-core.h b/hw/qdev-core.h
> index fce9e22..36191e9 100644
> --- a/hw/qdev-core.h
> +++ b/hw/qdev-core.h
> @@ -158,7 +158,6 @@ void qdev_init_nofail(DeviceState *dev);
> void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id,
> int required_for_version);
> void qdev_unplug(DeviceState *dev, Error **errp);
> -void qdev_free(DeviceState *dev);
> int qdev_simple_unplug_cb(DeviceState *dev);
> void qdev_machine_creation_done(void);
> bool qdev_machine_modified(void);
> diff --git a/hw/qdev-monitor.c b/hw/qdev-monitor.c
> index 479eecd..d534b9d 100644
> --- a/hw/qdev-monitor.c
> +++ b/hw/qdev-monitor.c
> @@ -466,7 +466,7 @@ DeviceState *qdev_device_add(QemuOpts *opts)
> qdev->id = id;
> }
> if (qemu_opt_foreach(opts, set_property, qdev, 1) != 0) {
> - qdev_free(qdev);
> + object_delete(OBJECT(qdev));
> return NULL;
> }
> if (qdev->id) {
> diff --git a/hw/qdev.c b/hw/qdev.c
> index 7ddcd24..c2d9b48 100644
> --- a/hw/qdev.c
> +++ b/hw/qdev.c
> @@ -154,7 +154,7 @@ int qdev_init(DeviceState *dev)
>
> rc = dc->init(dev);
> if (rc < 0) {
> - qdev_free(dev);
> + object_delete(OBJECT(dev));
> return rc;
> }
>
> @@ -237,7 +237,7 @@ void qbus_reset_all_fn(void *opaque)
> int qdev_simple_unplug_cb(DeviceState *dev)
> {
> /* just zap it */
> - qdev_free(dev);
> + object_delete(OBJECT(dev));
> return 0;
> }
>
> @@ -259,12 +259,6 @@ void qdev_init_nofail(DeviceState *dev)
> }
> }
>
> -/* Unlink device from bus and free the structure. */
> -void qdev_free(DeviceState *dev)
> -{
> - object_delete(OBJECT(dev));
> -}
> -
> void qdev_machine_creation_done(void)
> {
> /*
> @@ -765,7 +759,7 @@ static void qbus_finalize(Object *obj)
>
> while ((kid = QTAILQ_FIRST(&bus->children)) != NULL) {
> DeviceState *dev = kid->child;
> - qdev_free(dev);
> + object_delete(OBJECT(dev));
> }
> if (bus->parent) {
> QLIST_REMOVE(bus, sibling);
> diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c
> index dfb2631..68a27eb 100644
> --- a/hw/scsi-bus.c
> +++ b/hw/scsi-bus.c
> @@ -175,7 +175,7 @@ static int scsi_qdev_init(DeviceState *qdev)
> d = scsi_device_find(bus, dev->channel, dev->id, dev->lun);
> assert(d);
> if (d->lun == dev->lun && dev != d) {
> - qdev_free(&d->qdev);
> + object_delete(OBJECT(d));
> }
> }
>
> @@ -222,7 +222,7 @@ SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv,
> qdev_prop_set_bit(dev, "removable", removable);
> }
> if (qdev_prop_set_drive(dev, "drive", bdrv) < 0) {
> - qdev_free(dev);
> + object_delete(OBJECT(dev));
> return NULL;
> }
> if (qdev_init(dev) < 0)
> diff --git a/hw/shpc.c b/hw/shpc.c
> index 4597bbd..24bdfb8 100644
> --- a/hw/shpc.c
> +++ b/hw/shpc.c
> @@ -253,7 +253,7 @@ static void shpc_free_devices_in_slot(SHPCDevice *shpc, int slot)
> ++devfn) {
> PCIDevice *affected_dev = shpc->sec_bus->devices[devfn];
> if (affected_dev) {
> - qdev_free(&affected_dev->qdev);
> + object_delete(OBJECT(affected_dev));
> }
> }
> }
> diff --git a/hw/usb/bus.c b/hw/usb/bus.c
> index 99aac7a..1675798 100644
> --- a/hw/usb/bus.c
> +++ b/hw/usb/bus.c
> @@ -337,8 +337,9 @@ void usb_port_location(USBPort *downstream, USBPort *upstream, int portnr)
>
> void usb_unregister_port(USBBus *bus, USBPort *port)
> {
> - if (port->dev)
> - qdev_free(&port->dev->qdev);
> + if (port->dev) {
> + object_delete(OBJECT(port->dev));
> + }
> QTAILQ_REMOVE(&bus->free, port, next);
> bus->nfree--;
> }
> @@ -458,7 +459,7 @@ int usb_device_delete_addr(int busnr, int addr)
> return -1;
> dev = port->dev;
>
> - qdev_free(&dev->qdev);
> + object_delete(OBJECT(dev));
> return 0;
> }
>
> diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c
> index 50af971..2efb4d5 100644
> --- a/hw/usb/dev-storage.c
> +++ b/hw/usb/dev-storage.c
> @@ -664,7 +664,7 @@ static USBDevice *usb_msd_init(USBBus *bus, const char *filename)
> return NULL;
> }
> if (qdev_prop_set_drive(&dev->qdev, "drive", dinfo->bdrv) < 0) {
> - qdev_free(&dev->qdev);
> + object_delete(OBJECT(dev));
> return NULL;
> }
> if (qdev_init(&dev->qdev) < 0)
> diff --git a/hw/usb/host-linux.c b/hw/usb/host-linux.c
> index aa77b77..a0417fc 100644
> --- a/hw/usb/host-linux.c
> +++ b/hw/usb/host-linux.c
> @@ -1584,7 +1584,7 @@ USBDevice *usb_host_device_open(USBBus *bus, const char *devname)
> return dev;
>
> fail:
> - qdev_free(&dev->qdev);
> + object_delete(OBJECT(dev));
> return NULL;
> }
>
> diff --git a/hw/xen_platform.c b/hw/xen_platform.c
> index a54e7a2..d56f3e5 100644
> --- a/hw/xen_platform.c
> +++ b/hw/xen_platform.c
> @@ -89,7 +89,7 @@ static void unplug_nic(PCIBus *b, PCIDevice *d, void *o)
> if (pci_get_word(d->config + PCI_CLASS_DEVICE) ==
> PCI_CLASS_NETWORK_ETHERNET
> && strcmp(d->name, "xen-pci-passthrough") != 0) {
> - qdev_free(&d->qdev);
> + object_delete(OBJECT(d));
> }
> }
>
>
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [Qemu-devel] [PATCH 01/34] qdev: Eliminate qdev_free() in favor of QOM
2012-11-26 7:20 ` Paolo Bonzini
@ 2012-11-26 11:52 ` Andreas Färber
2012-11-26 12:04 ` Paolo Bonzini
0 siblings, 1 reply; 46+ messages in thread
From: Andreas Färber @ 2012-11-26 11:52 UTC (permalink / raw)
To: Paolo Bonzini
Cc: Michael S. Tsirkin, qemu-devel, Anthony Liguori,
Stefano Stabellini
Am 26.11.2012 08:20, schrieb Paolo Bonzini:
> Il 26/11/2012 01:12, Andreas Färber ha scritto:
>> qdev_free() was trivially wrapping object_delete(). Inline it and drop
>> the wrapper as a further step to QOM'ify qdev.
>
> The reference counts of devices and buses are completely disconnected
> from reality, and that's why object_delete() works.
>
> I'd prefer this patch not to be applied until this is straightened out...
Your series is marked for-1.3 whereas this is for 1.4, so no obvious
problem there - wanted to mention the overlap in the cover letter but
apparently forgot.
My quest was to kill obsolete things with old "qdev" in the name. :)
I don't really mind if this becomes object_delete() or object_unref() or
anything else as long as it's not such a trivial qdev_* wrapper calling
one QOM object_* function.
Andreas
--
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [Qemu-devel] [PATCH 01/34] qdev: Eliminate qdev_free() in favor of QOM
2012-11-26 11:52 ` Andreas Färber
@ 2012-11-26 12:04 ` Paolo Bonzini
0 siblings, 0 replies; 46+ messages in thread
From: Paolo Bonzini @ 2012-11-26 12:04 UTC (permalink / raw)
To: Andreas Färber
Cc: Michael S. Tsirkin, qemu-devel, Anthony Liguori,
Stefano Stabellini
Il 26/11/2012 12:52, Andreas Färber ha scritto:
> Am 26.11.2012 08:20, schrieb Paolo Bonzini:
>> Il 26/11/2012 01:12, Andreas Färber ha scritto:
>>> qdev_free() was trivially wrapping object_delete(). Inline it and drop
>>> the wrapper as a further step to QOM'ify qdev.
>>
>> The reference counts of devices and buses are completely disconnected
>> from reality, and that's why object_delete() works.
>>
>> I'd prefer this patch not to be applied until this is straightened out...
>
> Your series is marked for-1.3 whereas this is for 1.4, so no obvious
> problem there - wanted to mention the overlap in the cover letter but
> apparently forgot.
I have a more complete series for 1.4 (needs a bit more testing, but I
guess I can send out an RFC). The one I posted for 1.3 is a subset.
> My quest was to kill obsolete things with old "qdev" in the name. :)
> I don't really mind if this becomes object_delete() or object_unref() or
> anything else as long as it's not such a trivial qdev_* wrapper calling
> one QOM object_* function.
Ok, that's fine.
Paolo
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [Qemu-devel] [RFC 00/34] QOM realize, device-only plus ISA conversion
2012-11-26 0:12 [Qemu-devel] [RFC 00/34] QOM realize, device-only plus ISA conversion Andreas Färber
` (33 preceding siblings ...)
2012-11-26 0:12 ` [Qemu-devel] [RFC 34/34] i8259: Convert PICCommonState to use QOM realizefn Andreas Färber
@ 2012-12-04 22:19 ` Andreas Färber
2013-01-02 14:48 ` Anthony Liguori
35 siblings, 0 replies; 46+ messages in thread
From: Andreas Färber @ 2012-12-04 22:19 UTC (permalink / raw)
To: qemu-devel, Anthony Liguori
Cc: Kevin Wolf, Peter Maydell, Eduardo Habkost, Markus Armbruster,
Julien Grall, Stefan Hajnoczi, Paolo Bonzini, Cornelia Huck,
Igor Mammedov, Frederic Konrad
Ping,
Am 26.11.2012 01:12, schrieb Andreas Färber:
> Hello Anthony and Paolo,
>
> As announced at KVM Forum, I have been preparing a new approach to incrementally
> get us Anthony's QOM realizefn concept. A previous attempt by Paolo and me had
> been turned down for making this available at Object-level and over questions
> whether BlockDriverState may need its own three-stage realization model.
>
> So here's an all-new patchset doing it at DeviceState-level only, adapting the
> signature to void realize(DeviceState *, Error **).
> CPUState is on a good way to get derived from DeviceState, so in the future
> will benefit from this approach as well.
>
> I've picked ISADevice as an example to showcase what semantic effects the
> switch to QOM realizefn has (in the hopes the number of devices would be small):
> As requested by Anthony for QOM CPUState reset and as seen with virtual methods
> in object-oriented programming languages, it becomes the derived method's
> responsibility to decide when and whether to call the parent class' method. In
> lack of real vtables this requires to save the parent's method in case we want
> to call it; classes and matching macros may need to be added for that.
> Another point to note is that we should carefully distinguish what goes into
> the qdev initfn / QOM realizefn and what can already go into a QOM initfn.
>
> This series is rebased onto Julien's ioport cleanups (touching on ISA devices).
>
> It starts by preparing the "realized" property, wrapping qdev's initfn (04).
> This means setting realized to true will not yet affect its children, as seen
> in Paolo's previous patches. That can be implemented later when the realizefns
> have been reviewed not to create new devices that would mess with recursive
> child realization. (In the previous series we had recursive realization but
> on my request dropped the hook-up of qdev due to the aforementioned quirks.)
>
> At that point there is a coexistence of QOM device realizefn and qdev initfn.
> For the first time now I have set out to actually eliminate some qdev initfns,
> that's what I chose ISA for. This consists of three parts, introducing
> realizefns for ISADevices (28) and recursively for PITs (31) and for PICs (34).
> As seen for the PCI host bridge series, I've extracted general QOM cleanups
> from the main conversion patch to arrive at a clean QOM'ish state while
> hopefully keeping the main patches readable.
>
> This series also highlights an interesting find: Beyond the to-be-solved
> CPUState, there is also a "realize" function for BusState (02), which is not
> derived from DeviceState. :-)
> With the device-centric approach taken here it would still be possible to add
> "realized" properties to other types using their own infrastructure (e.g., a
> hardcoded setter rather than a realizefn hook).
>
> Posted as an RFC to encourage bikeshedding, in particular about the type names
> and macros introduced. Adding new header files to move them out of the source
> files for, e.g., vl.c is left for a follow-up, but for instance I was unsure
> about TYPE_ISA_FDC (should this be TYPE_ISA_FLOPPY_DRIVE_CONTROLLER as with
> PCI_HOST_BRIDGE rather than PHB?), and naming of type names and functions is
> highly inconsistent (e.g., isa_vga vs. vga_isa, or pic vs. i8259).
So far I've heard no comments on the main QOM/ISA part of the series...
Anthony, did I understand you correctly wrt the method overriding?
(PIC/PIT) Or did you have this differently in mind?
Anyone any suggestions for improvement? If not, I'll send out a v2 this
week, with qdev_free() either rebased onto Paolo or removal dropped.
qbus was not further touched in the series, so I'd probably defer the
qbus_realize() change.
Branch below is rebased to match v1.3.0 + memory-ioport pull request.
Regards,
Andreas
>
> Available for viewing/testing at:
> https://github.com/afaerber/qemu-cpu/commits/realize-qdev
> git://github.com/afaerber/qemu-cpu.git realize-qdev
[...]
> Andreas Färber (34):
> qdev: Eliminate qdev_free() in favor of QOM
(depends on what we want to replace qdev_free() with)
> qbus: QOM'ify qbus_realize()
(unrelated since qbus did not get a "realized" property in this series)
> qdev: Fold state enum into bool realized
> qdev: Prepare "realized" property
> isa: Split off instance_init for ISADevice
> applesmc: QOM'ify
> cirrus_vga: QOM'ify ISA Cirrus VGA
> debugcon: QOM'ify ISA debug console
> fdc: QOM'ify ISA floppy controller
> i82374: QOM'ify
> i8259: Fix PIC_COMMON() macro
(applied already)
> i8259: QOM cleanups
> ide: QOM'ify ISA IDE
> m48t59: QOM'ify ISA M48T59 NVRAM
> mc146818rtc: QOM'ify
> ne2000-isa: QOM'ify
> parallel: QOM'ify
> pc: QOM'ify port 92
> pckbd: QOM'ify
> pcspk: QOM'ify
> sb16: QOM'ify
> serial: QOM'ify ISA serial
> sga: QOM'ify
> vga-isa: QOM'ify ISA VGA
> vmmouse: QOM'ify
> vmport: QOM'ify
> wdt_ib700: QOM'ify
> isa: Use realizefn for ISADevice
> i8254: QOM'ify
> kvm/i8254: QOM'ify some more
> i8254: Convert PITCommonState to QOM realizefn
> i8259: QOM'ify some more
> kvm/i8259: QOM'ify some more
> i8259: Convert PICCommonState to use QOM realizefn
[snip]
--
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [Qemu-devel] [RFC 04/34] qdev: Prepare "realized" property
2012-11-26 0:12 ` [Qemu-devel] [RFC 04/34] qdev: Prepare "realized" property Andreas Färber
@ 2012-12-12 14:29 ` Eduardo Habkost
2012-12-12 16:51 ` Andreas Färber
0 siblings, 1 reply; 46+ messages in thread
From: Eduardo Habkost @ 2012-12-12 14:29 UTC (permalink / raw)
To: Andreas Färber; +Cc: Paolo Bonzini, qemu-devel, anthony
On Mon, Nov 26, 2012 at 01:12:16AM +0100, Andreas Färber wrote:
> Based on earlier patches by Paolo and me, introduce the QOM realizefn at
> device level only, as requested by Anthony.
>
> For now this just wraps the qdev initfn.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Andreas Färber <afaerber@suse.de>
> Cc: Anthony Liguori <anthony@codemonkey.ws>
> ---
> hw/qdev-core.h | 4 +++
> hw/qdev.c | 100 ++++++++++++++++++++++++++++++++++++++++++--------------
> 2 Dateien geändert, 80 Zeilen hinzugefügt(+), 24 Zeilen entfernt(-)
>
> diff --git a/hw/qdev-core.h b/hw/qdev-core.h
> index f0d3a5e..580a811 100644
> --- a/hw/qdev-core.h
> +++ b/hw/qdev-core.h
> @@ -29,6 +29,8 @@ enum {
> typedef int (*qdev_initfn)(DeviceState *dev);
> typedef int (*qdev_event)(DeviceState *dev);
> typedef void (*qdev_resetfn)(DeviceState *dev);
> +typedef void (*DeviceRealize)(DeviceState *dev, Error **err);
> +typedef void (*DeviceUnrealize)(DeviceState *dev, Error **err);
>
> struct VMStateDescription;
>
> @@ -47,6 +49,8 @@ typedef struct DeviceClass {
> const struct VMStateDescription *vmsd;
>
> /* Private to qdev / bus. */
> + DeviceRealize realize;
> + DeviceUnrealize unrealize;
> qdev_initfn init;
> qdev_event unplug;
> qdev_event exit;
> diff --git a/hw/qdev.c b/hw/qdev.c
> index bce6ad5..d7b6320 100644
> --- a/hw/qdev.c
> +++ b/hw/qdev.c
> @@ -147,37 +147,30 @@ DeviceState *qdev_try_create(BusState *bus, const char *type)
> Return 0 on success. */
> int qdev_init(DeviceState *dev)
> {
> - DeviceClass *dc = DEVICE_GET_CLASS(dev);
> - int rc;
> + Error *local_err = NULL;
>
> assert(!dev->realized);
>
> - rc = dc->init(dev);
> - if (rc < 0) {
> + object_property_set_bool(OBJECT(dev), true, "realized", &local_err);
> + if (local_err != NULL) {
> + error_free(local_err);
> object_delete(OBJECT(dev));
> - return rc;
> + return -1;
> }
> + return 0;
> +}
>
> - if (!OBJECT(dev)->parent) {
> - static int unattached_count = 0;
> - gchar *name = g_strdup_printf("device[%d]", unattached_count++);
> -
> - object_property_add_child(container_get(qdev_get_machine(),
> - "/unattached"),
> - name, OBJECT(dev), NULL);
> - g_free(name);
> - }
> +static void device_realize(DeviceState *dev, Error **err)
> +{
> + DeviceClass *dc = DEVICE_GET_CLASS(dev);
>
> - if (qdev_get_vmsd(dev)) {
> - vmstate_register_with_alias_id(dev, -1, qdev_get_vmsd(dev), dev,
> - dev->instance_id_alias,
> - dev->alias_required_for_version);
> - }
> - dev->realized = true;
> - if (dev->hotplugged) {
> - device_reset(dev);
> + if (dc->init) {
> + int rc = dc->init(dev);
> + if (rc < 0) {
> + error_setg(err, "Device initialization failed.");
> + return;
> + }
> }
> - return 0;
> }
[...]
> +static void device_class_init(ObjectClass *oc, void *data)
> +{
> + DeviceClass *dc = DEVICE_CLASS(oc);
> + dc->realize = device_realize;
> +}
> +
[...]
Stupid question: what exactly is the difference in capabilities and
semantics between DeviceClass.init() and DeviceClass.realize()? They
look exactly the same to me, from a first look. On which cases would
somebody use the former instead of the latter, and why?
--
Eduardo
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [Qemu-devel] [RFC 04/34] qdev: Prepare "realized" property
2012-12-12 14:29 ` Eduardo Habkost
@ 2012-12-12 16:51 ` Andreas Färber
2012-12-12 18:16 ` Eduardo Habkost
0 siblings, 1 reply; 46+ messages in thread
From: Andreas Färber @ 2012-12-12 16:51 UTC (permalink / raw)
To: Eduardo Habkost; +Cc: Paolo Bonzini, qemu-devel, anthony
Am 12.12.2012 15:29, schrieb Eduardo Habkost:
> On Mon, Nov 26, 2012 at 01:12:16AM +0100, Andreas Färber wrote:
>> Based on earlier patches by Paolo and me, introduce the QOM realizefn at
>> device level only, as requested by Anthony.
>>
>> For now this just wraps the qdev initfn.
...which it deprecates.
>>
>> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>> Signed-off-by: Andreas Färber <afaerber@suse.de>
>> Cc: Anthony Liguori <anthony@codemonkey.ws>
>> ---
>> hw/qdev-core.h | 4 +++
>> hw/qdev.c | 100 ++++++++++++++++++++++++++++++++++++++++++--------------
>> 2 Dateien geändert, 80 Zeilen hinzugefügt(+), 24 Zeilen entfernt(-)
>>
>> diff --git a/hw/qdev-core.h b/hw/qdev-core.h
>> index f0d3a5e..580a811 100644
>> --- a/hw/qdev-core.h
>> +++ b/hw/qdev-core.h
>> @@ -29,6 +29,8 @@ enum {
>> typedef int (*qdev_initfn)(DeviceState *dev);
>> typedef int (*qdev_event)(DeviceState *dev);
>> typedef void (*qdev_resetfn)(DeviceState *dev);
>> +typedef void (*DeviceRealize)(DeviceState *dev, Error **err);
>> +typedef void (*DeviceUnrealize)(DeviceState *dev, Error **err);
>>
>> struct VMStateDescription;
>>
>> @@ -47,6 +49,8 @@ typedef struct DeviceClass {
>> const struct VMStateDescription *vmsd;
>>
>> /* Private to qdev / bus. */
>> + DeviceRealize realize;
>> + DeviceUnrealize unrealize;
>> qdev_initfn init;
>> qdev_event unplug;
>> qdev_event exit;
>> diff --git a/hw/qdev.c b/hw/qdev.c
>> index bce6ad5..d7b6320 100644
>> --- a/hw/qdev.c
>> +++ b/hw/qdev.c
>> @@ -147,37 +147,30 @@ DeviceState *qdev_try_create(BusState *bus, const char *type)
>> Return 0 on success. */
>> int qdev_init(DeviceState *dev)
>> {
>> - DeviceClass *dc = DEVICE_GET_CLASS(dev);
>> - int rc;
>> + Error *local_err = NULL;
>>
>> assert(!dev->realized);
>>
>> - rc = dc->init(dev);
>> - if (rc < 0) {
>> + object_property_set_bool(OBJECT(dev), true, "realized", &local_err);
>> + if (local_err != NULL) {
>> + error_free(local_err);
>> object_delete(OBJECT(dev));
>> - return rc;
>> + return -1;
>> }
>> + return 0;
>> +}
>>
>> - if (!OBJECT(dev)->parent) {
>> - static int unattached_count = 0;
>> - gchar *name = g_strdup_printf("device[%d]", unattached_count++);
>> -
>> - object_property_add_child(container_get(qdev_get_machine(),
>> - "/unattached"),
>> - name, OBJECT(dev), NULL);
>> - g_free(name);
>> - }
>> +static void device_realize(DeviceState *dev, Error **err)
>> +{
>> + DeviceClass *dc = DEVICE_GET_CLASS(dev);
>>
>> - if (qdev_get_vmsd(dev)) {
>> - vmstate_register_with_alias_id(dev, -1, qdev_get_vmsd(dev), dev,
>> - dev->instance_id_alias,
>> - dev->alias_required_for_version);
>> - }
>> - dev->realized = true;
>> - if (dev->hotplugged) {
>> - device_reset(dev);
>> + if (dc->init) {
>> + int rc = dc->init(dev);
>> + if (rc < 0) {
>> + error_setg(err, "Device initialization failed.");
>> + return;
>> + }
>> }
>> - return 0;
>> }
> [...]
>> +static void device_class_init(ObjectClass *oc, void *data)
>> +{
>> + DeviceClass *dc = DEVICE_CLASS(oc);
>> + dc->realize = device_realize;
>> +}
>> +
> [...]
>
> Stupid question: what exactly is the difference in capabilities and
> semantics between DeviceClass.init() and DeviceClass.realize()? They
> look exactly the same to me, from a first look. On which cases would
> somebody use the former instead of the latter, and why?
Wherever possible, users should use the new DeviceClass::realize.
"init" or "initfn" clashes with QOM's instance_init name-wise.
As shown in this series, instance_init can be used in devices today
already, without having realize.
The distinction between instance_init and realize is that the former
initializes simple variables, sets up properties and anything the user
may want to modify, then realize processes these variables and is able
to fail and report the cause of failure (unlike DeviceClass::init).
In the isa patch after all the boring QOM'ish preparations, isa-device's
class_init overwrites DeviceClass:realize, thereby no longer invoking
any DeviceClass::init callback for the ISA devices. I2C, PCI, SysBus,
etc. would need to be done in further steps, but a) this is work, b) the
series shouldn't get too long for review/merge and c) it all depends on
in which class and thereby with which signature we want to have realize
- DeviceClass::realize(DeviceState *, Error **) or
ObjectClass::realize(Object *, Error **).
Andreas
--
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [Qemu-devel] [RFC 04/34] qdev: Prepare "realized" property
2012-12-12 16:51 ` Andreas Färber
@ 2012-12-12 18:16 ` Eduardo Habkost
2012-12-12 18:25 ` Andreas Färber
0 siblings, 1 reply; 46+ messages in thread
From: Eduardo Habkost @ 2012-12-12 18:16 UTC (permalink / raw)
To: Andreas Färber; +Cc: Paolo Bonzini, qemu-devel, anthony
On Wed, Dec 12, 2012 at 05:51:18PM +0100, Andreas Färber wrote:
> Am 12.12.2012 15:29, schrieb Eduardo Habkost:
> > On Mon, Nov 26, 2012 at 01:12:16AM +0100, Andreas Färber wrote:
> >> Based on earlier patches by Paolo and me, introduce the QOM realizefn at
> >> device level only, as requested by Anthony.
> >>
> >> For now this just wraps the qdev initfn.
>
> ...which it deprecates.
Good to know. I thought they had different purposes and I was missing
something.
[...]
> >> +static void device_realize(DeviceState *dev, Error **err)
> >> +{
> >> + DeviceClass *dc = DEVICE_GET_CLASS(dev);
> >>
> >> - if (qdev_get_vmsd(dev)) {
> >> - vmstate_register_with_alias_id(dev, -1, qdev_get_vmsd(dev), dev,
> >> - dev->instance_id_alias,
> >> - dev->alias_required_for_version);
> >> - }
> >> - dev->realized = true;
> >> - if (dev->hotplugged) {
> >> - device_reset(dev);
> >> + if (dc->init) {
> >> + int rc = dc->init(dev);
> >> + if (rc < 0) {
> >> + error_setg(err, "Device initialization failed.");
> >> + return;
> >> + }
> >> }
> >> - return 0;
> >> }
> > [...]
> >> +static void device_class_init(ObjectClass *oc, void *data)
> >> +{
> >> + DeviceClass *dc = DEVICE_CLASS(oc);
> >> + dc->realize = device_realize;
> >> +}
> >> +
> > [...]
> >
> > Stupid question: what exactly is the difference in capabilities and
> > semantics between DeviceClass.init() and DeviceClass.realize()? They
> > look exactly the same to me, from a first look. On which cases would
> > somebody use the former instead of the latter, and why?
>
> Wherever possible, users should use the new DeviceClass::realize.
>
> "init" or "initfn" clashes with QOM's instance_init name-wise.
> As shown in this series, instance_init can be used in devices today
> already, without having realize.
True. That's something I like in the new name. :-)
>
> The distinction between instance_init and realize is that the former
> initializes simple variables, sets up properties and anything the user
> may want to modify, then realize processes these variables and is able
> to fail and report the cause of failure (unlike DeviceClass::init).
I understood the difference between ObjectClass.instance_init() and
DeviceClass.init() (now called realize()), already. My question was
about the difference between DeviceClass.init() and
DeviceClass.realize().
>
> In the isa patch after all the boring QOM'ish preparations, isa-device's
> class_init overwrites DeviceClass:realize, thereby no longer invoking
> any DeviceClass::init callback for the ISA devices. I2C, PCI, SysBus,
> etc. would need to be done in further steps, but a) this is work, b) the
> series shouldn't get too long for review/merge and c) it all depends on
> in which class and thereby with which signature we want to have realize
> - DeviceClass::realize(DeviceState *, Error **) or
> ObjectClass::realize(Object *, Error **).
So, just to check if I understood all correctly:
DeviceClass.init() is just the old and deprecated version of
DeviceClass.realize() (just because the former has no Error parameter),
but both have exactly the same semantics/purpose, and devices should now
use DeviceClass.realize() instead. Correct?
--
Eduardo
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [Qemu-devel] [RFC 04/34] qdev: Prepare "realized" property
2012-12-12 18:16 ` Eduardo Habkost
@ 2012-12-12 18:25 ` Andreas Färber
2012-12-12 18:44 ` Eduardo Habkost
0 siblings, 1 reply; 46+ messages in thread
From: Andreas Färber @ 2012-12-12 18:25 UTC (permalink / raw)
To: Eduardo Habkost; +Cc: Paolo Bonzini, qemu-devel, anthony
Am 12.12.2012 19:16, schrieb Eduardo Habkost:
> So, just to check if I understood all correctly:
>
> DeviceClass.init() is just the old and deprecated version of
> DeviceClass.realize() (just because the former has no Error parameter),
> but both have exactly the same semantics/purpose, and devices should now
> use DeviceClass.realize() instead. Correct?
Almost! Some qdev initfns today do things that instance_init should do
and realizefn shouldn't. Creating child devices in qdev initfn tampers
with our future ability to set realized = true recursively.
The other difference that I see (RFC) is that qdev uses an
only-the-instance's-class-sets-init approach, whereas with QOM any class
in the hierarchy can set/override the "virtual" method but needs to take
care of storing and (if desired) calling the parent's version itself,
i.e. an inversion of control towards child classes.
Andreas
--
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [Qemu-devel] [RFC 04/34] qdev: Prepare "realized" property
2012-12-12 18:25 ` Andreas Färber
@ 2012-12-12 18:44 ` Eduardo Habkost
0 siblings, 0 replies; 46+ messages in thread
From: Eduardo Habkost @ 2012-12-12 18:44 UTC (permalink / raw)
To: Andreas Färber; +Cc: Paolo Bonzini, qemu-devel, anthony
On Wed, Dec 12, 2012 at 07:25:01PM +0100, Andreas Färber wrote:
> Am 12.12.2012 19:16, schrieb Eduardo Habkost:
> > So, just to check if I understood all correctly:
> >
> > DeviceClass.init() is just the old and deprecated version of
> > DeviceClass.realize() (just because the former has no Error parameter),
> > but both have exactly the same semantics/purpose, and devices should now
> > use DeviceClass.realize() instead. Correct?
>
> Almost! Some qdev initfns today do things that instance_init should do
> and realizefn shouldn't. Creating child devices in qdev initfn tampers
> with our future ability to set realized = true recursively.
In those cases, where should the child device cration be moved to?
Whatever the answer is, can we have those subtle differences documented
inside DeviceClass?
I specifically mean documenting the purpose of the init/realize/unrealize
function pointers and their semantics/requirements for subclasses, not
just documenting the semantics of the "realized" property and
device_set_realized(). Knowing what device_set_realize() and qdev_init()
are supposed to do when all classes already do what they are supposed to
is easy. Knowing what exactly subclasses can/can't to do when setting
init/realize/unrealize functions is a bit more complicated.
>
> The other difference that I see (RFC) is that qdev uses an
> only-the-instance's-class-sets-init approach, whereas with QOM any class
> in the hierarchy can set/override the "virtual" method but needs to take
> care of storing and (if desired) calling the parent's version itself,
> i.e. an inversion of control towards child classes.
I see. In theory we could change DeviceClass.init() to have the same
requirements/semantic, but then we would need to change every class to
save the parent's init() function and call it.
--
Eduardo
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [Qemu-devel] [RFC 00/34] QOM realize, device-only plus ISA conversion
2012-11-26 0:12 [Qemu-devel] [RFC 00/34] QOM realize, device-only plus ISA conversion Andreas Färber
` (34 preceding siblings ...)
2012-12-04 22:19 ` [Qemu-devel] [RFC 00/34] QOM realize, device-only plus ISA conversion Andreas Färber
@ 2013-01-02 14:48 ` Anthony Liguori
35 siblings, 0 replies; 46+ messages in thread
From: Anthony Liguori @ 2013-01-02 14:48 UTC (permalink / raw)
To: Andreas Färber, qemu-devel
Cc: Kevin Wolf, Peter Maydell, Eduardo Habkost, Markus Armbruster,
Julien Grall, Stefan Hajnoczi, Igor Mammedov, Cornelia Huck,
Paolo Bonzini, Frederic Konrad
So there are 3-4 different series in here all rolled into one. This
makes review a bit tedious.
I'd suggest:
1) Pull out all of the QOMification stuff into a separate series.
2) Pull out the style cleanups into another series
3) Pull out the introduction of realize/unrealize into a series
4) Pull out the ISA use of realize into another series.
Individually, each series looks very easy to merge. The general
approach is right along what I was hoping for.
Regards,
Anthony Liguori
Andreas Färber <afaerber@suse.de> writes:
> Hello Anthony and Paolo,
>
> As announced at KVM Forum, I have been preparing a new approach to incrementally
> get us Anthony's QOM realizefn concept. A previous attempt by Paolo and me had
> been turned down for making this available at Object-level and over questions
> whether BlockDriverState may need its own three-stage realization model.
>
> So here's an all-new patchset doing it at DeviceState-level only, adapting the
> signature to void realize(DeviceState *, Error **).
> CPUState is on a good way to get derived from DeviceState, so in the future
> will benefit from this approach as well.
>
> I've picked ISADevice as an example to showcase what semantic effects the
> switch to QOM realizefn has (in the hopes the number of devices would be small):
> As requested by Anthony for QOM CPUState reset and as seen with virtual methods
> in object-oriented programming languages, it becomes the derived method's
> responsibility to decide when and whether to call the parent class' method. In
> lack of real vtables this requires to save the parent's method in case we want
> to call it; classes and matching macros may need to be added for that.
> Another point to note is that we should carefully distinguish what goes into
> the qdev initfn / QOM realizefn and what can already go into a QOM initfn.
>
> This series is rebased onto Julien's ioport cleanups (touching on ISA devices).
>
> It starts by preparing the "realized" property, wrapping qdev's initfn (04).
> This means setting realized to true will not yet affect its children, as seen
> in Paolo's previous patches. That can be implemented later when the realizefns
> have been reviewed not to create new devices that would mess with recursive
> child realization. (In the previous series we had recursive realization but
> on my request dropped the hook-up of qdev due to the aforementioned quirks.)
>
> At that point there is a coexistence of QOM device realizefn and qdev initfn.
> For the first time now I have set out to actually eliminate some qdev initfns,
> that's what I chose ISA for. This consists of three parts, introducing
> realizefns for ISADevices (28) and recursively for PITs (31) and for PICs (34).
> As seen for the PCI host bridge series, I've extracted general QOM cleanups
> from the main conversion patch to arrive at a clean QOM'ish state while
> hopefully keeping the main patches readable.
>
> This series also highlights an interesting find: Beyond the to-be-solved
> CPUState, there is also a "realize" function for BusState (02), which is not
> derived from DeviceState. :-)
> With the device-centric approach taken here it would still be possible to add
> "realized" properties to other types using their own infrastructure (e.g., a
> hardcoded setter rather than a realizefn hook).
>
> Posted as an RFC to encourage bikeshedding, in particular about the type names
> and macros introduced. Adding new header files to move them out of the source
> files for, e.g., vl.c is left for a follow-up, but for instance I was unsure
> about TYPE_ISA_FDC (should this be TYPE_ISA_FLOPPY_DRIVE_CONTROLLER as with
> PCI_HOST_BRIDGE rather than PHB?), and naming of type names and functions is
> highly inconsistent (e.g., isa_vga vs. vga_isa, or pic vs. i8259).
>
> Available for viewing/testing at:
> https://github.com/afaerber/qemu-cpu/commits/realize-qdev
> git://github.com/afaerber/qemu-cpu.git realize-qdev
>
> Regards,
> Andreas
>
> Cc: Anthony Liguori <anthony@codemonkey.ws>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
>
> Cc: Julien Grall <julien.grall@citrix.com>
> Cc: Frederic Konrad <fred.konrad@greensocs.com>
> Cc: Peter Maydell <peter.maydell@linaro.org>
> Cc: Cornelia Huck <cornelia.huck@de.ibm.com>
> Cc: Kevin Wolf <kwolf@redhat.com>
> Cc: Stefan Hajnoczi <stefanha@redhat.com>
> Cc: Markus Armbruster <armbru@redhat.com>
> Cc: Eduardo Habkost <ehabkost@redhat.com>
> Cc: Igor Mammedov <imammedo@redhat.com>
>
> Andreas Färber (34):
> qdev: Eliminate qdev_free() in favor of QOM
> qbus: QOM'ify qbus_realize()
> qdev: Fold state enum into bool realized
> qdev: Prepare "realized" property
> isa: Split off instance_init for ISADevice
> applesmc: QOM'ify
> cirrus_vga: QOM'ify ISA Cirrus VGA
> debugcon: QOM'ify ISA debug console
> fdc: QOM'ify ISA floppy controller
> i82374: QOM'ify
> i8259: Fix PIC_COMMON() macro
> i8259: QOM cleanups
> ide: QOM'ify ISA IDE
> m48t59: QOM'ify ISA M48T59 NVRAM
> mc146818rtc: QOM'ify
> ne2000-isa: QOM'ify
> parallel: QOM'ify
> pc: QOM'ify port 92
> pckbd: QOM'ify
> pcspk: QOM'ify
> sb16: QOM'ify
> serial: QOM'ify ISA serial
> sga: QOM'ify
> vga-isa: QOM'ify ISA VGA
> vmmouse: QOM'ify
> vmport: QOM'ify
> wdt_ib700: QOM'ify
> isa: Use realizefn for ISADevice
> i8254: QOM'ify
> kvm/i8254: QOM'ify some more
> i8254: Convert PITCommonState to QOM realizefn
> i8259: QOM'ify some more
> kvm/i8259: QOM'ify some more
> i8259: Convert PICCommonState to use QOM realizefn
>
> hw/acpi_piix4.c | 2 +-
> hw/applesmc.c | 45 +++++++++---------
> hw/cirrus_vga.c | 27 ++++++-----
> hw/debugcon.c | 34 +++++++++-----
> hw/fdc.c | 45 ++++++++++--------
> hw/fdc.h | 2 +
> hw/i82374.c | 25 +++++-----
> hw/i8254.c | 26 +++++++---
> hw/i8254.h | 7 ++-
> hw/i8254_common.c | 19 ++------
> hw/i8254_internal.h | 1 -
> hw/i8259.c | 64 +++++++++++++++++--------
> hw/i8259_common.c | 20 +++-----
> hw/i8259_internal.h | 7 +--
> hw/ide/isa.c | 55 +++++++++++++---------
> hw/isa-bus.c | 15 ++----
> hw/isa.h | 1 -
> hw/kvm/i8254.c | 59 +++++++++++++++--------
> hw/kvm/i8259.c | 38 ++++++++++++---
> hw/m48t59.c | 54 +++++++++++----------
> hw/mc146818rtc.c | 56 ++++++++++++----------
> hw/mc146818rtc.h | 2 +
> hw/ne2000-isa.c | 27 ++++++-----
> hw/parallel.c | 42 ++++++++++-------
> hw/pc.c | 26 +++++-----
> hw/pc_piix.c | 2 +-
> hw/pci-hotplug.c | 2 +-
> hw/pci_bridge.c | 2 +-
> hw/pcie.c | 2 +-
> hw/pckbd.c | 34 ++++++++------
> hw/pcspk.c | 21 +++++----
> hw/pcspk.h | 4 +-
> hw/qdev-addr.c | 2 +-
> hw/qdev-core.h | 12 ++---
> hw/qdev-monitor.c | 2 +-
> hw/qdev-properties.c | 28 +++++------
> hw/qdev.c | 128 ++++++++++++++++++++++++++++++++++----------------
> hw/sb16.c | 35 +++++++++-----
> hw/scsi-bus.c | 4 +-
> hw/serial-isa.c | 33 +++++++------
> hw/serial-pci.c | 4 +-
> hw/serial.c | 6 +--
> hw/serial.h | 3 +-
> hw/sga.c | 19 ++++----
> hw/shpc.c | 2 +-
> hw/usb/bus.c | 7 +--
> hw/usb/dev-storage.c | 2 +-
> hw/usb/host-linux.c | 2 +-
> hw/vga-isa.c | 46 +++++++++---------
> hw/vmmouse.c | 24 +++++-----
> hw/vmport.c | 24 ++++++----
> hw/wdt_ib700.c | 22 +++++----
> hw/xen_platform.c | 2 +-
> 53 Dateien geändert, 692 Zeilen hinzugefügt(+), 481 Zeilen entfernt(-)
>
> --
> 1.7.10.4
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [Qemu-devel] [RFC 15/34] mc146818rtc: QOM'ify
2012-11-26 0:12 ` [Qemu-devel] [RFC 15/34] mc146818rtc: QOM'ify Andreas Färber
@ 2013-04-22 15:42 ` Andreas Färber
0 siblings, 0 replies; 46+ messages in thread
From: Andreas Färber @ 2013-04-22 15:42 UTC (permalink / raw)
To: qemu-devel; +Cc: Igor Mammedov, anthony
Am 26.11.2012 01:12, schrieb Andreas Färber:
> Introduce type constant and cast macro to obsolete DO_UPCAST().
>
> Prepares for ISA realizefn.
>
> Signed-off-by: Andreas Färber <afaerber@suse.de>
> ---
> hw/mc146818rtc.c | 38 +++++++++++++++++++++-----------------
> hw/mc146818rtc.h | 2 ++
> 2 Dateien geändert, 23 Zeilen hinzugefügt(+), 17 Zeilen entfernt(-)
Applied rebased version to qom-cpu-next (static const was applied
throughout the tree, file locations changed; no new conversions):
https://github.com/afaerber/qemu-cpu/commits/qom-cpu-next
Andreas
>
> diff --git a/hw/mc146818rtc.c b/hw/mc146818rtc.c
> index 7d84ce3..c87b7f6 100644
> --- a/hw/mc146818rtc.c
> +++ b/hw/mc146818rtc.c
> @@ -57,8 +57,11 @@
> #define RTC_CLOCK_RATE 32768
> #define UIP_HOLD_LENGTH (8 * NSEC_PER_SEC / 32768)
>
> +#define MC146818_RTC(obj) OBJECT_CHECK(RTCState, (obj), TYPE_MC146818_RTC)
> +
> typedef struct RTCState {
> - ISADevice dev;
> + ISADevice parent_obj;
> +
> MemoryRegion io;
> uint8_t cmos_data[128];
> uint8_t cmos_index;
> @@ -668,14 +671,14 @@ static uint64_t cmos_ioport_read(void *opaque, hwaddr addr,
>
> void rtc_set_memory(ISADevice *dev, int addr, int val)
> {
> - RTCState *s = DO_UPCAST(RTCState, dev, dev);
> + RTCState *s = MC146818_RTC(dev);
> if (addr >= 0 && addr <= 127)
> s->cmos_data[addr] = val;
> }
>
> static void rtc_set_date_from_host(ISADevice *dev)
> {
> - RTCState *s = DO_UPCAST(RTCState, dev, dev);
> + RTCState *s = MC146818_RTC(dev);
> struct tm tm;
>
> qemu_get_timedate(&tm, 0);
> @@ -737,7 +740,7 @@ static void rtc_notify_clock_reset(Notifier *notifier, void *data)
> RTCState *s = container_of(notifier, RTCState, clock_reset_notifier);
> int64_t now = *(int64_t *)data;
>
> - rtc_set_date_from_host(&s->dev);
> + rtc_set_date_from_host(ISA_DEVICE(s));
> periodic_timer_update(s, now);
> check_update_timer(s);
> #ifdef TARGET_I386
> @@ -752,7 +755,7 @@ static void rtc_notify_clock_reset(Notifier *notifier, void *data)
> static void rtc_notify_suspend(Notifier *notifier, void *data)
> {
> RTCState *s = container_of(notifier, RTCState, suspend_notifier);
> - rtc_set_memory(&s->dev, 0xF, 0xFE);
> + rtc_set_memory(ISA_DEVICE(s), 0xF, 0xFE);
> }
>
> static void rtc_reset(void *opaque)
> @@ -785,8 +788,7 @@ static const MemoryRegionOps cmos_ops = {
> static void rtc_get_date(Object *obj, Visitor *v, void *opaque,
> const char *name, Error **errp)
> {
> - ISADevice *isa = ISA_DEVICE(obj);
> - RTCState *s = DO_UPCAST(RTCState, dev, isa);
> + RTCState *s = MC146818_RTC(obj);
> struct tm current_tm;
>
> rtc_update_time(s);
> @@ -803,7 +805,7 @@ static void rtc_get_date(Object *obj, Visitor *v, void *opaque,
>
> static int rtc_initfn(ISADevice *dev)
> {
> - RTCState *s = DO_UPCAST(RTCState, dev, dev);
> + RTCState *s = MC146818_RTC(dev);
> int base = 0x70;
>
> s->cmos_data[RTC_REG_A] = 0x26;
> @@ -862,19 +864,21 @@ static int rtc_initfn(ISADevice *dev)
>
> ISADevice *rtc_init(ISABus *bus, int base_year, qemu_irq intercept_irq)
> {
> - ISADevice *dev;
> + DeviceState *dev;
> + ISADevice *isadev;
> RTCState *s;
>
> - dev = isa_create(bus, "mc146818rtc");
> - s = DO_UPCAST(RTCState, dev, dev);
> - qdev_prop_set_int32(&dev->qdev, "base_year", base_year);
> - qdev_init_nofail(&dev->qdev);
> + isadev = isa_create(bus, TYPE_MC146818_RTC);
> + dev = DEVICE(isadev);
> + s = MC146818_RTC(isadev);
> + qdev_prop_set_int32(dev, "base_year", base_year);
> + qdev_init_nofail(dev);
> if (intercept_irq) {
> s->irq = intercept_irq;
> } else {
> - isa_init_irq(dev, &s->irq, RTC_ISA_IRQ);
> + isa_init_irq(isadev, &s->irq, RTC_ISA_IRQ);
> }
> - return dev;
> + return isadev;
> }
>
> static Property mc146818rtc_properties[] = {
> @@ -894,8 +898,8 @@ static void rtc_class_initfn(ObjectClass *klass, void *data)
> dc->props = mc146818rtc_properties;
> }
>
> -static TypeInfo mc146818rtc_info = {
> - .name = "mc146818rtc",
> +static const TypeInfo mc146818rtc_info = {
> + .name = TYPE_MC146818_RTC,
> .parent = TYPE_ISA_DEVICE,
> .instance_size = sizeof(RTCState),
> .class_init = rtc_class_initfn,
> diff --git a/hw/mc146818rtc.h b/hw/mc146818rtc.h
> index f286b6a..b00c794 100644
> --- a/hw/mc146818rtc.h
> +++ b/hw/mc146818rtc.h
> @@ -4,6 +4,8 @@
> #include "isa.h"
> #include "mc146818rtc_regs.h"
>
> +#define TYPE_MC146818_RTC "mc146818rtc"
> +
> ISADevice *rtc_init(ISABus *bus, int base_year, qemu_irq intercept_irq);
> void rtc_set_memory(ISADevice *dev, int addr, int val);
> void rtc_set_date(ISADevice *dev, const struct tm *tm);
>
--
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
^ permalink raw reply [flat|nested] 46+ messages in thread
end of thread, other threads:[~2013-04-22 15:42 UTC | newest]
Thread overview: 46+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-26 0:12 [Qemu-devel] [RFC 00/34] QOM realize, device-only plus ISA conversion Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [PATCH 01/34] qdev: Eliminate qdev_free() in favor of QOM Andreas Färber
2012-11-26 7:20 ` Paolo Bonzini
2012-11-26 11:52 ` Andreas Färber
2012-11-26 12:04 ` Paolo Bonzini
2012-11-26 0:12 ` [Qemu-devel] [RFC 02/34] qbus: QOM'ify qbus_realize() Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 03/34] qdev: Fold state enum into bool realized Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 04/34] qdev: Prepare "realized" property Andreas Färber
2012-12-12 14:29 ` Eduardo Habkost
2012-12-12 16:51 ` Andreas Färber
2012-12-12 18:16 ` Eduardo Habkost
2012-12-12 18:25 ` Andreas Färber
2012-12-12 18:44 ` Eduardo Habkost
2012-11-26 0:12 ` [Qemu-devel] [RFC 05/34] isa: Split off instance_init for ISADevice Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 06/34] applesmc: QOM'ify Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 07/34] cirrus_vga: QOM'ify ISA Cirrus VGA Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 08/34] debugcon: QOM'ify ISA debug console Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 09/34] fdc: QOM'ify ISA floppy controller Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 10/34] i82374: QOM'ify Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [PATCH 11/34] i8259: Fix PIC_COMMON() macro Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 12/34] i8259: QOM cleanups Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 13/34] ide: QOM'ify ISA IDE Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 14/34] m48t59: QOM'ify ISA M48T59 NVRAM Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 15/34] mc146818rtc: QOM'ify Andreas Färber
2013-04-22 15:42 ` Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 16/34] ne2000-isa: QOM'ify Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 17/34] parallel: QOM'ify Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 18/34] pc: QOM'ify port 92 Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 19/34] pckbd: QOM'ify Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 20/34] pcspk: QOM'ify Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 21/34] sb16: QOM'ify Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 22/34] serial: QOM'ify ISA serial Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 23/34] sga: QOM'ify Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 24/34] vga-isa: QOM'ify ISA VGA Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 25/34] vmmouse: QOM'ify Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 26/34] vmport: QOM'ify Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 27/34] wdt_ib700: QOM'ify Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 28/34] isa: Use realizefn for ISADevice Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 29/34] i8254: QOM'ify Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 30/34] kvm/i8254: QOM'ify some more Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 31/34] i8254: Convert PITCommonState to QOM realizefn Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 32/34] i8259: QOM'ify some more Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 33/34] kvm/i8259: " Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 34/34] i8259: Convert PICCommonState to use QOM realizefn Andreas Färber
2012-12-04 22:19 ` [Qemu-devel] [RFC 00/34] QOM realize, device-only plus ISA conversion Andreas Färber
2013-01-02 14:48 ` Anthony Liguori
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).