Imagination_BXM-4-64

Memory Model, MMU, and .fw Container Format

This document specifies the addressing domains of the SpacemiT K3 (36.56.104.183) GPU, the MIPS wrapper remapping (including the BRN 63553 workaround), the 3-level GPU MMU, and the .fw v3 firmware file format.


1. The Four Addressing Domains ([P])

Domain Width Used By Description
Physical Address (phys_addr / dma_addr) 36 bits DRAM / SLC / AXI-ACELite Bus SoC physical space visible to the GPU (up to 64 GiB)
GPU Virtual Address (dev_addr) 40 bits GPU blocks (VDM, TE, ISP, PBE, CDM, PM, USC, PDS) Translated by the 3-level GPU MMU (PC→PD→PT) using BIF banks 0..7
MIPS Virtual Address (fw_addr) 32 bits Firmware MIPS core Translated by the MIPS TLB (16 entries, host page table) or fixed kseg0/kseg1 segments
Host Virtual Address (RISC-V) 64 bits Linux drm/imagination driver CPU mapping of shared GEM objects

2. MIPS Processor Virtual Memory Map ([P][O])

The firmware executes with the MMU enabled and CP0.Config.K0 = 3. Per MIPS32 encoding, K0 = 2 is uncached and K0 = 3 is cacheable (write-back): therefore kseg0 (0x80000000–0x9FFFFFFF, including the exception code at 0x9FC02000) executes cached, whereas kseg1 (0xBFC00000, boot/NMI) is uncached by architectural definition. This is consistent with the firmware invalidating/priming the exception code I$ at boot.

2.1 Fixed Windows (No TLB)

MIPS Virtual Range Segment / Mechanism Policy Purpose
0x80000000 – 0x800007FF kseg0 (index addresses) Cache ops Base for index-based I$/D$ maintenance (2 KiB, 128 lines × 16 B)
0xBFC00000 – 0xBFC0_0FFF kseg1 via REMAP1 Uncached Boot/reset/NMI vector and CP0/cache initialization routines (MIPS_BOOT_CODE section, max 4 KiB)
0xBFC01000 – 0xBFC0_1FFF kseg1 via REMAP2 Uncached Uncached mirror of MIPS_BOOT_DATA
0x9FC01000 – 0x9FC0_1FFF kseg0 via REMAP2 Cacheable (K0=3) MIPS_BOOT_DATA (the only window used by the firmware; see §2.3)
0x9FC02000 – 0x9FC0_3FFF kseg0 via REMAP3 Cacheable (K0=3) Exception code (MIPS_EXCEPTIONS_CODE, max 8 KiB): TLB Refill vector (+0x000), general vector (+0x180), and interrupt vectors (+0x200..+0x600)
0xBFC01800 MIPS wrapper Uncached MIPS wrapper fence / write-buffer drain register (write 1 + ehb + sync)

2.2 TLB-Mapped Windows (kseg2)

The first TLB entries are fixed (Wired): Wired = 4 in the K3 vendor configuration and Wired = 5 when the host uses pt_num_pages = 4 (mainline). The remainder (Wired..15) are dynamic and serviced by the TLB Refill vector. Each entry covers a pair of pages (EntryLo0 = VA, EntryLo1 = VA + page_size).

TLB Index Virtual Range PageMask / Size EntryLo.C Purpose
0 0xCF800000 – 0xCFFFFFFF 0x7FF800 (4 MiB/page) 2 (uncached) + XI Unicast CR bank (0xCF800000) and broadcast BCAST[...] bank (0xCFA00000), since both fall within the same 4 MiB page. EntryLo1 maps 0xCFC00000 (window used to write the exception dump)
1 0xCF000000 + n × pt_log2_page_size PT page PageMask 3 (write-back) MIPS page table window. One entry covers pt_num_pages × page_size when pt_num_pages = 2 (K3 vendor config: 16 KiB page → 32 KiB); with pt_num_pages = 4 it takes two entries (4 KiB page, 8 KiB each)
2 config-dependent per PT 3 With pt_num_pages = 4: second half of PT window (0xCF002000). With pt_num_pages = 2: stack
3 config-dependent 0x1800 (4 KiB) 3 With pt_num_pages = 4: stack (0xCF600000). With pt_num_pages = 2: first page of MIPS_PRIVATE_DATA
4 config-dependent 0x1800 (4 KiB) 3 Only with pt_num_pages = 4: first page of MIPS_PRIVATE_DATA
Wired..15 0xC0000000 + FW Heap per PTE per PTE FW Heap code/data (demand-paged)

Wired depends on pt_num_pages: 4 in K3 vendor (log2 = 14, 2 pages) and 5 in mainline (log2 = 12, 4 pages). Both are observed/derived; the firmware accepts both configurations (validates even 12 ≤ log2 ≤ 18 and pt_num_pages < 5).

Note ([O]): the firmware uses C = 3 (write-back) for the page table, stack, and private data, whereas the host maps FW Heap pages in pvr_vm_mips.c with C = 1 (write-through) because phys_bus_width = 36. A reimplementation may use write-through everywhere without changing the ABI.

2.3 MIPS_BOOT_DATA ([P][O])

64-byte structure populated by the host before releasing reset (layout confirmed in pvr_rogue_mips.h and by reads at offsets 0x00, 0x08, 0x10, 0x18, 0x30, 0x34 in the 0x9FC01000 window):

Offset Field Contents
0x00 stack_phys_addr (u64) Physical address of the stack (MIPS_STACK, 1 page)
0x08 reg_base (u64) Physical base of the GPU register bank
0x10 pt_phys_addr[0..3] (4 × u64) Physical addresses of the 4 MIPS page table pages
0x30 pt_log2_page_size (u32) 12 (4 KiB); accepts 12..18 with parity constraint
0x34 pt_num_pages (u32) 4 (ROGUE_MIPSFW_MAX_NUM_PAGETABLE_PAGES)
0x38 reserved1 (u32) 0
0x3C reserved2 (u32) 0

Rules observed during K3 boot:

Note on unicast vs. broadcast accesses ([D]): On K3 MC1 there is only 1 physical core (ROGUE_CR_MULTICORE_SYSTEM = 1), but the silicon implements XPU_REGISTER_BROADCAST = 1. The firmware must respect BCAST[off] (0xCFA00000 + off) addressing for per-core replicated registers and CR[off] (0xCF800000 + off) for core/global control registers, exactly as indicated in the tables of boot-gpu-init.md, kick-geometry-ta.md, and kick-compute-and-3d.md.


3. MIPS_ADDR_REMAP1..5 Registers and BRN 63553 Workaround ([P][O])

Before releasing MIPS from reset, the host driver (pvr_fw_mips.c) configures 5 physical address remapping windows in the MIPS wrapper:

Window CONFIG1 (Input) CONFIG2 (Output + Size) Purpose in Mainline
REMAP1 0x1820 (0x1FC00000 | VALID) 0x1828 (boot/exception DMA | 64KB) Maps boot/exception vector 0xBFC00000 → boot DRAM
REMAP2 0x1838 (data VA | VALID) 0x1840 (data DMA | 4KB..256KB) Maps private data / MIPS table when outside TLB
REMAP3 0x1850 (code VA | VALID) 0x1858 (code DMA | size) Firmware code window
REMAP4 0x1868 (trampoline / MMIO) 0x1870 (0x0 or MMIO base | size) GPU CR register window mapping
REMAP5 0x1880 (0x00000000 | VALID) 0x1888 (boot code DMA | 64KB) Mandatory BRN 63553 workaround (K3 36-bit bus)

BRN 63553 Workaround Detail ([P])

On the 36.56.104.183 silicon (36-bit physical bus with BRN 63553 present), spurious transactions to physical address 0x0 during MIPS startup/execution cause a bus fault if not redirected. The host programs REMAP5 pointing input address 0x0 to the boot code DMA buffer (64 KiB). The firmware must not disable or overwrite REMAP5 during boot or normal operation.


4. MIPS Page Table, EntryLo, and TLB ([P][O])

4.1 Table Structure

4.2 PTE / EntryLo Format (32-bit, 36-bit Physical)

Bits Field Semantics
[31] RI — Read Inhibit Copied from PTE to EntryLo
[30] XI — Execute Inhibit Copied from PTE to EntryLo
[29:6] PFN (24 bits) phys_addr >> 12 → covers 2^(24+12) = 36 bits (64 GiB)
[5:3] C — Coherency/cache 0 = ?; 1 = write-through; 2 = uncached; 3 = write-back (ROGUE_MIPSFW_*_CACHE_POLICY)
[2] D — Dirty (writable)  
[1] V — Valid  
[0] G — Global (no ASID)  

Public masks: ROGUE_MIPSFW_ENTRYLO_PFN_MASK_ABOVE_32BIT = 0x3FFFFFC0, ..._CACHE_POLICY_SHIFT = 3, ..._DIRTY_EN = 4, ..._VALID_EN = 2, ..._GLOBAL_EN = 1.

The host writes PTE = ((dma >> 12) << 6) & PFN_MASK | C << 3 | D | V | G.

4.3 PageMask Encoding

The firmware uses the public macro ROGUE_MIPSFW_TLB_GET_PAGE_MASK(page_size_KiB):

PageMask = (((page_size_KiB << 11) - 1) & ~0x7FF)
Page Size PageMask Written
4 KiB 0x00001800
4 MiB 0x007FF800

Bits [12:11] of the written value are the vendor macro’s bias; the effective mask field is [28:13] (0 → 4 KiB, 0x3FF → 4 MiB).

4.4 How the TLB Refill Vector Builds the Entry ([O])

For the missing page, with VPN2 = EntryHi[31:13] read from the PTE pair:

EntryLo0 = (PTE0 & 0xC000003F) | (((EntryHi >> 12) + 0) << 6)   // PFN = even VPN
EntryLo1 = (PTE1 & 0xC000003F) | (((EntryHi >> 12) + 1) << 6)   // PFN = odd VPN

In other words: the PFN placed in the TLB is the VPN itself (VA & 0x0FFFFFFF), not the actual physical address. The actual physical translation happens in the MIPS wrapper range-remap table (§4.5), which is programmed with the PTE’s PFN. Practical consequences:

4.5 TLB ↔ MIPS_ADDR_REMAP_RANGE Coupling (32 Entries)

The wrapper exposes 32 range-remap entries, two per TLB entry (ROGUE_MIPSFW_NUMBER_OF_REMAP_ENTRIES = 2 × 16). There are three registers, and confusing them is a common source of error:

Register Offset Width Role
ROGUE_CR_MIPS_ADDR_REMAP_RANGE_CONFIG 0x0878 (+ 0x087C = high word) 64 b entry programming
ROGUE_CR_MIPS_ADDR_REMAP_RANGE_READ 0x0880 32 b read trigger (W1)
ROGUE_CR_MIPS_ADDR_REMAP_RANGE_DATA 0x0888 (+ 0x088C) 64 b read result (RO)

Bitfields of CONFIG (64-bit, effective address = 0x0878 with high word at 0x087C):

Bits Field Semantics
0 MODE_ENABLE 1 = entry active
[5:1] ENTRY entry index (0..31); value written is index << 1
[9:7] REGION_SIZE region size (encoding: 4 KB = 0, 16 KB = 1 … 4 MB = 5)
11 TRUSTED privileged access
[31:12] BASE_ADDR_IN input page (VA/PA depending on mode)
[34:32] OS_ID associated OSID
[59:36] ADDR_OUT output page → lives in the high word (0x087C): ADDR_OUT = phys >> 12, and the firmware writes 0x087C = phys >> 8

DATA (0x0888/0x088C) is only used to read back the entry (which the state dump does), never to program it.

Allocation of the 32 entries:

Entries Usage
0..15 Temporary translation for the missing page, paired with the dynamic TLB entry of the same index
16..31 Permanent translation for wired entries: 16 + i ↔ TLB index i

Programming sequence (per page): CONFIG = (ENTRY = index) | (REGION_SIZE) | (BASE_ADDR_IN = page) | MODE_ENABLE, then 0x087C = phys >> 8 (ADDR_OUT). For this reason, the TLB Refill vector cannot use the page table window itself to resolve the fault: it reprograms a remap entry and only then reads PTE0/PTE1. Initialization zeroes all 32 entries (0x0878 = i << 1, 0x087C = 0).

4.6 Invalidation


5. GPU MMU (3 Levels: 40-bit Virtual → 36-bit Physical) ([P])

The GPU execution blocks (VDM, TE, ISP, PBE, CDM, PM, USC, PDS) translate 40-bit virtual addresses through a 3-level hierarchical MMU managed by the host driver (pvr_mmu.c, pvr_rogue_mmu_defs.h):

Level Acronym VA Bits ([39:0]) Entries per Table Entry Size Table Size Coverage per Entry
Level 1 PC (Page Catalogue) [39:30] (10 bits) 1024 4 bytes (u32) 4 KiB 1 GiB
Level 2 PD (Page Directory) [29:21] (9 bits) 512 8 bytes (u64) 4 KiB 2 MiB
Level 3 PT (Page Table) [20:12] (9 bits) 512 8 bytes (u64) 4 KiB 4 KiB (page)
Offset — [11:0] (12 bits) — — — 4 KiB

GPU MMU Entry Formats ([P])

Firmware Role in the GPU MMU ([D])

The firmware does not build or edit user-context PC/PD/PT tables (that is exclusively the host’s job). The firmware’s responsibilities are:

  1. Program BIF_CAT_BASE1..7 (BCAST[0x1208..0x1238]) with pc_dev_paddr from struct rogue_fwif_fwmemcontext when activating a memory context for a DM (see data-masters.md).
  2. Program the PM (Parameter Manager) catalogue in the dedicated context 0/1 tables (see kick-geometry-ta.md).
  3. Perform on-demand MMU/SLC/TLB cache invalidations (KCCB_CMD_MMUCACHE) and during BIF bank switches or HWR.
  4. Capture and report MMU Page Faults (EVENT_STATUS bit 9 = 0x200).

6. Public GPU Virtual Heaps ([P])

Per pvr_rogue_heap_config.h, the GPU’s 40-bit space is partitioned into well-defined heaps (most relevant to the firmware):

Heap Role for the Firmware
Firmware Main / Config / Raw Shared between host and MIPS (mapped in OSID 0 FW Heap; OSID 0..7 supported by hardware)
General Vertex buffers, textures, framebuffers, cCCB payloads, VDM/CDM control streams
PDS Code/Data PDS state programs and data — base programmed in BCAST[0x0610/0x0614] (sysinit.pds_exec_base)
USC Code USC shaders — base programmed in BCAST[0x4008/0x4010/0x4028] (sysinit.usc_exec_base)
Transfer Frag / RGNHDR / MMU Auxiliary rendering structures

7. .fw Container Format (Mainline v3) ([P][O])

The mainline driver loads powervr/rogue_36.56.104.183_v1.fw by validating a structured footer/header defined in pvr_fw_info.h.

File Structure

┌────────────────────────────────────────────────────────┐
│ Binary payload of firmware sections                    │
│  (MIPS code, boot/exceptions, data, etc.)              │
├────────────────────────────────────────────────────────┤
│ struct pvr_fw_device_info_header + 29 × u64 params     │  (referenced by device_info_size)
├────────────────────────────────────────────────────────┤
│ struct pvr_fw_layout_entry[layout_entry_num] (6 items) │
├────────────────────────────────────────────────────────┤
│ struct pvr_fw_info_header (at the end of the file)     │
└────────────────────────────────────────────────────────┘

Critical Fields of pvr_fw_info_header ([P])

The 6 Layout Sections (pvr_fw_layout_entry) ([P][O])

# Type (type) Purpose Critical Rule in Mainline
0 MIPS_PRIVATE_DATA MIPS private data (.data/.bss) Mapped in the private data window
1 MIPS_EXCEPTIONS Boot/reset/NMI vector (0xBFC00000) Mapped by REMAP1 (64 KiB)
2 MIPS_CODE Main code (.text/.rodata) Mandatory invariant ([O]): alloc_size must remain fixed at the budget expected by the layout (page-aligned) and satisfy pvr_fw_mips.c validation (used in REMAP3 and REMAP5 BRN 63553). Increasing alloc_size shifts the shared FWIF allocations placed immediately after base + alloc_size and breaks the boot handshake (firmware_started)
3 MIPS_STACK Execution stack (4 KiB) alloc_size = 0x1000, no payload in file (base_size = 0)
4 MIPS_BOOT_DATA Initial handshake area filled by the host Host writes sysinit addresses, MIPS page table, and config before releasing reset
5 MIPS_CORE_MEM / auxiliary Exception state data / reserved area per v3 layout Per pvr_fw_validate() in pvr_fw.c

device_info Block (29 Parameters Consumed by Mainline) ([P][O])

The mainline driver validates and consumes 29 parameters (u64) from the device_info block embedded in .fw for BVNC 36.56.104.183: