From dc25c86556c36dd23224d88234afc9ecbf780719 Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 2 Apr 2020 22:00:41 -0400 Subject: core: device_manager: Add a simple class to manage device RAM. --- src/core/device_memory.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/core/device_memory.h (limited to 'src/core/device_memory.h') diff --git a/src/core/device_memory.h b/src/core/device_memory.h new file mode 100644 index 000000000..a60a7238a --- /dev/null +++ b/src/core/device_memory.h @@ -0,0 +1,48 @@ +// Copyright 2020 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include "common/assert.h" +#include "common/common_funcs.h" +#include "core/hle/kernel/physical_memory.h" + +namespace Core { + +class System; + +namespace DramMemoryMap { +constexpr u64 Base = 0x80000000ULL; +constexpr u64 Size = 0x100000000ULL; +constexpr u64 End = Base + Size; +constexpr u64 KernelReserveBase = Base + 0x60000; +constexpr u64 SlabHeapBase = KernelReserveBase + 0x85000; +constexpr u64 SlapHeapSize = 0xa21000; +constexpr u64 SlabHeapEnd = SlabHeapBase + SlapHeapSize; +}; // namespace DramMemoryMap + +class DeviceMemory : NonCopyable { +public: + DeviceMemory(Core::System& system); + ~DeviceMemory(); + + template + PAddr GetPhysicalAddr(T* ptr) { + const auto ptr_addr{reinterpret_cast(ptr)}; + const auto base_addr{reinterpret_cast(base)}; + ASSERT(ptr_addr >= base_addr); + return ptr_addr - base_addr + DramMemoryMap::Base; + } + + PAddr GetPhysicalAddr(VAddr addr); + + u8* GetPointer(PAddr addr); + +private: + u8* base{}; + Kernel::PhysicalMemory physical_memory; + Core::System& system; +}; + +} // namespace Core -- cgit v1.2.3 From a040a152468bbd315781c3d50bea484c07e2e02a Mon Sep 17 00:00:00 2001 From: bunnei Date: Wed, 8 Apr 2020 17:39:58 -0400 Subject: core: device_memory: Update to use VirtualBuffer class. --- src/core/device_memory.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/core/device_memory.h') diff --git a/src/core/device_memory.h b/src/core/device_memory.h index a60a7238a..44458c2b5 100644 --- a/src/core/device_memory.h +++ b/src/core/device_memory.h @@ -6,7 +6,7 @@ #include "common/assert.h" #include "common/common_funcs.h" -#include "core/hle/kernel/physical_memory.h" +#include "common/virtual_buffer.h" namespace Core { @@ -24,24 +24,25 @@ constexpr u64 SlabHeapEnd = SlabHeapBase + SlapHeapSize; class DeviceMemory : NonCopyable { public: - DeviceMemory(Core::System& system); + explicit DeviceMemory(Core::System& system); ~DeviceMemory(); template PAddr GetPhysicalAddr(T* ptr) { const auto ptr_addr{reinterpret_cast(ptr)}; - const auto base_addr{reinterpret_cast(base)}; + const auto base_addr{reinterpret_cast(buffer.data())}; ASSERT(ptr_addr >= base_addr); return ptr_addr - base_addr + DramMemoryMap::Base; } PAddr GetPhysicalAddr(VAddr addr); - u8* GetPointer(PAddr addr); + constexpr u8* GetPointer(PAddr addr) { + return buffer.data() + (addr - DramMemoryMap::Base); + } private: - u8* base{}; - Kernel::PhysicalMemory physical_memory; + Common::VirtualBuffer buffer; Core::System& system; }; -- cgit v1.2.3 From a8292f6cd9f8b4088ee85b59a87e5bf0ce387cf0 Mon Sep 17 00:00:00 2001 From: bunnei Date: Wed, 8 Apr 2020 23:37:24 -0400 Subject: kernel: memory: page_table: Simplify GetPhysicalAddr impl. --- src/core/device_memory.h | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'src/core/device_memory.h') diff --git a/src/core/device_memory.h b/src/core/device_memory.h index 44458c2b5..cc7bda070 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); } -- cgit v1.2.3 From 92caa003a8fabf177f012a4f59ac4e123cbb4e98 Mon Sep 17 00:00:00 2001 From: bunnei Date: Wed, 15 Apr 2020 23:06:29 -0400 Subject: core: device_memory: Remove incorrect usage of constexpr. --- src/core/device_memory.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/core/device_memory.h') diff --git a/src/core/device_memory.h b/src/core/device_memory.h index cc7bda070..ff66e202d 100644 --- a/src/core/device_memory.h +++ b/src/core/device_memory.h @@ -28,12 +28,16 @@ public: ~DeviceMemory(); template - constexpr PAddr GetPhysicalAddr(T* ptr) { + PAddr GetPhysicalAddr(const T* ptr) const { return (reinterpret_cast(ptr) - reinterpret_cast(buffer.data())) + DramMemoryMap::Base; } - constexpr u8* GetPointer(PAddr addr) { + u8* GetPointer(PAddr addr) { + return buffer.data() + (addr - DramMemoryMap::Base); + } + + const u8* GetPointer(PAddr addr) const { return buffer.data() + (addr - DramMemoryMap::Base); } -- cgit v1.2.3 From 8bbe74a8dc62cd3933fd08237e707b0059fe8a78 Mon Sep 17 00:00:00 2001 From: bunnei Date: Fri, 17 Apr 2020 00:59:08 -0400 Subject: core: hle: Address various feedback & code cleanup. - Should be no functional changes. --- src/core/device_memory.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src/core/device_memory.h') diff --git a/src/core/device_memory.h b/src/core/device_memory.h index ff66e202d..9efa088d0 100644 --- a/src/core/device_memory.h +++ b/src/core/device_memory.h @@ -13,13 +13,15 @@ namespace Core { class System; namespace DramMemoryMap { -constexpr u64 Base = 0x80000000ULL; -constexpr u64 Size = 0x100000000ULL; -constexpr u64 End = Base + Size; -constexpr u64 KernelReserveBase = Base + 0x60000; -constexpr u64 SlabHeapBase = KernelReserveBase + 0x85000; -constexpr u64 SlapHeapSize = 0xa21000; -constexpr u64 SlabHeapEnd = SlabHeapBase + SlapHeapSize; +enum : u64 { + Base = 0x80000000ULL, + Size = 0x100000000ULL, + End = Base + Size, + KernelReserveBase = Base + 0x60000, + SlabHeapBase = KernelReserveBase + 0x85000, + SlapHeapSize = 0xa21000, + SlabHeapEnd = SlabHeapBase + SlapHeapSize, +}; }; // namespace DramMemoryMap class DeviceMemory : NonCopyable { -- cgit v1.2.3