Imagination_BXM-4-64

Geometry / TA Kick (DM2) and PM Programming

This document details the step-by-step register programming on the SpacemiT K3 (36.56.104.183) to execute a CCB_CMD_TYPE_GEOM command (DM2 — VDM / TE / PPP / Parameter Manager), including loading Freelist and HWRTData into the PM and handling completion in HW1.


1. Loading Freelist into the PM ([O])

Each RGXFWIF_FREELIST (64 B) holds the fields the firmware programs into the PM:

Off Field Used as
0x08/0x0C current_dev_addr (64 b) PTE address of the current free page
0x10 current_stack_top page index at the top of the stack
0x1C current_pages available pages
0x20/0x24 allocated_page_count / allocated_mmu_page_count consumption counters
0x2C grow_pending blocks cleanup
0x30 ready_pages pages reserved for OOM
0x38 global PB number (0..3) selects PB/core

1.1 Write (load) — exact map per slot × context

The PM has two “stacks” per context; the register set depends on (freelist slot ≠ 0) × (context == 1):

slot ctx current_dev_addr stack top counters trigger
0 0/2 0x0210/0x0214 0x0220 = 0, 0x0224 = top 0x0390/0x0394 0x0208 = 1
0 1 0x0218/0x021C 0x0230/0x0234 = top << 22 (u64) 0x0398/0x039C 0x0200 = 1
1/2 0/2 0x20B8/0x20BC 0x20C0 = top 0x20D0/0x20D4 0x20B0 = 1
1/2 1 0x2078/0x207C 0x2080 = top 0x2090/0x2094 0x20A8 = 1

0x0220 always receives 0 (the firmware does not program the page table base: hardware derives it from current_dev_addr, which steps −4 bytes per page).

After writing 1 to the trigger, the firmware polls the same register until bit 0 returns to 0 (the PM clears the bit when done):

CR[0x0208] = 1 ;  poll(CR[0x0208] & 1 == 0)

1.2 Readback (store) — no trigger and no poll

Before replacing a freelist (or on unload), the firmware copies the hardware state back into RGXFWIF_FREELIST:

slot ctx stack top → +0x10 alloc_page → +0x20 alloc_mmu → +0x24
0 0/2 CR[0x0348] CR[0x03A0] CR[0x03A4]
0 1 CR[0x0350] CR[0x03A8] CR[0x03AC]
1/2 0/2 CR[0x20C8] CR[0x20D8] CR[0x20DC]
1/2 1 CR[0x2088] CR[0x2098] CR[0x209C]

The context (core/PB) is selected by the global PB number (+0x38 of the freelist), the same field that selects the catalog base in HWRTData.

1.3 Growth (grow)

When growing the freelist by delta pages:

fl->current_dev_addr -= delta * 4          (64-bit decrement, with carry)
fl->current_pages   += delta
fl->current_stack_top += delta
top = CR[0x0348|0x0350|0x20C8|0x2088] + delta
CR[0x0230] = top << 22 ; CR[0x0234] = top >> 10      (context 1)

current_dev_addr steps −4 B per page because each stack entry is a 4-byte PTE.


2. Loading HWRTData into the PM ([O])

The PM has three logical contexts (0 = TA/geometry, 1 = 3D/fragment, 2 = auxiliary) and two hardware contexts. HWRTData provides the fields below (all from the mainline 1.1 ABI — the offsets are in data-structures.md; the vendor 24.2 binary uses different offsets and must not be used):

Field (struct rogue_fwif_hwrtdata) Register
pm_mlist_dev_addr (64 b) 0x02D8 (ctx 0) / 0x02E0 (ctx 1)
vce_cat_base 0x1248 (TA) / BCAST[0x1268] (3D)
te_cat_base 0x1250 / BCAST[0x1270]
alist_cat_base 0x1260 / BCAST[0x1280]
pm_alist_stack_pointer (64 b) 0x0268 (TA) / 0x0278 (3D)
pm_mlist_stack_pointer 0x02B8 / 0x02C8
hwrt_data_flags (global PB number bits and “geometry needs resume”) PB/core selection
state (enum rogue_fwif_rtdata_state) flow control

2.1 Exact order (one load)

  1. Eviction: if this HWRTData is loaded in another context, save that context’s catalogue bases before touching the registers (CR[0x0270], 0x02C0, 0x1248, 0x1250, 0x1260 for ctx 0; 0x0280, 0x02D0, 0x1268, 0x1270, 0x1280 for ctx 1) — pure read.
  2. Context selection: CR[0x03D0] = (mode << 16) | (old & ~0x10000) and CR[0x03D4] = ((mode >> 16) | old) & ~0x100 | (mode << 8), with bit 16 of 0x03D0 and bit 8 of 0x03D4 = selector (0 = TA, 1 = 3D); idle values 0x0100/1.
  3. Freelists: for each slot i (0..2), if the address changed: store_freelist(old, i, ctx) → CR[0x02A0] |= (1 << i) → poll(CR[0x02A8] & (1<<i) != 0) → load_freelist(new, i, ctx) → CR[0x02A0] &= ~(1 << i) → poll(CR[0x02A8] & (1<<i) == 0).
  4. Catalogues and lists: CR[0x1248]/0x1250/0x1260 (TA) or BCAST equivalent; CR[0x0268]/0x0278 (pm_alist_stack_pointer); CR[0x02B8]/0x02C8 (pm_mlist_stack_pointer); CR[0x02D8]/0x02E0 (pm_mlist_dev_addr).
  5. Load triggers: CR[0x0190] = 1 + poll b0 (ctx 0) or CR[0x0288] = 1 + poll b0 (ctx 1).
  6. Mode: CR[0x02B0] = 3 (start / full load) or 1 (resume).
  7. MMU invalidation (CR[0x12A0] = 0x1C + poll) when HWRTData changed.

2.2 pm_store_hwrtdata (unload)

For each loaded context: if HWRTData was in state FRAG_CONTEXT_STORED and without the “do not invalidate” flag, invalidate the catalogue (CR[0x12A0]); then read back the catalogue and list bases into HWRTData and run store_freelist on all three freelists before clearing the binding.

3. Geometry / TA Kick Sequence (DM2) ([D])

With MemCtx activated in the BIF (bank 1..7 bound to DM2), and Freelist and HWRTData loaded in the PM (HW context 0):

3.1. VHeap and First-Kick vs Non-First-Kick Initialization

  1. Writes hwrtdata.vheap_table_dev_vaddr to CR[0x0248] / CR[0x024C] (64-bit).
  2. If cmd.flags & FIRSTKICK (first TA of this HWRTData):
    • Zeroes TPC memory (tail_ptrs_dev_vaddr, size tail_ptrs_size) if requested by the init flag.
    • If RTA is active (rtc_dev_vaddr != 0), zeroes RTC memory (rtc_dev_vaddr, size 0x300 bytes).
    • (The TA context reset on this path is performed by CR[0x0C68] = 1 + poll, see §3.2.)
    • Configures VHeap mode in the PM and clears stale PM catalogue bases if necessary.
  3. If NOT FIRSTKICK (continuation TA on the same HWRTData):
    • Triggers TA resume in the PM: CR[0x0250] = 1 → poll CR[0x0250] bit 0 == 0.

Correction (2026-11-28): the resume trigger is 0x0250 (written only on the “non-first-kick” path). The 0x0258 cited in earlier versions is not used by any path. The other PM trigger is 0x0260 = 1 (+ poll), used on TA completion (flush), not on kick.

3.2. TE, PPP, TPU, and RTA/RTC Programming ([O])

Verified map (source in parentheses):

Register Width Source
CR[0x0C00] (ROGUE_CR_TE_AA) 32b hwrtdata_common.teaa
CR[0x0C08] 32b hwrtdata_common.te_mtile1
CR[0x0C10] 32b hwrtdata_common.te_mtile2
CR[0x0C18] 32b hwrtdata_common.te_screen
CR[0x0C20] 32b hwrtdata_common.mtile_stride
CR[0x0C28] 32b TE control field in command
CR[0x0C88] 32b PPP field in command
CR[0x0C98] 32b hwrtdata_common.screen_pixel_max
CR[0x0C38]/[0x0C3C] 64b hwrtdata.rgn_header_dev_addr
CR[0x0C40]/[0x0C44] 64b hwrtdata.tail_ptrs_dev_addr
CR[0x0C48] 32b low word of hwrtdata.te_cat_base — TE catalogue
CR[0x0C80]/[0x0C84] 64b hwrtdata.vce_cat_base — or vce_last_cat_base in partial render
CR[0x0248]/[0x024C] 64b hwrtdata.vheap_table_dev_vaddr
CR[0x0250] 32b 1 = “PM TA start” (single-RT path)
CR[0x17A0]/[0x17A4] 64b TPU border fields in command
CR[0x4098] 8b view index field in command
CR[0x40A8] 32b core & 1
CR[0x0400] 32b 1 = VDM start

RTA / RTC

Register Value
CR[0x0CB0]/[0x0CB4] hwrtdata.rtc_dev_addr (64 b) — render target cache base; 0 = no RTA
CR[0x0CB8] 1 = RTC initialization trigger
CR[0x0CE0] mode: 0 = multi-RT (RTA active), 1 = no active RT, 3 = exactly 1 RT
CR[0x0D20] rta_ctl.active_render_targets

Logic (once per kick):

if rtc_dev_vaddr == 0:                       # single-RT path
    active = !first_geom_kick
    CR[0x0CE0] = (active ? 3 : 1)
    CR[0x0CB0/0x0CB4] = 0 ; CR[0x0CB8] = 1
    CR[0x0D20] = active
    rta_ctl.render_target_index = 0 ; rta_ctl.current_render_target = 0
else:                                        # RTA path
    CR[0x0CB0/0x0CB4] = rtc_dev_vaddr
    CR[0x0C48] = low word of TE cat base
    if first_geom_kick: rta_ctl.active_render_targets = 0
    CR[0x0CE0] = 0 ; CR[0x0CB8] = 1
    CR[0x0D20] = rta_ctl.active_render_targets
    if (kick_flags & 2): read RTC bitmap (below)

first_geom_kick = (kick_flags & 1) && !(hwrtdata.flags & GEOM_NEEDS_RESUME). On this path the firmware also toggles the global PB number (HWRTDATA_GLOBAL_PB_NUMBER_BIT0, bit 8 of flags), according to the DM.

Valid RTs Bitmap (RTA)

The hardware maintains 2048 bits (256 B) at rtc_dev_vaddr + 0x200. The firmware converts them into an array of indices:

map = bif_map_gpu_memory(rtc_dev_vaddr + 0x200, 256)
bit = 0
for i in 0 .. active_render_targets-1:
    advance bit until finding the next 1 in map (up to 2047)
    valid_render_targets[i] = (bit < 2048) ? bit : 0
    bit++
bif_unmap_gpu_memory()
rta_ctl.render_target_index = 0
rta_ctl.current_render_target = valid_render_targets[0]

3.3. VDM Programming and Trigger (Normal vs CSW Resume)

Mode CR[0x0408/0x040C] (VDM Stream Base) CR[0x0418/0x041C] (VDM Call Stack)
Normal Kick cmd.regs.vdm_ctrl_stream_base 0 (or initial base)
CSW Resume cctx.geom_reg_vdm_context_state_resume_addr 64-bit value previously saved into context_state from CR[0x0418/0x041C] (and CSW resume programs in VDM tasks)

4. TA Completion (HW1 — EVENT_STATUS bit 5 or bit 7) ([D])

When DM2 interrupts the firmware in HW1:

Case A — PM Out of Memory (EVENT_STATUS & 0x80)

  1. Clears the event: CR[0x0138] = 0x80.
  2. If the context has already hit an unrecoverable limit/error, marks a lockup on DM2 and emits FWCCB_CMD_CONTEXT_RESET_NOTIFICATION.
  3. Otherwise, enters the SPM (Smart Parameter Management) flow described in partial-render-spm.md.

Case B — TA Finished (EVENT_STATUS & 0x20)

  1. Clears the event: CR[0x0138] = 0x20.
  2. Invalidates MMU caches associated with HWRTData if necessary.
  3. If a CSW store was active:
    • Polls ROGUE_CR_VDM_CONTEXT_STORE_STATUS (CR[0x0430]) bit 0 == 1 with a bounded timeout in CR_TIMER ticks (fallback on expiration: pulses CR[0x0100] = 0x804000 → 0 preserving 0x0420 and 0x0418).
    • If bit 1 of 0x0430 is set → TA was preempted (stored): saves CR[0x0418/0x041C] into the context CSW state, internally marks HWRTData as TA-preempted, executes PM TA flush (CR[0x0260] = 1, poll bit 0 == 0), TE flush (CR[0x0C50] = 0x40000000, poll bit 30 == 0), executes the DM2 completion flush (data-masters.md §4.1: BCAST[0x0688] = 1 per core, 0x0668 = 5, 0x1608 = 0x10001, 0x1744 = 0x80, 0x1720 = 7/0x27, wrapper barrier, and BCAST[0x3818] = 2 = DM_TA + poll 0x3820 b2), does not retire the cCCB command, and releases DM2 for the next context.
  4. Normal completion (not preempted):
    • Clears the internal TA preemption state of this HWRTData.
    • If not LASTKICK: executes PM TA flush (CR[0x0260] = 1, poll bit 0 == 0).
    • If RTA active (CR[0x0CB0/0x0CB4] != 0): reads the number of active render targets from CR[0x0D20] and stores it in hwrtdata.rta_ctl.active_render_targets, executes TE flush (CR[0x0C50] = 0x40000000, poll bit 30 == 0) and RTC flush (CR[0x0CB8] = 2, poll CR[0x0CB8] bit 1 == 0).
    • If non-RTA: executes TE flush (CR[0x0C50] = 0x40000000, poll CR[0x0C50] bit 30 == 0) and sets hwrtdata.rta_ctl.active_render_targets = 1 (when LASTKICK).
    • Executes the DM2 completion flush (data-masters.md §4.1: 0x0688 = 1 per core, 0x0668 = 5, 0x1608 = 0x10001, 0x1744 = 0x80, 0x1720 = 7/0x27, wrapper barrier, BCAST[0x3818] = 2 + poll 0x3820 b2), retires the command in the cCCB (executing UPDATEs), deactivates MemCtx in the BIF, and if LASTKICK sets HWRTDATA_HAS_LAST_GEOM (BIT(2) in hwrt_data_flags) and triggers DM3 (FRAG) rescheduling by writing CR[0x0B00] = 0.