From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=54195 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P2qGe-00062S-NO for qemu-devel@nongnu.org; Mon, 04 Oct 2010 15:00:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P2qGb-00087C-OY for qemu-devel@nongnu.org; Mon, 04 Oct 2010 15:00:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:8034) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P2qGb-00085p-IC for qemu-devel@nongnu.org; Mon, 04 Oct 2010 15:00:05 -0400 Message-Id: <20101004185714.983252370@redhat.com> Date: Mon, 04 Oct 2010 15:54:52 -0300 From: Marcelo Tosatti References: <20101004185447.891324545@redhat.com> Content-Disposition: inline; filename=do_qemu_ram_addr_from_host Subject: [Qemu-devel] [patch uq/master 5/8] Export qemu_ram_addr_from_host List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: kvm@vger.kernel.org, qemu-devel@nongnu.org Cc: Dean Nelson , Marcelo Tosatti , Huang Ying To be used by next patches. Signed-off-by: Marcelo Tosatti Index: qemu/cpu-common.h =================================================================== --- qemu.orig/cpu-common.h +++ qemu/cpu-common.h @@ -47,6 +47,7 @@ void qemu_ram_free(ram_addr_t addr); /* This should only be used for ram local to a device. */ void *qemu_get_ram_ptr(ram_addr_t addr); /* This should not be used by devices. */ +int do_qemu_ram_addr_from_host(void *ptr, ram_addr_t *ram_addr); ram_addr_t qemu_ram_addr_from_host(void *ptr); int cpu_register_io_memory(CPUReadMemoryFunc * const *mem_read, Index: qemu/exec.c =================================================================== --- qemu.orig/exec.c +++ qemu/exec.c @@ -2938,23 +2938,31 @@ void *qemu_get_ram_ptr(ram_addr_t addr) return NULL; } -/* Some of the softmmu routines need to translate from a host pointer - (typically a TLB entry) back to a ram offset. */ -ram_addr_t qemu_ram_addr_from_host(void *ptr) +int do_qemu_ram_addr_from_host(void *ptr, ram_addr_t *ram_addr) { RAMBlock *block; uint8_t *host = ptr; QLIST_FOREACH(block, &ram_list.blocks, next) { if (host - block->host < block->length) { - return block->offset + (host - block->host); + *ram_addr = block->offset + (host - block->host); + return 0; } } + return -1; +} - fprintf(stderr, "Bad ram pointer %p\n", ptr); - abort(); +/* Some of the softmmu routines need to translate from a host pointer + (typically a TLB entry) back to a ram offset. */ +ram_addr_t qemu_ram_addr_from_host(void *ptr) +{ + ram_addr_t ram_addr; - return 0; + if (do_qemu_ram_addr_from_host(ptr, &ram_addr)) { + fprintf(stderr, "Bad ram pointer %p\n", ptr); + abort(); + } + return ram_addr; } static uint32_t unassigned_mem_readb(void *opaque, target_phys_addr_t addr)