From dd59deeefaaa11e187762177157ed97d3a55654a Mon Sep 17 00:00:00 2001 From: Lightos1 <124387232+Lightos1@users.noreply.github.com> Date: Tue, 25 Aug 2026 21:25:01 +0200 Subject: [PATCH] clkmgr: (hack) prevent emc freq list mismatch with 64 lut freq hack --- Source/hoc-clk/sysmodule/src/file/kip.cpp | 12 ++++++++++++ Source/hoc-clk/sysmodule/src/mgr/clock_manager.cpp | 7 +++++-- Source/hoc-clk/sysmodule/src/mgr/clock_manager.hpp | 1 + 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Source/hoc-clk/sysmodule/src/file/kip.cpp b/Source/hoc-clk/sysmodule/src/file/kip.cpp index bb6169cf..e1e63d5a 100644 --- a/Source/hoc-clk/sysmodule/src/file/kip.cpp +++ b/Source/hoc-clk/sysmodule/src/file/kip.cpp @@ -219,6 +219,18 @@ namespace kip { // return; // } + /* Hack: Get the actually applied and in use emc max clock for 64 lut freq hack. */ + /* I hate this. */ + /* Don't fetch frequency if it's already set or we would overwrite it. */ + /* This technically only applies to Mariko *for now*. */ + if (clockManager::patchedEmcMaxClock == 0) { + if (board::GetSocType() == HocClkSocType_Mariko) { + clockManager::patchedEmcMaxClock = cust_get_mariko_emc_max(&table); + } else { + clockManager::patchedEmcMaxClock = cust_get_erista_emc_max(&table); + } + } + if ((u64)crc32::checksum_file("sdmc:/atmosphere/kips/hoc.kip") != config::GetConfigValue(KipCrc32) && !config::GetConfigValue(HocClkConfigValue_IsFirstLoad)) { MigrateKipData(cust_get_cust_rev(&table), cust_get_kip_version(&table)); diff --git a/Source/hoc-clk/sysmodule/src/mgr/clock_manager.cpp b/Source/hoc-clk/sysmodule/src/mgr/clock_manager.cpp index c035c11e..9448fc6b 100644 --- a/Source/hoc-clk/sysmodule/src/mgr/clock_manager.cpp +++ b/Source/hoc-clk/sysmodule/src/mgr/clock_manager.cpp @@ -53,6 +53,9 @@ namespace clockManager { LockableMutex gContextMutex; HocClkContext gContext = {}; FreqTable gFreqTable[HocClkModule_EnumMax]; + /* Hack: Fixes emc 64 lut freq list hack edge case. */ + /* The clock in the config may differ from the actual max clock, so it's read out from the kip before migration or any other potential overwrite. */ + u32 patchedEmcMaxClock = {}; std::uint64_t gLastTempLogNs = 0; std::uint64_t gLastFreqLogNs = 0; std::uint64_t gLastPowerLogNs = 0; @@ -297,7 +300,7 @@ namespace clockManager { /* Since it is a pain to patch the vtables in ipc we can just hack the freqs in. You can still set them. */ constexpr u64 EmcClkOSLimitHz = 1600000ULL * 1000; // 1600 MHz - const u64 maxHz = static_cast(config::GetConfigValue(KipConfigValue_marikoEmcMaxClock)) * 1000; + const u64 maxHz = patchedEmcMaxClock * 1000; if (module == HocClkModule_MEM && board::GetSocType() == HocClkSocType_Mariko && kip::kipAvailable && maxHz >= EmcClkOSLimitHz && config::GetConfigValue(KipConfigValue_stepMode) == 4 /* 33 MHz */) { @@ -819,7 +822,7 @@ namespace clockManager { gContext.isDram8GB = board::IsDram8GB(); gContext.consoleType = board::GetConsoleType(); gContext.isFirstLoad = config::GetConfigValue(HocClkConfigValue_IsFirstLoad); - + board::SetGpuSchedulingMode((GpuSchedulingMode)config::GetConfigValue(HocClkConfigValue_GPUScheduling), (GpuSchedulingOverrideMethod)config::GetConfigValue(HocClkConfigValue_GPUSchedulingMethod)); gContext.gpuSchedulingMode = (GpuSchedulingMode)config::GetConfigValue(HocClkConfigValue_GPUScheduling); diff --git a/Source/hoc-clk/sysmodule/src/mgr/clock_manager.hpp b/Source/hoc-clk/sysmodule/src/mgr/clock_manager.hpp index 6caee007..7dccdc8e 100644 --- a/Source/hoc-clk/sysmodule/src/mgr/clock_manager.hpp +++ b/Source/hoc-clk/sysmodule/src/mgr/clock_manager.hpp @@ -45,6 +45,7 @@ namespace clockManager { extern LockableMutex gContextMutex; extern HocClkContext gContext; extern FreqTable gFreqTable[HocClkModule_EnumMax]; + extern u32 patchedEmcMaxClock; extern std::uint64_t gLastTempLogNs; extern std::uint64_t gLastFreqLogNs; extern std::uint64_t gLastPowerLogNs;