Imagination_BXM-4-64

Kernel CCB (KCCB — Host → Firmware Commands)

The KCCB (Kernel Command Control Buffer) is the unidirectional ring buffer through which the Linux driver (pvr_ccb.c) sends control commands, kick submissions, power management requests, cache invalidations, and resource cleanup commands to the firmware.


1. Control Structure and Buffer ([P])

struct rogue_fwif_ccb_ctl — 144 bytes (shared by KCCB and FWCCB)

Verified in pvr_rogue_fwif_check.h (with cache-line padding between producer and consumer):

Offset Type Field Write Owner Description
0x00 u32 write_offset Producer (Host in KCCB) Next slot to be written (0 .. wrap_mask)
0x04..0x7F u8[124] padding — Cache-line separation between producer and consumer
0x80 (128) u32 read_offset Consumer (FW in KCCB) Next slot to be read by the firmware
0x84 (132) u32 wrap_mask Fixed at init num_slots - 1 (power of 2 minus 1)
0x88 (136) u32 cmd_size Fixed at init Size of each slot in bytes (88 bytes for struct rogue_fwif_kccb_cmd)
0x8C (140) u32 padding2 — Final padding to 144 bytes

struct rogue_fwif_kccb_cmd — 88 bytes ([P])

| Offset | Type | Field | Description | |—:|—|—|—| | 0x00 | u32 | cmd_type | Command code (enum rogue_fwif_kccb_cmd_type, base 0x2ABC0000 \| id) | | 0x04 | u32 | kccb_flags | KCCB command flags | | 0x08 | union (80 B) | cmd_data | Command-specific payload |


2. Return Slots (kernel_ccb_rtn_slots) ([P])

The kernel_ccb_rtn_slots array (pointed to by osinit.kernel_ccb_rtn_slots_fw_addr) holds a u32 word indexed by the KCCB slot (read_offset). Upon finishing processing a KCCB command, the firmware writes a combination of the public flags (pvr_rogue_fwif.h) to the corresponding slot:

Public Flag Value Semantics
ROGUE_FWIF_KCCB_RTN_SLOT_NO_RESPONSE 0x0 Not yet processed
ROGUE_FWIF_KCCB_RTN_SLOT_CMD_EXECUTED BIT(0) (0x1) The firmware consumed and processed the command
ROGUE_FWIF_KCCB_RTN_SLOT_CLEANUP_BUSY BIT(1) (0x2) Applicable to KCCB_CMD_CLEANUP: the resource still has work in flight (executed < submitted); the host must retry later
ROGUE_FWIF_KCCB_RTN_SLOT_POLL_FAILURE BIT(2) (0x4) A CR register poll failure occurred during the command (e.g., MMUCACHE / SLCFLUSHINVAL)

Visibility rule ([D]): Before advancing kccb_ctl.read_offset or signaling the host, the firmware must write the value to rtn_slots[slot] and ensure visibility (Write-Through + flush/fence when required).


3. KCCB Command Catalog (Mainline ABI 1.1) ([P][D])

The numeric values match enum rogue_fwif_kccb_cmd_type in pvr_rogue_fwif.h exactly, with marker ROGUE_CMD_MAGIC_DWORD_SHIFTED (0x2ABC0000) id:
Public Command (ROGUE_FWIF_KCCB_CMD_*) ID (0x2ABC00..) Member in cmd_data Required Firmware Action on K3 (36.56.104.183)
KICK 0x2ABC0065 (101) cmd_kick_data Updates cccb_ctl.write_offset (if applicable), places the common context onto the DM waiting queue (GEOM/FRAG/CDM), and triggers the scheduler
MMUCACHE 0x2ABC0066 (102) mmu_cache_data Ordered invalidation: (1) BCAST[0x3818] = 0x10 + poll 0x3820; (2) BCAST[0x12A0] = flags & 0xF + poll 0x12A0 == 0; (3) if (flags & 0x10) and BIF active: BCAST[0x1348] = 1 + poll 0x1348 bit 0 == 0; (4) 0xBFC01800 = 1, ehb, sync; (5) invalidates dynamic MIPS TLB entries; (6) if sUpdateAddr != 0, writes sUpdateValue to the translated address via uncached alias (+0x40000000); (7) if (flags >> 26) & 1, writes rtn_slots[slot] (1 = success, 5 = CMD_EXECUTED \| POLL_FAILURE) and triggers host IRQ
BP 0x2ABC0067 (103) bp_data Sets/clears a shader debug breakpoint (optional)
SLCFLUSHINVAL 0x2ABC0069 (105) slc_flush_inval_data Performs SLC flush and/or invalidation via ROGUE_CR_SLC_CTRL_FLUSH_INVAL (0x3818) + poll on ROGUE_CR_SLC_STATUS0 (0x3820)
CLEANUP 0x2ABC006A (106) cleanup_data Checks whether the object is idle (executed_commands == submitted_commands and not in queues/hardware). If free: unbinds from PM/BIF/scheduler and returns CMD_EXECUTED; if in use: returns CMD_EXECUTED \| CLEANUP_BUSY
POW 0x2ABC006B (107) pow_data (enum rogue_fwif_power_type) Sub-commands: 1 = POW_OFF_REQ; 2 = FORCED_IDLE (req=1 forces idle, req=2 cancels forced idle, req=3 enables bit 12 0x1000 in BCAST[0x0B58] and clears forced-idle flags); 3 = NUM_UNITS_CHANGE; 4 = APM_LATENCY_CHANGE (see power-management.md)
ZSBUFFER_BACKING_UPDATE 0x2ABC006C (108) zs_buffer_backing_data Confirms that the on-demand Z/S buffer was populated by the host after FWCCB_CMD_ZSBUFFER_BACKING
ZSBUFFER_UNBACKING_UPDATE 0x2ABC006D (109) zs_buffer_backing_data Confirms unbacking of the on-demand Z/S buffer
FREELIST_GROW_UPDATE 0x2ABC006E (110) free_list_gs_data Updates current_pages/ready_pages of the freelist after the host services FWCCB_CMD_FREELIST_GROW; if TA was waiting in SPM/OOM, resumes TA or advances SPM
FREELISTS_RECONSTRUCTION_UPDATE 0x2ABC0070 (112) free_lists_reconstruction_data Confirms that the host reconstructed the freelists after HWR; unblocks DMs waiting for reconstruction
NOTIFY_WRITE_OFFSET_UPDATE 0x2ABC0072 (114) write_offset_update_data Notifies a write_offset advance for an already-queued context
HEALTH_CHECK 0x2ABC0073 (115) — Health ping: does not alter hardware state; immediately marks CMD_EXECUTED and notifies the host
FORCE_UPDATE 0x2ABC0074 (116) force_update_data Forces signaling of pending UFOs/fences up to a cCCB offset
COMBINED_GEOM_FRAG_KICK 0x2ABC0075 (117) combined_geom_frag_cmd_kick_data Atomic shortcut that enqueues both a Geometry (DM2) kick and a Fragment (DM3) kick in a single KCCB command
OS_ONLINE_STATE_CONFIGURE 0x2ABC0076 (118) cmd_os_online_state_data Configures online/offline state of secondary OSIDs (virtualization)
REGCONFIG 0x2ABC00C8 (200) reg_config_data Manages optional list of register overrides applied at init
HWPERF_UPDATE_CONFIG 0x2ABC00C9 (201) hw_perf_ctrl Enables/disables HWPerf packet emission and updates the event mask
HWPERF_CTRL_BLKS 0x2ABC00CB (203) hw_perf_ctrl_blks Enables or disables configured HWPerf blocks
CORECLKSPEEDCHANGE 0x2ABC00CC (204) core_clk_speed_change_data Updates runtime_cfg.core_clock_speed, recalculates APM/HWR deadlines in CR_TIMER ticks, and emits a clock-change HWPerf event if enabled
LOGTYPE_UPDATE 0x2ABC00CE (206) — Re-reads tracebuf.log_type and updates active FW Trace groups
PDVFS_LIMIT_MAX_FREQ 0x2ABC00CF (207) pdvfs_max_freq_data Sets the maximum OPP/frequency limit (PDVFS)
OSID_PRIORITY_CHANGE 0x2ABC00D0 (208) — Adjusts the relative priority of an OSID
STATEFLAGS_CTRL 0x2ABC00D1 (209) — Updates global operational flags (e.g., HWR or CSW at runtime)
PDVFS_LIMIT_MIN_FREQ 0x2ABC00D4 (212) pdvfs_min_freq_data Sets the minimum OPP/frequency limit (PDVFS)
PHR_CFG 0x2ABC00D5 (213) — Configures Periodic Hardware Reset (optional)
WDG_CFG 0x2ABC00D7 (215) — Configures Safety Firmware Watchdog (optional)
COUNTER_DUMP 0x2ABC00D8 (216) counter_dump_config_data Controls performance counter dumping
HWPERF_CONFIG_ENABLE_BLKS 0x2ABC00D9 (217) hw_perf_cfg_enable_blks Configures, clears, and enables HWPerf counter blocks
HWPERF_SELECT_CUSTOM_CNTRS 0x2ABC00DA (218) hw_perf_select_cstm_cntrs Selects custom HWPerf counters
HWPERF_CONFIG_BLKS 0x2ABC00DC (220) hw_perf_cfg_da_blks Configures directly addressable HWPerf blocks (6 mux blocks on BXM-4-64)

4. Drain Order in BG Context (HW0) ([D])

  1. Upon waking in BG (HW0), the firmware reads kccb_ctl.read_offset and kccb_ctl.write_offset.
  2. While read_offset != write_offset:
    • Prior D-cache invalidation ([D]): invalidates the D-cache lines (cache Hit_Writeback_Invalidate_D, op 0x15, 16 B stride) covering the entire 88-byte slot ([slot_addr, slot_addr + 0x67]) before reading cmd_type and cmd_data, ensuring MIPS does not read a stale cached command after ring reuse by the host.
    • Reads struct rogue_fwif_kccb_cmd at slot read_offset.
    • Executes the corresponding action (respecting hardware synchronization for commands such as POW or MMUCACHE).
    • Writes the result to rtn_slots[read_offset].
    • Advances kccb_ctl.read_offset = (read_offset + 1) & wrap_mask.
  3. After draining ready KCCB commands, runs the DM queue scheduling cycle (see scheduler.md).
  4. Triggering host interrupt (hwirq 75) ([D]): when any consumed command requires immediate host awareness (or produced FWCCB items / updated UFOs), the firmware executes the bus ordering barrier before pulsing the IRQ:
    • Writes *(volatile u32 *)0xBFC01800 = 1, ehb, sync.
    • Performs a readback of 0xBFC01800 and CR[0x0020] (ROGUE_CR_CORE_ID__PBVNC) to ensure all DRAM/CR writes have completed.
    • Writes CR[0x08A8] = 1 (interrupt assert to the host CPU).

KCCB_CMD_CLEANUP — Checklist by Resource Type ([O])

The command carries the resource type at cmd + 0x08 (u16) and the resource address at cmd + 0x0C (dev addr masked with 0xC1FFFFFC). The firmware dispatches:

Type Resource “Still in Use” Condition (Returns Busy and Re-queues)
0 COMMON_CONTEXT the context’s CCB still has work: write pointer ≠ read pointer. Afterwards unlinks from the per-DM list and flushes D-cache
1 HWRTDATA completed references < pending references (HWRTDATA’s own counters). Afterwards unbinds from the 3 PM contexts and flushes D-cache
2 FREELIST grow_pending != 0 or the “FW init complete” bit is clear in global flags or the freelist is still loaded in any PM context (hwrtdata.apsFreeLists[0..2]) or inconsistent counters
3 ZSBUFFER completed references < pending references (ZS buffer counters); then range D-cache flush

General rules: