Patchwork [RFC,v1,14/20] piix3, ich9: create pc speaker through composition

login
register
mail settings
Submitter Hu Tao
Date May 22, 2013, 5:33 a.m.
Message ID <df34b18bf89b50571f41dac6ce0d701d841c851a.1369193012.git.hutao@cn.fujitsu.com>
Download mbox | patch
Permalink /patch/245523/
State New
Headers show

Comments

Hu Tao - May 22, 2013, 5:33 a.m.
Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
---
 hw/isa/lpc_ich9.c      |  9 +++++++--
 hw/pci-host/piix.c     | 10 ++++++++--
 include/hw/i386/ich9.h |  1 +
 3 files changed, 16 insertions(+), 4 deletions(-)

Patch

diff --git a/hw/isa/lpc_ich9.c b/hw/isa/lpc_ich9.c
index 42f60b9..a1927b2 100644
--- a/hw/isa/lpc_ich9.c
+++ b/hw/isa/lpc_ich9.c
@@ -597,8 +597,9 @@  static int ich9_lpc_realize(PCIDevice *d)
                               qdev_get_gpio_in(DEVICE(lpc->pit), 0));
     }
 
-    /* FIXME this should be refactored */
-    pcspk_init(lpc->isa_bus, lpc->pit);
+    /* Realize pcspk */
+    qdev_set_parent_bus(DEVICE(lpc->pcspk), BUS(lpc->isa_bus));
+    qdev_init_nofail(DEVICE(lpc->pcspk));
 
     return 0;
 }
@@ -669,6 +670,10 @@  static void ich9_lpc_initfn(Object *obj)
     }
     object_property_add_child(obj, "pit", OBJECT(s->pit), NULL);
     qdev_prop_set_uint32(DEVICE(s->pit), "iobase", 0x40);
+
+    s->pcspk = ISA_DEVICE(object_new(TYPE_PC_SPEAKER));
+    qdev_prop_set_uint32(&s->pcspk->qdev, "iobase", 0x61);
+    qdev_prop_set_ptr(&s->pcspk->qdev, "pit", s->pit);
 }
 
 static void ich9_lpc_class_init(ObjectClass *klass, void *data)
diff --git a/hw/pci-host/piix.c b/hw/pci-host/piix.c
index f3f3856..0030cad 100644
--- a/hw/pci-host/piix.c
+++ b/hw/pci-host/piix.c
@@ -77,6 +77,7 @@  typedef struct PIIX3State {
     DeviceState *hpet;
     ISADevice *rtc;
     ISADevice *pit;
+    ISADevice *pcspk;
 
     qemu_irq *pic;
 
@@ -630,8 +631,9 @@  static int piix3_realize(PCIDevice *dev)
                               qdev_get_gpio_in(DEVICE(s->pit), 0));
     }
 
-    /* FIXME this should be refactored */
-    pcspk_init(s->bus, s->pit);
+    /* Realize pcspk */
+    qdev_set_parent_bus(DEVICE(s->pcspk), BUS(s->bus));
+    qdev_init_nofail(DEVICE(s->pcspk));
 
     memory_region_init_io(&s->rcr_mem, &rcr_ops, s, "piix3-reset-control", 1);
     memory_region_add_subregion_overlap(pci_address_space_io(dev), RCR_IOPORT,
@@ -666,6 +668,10 @@  static void piix3_initfn(Object *obj)
     }
     object_property_add_child(obj, "pit", OBJECT(s->pit), NULL);
     qdev_prop_set_uint32(DEVICE(s->pit), "iobase", 0x40);
+
+    s->pcspk = ISA_DEVICE(object_new(TYPE_PC_SPEAKER));
+    qdev_prop_set_uint32(&s->pcspk->qdev, "iobase", 0x61);
+    qdev_prop_set_ptr(&s->pcspk->qdev, "pit", s->pit);
 }
 
 static void piix3_class_init(ObjectClass *klass, void *data)
diff --git a/include/hw/i386/ich9.h b/include/hw/i386/ich9.h
index 14ceafb..ad76b15 100644
--- a/include/hw/i386/ich9.h
+++ b/include/hw/i386/ich9.h
@@ -65,6 +65,7 @@  typedef struct ICH9LPCState {
     DeviceState *hpet;
     ISADevice *rtc;
     ISADevice *pit;
+    ISADevice *pcspk;
 
     qemu_irq *pic;
     qemu_irq *ioapic;