Add DRAM info to HW & Fuses screen

This commit is contained in:
Baptiste MOINE committed 2026-05-03 09:42:42 +02:00
1 parent 1bb615e00f
commit 91b85f2b57
5 files changed
+155 -2

No files matched your search

+2 -1
View File
@@ -138,7 +138,8 @@ What's tweakable, grouped by chip:
| **BM92T36** USB-PD | I2C\_1 @ 0x18 | Cable-inserted, PDO voltage, PDO amperage |
| **MAX77620** main PMIC | I2C\_5 @ 0x3C | OTP (Erista / Mariko), silicon revision |
| **MAX77621** CPU/GPU PMIC | I2C\_5 @ 0x1B | Chip ID |
| **Tegra fuses** | FUSE 0x7000F800 | 5 fuse offsets read by Hekate (SKU info, fuse ID, etc.) |
| **Tegra fuses** | FUSE 0x7000F800 | 6 fuse offsets read by Hekate (SKU info, fuse ID, ODM4, etc.) |
| **DRAM modules** | EMC 0xEC (MR5-8)| Vendor (MR5), Rev ID 1/2 (MR6/MR7), per-die density (MR8 5:2) |
| **GPIO** | Port Z bit 1 | SD card insert / eject |
| **Display** | EmuState | Backlight, rotation override |
| **Emulation** | EmuState | Pause / resume, button visualization |
+68
View File
@@ -74,6 +74,11 @@ void reset_to_defaults(EmuState *s) {
s->fuse_0x1A0 = 0x06;
s->fuse_0x148 = 0x83000001;
s->fuse_0x118 = 1785;
s->fuse_0x1D8 = 0x20; // DRAM ID 4 (Samsung K4UBE3D4AA)
s->dram_vendor = 1; // Samsung
s->dram_rev_id1 = 2;
s->dram_rev_id2 = 0;
s->dram_density = 0x18; // 4 GB die
s->backlight = 100;
s->rotation_override = -1;
}
@@ -384,6 +389,69 @@ void build_ui(EmuState *state) {
atomic_hex_input("FUSE 0x118 (ID)", state->fuse_0x118);
atomic_hex_input("FUSE 0x148", state->fuse_0x148);
atomic_hex_input("FUSE 0x1A0", state->fuse_0x1A0);
atomic_hex_input("FUSE 0x1D8 (ODM4)", state->fuse_0x1D8);
ImGui::TextDisabled("DRAM ID = (ODM4 >> 3) & 0x1F (T210B01 also OR's bits 14:12 << 5)");
}
if (ImGui::CollapsingHeader("DRAM modules")) {
// MR5 vendor codes per Hekate gui_info.c.
static const VendorEntry kDramVendors[] = {
{0, "Unknown"},
{1, "Samsung"},
{6, "Hynix"},
{255, "Micron"},
};
vendor_preset_combo("Vendor (MR5)", state->dram_vendor,
kDramVendors, IM_ARRAYSIZE(kDramVendors));
uint8_t v = state->dram_vendor.load();
if (ImGui::InputScalar("Vendor raw", ImGuiDataType_U8, &v, nullptr, nullptr, "%u"))
state->dram_vendor.store(v);
// Hekate prints the rev as "%X.%02X" with MR6 to the left of the dot
// and MR7 to the right (e.g. MR6=2, MR7=0 -> "2.00"; MR6=1, MR7=0x0C
// -> "1.0C"). Surface both bytes as decimal nibbles so the mapping is
// obvious in the UI.
int r1 = (int)state->dram_rev_id1.load();
if (ImGui::SliderInt("Rev major (MR6)", &r1, 0, 15, "%d"))
state->dram_rev_id1.store((uint8_t)r1);
int r2 = (int)state->dram_rev_id2.load();
if (ImGui::SliderInt("Rev minor (MR7)", &r2, 0, 255, "0x%02X"))
state->dram_rev_id2.store((uint8_t)r2);
ImGui::TextDisabled("Hekate displays \"<major>.<minor as 2 hex>\" (e.g. 2.00).");
// Density lives in MR8 bits 5:2. Hekate's gui_info.c only decodes
// codes 2-6; anything higher (3-8 GB dies, JEDEC codes 8-11) is shown
// as "Unk (N)". Restrict the combo to what Hekate prints; the MR8 raw
// input below covers custom codes if you want to exercise that branch.
struct DensityEntry { uint8_t code; const char *name; };
static const DensityEntry kDensities[] = {
{2, "512 MB / die"},
{3, "768 MB / die"},
{4, "1 GB / die"},
{5, "1.5 GB / die"},
{6, "2 GB / die"},
};
uint8_t d = state->dram_density.load();
uint8_t cur = (d & 0x3C) >> 2;
const char *cur_name = "Custom";
for (const auto &e : kDensities) if (e.code == cur) { cur_name = e.name; break; }
char preview[40];
snprintf(preview, sizeof(preview), "%s (code %u)", cur_name, cur);
if (ImGui::BeginCombo("Density (MR8)", preview)) {
for (const auto &e : kDensities) {
char item[40];
snprintf(item, sizeof(item), "%s (code %u)", e.name, e.code);
bool sel = (e.code == cur);
if (ImGui::Selectable(item, sel))
state->dram_density.store((uint8_t)((d & ~0x3C) | (e.code << 2)));
if (sel) ImGui::SetItemDefaultFocus();
}
ImGui::EndCombo();
}
if (ImGui::InputScalar("MR8 raw", ImGuiDataType_U8, &d, nullptr, nullptr, "0x%02X",
ImGuiInputTextFlags_CharsHexadecimal))
state->dram_density.store(d);
ImGui::TextDisabled("Total = die size x ranks x channels (Hekate prints \"<n> x <die>\").");
}
if (ImGui::CollapsingHeader("Emulation")) {
+10
View File
@@ -209,6 +209,16 @@ struct EmuState {
std::atomic<uint32_t> fuse_0x118{1785}; // FUSE_CPU_IDDQ_CALIB
std::atomic<uint32_t> fuse_0x148{0x83000001}; // FUSE_OPT_FT_REV / mixed
std::atomic<uint32_t> fuse_0x1A0{0x06}; // FUSE_OPT_VENDOR_CODE
std::atomic<uint32_t> fuse_0x1D8{0x20}; // FUSE_RESERVED_ODM4 (bits 7:3 = dram_id, 0x20 = id 4)
// DRAM mode register responses. Hekate reads these via the EMC controller
// (sdram_read_mrx) to populate the "Vendor / Rev / Density" columns on
// the HW & Fuses Info screen. Defaults match a Samsung K4F6E304HB-MGCH
// 4 GB module on both channels.
std::atomic<uint8_t> dram_vendor{1}; // MR5 MAN_ID (1=Samsung, 6=Hynix, 255=Micron)
std::atomic<uint8_t> dram_rev_id1{2}; // MR6 REV_ID1
std::atomic<uint8_t> dram_rev_id2{0}; // MR7 REV_ID2
std::atomic<uint8_t> dram_density{0x18}; // MR8 DENSITY (bits 5:2 = density code)
};
#endif // EMU_STATE_H
+5 -1
View File
@@ -79,9 +79,13 @@ constexpr uint64_t PMC_SIZE = 0x0C00;
constexpr uint64_t FUSE_BASE = 0x7000F800;
constexpr uint64_t FUSE_SIZE = 0x0400;
// EMC (External Memory Controller)
// EMC (External Memory Controller). EMC_BASE is the broadcast/control bank;
// EMC0/EMC1 are the per-channel banks used to read mode-register responses
// (sdram_read_mrx splits the 16-bit MRR into low byte = ch0, high byte = ch1).
constexpr uint64_t EMC_BASE = 0x7001B000;
constexpr uint64_t EMC_SIZE = 0x1000;
constexpr uint64_t EMC0_BASE = 0x7001E000;
constexpr uint64_t EMC1_BASE = 0x7001F000;
// MC (Memory Controller)
constexpr uint64_t MC_BASE = 0x70019000;
+70
View File
@@ -1283,6 +1283,9 @@ uint32_t fuse_read(EmuState *state, uint64_t addr) {
case 0x1A0: return state->fuse_0x1A0.load();
case 0x148: return state->fuse_0x148.load();
case 0x118: return state->fuse_0x118.load();
// FUSE_RESERVED_ODM4 - bits 7:3 carry the DRAM ID on T210, with bits 14:12
// appended on T210B01 to extend the range past 7.
case 0x1D8: return state->fuse_0x1D8.load();
default: return 0;
}
}
@@ -1293,6 +1296,63 @@ void fuse_write(EmuState *state, uint64_t addr, uint32_t val) {
(void)val;
}
// ==================== EMC (DRAM mode register reads) ====================
//
// Hekate's HW-info screen calls sdram_read_mrx(MRx), which:
// 1. writes EMC(EMC_MRR) with (rank << 30) | (mrx << 16) on the broadcast
// bank at EMC_BASE,
// 2. polls EMC(EMC_EMC_STATUS) bit 20 (MRR_DIVLD) until set,
// 3. reads EMC_CH0(EMC_MRR) and EMC_CH1(EMC_MRR) from the per-channel
// banks at EMC0_BASE / EMC1_BASE.
//
// We capture the requested mode register on the EMC_MRR write and route the
// per-channel reads back to the matching EmuState atomic.
static constexpr uint32_t EMC_ADR_CFG = 0x010;
static constexpr uint32_t EMC_MRR = 0x0EC;
static constexpr uint32_t EMC_EMC_STATUS = 0x2B4;
static constexpr uint32_t EMC_FBIO_CFG7 = 0x584;
static constexpr uint32_t EMC_STATUS_MRR_DIVLD = 1u << 20;
static uint32_t g_last_mrr_mrx = 5;
static uint8_t emc_mrx_value(EmuState *state, uint32_t mrx) {
switch (mrx) {
case 5: return state->dram_vendor.load();
case 6: return state->dram_rev_id1.load();
case 7: return state->dram_rev_id2.load();
case 8: return state->dram_density.load();
default: return 0;
}
}
uint32_t emc_read(EmuState *state, uint64_t addr) {
uint32_t offset = (uint32_t)(addr & 0xFFF);
bool per_channel = (addr >= EMC0_BASE);
if (per_channel) {
if (offset == EMC_MRR)
return emc_mrx_value(state, g_last_mrr_mrx);
return 0;
}
switch (offset) {
case EMC_ADR_CFG: return 0; // single rank
case EMC_FBIO_CFG7: return (1u << 1) | (1u << 2); // ch0 + ch1 enabled
case EMC_EMC_STATUS: return EMC_STATUS_MRR_DIVLD; // MRR data always valid
case EMC_MRR: return emc_mrx_value(state, g_last_mrr_mrx);
default: return 0;
}
}
void emc_write(EmuState *state, uint64_t addr, uint32_t val) {
(void)state;
uint32_t offset = (uint32_t)(addr & 0xFFF);
if (offset == EMC_MRR && addr < EMC0_BASE) {
g_last_mrr_mrx = (val >> 16) & 0xFF;
}
}
// ==================== SE (Security Engine) ====================
// Real AES-128 implementation lives in t210/se_engine.cpp. The functions
// below are thin shims so the existing dispatcher routing keeps working.
@@ -1491,6 +1551,10 @@ static void hook_mmio_read(uc_engine *uc, uc_mem_type type, uint64_t address,
result = clk_rst_read(state, address);
} else if (address >= FUSE_BASE && address < FUSE_BASE + FUSE_SIZE) {
result = fuse_read(state, address);
} else if ((address >= EMC_BASE && address < EMC_BASE + EMC_SIZE) ||
(address >= EMC0_BASE && address < EMC0_BASE + EMC_SIZE) ||
(address >= EMC1_BASE && address < EMC1_BASE + EMC_SIZE)) {
result = emc_read(state, address);
} else if (address >= SE_BASE && address < SE_BASE + SE_SIZE) {
result = se_read(state, address);
} else {
@@ -1578,6 +1642,10 @@ static void hook_mmio_write(uc_engine *uc, uc_mem_type type, uint64_t address,
clk_rst_write(state, address, val);
} else if (address >= FUSE_BASE && address < FUSE_BASE + FUSE_SIZE) {
fuse_write(state, address, val);
} else if ((address >= EMC_BASE && address < EMC_BASE + EMC_SIZE) ||
(address >= EMC0_BASE && address < EMC0_BASE + EMC_SIZE) ||
(address >= EMC1_BASE && address < EMC1_BASE + EMC_SIZE)) {
emc_write(state, address, val);
} else if (address >= SE_BASE && address < SE_BASE + SE_SIZE) {
se_write(state, address, val);
} else {
@@ -1822,6 +1890,8 @@ void mmio_init(uc_engine *uc, EmuState *state) {
{FUSE_BASE, FUSE_SIZE},
{0x60007000, 0x1000}, // FLOW_CTLR
{EMC_BASE, EMC_SIZE},
{EMC0_BASE, EMC_SIZE},
{EMC1_BASE, EMC_SIZE},
{MC_BASE, MC_SIZE},
{DISPLAY_A_BASE, DISPLAY_SIZE},
{DSI_BASE, DSI_SIZE},