From a8292f6cd9f8b4088ee85b59a87e5bf0ce387cf0 Mon Sep 17 00:00:00 2001 From: bunnei Date: Wed, 8 Apr 2020 23:37:24 -0400 Subject: [PATCH] kernel: memory: page_table: Simplify GetPhysicalAddr impl. --- src/core/device_memory.cpp | 7 ------- src/core/device_memory.h | 10 +++------- src/core/hle/kernel/memory/page_table.cpp | 4 ---- src/core/hle/kernel/memory/page_table.h | 4 +++- 4 files changed, 6 insertions(+), 19 deletions(-) diff --git a/src/core/device_memory.cpp b/src/core/device_memory.cpp index 61429a6acf..51097ced35 100644 --- a/src/core/device_memory.cpp +++ b/src/core/device_memory.cpp @@ -12,11 +12,4 @@ DeviceMemory::DeviceMemory(System& system) : buffer{DramMemoryMap::Size}, system DeviceMemory::~DeviceMemory() = default; -PAddr DeviceMemory::GetPhysicalAddr(VAddr addr) { - const u8* const base{system.Memory().GetPointer(addr)}; - ASSERT(base); - const uintptr_t offset{static_cast(base - GetPointer(DramMemoryMap::Base))}; - return DramMemoryMap::Base + offset; -} - } // namespace Core diff --git a/src/core/device_memory.h b/src/core/device_memory.h index 44458c2b57..cc7bda0709 100644 --- a/src/core/device_memory.h +++ b/src/core/device_memory.h @@ -28,15 +28,11 @@ public: ~DeviceMemory(); template - PAddr GetPhysicalAddr(T* ptr) { - const auto ptr_addr{reinterpret_cast(ptr)}; - const auto base_addr{reinterpret_cast(buffer.data())}; - ASSERT(ptr_addr >= base_addr); - return ptr_addr - base_addr + DramMemoryMap::Base; + constexpr PAddr GetPhysicalAddr(T* ptr) { + return (reinterpret_cast(ptr) - reinterpret_cast(buffer.data())) + + DramMemoryMap::Base; } - PAddr GetPhysicalAddr(VAddr addr); - constexpr u8* GetPointer(PAddr addr) { return buffer.data() + (addr - DramMemoryMap::Base); } diff --git a/src/core/hle/kernel/memory/page_table.cpp b/src/core/hle/kernel/memory/page_table.cpp index 93e7253e2b..941ecda212 100644 --- a/src/core/hle/kernel/memory/page_table.cpp +++ b/src/core/hle/kernel/memory/page_table.cpp @@ -936,10 +936,6 @@ ResultVal PageTable::AllocateAndMapMemory(std::size_t needed_num_pages, s return MakeResult(addr); } -PAddr PageTable::GetPhysicalAddr(VAddr addr) { - return system.DeviceMemory().GetPhysicalAddr(addr); -} - ResultCode PageTable::InitializeMemoryLayout(VAddr start, VAddr end) { block_manager = std::make_unique(start, end); diff --git a/src/core/hle/kernel/memory/page_table.h b/src/core/hle/kernel/memory/page_table.h index 6c3a3c275a..80384ab0f8 100644 --- a/src/core/hle/kernel/memory/page_table.h +++ b/src/core/hle/kernel/memory/page_table.h @@ -53,7 +53,6 @@ public: bool is_map_only, VAddr region_start, std::size_t region_num_pages, MemoryState state, MemoryPermission perm, PAddr map_addr = 0); - PAddr GetPhysicalAddr(VAddr addr); Common::PageTable& PageTableImpl() { return page_table_impl; @@ -211,6 +210,9 @@ public: constexpr bool IsInsideASLRRegion(VAddr address, std::size_t size) const { return !IsOutsideASLRRegion(address, size); } + constexpr PAddr GetPhysicalAddr(VAddr addr) { + return page_table_impl.backing_addr[addr >> Memory::PageBits] + addr; + } private: constexpr bool Contains(VAddr addr) const {