Patchwork [10/14] serial: convert PIO to new memory api read/write

login
register
mail settings
Submitter Alexander Graf
Date Oct. 8, 2012, 12:23 p.m.
Message ID <1349699033-6703-11-git-send-email-agraf@suse.de>
Download mbox | patch
Permalink /patch/190025/
State New
Headers show

Comments

Alexander Graf - Oct. 8, 2012, 12:23 p.m.
Signed-off-by: Alexander Graf <agraf@suse.de>
---
 hw/serial.c |   31 ++++++++++++++++++-------------
 1 files changed, 18 insertions(+), 13 deletions(-)

Patch

diff --git a/hw/serial.c b/hw/serial.c
index a421d1e..abae1e7 100644
--- a/hw/serial.c
+++ b/hw/serial.c
@@ -28,6 +28,7 @@ 
 #include "pc.h"
 #include "qemu-timer.h"
 #include "sysemu.h"
+#include "exec-memory.h"
 
 //#define DEBUG_SERIAL
 
@@ -367,7 +368,8 @@  static void serial_xmit(void *opaque)
 }
 
 
-static void serial_ioport_write(void *opaque, uint32_t addr, uint32_t val)
+static void serial_ioport_write(void *opaque, target_phys_addr_t addr,
+                                uint64_t val, unsigned size)
 {
     SerialState *s = opaque;
 
@@ -513,7 +515,8 @@  static void serial_ioport_write(void *opaque, uint32_t addr, uint32_t val)
     }
 }
 
-static uint32_t serial_ioport_read(void *opaque, uint32_t addr)
+static uint64_t serial_ioport_read(void *opaque, target_phys_addr_t addr,
+                                   unsigned size)
 {
     SerialState *s = opaque;
     uint32_t ret;
@@ -682,7 +685,7 @@  static int serial_post_load(void *opaque, int version_id)
         s->fcr_vmstate = 0;
     }
     /* Initialize fcr via setter to perform essential side-effects */
-    serial_ioport_write(s, 0x02, s->fcr_vmstate);
+    serial_ioport_write(s, 0x02, s->fcr_vmstate, 1);
     serial_update_parameters(s);
     return 0;
 }
@@ -764,13 +767,14 @@  void serial_set_frequency(SerialState *s, uint32_t frequency)
 static const int isa_serial_io[MAX_SERIAL_PORTS] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 };
 static const int isa_serial_irq[MAX_SERIAL_PORTS] = { 4, 3, 4, 3 };
 
-static const MemoryRegionPortio serial_portio[] = {
-    { 0, 8, 1, .read = serial_ioport_read, .write = serial_ioport_write },
-    PORTIO_END_OF_LIST()
-};
-
 static const MemoryRegionOps serial_io_ops = {
-    .old_portio = serial_portio
+    .read = serial_ioport_read,
+    .write = serial_ioport_write,
+    .impl = {
+        .min_access_size = 1,
+        .max_access_size = 1,
+    },
+    .endianness = DEVICE_LITTLE_ENDIAN,
 };
 
 static int serial_isa_initfn(ISADevice *dev)
@@ -823,8 +827,9 @@  SerialState *serial_init(int base, qemu_irq irq, int baudbase,
 
     vmstate_register(NULL, base, &vmstate_serial, s);
 
-    register_ioport_write(base, 8, 1, serial_ioport_write, s);
-    register_ioport_read(base, 8, 1, serial_ioport_read, s);
+    memory_region_init_io(&s->io, &serial_io_ops, s, "serial", 8);
+    memory_region_add_subregion(get_system_io(), base, &s->io);
+
     return s;
 }
 
@@ -833,7 +838,7 @@  static uint64_t serial_mm_read(void *opaque, target_phys_addr_t addr,
                                unsigned size)
 {
     SerialState *s = opaque;
-    return serial_ioport_read(s, addr >> s->it_shift);
+    return serial_ioport_read(s, addr >> s->it_shift, 1);
 }
 
 static void serial_mm_write(void *opaque, target_phys_addr_t addr,
@@ -841,7 +846,7 @@  static void serial_mm_write(void *opaque, target_phys_addr_t addr,
 {
     SerialState *s = opaque;
     value &= ~0u >> (32 - (size * 8));
-    serial_ioport_write(s, addr >> s->it_shift, value);
+    serial_ioport_write(s, addr >> s->it_shift, value, 1);
 }
 
 static const MemoryRegionOps serial_mm_ops[3] = {