Files
eden/src/core/hle/service/nvdrv/interface.cpp
T

260 lines
7.9 KiB
C++
Raw Normal View History

// Copyright 2018 yuzu emulator team
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include <cinttypes>
#include "common/logging/log.h"
2018-08-28 12:30:33 -04:00
#include "core/core.h"
#include "core/hle/ipc_helpers.h"
#include "core/hle/kernel/k_readable_event.h"
#include "core/hle/kernel/k_thread.h"
#include "core/hle/kernel/k_writable_event.h"
#include "core/hle/kernel/kernel.h"
#include "core/hle/service/nvdrv/interface.h"
#include "core/hle/service/nvdrv/nvdata.h"
#include "core/hle/service/nvdrv/nvdrv.h"
namespace Service::Nvidia {
void NVDRV::SignalGPUInterruptSyncpt(const u32 syncpoint_id, const u32 value) {
nvdrv->SignalSyncpt(syncpoint_id, value);
}
void NVDRV::Open(Kernel::HLERequestContext& ctx) {
2018-07-02 10:13:26 -06:00
LOG_DEBUG(Service_NVDRV, "called");
2021-05-03 14:39:03 +10:00
IPC::ResponseBuilder rb{ctx, 4};
rb.Push(RESULT_SUCCESS);
2020-11-10 15:56:41 +11:00
if (!is_initialized) {
2021-05-03 14:39:03 +10:00
rb.Push<DeviceFD>(0);
rb.PushEnum(NvResult::NotInitialized);
2020-11-08 19:11:34 +11:00
LOG_ERROR(Service_NVDRV, "NvServices is not initalized!");
return;
}
const auto& buffer = ctx.ReadBuffer();
2020-11-08 19:11:34 +11:00
const std::string device_name(buffer.begin(), buffer.end());
2021-05-03 14:39:03 +10:00
if (device_name == "/dev/nvhost-prof-gpu") {
rb.Push<DeviceFD>(0);
rb.PushEnum(NvResult::NotSupported);
LOG_WARNING(Service_NVDRV, "/dev/nvhost-prof-gpu cannot be openned on production");
return;
}
2020-11-08 19:11:34 +11:00
DeviceFD fd = nvdrv->Open(device_name);
2020-11-08 19:11:34 +11:00
rb.Push<DeviceFD>(fd);
rb.PushEnum(fd != INVALID_NVDRV_FD ? NvResult::Success : NvResult::FileOperationFailed);
}
void NVDRV::ServiceError(Kernel::HLERequestContext& ctx, NvResult result) {
IPC::ResponseBuilder rb{ctx, 3};
rb.Push(RESULT_SUCCESS);
rb.PushEnum(result);
}
2020-11-08 19:11:34 +11:00
void NVDRV::Ioctl1(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp{ctx};
2020-11-08 19:11:34 +11:00
const auto fd = rp.Pop<DeviceFD>();
const auto command = rp.PopRaw<Ioctl>();
LOG_DEBUG(Service_NVDRV, "called fd={}, ioctl=0x{:08X}", fd, command.raw);
2020-11-10 15:56:41 +11:00
if (!is_initialized) {
2020-11-08 19:11:34 +11:00
ServiceError(ctx, NvResult::NotInitialized);
LOG_ERROR(Service_NVDRV, "NvServices is not initalized!");
return;
2019-09-19 15:37:25 +10:00
}
2020-11-08 19:11:34 +11:00
// Check device
std::vector<u8> output_buffer(ctx.GetWriteBufferSize(0));
const auto input_buffer = ctx.ReadBuffer(0);
2019-09-19 15:37:25 +10:00
const auto nv_result = nvdrv->Ioctl1(fd, command, input_buffer, output_buffer);
if (command.is_out != 0) {
ctx.WriteBuffer(output_buffer);
}
2020-11-08 19:11:34 +11:00
2019-07-04 10:19:25 -04:00
IPC::ResponseBuilder rb{ctx, 3};
rb.Push(RESULT_SUCCESS);
2020-11-08 19:11:34 +11:00
rb.PushEnum(nv_result);
2019-09-19 15:37:25 +10:00
}
void NVDRV::Ioctl2(Kernel::HLERequestContext& ctx) {
2020-11-08 19:11:34 +11:00
IPC::RequestParser rp{ctx};
const auto fd = rp.Pop<DeviceFD>();
const auto command = rp.PopRaw<Ioctl>();
LOG_DEBUG(Service_NVDRV, "called fd={}, ioctl=0x{:08X}", fd, command.raw);
2020-11-10 15:56:41 +11:00
if (!is_initialized) {
2020-11-08 19:11:34 +11:00
ServiceError(ctx, NvResult::NotInitialized);
LOG_ERROR(Service_NVDRV, "NvServices is not initalized!");
return;
}
const auto input_buffer = ctx.ReadBuffer(0);
const auto input_inlined_buffer = ctx.ReadBuffer(1);
std::vector<u8> output_buffer(ctx.GetWriteBufferSize(0));
const auto nv_result =
nvdrv->Ioctl2(fd, command, input_buffer, input_inlined_buffer, output_buffer);
2020-11-08 19:11:34 +11:00
if (command.is_out != 0) {
ctx.WriteBuffer(output_buffer);
}
IPC::ResponseBuilder rb{ctx, 3};
rb.Push(RESULT_SUCCESS);
rb.PushEnum(nv_result);
2019-09-19 15:37:25 +10:00
}
void NVDRV::Ioctl3(Kernel::HLERequestContext& ctx) {
2020-11-08 19:11:34 +11:00
IPC::RequestParser rp{ctx};
const auto fd = rp.Pop<DeviceFD>();
const auto command = rp.PopRaw<Ioctl>();
LOG_DEBUG(Service_NVDRV, "called fd={}, ioctl=0x{:08X}", fd, command.raw);
2020-11-10 15:56:41 +11:00
if (!is_initialized) {
2020-11-08 19:11:34 +11:00
ServiceError(ctx, NvResult::NotInitialized);
LOG_ERROR(Service_NVDRV, "NvServices is not initalized!");
return;
}
const auto input_buffer = ctx.ReadBuffer(0);
std::vector<u8> output_buffer(ctx.GetWriteBufferSize(0));
std::vector<u8> output_buffer_inline(ctx.GetWriteBufferSize(1));
const auto nv_result =
nvdrv->Ioctl3(fd, command, input_buffer, output_buffer, output_buffer_inline);
if (command.is_out != 0) {
ctx.WriteBuffer(output_buffer, 0);
ctx.WriteBuffer(output_buffer_inline, 1);
2020-11-08 19:11:34 +11:00
}
IPC::ResponseBuilder rb{ctx, 3};
rb.Push(RESULT_SUCCESS);
rb.PushEnum(nv_result);
2019-09-19 15:37:25 +10:00
}
2018-01-17 17:08:46 +01:00
void NVDRV::Close(Kernel::HLERequestContext& ctx) {
2018-07-02 10:13:26 -06:00
LOG_DEBUG(Service_NVDRV, "called");
2018-01-17 17:08:46 +01:00
2020-11-10 15:56:41 +11:00
if (!is_initialized) {
2020-11-08 19:11:34 +11:00
ServiceError(ctx, NvResult::NotInitialized);
LOG_ERROR(Service_NVDRV, "NvServices is not initalized!");
return;
}
2018-01-17 17:08:46 +01:00
2020-11-08 19:11:34 +11:00
IPC::RequestParser rp{ctx};
const auto fd = rp.Pop<DeviceFD>();
const auto result = nvdrv->Close(fd);
2018-01-17 17:08:46 +01:00
2020-11-08 19:11:34 +11:00
IPC::ResponseBuilder rb{ctx, 3};
rb.Push(RESULT_SUCCESS);
rb.PushEnum(result);
2018-01-17 17:08:46 +01:00
}
void NVDRV::Initialize(Kernel::HLERequestContext& ctx) {
2018-07-02 10:13:26 -06:00
LOG_WARNING(Service_NVDRV, "(STUBBED) called");
2020-11-10 15:56:41 +11:00
is_initialized = true;
2020-11-08 19:11:34 +11:00
IPC::ResponseBuilder rb{ctx, 3};
rb.Push(RESULT_SUCCESS);
2020-11-08 19:11:34 +11:00
rb.PushEnum(NvResult::Success);
}
2018-02-05 18:19:31 -08:00
void NVDRV::QueryEvent(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp{ctx};
2020-11-08 19:11:34 +11:00
const auto fd = rp.Pop<DeviceFD>();
const auto event_id = rp.Pop<u32>() & 0x00FF;
2018-07-02 10:13:26 -06:00
LOG_WARNING(Service_NVDRV, "(STUBBED) called, fd={:X}, event_id={:X}", fd, event_id);
2018-02-05 18:19:31 -08:00
2020-11-10 15:56:41 +11:00
if (!is_initialized) {
2020-11-08 19:11:34 +11:00
ServiceError(ctx, NvResult::NotInitialized);
LOG_ERROR(Service_NVDRV, "NvServices is not initalized!");
return;
}
2020-11-10 15:56:41 +11:00
const auto nv_result = nvdrv->VerifyFD(fd);
2020-11-08 19:11:34 +11:00
if (nv_result != NvResult::Success) {
LOG_ERROR(Service_NVDRV, "Invalid FD specified DeviceFD={}!", fd);
ServiceError(ctx, nv_result);
return;
}
2019-07-01 11:10:27 -04:00
if (event_id < MaxNvEvents) {
2020-11-08 19:11:34 +11:00
IPC::ResponseBuilder rb{ctx, 3, 1};
rb.Push(RESULT_SUCCESS);
2019-09-26 18:11:27 -04:00
auto event = nvdrv->GetEvent(event_id);
event->Clear();
rb.PushCopyObjects(event);
2020-11-08 19:11:34 +11:00
rb.PushEnum(NvResult::Success);
} else {
2020-11-08 19:11:34 +11:00
IPC::ResponseBuilder rb{ctx, 3};
rb.Push(RESULT_SUCCESS);
rb.PushEnum(NvResult::BadParameter);
}
2018-02-05 18:19:31 -08:00
}
2020-06-29 04:01:34 +02:00
void NVDRV::SetAruid(Kernel::HLERequestContext& ctx) {
2018-01-18 23:50:18 -05:00
IPC::RequestParser rp{ctx};
pid = rp.Pop<u64>();
2018-07-02 10:13:26 -06:00
LOG_WARNING(Service_NVDRV, "(STUBBED) called, pid=0x{:X}", pid);
IPC::ResponseBuilder rb{ctx, 3};
2018-01-18 23:50:18 -05:00
rb.Push(RESULT_SUCCESS);
2020-11-08 19:11:34 +11:00
rb.PushEnum(NvResult::Success);
2018-01-18 23:50:18 -05:00
}
2020-06-29 04:01:34 +02:00
void NVDRV::SetGraphicsFirmwareMemoryMarginEnabled(Kernel::HLERequestContext& ctx) {
2018-07-02 10:13:26 -06:00
LOG_WARNING(Service_NVDRV, "(STUBBED) called");
2018-02-05 18:19:31 -08:00
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(RESULT_SUCCESS);
}
void NVDRV::GetStatus(Kernel::HLERequestContext& ctx) {
LOG_WARNING(Service_NVDRV, "(STUBBED) called");
2020-11-08 19:11:34 +11:00
IPC::ResponseBuilder rb{ctx, 3};
rb.Push(RESULT_SUCCESS);
2020-11-08 19:11:34 +11:00
rb.PushEnum(NvResult::Success);
}
void NVDRV::DumpGraphicsMemoryInfo(Kernel::HLERequestContext& ctx) {
// According to SwitchBrew, this has no inputs and no outputs, so effectively does nothing on
// retail hardware.
LOG_DEBUG(Service_NVDRV, "called");
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(RESULT_SUCCESS);
}
NVDRV::NVDRV(Core::System& system_, std::shared_ptr<Module> nvdrv_, const char* name)
: ServiceFramework{system_, name}, nvdrv{std::move(nvdrv_)} {
static const FunctionInfo functions[] = {
{0, &NVDRV::Open, "Open"},
2020-11-08 19:11:34 +11:00
{1, &NVDRV::Ioctl1, "Ioctl"},
2018-01-17 17:08:46 +01:00
{2, &NVDRV::Close, "Close"},
{3, &NVDRV::Initialize, "Initialize"},
2018-02-05 18:19:31 -08:00
{4, &NVDRV::QueryEvent, "QueryEvent"},
2018-04-10 20:26:49 +03:00
{5, nullptr, "MapSharedMem"},
{6, &NVDRV::GetStatus, "GetStatus"},
2020-06-29 04:01:34 +02:00
{7, nullptr, "SetAruidForTest"},
{8, &NVDRV::SetAruid, "SetAruid"},
{9, &NVDRV::DumpGraphicsMemoryInfo, "DumpGraphicsMemoryInfo"},
2018-04-10 20:26:49 +03:00
{10, nullptr, "InitializeDevtools"},
2019-09-19 15:37:25 +10:00
{11, &NVDRV::Ioctl2, "Ioctl2"},
{12, &NVDRV::Ioctl3, "Ioctl3"},
2020-06-29 04:01:34 +02:00
{13, &NVDRV::SetGraphicsFirmwareMemoryMarginEnabled,
"SetGraphicsFirmwareMemoryMarginEnabled"},
};
RegisterHandlers(functions);
}
NVDRV::~NVDRV() = default;
} // namespace Service::Nvidia