code wiki / _hdl_build / nx_gpu_ring.nx

nx_gpu_ring.nx

buildroot/runtime/_hdl_build/nx_gpu_ring.nx

11357 B147 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind tooltopic gpu
docsdependenciesstructsconstsfunctions

about

nx_gpu_ring.nx -- GATE: a GPU BAR/MMIO COMMAND-RING SUBMISSION MODEL (deepens GPU-DRIVER toward the real-hw BAR/ring gap). Where nx_gpu_driver has the vendor table + safe opcode set, THIS models the actual submission MECHANISM real GPUs use: a device with BAR-mapped MMIO registers (ring base/size/head/tail, doorbell, fence, status) over an mmap'd 'device memory', a command ring the host fills, a DOORBELL write that makes the device consume the ring, and a FENCE the device writes on completion that the host waits on. The rung before a real PCIe BAR submission. ★ NEVER-BRICK (cardinal 26) BY CONSTRUCTION: pure in-memory model over mmap'd 'BAR' memory -- touches NO real PCI device, NO firmware. The device's dispatch has ZERO firmware/vBIOS/flash-write opcodes and REFUSES (halts the ring, STATUS=ERR) any opcode outside the safe set -- the firmware-write path does not execute. The real-BAR activation (gpu_activate_real_bar) is REFUSED by construction. Proven mechanically in T4/T5, not asserted. T1 MMIO register read/write roundtrip (the BAR register file). T2 submit a frame: doorbell -> device consumes ring -> framebuffer reflects the commands -> fence signals completion (head advances to tail). T3 NEVER-BRICK: a normal frame has 0 firmware-write opcodes; the device runs it fully. T4 teeth: a firmware-write opcode in the ring is REFUSED -- device HALTS at it, fence not signalled, it never runs. T5 real-BAR activation refused by construction + determinism (process twice -> identical device memory). expect_exit: 0 Sovereign: nx_syscalls.

dependencies 2 imports · 0 importers

nx_syscalls.nx nx_itoa_lib.nx nx_gpu_ring.nx

imports: nx_syscalls.nxnx_itoa_lib.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main g_puts sys_write dev_new sys_mmap mmio_w mmio_w ↻ mmio_r g_pn nxi_out nxi_fd sys_mmap ↻ ccz_cat_num sys_write ↻ sys_munmap ck g_puts ↻ ring_push mmio_r ↻ mmio_w ↻ ring_doorbell mmio_w ↻ dev_process mmio_r ↻ op_safe mmio_w ↻ fence_reached mmio_r ↻ op_safe ↻ gpu_activate_real_bar dev_cksum sys_openat_append sys_write ↻ sys_close sys_exit

structs

none

consts

18const REG_MAGIC_5381: i64 = 5381
29const REG_RING_BASE: i64 = 0
30const REG_RING_SIZE: i64 = 1
31const REG_HEAD: i64 = 2 // consumer index (device-owned)
32const REG_TAIL: i64 = 3 // producer index (host-owned)
33const REG_DOORBELL: i64 = 4 // host writes -> device consumes
34const REG_FENCE: i64 = 5 // device writes completion value; host polls (read-only to host)
35const REG_STATUS: i64 = 6 // 0=idle 1=ok 2=ERROR(refused)
36const REG_DRAWS: i64 = 7 // draws executed (a visible side effect)
37const RING_BASE: i64 = 64 // ring slots start here; each slot = 3 words (op,a0,a1)
38const FB_BASE: i64 = 512 // simulated framebuffer
39const DEVWORDS: i64 = 4096
40const ST_OK: i64 = 1
41const ST_ERR: i64 = 2
43const OP_CLEAR: i64 = 1
44const OP_DRAW: i64 = 2
45const OP_COPY: i64 = 3
46const OP_COMPUTE: i64 = 4
47const OP_FENCE: i64 = 5
48const OP_FW_WRITE: i64 = 100 // firmware write -- the brick risk; NOT safe, used only to PROVE refusal

functions

20func g_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
called by 2: ckmain calls 1: sys_write
25func g_pn(v: i64) -> i64 { nxi_out(v); return 0 }
called by 1: main calls 1: nxi_out
26func ck(name: *u8, c: i64) -> i64 { if c==1 { g_puts(" PASS " as *u8) } else { g_puts(" FAIL " as *u8) } g_puts(name); g_puts("\n" as *u8); return c }
called by 1: main calls 1: g_puts
49func op_safe(op: i64) -> i64 { if op>=1 { if op<=5 { return 1 } } return 0 }
called by 2: dev_processmain
52func mmio_w(dev: *i64, off: i64, val: i64) -> i64 { dev[off]=val; return 0 }
53func mmio_r(dev: *i64, off: i64) -> i64 { return dev[off] }
55func dev_new() -> *i64
called by 1: main calls 2: sys_mmapmmio_w
63func ring_push(dev: *i64, op: i64, a0: i64, a1: i64) -> i64
called by 1: main calls 2: mmio_rmmio_w
72func dev_process(dev: *i64) -> i64
called by 1: ring_doorbell calls 3: mmio_rop_safemmio_w
89func ring_doorbell(dev: *i64) -> i64 { mmio_w(dev, REG_DOORBELL, 1); return dev_process(dev) }
called by 1: main calls 2: mmio_wdev_process
91func fence_reached(dev: *i64, want: i64) -> i64 { if mmio_r(dev, REG_FENCE) >= want { return 1 } return 0 }
called by 1: main calls 1: mmio_r
92func dev_cksum(dev: *i64) -> i64 { var h: i64=REG_MAGIC_5381; var i: i64=0; while i<DEVWORDS { h=((h<<5)+h)+dev[i]; i=i+1 } return h }
called by 1: main
94func gpu_activate_real_bar(neverbrick_hw_proof: i64) -> i64 { if neverbrick_hw_proof==0 { return 0-1 } return 0-1 }
called by 1: main
96func main() -> i64