Fix ReverseNX RT/Tool mode synchronization

This commit is contained in:
KazushiM
2022-10-16 11:38:21 +08:00
parent dd466ffb79
commit d596016c84
5 changed files with 245 additions and 159 deletions

View File

@@ -44,7 +44,7 @@ index 6628524..640629f 160000
-Subproject commit 66285245361a02e5480c7bb7dac9ef6449ae6181
+Subproject commit 640629f49f9e8997ef0769b21b26f4fc177c736f
diff --git a/Overlay/source/main.cpp b/Overlay/source/main.cpp
index cec060c..90c020b 100644
index cec060c..13818bb 100644
--- a/Overlay/source/main.cpp
+++ b/Overlay/source/main.cpp
@@ -1,9 +1,12 @@
@@ -60,7 +60,7 @@ index cec060c..90c020b 100644
bool PluginRunning = false;
bool closed = false;
Handle debug;
@@ -20,6 +23,10 @@ bool plugin = false;
@@ -20,6 +23,11 @@ bool plugin = false;
char DockedChar[32];
char SystemChar[32];
char PluginChar[36];
@@ -68,10 +68,26 @@ index cec060c..90c020b 100644
+static Service g_sysclkSrv;
+static std::atomic<std::size_t> g_refCnt;
+bool sysclkComm = false;
+bool sysclkSync = false;
bool CheckPort () {
Handle saltysd;
@@ -54,6 +61,57 @@ bool isServiceRunning(const char *serviceName) {
@@ -43,17 +51,84 @@ bool CheckPort () {
return false;
}
-bool isServiceRunning(const char *serviceName) {
- Handle handle;
- SmServiceName service_name = smEncodeName(serviceName);
+bool isServiceRunning(const char *serviceName) {
+ Handle handle;
+ SmServiceName service_name = smEncodeName(serviceName);
if (R_FAILED(smRegisterService(&handle, service_name, false, 1))) return true;
else {
- svcCloseHandle(handle);
+ svcCloseHandle(handle);
smUnregisterService(service_name);
return false;
}
}
@@ -80,56 +96,81 @@ index cec060c..90c020b 100644
+
+enum SysClkIpcCmd
+{
+ SysClkIpcCmd_GetApiVersion = 0,
+ SysClkIpcCmd_SetReverseNXRTMode = 11,
+ SysClkIpcCmd_GetApiVersion = 0,
+ SysClkIpcCmd_GetConfigValues = 9,
+ SysClkIpcCmd_SetReverseNXRTMode = 11,
+};
+
+enum SysClkConfigValue
+{
+ SysClkConfigValue_SyncReverseNXMode = 4,
+ SysClkConfigValue_EnumMax = 8,
+};
+
+enum ReverseNXMode
+{
+ ReverseNX_NotValid = 0,
+ ReverseNX_SystemDefault = 0,
+ ReverseNX_Handheld,
+ ReverseNX_Docked,
+};
+
+struct SysClkConfigValueList
+{
+ uint64_t values[SysClkConfigValue_EnumMax];
+};
+
+void sysclkIpcExit(void)
+{
+ if (--g_refCnt == 0)
+ {
+ serviceClose(&g_sysclkSrv);
+ }
+ if (--g_refCnt == 0)
+ serviceClose(&g_sysclkSrv);
+}
+
+Result sysclkIpcInitialize(void)
+{
+ Result rc = 0;
+ Result rc = 0;
+
+ g_refCnt++;
+ g_refCnt++;
+
+ if (serviceIsActive(&g_sysclkSrv))
+ return 0;
+ if (serviceIsActive(&g_sysclkSrv))
+ return 0;
+
+ rc = smGetService(&g_sysclkSrv, SYSCLK_IPC_SERVICE_NAME);
+ rc = smGetService(&g_sysclkSrv, SYSCLK_IPC_SERVICE_NAME);
+
+ if (R_FAILED(rc)) sysclkIpcExit();
+ if (R_FAILED(rc))
+ sysclkIpcExit();
+
+ return rc;
+ return rc;
+}
+
+Result sysclkIpcGetAPIVersion(u32* out_ver)
+{
+ return serviceDispatchOut(&g_sysclkSrv, SysClkIpcCmd_GetApiVersion, *out_ver);
+ return serviceDispatchOut(&g_sysclkSrv, SysClkIpcCmd_GetApiVersion, *out_ver);
+}
+
+typedef enum
+Result sysclkIpcGetConfigValues(SysClkConfigValueList* out_configValues)
+{
+ ReverseNX_SystemDefault = 0,
+ ReverseNX_Handheld,
+ ReverseNX_Docked,
+ ReverseNX_RTResetToDefault,
+} ReverseNXMode;
+ return serviceDispatchOut(&g_sysclkSrv, SysClkIpcCmd_GetConfigValues, *out_configValues);
+}
+
+Result sysclkIpcSetReverseNXRTMode(ReverseNXMode mode)
+{
+ return serviceDispatchIn(&g_sysclkSrv, SysClkIpcCmd_SetReverseNXRTMode, mode);
+ return serviceDispatchIn(&g_sysclkSrv, SysClkIpcCmd_SetReverseNXRTMode, mode);
+}
+
class GuiTest : public tsl::Gui {
public:
GuiTest(u8 arg1, u8 arg2, bool arg3) { }
@@ -88,6 +146,7 @@ public:
@@ -67,7 +142,7 @@ public:
// A list that can contain sub elements and handles scrolling
auto list = new tsl::elm::List();
-
+
list->addItem(new tsl::elm::CustomDrawer([](tsl::gfx::Renderer *renderer, s32 x, s32 y, s32 w, s32 h) {
if (SaltySD == false) renderer->drawString("SaltyNX is not working!", false, x, y+50, 20, renderer->a(0xF33F));
else if (plugin == false) renderer->drawString("Can't detect ReverseNX-RT plugin!", false, x, y+50, 20, renderer->a(0xF33F));
@@ -88,16 +163,18 @@ public:
else {
renderer->drawString(SystemChar, false, x, y+40, 20, renderer->a(0xFFFF));
renderer->drawString(DockedChar, false, x, y+60, 20, renderer->a(0xFFFF));
@@ -137,11 +178,12 @@ index cec060c..90c020b 100644
}
}
}), 100);
@@ -95,9 +154,10 @@ public:
if (MAGIC == 0x06BA7E39) {
auto *clickableListItem = new tsl::elm::ListItem("Change system control");
clickableListItem->setClickListener([](u64 keys) {
- clickableListItem->setClickListener([](u64 keys) {
- if (keys & KEY_A) {
+ clickableListItem->setClickListener([](u64 keys) {
+ if (keys & HidNpadButton_A) {
if (PluginRunning == true) {
def = !def;
@@ -149,11 +191,16 @@ index cec060c..90c020b 100644
if (dmntcht == true) {
dmntchtWriteCheatProcessMemory(def_address, &def, 0x1);
dmntchtReadCheatProcessMemory(def_address, &def, 0x1);
@@ -120,9 +180,10 @@ public:
@@ -117,12 +194,13 @@ public:
});
list->addItem(clickableListItem);
-
+
auto *clickableListItem2 = new tsl::elm::ListItem("Change mode");
clickableListItem2->setClickListener([](u64 keys) {
- clickableListItem2->setClickListener([](u64 keys) {
- if (keys & KEY_A) {
+ clickableListItem2->setClickListener([](u64 keys) {
+ if (keys & HidNpadButton_A) {
if (PluginRunning == true && def == false) {
isDocked =! isDocked;
@@ -161,16 +208,44 @@ index cec060c..90c020b 100644
if (dmntcht == true) {
dmntchtWriteCheatProcessMemory(docked_address, &isDocked, 0x1);
dmntchtReadCheatProcessMemory(docked_address, &isDocked, 0x1);
@@ -145,7 +206,7 @@ public:
@@ -137,15 +215,15 @@ public:
}
else return false;
}
-
+
return false;
});
list->addItem(clickableListItem2);
}
else if (SaltySD == true && plugin == true && check == false) {
auto *clickableListItem = new tsl::elm::ListItem("(De)activate plugin");
clickableListItem->setClickListener([](u64 keys) {
- clickableListItem->setClickListener([](u64 keys) {
- if (keys & KEY_A) {
+ clickableListItem->setClickListener([](u64 keys) {
+ if (keys & HidNpadButton_A) {
if (bak == false) {
rename("sdmc:/SaltySD/plugins/ReverseNX-RT.elf", "sdmc:/SaltySD/plugins/ReverseNX-RT.elf.bak");
bak = true;
@@ -179,12 +240,22 @@ public:
@@ -156,7 +234,7 @@ public:
}
return true;
}
-
+
return false;
});
list->addItem(clickableListItem);
@@ -164,7 +242,7 @@ public:
// Add the list to the frame for it to be drawn
frame->setContent(list);
-
+
// Return the frame to have it become the top level element of this Gui
return frame;
}
@@ -179,30 +257,39 @@ public:
closed = true;
}
if (PluginRunning == true) {
@@ -188,14 +263,23 @@ index cec060c..90c020b 100644
+ }
+ if (def && defChanged) {
+ defChanged = false;
+ sysclkIpcSetReverseNXRTMode(ReverseNX_RTResetToDefault);
+ sysclkIpcSetReverseNXRTMode(ReverseNX_SystemDefault);
+ }
+ }
i = 0;
}
else i++;
@@ -198,11 +269,10 @@ public:
}
-
+
if (isDocked == true) sprintf(DockedChar, "Mode: Docked");
else sprintf(DockedChar, "Mode: Handheld");
-
+
if (def == true) sprintf(SystemChar, "Controlled by system: Yes");
else sprintf(SystemChar, "Controlled by system: No");
-
+
if (bak == false) sprintf(PluginChar, "ReverseNX-RT plugin is activated.");
else sprintf(PluginChar, "ReverseNX-RT plugin is deactivated.");
-
@@ -207,29 +291,71 @@ index cec060c..90c020b 100644
return false; // Return true here to singal the inputs have been consumed
}
};
@@ -234,6 +304,13 @@ public:
@@ -213,10 +300,10 @@ public:
virtual void initServices() override {
smInitialize();
fsdevMountSdmc();
-
+
SaltySD = CheckPort();
if (SaltySD == false) return;
-
+
FILE* temp = fopen("sdmc:/SaltySD/plugins/ReverseNX-RT.elf", "r");
if (temp != NULL) {
fclose(temp);
@@ -234,6 +321,20 @@ public:
else return;
}
+ // Initialize sysclkIpc
+ sysclkComm = false;
+ sysclkSync = false;
+ if (isServiceRunning(SYSCLK_IPC_SERVICE_NAME)) {
+ uint32_t apiVer;
+ if (R_SUCCEEDED(sysclkIpcInitialize()) && R_SUCCEEDED(sysclkIpcGetAPIVersion(&apiVer)) && apiVer == SYSCLK_IPC_API_VERSION)
+ if (R_SUCCEEDED(sysclkIpcInitialize()) && R_SUCCEEDED(sysclkIpcGetAPIVersion(&apiVer)) && apiVer == SYSCLK_IPC_API_VERSION) {
+ sysclkComm = true;
+
+ SysClkConfigValueList* list = new SysClkConfigValueList;
+ if (R_SUCCEEDED(sysclkIpcGetConfigValues(list)))
+ sysclkSync = bool(list->values[SysClkConfigValue_SyncReverseNXMode]);
+ delete list;
+ }
+ }
+
if (R_FAILED(pmdmntGetApplicationProcessId(&PID))) remove("sdmc:/SaltySD/ReverseNX-RT.hex");
else {
check = true;
@@ -278,10 +355,13 @@ public:
@@ -244,9 +345,9 @@ public:
fread(&def_address, 0x5, 1, offset);
fread(&MAGIC_address, 0x5, 1, offset);
fclose(offset);
-
+
dmntcht = isServiceRunning("dmnt:cht");
-
+
if (dmntcht == true) {
if (R_SUCCEEDED(dmntchtInitialize())) {
bool out = false;
@@ -272,16 +373,19 @@ public:
}
}
}
-
+
if (isDocked == true) sprintf(DockedChar, "Mode: Docked");
else sprintf(DockedChar, "Mode: Handheld");
-
+
if (def == true) sprintf(SystemChar, "Controlled by system: Yes");
else sprintf(SystemChar, "Controlled by system: No");
-
+
+ sprintf(SysclkChar, "Sys-clk-OC Sync: %s", sysclkComm ? (sysclkSync ? "ON" : "OFF") : "UNAVAILABLE");
+
+ sprintf(SysclkChar, "Sys-clk-OC Sync Service: %s", sysclkComm ? "ON" : "OFF");
} // Called at the start to initialize all services necessary for this Overlay
-
+
virtual void exitServices() override {
+ sysclkIpcExit();
dmntchtExit();

View File

@@ -45,7 +45,6 @@ typedef struct
uint8_t enabled;
uint64_t applicationId;
SysClkProfile profile;
SysClkProfile realProfile;
uint32_t freqs[SysClkModule_EnumMax];
uint32_t overrideFreqs[SysClkModule_EnumMax];
uint32_t temps[SysClkThermalSensor_EnumMax];
@@ -54,21 +53,20 @@ typedef struct
typedef enum
{
ReverseNX_SystemDefault = 0,
ReverseNX_NotFound = 0,
ReverseNX_NotValid = 0,
ReverseNX_GotValue = 0,
ReverseNX_SystemDefault = 0,
ReverseNX_Handheld,
ReverseNX_Docked,
ReverseNX_RTResetToDefault,
} ReverseNXMode;
typedef struct
{
bool systemCoreBoostCPU;
bool gotBoostCPUFreq;
bool allowUnsafeFreq;
ReverseNXMode reverseNXMode;
bool syncReverseNXMode;
SysClkProfile realProfile;
ReverseNXMode reverseNXToolMode;
ReverseNXMode reverseNXRTMode;
uint32_t maxMEMFreq;
uint32_t boostCPUFreq;
} SysClkOcExtra;

View File

@@ -45,7 +45,6 @@ ClockManager::ClockManager()
this->context = new SysClkContext;
this->context->applicationId = 0;
this->context->profile = SysClkProfile_Handheld;
this->context->realProfile = SysClkProfile_Handheld;
this->context->enabled = false;
for(unsigned int i = 0; i < SysClkModule_EnumMax; i++)
{
@@ -59,11 +58,13 @@ ClockManager::ClockManager()
this->oc = new SysClkOcExtra;
this->oc->systemCoreBoostCPU = false;
this->oc->gotBoostCPUFreq = false;
this->oc->allowUnsafeFreq = false;
this->oc->reverseNXMode = ReverseNX_NotFound;
this->oc->syncReverseNXMode = false;
this->oc->realProfile = SysClkProfile_Handheld;
this->oc->reverseNXToolMode = ReverseNX_NotFound;
this->oc->reverseNXRTMode = ReverseNX_NotFound;
this->oc->maxMEMFreq = 0;
this->oc->boostCPUFreq = 1785'000'000;
this->oc->boostCPUFreq = 0;
}
ClockManager::~ClockManager()
@@ -77,24 +78,11 @@ bool ClockManager::IsCpuBoostMode()
{
std::uint32_t confId = this->context->perfConfId;
bool isCpuBoostMode = (confId == 0x92220009 || confId == 0x9222000A);
if (isCpuBoostMode && !this->oc->gotBoostCPUFreq)
{
this->oc->gotBoostCPUFreq = true;
this->oc->boostCPUFreq = std::max(this->context->freqs[SysClkModule_CPU], this->oc->boostCPUFreq);
}
if (isCpuBoostMode && !this->oc->boostCPUFreq)
this->oc->boostCPUFreq = std::max(this->context->freqs[SysClkModule_CPU], 1785'000'000U);
return isCpuBoostMode;
}
bool ClockManager::IsReverseNXModeValid()
{
return (this->oc->reverseNXMode);
}
bool ClockManager::IsReverseNXDocked()
{
return (this->oc->reverseNXMode == ReverseNX_Docked);
}
void ClockManager::SetRunning(bool running)
{
this->running = running;
@@ -107,10 +95,8 @@ bool ClockManager::Running()
uint32_t ClockManager::GetHz(SysClkModule module)
{
uint32_t hz = 0;
/* Temp override setting */
hz = this->context->overrideFreqs[module];
uint32_t hz = this->context->overrideFreqs[module];
/* Per-Game setting */
if (!hz)
@@ -120,25 +106,23 @@ uint32_t ClockManager::GetHz(SysClkModule module)
if (!hz)
hz = this->config->GetAutoClockHz(SYSCLK_GLOBAL_PROFILE_TID, module, this->context->profile);
/* Return pre-set hz if ReverseNX is enabled, downclock is disabled when realProfile == Docked */
if (!hz && IsReverseNXModeValid())
/* Return pre-set hz */
if (!hz && this->oc->syncReverseNXMode && GetReverseNXMode())
{
switch(module)
switch (module)
{
case SysClkModule_CPU:
hz = 1020'000'000;
break;
case SysClkModule_GPU:
if (!IsReverseNXDocked() && this->context->realProfile != SysClkProfile_Docked)
hz = 460'800'000;
else
hz = 768'000'000;
hz = (GetReverseNXMode() == ReverseNX_Docked ||
this->oc->realProfile == SysClkProfile_Docked) ?
768'000'000 : 460'800'000;
break;
case SysClkModule_MEM:
if (!IsReverseNXDocked() && this->context->realProfile != SysClkProfile_Docked)
hz = 1600000000;
else
hz = MAX_MEM_CLOCK;
hz = (GetReverseNXMode() == ReverseNX_Docked ||
this->oc->realProfile == SysClkProfile_Docked) ?
MAX_MEM_CLOCK : 1600'000'000;
break;
default:
break;
@@ -148,17 +132,17 @@ uint32_t ClockManager::GetHz(SysClkModule module)
if (hz)
{
/* Considering realProfile frequency limit */
hz = Clocks::GetNearestHz(module, this->context->realProfile, hz, this->oc->allowUnsafeFreq);
hz = Clocks::GetNearestHz(module, this->oc->realProfile, hz, this->oc->allowUnsafeFreq);
if (module == SysClkModule_MEM && hz == MAX_MEM_CLOCK)
{
/* Trigger Max Mem Clock and record it */
if (!this->oc->maxMEMFreq)
{
uint32_t CurrentHz = Clocks::GetCurrentHz(SysClkModule_MEM);
uint32_t currentHz = Clocks::GetCurrentHz(SysClkModule_MEM);
Clocks::SetHz(SysClkModule_MEM, MAX_MEM_CLOCK);
this->oc->maxMEMFreq = Clocks::GetCurrentHz(SysClkModule_MEM);
Clocks::SetHz(SysClkModule_MEM, CurrentHz);
Clocks::SetHz(SysClkModule_MEM, currentHz);
}
return this->oc->maxMEMFreq;
@@ -170,8 +154,8 @@ uint32_t ClockManager::GetHz(SysClkModule module)
{
if (this->oc->systemCoreBoostCPU && hz < this->oc->boostCPUFreq)
return this->oc->boostCPUFreq;
else if (!hz)
/* Prevent crash when hz = 0 in SetHz(0), trigger RefreshContext() and Tick() */
if (!hz)
/* Trigger RefreshContext() and Tick(), resetting default CPU frequency */
return 1020'000'000;
}
@@ -182,11 +166,7 @@ void ClockManager::Tick()
{
std::scoped_lock lock{this->contextMutex};
bool setClock = false;
setClock |= this->config->Refresh();
setClock |= this->RefreshContext();
setClock &= this->context->enabled;
if (setClock)
if (this->RefreshContext() && this->context->enabled)
{
for (unsigned int module = 0; module < SysClkModule_EnumMax; module++)
{
@@ -216,7 +196,7 @@ void ClockManager::WaitForNextTick()
bool isAutoBoostEnabled = this->GetConfig()->GetConfigValue(SysClkConfigValue_AutoCPUBoost);
if ( isAutoBoostEnabled
&& this->context->realProfile != SysClkProfile_Handheld
&& this->oc->realProfile != SysClkProfile_Handheld
&& this->context->enabled
&& this->context->freqs[SysClkModule_CPU] <= this->oc->boostCPUFreq)
{
@@ -257,23 +237,16 @@ void ClockManager::WaitForNextTick()
SysClkProfile ClockManager::ReverseNXProfileHandler()
{
if (!IsReverseNXModeValid())
switch (GetReverseNXMode())
{
return this->context->realProfile;
case ReverseNX_Docked:
return SysClkProfile_Docked;
case ReverseNX_Handheld:
return (this->oc->realProfile == SysClkProfile_Docked) ?
SysClkProfile_HandheldChargingOfficial : this->oc->realProfile;
default:
return this->oc->realProfile;
}
if (IsReverseNXDocked())
{
return SysClkProfile_Docked;
}
if (// !IsReversedNXDocked() &&
this->context->realProfile == SysClkProfile_Docked)
{
return SysClkProfile_HandheldChargingOfficial;
}
return this->context->realProfile;
}
ReverseNXMode ClockManager::ReverseNXFileHandler(const char* filePath)
@@ -291,22 +264,22 @@ ReverseNXMode ClockManager::ReverseNXFileHandler(const char* filePath)
fread(&readBuffer, 1, sizeof(readBuffer), readFile);
fclose(readFile);
if (!memcmp(&readBuffer, &magicDocked, sizeof(readBuffer)))
if (R_SUCCEEDED(memcmp(&readBuffer, &magicDocked, sizeof(readBuffer))))
return ReverseNX_Docked;
if (!memcmp(&readBuffer, &magicHandheld, sizeof(readBuffer)))
if (R_SUCCEEDED(memcmp(&readBuffer, &magicHandheld, sizeof(readBuffer))))
return ReverseNX_Handheld;
return ReverseNX_NotValid;
return ReverseNX_NotFound;
}
void ClockManager::CheckReverseNXTool()
ReverseNXMode ClockManager::GetReverseNXToolMode()
{
bool shouldCheckReverseNXTool = FileUtils::ExistReverseNXTool();
if (!shouldCheckReverseNXTool)
return;
return ReverseNX_NotFound;
ReverseNXMode getMode = ReverseNX_NotValid;
ReverseNXMode getMode = ReverseNX_NotFound;
if (this->context->applicationId != PROCESS_MANAGEMENT_QLAUNCH_TID)
{
const char asmFileName[] = "_ZN2nn2oe18GetPerformanceModeEv.asm64"; // Checking one asm64 file is enough
@@ -324,23 +297,14 @@ void ClockManager::CheckReverseNXTool()
}
}
this->oc->reverseNXMode = getMode;
return getMode;
}
bool ClockManager::CheckReverseNXRT()
ReverseNXMode ClockManager::GetReverseNXMode()
{
bool shouldAdjustProfile = false;
ReverseNXMode getMode = this->GetConfig()->GetReverseNXRTMode();
if (getMode)
{
this->GetConfig()->SetReverseNXRTMode(ReverseNX_GotValue);
this->oc->reverseNXMode = (getMode == ReverseNX_RTResetToDefault) ?
ReverseNX_SystemDefault : getMode;
shouldAdjustProfile = true;
}
return shouldAdjustProfile;
if (this->oc->reverseNXRTMode)
return this->oc->reverseNXRTMode;
return this->oc->reverseNXToolMode;
}
void ClockManager::ChargingHandler()
@@ -351,14 +315,11 @@ void ClockManager::ChargingHandler()
Service* session = psmGetServiceSession();
serviceDispatchOut(session, GetBatteryChargeInfoFields, *(chargeInfoField));
bool fastChargingEnabled = chargeInfoField->ChargeCurrentLimit > 768;
bool fastChargingConfig = !(this->GetConfig()->GetConfigValue(SysClkConfigValue_DisableFastCharging));
if (fastChargingEnabled != fastChargingConfig)
{
bool fastChargingState = chargeInfoField->ChargeCurrentLimit > 768;
bool fastChargingConfig = !(this->GetConfig()->GetConfigValue(SysClkConfigValue_DisableFastCharging));
if (fastChargingState != fastChargingConfig)
serviceDispatch(session, fastChargingConfig ? EnableFastBatteryCharging : DisableFastBatteryCharging);
}
u32 chargeLimit = this->GetConfig()->GetConfigValue(SysClkConfigValue_ChargingLimitPercentage);
bool isChargerConnected = (chargeInfoField->ChargerType != ChargerType_None);
if (isChargerConnected)
{
@@ -366,6 +327,7 @@ void ClockManager::ChargingHandler()
if (R_SUCCEEDED(psmGetBatteryChargePercentage(&chargeNow)))
{
bool isCharging = ((chargeInfoField->unk_x14 >> 8) & 1);
u32 chargeLimit = this->GetConfig()->GetConfigValue(SysClkConfigValue_ChargingLimitPercentage);
if (isCharging && chargeLimit < chargeNow) {
serviceDispatch(session, DisableBatteryCharging);
}
@@ -384,8 +346,8 @@ bool ClockManager::RefreshContext()
{
ChargingHandler();
bool hasChanged = false;
bool isReverseNXSyncEnabled = this->GetConfig()->GetConfigValue(SysClkConfigValue_SyncReverseNXMode);
bool hasChanged = this->config->Refresh();
this->oc->syncReverseNXMode = this->GetConfig()->GetConfigValue(SysClkConfigValue_SyncReverseNXMode);
this->oc->allowUnsafeFreq = this->GetConfig()->GetConfigValue(SysClkConfigValue_AllowUnsafeFrequencies);
bool enabled = this->GetConfig()->Enabled();
@@ -403,18 +365,17 @@ bool ClockManager::RefreshContext()
this->context->applicationId = applicationId;
hasChanged = true;
/* Clear ReverseNX state and recheck -Tool patches*/
if (isReverseNXSyncEnabled) {
this->oc->reverseNXMode = ReverseNX_SystemDefault;
CheckReverseNXTool();
}
/* Clear ReverseNX state */
this->GetConfig()->SetReverseNXRTMode(ReverseNX_NotFound);
this->oc->reverseNXRTMode = ReverseNX_NotFound;
this->oc->reverseNXToolMode = GetReverseNXToolMode();
}
SysClkProfile profile = Clocks::GetCurrentProfile();
if (profile != this->context->realProfile)
if (profile != this->oc->realProfile)
{
FileUtils::LogLine("[mgr] Profile change: %s", Clocks::GetProfileName(profile, true));
this->context->realProfile = profile;
this->oc->realProfile = profile;
hasChanged = true;
}
@@ -431,16 +392,19 @@ bool ClockManager::RefreshContext()
}
}
// restore clocks to stock values on app or profile change
// and let ptm module handle boost clocks rather than resetting
if (hasChanged && !IsCpuBoostMode())
Clocks::ResetToStock();
{
this->oc->reverseNXRTMode = this->GetConfig()->GetReverseNXRTMode();
SysClkProfile currentProfile = this->context->profile;
SysClkProfile expectedProfile = this->oc->syncReverseNXMode ?
ReverseNXProfileHandler() : this->oc->realProfile;
this->context->profile = expectedProfile;
if (currentProfile != expectedProfile)
hasChanged = true;
}
/* Check ReverseNX-RT and adjust nominal profile when context changes */
if (isReverseNXSyncEnabled) {
hasChanged |= CheckReverseNXRT();
if (hasChanged)
this->context->profile = ReverseNXProfileHandler();
// let ptm module handle boost clocks rather than resetting
if (hasChanged && !IsCpuBoostMode()) {
Clocks::ResetToStock();
}
std::uint32_t hz = 0;

View File

@@ -107,15 +107,14 @@ class ClockManager
SysClkOcExtra *oc;
bool IsCpuBoostMode();
bool IsReverseNXModeValid();
bool IsReverseNXDocked();
uint32_t GetHz(SysClkModule);
SysClkProfile ReverseNXProfileHandler();
ReverseNXMode ReverseNXFileHandler(const char*);
ReverseNXMode GetReverseNXToolMode();
ReverseNXMode GetReverseNXMode();
void CheckReverseNXTool();
bool CheckReverseNXRT();
void ChargingHandler();
};

View File

@@ -86,7 +86,6 @@ bool Config::Refresh()
if (!this->loaded || this->mtime != this->CheckModificationTime())
{
this->Load();
Clocks::ResetToStock(); // Reset to stock since we can't detect if user set "Do not override" for specific module
return true;
}
return false;