interface.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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/event.h"
  9. #include "core/hle/service/nvdrv/interface.h"
  10. #include "core/hle/service/nvdrv/nvdrv.h"
  11. namespace Service::Nvidia {
  12. void NVDRV::Open(Kernel::HLERequestContext& ctx) {
  13. LOG_DEBUG(Service_NVDRV, "called");
  14. const auto& buffer = ctx.ReadBuffer();
  15. std::string device_name(buffer.begin(), buffer.end());
  16. u32 fd = nvdrv->Open(device_name);
  17. IPC::ResponseBuilder rb{ctx, 4};
  18. rb.Push(RESULT_SUCCESS);
  19. rb.Push<u32>(fd);
  20. rb.Push<u32>(0);
  21. }
  22. void NVDRV::Ioctl(Kernel::HLERequestContext& ctx) {
  23. LOG_DEBUG(Service_NVDRV, "called");
  24. IPC::RequestParser rp{ctx};
  25. u32 fd = rp.Pop<u32>();
  26. u32 command = rp.Pop<u32>();
  27. std::vector<u8> output(ctx.GetWriteBufferSize());
  28. IPC::ResponseBuilder rb{ctx, 3};
  29. rb.Push(RESULT_SUCCESS);
  30. rb.Push(nvdrv->Ioctl(fd, command, ctx.ReadBuffer(), output));
  31. ctx.WriteBuffer(output);
  32. }
  33. void NVDRV::Close(Kernel::HLERequestContext& ctx) {
  34. LOG_DEBUG(Service_NVDRV, "called");
  35. IPC::RequestParser rp{ctx};
  36. u32 fd = rp.Pop<u32>();
  37. auto result = nvdrv->Close(fd);
  38. IPC::ResponseBuilder rb{ctx, 2};
  39. rb.Push(result);
  40. }
  41. void NVDRV::Initialize(Kernel::HLERequestContext& ctx) {
  42. LOG_WARNING(Service_NVDRV, "(STUBBED) called");
  43. IPC::ResponseBuilder rb{ctx, 3};
  44. rb.Push(RESULT_SUCCESS);
  45. rb.Push<u32>(0);
  46. }
  47. void NVDRV::QueryEvent(Kernel::HLERequestContext& ctx) {
  48. IPC::RequestParser rp{ctx};
  49. u32 fd = rp.Pop<u32>();
  50. u32 event_id = rp.Pop<u32>();
  51. LOG_WARNING(Service_NVDRV, "(STUBBED) called, fd={:X}, event_id={:X}", fd, event_id);
  52. IPC::ResponseBuilder rb{ctx, 3, 1};
  53. rb.Push(RESULT_SUCCESS);
  54. rb.PushCopyObjects(query_event);
  55. rb.Push<u32>(0);
  56. }
  57. void NVDRV::SetClientPID(Kernel::HLERequestContext& ctx) {
  58. IPC::RequestParser rp{ctx};
  59. pid = rp.Pop<u64>();
  60. LOG_WARNING(Service_NVDRV, "(STUBBED) called, pid=0x{:X}", pid);
  61. IPC::ResponseBuilder rb{ctx, 3};
  62. rb.Push(RESULT_SUCCESS);
  63. rb.Push<u32>(0);
  64. }
  65. void NVDRV::FinishInitialize(Kernel::HLERequestContext& ctx) {
  66. LOG_WARNING(Service_NVDRV, "(STUBBED) called");
  67. IPC::ResponseBuilder rb{ctx, 2};
  68. rb.Push(RESULT_SUCCESS);
  69. }
  70. NVDRV::NVDRV(std::shared_ptr<Module> nvdrv, const char* name)
  71. : ServiceFramework(name), nvdrv(std::move(nvdrv)) {
  72. static const FunctionInfo functions[] = {
  73. {0, &NVDRV::Open, "Open"},
  74. {1, &NVDRV::Ioctl, "Ioctl"},
  75. {2, &NVDRV::Close, "Close"},
  76. {3, &NVDRV::Initialize, "Initialize"},
  77. {4, &NVDRV::QueryEvent, "QueryEvent"},
  78. {5, nullptr, "MapSharedMem"},
  79. {6, nullptr, "GetStatus"},
  80. {7, nullptr, "ForceSetClientPID"},
  81. {8, &NVDRV::SetClientPID, "SetClientPID"},
  82. {9, nullptr, "DumpGraphicsMemoryInfo"},
  83. {10, nullptr, "InitializeDevtools"},
  84. {11, &NVDRV::Ioctl, "Ioctl2"},
  85. {12, nullptr, "Ioctl3"},
  86. {13, &NVDRV::FinishInitialize, "FinishInitialize"},
  87. };
  88. RegisterHandlers(functions);
  89. auto& kernel = Core::System::GetInstance().Kernel();
  90. query_event = Kernel::Event::Create(kernel, Kernel::ResetType::OneShot, "NVDRV::query_event");
  91. }
  92. } // namespace Service::Nvidia