Better dram timings

This commit is contained in:
Lightos1
2026-01-12 20:49:49 +01:00
parent b8faa12495
commit a23db6e63d
5 changed files with 82 additions and 413 deletions

View File

@@ -29,16 +29,12 @@ namespace ams::ldr::oc::pcv::mariko {
/* TODO: This function is quite uggly, refactor! */
void CalculateMiscTimings() {
rdv = 0x39 + C.mem_burst_read_latency;
einput_duration = 0x1C;
quse_width = 0x8;
for (u32 i = 0; i < g_misc_table_size; i++) {
const auto& e = g_misc_table[i];
if (C.marikoEmcMaxClock >= e.min_freq) {
rdv += e.rdv_inc;
if (e.einput) einput_duration = e.einput;
if (e.quse_width) quse_width = e.quse_width;
}
}
@@ -54,14 +50,6 @@ namespace ams::ldr::oc::pcv::mariko {
}
}
void CalculateObdly() {
obdly = 0x10000002 + C.mem_burst_write_latency;
if (auto patch = FindObdlyPatch()) {
obdly += patch->adjust;
}
}
void CalculateTWTPDEN() {
tWTPDEN = tW2P + 1 + CEIL(tDQSS_max / tCK_avg) + CEIL(tDQS2DQ_max / tCK_avg) + 6;
if (C.marikoEmcMaxClock >= 2'233'000 && C.marikoEmcMaxClock < 2'533'000) tWTPDEN++;
@@ -76,24 +64,6 @@ namespace ams::ldr::oc::pcv::mariko {
}
}
void CalculateQrst() {
qrst = 0x00070000;
u32 qrst_calc = ROUND(22.1 - (C.marikoEmcMaxClock / 1000000.0) * 8.0) + C.mem_burst_read_latency;
u32 qrst_low = MAX(static_cast<u32>(0), qrst_calc);
if (C.marikoEmcMaxClock >= 2'533'000) {
qrst = INCREMENT_HIGH_BYTES_BY(qrst, 1);
} else if (C.marikoEmcMaxClock == 2'800'000) {
qrst = SET_HIGH_BYTES(qrst, 6);
}
qrst = SET_LOW_BYTES(qrst, qrst_low);
if (auto patch = FindQrstPatch()) {
qrst = INCREMENT_LOW_BYTES_BY(qrst, patch->adjust);
}
}
void CalculateQsafe() {
qsafe = ROUND((C.marikoEmcMaxClock / 1000.0) / 138.0 + 37.4) + C.mem_burst_read_latency;
if (auto patch = FindQsafePatch()) {
@@ -132,10 +102,8 @@ namespace ams::ldr::oc::pcv::mariko {
void CalculateTimings() {
CalculateMiscTimings();
CalculateIbdly();
CalculateObdly();
CalculateTWTPDEN();
CalculateTR2W();
CalculateQrst();
CalculateQsafe();
CalculateQpop();
CalculatePdex2rw();

View File

@@ -20,29 +20,29 @@
namespace ams::ldr::oc::pcv::mariko {
const MiscTimings g_misc_table[] = {
{1'866'000, 1, 0x20, 0x9, },
{2'133'000, 1, 0x24, 0xA, },
{2'166'000, 1, 0, 0, },
{2'233'000, 0, 0x25, 0, },
{2'300'000, 0, 0x26, 0xB, },
{2'333'000, 0, 0x27, 0, },
{2'366'000, 1, 0x26, 0xA, },
{2'433'000, 0, 0x27, 0, },
{2'466'000, 0, 0x2A, 0, },
{2'500'000, 0, 0x28, 0xB, },
{2'533'000, 0, 0x29, 0, },
{2'566'000, 1, 0, 0, },
{2'633'000, 0, 0x2A, 0, },
{2'700'000, 0, 0x2B, 0xC, },
{2'733'000, 0, 0x2C, 0, },
{2'766'000, 1, 0x2B, 0xB, },
{2'833'000, 0, 0x2C, 0, },
{2'866'000, 0, 0, 0, },
{2'900'000, 0, 0, 0, },
{2'933'000, 0, 0x2E, 0xC, },
{2'966'000, 1, 0, 0, },
{3'033'000, 0, 0x2F, 0, },
{3'133'000, 1, 0x31, 0xD, },
{1'866'000, 0x20, },
{2'133'000, 0x24, },
{2'166'000, 0, },
{2'233'000, 0x25, },
{2'300'000, 0x26, },
{2'333'000, 0x27, },
{2'366'000, 0x26, },
{2'433'000, 0x27, },
{2'466'000, 0x2A, },
{2'500'000, 0x28, },
{2'533'000, 0x29, },
{2'566'000, 0, },
{2'633'000, 0x2A, },
{2'700'000, 0x2B, },
{2'733'000, 0x2C, },
{2'766'000, 0x2B, },
{2'833'000, 0x2C, },
{2'866'000, 0, },
{2'900'000, 0, },
{2'933'000, 0x2E, },
{2'966'000, 0, },
{3'033'000, 0x2F, },
{3'133'000, 0x31, },
};
const u32 g_misc_table_size = sizeof(g_misc_table) / sizeof(g_misc_table[0]);
@@ -98,39 +98,6 @@ namespace ams::ldr::oc::pcv::mariko {
return nullptr;
}
const AdjustPatch g_obdly_patches[] = {
{2'533'000, -2},
{2'566'000, -2},
{2'600'000, -2},
{2'633'000, -2},
{2'666'000, -2},
{2'700'000, -2},
{2'733'000, -2},
{2'766'000, -2},
{2'800'000, -2},
{2'833'000, -2},
{2'866'000, -2},
{2'900'000, -2},
{2'933'000, -2},
{2'966'000, -2},
{3'000'000, -2},
{3'033'000, -2},
{3'066'000, -2},
{3'100'000, -2},
{3'133'000, -2},
{3'166'000, -2},
{3'200'000, -2},
};
const u32 g_obdly_table_size = sizeof(g_obdly_patches) / sizeof(g_obdly_patches[0]);
const AdjustPatch *FindObdlyPatch() {
for (u32 i = 0; i < g_obdly_table_size; i++)
if (g_obdly_patches[i].freq == C.marikoEmcMaxClock)
return &g_obdly_patches[i];
return nullptr;
}
const AdjustPatch g_tr2w_patches[] = {
{2'500'000, 1},
{2'533'000, 1},
@@ -149,42 +116,6 @@ namespace ams::ldr::oc::pcv::mariko {
return nullptr;
}
const AdjustPatch g_qrst_patches[] = {
{2'166'000, 1},
{2'200'000, 1},
{2'233'000, 1},
{2'266'000, 1},
{2'366'000, 2},
{2'400'000, 2},
{2'433'000, 1},
{2'466'000, 2},
{2'500'000, 1},
{2'533'000, -1},
{2'600'000, 1},
{2'700'000, -1},
{2'733'000, -1},
{2'766'000, 1},
{2'800'000, 1},
{2'833'000, 1},
{2'866'000, 1},
{2'900'000, 1},
{2'933'000, -1},
{2'966'000, 1},
{3'000'000, 1},
{3'100'000, 1},
{3'166'000, 1},
{3'200'000, 1},
};
const u32 g_qrst_table_size = sizeof(g_qrst_patches) / sizeof(g_qrst_patches[0]);
const AdjustPatch *FindQrstPatch() {
for (u32 i = 0; i < g_qrst_table_size; i++)
if (g_qrst_patches[i].freq == C.marikoEmcMaxClock)
return &g_qrst_patches[i];
return nullptr;
}
const AdjustPatch g_qsafe_patches[] = {
{2'166'000, 1},
{2'200'000, 1},

View File

@@ -37,18 +37,10 @@ namespace ams::ldr::oc::pcv::mariko {
extern const u32 g_ibdly_table_size;
const AdjustPatch *FindIbdlyPatch();
extern const AdjustPatch g_obdly_patches[];
extern const u32 g_obdly_table_size;
const AdjustPatch *FindObdlyPatch();
extern const AdjustPatch g_tr2w_patches[];
extern const u32 g_tr2w_table_size;
const AdjustPatch *FindTR2WPatch();
extern const AdjustPatch g_qrst_patches[];
extern const u32 q_qrst_table_size;
const AdjustPatch *FindQrstPatch();
extern const AdjustPatch g_qsafe_patches[];
extern const u32 g_qsafe_table_size;
const AdjustPatch *FindQsafePatch();
@@ -63,9 +55,7 @@ namespace ams::ldr::oc::pcv::mariko {
struct MiscTimings {
u32 min_freq;
u32 rdv_inc;
u32 einput;
u32 quse_width;
};
extern const MiscTimings g_misc_table[];