Files
RCM-Emulator/t210/ccplex.h
T
Claude f19a52b779 Run CCPLEX CPU0 so hwtest's PCIe probe completes, and speed up the core
hwtest-rcm's Wi-Fi probe hands PCIe to an AArch64 stub on CPU0, because
PCIe and MSELECT answer a CPU-complex master only. The emulator had no
CCPLEX, so the stub never reported; and the sweep never got that far
anyway, because it hung in the fan test.

CPU0 (t210/ccplex.cpp)
- A second Unicorn engine, AArch64, Cortex-A57, sharing IRAM, DRAM, TZRAM
  and every peripheral model with the BPMP. It starts when
  RST_CPUG_CMPLX_CLR releases CPU0 with every precondition of bdk's
  ccplex_boot_cpu0() met: CPU rail (MAX77621 + MAX77620 GPIO5 on Erista,
  MAX77812 EN_M4 on Mariko), CRAIL/C0NC/CE0, CPUG clock, PLLX, MSELECT,
  RAM repair, an AArch64 vector in SB_AA64_RESET_LOW/HIGH. A release that
  misses one is refused and the reason printed.
- Entered at EL3, MMU off, like silicon. Unicorn builds its ARM64 core at
  EL1 and neither a PSTATE write (stale hflags) nor an exception (never
  delivered) moves it, so a one-instruction ERET trampoline does.
- Its own clock (1 ns/instruction, 250 ns/bus access), run in 250 us
  lockstep slices behind the BPMP; WFE/WFI park it to the slice end.
- PCIe is master-aware: the BPMP still reads all ones, CPU0 is served.
  MSELECT, AFI_PCIE_CONFIG, LNKSTA, the endpoint class/BAR, the PCIE
  partition, PEX_L1 pinmux and PMC_GLB_AMAP_CFG take their measured values.

hwtest now runs its whole sweep and reports "WLAN core enumerated on the
PCIe bus" / "Wireless : pass", matching the healthy-console capture in
its README.

Performance
- No per-instruction hooks. Three UC_HOOK_CODE callbacks (one registered
  twice, one doing a uc_mem_read per instruction) are replaced by a block
  hook that counts each block's instructions once (cached), credited when
  it has run - the same totals, so the clock is unchanged.
- Peripherals are uc_mmio_map() windows instead of memory hooks, which
  had forced every guest load/store onto Unicorn's slow path; the register
  cache is a paged array instead of a std::map.
- The display reads the framebuffer straight from host DRAM, reuses its
  buffers, skips unchanged frames, and no renderer uses PRESENTVSYNC (a
  vsync'd present could stall the emulated CPU for a whole frame).
Reaching hwtest's fan test: 2.7 s -> 0.8 s; whole sweep ~3 s.

Reliability
- TIMERUS poll pacing: bdk's fan_get_speed() waits for TIMERUS to EQUAL a
  deadline (int - u32 is unsigned, so `> 0` is `!= 0`), and the dilated
  clock stepped past it, so the loop spun until TIMERUS wrapped. Polls at
  most 200 instructions apart now advance the clock by at most 1 us.
- MAX77621/MAX77812 are register files: bdk's hw_init() disabling the
  Erista CPU/GPU bucks used to be ignored and read back as enabled.
- Mariko reads FUSE_RESERVED_ODM28_B01 bit 0 set, so bdk addresses the
  retail MAX77812 at 0x33 instead of the NAK'd 0x31.
- Windows: disk images are opened O_BINARY (MinGW defaults to text mode,
  corrupting sectors) and rawnand chunks are sized with _fstati64.
- Soft reboot resets CPU0 and the PCIe root complex; the payload is
  loaded once, size-checked; an empty/unreadable payload is rejected; the
  NOP-slide check no longer trips on a counter that never reset; the M/C
  windows fall back to a software renderer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YYewwDPujjo5B2xRyC5Grb
2026-09-25 15:55:48 +00:00

58 lines
2.4 KiB
C++

#ifndef T210_CCPLEX_H
#define T210_CCPLEX_H
#include <cstdint>
struct EmuState;
/*
* CCPLEX CPU0 - the first Cortex-A57 of the Tegra X1's main CPU cluster.
*
* An RCM payload runs on the BPMP, but it can boot CPU0 itself with bdk's
* ccplex_boot_cpu0(): rail on, PLLX, CCLK, the CRAIL/C0NC/CE0 partitions,
* RAM repair, the AArch64 reset vector in SB_AA64_RESET_LOW/HIGH, then
* RST_CPUG_CMPLX_CLR. hwtest does exactly that for its PCIe probe, because
* PCIe answers a CPU-complex master only.
*
* This model watches those registers and, when the core is released with
* every precondition met, runs it: a second Unicorn engine in AArch64 mode,
* entered at EL3 with the MMU off at the programmed vector, sharing IRAM,
* DRAM, TZRAM and every peripheral model with the BPMP. A release that is
* missing something does not start the core, and says which precondition
* was missing - on silicon the core would simply never run.
*
* Time: CPU0 keeps its own clock, advanced by the instructions it retires
* and by the latency of each bus access it makes, and the main loop runs it
* in short slices up to the BPMP's current time. WFE/WFI park it until the
* end of the slice. Everything is a pure function of the instruction stream,
* so runs stay deterministic.
*/
// Power-on state: CPU0 in reset, no vector, clocks off.
void ccplex_reset(EmuState *state);
// CAR (clock and reset controller) forwarding.
void ccplex_car_write(EmuState *state, uint32_t offset, uint32_t val);
bool ccplex_car_read(uint32_t offset, uint32_t *out);
// SB block (SYSREG + 0x200): SB_CSR and the AArch64 reset vector.
uint32_t ccplex_sb_read(uint32_t offset);
void ccplex_sb_write(EmuState *state, uint32_t offset, uint32_t val);
// A PMC power partition toggled / the CPU rail regulator changed. Losing any
// of them under a running core stops it.
void ccplex_partition_changed(EmuState *state, int part, bool on);
void ccplex_rail_changed(EmuState *state);
// Called by the MMIO front-end for every access CPU0 makes: charges the bus
// latency to CPU0's clock before the access is dispatched.
void ccplex_bus_tick(EmuState *state);
// True while CPU0 is out of reset and executing (not parked on a hung bus).
bool ccplex_cpu0_running();
// Run CPU0 until its clock reaches `until_us` - the BPMP's current time.
void ccplex_run(EmuState *state, uint64_t until_us);
#endif // T210_CCPLEX_H