Patchwork [06/10] convert i8042 as piix3 proper QOM child

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

Comments

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

I8042 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/pc.c    |    9 ++-------
 hw/pckbd.c |   24 +-----------------------
 hw/piix3.c |   13 +++++++++++--
 hw/piix3.h |   24 ++++++++++++++++++++++++
 hw/ps2.h   |    3 +++
 5 files changed, 41 insertions(+), 32 deletions(-)

Patch

diff --git a/hw/pc.c b/hw/pc.c
index 94fdea9..a14bf5a 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -931,8 +931,7 @@  static void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi,
 {
     int i;
     DriveInfo *fd[MAX_FD];
-    qemu_irq *a20_line;
-    ISADevice *i8042, *vmmouse;
+    ISADevice *vmmouse;
     qemu_irq *cpu_exit_irq;
 
     register_ioport_write(0x80, 1, 1, ioport80_write, NULL);
@@ -951,9 +950,6 @@  static void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi,
         }
     }
 
-    a20_line = qemu_allocate_irqs(handle_a20_line_change, first_cpu, 1);
-    i8042 = isa_create_simple(isa_bus, "i8042");
-    i8042_setup_a20_line(i8042, &a20_line[0]);
     if (!no_vmport) {
         vmport_init(isa_bus);
         vmmouse = isa_try_create(isa_bus, "vmmouse");
@@ -961,7 +957,6 @@  static void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi,
         vmmouse = NULL;
     }
     if (vmmouse) {
-        qdev_prop_set_ptr(&vmmouse->qdev, "ps2_mouse", i8042);
         qdev_init_nofail(&vmmouse->qdev);
     }
 
@@ -1153,8 +1148,8 @@  static void pc_init1(MemoryRegion *system_memory,
         i440fx_state = NULL;
         isa_bus = isa_bus_new(NULL, system_io);
         no_hpet = 1;
+        isa_bus_irqs(isa_bus, gsi);
     }
-    isa_bus_irqs(isa_bus, gsi);
 
     if (kvm_irqchip_in_kernel()) {
         i8259 = kvm_i8259_init(isa_bus);
diff --git a/hw/pckbd.c b/hw/pckbd.c
index 5bb3e0a..d76bcbb 100644
--- a/hw/pckbd.c
+++ b/hw/pckbd.c
@@ -126,22 +126,6 @@ 
 #define KBD_PENDING_KBD         1
 #define KBD_PENDING_AUX         2
 
-typedef struct KBDState {
-    uint8_t write_cmd; /* if non zero, write data to port 60 is expected */
-    uint8_t status;
-    uint8_t mode;
-    uint8_t outport;
-    /* Bitmask of devices with data available.  */
-    uint8_t pending;
-    void *kbd;
-    void *mouse;
-
-    qemu_irq irq_kbd;
-    qemu_irq irq_mouse;
-    qemu_irq *a20_out;
-    hwaddr mask;
-} KBDState;
-
 /* update irq and KBD_STAT_[MOUSE_]OBF */
 /* XXX: not generating the irqs if KBD_MODE_DISABLE_KBD is set may be
    incorrect, but it avoids having to simulate exact delays */
@@ -431,12 +415,6 @@  void i8042_mm_init(qemu_irq kbd_irq, qemu_irq mouse_irq,
     qemu_register_reset(kbd_reset, s);
 }
 
-typedef struct ISAKBDState {
-    ISADevice dev;
-    KBDState kbd;
-    MemoryRegion io[2];
-} ISAKBDState;
-
 void i8042_isa_mouse_fake_event(void *opaque)
 {
     ISADevice *dev = opaque;
@@ -513,7 +491,7 @@  static void i8042_class_initfn(ObjectClass *klass, void *data)
 }
 
 static TypeInfo i8042_info = {
-    .name          = "i8042",
+    .name          = TYPE_I8042,
     .parent        = TYPE_ISA_DEVICE,
     .instance_size = sizeof(ISAKBDState),
     .class_init    = i8042_class_initfn,
diff --git a/hw/piix3.c b/hw/piix3.c
index 675212e..c6bf3cb 100644
--- a/hw/piix3.c
+++ b/hw/piix3.c
@@ -202,6 +202,8 @@  static int piix3_realize(PCIDevice *dev)
     s->bus = isa_bus_new(DEVICE(dev), pci_address_space_io(dev));
     isa_bus_irqs(s->bus, s->pic);
 
+    a20_line = qemu_allocate_irqs(handle_a20_line_change, first_cpu, 2);
+
     /* Realize the RTC */
     qdev_set_parent_bus(DEVICE(&s->rtc), BUS(s->bus));
     qdev_init_nofail(DEVICE(&s->rtc));
@@ -260,8 +262,12 @@  static int piix3_realize(PCIDevice *dev)
     /* Realize the PORT92 */
     qdev_set_parent_bus(DEVICE(&s->port92), BUS(s->bus));
     qdev_init_nofail(DEVICE(&s->port92));
-    a20_line = qemu_allocate_irqs(handle_a20_line_change, first_cpu, 1);
-    s->port92.a20_out = &a20_line[0];
+    s->port92.a20_out = &a20_line[1];
+
+    /* Realize the I8042 */
+    qdev_set_parent_bus(DEVICE(&s->i8042), BUS(s->bus));
+    i8042_setup_a20_line(ISA_DEVICE(&s->i8042), &a20_line[0]);
+    qdev_init_nofail(DEVICE(&s->i8042));
 
     return 0;
 }
@@ -298,6 +304,9 @@  static void piix3_initfn(Object *obj)
 
     object_initialize(&s->port92, TYPE_PORT92);
     object_property_add_child(obj, "port92", OBJECT(&s->port92), NULL);
+
+    object_initialize(&s->i8042, TYPE_I8042);
+    object_property_add_child(obj, "i8042", OBJECT(&s->i8042), NULL);
 }
 
 static void piix3_class_init(ObjectClass *klass, void *data)
diff --git a/hw/piix3.h b/hw/piix3.h
index 4e5ee20..94a0daf 100644
--- a/hw/piix3.h
+++ b/hw/piix3.h
@@ -35,6 +35,7 @@ 
 #include "i8254.h"
 #include "i8254_internal.h"
 #include "pcspk.h"
+#include "ps2.h"
 
 #define PIIX_NUM_PIC_IRQS       16      /* i8259 * 2 */
 #define PIIX_NUM_PIRQS          4ULL    /* PIRQ[A-D] */
@@ -61,6 +62,28 @@  typedef struct Port92State {
     qemu_irq *a20_out;
 } Port92State;
 
+typedef struct KBDState {
+    uint8_t write_cmd; /* if non zero, write data to port 60 is expected */
+    uint8_t status;
+    uint8_t mode;
+    uint8_t outport;
+    /* Bitmask of devices with data available.  */
+    uint8_t pending;
+    void *kbd;
+    void *mouse;
+
+    qemu_irq irq_kbd;
+    qemu_irq irq_mouse;
+    qemu_irq *a20_out;
+    hwaddr mask;
+} KBDState;
+
+typedef struct ISAKBDState {
+    ISADevice dev;
+    KBDState kbd;
+    MemoryRegion io[2];
+} ISAKBDState;
+
 typedef struct PIIX3State {
     PCIDevice dev;
 
@@ -90,6 +113,7 @@  typedef struct PIIX3State {
 #endif
     PCSpkState pcspk;
     Port92State port92;
+    ISAKBDState i8042;
 
     qemu_irq *pic;
 
diff --git a/hw/ps2.h b/hw/ps2.h
index 7c45ce7..1cd7c07 100644
--- a/hw/ps2.h
+++ b/hw/ps2.h
@@ -25,6 +25,9 @@ 
 #ifndef HW_PS2_H
 #define HW_PS2_H
 
+
+#define TYPE_I8042 "i8042"
+
 /* ps2.c */
 void *ps2_kbd_init(void (*update_irq)(void *, int), void *update_arg);
 void *ps2_mouse_init(void (*update_irq)(void *, int), void *update_arg);