diff --git a/src/clocks.cpp b/src/clocks.cpp index 35938046..43a4c36c 100644 --- a/src/clocks.cpp +++ b/src/clocks.cpp @@ -41,9 +41,6 @@ void Clocks::Initialize() rc = pcvInitialize(); ASSERT_RESULT_OK(rc, "pcvInitialize"); - rc = apmInitialize(); - ASSERT_RESULT_OK(rc, "apmInitialize"); - rc = apmExtInitialize(); ASSERT_RESULT_OK(rc, "apmExtInitialize"); @@ -54,7 +51,7 @@ void Clocks::Initialize() void Clocks::Exit() { pcvExit(); - apmExit(); + apmExtExit(); psmExit(); } @@ -96,17 +93,15 @@ std::string Clocks::GetProfileName(ClockProfile profile, bool pretty) return ""; } -void Clocks::ResetToStock() { +std::uint32_t Clocks::ResetToStock() { std::uint32_t mode = 0; Result rc = apmExtGetPerformanceMode(&mode); ASSERT_RESULT_OK(rc, "apmExtGetPerformanceMode"); - std::uint32_t conf = 0; - rc = apmGetPerformanceConfiguration(mode, &conf); - ASSERT_RESULT_OK(rc, "apmGetPerformanceConfiguration"); + rc = apmExtSysRequestPerformanceMode(mode); + ASSERT_RESULT_OK(rc, "apmExtSysRequestPerformanceMode"); - rc = apmSetPerformanceConfiguration(mode, conf); - ASSERT_RESULT_OK(rc, "apmSetPerformanceConfiguration"); + return mode; } ClockProfile Clocks::GetCurrentProfile() diff --git a/src/clocks.h b/src/clocks.h index d8398743..5c0a5cc5 100644 --- a/src/clocks.h +++ b/src/clocks.h @@ -26,7 +26,7 @@ class Clocks public: static void Exit(); static void Initialize(); - static void ResetToStock(); + static std::uint32_t ResetToStock(); static ClockProfile GetCurrentProfile(); static std::uint32_t GetCurrentHz(PcvModule module); static void SetHz(PcvModule module, std::uint32_t hz); diff --git a/src/ipc/apm_ext.c b/src/ipc/apm_ext.c index 0cdb2841..663814c5 100644 --- a/src/ipc/apm_ext.c +++ b/src/ipc/apm_ext.c @@ -11,6 +11,7 @@ #include "apm_ext.h" static Service g_apmSrv; +static Service g_apmSysSrv; static u64 g_refCnt; Result apmExtInitialize(void) @@ -25,6 +26,9 @@ Result apmExtInitialize(void) Result rc = 0; rc = smGetService(&g_apmSrv, "apm"); + if(R_SUCCEEDED(rc)) { + rc = smGetService(&g_apmSysSrv, "apm:sys"); + } if (R_FAILED(rc)) { @@ -39,6 +43,7 @@ void apmExtExit(void) if (atomicDecrement64(&g_refCnt) == 0) { serviceClose(&g_apmSrv); + serviceClose(&g_apmSysSrv); } } @@ -82,3 +87,40 @@ Result apmExtGetPerformanceMode(u32 *out_mode) return rc; } + +Result apmExtSysRequestPerformanceMode(u32 mode) +{ + IpcCommand c; + ipcInitialize(&c); + + struct + { + u64 magic; + u64 cmd_id; + u32 mode; + } *raw; + + raw = ipcPrepareHeader(&c, sizeof(*raw)); + + raw->magic = SFCI_MAGIC; + raw->cmd_id = 0; + raw->mode = mode; + + Result rc = serviceIpcDispatch(&g_apmSysSrv); + + if (R_SUCCEEDED(rc)) + { + IpcParsedCommand r; + ipcParse(&r); + + struct + { + u64 magic; + u64 result; + } *resp = r.Raw; + + rc = resp->result; + } + + return rc; +} diff --git a/src/ipc/apm_ext.h b/src/ipc/apm_ext.h index 156672c2..24433b65 100644 --- a/src/ipc/apm_ext.h +++ b/src/ipc/apm_ext.h @@ -21,6 +21,7 @@ extern "C" void apmExtExit(void); Result apmExtGetPerformanceMode(u32 *out_mode); + Result apmExtSysRequestPerformanceMode(u32 mode); #ifdef __cplusplus }