From b00d2c7c7077cc72e831230456c5262efd6341ef Mon Sep 17 00:00:00 2001 From: hanabbi Date: Wed, 13 Sep 2023 10:58:08 +0900 Subject: [PATCH] loader: patch cpu dfll data for slt this will correct cpu voltage, and cpu freq drops from uv --- .../loader/source/oc/oc_common.hpp | 19 +++++++-------- .../loader/source/oc/pcv/pcv_common.hpp | 10 ++++++++ .../loader/source/oc/pcv/pcv_mariko.cpp | 23 +++++++++++++++++++ pages/src/main.ts | 5 ++-- 4 files changed, 46 insertions(+), 11 deletions(-) diff --git a/Source/Atmosphere/stratosphere/loader/source/oc/oc_common.hpp b/Source/Atmosphere/stratosphere/loader/source/oc/oc_common.hpp index 788538a9..1645c6af 100644 --- a/Source/Atmosphere/stratosphere/loader/source/oc/oc_common.hpp +++ b/Source/Atmosphere/stratosphere/loader/source/oc/oc_common.hpp @@ -38,15 +38,16 @@ namespace ams::ldr { R_DEFINE_ERROR_RESULT(InvalidMtcTable, 1003); R_DEFINE_ERROR_RESULT(InvalidDvbTable, 1004); R_DEFINE_ERROR_RESULT(InvalidCpuFreqVddEntry, 1005); - R_DEFINE_ERROR_RESULT(InvalidCpuDvfs, 1006); - R_DEFINE_ERROR_RESULT(InvalidCpuMinVolt, 1007); - R_DEFINE_ERROR_RESULT(InvalidGpuDvfs, 1008); - R_DEFINE_ERROR_RESULT(InvalidGpuFreqMaxPattern, 1009); - R_DEFINE_ERROR_RESULT(InvalidGpuPllEntry, 1010); - R_DEFINE_ERROR_RESULT(InvalidRegulatorEntry, 1011); - R_DEFINE_ERROR_RESULT(UninitializedPatcher, 1012); - R_DEFINE_ERROR_RESULT(UnsuccessfulPatcher, 1013); - R_DEFINE_ERROR_RESULT(SafetyCheckFailure, 1014); + R_DEFINE_ERROR_RESULT(InvalidCpuVoltDfllEntry, 1006); + R_DEFINE_ERROR_RESULT(InvalidCpuDvfs, 1007); + R_DEFINE_ERROR_RESULT(InvalidCpuMinVolt, 1008); + R_DEFINE_ERROR_RESULT(InvalidGpuDvfs, 1009); + R_DEFINE_ERROR_RESULT(InvalidGpuFreqMaxPattern, 1010); + R_DEFINE_ERROR_RESULT(InvalidGpuPllEntry, 1011); + R_DEFINE_ERROR_RESULT(InvalidRegulatorEntry, 1012); + R_DEFINE_ERROR_RESULT(UninitializedPatcher, 1013); + R_DEFINE_ERROR_RESULT(UnsuccessfulPatcher, 1014); + R_DEFINE_ERROR_RESULT(SafetyCheckFailure, 1015); } namespace ams::ldr::oc { diff --git a/Source/Atmosphere/stratosphere/loader/source/oc/pcv/pcv_common.hpp b/Source/Atmosphere/stratosphere/loader/source/oc/pcv/pcv_common.hpp index 83e4ee3a..c225b136 100644 --- a/Source/Atmosphere/stratosphere/loader/source/oc/pcv/pcv_common.hpp +++ b/Source/Atmosphere/stratosphere/loader/source/oc/pcv/pcv_common.hpp @@ -34,6 +34,16 @@ typedef struct cvb_entry_t { } cvb_entry_t; static_assert(sizeof(cvb_entry_t) == 0x38); +typedef struct cvb_cpu_dfll_data { + u32 tune0_low; + u32 tune0_high; + u32 tune1_low; + u32 tune1_high; + unsigned int tune_high_min_millivolts; + unsigned int tune_high_margin_millivolts; + unsigned long dvco_calibration_max; +} cvb_cpu_dfll_data; + typedef struct emc_dvb_dvfs_table_t { u64 freq; s32 volt[4] = {0}; diff --git a/Source/Atmosphere/stratosphere/loader/source/oc/pcv/pcv_mariko.cpp b/Source/Atmosphere/stratosphere/loader/source/oc/pcv/pcv_mariko.cpp index 39047087..d3f34829 100644 --- a/Source/Atmosphere/stratosphere/loader/source/oc/pcv/pcv_mariko.cpp +++ b/Source/Atmosphere/stratosphere/loader/source/oc/pcv/pcv_mariko.cpp @@ -51,6 +51,28 @@ Result CpuVoltRange(u32* ptr) { R_THROW(ldr::ResultInvalidCpuMinVolt()); } +Result CpuVoltDfll(u32* ptr) { + cvb_cpu_dfll_data *entry = reinterpret_cast(ptr); + + R_UNLESS(entry->tune0_low == 0x0000FFCF, ldr::ResultInvalidCpuVoltDfllEntry()); + R_UNLESS(entry->tune0_high == 0x00000000, ldr::ResultInvalidCpuVoltDfllEntry()); + R_UNLESS(entry->tune1_low == 0x012207FF, ldr::ResultInvalidCpuVoltDfllEntry()); + R_UNLESS(entry->tune1_high == 0x03FFF7FF, ldr::ResultInvalidCpuVoltDfllEntry()); + + if (C.marikoCpuUV) { + if (C.marikoCpuUV == 1) { + PATCH_OFFSET(&(entry->tune0_low), 0x0000FF90); //process_id 0 + } else if (C.marikoCpuUV == 2) { + PATCH_OFFSET(&(entry->tune0_low), 0x0000FFA0); //process_id 1 + } + PATCH_OFFSET(&(entry->tune0_high), 0x0000FFFF); + PATCH_OFFSET(&(entry->tune1_low), 0x021107FF); + PATCH_OFFSET(&(entry->tune1_high), 0x00000000); + } + + R_SUCCEED(); +} + Result GpuFreqMaxAsm(u32* ptr32) { // Check if both two instructions match the pattern u32 ins1 = *ptr32, ins2 = *(ptr32 + 1); @@ -537,6 +559,7 @@ void Patch(uintptr_t mapped_nso, size_t nso_size) { { "CPU Freq Vdd", &CpuFreqVdd, 1, nullptr, CpuClkOSLimit }, { "CPU Freq Table", CpuFreqCvbTable, 1, nullptr, CpuCvbDefaultMaxFreq }, { "CPU Volt Limit", &CpuVoltRange, 13, nullptr, CpuVoltOfficial }, + { "CPU Volt Dfll", &CpuVoltDfll, 1, nullptr, 0x0000FFCF }, { "GPU Freq Table", GpuFreqCvbTable, 1, nullptr, GpuCvbDefaultMaxFreq }, { "GPU Freq Asm", &GpuFreqMaxAsm, 2, &GpuMaxClockPatternFn }, //{ "GPU Freq PLL", &GpuFreqPllLimit, 1, nullptr, GpuClkPllLimit }, diff --git a/pages/src/main.ts b/pages/src/main.ts index 8fa32aa9..a081a209 100644 --- a/pages/src/main.ts +++ b/pages/src/main.ts @@ -313,9 +313,10 @@ var CustTable: Array = [ ["Reduce CPU power draw", "Your CPU might not withstand undervolt and performance might drop", "0 : Default Table", - "1 : Undervolt Level 1 (SLT)",], + "1 : Undervolt Level 1 (SLT - CPU process_id: 0)", + "2 : Undervolt Level 1 (SLT - CPU process_id: 1)",], 0, - [0,1], + [0,2], 1, ), new CustEntry(