Imagination_BXM-4-64

Hardware Recovery (HWR)

The HWR subsystem detects shader/pipeline lockups, GPU MMU page faults (MMU_PAGE_FAULT), and CR register poll failures, executes an isolated GPU reset without rebooting the SoC, identifies guilty/innocent contexts, requests freelist reconstruction from the host, and resumes normal operation.


1. Lockup Detection — 3-Stage Watchdog ([P][O][D])

While any DM (GEOM=2, FRAG=3, CDM=4) has an active running context and ROGUE_FWIF_INICFG_HWR_EN is enabled:

  1. Per-DM Deadline (HW2 timer):
    • When dispatching a kick to a DM, the firmware records the initial timestamp in CR_TIMER and arms the periodic check deadline (derived from runtime_cfg.core_clock_speed and max_deadline_ms / hcs_deadline_ms).
    • A countdown of consecutive checks (observed platform value: 24 consecutive checks without progress before declaring a definitive lockup; the exact threshold is implementation-configurable) protects against false positives on heavy yet legitimate shaders.
  2. Progress Verification Stages:
    • Stage 1 — Fast signatures: compares DM signature/progress registers between consecutive samples; if progress occurred, resets the counter.
    • Stage 2 — Cycle counters: checks per-DM progress registers (e.g., ROGUE_CR_PERF_3D_CYCLE at 0x6028, ROGUE_CR_PERF_COMPUTE_CYCLE at 0x6030).
    • Stage 3 — Full check: if no progress occurs before the checks are exhausted, marks the DM as locked up in sysdata.hwr_recovery_flags[dm].

Other Immediate HWR Triggers


2. HWR Reset Sequence on SpacemiT K3 (36.56.104.183) ([D])

Once all active DMs have either completed normally or been marked as locked up (no healthy DM remaining in flight), the firmware executes the HWR reset procedure for each physical core (0 .. MULTICORE_SYSTEM - 1, on K3 only core 0):

2.1. Pre-Reset Preparation

  1. Check integrity of the freelists loaded in the PM and internally flag which freelists will need host reconstruction.
  2. Record for each DM with active work whether it was in normal execution, in Partial Render, or had an accumulated pending error.
  3. Capture start_time = ROGUE_CR_TIMER (0x0160/0x0164) to record the reset duration in struct rogue_fwif_hwrinfobuf.

2.2. Bus Quiesce, Reset, and Reinit

For core c (with base = c * 0x80000, 0 on K3), retry up to an implementation-defined finite attempt limit (e.g., 3 attempts) if any quiesce/reset poll fails:

Step Hardware Operation Poll / Success Criterion
1 CR[0x0890] = 1 << c Select target core
2 CR[base + 0x1340] \|= 1 Pause BIF/MMU requests
3 Poll ROGUE_CR_BIFPM_STATUS_MMU (base + 0x1350) Mask 0xFF == 0 (PM MMU drained)
4 Poll ROGUE_CR_BIFPM_READS_EXT_STATUS (base + 0x1338) Mask 0xFFFF == 0 (external reads drained)
5 MMU cache invalidation (BCAST[0x12A0] = 0x1C) Poll 0x12A0 == 0 (if failed → fatal error)
6 (On core 0) Full D-cache flush (0x80000000..0x800007F0, stride 0x10) + 0xBFC01800 = 1 + ehb + sync Drain MIPS write buffers
7 Poll ROGUE_CR_SIDEKICK_IDLE (base + 0x03C8) Mask 0x20 == 0x20 (bit 5)
8 Poll ROGUE_CR_SLC_IDLE (base + 0x3898) Mask 0xFF == 0xFF (all 8 SLC subunits idle; if failed → fatal error)
9 Assert standard soft reset + set additional bits: BCAST[0x0100] \|= 0x10610000 and BCAST[0x0104] \|= 0x00080004 Reset pipeline blocks while keeping MIPS and base infrastructure
10 Full D-cache flush + 0xBFC01800 = 1 + ehb + sync Ensure coherence before releasing reset
11 Release soft reset pulse in ROGUE_CR_SOFT_RESET Bring blocks out of reset
12 Execute full boot-gpu-init (boot-gpu-init.md) Restore SLC, PDS/USC bases, and BXM-4-64 defaults
13 CR[base + 0x1340] &= ~1 Resume BIF/MMU
14 BCAST[0x1608] = 0x00078001 Post-HWR auxiliary block reset/init → Poll CR[0x1608] bit 0 == 0
15 SLC flush + invalidation (BCAST[0x3818] + poll 0x3820) If failed → fatal error
16 If all quiesce/reset polls (steps 3, 4, 7, and 14) passed, exit the reset loop with success; otherwise retry up to the configured limit —

2.3. Post-Reset Cleanup and Host Notifications

  1. Restore CR[0x0890] = (1 << MULTICORE_SYSTEM) - 1.
  2. Capture end_time = ROGUE_CR_TIMER and populate the reset start/end timestamps in the new entries of struct rogue_fwif_hwrinfobuf.
  3. Reinitialize the LRU table of the 7 dynamic BIF banks (BIF_CAT_BASE1..7) and reset the SPM controller to idle (BCAST[0x02A0] &= ~3, BCAST[0x0338] = 0).
  4. Execute full D-cache flush + 0xBFC01800 = 1 + ehb + sync + final SLC flush/invalidation.
  5. Recovery of affected DMs:
    • For each affected DM: discard the stuck TASK command in the cCCB, mark output Sync Checkpoints with 0x00000EFF (PVR_SYNC_CHECKPOINT_ERRORED) to prevent host deadlock, update hwrtdata.state = ROGUE_FWIF_RTDATA_STATE_HWR (9) when applicable, update cleanup_ctl.executed_commands, advance Roff past the guilty job, and emit FWCCB_CMD_CONTEXT_RESET_NOTIFICATION (0x2ABC0069) classifying the context as GUILTY_LOCKUP or INNOCENT_LOCKUP.
  6. Debug Dump: if the total emitted dumps is less than osinit.hwr_debug_dump_limit (or ROGUE_FWIF_HWR_DEBUG_DUMP_ALL = 99999), emit FWCCB_CMD_DEBUG_DUMP (0x2ABC006A).
  7. Freelist Reconstruction: if any freelist became inconsistent due to the reset, emit FWCCB_CMD_FREELISTS_RECONSTRUCTION (0x2ABC0068) and keep DM2/DM3 paused until KCCB_CMD_FREELISTS_RECONSTRUCTION_UPDATE (0x2ABC0070) is received.
  8. Unrecoverable Fallback: if the reset failed after exhausting retries (or a fatal MMU/SLC error occurred), emit FWCCB_CMD_REQUEST_GPU_RESTART (0x2ABC006D) requesting the Linux driver to perform a GPU hard reset via RESET_APMU_GPU.
  9. Clear SLAVE_REQ (CR[0x0138] = 0x80000) and schedule the BG task by writing CR[0x0B00] = 0x20.

3. MMU Page Fault (EVENT_STATUS bit 9) ([P][O])

The event is bit 9 (0x200) of ROGUE_CR_EVENT_STATUS and is cleared with BCAST[0x0138] = 0x200. The handler reads, per core, two public registers:

Register Bits Meaning
ROGUE_CR_BIF_FAULT_BANK0_MMU_STATUS (0x12B0) 0 FAULT fault pending
  [3:2] FAULT_PM_META_RO fault on PM meta write
  4 FAULT_RO access targeted a read-only page
  [6:5] DATA_TYPE data type
  [10:8] PAGE_SIZE catalog page size
  [27:12] CAT_BASE faulting catalog index (0..7 = BIF banks; 8+ = PM catalogs)
ROGUE_CR_BIF_FAULT_BANK0_REQ_STATUS (0x12B8/0x12BC, 64 b) [51:4] ADDRESS faulting 40-bit address (16 B aligned)
  [47:40] TAG_ID requester (DM/PMC/ISP/PBE/USC…)
  [45:44] TAG_SB side-band
  50 RNW 1 = read, 0 = write

3.1 Recording in rogue_fwif_hwrinfobuf (136 B per entry, 16 entries)

Off Field Source
0x00 mmu_info.mmu_status[0] REQ_STATUS (address + RNW + TAG)
0x08 mmu_info.mmu_status[1] MMU_STATUS (0x12B0)
0x10 mmu_info.pc_address catalog base resolved via CAT_BASE: CR[0x1200 + 8*cat] for cat < 8; for 8..14 → CR[0x1248/0x1250/0x1260/0x1268/0x1270/0x1280]; otherwise 0xFFFFFFFFFFFFFFFF
0x48 hwr_type 3 = BIF0FAULT (MIPS TLB = 8, poll failure = 2, overrun = 1, unknown = 0)
0x40 event_status CR[0x0130]
0x4C dm 0

Handler consequences: clears the fault bit in the context copy, marks active DMs in the HWR flags (see §3.3), notifies the contexts, and schedules the IRQ task (CR[0x0B00] = 0x20). If the host requested a debug dump, sends the corresponding FWCCB message.

3.2 Poll Failure (type 2) and Overrun (type 1)

When a register poll times out, the firmware populates poll_info (0x00..0x0C): cr_poll_addr, cr_poll_mask, cr_poll_last_value, with the convention cr_poll_addr[31] = 1 ⇔ register is W1C. The response is the same as for an MMU fault (per-DM flags + CR[0x0B00] = 0x20).

3.3 Per-DM State Flags (RGXFWIF_DM_STATE_*)

Bit Name Usage
0x001 READY_FOR_HWR DM idle, may be reset
0x004 NEEDS_SKIP skip to the next command before resuming
0x008 NEEDS_PR_CLEANUP needs partial render cleanup
0x010 NEEDS_TRACE_CLEAR increment the recovery counter
0x020 GUILTY_LOCKUP caused the lockup
0x040 INNOCENT_LOCKUP affected by another DM
0x080 GUILTY_OVERRUNING caused the deadline overrun
0x100 INNOCENT_OVERRUNING affected by another DM
0x200 HARD_CONTEXT_SWITCH preempted by priority
0x400/0x800/0x1000 GPU_ECC_HWR / PARITY_HWR / LATENT_HWR memory error

3.4 Fast Signatures (Stage 1)

Each DM has a progress counter read per core:

DM Register
2 (TA/VDM) CR[0x6020]
3 (3D/ISP) CR[0x6028]
4 (CDM) CR[0x6030]

The firmware stores the last value per core and computes the delta on each check; if the delta fails to advance within the context deadline (ui32MaxDeadlineMS, capped by hcs_deadline_ms/max_deadline_ms from runtime config), the DM is considered locked up. The optional full check uses descriptor tables supplied by the host in the initialization block (signature descriptor fields): each descriptor has 4 × u16 ({read register, index register (0 = direct read), start index, end index}) and the FW accumulates the values into a CRC compared against the expected value. If the host passes 0 in these fields (as mainline 1.1 does), the mechanism is disabled and only the deadline remains.


4. Discarded Geometry, Aborts, and Sync Checkpoints ([D])

4.1 ROGUE_FWIF_RTDATA_STATE_HWR (value 9) — the HWRTData “Tombstone”

When an HWRTData is involved in HWR, its state does not return to NONE (0). The firmware uses a dedicated state, ROGUE_FWIF_RTDATA_STATE_HWR (9), and keeps it until the HWRTData is recycled. The reason is explained by the ABI itself: zeroing the state would cause the next TA to be treated as the first TA (KICKTAFIRST), reloading an HWRTData that the host considers dead.

Observed consequences:

  1. The PM loader (pm_load_hwrtdata) returns “skip load” when the HWRTData is in state 9, except for the auxiliary PM context (2). That is: TA and 3D for that HWRTData are not dispatched, while the auxiliary context may still be used.
  2. The TA kick also checks the state before loading (is_state9(hwrtdata, 1)).
  3. A FRAG arriving for an HWRTData in state 9 is discarded via this exact path — there is no “special if” in the 3D kick: the PM load failure is what prevents dispatch.
  4. The HWRTData is only recycled when the host returns it (cleanup/recreation); until then, state 9 persists and all new work targeting it is discarded.

4.2 Sync Checkpoint Values ([P])

Value Meaning When Written by Firmware
0xAC1 PVR_SYNC_CHECKPOINT_ACTIVE (unsignaled) Initial state, written by the host
0x519 PVR_SYNC_CHECKPOINT_SIGNALED Normal UPDATE; also on UPDATE with bit 0 of the address set, in which case the firmware increments the checkpoint value and marks it signaled
0xEFF PVR_SYNC_CHECKPOINT_ERRORED KCCB_CMD_FORCE_UPDATE: all checkpoints still at 0xAC1 belonging to the CCB are marked “errored” to unblock the host on teardown

Bit 0 of the UFO address distinguishes a “plain UFO” from a “counted sync checkpoint”: in the latter case the firmware executes *(ckpt+4) += 1 and writes 0x519 to *ckpt.

4.3 Aborted Geometry (CCB_CMD_TYPE_ABORT / Cancellation)

  1. The ABORT command performs no GPU work: it walks the context chain, marks the HWRTData as discarded, and runs UPDATE/retirement of pending commands.
  2. If a TA was in flight for the same HWRTData, the state transitions to HWR (9, §4.1) — from then on any FRAG is ignored.
  3. The HWRTData’s cleanup_ctl receives the reference to be returned to the host; FWCCB_CMD_CONTEXT_RESET_NOTIFICATION notifies the owning process when HWR identified the guilty context.
  4. During process teardown, the host uses KCCB_CMD_FORCE_UPDATE to mark as errored the checkpoints that will never be signaled (§4.2) — without this, drm_sched would wait forever.

4.4 3D Completion Timeouts

Upon 3D completion the firmware waits for two events:

Event EVENT_STATUS Bit Action on Success Action on Timeout
PM_3D_MEM_FREE 8 (0x100) clears BCAST[0x0138] = 0x100 does not clear: the event remains pending
ZLS_FINISHED (end of Z/S store) 14 (0x4000) clears BCAST[0x0138] = 0x4000 (together with 0x08) clears only 0x08; bit 14 remains pending

In both cases the firmware restores the 3D mem-free enable register (CR[core*0x80000+0x03E0]) to its previous value before continuing: a timeout does not leave 3D “deaf” for the next render. The timeout is logged (group pm) and does not trigger HWR on its own; the uncleared event will be re-observed on the next IRQ entry.