interface.cpp 3.2 KB

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