2018-02-07 21:54:35 -05:00
|
|
|
|
// Copyright 2018 yuzu emulator team
|
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <array>
|
|
|
|
|
#include <memory>
|
2018-10-30 00:03:25 -04:00
|
|
|
|
#include <optional>
|
2018-04-21 14:40:51 -04:00
|
|
|
|
#include <vector>
|
2018-04-21 12:31:30 -04:00
|
|
|
|
|
2018-02-07 21:54:35 -05:00
|
|
|
|
#include "common/common_types.h"
|
|
|
|
|
|
2018-02-11 23:44:12 -05:00
|
|
|
|
namespace Tegra {
|
|
|
|
|
|
|
|
|
|
/// Virtual addresses in the GPU's memory map are 64 bit.
|
|
|
|
|
using GPUVAddr = u64;
|
2018-02-07 21:54:35 -05:00
|
|
|
|
|
|
|
|
|
class MemoryManager final {
|
|
|
|
|
public:
|
2018-11-23 12:58:55 -05:00
|
|
|
|
MemoryManager();
|
2018-02-07 21:54:35 -05:00
|
|
|
|
|
2018-04-21 11:16:21 -04:00
|
|
|
|
GPUVAddr AllocateSpace(u64 size, u64 align);
|
|
|
|
|
GPUVAddr AllocateSpace(GPUVAddr gpu_addr, u64 size, u64 align);
|
|
|
|
|
GPUVAddr MapBufferEx(VAddr cpu_addr, u64 size);
|
|
|
|
|
GPUVAddr MapBufferEx(VAddr cpu_addr, GPUVAddr gpu_addr, u64 size);
|
2018-05-20 15:21:06 -04:00
|
|
|
|
GPUVAddr UnmapBuffer(GPUVAddr gpu_addr, u64 size);
|
2018-10-12 21:52:16 -04:00
|
|
|
|
GPUVAddr GetRegionEnd(GPUVAddr region_start) const;
|
2018-10-30 00:03:25 -04:00
|
|
|
|
std::optional<VAddr> GpuToCpuAddress(GPUVAddr gpu_addr);
|
2018-02-07 21:54:35 -05:00
|
|
|
|
|
2018-04-23 11:57:12 -04:00
|
|
|
|
static constexpr u64 PAGE_BITS = 16;
|
|
|
|
|
static constexpr u64 PAGE_SIZE = 1 << PAGE_BITS;
|
|
|
|
|
static constexpr u64 PAGE_MASK = PAGE_SIZE - 1;
|
|
|
|
|
|
2019-02-24 00:15:35 -05:00
|
|
|
|
u8 Read8(GPUVAddr addr);
|
|
|
|
|
u16 Read16(GPUVAddr addr);
|
|
|
|
|
u32 Read32(GPUVAddr addr);
|
|
|
|
|
u64 Read64(GPUVAddr addr);
|
|
|
|
|
|
|
|
|
|
void Write8(GPUVAddr addr, u8 data);
|
|
|
|
|
void Write16(GPUVAddr addr, u16 data);
|
|
|
|
|
void Write32(GPUVAddr addr, u32 data);
|
|
|
|
|
void Write64(GPUVAddr addr, u64 data);
|
|
|
|
|
|
|
|
|
|
u8* GetPointer(GPUVAddr vaddr);
|
|
|
|
|
|
|
|
|
|
void ReadBlock(GPUVAddr src_addr, void* dest_buffer, std::size_t size);
|
|
|
|
|
void WriteBlock(GPUVAddr dest_addr, const void* src_buffer, std::size_t size);
|
|
|
|
|
void CopyBlock(VAddr dest_addr, VAddr src_addr, std::size_t size);
|
|
|
|
|
|
2018-02-07 21:54:35 -05:00
|
|
|
|
private:
|
|
|
|
|
enum class PageStatus : u64 {
|
|
|
|
|
Unmapped = 0xFFFFFFFFFFFFFFFFULL,
|
|
|
|
|
Allocated = 0xFFFFFFFFFFFFFFFEULL,
|
2018-11-23 12:58:55 -05:00
|
|
|
|
Reserved = 0xFFFFFFFFFFFFFFFDULL,
|
2018-02-07 21:54:35 -05:00
|
|
|
|
};
|
|
|
|
|
|
2018-10-31 22:20:37 -04:00
|
|
|
|
std::optional<GPUVAddr> FindFreeBlock(GPUVAddr region_start, u64 size, u64 align,
|
|
|
|
|
PageStatus status);
|
|
|
|
|
VAddr& PageSlot(GPUVAddr gpu_addr);
|
|
|
|
|
|
2018-02-07 21:54:35 -05:00
|
|
|
|
static constexpr u64 MAX_ADDRESS{0x10000000000ULL};
|
2018-04-23 11:57:12 -04:00
|
|
|
|
static constexpr u64 PAGE_TABLE_BITS{10};
|
2018-02-07 21:54:35 -05:00
|
|
|
|
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<VAddr, PAGE_BLOCK_SIZE>;
|
|
|
|
|
std::array<std::unique_ptr<PageBlock>, PAGE_TABLE_SIZE> page_table{};
|
2018-04-21 14:40:51 -04:00
|
|
|
|
|
|
|
|
|
struct MappedRegion {
|
|
|
|
|
VAddr cpu_addr;
|
|
|
|
|
GPUVAddr gpu_addr;
|
|
|
|
|
u64 size;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
std::vector<MappedRegion> mapped_regions;
|
2018-02-07 21:54:35 -05:00
|
|
|
|
};
|
|
|
|
|
|
2018-02-11 23:44:12 -05:00
|
|
|
|
} // namespace Tegra
|