Patchwork [5/8,MIPS] qdev: convert ISA VGA MM to sysbus device

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

Comments

Hervé Poussineau - Sept. 8, 2010, 8:39 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 |   94 ++++++++++++++++++++++++++++++++-----------------------
 3 files changed, 56 insertions(+), 42 deletions(-)
Blue Swirl - Sept. 9, 2010, 2:28 p.m.
2010/9/8 Hervé Poussineau <hpoussin@reactos.org>:
> 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 |   94 ++++++++++++++++++++++++++++++++-----------------------
>  3 files changed, 56 insertions(+), 42 deletions(-)
>
> diff --git a/hw/mips_jazz.c b/hw/mips_jazz.c
> index 5c66cd4..98567d2 100644
> --- a/hw/mips_jazz.c
> +++ b/hw/mips_jazz.c
> @@ -218,7 +218,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);
> +        sysbus_create_simple("sysbus-vga", 0x60000000, NULL);
>         break;
>     default:
>         break;
> diff --git a/hw/pc.h b/hw/pc.h
> index e078fd9..946ae78 100644
> --- a/hw/pc.h
> +++ b/hw/pc.h
> @@ -153,8 +153,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..ecd6a41 100644
> --- a/hw/vga-isa-mm.c
> +++ b/hw/vga-isa-mm.c
> @@ -21,62 +21,58 @@
>  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
>  * THE SOFTWARE.
>  */
> -#include "hw.h"
> +
>  #include "console.h"
> -#include "pc.h"
>  #include "vga_int.h"
>  #include "pixel_ops.h"
> -#include "qemu-timer.h"
> +#include "sysbus.h"
>
> -typedef struct ISAVGAMMState {
> -    VGACommonState vga;
> -    int it_shift;
> -} ISAVGAMMState;
> +#define VRAM_BASE 0x40000000
>
>  /* Memory mapped interface */
>  static uint32_t vga_mm_readb (void *opaque, target_phys_addr_t addr)
>  {
> -    ISAVGAMMState *s = opaque;
> +    VGACommonState *s = opaque;
>
> -    return vga_ioport_read(&s->vga, addr >> s->it_shift) & 0xff;
> +    return vga_ioport_read(s, addr) & 0xff;
>  }
>
>  static void vga_mm_writeb (void *opaque,
>                            target_phys_addr_t addr, uint32_t value)
>  {
> -    ISAVGAMMState *s = opaque;
> +    VGACommonState *s = opaque;
>
> -    vga_ioport_write(&s->vga, addr >> s->it_shift, value & 0xff);
> +    vga_ioport_write(s, addr, value & 0xff);
>  }
>
>  static uint32_t vga_mm_readw (void *opaque, target_phys_addr_t addr)
>  {
> -    ISAVGAMMState *s = opaque;
> +    VGACommonState *s = opaque;
>
> -    return vga_ioport_read(&s->vga, addr >> s->it_shift) & 0xffff;
> +    return vga_ioport_read(s, addr) & 0xffff;
>  }
>
>  static void vga_mm_writew (void *opaque,
>                            target_phys_addr_t addr, uint32_t value)
>  {
> -    ISAVGAMMState *s = opaque;
> +    VGACommonState *s = opaque;
>
> -    vga_ioport_write(&s->vga, addr >> s->it_shift, value & 0xffff);
> +    vga_ioport_write(s, addr, value & 0xffff);
>  }
>
>  static uint32_t vga_mm_readl (void *opaque, target_phys_addr_t addr)
>  {
> -    ISAVGAMMState *s = opaque;
> +    VGACommonState *s = opaque;
>
> -    return vga_ioport_read(&s->vga, addr >> s->it_shift);
> +    return vga_ioport_read(s, addr);
>  }
>
>  static void vga_mm_writel (void *opaque,
>                            target_phys_addr_t addr, uint32_t value)
>  {
> -    ISAVGAMMState *s = opaque;
> +    VGACommonState *s = opaque;
>
> -    vga_ioport_write(&s->vga, addr >> s->it_shift, value);
> +    vga_ioport_write(s, addr, value);
>  }
>
>  static CPUReadMemoryFunc * const vga_mm_read_ctrl[] = {
> @@ -91,36 +87,56 @@ 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)
> +typedef struct {
> +    SysBusDevice busdev;
> +    VGACommonState vga;
> +} SysBusVGAState;
> +
> +static const VMStateDescription vmstate_vga = {
> +    .name = "sysbus-vga",
> +    .version_id = 0,
> +    .minimum_version_id = 0,
> +    .minimum_version_id_old = 0,
> +    .fields = (VMStateField []) {
> +        VMSTATE_STRUCT(vga, SysBusVGAState, 0, vmstate_vga_common, VGACommonState),
> +        VMSTATE_END_OF_LIST()
> +    }
> +};
> +
> +static int vga_sysbus_initfn(SysBusDevice *dev)
>  {
> +    VGACommonState *s = &FROM_SYSBUS(SysBusVGAState, dev)->vga;
>     int s_ioport_ctrl, vga_io_memory;
>
> -    s->it_shift = it_shift;
> +    vga_common_init(s, VGA_RAM_SIZE);
> +    s->bank_offset = 0;
> +
>     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);
>
> -    vmstate_register(NULL, 0, &vmstate_vga_common, s);
> +    cpu_register_physical_memory(VRAM_BASE + 0x000a0000, 0x20000, vga_io_memory);
> +    qemu_register_coalesced_mmio(VRAM_BASE + 0x000a0000, 0x20000);
>
> -    cpu_register_physical_memory(ctrl_base, 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);

These should be created with sysbus_init_mmio(), but that doesn't
handle MMIO coalescing. Perhaps we need sysbus_init_coalesced_mmio().

> -}
> +    sysbus_init_mmio(dev, 0x100000, s_ioport_ctrl);
>
> -int isa_vga_mm_init(target_phys_addr_t vram_base,
> -                    target_phys_addr_t ctrl_base, int it_shift)
> -{
> -    ISAVGAMMState *s;
> +    s->ds = graphic_console_init(s->update, s->invalidate,
> +                                 s->screen_dump, s->text_update, s);
>
> -    s = qemu_mallocz(sizeof(*s));
> +    vga_init_vbe(s);
>
> -    vga_common_init(&s->vga, VGA_RAM_SIZE);
> -    vga_mm_init(s, vram_base, ctrl_base, it_shift);
> +    return 0;
> +}
>
> -    s->vga.ds = graphic_console_init(s->vga.update, s->vga.invalidate,
> -                                     s->vga.screen_dump, s->vga.text_update, s);
> +static SysBusDeviceInfo vga_sysbus_info = {
> +    .qdev.name  = "sysbus-vga",
> +    .qdev.size  = sizeof(SysBusVGAState),
> +    .qdev.vmsd  = &vmstate_vga,
> +    .init       = vga_sysbus_initfn,
> +};
>
> -    vga_init_vbe(&s->vga);
> -    return 0;
> +static void vga_register(void)
> +{
> +    sysbus_register_withprop(&vga_sysbus_info);
>  }
> +
> +device_init(vga_register)
> --
> 1.7.1.GIT
>
>
>

Patch

diff --git a/hw/mips_jazz.c b/hw/mips_jazz.c
index 5c66cd4..98567d2 100644
--- a/hw/mips_jazz.c
+++ b/hw/mips_jazz.c
@@ -218,7 +218,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);
+        sysbus_create_simple("sysbus-vga", 0x60000000, NULL);
         break;
     default:
         break;
diff --git a/hw/pc.h b/hw/pc.h
index e078fd9..946ae78 100644
--- a/hw/pc.h
+++ b/hw/pc.h
@@ -153,8 +153,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..ecd6a41 100644
--- a/hw/vga-isa-mm.c
+++ b/hw/vga-isa-mm.c
@@ -21,62 +21,58 @@ 
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
-#include "hw.h"
+
 #include "console.h"
-#include "pc.h"
 #include "vga_int.h"
 #include "pixel_ops.h"
-#include "qemu-timer.h"
+#include "sysbus.h"
 
-typedef struct ISAVGAMMState {
-    VGACommonState vga;
-    int it_shift;
-} ISAVGAMMState;
+#define VRAM_BASE 0x40000000
 
 /* Memory mapped interface */
 static uint32_t vga_mm_readb (void *opaque, target_phys_addr_t addr)
 {
-    ISAVGAMMState *s = opaque;
+    VGACommonState *s = opaque;
 
-    return vga_ioport_read(&s->vga, addr >> s->it_shift) & 0xff;
+    return vga_ioport_read(s, addr) & 0xff;
 }
 
 static void vga_mm_writeb (void *opaque,
                            target_phys_addr_t addr, uint32_t value)
 {
-    ISAVGAMMState *s = opaque;
+    VGACommonState *s = opaque;
 
-    vga_ioport_write(&s->vga, addr >> s->it_shift, value & 0xff);
+    vga_ioport_write(s, addr, value & 0xff);
 }
 
 static uint32_t vga_mm_readw (void *opaque, target_phys_addr_t addr)
 {
-    ISAVGAMMState *s = opaque;
+    VGACommonState *s = opaque;
 
-    return vga_ioport_read(&s->vga, addr >> s->it_shift) & 0xffff;
+    return vga_ioport_read(s, addr) & 0xffff;
 }
 
 static void vga_mm_writew (void *opaque,
                            target_phys_addr_t addr, uint32_t value)
 {
-    ISAVGAMMState *s = opaque;
+    VGACommonState *s = opaque;
 
-    vga_ioport_write(&s->vga, addr >> s->it_shift, value & 0xffff);
+    vga_ioport_write(s, addr, value & 0xffff);
 }
 
 static uint32_t vga_mm_readl (void *opaque, target_phys_addr_t addr)
 {
-    ISAVGAMMState *s = opaque;
+    VGACommonState *s = opaque;
 
-    return vga_ioport_read(&s->vga, addr >> s->it_shift);
+    return vga_ioport_read(s, addr);
 }
 
 static void vga_mm_writel (void *opaque,
                            target_phys_addr_t addr, uint32_t value)
 {
-    ISAVGAMMState *s = opaque;
+    VGACommonState *s = opaque;
 
-    vga_ioport_write(&s->vga, addr >> s->it_shift, value);
+    vga_ioport_write(s, addr, value);
 }
 
 static CPUReadMemoryFunc * const vga_mm_read_ctrl[] = {
@@ -91,36 +87,56 @@  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)
+typedef struct {
+    SysBusDevice busdev;
+    VGACommonState vga;
+} SysBusVGAState;
+
+static const VMStateDescription vmstate_vga = {
+    .name = "sysbus-vga",
+    .version_id = 0,
+    .minimum_version_id = 0,
+    .minimum_version_id_old = 0,
+    .fields = (VMStateField []) {
+        VMSTATE_STRUCT(vga, SysBusVGAState, 0, vmstate_vga_common, VGACommonState),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
+static int vga_sysbus_initfn(SysBusDevice *dev)
 {
+    VGACommonState *s = &FROM_SYSBUS(SysBusVGAState, dev)->vga;
     int s_ioport_ctrl, vga_io_memory;
 
-    s->it_shift = it_shift;
+    vga_common_init(s, VGA_RAM_SIZE);
+    s->bank_offset = 0;
+
     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);
 
-    vmstate_register(NULL, 0, &vmstate_vga_common, s);
+    cpu_register_physical_memory(VRAM_BASE + 0x000a0000, 0x20000, vga_io_memory);
+    qemu_register_coalesced_mmio(VRAM_BASE + 0x000a0000, 0x20000);
 
-    cpu_register_physical_memory(ctrl_base, 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);
-}
+    sysbus_init_mmio(dev, 0x100000, s_ioport_ctrl);
 
-int isa_vga_mm_init(target_phys_addr_t vram_base,
-                    target_phys_addr_t ctrl_base, int it_shift)
-{
-    ISAVGAMMState *s;
+    s->ds = graphic_console_init(s->update, s->invalidate,
+                                 s->screen_dump, s->text_update, s);
 
-    s = qemu_mallocz(sizeof(*s));
+    vga_init_vbe(s);
 
-    vga_common_init(&s->vga, VGA_RAM_SIZE);
-    vga_mm_init(s, vram_base, ctrl_base, it_shift);
+    return 0;
+}
 
-    s->vga.ds = graphic_console_init(s->vga.update, s->vga.invalidate,
-                                     s->vga.screen_dump, s->vga.text_update, s);
+static SysBusDeviceInfo vga_sysbus_info = {
+    .qdev.name  = "sysbus-vga",
+    .qdev.size  = sizeof(SysBusVGAState),
+    .qdev.vmsd  = &vmstate_vga,
+    .init       = vga_sysbus_initfn,
+};
 
-    vga_init_vbe(&s->vga);
-    return 0;
+static void vga_register(void)
+{
+    sysbus_register_withprop(&vga_sysbus_info);
 }
+
+device_init(vga_register)