simplify MemoryRegion

This commit is contained in:
Nguyen Anh Quynh 2020-06-11 20:55:13 +08:00
parent db01ecd4be
commit e120cd03b4
4 changed files with 1 additions and 80 deletions

View File

@ -182,7 +182,6 @@ struct uc_struct {
RAMList ram_list; // qemu/exec.c RAMList ram_list; // qemu/exec.c
BounceBuffer bounce; // qemu/cpu-exec.c BounceBuffer bounce; // qemu/cpu-exec.c
volatile sig_atomic_t exit_request; // qemu/cpu-exec.c volatile sig_atomic_t exit_request; // qemu/cpu-exec.c
bool global_dirty_log; // qemu/memory.c
/* This is a multi-level map on the virtual address space. /* This is a multi-level map on the virtual address space.
The bottom level has pointers to PageDesc. */ The bottom level has pointers to PageDesc. */
void **l1_map; // qemu/translate-all.c void **l1_map; // qemu/translate-all.c

View File

@ -287,7 +287,7 @@ static MemoryRegionSection *phys_page_find(PhysPageEntry lp, hwaddr addr,
bool memory_region_is_unassigned(struct uc_struct* uc, MemoryRegion *mr) bool memory_region_is_unassigned(struct uc_struct* uc, MemoryRegion *mr)
{ {
return mr != &uc->io_mem_rom && mr != &uc->io_mem_notdirty && return mr != &uc->io_mem_rom && mr != &uc->io_mem_notdirty &&
!mr->rom_device && mr != &uc->io_mem_watch; mr != &uc->io_mem_watch;
} }
static MemoryRegionSection *address_space_lookup_region(AddressSpaceDispatch *d, static MemoryRegionSection *address_space_lookup_region(AddressSpaceDispatch *d,

View File

@ -134,21 +134,14 @@ struct MemoryRegion {
uint64_t align; uint64_t align;
bool subpage; bool subpage;
bool terminates; bool terminates;
bool romd_mode;
bool ram; bool ram;
bool skip_dump;
bool readonly; /* For RAM regions */ bool readonly; /* For RAM regions */
bool enabled; bool enabled;
bool rom_device;
bool warning_printed; /* For reservations */
MemoryRegion *alias;
hwaddr alias_offset;
int32_t priority; int32_t priority;
bool may_overlap; bool may_overlap;
QTAILQ_HEAD(subregions, MemoryRegion) subregions; QTAILQ_HEAD(subregions, MemoryRegion) subregions;
QTAILQ_ENTRY(MemoryRegion) subregions_link; QTAILQ_ENTRY(MemoryRegion) subregions_link;
const char *name; const char *name;
uint8_t dirty_log_mask;
struct uc_struct *uc; struct uc_struct *uc;
uint32_t perms; //all perms, partially redundant with readonly uint32_t perms; //all perms, partially redundant with readonly
uint64_t end; uint64_t end;
@ -168,11 +161,6 @@ struct MemoryListener {
void (*region_add)(MemoryListener *listener, MemoryRegionSection *section); void (*region_add)(MemoryListener *listener, MemoryRegionSection *section);
void (*region_del)(MemoryListener *listener, MemoryRegionSection *section); void (*region_del)(MemoryListener *listener, MemoryRegionSection *section);
void (*region_nop)(MemoryListener *listener, MemoryRegionSection *section); void (*region_nop)(MemoryListener *listener, MemoryRegionSection *section);
void (*log_start)(MemoryListener *listener, MemoryRegionSection *section);
void (*log_stop)(MemoryListener *listener, MemoryRegionSection *section);
void (*log_sync)(MemoryListener *listener, MemoryRegionSection *section);
void (*log_global_start)(MemoryListener *listener);
void (*log_global_stop)(MemoryListener *listener);
/* Lower = earlier (during add), later (during del) */ /* Lower = earlier (during add), later (during del) */
unsigned priority; unsigned priority;
AddressSpace *address_space_filter; AddressSpace *address_space_filter;
@ -311,16 +299,6 @@ uint64_t memory_region_size(MemoryRegion *mr);
*/ */
bool memory_region_is_ram(MemoryRegion *mr); bool memory_region_is_ram(MemoryRegion *mr);
/**
* memory_region_is_skip_dump: check whether a memory region should not be
* dumped
*
* Returns %true is a memory region should not be dumped(e.g. VFIO BAR MMAP).
*
* @mr: the memory region being queried
*/
bool memory_region_is_skip_dump(MemoryRegion *mr);
/** /**
* memory_region_is_iommu: check whether a memory region is an iommu * memory_region_is_iommu: check whether a memory region is an iommu
* *
@ -350,15 +328,6 @@ void memory_region_notify_iommu(MemoryRegion *mr,
*/ */
const char *memory_region_name(const MemoryRegion *mr); const char *memory_region_name(const MemoryRegion *mr);
/**
* memory_region_is_logging: return whether a memory region is logging writes
*
* Returns %true if the memory region is logging writes
*
* @mr: the memory region being queried
*/
bool memory_region_is_logging(MemoryRegion *mr);
/** /**
* memory_region_is_rom: check whether a memory region is ROM * memory_region_is_rom: check whether a memory region is ROM
* *

View File

@ -263,8 +263,6 @@ struct FlatRange {
MemoryRegion *mr; MemoryRegion *mr;
hwaddr offset_in_region; hwaddr offset_in_region;
AddrRange addr; AddrRange addr;
uint8_t dirty_log_mask;
bool romd_mode;
bool readonly; bool readonly;
}; };
@ -288,7 +286,6 @@ static bool flatrange_equal(FlatRange *a, FlatRange *b)
return a->mr == b->mr return a->mr == b->mr
&& addrrange_equal(a->addr, b->addr) && addrrange_equal(a->addr, b->addr)
&& a->offset_in_region == b->offset_in_region && a->offset_in_region == b->offset_in_region
&& a->romd_mode == b->romd_mode
&& a->readonly == b->readonly; && a->readonly == b->readonly;
} }
@ -341,8 +338,6 @@ static bool can_merge(FlatRange *r1, FlatRange *r2)
&& int128_eq(int128_add(int128_make64(r1->offset_in_region), && int128_eq(int128_add(int128_make64(r1->offset_in_region),
r1->addr.size), r1->addr.size),
int128_make64(r2->offset_in_region)) int128_make64(r2->offset_in_region))
&& r1->dirty_log_mask == r2->dirty_log_mask
&& r1->romd_mode == r2->romd_mode
&& r1->readonly == r2->readonly; && r1->readonly == r2->readonly;
} }
@ -543,13 +538,6 @@ static void render_memory_region(FlatView *view,
clip = addrrange_intersection(tmp, clip); clip = addrrange_intersection(tmp, clip);
if (mr->alias) {
int128_subfrom(&base, int128_make64(mr->alias->addr));
int128_subfrom(&base, int128_make64(mr->alias_offset));
render_memory_region(view, mr->alias, base, clip, readonly);
return;
}
/* Render subregions in priority order. */ /* Render subregions in priority order. */
QTAILQ_FOREACH(subregion, &mr->subregions, subregions_link) { QTAILQ_FOREACH(subregion, &mr->subregions, subregions_link) {
render_memory_region(view, subregion, base, clip, readonly); render_memory_region(view, subregion, base, clip, readonly);
@ -564,8 +552,6 @@ static void render_memory_region(FlatView *view,
remain = clip.size; remain = clip.size;
fr.mr = mr; fr.mr = mr;
fr.dirty_log_mask = mr->dirty_log_mask;
fr.romd_mode = mr->romd_mode;
fr.readonly = readonly; fr.readonly = readonly;
/* Render the region itself into any gaps left by the current view. */ /* Render the region itself into any gaps left by the current view. */
@ -666,11 +652,6 @@ static void address_space_update_topology_pass(AddressSpace *as,
if (adding) { if (adding) {
MEMORY_LISTENER_UPDATE_REGION(frnew, as, Forward, region_nop); MEMORY_LISTENER_UPDATE_REGION(frnew, as, Forward, region_nop);
if (frold->dirty_log_mask && !frnew->dirty_log_mask) {
MEMORY_LISTENER_UPDATE_REGION(frnew, as, Reverse, log_stop);
} else if (frnew->dirty_log_mask && !frold->dirty_log_mask) {
MEMORY_LISTENER_UPDATE_REGION(frnew, as, Forward, log_start);
}
} }
++iold; ++iold;
@ -747,7 +728,6 @@ void memory_region_init(struct uc_struct *uc, MemoryRegion *mr,
memset(mr, 0, sizeof(*mr)); memset(mr, 0, sizeof(*mr));
mr->ops = &unassigned_mem_ops; mr->ops = &unassigned_mem_ops;
mr->enabled = true; mr->enabled = true;
mr->romd_mode = true;
mr->destructor = memory_region_destructor_none; mr->destructor = memory_region_destructor_none;
QTAILQ_INIT(&mr->subregions); QTAILQ_INIT(&mr->subregions);
@ -938,26 +918,11 @@ bool memory_region_is_ram(MemoryRegion *mr)
return mr->ram; return mr->ram;
} }
bool memory_region_is_skip_dump(MemoryRegion *mr)
{
return mr->skip_dump;
}
bool memory_region_is_logging(MemoryRegion *mr)
{
return mr->dirty_log_mask;
}
bool memory_region_is_rom(MemoryRegion *mr) bool memory_region_is_rom(MemoryRegion *mr)
{ {
return mr->ram && mr->readonly; return mr->ram && mr->readonly;
} }
bool memory_region_is_iommu(MemoryRegion *mr)
{
return mr->iommu_ops != 0;
}
void memory_region_set_readonly(MemoryRegion *mr, bool readonly) void memory_region_set_readonly(MemoryRegion *mr, bool readonly)
{ {
if (mr->readonly != readonly) { if (mr->readonly != readonly) {
@ -975,12 +940,6 @@ void memory_region_set_readonly(MemoryRegion *mr, bool readonly)
void *memory_region_get_ram_ptr(MemoryRegion *mr) void *memory_region_get_ram_ptr(MemoryRegion *mr)
{ {
if (mr->alias) {
return (char*)memory_region_get_ram_ptr(mr->alias) + mr->alias_offset;
}
assert(mr->terminates);
return qemu_get_ram_ptr(mr->uc, mr->ram_addr & TARGET_PAGE_MASK); return qemu_get_ram_ptr(mr->uc, mr->ram_addr & TARGET_PAGE_MASK);
} }
@ -1178,12 +1137,6 @@ static void listener_add_address_space(MemoryListener *listener,
return; return;
} }
if (listener->address_space_filter->uc->global_dirty_log) {
if (listener->log_global_start) {
listener->log_global_start(listener);
}
}
view = address_space_get_flatview(as); view = address_space_get_flatview(as);
FOR_EACH_FLAT_RANGE(fr, view) { FOR_EACH_FLAT_RANGE(fr, view) {
MemoryRegionSection section = MemoryRegionSection_make( MemoryRegionSection section = MemoryRegionSection_make(