usb.cpp 7.3 KB

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