mirror of
https://github.com/izzy2lost/xemu.git
synced 2026-07-06 00:20:22 -07:00
memory: add address_space_translate
Using phys_page_find to translate an AddressSpace to a MemoryRegionSection is unwieldy. It requires to pass the page index rather than the address, and later memory_region_section_addr has to be called. Replace memory_region_section_addr with a function that does all of it: call phys_page_find, compute the offset within the region, and check how big the current mapping is. This way, a large flat region can be written with a single lookup rather than a page at a time. address_space_translate will also provide a single point where IOMMU forwarding is implemented. Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Richard Henderson <rth@twiddle.net> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
+14
-17
@@ -751,23 +751,6 @@ void memory_region_set_alias_offset(MemoryRegion *mr,
|
||||
MemoryRegionSection memory_region_find(MemoryRegion *mr,
|
||||
hwaddr 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 hwaddr
|
||||
memory_region_section_addr(MemoryRegionSection *section,
|
||||
hwaddr addr)
|
||||
{
|
||||
addr -= section->offset_within_address_space;
|
||||
addr += section->offset_within_region;
|
||||
return addr;
|
||||
}
|
||||
|
||||
/**
|
||||
* address_space_sync_dirty_bitmap: synchronize the dirty log for all memory
|
||||
*
|
||||
@@ -869,6 +852,20 @@ void address_space_write(AddressSpace *as, hwaddr addr,
|
||||
*/
|
||||
void address_space_read(AddressSpace *as, hwaddr addr, uint8_t *buf, int len);
|
||||
|
||||
/* address_space_translate: translate an address range into an address space
|
||||
* into a MemoryRegionSection and an address range into that section
|
||||
*
|
||||
* @as: #AddressSpace to be accessed
|
||||
* @addr: address within that address space
|
||||
* @xlat: pointer to address within the returned memory region section's
|
||||
* #MemoryRegion.
|
||||
* @len: pointer to length
|
||||
* @is_write: indicates the transfer direction
|
||||
*/
|
||||
MemoryRegionSection *address_space_translate(AddressSpace *as, hwaddr addr,
|
||||
hwaddr *xlat, hwaddr *len,
|
||||
bool is_write);
|
||||
|
||||
/* address_space_map: map a physical memory region into a host virtual address
|
||||
*
|
||||
* May map a subset of the requested range, given by and returned in @plen.
|
||||
|
||||
Reference in New Issue
Block a user