Add a dock and TV model

This commit is contained in:
Baptiste MOINE committed 2026-11-05 23:46:09 +01:00
1 parent 20949b4242
commit 61e1fb981a
10 files changed
+1639 -69

No files matched your search

+7
View File
@@ -39,6 +39,11 @@ slow or destructive.
- Boot a Linux kernel on CPU0 (switchroot's L4T 4.9), with a GIC-400, the - Boot a Linux kernel on CPU0 (switchroot's L4T 4.9), with a GIC-400, the
generic timer, PSCI and the clock controller's reset values for it. See generic timer, PSCI and the clock controller's reset values for it. See
[Booting Linux on CPU0](#booting-linux-on-cpu0). [Booting Linux on CPU0](#booting-linux-on-cpu0).
- Put a dock on the USB-C port (`--dock`): a Nintendo dock, a third-party
USB-C adapter or a Nintendo charger on the BM92T36, the dock's
DisplayPort-to-HDMI converter on DPAUX1, and a TV in a second window that
shows what display head B sends through SOR1. hwtest-rcm's Dock Test runs
its whole handshake and TV link against it.
- Tweak emulated hardware live (battery, charger, thermal, USB-PD, PMIC, - Tweak emulated hardware live (battery, charger, thermal, USB-PD, PMIC,
fuses, SD insertion, the USB host) from a side window. See [Live hardware tweaks](#live-hardware-tweaks). fuses, SD insertion, the USB host) from a side window. See [Live hardware tweaks](#live-hardware-tweaks).
- Inspect each Tegra UART port (TX history) and inject keystrokes into the - Inspect each Tegra UART port (TX history) and inject keystrokes into the
@@ -365,6 +370,7 @@ needed.
| `--fault` | `NAME[,NAME…]` \| `list` | Break a chip or a rail; repeatable. A **chip** fault (`max77812`, `max77621_cpu`, `max77621_gpu`, `bq24193`, `max17050`, `tmp451`, `bm92t36`) makes the part NAK its I2C address, refuse writes and take every rail it supplies down with it. A **rail** fault (`vdd_cpu`) leaves the regulator answering and reading back as enabled while its output never comes up, so only what the rail feeds notices: the CPU RAM repair never completes and CPU0 cannot run. `list` prints the names and exits. Faults survive a payload reboot, like the hardware they model, and add to `[faults]` in the ini (`NAME=dead`). See [DESIGN.md](DESIGN.md#fault-injection). | | `--fault` | `NAME[,NAME…]` \| `list` | Break a chip or a rail; repeatable. A **chip** fault (`max77812`, `max77621_cpu`, `max77621_gpu`, `bq24193`, `max17050`, `tmp451`, `bm92t36`) makes the part NAK its I2C address, refuse writes and take every rail it supplies down with it. A **rail** fault (`vdd_cpu`) leaves the regulator answering and reading back as enabled while its output never comes up, so only what the rail feeds notices: the CPU RAM repair never completes and CPU0 cannot run. `list` prints the names and exits. Faults survive a payload reboot, like the hardware they model, and add to `[faults]` in the ini (`NAME=dead`). See [DESIGN.md](DESIGN.md#fault-injection). |
| `--usb-host` | `nbd[:port]` (optional) | A PC on the USB-C port. It enumerates whatever USB gadget the payload brings up; a mass storage disk is read back (checked against the SD image), its last 8 sectors are written back unchanged and read again unless it is write-protected, and it is ejected; HID reports are polled. With `nbd` the disk is served over NBD on 127.0.0.1 (port 10809 by default) until the client disconnects, then ejected - see [Mounting a gadget's disk](#mounting-a-gadgets-disk). Logged as `[usb-host]`; `RCM_USB_TRACE=1` traces every transfer. Overrides `[usb] host` and `[usb] nbd_port` in the ini. | | `--usb-host` | `nbd[:port]` (optional) | A PC on the USB-C port. It enumerates whatever USB gadget the payload brings up; a mass storage disk is read back (checked against the SD image), its last 8 sectors are written back unchanged and read again unless it is write-protected, and it is ejected; HID reports are polled. With `nbd` the disk is served over NBD on 127.0.0.1 (port 10809 by default) until the client disconnects, then ejected - see [Mounting a gadget's disk](#mounting-a-gadgets-disk). Logged as `[usb-host]`; `RCM_USB_TRACE=1` traces every transfer. Overrides `[usb] host` and `[usb] nbd_port` in the ini. |
| `--load` | `FILE@ADDR` | Place a file in DRAM before the payload starts, the way a bootloader leaves a kernel and its device tree; repeatable. See [Booting Linux on CPU0](#booting-linux-on-cpu0). | | `--load` | `FILE@ADDR` | Place a file in DRAM before the payload starts, the way a bootloader leaves a kernel and its device tree; repeatable. See [Booting Linux on CPU0](#booting-linux-on-cpu0). |
| `--dock` | `nintendo` \| `thirdparty` \| `charger` \| `none`, `:notv` | What is on the USB-C port, behind the BM92T36: a Nintendo dock (057E:2003, 15 V, Nintendo's alt mode, DisplayPort on pin D), a third-party adapter (Fresco Logic 1D5C:7102, four power profiles, the DisplayPort SVID) or the Nintendo charger (057E:2004, no video). A dock's DisplayPort-to-HDMI converter answers on DPAUX1 (DPCD 1.2, the TV's EDID over I2C-over-AUX), and SOR1 judges link training lane by lane against the board's wiring; once trained, head B's frames show in a TV window. `:notv` leaves the dock's HDMI empty. `RCM_EMU_TV_SNAP=file` saves the TV picture, `RCM_EMU_DPTRACE=file` traces DPAUX1 and SOR1. Overrides `[dock] kind` and `[dock] tv` in the ini. Default `none`. |
| `--input-script` | file or spec | Scripted input keyed to emulated time: `<ms> P\|U\|D [hold_ms]` presses POWER / VOL+ / VOL-, `<ms> TAP <x> <y> [hold_ms]` taps the touchscreen at (x, y) in the 1280x720 picture, `<ms> SNAP <file>` saves the next displayed frame to `<file>` (raw B, G, R, A like `last_fb.rgba`, size in the matching `.meta`), `+N` times an event N ms after the previous one. Events are separated by `,`, `;` or newlines. | | `--input-script` | file or spec | Scripted input keyed to emulated time: `<ms> P\|U\|D [hold_ms]` presses POWER / VOL+ / VOL-, `<ms> TAP <x> <y> [hold_ms]` taps the touchscreen at (x, y) in the 1280x720 picture, `<ms> SNAP <file>` saves the next displayed frame to `<file>` (raw B, G, R, A like `last_fb.rgba`, size in the matching `.meta`), `+N` times an event N ms after the previous one. Events are separated by `,`, `;` or newlines. |
| `--auto-pin-recovery` | (none) | Drive the Lockpick PIN-recovery menu without user input. | | `--auto-pin-recovery` | (none) | Drive the Lockpick PIN-recovery menu without user input. |
| `--auto-te-script` | (none) | Drive `recover_pin.te` in TegraExplorer without input. | | `--auto-te-script` | (none) | Drive `recover_pin.te` in TegraExplorer without input. |
@@ -386,6 +392,7 @@ flowchart LR
t210 --> se["se_engine.{h,cpp}<br/>AES-128, SHA-256, RSA, RNG"] t210 --> se["se_engine.{h,cpp}<br/>AES-128, SHA-256, RSA, RNG"]
t210 --> i2c["i2c3.{h,cpp}<br/>STMFTS / FTS4 touch"] t210 --> i2c["i2c3.{h,cpp}<br/>STMFTS / FTS4 touch"]
t210 --> usb["usb.{h,cpp}<br/>USB device controllers + host PC"] t210 --> usb["usb.{h,cpp}<br/>USB device controllers + host PC"]
t210 --> dock["dock.{h,cpp}<br/>BM92T36, the dock, DPAUX1, SOR1"]
display --> sdl["sdl_display.{h,cpp}<br/>DC window scan-out<br/>+ SDL2"] display --> sdl["sdl_display.{h,cpp}<br/>DC window scan-out<br/>+ SDL2"]
``` ```
+2
View File
@@ -140,6 +140,8 @@ void reset_to_defaults(EmuState *s) {
X(usb_pd_inserted, "usb_pd", "inserted", 0) \ X(usb_pd_inserted, "usb_pd", "inserted", 0) \
X(usb_pd_voltage_mv, "usb_pd", "voltage_mv", 0) \ X(usb_pd_voltage_mv, "usb_pd", "voltage_mv", 0) \
X(usb_pd_amperage_ma, "usb_pd", "amperage_ma", 0) \ X(usb_pd_amperage_ma, "usb_pd", "amperage_ma", 0) \
X(dock_kind, "dock", "kind", 0) \
X(dock_tv, "dock", "tv", 0) \
X(usb_host, "usb", "host", 0) \ X(usb_host, "usb", "host", 0) \
X(usb_nbd_port, "usb", "nbd_port", 0) \ X(usb_nbd_port, "usb", "nbd_port", 0) \
/* SoC / PMIC */ \ /* SoC / PMIC */ \
+97 -5
View File
@@ -1,4 +1,6 @@
#include "sdl_display.h" #include "sdl_display.h"
#include "../t210/dock.h"
#include "../t210/mmio.h"
#include <string> #include <string>
#include "config_window.h" #include "config_window.h"
#include "console_window.h" #include "console_window.h"
@@ -291,8 +293,9 @@ uint32_t dst_factor(uint32_t sel, uint32_t k1, uint32_t k2, uint32_t sa) {
} }
} }
// Draw window w onto the panel picture. // Draw window w onto the panel picture (pw x ph, row-major).
void draw_window(const Win &w, std::vector<uint32_t> &panel) { void draw_window(const Win &w, std::vector<uint32_t> &panel, uint32_t pw = kPanelW,
uint32_t ph = kPanelH) {
bool blend = !(w.blend_layer & (1u << 24)); bool blend = !(w.blend_layer & (1u << 24));
uint32_t k1 = (w.blend_layer >> 8) & 0xFF, k2 = (w.blend_layer >> 16) & 0xFF; uint32_t k1 = (w.blend_layer >> 8) & 0xFF, k2 = (w.blend_layer >> 16) & 0xFF;
uint32_t ssel = w.blend_match & 7, dsel = (w.blend_match >> 4) & 7; uint32_t ssel = w.blend_match & 7, dsel = (w.blend_match >> 4) & 7;
@@ -305,12 +308,12 @@ void draw_window(const Win &w, std::vector<uint32_t> &panel) {
txs[ox] = (uint32_t)((uint64_t)ox * w.pre_w / w.out_w); txs[ox] = (uint32_t)((uint64_t)ox * w.pre_w / w.out_w);
for (uint32_t oy = 0; oy < w.out_h; oy++) { for (uint32_t oy = 0; oy < w.out_h; oy++) {
int32_t py = w.y + (int32_t)oy; int32_t py = w.y + (int32_t)oy;
if (py < 0 || py >= (int32_t)kPanelH) if (py < 0 || py >= (int32_t)ph)
continue; continue;
uint32_t ty = (uint32_t)((uint64_t)oy * w.pre_h / w.out_h); uint32_t ty = (uint32_t)((uint64_t)oy * w.pre_h / w.out_h);
for (uint32_t ox = 0; ox < w.out_w; ox++) { for (uint32_t ox = 0; ox < w.out_w; ox++) {
int32_t px = w.x + (int32_t)ox; int32_t px = w.x + (int32_t)ox;
if (px < 0 || px >= (int32_t)kPanelW) if (px < 0 || px >= (int32_t)pw)
continue; continue;
uint32_t tx = txs[ox]; uint32_t tx = txs[ox];
// (tx, ty) is post-turn; walk it back to the surface. // (tx, ty) is post-turn; walk it back to the surface.
@@ -323,7 +326,7 @@ void draw_window(const Win &w, std::vector<uint32_t> &panel) {
if (off + w.bpp > w.len) if (off + w.bpp > w.len)
continue; continue;
uint32_t s = depth_argb(w.mem + off, w.depth); uint32_t s = depth_argb(w.mem + off, w.depth);
uint32_t &d = panel[(size_t)py * kPanelW + px]; uint32_t &d = panel[(size_t)py * pw + px];
if (!blend) { if (!blend) {
d = s | 0xFF000000u; d = s | 0xFF000000u;
continue; continue;
@@ -340,9 +343,98 @@ void draw_window(const Win &w, std::vector<uint32_t> &panel) {
} }
} }
// ---- The TV on the dock ------------------------------------------------------
//
// A second window, shown while a dock with video is configured: head B's
// windows composed at the head's active size, as SOR1 sends them, when the
// dock model says frames reach the TV; otherwise a dark screen, and the
// window title says why there is no picture.
SDL_Window *tv_window = nullptr;
SDL_Renderer *tv_renderer = nullptr;
SDL_Texture *tv_texture = nullptr;
uint32_t tv_tex_w = 0, tv_tex_h = 0;
std::string tv_title;
void tv_update(EmuState *state, uc_engine *uc) {
uint8_t k = state->dock_kind.load();
bool want = (k == 1 || k == 2) && state->dock_tv.load();
if (!want) {
if (tv_window)
SDL_HideWindow(tv_window);
return;
}
if (!tv_window) {
tv_window = SDL_CreateWindow("TV (dock HDMI)", SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED, 960, 540,
SDL_WINDOW_RESIZABLE);
if (!tv_window)
return;
tv_renderer = SDL_CreateRenderer(tv_window, -1, SDL_RENDERER_ACCELERATED);
if (!tv_renderer)
tv_renderer = SDL_CreateRenderer(tv_window, -1, SDL_RENDERER_SOFTWARE);
}
SDL_ShowWindow(tv_window);
TvState t;
dock_tv_state(state, &t);
uint32_t act = mmio_bus_read(state, 0x54240000 + 0x409 * 4, 4);
uint32_t w = act & 0x1FFF, h = (act >> 16) & 0x1FFF;
char title[256];
if (t.video && w && h)
snprintf(title, sizeof(title), "TV (dock HDMI) - %ux%u, %s", w, h, t.status);
else
snprintf(title, sizeof(title), "TV (dock HDMI) - no signal: %s", t.status);
if (tv_title != title) {
tv_title = title;
SDL_SetWindowTitle(tv_window, title);
printf("[tv] %s\n", title + 16);
fflush(stdout);
}
SDL_SetRenderDrawColor(tv_renderer, 8, 8, 24, 255);
SDL_RenderClear(tv_renderer);
if (t.video && w && h && w <= 4096 && h <= 4096) {
std::vector<uint32_t> pic((size_t)w * h, 0xFF000000u);
std::vector<Win> wins;
for (int i = 0; i < 4; i++) {
Win wn;
if (load_window(state, uc, i, state->dcb_win_active[i], -1, wn))
wins.push_back(std::move(wn));
}
std::stable_sort(wins.begin(), wins.end(),
[](const Win &a, const Win &b) { return a.layer > b.layer; });
for (const Win &wn : wins)
draw_window(wn, pic, w, h);
if (!tv_texture || tv_tex_w != w || tv_tex_h != h) {
if (tv_texture)
SDL_DestroyTexture(tv_texture);
tv_texture = SDL_CreateTexture(tv_renderer, SDL_PIXELFORMAT_ARGB8888,
SDL_TEXTUREACCESS_STREAMING, (int)w, (int)h);
tv_tex_w = w;
tv_tex_h = h;
}
if (tv_texture) {
SDL_UpdateTexture(tv_texture, nullptr, pic.data(), (int)(w * 4));
SDL_RenderCopy(tv_renderer, tv_texture, nullptr, nullptr);
}
if (const char *snap = getenv("RCM_EMU_TV_SNAP")) {
static uint64_t last = 0;
if (state->emu_usec - last > 500000) {
last = state->emu_usec;
if (FILE *f = fopen(snap, "wb")) {
fwrite(&w, 4, 1, f);
fwrite(&h, 4, 1, f);
fwrite(pic.data(), 4, pic.size(), f);
fclose(f);
}
}
}
}
SDL_RenderPresent(tv_renderer);
}
} // namespace } // namespace
void sdl_display_update(EmuState *state, uc_engine *uc) { void sdl_display_update(EmuState *state, uc_engine *uc) {
tv_update(state, uc);
if (!renderer) if (!renderer)
return; return;
+11
View File
@@ -290,6 +290,12 @@ struct EmuState {
uint32_t dc_win[4][dcwin::kRegs] = {}; uint32_t dc_win[4][dcwin::kRegs] = {};
uint32_t dc_win_active[4][dcwin::kRegs] = {}; uint32_t dc_win_active[4][dcwin::kRegs] = {};
uint32_t dc_window_header = 0; // DC_CMD_DISPLAY_WINDOW_HEADER uint32_t dc_window_header = 0; // DC_CMD_DISPLAY_WINDOW_HEADER
// Display head B (DC1, 0x54240000): the head that feeds SOR1 and the
// dock. Same window model as head A, scanned out to the TV window.
uint32_t dcb_win[4][dcwin::kRegs] = {};
uint32_t dcb_win_active[4][dcwin::kRegs] = {};
uint32_t dcb_window_header = 0;
bool dcb_programmed = false;
// False from reset until the payload first activates a window. Until // False from reset until the payload first activates a window. Until
// then the scan-out shows the emulator's own framebuffer (FB_BASE). // then the scan-out shows the emulator's own framebuffer (FB_BASE).
bool dc_programmed = false; bool dc_programmed = false;
@@ -499,6 +505,11 @@ struct EmuState {
// USB-PD controller (BM92T36, I2C1 @ 0x18). One synthesized fixed PDO. // USB-PD controller (BM92T36, I2C1 @ 0x18). One synthesized fixed PDO.
std::atomic<bool> usb_pd_inserted{false}; std::atomic<bool> usb_pd_inserted{false};
// The dock on the USB-C port (t210/dock.h DockKind) and whether a TV is
// on its HDMI output. [dock] kind=0 none, 1 Nintendo dock, 2 third-party
// adapter, 3 Nintendo charger; tv=0/1. --dock overrides.
std::atomic<uint8_t> dock_kind{0};
std::atomic<bool> dock_tv{true};
std::atomic<uint16_t> usb_pd_voltage_mv{5000}; std::atomic<uint16_t> usb_pd_voltage_mv{5000};
std::atomic<uint16_t> usb_pd_amperage_ma{1500}; std::atomic<uint16_t> usb_pd_amperage_ma{1500};
+22
View File
@@ -27,6 +27,7 @@
#include "trace.h" #include "trace.h"
#include "t210/bpmp.h" #include "t210/bpmp.h"
#include "t210/ccplex.h" #include "t210/ccplex.h"
#include "t210/dock.h"
#include "t210/memory_map.h" #include "t210/memory_map.h"
#include "t210/mmio.h" #include "t210/mmio.h"
#include "display/sdl_display.h" #include "display/sdl_display.h"
@@ -340,6 +341,23 @@ int main(int argc, char *argv[]) {
rawnand_prefix = argv[++i]; rawnand_prefix = argv[++i];
} else if (strcmp(argv[i], "--prod-keys") == 0 && i + 1 < argc) { } else if (strcmp(argv[i], "--prod-keys") == 0 && i + 1 < argc) {
prod_keys_path = argv[++i]; prod_keys_path = argv[++i];
} else if (strcmp(argv[i], "--dock") == 0 && i + 1 < argc) {
// What is on the USB-C port. Same contract as --oem: overrides
// the ini. "nintendo", "thirdparty" (Ugreen-style), "charger",
// "none"; append ":notv" for a dock with nothing on its HDMI.
const char *d = argv[++i];
uint8_t k = 0xFF;
if (!strncmp(d, "nintendo", 8)) k = 1;
else if (!strncmp(d, "thirdparty", 10) || !strncmp(d, "ugreen", 6)) k = 2;
else if (!strncmp(d, "charger", 7)) k = 3;
else if (!strncmp(d, "none", 4)) k = 0;
if (k == 0xFF) {
fprintf(stderr, "[emu] Unknown --dock '%s'; expected nintendo, thirdparty, charger or none\n", d);
return 1;
}
state.dock_kind = k;
state.dock_tv = strstr(d, ":notv") == nullptr;
printf("[emu] Dock: %s%s [overrides ini]\n", d, "");
} else if (strcmp(argv[i], "--oem") == 0 && i + 1 < argc) { } else if (strcmp(argv[i], "--oem") == 0 && i + 1 < argc) {
const char *oem = argv[++i]; const char *oem = argv[++i];
if (strcmp(oem, "mariko") == 0 || strcmp(oem, "t210b01") == 0) { if (strcmp(oem, "mariko") == 0 || strcmp(oem, "t210b01") == 0) {
@@ -802,6 +820,8 @@ int main(int argc, char *argv[]) {
state.emu_usec += CPU0_QUANTUM_INSTRUCTIONS / 10; state.emu_usec += CPU0_QUANTUM_INSTRUCTIONS / 10;
state.bpmp_slept_us += CPU0_QUANTUM_INSTRUCTIONS / 10; state.bpmp_slept_us += CPU0_QUANTUM_INSTRUCTIONS / 10;
ccplex_run(&state, state.emu_usec); ccplex_run(&state, state.emu_usec);
dock_tick(&state);
display_tick(&state);
if (state.reboot_requested.load()) if (state.reboot_requested.load())
break; break;
continue; continue;
@@ -825,6 +845,8 @@ int main(int argc, char *argv[]) {
} }
// CPU0 catches up to the BPMP's clock. // CPU0 catches up to the BPMP's clock.
ccplex_run(&state, state.emu_usec); ccplex_run(&state, state.emu_usec);
dock_tick(&state);
display_tick(&state);
if (state.reboot_requested.load()) if (state.reboot_requested.load())
break; break;
} }
+1218
View File
File diff suppressed because it is too large. Load diff
+72
View File
@@ -0,0 +1,72 @@
#ifndef T210_DOCK_H
#define T210_DOCK_H
#include <cstdint>
struct EmuState;
/*
* The USB-C port, the dock on it and the TV behind the dock.
*
* BM92T36 (I2C1 0x18): the PD controller's registers and commands as
* switchroot's bm92txx.c and HOS's usb sysmodule drive them, with a partner
* on the cable that answers the way the measured docks did: a Nintendo dock
* (057E:2003, 5 V 0.5 A + 15 V 3 A, Nintendo alt mode, DP pin D), a third-
* party adapter (Fresco Logic 1D5C:7102, four PDOs, DisplayPort SVID) or
* the Nintendo charger (057E:2004, no video). Its interrupt is GPIO PK4,
* active low; its reset is PV5.
*
* DPAUX1 (0x54040000): the AUX channel to the dock's DisplayPort-to-HDMI
* converter (Realtek OUI 00-E0-4C, DPCD 1.2), its DPCD, and the TV's EDID
* over I2C-over-AUX. HPD reaches DPAUX1 only while the hdmi_int_dp_hpd pad
* is in SFIO mode, as measured.
*
* SOR1 (0x54580000): link training is judged lane by lane against what the
* board does - DP lane 0 leaves the SoC on pad 0 and lane 1 on pad 1, so the
* crossbar has to route them there (L4T's nvidia,xbar-ctrl <2 1 0 3 4>), and
* a lane only trains with its pad powered, the macro PLL up, PLLDP locked
* and SOR1 clocked from the brick at the rate the sink was told.
*/
enum DockKind : uint8_t {
DOCK_NONE = 0,
DOCK_NINTENDO = 1,
DOCK_THIRD_PARTY = 2, // Ugreen-style adapter: Fresco Logic 1D5C:7102
DOCK_CHARGER = 3, // Nintendo charger, no DisplayPort
};
void dock_reset(EmuState *state);
// Advance the dock's timers to state->emu_usec. Cheap; called often.
void dock_tick(EmuState *state);
// BM92T36. A write carries its register first; a read returns n bytes from
// `reg` on (block registers lead with their length byte, as on the chip).
bool bm92_present(EmuState *state);
void bm92_write(EmuState *state, const uint8_t *buf, uint32_t n);
void bm92_read(EmuState *state, uint8_t reg, uint8_t *out, uint32_t n);
// PK4 as the SoC sees it: false while an enabled alert is pending.
bool bm92_alert_line(EmuState *state);
// PV5 driven by the SoC: high holds the chip in reset.
void bm92_reset_line(EmuState *state, bool high);
// HPD from the dock's DisplayPort sink.
bool dock_hpd(EmuState *state);
// DPAUX1 and SOR1 register windows (byte offsets).
uint32_t dpaux1_read(EmuState *state, uint32_t off);
void dpaux1_write(EmuState *state, uint32_t off, uint32_t val);
uint32_t sor1_read(EmuState *state, uint32_t off);
void sor1_write(EmuState *state, uint32_t off, uint32_t val);
// What the TV shows, for its window.
struct TvState {
bool connected; // a dock with a TV behind it is on the cable
bool hpd; // the converter raised HPD to the SoC
bool link_trained; // every configured lane has CR, EQ, symbol lock
bool video; // SOR1 attached to a running head: frames flow
uint32_t lanes, rate_code;
char status[160]; // one line for the "no signal" screen
};
void dock_tv_state(EmuState *state, TvState *out);
#endif // T210_DOCK_H
+1
View File
@@ -108,6 +108,7 @@ constexpr uint64_t MC_SIZE = 0x1000;
// Display Controller (DC/DSI) // Display Controller (DC/DSI)
constexpr uint64_t DISPLAY_A_BASE = 0x54200000; constexpr uint64_t DISPLAY_A_BASE = 0x54200000;
constexpr uint64_t DISPLAY_B_BASE = 0x54240000; // DC1: feeds SOR1 / the dock
constexpr uint64_t DISPLAY_SIZE = 0x40000; constexpr uint64_t DISPLAY_SIZE = 0x40000;
// DSI Controller // DSI Controller
+207 -64
View File
@@ -9,6 +9,7 @@
#include "ccplex.h" #include "ccplex.h"
#include "pcie.h" #include "pcie.h"
#include "gic.h" #include "gic.h"
#include "dock.h"
#include "usb.h" #include "usb.h"
#include "regcache.h" #include "regcache.h"
#include "se_engine.h" #include "se_engine.h"
@@ -541,6 +542,19 @@ uint32_t gpio_read(EmuState *state, uint64_t addr) {
// PH5/BT_HOST_WAKE and PH3/BT_DEV_WAKE are read while the Tegra is // PH5/BT_HOST_WAKE and PH3/BT_DEV_WAKE are read while the Tegra is
// deliberately not driving them, and mirroring OUT there answers 0 to every // deliberately not driving them, and mirroring OUT there answers 0 to every
// question regardless of what is on the board. // question regardless of what is on the board.
// Port K (bank 2, port 2): PK4 is the PD controller's alert, active low.
// Port CC (bank 7, port 0): CC1 is HPD from the dock. Both read the pin
// when it is an input, as in GPIO mode they are.
if (offset == 0x238 || offset == 0x730) {
uint32_t v = mmio_regs.get(addr - 0x10);
uint32_t oe = mmio_regs.get(addr - 0x20);
uint32_t bit = offset == 0x238 ? (1u << 4) : (1u << 1);
bool level = offset == 0x238 ? bm92_alert_line(state) : dock_hpd(state);
if (!(oe & bit))
v = level ? (v | bit) : (v & ~bit);
return v;
}
if (offset == 0x13C) { if (offset == 0x13C) {
uint32_t v = gpio_h_in(state); uint32_t v = gpio_h_in(state);
TRACE("[gpio] R: Port H IN = 0x%02X\n", v); TRACE("[gpio] R: Port H IN = 0x%02X\n", v);
@@ -624,6 +638,13 @@ void gpio_write(EmuState *state, uint64_t addr, uint32_t val) {
gpio_h_update(state); gpio_h_update(state);
sd_card_gpio_update(); sd_card_gpio_update();
} }
// Port V (bank 5, port 1): PV5 drives the PD controller's reset, high =
// held. Only once it is a GPIO output: as the SFIO it rests low.
if (offset >= 0x500 && offset < 0x600) {
uint32_t cnf = mmio_regs.get(GPIO_BASE + 0x504), oe = mmio_regs.get(GPIO_BASE + 0x514);
uint32_t out = mmio_regs.get(GPIO_BASE + 0x524);
bm92_reset_line(state, (cnf & oe & out & (1u << 5)) != 0);
}
} }
// ==================== I2C ==================== // ==================== I2C ====================
@@ -647,6 +668,8 @@ void gpio_write(EmuState *state, uint64_t addr, uint32_t val) {
static uint8_t i2c_slave_addr = 0; static uint8_t i2c_slave_addr = 0;
static uint8_t i2c_reg_addr = 0; static uint8_t i2c_reg_addr = 0;
// What the last normal-mode read of the BM92T36 returned, for CMD_DATA1/2.
static uint8_t bm92_normal_rx[8];
// Last full CMD_DATA1 word, committed when I2C_CNFG starts the transfer. // Last full CMD_DATA1 word, committed when I2C_CNFG starts the transfer.
static uint32_t i2c_cmd_data1 = 0; static uint32_t i2c_cmd_data1 = 0;
@@ -799,7 +822,8 @@ static bool i2c_slave_fitted(EmuState *state, bool on_i2c5, uint8_t addr) {
} }
} }
switch (addr) { switch (addr) {
case 0x18: // BM92T36 USB-PD case 0x18: // BM92T36 USB-PD: NAKs in reset and while it boots
return bm92_present(state);
case 0x36: // MAX17050 fuel gauge case 0x36: // MAX17050 fuel gauge
case 0x4C: // TMP451 thermal case 0x4C: // TMP451 thermal
case 0x6B: // BQ24193 charger case 0x6B: // BQ24193 charger
@@ -987,49 +1011,22 @@ struct PacketState {
uint8_t rx_buf[64] = {0}; uint8_t rx_buf[64] = {0};
uint32_t rx_size = 0; uint32_t rx_size = 0;
uint32_t rx_pos = 0; uint32_t rx_pos = 0;
uint8_t tx_buf[64] = {0}; // a write's payload, for chips that take
// whole messages (the BM92T36)
}; };
static PacketState pkt_i2c1; static PacketState pkt_i2c1;
static PacketState pkt_i2c5; static PacketState pkt_i2c5;
// I2C_INT_STATUS per controller (I2C1, I2C5): PACKET_XFER_COMPLETE (7) and
// ALL_PACKETS_XFER_COMPLETE (6) latch when a packet finishes, NO_ACK (3)
// when nobody answered; write 1 to clear. BUS_CLEAR_DONE (11) always reads
// set, as before.
static uint32_t i2c_int_latch[2];
#define I2C_PACKET_PROT_I2C (1u << 4) #define I2C_PACKET_PROT_I2C (1u << 4)
#define I2C_HEADER_READ (1u << 19) #define I2C_HEADER_READ (1u << 19)
static void bm92t36_fill_rx(EmuState *state, uint8_t reg, uint8_t *buf, uint32_t size) { // The BM92T36 itself is t210/dock.cpp; packet and normal-mode accesses
// All multi-byte values are little-endian on the wire (Hekate reassembles // to I2C1 0x18 are routed there.
// with `(buf[1] << 8) | buf[0]`). FW_TYPE is the exception — Hekate uses
// `(buf[0] << 4) | buf[1]` and expects 0x36, so buf[0]=3, buf[1]=6.
auto put = [&](uint32_t i, uint8_t v) { if (i < size) buf[i] = v; };
switch (reg) {
case 0x03: // STATUS1: bit 7 = cable inserted
put(0, state->usb_pd_inserted.load() ? 0x80 : 0x00);
break;
case 0x4B: // FW_TYPE_REG -> VER_36 = 0x36
put(0, 0x03); put(1, 0x06);
break;
case 0x4D: // MAN_ID_REG -> MAN_ROHM = 0x04B5
put(0, 0xB5); put(1, 0x04);
break;
case 0x4E: // DEV_ID_REG -> DEV_BM92T = 0x03B0
put(0, 0xB0); put(1, 0x03);
break;
case 0x08: // READ_PDOS_SRC: byte0 = PDO-bytes count, then 4-byte PDOs
case 0x28: { // CURRENT_PDO: same layout, 1 PDO
// Synthesize a single Fixed-type PDO from the EmuState values.
// pd_object_t bitfields (LSB->MSB): amp:10, volt:10, info:10, type:2.
uint32_t amp_lsb = (uint32_t)(state->usb_pd_amperage_ma.load() / 10) & 0x3FF;
uint32_t volt_lsb = (uint32_t)(state->usb_pd_voltage_mv.load() / 50) & 0x3FF;
uint32_t pdo = amp_lsb | (volt_lsb << 10);
put(0, 4);
put(1, (uint8_t)(pdo >> 0));
put(2, (uint8_t)(pdo >> 8));
put(3, (uint8_t)(pdo >> 16));
put(4, (uint8_t)(pdo >> 24));
break;
}
default:
break;
}
}
// ==================== I2C_2: Rohm BH1730 ambient light sensor ============ // ==================== I2C_2: Rohm BH1730 ambient light sensor ============
// //
@@ -1097,7 +1094,7 @@ static void packet_populate_rx(EmuState *state, bool on_i2c5, PacketState &p) {
p.rx_size = std::min((uint32_t)sizeof(p.rx_buf), p.payload_size); p.rx_size = std::min((uint32_t)sizeof(p.rx_buf), p.payload_size);
memset(p.rx_buf, 0, sizeof(p.rx_buf)); memset(p.rx_buf, 0, sizeof(p.rx_buf));
if (!on_i2c5 && p.dev_addr == 0x18) { if (!on_i2c5 && p.dev_addr == 0x18) {
bm92t36_fill_rx(state, p.reg_addr, p.rx_buf, p.rx_size); bm92_read(state, p.reg_addr, p.rx_buf, p.rx_size);
return; return;
} }
// Every other slave: serve packet-mode reads from the same register models // Every other slave: serve packet-mode reads from the same register models
@@ -1134,7 +1131,7 @@ uint32_t i2c_read(EmuState *state, uint64_t addr) {
case 0x8C: // I2C_CONFIG_LOAD case 0x8C: // I2C_CONFIG_LOAD
return 0; // MSTR_CONFIG_LOAD (bit 0) cleared = load complete return 0; // MSTR_CONFIG_LOAD (bit 0) cleared = load complete
case 0x68: // I2C_INT_STATUS case 0x68: // I2C_INT_STATUS
return (1 << 11); // BUS_CLEAR_DONE (bit 11) return i2c_int_latch[on_i2c5 ? 1 : 0] | (1 << 11);
case 0x54: { // I2C_RX_FIFO (packet-mode receive) case 0x54: { // I2C_RX_FIFO (packet-mode receive)
uint32_t word = 0; uint32_t word = 0;
uint32_t n = std::min((uint32_t)4, pkt.rx_size - pkt.rx_pos); uint32_t n = std::min((uint32_t)4, pkt.rx_size - pkt.rx_pos);
@@ -1156,9 +1153,15 @@ uint32_t i2c_read(EmuState *state, uint64_t addr) {
} }
return 0; return 0;
} }
case 0x10: // I2C_CMD_DATA2 (bytes 4-7) — no slaves currently need a >4 byte response case 0x10: // I2C_CMD_DATA2 (bytes 4-7): only the PD controller fills it
if (!on_i2c5 && i2c_slave_addr == 0x18)
return bm92_normal_rx[4] | bm92_normal_rx[5] << 8 | bm92_normal_rx[6] << 16 |
(uint32_t)bm92_normal_rx[7] << 24;
return 0; return 0;
case 0x0C: // I2C_CMD_DATA1 case 0x0C: // I2C_CMD_DATA1
if (!on_i2c5 && i2c_slave_addr == 0x18)
return bm92_normal_rx[0] | bm92_normal_rx[1] << 8 | bm92_normal_rx[2] << 16 |
(uint32_t)bm92_normal_rx[3] << 24;
// TMP451 SoC/PCB thermal sensor (slave 0x4C on I2C_1). // TMP451 SoC/PCB thermal sensor (slave 0x4C on I2C_1).
// Hekate reads (per bdk/thermal/tmp451.c) the integer °C from // Hekate reads (per bdk/thermal/tmp451.c) the integer °C from
// PCB: 0x00, SoC: 0x01 // PCB: 0x00, SoC: 0x01
@@ -1503,6 +1506,20 @@ void i2c_write(EmuState *state, uint64_t addr, uint32_t val) {
i2c_cnfg_reg[on_i2c5 ? 1 : 0] = val; i2c_cnfg_reg[on_i2c5 ? 1 : 0] = val;
bool is_write = (val & (1u << 6)) == 0; bool is_write = (val & (1u << 6)) == 0;
uint32_t size = ((val >> 1) & 7) + 1; uint32_t size = ((val >> 1) & 7) + 1;
// BM92T36: whole messages, normal mode (up to 8 bytes in CMD_DATA1/2).
if ((val & (1u << 9)) && !on_i2c5 && i2c_slave_addr == 0x18 &&
i2c_slave_present(state, false, 0x18)) {
uint32_t d2 = mmio_regs.get(I2C1_BASE + 0x10);
uint8_t b[8];
for (int k = 0; k < 4; k++) {
b[k] = (uint8_t)(i2c_cmd_data1 >> (8 * k));
b[4 + k] = (uint8_t)(d2 >> (8 * k));
}
if (is_write && size >= 2)
bm92_write(state, b, size);
else if (!is_write)
bm92_read(state, i2c_reg_addr, bm92_normal_rx, size);
}
if ((val & (1u << 9)) && is_write && size >= 2 && on_i2c5 && if ((val & (1u << 9)) && is_write && size >= 2 && on_i2c5 &&
i2c_slave_addr == MAX77620_I2C_ADDR) { i2c_slave_addr == MAX77620_I2C_ADDR) {
max77620_regs_init(state); max77620_regs_init(state);
@@ -1598,6 +1615,8 @@ void i2c_write(EmuState *state, uint64_t addr, uint32_t val) {
if (pkt.is_read) { if (pkt.is_read) {
packet_populate_rx(state, on_i2c5, pkt); packet_populate_rx(state, on_i2c5, pkt);
pkt.hdr_idx = 0; pkt.hdr_idx = 0;
i2c_int_latch[on_i2c5 ? 1 : 0] |= (1u << 7) | (1u << 6) |
(i2c_slave_present(state, on_i2c5, pkt.dev_addr) ? 0 : (1u << 3));
} else { } else {
pkt.hdr_idx = 3; pkt.hdr_idx = 3;
} }
@@ -1605,6 +1624,8 @@ void i2c_write(EmuState *state, uint64_t addr, uint32_t val) {
default: default:
for (int k = 0; k < 4 && pkt.tx_seen < pkt.payload_size; k++) { for (int k = 0; k < 4 && pkt.tx_seen < pkt.payload_size; k++) {
uint8_t b = (uint8_t)(val >> (8 * k)); uint8_t b = (uint8_t)(val >> (8 * k));
if (pkt.tx_seen < sizeof(pkt.tx_buf))
pkt.tx_buf[pkt.tx_seen] = b;
if (pkt.tx_seen == 0) if (pkt.tx_seen == 0)
pkt.reg_addr = b; // first payload byte: the register address pkt.reg_addr = b; // first payload byte: the register address
else else
@@ -1612,12 +1633,22 @@ void i2c_write(EmuState *state, uint64_t addr, uint32_t val) {
(uint8_t)(pkt.reg_addr + pkt.tx_seen - 1), b); (uint8_t)(pkt.reg_addr + pkt.tx_seen - 1), b);
pkt.tx_seen++; pkt.tx_seen++;
} }
if (pkt.tx_seen >= pkt.payload_size) if (pkt.tx_seen >= pkt.payload_size) {
pkt.hdr_idx = 0; pkt.hdr_idx = 0;
i2c_int_latch[on_i2c5 ? 1 : 0] |= (1u << 7) | (1u << 6) |
(i2c_slave_present(state, on_i2c5, pkt.dev_addr) ? 0 : (1u << 3));
if (!on_i2c5 && pkt.dev_addr == 0x18 && pkt.payload_size >= 2 &&
i2c_slave_present(state, false, 0x18))
bm92_write(state, pkt.tx_buf,
std::min<uint32_t>(pkt.payload_size, sizeof(pkt.tx_buf)));
}
break; break;
} }
break; break;
} }
case 0x68: // I2C_INT_STATUS: write 1 to clear
i2c_int_latch[on_i2c5 ? 1 : 0] &= ~val;
break;
case 0x5C: // I2C_FIFO_CONTROL — TX/RX flush at the start of each xfer case 0x5C: // I2C_FIFO_CONTROL — TX/RX flush at the start of each xfer
if (val & 0x3) { if (val & 0x3) {
pkt.hdr_idx = 0; pkt.hdr_idx = 0;
@@ -1653,15 +1684,15 @@ static constexpr uint32_t kDcIntFrameEndVBlank = (1u << 1) | (1u << 2);
// Resolve a DC word index to the windows it addresses and the register-file // Resolve a DC word index to the windows it addresses and the register-file
// slot. False for anything that is not a window register. // slot. False for anything that is not a window register.
static bool dc_window_reg(const EmuState *state, uint32_t index, static bool dc_window_reg(uint32_t header, uint32_t index,
uint32_t *mask, uint32_t *slot) { uint32_t *mask, uint32_t *slot) {
if (index >= 0x700 && index < 0x800) { if (index >= 0x700 && index < 0x800) {
*mask = (state->dc_window_header >> 4) & 0xF; *mask = (header >> 4) & 0xF;
*slot = index - 0x700; *slot = index - 0x700;
return true; return true;
} }
if (index >= 0x800 && index < 0x840) { if (index >= 0x800 && index < 0x840) {
*mask = (state->dc_window_header >> 4) & 0xF; *mask = (header >> 4) & 0xF;
*slot = 0x100 + (index - 0x800); *slot = 0x100 + (index - 0x800);
return true; return true;
} }
@@ -1677,28 +1708,101 @@ static bool dc_window_reg(const EmuState *state, uint32_t index,
return false; return false;
} }
// The two heads share one model; this is a head's slice of EmuState.
struct DcHead {
uint64_t base;
uint32_t (*win)[dcwin::kRegs];
uint32_t (*act)[dcwin::kRegs];
uint32_t *header;
bool *programmed;
char name;
};
static DcHead dc_head(EmuState *s, uint64_t addr) {
if (addr >= DISPLAY_B_BASE)
return {DISPLAY_B_BASE, s->dcb_win, s->dcb_win_active, &s->dcb_window_header,
&s->dcb_programmed, 'B'};
return {DISPLAY_A_BASE, s->dc_win, s->dc_win_active, &s->dc_window_header,
&s->dc_programmed, 'A'};
}
// Head B's interrupts are real: FRAME_END and V_BLANK latch once per frame
// while the head runs (DISPLAY_COMMAND C_DISPLAY), clear on a write of 1,
// and drive GIC SPI 74 when enabled - which a kernel's vblank waits need.
// Head A keeps reading "a frame has just ended" for the payloads that poll.
static uint32_t dcb_int_latch = 0;
static uint64_t dcb_last_frame = 0;
static bool dcb_running(EmuState *s) {
return ((mmio_regs.get(DISPLAY_B_BASE + 0x032 * 4) >> 5) & 3) == 1;
}
static void dcb_frames(EmuState *s) {
if (!dcb_running(s))
return;
uint64_t f = s->emu_usec / 16667;
if (f != dcb_last_frame) {
dcb_last_frame = f;
dcb_int_latch |= (1u << 1) | (1u << 2);
}
uint32_t en = mmio_regs.get(DISPLAY_B_BASE + 0x039 * 4);
gic_set_spi(74, (dcb_int_latch & en) != 0);
}
// DC_CMD_CONT_SYNCPT_VSYNC (0x028): SYNCPT_VSYNC_ENABLE (bit 8) makes the
// head increment host1x syncpoint INDX (7:0) once per frame. A frame counter
// that needs no interrupt logic: hekate's panel uses 9, hwtest's TV check 11.
static void dc_syncpt_tick(EmuState *s, uint64_t base, uint64_t *last) {
uint32_t cmd = mmio_regs.get(base + 0x032 * 4);
uint32_t sv = mmio_regs.get(base + 0x028 * 4);
uint64_t f = s->emu_usec / 16667;
if (((cmd >> 5) & 3) != 1 || !(sv & (1u << 8))) {
*last = f;
return;
}
if (f == *last)
return;
uint64_t reg = HOST1X_BASE + 0x2100 + 0xF80 + 4 * (sv & 0xFF);
mmio_regs[reg] = mmio_regs.get(reg) + (uint32_t)(f - *last);
*last = f;
}
void display_tick(EmuState *s) {
static uint64_t last_a = 0, last_b = 0;
dcb_frames(s);
dc_syncpt_tick(s, DISPLAY_A_BASE, &last_a);
dc_syncpt_tick(s, DISPLAY_B_BASE, &last_b);
}
static void dc_reset(EmuState *state) { static void dc_reset(EmuState *state) {
memset(state->dc_win, 0, sizeof(state->dc_win)); memset(state->dc_win, 0, sizeof(state->dc_win));
memset(state->dc_win_active, 0, sizeof(state->dc_win_active)); memset(state->dc_win_active, 0, sizeof(state->dc_win_active));
for (int w = 0; w < 4; w++) memset(state->dcb_win, 0, sizeof(state->dcb_win));
memset(state->dcb_win_active, 0, sizeof(state->dcb_win_active));
for (int w = 0; w < 4; w++) {
state->dc_win[w][dcwin::BLEND_LAYER] = state->dc_win[w][dcwin::BLEND_LAYER] =
state->dc_win_active[w][dcwin::BLEND_LAYER] = dcwin::BLEND_LAYER_RESET; state->dc_win_active[w][dcwin::BLEND_LAYER] = dcwin::BLEND_LAYER_RESET;
state->dcb_win[w][dcwin::BLEND_LAYER] =
state->dcb_win_active[w][dcwin::BLEND_LAYER] = dcwin::BLEND_LAYER_RESET;
}
state->dc_window_header = 0; state->dc_window_header = 0;
state->dc_programmed = false; state->dc_programmed = false;
state->dcb_window_header = 0;
state->dcb_programmed = false;
dcb_int_latch = 0;
state->vic_out_addr = 0; state->vic_out_addr = 0;
state->vic_out_xform = 0; state->vic_out_xform = 0;
} }
// One line per window whose picture changed (not for moves: bdk slides its // One line per window whose picture changed (not for moves: bdk slides its
// log window in 16 pixels at a time). // log window in 16 pixels at a time).
static void dc_log_window(int w, const uint32_t *r) { static void dc_log_window(char head, int w, const uint32_t *r) {
const char *hn = head == 'B' ? " (head B)" : "";
if (!(r[dcwin::OPTIONS] & dcwin::WIN_ENABLE)) { if (!(r[dcwin::OPTIONS] & dcwin::WIN_ENABLE)) {
printf("[display] window %c off\n", 'A' + w); printf("[display] window %c%s off\n", 'A' + w, hn);
return; return;
} }
static const char *const kKind[4] = {"pitch", "tiled", "block", "?"}; static const char *const kKind[4] = {"pitch", "tiled", "block", "?"};
uint32_t kind = r[dcwin::SURFACE_KIND]; uint32_t kind = r[dcwin::SURFACE_KIND];
printf("[display] window %c: %ux%u @ 0x%08X, %s", 'A' + w, printf("[display] window %c%s: %ux%u @ 0x%08X, %s", 'A' + w, hn,
r[dcwin::SIZE] & 0x1FFF, (r[dcwin::SIZE] >> 16) & 0x1FFF, r[dcwin::SIZE] & 0x1FFF, (r[dcwin::SIZE] >> 16) & 0x1FFF,
r[dcwin::START_ADDR], kKind[kind & 3]); r[dcwin::START_ADDR], kKind[kind & 3]);
if ((kind & 3) == 2) if ((kind & 3) == 2)
@@ -1709,52 +1813,71 @@ static void dc_log_window(int w, const uint32_t *r) {
} }
uint32_t display_read(EmuState *state, uint64_t addr) { uint32_t display_read(EmuState *state, uint64_t addr) {
uint32_t index = (uint32_t)(addr - DISPLAY_A_BASE) / 4; DcHead h = dc_head(state, addr);
uint32_t index = (uint32_t)(addr - h.base) / 4;
uint32_t mask, slot; uint32_t mask, slot;
if (dc_window_reg(state, index, &mask, &slot)) { if (dc_window_reg(*h.header, index, &mask, &slot)) {
for (int w = 0; w < 4; w++) for (int w = 0; w < 4; w++)
if (mask & (1u << w)) if (mask & (1u << w))
return state->dc_win[w][slot]; return h.win[w][slot];
return 0; return 0;
} }
switch (index) { switch (index) {
case kDcCmdIntStatus: return kDcIntFrameEndVBlank; case kDcCmdIntStatus:
if (h.name == 'B') {
dcb_frames(state);
return dcb_int_latch;
}
return kDcIntFrameEndVBlank;
case kDcCmdStateControl: return 0; case kDcCmdStateControl: return 0;
case kDcCmdWindowHeader: return state->dc_window_header; case kDcCmdWindowHeader: return *h.header;
default: return mmio_regs.get(addr); default: return mmio_regs.get(addr);
} }
} }
void display_write(EmuState *state, uint64_t addr, uint32_t val) { void display_write(EmuState *state, uint64_t addr, uint32_t val) {
uint32_t index = (uint32_t)(addr - DISPLAY_A_BASE) / 4; DcHead h = dc_head(state, addr);
uint32_t index = (uint32_t)(addr - h.base) / 4;
uint32_t mask, slot; uint32_t mask, slot;
if (dc_window_reg(state, index, &mask, &slot)) { if (dc_window_reg(*h.header, index, &mask, &slot)) {
for (int w = 0; w < 4; w++) for (int w = 0; w < 4; w++)
if (mask & (1u << w)) if (mask & (1u << w))
state->dc_win[w][slot] = val; h.win[w][slot] = val;
return; return;
} }
if (h.name == 'B' && index == kDcCmdIntStatus) {
dcb_int_latch &= ~val; // write 1 to clear
dcb_frames(state);
return;
}
if (h.name == 'B' && index == 0x032) {
static uint32_t last = 0;
if (((val >> 5) & 3) != ((last >> 5) & 3))
printf("[display] head B %s\n", ((val >> 5) & 3) == 1 ? "running (C_DISPLAY)" :
((val >> 5) & 3) == 0 ? "stopped" : "one-shot");
last = val;
}
if (index == kDcCmdWindowHeader) { if (index == kDcCmdWindowHeader) {
state->dc_window_header = val; *h.header = val;
} else if (index == kDcCmdStateControl) { } else if (index == kDcCmdStateControl) {
uint32_t req = (val >> 1) & 0xF; // WIN_A..D_ACT_REQ uint32_t req = (val >> 1) & 0xF; // WIN_A..D_ACT_REQ
for (int w = 0; w < 4; w++) { for (int w = 0; w < 4; w++) {
if (!(req & (1u << w))) if (!(req & (1u << w)))
continue; continue;
uint32_t *act = state->dc_win_active[w]; uint32_t *act = h.act[w];
const uint32_t *asm_ = state->dc_win[w]; const uint32_t *asm_ = h.win[w];
static const uint32_t kShown[] = { static const uint32_t kShown[] = {
dcwin::OPTIONS, dcwin::COLOR_DEPTH, dcwin::SIZE, dcwin::LINE_STRIDE, dcwin::OPTIONS, dcwin::COLOR_DEPTH, dcwin::SIZE, dcwin::LINE_STRIDE,
dcwin::START_ADDR, dcwin::SURFACE_KIND}; dcwin::START_ADDR, dcwin::SURFACE_KIND};
bool changed = !state->dc_programmed; bool changed = !*h.programmed;
for (uint32_t r : kShown) for (uint32_t r : kShown)
changed |= act[r] != asm_[r]; changed |= act[r] != asm_[r];
memcpy(act, asm_, sizeof(state->dc_win_active[w])); memcpy(act, asm_, sizeof(state->dc_win_active[w]));
if (changed) if (changed)
dc_log_window(w, act); dc_log_window(h.name, w, act);
} }
if (req) { if (req) {
state->dc_programmed = true; *h.programmed = true;
state->display_dirty = true; state->display_dirty = true;
} }
} }
@@ -4688,6 +4811,13 @@ static uint32_t i2c_empty_bus_read(uint64_t address) {
uint32_t mmio_bus_read(EmuState *state, uint64_t address, unsigned size) { uint32_t mmio_bus_read(EmuState *state, uint64_t address, unsigned size) {
(void)size; (void)size;
// host1x syncpoints: the heads' per-frame increments are brought up to
// date before a read, so a payload timing frames inside one BPMP batch
// (a paced TIMERUS wait) sees them.
if (address >= HOST1X_BASE + 0x3080 && address < HOST1X_BASE + 0x3080 + 0x300) {
display_tick(state);
return mmio_regs.get(address);
}
if (address >= TMR_BASE && address < TMR_BASE + TMR_SIZE) { if (address >= TMR_BASE && address < TMR_BASE + TMR_SIZE) {
// TIMERUS_CNTR_1US. The rest of the timer block reads 0. The BPMP's // TIMERUS_CNTR_1US. The rest of the timer block reads 0. The BPMP's
// reads go through the clock's poll pacing; CPU0 has its own clock. // reads go through the clock's poll pacing; CPU0 has its own clock.
@@ -4723,6 +4853,10 @@ uint32_t mmio_bus_read(EmuState *state, uint64_t address, unsigned size) {
return bpmp_cache_read(state, address); return bpmp_cache_read(state, address);
if (address >= GICD_BASE && address < GICD_BASE + GICD_SIZE) if (address >= GICD_BASE && address < GICD_BASE + GICD_SIZE)
return gic_dist_read((uint32_t)(address - GICD_BASE), size); return gic_dist_read((uint32_t)(address - GICD_BASE), size);
if (address >= 0x54040000 && address < 0x54041000)
return dpaux1_read(state, (uint32_t)(address - 0x54040000));
if (address >= 0x54580000 && address < 0x54581000)
return sor1_read(state, (uint32_t)(address - 0x54580000));
if (address >= GICC_BASE && address < GICC_BASE + GICC_SIZE) if (address >= GICC_BASE && address < GICC_BASE + GICC_SIZE)
return gic_cpu_read((uint32_t)(address - GICC_BASE), size); return gic_cpu_read((uint32_t)(address - GICC_BASE), size);
if (address >= SOC_THERM_BASE && address < SOC_THERM_BASE + SOC_THERM_SIZE) if (address >= SOC_THERM_BASE && address < SOC_THERM_BASE + SOC_THERM_SIZE)
@@ -4751,7 +4885,7 @@ uint32_t mmio_bus_read(EmuState *state, uint64_t address, unsigned size) {
if ((address >= I2C4_BASE && address < I2C4_BASE + I2C_CTRL_SIZE) || if ((address >= I2C4_BASE && address < I2C4_BASE + I2C_CTRL_SIZE) ||
(address >= I2C6_BASE && address < I2C6_BASE + I2C_CTRL_SIZE)) (address >= I2C6_BASE && address < I2C6_BASE + I2C_CTRL_SIZE))
return i2c_empty_bus_read(address); return i2c_empty_bus_read(address);
if (address >= DISPLAY_A_BASE && address < DISPLAY_A_BASE + DISPLAY_SIZE) if (address >= DISPLAY_A_BASE && address < DISPLAY_B_BASE + DISPLAY_SIZE)
return display_read(state, address); return display_read(state, address);
if (address >= PMC_BASE && address < PMC_BASE + PMC_SIZE) if (address >= PMC_BASE && address < PMC_BASE + PMC_SIZE)
return pmc_read(state, address); return pmc_read(state, address);
@@ -4896,6 +5030,10 @@ void mmio_bus_write(EmuState *state, uint64_t address, unsigned size,
} else if (address >= BPMP_CACHE_BASE && } else if (address >= BPMP_CACHE_BASE &&
address < BPMP_CACHE_BASE + BPMP_CACHE_SIZE) { address < BPMP_CACHE_BASE + BPMP_CACHE_SIZE) {
bpmp_cache_write(state, address, val); bpmp_cache_write(state, address, val);
} else if (address >= 0x54040000 && address < 0x54041000) {
dpaux1_write(state, (uint32_t)(address - 0x54040000), val);
} else if (address >= 0x54580000 && address < 0x54581000) {
sor1_write(state, (uint32_t)(address - 0x54580000), val);
} else if (address >= GICD_BASE && address < GICD_BASE + GICD_SIZE) { } else if (address >= GICD_BASE && address < GICD_BASE + GICD_SIZE) {
gic_dist_write((uint32_t)(address - GICD_BASE), size, val); gic_dist_write((uint32_t)(address - GICD_BASE), size, val);
} else if (address >= GICC_BASE && address < GICC_BASE + GICC_SIZE) { } else if (address >= GICC_BASE && address < GICC_BASE + GICC_SIZE) {
@@ -4920,7 +5058,7 @@ void mmio_bus_write(EmuState *state, uint64_t address, unsigned size,
} else if (address >= I2C5_BASE && address < I2C5_BASE + I2C_CTRL_SIZE) { } else if (address >= I2C5_BASE && address < I2C5_BASE + I2C_CTRL_SIZE) {
i2c_write(state, address, val); i2c_write(state, address, val);
} else if (address >= DISPLAY_A_BASE && } else if (address >= DISPLAY_A_BASE &&
address < DISPLAY_A_BASE + DISPLAY_SIZE) { address < DISPLAY_B_BASE + DISPLAY_SIZE) {
display_write(state, address, val); display_write(state, address, val);
} else if (address >= DSI_BASE && address < DSI_BASE + DSI_SIZE) { } else if (address >= DSI_BASE && address < DSI_BASE + DSI_SIZE) {
dsi_write(state, address, val); dsi_write(state, address, val);
@@ -5035,6 +5173,7 @@ const struct {
{EMC1_BASE, EMC_SIZE}, {EMC1_BASE, EMC_SIZE},
{MC_BASE, MC_SIZE}, {MC_BASE, MC_SIZE},
{DISPLAY_A_BASE, DISPLAY_SIZE}, {DISPLAY_A_BASE, DISPLAY_SIZE},
{DISPLAY_B_BASE, DISPLAY_SIZE},
{DSI_BASE, DSI_SIZE}, {DSI_BASE, DSI_SIZE},
{I2C2_BASE, I2C2_SIZE}, {I2C2_BASE, I2C2_SIZE},
{SOC_THERM_BASE, SOC_THERM_SIZE}, {SOC_THERM_BASE, SOC_THERM_SIZE},
@@ -5059,6 +5198,9 @@ const struct {
{MSELECT_BASE, MSELECT_SIZE}, {MSELECT_BASE, MSELECT_SIZE},
// GIC-400 distributor, CPU interface and the virtualisation pages. // GIC-400 distributor, CPU interface and the virtualisation pages.
{GICD_BASE, 0x7000}, {GICD_BASE, 0x7000},
// The DisplayPort path to the dock: DPAUX1, SOR1, display head B.
{0x54040000, 0x1000},
{0x54580000, 0x1000},
// PCIe. T210 puts the root complex at the BOTTOM of the address map, // PCIe. T210 puts the root complex at the BOTTOM of the address map,
// below every other peripheral. // below every other peripheral.
{PCIE_BLOCK_BASE, PCIE_BLOCK_SIZE}, {PCIE_BLOCK_BASE, PCIE_BLOCK_SIZE},
@@ -5148,6 +5290,7 @@ void mmio_init(uc_engine *uc, EmuState *state) {
pcie_reset(state); pcie_reset(state);
ccplex_reset(state); ccplex_reset(state);
gic_reset(); gic_reset();
dock_reset(state);
sdhci_reset_regs(sdhci_regs[0]); sdhci_reset_regs(sdhci_regs[0]);
sdhci_reset_regs(sdhci_regs[1]); sdhci_reset_regs(sdhci_regs[1]);
dc_reset(state); dc_reset(state);
+2
View File
@@ -39,6 +39,8 @@ void mmio_unmap_bus(uc_engine *uc);
// Map one 4 KiB page of the peripheral band as a register window (CPU0's // Map one 4 KiB page of the peripheral band as a register window (CPU0's
// first access to a block the emulator does not model). // first access to a block the emulator does not model).
bool mmio_map_page(uc_engine *uc, EmuState *state, uint64_t page); bool mmio_map_page(uc_engine *uc, EmuState *state, uint64_t page);
// Display head B's frame clock (interrupt latch, GIC line); called often.
void display_tick(EmuState *state);
// The shared dispatch both engines' MMIO callbacks funnel into. `size` is the // The shared dispatch both engines' MMIO callbacks funnel into. `size` is the
// access width in bytes (1, 2 or 4). // access width in bytes (1, 2 or 4).