From patchwork Wed Oct 20 17:43:43 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 68454 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 8DDF2B70D1 for ; Thu, 21 Oct 2010 04:49:36 +1100 (EST) Received: from localhost ([127.0.0.1]:39347 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P8cn7-0002me-He for incoming@patchwork.ozlabs.org; Wed, 20 Oct 2010 13:49:33 -0400 Received: from [140.186.70.92] (port=37350 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P8cio-0000Mi-D9 for qemu-devel@nongnu.org; Wed, 20 Oct 2010 13:45:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P8cin-00065G-Bn for qemu-devel@nongnu.org; Wed, 20 Oct 2010 13:45:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:14485) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P8cin-00064S-4m for qemu-devel@nongnu.org; Wed, 20 Oct 2010 13:45:05 -0400 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o9KHj2Oi000653 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 20 Oct 2010 13:45:02 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o9KHj2ZO027942; Wed, 20 Oct 2010 13:45:02 -0400 Received: from amt.cnet (vpn-9-16.rdu.redhat.com [10.11.9.16]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id o9KHix7o019203; Wed, 20 Oct 2010 13:45:00 -0400 Received: from amt.cnet (localhost.localdomain [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id 6A5216561E5; Wed, 20 Oct 2010 15:44:23 -0200 (BRST) Received: (from marcelo@localhost) by amt.cnet (8.14.4/8.14.4/Submit) id o9KHiKRJ003556; Wed, 20 Oct 2010 15:44:20 -0200 From: Marcelo Tosatti To: Anthony Liguori Date: Wed, 20 Oct 2010 15:43:43 -0200 Message-Id: <8af660ed826e2ef4ca70416868e48f5cd1d748c4.1287596626.git.mtosatti@redhat.com> In-Reply-To: References: X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Marcelo Tosatti , qemu-devel@nongnu.org, kvm@vger.kernel.org, Avi Kivity Subject: [Qemu-devel] [PATCH 06/10] Export qemu_ram_addr_from_host X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org To be used by next patches. Signed-off-by: Marcelo Tosatti Signed-off-by: Avi Kivity --- cpu-common.h | 3 ++- exec-all.h | 2 +- exec.c | 26 +++++++++++++++++--------- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/cpu-common.h b/cpu-common.h index 0426bc8..a543b5d 100644 --- a/cpu-common.h +++ b/cpu-common.h @@ -47,7 +47,8 @@ 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. */ -ram_addr_t qemu_ram_addr_from_host(void *ptr); +int qemu_ram_addr_from_host(void *ptr, ram_addr_t *ram_addr); +ram_addr_t qemu_ram_addr_from_host_nofail(void *ptr); int cpu_register_io_memory(CPUReadMemoryFunc * const *mem_read, CPUWriteMemoryFunc * const *mem_write, diff --git a/exec-all.h b/exec-all.h index 3a53fe6..c457058 100644 --- a/exec-all.h +++ b/exec-all.h @@ -334,7 +334,7 @@ static inline tb_page_addr_t get_page_addr_code(CPUState *env1, target_ulong add } p = (void *)(unsigned long)addr + env1->tlb_table[mmu_idx][page_index].addend; - return qemu_ram_addr_from_host(p); + return qemu_ram_addr_from_host_nofail(p); } #endif diff --git a/exec.c b/exec.c index 1fbe91c..631d8c5 100644 --- a/exec.c +++ b/exec.c @@ -2085,7 +2085,7 @@ static inline void tlb_update_dirty(CPUTLBEntry *tlb_entry) if ((tlb_entry->addr_write & ~TARGET_PAGE_MASK) == IO_MEM_RAM) { p = (void *)(unsigned long)((tlb_entry->addr_write & TARGET_PAGE_MASK) + tlb_entry->addend); - ram_addr = qemu_ram_addr_from_host(p); + ram_addr = qemu_ram_addr_from_host_nofail(p); if (!cpu_physical_memory_is_dirty(ram_addr)) { tlb_entry->addr_write |= TLB_NOTDIRTY; } @@ -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 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_nofail(void *ptr) +{ + ram_addr_t ram_addr; - return 0; + if (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) @@ -3703,7 +3711,7 @@ void cpu_physical_memory_unmap(void *buffer, target_phys_addr_t len, { if (buffer != bounce.buffer) { if (is_write) { - ram_addr_t addr1 = qemu_ram_addr_from_host(buffer); + ram_addr_t addr1 = qemu_ram_addr_from_host_nofail(buffer); while (access_len) { unsigned l; l = TARGET_PAGE_SIZE;