service.cpp 5.4 KB

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