Patchwork [11/20,MIPS] qdev: convert vga-isa-mm to ISA device

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

Comments

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

Signed-off-by: Hervé Poussineau <hpoussin@reactos.org>
---
 hw/mips_jazz.c  |    2 +-
 hw/pc.h         |    2 -
 hw/vga-isa-mm.c |   66 ++++++++++++++++++++++++++++++++----------------------
 vl.c            |    1 +
 4 files changed, 41 insertions(+), 30 deletions(-)

Patch

diff --git a/hw/mips_jazz.c b/hw/mips_jazz.c
index b737cf3..96946e8 100644
--- a/hw/mips_jazz.c
+++ b/hw/mips_jazz.c
@@ -209,7 +209,7 @@  void mips_jazz_init (ram_addr_t ram_size,
             g364fb_mm_init(0x40000000, 0x60000000, 0, rc4030[3]);
             break;
         case JAZZ_PICA61:
-            isa_vga_mm_init(0x40000000, 0x60000000, 0);
+            isa_create_simple("isa-vga-mm");
             break;
         default:
             break;
diff --git a/hw/pc.h b/hw/pc.h
index f5a479a..acfed83 100644
--- a/hw/pc.h
+++ b/hw/pc.h
@@ -154,8 +154,6 @@  extern enum vga_retrace_method vga_retrace_method;
 int isa_vga_init(void);
 int pci_vga_init(PCIBus *bus,
                  unsigned long vga_bios_offset, int vga_bios_size);
-int isa_vga_mm_init(target_phys_addr_t vram_base,
-                    target_phys_addr_t ctrl_base, int it_shift);
 
 /* cirrus_vga.c */
 void pci_cirrus_vga_init(PCIBus *bus);
diff --git a/hw/vga-isa-mm.c b/hw/vga-isa-mm.c
index 680b557..82d2e81 100644
--- a/hw/vga-isa-mm.c
+++ b/hw/vga-isa-mm.c
@@ -23,14 +23,17 @@ 
  */
 #include "hw.h"
 #include "console.h"
-#include "pc.h"
 #include "vga_int.h"
 #include "pixel_ops.h"
 #include "qemu-timer.h"
+#include "isa.h"
+#include "qdev-addr.h"
 
 typedef struct ISAVGAMMState {
+    ISADevice dev;
+    target_phys_addr_t iobase;
+    target_phys_addr_t vram;
     VGACommonState vga;
-    int it_shift;
 } ISAVGAMMState;
 
 /* Memory mapped interface */
@@ -38,7 +41,7 @@  static uint32_t vga_mm_readb (void *opaque, target_phys_addr_t addr)
 {
     ISAVGAMMState *s = opaque;
 
-    return vga_ioport_read(&s->vga, addr >> s->it_shift) & 0xff;
+    return vga_ioport_read(&s->vga, addr) & 0xff;
 }
 
 static void vga_mm_writeb (void *opaque,
@@ -46,14 +49,14 @@  static void vga_mm_writeb (void *opaque,
 {
     ISAVGAMMState *s = opaque;
 
-    vga_ioport_write(&s->vga, addr >> s->it_shift, value & 0xff);
+    vga_ioport_write(&s->vga, addr, value & 0xff);
 }
 
 static uint32_t vga_mm_readw (void *opaque, target_phys_addr_t addr)
 {
     ISAVGAMMState *s = opaque;
 
-    return vga_ioport_read(&s->vga, addr >> s->it_shift) & 0xffff;
+    return vga_ioport_read(&s->vga, addr) & 0xffff;
 }
 
 static void vga_mm_writew (void *opaque,
@@ -61,14 +64,14 @@  static void vga_mm_writew (void *opaque,
 {
     ISAVGAMMState *s = opaque;
 
-    vga_ioport_write(&s->vga, addr >> s->it_shift, value & 0xffff);
+    vga_ioport_write(&s->vga, addr, value & 0xffff);
 }
 
 static uint32_t vga_mm_readl (void *opaque, target_phys_addr_t addr)
 {
     ISAVGAMMState *s = opaque;
 
-    return vga_ioport_read(&s->vga, addr >> s->it_shift);
+    return vga_ioport_read(&s->vga, addr);
 }
 
 static void vga_mm_writel (void *opaque,
@@ -76,7 +79,7 @@  static void vga_mm_writel (void *opaque,
 {
     ISAVGAMMState *s = opaque;
 
-    vga_ioport_write(&s->vga, addr >> s->it_shift, value);
+    vga_ioport_write(&s->vga, addr, value);
 }
 
 static CPUReadMemoryFunc * const vga_mm_read_ctrl[] = {
@@ -91,36 +94,45 @@  static CPUWriteMemoryFunc * const vga_mm_write_ctrl[] = {
     &vga_mm_writel,
 };
 
-static void vga_mm_init(ISAVGAMMState *s, target_phys_addr_t vram_base,
-                        target_phys_addr_t ctrl_base, int it_shift)
+static int isa_vga_mm_init(ISADevice *dev)
 {
+    ISAVGAMMState *s = DO_UPCAST(ISAVGAMMState, dev, dev);
     int s_ioport_ctrl, vga_io_memory;
 
-    s->it_shift = it_shift;
+    vga_common_init(&s->vga, VGA_RAM_SIZE);
+
     s_ioport_ctrl = cpu_register_io_memory(vga_mm_read_ctrl, vga_mm_write_ctrl, s);
-    vga_io_memory = cpu_register_io_memory(vga_mem_read, vga_mem_write, s);
+    vga_io_memory = cpu_register_io_memory(vga_mem_read, vga_mem_write, &s->vga);
 
     vmstate_register(NULL, 0, &vmstate_vga_common, s);
 
-    cpu_register_physical_memory(ctrl_base, 0x100000, s_ioport_ctrl);
+    cpu_register_physical_memory(s->iobase, 0x100000, s_ioport_ctrl);
     s->vga.bank_offset = 0;
-    cpu_register_physical_memory(vram_base + 0x000a0000, 0x20000, vga_io_memory);
-    qemu_register_coalesced_mmio(vram_base + 0x000a0000, 0x20000);
-}
-
-int isa_vga_mm_init(target_phys_addr_t vram_base,
-                    target_phys_addr_t ctrl_base, int it_shift)
-{
-    ISAVGAMMState *s;
-
-    s = qemu_mallocz(sizeof(*s));
-
-    vga_common_init(&s->vga, VGA_RAM_SIZE);
-    vga_mm_init(s, vram_base, ctrl_base, it_shift);
+    cpu_register_physical_memory(s->vram + 0x000a0000, 0x20000, vga_io_memory);
+    qemu_register_coalesced_mmio(s->vram + 0x000a0000, 0x20000);
 
     s->vga.ds = graphic_console_init(s->vga.update, s->vga.invalidate,
-                                     s->vga.screen_dump, s->vga.text_update, s);
+                                     s->vga.screen_dump, s->vga.text_update, &s->vga);
 
     vga_init_vbe(&s->vga);
     return 0;
 }
+
+static ISADeviceInfo isa_vga_mm_device_info = {
+    .qdev.name  = "isa-vga-mm",
+    .qdev.size  = sizeof(ISAVGAMMState),
+    .qdev.vmsd  = &vmstate_vga_common,
+    .init       = isa_vga_mm_init,
+    .qdev.props = (Property[]) {
+        DEFINE_PROP_TADDR("iobase", ISAVGAMMState, iobase, 0x60000000),
+        DEFINE_PROP_TADDR("vram", ISAVGAMMState, vram, 0x40000000),
+        DEFINE_PROP_END_OF_LIST(),
+    },
+};
+
+static void isa_vga_mm_register_device(void)
+{
+    isa_qdev_register(&isa_vga_mm_device_info);
+}
+
+device_init(isa_vga_mm_register_device)
diff --git a/vl.c b/vl.c
index b3e3676..9815f8d 100644
--- a/vl.c
+++ b/vl.c
@@ -265,6 +265,7 @@  static struct {
     { .driver = "VGA",                  .flag = &default_vga       },
     { .driver = "cirrus-vga",           .flag = &default_vga       },
     { .driver = "vmware-svga",          .flag = &default_vga       },
+    { .driver = "isa-vga-mm",           .flag = &default_vga       },
 };
 
 static int default_driver_check(QemuOpts *opts, void *opaque)