From patchwork Thu Feb 9 03:22:48 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wen Congyang X-Patchwork-Id: 140295 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id C5EF7B71A7 for ; Thu, 9 Feb 2012 14:19:43 +1100 (EST) Received: from localhost ([::1]:39820 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RvKXq-00062h-MC for incoming@patchwork.ozlabs.org; Wed, 08 Feb 2012 22:19:38 -0500 Received: from eggs.gnu.org ([140.186.70.92]:43052) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RvKXl-00062R-6U for qemu-devel@nongnu.org; Wed, 08 Feb 2012 22:19:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RvKXj-0001M6-Ve for qemu-devel@nongnu.org; Wed, 08 Feb 2012 22:19:33 -0500 Received: from [222.73.24.84] (port=55256 helo=song.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RvKXj-0001Lr-2x for qemu-devel@nongnu.org; Wed, 08 Feb 2012 22:19:31 -0500 Received: from tang.cn.fujitsu.com (tang.cn.fujitsu.com [10.167.250.3]) by song.cn.fujitsu.com (Postfix) with ESMTP id 3AAEF17008E; Thu, 9 Feb 2012 11:19:27 +0800 (CST) Received: from mailserver.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id q193JQQD032735; Thu, 9 Feb 2012 11:19:26 +0800 Received: from [10.167.225.226] ([10.167.225.226]) by mailserver.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.1FP4) with ESMTP id 2012020911175829-576849 ; Thu, 9 Feb 2012 11:17:58 +0800 Message-ID: <4F333C08.7070008@cn.fujitsu.com> Date: Thu, 09 Feb 2012 11:22:48 +0800 From: Wen Congyang User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100413 Fedora/3.0.4-2.fc13 Thunderbird/3.0.4 MIME-Version: 1.0 To: qemu-devel , Jan Kiszka , Dave Anderson , HATAYAMA Daisuke , Luiz Capitulino , Eric Blake References: <4F333AAA.1070601@cn.fujitsu.com> In-Reply-To: <4F333AAA.1070601@cn.fujitsu.com> X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.1FP4|July 25, 2010) at 2012-02-09 11:17:58, Serialize by Router on mailserver/fnst(Release 8.5.1FP4|July 25, 2010) at 2012-02-09 11:17:58, Serialize complete at 2012-02-09 11:17:58 X-detected-operating-system: by eggs.gnu.org: FreeBSD 6.x (1) X-Received-From: 222.73.24.84 Subject: [Qemu-devel] [RFC][PATCH 05/16 v6] Add API to get memory mapping 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 Add API to get all virtual address and physical address mapping. If there is no virtual address for some physical address, the virtual address is 0. Signed-off-by: Wen Congyang --- memory_mapping.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ memory_mapping.h | 1 + 2 files changed, 66 insertions(+), 0 deletions(-) diff --git a/memory_mapping.c b/memory_mapping.c index d83b7d7..fc0ddee 100644 --- a/memory_mapping.c +++ b/memory_mapping.c @@ -128,3 +128,68 @@ void free_memory_mapping_list(MemoryMappingList *list) list->num = 0; } + +void get_memory_mapping(MemoryMappingList *list) +{ + CPUState *env; + MemoryMapping *memory_mapping; + RAMBlock *block; + ram_addr_t offset, length; + + last_mapping = NULL; + + for (env = first_cpu; env != NULL; env = env->next_cpu) { + cpu_get_memory_mapping(list, env); + } + + /* some memory may be not mapped, add them into memory mapping's list */ + QLIST_FOREACH(block, &ram_list.blocks, next) { + offset = block->offset; + length = block->length; + + QTAILQ_FOREACH(memory_mapping, &list->head, next) { + if (memory_mapping->phys_addr >= (offset + length)) { + /* + * memory_mapping's list does not conatin the region + * [offset, offset+length) + */ + create_new_memory_mapping(list, offset, 0, length); + length = 0; + break; + } + + if ((memory_mapping->phys_addr + memory_mapping->length) <= + offset) { + continue; + } + + if (memory_mapping->phys_addr > offset) { + /* + * memory_mapping's list does not conatin the region + * [offset, memory_mapping->phys_addr) + */ + create_new_memory_mapping(list, offset, 0, + memory_mapping->phys_addr - offset); + } + + if ((offset + length) <= + (memory_mapping->phys_addr + memory_mapping->length)) { + length = 0; + break; + } + length -= memory_mapping->phys_addr + memory_mapping->length - + offset; + offset = memory_mapping->phys_addr + memory_mapping->length; + } + + if (length > 0) { + /* + * memory_mapping's list does not conatin the region + * [offset, memory_mapping->phys_addr) + */ + create_new_memory_mapping(list, offset, 0, length); + } + } + + return; +} diff --git a/memory_mapping.h b/memory_mapping.h index a4b1532..679f9ef 100644 --- a/memory_mapping.h +++ b/memory_mapping.h @@ -34,5 +34,6 @@ void add_to_memory_mapping(MemoryMappingList *list, ram_addr_t length); void free_memory_mapping_list(MemoryMappingList *list); +void get_memory_mapping(MemoryMappingList *list); #endif