Patchwork [04/10] convert PCSPK as piix3 proper QOM child

login
register
mail settings
Submitter Wanpeng Li
Date Nov. 8, 2012, 5:36 a.m.
Message ID <1352352999-2561-5-git-send-email-liwanp@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/197769/
State New
Headers show

Comments

Wanpeng Li - Nov. 8, 2012, 5:36 a.m.
convert PCSPK as piix3 proper QOM child.

PCSPK creation for the PIIX3 is done by calling object_init() with
qdev_init() being called for each child device in the PIIX3 ::init
function.

Signed-off-by: Wanpeng Li <liwanp@linux.vnet.ibm.com>
---
 hw/pcspk.c |   19 +------------------
 hw/pcspk.h |   19 +++++++++++++++++++
 hw/piix3.c |    8 ++++++++
 hw/piix3.h |    2 ++
 4 files changed, 30 insertions(+), 18 deletions(-)

Patch

diff --git a/hw/pcspk.c b/hw/pcspk.c
index ad6491b..fc8bc99 100644
--- a/hw/pcspk.c
+++ b/hw/pcspk.c
@@ -25,31 +25,14 @@ 
 #include "hw.h"
 #include "pc.h"
 #include "isa.h"
-#include "audio/audio.h"
 #include "qemu-timer.h"
 #include "i8254.h"
 #include "pcspk.h"
 
-#define PCSPK_BUF_LEN 1792
 #define PCSPK_SAMPLE_RATE 32000
 #define PCSPK_MAX_FREQ (PCSPK_SAMPLE_RATE >> 1)
 #define PCSPK_MIN_COUNT ((PIT_FREQ + PCSPK_MAX_FREQ - 1) / PCSPK_MAX_FREQ)
 
-typedef struct {
-    ISADevice dev;
-    MemoryRegion ioport;
-    uint32_t iobase;
-    uint8_t sample_buf[PCSPK_BUF_LEN];
-    QEMUSoundCard card;
-    SWVoiceOut *voice;
-    void *pit;
-    unsigned int pit_count;
-    unsigned int samples;
-    unsigned int play_pos;
-    int data_on;
-    int dummy_refresh_clock;
-} PCSpkState;
-
 static const char *s_spk = "pcspk";
 static PCSpkState *pcspk_state;
 
@@ -188,7 +171,7 @@  static void pcspk_class_initfn(ObjectClass *klass, void *data)
 }
 
 static TypeInfo pcspk_info = {
-    .name           = "isa-pcspk",
+    .name           = TYPE_PCSPK,
     .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..07b3a8f 100644
--- a/hw/pcspk.h
+++ b/hw/pcspk.h
@@ -27,6 +27,25 @@ 
 
 #include "hw.h"
 #include "isa.h"
+#include "audio/audio.h"
+
+#define PCSPK_BUF_LEN 1792
+#define TYPE_PCSPK "isa-pcspk"
+
+typedef struct {
+    ISADevice dev;
+    MemoryRegion ioport;
+    uint32_t iobase;
+    uint8_t sample_buf[PCSPK_BUF_LEN];
+    QEMUSoundCard card;
+    SWVoiceOut *voice;
+    void *pit;
+    unsigned int pit_count;
+    unsigned int samples;
+    unsigned int play_pos;
+    int data_on;
+    int dummy_refresh_clock;
+} PCSpkState;
 
 static inline ISADevice *pcspk_init(ISABus *bus, ISADevice *pit)
 {
diff --git a/hw/piix3.c b/hw/piix3.c
index 41739bd..35a0de9 100644
--- a/hw/piix3.c
+++ b/hw/piix3.c
@@ -250,6 +250,11 @@  static int piix3_realize(PCIDevice *dev)
             qdev_get_gpio_in(DEVICE(&s->pit), 0));
         }
     }
+    /* Realize the PCSPK */
+    qdev_set_parent_bus(DEVICE(&s->pcspk), BUS(s->bus));
+    qdev_prop_set_uint32(DEVICE(&s->pcspk), "iobase", 0x61);
+    qdev_prop_set_ptr(DEVICE(&s->pcspk), "pit", ISA_DEVICE(&s->pit));
+    qdev_init_nofail(DEVICE(&s->pcspk));
 
     return 0;
 }
@@ -280,6 +285,9 @@  static void piix3_initfn(Object *obj)
             qdev_prop_set_int32(DEVICE(&s->pit), "iobase", 0x40);
        }
     }
+
+    object_initialize(&s->pcspk, TYPE_PCSPK);
+    object_property_add_child(obj, "pcspk", OBJECT(&s->pcspk), NULL);
 }
 
 static void piix3_class_init(ObjectClass *klass, void *data)
diff --git a/hw/piix3.h b/hw/piix3.h
index 58486b9..32f7a95 100644
--- a/hw/piix3.h
+++ b/hw/piix3.h
@@ -34,6 +34,7 @@ 
 #include "hpet_emul.h"
 #include "i8254.h"
 #include "i8254_internal.h"
+#include "pcspk.h"
 
 #define PIIX_NUM_PIC_IRQS       16      /* i8259 * 2 */
 #define PIIX_NUM_PIRQS          4ULL    /* PIRQ[A-D] */
@@ -77,6 +78,7 @@  typedef struct PIIX3State {
         KVMPITState kvm_pit;
     } pit;
 #endif
+    PCSpkState pcspk;
 
     qemu_irq *pic;