2022-04-23 09:59:50 +01:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2020-04-03 03:00:41 +01:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2020-01-19 00:49:30 +00:00
|
|
|
#include "common/host_memory.h"
|
2023-03-18 01:26:04 +00:00
|
|
|
#include "common/typed_address.h"
|
2020-04-03 03:00:41 +01:00
|
|
|
|
|
|
|
namespace Core {
|
|
|
|
|
|
|
|
namespace DramMemoryMap {
|
2020-04-17 05:59:08 +01:00
|
|
|
enum : u64 {
|
|
|
|
Base = 0x80000000ULL,
|
|
|
|
KernelReserveBase = Base + 0x60000,
|
|
|
|
SlabHeapBase = KernelReserveBase + 0x85000,
|
|
|
|
};
|
2020-04-03 03:00:41 +01:00
|
|
|
}; // namespace DramMemoryMap
|
|
|
|
|
2020-01-19 00:49:30 +00:00
|
|
|
class DeviceMemory {
|
2020-04-03 03:00:41 +01:00
|
|
|
public:
|
2020-07-28 04:36:08 +01:00
|
|
|
explicit DeviceMemory();
|
2020-04-03 03:00:41 +01:00
|
|
|
~DeviceMemory();
|
|
|
|
|
2020-01-19 00:49:30 +00:00
|
|
|
DeviceMemory& operator=(const DeviceMemory&) = delete;
|
|
|
|
DeviceMemory(const DeviceMemory&) = delete;
|
|
|
|
|
2020-04-03 03:00:41 +01:00
|
|
|
template <typename T>
|
2023-03-18 01:26:04 +00:00
|
|
|
Common::PhysicalAddress GetPhysicalAddr(const T* ptr) const {
|
2020-01-19 00:49:30 +00:00
|
|
|
return (reinterpret_cast<uintptr_t>(ptr) -
|
|
|
|
reinterpret_cast<uintptr_t>(buffer.BackingBasePointer())) +
|
2020-04-09 04:37:24 +01:00
|
|
|
DramMemoryMap::Base;
|
2020-04-03 03:00:41 +01:00
|
|
|
}
|
|
|
|
|
2022-09-06 01:42:24 +01:00
|
|
|
template <typename T>
|
2023-03-18 01:26:04 +00:00
|
|
|
T* GetPointer(Common::PhysicalAddress addr) {
|
|
|
|
return reinterpret_cast<T*>(buffer.BackingBasePointer() +
|
|
|
|
(GetInteger(addr) - DramMemoryMap::Base));
|
2020-04-16 04:06:29 +01:00
|
|
|
}
|
|
|
|
|
2022-09-06 01:42:24 +01:00
|
|
|
template <typename T>
|
2023-03-18 01:26:04 +00:00
|
|
|
const T* GetPointer(Common::PhysicalAddress addr) const {
|
|
|
|
return reinterpret_cast<T*>(buffer.BackingBasePointer() +
|
|
|
|
(GetInteger(addr) - DramMemoryMap::Base));
|
2020-04-08 22:39:58 +01:00
|
|
|
}
|
2020-04-03 03:00:41 +01:00
|
|
|
|
2020-01-19 00:49:30 +00:00
|
|
|
Common::HostMemory buffer;
|
2020-04-03 03:00:41 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Core
|