kern: revamp KMemoryRegionType to better encode derivation hierarchies

This commit is contained in:
Michael Scire
2020-08-23 13:19:45 -07:00
committed by SciresM
parent d50c7c5c79
commit 1983f86875
17 changed files with 746 additions and 426 deletions

View File

@@ -405,7 +405,7 @@ namespace ams::kern::board::nintendo::nx {
void KDevicePageTable::Initialize() {
/* Set the memory controller register address. */
g_memory_controller_address = KMemoryLayout::GetMemoryControllerRegion().GetAddress();
g_memory_controller_address = KMemoryLayout::GetDevicePhysicalAddress(KMemoryRegionType_MemoryController);
/* Allocate a page to use as a reserved/no device table. */
const KVirtualAddress table_virt_addr = Kernel::GetPageTableManager().Allocate();

View File

@@ -181,7 +181,7 @@ namespace ams::kern::board::nintendo::nx {
/* Find the region for the address. */
const KMemoryRegion *region = KMemoryLayout::Find(KPhysicalAddress(address));
if (AMS_LIKELY(region != nullptr)) {
if (AMS_LIKELY(region->IsDerivedFrom(KMemoryRegionAttr_NoUserMap | KMemoryRegionType_MemoryController))) {
if (AMS_LIKELY(region->IsDerivedFrom(KMemoryRegionType_MemoryController))) {
/* Get the offset within the region. */
const size_t offset = address - region->GetAddress();
MESOSPHERE_ABORT_UNLESS(offset < region->GetSize());
@@ -206,9 +206,9 @@ namespace ams::kern::board::nintendo::nx {
}
/* Memory controller is allowed if the register is whitelisted. */
if (region->IsDerivedFrom(KMemoryRegionAttr_NoUserMap | KMemoryRegionType_MemoryController ) ||
region->IsDerivedFrom(KMemoryRegionAttr_NoUserMap | KMemoryRegionType_MemoryController0) ||
region->IsDerivedFrom(KMemoryRegionAttr_NoUserMap | KMemoryRegionType_MemoryController1))
if (region->IsDerivedFrom(KMemoryRegionType_MemoryController ) ||
region->IsDerivedFrom(KMemoryRegionType_MemoryController0) ||
region->IsDerivedFrom(KMemoryRegionType_MemoryController1))
{
/* Get the offset within the region. */
const size_t offset = address - region->GetAddress();