Patchwork [06/20,MIPS] qdev: convert i8042 to rc4030 device

login
register
mail settings
Submitter Hervé Poussineau
Date Aug. 1, 2010, 5:37 p.m.
Message ID <1280684242-19611-6-git-send-email-hpoussin@reactos.org>
Download mbox | patch
Permalink /patch/60476/
State New
Headers show

Comments

Hervé Poussineau - Aug. 1, 2010, 5:37 p.m.
Use it in Jazz emulation
Remove i8042_mm_init() function, which is not used anymore

Signed-off-by: Hervé Poussineau <hpoussin@reactos.org>
---
 hw/mips_jazz.c |    2 +-
 hw/pc.h        |    3 --
 hw/pckbd.c     |   65 ++++++++++++++++++++++++++++++++++++++-----------------
 3 files changed, 46 insertions(+), 24 deletions(-)

Patch

diff --git a/hw/mips_jazz.c b/hw/mips_jazz.c
index c000fd3..9663a3c 100644
--- a/hw/mips_jazz.c
+++ b/hw/mips_jazz.c
@@ -252,7 +252,7 @@  void mips_jazz_init (ram_addr_t ram_size,
     cpu_register_physical_memory(0x80004000, 0x00001000, s_rtc);
 
     /* Keyboard (i8042) */
-    i8042_mm_init(rc4030[6], rc4030[7], 0x80005000, 0x1000, 0x1);
+    rc4030_create_simple("rc4030-i8042");
 
     /* Serial ports */
     if (serial_hds[0]) {
diff --git a/hw/pc.h b/hw/pc.h
index 63b0249..e078fd9 100644
--- a/hw/pc.h
+++ b/hw/pc.h
@@ -74,9 +74,6 @@  void *vmmouse_init(void *m);
 /* pckbd.c */
 
 void i8042_init(qemu_irq kbd_irq, qemu_irq mouse_irq, uint32_t io_base);
-void i8042_mm_init(qemu_irq kbd_irq, qemu_irq mouse_irq,
-                   target_phys_addr_t base, ram_addr_t size,
-                   target_phys_addr_t mask);
 void i8042_isa_mouse_fake_event(void *opaque);
 void i8042_setup_a20_line(ISADevice *dev, qemu_irq *a20_out);
 
diff --git a/hw/pckbd.c b/hw/pckbd.c
index 0533b1d..c422a78 100644
--- a/hw/pckbd.c
+++ b/hw/pckbd.c
@@ -26,6 +26,8 @@ 
 #include "pc.h"
 #include "ps2.h"
 #include "sysemu.h"
+#include "rc4030.h"
+#include "qdev-addr.h"
 
 /* debug PC keyboard */
 //#define DEBUG_KBD
@@ -407,26 +409,6 @@  static CPUWriteMemoryFunc * const kbd_mm_write[] = {
     &kbd_mm_writeb,
 };
 
-void i8042_mm_init(qemu_irq kbd_irq, qemu_irq mouse_irq,
-                   target_phys_addr_t base, ram_addr_t size,
-                   target_phys_addr_t mask)
-{
-    KBDState *s = qemu_mallocz(sizeof(KBDState));
-    int s_io_memory;
-
-    s->irq_kbd = kbd_irq;
-    s->irq_mouse = mouse_irq;
-    s->mask = mask;
-
-    vmstate_register(NULL, 0, &vmstate_kbd, s);
-    s_io_memory = cpu_register_io_memory(kbd_mm_read, kbd_mm_write, s);
-    cpu_register_physical_memory(base, size, s_io_memory);
-
-    s->kbd = ps2_kbd_init(kbd_update_kbd_irq, s);
-    s->mouse = ps2_mouse_init(kbd_update_aux_irq, s);
-    qemu_register_reset(kbd_reset, s);
-}
-
 typedef struct ISAKBDState {
     ISADevice dev;
     KBDState  kbd;
@@ -486,8 +468,51 @@  static ISADeviceInfo i8042_info = {
     .init          = i8042_initfn,
 };
 
+typedef struct RC4030KBDState {
+    RC4030Device dev;
+    target_phys_addr_t iobase;
+    uint32_t size;
+    uint32_t irq_kbd;
+    uint32_t irq_aux;
+    KBDState kbd;
+} RC4030KBDState;
+
+static int i8042_rc4030_initfn(RC4030Device *dev)
+{
+    RC4030KBDState *rc4030 = DO_UPCAST(RC4030KBDState, dev, dev);
+    KBDState *s = &rc4030->kbd;
+    int s_io;
+
+    rc4030_init_irq(dev, &s->irq_kbd, rc4030->irq_kbd);
+    rc4030_init_irq(dev, &s->irq_mouse, rc4030->irq_aux);
+
+    s_io = cpu_register_io_memory(kbd_mm_read, kbd_mm_write, s);
+    cpu_register_physical_memory(rc4030->iobase, rc4030->size, s_io);
+
+    s->kbd = ps2_kbd_init(kbd_update_kbd_irq, s);
+    s->mouse = ps2_mouse_init(kbd_update_aux_irq, s);
+    qemu_register_reset(kbd_reset, s);
+
+    return 0;
+}
+
+static RC4030DeviceInfo i8042_rc4030_info = {
+    .qdev.name  = "rc4030-i8042",
+    .qdev.size  = sizeof(RC4030KBDState),
+    .init       = i8042_rc4030_initfn,
+    .qdev.props = (Property[]) {
+        DEFINE_PROP_TADDR("iobase", RC4030KBDState, iobase, 0x80005000),
+        DEFINE_PROP_HEX32("size", RC4030KBDState, size, 0x1000),
+        DEFINE_PROP_TADDR("mask", RC4030KBDState, kbd.mask, 0x1),
+        DEFINE_PROP_UINT32("irq_kbd", RC4030KBDState, irq_kbd, 6),
+        DEFINE_PROP_UINT32("irq_aux", RC4030KBDState, irq_aux, 7),
+        DEFINE_PROP_END_OF_LIST(),
+    },
+};
+
 static void i8042_register(void)
 {
     isa_qdev_register(&i8042_info);
+    rc4030_qdev_register(&i8042_rc4030_info);
 }
 device_init(i8042_register)