Revert "loader: format code"

This reverts commit d5bf7b0432.
This commit is contained in:
souldbminersmwc
2025-12-11 16:12:40 -05:00
parent d5bf7b0432
commit cd531d163e
3 changed files with 513 additions and 588 deletions

View File

@@ -14,23 +14,20 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "../mtc_timing_value.hpp"
#include "../oc_common.hpp" #include "../oc_common.hpp"
#include "../mtc_timing_value.hpp"
#include "timing_tables.hpp" #include "timing_tables.hpp"
namespace ams::ldr::oc::pcv::mariko namespace ams::ldr::oc::pcv::mariko {
{
s32 FixEinput(s32 val) s32 FixEinput(s32 val) {
{
if (auto patch = FindEinput()) { if (auto patch = FindEinput()) {
return patch->correct; return patch->correct;
} }
return val; return val;
} }
u32 GetRext() u32 GetRext() {
{
if (auto r = FindRext()) { if (auto r = FindRext()) {
return r->correct; return r->correct;
} }
@@ -38,8 +35,7 @@ u32 GetRext()
} }
/* TODO: This function is quite uggly, refactor! */ /* TODO: This function is quite uggly, refactor! */
void CalculateMiscTimings() void CalculateMiscTimings() {
{
tW2P = 0x2d; tW2P = 0x2d;
rdv = 0x39 + C.mem_burst_read_latency; rdv = 0x39 + C.mem_burst_read_latency;
einput_duration = 0x1C; einput_duration = 0x1C;
@@ -49,28 +45,21 @@ void CalculateMiscTimings()
const auto& e = g_misc_table[i]; const auto& e = g_misc_table[i];
if (C.marikoEmcMaxClock >= e.min_freq) { if (C.marikoEmcMaxClock >= e.min_freq) {
rdv += e.rdv_inc; rdv += e.rdv_inc;
if (e.einput) if (e.einput) einput_duration = e.einput;
einput_duration = e.einput; if (e.quse_width) quse_width = e.quse_width;
if (e.quse_width)
quse_width = e.quse_width;
} }
} }
if (WL >= 16) if (WL >= 16) tW2P += 6;
tW2P += 6; if (WL >= 18) tW2P += 8;
if (WL >= 18)
tW2P += 8;
s32 einput_calc = s32 einput_calc = quse_width - (0.010182 * (C.marikoEmcMaxClock / 1000.0) - 0.0879) + 0.5;
quse_width - (0.010182 * (C.marikoEmcMaxClock / 1000.0) - 0.0879) + 0.5;
einput = FixEinput(einput_calc); einput = FixEinput(einput_calc);
rext = GetRext(); rext = GetRext();
} }
void CalculateIbdly() void CalculateIbdly() {
{ /* Ibdly is so inconsistent, I am using the most common value and then checking with a lookup table. */
/* Ibdly is so inconsistent, I am using the most common value and then
* checking with a lookup table. */
ibdly = 0x1000001D + C.mem_burst_read_latency; ibdly = 0x1000001D + C.mem_burst_read_latency;
if (auto patch = FindIbdlyPatch()) { if (auto patch = FindIbdlyPatch()) {
@@ -78,8 +67,7 @@ void CalculateIbdly()
} }
} }
void CalculateObdly() void CalculateObdly() {
{
obdly = 0x10000002 + C.mem_burst_write_latency; obdly = 0x10000002 + C.mem_burst_write_latency;
if (auto patch = FindObdlyPatch()) { if (auto patch = FindObdlyPatch()) {
@@ -87,33 +75,25 @@ void CalculateObdly()
} }
} }
void CalculateTWTPDEN() void CalculateTWTPDEN() {
{ tWTPDEN = tW2P + 1 + CEIL(tDQSS_max / tCK_avg) + CEIL(tDQS2DQ_max / tCK_avg) + 6;
tWTPDEN = if (C.marikoEmcMaxClock >= 2'233'000 && C.marikoEmcMaxClock < 2'533'000) tWTPDEN++;
tW2P + 1 + CEIL(tDQSS_max / tCK_avg) + CEIL(tDQS2DQ_max / tCK_avg) + 6; if (C.marikoEmcMaxClock >= 2'433'000 && C.marikoEmcMaxClock < 2'800'000) tWTPDEN--;
if (C.marikoEmcMaxClock >= 2'233'000 && C.marikoEmcMaxClock < 2'533'000)
tWTPDEN++;
if (C.marikoEmcMaxClock >= 2'433'000 && C.marikoEmcMaxClock < 2'800'000)
tWTPDEN--;
} }
void CalculateTR2W() void CalculateTR2W() {
{ tR2W = CEIL(RL_DBI + (tDQSCK_max / tCK_avg) + (BL / 2) - WL + tWPRE + FLOOR(tRPST) + 9.0);
tR2W = CEIL(RL_DBI + (tDQSCK_max / tCK_avg) + (BL / 2) - WL + tWPRE +
FLOOR(tRPST) + 9.0);
if (auto patch = FindTR2WPatch()) { if (auto patch = FindTR2WPatch()) {
tR2W += patch->adjust; tR2W += patch->adjust;
} }
} }
void CalculateTW2R() void CalculateTW2R() {
{
tW2R = WL + (BL / 2) - 6 + CEIL(tWTR / tCK_avg); tW2R = WL + (BL / 2) - 6 + CEIL(tWTR / tCK_avg);
const FreqTW2R* t = FindTW2R(); const FreqTW2R* t = FindTW2R();
if (!t) if (!t) return;
return;
tW2R += t->adjust; tW2R += t->adjust;
@@ -126,21 +106,17 @@ void CalculateTW2R()
} }
} }
void CalculateQuse() void CalculateQuse() {
{ quse = ROUND(0.002266 * (C.marikoEmcMaxClock / 1000.0) + 31.88) + C.mem_burst_read_latency;
quse = ROUND(0.002266 * (C.marikoEmcMaxClock / 1000.0) + 31.88) +
C.mem_burst_read_latency;
if (auto patch = FindQusePatch()) { if (auto patch = FindQusePatch()) {
quse += patch->adjust; quse += patch->adjust;
} }
} }
void CalculateQrst() void CalculateQrst() {
{
qrst = 0x00070000; qrst = 0x00070000;
u32 qrst_calc = ROUND(22.1 - (C.marikoEmcMaxClock / 1000000.0) * 8.0) + u32 qrst_calc = ROUND(22.1 - (C.marikoEmcMaxClock / 1000000.0) * 8.0) + C.mem_burst_read_latency;
C.mem_burst_read_latency;
u32 qrst_low = MAX(static_cast<u32>(0), qrst_calc); u32 qrst_low = MAX(static_cast<u32>(0), qrst_calc);
if (C.marikoEmcMaxClock >= 2'533'000) { if (C.marikoEmcMaxClock >= 2'533'000) {
@@ -156,53 +132,42 @@ void CalculateQrst()
} }
} }
void CalculateQsafe() void CalculateQsafe() {
{ qsafe = ROUND((C.marikoEmcMaxClock / 1000.0) / 138.0 + 37.4) + C.mem_burst_read_latency;
qsafe = ROUND((C.marikoEmcMaxClock / 1000.0) / 138.0 + 37.4) +
C.mem_burst_read_latency;
if (auto patch = FindQsafePatch()) { if (auto patch = FindQsafePatch()) {
qsafe += patch->adjust; qsafe += patch->adjust;
} }
} }
void CalculateQpop() void CalculateQpop() {
{ qpop = FLOOR(((C.marikoEmcMaxClock / 1000.0) - 2133 + 167) / 200.0) + 0x2D + C.mem_burst_read_latency;
qpop = FLOOR(((C.marikoEmcMaxClock / 1000.0) - 2133 + 167) / 200.0) + 0x2D +
C.mem_burst_read_latency;
if (C.marikoEmcMaxClock >= 3'133'000) if (C.marikoEmcMaxClock >= 3'133'000) qpop++;
qpop++;
} }
void CalculatePdex2rw() void CalculatePdex2rw() {
{
double freq_mhz = C.marikoEmcMaxClock / 1000.0; double freq_mhz = C.marikoEmcMaxClock / 1000.0;
double pdex_local = (0.011 * freq_mhz) - 1.443; double pdex_local = (0.011 * freq_mhz) - 1.443;
pdex2rw = static_cast<u32>(ROUND(pdex_local)); pdex2rw = static_cast<u32>(ROUND(pdex_local));
if (pdex2rw < 22) if (pdex2rw < 22) pdex2rw = 22;
pdex2rw = 22; if (pdex2rw > 33) pdex2rw = 33;
if (pdex2rw > 33)
pdex2rw = 33;
if (auto patch = FindPdex2rwPatch()) { if (auto patch = FindPdex2rwPatch()) {
pdex2rw += patch->adjust; pdex2rw += patch->adjust;
} }
} }
void CalculateCke2pden() void CalculateCke2pden() {
{ cke2pden = (static_cast<double>((C.marikoEmcMaxClock / 1000.0) * 0.00875) - 0.65);
cke2pden =
(static_cast<double>((C.marikoEmcMaxClock / 1000.0) * 0.00875) - 0.65);
if (auto patch = FindCke2pdenPatch()) { if (auto patch = FindCke2pdenPatch()) {
cke2pden += patch->adjust; cke2pden += patch->adjust;
} }
} }
void CalculateTimings() void CalculateTimings() {
{
CalculateMiscTimings(); CalculateMiscTimings();
CalculateIbdly(); CalculateIbdly();
CalculateObdly(); CalculateObdly();
@@ -217,4 +182,4 @@ void CalculateTimings()
CalculateCke2pden(); CalculateCke2pden();
} }
} // namespace ams::ldr::oc::pcv::mariko }

View File

@@ -17,8 +17,7 @@
#include "../mtc_timing_value.hpp" #include "../mtc_timing_value.hpp"
#include "timing_tables.hpp" #include "timing_tables.hpp"
namespace ams::ldr::oc::pcv::mariko namespace ams::ldr::oc::pcv::mariko {
{
const MiscTimings g_misc_table[] = { const MiscTimings g_misc_table[] = {
{1'866'000, 1, 0x20, 0x9, 0}, {1'866'000, 1, 0x20, 0x9, 0},
@@ -48,23 +47,23 @@ const MiscTimings g_misc_table[] = {
const u32 g_misc_table_size = sizeof(g_misc_table) / sizeof(g_misc_table[0]); const u32 g_misc_table_size = sizeof(g_misc_table) / sizeof(g_misc_table[0]);
const ReplacePatch g_einput_patches[] = { { 2'133'000, 0x16 }, const ReplacePatch g_einput_patches[] = {
{ 2'166'000, 0x17 }, { 2'200'000, 0x17 }, { 2'233'000, 0x16 }, {2'133'000, 0x16}, {2'166'000, 0x17}, {2'200'000, 0x17},
{ 2'266'000, 0x16 }, { 2'300'000, 0x15 }, { 2'333'000, 0x14 }, {2'233'000, 0x16}, {2'266'000, 0x16}, {2'300'000, 0x15},
{ 2'366'000, 0x16 }, { 2'400'000, 0x16 }, { 2'433'000, 0x15 }, {2'333'000, 0x14}, {2'366'000, 0x16}, {2'400'000, 0x16},
{ 2'466'000, 0x15 }, { 2'500'000, 0x14 }, { 2'533'000, 0x13 }, {2'433'000, 0x15}, {2'466'000, 0x15}, {2'500'000, 0x14},
{ 2'566'000, 0x14 }, { 2'600'000, 0x14 }, { 2'633'000, 0x13 }, {2'533'000, 0x13}, {2'566'000, 0x14}, {2'600'000, 0x14},
{ 2'666'000, 0x13 }, { 2'700'000, 0x12 }, { 2'733'000, 0x11 }, {2'633'000, 0x13}, {2'666'000, 0x13}, {2'700'000, 0x12},
{ 2'766'000, 0x13 }, { 2'800'000, 0x13 }, { 2'833'000, 0x12 }, {2'733'000, 0x11}, {2'766'000, 0x13}, {2'800'000, 0x13},
{ 2'866'000, 0x12 }, { 2'900'000, 0x12 }, { 2'933'000, 0x10 }, {2'833'000, 0x12}, {2'866'000, 0x12}, {2'900'000, 0x12},
{ 2'966'000, 0x11 }, { 3'000'000, 0x11 }, { 3'033'000, 0x10 }, {2'933'000, 0x10}, {2'966'000, 0x11}, {3'000'000, 0x11},
{ 3'066'000, 0x10 }, { 3'100'000, 0x10 }, { 3'133'000, 0x0F } }; {3'033'000, 0x10}, {3'066'000, 0x10}, {3'100'000, 0x10},
{3'133'000, 0x0F}
};
const u32 g_einput_patches_size = const u32 g_einput_patches_size = sizeof(g_einput_patches) / sizeof(g_einput_patches[0]);
sizeof(g_einput_patches) / sizeof(g_einput_patches[0]);
const ReplacePatch *FindEinput() const ReplacePatch *FindEinput() {
{
for (u32 i = 0; i < g_einput_patches_size; i++) for (u32 i = 0; i < g_einput_patches_size; i++)
if (g_einput_patches[i].freq == C.marikoEmcMaxClock) if (g_einput_patches[i].freq == C.marikoEmcMaxClock)
return &g_einput_patches[i]; return &g_einput_patches[i];
@@ -72,43 +71,22 @@ const ReplacePatch *FindEinput()
} }
const ReplacePatch g_rext_table[] = { const ReplacePatch g_rext_table[] = {
{ 2'133'000, 0x1A }, {2'133'000, 0x1A}, {2'166'000, 0x19}, {2'200'000, 0x19},
{ 2'166'000, 0x19 }, {2'233'000, 0x19}, {2'266'000, 0x1A}, {2'300'000, 0x1B},
{ 2'200'000, 0x19 }, {2'333'000, 0x1B}, {2'366'000, 0x1B}, {2'400'000, 0x1B},
{ 2'233'000, 0x19 }, {2'433'000, 0x1B}, {2'466'000, 0x1B}, {2'500'000, 0x1A},
{ 2'266'000, 0x1A }, {2'533'000, 0x1C}, {2'566'000, 0x1B}, {2'600'000, 0x17},
{ 2'300'000, 0x1B }, {2'633'000, 0x1B}, {2'666'000, 0x1B}, {2'700'000, 0x1C},
{ 2'333'000, 0x1B }, {2'733'000, 0x1C}, {2'766'000, 0x1D}, {2'800'000, 0x1D},
{ 2'366'000, 0x1B }, {2'833'000, 0x1D}, {2'866'000, 0x1D}, {2'900'000, 0x1D},
{ 2'400'000, 0x1B }, {2'933'000, 0x1C}, {2'966'000, 0x1D}, {3'000'000, 0x1D},
{ 2'433'000, 0x1B }, {3'033'000, 0x1D}, {3'066'000, 0x1D}, {3'100'000, 0x1D},
{ 2'466'000, 0x1B },
{ 2'500'000, 0x1A },
{ 2'533'000, 0x1C },
{ 2'566'000, 0x1B },
{ 2'600'000, 0x17 },
{ 2'633'000, 0x1B },
{ 2'666'000, 0x1B },
{ 2'700'000, 0x1C },
{ 2'733'000, 0x1C },
{ 2'766'000, 0x1D },
{ 2'800'000, 0x1D },
{ 2'833'000, 0x1D },
{ 2'866'000, 0x1D },
{ 2'900'000, 0x1D },
{ 2'933'000, 0x1C },
{ 2'966'000, 0x1D },
{ 3'000'000, 0x1D },
{ 3'033'000, 0x1D },
{ 3'066'000, 0x1D },
{ 3'100'000, 0x1D },
{3'133'000, 0x1D}, {3'133'000, 0x1D},
}; };
const u32 g_rext_table_size = sizeof(g_rext_table) / sizeof(g_rext_table[0]); const u32 g_rext_table_size = sizeof(g_rext_table) / sizeof(g_rext_table[0]);
const ReplacePatch *FindRext() const ReplacePatch *FindRext() {
{
for (u32 i = 0; i < g_rext_table_size; i++) for (u32 i = 0; i < g_rext_table_size; i++)
if (g_rext_table[i].freq == C.marikoEmcMaxClock) if (g_rext_table[i].freq == C.marikoEmcMaxClock)
return &g_rext_table[i]; return &g_rext_table[i];
@@ -130,8 +108,7 @@ const FreqTW2R g_tw2r_table[] = {
const u32 g_tw2r_table_size = sizeof(g_tw2r_table) / sizeof(g_tw2r_table[0]); const u32 g_tw2r_table_size = sizeof(g_tw2r_table) / sizeof(g_tw2r_table[0]);
const FreqTW2R *FindTW2R() const FreqTW2R *FindTW2R() {
{
for (u32 i = 0; i < g_tw2r_table_size; i++) for (u32 i = 0; i < g_tw2r_table_size; i++)
if (C.marikoEmcMaxClock <= g_tw2r_table[i].max_freq) if (C.marikoEmcMaxClock <= g_tw2r_table[i].max_freq)
return &g_tw2r_table[i]; return &g_tw2r_table[i];
@@ -157,11 +134,9 @@ const AdjustPatch g_ibdly_patches[] = {
{2'933'000, -1}, {2'933'000, -1},
}; };
const u32 g_ibdly_table_size = const u32 g_ibdly_table_size = sizeof(g_ibdly_patches) / sizeof(g_ibdly_patches[0]);
sizeof(g_ibdly_patches) / sizeof(g_ibdly_patches[0]);
const AdjustPatch *FindIbdlyPatch() const AdjustPatch *FindIbdlyPatch() {
{
for (u32 i = 0; i < g_ibdly_table_size; i++) for (u32 i = 0; i < g_ibdly_table_size; i++)
if (g_ibdly_patches[i].freq == C.marikoEmcMaxClock) if (g_ibdly_patches[i].freq == C.marikoEmcMaxClock)
return &g_ibdly_patches[i]; return &g_ibdly_patches[i];
@@ -190,11 +165,9 @@ const AdjustPatch g_obdly_patches[] = {
{3'133'000, -2}, {3'133'000, -2},
}; };
const u32 g_obdly_table_size = const u32 g_obdly_table_size = sizeof(g_obdly_patches) / sizeof(g_obdly_patches[0]);
sizeof(g_obdly_patches) / sizeof(g_obdly_patches[0]);
const AdjustPatch *FindObdlyPatch() const AdjustPatch *FindObdlyPatch() {
{
for (u32 i = 0; i < g_obdly_table_size; i++) for (u32 i = 0; i < g_obdly_table_size; i++)
if (g_obdly_patches[i].freq == C.marikoEmcMaxClock) if (g_obdly_patches[i].freq == C.marikoEmcMaxClock)
return &g_obdly_patches[i]; return &g_obdly_patches[i];
@@ -210,11 +183,9 @@ const AdjustPatch g_tr2w_patches[] = {
{3'133'000, 1}, {3'133'000, 1},
}; };
const u32 g_tr2w_table_size = const u32 g_tr2w_table_size = sizeof(g_tr2w_patches) / sizeof(g_tr2w_patches[0]);
sizeof(g_tr2w_patches) / sizeof(g_tr2w_patches[0]);
const AdjustPatch *FindTR2WPatch() const AdjustPatch *FindTR2WPatch() {
{
for (u32 i = 0; i < g_tr2w_table_size; i++) for (u32 i = 0; i < g_tr2w_table_size; i++)
if (g_tr2w_patches[i].freq == C.marikoEmcMaxClock) if (g_tr2w_patches[i].freq == C.marikoEmcMaxClock)
return &g_tr2w_patches[i]; return &g_tr2w_patches[i];
@@ -241,11 +212,9 @@ const AdjustPatch g_quse_patches[] = {
{2'933'000, -1}, {2'933'000, -1},
}; };
const u32 g_quse_table_size = const u32 g_quse_table_size = sizeof(g_quse_patches) / sizeof(g_quse_patches[0]);
sizeof(g_quse_patches) / sizeof(g_quse_patches[0]);
const AdjustPatch *FindQusePatch() const AdjustPatch *FindQusePatch() {
{
for (u32 i = 0; i < g_quse_table_size; i++) for (u32 i = 0; i < g_quse_table_size; i++)
if (g_quse_patches[i].freq == C.marikoEmcMaxClock) if (g_quse_patches[i].freq == C.marikoEmcMaxClock)
return &g_quse_patches[i]; return &g_quse_patches[i];
@@ -277,11 +246,9 @@ const AdjustPatch g_qrst_patches[] = {
{3'200'000, 1}, {3'200'000, 1},
}; };
const u32 g_qrst_table_size = const u32 g_qrst_table_size = sizeof(g_qrst_patches) / sizeof(g_qrst_patches[0]);
sizeof(g_qrst_patches) / sizeof(g_qrst_patches[0]);
const AdjustPatch *FindQrstPatch() const AdjustPatch *FindQrstPatch() {
{
for (u32 i = 0; i < g_qrst_table_size; i++) for (u32 i = 0; i < g_qrst_table_size; i++)
if (g_qrst_patches[i].freq == C.marikoEmcMaxClock) if (g_qrst_patches[i].freq == C.marikoEmcMaxClock)
return &g_qrst_patches[i]; return &g_qrst_patches[i];
@@ -310,11 +277,9 @@ const AdjustPatch g_qsafe_patches[] = {
{3'200'000, -1}, {3'200'000, -1},
}; };
const u32 g_qsafe_table_size = const u32 g_qsafe_table_size = sizeof(g_qsafe_patches) / sizeof(g_qsafe_patches[0]);
sizeof(g_qsafe_patches) / sizeof(g_qsafe_patches[0]);
const AdjustPatch *FindQsafePatch() const AdjustPatch *FindQsafePatch() {
{
for (u32 i = 0; i < g_qsafe_table_size; i++) for (u32 i = 0; i < g_qsafe_table_size; i++)
if (g_qsafe_patches[i].freq == C.marikoEmcMaxClock) if (g_qsafe_patches[i].freq == C.marikoEmcMaxClock)
return &g_qsafe_patches[i]; return &g_qsafe_patches[i];
@@ -337,11 +302,9 @@ const AdjustPatch g_pdex2rw_patches[] = {
{3'066'000, 1}, {3'066'000, 1},
}; };
const u32 g_pdex2rw_table_size = const u32 g_pdex2rw_table_size = sizeof(g_pdex2rw_patches) / sizeof(g_pdex2rw_patches[0]);
sizeof(g_pdex2rw_patches) / sizeof(g_pdex2rw_patches[0]);
const AdjustPatch *FindPdex2rwPatch() const AdjustPatch *FindPdex2rwPatch() {
{
for (u32 i = 0; i < g_pdex2rw_table_size; i++) for (u32 i = 0; i < g_pdex2rw_table_size; i++)
if (g_pdex2rw_patches[i].freq == C.marikoEmcMaxClock) if (g_pdex2rw_patches[i].freq == C.marikoEmcMaxClock)
return &g_pdex2rw_patches[i]; return &g_pdex2rw_patches[i];
@@ -365,15 +328,13 @@ const AdjustPatch g_cke2pden_patches[] = {
{3'100'000, 1}, {3'100'000, 1},
}; };
const u32 g_cke2pden_table_size = const u32 g_cke2pden_table_size = sizeof(g_cke2pden_patches) / sizeof(g_cke2pden_patches[0]);
sizeof(g_cke2pden_patches) / sizeof(g_cke2pden_patches[0]);
const AdjustPatch *FindCke2pdenPatch() const AdjustPatch *FindCke2pdenPatch() {
{
for (u32 i = 0; i < g_cke2pden_table_size; i++) for (u32 i = 0; i < g_cke2pden_table_size; i++)
if (g_cke2pden_patches[i].freq == C.marikoEmcMaxClock) if (g_cke2pden_patches[i].freq == C.marikoEmcMaxClock)
return &g_cke2pden_patches[i]; return &g_cke2pden_patches[i];
return nullptr; return nullptr;
} }
} // namespace ams::ldr::oc::pcv::mariko }

View File

@@ -17,8 +17,7 @@
#pragma once #pragma once
#include "../mtc_timing_value.hpp" #include "../mtc_timing_value.hpp"
namespace ams::ldr::oc::pcv::mariko namespace ams::ldr::oc::pcv::mariko {
{
struct ReplacePatch { struct ReplacePatch {
u32 freq; u32 freq;
@@ -92,4 +91,4 @@ extern const FreqTW2R g_tw2r_table[];
extern const u32 g_tw2r_table_size; extern const u32 g_tw2r_table_size;
const FreqTW2R *FindTW2R(); const FreqTW2R *FindTW2R();
} // namespace ams::ldr::oc::pcv::mariko }