pcv.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include <memory>
  4. #include "core/hle/ipc_helpers.h"
  5. #include "core/hle/service/pcv/pcv.h"
  6. #include "core/hle/service/service.h"
  7. #include "core/hle/service/sm/sm.h"
  8. namespace Service::PCV {
  9. class PCV final : public ServiceFramework<PCV> {
  10. public:
  11. explicit PCV(Core::System& system_) : ServiceFramework{system_, "pcv"} {
  12. // clang-format off
  13. static const FunctionInfo functions[] = {
  14. {0, nullptr, "SetPowerEnabled"},
  15. {1, nullptr, "SetClockEnabled"},
  16. {2, nullptr, "SetClockRate"},
  17. {3, nullptr, "GetClockRate"},
  18. {4, nullptr, "GetState"},
  19. {5, nullptr, "GetPossibleClockRates"},
  20. {6, nullptr, "SetMinVClockRate"},
  21. {7, nullptr, "SetReset"},
  22. {8, nullptr, "SetVoltageEnabled"},
  23. {9, nullptr, "GetVoltageEnabled"},
  24. {10, nullptr, "GetVoltageRange"},
  25. {11, nullptr, "SetVoltageValue"},
  26. {12, nullptr, "GetVoltageValue"},
  27. {13, nullptr, "GetTemperatureThresholds"},
  28. {14, nullptr, "SetTemperature"},
  29. {15, nullptr, "Initialize"},
  30. {16, nullptr, "IsInitialized"},
  31. {17, nullptr, "Finalize"},
  32. {18, nullptr, "PowerOn"},
  33. {19, nullptr, "PowerOff"},
  34. {20, nullptr, "ChangeVoltage"},
  35. {21, nullptr, "GetPowerClockInfoEvent"},
  36. {22, nullptr, "GetOscillatorClock"},
  37. {23, nullptr, "GetDvfsTable"},
  38. {24, nullptr, "GetModuleStateTable"},
  39. {25, nullptr, "GetPowerDomainStateTable"},
  40. {26, nullptr, "GetFuseInfo"},
  41. {27, nullptr, "GetDramId"},
  42. {28, nullptr, "IsPoweredOn"},
  43. {29, nullptr, "GetVoltage"},
  44. };
  45. // clang-format on
  46. RegisterHandlers(functions);
  47. }
  48. };
  49. class IClkrstSession final : public ServiceFramework<IClkrstSession> {
  50. public:
  51. explicit IClkrstSession(Core::System& system_, DeviceCode deivce_code_)
  52. : ServiceFramework{system_, "IClkrstSession"}, deivce_code(deivce_code_) {
  53. // clang-format off
  54. static const FunctionInfo functions[] = {
  55. {0, nullptr, "SetClockEnabled"},
  56. {1, nullptr, "SetClockDisabled"},
  57. {2, nullptr, "SetResetAsserted"},
  58. {3, nullptr, "SetResetDeasserted"},
  59. {4, nullptr, "SetPowerEnabled"},
  60. {5, nullptr, "SetPowerDisabled"},
  61. {6, nullptr, "GetState"},
  62. {7, &IClkrstSession::SetClockRate, "SetClockRate"},
  63. {8, &IClkrstSession::GetClockRate, "GetClockRate"},
  64. {9, nullptr, "SetMinVClockRate"},
  65. {10, nullptr, "GetPossibleClockRates"},
  66. {11, nullptr, "GetDvfsTable"},
  67. };
  68. // clang-format on
  69. RegisterHandlers(functions);
  70. }
  71. private:
  72. void SetClockRate(Kernel::HLERequestContext& ctx) {
  73. IPC::RequestParser rp{ctx};
  74. clock_rate = rp.Pop<u32>();
  75. LOG_DEBUG(Service_PCV, "(STUBBED) called, clock_rate={}", clock_rate);
  76. IPC::ResponseBuilder rb{ctx, 2};
  77. rb.Push(ResultSuccess);
  78. }
  79. void GetClockRate(Kernel::HLERequestContext& ctx) {
  80. LOG_DEBUG(Service_PCV, "(STUBBED) called");
  81. IPC::ResponseBuilder rb{ctx, 3};
  82. rb.Push(ResultSuccess);
  83. rb.Push<u32>(clock_rate);
  84. }
  85. DeviceCode deivce_code;
  86. u32 clock_rate{};
  87. };
  88. class CLKRST final : public ServiceFramework<CLKRST> {
  89. public:
  90. explicit CLKRST(Core::System& system_, const char* name) : ServiceFramework{system_, name} {
  91. // clang-format off
  92. static const FunctionInfo functions[] = {
  93. {0, &CLKRST::OpenSession, "OpenSession"},
  94. {1, nullptr, "GetTemperatureThresholds"},
  95. {2, nullptr, "SetTemperature"},
  96. {3, nullptr, "GetModuleStateTable"},
  97. {4, nullptr, "GetModuleStateTableEvent"},
  98. {5, nullptr, "GetModuleStateTableMaxCount"},
  99. };
  100. // clang-format on
  101. RegisterHandlers(functions);
  102. }
  103. private:
  104. void OpenSession(Kernel::HLERequestContext& ctx) {
  105. IPC::RequestParser rp{ctx};
  106. const auto device_code = static_cast<DeviceCode>(rp.Pop<u32>());
  107. const auto unkonwn_input = rp.Pop<u32>();
  108. LOG_DEBUG(Service_PCV, "called, device_code={}, input={}", device_code, unkonwn_input);
  109. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  110. rb.Push(ResultSuccess);
  111. rb.PushIpcInterface<IClkrstSession>(system, device_code);
  112. }
  113. };
  114. class CLKRST_A final : public ServiceFramework<CLKRST_A> {
  115. public:
  116. explicit CLKRST_A(Core::System& system_) : ServiceFramework{system_, "clkrst:a"} {
  117. // clang-format off
  118. static const FunctionInfo functions[] = {
  119. {0, nullptr, "ReleaseControl"},
  120. };
  121. // clang-format on
  122. RegisterHandlers(functions);
  123. }
  124. };
  125. void InstallInterfaces(SM::ServiceManager& sm, Core::System& system) {
  126. std::make_shared<PCV>(system)->InstallAsService(sm);
  127. std::make_shared<CLKRST>(system, "clkrst")->InstallAsService(sm);
  128. std::make_shared<CLKRST>(system, "clkrst:i")->InstallAsService(sm);
  129. std::make_shared<CLKRST_A>(system)->InstallAsService(sm);
  130. }
  131. } // namespace Service::PCV