Patchwork [09/20,MIPS] qdev: convert jazz-led to sysbus device

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

Comments

Hervé Poussineau - Aug. 1, 2010, 5:37 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                        |   58 +++++++++++++++++-----------------
 hw/mips.h                            |    3 --
 hw/mips_jazz.c                       |    4 ++-
 9 files changed, 38 insertions(+), 34 deletions(-)

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 8a9c427..6c902b3 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -220,7 +220,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..76af572 100644
--- a/hw/jazz_led.c
+++ b/hw/jazz_led.c
@@ -26,6 +26,8 @@ 
 #include "mips.h"
 #include "console.h"
 #include "pixel_ops.h"
+#include "sysbus.h"
+#include "qdev-addr.h"
 
 //#define DEBUG_LED
 
@@ -43,6 +45,10 @@  typedef enum {
 } screen_state_t;
 
 typedef struct LedState {
+    SysBusDevice busdev;
+
+    target_phys_addr_t addr;
+    uint32_t size;
     uint8_t segments;
     DisplayState *ds;
     screen_state_t state;
@@ -70,30 +76,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 +110,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 +289,39 @@  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 jazz_led_init(SysBusDevice *dev)
 {
-    LedState *s;
+    LedState *s = FROM_SYSBUS(LedState, dev);
     int io;
 
-    s = qemu_mallocz(sizeof(LedState));
-
     s->state = REDRAW_SEGMENTS | REDRAW_BACKGROUND;
 
     io = cpu_register_io_memory(led_read, led_write, s);
-    cpu_register_physical_memory(base, 1, io);
+    cpu_register_physical_memory(s->addr, s->size, 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);
+
+    return 0;
+}
+
+static SysBusDeviceInfo jazz_led_device_info = {
+    .qdev.name  = "jazz-led",
+    .qdev.size  = sizeof(LedState),
+    .init       = jazz_led_init,
+    .qdev.props = (Property[]) {
+        DEFINE_PROP_TADDR("iobase", LedState, addr, 0x8000f000),
+        DEFINE_PROP_HEX32("size", LedState, size, 0x1000),
+        DEFINE_PROP_END_OF_LIST(),
+    },
+};
+
+static void jazz_led_register_devices(void)
+{
+    sysbus_register_withprop(&jazz_led_device_info);
 }
+
+device_init(jazz_led_register_devices)
diff --git a/hw/mips.h b/hw/mips.h
index 55fb701..023d85c 100644
--- a/hw/mips.h
+++ b/hw/mips.h
@@ -20,9 +20,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);
-
 /* dp8393x.c */
 void dp83932_init(NICInfo *nd, target_phys_addr_t base, int it_shift,
                   qemu_irq irq, void* mem_opaque,
diff --git a/hw/mips_jazz.c b/hw/mips_jazz.c
index 1298bc1..8c3c956 100644
--- a/hw/mips_jazz.c
+++ b/hw/mips_jazz.c
@@ -124,6 +124,7 @@  void mips_jazz_init (ram_addr_t ram_size,
     char *filename;
     int bios_size, n;
     BusState *cpu;
+    DeviceState *dev;
     qemu_irq *rc4030, *i8259;
     rc4030_dma *dmas;
     void* rc4030_opaque;
@@ -275,7 +276,8 @@  void mips_jazz_init (ram_addr_t ram_size,
     ds1225y_init(0x80009000, "nvram");
 
     /* LED indicator */
-    jazz_led_init(0x8000f000);
+    dev = qdev_create(NULL, "jazz-led");
+    qdev_init_nofail(dev);
 }
 
 static