usb.cpp 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. // Copyright 2018 yuzu emulator team
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <memory>
  5. #include "common/logging/log.h"
  6. #include "core/hle/ipc_helpers.h"
  7. #include "core/hle/kernel/hle_ipc.h"
  8. #include "core/hle/service/service.h"
  9. #include "core/hle/service/sm/sm.h"
  10. #include "core/hle/service/usb/usb.h"
  11. namespace Service::USB {
  12. class IDsInterface final : public ServiceFramework<IDsInterface> {
  13. public:
  14. explicit IDsInterface(Core::System& system_) : ServiceFramework{system_, "IDsInterface"} {
  15. // clang-format off
  16. static const FunctionInfo functions[] = {
  17. {0, nullptr, "GetDsEndpoint"},
  18. {1, nullptr, "GetSetupEvent"},
  19. {2, nullptr, "Unknown2"},
  20. {3, nullptr, "EnableInterface"},
  21. {4, nullptr, "DisableInterface"},
  22. {5, nullptr, "CtrlInPostBufferAsync"},
  23. {6, nullptr, "CtrlOutPostBufferAsync"},
  24. {7, nullptr, "GetCtrlInCompletionEvent"},
  25. {8, nullptr, "GetCtrlInReportData"},
  26. {9, nullptr, "GetCtrlOutCompletionEvent"},
  27. {10, nullptr, "GetCtrlOutReportData"},
  28. {11, nullptr, "StallCtrl"},
  29. {12, nullptr, "AppendConfigurationData"},
  30. };
  31. // clang-format on
  32. RegisterHandlers(functions);
  33. }
  34. };
  35. class USB_DS final : public ServiceFramework<USB_DS> {
  36. public:
  37. explicit USB_DS(Core::System& system_) : ServiceFramework{system_, "usb:ds"} {
  38. // clang-format off
  39. static const FunctionInfo functions[] = {
  40. {0, nullptr, "BindDevice"},
  41. {1, nullptr, "BindClientProcess"},
  42. {2, nullptr, "GetDsInterface"},
  43. {3, nullptr, "GetStateChangeEvent"},
  44. {4, nullptr, "GetState"},
  45. {5, nullptr, "ClearDeviceData"},
  46. {6, nullptr, "AddUsbStringDescriptor"},
  47. {7, nullptr, "DeleteUsbStringDescriptor"},
  48. {8, nullptr, "SetUsbDeviceDescriptor"},
  49. {9, nullptr, "SetBinaryObjectStore"},
  50. {10, nullptr, "Enable"},
  51. {11, nullptr, "Disable"},
  52. {12, nullptr, "Unknown12"},
  53. };
  54. // clang-format on
  55. RegisterHandlers(functions);
  56. }
  57. };
  58. class IClientEpSession final : public ServiceFramework<IClientEpSession> {
  59. public:
  60. explicit IClientEpSession(Core::System& system_)
  61. : ServiceFramework{system_, "IClientEpSession"} {
  62. // clang-format off
  63. static const FunctionInfo functions[] = {
  64. {0, nullptr, "ReOpen"},
  65. {1, nullptr, "Close"},
  66. {2, nullptr, "GetCompletionEvent"},
  67. {3, nullptr, "PopulateRing"},
  68. {4, nullptr, "PostBufferAsync"},
  69. {5, nullptr, "GetXferReport"},
  70. {6, nullptr, "PostBufferMultiAsync"},
  71. {7, nullptr, "CreateSmmuSpace"},
  72. {8, nullptr, "ShareReportRing"},
  73. };
  74. // clang-format on
  75. RegisterHandlers(functions);
  76. }
  77. };
  78. class IClientIfSession final : public ServiceFramework<IClientIfSession> {
  79. public:
  80. explicit IClientIfSession(Core::System& system_)
  81. : ServiceFramework{system_, "IClientIfSession"} {
  82. // clang-format off
  83. static const FunctionInfo functions[] = {
  84. {0, nullptr, "GetStateChangeEvent"},
  85. {1, nullptr, "SetInterface"},
  86. {2, nullptr, "GetInterface"},
  87. {3, nullptr, "GetAlternateInterface"},
  88. {4, nullptr, "GetCurrentFrame"},
  89. {5, nullptr, "CtrlXferAsync"},
  90. {6, nullptr, "GetCtrlXferCompletionEvent"},
  91. {7, nullptr, "GetCtrlXferReport"},
  92. {8, nullptr, "ResetDevice"},
  93. {9, nullptr, "OpenUsbEp"},
  94. };
  95. // clang-format on
  96. RegisterHandlers(functions);
  97. }
  98. };
  99. class USB_HS final : public ServiceFramework<USB_HS> {
  100. public:
  101. explicit USB_HS(Core::System& system_) : ServiceFramework{system_, "usb:hs"} {
  102. // clang-format off
  103. static const FunctionInfo functions[] = {
  104. {0, nullptr, "BindClientProcess"},
  105. {1, nullptr, "QueryAllInterfaces"},
  106. {2, nullptr, "QueryAvailableInterfaces"},
  107. {3, nullptr, "QueryAcquiredInterfaces"},
  108. {4, nullptr, "CreateInterfaceAvailableEvent"},
  109. {5, nullptr, "DestroyInterfaceAvailableEvent"},
  110. {6, nullptr, "GetInterfaceStateChangeEvent"},
  111. {7, nullptr, "AcquireUsbIf"},
  112. {8, nullptr, "Unknown8"},
  113. };
  114. // clang-format on
  115. RegisterHandlers(functions);
  116. }
  117. };
  118. class IPdSession final : public ServiceFramework<IPdSession> {
  119. public:
  120. explicit IPdSession(Core::System& system_) : ServiceFramework{system_, "IPdSession"} {
  121. // clang-format off
  122. static const FunctionInfo functions[] = {
  123. {0, nullptr, "BindNoticeEvent"},
  124. {1, nullptr, "UnbindNoticeEvent"},
  125. {2, nullptr, "GetStatus"},
  126. {3, nullptr, "GetNotice"},
  127. {4, nullptr, "EnablePowerRequestNotice"},
  128. {5, nullptr, "DisablePowerRequestNotice"},
  129. {6, nullptr, "ReplyPowerRequest"},
  130. };
  131. // clang-format on
  132. RegisterHandlers(functions);
  133. }
  134. };
  135. class USB_PD final : public ServiceFramework<USB_PD> {
  136. public:
  137. explicit USB_PD(Core::System& system_) : ServiceFramework{system_, "usb:pd"} {
  138. // clang-format off
  139. static const FunctionInfo functions[] = {
  140. {0, &USB_PD::GetPdSession, "GetPdSession"},
  141. };
  142. // clang-format on
  143. RegisterHandlers(functions);
  144. }
  145. private:
  146. void GetPdSession(Kernel::HLERequestContext& ctx) {
  147. LOG_DEBUG(Service_USB, "called");
  148. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  149. rb.Push(ResultSuccess);
  150. rb.PushIpcInterface<IPdSession>(system);
  151. }
  152. };
  153. class IPdCradleSession final : public ServiceFramework<IPdCradleSession> {
  154. public:
  155. explicit IPdCradleSession(Core::System& system_)
  156. : ServiceFramework{system_, "IPdCradleSession"} {
  157. // clang-format off
  158. static const FunctionInfo functions[] = {
  159. {0, nullptr, "SetCradleVdo"},
  160. {1, nullptr, "GetCradleVdo"},
  161. {2, nullptr, "ResetCradleUsbHub"},
  162. {3, nullptr, "GetHostPdcFirmwareType"},
  163. {4, nullptr, "GetHostPdcFirmwareRevision"},
  164. {5, nullptr, "GetHostPdcManufactureId"},
  165. {6, nullptr, "GetHostPdcDeviceId"},
  166. {7, nullptr, "EnableCradleRecovery"},
  167. {8, nullptr, "DisableCradleRecovery"},
  168. };
  169. // clang-format on
  170. RegisterHandlers(functions);
  171. }
  172. };
  173. class USB_PD_C final : public ServiceFramework<USB_PD_C> {
  174. public:
  175. explicit USB_PD_C(Core::System& system_) : ServiceFramework{system_, "usb:pd:c"} {
  176. // clang-format off
  177. static const FunctionInfo functions[] = {
  178. {0, &USB_PD_C::GetPdCradleSession, "GetPdCradleSession"},
  179. };
  180. // clang-format on
  181. RegisterHandlers(functions);
  182. }
  183. private:
  184. void GetPdCradleSession(Kernel::HLERequestContext& ctx) {
  185. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  186. rb.Push(ResultSuccess);
  187. rb.PushIpcInterface<IPdCradleSession>(system);
  188. LOG_DEBUG(Service_USB, "called");
  189. }
  190. };
  191. class USB_PM final : public ServiceFramework<USB_PM> {
  192. public:
  193. explicit USB_PM(Core::System& system_) : ServiceFramework{system_, "usb:pm"} {
  194. // clang-format off
  195. static const FunctionInfo functions[] = {
  196. {0, nullptr, "GetPowerEvent"},
  197. {1, nullptr, "GetPowerState"},
  198. {2, nullptr, "GetDataEvent"},
  199. {3, nullptr, "GetDataRole"},
  200. {4, nullptr, "SetDiagData"},
  201. {5, nullptr, "GetDiagData"},
  202. };
  203. // clang-format on
  204. RegisterHandlers(functions);
  205. }
  206. };
  207. void InstallInterfaces(SM::ServiceManager& sm, Core::System& system) {
  208. std::make_shared<USB_DS>(system)->InstallAsService(sm);
  209. std::make_shared<USB_HS>(system)->InstallAsService(sm);
  210. std::make_shared<USB_PD>(system)->InstallAsService(sm);
  211. std::make_shared<USB_PD_C>(system)->InstallAsService(sm);
  212. std::make_shared<USB_PM>(system)->InstallAsService(sm);
  213. }
  214. } // namespace Service::USB