[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 08/26] fdc: QOM'ify some more
From: |
Hu Tao |
Subject: |
[Qemu-devel] [PATCH 08/26] fdc: QOM'ify some more |
Date: |
Sat, 22 Jun 2013 16:50:20 +0800 |
Introduce type constant and avoid DO_UPCAST().
Cc: Kevin Wolf <address@hidden>
Cc: Stefan Hajnoczi <address@hidden>
Signed-off-by: Hu Tao <address@hidden>
---
hw/block/fdc.c | 28 +++++++++++++++-------------
1 file changed, 15 insertions(+), 13 deletions(-)
diff --git a/hw/block/fdc.c b/hw/block/fdc.c
index 8b8f60e..4f5f8a8 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);
}
@@ -2153,7 +2155,7 @@ static void sysbus_fdc_initfn(Object *obj)
static void sysbus_fdc_realize(DeviceState *dev, Error **errp)
{
- FDCtrlSysBus *sys = DO_UPCAST(FDCtrlSysBus, busdev.qdev, dev);
+ FDCtrlSysBus *sys = SYSBUS_FDC(dev);
FDCtrl *fdctrl = &sys->state;
sysbus_init_mmio(SYS_BUS_DEVICE(dev), &fdctrl->iomem);
@@ -2170,7 +2172,7 @@ static void sysbus_fdc_realize(DeviceState *dev, Error
**errp)
static void sun4m_fdc_initfn(Object *obj)
{
- FDCtrlSysBus *sys = DO_UPCAST(FDCtrlSysBus, busdev.qdev.parent_obj, obj);
+ FDCtrlSysBus *sys = SYSBUS_FDC(obj);
FDCtrl *fdctrl = &sys->state;
memory_region_init_io(&fdctrl->iomem, &fdctrl_mem_strict_ops, fdctrl,
@@ -2270,7 +2272,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),
.instance_init = sysbus_fdc_initfn,
--
1.8.3.1
- Re: [Qemu-devel] [PATCH 01/26] ohci: use realize for ohci, (continued)
- [Qemu-devel] [PATCH 03/26] i440fx-pcihost: use realize for i440fx-pcihost, Hu Tao, 2013/06/22
- [Qemu-devel] [PATCH 02/26] ohci: QOM'ify some more, Hu Tao, 2013/06/22
- [Qemu-devel] [PATCH 04/26] i440fx: use type-safe cast instead of directly access of parent dev, Hu Tao, 2013/06/22
- [Qemu-devel] [PATCH 09/26] pflash_cfi01: use realize for pflash_cfi01, Hu Tao, 2013/06/22
- [Qemu-devel] [PATCH 07/26] fdc: use realize for fdc., Hu Tao, 2013/06/22
- [Qemu-devel] [PATCH 05/26] q35: use realize for q35 host, Hu Tao, 2013/06/22
- [Qemu-devel] [PATCH 10/26] pflash-cfi01: QOM'ify some more, Hu Tao, 2013/06/22
- [Qemu-devel] [PATCH 12/26] pflash-cfi02: QOM'ify some more, Hu Tao, 2013/06/22
- [Qemu-devel] [PATCH 11/26] pflash_cfi02: use realize for pflash_cfi02, Hu Tao, 2013/06/22
- [Qemu-devel] [PATCH 08/26] fdc: QOM'ify some more,
Hu Tao <=
- [Qemu-devel] [PATCH 14/26] ahci: QOM'ify some more, Hu Tao, 2013/06/22
- [Qemu-devel] [PATCH 06/26] q35: use type-safe cast instead of directly access of parent dev, Hu Tao, 2013/06/22
- [Qemu-devel] [PATCH 15/26] fwcfg: use realize for fwcfg, Hu Tao, 2013/06/22
- [Qemu-devel] [PATCH 16/26] fwcfg: QOM'ify some more, Hu Tao, 2013/06/22
- [Qemu-devel] [PATCH 17/26] scsi esp: use realize for scsi esp, Hu Tao, 2013/06/22
- [Qemu-devel] [PATCH 13/26] ahci: use realize for ahci, Hu Tao, 2013/06/22
- [Qemu-devel] [PATCH 21/26] kvmclock: use realize for kvmclock, Hu Tao, 2013/06/22