From patchwork Fri Dec 9 08:09:03 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wen Congyang X-Patchwork-Id: 130317 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 228971007D6 for ; Fri, 9 Dec 2011 19:07:09 +1100 (EST) Received: from localhost ([::1]:53607 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RYvU1-0001R0-SJ for incoming@patchwork.ozlabs.org; Fri, 09 Dec 2011 03:07:05 -0500 Received: from eggs.gnu.org ([140.186.70.92]:46879) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RYvTu-0001MW-L3 for qemu-devel@nongnu.org; Fri, 09 Dec 2011 03:06:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RYvTt-0007wP-J9 for qemu-devel@nongnu.org; Fri, 09 Dec 2011 03:06:58 -0500 Received: from [222.73.24.84] (port=53126 helo=song.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RYvTs-0007wH-Mr for qemu-devel@nongnu.org; Fri, 09 Dec 2011 03:06:57 -0500 Received: from tang.cn.fujitsu.com (tang.cn.fujitsu.com [10.167.250.3]) by song.cn.fujitsu.com (Postfix) with ESMTP id 1E8C917008D; Fri, 9 Dec 2011 16:06:54 +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 pB986qWr022061; Fri, 9 Dec 2011 16:06:52 +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 2011120916062262-373795 ; Fri, 9 Dec 2011 16:06:22 +0800 Message-ID: <4EE1C21F.9040307@cn.fujitsu.com> Date: Fri, 09 Dec 2011 16:09:03 +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 References: <4EE1BF66.7030602@cn.fujitsu.com> In-Reply-To: <4EE1BF66.7030602@cn.fujitsu.com> X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.1FP4|July 25, 2010) at 2011-12-09 16:06:22, Serialize by Router on mailserver/fnst(Release 8.5.1FP4|July 25, 2010) at 2011-12-09 16:06:24, Serialize complete at 2011-12-09 16:06:24 X-detected-operating-system: by eggs.gnu.org: FreeBSD 6.x (1) X-Received-From: 222.73.24.84 Subject: [Qemu-devel] [RFC][PATCH 4/5 v2] 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 | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ memory_mapping.h | 1 + 2 files changed, 54 insertions(+), 0 deletions(-) diff --git a/memory_mapping.c b/memory_mapping.c index d83b7d7..6c1778c 100644 --- a/memory_mapping.c +++ b/memory_mapping.c @@ -128,3 +128,56 @@ 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; + + 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'list does not conatin the region + * [offset, offset+length) + */ + create_new_memory_mapping(list, offset, 0, length); + break; + } + + if ((memory_mapping->phys_addr + memory_mapping->length) <= + offset) { + continue; + } + + if (memory_mapping->phys_addr > offset) { + /* + * memory_mapping'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)) { + break; + } + length -= memory_mapping->phys_addr + memory_mapping->length - + offset; + offset = memory_mapping->phys_addr + memory_mapping->length; + } + } + + return; +} diff --git a/memory_mapping.h b/memory_mapping.h index 871591d..9a876b7 100644 --- a/memory_mapping.h +++ b/memory_mapping.h @@ -25,5 +25,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