From patchwork Mon May 6 14:26:12 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 241691 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 1F7B12C00F1 for ; Tue, 7 May 2013 00:36:41 +1000 (EST) Received: from localhost ([::1]:42612 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UZMWt-0008MF-BQ for incoming@patchwork.ozlabs.org; Mon, 06 May 2013 10:36:39 -0400 Received: from eggs.gnu.org ([208.118.235.92]:41660) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UZMNQ-0005sH-DI for qemu-devel@nongnu.org; Mon, 06 May 2013 10:26:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UZMNK-0005h9-Gv for qemu-devel@nongnu.org; Mon, 06 May 2013 10:26:52 -0400 Received: from goliath.siemens.de ([192.35.17.28]:25152) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UZMNK-0005h0-4C for qemu-devel@nongnu.org; Mon, 06 May 2013 10:26:46 -0400 Received: from mail1.siemens.de (localhost [127.0.0.1]) by goliath.siemens.de (8.13.6/8.13.6) with ESMTP id r46EQLl0014135; Mon, 6 May 2013 16:26:21 +0200 Received: from mchn199C.mchp.siemens.de ([139.25.109.49]) by mail1.siemens.de (8.13.6/8.13.6) with ESMTP id r46EQJBO011305; Mon, 6 May 2013 16:26:21 +0200 From: Jan Kiszka To: qemu-devel Date: Mon, 6 May 2013 16:26:12 +0200 Message-Id: <71c94383d7247e68bfbd45786227844e37f330ce.1367849167.git.jan.kiszka@siemens.com> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x X-Received-From: 192.35.17.28 Cc: Paolo Bonzini , Liu Ping Fan , =?UTF-8?q?Andreas=20F=C3=A4rber?= Subject: [Qemu-devel] [RFC][PATCH 09/15] memory: Introduce address_space_lookup_region 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 This new service so far only replaces phys_page_find as public API. In a follow-up step, it will return the effective memory region for the specified address, i.e. after resolving what are currently sub-pages. Moreover, it will also once encapsulate locking and reference counting when we introduce BQL-free dispatching. Signed-off-by: Jan Kiszka --- cputlb.c | 2 +- exec.c | 46 +++++++++++++++++++++------------------------- include/exec/cputlb.h | 2 -- include/exec/memory.h | 9 +++++++++ translate-all.c | 3 +-- 5 files changed, 32 insertions(+), 30 deletions(-) diff --git a/cputlb.c b/cputlb.c index aba7e44..e2c95c1 100644 --- a/cputlb.c +++ b/cputlb.c @@ -254,7 +254,7 @@ void tlb_set_page(CPUArchState *env, target_ulong vaddr, if (size != TARGET_PAGE_SIZE) { tlb_add_large_page(env, vaddr, size); } - section = phys_page_find(address_space_memory.dispatch, paddr >> TARGET_PAGE_BITS); + section = address_space_lookup_region(&address_space_memory, paddr); #if defined(DEBUG_TLB) printf("tlb_set_page: vaddr=" TARGET_FMT_lx " paddr=0x" TARGET_FMT_plx " prot=%x idx=%d pd=0x%08lx\n", diff --git a/exec.c b/exec.c index 19725db..53c2778 100644 --- a/exec.c +++ b/exec.c @@ -182,7 +182,8 @@ static void phys_page_set(AddressSpaceDispatch *d, phys_page_set_level(&d->phys_map, &index, &nb, leaf, P_L2_LEVELS - 1); } -MemoryRegionSection *phys_page_find(AddressSpaceDispatch *d, hwaddr index) +static MemoryRegionSection *phys_page_find(AddressSpaceDispatch *d, + hwaddr index) { PhysPageEntry lp = d->phys_map; PhysPageEntry *p; @@ -1894,19 +1895,16 @@ static void invalidate_and_set_dirty(hwaddr addr, void address_space_rw(AddressSpace *as, hwaddr addr, uint8_t *buf, int len, bool is_write) { - AddressSpaceDispatch *d = as->dispatch; int l; uint8_t *ptr; uint32_t val; - hwaddr page; MemoryRegionSection *section; while (len > 0) { - page = addr & TARGET_PAGE_MASK; - l = (page + TARGET_PAGE_SIZE) - addr; + l = ((addr & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE) - addr; if (l > len) l = len; - section = phys_page_find(d, page >> TARGET_PAGE_BITS); + section = address_space_lookup_region(as, addr); if (is_write) { if (!memory_region_is_ram(section->mr)) { @@ -2006,18 +2004,15 @@ void cpu_physical_memory_rw(hwaddr addr, uint8_t *buf, void cpu_physical_memory_write_rom(hwaddr addr, const uint8_t *buf, int len) { - AddressSpaceDispatch *d = address_space_memory.dispatch; int l; uint8_t *ptr; - hwaddr page; MemoryRegionSection *section; while (len > 0) { - page = addr & TARGET_PAGE_MASK; - l = (page + TARGET_PAGE_SIZE) - addr; + l = ((addr & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE) - addr; if (l > len) l = len; - section = phys_page_find(d, page >> TARGET_PAGE_BITS); + section = address_space_lookup_region(&address_space_memory, addr); if (!(memory_region_is_ram(section->mr) || memory_region_is_romd(section->mr))) { @@ -2096,22 +2091,19 @@ void *address_space_map(AddressSpace *as, hwaddr *plen, bool is_write) { - AddressSpaceDispatch *d = as->dispatch; hwaddr len = *plen; hwaddr todo = 0; int l; - hwaddr page; MemoryRegionSection *section; ram_addr_t raddr = RAM_ADDR_MAX; ram_addr_t rlen; void *ret; while (len > 0) { - page = addr & TARGET_PAGE_MASK; - l = (page + TARGET_PAGE_SIZE) - addr; + l = ((addr & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE) - addr; if (l > len) l = len; - section = phys_page_find(d, page >> TARGET_PAGE_BITS); + section = address_space_lookup_region(as, addr); if (!(memory_region_is_ram(section->mr) && !section->readonly)) { if (todo || bounce.buffer) { @@ -2188,6 +2180,11 @@ void cpu_physical_memory_unmap(void *buffer, hwaddr len, return address_space_unmap(&address_space_memory, buffer, len, is_write, access_len); } +MemoryRegionSection *address_space_lookup_region(AddressSpace *as, hwaddr addr) +{ + return phys_page_find(as->dispatch, addr >> TARGET_PAGE_BITS); +} + /* warning: addr must be aligned */ static inline uint32_t ldl_phys_internal(hwaddr addr, enum device_endian endian) @@ -2196,7 +2193,7 @@ static inline uint32_t ldl_phys_internal(hwaddr addr, uint32_t val; MemoryRegionSection *section; - section = phys_page_find(address_space_memory.dispatch, addr >> TARGET_PAGE_BITS); + section = address_space_lookup_region(&address_space_memory, addr); if (!(memory_region_is_ram(section->mr) || memory_region_is_romd(section->mr))) { @@ -2255,7 +2252,7 @@ static inline uint64_t ldq_phys_internal(hwaddr addr, uint64_t val; MemoryRegionSection *section; - section = phys_page_find(address_space_memory.dispatch, addr >> TARGET_PAGE_BITS); + section = address_space_lookup_region(&address_space_memory, addr); if (!(memory_region_is_ram(section->mr) || memory_region_is_romd(section->mr))) { @@ -2322,7 +2319,7 @@ static inline uint32_t lduw_phys_internal(hwaddr addr, uint64_t val; MemoryRegionSection *section; - section = phys_page_find(address_space_memory.dispatch, addr >> TARGET_PAGE_BITS); + section = address_space_lookup_region(&address_space_memory, addr); if (!(memory_region_is_ram(section->mr) || memory_region_is_romd(section->mr))) { @@ -2381,7 +2378,7 @@ void stl_phys_notdirty(hwaddr addr, uint32_t val) uint8_t *ptr; MemoryRegionSection *section; - section = phys_page_find(address_space_memory.dispatch, addr >> TARGET_PAGE_BITS); + section = address_space_lookup_region(&address_space_memory, addr); if (!memory_region_is_ram(section->mr) || section->readonly) { addr = memory_region_section_addr(section, addr); @@ -2413,7 +2410,7 @@ void stq_phys_notdirty(hwaddr addr, uint64_t val) uint8_t *ptr; MemoryRegionSection *section; - section = phys_page_find(address_space_memory.dispatch, addr >> TARGET_PAGE_BITS); + section = address_space_lookup_region(&address_space_memory, addr); if (!memory_region_is_ram(section->mr) || section->readonly) { addr = memory_region_section_addr(section, addr); @@ -2442,7 +2439,7 @@ static inline void stl_phys_internal(hwaddr addr, uint32_t val, uint8_t *ptr; MemoryRegionSection *section; - section = phys_page_find(address_space_memory.dispatch, addr >> TARGET_PAGE_BITS); + section = address_space_lookup_region(&address_space_memory, addr); if (!memory_region_is_ram(section->mr) || section->readonly) { addr = memory_region_section_addr(section, addr); @@ -2509,7 +2506,7 @@ static inline void stw_phys_internal(hwaddr addr, uint32_t val, uint8_t *ptr; MemoryRegionSection *section; - section = phys_page_find(address_space_memory.dispatch, addr >> TARGET_PAGE_BITS); + section = address_space_lookup_region(&address_space_memory, addr); if (!memory_region_is_ram(section->mr) || section->readonly) { addr = memory_region_section_addr(section, addr); @@ -2634,8 +2631,7 @@ bool cpu_physical_memory_is_io(hwaddr phys_addr) { MemoryRegionSection *section; - section = phys_page_find(address_space_memory.dispatch, - phys_addr >> TARGET_PAGE_BITS); + section = address_space_lookup_region(&address_space_memory, phys_addr); return !(memory_region_is_ram(section->mr) || memory_region_is_romd(section->mr)); diff --git a/include/exec/cputlb.h b/include/exec/cputlb.h index 733c885..f144e6e 100644 --- a/include/exec/cputlb.h +++ b/include/exec/cputlb.h @@ -26,8 +26,6 @@ void tlb_unprotect_code_phys(CPUArchState *env, ram_addr_t ram_addr, target_ulong vaddr); void tlb_reset_dirty_range(CPUTLBEntry *tlb_entry, uintptr_t start, uintptr_t length); -MemoryRegionSection *phys_page_find(struct AddressSpaceDispatch *d, - hwaddr index); void cpu_tlb_reset_dirty_all(ram_addr_t start1, ram_addr_t length); void tlb_set_dirty(CPUArchState *env, target_ulong vaddr); extern int tlb_flush_count; diff --git a/include/exec/memory.h b/include/exec/memory.h index 9e88320..11ca4e2 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -887,6 +887,15 @@ void *address_space_map(AddressSpace *as, hwaddr addr, void address_space_unmap(AddressSpace *as, void *buffer, hwaddr len, int is_write, hwaddr access_len); +/** + * address_space_lookup_region: Looks up memory region corresponding to given + * access address + * + * @as: #AddressSpace to be accessed + * @addr: address within that address space + */ +MemoryRegionSection *address_space_lookup_region(AddressSpace *as, + hwaddr addr); #endif diff --git a/translate-all.c b/translate-all.c index da93608..078a657 100644 --- a/translate-all.c +++ b/translate-all.c @@ -1356,8 +1356,7 @@ void tb_invalidate_phys_addr(hwaddr addr) ram_addr_t ram_addr; MemoryRegionSection *section; - section = phys_page_find(address_space_memory.dispatch, - addr >> TARGET_PAGE_BITS); + section = address_space_lookup_region(&address_space_memory, addr); if (!(memory_region_is_ram(section->mr) || (section->mr->rom_device && section->mr->readable))) { return;