mirror of
https://github.com/yuzu-emu/yuzu-mainline.git
synced 2024-12-12 22:34:33 +01:00
kernel: memory: page_table: Simplify GetPhysicalAddr impl.
This commit is contained in:
parent
c629e544a7
commit
a8292f6cd9
@ -12,11 +12,4 @@ DeviceMemory::DeviceMemory(System& system) : buffer{DramMemoryMap::Size}, system
|
|||||||
|
|
||||||
DeviceMemory::~DeviceMemory() = default;
|
DeviceMemory::~DeviceMemory() = default;
|
||||||
|
|
||||||
PAddr DeviceMemory::GetPhysicalAddr(VAddr addr) {
|
|
||||||
const u8* const base{system.Memory().GetPointer(addr)};
|
|
||||||
ASSERT(base);
|
|
||||||
const uintptr_t offset{static_cast<uintptr_t>(base - GetPointer(DramMemoryMap::Base))};
|
|
||||||
return DramMemoryMap::Base + offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Core
|
} // namespace Core
|
||||||
|
@ -28,15 +28,11 @@ public:
|
|||||||
~DeviceMemory();
|
~DeviceMemory();
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
PAddr GetPhysicalAddr(T* ptr) {
|
constexpr PAddr GetPhysicalAddr(T* ptr) {
|
||||||
const auto ptr_addr{reinterpret_cast<uintptr_t>(ptr)};
|
return (reinterpret_cast<uintptr_t>(ptr) - reinterpret_cast<uintptr_t>(buffer.data())) +
|
||||||
const auto base_addr{reinterpret_cast<uintptr_t>(buffer.data())};
|
DramMemoryMap::Base;
|
||||||
ASSERT(ptr_addr >= base_addr);
|
|
||||||
return ptr_addr - base_addr + DramMemoryMap::Base;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PAddr GetPhysicalAddr(VAddr addr);
|
|
||||||
|
|
||||||
constexpr u8* GetPointer(PAddr addr) {
|
constexpr u8* GetPointer(PAddr addr) {
|
||||||
return buffer.data() + (addr - DramMemoryMap::Base);
|
return buffer.data() + (addr - DramMemoryMap::Base);
|
||||||
}
|
}
|
||||||
|
@ -936,10 +936,6 @@ ResultVal<VAddr> PageTable::AllocateAndMapMemory(std::size_t needed_num_pages, s
|
|||||||
return MakeResult<VAddr>(addr);
|
return MakeResult<VAddr>(addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
PAddr PageTable::GetPhysicalAddr(VAddr addr) {
|
|
||||||
return system.DeviceMemory().GetPhysicalAddr(addr);
|
|
||||||
}
|
|
||||||
|
|
||||||
ResultCode PageTable::InitializeMemoryLayout(VAddr start, VAddr end) {
|
ResultCode PageTable::InitializeMemoryLayout(VAddr start, VAddr end) {
|
||||||
block_manager = std::make_unique<MemoryBlockManager>(start, end);
|
block_manager = std::make_unique<MemoryBlockManager>(start, end);
|
||||||
|
|
||||||
|
@ -53,7 +53,6 @@ public:
|
|||||||
bool is_map_only, VAddr region_start,
|
bool is_map_only, VAddr region_start,
|
||||||
std::size_t region_num_pages, MemoryState state,
|
std::size_t region_num_pages, MemoryState state,
|
||||||
MemoryPermission perm, PAddr map_addr = 0);
|
MemoryPermission perm, PAddr map_addr = 0);
|
||||||
PAddr GetPhysicalAddr(VAddr addr);
|
|
||||||
|
|
||||||
Common::PageTable& PageTableImpl() {
|
Common::PageTable& PageTableImpl() {
|
||||||
return page_table_impl;
|
return page_table_impl;
|
||||||
@ -211,6 +210,9 @@ public:
|
|||||||
constexpr bool IsInsideASLRRegion(VAddr address, std::size_t size) const {
|
constexpr bool IsInsideASLRRegion(VAddr address, std::size_t size) const {
|
||||||
return !IsOutsideASLRRegion(address, size);
|
return !IsOutsideASLRRegion(address, size);
|
||||||
}
|
}
|
||||||
|
constexpr PAddr GetPhysicalAddr(VAddr addr) {
|
||||||
|
return page_table_impl.backing_addr[addr >> Memory::PageBits] + addr;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
constexpr bool Contains(VAddr addr) const {
|
constexpr bool Contains(VAddr addr) const {
|
||||||
|
Loading…
Reference in New Issue
Block a user