From patchwork Mon Oct 11 18:31:19 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 67466 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 B7082B7043 for ; Tue, 12 Oct 2010 05:43:57 +1100 (EST) Received: from localhost ([127.0.0.1]:36078 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P5NLm-0003qc-Lz for incoming@patchwork.ozlabs.org; Mon, 11 Oct 2010 14:43:54 -0400 Received: from [140.186.70.92] (port=38203 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P5NGk-0001IB-MH for qemu-devel@nongnu.org; Mon, 11 Oct 2010 14:38:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P5NGh-0005vj-VE for qemu-devel@nongnu.org; Mon, 11 Oct 2010 14:38:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52422) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P5NGh-0005tu-Oh for qemu-devel@nongnu.org; Mon, 11 Oct 2010 14:38:39 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o9BIcZo2029508 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 11 Oct 2010 14:38:35 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o9BIcYWs028366; Mon, 11 Oct 2010 14:38:34 -0400 Received: from amt.cnet (vpn-9-78.rdu.redhat.com [10.11.9.78]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id o9BIcXAt022089; Mon, 11 Oct 2010 14:38:33 -0400 Received: from amt.cnet (localhost.localdomain [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id 8B2896520B4; Mon, 11 Oct 2010 15:38:19 -0300 (BRT) Received: (from marcelo@localhost) by amt.cnet (8.14.4/8.14.4/Submit) id o9BIcHJG009935; Mon, 11 Oct 2010 15:38:17 -0300 Message-Id: <20101011183226.915543887@redhat.com> User-Agent: quilt/0.47-1 Date: Mon, 11 Oct 2010 15:31:19 -0300 From: Marcelo Tosatti To: kvm@vger.kernel.org, qemu-devel@nongnu.org References: <20101011183114.455477545@redhat.com> Content-Disposition: inline; filename=do_qemu_ram_addr_from_host X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Dean Nelson , Marcelo Tosatti , Huang Ying Subject: [Qemu-devel] [patch 5/8] 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 Index: qemu/cpu-common.h =================================================================== --- qemu.orig/cpu-common.h +++ qemu/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, Index: qemu/exec.c =================================================================== --- qemu.orig/exec.c +++ qemu/exec.c @@ -2086,7 +2086,7 @@ static inline void tlb_update_dirty(CPUT 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 *buf { 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; Index: qemu/exec-all.h =================================================================== --- qemu.orig/exec-all.h +++ qemu/exec-all.h @@ -334,7 +334,7 @@ static inline tb_page_addr_t get_page_ad } 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