qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Scott Wood <scottwood@freescale.com>
To: Alexander Graf <agraf@suse.de>
Cc: Scott Wood <scottwood@freescale.com>,
	qemu-ppc@nongnu.org, qemu-devel@nongnu.org
Subject: [Qemu-devel] [RFC PATCH v2 3/6] memory: add memory_region_to_address()
Date: Mon, 15 Apr 2013 18:19:31 -0500	[thread overview]
Message-ID: <1366067974-5413-4-git-send-email-scottwood@freescale.com> (raw)
In-Reply-To: <1366067974-5413-1-git-send-email-scottwood@freescale.com>

This is useful for when a user of the memory region API needs to
communicate the absolute bus address to something outside QEMU
(in particular, KVM).

Signed-off-by: Scott Wood <scottwood@freescale.com>
---
TODO: Use add/del memory listeners later in the patchset, which would
eliminate the need for this patch.
---
 include/exec/memory.h |    9 +++++++++
 memory.c              |   38 ++++++++++++++++++++++++++++++++++----
 2 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/include/exec/memory.h b/include/exec/memory.h
index 2322732..b800391 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -892,6 +892,15 @@ void *address_space_map(AddressSpace *as, hwaddr addr,
 void address_space_unmap(AddressSpace *as, void *buffer, hwaddr len,
                          int is_write, hwaddr access_len);
 
+/* memory_region_to_address: Find the full address of the start of the
+ *      given #MemoryRegion, ignoring aliases.  There is no guarantee
+ *      that the #MemoryRegion is actually visible at this address, if
+ *      there are overlapping regions.
+ *
+ * @mr: #MemoryRegion being queried
+ * @asp: if non-NULL, returns the #AddressSpace @mr is mapped in, if any
+ */
+hwaddr memory_region_to_address(MemoryRegion *mr, AddressSpace **asp);
 
 #endif
 
diff --git a/memory.c b/memory.c
index 75ca281..5d3b13d 100644
--- a/memory.c
+++ b/memory.c
@@ -453,21 +453,51 @@ const IORangeOps memory_region_iorange_ops = {
     .destructor = memory_region_iorange_destructor,
 };
 
-static AddressSpace *memory_region_to_address_space(MemoryRegion *mr)
+static AddressSpace *memory_region_root_to_address_space(MemoryRegion *mr)
 {
     AddressSpace *as;
 
-    while (mr->parent) {
-        mr = mr->parent;
-    }
     QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) {
         if (mr == as->root) {
             return as;
         }
     }
+
+    return NULL;
+}
+
+static AddressSpace *memory_region_to_address_space(MemoryRegion *mr)
+{
+    AddressSpace *as;
+
+    while (mr->parent) {
+        mr = mr->parent;
+    }
+
+    as = memory_region_root_to_address_space(mr);
+    if (as) {
+        return as;
+    }
+
     abort();
 }
 
+hwaddr memory_region_to_address(MemoryRegion *mr, AddressSpace **asp)
+{
+    hwaddr addr = mr->addr;
+
+    while (mr->parent) {
+        mr = mr->parent;
+        addr += mr->addr;
+    }
+
+    if (asp) {
+        *asp = memory_region_root_to_address_space(mr);
+    }
+
+    return addr;
+}
+
 /* Render a memory region into the global view.  Ranges in @view obscure
  * ranges in @mr.
  */
-- 
1.7.10.4

  parent reply	other threads:[~2013-04-15 23:20 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1360823521-32306-1-git-send-email-scottwood@freescale.com>
     [not found] ` <1360823521-32306-3-git-send-email-scottwood@freescale.com>
2013-03-21  8:30   ` [Qemu-devel] [RFC ppc-next PATCH 2/6] kvm: hw/kvm is not x86-specific Alexander Graf
     [not found] ` <1360823521-32306-4-git-send-email-scottwood@freescale.com>
2013-03-21  8:31   ` [Qemu-devel] [RFC ppc-next PATCH 3/6] memory: add memory_region_to_address() Alexander Graf
2013-03-21 10:53     ` Peter Maydell
2013-03-21 10:59       ` Alexander Graf
2013-03-21 11:01         ` Peter Maydell
2013-03-21 11:05           ` Alexander Graf
2013-03-21 11:09             ` Peter Maydell
2013-03-21 11:14               ` Alexander Graf
2013-03-21 11:22                 ` Peter Maydell
2013-03-21 11:29                   ` Alexander Graf
2013-03-21 11:32                     ` Peter Maydell
2013-03-21 11:38                       ` Alexander Graf
2013-03-21 11:44                         ` Peter Maydell
2013-03-21 11:49                           ` Alexander Graf
2013-03-21 11:51                             ` [Qemu-devel] [Qemu-ppc] " Alexander Graf
2013-03-21 22:43                               ` Scott Wood
2013-03-22 13:08                                 ` Peter Maydell
2013-03-22 22:05                                   ` Scott Wood
2013-03-23 11:24                                     ` Peter Maydell
2013-03-25 18:23                                       ` Scott Wood
2013-03-21 11:53                             ` [Qemu-devel] " Peter Maydell
     [not found] ` <1360823521-32306-6-git-send-email-scottwood@freescale.com>
2013-03-21  8:34   ` [Qemu-devel] [RFC ppc-next PATCH 5/6] kvm: export result of irqchip config check Alexander Graf
2013-03-21  8:45     ` Jan Kiszka
2013-03-21  8:50       ` Alexander Graf
     [not found] ` <1360823521-32306-7-git-send-email-scottwood@freescale.com>
2013-03-21  8:41   ` [Qemu-devel] [RFC ppc-next PATCH 6/6] kvm/openpic: in-kernel mpic support Alexander Graf
2013-03-21 20:50     ` Scott Wood
2013-03-21 21:29       ` Alexander Graf
2013-03-21 21:59         ` Scott Wood
2013-03-21 23:45           ` Alexander Graf
2013-03-22 22:51             ` Scott Wood
2013-04-15 23:19 ` [Qemu-devel] [RFC PATCH v2 0/6] kvm/openpic: in-kernel irqchip Scott Wood
2013-04-15 23:19   ` [Qemu-devel] [RFC PATCH v2 1/6] kvm: update linux-headers Scott Wood
2013-04-15 23:19   ` [Qemu-devel] [RFC PATCH v2 2/6] kvm: use hw/kvm/Makefile.objs consistently for all relevant architectures Scott Wood
2013-04-15 23:19   ` Scott Wood [this message]
2013-04-16  8:25     ` [Qemu-devel] [RFC PATCH v2 3/6] memory: add memory_region_to_address() Peter Maydell
2013-04-17  0:10       ` Scott Wood
2013-04-17  9:14         ` Peter Maydell
2013-04-15 23:19   ` [Qemu-devel] [RFC PATCH v2 4/6] openpic: factor out some common defines into openpic.h Scott Wood
2013-04-15 23:19   ` [Qemu-devel] [RFC PATCH v2 5/6] PPC: e500: factor out mpic init code Scott Wood
2013-04-15 23:19   ` [Qemu-devel] [RFC PATCH v2 6/6] kvm/openpic: in-kernel mpic support Scott Wood

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=1366067974-5413-4-git-send-email-scottwood@freescale.com \
    --to=scottwood@freescale.com \
    --cc=agraf@suse.de \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@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).