From patchwork Mon Apr 9 19:19:02 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Blue Swirl X-Patchwork-Id: 151460 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 F0D4CB7027 for ; Tue, 10 Apr 2012 05:19:47 +1000 (EST) Received: from localhost ([::1]:60648 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SHK7t-0003DY-QR for incoming@patchwork.ozlabs.org; Mon, 09 Apr 2012 15:19:45 -0400 Received: from eggs.gnu.org ([208.118.235.92]:33797) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SHK7e-0002x1-BG for qemu-devel@nongnu.org; Mon, 09 Apr 2012 15:19:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SHK7Z-0003U8-4J for qemu-devel@nongnu.org; Mon, 09 Apr 2012 15:19:29 -0400 Received: from mail-iy0-f173.google.com ([209.85.210.173]:49821) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SHK7Y-0003Rc-PF for qemu-devel@nongnu.org; Mon, 09 Apr 2012 15:19:25 -0400 Received: by iafj26 with SMTP id j26so7505426iaf.4 for ; Mon, 09 Apr 2012 12:19:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type; bh=UyMauS+xyM+xoSSFAlEsNKOtQCcHsHj6xKrVoSxWAnU=; b=GQcStKGIP/gCOzg/hG+m41msjXPlrq65CCe2krjoLylEb5Tht+HL3X3qhGUYhbWtP1 6dAZEenotUAyKVmZJW3bDFZ12CqyoSePx0pBHX1ONbvDfg6k+gPPyqVMkd62lu66S338 0xiKghQ0LH1otrwVABOIzeimm1jG4iu4PvBqJY8grUtSP8bPgHYbV1T6jP68FocbF+IG C4lLlJKcWQSaEorJE+R65mPmijqJs1ofnB3CSlblQwdwjo/uv3/w/6dugolzcTfOvORj r+29AC8biCEnd96nnPXYqofNzftvxa0PJ/khn1fmc8oM3cQaxN6lV4h3w5r3B58winr+ NG0Q== Received: by 10.50.47.162 with SMTP id e2mr172074ign.0.1333999163136; Mon, 09 Apr 2012 12:19:23 -0700 (PDT) MIME-Version: 1.0 Received: by 10.50.197.194 with HTTP; Mon, 9 Apr 2012 12:19:02 -0700 (PDT) From: Blue Swirl Date: Mon, 9 Apr 2012 19:19:02 +0000 Message-ID: To: Avi Kivity , qemu-devel X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.210.173 Subject: [Qemu-devel] [PATCH 3/3] memory: move RAM test functions to memory 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 Rename functions with memory_region_ prefix to avoid future clashes. Change the RAM/ROM/ROMD test functions to take MemoryRegion instead of MemoryRegionSection. Adjust callers. Signed-off-by: Blue Swirl --- cputlb.c | 10 +++++----- cputlb.h | 18 ----------------- exec.c | 67 ++++++++++++++++++++++++++++---------------------------------- memory.h | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 88 insertions(+), 60 deletions(-) From 4cf1831f0854623181dc4e946f63dd53e6d207bd Mon Sep 17 00:00:00 2001 Message-Id: <4cf1831f0854623181dc4e946f63dd53e6d207bd.1333999035.git.blauwirbel@gmail.com> In-Reply-To: <5c865cbcae81430ab1bed4e9c3c5b8bf0dd43e0b.1333999034.git.blauwirbel@gmail.com> References: <5c865cbcae81430ab1bed4e9c3c5b8bf0dd43e0b.1333999034.git.blauwirbel@gmail.com> From: Blue Swirl Date: Mon, 9 Apr 2012 17:38:52 +0000 Subject: [PATCH 3/3] memory: move RAM test functions to memory Rename functions with memory_region_ prefix to avoid future clashes. Change the RAM/ROM/ROMD test functions to take MemoryRegion instead of MemoryRegionSection. Adjust callers. Signed-off-by: Blue Swirl --- cputlb.c | 10 ++++---- cputlb.h | 18 ---------------- exec.c | 67 +++++++++++++++++++++++++++---------------------------------- memory.h | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 88 insertions(+), 60 deletions(-) diff --git a/cputlb.c b/cputlb.c index c49a3e8..dc15b28 100644 --- a/cputlb.c +++ b/cputlb.c @@ -256,13 +256,13 @@ void tlb_set_page(CPUArchState *env, target_ulong vaddr, #endif address = vaddr; - if (!is_ram_rom_romd(section)) { + if (!memory_region_is_ram_rom_romd(section->mr)) { /* IO memory case (romd handled later) */ address |= TLB_MMIO; } - if (is_ram_rom_romd(section)) { + if (memory_region_is_ram_rom_romd(section->mr)) { addend = (unsigned long)memory_region_get_ram_ptr(section->mr) - + section_addr(section, paddr); + + memory_region_section_addr(section, paddr); } else { addend = 0; } @@ -289,13 +289,13 @@ void tlb_set_page(CPUArchState *env, target_ulong vaddr, } if (prot & PAGE_WRITE) { if ((memory_region_is_ram(section->mr) && section->readonly) - || is_romd(section)) { + || memory_region_is_romd(section->mr)) { /* Write access calls the I/O callback. */ te->addr_write = address | TLB_MMIO; } else if (memory_region_is_ram(section->mr) && !cpu_physical_memory_is_dirty( section->mr->ram_addr - + section_addr(section, paddr))) { + + memory_region_section_addr(section, paddr))) { te->addr_write = address | TLB_NOTDIRTY; } else { te->addr_write = address; diff --git a/cputlb.h b/cputlb.h index d16c22e..ce6e297 100644 --- a/cputlb.h +++ b/cputlb.h @@ -32,8 +32,6 @@ void tlb_set_dirty(CPUArchState *env, target_ulong vaddr); extern int tlb_flush_count; /* exec.c */ -target_phys_addr_t section_addr(MemoryRegionSection *section, - target_phys_addr_t addr); void tb_flush_jmp_cache(CPUArchState *env, target_ulong addr); target_phys_addr_t memory_region_section_get_iotlb(CPUArchState *env, MemoryRegionSection *section, @@ -43,21 +41,5 @@ target_phys_addr_t memory_region_section_get_iotlb(CPUArchState *env, target_ulong *address); bool memory_region_is_unassigned(MemoryRegion *mr); -static inline bool is_ram_rom(MemoryRegionSection *s) -{ - return memory_region_is_ram(s->mr); -} - -static inline bool is_romd(MemoryRegionSection *s) -{ - MemoryRegion *mr = s->mr; - - return mr->rom_device && mr->readable; -} -static inline bool is_ram_rom_romd(MemoryRegionSection *s) -{ - return is_ram_rom(s) || is_romd(s); -} - #endif #endif diff --git a/exec.c b/exec.c index 0dda7b5..5080dde 100644 --- a/exec.c +++ b/exec.c @@ -507,10 +507,10 @@ target_phys_addr_t memory_region_section_get_iotlb(CPUArchState *env, target_phys_addr_t iotlb; CPUWatchpoint *wp; - if (is_ram_rom(section)) { + if (memory_region_is_ram_rom(section->mr)) { /* Normal RAM. */ iotlb = (memory_region_get_ram_addr(section->mr) & TARGET_PAGE_MASK) - + section_addr(section, paddr); + + memory_region_section_addr(section, paddr); if (!section->readonly) { iotlb |= phys_section_notdirty; } else { @@ -524,7 +524,7 @@ target_phys_addr_t memory_region_section_get_iotlb(CPUArchState *env, We can't use the high bits of pd for this because IO_MEM_ROMD uses these as a ram address. */ iotlb = section - phys_sections; - iotlb += section_addr(section, paddr); + iotlb += memory_region_section_addr(section, paddr); } /* Make accesses to pages with watchpoints go via the @@ -550,14 +550,6 @@ bool memory_region_is_unassigned(MemoryRegion *mr) && mr != &io_mem_watch; } -target_phys_addr_t section_addr(MemoryRegionSection *section, - target_phys_addr_t addr) -{ - addr -= section->offset_within_address_space; - addr += section->offset_within_region; - return addr; -} - #define mmap_lock() do { } while(0) #define mmap_unlock() do { } while(0) #endif @@ -1523,7 +1515,7 @@ static void breakpoint_invalidate(CPUArchState *env, target_ulong pc) return; } ram_addr = (memory_region_get_ram_addr(section->mr) & TARGET_PAGE_MASK) - + section_addr(section, addr); + + memory_region_section_addr(section, addr); tb_invalidate_phys_page_range(ram_addr, ram_addr + 1, 0); } #endif @@ -3514,7 +3506,7 @@ void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf, if (is_write) { if (!memory_region_is_ram(section->mr)) { target_phys_addr_t addr1; - addr1 = section_addr(section, addr); + addr1 = memory_region_section_addr(section, addr); /* XXX: could force cpu_single_env to NULL to avoid potential bugs */ if (l >= 4 && ((addr1 & 3) == 0)) { @@ -3536,7 +3528,7 @@ void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf, } else if (!section->readonly) { ram_addr_t addr1; addr1 = memory_region_get_ram_addr(section->mr) - + section_addr(section, addr); + + memory_region_section_addr(section, addr); /* RAM case */ ptr = qemu_get_ram_ptr(addr1); memcpy(ptr, buf, l); @@ -3550,10 +3542,10 @@ void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf, qemu_put_ram_ptr(ptr); } } else { - if (!is_ram_rom_romd(section)) { + if (!memory_region_is_ram_rom_romd(section->mr)) { target_phys_addr_t addr1; /* I/O case */ - addr1 = section_addr(section, addr); + addr1 = memory_region_section_addr(section, addr); if (l >= 4 && ((addr1 & 3) == 0)) { /* 32 bit read access */ val = io_mem_read(section->mr, addr1, 4); @@ -3573,7 +3565,8 @@ void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf, } else { /* RAM case */ ptr = qemu_get_ram_ptr(section->mr->ram_addr - + section_addr(section, addr)); + + memory_region_section_addr(section, + addr)); memcpy(buf, ptr, l); qemu_put_ram_ptr(ptr); } @@ -3600,12 +3593,12 @@ void cpu_physical_memory_write_rom(target_phys_addr_t addr, l = len; section = phys_page_find(page >> TARGET_PAGE_BITS); - if (!is_ram_rom_romd(section)) { + if (!memory_region_is_ram_rom_romd(section->mr)) { /* do nothing */ } else { unsigned long addr1; addr1 = memory_region_get_ram_addr(section->mr) - + section_addr(section, addr); + + memory_region_section_addr(section, addr); /* ROM/RAM case */ ptr = qemu_get_ram_ptr(addr1); memcpy(ptr, buf, l); @@ -3706,7 +3699,7 @@ void *cpu_physical_memory_map(target_phys_addr_t addr, } if (!todo) { raddr = memory_region_get_ram_addr(section->mr) - + section_addr(section, addr); + + memory_region_section_addr(section, addr); } len -= l; @@ -3768,9 +3761,9 @@ static inline uint32_t ldl_phys_internal(target_phys_addr_t addr, section = phys_page_find(addr >> TARGET_PAGE_BITS); - if (!is_ram_rom_romd(section)) { + if (!memory_region_is_ram_rom_romd(section->mr)) { /* I/O case */ - addr = section_addr(section, addr); + addr = memory_region_section_addr(section, addr); val = io_mem_read(section->mr, addr, 4); #if defined(TARGET_WORDS_BIGENDIAN) if (endian == DEVICE_LITTLE_ENDIAN) { @@ -3785,7 +3778,7 @@ static inline uint32_t ldl_phys_internal(target_phys_addr_t addr, /* RAM case */ ptr = qemu_get_ram_ptr((memory_region_get_ram_addr(section->mr) & TARGET_PAGE_MASK) - + section_addr(section, addr)); + + memory_region_section_addr(section, addr)); switch (endian) { case DEVICE_LITTLE_ENDIAN: val = ldl_le_p(ptr); @@ -3826,9 +3819,9 @@ static inline uint64_t ldq_phys_internal(target_phys_addr_t addr, section = phys_page_find(addr >> TARGET_PAGE_BITS); - if (!is_ram_rom_romd(section)) { + if (!memory_region_is_ram_rom_romd(section->mr)) { /* I/O case */ - addr = section_addr(section, addr); + addr = memory_region_section_addr(section, addr); /* XXX This is broken when device endian != cpu endian. Fix and add "endian" variable check */ @@ -3843,7 +3836,7 @@ static inline uint64_t ldq_phys_internal(target_phys_addr_t addr, /* RAM case */ ptr = qemu_get_ram_ptr((memory_region_get_ram_addr(section->mr) & TARGET_PAGE_MASK) - + section_addr(section, addr)); + + memory_region_section_addr(section, addr)); switch (endian) { case DEVICE_LITTLE_ENDIAN: val = ldq_le_p(ptr); @@ -3892,9 +3885,9 @@ static inline uint32_t lduw_phys_internal(target_phys_addr_t addr, section = phys_page_find(addr >> TARGET_PAGE_BITS); - if (!is_ram_rom_romd(section)) { + if (!memory_region_is_ram_rom_romd(section->mr)) { /* I/O case */ - addr = section_addr(section, addr); + addr = memory_region_section_addr(section, addr); val = io_mem_read(section->mr, addr, 2); #if defined(TARGET_WORDS_BIGENDIAN) if (endian == DEVICE_LITTLE_ENDIAN) { @@ -3909,7 +3902,7 @@ static inline uint32_t lduw_phys_internal(target_phys_addr_t addr, /* RAM case */ ptr = qemu_get_ram_ptr((memory_region_get_ram_addr(section->mr) & TARGET_PAGE_MASK) - + section_addr(section, addr)); + + memory_region_section_addr(section, addr)); switch (endian) { case DEVICE_LITTLE_ENDIAN: val = lduw_le_p(ptr); @@ -3951,7 +3944,7 @@ void stl_phys_notdirty(target_phys_addr_t addr, uint32_t val) section = phys_page_find(addr >> TARGET_PAGE_BITS); if (!memory_region_is_ram(section->mr) || section->readonly) { - addr = section_addr(section, addr); + addr = memory_region_section_addr(section, addr); if (memory_region_is_ram(section->mr)) { section = &phys_sections[phys_section_rom]; } @@ -3959,7 +3952,7 @@ void stl_phys_notdirty(target_phys_addr_t addr, uint32_t val) } else { unsigned long addr1 = (memory_region_get_ram_addr(section->mr) & TARGET_PAGE_MASK) - + section_addr(section, addr); + + memory_region_section_addr(section, addr); ptr = qemu_get_ram_ptr(addr1); stl_p(ptr, val); @@ -3983,7 +3976,7 @@ void stq_phys_notdirty(target_phys_addr_t addr, uint64_t val) section = phys_page_find(addr >> TARGET_PAGE_BITS); if (!memory_region_is_ram(section->mr) || section->readonly) { - addr = section_addr(section, addr); + addr = memory_region_section_addr(section, addr); if (memory_region_is_ram(section->mr)) { section = &phys_sections[phys_section_rom]; } @@ -3997,7 +3990,7 @@ void stq_phys_notdirty(target_phys_addr_t addr, uint64_t val) } else { ptr = qemu_get_ram_ptr((memory_region_get_ram_addr(section->mr) & TARGET_PAGE_MASK) - + section_addr(section, addr)); + + memory_region_section_addr(section, addr)); stq_p(ptr, val); } } @@ -4012,7 +4005,7 @@ static inline void stl_phys_internal(target_phys_addr_t addr, uint32_t val, section = phys_page_find(addr >> TARGET_PAGE_BITS); if (!memory_region_is_ram(section->mr) || section->readonly) { - addr = section_addr(section, addr); + addr = memory_region_section_addr(section, addr); if (memory_region_is_ram(section->mr)) { section = &phys_sections[phys_section_rom]; } @@ -4029,7 +4022,7 @@ static inline void stl_phys_internal(target_phys_addr_t addr, uint32_t val, } else { unsigned long addr1; addr1 = (memory_region_get_ram_addr(section->mr) & TARGET_PAGE_MASK) - + section_addr(section, addr); + + memory_region_section_addr(section, addr); /* RAM case */ ptr = qemu_get_ram_ptr(addr1); switch (endian) { @@ -4085,7 +4078,7 @@ static inline void stw_phys_internal(target_phys_addr_t addr, uint32_t val, section = phys_page_find(addr >> TARGET_PAGE_BITS); if (!memory_region_is_ram(section->mr) || section->readonly) { - addr = section_addr(section, addr); + addr = memory_region_section_addr(section, addr); if (memory_region_is_ram(section->mr)) { section = &phys_sections[phys_section_rom]; } @@ -4102,7 +4095,7 @@ static inline void stw_phys_internal(target_phys_addr_t addr, uint32_t val, } else { unsigned long addr1; addr1 = (memory_region_get_ram_addr(section->mr) & TARGET_PAGE_MASK) - + section_addr(section, addr); + + memory_region_section_addr(section, addr); /* RAM case */ ptr = qemu_get_ram_ptr(addr1); switch (endian) { diff --git a/memory.h b/memory.h index 53ff62b..3b48394 100644 --- a/memory.h +++ b/memory.h @@ -339,6 +339,43 @@ uint64_t memory_region_size(MemoryRegion *mr); bool memory_region_is_ram(MemoryRegion *mr); /** + * memory_region_is_ram_rom: check whether a memory region is RAM or ROM + * + * Returns %true is a memory region is RAM or ROM + * + * @mr: the memory region being queried + */ +static inline bool memory_region_is_ram_rom(MemoryRegion *mr) +{ + return memory_region_is_ram(mr); +} + +/** + * memory_region_is_romd: check whether a memory region is ROMD + * + * Returns %true is a memory region is ROMD + * + * @mr: the memory region being queried + */ +static inline bool memory_region_is_romd(MemoryRegion *mr) +{ + return mr->rom_device && mr->readable; +} + +/** + * memory_region_is_ram_rom_romd: check whether a memory region is + * RAM, ROM or ROMD + * + * Returns %true is a memory region is RAM, ROM or ROMD + * + * @mr: the memory region being queried + */ +static inline bool memory_region_is_ram_rom_romd(MemoryRegion *mr) +{ + return memory_region_is_ram_rom(mr) || memory_region_is_romd(mr); +} + +/** * memory_region_name: get a memory region's name * * Returns the string that was used to initialize the memory region. @@ -666,6 +703,22 @@ void memory_region_set_alias_offset(MemoryRegion *mr, MemoryRegionSection memory_region_find(MemoryRegion *address_space, target_phys_addr_t addr, uint64_t size); +/** + * memory_region_section_addr: get offset within MemoryRegionSection + * + * Returns offset within MemoryRegionSection + * + * @section: the memory region section being queried + * @addr: address in address space + */ +static inline target_phys_addr_t +memory_region_section_addr(MemoryRegionSection *section, + target_phys_addr_t addr) +{ + addr -= section->offset_within_address_space; + addr += section->offset_within_region; + return addr; +} /** * memory_global_sync_dirty_bitmap: synchronize the dirty log for all memory -- 1.7.2.5