omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / gpu / driver / gsp / seq.om
| 1 | note gsp/seq.om: the CPU side of GSP_RUN_CPU_SEQUENCER (event 0x1002) in seeded Omega, a port of |
| 2 | note aien-dev/aienux PR #441 native/kernel/gpu/gsp_seq.{h,c} (gsp_seq_run, payload_dwords), which replaces |
| 3 | note NVIDIA's kgspExecuteSequencerBuffer_IMPL (open-gpu-kernel-modules 580.173.02, |
| 4 | note src/nvidia/src/kernel/gpu/gsp/kernel_gsp.c:5297-5432, called from the 0x1002 handler at :442). |
| 5 | note Opcodes and payload sizes (rmgspseq.h src/nvidia/arch/nvalloc/common/inc/rmgspseq.h:78-101, :215): |
| 6 | note 0 REG_WRITE 2 dwords addr val BAR0[addr] = val kernel_gsp.c:5331 |
| 7 | note 1 REG_MODIFY 3 dwords addr mask val BAR0[addr] = (old & ~mask) | val :5341 |
| 8 | note 2 REG_POLL 5 dwords addr mask val tmo err wait until (BAR0[addr] & mask) == val :5356 |
| 9 | note 3 DELAY_US 1 dword us wait us microseconds :5383 |
| 10 | note 4 REG_STORE 2 dwords addr index save[index] = BAR0[addr], index < 8 :5392, :5397 |
| 11 | note 5 CORE_RESET 6 CORE_START 7 CORE_WAIT_FOR_HALT 8 CORE_RESUME: 0 dwords :5403 :5412 :5420 |
| 12 | note All nine are here; none is missing. The four core opcodes are falcon HALs in NVIDIA (kflcnReset, |
| 13 | note kflcnStartCpu, kflcnWaitForHalt; on GB10B CORE_RESUME goes to kgspExecuteSequencerCommand_GA102, |
| 14 | note g_kernel_gsp_nvoc.c:1028-1047 -> kernel_gsp_ga102.c:136-200). They restart the chip, so, as in the C, |
| 15 | note they are not guessed at register level: the build supplies fn sqcorefn op ulong to long (0 done, |
| 16 | note anything else failed) and sets sqcore 1; with sqcore 0 every core opcode is refused. |
| 17 | note The walk is the C's: nwords (bufferSizeDWord) > 0, ci (cmdIndex) < nwords, stop at ci; an unknown |
| 18 | note opcode or a payload that runs past ci is refused before anything of it is done. REG_POLL's timeout |
| 19 | note and error dwords are not used: a poll gets sqbud extra reads (0 counts as 1), as in the C. |
| 20 | note Library unit: no main. Build after gsp/mmio.om (gsprd, gspwr, gsppause, gspmode, M32) and, for host |
| 21 | note tests, gsp/sim.om. Register I/O is only gsprd/gspwr; mode 0 is the simulator, mode 1 BAR0. |
| 22 | note Name prefix sq / SQ only. Nothing here has run on the chip. |
| 23 | note |
| 24 | note API: put the dwords in sqbuf[0..nwords), set sqbud (poll budget), sqcore (0/1), clear sqsave and sqdly |
| 25 | note if wanted, then r = sqrun nwords cmdindex. sqrun returns 0 or a code below; sqwhy r puts the C's why text |
| 26 | note into sqwb[0..sqwl). sqsave[0..8) gets REG_STORE values; sqdly[0] counts DELAY_US opcodes, sqdly[1] |
| 27 | note adds their microseconds (mode 1 also sleeps them). |
| 28 | note Codes: -1 empty buffer; -2 cmdIndex not inside the buffer; -3 unknown opcode; -4 opcode overruns |
| 29 | note cmdIndex; -5 poll timed out; -6 save index out of range; -7 core opcode with no core callback; |
| 30 | note -8 core opcode failed; .om only: -9 nwords over 16384 (sqbuf, the 64 KiB GSP message limit, |
| 31 | note message_queue_priv.h:91-96, as dwords); -10 the mode 1 sleep failed; -11 poll budget over 999998 |
| 32 | note (the OM-1 loop bound). The C's "null argument" has no counterpart: nothing here can be null. |
| 33 | const SQMAX ulong 16384 |
| 34 | const SQSAVE ulong 8 |
| 35 | const SQBMAX ulong 999998 |
| 36 | note opcode numbers (rmgspseq.h:78-101) |
| 37 | const SQWR ulong 0 |
| 38 | const SQMOD ulong 1 |
| 39 | const SQPOLL ulong 2 |
| 40 | const SQDLY ulong 3 |
| 41 | const SQSTO ulong 4 |
| 42 | const SQCRST ulong 5 |
| 43 | const SQCRES ulong 8 |
| 44 | const SQEEMP long -1 |
| 45 | const SQEIDX long -2 |
| 46 | const SQEOP long -3 |
| 47 | const SQEOVR long -4 |
| 48 | const SQEPOLL long -5 |
| 49 | const SQESAVE long -6 |
| 50 | const SQENOC long -7 |
| 51 | const SQECORE long -8 |
| 52 | const SQECAP long -9 |
| 53 | const SQESLP long -10 |
| 54 | const SQEBUD long -11 |
| 55 | text sqwt "empty buffer|cmdIndex not inside the buffer|unknown opcode|opcode overruns cmdIndex|poll timed out|save index out of range|core opcode with no core callback|core opcode failed|nwords over 16384|delay sleep failed|poll budget over 999998|" |
| 56 | global sqbuf uint 16384 |
| 57 | global sqsave ulong 8 |
| 58 | global sqbud ulong 1 |
| 59 | global sqcore ulong 1 |
| 60 | global sqdly ulong 2 |
| 61 | global sqwb uchar 64 |
| 62 | global sqwl ulong 1 |
| 63 | note payload dwords of op, M32 for an unknown opcode (GSP_SEQUENCER_PAYLOAD_SIZE_DWORDS) |
| 64 | fn sqpay op ulong to ulong |
| 65 | if or eq op SQWR eq op SQSTO |
| 66 | ret 2 |
| 67 | end |
| 68 | if eq op SQMOD |
| 69 | ret 3 |
| 70 | end |
| 71 | if eq op SQPOLL |
| 72 | ret 5 |
| 73 | end |
| 74 | if eq op SQDLY |
| 75 | ret 1 |
| 76 | end |
| 77 | if and ge op SQCRST le op SQCRES |
| 78 | ret 0 |
| 79 | end |
| 80 | ret M32 |
| 81 | end |
| 82 | fn sqw i ulong to ulong |
| 83 | ret ulong get sqbuf i |
| 84 | end |
| 85 | fn sqpoll a0 ulong a1 ulong a2 ulong to long |
| 86 | left = get sqbud 0 |
| 87 | if eq left 0 |
| 88 | left = 1 |
| 89 | end |
| 90 | v = and gsprd a0 M32 |
| 91 | while ne and v a1 a2 bound 999999 |
| 92 | if eq left 0 |
| 93 | ret SQEPOLL |
| 94 | end |
| 95 | left = sub left 1 |
| 96 | gsppause |
| 97 | v = and gsprd a0 M32 |
| 98 | end |
| 99 | ret 0 |
| 100 | end |
| 101 | note one opcode whose payload starts at sqbuf[i] |
| 102 | fn sqone op ulong i ulong to long |
| 103 | if eq op SQWR |
| 104 | gspwr sqw i sqw add i 1 |
| 105 | ret 0 |
| 106 | end |
| 107 | if eq op SQMOD |
| 108 | a = sqw i |
| 109 | v = and gsprd a M32 |
| 110 | gspwr a or and v xor sqw add i 1 M32 sqw add i 2 |
| 111 | ret 0 |
| 112 | end |
| 113 | if eq op SQPOLL |
| 114 | r = sqpoll sqw i sqw add i 1 sqw add i 2 |
| 115 | ret r |
| 116 | end |
| 117 | if eq op SQDLY |
| 118 | us = sqw i |
| 119 | put sqdly 0 add get sqdly 0 1 |
| 120 | put sqdly 1 add get sqdly 1 us |
| 121 | if ne get gspmode 0 0 |
| 122 | s = gspdelay us |
| 123 | if lt s 0 |
| 124 | ret SQESLP |
| 125 | end |
| 126 | end |
| 127 | ret 0 |
| 128 | end |
| 129 | if eq op SQSTO |
| 130 | k = sqw add i 1 |
| 131 | if ge k SQSAVE |
| 132 | ret SQESAVE |
| 133 | end |
| 134 | put sqsave k and gsprd sqw i M32 |
| 135 | ret 0 |
| 136 | end |
| 137 | if eq get sqcore 0 0 |
| 138 | ret SQENOC |
| 139 | end |
| 140 | c = sqcorefn op |
| 141 | if ne c 0 |
| 142 | ret SQECORE |
| 143 | end |
| 144 | ret 0 |
| 145 | end |
| 146 | fn sqrun nw ulong ci ulong to long |
| 147 | put sqwl 0 0 |
| 148 | if eq nw 0 |
| 149 | ret SQEEMP |
| 150 | end |
| 151 | if ge ci nw |
| 152 | ret SQEIDX |
| 153 | end |
| 154 | if gt nw SQMAX |
| 155 | ret SQECAP |
| 156 | end |
| 157 | if gt get sqbud 0 SQBMAX |
| 158 | ret SQEBUD |
| 159 | end |
| 160 | i = ulong 0 |
| 161 | while lt i ci bound 999999 |
| 162 | op = sqw i |
| 163 | i = add i 1 |
| 164 | n = sqpay op |
| 165 | if eq n M32 |
| 166 | ret SQEOP |
| 167 | end |
| 168 | if gt add i n ci |
| 169 | ret SQEOVR |
| 170 | end |
| 171 | r = sqone op i |
| 172 | if ne r 0 |
| 173 | ret r |
| 174 | end |
| 175 | i = add i n |
| 176 | end |
| 177 | ret 0 |
| 178 | end |
| 179 | note the why text of code e into sqwb[0..sqwl); 0 leaves it empty |
| 180 | fn sqwhy e long to void |
| 181 | put sqwl 0 0 |
| 182 | if ge e 0 |
| 183 | ret |
| 184 | end |
| 185 | k = ulong sub 0 add e 1 |
| 186 | w = ulong 0 |
| 187 | o = ulong 0 |
| 188 | for j ulong len sqwt |
| 189 | c = get sqwt j |
| 190 | if eq c 124 |
| 191 | w = add w 1 |
| 192 | else |
| 193 | if eq w k |
| 194 | put sqwb o c |
| 195 | o = add o 1 |
| 196 | end |
| 197 | end |
| 198 | end |
| 199 | put sqwl 0 o |
| 200 | end |