Patchwork hw/smc91c111: Convert to MemoryRegion

login
register
mail settings
Submitter Peter Maydell
Date Aug. 24, 2011, 5:28 p.m.
Message ID <1314206901-18462-1-git-send-email-peter.maydell@linaro.org>
Download mbox | patch
Permalink /patch/111387/
State New
Headers show

Comments

Peter Maydell - Aug. 24, 2011, 5:28 p.m.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
This is against master and doesn't depend on or conflict with anything
that's in Avi's branch. (I needed this because I've just rebased qemu-linaro
on master and one of the omap3 boards connects an smc91c111 up to the
omap_gpmc, which means it needs to be able to expose a MemoryRegion*.)

 hw/smc91c111.c |   29 +++++++++++++----------------
 1 files changed, 13 insertions(+), 16 deletions(-)
Avi Kivity - Aug. 25, 2011, 9:04 a.m.
On 08/24/2011 08:28 PM, Peter Maydell wrote:
> Signed-off-by: Peter Maydell<peter.maydell@linaro.org>
> ---
> This is against master and doesn't depend on or conflict with anything
> that's in Avi's branch. (I needed this because I've just rebased qemu-linaro
> on master and one of the omap3 boards connects an smc91c111 up to the
> omap_gpmc, which means it needs to be able to expose a MemoryRegion*.)
>

Thanks, applied to memory/queue.  If you need this in soon, feel free to 
ask Anthony to merge it.

Patch

diff --git a/hw/smc91c111.c b/hw/smc91c111.c
index 3a8a85c..fc8c498 100644
--- a/hw/smc91c111.c
+++ b/hw/smc91c111.c
@@ -43,7 +43,7 @@  typedef struct {
     uint8_t data[NUM_PACKETS][2048];
     uint8_t int_level;
     uint8_t int_mask;
-    int mmio_index;
+    MemoryRegion mmio;
 } smc91c111_state;
 
 static const VMStateDescription vmstate_smc91c111 = {
@@ -717,16 +717,15 @@  static ssize_t smc91c111_receive(VLANClientState *nc, const uint8_t *buf, size_t
     return size;
 }
 
-static CPUReadMemoryFunc * const smc91c111_readfn[] = {
-    smc91c111_readb,
-    smc91c111_readw,
-    smc91c111_readl
-};
-
-static CPUWriteMemoryFunc * const smc91c111_writefn[] = {
-    smc91c111_writeb,
-    smc91c111_writew,
-    smc91c111_writel
+static const MemoryRegionOps smc91c111_mem_ops = {
+    /* The special case for 32 bit writes to 0xc means we can't just
+     * set .impl.min/max_access_size to 1, unfortunately
+     */
+    .old_mmio = {
+        .read = { smc91c111_readb, smc91c111_readw, smc91c111_readl, },
+        .write = { smc91c111_writeb, smc91c111_writew, smc91c111_writel, },
+    },
+    .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
 static void smc91c111_cleanup(VLANClientState *nc)
@@ -747,11 +746,9 @@  static NetClientInfo net_smc91c111_info = {
 static int smc91c111_init1(SysBusDevice *dev)
 {
     smc91c111_state *s = FROM_SYSBUS(smc91c111_state, dev);
-
-    s->mmio_index = cpu_register_io_memory(smc91c111_readfn,
-                                           smc91c111_writefn, s,
-                                           DEVICE_NATIVE_ENDIAN);
-    sysbus_init_mmio(dev, 16, s->mmio_index);
+    memory_region_init_io(&s->mmio, &smc91c111_mem_ops, s,
+                          "smc91c111-mmio", 16);
+    sysbus_init_mmio_region(dev, &s->mmio);
     sysbus_init_irq(dev, &s->irq);
     qemu_macaddr_default_if_unset(&s->conf.macaddr);
     s->nic = qemu_new_nic(&net_smc91c111_info, &s->conf,