Imagination_BXM-4-64

Data Masters and BIF/MMU Context Management

This document details the Data Masters (DMs) present on the SpacemiT K3 (36.56.104.183) and the exact allocation algorithm for the 8 BIF catalogue banks (BIF_CAT_BASE0..7) used before each hardware kick.


1. Data Master Matrix on K3 (36.56.104.183) ([P][O])

DM Index Mainline Enum Status on K3 Associated Physical Units EVENT_STATUS (0x0130) Event MTS Enable
0 PVR_FWIF_DM_GP Active General control, MMU Fault, USC trigger, Slave req 0x200 (b9), 0x1000 (b12), 0x8000 (b15), 0x80000 (b19) 0x0B58 = 0x89200
1 PVR_FWIF_DM_TDM Absent (No 2D/TLA/TDM engine on K3) — Unused
2 PVR_FWIF_DM_GEOM Active VDM, TE, PPP, PM (ctx 0), TPU/USC (vertex) 0x20 (TA_FINISHED, b5), 0x80 (PM_OOM, b7) 0x0B68 = 0xA0
3 PVR_FWIF_DM_FRAG Active ISP (6 pipes), PBE (8 MRTs / 3 MRTs in 3D-TQ), ZLS, PM (ctx 1), TPU/USC (pixel) 0x08 (PIXELBE_END_RENDER, b3); auxiliary 0x100 (PM_3D_MEM_FREE, b8), 0x4000 (ISP_ZLS_END, b14) 0x0B70 = 0x08
4 PVR_FWIF_DM_CDM Active CDM, PDS, USC (compute), TPU (0x1858) 0x04 (COMPUTE_FINISHED, b2) 0x0B78 = 0x04
5 PVR_FWIF_DM_RAY Absent (No Ray Tracing on K3) — Unused

2. Architecture of the 8 BIF Banks (BIF_CAT_BASE0..7) ([P][D])

The GPU internal bus interface (BIF/MMU) has 8 64-bit Page Catalogue base registers (ROGUE_CR_BIF_CAT_BASE0 .. ROGUE_CR_BIF_CAT_BASE7), spaced 8 bytes apart starting at 0x1200:

BIF Bank MMIO Offset (Unicast / Broadcast) Usage on K3 (36.56.104.183)
Bank 0 0x1200 / BCAST[0x1200] Reserved for Firmware / OSID 0 (configured by host; never reused for user contexts!)
Bank 1 0x1208 / BCAST[0x1208] Dynamic slot 0 (user memory contexts)
Bank 2 0x1210 / BCAST[0x1210] Dynamic slot 1
Bank 3 0x1218 / BCAST[0x1218] Dynamic slot 2
Bank 4 0x1220 / BCAST[0x1220] Dynamic slot 3
Bank 5 0x1228 / BCAST[0x1228] Dynamic slot 4
Bank 6 0x1230 / BCAST[0x1230] Dynamic slot 5
Bank 7 0x1238 / BCAST[0x1238] Dynamic slot 6
Requester / DM Word of 0x1240 Field (bits) Write Scope
DM0 / GP (req = 0) High (+0x04, 0x1244) [2:0] (bank & 0x7) All cores (0 .. CR[0xF308] - 1)
DM2 / GEOM (req = 2 or 6) Low (+0x00, 0x1240) [2:0] (bank & 0x7) Active core (core_id * 0x80000)
DM3 / FRAG (req = 3) Low (+0x00, 0x1240) [10:8] ((bank & 0x7) << 8) All cores (0 .. CR[0xF308] - 1)
DM4 / CDM (req = 4) Low (+0x00, 0x1240) [18:16] ((bank & 0x7) << 16) All cores (0 .. CR[0xF308] - 1)

3. MemCtx Activation and Deactivation Algorithm ([D])

The firmware maintains a small reference-counted LRU table for the 7 dynamic slots (idx = 0..6, corresponding to physical banks 1..7) (a 1-byte counter per slot + eviction cursor):

Activation (before triggering a kick on a DM)

  1. Reads idx = memctx->page_cat_base_reg_set and pc_paddr = memctx->pc_dev_paddr.
  2. Fast Path (Hit):
    • Checks whether idx < 7 and the current content of CR[0x1208 + idx*8] matches pc_paddr (low word masked with 0xFFFFF000 and high word masked with 0xFF).
    • If it matches, no MMU cache invalidation or BIF_CAT_BASE reprogramming is needed.
  3. Slow Path (Miss — LRU allocation/eviction):
    • Evicts the least recently used slot whose reference count (refcount) is 0.
    • If no slot has refcount == 0 (all 7 banks simultaneously in use — rare since there are only 3 user DMs + PM), returns failure and defers the kick.
    • Updates memctx->page_cat_base_reg_set = idx.
    • Barrier + MMU cache invalidation before changing the base: ensures a memory barrier (sync) and performs MMU invalidation with mask 0x1C (ROGUE_CR_BIF_CTRL_INVAL, BCAST[0x12A0] = 0x1C, followed by polling until 0x12A0 == 0).
    • Writes the 64 bits of pc_paddr into BCAST[0x1208 + idx*8] (lo at +0, hi at +4).
    • If memctx->flags indicates an active breakpoint (bit 3), configures the breakpoint register for that context.
  4. Binding to the DM:
    • Programs the physical bank index bank = idx + 1 (1..7) into the corresponding field of BIF_CAT_BASE_INDEX (0x1240/0x1244) per the table above.
  5. Reference counting:
    • If refcount[idx] was 0, removes idx from the evictable (LRU) list.
    • Increments refcount[idx].
    • Reset width caution: when zeroing the counter table (boot or HWR), clear strictly the 7 bytes of refcount[0..6] without overwriting adjacent state/cursor fields.

Deactivation (upon kick completion on the DM — HW1)

  1. Decrements refcount[idx] of the slot associated with memctx.
  2. If refcount[idx] reaches 0, returns idx to the tail of the LRU list (keeping BIF_CAT_BASE populated to maximize cache hits on subsequent kicks from the same context!).
  3. Upon receiving KCCB_CMD_CLEANUP for an fwmemcontext or after an HWR reset, invalidates the slot entry (page_cat_base_reg_set = 0xFFFFFFFF) and clears all counters on HWR reset.

4. MMU and SLC Cache Invalidation ([P][D])

The two invalidation primitives used on the K3 (36.56.104.183):

Operation Register Sequence Mandatory Poll
MMU Cache Invalidation (BIF) BCAST[0x12A0] = mask (e.g., 0x1C for PC/PD/PT in BIF, or flags & 0xF via KCCB_CMD_MMUCACHE) Poll CR[0x12A0] until == 0
SLC Flush/Invalidation BCAST[0x3818] = op (0x10 = global flush+inval or per-DM bits in ROGUE_CR_SLC_CTRL_FLUSH_INVAL) Poll ROGUE_CR_SLC_STATUS0 (CR[0x3820]) until completion
PM/BIF Memory Flush/Invalidation If (flags & 0x10) in KCCB_CMD_MMUCACHE: BCAST[0x1348] = 1 Poll CR[0x1348] bit 0 == 0
Post-Kick DM Cache Invalidation Full per-DM sequence in §4.1 (not a single register) Explicit polls in §4.1

4.1 Per-DM Completion Flush ([D])

The firmware uses three sibling routines (one per user DM) called in the completion handler before retiring the cCCB command (hence before any UFO/Sync Checkpoint UPDATE that releases the host). The skeleton is shared; what differs is the value written to each register and one extra block that runs only for DM3.

Step GEOM (DM2) FRAG/3D (DM3) CDM (DM4)
1. unified store / drain BCAST[0x4000] = 1 BCAST[0x4000] = 1 BCAST[0x4000] = 1
2. per-core cache trigger CR[core*0x80000+0x0688] = 1 = 2 = 4
3. poll step 2 0x0688 == 0 (core bit) same same
4. DM cache block BCAST[0x0668] = 5 BCAST[0x0668] = 3 BCAST[0x0668] = 9
5. poll step 4 0x0668 bit 0 == 0 same same
6. TPU/USC block BCAST[0x1608] = 0x10001 BCAST[0x1608] = 0x38001 BCAST[0x1608] = 0x10001
7. poll step 6 0x1608 bit 0 == 0 same same
8. DM3 only: internal caches — BCAST[0x1480] = 1, BCAST[0x1470] = 1, BCAST[0x1478] = 1; poll 0x1470 and 0x1478 (bit 0 == 0) —
9. final invalidate BCAST[0x1488] = 1 same same
10. write filter BCAST[0x1744] = 0x80 = 0x180 = 0x280
11. MCU fence BCAST[0x1740] = 0 (ROGUE_CR_MCU_FENCE) same same
12. clean trigger BCAST[0x1720] = 7 (GP context) / 0x27 (others) = 0xb / 0x2b = 0x13 / 0x33
13. poll step 12 BCAST[0x1728] bit 0 == 0 same same
14. wrapper barrier only when DM is not GP: 0xBFC01800 = 1, ehb, sync same same
15. SLC flush/inval BCAST[0x3818] = 2 (DM_TA) = 6 (DM_TA \| DM_PIXEL) = 8 (DM_COMPUTE)
16. SLC poll ROGUE_CR_SLC_STATUS0 (0x3820) bit 2 == 0, per core same same

Implementation notes: