memctrlbase: Remove region by entry.

This commit is contained in:
joevt
2024-02-21 15:42:10 -08:00
committed by dingusdev
parent ab8abf39cc
commit 71990129f3
2 changed files with 31 additions and 0 deletions

View File

@@ -402,6 +402,36 @@ bool MemCtrlBase::remove_mmio_region(uint32_t start_addr, uint32_t size, MMIODev
return (found > 0);
}
AddressMapEntry* MemCtrlBase::remove_region(AddressMapEntry* entry)
{
int found = 0;
address_map.erase(std::remove_if(address_map.begin(), address_map.end(),
[entry, &found](const AddressMapEntry *cmp_entry) {
if (entry == cmp_entry) {
if (found)
LOG_F(ERROR, "Removed mem region %s", get_entry_str(entry).c_str());
else
LOG_F(INFO, "Removed mem region %s", get_entry_str(entry).c_str());
found++;
return true;
}
return false;
}
), address_map.end());
if (found == 0) {
LOG_F(ERROR, "Cannot find mem region %s to remove",
get_entry_str(entry).c_str()
);
return nullptr;
}
return entry;
}
AddressMapEntry* MemCtrlBase::find_rom_region()
{
for (auto& entry : address_map) {

View File

@@ -76,6 +76,7 @@ public:
MMIODevice* dev_instance);
virtual bool remove_mmio_region(uint32_t start_addr, uint32_t size,
MMIODevice* dev_instance);
virtual AddressMapEntry* remove_region(AddressMapEntry* entry);
virtual AddressMapEntry* set_data(uint32_t reg_addr, const uint8_t* data, uint32_t size);