From c711253798b32c4ef73cf38749ea5cf17a352daa Mon Sep 17 00:00:00 2001 From: bunnei Date: Wed, 7 Feb 2018 21:54:35 -0500 Subject: nvdrv: Add MemoryManager class to track GPU memory. --- src/core/hle/service/nvdrv/memory_manager.h | 48 +++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/core/hle/service/nvdrv/memory_manager.h (limited to 'src/core/hle/service/nvdrv/memory_manager.h') diff --git a/src/core/hle/service/nvdrv/memory_manager.h b/src/core/hle/service/nvdrv/memory_manager.h new file mode 100644 index 000000000..4ba1a3952 --- /dev/null +++ b/src/core/hle/service/nvdrv/memory_manager.h @@ -0,0 +1,48 @@ +// Copyright 2018 yuzu emulator team +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include +#include +#include "common/common_types.h" +#include "core/memory.h" + +namespace Service { +namespace Nvidia { + +class MemoryManager final { +public: + MemoryManager() = default; + + PAddr AllocateSpace(u64 size, u64 align); + PAddr AllocateSpace(PAddr paddr, u64 size, u64 align); + PAddr MapBufferEx(VAddr vaddr, u64 size); + PAddr MapBufferEx(VAddr vaddr, PAddr paddr, u64 size); + VAddr PhysicalToVirtualAddress(PAddr paddr); + +private: + boost::optional FindFreeBlock(u64 size, u64 align = 1); + bool IsPageMapped(PAddr paddr); + VAddr& PageSlot(PAddr paddr); + + enum class PageStatus : u64 { + Unmapped = 0xFFFFFFFFFFFFFFFFULL, + Allocated = 0xFFFFFFFFFFFFFFFEULL, + }; + + static constexpr u64 MAX_ADDRESS{0x10000000000ULL}; + static constexpr u64 PAGE_TABLE_BITS{14}; + static constexpr u64 PAGE_TABLE_SIZE{1 << PAGE_TABLE_BITS}; + static constexpr u64 PAGE_TABLE_MASK{PAGE_TABLE_SIZE - 1}; + static constexpr u64 PAGE_BLOCK_BITS{14}; + static constexpr u64 PAGE_BLOCK_SIZE{1 << PAGE_BLOCK_BITS}; + static constexpr u64 PAGE_BLOCK_MASK{PAGE_BLOCK_SIZE - 1}; + + using PageBlock = std::array; + std::array, PAGE_TABLE_SIZE> page_table{}; +}; + +} // namespace Nvidia +} // namespace Service -- cgit v1.2.3