From patchwork Mon Apr 15 23:19:31 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Scott Wood X-Patchwork-Id: 236764 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 3BDAF2C00E3 for ; Tue, 16 Apr 2013 09:20:39 +1000 (EST) Received: from localhost ([::1]:53193 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1URshR-0004hB-BR for incoming@patchwork.ozlabs.org; Mon, 15 Apr 2013 19:20:37 -0400 Received: from eggs.gnu.org ([208.118.235.92]:51428) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1URsgn-0004VK-Rx for qemu-devel@nongnu.org; Mon, 15 Apr 2013 19:20:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1URsgi-0004lJ-78 for qemu-devel@nongnu.org; Mon, 15 Apr 2013 19:19:57 -0400 Received: from va3ehsobe006.messaging.microsoft.com ([216.32.180.16]:40237 helo=va3outboundpool.messaging.microsoft.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1URsgY-0004cA-AN; Mon, 15 Apr 2013 19:19:42 -0400 Received: from mail129-va3-R.bigfish.com (10.7.14.242) by VA3EHSOBE004.bigfish.com (10.7.40.24) with Microsoft SMTP Server id 14.1.225.23; Mon, 15 Apr 2013 23:19:41 +0000 Received: from mail129-va3 (localhost [127.0.0.1]) by mail129-va3-R.bigfish.com (Postfix) with ESMTP id 9764D1E05C7; Mon, 15 Apr 2013 23:19:41 +0000 (UTC) X-Forefront-Antispam-Report: CIP:70.37.183.190; KIP:(null); UIP:(null); IPV:NLI; H:mail.freescale.net; RD:none; EFVD:NLI X-SpamScore: 1 X-BigFish: VS1(z551bizzz1f42h1fc6h1ee6h1de0h1fdah1202h1e76h1d1ah1d2ahzz8275bhz2dh2a8h668h839hd24he5bhf0ah1288h12a5h12a9h12bdh12e5h137ah139eh13b6h1441h1504h1537h162dh1631h1758h1898h18e1h1946h19b5h1ad9h1b0ah1155h) Received: from mail129-va3 (localhost.localdomain [127.0.0.1]) by mail129-va3 (MessageSwitch) id 1366067978769723_5671; Mon, 15 Apr 2013 23:19:38 +0000 (UTC) Received: from VA3EHSMHS014.bigfish.com (unknown [10.7.14.236]) by mail129-va3.bigfish.com (Postfix) with ESMTP id B5E6D4C0072; Mon, 15 Apr 2013 23:19:38 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by VA3EHSMHS014.bigfish.com (10.7.99.24) with Microsoft SMTP Server (TLS) id 14.1.225.23; Mon, 15 Apr 2013 23:19:38 +0000 Received: from tx30smr01.am.freescale.net (10.81.153.31) by 039-SN1MMR1-002.039d.mgd.msft.net (10.84.1.15) with Microsoft SMTP Server (TLS) id 14.2.328.11; Mon, 15 Apr 2013 23:19:37 +0000 Received: from snotra.am.freescale.net ([10.214.83.122]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id r3FNJYs2017756; Mon, 15 Apr 2013 16:19:37 -0700 From: Scott Wood To: Alexander Graf Date: Mon, 15 Apr 2013 18:19:31 -0500 Message-ID: <1366067974-5413-4-git-send-email-scottwood@freescale.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1366067974-5413-1-git-send-email-scottwood@freescale.com> References: <1360823521-32306-1-git-send-email-scottwood@freescale.com> <1366067974-5413-1-git-send-email-scottwood@freescale.com> MIME-Version: 1.0 X-OriginatorOrg: freescale.com X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 X-Received-From: 216.32.180.16 Cc: Scott Wood , qemu-ppc@nongnu.org, qemu-devel@nongnu.org Subject: [Qemu-devel] [RFC PATCH v2 3/6] memory: add memory_region_to_address() 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 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 --- 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. */