All of lore.kernel.org
 help / color / mirror / Atom feed
From: KONRAD Frederic <frederic.konrad@adacore.com>
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, alex.bennee@linaro.org,
	pbonzini@redhat.com, alistair@alistair23.me,
	frederic.konrad@adacore.com
Subject: [Qemu-devel] [PATCH v1 1/3] add memory_region_get_offset_within_address_space
Date: Thu, 29 Jun 2017 11:28:51 +0200	[thread overview]
Message-ID: <1498728533-23160-2-git-send-email-frederic.konrad@adacore.com> (raw)
In-Reply-To: <1498728533-23160-1-git-send-email-frederic.konrad@adacore.com>

This is helpful in the next patch to know if a rom is pointed by an alias.

Signed-off-by: KONRAD Frederic <frederic.konrad@adacore.com>
---
 include/exec/memory.h | 10 ++++++++++
 memory.c              | 22 ++++++++++++++++++++--
 2 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/include/exec/memory.h b/include/exec/memory.h
index 8503685..e342412 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -1270,6 +1270,16 @@ void memory_region_set_size(MemoryRegion *mr, uint64_t size);
 void memory_region_set_alias_offset(MemoryRegion *mr,
                                     hwaddr offset);
 
+/*
+ * memory_region_get_offset_within_address_space: get the offset of a region
+ *
+ * Returns the offset of a region within its address space. @mr must be mapped
+ * to an #AddressSpace.
+ *
+ * @mr: the #MemoryRegion to check.
+ */
+hwaddr memory_region_get_offset_within_address_space(MemoryRegion *mr);
+
 /**
  * memory_region_present: checks if an address relative to a @container
  * translates into #MemoryRegion within @container
diff --git a/memory.c b/memory.c
index 1044bba..2b7439b 100644
--- a/memory.c
+++ b/memory.c
@@ -598,11 +598,18 @@ static MemTxResult access_with_adjusted_size(hwaddr addr,
     return r;
 }
 
-static AddressSpace *memory_region_to_address_space(MemoryRegion *mr)
+static AddressSpace *memory_region_to_address_space(MemoryRegion *mr,
+                                                    hwaddr *offset)
 {
     AddressSpace *as;
 
+    if (offset) {
+        *offset = 0;
+    }
     while (mr->container) {
+        if (offset) {
+            *offset += mr->addr;
+        }
         mr = mr->container;
     }
     QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) {
@@ -613,6 +620,17 @@ static AddressSpace *memory_region_to_address_space(MemoryRegion *mr)
     return NULL;
 }
 
+hwaddr memory_region_get_offset_within_address_space(MemoryRegion *mr)
+{
+    hwaddr offset;
+    AddressSpace *as;
+
+    as = memory_region_to_address_space(mr, &offset);
+    assert(as);
+
+    return offset;
+}
+
 /* Render a memory region into the global view.  Ranges in @view obscure
  * ranges in @mr.
  */
@@ -2251,7 +2269,7 @@ static MemoryRegionSection memory_region_find_rcu(MemoryRegion *mr,
         addr += root->addr;
     }
 
-    as = memory_region_to_address_space(root);
+    as = memory_region_to_address_space(root, NULL);
     if (!as) {
         return ret;
     }
-- 
1.8.3.1

  reply	other threads:[~2017-06-29  9:29 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-29  9:28 [Qemu-devel] [PATCH v1 0/3] Some armv7m fixes KONRAD Frederic
2017-06-29  9:28 ` KONRAD Frederic [this message]
2017-06-29  9:28 ` [Qemu-devel] [PATCH v1 2/3] arm: fix the armv7m reset state KONRAD Frederic
2017-06-29 15:14   ` Peter Maydell
2017-06-29 16:41     ` KONRAD Frederic
2017-06-29 16:45       ` Peter Maydell
2017-06-30  8:24         ` KONRAD Frederic
2017-06-30  9:06           ` Peter Maydell
2017-07-03  7:31             ` KONRAD Frederic
2017-07-03  8:51               ` Peter Maydell
2017-07-03  9:04                 ` KONRAD Frederic
2017-06-29  9:28 ` [Qemu-devel] [PATCH v1 3/3] armv7m_systick: abort instead of locking on a bad rate KONRAD Frederic
2017-06-29 12:35   ` Philippe Mathieu-Daudé
2017-06-29 12:43     ` Peter Maydell
2017-06-29 12:48       ` KONRAD Frederic
2017-06-29 13:02       ` Philippe Mathieu-Daudé
2017-06-29 13:17         ` KONRAD Frederic
2017-07-06 23:49 ` [Qemu-devel] [PATCH v1 0/3] Some armv7m fixes no-reply
2017-07-07  0:03   ` Fam Zheng

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=1498728533-23160-2-git-send-email-frederic.konrad@adacore.com \
    --to=frederic.konrad@adacore.com \
    --cc=alex.bennee@linaro.org \
    --cc=alistair@alistair23.me \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.