Skip to contentSkip to conversation

QOM realize for ISA, part 1

PATCH Applied Andreas Färber 3 participants 23 messages Apr 27, 2013 – Apr 29, 2013

lore
Share & tools
lore
#0 lore raw

v2 cover QOM realize for ISA, part 1

Hello,

Here is my next batch of QOM realize patches.

These mostly introduce QOM cast macros for ISADevice-derived types, so should hopefully be safe to apply for 1.5.

The mc146818 patch is also queued on qom-cpu and reused for CPU hot-add.

Available from:
https://github.com/afaerber/qemu-cpu/commits/realize-isa.cleanup.v2
git://github.com/afaerber/qemu-cpu.git realize-isa.cleanup.v2

Regards,
Andreas

v1 -> v2:
* QOM realize infrastructure was split off and applied.
* isa-debugcon was QOM'ified.
* Rebased onto multiple hw/ reorganizations.
* Renamed M48T59_ISA() to ISA_M48T59() to match dominant specific <- base scheme.
* Deferred ISADevice::init removal to follow-up series.

Cc Anthony Liguori <[email protected]>
Cc Blue Swirl <[email protected]>
Cc Aurélien Jarno <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Igor Mammedov <[email protected]>
Cc Artyom Tarasenko <[email protected]>

Andreas Färber (20):
applesmc: QOM'ify
cirrus_vga: QOM'ify ISA Cirrus VGA
fdc: QOM'ify ISA floppy controller
i82374: QOM'ify
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

 hw/audio/pcspk.c                |  9 ++++++---
 hw/audio/sb16.c                 | 14 ++++++++------
 hw/block/fdc.c                  | 21 ++++++++++++---------
 hw/char/parallel.c              | 11 ++++++++---
 hw/char/serial-isa.c            | 11 +++++++----
 hw/display/cirrus_vga.c         | 15 ++++++++++-----
 hw/display/vga-isa.c            | 29 +++++++++++++++++------------
 hw/dma/i82374.c                 | 10 +++++++---
 hw/i386/kvm/i8259.c             |  2 +-
 hw/i386/pc.c                    | 14 +++++++++-----
 hw/i386/pc_piix.c               |  2 +-
 hw/ide/isa.c                    | 39 ++++++++++++++++++++++++---------------
 hw/input/pckbd.c                | 16 +++++++++++-----
 hw/input/vmmouse.c              | 14 +++++++++-----
 hw/intc/i8259.c                 | 16 +++++++++-------
 hw/intc/i8259_common.c          |  8 ++++----
 hw/misc/applesmc.c              | 33 +++++++++++++++++++--------------
 hw/misc/sga.c                   | 10 +++++++---
 hw/misc/vmport.c                | 12 ++++++++----
 hw/net/ne2000-isa.c             | 10 +++++++---
 hw/timer/m48t59.c               | 35 +++++++++++++++++++++--------------
 hw/timer/mc146818rtc.c          | 36 ++++++++++++++++++++----------------
 hw/watchdog/wdt_ib700.c         | 12 ++++++++----
 include/hw/audio/pcspk.h        |  4 +++-
 include/hw/block/fdc.h          |  2 ++
 include/hw/char/serial.h        |  1 +
 include/hw/isa/i8259_internal.h |  3 ++-
 include/hw/timer/mc146818rtc.h  |  2 ++
 28 files changed, 243 insertions(+), 148 deletions(-)
Signature · 1 line
1.8.1.4
#1 lore raw

PATCH v2 1/20 applesmc: QOM'ify

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.

---
 hw/misc/applesmc.c | 33 +++++++++++++++++++--------------
 1 file changed, 19 insertions(+), 14 deletions(-)
hw/misc/applesmc.c +19 -14
index c29558b..78904a8 100644
@@ -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(),
 };
 
@@ -237,9 +242,9 @@ static void qdev_applesmc_class_init(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo applesmc_isa_info = {
-    .name          = "isa-applesmc",
+    .name          = TYPE_APPLE_SMC,
     .parent        = TYPE_ISA_DEVICE,
-    .instance_size = sizeof(struct AppleSMCStatus),
+    .instance_size = sizeof(AppleSMCState),
     .class_init    = qdev_applesmc_class_init,
 };
 
Signature · 1 line
1.8.1.4
#2 lore raw

PATCH v2 2/20 cirrus_vga: QOM'ify ISA Cirrus VGA

In reply to Andreas Färber

Introduce type constant and cast macro to obsolete DO_UPCAST().

Prepares for ISA realizefn.

---
 hw/display/cirrus_vga.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
hw/display/cirrus_vga.c +10 -5
index 6e47956..64bfe2b 100644
@@ -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;
 
@@ -2904,7 +2909,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 const TypeInfo isa_cirrus_vga_info = {
-    .name          = "isa-cirrus-vga",
+    .name          = TYPE_ISA_CIRRUS_VGA,
     .parent        = TYPE_ISA_DEVICE,
     .instance_size = sizeof(ISACirrusVGAState),
     .class_init = isa_cirrus_vga_class_init,
Signature · 1 line
1.8.1.4
#3 lore raw

PATCH v2 3/20 fdc: QOM'ify ISA floppy controller

In reply to Andreas Färber

Introduce type constant and cast macro to obsolete DO_UPCAST(). Reuse type constant for PC machine compatibility settings.

Prepares for ISA realizefn.

Cc Markus Armbruster <[email protected]>
---
 hw/block/fdc.c         | 21 ++++++++++++---------
 hw/i386/pc_piix.c      |  2 +-
 include/hw/block/fdc.h |  2 ++
 3 files changed, 15 insertions(+), 10 deletions(-)
hw/block/fdc.c +12 -9
index f1f1fd7..0888652 100644
@@ -549,8 +549,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;
@@ -778,7 +781,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);
@@ -2021,7 +2024,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;
     }
@@ -2116,13 +2119,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);
@@ -2169,7 +2172,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;
 }
@@ -2197,7 +2200,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,10 +2213,10 @@ static void isabus_fdc_class_init1(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo isa_fdc_info = {
-    .name          = "isa-fdc",
+    .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 ={
hw/i386/pc_piix.c +1 -1
index 89b4cb4..08dd61d 100644
@@ -458,7 +458,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",\
         }, {\
include/hw/block/fdc.h +2 -0
index a8f6f7c..d48b2f8 100644
@@ -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);
Signature · 1 line
1.8.1.4
#4 lore raw

PATCH v2 4/20 i82374: QOM'ify

In reply to Andreas Färber

Introduce type constant and cast macro to obsolete DO_UPCAST().

Prepares for ISA realizefn.

---
 hw/dma/i82374.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
hw/dma/i82374.c +7 -3
index 835639d..f3d1924 100644
@@ -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);
@@ -154,7 +158,7 @@ static void i82374_class_init(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo i82374_isa_info = {
-    .name  = "i82374",
+    .name  = TYPE_I82374,
     .parent = TYPE_ISA_DEVICE,
     .instance_size  = sizeof(ISAi82374State),
     .class_init = i82374_class_init,
Signature · 1 line
1.8.1.4
#5 lore raw

PATCH v2 5/20 i8259: QOM cleanups

In reply to Andreas Färber

Eliminate DO_UPCAST() for PICCommonState. Prepares for ISA realizefn.

Also give the i8259_common type registration functions unique names while at it.

---
 hw/i386/kvm/i8259.c             |  2 +-
 hw/intc/i8259.c                 | 16 +++++++++-------
 hw/intc/i8259_common.c          |  8 ++++----
 include/hw/isa/i8259_internal.h |  3 ++-
 4 files changed, 16 insertions(+), 13 deletions(-)
hw/i386/kvm/i8259.c +1 -1
index ea77be8..d961eca 100644
@@ -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);
hw/intc/i8259.c +9 -7
index ce14bd0..fef00fc 100644
@@ -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, const QDict *qdict)
@@ -416,7 +418,7 @@ void pic_info(Monitor *mon, const QDict *qdict)
         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;
 }
hw/intc/i8259_common.c +4 -4
index 996ba9d..c2ba6a5 100644
@@ -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;
 }
@@ -153,9 +153,9 @@ static const 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)
include/hw/isa/i8259_internal.h +2 -1
index d3ddb27..b4e757a 100644
@@ -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 */
Signature · 1 line
1.8.1.4
#6 lore raw

PATCH v2 6/20 ide: QOM'ify ISA IDE

In reply to Andreas Färber

Introduce type constant and cast macro to obsolete DO_UPCAST(). Add missing braces.

Prepares for ISA realizefn.

---
 hw/ide/isa.c | 39 ++++++++++++++++++++++++---------------
 1 file changed, 24 insertions(+), 15 deletions(-)
hw/ide/isa.c +24 -15
index e0d47bf..5e7422f 100644
@@ -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[] = {
@@ -112,7 +121,7 @@ static void isa_ide_class_initfn(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo isa_ide_info = {
-    .name          = "isa-ide",
+    .name          = TYPE_ISA_IDE,
     .parent        = TYPE_ISA_DEVICE,
     .instance_size = sizeof(ISAIDEState),
     .class_init    = isa_ide_class_initfn,
Signature · 1 line
1.8.1.4
#7 lore raw

PATCH v2 7/20 m48t59: QOM'ify ISA M48T59 NVRAM

In reply to Andreas Färber

Introduce type constant and cast macro to obsolete DO_UPCAST() and container_of().

Prepares for ISA realizefn.

---
 hw/timer/m48t59.c | 35 +++++++++++++++++++++--------------
 1 file changed, 21 insertions(+), 14 deletions(-)
hw/timer/m48t59.c +21 -14
index 5019e06..45753d8 100644
@@ -72,8 +72,13 @@ struct M48t59State {
     uint8_t  lock;
 };
 
+#define TYPE_ISA_M48T59 "m48t59_isa"
+#define ISA_M48T59(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 = ISA_M48T59(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 = ISA_M48T59(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 = ISA_M48T59(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);
@@ -739,10 +746,10 @@ static void m48t59_init_class_isa1(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo m48t59_isa_info = {
-    .name          = "m48t59_isa",
+    .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[] = {
Signature · 1 line
1.8.1.4
#8 lore raw

PATCH v2 8/20 mc146818rtc: QOM'ify

In reply to Andreas Färber

Introduce type constant and cast macro to obsolete DO_UPCAST().

Prepares for ISA realizefn.

---
 hw/timer/mc146818rtc.c         | 36 ++++++++++++++++++++----------------
 include/hw/timer/mc146818rtc.h |  2 ++
 2 files changed, 22 insertions(+), 16 deletions(-)
hw/timer/mc146818rtc.c +20 -16
index 69e6844..afbd0db 100644
@@ -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;
@@ -672,14 +675,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);
@@ -741,7 +744,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
@@ -756,7 +759,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)
@@ -789,8 +792,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);
@@ -807,7 +809,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;
@@ -866,19 +868,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[] = {
@@ -899,7 +903,7 @@ static void rtc_class_initfn(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo mc146818rtc_info = {
-    .name          = "mc146818rtc",
+    .name          = TYPE_MC146818_RTC,
     .parent        = TYPE_ISA_DEVICE,
     .instance_size = sizeof(RTCState),
     .class_init    = rtc_class_initfn,
include/hw/timer/mc146818rtc.h +2 -0
index 854ea3f..425bd17 100644
@@ -4,6 +4,8 @@
 #include "hw/isa/isa.h"
 #include "hw/timer/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);
Signature · 1 line
1.8.1.4
Reviewed-by on v2 8/20
#9 lore raw

Re: [Qemu-devel] [PATCH for-1.5 v2 08/20] mc146818rtc: QOM'ify

Quoted 136 lines · On Sat, 27 Apr 2013 22:18:43 +0200 Andreas Färber <[email protected]> wrote:

Introduce type constant and cast macro to obsolete DO_UPCAST().

Prepares for ISA realizefn.

---
 hw/timer/mc146818rtc.c         | 36 ++++++++++++++++++++----------------
 include/hw/timer/mc146818rtc.h |  2 ++
 2 files changed, 22 insertions(+), 16 deletions(-)
hw/timer/mc146818rtc.c +20 -16
index 69e6844..afbd0db 100644
@@ -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;
@@ -672,14 +675,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);
@@ -741,7 +744,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
@@ -756,7 +759,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)
@@ -789,8 +792,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);
@@ -807,7 +809,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;
@@ -866,19 +868,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[] = {
@@ -899,7 +903,7 @@ static void rtc_class_initfn(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo mc146818rtc_info = {
-    .name          = "mc146818rtc",
+    .name          = TYPE_MC146818_RTC,
     .parent        = TYPE_ISA_DEVICE,
     .instance_size = sizeof(RTCState),
     .class_init    = rtc_class_initfn,
include/hw/timer/mc146818rtc.h +2 -0
index 854ea3f..425bd17 100644
@@ -4,6 +4,8 @@
 #include "hw/isa/isa.h"
 #include "hw/timer/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);
Signature · 1 line
1.8.1.4
Signature · 2 lines
Regards,
  Igor
#10 lore raw

PATCH v2 9/20 ne2000-isa: QOM'ify

In reply to Andreas Färber

Introduce type constant and cast macro to obsolete DO_UPCAST().

Prepares for ISA realizefn.

---
 hw/net/ne2000-isa.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
hw/net/ne2000-isa.c +7 -3
index a093aa8..f8e610c 100644
@@ -29,8 +29,12 @@
 #include "ne2000.h"
 #include "exec/address-spaces.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);
@@ -98,7 +102,7 @@ static void isa_ne2000_class_initfn(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo ne2000_isa_info = {
-    .name          = "ne2k_isa",
+    .name          = TYPE_ISA_NE2000,
     .parent        = TYPE_ISA_DEVICE,
     .instance_size = sizeof(ISANE2000State),
     .class_init    = isa_ne2000_class_initfn,
Signature · 1 line
1.8.1.4
#11 lore raw

PATCH v2 10/20 parallel: QOM'ify

In reply to Andreas Färber

Introduce type constant and cast macro to obsolete DO_UPCAST().

Prepares for ISA realizefn.

---
 hw/char/parallel.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
hw/char/parallel.c +8 -3
index b5e867f..8e48284 100644
@@ -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;
@@ -600,7 +605,7 @@ static void parallel_isa_class_initfn(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo parallel_isa_info = {
-    .name          = "isa-parallel",
+    .name          = TYPE_ISA_PARALLEL,
     .parent        = TYPE_ISA_DEVICE,
     .instance_size = sizeof(ISAParallelState),
     .class_init    = parallel_isa_class_initfn,
Signature · 1 line
1.8.1.4
#12 lore raw

PATCH v2 11/20 pc: QOM'ify port 92

In reply to Andreas Färber

Introduce type constant and cast macro to obsolete DO_UPCAST().

Prepares for ISA realizefn.

---
 hw/i386/pc.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
hw/i386/pc.c +9 -5
index 0d6e72b..29d2703 100644
@@ -429,9 +429,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;
@@ -463,7 +467,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;
 }
@@ -481,7 +485,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;
 }
@@ -498,7 +502,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);
@@ -518,7 +522,7 @@ static void port92_class_initfn(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo port92_info = {
-    .name          = "port92",
+    .name          = TYPE_PORT92,
     .parent        = TYPE_ISA_DEVICE,
     .instance_size = sizeof(Port92State),
     .class_init    = port92_class_initfn,
Signature · 1 line
1.8.1.4
#13 lore raw

PATCH v2 12/20 pckbd: QOM'ify

In reply to Andreas Färber

Introduce type constant and cast macro to obsolete DO_UPCAST().

Prepares for ISA realizefn.

---
 hw/input/pckbd.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)
hw/input/pckbd.c +11 -5
index 08ceb9f..17a5614 100644
@@ -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);
@@ -513,7 +519,7 @@ static void i8042_class_initfn(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo i8042_info = {
-    .name          = "i8042",
+    .name          = TYPE_I8042,
     .parent        = TYPE_ISA_DEVICE,
     .instance_size = sizeof(ISAKBDState),
     .class_init    = i8042_class_initfn,
Signature · 1 line
1.8.1.4
#14 lore raw

PATCH v2 13/20 pcspk: QOM'ify

In reply to Andreas Färber

Introduce type constant and cast macro to obsolete DO_UPCAST().

Prepares for ISA realizefn.

---
 hw/audio/pcspk.c         | 9 ++++++---
 include/hw/audio/pcspk.h | 4 +++-
 2 files changed, 9 insertions(+), 4 deletions(-)
hw/audio/pcspk.c +6 -3
index 34e0df7..d844e85 100644
@@ -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);
@@ -188,7 +191,7 @@ static void pcspk_class_initfn(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo pcspk_info = {
-    .name           = "isa-pcspk",
+    .name           = TYPE_PC_SPEAKER,
     .parent         = TYPE_ISA_DEVICE,
     .instance_size  = sizeof(PCSpkState),
     .class_init     = pcspk_class_initfn,
include/hw/audio/pcspk.h +3 -1
index ce8ef4f..b60c000 100644
@@ -28,11 +28,13 @@
 #include "hw/hw.h"
 #include "hw/isa/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);
Signature · 1 line
1.8.1.4
#15 lore raw

PATCH v2 14/20 sb16: QOM'ify

In reply to Andreas Färber

Introduce type constant and cast macro to obsolete DO_UPCAST().

Prepares for ISA realizefn.

---
 hw/audio/sb16.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
hw/audio/sb16.c +8 -6
index 783b6b4..61583bc 100644
@@ -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;
 }
 
@@ -1410,7 +1412,7 @@ static void sb16_class_initfn (ObjectClass *klass, void *data)
 }
 
 static const TypeInfo sb16_info = {
-    .name          = "sb16",
+    .name          = TYPE_SB16,
     .parent        = TYPE_ISA_DEVICE,
     .instance_size = sizeof (SB16State),
     .class_init    = sb16_class_initfn,
Signature · 1 line
1.8.1.4
#16 lore raw

PATCH v2 15/20 serial: QOM'ify ISA serial

In reply to Andreas Färber

Introduce type constant and cast macro to obsolete DO_UPCAST().

Prepares for ISA realizefn.

---
 hw/char/serial-isa.c     | 11 +++++++----
 include/hw/char/serial.h |  1 +
 2 files changed, 8 insertions(+), 4 deletions(-)
hw/char/serial-isa.c +7 -4
index ed140d0..342b4cc 100644
@@ -26,8 +26,11 @@
 #include "hw/char/serial.h"
 #include "hw/isa/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) {
@@ -100,7 +103,7 @@ static void serial_isa_class_initfn(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo serial_isa_info = {
-    .name          = "isa-serial",
+    .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;
     }
include/hw/char/serial.h +1 -0
index e884499..bca79f1 100644
@@ -96,6 +96,7 @@ 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);
 
 #endif
Signature · 1 line
1.8.1.4
#17 lore raw

PATCH v2 16/20 sga: QOM'ify

In reply to Andreas Färber

Introduce type constant and cast macro.

Prepares for ISA realizefn.

---
 hw/misc/sga.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
hw/misc/sga.c +7 -3
index 5cf4b86..c842190 100644
@@ -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);
@@ -49,7 +53,7 @@ static void sga_class_initfn(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo sga_info = {
-    .name          = "sga",
+    .name          = TYPE_SGA,
     .parent        = TYPE_ISA_DEVICE,
     .instance_size = sizeof(ISASGAState),
     .class_init    = sga_class_initfn,
Signature · 1 line
1.8.1.4
#18 lore raw

PATCH v2 17/20 vga-isa: QOM'ify ISA VGA

In reply to Andreas Färber

Introduce type constant and cast macro to obsolete DO_UPCAST() and container_of(). Prepares for ISA realizefn.

Unify function naming scheme while at it.

---
 hw/display/vga-isa.c | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)
hw/display/vga-isa.c +17 -12
index 2b3cc9b..9e63b69 100644
@@ -31,14 +31,18 @@
 #include "qemu/timer.h"
 #include "hw/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;
@@ -75,26 +79,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 const 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)
Signature · 1 line
1.8.1.4
#19 lore raw

PATCH v2 18/20 vmmouse: QOM'ify

In reply to Andreas Färber

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.

---
 hw/input/vmmouse.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
hw/input/vmmouse.c +9 -5
index f4f9c93..a610738 100644
@@ -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->queue_size = VMMOUSE_QUEUE_SIZE;
 
@@ -259,7 +263,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,7 +291,7 @@ static void vmmouse_class_initfn(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo vmmouse_info = {
-    .name          = "vmmouse",
+    .name          = TYPE_VMMOUSE,
     .parent        = TYPE_ISA_DEVICE,
     .instance_size = sizeof(VMMouseState),
     .class_init    = vmmouse_class_initfn,
Signature · 1 line
1.8.1.4
#20 lore raw

PATCH v2 19/20 vmport: QOM'ify

In reply to Andreas Färber

Introduce type constant and cast macro to obsolete DO_UPCAST(). Prepares for ISA realizefn.

Drop reserved underscore from struct name while at it.

---
 hw/misc/vmport.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
hw/misc/vmport.c +8 -4
index 0d07ea1..c146129 100644
@@ -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);
@@ -156,7 +160,7 @@ static void vmport_class_initfn(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo vmport_info = {
-    .name          = "vmport",
+    .name          = TYPE_VMPORT,
     .parent        = TYPE_ISA_DEVICE,
     .instance_size = sizeof(VMPortState),
     .class_init    = vmport_class_initfn,
Signature · 1 line
1.8.1.4
#21 lore raw

PATCH v2 20/20 wdt_ib700: QOM'ify

In reply to Andreas Färber

Introduce type constant and cast macro to obsolete DO_UPCAST().

Prepares for ISA realizefn.

---
 hw/watchdog/wdt_ib700.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
hw/watchdog/wdt_ib700.c +8 -4
index b8c4be8..6b8e33a 100644
@@ -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");
 
@@ -130,7 +134,7 @@ static void wdt_ib700_class_init(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo wdt_ib700_info = {
-    .name          = "ib700",
+    .name          = TYPE_IB700,
     .parent        = TYPE_ISA_DEVICE,
     .instance_size = sizeof(IB700State),
     .class_init    = wdt_ib700_class_init,
Signature · 1 line
1.8.1.4