diff options
author | Fernando Sahmkow <fsahmkow27@gmail.com> | 2023-12-24 18:20:02 +0100 |
---|---|---|
committer | Liam <byteslice@airmail.cc> | 2024-01-19 03:12:30 +0100 |
commit | 7a9d1ad2f873003e6aad637e8749b77b91247da3 (patch) | |
tree | e167a5d5ad73dbd78dc4b5c165b12a1220a167f4 /src/core/hle/service/nvdrv/nvdrv_interface.cpp | |
parent | Core: Initial implementation of device memory mapping (diff) | |
download | yuzu-7a9d1ad2f873003e6aad637e8749b77b91247da3.tar yuzu-7a9d1ad2f873003e6aad637e8749b77b91247da3.tar.gz yuzu-7a9d1ad2f873003e6aad637e8749b77b91247da3.tar.bz2 yuzu-7a9d1ad2f873003e6aad637e8749b77b91247da3.tar.lz yuzu-7a9d1ad2f873003e6aad637e8749b77b91247da3.tar.xz yuzu-7a9d1ad2f873003e6aad637e8749b77b91247da3.tar.zst yuzu-7a9d1ad2f873003e6aad637e8749b77b91247da3.zip |
Diffstat (limited to 'src/core/hle/service/nvdrv/nvdrv_interface.cpp')
-rw-r--r-- | src/core/hle/service/nvdrv/nvdrv_interface.cpp | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/src/core/hle/service/nvdrv/nvdrv_interface.cpp b/src/core/hle/service/nvdrv/nvdrv_interface.cpp index c8a880e84..492ad849a 100644 --- a/src/core/hle/service/nvdrv/nvdrv_interface.cpp +++ b/src/core/hle/service/nvdrv/nvdrv_interface.cpp @@ -3,14 +3,18 @@ // SPDX-License-Identifier: GPL-3.0-or-later #include "common/logging/log.h" +#include "common/scope_exit.h" #include "core/core.h" #include "core/hle/kernel/k_event.h" +#include "core/hle/kernel/k_process.h" #include "core/hle/kernel/k_readable_event.h" #include "core/hle/service/ipc_helpers.h" #include "core/hle/service/nvdrv/nvdata.h" #include "core/hle/service/nvdrv/nvdrv.h" #include "core/hle/service/nvdrv/nvdrv_interface.h" +#pragma optimize("", off) + namespace Service::Nvidia { void NVDRV::Open(HLERequestContext& ctx) { @@ -37,7 +41,7 @@ void NVDRV::Open(HLERequestContext& ctx) { return; } - DeviceFD fd = nvdrv->Open(device_name); + DeviceFD fd = nvdrv->Open(device_name, session_id); rb.Push<DeviceFD>(fd); rb.PushEnum(fd != INVALID_NVDRV_FD ? NvResult::Success : NvResult::FileOperationFailed); @@ -150,12 +154,29 @@ void NVDRV::Close(HLERequestContext& ctx) { void NVDRV::Initialize(HLERequestContext& ctx) { LOG_WARNING(Service_NVDRV, "(STUBBED) called"); + IPC::ResponseBuilder rb{ctx, 3}; + SCOPE_EXIT({ + rb.Push(ResultSuccess); + rb.PushEnum(NvResult::Success); + }); - is_initialized = true; + if (is_initialized) { + // No need to initialize again + return; + } - IPC::ResponseBuilder rb{ctx, 3}; - rb.Push(ResultSuccess); - rb.PushEnum(NvResult::Success); + IPC::RequestParser rp{ctx}; + const auto process_handle{ctx.GetCopyHandle(0)}; + // The transfer memory is lent to nvdrv as a work buffer since nvdrv is + // unable to allocate as much memory on its own. For HLE it's unnecessary to handle it + [[maybe_unused]] const auto transfer_memory_handle{ctx.GetCopyHandle(1)}; + [[maybe_unused]] const auto transfer_memory_size = rp.Pop<u32>(); + + auto& container = nvdrv->GetContainer(); + auto process = ctx.GetObjectFromHandle(process_handle); + session_id = container.OpenSession(process->DynamicCast<Kernel::KProcess*>()); + + is_initialized = true; } void NVDRV::QueryEvent(HLERequestContext& ctx) { @@ -242,6 +263,9 @@ NVDRV::NVDRV(Core::System& system_, std::shared_ptr<Module> nvdrv_, const char* RegisterHandlers(functions); } -NVDRV::~NVDRV() = default; +NVDRV::~NVDRV() { + auto& container = nvdrv->GetContainer(); + container.CloseSession(session_id); +} } // namespace Service::Nvidia |