interplane.Get Omega
Read in your language

omega-gpu-driver

aien-dev/omega-gpu-driver

Brought by drakestapleton

branch main Branches Tags History

omega-gpu-driver / gsp / seq.om

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