From mboxrd@z Thu Jan 1 00:00:00 1970 From: Isaku Yamahata Subject: [PATCH 09/21] exec.c: factor out qemu_get_ram_ptr() Date: Thu, 29 Dec 2011 10:25:48 +0900 Message-ID: References: Cc: yamahata@valinux.co.jp, t.hirofuchi@aist.go.jp, satoshi.itoh@aist.go.jp To: kvm@vger.kernel.org, qemu-devel@nongnu.org Return-path: Received: from mail.valinux.co.jp ([210.128.90.3]:47801 "EHLO mail.valinux.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754564Ab1L2B0C (ORCPT ); Wed, 28 Dec 2011 20:26:02 -0500 In-Reply-To: In-Reply-To: References: Sender: kvm-owner@vger.kernel.org List-ID: 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) -- 1.7.1.1 From mboxrd@z Thu Jan 1 00:00:00 1970 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 From: Isaku Yamahata Date: Thu, 29 Dec 2011 10:25:48 +0900 Message-Id: In-Reply-To: References: In-Reply-To: References: Subject: [Qemu-devel] [PATCH 09/21] exec.c: factor out qemu_get_ram_ptr() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: kvm@vger.kernel.org, qemu-devel@nongnu.org Cc: yamahata@valinux.co.jp, t.hirofuchi@aist.go.jp, satoshi.itoh@aist.go.jp 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) -- 1.7.1.1