Patchwork [RFC,20/34] pcspk: QOM'ify

login
register
mail settings
Submitter Andreas Färber
Date Nov. 26, 2012, 12:12 a.m.
Message ID <1353888766-6951-21-git-send-email-afaerber@suse.de>
Download mbox | patch
Permalink /patch/201603/
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().

Prepares for ISA realizefn.

Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 hw/pcspk.c |   11 +++++++----
 hw/pcspk.h |    4 +++-
 2 Dateien geändert, 10 Zeilen hinzugefügt(+), 5 Zeilen entfernt(-)

Patch

diff --git a/hw/pcspk.c b/hw/pcspk.c
index ad6491b..f800962 100644
--- a/hw/pcspk.c
+++ b/hw/pcspk.c
@@ -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);
@@ -187,8 +190,8 @@  static void pcspk_class_initfn(ObjectClass *klass, void *data)
     dc->props = pcspk_properties;
 }
 
-static TypeInfo pcspk_info = {
-    .name           = "isa-pcspk",
+static const TypeInfo pcspk_info = {
+    .name           = TYPE_PC_SPEAKER,
     .parent         = TYPE_ISA_DEVICE,
     .instance_size  = sizeof(PCSpkState),
     .class_init     = pcspk_class_initfn,
diff --git a/hw/pcspk.h b/hw/pcspk.h
index 7f42bac..1ec7c41 100644
--- a/hw/pcspk.h
+++ b/hw/pcspk.h
@@ -28,11 +28,13 @@ 
 #include "hw.h"
 #include "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);