interface.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. // Copyright 2018 yuzu emulator team
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <cinttypes>
  5. #include "common/logging/log.h"
  6. #include "core/core.h"
  7. #include "core/hle/ipc_helpers.h"
  8. #include "core/hle/kernel/kernel.h"
  9. #include "core/hle/kernel/readable_event.h"
  10. #include "core/hle/kernel/writable_event.h"
  11. #include "core/hle/service/nvdrv/interface.h"
  12. #include "core/hle/service/nvdrv/nvdrv.h"
  13. namespace Service::Nvidia {
  14. void NVDRV::Open(Kernel::HLERequestContext& ctx) {
  15. LOG_DEBUG(Service_NVDRV, "called");
  16. const auto& buffer = ctx.ReadBuffer();
  17. std::string device_name(buffer.begin(), buffer.end());
  18. u32 fd = nvdrv->Open(device_name);
  19. IPC::ResponseBuilder rb{ctx, 4};
  20. rb.Push(RESULT_SUCCESS);
  21. rb.Push<u32>(fd);
  22. rb.Push<u32>(0);
  23. }
  24. void NVDRV::Ioctl(Kernel::HLERequestContext& ctx) {
  25. LOG_DEBUG(Service_NVDRV, "called");
  26. IPC::RequestParser rp{ctx};
  27. u32 fd = rp.Pop<u32>();
  28. u32 command = rp.Pop<u32>();
  29. std::vector<u8> output(ctx.GetWriteBufferSize());
  30. IPC::ResponseBuilder rb{ctx, 3};
  31. rb.Push(RESULT_SUCCESS);
  32. rb.Push(nvdrv->Ioctl(fd, command, ctx.ReadBuffer(), output));
  33. ctx.WriteBuffer(output);
  34. }
  35. void NVDRV::Close(Kernel::HLERequestContext& ctx) {
  36. LOG_DEBUG(Service_NVDRV, "called");
  37. IPC::RequestParser rp{ctx};
  38. u32 fd = rp.Pop<u32>();
  39. auto result = nvdrv->Close(fd);
  40. IPC::ResponseBuilder rb{ctx, 2};
  41. rb.Push(result);
  42. }
  43. void NVDRV::Initialize(Kernel::HLERequestContext& ctx) {
  44. LOG_WARNING(Service_NVDRV, "(STUBBED) called");
  45. IPC::ResponseBuilder rb{ctx, 3};
  46. rb.Push(RESULT_SUCCESS);
  47. rb.Push<u32>(0);
  48. }
  49. void NVDRV::QueryEvent(Kernel::HLERequestContext& ctx) {
  50. IPC::RequestParser rp{ctx};
  51. u32 fd = rp.Pop<u32>();
  52. u32 event_id = rp.Pop<u32>();
  53. LOG_WARNING(Service_NVDRV, "(STUBBED) called, fd={:X}, event_id={:X}", fd, event_id);
  54. IPC::ResponseBuilder rb{ctx, 3, 1};
  55. rb.Push(RESULT_SUCCESS);
  56. rb.PushCopyObjects(query_event.readable);
  57. rb.Push<u32>(0);
  58. }
  59. void NVDRV::SetClientPID(Kernel::HLERequestContext& ctx) {
  60. IPC::RequestParser rp{ctx};
  61. pid = rp.Pop<u64>();
  62. LOG_WARNING(Service_NVDRV, "(STUBBED) called, pid=0x{:X}", pid);
  63. IPC::ResponseBuilder rb{ctx, 3};
  64. rb.Push(RESULT_SUCCESS);
  65. rb.Push<u32>(0);
  66. }
  67. void NVDRV::FinishInitialize(Kernel::HLERequestContext& ctx) {
  68. LOG_WARNING(Service_NVDRV, "(STUBBED) called");
  69. IPC::ResponseBuilder rb{ctx, 2};
  70. rb.Push(RESULT_SUCCESS);
  71. }
  72. void NVDRV::GetStatus(Kernel::HLERequestContext& ctx) {
  73. LOG_WARNING(Service_NVDRV, "(STUBBED) called");
  74. IPC::ResponseBuilder rb{ctx, 2};
  75. rb.Push(RESULT_SUCCESS);
  76. }
  77. void NVDRV::DumpGraphicsMemoryInfo(Kernel::HLERequestContext& ctx) {
  78. // According to SwitchBrew, this has no inputs and no outputs, so effectively does nothing on
  79. // retail hardware.
  80. LOG_DEBUG(Service_NVDRV, "called");
  81. IPC::ResponseBuilder rb{ctx, 2};
  82. rb.Push(RESULT_SUCCESS);
  83. }
  84. NVDRV::NVDRV(std::shared_ptr<Module> nvdrv, const char* name)
  85. : ServiceFramework(name), nvdrv(std::move(nvdrv)) {
  86. static const FunctionInfo functions[] = {
  87. {0, &NVDRV::Open, "Open"},
  88. {1, &NVDRV::Ioctl, "Ioctl"},
  89. {2, &NVDRV::Close, "Close"},
  90. {3, &NVDRV::Initialize, "Initialize"},
  91. {4, &NVDRV::QueryEvent, "QueryEvent"},
  92. {5, nullptr, "MapSharedMem"},
  93. {6, &NVDRV::GetStatus, "GetStatus"},
  94. {7, nullptr, "ForceSetClientPID"},
  95. {8, &NVDRV::SetClientPID, "SetClientPID"},
  96. {9, &NVDRV::DumpGraphicsMemoryInfo, "DumpGraphicsMemoryInfo"},
  97. {10, nullptr, "InitializeDevtools"},
  98. {11, &NVDRV::Ioctl, "Ioctl2"},
  99. {12, nullptr, "Ioctl3"},
  100. {13, &NVDRV::FinishInitialize, "FinishInitialize"},
  101. };
  102. RegisterHandlers(functions);
  103. auto& kernel = Core::System::GetInstance().Kernel();
  104. query_event = Kernel::WritableEvent::CreateEventPair(kernel, Kernel::ResetType::Automatic,
  105. "NVDRV::query_event");
  106. }
  107. NVDRV::~NVDRV() = default;
  108. } // namespace Service::Nvidia