Patchwork [RFC,09/34] fdc: QOM'ify ISA floppy controller

login
register
mail settings
Submitter Andreas Färber
Date Nov. 26, 2012, 12:12 a.m.
Message ID <1353888766-6951-10-git-send-email-afaerber@suse.de>
Download mbox | patch
Permalink /patch/201621/
State New
Headers show

Comments

Andreas Färber - Nov. 26, 2012, 12:12 a.m.
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(-)

Patch

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",\
         }, {\