From ae131502c6f1128c5d9f1941614e70cec48cfdf3 Mon Sep 17 00:00:00 2001 From: Billy Laws Date: Sun, 9 Aug 2020 16:01:38 +0100 Subject: [PATCH] Fix reservation in GPU VMM Rather than reserving a region so it *can* be used by MapAllocate reserved actually prevents a region from being used by MapAllocate. --- app/src/main/cpp/skyline/gpu/memory_manager.cpp | 14 +++++++------- app/src/main/cpp/skyline/gpu/memory_manager.h | 12 ++++++------ .../services/nvdrv/devices/nvhost_as_gpu.cpp | 6 +++--- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/app/src/main/cpp/skyline/gpu/memory_manager.cpp b/app/src/main/cpp/skyline/gpu/memory_manager.cpp index bfe663d6..0f0078f7 100644 --- a/app/src/main/cpp/skyline/gpu/memory_manager.cpp +++ b/app/src/main/cpp/skyline/gpu/memory_manager.cpp @@ -83,7 +83,7 @@ namespace skyline::gpu::vmm { throw exception("Failed to insert chunk into GPU address space!"); } - u64 MemoryManager::AllocateSpace(u64 size) { + u64 MemoryManager::ReserveSpace(u64 size) { size = util::AlignUp(size, constant::GpuPageSize); auto newChunk = FindChunk(size, ChunkState::Unmapped); if (!newChunk) @@ -91,23 +91,23 @@ namespace skyline::gpu::vmm { auto chunk = *newChunk; chunk.size = size; - chunk.state = ChunkState::Allocated; + chunk.state = ChunkState::Reserved; return InsertChunk(chunk); } - u64 MemoryManager::AllocateFixed(u64 address, u64 size) { + u64 MemoryManager::ReserveFixed(u64 address, u64 size) { if ((address & (constant::GpuPageSize - 1)) != 0) return 0; size = util::AlignUp(size, constant::GpuPageSize); - return InsertChunk(ChunkDescriptor(address, size, 0, ChunkState::Allocated)); + return InsertChunk(ChunkDescriptor(address, size, 0, ChunkState::Reserved)); } - u64 MemoryManager::MapAllocated(u64 address, u64 size) { + u64 MemoryManager::MapAllocate(u64 address, u64 size) { size = util::AlignUp(size, constant::GpuPageSize); - auto mappedChunk = FindChunk(size, ChunkState::Allocated); + auto mappedChunk = FindChunk(size, ChunkState::Unmapped); if (!mappedChunk) return 0; @@ -139,7 +139,7 @@ namespace skyline::gpu::vmm { if (chunk == chunkList.end()) return false; - chunk->state = ChunkState::Allocated; + chunk->state = ChunkState::Reserved; chunk->cpuAddress = 0; return true; diff --git a/app/src/main/cpp/skyline/gpu/memory_manager.h b/app/src/main/cpp/skyline/gpu/memory_manager.h index 270b8f98..ca97ee48 100644 --- a/app/src/main/cpp/skyline/gpu/memory_manager.h +++ b/app/src/main/cpp/skyline/gpu/memory_manager.h @@ -17,7 +17,7 @@ namespace skyline { */ enum ChunkState { Unmapped, //!< The chunk is unmapped - Allocated, //!< The chunk is allocated but unmapped + Reserved, //!< The chunk is reserved Mapped //!< The chunk is mapped and a CPU side address is present }; @@ -68,19 +68,19 @@ namespace skyline { MemoryManager(const DeviceState &state); /** - * @brief This reserves a region of the GPU address space so it can be automatically used when mapping + * @brief This reserves a region of the GPU address space so it will not be chosen automatically when mapping * @param size The size of the region to reserve * @return The virtual GPU base address of the region base */ - u64 AllocateSpace(u64 size); + u64 ReserveSpace(u64 size); /** - * @brief This reserves a fixed region of the GPU address space so it can be automatically used when mapping + * @brief This reserves a fixed region of the GPU address space so it will not be chosen automatically when mapping * @param address The virtual base address of the region to allocate * @param size The size of the region to allocate * @return The virtual address of the region base */ - u64 AllocateFixed(u64 address, u64 size); + u64 ReserveFixed(u64 address, u64 size); /** * @brief This maps a physical CPU memory region to an automatically chosen virtual memory region @@ -88,7 +88,7 @@ namespace skyline { * @param size The size of the region to map * @return The virtual address of the region base */ - u64 MapAllocated(u64 address, u64 size); + u64 MapAllocate(u64 address, u64 size); /** * @brief This maps a physical CPU memory region to a fixed virtual memory region diff --git a/app/src/main/cpp/skyline/services/nvdrv/devices/nvhost_as_gpu.cpp b/app/src/main/cpp/skyline/services/nvdrv/devices/nvhost_as_gpu.cpp index 0a50c286..9b7ce3a3 100644 --- a/app/src/main/cpp/skyline/services/nvdrv/devices/nvhost_as_gpu.cpp +++ b/app/src/main/cpp/skyline/services/nvdrv/devices/nvhost_as_gpu.cpp @@ -37,9 +37,9 @@ namespace skyline::service::nvdrv::device { u64 size = static_cast(region.pages) * static_cast(region.pageSize); if (region.flags & 1) - region.offset = state.gpu->memoryManager.AllocateFixed(region.offset, size); + region.offset = state.gpu->memoryManager.ReserveFixed(region.offset, size); else - region.offset = state.gpu->memoryManager.AllocateSpace(size); + region.offset = state.gpu->memoryManager.ReserveSpace(size); if (region.offset == 0) { state.logger->Warn("Failed to allocate GPU address space region!"); @@ -78,7 +78,7 @@ namespace skyline::service::nvdrv::device { if (region.flags & 1) region.offset = state.gpu->memoryManager.MapFixed(region.offset, mapPhysicalAddress, mapSize); else - region.offset = state.gpu->memoryManager.MapAllocated(mapPhysicalAddress, mapSize); + region.offset = state.gpu->memoryManager.MapAllocate(mapPhysicalAddress, mapSize); if (region.offset == 0) { state.logger->Warn("Failed to map GPU address space region!");