usb.cpp 7.5 KB

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