Patchwork [1/2] pc87312: Replace register_ioport_*() with MemoryRegion

login
register
mail settings
Submitter Andreas Färber
Date Jan. 15, 2013, 8:57 a.m.
Message ID <1358240234-31883-2-git-send-email-andreas.faerber@web.de>
Download mbox | patch
Permalink /patch/212038/
State New
Headers show

Comments

Andreas Färber - Jan. 15, 2013, 8:57 a.m.
Prepare an instance_init function for the MemoryRegion init.

Signed-off-by: Andreas Färber <andreas.faerber@web.de>
Tested-by: Hervé Poussineau <hpoussin@reactos.org>
---
 hw/pc87312.c |   26 ++++++++++++++++++++++----
 hw/pc87312.h |    2 ++
 2 Dateien geändert, 24 Zeilen hinzugefügt(+), 4 Zeilen entfernt(-)

Patch

diff --git a/hw/pc87312.c b/hw/pc87312.c
index 6a17afd..97fabfa 100644
--- a/hw/pc87312.c
+++ b/hw/pc87312.c
@@ -194,7 +194,8 @@  static void pc87312_hard_reset(PC87312State *s)
     pc87312_soft_reset(s);
 }
 
-static void pc87312_ioport_write(void *opaque, uint32_t addr, uint32_t val)
+static void pc87312_io_write(void *opaque, hwaddr addr, uint64_t val,
+                             unsigned int size)
 {
     PC87312State *s = opaque;
 
@@ -213,7 +214,7 @@  static void pc87312_ioport_write(void *opaque, uint32_t addr, uint32_t val)
     }
 }
 
-static uint32_t pc87312_ioport_read(void *opaque, uint32_t addr)
+static uint64_t pc87312_io_read(void *opaque, hwaddr addr, unsigned int size)
 {
     PC87312State *s = opaque;
     uint32_t val;
@@ -241,6 +242,16 @@  static uint32_t pc87312_ioport_read(void *opaque, uint32_t addr)
     return val;
 }
 
+static const MemoryRegionOps pc87312_io_ops = {
+    .read  = pc87312_io_read,
+    .write = pc87312_io_write,
+    .endianness = DEVICE_LITTLE_ENDIAN,
+    .valid = {
+        .min_access_size = 1,
+        .max_access_size = 1,
+    },
+};
+
 static int pc87312_post_load(void *opaque, int version_id)
 {
     PC87312State *s = opaque;
@@ -270,6 +281,7 @@  static int pc87312_init(ISADevice *dev)
     s = PC87312(dev);
     bus = isa_bus_from_device(dev);
     pc87312_hard_reset(s);
+    isa_register_ioport(dev, &s->io, s->iobase);
 
     if (is_parallel_enabled(s)) {
         chr = parallel_hds[0];
@@ -337,11 +349,16 @@  static int pc87312_init(ISADevice *dev)
         trace_pc87312_info_ide(get_ide_iobase(s));
     }
 
-    register_ioport_write(s->iobase, 2, 1, pc87312_ioport_write, s);
-    register_ioport_read(s->iobase, 2, 1, pc87312_ioport_read, s);
     return 0;
 }
 
+static void pc87312_initfn(Object *obj)
+{
+    PC87312State *s = PC87312(obj);
+
+    memory_region_init_io(&s->io, &pc87312_io_ops, s, "pc87312", 2);
+}
+
 static const VMStateDescription vmstate_pc87312 = {
     .name = "pc87312",
     .version_id = 1,
@@ -376,6 +393,7 @@  static const TypeInfo pc87312_type_info = {
     .name          = TYPE_PC87312,
     .parent        = TYPE_ISA_DEVICE,
     .instance_size = sizeof(PC87312State),
+    .instance_init = pc87312_initfn,
     .class_init    = pc87312_class_init,
 };
 
diff --git a/hw/pc87312.h b/hw/pc87312.h
index 7ca7912..7b9e6f6 100644
--- a/hw/pc87312.h
+++ b/hw/pc87312.h
@@ -56,6 +56,8 @@  typedef struct PC87312State {
         uint32_t base;
     } ide;
 
+    MemoryRegion io;
+
     uint8_t read_id_step;
     uint8_t selected_index;