qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 01/10] ioport: change portio_list not to use memory_region_set_offset()
Date: Wed,  8 Feb 2012 17:27:50 +0200	[thread overview]
Message-ID: <1328714879-18906-2-git-send-email-avi@redhat.com> (raw)
In-Reply-To: <1328714879-18906-1-git-send-email-avi@redhat.com>

memory_region_set_offset() will be going away soon, so don't use it.
Use an alias instead.

Signed-off-by: Avi Kivity <avi@redhat.com>
---
 ioport.c |   25 +++++++++++++++++++------
 ioport.h |    1 +
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/ioport.c b/ioport.c
index 36fa3a4..505b252 100644
--- a/ioport.c
+++ b/ioport.c
@@ -328,6 +328,7 @@ void portio_list_init(PortioList *piolist,
     piolist->ports = callbacks;
     piolist->nr = 0;
     piolist->regions = g_new0(MemoryRegion *, n);
+    piolist->aliases = g_new0(MemoryRegion *, n);
     piolist->address_space = NULL;
     piolist->opaque = opaque;
     piolist->name = name;
@@ -336,6 +337,7 @@ void portio_list_init(PortioList *piolist,
 void portio_list_destroy(PortioList *piolist)
 {
     g_free(piolist->regions);
+    g_free(piolist->aliases);
 }
 
 static void portio_list_add_1(PortioList *piolist,
@@ -345,7 +347,7 @@ static void portio_list_add_1(PortioList *piolist,
 {
     MemoryRegionPortio *pio;
     MemoryRegionOps *ops;
-    MemoryRegion *region;
+    MemoryRegion *region, *alias;
     unsigned i;
 
     /* Copy the sub-list and null-terminate it.  */
@@ -362,12 +364,19 @@ static void portio_list_add_1(PortioList *piolist,
     ops->old_portio = pio;
 
     region = g_new(MemoryRegion, 1);
+    alias = g_new(MemoryRegion, 1);
+    /*
+     * Use an alias so that the callback is called with an absolute address,
+     * rather than an offset relative to to start + off_low.
+     */
     memory_region_init_io(region, ops, piolist->opaque, piolist->name,
-                          off_high - off_low);
-    memory_region_set_offset(region, start + off_low);
+                          UINT64_MAX);
+    memory_region_init_alias(alias, piolist->name,
+                             region, start + off_low, off_high - off_low);
     memory_region_add_subregion(piolist->address_space,
-                                start + off_low, region);
+                                start + off_low, alias);
     piolist->regions[piolist->nr++] = region;
+    piolist->aliases[piolist->nr++] = alias;
 }
 
 void portio_list_add(PortioList *piolist,
@@ -409,15 +418,19 @@ void portio_list_add(PortioList *piolist,
 
 void portio_list_del(PortioList *piolist)
 {
-    MemoryRegion *mr;
+    MemoryRegion *mr, *alias;
     unsigned i;
 
     for (i = 0; i < piolist->nr; ++i) {
         mr = piolist->regions[i];
-        memory_region_del_subregion(piolist->address_space, mr);
+        alias = piolist->aliases[i];
+        memory_region_del_subregion(piolist->address_space, alias);
+        memory_region_destroy(alias);
         memory_region_destroy(mr);
         g_free((MemoryRegionOps *)mr->ops);
         g_free(mr);
+        g_free(alias);
         piolist->regions[i] = NULL;
+        piolist->aliases[i] = NULL;
     }
 }
diff --git a/ioport.h b/ioport.h
index ae3e9da..ab29c89 100644
--- a/ioport.h
+++ b/ioport.h
@@ -60,6 +60,7 @@ typedef struct PortioList {
     struct MemoryRegion *address_space;
     unsigned nr;
     struct MemoryRegion **regions;
+    struct MemoryRegion **aliases;
     void *opaque;
     const char *name;
 } PortioList;
-- 
1.7.9

  reply	other threads:[~2012-02-08 15:28 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-08 15:27 [Qemu-devel] [PATCH 00/10] Remove AddressSpaceOps Avi Kivity
2012-02-08 15:27 ` Avi Kivity [this message]
2012-02-08 15:27 ` [Qemu-devel] [PATCH 02/10] memory: remove memory_region_set_offset() Avi Kivity
2012-02-08 15:27 ` [Qemu-devel] [PATCH 03/10] memory: add shorthand for invoking a callback on all listeners Avi Kivity
2012-02-08 15:27 ` [Qemu-devel] [PATCH 04/10] memory: switch memory listeners to a QTAILQ Avi Kivity
2012-02-08 15:27 ` [Qemu-devel] [PATCH 05/10] memory: code motion: move MEMORY_LISTENER_CALL() Avi Kivity
2012-02-08 15:27 ` [Qemu-devel] [PATCH 06/10] memory: move ioeventfd ops to MemoryListener Avi Kivity
2012-02-08 15:27 ` [Qemu-devel] [PATCH 07/10] memory: add a readonly attribute to MemoryRegionSection Avi Kivity
2012-02-08 15:27 ` [Qemu-devel] [PATCH 08/10] memory: don't pass ->readable attribute to cpu_register_physical_memory_log Avi Kivity
2012-02-08 15:27 ` [Qemu-devel] [PATCH 09/10] memory: use a MemoryListener for core memory map updates too Avi Kivity
2012-02-09  7:58   ` Paolo Bonzini
2012-02-09  9:28     ` Avi Kivity
2012-02-08 15:27 ` [Qemu-devel] [PATCH 10/10] memory: drop AddressSpaceOps Avi Kivity
2012-02-08 15:35 ` [Qemu-devel] [PATCH 00/10] Remove AddressSpaceOps Avi Kivity
2012-02-08 23:28 ` Richard Henderson

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=1328714879-18906-2-git-send-email-avi@redhat.com \
    --to=avi@redhat.com \
    --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).