Patchwork [03/14] slavio_misc: convert diagnostic to memory API

login
register
mail settings
Submitter Benoit Canet
Date Nov. 15, 2011, 11:13 a.m.
Message ID <1321355644-1982-4-git-send-email-benoit.canet@gmail.com>
Download mbox | patch
Permalink /patch/125747/
State New
Headers show

Comments

Benoit Canet - Nov. 15, 2011, 11:13 a.m.
Signed-off-by: Benoit Canet <benoit.canet@gmail.com>
---
 hw/slavio_misc.c |   31 +++++++++++++++----------------
 1 files changed, 15 insertions(+), 16 deletions(-)

Patch

diff --git a/hw/slavio_misc.c b/hw/slavio_misc.c
index 7b98f11..60a115d 100644
--- a/hw/slavio_misc.c
+++ b/hw/slavio_misc.c
@@ -37,6 +37,7 @@ 
 typedef struct MiscState {
     SysBusDevice busdev;
     MemoryRegion cfg_iomem;
+    MemoryRegion diag_iomem;
     qemu_irq irq;
     qemu_irq fdc_tc;
     uint32_t dummy;
@@ -133,7 +134,7 @@  static const MemoryRegionOps slavio_cfg_mem_ops = {
 };
 
 static void slavio_diag_mem_writeb(void *opaque, target_phys_addr_t addr,
-                                   uint32_t val)
+                                   uint64_t val, unsigned size)
 {
     MiscState *s = opaque;
 
@@ -141,7 +142,8 @@  static void slavio_diag_mem_writeb(void *opaque, target_phys_addr_t addr,
     s->diag = val & 0xff;
 }
 
-static uint32_t slavio_diag_mem_readb(void *opaque, target_phys_addr_t addr)
+static uint64_t slavio_diag_mem_readb(void *opaque, target_phys_addr_t addr,
+                                      unsigned size)
 {
     MiscState *s = opaque;
     uint32_t ret = 0;
@@ -151,16 +153,14 @@  static uint32_t slavio_diag_mem_readb(void *opaque, target_phys_addr_t addr)
     return ret;
 }
 
-static CPUReadMemoryFunc * const slavio_diag_mem_read[3] = {
-    slavio_diag_mem_readb,
-    NULL,
-    NULL,
-};
-
-static CPUWriteMemoryFunc * const slavio_diag_mem_write[3] = {
-    slavio_diag_mem_writeb,
-    NULL,
-    NULL,
+static const MemoryRegionOps slavio_diag_mem_ops = {
+    .read = slavio_diag_mem_readb,
+    .write = slavio_diag_mem_writeb,
+    .endianness = DEVICE_NATIVE_ENDIAN,
+    .valid = {
+        .min_access_size = 1,
+        .max_access_size = 1,
+    },
 };
 
 static void slavio_mdm_mem_writeb(void *opaque, target_phys_addr_t addr,
@@ -433,10 +433,9 @@  static int slavio_misc_init1(SysBusDevice *dev)
     sysbus_init_mmio_region(dev, &s->cfg_iomem);
 
     /* Diagnostics */
-    io = cpu_register_io_memory(slavio_diag_mem_read,
-                                slavio_diag_mem_write, s,
-                                DEVICE_NATIVE_ENDIAN);
-    sysbus_init_mmio(dev, MISC_SIZE, io);
+    memory_region_init_io(&s->diag_iomem, &slavio_diag_mem_ops, s,
+                          "diagnostic", MISC_SIZE);
+    sysbus_init_mmio_region(dev, &s->diag_iomem);
 
     /* Modem control */
     io = cpu_register_io_memory(slavio_mdm_mem_read,