Patchwork [3/8,MIPS] qdev: convert jazz-led to sysbus device

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

Comments

Hervé Poussineau - Sept. 8, 2010, 8:39 p.m.
Use it in Jazz emulation
Remove jazz_led_init() function, which is not used anymore
Compile jazz_led.c file only once

Signed-off-by: Hervé Poussineau <hpoussin@reactos.org>
---
 Makefile.objs                        |    1 +
 Makefile.target                      |    2 +-
 default-configs/mips-softmmu.mak     |    1 +
 default-configs/mips64-softmmu.mak   |    1 +
 default-configs/mips64el-softmmu.mak |    1 +
 default-configs/mipsel-softmmu.mak   |    1 +
 hw/jazz_led.c                        |   81 ++++++++++++++++++++--------------
 hw/mips.h                            |    3 -
 hw/mips_jazz.c                       |    2 +-
 9 files changed, 55 insertions(+), 38 deletions(-)
Markus Armbruster - Sept. 25, 2010, 9:55 a.m.
Hervé Poussineau <hpoussin@reactos.org> writes:

> Use it in Jazz emulation
> Remove jazz_led_init() function, which is not used anymore
> Compile jazz_led.c file only once
[...]
> diff --git a/hw/jazz_led.c b/hw/jazz_led.c
> index 4cb680c..f364301 100644
> --- a/hw/jazz_led.c
> +++ b/hw/jazz_led.c
[...]
> @@ -70,30 +70,18 @@ static uint32_t led_readb(void *opaque, target_phys_addr_t addr)
>  static uint32_t led_readw(void *opaque, target_phys_addr_t addr)
>  {
>      uint32_t v;
> -#ifdef TARGET_WORDS_BIGENDIAN
> -    v = led_readb(opaque, addr) << 8;
> -    v |= led_readb(opaque, addr + 1);
> -#else
>      v = led_readb(opaque, addr);
>      v |= led_readb(opaque, addr + 1) << 8;
> -#endif
>      return v;
>  }

Stupid question: why can you drop the #if here?

[...]

Patch

diff --git a/Makefile.objs b/Makefile.objs
index 4a1eaa1..fb25c66 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -231,6 +231,7 @@  hw-obj-$(CONFIG_RC4030) += rc4030.o
 hw-obj-$(CONFIG_DP8393X) += dp8393x.o
 hw-obj-$(CONFIG_DS1225Y) += ds1225y.o
 hw-obj-$(CONFIG_MIPSNET) += mipsnet.o
+hw-obj-$(CONFIG_JAZZ_LED) += jazz_led.o
 
 # Sound
 sound-obj-y =
diff --git a/Makefile.target b/Makefile.target
index 18826bb..78b37ab 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -223,7 +223,7 @@  obj-ppc-$(CONFIG_FDT) += device_tree.o
 obj-mips-y = mips_r4k.o mips_jazz.o mips_malta.o mips_mipssim.o
 obj-mips-y += mips_addr.o mips_timer.o mips_int.o
 obj-mips-y += vga.o i8259.o
-obj-mips-y += g364fb.o jazz_led.o
+obj-mips-y += g364fb.o
 obj-mips-y += gt64xxx.o mc146818rtc.o
 obj-mips-y += cirrus_vga.o
 obj-mips-$(CONFIG_FULONG) += bonito.o vt82c686.o mips_fulong2e.o
diff --git a/default-configs/mips-softmmu.mak b/default-configs/mips-softmmu.mak
index 3d0af83..69bb235 100644
--- a/default-configs/mips-softmmu.mak
+++ b/default-configs/mips-softmmu.mak
@@ -30,3 +30,4 @@  CONFIG_DP8393X=y
 CONFIG_DS1225Y=y
 CONFIG_MIPSNET=y
 CONFIG_PFLASH_CFI01=y
+CONFIG_JAZZ_LED=y
diff --git a/default-configs/mips64-softmmu.mak b/default-configs/mips64-softmmu.mak
index 0030de4..0421bb6 100644
--- a/default-configs/mips64-softmmu.mak
+++ b/default-configs/mips64-softmmu.mak
@@ -30,3 +30,4 @@  CONFIG_DP8393X=y
 CONFIG_DS1225Y=y
 CONFIG_MIPSNET=y
 CONFIG_PFLASH_CFI01=y
+CONFIG_JAZZ_LED=y
diff --git a/default-configs/mips64el-softmmu.mak b/default-configs/mips64el-softmmu.mak
index fa2a3ff..b5d4406 100644
--- a/default-configs/mips64el-softmmu.mak
+++ b/default-configs/mips64el-softmmu.mak
@@ -32,3 +32,4 @@  CONFIG_DS1225Y=y
 CONFIG_MIPSNET=y
 CONFIG_PFLASH_CFI01=y
 CONFIG_FULONG=y
+CONFIG_JAZZ_LED=y
diff --git a/default-configs/mipsel-softmmu.mak b/default-configs/mipsel-softmmu.mak
index 238b73a..0d9a093 100644
--- a/default-configs/mipsel-softmmu.mak
+++ b/default-configs/mipsel-softmmu.mak
@@ -30,3 +30,4 @@  CONFIG_DP8393X=y
 CONFIG_DS1225Y=y
 CONFIG_MIPSNET=y
 CONFIG_PFLASH_CFI01=y
+CONFIG_JAZZ_LED=y
diff --git a/hw/jazz_led.c b/hw/jazz_led.c
index 4cb680c..f364301 100644
--- a/hw/jazz_led.c
+++ b/hw/jazz_led.c
@@ -22,10 +22,9 @@ 
  * THE SOFTWARE.
  */
 
-#include "hw.h"
-#include "mips.h"
 #include "console.h"
 #include "pixel_ops.h"
+#include "sysbus.h"
 
 //#define DEBUG_LED
 
@@ -43,6 +42,7 @@  typedef enum {
 } screen_state_t;
 
 typedef struct LedState {
+    DeviceState qdev;
     uint8_t segments;
     DisplayState *ds;
     screen_state_t state;
@@ -70,30 +70,18 @@  static uint32_t led_readb(void *opaque, target_phys_addr_t addr)
 static uint32_t led_readw(void *opaque, target_phys_addr_t addr)
 {
     uint32_t v;
-#ifdef TARGET_WORDS_BIGENDIAN
-    v = led_readb(opaque, addr) << 8;
-    v |= led_readb(opaque, addr + 1);
-#else
     v = led_readb(opaque, addr);
     v |= led_readb(opaque, addr + 1) << 8;
-#endif
     return v;
 }
 
 static uint32_t led_readl(void *opaque, target_phys_addr_t addr)
 {
     uint32_t v;
-#ifdef TARGET_WORDS_BIGENDIAN
-    v = led_readb(opaque, addr) << 24;
-    v |= led_readb(opaque, addr + 1) << 16;
-    v |= led_readb(opaque, addr + 2) << 8;
-    v |= led_readb(opaque, addr + 3);
-#else
     v = led_readb(opaque, addr);
     v |= led_readb(opaque, addr + 1) << 8;
     v |= led_readb(opaque, addr + 2) << 16;
     v |= led_readb(opaque, addr + 3) << 24;
-#endif
     return v;
 }
 
@@ -116,28 +104,16 @@  static void led_writeb(void *opaque, target_phys_addr_t addr, uint32_t val)
 
 static void led_writew(void *opaque, target_phys_addr_t addr, uint32_t val)
 {
-#ifdef TARGET_WORDS_BIGENDIAN
-    led_writeb(opaque, addr, (val >> 8) & 0xff);
-    led_writeb(opaque, addr + 1, val & 0xff);
-#else
     led_writeb(opaque, addr, val & 0xff);
     led_writeb(opaque, addr + 1, (val >> 8) & 0xff);
-#endif
 }
 
 static void led_writel(void *opaque, target_phys_addr_t addr, uint32_t val)
 {
-#ifdef TARGET_WORDS_BIGENDIAN
-    led_writeb(opaque, addr, (val >> 24) & 0xff);
-    led_writeb(opaque, addr + 1, (val >> 16) & 0xff);
-    led_writeb(opaque, addr + 2, (val >> 8) & 0xff);
-    led_writeb(opaque, addr + 3, val & 0xff);
-#else
     led_writeb(opaque, addr, val & 0xff);
     led_writeb(opaque, addr + 1, (val >> 8) & 0xff);
     led_writeb(opaque, addr + 2, (val >> 16) & 0xff);
     led_writeb(opaque, addr + 3, (val >> 24) & 0xff);
-#endif
 }
 
 static CPUReadMemoryFunc * const led_read[3] = {
@@ -307,21 +283,60 @@  static void jazz_led_text_update(void *opaque, console_ch_t *chardata)
     dpy_update(s->ds, 0, 0, 2, 1);
 }
 
-void jazz_led_init(target_phys_addr_t base)
+static int led_post_load(void *opaque, int version_id)
 {
-    LedState *s;
-    int io;
+    LedState *s = opaque;
 
-    s = qemu_mallocz(sizeof(LedState));
+    jazz_led_invalidate_display(s);
+    return 0;
+}
 
-    s->state = REDRAW_SEGMENTS | REDRAW_BACKGROUND;
+static const VMStateDescription vmstate_led = {
+    .name = "jazz-led",
+    .version_id = 0,
+    .minimum_version_id = 0,
+    .minimum_version_id_old = 0,
+    .post_load = led_post_load,
+    .fields = (VMStateField []) {
+        VMSTATE_UINT8(segments, LedState),
+        VMSTATE_END_OF_LIST()
+    }
+};
 
-    io = cpu_register_io_memory(led_read, led_write, s);
-    cpu_register_physical_memory(base, 1, io);
+typedef struct {
+    SysBusDevice busdev;
+    LedState leds;
+} SysBusLedState;
+
+static int led_sysbus_initfn(SysBusDevice *dev)
+{
+    LedState *s = &FROM_SYSBUS(SysBusLedState, dev)->leds;
+    int s_io;
+
+    s_io = cpu_register_io_memory(led_read, led_write, s);
+    sysbus_init_mmio(dev, 0x1000, s_io);
 
     s->ds = graphic_console_init(jazz_led_update_display,
                                  jazz_led_invalidate_display,
                                  jazz_led_screen_dump,
                                  jazz_led_text_update, s);
     qemu_console_resize(s->ds, 60, 80);
+
+    led_post_load(s, 0);
+
+    return 0;
 }
+
+static SysBusDeviceInfo led_sysbus_info = {
+    .qdev.name  = "jazz-led",
+    .qdev.size  = sizeof(SysBusLedState),
+    .qdev.vmsd  = &vmstate_led,
+    .init       = led_sysbus_initfn,
+};
+
+static void led_register(void)
+{
+    sysbus_register_withprop(&led_sysbus_info);
+}
+
+device_init(led_register)
diff --git a/hw/mips.h b/hw/mips.h
index 8f32ba0..285f7dc 100644
--- a/hw/mips.h
+++ b/hw/mips.h
@@ -16,9 +16,6 @@  int g364fb_mm_init(target_phys_addr_t vram_base,
 /* mipsnet.c */
 void mipsnet_init(int base, qemu_irq irq, NICInfo *nd);
 
-/* jazz_led.c */
-extern void jazz_led_init(target_phys_addr_t base);
-
 /* rc4030.c */
 typedef struct rc4030DMAState *rc4030_dma;
 void rc4030_dma_memory_rw(void *opaque, target_phys_addr_t addr, uint8_t *buf, int len, int is_write);
diff --git a/hw/mips_jazz.c b/hw/mips_jazz.c
index 06968d3..0af4044 100644
--- a/hw/mips_jazz.c
+++ b/hw/mips_jazz.c
@@ -294,7 +294,7 @@  void mips_jazz_init (ram_addr_t ram_size,
     sysbus_create_simple("nvram", 0x80009000, NULL);
 
     /* LED indicator */
-    jazz_led_init(0x8000f000);
+    sysbus_create_simple("jazz-led", 0x8000f000, NULL);
 }
 
 static