summaryrefslogtreecommitdiffstats
path: root/src/core/hle/kernel/memory/memory_manager.h
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2020-04-05 21:28:31 +0200
committerbunnei <bunneidev@gmail.com>2020-04-17 06:59:30 +0200
commit5d6e8a5b44acf0fb2d78ef718116ccf007bd161b (patch)
tree2b42e7051956e2cdc7ad919cada6d1f3ac9dba5d /src/core/hle/kernel/memory/memory_manager.h
parentkernel: memory: Add MemoryBlockManager class, to manage memory blocks. (diff)
downloadyuzu-5d6e8a5b44acf0fb2d78ef718116ccf007bd161b.tar
yuzu-5d6e8a5b44acf0fb2d78ef718116ccf007bd161b.tar.gz
yuzu-5d6e8a5b44acf0fb2d78ef718116ccf007bd161b.tar.bz2
yuzu-5d6e8a5b44acf0fb2d78ef718116ccf007bd161b.tar.lz
yuzu-5d6e8a5b44acf0fb2d78ef718116ccf007bd161b.tar.xz
yuzu-5d6e8a5b44acf0fb2d78ef718116ccf007bd161b.tar.zst
yuzu-5d6e8a5b44acf0fb2d78ef718116ccf007bd161b.zip
Diffstat (limited to 'src/core/hle/kernel/memory/memory_manager.h')
-rw-r--r--src/core/hle/kernel/memory/memory_manager.h97
1 files changed, 97 insertions, 0 deletions
diff --git a/src/core/hle/kernel/memory/memory_manager.h b/src/core/hle/kernel/memory/memory_manager.h
new file mode 100644
index 000000000..b078d7a5e
--- /dev/null
+++ b/src/core/hle/kernel/memory/memory_manager.h
@@ -0,0 +1,97 @@
+// Copyright 2020 yuzu Emulator Project
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include <array>
+#include <mutex>
+
+#include "common/common_funcs.h"
+#include "common/common_types.h"
+#include "core/hle/kernel/memory/page_heap.h"
+#include "core/hle/result.h"
+
+namespace Kernel::Memory {
+
+class PageLinkedList;
+
+class MemoryManager final : NonCopyable {
+public:
+ enum class Pool : u32 {
+ Application = 0,
+ Applet = 1,
+ System = 2,
+ SystemNonSecure = 3,
+
+ Count,
+
+ Shift = 4,
+ Mask = (0xF << Shift),
+ };
+
+ enum class Direction : u32 {
+ FromFront = 0,
+ FromBack = 1,
+
+ Shift = 0,
+ Mask = (0xF << Shift),
+ };
+
+ MemoryManager() = default;
+
+ constexpr std::size_t GetSize(Pool pool) const {
+ return managers[static_cast<std::size_t>(pool)].GetSize();
+ }
+
+ void InitializeManager(Pool pool, u64 start_address, u64 end_address);
+ VAddr AllocateContinuous(std::size_t num_pages, std::size_t align_pages, Pool pool,
+ Direction dir = Direction::FromFront);
+ ResultCode Allocate(PageLinkedList& page_list, std::size_t num_pages, Pool pool,
+ Direction dir = Direction::FromFront);
+ ResultCode Free(PageLinkedList& page_list, std::size_t num_pages, Pool pool,
+ Direction dir = Direction::FromFront);
+
+ static constexpr std::size_t MaxManagerCount = 10;
+
+private:
+ class Impl final : NonCopyable {
+ private:
+ using RefCount = u16;
+
+ private:
+ PageHeap heap;
+ Pool pool{};
+
+ public:
+ Impl() = default;
+
+ std::size_t Initialize(Pool new_pool, u64 start_address, u64 end_address);
+
+ VAddr AllocateBlock(s32 index) {
+ return heap.AllocateBlock(index);
+ }
+
+ void Free(VAddr addr, std::size_t num_pages) {
+ heap.Free(addr, num_pages);
+ }
+
+ constexpr std::size_t GetSize() const {
+ return heap.GetSize();
+ }
+
+ constexpr VAddr GetAddress() const {
+ return heap.GetAddress();
+ }
+
+ constexpr VAddr GetEndAddress() const {
+ return heap.GetEndAddress();
+ }
+ };
+
+private:
+ std::array<std::mutex, static_cast<std::size_t>(Pool::Count)> pool_locks;
+ std::array<Impl, MaxManagerCount> managers;
+};
+
+} // namespace Kernel::Memory