From 09b3d6a55e36bc702b50821279b3ef69dad7d6b5 Mon Sep 17 00:00:00 2001 From: hanabbi Date: Sat, 24 Jun 2023 19:12:44 +0900 Subject: [PATCH] fix using wrong mariko CPU/GPU dvfs table to patch limints --- .../stratosphere/loader/source/oc/oc_test.cpp | 7 ++++-- .../stratosphere/loader/source/oc/pcv/pcv.cpp | 19 +++++++++++++--- .../stratosphere/loader/source/oc/pcv/pcv.hpp | 2 +- .../loader/source/oc/pcv/pcv_mariko.cpp | 22 ++++++++++++++++--- 4 files changed, 41 insertions(+), 9 deletions(-) diff --git a/Source/Atmosphere/stratosphere/loader/source/oc/oc_test.cpp b/Source/Atmosphere/stratosphere/loader/source/oc/oc_test.cpp index 7b8100e3..c0cb1c75 100644 --- a/Source/Atmosphere/stratosphere/loader/source/oc/oc_test.cpp +++ b/Source/Atmosphere/stratosphere/loader/source/oc/oc_test.cpp @@ -77,10 +77,13 @@ Result Test_PcvDvfsTable() { // Customized table default assert(GetDvfsTableEntryCount((cvb_entry_t *)(&ams::ldr::oc::C.eristaCpuDvfsTable)) == 19); - assert(GetDvfsTableEntryCount((cvb_entry_t *)(&ams::ldr::oc::C.marikoCpuDvfsTable)) == 22); + assert(GetDvfsTableEntryCount((cvb_entry_t *)(&ams::ldr::oc::C.marikoCpuDvfsTable)) == 21); + assert(GetDvfsTableEntryCount((cvb_entry_t *)(&ams::ldr::oc::C.marikoCpuDvfsTableSLT)) == 22); assert(GetDvfsTableEntryCount((cvb_entry_t *)(&ams::ldr::oc::C.eristaGpuDvfsTable)) == 12); - assert(GetDvfsTableEntryCount((cvb_entry_t *)(&ams::ldr::oc::C.marikoGpuDvfsTable)) == 18); + assert(GetDvfsTableEntryCount((cvb_entry_t *)(&ams::ldr::oc::C.marikoGpuDvfsTable)) == 17); + assert(GetDvfsTableEntryCount((cvb_entry_t *)(&ams::ldr::oc::C.marikoGpuDvfsTableSLT)) == 17); + assert(GetDvfsTableEntryCount((cvb_entry_t *)(&ams::ldr::oc::C.marikoGpuDvfsTableHiOPT)) == 17); constexpr size_t limit = ams::ldr::oc::pcv::DvfsTableEntryLimit; cvb_entry_t customized_table[limit] = {}; diff --git a/Source/Atmosphere/stratosphere/loader/source/oc/pcv/pcv.cpp b/Source/Atmosphere/stratosphere/loader/source/oc/pcv/pcv.cpp index f95baf85..6d50aaf4 100644 --- a/Source/Atmosphere/stratosphere/loader/source/oc/pcv/pcv.cpp +++ b/Source/Atmosphere/stratosphere/loader/source/oc/pcv/pcv.cpp @@ -92,10 +92,23 @@ void SafetyCheck() { }; u32 eristaCpuDvfsMaxFreq = static_cast(GetDvfsTableLastEntry(C.eristaCpuDvfsTable)->freq); - u32 marikoCpuDvfsMaxFreq = static_cast(GetDvfsTableLastEntry(C.marikoCpuDvfsTable)->freq); + u32 marikoCpuDvfsMaxFreq = static_cast(C.marikoCpuUV ? GetDvfsTableLastEntry(C.marikoCpuDvfsTableSLT)->freq : GetDvfsTableLastEntry(C.marikoCpuDvfsTable)->freq); u32 eristaGpuDvfsMaxFreq = static_cast(GetDvfsTableLastEntry(C.eristaGpuDvfsTable)->freq); - u32 marikoGpuDvfsMaxFreq = static_cast(GetDvfsTableLastEntry(C.marikoGpuDvfsTable)->freq); - + u32 marikoGpuDvfsMaxFreq; + switch (C.marikoGpuUV) { + case 0: + marikoGpuDvfsMaxFreq = static_cast(GetDvfsTableLastEntry(C.marikoGpuDvfsTable)->freq); + break; + case 1: + marikoGpuDvfsMaxFreq = static_cast(GetDvfsTableLastEntry(C.marikoGpuDvfsTableSLT)->freq); + break; + case 2: + marikoGpuDvfsMaxFreq = static_cast(GetDvfsTableLastEntry(C.marikoGpuDvfsTableHiOPT)->freq); + break; + default: + marikoGpuDvfsMaxFreq = static_cast(GetDvfsTableLastEntry(C.marikoGpuDvfsTable)->freq); + } + sValidator validators[] = { { C.commonCpuBoostClock, 1020'000, 3000'000, true }, { C.commonEmcMemVolt, 1100'000, 1250'000 }, diff --git a/Source/Atmosphere/stratosphere/loader/source/oc/pcv/pcv.hpp b/Source/Atmosphere/stratosphere/loader/source/oc/pcv/pcv.hpp index 9b93a8ab..0c3ba2a8 100644 --- a/Source/Atmosphere/stratosphere/loader/source/oc/pcv/pcv.hpp +++ b/Source/Atmosphere/stratosphere/loader/source/oc/pcv/pcv.hpp @@ -175,7 +175,7 @@ namespace erista { template Result CpuFreqCvbTable(u32* ptr) { cvb_entry_t* default_table = isMariko ? (cvb_entry_t *)(&mariko::CpuCvbTableDefault) : (cvb_entry_t *)(&erista::CpuCvbTableDefault); - cvb_entry_t* customize_table = const_cast(isMariko ? C.marikoCpuDvfsTable : C.eristaCpuDvfsTable); + cvb_entry_t* customize_table = const_cast(isMariko ? (C.marikoCpuUV ? C.marikoCpuDvfsTableSLT : C.marikoCpuDvfsTable) : C.eristaCpuDvfsTable); u32 cpu_max_volt = isMariko ? C.marikoCpuMaxVolt : C.eristaCpuMaxVolt; u32 cpu_freq_threshold = isMariko ? (C.marikoCpuUV ? 2193'000 : 2091'000) : 1887'000; 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 728c6d0d..7b83291e 100644 --- a/Source/Atmosphere/stratosphere/loader/source/oc/pcv/pcv_mariko.cpp +++ b/Source/Atmosphere/stratosphere/loader/source/oc/pcv/pcv_mariko.cpp @@ -27,8 +27,12 @@ Result CpuFreqVdd(u32* ptr) { R_UNLESS(entry->step_mv == 5000, ldr::ResultInvalidCpuFreqVddEntry()); R_UNLESS(entry->max_mv == 1525'000, ldr::ResultInvalidCpuFreqVddEntry()); - PATCH_OFFSET(ptr, GetDvfsTableLastEntry(C.marikoCpuDvfsTable)->freq); - + if (C.marikoCpuUV) { + PATCH_OFFSET(ptr, GetDvfsTableLastEntry(C.marikoCpuDvfsTableSLT)->freq); + } else { + PATCH_OFFSET(ptr, GetDvfsTableLastEntry(C.marikoCpuDvfsTable)->freq); + } + R_SUCCEED(); } @@ -58,7 +62,19 @@ Result GpuFreqMaxAsm(u32* ptr32) { if (rd != asm_get_rd(ins2)) R_THROW(ldr::ResultInvalidGpuFreqMaxPattern()); - u32 max_clock = GetDvfsTableLastEntry(C.marikoGpuDvfsTable)->freq; + u32 max_clock; + switch(C.marikoGpuUV) { + case 0: + max_clock = GetDvfsTableLastEntry(C.marikoGpuDvfsTable)->freq; + break; + case 1: + max_clock = GetDvfsTableLastEntry(C.marikoGpuDvfsTableSLT)->freq; + break; + case 2: + max_clock = GetDvfsTableLastEntry(C.marikoGpuDvfsTableHiOPT)->freq; + break; + default: max_clock = GetDvfsTableLastEntry(C.marikoGpuDvfsTable)->freq; + } u32 asm_patch[2] = { asm_set_rd(asm_set_imm16(asm_pattern[0], max_clock), rd), asm_set_rd(asm_set_imm16(asm_pattern[1], max_clock >> 16), rd)