diff --git a/libraries/libstratosphere/include/stratosphere/htclow/htclow_module_types.hpp b/libraries/libstratosphere/include/stratosphere/htclow/htclow_module_types.hpp index ef8c92e3f..f5a8817ef 100644 --- a/libraries/libstratosphere/include/stratosphere/htclow/htclow_module_types.hpp +++ b/libraries/libstratosphere/include/stratosphere/htclow/htclow_module_types.hpp @@ -20,7 +20,9 @@ namespace ams::htclow { enum class ModuleId : u8 { - /* ... */ + Htcfs = 1, + Htcmisc = 3, + Htcs = 4, }; struct ModuleType { diff --git a/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_service_channels.hpp b/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_service_channels.hpp index bcaf32b9f..d42bb45c0 100644 --- a/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_service_channels.hpp +++ b/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_service_channels.hpp @@ -20,20 +20,20 @@ namespace ams::htclow::ctrl { constexpr inline const impl::ChannelInternalType ServiceChannels[] = { { - .channel_id = 0, - .module_id = static_cast(1), + .channel_id = 0, /* TODO: htcfs::ChannelId? */ + .module_id = ModuleId::Htcfs, }, { - .channel_id = 1, - .module_id = static_cast(3), + .channel_id = 1, /* TODO: htcmisc::ServerChannelId? */ + .module_id = ModuleId::Htcmisc, }, { - .channel_id = 2, - .module_id = static_cast(3), + .channel_id = 2, /* TODO: htcmisc::ClientChannelId? */ + .module_id = ModuleId::Htcmisc, }, { - .channel_id = 0, - .module_id = static_cast(4), + .channel_id = 0, /* TODO: htcs::ChannelId? */ + .module_id = ModuleId::Htcs, }, }; diff --git a/stratosphere/htc/source/htc_main.cpp b/stratosphere/htc/source/htc_main.cpp index e9797aca1..17e0a5c03 100644 --- a/stratosphere/htc/source/htc_main.cpp +++ b/stratosphere/htc/source/htc_main.cpp @@ -153,6 +153,12 @@ namespace ams::htc { constexpr htclow::impl::DriverType DefaultHtclowDriverType = htclow::impl::DriverType::Usb; + constexpr inline size_t NumHtcsIpcThreads = 8; + + alignas(os::ThreadStackAlignment) u8 g_htc_ipc_thread_stack[4_KB]; + alignas(os::ThreadStackAlignment) u8 g_htcfs_ipc_thread_stack[4_KB]; + alignas(os::ThreadStackAlignment) u8 g_htcs_ipc_thread_stack[NumHtcsIpcThreads][4_KB]; + htclow::impl::DriverType GetHtclowDriverType() { /* Get the transport type. */ char transport[0x10]; @@ -178,6 +184,18 @@ namespace ams::htc { } } + void HtcIpcThreadFunction(void *arg) { + //htc::server::LoopHtcmiscServer(); + } + + void HtcfsIpcThreadFunction(void *arg) { + //htcfs::LoopHipcServer(); + } + + void HtcsIpcThreadFunction(void *arg) { + //htcs::server::LoopHipcServer(); + } + } } @@ -194,10 +212,65 @@ int main(int argc, char **argv) /* Initialize the htclow manager. */ htclow::HtclowManagerHolder::AddReference(); + ON_SCOPE_EXIT { htclow::HtclowManagerHolder::Release(); }; - /* TODO */ + /* Get the htclow manager. */ + auto *htclow_manager = htclow::HtclowManagerHolder::GetHtclowManager(); + + /* Initialize the htc misc server. */ + //htc::server::InitializeHtcmiscServer(htclow_manager); + + /* Create the htc misc ipc thread. */ + os::ThreadType htc_ipc_thread; + os::CreateThread(std::addressof(htc_ipc_thread), htc::HtcIpcThreadFunction, nullptr, htc::g_htc_ipc_thread_stack, sizeof(htc::g_htc_ipc_thread_stack), AMS_GET_SYSTEM_THREAD_PRIORITY(htc, HtcIpc)); + os::SetThreadNamePointer(std::addressof(htc_ipc_thread), AMS_GET_SYSTEM_THREAD_NAME(htc, HtcIpc)); + + /* Initialize the htcfs server. */ + //htcfs::Initialize(); + //htcfs::RegisterHipcServer(); + + /* Create the htcfs ipc thread. */ + os::ThreadType htcfs_ipc_thread; + os::CreateThread(std::addressof(htcfs_ipc_thread), htc::HtcfsIpcThreadFunction, nullptr, htc::g_htcfs_ipc_thread_stack, sizeof(htc::g_htcfs_ipc_thread_stack), AMS_GET_SYSTEM_THREAD_PRIORITY(htc, HtcfsIpc)); + os::SetThreadNamePointer(std::addressof(htcfs_ipc_thread), AMS_GET_SYSTEM_THREAD_NAME(htc, HtcfsIpc)); + + /* Initialize the htcs server. */ + //htcs::server::Initialize(); + //htcs::server::RegisterHipcServer(); + + /* Create the htcs ipc threads. */ + os::ThreadType htcs_ipc_threads[htc::NumHtcsIpcThreads]; + for (size_t i = 0; i < htc::NumHtcsIpcThreads; ++i) { + os::CreateThread(std::addressof(htcs_ipc_threads[i]), htc::HtcsIpcThreadFunction, nullptr, htc::g_htcs_ipc_thread_stack[i], sizeof(htc::g_htcs_ipc_thread_stack[i]), AMS_GET_SYSTEM_THREAD_PRIORITY(htc, HtcsIpc)); + os::SetThreadNamePointer(std::addressof(htcs_ipc_threads[i]), AMS_GET_SYSTEM_THREAD_NAME(htc, HtcsIpc)); + } + + /* Initialize psc. */ + //htc::server::InitializePowerStateMonitor(driver_type, htclow_manager); + + /* Start all threads. */ + os::StartThread(std::addressof(htc_ipc_thread)); + os::StartThread(std::addressof(htcfs_ipc_thread)); + for (size_t i = 0; i < htc::NumHtcsIpcThreads; ++i) { + os::StartThread(std::addressof(htcs_ipc_threads[i])); + } + + /* Loop psc monitor. */ + //htc::server::LoopMonitorPowerState(); + + /* Destroy all threads. */ + for (size_t i = 0; i < htc::NumHtcsIpcThreads; ++i) { + os::WaitThread(std::addressof(htcs_ipc_threads[i])); + os::DestroyThread(std::addressof(htcs_ipc_threads[i])); + } + os::WaitThread(std::addressof(htcfs_ipc_thread)); + os::DestroyThread(std::addressof(htcfs_ipc_thread)); + os::WaitThread(std::addressof(htc_ipc_thread)); + os::DestroyThread(std::addressof(htc_ipc_thread)); + + /* Finalize psc monitor. */ + //htc::server::FinalizePowerStateMonitor(); - /* Cleanup */ return 0; }