diff options
author | Andreas Kling <kling@serenityos.org> | 2022-04-05 12:37:11 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-04-05 13:45:10 +0200 |
commit | e0da8da6574be1575864f38b3cd8670a3cb8326e (patch) | |
tree | 7a4b548da0cb79dbf505add18bc8aa160814c848 | |
parent | 3dbb4bc3a617e3ca421a35c6196ad5902bb357d1 (diff) | |
download | serenity-e0da8da6574be1575864f38b3cd8670a3cb8326e.zip |
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.)
-rw-r--r-- | Kernel/Interrupts/APIC.cpp | 2 | ||||
-rw-r--r-- | Kernel/Memory/MemoryManager.cpp | 10 | ||||
-rw-r--r-- | Kernel/Memory/MemoryManager.h | 1 | ||||
-rw-r--r-- | Kernel/Memory/RegionTree.cpp | 10 | ||||
-rw-r--r-- | 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<void const*>(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<NonnullOwnPtr<Memory::Region>> 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<NonnullOwnPtr<Region>> allocate_kernel_region(size_t, StringView name, Region::Access access, AllocationStrategy strategy = AllocationStrategy::Reserve, Region::Cacheable = Region::Cacheable::Yes); ErrorOr<NonnullOwnPtr<Region>> allocate_kernel_region(PhysicalAddress, size_t, StringView name, Region::Access access, Region::Cacheable = Region::Cacheable::Yes); ErrorOr<NonnullOwnPtr<Region>> allocate_kernel_region_with_vmobject(VMObject&, size_t, StringView name, Region::Access access, Region::Cacheable = Region::Cacheable::Yes); + ErrorOr<NonnullOwnPtr<Region>> 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<void> RegionTree::place_specifically(Region& region, VirtualRange const& return {}; } -ErrorOr<NonnullOwnPtr<Memory::Region>> 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<void> place_anywhere(Region&, RandomizeVirtualAddress, size_t size, size_t alignment = PAGE_SIZE); ErrorOr<void> place_specifically(Region&, VirtualRange const&); - ErrorOr<NonnullOwnPtr<Memory::Region>> 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. |