usb.cpp 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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() : ServiceFramework{"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() : ServiceFramework{"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() : ServiceFramework{"IClientEpSession"} {
  61. // clang-format off
  62. static const FunctionInfo functions[] = {
  63. {0, nullptr, "Open"},
  64. {1, nullptr, "Close"},
  65. {2, nullptr, "Unknown2"},
  66. {3, nullptr, "Populate"},
  67. {4, nullptr, "PostBufferAsync"},
  68. {5, nullptr, "GetXferReport"},
  69. {6, nullptr, "PostBufferMultiAsync"},
  70. {7, nullptr, "Unknown7"},
  71. {8, nullptr, "Unknown8"},
  72. };
  73. // clang-format on
  74. RegisterHandlers(functions);
  75. }
  76. };
  77. class IClientIfSession final : public ServiceFramework<IClientIfSession> {
  78. public:
  79. explicit IClientIfSession() : ServiceFramework{"IClientIfSession"} {
  80. // clang-format off
  81. static const FunctionInfo functions[] = {
  82. {0, nullptr, "Unknown0"},
  83. {1, nullptr, "SetInterface"},
  84. {2, nullptr, "GetInterface"},
  85. {3, nullptr, "GetAlternateInterface"},
  86. {4, nullptr, "GetCurrentFrame"},
  87. {5, nullptr, "CtrlXferAsync"},
  88. {6, nullptr, "Unknown6"},
  89. {7, nullptr, "GetCtrlXferReport"},
  90. {8, nullptr, "ResetDevice"},
  91. {9, nullptr, "OpenUsbEp"},
  92. };
  93. // clang-format on
  94. RegisterHandlers(functions);
  95. }
  96. };
  97. class USB_HS final : public ServiceFramework<USB_HS> {
  98. public:
  99. explicit USB_HS() : ServiceFramework{"usb:hs"} {
  100. // clang-format off
  101. static const FunctionInfo functions[] = {
  102. {0, nullptr, "BindClientProcess"},
  103. {1, nullptr, "QueryAllInterfaces"},
  104. {2, nullptr, "QueryAvailableInterfaces"},
  105. {3, nullptr, "QueryAcquiredInterfaces"},
  106. {4, nullptr, "CreateInterfaceAvailableEvent"},
  107. {5, nullptr, "DestroyInterfaceAvailableEvent"},
  108. {6, nullptr, "GetInterfaceStateChangeEvent"},
  109. {7, nullptr, "AcquireUsbIf"},
  110. {8, nullptr, "Unknown8"},
  111. };
  112. // clang-format on
  113. RegisterHandlers(functions);
  114. }
  115. };
  116. class IPdSession final : public ServiceFramework<IPdSession> {
  117. public:
  118. explicit IPdSession() : ServiceFramework{"IPdSession"} {
  119. // clang-format off
  120. static const FunctionInfo functions[] = {
  121. {0, nullptr, "BindNoticeEvent"},
  122. {1, nullptr, "UnbindNoticeEvent"},
  123. {2, nullptr, "GetStatus"},
  124. {3, nullptr, "GetNotice"},
  125. {4, nullptr, "EnablePowerRequestNotice"},
  126. {5, nullptr, "DisablePowerRequestNotice"},
  127. {6, nullptr, "ReplyPowerRequest"},
  128. };
  129. // clang-format on
  130. RegisterHandlers(functions);
  131. }
  132. };
  133. class USB_PD final : public ServiceFramework<USB_PD> {
  134. public:
  135. explicit USB_PD() : ServiceFramework{"usb:pd"} {
  136. // clang-format off
  137. static const FunctionInfo functions[] = {
  138. {0, &USB_PD::GetPdSession, "GetPdSession"},
  139. };
  140. // clang-format on
  141. RegisterHandlers(functions);
  142. }
  143. private:
  144. void GetPdSession(Kernel::HLERequestContext& ctx) {
  145. LOG_DEBUG(Service_USB, "called");
  146. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  147. rb.Push(RESULT_SUCCESS);
  148. rb.PushIpcInterface<IPdSession>();
  149. }
  150. };
  151. class IPdCradleSession final : public ServiceFramework<IPdCradleSession> {
  152. public:
  153. explicit IPdCradleSession() : ServiceFramework{"IPdCradleSession"} {
  154. // clang-format off
  155. static const FunctionInfo functions[] = {
  156. {0, nullptr, "VdmUserWrite"},
  157. {1, nullptr, "VdmUserRead"},
  158. {2, nullptr, "Vdm20Init"},
  159. {3, nullptr, "GetFwType"},
  160. {4, nullptr, "GetFwRevision"},
  161. {5, nullptr, "GetManufacturerId"},
  162. {6, nullptr, "GetDeviceId"},
  163. {7, nullptr, "Unknown7"},
  164. {8, nullptr, "Unknown8"},
  165. };
  166. // clang-format on
  167. RegisterHandlers(functions);
  168. }
  169. };
  170. class USB_PD_C final : public ServiceFramework<USB_PD_C> {
  171. public:
  172. explicit USB_PD_C() : ServiceFramework{"usb:pd:c"} {
  173. // clang-format off
  174. static const FunctionInfo functions[] = {
  175. {0, &USB_PD_C::GetPdCradleSession, "GetPdCradleSession"},
  176. };
  177. // clang-format on
  178. RegisterHandlers(functions);
  179. }
  180. private:
  181. void GetPdCradleSession(Kernel::HLERequestContext& ctx) {
  182. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  183. rb.Push(RESULT_SUCCESS);
  184. rb.PushIpcInterface<IPdCradleSession>();
  185. LOG_DEBUG(Service_USB, "called");
  186. }
  187. };
  188. class USB_PM final : public ServiceFramework<USB_PM> {
  189. public:
  190. explicit USB_PM() : ServiceFramework{"usb:pm"} {
  191. // clang-format off
  192. static const FunctionInfo functions[] = {
  193. {0, nullptr, "Unknown0"},
  194. {1, nullptr, "Unknown1"},
  195. {2, nullptr, "Unknown2"},
  196. {3, nullptr, "Unknown3"},
  197. {4, nullptr, "Unknown4"},
  198. {5, nullptr, "Unknown5"},
  199. };
  200. // clang-format on
  201. RegisterHandlers(functions);
  202. }
  203. };
  204. void InstallInterfaces(SM::ServiceManager& sm) {
  205. std::make_shared<USB_DS>()->InstallAsService(sm);
  206. std::make_shared<USB_HS>()->InstallAsService(sm);
  207. std::make_shared<USB_PD>()->InstallAsService(sm);
  208. std::make_shared<USB_PD_C>()->InstallAsService(sm);
  209. std::make_shared<USB_PM>()->InstallAsService(sm);
  210. }
  211. } // namespace Service::USB