From ba2426aa3f9b433b54e43e5dae3c596e6f3ae45d Mon Sep 17 00:00:00 2001 From: Subv Date: Sun, 11 Feb 2018 21:30:23 -0500 Subject: nvdrv: Make the GPU memory manager available to nvhost-gpu. --- src/core/hle/service/nvdrv/devices/nvhost_as_gpu.h | 5 ++--- src/core/hle/service/nvdrv/devices/nvhost_gpu.h | 10 +++++++++- src/core/hle/service/nvdrv/nvdrv.cpp | 7 +++++-- 3 files changed, 16 insertions(+), 6 deletions(-) (limited to 'src/core/hle') diff --git a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.h b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.h index 9d37b971a..44ffddcd9 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.h +++ b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.h @@ -20,9 +20,8 @@ class nvmap; class nvhost_as_gpu final : public nvdevice { public: - nvhost_as_gpu(std::shared_ptr nvmap_dev) : nvdevice(), nvmap_dev(std::move(nvmap_dev)) { - memory_manager = std::make_shared(); - } + nvhost_as_gpu(std::shared_ptr nvmap_dev, std::shared_ptr memory_manager) + : nvdevice(), nvmap_dev(std::move(nvmap_dev)), memory_manager(std::move(memory_manager)) {} ~nvhost_as_gpu() override = default; u32 ioctl(Ioctl command, const std::vector& input, std::vector& output) override; diff --git a/src/core/hle/service/nvdrv/devices/nvhost_gpu.h b/src/core/hle/service/nvdrv/devices/nvhost_gpu.h index 4fe2c9ad5..5b40eaa88 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_gpu.h +++ b/src/core/hle/service/nvdrv/devices/nvhost_gpu.h @@ -4,20 +4,25 @@ #pragma once +#include #include #include "common/common_types.h" #include "common/swap.h" #include "core/hle/service/nvdrv/devices/nvdevice.h" +#include "core/hle/service/nvdrv/memory_manager.h" namespace Service { namespace Nvidia { namespace Devices { + +class nvmap; constexpr u32 NVGPU_IOCTL_MAGIC('H'); constexpr u32 NVGPU_IOCTL_CHANNEL_SUBMIT_GPFIFO(0x8); class nvhost_gpu final : public nvdevice { public: - nvhost_gpu() = default; + nvhost_gpu(std::shared_ptr nvmap_dev, std::shared_ptr memory_manager) + : nvdevice(), nvmap_dev(std::move(nvmap_dev)), memory_manager(std::move(memory_manager)) {} ~nvhost_gpu() override = default; u32 ioctl(Ioctl command, const std::vector& input, std::vector& output) override; @@ -132,6 +137,9 @@ private: u32 AllocGPFIFOEx2(const std::vector& input, std::vector& output); u32 AllocateObjectContext(const std::vector& input, std::vector& output); u32 SubmitGPFIFO(const std::vector& input, std::vector& output); + + std::shared_ptr nvmap_dev; + std::shared_ptr memory_manager; }; } // namespace Devices diff --git a/src/core/hle/service/nvdrv/nvdrv.cpp b/src/core/hle/service/nvdrv/nvdrv.cpp index a98634422..469d6d33a 100644 --- a/src/core/hle/service/nvdrv/nvdrv.cpp +++ b/src/core/hle/service/nvdrv/nvdrv.cpp @@ -11,6 +11,7 @@ #include "core/hle/service/nvdrv/devices/nvhost_gpu.h" #include "core/hle/service/nvdrv/devices/nvmap.h" #include "core/hle/service/nvdrv/interface.h" +#include "core/hle/service/nvdrv/memory_manager.h" #include "core/hle/service/nvdrv/nvdrv.h" #include "core/hle/service/nvdrv/nvmemp.h" @@ -31,12 +32,14 @@ void InstallInterfaces(SM::ServiceManager& service_manager) { Module::Module() { auto nvmap_dev = std::make_shared(); - devices["/dev/nvhost-as-gpu"] = std::make_shared(nvmap_dev); + auto memory_manager = std::make_shared(); + devices["/dev/nvhost-as-gpu"] = + std::make_shared(nvmap_dev, memory_manager); + devices["/dev/nvhost-gpu"] = std::make_shared(nvmap_dev, memory_manager); devices["/dev/nvhost-ctrl-gpu"] = std::make_shared(); devices["/dev/nvmap"] = nvmap_dev; devices["/dev/nvdisp_disp0"] = std::make_shared(nvmap_dev); devices["/dev/nvhost-ctrl"] = std::make_shared(); - devices["/dev/nvhost-gpu"] = std::make_shared(); } u32 Module::Open(std::string device_name) { -- cgit v1.2.3 From e01a8f218707b6f3ed0f111c432440b07ea5b6ff Mon Sep 17 00:00:00 2001 From: Subv Date: Sun, 11 Feb 2018 21:34:20 -0500 Subject: GPU: Added a command processor to decode the GPU pushbuffers and forward the commands to their respective engines. --- src/core/hle/service/nvdrv/devices/nvhost_as_gpu.h | 2 +- src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp | 4 +++- src/core/hle/service/nvdrv/devices/nvhost_gpu.h | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) (limited to 'src/core/hle') diff --git a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.h b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.h index 44ffddcd9..301a8a79f 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.h +++ b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.h @@ -21,7 +21,7 @@ class nvmap; class nvhost_as_gpu final : public nvdevice { public: nvhost_as_gpu(std::shared_ptr nvmap_dev, std::shared_ptr memory_manager) - : nvdevice(), nvmap_dev(std::move(nvmap_dev)), memory_manager(std::move(memory_manager)) {} + : nvmap_dev(std::move(nvmap_dev)), memory_manager(std::move(memory_manager)) {} ~nvhost_as_gpu() override = default; u32 ioctl(Ioctl command, const std::vector& input, std::vector& output) override; diff --git a/src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp b/src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp index 229048d37..1c3079889 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp +++ b/src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp @@ -6,6 +6,7 @@ #include "common/assert.h" #include "common/logging/log.h" #include "core/hle/service/nvdrv/devices/nvhost_gpu.h" +#include "video_core/command_processor.h" namespace Service { namespace Nvidia { @@ -130,7 +131,8 @@ u32 nvhost_gpu::SubmitGPFIFO(const std::vector& input, std::vector& outp std::memcpy(&entries[0], &input.data()[sizeof(IoctlSubmitGpfifo)], params.num_entries * sizeof(IoctlGpfifoEntry)); for (auto entry : entries) { - VAddr va_addr = entry.Address(); + VAddr va_addr = memory_manager->PhysicalToVirtualAddress(entry.Address()); + Tegra::CommandProcessor::ProcessCommandList(va_addr, entry.sz); // TODO(ogniK): Process these } params.fence_out.id = 0; diff --git a/src/core/hle/service/nvdrv/devices/nvhost_gpu.h b/src/core/hle/service/nvdrv/devices/nvhost_gpu.h index 5b40eaa88..6f9b90b05 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_gpu.h +++ b/src/core/hle/service/nvdrv/devices/nvhost_gpu.h @@ -22,7 +22,7 @@ constexpr u32 NVGPU_IOCTL_CHANNEL_SUBMIT_GPFIFO(0x8); class nvhost_gpu final : public nvdevice { public: nvhost_gpu(std::shared_ptr nvmap_dev, std::shared_ptr memory_manager) - : nvdevice(), nvmap_dev(std::move(nvmap_dev)), memory_manager(std::move(memory_manager)) {} + : nvmap_dev(std::move(nvmap_dev)), memory_manager(std::move(memory_manager)) {} ~nvhost_gpu() override = default; u32 ioctl(Ioctl command, const std::vector& input, std::vector& output) override; -- cgit v1.2.3 From 6cddf9d88e7fc49919fda92bcd4235797c56f07f Mon Sep 17 00:00:00 2001 From: Subv Date: Sun, 11 Feb 2018 23:44:12 -0500 Subject: Make a GPU class in VideoCore to contain the GPU state. Also moved the GPU MemoryManager class to video_core since it makes more sense for it to be there. --- .../hle/service/nvdrv/devices/nvhost_as_gpu.cpp | 12 ++- src/core/hle/service/nvdrv/devices/nvhost_as_gpu.h | 5 +- src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp | 7 +- src/core/hle/service/nvdrv/devices/nvhost_gpu.h | 5 +- src/core/hle/service/nvdrv/memory_manager.cpp | 112 --------------------- src/core/hle/service/nvdrv/memory_manager.h | 48 --------- src/core/hle/service/nvdrv/nvdrv.cpp | 7 +- 7 files changed, 15 insertions(+), 181 deletions(-) delete mode 100644 src/core/hle/service/nvdrv/memory_manager.cpp delete mode 100644 src/core/hle/service/nvdrv/memory_manager.h (limited to 'src/core/hle') diff --git a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp index cf3601f02..9832e1899 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp +++ b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp @@ -4,6 +4,7 @@ #include "common/assert.h" #include "common/logging/log.h" +#include "core/core.h" #include "core/hle/service/nvdrv/devices/nvhost_as_gpu.h" #include "core/hle/service/nvdrv/devices/nvmap.h" @@ -44,11 +45,12 @@ u32 nvhost_as_gpu::AllocateSpace(const std::vector& input, std::vector& LOG_DEBUG(Service_NVDRV, "called, pages=%x, page_size=%x, flags=%x", params.pages, params.page_size, params.flags); + auto& gpu = Core::System::GetInstance().GPU(); const u64 size{static_cast(params.pages) * static_cast(params.page_size)}; if (params.flags & 1) { - params.offset = memory_manager->AllocateSpace(params.offset, size, 1); + params.offset = gpu.memory_manager->AllocateSpace(params.offset, size, 1); } else { - params.offset = memory_manager->AllocateSpace(size, params.align); + params.offset = gpu.memory_manager->AllocateSpace(size, params.align); } std::memcpy(output.data(), ¶ms, output.size()); @@ -71,10 +73,12 @@ u32 nvhost_as_gpu::MapBufferEx(const std::vector& input, std::vector& ou auto object = nvmap_dev->GetObject(params.nvmap_handle); ASSERT(object); + auto& gpu = Core::System::GetInstance().GPU(); + if (params.flags & 1) { - params.offset = memory_manager->MapBufferEx(object->addr, params.offset, object->size); + params.offset = gpu.memory_manager->MapBufferEx(object->addr, params.offset, object->size); } else { - params.offset = memory_manager->MapBufferEx(object->addr, object->size); + params.offset = gpu.memory_manager->MapBufferEx(object->addr, object->size); } std::memcpy(output.data(), ¶ms, output.size()); diff --git a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.h b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.h index 301a8a79f..f8a60cce7 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.h +++ b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.h @@ -10,7 +10,6 @@ #include "common/common_types.h" #include "common/swap.h" #include "core/hle/service/nvdrv/devices/nvdevice.h" -#include "core/hle/service/nvdrv/memory_manager.h" namespace Service { namespace Nvidia { @@ -20,8 +19,7 @@ class nvmap; class nvhost_as_gpu final : public nvdevice { public: - nvhost_as_gpu(std::shared_ptr nvmap_dev, std::shared_ptr memory_manager) - : nvmap_dev(std::move(nvmap_dev)), memory_manager(std::move(memory_manager)) {} + nvhost_as_gpu(std::shared_ptr nvmap_dev) : nvmap_dev(std::move(nvmap_dev)) {} ~nvhost_as_gpu() override = default; u32 ioctl(Ioctl command, const std::vector& input, std::vector& output) override; @@ -100,7 +98,6 @@ private: u32 GetVARegions(const std::vector& input, std::vector& output); std::shared_ptr nvmap_dev; - std::shared_ptr memory_manager; }; } // namespace Devices diff --git a/src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp b/src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp index 1c3079889..0b2ebd466 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp +++ b/src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp @@ -5,8 +5,8 @@ #include #include "common/assert.h" #include "common/logging/log.h" +#include "core/core.h" #include "core/hle/service/nvdrv/devices/nvhost_gpu.h" -#include "video_core/command_processor.h" namespace Service { namespace Nvidia { @@ -131,9 +131,8 @@ u32 nvhost_gpu::SubmitGPFIFO(const std::vector& input, std::vector& outp std::memcpy(&entries[0], &input.data()[sizeof(IoctlSubmitGpfifo)], params.num_entries * sizeof(IoctlGpfifoEntry)); for (auto entry : entries) { - VAddr va_addr = memory_manager->PhysicalToVirtualAddress(entry.Address()); - Tegra::CommandProcessor::ProcessCommandList(va_addr, entry.sz); - // TODO(ogniK): Process these + VAddr va_addr = entry.Address(); + Core::System::GetInstance().GPU().ProcessCommandList(va_addr, entry.sz); } params.fence_out.id = 0; params.fence_out.value = 0; diff --git a/src/core/hle/service/nvdrv/devices/nvhost_gpu.h b/src/core/hle/service/nvdrv/devices/nvhost_gpu.h index 6f9b90b05..e7e9a0088 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_gpu.h +++ b/src/core/hle/service/nvdrv/devices/nvhost_gpu.h @@ -9,7 +9,6 @@ #include "common/common_types.h" #include "common/swap.h" #include "core/hle/service/nvdrv/devices/nvdevice.h" -#include "core/hle/service/nvdrv/memory_manager.h" namespace Service { namespace Nvidia { @@ -21,8 +20,7 @@ constexpr u32 NVGPU_IOCTL_CHANNEL_SUBMIT_GPFIFO(0x8); class nvhost_gpu final : public nvdevice { public: - nvhost_gpu(std::shared_ptr nvmap_dev, std::shared_ptr memory_manager) - : nvmap_dev(std::move(nvmap_dev)), memory_manager(std::move(memory_manager)) {} + nvhost_gpu(std::shared_ptr nvmap_dev) : nvmap_dev(std::move(nvmap_dev)) {} ~nvhost_gpu() override = default; u32 ioctl(Ioctl command, const std::vector& input, std::vector& output) override; @@ -139,7 +137,6 @@ private: u32 SubmitGPFIFO(const std::vector& input, std::vector& output); std::shared_ptr nvmap_dev; - std::shared_ptr memory_manager; }; } // namespace Devices diff --git a/src/core/hle/service/nvdrv/memory_manager.cpp b/src/core/hle/service/nvdrv/memory_manager.cpp deleted file mode 100644 index 55a8675d5..000000000 --- a/src/core/hle/service/nvdrv/memory_manager.cpp +++ /dev/null @@ -1,112 +0,0 @@ -// Copyright 2018 yuzu emulator team -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#include "common/assert.h" -#include "core/hle/service/nvdrv/memory_manager.h" - -namespace Service { -namespace Nvidia { - -PAddr MemoryManager::AllocateSpace(u64 size, u64 align) { - boost::optional paddr = FindFreeBlock(size, align); - ASSERT(paddr); - - for (u64 offset = 0; offset < size; offset += Memory::PAGE_SIZE) { - PageSlot(*paddr + offset) = static_cast(PageStatus::Allocated); - } - - return *paddr; -} - -PAddr MemoryManager::AllocateSpace(PAddr paddr, u64 size, u64 align) { - for (u64 offset = 0; offset < size; offset += Memory::PAGE_SIZE) { - if (IsPageMapped(paddr + offset)) { - return AllocateSpace(size, align); - } - } - - for (u64 offset = 0; offset < size; offset += Memory::PAGE_SIZE) { - PageSlot(paddr + offset) = static_cast(PageStatus::Allocated); - } - - return paddr; -} - -PAddr MemoryManager::MapBufferEx(VAddr vaddr, u64 size) { - vaddr &= ~Memory::PAGE_MASK; - - boost::optional paddr = FindFreeBlock(size); - ASSERT(paddr); - - for (u64 offset = 0; offset < size; offset += Memory::PAGE_SIZE) { - PageSlot(*paddr + offset) = vaddr + offset; - } - - return *paddr; -} - -PAddr MemoryManager::MapBufferEx(VAddr vaddr, PAddr paddr, u64 size) { - vaddr &= ~Memory::PAGE_MASK; - paddr &= ~Memory::PAGE_MASK; - - for (u64 offset = 0; offset < size; offset += Memory::PAGE_SIZE) { - if (PageSlot(paddr + offset) != static_cast(PageStatus::Allocated)) { - return MapBufferEx(vaddr, size); - } - } - - for (u64 offset = 0; offset < size; offset += Memory::PAGE_SIZE) { - PageSlot(paddr + offset) = vaddr + offset; - } - - return paddr; -} - -boost::optional MemoryManager::FindFreeBlock(u64 size, u64 align) { - PAddr paddr{}; - u64 free_space{}; - align = (align + Memory::PAGE_MASK) & ~Memory::PAGE_MASK; - - while (paddr + free_space < MAX_ADDRESS) { - if (!IsPageMapped(paddr + free_space)) { - free_space += Memory::PAGE_SIZE; - if (free_space >= size) { - return paddr; - } - } else { - paddr += free_space + Memory::PAGE_SIZE; - free_space = 0; - const u64 remainder{paddr % align}; - if (!remainder) { - paddr = (paddr - remainder) + align; - } - } - } - - return {}; -} - -VAddr MemoryManager::PhysicalToVirtualAddress(PAddr paddr) { - VAddr base_addr = PageSlot(paddr); - ASSERT(base_addr != static_cast(PageStatus::Unmapped)); - return base_addr + (paddr & Memory::PAGE_MASK); -} - -bool MemoryManager::IsPageMapped(PAddr paddr) { - return PageSlot(paddr) != static_cast(PageStatus::Unmapped); -} - -VAddr& MemoryManager::PageSlot(PAddr paddr) { - auto& block = page_table[(paddr >> (Memory::PAGE_BITS + PAGE_TABLE_BITS)) & PAGE_TABLE_MASK]; - if (!block) { - block = std::make_unique(); - for (unsigned index = 0; index < PAGE_BLOCK_SIZE; index++) { - (*block)[index] = static_cast(PageStatus::Unmapped); - } - } - return (*block)[(paddr >> Memory::PAGE_BITS) & PAGE_BLOCK_MASK]; -} - -} // namespace Nvidia -} // namespace Service diff --git a/src/core/hle/service/nvdrv/memory_manager.h b/src/core/hle/service/nvdrv/memory_manager.h deleted file mode 100644 index 4ba1a3952..000000000 --- a/src/core/hle/service/nvdrv/memory_manager.h +++ /dev/null @@ -1,48 +0,0 @@ -// 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 diff --git a/src/core/hle/service/nvdrv/nvdrv.cpp b/src/core/hle/service/nvdrv/nvdrv.cpp index 469d6d33a..ea00240e6 100644 --- a/src/core/hle/service/nvdrv/nvdrv.cpp +++ b/src/core/hle/service/nvdrv/nvdrv.cpp @@ -11,7 +11,6 @@ #include "core/hle/service/nvdrv/devices/nvhost_gpu.h" #include "core/hle/service/nvdrv/devices/nvmap.h" #include "core/hle/service/nvdrv/interface.h" -#include "core/hle/service/nvdrv/memory_manager.h" #include "core/hle/service/nvdrv/nvdrv.h" #include "core/hle/service/nvdrv/nvmemp.h" @@ -32,10 +31,8 @@ void InstallInterfaces(SM::ServiceManager& service_manager) { Module::Module() { auto nvmap_dev = std::make_shared(); - auto memory_manager = std::make_shared(); - devices["/dev/nvhost-as-gpu"] = - std::make_shared(nvmap_dev, memory_manager); - devices["/dev/nvhost-gpu"] = std::make_shared(nvmap_dev, memory_manager); + devices["/dev/nvhost-as-gpu"] = std::make_shared(nvmap_dev); + devices["/dev/nvhost-gpu"] = std::make_shared(nvmap_dev); devices["/dev/nvhost-ctrl-gpu"] = std::make_shared(); devices["/dev/nvmap"] = nvmap_dev; devices["/dev/nvdisp_disp0"] = std::make_shared(nvmap_dev); -- cgit v1.2.3