service.cpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include "common/logging/log.h"
  5. #include "common/string_util.h"
  6. #include "core/hle/service/ac_u.h"
  7. #include "core/hle/service/act_a.h"
  8. #include "core/hle/service/act_u.h"
  9. #include "core/hle/service/am/am.h"
  10. #include "core/hle/service/apt/apt.h"
  11. #include "core/hle/service/boss/boss.h"
  12. #include "core/hle/service/cam/cam.h"
  13. #include "core/hle/service/cecd/cecd.h"
  14. #include "core/hle/service/cfg/cfg.h"
  15. #include "core/hle/service/csnd_snd.h"
  16. #include "core/hle/service/dlp/dlp.h"
  17. #include "core/hle/service/dsp_dsp.h"
  18. #include "core/hle/service/err_f.h"
  19. #include "core/hle/service/frd/frd.h"
  20. #include "core/hle/service/fs/archive.h"
  21. #include "core/hle/service/gsp_gpu.h"
  22. #include "core/hle/service/gsp_lcd.h"
  23. #include "core/hle/service/hid/hid.h"
  24. #include "core/hle/service/http_c.h"
  25. #include "core/hle/service/ir/ir.h"
  26. #include "core/hle/service/ldr_ro/ldr_ro.h"
  27. #include "core/hle/service/mic_u.h"
  28. #include "core/hle/service/ndm/ndm.h"
  29. #include "core/hle/service/news/news.h"
  30. #include "core/hle/service/nim/nim.h"
  31. #include "core/hle/service/ns_s.h"
  32. #include "core/hle/service/nwm_uds.h"
  33. #include "core/hle/service/pm_app.h"
  34. #include "core/hle/service/ptm/ptm.h"
  35. #include "core/hle/service/service.h"
  36. #include "core/hle/service/soc_u.h"
  37. #include "core/hle/service/srv.h"
  38. #include "core/hle/service/ssl_c.h"
  39. #include "core/hle/service/y2r_u.h"
  40. namespace Service {
  41. std::unordered_map<std::string, Kernel::SharedPtr<Kernel::ClientPort>> g_kernel_named_ports;
  42. std::unordered_map<std::string, Kernel::SharedPtr<Kernel::ClientPort>> g_srv_services;
  43. /**
  44. * Creates a function string for logging, complete with the name (or header code, depending
  45. * on what's passed in) the port name, and all the cmd_buff arguments.
  46. */
  47. static std::string MakeFunctionString(const char* name, const char* port_name,
  48. const u32* cmd_buff) {
  49. // Number of params == bits 0-5 + bits 6-11
  50. int num_params = (cmd_buff[0] & 0x3F) + ((cmd_buff[0] >> 6) & 0x3F);
  51. std::string function_string =
  52. Common::StringFromFormat("function '%s': port=%s", name, port_name);
  53. for (int i = 1; i <= num_params; ++i) {
  54. function_string += Common::StringFromFormat(", cmd_buff[%i]=0x%X", i, cmd_buff[i]);
  55. }
  56. return function_string;
  57. }
  58. ResultCode Interface::HandleSyncRequest(Kernel::SharedPtr<Kernel::ServerSession> server_session) {
  59. // TODO(Subv): Make use of the server_session in the HLE service handlers to distinguish which session triggered each command.
  60. u32* cmd_buff = Kernel::GetCommandBuffer();
  61. auto itr = m_functions.find(cmd_buff[0]);
  62. if (itr == m_functions.end() || itr->second.func == nullptr) {
  63. std::string function_name = (itr == m_functions.end())
  64. ? Common::StringFromFormat("0x%08X", cmd_buff[0])
  65. : itr->second.name;
  66. LOG_ERROR(
  67. Service, "unknown / unimplemented %s",
  68. MakeFunctionString(function_name.c_str(), GetPortName().c_str(), cmd_buff).c_str());
  69. // TODO(bunnei): Hack - ignore error
  70. cmd_buff[1] = 0;
  71. return RESULT_SUCCESS;
  72. }
  73. LOG_TRACE(Service, "%s",
  74. MakeFunctionString(itr->second.name, GetPortName().c_str(), cmd_buff).c_str());
  75. itr->second.func(this);
  76. return RESULT_SUCCESS; // TODO: Implement return from actual function, it should fail if the parameter translation fails
  77. }
  78. void Interface::Register(const FunctionInfo* functions, size_t n) {
  79. m_functions.reserve(n);
  80. for (size_t i = 0; i < n; ++i) {
  81. // Usually this array is sorted by id already, so hint to instead at the end
  82. m_functions.emplace_hint(m_functions.cend(), functions[i].id, functions[i]);
  83. }
  84. }
  85. ////////////////////////////////////////////////////////////////////////////////////////////////////
  86. // Module interface
  87. static void AddNamedPort(Interface* interface_) {
  88. auto client_port = Kernel::ClientPort::CreateForHLE(interface_->GetMaxSessions(), std::shared_ptr<Interface>(interface_));
  89. g_kernel_named_ports.emplace(interface_->GetPortName(), client_port);
  90. }
  91. void AddService(Interface* interface_) {
  92. auto client_port = Kernel::ClientPort::CreateForHLE(interface_->GetMaxSessions(), std::shared_ptr<Interface>(interface_));
  93. g_srv_services.emplace(interface_->GetPortName(), client_port);
  94. }
  95. /// Initialize ServiceManager
  96. void Init() {
  97. AddNamedPort(new SRV::Interface);
  98. AddNamedPort(new ERR_F::Interface);
  99. Service::FS::ArchiveInit();
  100. Service::AM::Init();
  101. Service::APT::Init();
  102. Service::BOSS::Init();
  103. Service::CAM::Init();
  104. Service::CECD::Init();
  105. Service::CFG::Init();
  106. Service::DLP::Init();
  107. Service::FRD::Init();
  108. Service::HID::Init();
  109. Service::IR::Init();
  110. Service::NEWS::Init();
  111. Service::NDM::Init();
  112. Service::NIM::Init();
  113. Service::PTM::Init();
  114. AddService(new AC_U::Interface);
  115. AddService(new ACT_A::Interface);
  116. AddService(new ACT_U::Interface);
  117. AddService(new CSND_SND::Interface);
  118. AddService(new DSP_DSP::Interface);
  119. AddService(new GSP_GPU::Interface);
  120. AddService(new GSP_LCD::Interface);
  121. AddService(new HTTP_C::Interface);
  122. AddService(new LDR_RO::Interface);
  123. AddService(new MIC_U::Interface);
  124. AddService(new NS_S::Interface);
  125. AddService(new NWM_UDS::Interface);
  126. AddService(new PM_APP::Interface);
  127. AddService(new SOC_U::Interface);
  128. AddService(new SSL_C::Interface);
  129. AddService(new Y2R_U::Interface);
  130. LOG_DEBUG(Service, "initialized OK");
  131. }
  132. /// Shutdown ServiceManager
  133. void Shutdown() {
  134. Service::PTM::Shutdown();
  135. Service::NDM::Shutdown();
  136. Service::NIM::Shutdown();
  137. Service::NEWS::Shutdown();
  138. Service::IR::Shutdown();
  139. Service::HID::Shutdown();
  140. Service::FRD::Shutdown();
  141. Service::DLP::Shutdown();
  142. Service::CFG::Shutdown();
  143. Service::CECD::Shutdown();
  144. Service::CAM::Shutdown();
  145. Service::BOSS::Shutdown();
  146. Service::APT::Shutdown();
  147. Service::AM::Shutdown();
  148. Service::FS::ArchiveShutdown();
  149. g_srv_services.clear();
  150. g_kernel_named_ports.clear();
  151. LOG_DEBUG(Service, "shutdown OK");
  152. }
  153. }