diff options
author | bunnei <bunneidev@gmail.com> | 2018-02-08 07:10:42 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-08 07:10:42 +0100 |
commit | db11c9a0b927a8f1d09f4cdf6bbe524485cb61b4 (patch) | |
tree | a9a7ab29e0c2e89bf2ec9874df074eb9db792dcc /src/core/hle/service/nvdrv/devices | |
parent | Merge pull request #168 from mailwl/new-stubs (diff) | |
parent | nvhost_as_gpu: Implement AllocateSpace and MapBufferEx. (diff) | |
download | yuzu-db11c9a0b927a8f1d09f4cdf6bbe524485cb61b4.tar yuzu-db11c9a0b927a8f1d09f4cdf6bbe524485cb61b4.tar.gz yuzu-db11c9a0b927a8f1d09f4cdf6bbe524485cb61b4.tar.bz2 yuzu-db11c9a0b927a8f1d09f4cdf6bbe524485cb61b4.tar.lz yuzu-db11c9a0b927a8f1d09f4cdf6bbe524485cb61b4.tar.xz yuzu-db11c9a0b927a8f1d09f4cdf6bbe524485cb61b4.tar.zst yuzu-db11c9a0b927a8f1d09f4cdf6bbe524485cb61b4.zip |
Diffstat (limited to 'src/core/hle/service/nvdrv/devices')
-rw-r--r-- | src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp | 38 | ||||
-rw-r--r-- | src/core/hle/service/nvdrv/devices/nvhost_as_gpu.h | 12 | ||||
-rw-r--r-- | src/core/hle/service/nvdrv/devices/nvmap.cpp | 27 | ||||
-rw-r--r-- | src/core/hle/service/nvdrv/devices/nvmap.h | 14 |
4 files changed, 62 insertions, 29 deletions
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 11ab25545..cf3601f02 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp +++ b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp @@ -5,6 +5,7 @@ #include "common/assert.h" #include "common/logging/log.h" #include "core/hle/service/nvdrv/devices/nvhost_as_gpu.h" +#include "core/hle/service/nvdrv/devices/nvmap.h" namespace Service { namespace Nvidia { @@ -40,9 +41,16 @@ u32 nvhost_as_gpu::InitalizeEx(const std::vector<u8>& input, std::vector<u8>& ou u32 nvhost_as_gpu::AllocateSpace(const std::vector<u8>& input, std::vector<u8>& output) { IoctlAllocSpace params{}; std::memcpy(¶ms, input.data(), input.size()); - LOG_WARNING(Service_NVDRV, "(STUBBED) called, pages=%x, page_size=%x, flags=%x", params.pages, - params.page_size, params.flags); - params.offset = 0xdeadbeef; // TODO(ogniK): Actually allocate space and give a real offset + LOG_DEBUG(Service_NVDRV, "called, pages=%x, page_size=%x, flags=%x", params.pages, + params.page_size, params.flags); + + const u64 size{static_cast<u64>(params.pages) * static_cast<u64>(params.page_size)}; + if (params.flags & 1) { + params.offset = memory_manager->AllocateSpace(params.offset, size, 1); + } else { + params.offset = memory_manager->AllocateSpace(size, params.align); + } + std::memcpy(output.data(), ¶ms, output.size()); return 0; } @@ -51,12 +59,24 @@ u32 nvhost_as_gpu::MapBufferEx(const std::vector<u8>& input, std::vector<u8>& ou IoctlMapBufferEx params{}; std::memcpy(¶ms, input.data(), input.size()); - LOG_WARNING(Service_NVDRV, - "(STUBBED) called, flags=%x, nvmap_handle=%x, buffer_offset=%lx, mapping_size=%lx, " - "offset=%lx", - params.flags, params.nvmap_handle, params.buffer_offset, params.mapping_size, - params.offset); - params.offset = 0x0; // TODO(ogniK): Actually map and give a real offset + LOG_DEBUG(Service_NVDRV, + "called, flags=%x, nvmap_handle=%x, buffer_offset=%lx, mapping_size=%lx, offset=%lx", + params.flags, params.nvmap_handle, params.buffer_offset, params.mapping_size, + params.offset); + + if (!params.nvmap_handle) { + return 0; + } + + auto object = nvmap_dev->GetObject(params.nvmap_handle); + ASSERT(object); + + if (params.flags & 1) { + params.offset = memory_manager->MapBufferEx(object->addr, params.offset, object->size); + } else { + params.offset = memory_manager->MapBufferEx(object->addr, object->size); + } + std::memcpy(output.data(), ¶ms, output.size()); return 0; } 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 06c256d5d..9d37b971a 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.h +++ b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.h @@ -4,18 +4,25 @@ #pragma once +#include <memory> +#include <utility> #include <vector> #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; + class nvhost_as_gpu final : public nvdevice { public: - nvhost_as_gpu() = default; + nvhost_as_gpu(std::shared_ptr<nvmap> nvmap_dev) : nvdevice(), nvmap_dev(std::move(nvmap_dev)) { + memory_manager = std::make_shared<MemoryManager>(); + } ~nvhost_as_gpu() override = default; u32 ioctl(Ioctl command, const std::vector<u8>& input, std::vector<u8>& output) override; @@ -92,6 +99,9 @@ private: u32 MapBufferEx(const std::vector<u8>& input, std::vector<u8>& output); u32 BindChannel(const std::vector<u8>& input, std::vector<u8>& output); u32 GetVARegions(const std::vector<u8>& input, std::vector<u8>& output); + + std::shared_ptr<nvmap> nvmap_dev; + std::shared_ptr<MemoryManager> memory_manager; }; } // namespace Devices diff --git a/src/core/hle/service/nvdrv/devices/nvmap.cpp b/src/core/hle/service/nvdrv/devices/nvmap.cpp index cb3692689..02b33374a 100644 --- a/src/core/hle/service/nvdrv/devices/nvmap.cpp +++ b/src/core/hle/service/nvdrv/devices/nvmap.cpp @@ -13,10 +13,8 @@ namespace Nvidia { namespace Devices { VAddr nvmap::GetObjectAddress(u32 handle) const { - auto itr = handles.find(handle); - ASSERT(itr != handles.end()); - - auto object = itr->second; + auto object = GetObject(handle); + ASSERT(object); ASSERT(object->status == Object::Status::Allocated); return object->addr; } @@ -52,7 +50,7 @@ u32 nvmap::IocCreate(const std::vector<u8>& input, std::vector<u8>& output) { u32 handle = next_handle++; handles[handle] = std::move(object); - LOG_WARNING(Service_NVDRV, "(STUBBED) size 0x%08X", params.size); + LOG_DEBUG(Service_NVDRV, "size=0x%08X", params.size); params.handle = handle; @@ -64,17 +62,16 @@ u32 nvmap::IocAlloc(const std::vector<u8>& input, std::vector<u8>& output) { IocAllocParams params; std::memcpy(¶ms, input.data(), sizeof(params)); - auto itr = handles.find(params.handle); - ASSERT(itr != handles.end()); + auto object = GetObject(params.handle); + ASSERT(object); - auto object = itr->second; object->flags = params.flags; object->align = params.align; object->kind = params.kind; object->addr = params.addr; object->status = Object::Status::Allocated; - LOG_WARNING(Service_NVDRV, "(STUBBED) Allocated address 0x%llx", params.addr); + LOG_DEBUG(Service_NVDRV, "called, addr=0x%llx", params.addr); std::memcpy(output.data(), ¶ms, sizeof(params)); return 0; @@ -86,10 +83,10 @@ u32 nvmap::IocGetId(const std::vector<u8>& input, std::vector<u8>& output) { LOG_WARNING(Service_NVDRV, "called"); - auto itr = handles.find(params.handle); - ASSERT(itr != handles.end()); + auto object = GetObject(params.handle); + ASSERT(object); - params.id = itr->second->id; + params.id = object->id; std::memcpy(output.data(), ¶ms, sizeof(params)); return 0; @@ -123,10 +120,8 @@ u32 nvmap::IocParam(const std::vector<u8>& input, std::vector<u8>& output) { LOG_WARNING(Service_NVDRV, "(STUBBED) called type=%u", params.type); - auto itr = handles.find(params.handle); - ASSERT(itr != handles.end()); - - auto object = itr->second; + auto object = GetObject(params.handle); + ASSERT(object); ASSERT(object->status == Object::Status::Allocated); switch (static_cast<ParamTypes>(params.type)) { diff --git a/src/core/hle/service/nvdrv/devices/nvmap.h b/src/core/hle/service/nvdrv/devices/nvmap.h index 1591ac8ff..4681e438b 100644 --- a/src/core/hle/service/nvdrv/devices/nvmap.h +++ b/src/core/hle/service/nvdrv/devices/nvmap.h @@ -26,8 +26,7 @@ public: u32 ioctl(Ioctl command, const std::vector<u8>& input, std::vector<u8>& output) override; -private: - // Represents an nvmap object. + /// Represents an nvmap object. struct Object { enum class Status { Created, Allocated }; u32 id; @@ -39,10 +38,19 @@ private: Status status; }; + std::shared_ptr<Object> GetObject(u32 handle) const { + auto itr = handles.find(handle); + if (itr != handles.end()) { + return itr->second; + } + return {}; + } + +private: /// Id to use for the next handle that is created. u32 next_handle = 1; - // Id to use for the next object that is created. + /// Id to use for the next object that is created. u32 next_id = 1; /// Mapping of currently allocated handles to the objects they represent. |