From e0da8da6574be1575864f38b3cd8670a3cb8326e Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 5 Apr 2022 12:37:11 +0200 Subject: Kernel: Move create_identity_mapped_region() to MemoryManager This had no business being in RegionTree, since RegionTree doesn't track identity-mapped regions anyway. (We allow *any* address to be identity mapped, not just the ones that are part of the RegionTree's range.) --- Kernel/Interrupts/APIC.cpp | 2 +- Kernel/Memory/MemoryManager.cpp | 10 ++++++++++ Kernel/Memory/MemoryManager.h | 1 + Kernel/Memory/RegionTree.cpp | 10 ---------- Kernel/Memory/RegionTree.h | 2 -- 5 files changed, 12 insertions(+), 13 deletions(-) diff --git a/Kernel/Interrupts/APIC.cpp b/Kernel/Interrupts/APIC.cpp index 2e52550536..f66e9bf811 100644 --- a/Kernel/Interrupts/APIC.cpp +++ b/Kernel/Interrupts/APIC.cpp @@ -332,7 +332,7 @@ UNMAP_AFTER_INIT void APIC::setup_ap_boot_environment() constexpr u64 apic_startup_region_base = 0x8000; auto apic_startup_region_size = Memory::page_round_up(apic_ap_start_size + (2 * aps_to_enable * sizeof(FlatPtr))).release_value_but_fixme_should_propagate_errors(); VERIFY(apic_startup_region_size < USER_RANGE_BASE); - auto apic_startup_region = MUST(MM.region_tree().create_identity_mapped_region(PhysicalAddress(apic_startup_region_base), apic_startup_region_size)); + auto apic_startup_region = MUST(MM.create_identity_mapped_region(PhysicalAddress(apic_startup_region_base), apic_startup_region_size)); u8* apic_startup_region_ptr = apic_startup_region->vaddr().as_ptr(); memcpy(apic_startup_region_ptr, reinterpret_cast(apic_ap_start), apic_ap_start_size); diff --git a/Kernel/Memory/MemoryManager.cpp b/Kernel/Memory/MemoryManager.cpp index 2934655b75..627bce7cb0 100644 --- a/Kernel/Memory/MemoryManager.cpp +++ b/Kernel/Memory/MemoryManager.cpp @@ -1232,4 +1232,14 @@ void MemoryManager::copy_physical_page(PhysicalPage& physical_page, u8 page_buff unquickmap_page(); } +ErrorOr> MemoryManager::create_identity_mapped_region(PhysicalAddress address, size_t size) +{ + auto vmobject = TRY(Memory::AnonymousVMObject::try_create_for_physical_range(address, size)); + auto region = TRY(Memory::Region::create_unplaced(move(vmobject), 0, {}, Memory::Region::Access::ReadWriteExecute)); + Memory::VirtualRange range { VirtualAddress { (FlatPtr)address.get() }, size }; + region->m_range = range; + TRY(region->map(MM.kernel_page_directory())); + return region; +} + } diff --git a/Kernel/Memory/MemoryManager.h b/Kernel/Memory/MemoryManager.h index f7b63b658e..4f8d1fc357 100644 --- a/Kernel/Memory/MemoryManager.h +++ b/Kernel/Memory/MemoryManager.h @@ -188,6 +188,7 @@ public: ErrorOr> allocate_kernel_region(size_t, StringView name, Region::Access access, AllocationStrategy strategy = AllocationStrategy::Reserve, Region::Cacheable = Region::Cacheable::Yes); ErrorOr> allocate_kernel_region(PhysicalAddress, size_t, StringView name, Region::Access access, Region::Cacheable = Region::Cacheable::Yes); ErrorOr> allocate_kernel_region_with_vmobject(VMObject&, size_t, StringView name, Region::Access access, Region::Cacheable = Region::Cacheable::Yes); + ErrorOr> create_identity_mapped_region(PhysicalAddress, size_t); struct SystemMemoryInfo { PhysicalSize user_physical_pages { 0 }; diff --git a/Kernel/Memory/RegionTree.cpp b/Kernel/Memory/RegionTree.cpp index 5736a56aa1..f512a25677 100644 --- a/Kernel/Memory/RegionTree.cpp +++ b/Kernel/Memory/RegionTree.cpp @@ -154,16 +154,6 @@ ErrorOr RegionTree::place_specifically(Region& region, VirtualRange const& return {}; } -ErrorOr> RegionTree::create_identity_mapped_region(PhysicalAddress paddr, size_t size) -{ - auto vmobject = TRY(Memory::AnonymousVMObject::try_create_for_physical_range(paddr, size)); - auto region = TRY(Memory::Region::create_unplaced(move(vmobject), 0, {}, Memory::Region::Access::ReadWriteExecute)); - Memory::VirtualRange range { VirtualAddress { (FlatPtr)paddr.get() }, size }; - region->m_range = range; - TRY(region->map(MM.kernel_page_directory())); - return region; -} - bool RegionTree::remove(Region& region) { SpinlockLocker locker(m_lock); diff --git a/Kernel/Memory/RegionTree.h b/Kernel/Memory/RegionTree.h index 339fc6fd3c..50623ee02f 100644 --- a/Kernel/Memory/RegionTree.h +++ b/Kernel/Memory/RegionTree.h @@ -45,8 +45,6 @@ public: ErrorOr place_anywhere(Region&, RandomizeVirtualAddress, size_t size, size_t alignment = PAGE_SIZE); ErrorOr place_specifically(Region&, VirtualRange const&); - ErrorOr> create_identity_mapped_region(PhysicalAddress, size_t); - void delete_all_regions_assuming_they_are_unmapped(); // FIXME: Access the region tree through a SpinlockProtected or similar. -- cgit v1.2.3