mirror of
https://git.h3cjp.net/H3cJP/citra.git
synced 2024-12-27 21:56:42 +00:00
core: device_memory: Templatize GetPointer(..).
This commit is contained in:
parent
cb073f95dc
commit
47b8160666
|
@ -31,12 +31,14 @@ public:
|
||||||
DramMemoryMap::Base;
|
DramMemoryMap::Base;
|
||||||
}
|
}
|
||||||
|
|
||||||
u8* GetPointer(PAddr addr) {
|
template <typename T>
|
||||||
return buffer.BackingBasePointer() + (addr - DramMemoryMap::Base);
|
T* GetPointer(PAddr addr) {
|
||||||
|
return reinterpret_cast<T*>(buffer.BackingBasePointer() + (addr - DramMemoryMap::Base));
|
||||||
}
|
}
|
||||||
|
|
||||||
const u8* GetPointer(PAddr addr) const {
|
template <typename T>
|
||||||
return buffer.BackingBasePointer() + (addr - DramMemoryMap::Base);
|
const T* GetPointer(PAddr addr) const {
|
||||||
|
return reinterpret_cast<T*>(buffer.BackingBasePointer() + (addr - DramMemoryMap::Base));
|
||||||
}
|
}
|
||||||
|
|
||||||
Common::HostMemory buffer;
|
Common::HostMemory buffer;
|
||||||
|
|
|
@ -94,8 +94,8 @@ VAddr InitializeSlabHeap(Core::System& system, KMemoryLayout& memory_layout, VAd
|
||||||
// TODO(bunnei): Fix this once we support the kernel virtual memory layout.
|
// TODO(bunnei): Fix this once we support the kernel virtual memory layout.
|
||||||
|
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
void* backing_kernel_memory{
|
void* backing_kernel_memory{system.DeviceMemory().GetPointer<void>(
|
||||||
system.DeviceMemory().GetPointer(TranslateSlabAddrToPhysical(memory_layout, start))};
|
TranslateSlabAddrToPhysical(memory_layout, start))};
|
||||||
|
|
||||||
const KMemoryRegion* region = memory_layout.FindVirtual(start + size - 1);
|
const KMemoryRegion* region = memory_layout.FindVirtual(start + size - 1);
|
||||||
ASSERT(region != nullptr);
|
ASSERT(region != nullptr);
|
||||||
|
@ -181,7 +181,7 @@ void InitializeKPageBufferSlabHeap(Core::System& system) {
|
||||||
ASSERT(slab_address != 0);
|
ASSERT(slab_address != 0);
|
||||||
|
|
||||||
// Initialize the slabheap.
|
// Initialize the slabheap.
|
||||||
KPageBuffer::InitializeSlabHeap(kernel, system.DeviceMemory().GetPointer(slab_address),
|
KPageBuffer::InitializeSlabHeap(kernel, system.DeviceMemory().GetPointer<void>(slab_address),
|
||||||
slab_size);
|
slab_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ Result KCodeMemory::Initialize(Core::DeviceMemory& device_memory, VAddr addr, si
|
||||||
|
|
||||||
// Clear the memory.
|
// Clear the memory.
|
||||||
for (const auto& block : m_page_group.Nodes()) {
|
for (const auto& block : m_page_group.Nodes()) {
|
||||||
std::memset(device_memory.GetPointer(block.GetAddress()), 0xFF, block.GetSize());
|
std::memset(device_memory.GetPointer<void>(block.GetAddress()), 0xFF, block.GetSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set remaining tracking members.
|
// Set remaining tracking members.
|
||||||
|
|
|
@ -331,7 +331,7 @@ Result KMemoryManager::AllocateAndOpenForProcess(KPageGroup* out, size_t num_pag
|
||||||
|
|
||||||
// Set all the allocated memory.
|
// Set all the allocated memory.
|
||||||
for (const auto& block : out->Nodes()) {
|
for (const auto& block : out->Nodes()) {
|
||||||
std::memset(system.DeviceMemory().GetPointer(block.GetAddress()), fill_pattern,
|
std::memset(system.DeviceMemory().GetPointer<void>(block.GetAddress()), fill_pattern,
|
||||||
block.GetSize());
|
block.GetSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ namespace Kernel {
|
||||||
|
|
||||||
KPageBuffer* KPageBuffer::FromPhysicalAddress(Core::System& system, PAddr phys_addr) {
|
KPageBuffer* KPageBuffer::FromPhysicalAddress(Core::System& system, PAddr phys_addr) {
|
||||||
ASSERT(Common::IsAligned(phys_addr, PageSize));
|
ASSERT(Common::IsAligned(phys_addr, PageSize));
|
||||||
return reinterpret_cast<KPageBuffer*>(system.DeviceMemory().GetPointer(phys_addr));
|
return system.DeviceMemory().GetPointer<KPageBuffer>(phys_addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Kernel
|
} // namespace Kernel
|
||||||
|
|
|
@ -1648,7 +1648,7 @@ Result KPageTable::SetHeapSize(VAddr* out, std::size_t size) {
|
||||||
|
|
||||||
// Clear all the newly allocated pages.
|
// Clear all the newly allocated pages.
|
||||||
for (const auto& it : pg.Nodes()) {
|
for (const auto& it : pg.Nodes()) {
|
||||||
std::memset(system.DeviceMemory().GetPointer(it.GetAddress()), heap_fill_value,
|
std::memset(system.DeviceMemory().GetPointer<void>(it.GetAddress()), heap_fill_value,
|
||||||
it.GetSize());
|
it.GetSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1805,9 +1805,9 @@ bool KPageTable::IsRegionMapped(VAddr address, u64 size) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KPageTable::IsRegionContiguous(VAddr addr, u64 size) const {
|
bool KPageTable::IsRegionContiguous(VAddr addr, u64 size) const {
|
||||||
auto start_ptr = system.Memory().GetPointer(addr);
|
auto start_ptr = system.DeviceMemory().GetPointer<u8>(addr);
|
||||||
for (u64 offset{}; offset < size; offset += PageSize) {
|
for (u64 offset{}; offset < size; offset += PageSize) {
|
||||||
if (start_ptr != system.Memory().GetPointer(addr + offset)) {
|
if (start_ptr != system.DeviceMemory().GetPointer<u8>(addr + offset)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
start_ptr += PageSize;
|
start_ptr += PageSize;
|
||||||
|
|
|
@ -50,7 +50,7 @@ Result KSharedMemory::Initialize(Core::DeviceMemory& device_memory_, KProcess* o
|
||||||
is_initialized = true;
|
is_initialized = true;
|
||||||
|
|
||||||
// Clear all pages in the memory.
|
// Clear all pages in the memory.
|
||||||
std::memset(device_memory_.GetPointer(physical_address_), 0, size_);
|
std::memset(device_memory_.GetPointer<void>(physical_address_), 0, size_);
|
||||||
|
|
||||||
return ResultSuccess;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@ public:
|
||||||
* @return A pointer to the shared memory block from the specified offset
|
* @return A pointer to the shared memory block from the specified offset
|
||||||
*/
|
*/
|
||||||
u8* GetPointer(std::size_t offset = 0) {
|
u8* GetPointer(std::size_t offset = 0) {
|
||||||
return device_memory->GetPointer(physical_address + offset);
|
return device_memory->GetPointer<u8>(physical_address + offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -63,7 +63,7 @@ public:
|
||||||
* @return A pointer to the shared memory block from the specified offset
|
* @return A pointer to the shared memory block from the specified offset
|
||||||
*/
|
*/
|
||||||
const u8* GetPointer(std::size_t offset = 0) const {
|
const u8* GetPointer(std::size_t offset = 0) const {
|
||||||
return device_memory->GetPointer(physical_address + offset);
|
return device_memory->GetPointer<u8>(physical_address + offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Finalize() override;
|
void Finalize() override;
|
||||||
|
|
|
@ -65,7 +65,7 @@ struct Memory::Impl {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
return system.DeviceMemory().GetPointer(paddr) + vaddr;
|
return system.DeviceMemory().GetPointer<u8>(paddr) + vaddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] u8* GetPointerFromDebugMemory(VAddr vaddr) const {
|
[[nodiscard]] u8* GetPointerFromDebugMemory(VAddr vaddr) const {
|
||||||
|
@ -75,7 +75,7 @@ struct Memory::Impl {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
return system.DeviceMemory().GetPointer(paddr) + vaddr;
|
return system.DeviceMemory().GetPointer<u8>(paddr) + vaddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
u8 Read8(const VAddr addr) {
|
u8 Read8(const VAddr addr) {
|
||||||
|
@ -499,7 +499,7 @@ struct Memory::Impl {
|
||||||
} else {
|
} else {
|
||||||
while (base != end) {
|
while (base != end) {
|
||||||
page_table.pointers[base].Store(
|
page_table.pointers[base].Store(
|
||||||
system.DeviceMemory().GetPointer(target) - (base << YUZU_PAGEBITS), type);
|
system.DeviceMemory().GetPointer<u8>(target) - (base << YUZU_PAGEBITS), type);
|
||||||
page_table.backing_addr[base] = target - (base << YUZU_PAGEBITS);
|
page_table.backing_addr[base] = target - (base << YUZU_PAGEBITS);
|
||||||
|
|
||||||
ASSERT_MSG(page_table.pointers[base].Pointer(),
|
ASSERT_MSG(page_table.pointers[base].Pointer(),
|
||||||
|
|
Loading…
Reference in a new issue