summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar bunnei2020-04-08 17:39:58 -0400
committerGravatar bunnei2020-04-17 00:59:31 -0400
commita040a152468bbd315781c3d50bea484c07e2e02a (patch)
tree2723c7160111f0328ce13aa09445c8badc02a3bb /src
parentcommon: Add VirtualBuffer class, to abstract memory virtualization. (diff)
downloadyuzu-a040a152468bbd315781c3d50bea484c07e2e02a.tar.gz
yuzu-a040a152468bbd315781c3d50bea484c07e2e02a.tar.xz
yuzu-a040a152468bbd315781c3d50bea484c07e2e02a.zip
core: device_memory: Update to use VirtualBuffer class.
Diffstat (limited to 'src')
-rw-r--r--src/core/device_memory.cpp38
-rw-r--r--src/core/device_memory.h13
2 files changed, 12 insertions, 39 deletions
diff --git a/src/core/device_memory.cpp b/src/core/device_memory.cpp
index 1e4187546..61429a6ac 100644
--- a/src/core/device_memory.cpp
+++ b/src/core/device_memory.cpp
@@ -2,49 +2,21 @@
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#ifdef _WIN32
6#include <windows.h>
7#endif
8
9#include "common/assert.h"
10#include "core/core.h" 5#include "core/core.h"
11#include "core/device_memory.h" 6#include "core/device_memory.h"
12#include "core/memory.h" 7#include "core/memory.h"
13 8
14namespace Core { 9namespace Core {
15 10
16constexpr u64 DramSize{4ULL * 1024 * 1024 * 1024}; 11DeviceMemory::DeviceMemory(System& system) : buffer{DramMemoryMap::Size}, system{system} {}
17
18DeviceMemory::DeviceMemory(System& system) : system{system} {
19#ifdef _WIN32
20 base = static_cast<u8*>(
21 VirtualAlloc(nullptr, // System selects address
22 DramSize, // Size of allocation
23 MEM_RESERVE | MEM_COMMIT | MEM_WRITE_WATCH, // Allocate reserved pages
24 PAGE_READWRITE)); // Protection = no access
25#else
26 physical_memory.resize(DramSize);
27 base = physical_memory.data();
28#endif
29}
30 12
31DeviceMemory::~DeviceMemory() { 13DeviceMemory::~DeviceMemory() = default;
32#ifdef _WIN32
33 ASSERT(VirtualFree(base, DramSize, MEM_RELEASE));
34#endif
35}
36 14
37PAddr DeviceMemory::GetPhysicalAddr(VAddr addr) { 15PAddr DeviceMemory::GetPhysicalAddr(VAddr addr) {
38 u8* pointer{system.Memory().GetPointer(addr)}; 16 const u8* const base{system.Memory().GetPointer(addr)};
39 ASSERT(pointer); 17 ASSERT(base);
40 const uintptr_t offset{static_cast<uintptr_t>(pointer - GetPointer(DramMemoryMap::Base))}; 18 const uintptr_t offset{static_cast<uintptr_t>(base - GetPointer(DramMemoryMap::Base))};
41 return DramMemoryMap::Base + offset; 19 return DramMemoryMap::Base + offset;
42} 20}
43 21
44u8* DeviceMemory::GetPointer(PAddr addr) {
45 ASSERT(addr >= DramMemoryMap::Base);
46 ASSERT(addr < DramMemoryMap::Base + DramSize);
47 return base + (addr - DramMemoryMap::Base);
48}
49
50} // namespace Core 22} // namespace Core
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 @@
6 6
7#include "common/assert.h" 7#include "common/assert.h"
8#include "common/common_funcs.h" 8#include "common/common_funcs.h"
9#include "core/hle/kernel/physical_memory.h" 9#include "common/virtual_buffer.h"
10 10
11namespace Core { 11namespace Core {
12 12
@@ -24,24 +24,25 @@ constexpr u64 SlabHeapEnd = SlabHeapBase + SlapHeapSize;
24 24
25class DeviceMemory : NonCopyable { 25class DeviceMemory : NonCopyable {
26public: 26public:
27 DeviceMemory(Core::System& system); 27 explicit DeviceMemory(Core::System& system);
28 ~DeviceMemory(); 28 ~DeviceMemory();
29 29
30 template <typename T> 30 template <typename T>
31 PAddr GetPhysicalAddr(T* ptr) { 31 PAddr GetPhysicalAddr(T* ptr) {
32 const auto ptr_addr{reinterpret_cast<uintptr_t>(ptr)}; 32 const auto ptr_addr{reinterpret_cast<uintptr_t>(ptr)};
33 const auto base_addr{reinterpret_cast<uintptr_t>(base)}; 33 const auto base_addr{reinterpret_cast<uintptr_t>(buffer.data())};
34 ASSERT(ptr_addr >= base_addr); 34 ASSERT(ptr_addr >= base_addr);
35 return ptr_addr - base_addr + DramMemoryMap::Base; 35 return ptr_addr - base_addr + DramMemoryMap::Base;
36 } 36 }
37 37
38 PAddr GetPhysicalAddr(VAddr addr); 38 PAddr GetPhysicalAddr(VAddr addr);
39 39
40 u8* GetPointer(PAddr addr); 40 constexpr u8* GetPointer(PAddr addr) {
41 return buffer.data() + (addr - DramMemoryMap::Base);
42 }
41 43
42private: 44private:
43 u8* base{}; 45 Common::VirtualBuffer<u8> buffer;
44 Kernel::PhysicalMemory physical_memory;
45 Core::System& system; 46 Core::System& system;
46}; 47};
47 48