Patchwork [20/26] hpet: QOM'ify some more

login
register
mail settings
Submitter Hu Tao
Date June 22, 2013, 8:50 a.m.
Message ID <da4c25150beef691e621410639e8bc4473dbea46.1371804804.git.hutao@cn.fujitsu.com>
Download mbox | patch
Permalink /patch/253384/
State New
Headers show

Comments

Hu Tao - June 22, 2013, 8:50 a.m.
Introduce type constant, avoid DO_UPCAST() and
FROM_SYSBUS().

Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Anthony Liguori <aliguori@us.ibm.com>
Cc: "Andreas Färber" <afaerber@suse.de>
Cc: Avi Kivity <avi@redhat.com>
Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
---
 hw/timer/hpet.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

Patch

diff --git a/hw/timer/hpet.c b/hw/timer/hpet.c
index 95aad3a..c2c4504 100644
--- a/hw/timer/hpet.c
+++ b/hw/timer/hpet.c
@@ -42,6 +42,9 @@ 
 
 #define HPET_MSI_SUPPORT        0
 
+#define TYPE_HPET "hpet"
+#define HPET(obj) OBJECT_CHECK(HPETState, (obj), TYPE_HPET)
+
 struct HPETState;
 typedef struct HPETTimer {  /* timers */
     uint8_t tn;             /*timer number*/
@@ -278,7 +281,7 @@  static const VMStateDescription vmstate_hpet_timer = {
 };
 
 static const VMStateDescription vmstate_hpet = {
-    .name = "hpet",
+    .name = TYPE_HPET,
     .version_id = 2,
     .minimum_version_id = 1,
     .minimum_version_id_old = 1,
@@ -634,7 +637,8 @@  static const MemoryRegionOps hpet_ram_ops = {
 
 static void hpet_reset(DeviceState *d)
 {
-    HPETState *s = FROM_SYSBUS(HPETState, SYS_BUS_DEVICE(d));
+    HPETState *s = HPET(d);
+    SysBusDevice *bus = SYS_BUS_DEVICE(d);
     int i;
 
     for (i = 0; i < s->num_timers; i++) {
@@ -657,7 +661,7 @@  static void hpet_reset(DeviceState *d)
     s->hpet_offset = 0ULL;
     s->config = 0ULL;
     hpet_cfg.hpet[s->hpet_id].event_timer_block_id = (uint32_t)s->capability;
-    hpet_cfg.hpet[s->hpet_id].address = SYS_BUS_DEVICE(d)->mmio[0].addr;
+    hpet_cfg.hpet[s->hpet_id].address = bus->mmio[0].addr;
 
     /* to document that the RTC lowers its output on reset as well */
     s->rtc_irq_level = 0;
@@ -665,7 +669,7 @@  static void hpet_reset(DeviceState *d)
 
 static void hpet_handle_legacy_irq(void *opaque, int n, int level)
 {
-    HPETState *s = FROM_SYSBUS(HPETState, opaque);
+    HPETState *s = opaque;
 
     if (n == HPET_LEGACY_PIT_INT) {
         if (!hpet_in_legacy_mode(s)) {
@@ -681,14 +685,14 @@  static void hpet_handle_legacy_irq(void *opaque, int n, int level)
 
 static void hpet_init(Object *obj)
 {
-    HPETState *s = DO_UPCAST(HPETState, busdev.qdev.parent_obj, obj);
+    HPETState *s = HPET(obj);
 
     memory_region_init_io(&s->iomem, &hpet_ram_ops, s, "hpet", 0x400);
 }
 
 static void hpet_realize(DeviceState *dev, Error **errp)
 {
-    HPETState *s = DO_UPCAST(HPETState, busdev.qdev, dev);
+    HPETState *s = HPET(dev);
     int i;
     HPETTimer *timer;
 
@@ -750,7 +754,7 @@  static void hpet_device_class_init(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo hpet_device_info = {
-    .name          = "hpet",
+    .name          = TYPE_HPET,
     .parent        = TYPE_SYS_BUS_DEVICE,
     .instance_size = sizeof(HPETState),
     .instance_init = hpet_init,