From patchwork Thu Dec 29 01:25:48 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaku Yamahata X-Patchwork-Id: 133476 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 ABE10B6FA2 for ; Thu, 29 Dec 2011 12:47:27 +1100 (EST) Received: from localhost ([::1]:39812 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rg55Z-0003fK-1j for incoming@patchwork.ozlabs.org; Wed, 28 Dec 2011 20:47:25 -0500 Received: from eggs.gnu.org ([140.186.70.92]:33971) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rg4lA-0005Rp-H6 for qemu-devel@nongnu.org; Wed, 28 Dec 2011 20:26:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Rg4ky-0004Hs-Fq for qemu-devel@nongnu.org; Wed, 28 Dec 2011 20:26:20 -0500 Received: from mail.valinux.co.jp ([210.128.90.3]:42934) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rg4kx-0004G7-VK for qemu-devel@nongnu.org; Wed, 28 Dec 2011 20:26:08 -0500 Received: from ps.local.valinux.co.jp (vagw.valinux.co.jp [210.128.90.14]) by mail.valinux.co.jp (Postfix) with SMTP id 71200875B7; Thu, 29 Dec 2011 10:26:01 +0900 (JST) Received: (nullmailer pid 15177 invoked by uid 1000); Thu, 29 Dec 2011 01:26:01 -0000 From: Isaku Yamahata To: kvm@vger.kernel.org, qemu-devel@nongnu.org Date: Thu, 29 Dec 2011 10:25:48 +0900 Message-Id: X-Mailer: git-send-email 1.7.1.1 In-Reply-To: References: In-Reply-To: References: X-Virus-Scanned: clamav-milter 0.95.2 at va-mail.local.valinux.co.jp X-Virus-Status: Clean X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 210.128.90.3 Cc: yamahata@valinux.co.jp, t.hirofuchi@aist.go.jp, satoshi.itoh@aist.go.jp Subject: [Qemu-devel] [PATCH 09/21] exec.c: factor out qemu_get_ram_ptr() 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 Signed-off-by: Isaku Yamahata --- cpu-all.h | 2 ++ exec.c | 51 +++++++++++++++++++++++++++++---------------------- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/cpu-all.h b/cpu-all.h index 9d78715..0244f7a 100644 --- a/cpu-all.h +++ b/cpu-all.h @@ -496,6 +496,8 @@ extern RAMList ram_list; extern const char *mem_path; extern int mem_prealloc; +RAMBlock *qemu_get_ram_block(ram_addr_t adar); + /* physical memory access */ /* MMIO pages are identified by a combination of an IO device index and diff --git a/exec.c b/exec.c index 32782b4..51b8d15 100644 --- a/exec.c +++ b/exec.c @@ -3117,15 +3117,7 @@ void qemu_ram_remap(ram_addr_t addr, ram_addr_t length) } #endif /* !_WIN32 */ -/* Return a host pointer to ram allocated with qemu_ram_alloc. - With the exception of the softmmu code in this file, this should - only be used for local memory (e.g. video ram) that the device owns, - and knows it isn't going to access beyond the end of the block. - - It should not be used for general purpose DMA. - Use cpu_physical_memory_map/cpu_physical_memory_rw instead. - */ -void *qemu_get_ram_ptr(ram_addr_t addr) +RAMBlock *qemu_get_ram_block(ram_addr_t addr) { RAMBlock *block; @@ -3136,19 +3128,7 @@ void *qemu_get_ram_ptr(ram_addr_t addr) QLIST_REMOVE(block, next); QLIST_INSERT_HEAD(&ram_list.blocks, block, next); } - if (xen_enabled()) { - /* We need to check if the requested address is in the RAM - * because we don't want to map the entire memory in QEMU. - * In that case just map until the end of the page. - */ - if (block->offset == 0) { - return xen_map_cache(addr, 0, 0); - } else if (block->host == NULL) { - block->host = - xen_map_cache(block->offset, block->length, 1); - } - } - return block->host + (addr - block->offset); + return block; } } @@ -3159,6 +3139,33 @@ void *qemu_get_ram_ptr(ram_addr_t addr) } /* Return a host pointer to ram allocated with qemu_ram_alloc. + With the exception of the softmmu code in this file, this should + only be used for local memory (e.g. video ram) that the device owns, + and knows it isn't going to access beyond the end of the block. + + It should not be used for general purpose DMA. + Use cpu_physical_memory_map/cpu_physical_memory_rw instead. + */ +void *qemu_get_ram_ptr(ram_addr_t addr) +{ + RAMBlock *block = qemu_get_ram_block(addr); + + if (xen_enabled()) { + /* We need to check if the requested address is in the RAM + * because we don't want to map the entire memory in QEMU. + * In that case just map until the end of the page. + */ + if (block->offset == 0) { + return xen_map_cache(addr, 0, 0); + } else if (block->host == NULL) { + block->host = + xen_map_cache(block->offset, block->length, 1); + } + } + return block->host + (addr - block->offset); +} + +/* Return a host pointer to ram allocated with qemu_ram_alloc. * Same as qemu_get_ram_ptr but avoid reordering ramblocks. */ void *qemu_safe_ram_ptr(ram_addr_t addr)