qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 09/23] memory: add backward compatibility for ol


From: Anthony Liguori
Subject: Re: [Qemu-devel] [PATCH 09/23] memory: add backward compatibility for old portio registration
Date: Mon, 25 Jul 2011 14:01:52 -0500
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.17) Gecko/20110516 Lightning/1.0b2 Thunderbird/3.1.10

On 07/25/2011 09:02 AM, Avi Kivity wrote:
Signed-off-by: Avi Kivity<address@hidden>

Reviewed-by: Anthony Liguori <address@hidden>

Regards,

Anthony Liguori

---
  memory.c |   32 ++++++++++++++++++++++++++++++++
  memory.h |   17 +++++++++++++++++
  2 files changed, 49 insertions(+), 0 deletions(-)

diff --git a/memory.c b/memory.c
index 62bd60b..bb04952 100644
--- a/memory.c
+++ b/memory.c
@@ -211,6 +211,21 @@ static AddressSpace address_space_memory = {
      .ops =&address_space_ops_memory,
  };

+static const MemoryRegionPortio *find_portio(MemoryRegion *mr, uint64_t offset,
+                                             unsigned width, bool write)
+{
+    const MemoryRegionPortio *mrp;
+
+    for (mrp = mr->ops->old_portio; mrp->size; ++mrp) {
+        if (offset>= mrp->offset&&  offset<  mrp->offset + mrp->len
+&&  width == mrp->size
+&&  (write ? (bool)mrp->write : (bool)mrp->read)) {
+            return mrp;
+        }
+    }
+    return NULL;
+}
+
  static void memory_region_iorange_read(IORange *iorange,
                                         uint64_t offset,
                                         unsigned width,
@@ -218,6 +233,15 @@ static void memory_region_iorange_read(IORange *iorange,
  {
      MemoryRegion *mr = container_of(iorange, MemoryRegion, iorange);

+    if (mr->ops->old_portio) {
+        const MemoryRegionPortio *mrp = find_portio(mr, offset, width, false);
+
+        *data = ((uint64_t)1<<  (width * 8)) - 1;
+        if (mrp) {
+            *data = mrp->read(mr->opaque, offset - mrp->offset);
+        }
+        return;
+    }
      *data = mr->ops->read(mr->opaque, offset, width);
  }

@@ -228,6 +252,14 @@ static void memory_region_iorange_write(IORange *iorange,
  {
      MemoryRegion *mr = container_of(iorange, MemoryRegion, iorange);

+    if (mr->ops->old_portio) {
+        const MemoryRegionPortio *mrp = find_portio(mr, offset, width, true);
+
+        if (mrp) {
+            mrp->write(mr->opaque, offset - mrp->offset, data);
+        }
+        return;
+    }
      mr->ops->write(mr->opaque, offset, data, width);
  }

diff --git a/memory.h b/memory.h
index 2afbf13..f026eae 100644
--- a/memory.h
+++ b/memory.h
@@ -10,9 +10,11 @@
  #include "targphys.h"
  #include "qemu-queue.h"
  #include "iorange.h"
+#include "ioport.h"

  typedef struct MemoryRegionOps MemoryRegionOps;
  typedef struct MemoryRegion MemoryRegion;
+typedef struct MemoryRegionPortio MemoryRegionPortio;

  /* Must match *_DIRTY_FLAGS in cpu-all.h.  To be replaced with dynamic
   * registration.
@@ -65,6 +67,11 @@ struct MemoryRegionOps {
           */
           bool unaligned;
      } impl;
+
+    /* If .read and .write are not present, old_portio may be used for
+     * backwards compatibility with old portio registration
+     */
+    const MemoryRegionPortio *old_portio;
  };

  typedef struct CoalescedMemoryRange CoalescedMemoryRange;
@@ -92,6 +99,16 @@ struct MemoryRegion {
      uint8_t dirty_log_mask;
  };

+struct MemoryRegionPortio {
+    uint32_t offset;
+    uint32_t len;
+    unsigned size;
+    IOPortReadFunc *read;
+    IOPortWriteFunc *write;
+};
+
+#define PORTIO_END { }
+
  /* Initialize a memory region
   *
   * The region typically acts as a container for other memory regions.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]