[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 08/26] fdc: QOM'ify some more
From: |
Hu Tao |
Subject: |
[Qemu-devel] [PATCH v2 08/26] fdc: QOM'ify some more |
Date: |
Mon, 1 Jul 2013 18:18:24 +0800 |
Introduce type constant and avoid DO_UPCAST(), container_of(),
and use DEVICE() to avoid accessing parent qdev directly.
Signed-off-by: Hu Tao <address@hidden>
---
hw/block/fdc.c | 37 ++++++++++++++++++++-----------------
1 file changed, 20 insertions(+), 17 deletions(-)
diff --git a/hw/block/fdc.c b/hw/block/fdc.c
index 930f191..f8270cb 100644
--- a/hw/block/fdc.c
+++ b/hw/block/fdc.c
@@ -544,6 +544,9 @@ struct FDCtrl {
uint8_t timer1;
};
+#define TYPE_SYSBUS_FDC "sysbus-fdc"
+#define SYSBUS_FDC(obj) OBJECT_CHECK(FDCtrlSysBus, (obj), TYPE_SYSBUS_FDC)
+
typedef struct FDCtrlSysBus {
SysBusDevice busdev;
struct FDCtrl state;
@@ -773,10 +776,9 @@ static const VMStateDescription vmstate_fdc = {
static void fdctrl_external_reset_sysbus(DeviceState *d)
{
- FDCtrlSysBus *sys = container_of(d, FDCtrlSysBus, busdev.qdev);
- FDCtrl *s = &sys->state;
+ FDCtrlSysBus *sys = SYSBUS_FDC(d);
- fdctrl_reset(s, 0);
+ fdctrl_reset(&sys->state, 0);
}
static void fdctrl_external_reset_isa(DeviceState *d)
@@ -2049,8 +2051,8 @@ void fdctrl_init_sysbus(qemu_irq irq, int dma_chann,
DeviceState *dev;
FDCtrlSysBus *sys;
- dev = qdev_create(NULL, "sysbus-fdc");
- sys = DO_UPCAST(FDCtrlSysBus, busdev.qdev, dev);
+ dev = qdev_create(NULL, TYPE_SYSBUS_FDC);
+ sys = SYSBUS_FDC(dev);
fdctrl = &sys->state;
fdctrl->dma_chann = dma_chann; /* FIXME */
if (fds[0]) {
@@ -2060,8 +2062,8 @@ void fdctrl_init_sysbus(qemu_irq irq, int dma_chann,
qdev_prop_set_drive_nofail(dev, "driveB", fds[1]->bdrv);
}
qdev_init_nofail(dev);
- sysbus_connect_irq(&sys->busdev, 0, irq);
- sysbus_mmio_map(&sys->busdev, 0, mmio_base);
+ sysbus_connect_irq(SYS_BUS_DEVICE(sys), 0, irq);
+ sysbus_mmio_map(SYS_BUS_DEVICE(sys), 0, mmio_base);
}
void sun4m_fdctrl_init(qemu_irq irq, hwaddr io_base,
@@ -2075,9 +2077,9 @@ void sun4m_fdctrl_init(qemu_irq irq, hwaddr io_base,
qdev_prop_set_drive_nofail(dev, "drive", fds[0]->bdrv);
}
qdev_init_nofail(dev);
- sys = DO_UPCAST(FDCtrlSysBus, busdev.qdev, dev);
- sysbus_connect_irq(&sys->busdev, 0, irq);
- sysbus_mmio_map(&sys->busdev, 0, io_base);
+ sys = SYSBUS_FDC(dev);
+ sysbus_connect_irq(SYS_BUS_DEVICE(sys), 0, irq);
+ sysbus_mmio_map(SYS_BUS_DEVICE(sys), 0, io_base);
*fdc_tc = qdev_get_gpio_in(dev, 0);
}
@@ -2145,17 +2147,17 @@ static void isabus_fdc_realize(DeviceState *dev, Error
**errp)
static int sysbus_fdc_init1(SysBusDevice *dev)
{
- FDCtrlSysBus *sys = DO_UPCAST(FDCtrlSysBus, busdev, dev);
+ FDCtrlSysBus *sys = SYSBUS_FDC(dev);
FDCtrl *fdctrl = &sys->state;
int ret;
memory_region_init_io(&fdctrl->iomem, &fdctrl_mem_ops, fdctrl, "fdc",
0x08);
sysbus_init_mmio(dev, &fdctrl->iomem);
sysbus_init_irq(dev, &fdctrl->irq);
- qdev_init_gpio_in(&dev->qdev, fdctrl_handle_tc, 1);
+ qdev_init_gpio_in(DEVICE(dev), fdctrl_handle_tc, 1);
fdctrl->dma_chann = -1;
- qdev_set_legacy_instance_id(&dev->qdev, 0 /* io */, 2); /* FIXME */
+ qdev_set_legacy_instance_id(DEVICE(dev), 0 /* io */, 2); /* FIXME */
ret = fdctrl_init_common(fdctrl);
return ret;
@@ -2163,16 +2165,17 @@ static int sysbus_fdc_init1(SysBusDevice *dev)
static int sun4m_fdc_init1(SysBusDevice *dev)
{
- FDCtrl *fdctrl = &(FROM_SYSBUS(FDCtrlSysBus, dev)->state);
+ FDCtrlSysBus *sys = SYSBUS_FDC(dev);
+ FDCtrl *fdctrl = &sys->state;
memory_region_init_io(&fdctrl->iomem, &fdctrl_mem_strict_ops, fdctrl,
"fdctrl", 0x08);
sysbus_init_mmio(dev, &fdctrl->iomem);
sysbus_init_irq(dev, &fdctrl->irq);
- qdev_init_gpio_in(&dev->qdev, fdctrl_handle_tc, 1);
+ qdev_init_gpio_in(DEVICE(dev), fdctrl_handle_tc, 1);
fdctrl->sun4m = 1;
- qdev_set_legacy_instance_id(&dev->qdev, 0 /* io */, 2); /* FIXME */
+ qdev_set_legacy_instance_id(DEVICE(dev), 0 /* io */, 2); /* FIXME */
return fdctrl_init_common(fdctrl);
}
@@ -2253,7 +2256,7 @@ static void sysbus_fdc_class_init(ObjectClass *klass,
void *data)
}
static const TypeInfo sysbus_fdc_info = {
- .name = "sysbus-fdc",
+ .name = TYPE_SYSBUS_FDC,
.parent = TYPE_SYS_BUS_DEVICE,
.instance_size = sizeof(FDCtrlSysBus),
.class_init = sysbus_fdc_class_init,
--
1.8.3.1
- [Qemu-devel] [PATCH v2 02/26] ohci: QOM'ify some more, (continued)
- [Qemu-devel] [PATCH v2 02/26] ohci: QOM'ify some more, Hu Tao, 2013/07/01
- [Qemu-devel] [PATCH v2 03/26] ohci: use realize for ohci, Hu Tao, 2013/07/01
- [Qemu-devel] [PATCH v2 05/26] i440fx: use type-safe cast instead of directly access of parent dev, Hu Tao, 2013/07/01
- [Qemu-devel] [PATCH v2 04/26] i440fx-pcihost: use realize for i440fx-pcihost, Hu Tao, 2013/07/01
- [Qemu-devel] [PATCH v2 06/26] q35: use type-safe cast instead of directly access of parent dev, Hu Tao, 2013/07/01
- [Qemu-devel] [PATCH v2 08/26] fdc: QOM'ify some more,
Hu Tao <=
- [Qemu-devel] [PATCH v2 07/26] q35: use realize for q35 host, Hu Tao, 2013/07/01
- [Qemu-devel] [PATCH v2 11/26] pflash_cfi01: use realize for pflash_cfi01, Hu Tao, 2013/07/01
- [Qemu-devel] [PATCH v2 09/26] fdc: use realize for fdc., Hu Tao, 2013/07/01
- [Qemu-devel] [PATCH v2 12/26] pflash-cfi02: QOM'ify some more, Hu Tao, 2013/07/01
- [Qemu-devel] [PATCH v2 14/26] ahci: QOM'ify some more, Hu Tao, 2013/07/01