>From 796abe4e7114d18e74cc869922cc5eb0813396c8 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Tue, 7 May 2013 11:30:23 +0200 Subject: [PATCH] subpage fix Note: this temporarily breaks RAM regions in the I/O address space, but there is none. It will be fixed later when the special address space listener is dropped. Signed-off-by: Paolo Bonzini --- exec.c | 56 ++++++++++++-------------------------------------------- 1 files changed, 12 insertions(+), 44 deletions(-) diff --git a/exec.c b/exec.c index 7098632..21bd08d 100644 --- a/exec.c +++ b/exec.c @@ -65,7 +65,6 @@ AddressSpace address_space_io; AddressSpace address_space_memory; MemoryRegion io_mem_ram, io_mem_rom, io_mem_unassigned, io_mem_notdirty; -static MemoryRegion io_mem_subpage_ram; #endif @@ -80,7 +79,8 @@ int use_icount; #if !defined(CONFIG_USER_ONLY) -#define SUBSECTION_IDX(addr) ((addr) & ~TARGET_PAGE_MASK) +#define SUBSECTION_IDX(addr) ((addr) & ~TARGET_PAGE_MASK) +#define PHYS_SECTION_ID(psection) ((psection) - phys_sections) typedef struct PhysSection { MemoryRegionSection section; @@ -695,7 +695,7 @@ hwaddr memory_region_section_get_iotlb(CPUArchState *env, iotlb |= phys_section_rom; } } else { - iotlb = container_of(section, PhysSection, section) - phys_sections; + iotlb = PHYS_SECTION_ID(container_of(section, PhysSection, section)); iotlb += xlat; } @@ -782,7 +782,7 @@ static void register_subsection(AddressSpaceDispatch *d, .offset_within_address_space = base, .size = TARGET_PAGE_SIZE, }; - uint16_t new_section; + uint16_t new_section, new_subsection; hwaddr start, end; assert(psection->sub_section || @@ -793,10 +793,17 @@ static void register_subsection(AddressSpaceDispatch *d, psection = &phys_sections[new_section]; subsections_init(psection); phys_page_set(d, base >> TARGET_PAGE_BITS, 1, new_section); + } else { + new_section = PHYS_SECTION_ID(psection); } + + new_subsection = phys_section_add(section); + + /* phys_section_add invalidates psection, reload it */ + psection = &phys_sections[new_section]; start = section->offset_within_address_space & ~TARGET_PAGE_MASK; end = start + section->size - 1; - subsection_register(psection, start, end, phys_section_add(section)); + subsection_register(psection, start, end, new_subsection); } @@ -1607,38 +1614,6 @@ static const MemoryRegionOps watch_mem_ops = { .endianness = DEVICE_NATIVE_ENDIAN, }; -static uint64_t subpage_ram_read(void *opaque, hwaddr addr, - unsigned size) -{ - ram_addr_t raddr = addr; - void *ptr = qemu_get_ram_ptr(raddr); - switch (size) { - case 1: return ldub_p(ptr); - case 2: return lduw_p(ptr); - case 4: return ldl_p(ptr); - default: abort(); - } -} - -static void subpage_ram_write(void *opaque, hwaddr addr, - uint64_t value, unsigned size) -{ - ram_addr_t raddr = addr; - void *ptr = qemu_get_ram_ptr(raddr); - switch (size) { - case 1: return stb_p(ptr, value); - case 2: return stw_p(ptr, value); - case 4: return stl_p(ptr, value); - default: abort(); - } -} - -static const MemoryRegionOps subpage_ram_ops = { - .read = subpage_ram_read, - .write = subpage_ram_write, - .endianness = DEVICE_NATIVE_ENDIAN, -}; - static int subsection_register(PhysSection *psection, uint32_t start, uint32_t end, uint16_t section) { @@ -1648,11 +1623,6 @@ static int subsection_register(PhysSection *psection, uint32_t start, return -1; idx = SUBSECTION_IDX(start); eidx = SUBSECTION_IDX(end); - if (memory_region_is_ram(phys_sections[section].section.mr)) { - MemoryRegionSection new_section = phys_sections[section].section; - new_section.mr = &io_mem_subpage_ram; - section = phys_section_add(&new_section); - } for (; idx <= eidx; idx++) { psection->sub_section[idx] = section; } @@ -1692,8 +1662,6 @@ static void io_mem_init(void) "unassigned", UINT64_MAX); memory_region_init_io(&io_mem_notdirty, ¬dirty_mem_ops, NULL, "notdirty", UINT64_MAX); - memory_region_init_io(&io_mem_subpage_ram, &subpage_ram_ops, NULL, - "subpage-ram", UINT64_MAX); memory_region_init_io(&io_mem_watch, &watch_mem_ops, NULL, "watch", UINT64_MAX); } -- 1.7.1