From patchwork Wed Sep 3 18:36:14 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bogdan Purcareata X-Patchwork-Id: 385507 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id F3A44140216 for ; Wed, 3 Sep 2014 21:39:38 +1000 (EST) Received: from localhost ([::1]:44436 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XP8uX-0003fl-46 for incoming@patchwork.ozlabs.org; Wed, 03 Sep 2014 07:39:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58263) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XP8tr-0002X5-8n for qemu-devel@nongnu.org; Wed, 03 Sep 2014 07:39:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XP8tk-00033z-EK for qemu-devel@nongnu.org; Wed, 03 Sep 2014 07:38:55 -0400 Received: from mail-by2lp0241.outbound.protection.outlook.com ([207.46.163.241]:49973 helo=na01-by2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XP8tW-00030i-9z; Wed, 03 Sep 2014 07:38:34 -0400 Received: from BN3PR0301CA0061.namprd03.prod.outlook.com (25.160.152.157) by BL2PR03MB179.namprd03.prod.outlook.com (10.255.230.154) with Microsoft SMTP Server (TLS) id 15.0.1019.16; Wed, 3 Sep 2014 11:38:31 +0000 Received: from BY2FFO11FD058.protection.gbl (2a01:111:f400:7c0c::198) by BN3PR0301CA0061.outlook.office365.com (2a01:111:e400:401e::29) with Microsoft SMTP Server (TLS) id 15.0.1019.16 via Frontend Transport; Wed, 3 Sep 2014 11:38:31 +0000 Received: from tx30smr01.am.freescale.net (192.88.168.50) by BY2FFO11FD058.mail.protection.outlook.com (10.1.15.178) with Microsoft SMTP Server (TLS) id 15.0.1010.11 via Frontend Transport; Wed, 3 Sep 2014 11:38:31 +0000 Received: from exile.ea.freescale.net (exile.ea.freescale.net [10.171.73.223]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id s83BcOHm019554; Wed, 3 Sep 2014 04:38:29 -0700 From: Bogdan Purcareata To: Date: Wed, 3 Sep 2014 14:36:14 -0400 Message-ID: <1409769375-22286-2-git-send-email-bogdan.purcareata@freescale.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1409769375-22286-1-git-send-email-bogdan.purcareata@freescale.com> References: <1409769375-22286-1-git-send-email-bogdan.purcareata@freescale.com> X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:192.88.168.50; CTRY:US; IPV:CAL; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(6009001)(199003)(189002)(107046002)(97736001)(99396002)(229853001)(90102001)(2351001)(77156001)(48376002)(31966008)(50226001)(104166001)(4396001)(74662001)(50986999)(77982001)(26826002)(50466002)(104016003)(33646002)(110136001)(106466001)(102836001)(105606002)(74502001)(62966002)(89996001)(92566001)(79102001)(21056001)(64706001)(87286001)(20776003)(68736004)(47776003)(95666004)(575784001)(93916002)(86362001)(80022001)(87936001)(44976005)(92726001)(76482001)(46102001)(19580395003)(19580405001)(83322001)(76176999)(85306004)(81342001)(36756003)(6806004)(88136002)(84676001)(85852003)(83072002)(81542001); DIR:OUT; SFP:; SCL:1; SRVR:BL2PR03MB179; H:tx30smr01.am.freescale.net; FPR:; MLV:ovrnspm; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:;UriScan:; X-Forefront-PRVS: 032334F434 Received-SPF: Fail (protection.outlook.com: domain of freescale.com does not designate 192.88.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=bogdan.purcareata@freescale.com; X-OriginatorOrg: freescale.com X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 X-Received-From: 207.46.163.241 Cc: qemu-devel@nongnu.org, Bogdan Purcareata Subject: [Qemu-devel] [PATCH 1/2] memory: Add MemoryRegion get address space offset helper function X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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); + +/** * 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; +} + const char *memory_region_name(const MemoryRegion *mr) { if (!mr->name) {