Imagination_BXM-4-64

Host ↔ Firmware Interface and Boot Handshake

This document specifies the initialization, communication, and synchronization contract between the Linux host driver (drivers/gpu/drm/imagination) and the MIPS firmware of the SpacemiT K3 (36.56.104.183) GPU.


1. Host Initialization Sequence (pvr_fw_start) ([P])

Before the firmware executes its first instruction, the host performs the following sequence on the GPU hardware:

  1. SoC Clocks and Reset: Enables power domain K3_PMU_GPU_PWR_DOMAIN, enables CLK_APMU_GPU, deasserts RESET_APMU_GPU.
  2. Internal Soft Reset: Holds GPU blocks in reset via ROGUE_CR_SOFT_RESET (0x0100).
  3. MIPS Wrapper Configuration (pvr_fw_mips.c):
    • Programs ROGUE_CR_MIPS_WRAPPER_CONFIG (0x1800) with the base physical boot address.
    • Programs MIPS_ADDR_REMAP1..4 with code, data, exceptions, and MMIO.
    • Programs MIPS_ADDR_REMAP5 (0x1880/0x1888) mapping 0x0 → boot code DMA (BRN 63553).
    • Populates MIPS_BOOT_DATA in shared DRAM with:
      • Physical address of the MIPS page table (page_table_phys) and number of FW Heap pages.
      • Firmware virtual pointer (fw_addr) to struct rogue_fwif_sysinit and struct rogue_fwif_osinit (or boot pointer leading to sysinit).
      • FW Heap size and remapping configuration.
  4. Garten / Coherency Configuration:
    • Programs ROGUE_CR_MTS_GARTEN_WRAPPER_CONFIG (0x0BE0) defining the catalogue/OSID0 and SLC access policy.
    • Configures ROGUE_CR_BIF_CAT_BASE0 (0x1200) if applicable to OSID 0.
  5. Releasing the MIPS Processor:
    • Writes 0 to sysinit.firmware_started and 0 to FW_BOOT_STAGE (ROGUE_CR_SCRATCH0 or stage field depending on version).
    • Releases MIPS core reset (keeping SOFT_RESET controlled per the pvr_fw_startstop.c sequence).
  6. Waiting for Handshake:
    • The host polls sysinit.firmware_started (offset 0x160 in struct rogue_fwif_sysinit) waiting for the value 1 (typical driver timeout: several seconds; real boot on K3 takes < 2 ms).

2. Firmware Handshake Sequence ([P][D])

After leaving the reset vector (0xBFC00000) and initializing CP0, I$/D$, TLB, and stack (see execution-environment.md):

  1. Reading MIPS_BOOT_DATA:
    • Retrieves page_table_phys and enables dynamic FW Heap translation via TLB Refill.
    • Obtains the fw_addr pointers to struct rogue_fwif_sysinit, struct rogue_fwif_sysdata, struct rogue_fwif_osinit, and struct rogue_fwif_osdata (OSID 0).
  2. Boot Progress Stages (FW_BOOT_STAGE):
    • The firmware may report incremental progress in the boot diagnostic register (useful for debugging early hangs before firmware_started = 1).
  3. Compatibility Validation (compchecks):
    • Fills osinit.rogue_comp_checks (offset 0x28 in struct rogue_fwif_osinit) with the firmware’s compiled values (hw_bvnc, fw_bvnc, fw_build_options, ddk_version, ddk_build, and updated = 1).
    • Reads initial parameters from sysinit (initial_core_clock_speed at +0x158, active_pm_latency_ms at +0x15C, runtime_cfg_fw_addr at +0x13C).
  4. GPU Unit Initialization:
    • Executes the full sequence from boot-gpu-init.md (SLC detection at 0x3970, PDS/USC bases, BXM-4-64 unit defaults table, polls 0x4068/0x0CD8, event clear 0x0138 = 0x41FC, configuration of MTS_DM0..4_INTERRUPT_ENABLE and MTS_BGCTX/MTS_INTCTX).
  5. Publishing firmware_started = 1 with Mandatory Barrier ([D]):
    • Reads ROGUE_CR_TIMER (0x0160/0x0164) and writes it to sysinit.firmware_started_timestamp (+0x168).
    • Performs D-cache flush over sysinit (16 B lines).
    • Writes 1 to 0xBFC01800 (MIPS wrapper fence), followed by ehb and sync.
    • Performs a dummy CR register read (e.g., CR[0x0020]) to drain the MMIO path.
    • Writes sysinit.firmware_started = 1 (+0x160).
    • Performs D-cache flush of the line containing firmware_started, writes 1 to 0xBFC01800, ehb + sync.
  6. Entering the Operational Loop:
    • Enables CP0 interrupts (HW0, HW1, HW2) and enters WAIT until the first host kick.

3. Host → Firmware Signaling (MTS Doorbell) ([P][D])

The host never interrupts MIPS by writing directly to CP0 registers. All Host → FW signaling goes through MTS (ROGUE_CR_MTS_SCHEDULE, offset 0x0B00):

Write to 0x0B00 Relevant Bits Effect in Firmware
dm (0..4) + OSID (0..7) + BG flag ROGUE_CR_MTS_SCHEDULE_DM_SHIFT, TASK_NON_COUNTED / COUNTED Enqueues a Background (BG, HW0) task in MTS; MIPS wakes from WAIT and enters the BG handler
KCCB kick (DM0 / GP) DM = 0 (GP) Signals that kccb_ctl.write_offset advanced and there are new KCCB commands to drain
Specific DM kick DM = 2 (GEOM), 3 (FRAG), 4 (CDM) Can be issued by the host or by the firmware itself (CR[0x0B00] = 0) to re-evaluate queues

4. Firmware → Host Signaling (Interrupt hwirq 75) ([P][D])

To wake the Linux driver (after completing work and updating UFOs/Sync Checkpoints, enqueuing a command in FWCCB, or reporting HWR/Power):

  1. The firmware ensures memory visibility of writes to UFOs / fwccb_ctl.write_offset / sysdata (D-cache flush + 0xBFC01800 = 1 + ehb + sync).
  2. The firmware triggers the host interrupt for the corresponding OSID (ROGUE_CR_MIPS_WRAPPER_IRQ_STATUS / ROGUE_CR_IRQ_OS0_EVENT_STATUS register — in the MIPS wrapper, writing the host IRQ trigger register, and the host acknowledges/clears it in ROGUE_CR_IRQ_OS0_EVENT_CLEAR when handling Linux IRQ 53 / APLIC hwirq 75).
  3. In its IRQ handler, the Linux driver reads IRQ_OS0_EVENT_STATUS, clears the corresponding bit, drains the FWCCB ring (pvr_ccb.c), and signals the dma_fence objects of completed jobs.

5. Clean Stop (pvr_fw_stop) and Warm Boot ([P][D])

Stop / Power-Off (APM or Suspend)

  1. When all queues are empty and the APM timer (active_pm_latency_ms, default 100 ms) expires — or when the host sends KCCB_CMD_POW with ROGUE_FWIF_POW_OFF_REQ / ROGUE_FWIF_POW_FORCED_IDLE_REQ:
  2. The firmware ensures no DM is active, drains caches/SLC, updates sysdata.pow_state = ROGUE_FWIF_POW_OFF, and writes the marker at osdata.power_sync_fw_addr (offset 0x23C of struct rogue_fwif_osdata, if configured).
  3. Executes the final power-off sequence (see power-management.md) and enters a clean-halt infinite WAIT.
  4. The host confirms the idle/off state, puts MIPS in reset, and cuts GPU clock/power in the SoC.

Warm Boot

  1. The host restores power and CLK_APMU_GPU, reprograms MIPS_ADDR_REMAP1..5 (including REMAP5 BRN 63553), and releases MIPS.
  2. The firmware re-runs CP0/TLB initialization and boot-gpu-init (all GPU units lost state during the power gate!).
  3. Upon verifying that sysinit/osinit already contain an active connection_ctl and existing contexts, the firmware preserves the logical state of contexts and immediately resumes scheduling after signaling firmware_started = 1.
  4. Typical time observed on a K3 board for post-APM warm reinit: < 2 ms.