Patchwork [1/8,MIPS] qdev: convert i8042 to sysbus device

login
register
mail settings
Submitter Hervé Poussineau
Date Sept. 8, 2010, 8:39 p.m.
Message ID <1283978392-6313-2-git-send-email-hpoussin@reactos.org>
Download mbox | patch
Permalink /patch/64207/
State New
Headers show

Comments

Hervé Poussineau - Sept. 8, 2010, 8:39 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 |    3 ++-
 hw/pc.h        |    3 ---
 hw/pckbd.c     |   55 +++++++++++++++++++++++++++++++++++--------------------
 3 files changed, 37 insertions(+), 24 deletions(-)
Markus Armbruster - Sept. 25, 2010, 9:47 a.m.
Hervé Poussineau <hpoussin@reactos.org> writes:

> 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 |    3 ++-
>  hw/pc.h        |    3 ---
>  hw/pckbd.c     |   55 +++++++++++++++++++++++++++++++++++--------------------
>  3 files changed, 37 insertions(+), 24 deletions(-)
>
> diff --git a/hw/mips_jazz.c b/hw/mips_jazz.c
> index 5d5305a..e306839 100644
> --- a/hw/mips_jazz.c
> +++ b/hw/mips_jazz.c
> @@ -37,6 +37,7 @@
>  #include "loader.h"
>  #include "mc146818rtc.h"
>  #include "blockdev.h"
> +#include "sysbus.h"
>  
>  enum jazz_model_e
>  {
> @@ -263,7 +264,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);
> +    sysbus_create_varargs("rc4030-i8042", 0x80005000, rc4030[6], rc4030[7], NULL);
>  
>      /* 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 6e4e406..33dc953 100644
> --- a/hw/pckbd.c
> +++ b/hw/pckbd.c
> @@ -26,6 +26,7 @@
>  #include "pc.h"
>  #include "ps2.h"
>  #include "sysemu.h"
> +#include "sysbus.h"
>  
>  /* debug PC keyboard */
>  //#define DEBUG_KBD
> @@ -424,26 +425,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;
> @@ -503,8 +484,42 @@ static ISADeviceInfo i8042_info = {
>      .init          = i8042_initfn,
>  };
>  
> +typedef struct SysBusKBDState {
> +    SysBusDevice busdev;
> +    KBDState kbd;
> +} SysBusKBDState;
> +
> +static int i8042_sysbus_initfn(SysBusDevice *dev)
> +{
> +    KBDState *s = &FROM_SYSBUS(SysBusKBDState, dev)->kbd;
> +    int s_io;
> +
> +    sysbus_init_irq(dev, &s->irq_kbd);
> +    sysbus_init_irq(dev, &s->irq_mouse);
> +
> +    s_io = cpu_register_io_memory(kbd_mm_read, kbd_mm_write, s);
> +    sysbus_init_mmio(dev, 0x1000, s_io);
> +
> +    s->mask = 0x1;
> +    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 SysBusDeviceInfo i8042_sysbus_info = {
> +    .qdev.name  = "rc4030-i8042",
> +    .qdev.size  = sizeof(SysBusKBDState),
> +    .init       = i8042_sysbus_initfn,
> +    .qdev.props = (Property[]) {
> +        DEFINE_PROP_END_OF_LIST(),
> +    },
> +};
> +

Shouldn't you initialize qdev.vmsd here?

>  static void i8042_register(void)
>  {
>      isa_qdev_register(&i8042_info);
> +    sysbus_register_withprop(&i8042_sysbus_info);
>  }
>  device_init(i8042_register)

Patch

diff --git a/hw/mips_jazz.c b/hw/mips_jazz.c
index 5d5305a..e306839 100644
--- a/hw/mips_jazz.c
+++ b/hw/mips_jazz.c
@@ -37,6 +37,7 @@ 
 #include "loader.h"
 #include "mc146818rtc.h"
 #include "blockdev.h"
+#include "sysbus.h"
 
 enum jazz_model_e
 {
@@ -263,7 +264,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);
+    sysbus_create_varargs("rc4030-i8042", 0x80005000, rc4030[6], rc4030[7], NULL);
 
     /* 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 6e4e406..33dc953 100644
--- a/hw/pckbd.c
+++ b/hw/pckbd.c
@@ -26,6 +26,7 @@ 
 #include "pc.h"
 #include "ps2.h"
 #include "sysemu.h"
+#include "sysbus.h"
 
 /* debug PC keyboard */
 //#define DEBUG_KBD
@@ -424,26 +425,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;
@@ -503,8 +484,42 @@  static ISADeviceInfo i8042_info = {
     .init          = i8042_initfn,
 };
 
+typedef struct SysBusKBDState {
+    SysBusDevice busdev;
+    KBDState kbd;
+} SysBusKBDState;
+
+static int i8042_sysbus_initfn(SysBusDevice *dev)
+{
+    KBDState *s = &FROM_SYSBUS(SysBusKBDState, dev)->kbd;
+    int s_io;
+
+    sysbus_init_irq(dev, &s->irq_kbd);
+    sysbus_init_irq(dev, &s->irq_mouse);
+
+    s_io = cpu_register_io_memory(kbd_mm_read, kbd_mm_write, s);
+    sysbus_init_mmio(dev, 0x1000, s_io);
+
+    s->mask = 0x1;
+    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 SysBusDeviceInfo i8042_sysbus_info = {
+    .qdev.name  = "rc4030-i8042",
+    .qdev.size  = sizeof(SysBusKBDState),
+    .init       = i8042_sysbus_initfn,
+    .qdev.props = (Property[]) {
+        DEFINE_PROP_END_OF_LIST(),
+    },
+};
+
 static void i8042_register(void)
 {
     isa_qdev_register(&i8042_info);
+    sysbus_register_withprop(&i8042_sysbus_info);
 }
 device_init(i8042_register)