qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: Anthony Liguori <anthony@codemonkey.ws>, qemu-devel@nongnu.org
Cc: kvm@vger.kernel.org
Subject: [Qemu-devel] [PATCH v2 10/23] memory: add backward compatibility for old portio registration
Date: Tue, 26 Jul 2011 14:26:09 +0300	[thread overview]
Message-ID: <1311679582-11211-11-git-send-email-avi@redhat.com> (raw)
In-Reply-To: <1311679582-11211-1-git-send-email-avi@redhat.com>

Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
---
 memory.c |   32 ++++++++++++++++++++++++++++++++
 memory.h |   17 +++++++++++++++++
 2 files changed, 49 insertions(+), 0 deletions(-)

diff --git a/memory.c b/memory.c
index df0ed0e..5f2c9ef 100644
--- a/memory.c
+++ b/memory.c
@@ -218,6 +218,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,
@@ -225,6 +240,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);
 }
 
@@ -235,6 +259,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 88ba428..40ab95a 100644
--- a/memory.h
+++ b/memory.h
@@ -23,9 +23,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.
@@ -78,6 +80,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;
@@ -105,6 +112,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 { }
+
 /**
  * memory_region_init: Initialize a memory region
  *
-- 
1.7.5.3

  parent reply	other threads:[~2011-07-26 11:26 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-26 11:25 [Qemu-devel] [PATCH v2 00/23] Memory API, batch 1 Avi Kivity
2011-07-26 11:26 ` [Qemu-devel] [PATCH v2 01/23] Add memory API documentation Avi Kivity
2011-07-26 11:26 ` [Qemu-devel] [PATCH v2 02/23] Hierarchical memory region API Avi Kivity
2011-07-26 11:26 ` [Qemu-devel] [PATCH v2 03/23] memory: implement dirty tracking Avi Kivity
2011-07-26 11:26 ` [Qemu-devel] [PATCH v2 04/23] memory: merge adjacent segments of a single memory region Avi Kivity
2011-07-26 11:36   ` Paolo Bonzini
2011-07-26 11:38     ` Avi Kivity
2011-07-26 11:51       ` Paolo Bonzini
2011-07-26 12:04         ` Avi Kivity
2011-07-26 15:41     ` Richard Henderson
2011-07-26 16:04       ` Avi Kivity
2011-07-26 11:26 ` [Qemu-devel] [PATCH v2 05/23] Internal interfaces for memory API Avi Kivity
2011-07-26 11:26 ` [Qemu-devel] [PATCH v2 06/23] memory: abstract address space operations Avi Kivity
2011-07-26 11:26 ` [Qemu-devel] [PATCH v2 07/23] memory: rename MemoryRegion::has_ram_addr to ::terminates Avi Kivity
2011-07-26 11:26 ` [Qemu-devel] [PATCH v2 08/23] memory: late initialization of ram_addr Avi Kivity
2011-07-26 11:26 ` [Qemu-devel] [PATCH v2 09/23] memory: I/O address space support Avi Kivity
2011-07-26 11:26 ` Avi Kivity [this message]
2011-07-26 11:26 ` [Qemu-devel] [PATCH v2 11/23] memory: add backward compatibility for old mmio registration Avi Kivity
2011-07-26 11:26 ` [Qemu-devel] [PATCH v2 12/23] memory: add ioeventfd support Avi Kivity
2011-07-26 11:26 ` [Qemu-devel] [PATCH v2 13/23] memory: separate building the final memory map into two steps Avi Kivity
2011-07-26 11:26 ` [Qemu-devel] [PATCH v2 14/23] memory: transaction API Avi Kivity
2011-07-26 11:26 ` [Qemu-devel] [PATCH v2 15/23] exec.c: initialize memory map Avi Kivity
2011-07-26 11:26 ` [Qemu-devel] [PATCH v2 16/23] ioport: register ranges by byte aligned addresses always Avi Kivity
2011-07-26 11:26 ` [Qemu-devel] [PATCH v2 17/23] pc: grab system_memory Avi Kivity
2011-07-26 11:26 ` [Qemu-devel] [PATCH v2 18/23] pc: convert pc_memory_init() to memory API Avi Kivity
2011-07-26 11:26 ` [Qemu-devel] [PATCH v2 19/23] pc: move global memory map out of pc_init1() and into its callers Avi Kivity
2011-07-26 11:26 ` [Qemu-devel] [PATCH v2 20/23] pci: pass address space to pci bus when created Avi Kivity
2011-07-26 11:26 ` [Qemu-devel] [PATCH v2 21/23] pci: add MemoryRegion based BAR management API Avi Kivity
2011-07-26 11:26 ` [Qemu-devel] [PATCH v2 22/23] sysbus: add MemoryRegion based memory " Avi Kivity
2011-07-26 11:26 ` [Qemu-devel] [PATCH v2 23/23] usb-ohci: convert to MemoryRegion Avi Kivity
2011-07-29 14:18 ` [Qemu-devel] [PATCH v2 00/23] Memory API, batch 1 Anthony Liguori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1311679582-11211-11-git-send-email-avi@redhat.com \
    --to=avi@redhat.com \
    --cc=anthony@codemonkey.ws \
    --cc=kvm@vger.kernel.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).