usb.cpp 8.0 KB

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