Sys-clk-OC: Fixed #41; Erista support added; Manager is deprecated
This commit is contained in:
@@ -58,7 +58,6 @@ ClockManager::ClockManager()
|
||||
|
||||
this->oc = new SysClkOcExtra;
|
||||
this->oc->systemCoreBoostCPU = false;
|
||||
this->oc->allowUnsafeFreq = false;
|
||||
this->oc->governor = false;
|
||||
this->oc->realProfile = SysClkProfile_Handheld;
|
||||
this->oc->maxMEMFreq = 0;
|
||||
@@ -138,7 +137,7 @@ uint32_t ClockManager::GetHz(SysClkModule module)
|
||||
if (hz)
|
||||
{
|
||||
/* Considering realProfile frequency limit */
|
||||
hz = Clocks::GetNearestHz(module, this->oc->realProfile, hz, this->oc->allowUnsafeFreq);
|
||||
hz = Clocks::GetNearestHz(module, this->oc->realProfile, hz);
|
||||
|
||||
if (module == SysClkModule_MEM && hz == MAX_MEM_CLOCK)
|
||||
{
|
||||
@@ -244,7 +243,8 @@ bool ClockManager::RefreshContext()
|
||||
bool hasChanged = this->config->Refresh();
|
||||
if (hasChanged) {
|
||||
this->rnxSync->ToggleSync(this->GetConfig()->GetConfigValue(SysClkConfigValue_SyncReverseNXMode));
|
||||
this->oc->allowUnsafeFreq = this->GetConfig()->GetConfigValue(SysClkConfigValue_AllowUnsafeFrequencies);
|
||||
bool allowUnsafe = this->GetConfig()->GetConfigValue(SysClkConfigValue_AllowUnsafeFrequencies);
|
||||
Clocks::SetAllowUnsafe(allowUnsafe);
|
||||
}
|
||||
|
||||
bool enabled = this->GetConfig()->Enabled();
|
||||
@@ -255,14 +255,6 @@ bool ClockManager::RefreshContext()
|
||||
hasChanged = true;
|
||||
}
|
||||
|
||||
bool governor = this->GetConfig()->GetConfigValue(SysClkConfigValue_GovernorExperimental);
|
||||
if (governor != this->oc->governor)
|
||||
{
|
||||
this->oc->governor = governor;
|
||||
FileUtils::LogLine("[mgr] Governor status: %s", governor ? "enabled" : "disabled");
|
||||
hasChanged = true;
|
||||
}
|
||||
|
||||
std::uint64_t applicationId = ProcessManagement::GetCurrentApplicationId();
|
||||
if (applicationId != this->context->applicationId)
|
||||
{
|
||||
@@ -274,8 +266,17 @@ bool ClockManager::RefreshContext()
|
||||
this->rnxSync->Reset(applicationId);
|
||||
}
|
||||
|
||||
bool governor = this->GetConfig()->GetConfigValue(SysClkConfigValue_GovernorExperimental);
|
||||
governor &= !this->GetConfig()->GetTitleGovernorDisabled(applicationId);
|
||||
if (governor != this->oc->governor)
|
||||
{
|
||||
this->oc->governor = governor;
|
||||
FileUtils::LogLine("[mgr] Governor status: %s", governor ? "enabled" : "disabled");
|
||||
hasChanged = true;
|
||||
}
|
||||
|
||||
if (hasChanged) {
|
||||
if (enabled && governor && !this->GetConfig()->GetTitleGovernorDisabled(applicationId))
|
||||
if (enabled && governor)
|
||||
this->governor->Start();
|
||||
else
|
||||
this->governor->Stop();
|
||||
|
||||
@@ -8,27 +8,70 @@
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include <cstring>
|
||||
#include <nxExt.h>
|
||||
#include "clocks.h"
|
||||
#include "errors.h"
|
||||
|
||||
void Clocks::GetList(SysClkModule module, std::uint32_t **outClocks)
|
||||
void Clocks::GetRange(SysClkModule module, SysClkProfile profile, uint32_t** min, uint32_t** max)
|
||||
{
|
||||
switch(module)
|
||||
{
|
||||
case SysClkModule_CPU:
|
||||
*outClocks = sysclk_g_freq_table_cpu_hz;
|
||||
break;
|
||||
case SysClkModule_GPU:
|
||||
*outClocks = sysclk_g_freq_table_gpu_hz;
|
||||
break;
|
||||
case SysClkModule_MEM:
|
||||
*outClocks = sysclk_g_freq_table_mem_hz;
|
||||
break;
|
||||
default:
|
||||
*outClocks = NULL;
|
||||
ERROR_THROW("No such PcvModule: %u", module);
|
||||
if (module == SysClkModule_MEM) {
|
||||
*min = isMariko ? &g_freq_table_mem_hz[4] : &g_freq_table_mem_hz[0]; // 1600 / 665
|
||||
*max = &g_freq_table_mem_hz[5]; // 1862 - Max
|
||||
return;
|
||||
}
|
||||
|
||||
if (module == SysClkModule_CPU) {
|
||||
*min = &g_freq_table_cpu_hz[0];
|
||||
if (!isMariko)
|
||||
*max = &g_freq_table_cpu_hz[11]; // 1785
|
||||
else {
|
||||
if (allowUnsafe)
|
||||
*max = &g_freq_table_cpu_hz[17]; // 2397
|
||||
else
|
||||
*max = &g_freq_table_cpu_hz[13]; // 1963
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (module == SysClkModule_GPU) {
|
||||
*min = &g_freq_table_gpu_hz[0];
|
||||
if (isMariko && !allowUnsafe) {
|
||||
*max = &g_freq_table_gpu_hz[11]; // 921
|
||||
return;
|
||||
}
|
||||
|
||||
switch (profile) {
|
||||
case SysClkProfile_Handheld:
|
||||
*max = isMariko ? &g_freq_table_gpu_hz[11] : &g_freq_table_gpu_hz[5]; // 921 / 460
|
||||
break;
|
||||
case SysClkProfile_HandheldChargingUSB:
|
||||
*max = isMariko ? &g_freq_table_gpu_hz[16] : &g_freq_table_gpu_hz[9]; // 1267 / 768
|
||||
break;
|
||||
default:
|
||||
*max = isMariko ? &g_freq_table_gpu_hz[17] : &g_freq_table_gpu_hz[11]; // 1305 / 921
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
ERROR_THROW("No such PcvModule: %u", module);
|
||||
}
|
||||
|
||||
Result Clocks::GetTable(SysClkModule module, SysClkProfile profile, size_t max_entry_num, uint32_t* out_table) {
|
||||
uint32_t* min = NULL;
|
||||
uint32_t* max = NULL;
|
||||
memset(out_table, 0, max_entry_num * sizeof(uint32_t));
|
||||
GetRange(module, profile, &min, &max);
|
||||
if (!min || !max || (max - min) / sizeof(uint32_t) >= max_entry_num)
|
||||
return 1;
|
||||
|
||||
uint32_t* p = min;
|
||||
size_t idx = 0;
|
||||
while(p <= max)
|
||||
out_table[idx++] = *p++;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Clocks::Initialize()
|
||||
@@ -42,9 +85,17 @@ void Clocks::Initialize()
|
||||
splExit();
|
||||
|
||||
switch (hardware_type) {
|
||||
case 0: //Icosa
|
||||
case 1: //Copper
|
||||
ERROR_THROW("[!] Erista is not supported!");
|
||||
case 1: //Icosa
|
||||
case 2: //Copper
|
||||
isMariko = false;
|
||||
break;
|
||||
case 3: // Iowa
|
||||
case 4: // Hoag
|
||||
case 5: // Aula
|
||||
isMariko = true;
|
||||
break;
|
||||
default:
|
||||
ERROR_THROW("Unknown hardware type: 0x%X!", hardware_type);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -303,63 +354,25 @@ std::uint32_t Clocks::GetCurrentHz(SysClkModule module)
|
||||
return hz;
|
||||
}
|
||||
|
||||
std::uint32_t Clocks::GetNearestHz(SysClkModule module, SysClkProfile profile, std::uint32_t inHz, bool allowUnsafe)
|
||||
std::uint32_t Clocks::GetNearestHz(SysClkModule module, SysClkProfile profile, std::uint32_t inHz)
|
||||
{
|
||||
std::uint32_t hz = GetNearestHz(module, inHz);
|
||||
std::uint32_t maxHz = GetMaxAllowedHz(module, profile, allowUnsafe);
|
||||
uint32_t* min = NULL;
|
||||
uint32_t* max = NULL;
|
||||
GetRange(module, profile, &min, &max);
|
||||
|
||||
if(maxHz != 0)
|
||||
{
|
||||
hz = std::min(hz, maxHz);
|
||||
}
|
||||
|
||||
return hz;
|
||||
}
|
||||
|
||||
std::uint32_t Clocks::GetMaxAllowedHz(SysClkModule module, SysClkProfile profile, bool allowUnsafe)
|
||||
{
|
||||
switch (module) {
|
||||
case SysClkModule_CPU:
|
||||
if (!allowUnsafe)
|
||||
return SYSCLK_CPU_SAFE_MAX_HZ;
|
||||
break;
|
||||
case SysClkModule_GPU:
|
||||
if (profile == SysClkProfile_Handheld || !allowUnsafe)
|
||||
return SYSCLK_GPU_HANDHELD_MAX_HZ;
|
||||
if (profile == SysClkProfile_HandheldChargingUSB)
|
||||
return SYSCLK_GPU_CHARGING_USB_MAX_HZ;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::uint32_t Clocks::GetNearestHz(SysClkModule module, std::uint32_t inHz)
|
||||
{
|
||||
std::uint32_t *clockTable = NULL;
|
||||
GetList(module, &clockTable);
|
||||
|
||||
if (!clockTable || !clockTable[0])
|
||||
{
|
||||
if (!min || !max)
|
||||
ERROR_THROW("table lookup failed for SysClkModule: %u", module);
|
||||
|
||||
uint32_t inMHz = inHz / 1000000U;
|
||||
uint32_t* p = min;
|
||||
|
||||
while(p <= max) {
|
||||
if (inMHz == *p / 1000000U)
|
||||
return *p;
|
||||
p++;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
while(clockTable[i])
|
||||
{
|
||||
// if (inHz <= (clockTable[i] + clockTable[i + 1]) / 2)
|
||||
if ((inHz / 1000'000) == (clockTable[i] / 1000'000))
|
||||
{
|
||||
return clockTable[i];
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
/* Freq not found in the table, return inHz regardlessly */
|
||||
return inHz;
|
||||
return *max;
|
||||
}
|
||||
|
||||
std::int32_t Clocks::GetTsTemperatureMilli(TsLocation location)
|
||||
|
||||
@@ -18,6 +18,10 @@
|
||||
class Clocks
|
||||
{
|
||||
public:
|
||||
static void GetRange(SysClkModule module, SysClkProfile profile, uint32_t** min, uint32_t** max);
|
||||
static Result GetTable(SysClkModule module, SysClkProfile profile, size_t max_entry_num, uint32_t* out_table);
|
||||
static void SetAllowUnsafe(bool allow) { allowUnsafe = allow; };
|
||||
static bool GetIsMariko() { return isMariko; };
|
||||
static void Exit();
|
||||
static void Initialize();
|
||||
static SysClkApmConfiguration* GetEmbeddedApmConfig(uint32_t confId);
|
||||
@@ -29,14 +33,14 @@ class Clocks
|
||||
static const char* GetProfileName(SysClkProfile profile, bool pretty);
|
||||
static const char* GetModuleName(SysClkModule module, bool pretty);
|
||||
static const char* GetThermalSensorName(SysClkThermalSensor sensor, bool pretty);
|
||||
static std::uint32_t GetNearestHz(SysClkModule module, SysClkProfile profile, std::uint32_t inHz, bool allowUnsafe);
|
||||
static std::uint32_t GetNearestHz(SysClkModule module, SysClkProfile profile, std::uint32_t inHz);
|
||||
static std::uint32_t GetTemperatureMilli(SysClkThermalSensor sensor);
|
||||
static void GetList(SysClkModule module, std::uint32_t **outClocks);
|
||||
|
||||
protected:
|
||||
static inline bool allowUnsafe;
|
||||
static inline bool isMariko;
|
||||
static std::int32_t GetTsTemperatureMilli(TsLocation location);
|
||||
static PcvModule GetPcvModule(SysClkModule sysclkModule);
|
||||
static PcvModuleId GetPcvModuleId(SysClkModule sysclkModule);
|
||||
static std::uint32_t GetNearestHz(SysClkModule module, std::uint32_t inHz);
|
||||
static std::uint32_t GetMaxAllowedHz(SysClkModule module, SysClkProfile profile, bool allowUnsafe);
|
||||
static std::uint32_t GetMaxAllowedHz(SysClkModule module, SysClkProfile profile);
|
||||
};
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include "errors.h"
|
||||
#include "clocks.h"
|
||||
#include "file_utils.h"
|
||||
|
||||
Config::Config(std::string path)
|
||||
@@ -64,6 +65,12 @@ void Config::Load()
|
||||
FileUtils::LogLine("[cfg] Error loading file");
|
||||
}
|
||||
|
||||
// Erista: Disable Mariko only features
|
||||
if (!Clocks::GetIsMariko()) {
|
||||
this->configValues[SysClkConfigValue_AllowUnsafeFrequencies] = 0;
|
||||
this->configValues[SysClkConfigValue_AutoCPUBoost] = 0;
|
||||
}
|
||||
|
||||
this->loaded = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -160,6 +160,14 @@ Result IpcService::ServiceHandlerFunc(void* arg, const IpcServerRequest* r, u8*
|
||||
return ipcSrv->SetReverseNXRTMode(mode);
|
||||
}
|
||||
break;
|
||||
case SysClkIpcCmd_GetFrequencyTable:
|
||||
if(r->data.size >= sizeof(SysClkIpc_GetFrequencyTable_Args))
|
||||
{
|
||||
SysClkIpc_GetFrequencyTable_Args* in_args = (SysClkIpc_GetFrequencyTable_Args*)r->data.ptr;
|
||||
*out_dataSize = sizeof(uint32_t) * in_args->max_entry_num;
|
||||
return ipcSrv->GetFrequencyTable(in_args, (uint32_t*)out_data);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return SYSCLK_ERROR(Generic);
|
||||
@@ -301,3 +309,7 @@ Result IpcService::SetReverseNXRTMode(ReverseNXMode mode) {
|
||||
ClockManager::GetInstance()->SetRNXRTMode(mode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Result IpcService::GetFrequencyTable(SysClkIpc_GetFrequencyTable_Args* args, uint32_t* out_table) {
|
||||
return Clocks::GetTable(args->module, args->profile, args->max_entry_num, out_table);
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ class IpcService
|
||||
Result GetConfigValues(SysClkConfigValueList* out_configValues);
|
||||
Result SetConfigValues(SysClkConfigValueList* configValues);
|
||||
Result SetReverseNXRTMode(ReverseNXMode mode);
|
||||
Result GetFrequencyTable(SysClkIpc_GetFrequencyTable_Args* args, uint32_t* out_table);
|
||||
|
||||
bool running;
|
||||
Thread thread;
|
||||
|
||||
@@ -135,11 +135,8 @@ Governor::Governor() {
|
||||
m_cpu_freq.module = SysClkModule_CPU;
|
||||
m_gpu_freq.module = SysClkModule_GPU;
|
||||
|
||||
uint32_t* list = NULL;
|
||||
Clocks::GetList(SysClkModule_CPU, &list);
|
||||
m_cpu_freq.hz_list = list;
|
||||
Clocks::GetList(SysClkModule_GPU, &list);
|
||||
m_gpu_freq.hz_list = list;
|
||||
m_cpu_freq.hz_list = &g_freq_table_cpu_hz[0];
|
||||
m_gpu_freq.hz_list = &g_freq_table_cpu_hz[0];
|
||||
|
||||
m_cpu_freq.boost_hz = 1785'000'000;
|
||||
m_cpu_freq.utilref_hz = 2397'000'000;
|
||||
|
||||
Reference in New Issue
Block a user