From patchwork Thu Mar 1 02:43:13 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wen Congyang X-Patchwork-Id: 143877 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 7ADC2B6FA3 for ; Thu, 1 Mar 2012 13:42:12 +1100 (EST) Received: from localhost ([::1]:41454 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S2vy6-0008Vp-CQ for incoming@patchwork.ozlabs.org; Wed, 29 Feb 2012 21:42:10 -0500 Received: from eggs.gnu.org ([208.118.235.92]:43880) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S2vxz-0008Vk-9u for qemu-devel@nongnu.org; Wed, 29 Feb 2012 21:42:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S2vxx-00032v-4m for qemu-devel@nongnu.org; Wed, 29 Feb 2012 21:42:02 -0500 Received: from [222.73.24.84] (port=60123 helo=song.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S2vxw-00032S-Hv for qemu-devel@nongnu.org; Wed, 29 Feb 2012 21:42:01 -0500 Received: from tang.cn.fujitsu.com (tang.cn.fujitsu.com [10.167.250.3]) by song.cn.fujitsu.com (Postfix) with ESMTP id 367CB170115; Thu, 1 Mar 2012 10:41:59 +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 q212fuel007534; Thu, 1 Mar 2012 10:41:56 +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 2012030110400831-829501 ; Thu, 1 Mar 2012 10:40:08 +0800 Message-ID: <4F4EE241.5030503@cn.fujitsu.com> Date: Thu, 01 Mar 2012 10:43:13 +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: <4F4EE080.9060307@cn.fujitsu.com> In-Reply-To: <4F4EE080.9060307@cn.fujitsu.com> X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.1FP4|July 25, 2010) at 2012-03-01 10:40:08, Serialize by Router on mailserver/fnst(Release 8.5.1FP4|July 25, 2010) at 2012-03-01 10:40:09, Serialize complete at 2012-03-01 10:40:09 X-detected-operating-system: by eggs.gnu.org: FreeBSD 6.x (1) X-Received-From: 222.73.24.84 Subject: [Qemu-devel] [RFC][PATCH 04/14 v7] 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 | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ memory_mapping.h | 8 ++++++ 2 files changed, 79 insertions(+), 0 deletions(-) diff --git a/memory_mapping.c b/memory_mapping.c index 84fb2c8..3743805 100644 --- a/memory_mapping.c +++ b/memory_mapping.c @@ -132,3 +132,74 @@ void memory_mapping_list_init(MemoryMappingList *list) list->last_mapping = NULL; QTAILQ_INIT(&list->head); } + +int qemu_get_guest_memory_mapping(MemoryMappingList *list) +{ + CPUState *env; + MemoryMapping *memory_mapping; + RAMBlock *block; + ram_addr_t offset, length; + int ret; + +#if defined(CONFIG_HAVE_GET_MEMORY_MAPPING) + for (env = first_cpu; env != NULL; env = env->next_cpu) { + ret = cpu_get_memory_mapping(list, env); + if (ret < 0) { + return -1; + } + } +#else + return -2; +#endif + + /* 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 0; +} diff --git a/memory_mapping.h b/memory_mapping.h index 633fcb9..5760d1d 100644 --- a/memory_mapping.h +++ b/memory_mapping.h @@ -41,4 +41,12 @@ void memory_mapping_list_add_sorted(MemoryMappingList *list, void memory_mapping_list_free(MemoryMappingList *list); void memory_mapping_list_init(MemoryMappingList *list); +/* + * Return value: + * 0: success + * -1: failed + * -2: unsupported + */ +int qemu_get_guest_memory_mapping(MemoryMappingList *list); + #endif