summaryrefslogtreecommitdiffstats
path: root/src/core/device_memory_manager.h
diff options
context:
space:
mode:
authorFernando Sahmkow <fsahmkow27@gmail.com>2023-12-24 21:49:54 +0100
committerLiam <byteslice@airmail.cc>2024-01-19 03:12:30 +0100
commitc85d7ccd79fb69bc096cd19bb8f95ac9534ffc23 (patch)
tree7634acb7cfbee7829f958ad6ba03028c13a4ffec /src/core/device_memory_manager.h
parentNVDRV: Implement sessions and initial implementation of SMMU (diff)
downloadyuzu-c85d7ccd79fb69bc096cd19bb8f95ac9534ffc23.tar
yuzu-c85d7ccd79fb69bc096cd19bb8f95ac9534ffc23.tar.gz
yuzu-c85d7ccd79fb69bc096cd19bb8f95ac9534ffc23.tar.bz2
yuzu-c85d7ccd79fb69bc096cd19bb8f95ac9534ffc23.tar.lz
yuzu-c85d7ccd79fb69bc096cd19bb8f95ac9534ffc23.tar.xz
yuzu-c85d7ccd79fb69bc096cd19bb8f95ac9534ffc23.tar.zst
yuzu-c85d7ccd79fb69bc096cd19bb8f95ac9534ffc23.zip
Diffstat (limited to 'src/core/device_memory_manager.h')
-rw-r--r--src/core/device_memory_manager.h51
1 files changed, 50 insertions, 1 deletions
diff --git a/src/core/device_memory_manager.h b/src/core/device_memory_manager.h
index 0861b792d..71b95016c 100644
--- a/src/core/device_memory_manager.h
+++ b/src/core/device_memory_manager.h
@@ -5,6 +5,8 @@
#include <deque>
#include <memory>
+#include <array>
+#include <atomic>
#include "common/common_types.h"
#include "common/virtual_buffer.h"
@@ -23,6 +25,7 @@ struct DeviceMemoryManagerAllocator;
template <typename Traits>
class DeviceMemoryManager {
using DeviceInterface = typename Traits::DeviceInterface;
+ using DeviceMethods = Traits::DeviceMethods;
public:
DeviceMemoryManager(const DeviceMemory& device_memory);
@@ -35,7 +38,7 @@ public:
DAddr AllocatePinned(size_t size);
void Free(DAddr start, size_t size);
- void Map(DAddr address, VAddr virtual_address, size_t size, size_t p_id);
+ void Map(DAddr address, VAddr virtual_address, size_t size, size_t process_id);
void Unmap(DAddr address, size_t size);
// Write / Read
@@ -57,6 +60,8 @@ public:
size_t RegisterProcess(Memory::Memory* memory);
void UnregisterProcess(size_t id);
+ void UpdatePagesCachedCount(DAddr addr, size_t size, s32 delta);
+
private:
static constexpr bool supports_pinning = Traits::supports_pinning;
static constexpr size_t device_virtual_bits = Traits::device_virtual_bits;
@@ -90,8 +95,52 @@ private:
Common::VirtualBuffer<u32> compressed_physical_ptr;
Common::VirtualBuffer<u32> compressed_device_addr;
+ // Process memory interfaces
+
std::deque<size_t> id_pool;
std::deque<Memory::Memory*> registered_processes;
+
+ // Memory protection management
+
+ static constexpr size_t guest_max_as_bits = 39;
+ static constexpr size_t guest_as_size = 1ULL << guest_max_as_bits;
+ static constexpr size_t guest_mask = guest_as_size - 1ULL;
+ static constexpr size_t process_id_start_bit = guest_max_as_bits;
+
+ std::pair<size_t, VAddr> ExtractCPUBacking(size_t page_index) {
+ auto content = cpu_backing_address[page_index];
+ const VAddr address = content & guest_mask;
+ const size_t process_id = static_cast<size_t>(content >> process_id_start_bit);
+ return std::make_pair(process_id, address);
+ }
+
+ void InsertCPUBacking(size_t page_index, VAddr address, size_t process_id) {
+ cpu_backing_address[page_index] = address | (process_id << page_index);
+ }
+
+ Common::VirtualBuffer<VAddr> cpu_backing_address;
+ static constexpr size_t subentries = 4;
+ static constexpr size_t subentries_mask = subentries - 1;
+ class CounterEntry final {
+ public:
+ CounterEntry() = default;
+
+ std::atomic_uint16_t& Count(std::size_t page) {
+ return values[page & subentries_mask];
+ }
+
+ const std::atomic_uint16_t& Count(std::size_t page) const {
+ return values[page & subentries_mask];
+ }
+
+ private:
+ std::array<std::atomic_uint16_t, subentries> values{};
+ };
+ static_assert(sizeof(CounterEntry) == subentries * sizeof(u16), "CounterEntry should be 8 bytes!");
+
+ static constexpr size_t num_counter_entries = (1ULL << (device_virtual_bits - page_bits)) / subentries;
+ using CachedPages = std::array<CounterEntry, num_counter_entries>;
+ std::unique_ptr<CachedPages> cached_pages;
};
} // namespace Core \ No newline at end of file