Skip to content

Commit

Permalink
use apm:sys->RequestPerformanceMode to reset
Browse files Browse the repository at this point in the history
fixes #6
  • Loading branch information
p-sam committed Mar 8, 2019
1 parent 330e378 commit b4b44ee
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 11 deletions.
15 changes: 5 additions & 10 deletions src/clocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -54,7 +51,7 @@ void Clocks::Initialize()
void Clocks::Exit()
{
pcvExit();
apmExit();
apmExtExit();
psmExit();
}

Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/clocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
42 changes: 42 additions & 0 deletions src/ipc/apm_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "apm_ext.h"

static Service g_apmSrv;
static Service g_apmSysSrv;
static u64 g_refCnt;

Result apmExtInitialize(void)
Expand All @@ -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))
{
Expand All @@ -39,6 +43,7 @@ void apmExtExit(void)
if (atomicDecrement64(&g_refCnt) == 0)
{
serviceClose(&g_apmSrv);
serviceClose(&g_apmSysSrv);
}
}

Expand Down Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions src/ipc/apm_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ extern "C"
void apmExtExit(void);

Result apmExtGetPerformanceMode(u32 *out_mode);
Result apmExtSysRequestPerformanceMode(u32 mode);

#ifdef __cplusplus
}
Expand Down

0 comments on commit b4b44ee

Please sign in to comment.