From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57429) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XPwy8-0001VA-0r for qemu-devel@nongnu.org; Fri, 05 Sep 2014 13:06:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XPwy3-0006Ry-Ix for qemu-devel@nongnu.org; Fri, 05 Sep 2014 13:06:39 -0400 Message-ID: <1409931107.24184.191.camel@snotra.buserror.net> From: Scott Wood Date: Fri, 5 Sep 2014 10:31:47 -0500 In-Reply-To: <1409769375-22286-2-git-send-email-bogdan.purcareata@freescale.com> References: <1409769375-22286-1-git-send-email-bogdan.purcareata@freescale.com> <1409769375-22286-2-git-send-email-bogdan.purcareata@freescale.com> Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [Qemu-ppc] [PATCH 1/2] memory: Add MemoryRegion get address space offset helper function List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Bogdan Purcareata Cc: qemu-ppc@nongnu.org, qemu-devel@nongnu.org On Wed, 2014-09-03 at 14:36 -0400, Bogdan Purcareata wrote: > Adding this function would allow a MemoryRegion to compute its start address > within the AddressSpace. This is done recursively based on mr->container. > > Signed-off-by: Bogdan Purcareata > --- > include/exec/memory.h | 8 ++++++++ > memory.c | 10 ++++++++++ > 2 files changed, 18 insertions(+) > > diff --git a/include/exec/memory.h b/include/exec/memory.h > index d165b27..7503819 100644 > --- a/include/exec/memory.h > +++ b/include/exec/memory.h > @@ -444,6 +444,14 @@ struct Object *memory_region_owner(MemoryRegion *mr); > uint64_t memory_region_size(MemoryRegion *mr); > > /** > + * memory_region_get_address_space_offset: get a memory region's address > + * within the address space > + * > + * @mr: the memory region being queried. > + */ > +hwaddr memory_region_get_address_space_offset(MemoryRegion *mr); Hmm, this seems familiar: http://patchwork.ozlabs.org/patch/220385/ http://patchwork.ozlabs.org/patch/236764/ :-) > + > +/** > * memory_region_is_ram: check whether a memory region is random access > * > * Returns %true is a memory region is random access. > diff --git a/memory.c b/memory.c > index ef0be1c..7445032 100644 > --- a/memory.c > +++ b/memory.c > @@ -1307,6 +1307,16 @@ uint64_t memory_region_size(MemoryRegion *mr) > return int128_get64(mr->size); > } > > +hwaddr memory_region_get_address_space_offset(MemoryRegion *mr) > +{ > + MemoryRegion *p; > + hwaddr result = 0x0; > + > + for (p = mr; p != NULL; result += p->addr, p = p->container); > + > + return result; > +} This would be more readable as: while (mr) { result += mr->addr; mr = mr->container; } -Scott