From 6bba19ba4e2b8c89496569439ca38a328cf29a77 Mon Sep 17 00:00:00 2001 From: Avi Kivity Date: Wed, 14 Sep 2011 11:54:58 +0300 Subject: memory: introduce memory_region_set_enabled() This allows users to disable a memory region without removing it from the hierarchy, simplifying the implementation of memory routers. Signed-off-by: Avi Kivity --- memory.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'memory.h') diff --git a/memory.h b/memory.h index 53bf261792..c6997c4ee3 100644 --- a/memory.h +++ b/memory.h @@ -123,6 +123,7 @@ struct MemoryRegion { bool terminates; bool readable; bool readonly; /* For RAM regions */ + bool enabled; MemoryRegion *alias; target_phys_addr_t alias_offset; unsigned priority; @@ -501,6 +502,22 @@ void memory_region_add_subregion_overlap(MemoryRegion *mr, void memory_region_del_subregion(MemoryRegion *mr, MemoryRegion *subregion); + +/* + * memory_region_set_enabled: dynamically enable or disable a region + * + * Enables or disables a memory region. A disabled memory region + * ignores all accesses to itself and its subregions. It does not + * obscure sibling subregions with lower priority - it simply behaves as + * if it was removed from the hierarchy. + * + * Regions default to being enabled. + * + * @mr: the region to be updated + * @enabled: whether to enable or disable the region + */ +void memory_region_set_enabled(MemoryRegion *mr, bool enabled); + /* Start a transaction; changes will be accumulated and made visible only * when the transaction ends. */ -- cgit 1.4.1 From 2282e1af408db47bab0f900344c0ba0935835f48 Mon Sep 17 00:00:00 2001 From: Avi Kivity Date: Wed, 14 Sep 2011 12:10:12 +0300 Subject: memory: introduce memory_region_set_address() Allow changing the address of a memory region while it is in the memory hierarchy. Signed-off-by: Avi Kivity --- memory.c | 21 +++++++++++++++++++++ memory.h | 11 +++++++++++ 2 files changed, 32 insertions(+) (limited to 'memory.h') diff --git a/memory.c b/memory.c index d0f90ca350..a080d210c1 100644 --- a/memory.c +++ b/memory.c @@ -1324,6 +1324,27 @@ void memory_region_set_enabled(MemoryRegion *mr, bool enabled) memory_region_update_topology(NULL); } +void memory_region_set_address(MemoryRegion *mr, target_phys_addr_t addr) +{ + MemoryRegion *parent = mr->parent; + unsigned priority = mr->priority; + bool may_overlap = mr->may_overlap; + + if (addr == mr->addr || !parent) { + mr->addr = addr; + return; + } + + memory_region_transaction_begin(); + memory_region_del_subregion(parent, mr); + if (may_overlap) { + memory_region_add_subregion_overlap(parent, addr, mr, priority); + } else { + memory_region_add_subregion(parent, addr, mr); + } + memory_region_transaction_commit(); +} + void set_system_memory_map(MemoryRegion *mr) { address_space_memory.root = mr; diff --git a/memory.h b/memory.h index c6997c4ee3..db53422b2b 100644 --- a/memory.h +++ b/memory.h @@ -518,6 +518,17 @@ void memory_region_del_subregion(MemoryRegion *mr, */ void memory_region_set_enabled(MemoryRegion *mr, bool enabled); +/* + * memory_region_set_address: dynamically update the address of a region + * + * Dynamically updates the address of a region, relative to its parent. + * May be used on regions are currently part of a memory hierarchy. + * + * @mr: the region to be updated + * @addr: new address, relative to parent region + */ +void memory_region_set_address(MemoryRegion *mr, target_phys_addr_t addr); + /* Start a transaction; changes will be accumulated and made visible only * when the transaction ends. */ -- cgit 1.4.1 From 4703359e0eeb27c382fdf2951b842cf8bde26672 Mon Sep 17 00:00:00 2001 From: Avi Kivity Date: Sun, 4 Dec 2011 19:16:50 +0200 Subject: memory: introduce memory_region_set_alias_offset() Add an API to update an alias offset of an active alias. This can be used to simplify implementation of dynamic memory banks. Signed-off-by: Avi Kivity --- memory.c | 14 ++++++++++++++ memory.h | 12 ++++++++++++ 2 files changed, 26 insertions(+) (limited to 'memory.h') diff --git a/memory.c b/memory.c index a080d210c1..7e842b3ad5 100644 --- a/memory.c +++ b/memory.c @@ -1345,6 +1345,20 @@ void memory_region_set_address(MemoryRegion *mr, target_phys_addr_t addr) memory_region_transaction_commit(); } +void memory_region_set_alias_offset(MemoryRegion *mr, target_phys_addr_t offset) +{ + target_phys_addr_t old_offset = mr->alias_offset; + + assert(mr->alias); + mr->alias_offset = offset; + + if (offset == old_offset || !mr->parent) { + return; + } + + memory_region_update_topology(mr); +} + void set_system_memory_map(MemoryRegion *mr) { address_space_memory.root = mr; diff --git a/memory.h b/memory.h index db53422b2b..c07bcca306 100644 --- a/memory.h +++ b/memory.h @@ -529,6 +529,18 @@ void memory_region_set_enabled(MemoryRegion *mr, bool enabled); */ void memory_region_set_address(MemoryRegion *mr, target_phys_addr_t addr); +/* + * memory_region_set_alias_offset: dynamically update a memory alias's offset + * + * Dynamically updates the offset into the target region that an alias points + * to, as if the fourth argument to memory_region_init_alias() has changed. + * + * @mr: the #MemoryRegion to be updated; should be an alias. + * @offset: the new offset into the target memory region + */ +void memory_region_set_alias_offset(MemoryRegion *mr, + target_phys_addr_t offset); + /* Start a transaction; changes will be accumulated and made visible only * when the transaction ends. */ -- cgit 1.4.1