Patchwork [12/20,MIPS] qdev: convert g364fb to rc4030 device

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

Comments

Hervé Poussineau - Aug. 1, 2010, 5:37 p.m.
Use it in Jazz emulation

Signed-off-by: Hervé Poussineau <hpoussin@reactos.org>
---
 hw/g364fb.c    |   62 +++++++++++++++++++++++++++++++++++++++++--------------
 hw/mips.h      |    5 ----
 hw/mips_jazz.c |    2 +-
 vl.c           |    1 +
 4 files changed, 48 insertions(+), 22 deletions(-)

Patch

diff --git a/hw/g364fb.c b/hw/g364fb.c
index 3c8fb98..4b5e6ef 100644
--- a/hw/g364fb.c
+++ b/hw/g364fb.c
@@ -21,6 +21,8 @@ 
 #include "mips.h"
 #include "console.h"
 #include "pixel_ops.h"
+#include "rc4030.h"
+#include "qdev-addr.h"
 
 //#define DEBUG_G364
 
@@ -37,7 +39,7 @@  typedef struct G364State {
     /* hardware */
     uint8_t *vram;
     ram_addr_t vram_offset;
-    int vram_size;
+    uint32_t vram_size;
     qemu_irq irq;
     /* registers */
     uint8_t color_palette[256][3];
@@ -53,6 +55,14 @@  typedef struct G364State {
     int blanked;
 } G364State;
 
+typedef struct RC4030G364State {
+    RC4030Device dev;
+    target_phys_addr_t iobase;
+    target_phys_addr_t vram;
+    uint32_t irq;
+    G364State state;
+} RC4030G364State;
+
 #define REG_ID       0x000000
 #define REG_BOOT     0x080000
 #define REG_DISPLAY  0x080118
@@ -279,9 +289,8 @@  static inline void g364fb_invalidate_display(void *opaque)
     }
 }
 
-static void g364fb_reset(void *opaque)
+static void g364fb_reset(G364State *s)
 {
-    G364State *s = opaque;
     qemu_irq_lower(s->irq);
 
     memset(s->color_palette, 0, sizeof(s->color_palette));
@@ -292,7 +301,13 @@  static void g364fb_reset(void *opaque)
     s->top_of_screen = 0;
     s->width = s->height = 0;
     memset(s->vram, 0, s->vram_size);
-    g364fb_invalidate_display(opaque);
+    g364fb_invalidate_display(s);
+}
+
+static void g364fb_reset1(DeviceState *d)
+{
+    G364State *s = &container_of(d, RC4030G364State, dev.qdev)->state;
+    g364fb_reset(s);
 }
 
 static void g364fb_screen_dump(void *opaque, const char *filename)
@@ -583,32 +598,47 @@  static void g364fb_save(QEMUFile *f, void *opaque)
     qemu_put_be32(f, s->height);
 }
 
-int g364fb_mm_init(target_phys_addr_t vram_base,
-                   target_phys_addr_t ctrl_base, int it_shift,
-                   qemu_irq irq)
+static int g364fb_init(RC4030Device *dev)
 {
-    G364State *s;
+    RC4030G364State *rc4030 = container_of(dev, RC4030G364State, dev);
+    G364State *s = &rc4030->state;
     int io_ctrl;
 
-    s = qemu_mallocz(sizeof(G364State));
-
-    s->vram_size = 8 * 1024 * 1024;
     s->vram_offset = qemu_ram_alloc(NULL, "g364fb.vram", s->vram_size);
     s->vram = qemu_get_ram_ptr(s->vram_offset);
-    s->irq = irq;
+    rc4030_init_irq(dev, &s->irq, rc4030->irq);
 
-    qemu_register_reset(g364fb_reset, s);
     register_savevm(NULL, "g364fb", 0, 1, g364fb_save, g364fb_load, s);
-    g364fb_reset(s);
 
     s->ds = graphic_console_init(g364fb_update_display,
                                  g364fb_invalidate_display,
                                  g364fb_screen_dump, NULL, s);
 
-    cpu_register_physical_memory(vram_base, s->vram_size, s->vram_offset);
+    cpu_register_physical_memory(rc4030->vram, s->vram_size, s->vram_offset);
 
     io_ctrl = cpu_register_io_memory(g364fb_ctrl_read, g364fb_ctrl_write, s);
-    cpu_register_physical_memory(ctrl_base, 0x200000, io_ctrl);
+    cpu_register_physical_memory(rc4030->iobase, 0x200000, io_ctrl);
 
     return 0;
 }
+
+static RC4030DeviceInfo g364fb_device_info = {
+    .qdev.name  = "rc4030-g364fb",
+    .qdev.size  = sizeof(RC4030G364State),
+    .qdev.reset = g364fb_reset1,
+    .init       = g364fb_init,
+    .qdev.props = (Property[]) {
+        DEFINE_PROP_TADDR("iobase", RC4030G364State, iobase, 0x60000000),
+        DEFINE_PROP_TADDR("vram", RC4030G364State, vram, 0x40000000),
+        DEFINE_PROP_HEX32("vram_size", RC4030G364State, state.vram_size, 8 * 1024 * 1024),
+        DEFINE_PROP_UINT32("irq", RC4030G364State, irq, 3),
+        DEFINE_PROP_END_OF_LIST(),
+    },
+};
+
+static void g364fb_register_devices(void)
+{
+    rc4030_qdev_register(&g364fb_device_info);
+}
+
+device_init(g364fb_register_devices)
diff --git a/hw/mips.h b/hw/mips.h
index 023d85c..aa790d8 100644
--- a/hw/mips.h
+++ b/hw/mips.h
@@ -12,11 +12,6 @@  PCIBus *bonito_init(qemu_irq *pic);
 void *ds1225y_init(target_phys_addr_t mem_base, const char *filename);
 void ds1225y_set_protection(void *opaque, int protection);
 
-/* g364fb.c */
-int g364fb_mm_init(target_phys_addr_t vram_base,
-                   target_phys_addr_t ctrl_base, int it_shift,
-                   qemu_irq irq);
-
 /* mipsnet.c */
 void mipsnet_init(int base, qemu_irq irq, NICInfo *nd);
 
diff --git a/hw/mips_jazz.c b/hw/mips_jazz.c
index 96946e8..c4f3721 100644
--- a/hw/mips_jazz.c
+++ b/hw/mips_jazz.c
@@ -206,7 +206,7 @@  void mips_jazz_init (ram_addr_t ram_size,
     if (vga_interface_type != VGA_NONE) {
         switch (jazz_model) {
         case JAZZ_MAGNUM:
-            g364fb_mm_init(0x40000000, 0x60000000, 0, rc4030[3]);
+            rc4030_create_simple("rc4030-g364fb");
             break;
         case JAZZ_PICA61:
             isa_create_simple("isa-vga-mm");
diff --git a/vl.c b/vl.c
index 9815f8d..eb4c212 100644
--- a/vl.c
+++ b/vl.c
@@ -266,6 +266,7 @@  static struct {
     { .driver = "cirrus-vga",           .flag = &default_vga       },
     { .driver = "vmware-svga",          .flag = &default_vga       },
     { .driver = "isa-vga-mm",           .flag = &default_vga       },
+    { .driver = "rc4030-g364fb",        .flag = &default_vga       },
 };
 
 static int default_driver_check(QemuOpts *opts, void *opaque)