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 / sim.om

332 lines · 7069 bytes Raw Blame History
1note gsp/sim.om: a simulated GB10B SEC2 + GSP falcon for host tests of gsp/mmio.om. NOT the chip.
2note Port of aien-dev/aienux PR #441 native/kernel/gpu/gsp_sim.{h,c}. Models only what the driver source
3note says the host sees on BAR0 during GSP start-up: SEC2 EMEM channel 0 (1 KiB, EMEMC/EMEMD with write
4note auto-increment), its queue HEAD/TAIL and MAILBOX0/1, and the GSP falcon's MAILBOX0/1, HWCFG2
5note (target-mask pattern, lockdown bit 13), FALCON_OS, RISC-V CPUCTL and QUEUE_HEAD(0). Time is counted
6note in reads of the polled register. Every access is logged in order (first 1024 kept, all counted);
7note accesses the driver never makes, and orders it never uses, are violations. SIM-CHOICE marks what
8note the source does not settle. The offsets are this file's own copies (not the driver's), so a wrong
9note driver constant shows up as a wrong access instead of moving the simulator with it.
10note Library unit: no main. simrd / simwr are the mode 0 device of gsprd / gspwr.
11const XS2MB0 ulong 8650816
12const XS2MB1 ulong 8650820
13const XS2EMC ulong 8653504
14const XS2EMD ulong 8653508
15const XS2QH ulong 8653824
16const XS2QT ulong 8653828
17const XGMB0 ulong 1114176
18const XGMB1 ulong 1114180
19const XGOS ulong 1114240
20const XGHWCF2 ulong 1114356
21const XGQH ulong 1117184
22const XGCPUCT ulong 1119112
23note AINCW 1<<24, busy 0xc001cafe, lockdown 1<<13, active 1<<7, a wait that never ends 0xFFFFFFFF
24const XAINCW ulong 16777216
25const XBUSY ulong 3221342974
26const XLOCK ulong 8192
27const XACT ulong 128
28const XM32 ulong 4294967295
29const NOEND ulong 4294967295
30const LOGMAX ulong 1024
31note config (struct ck_gspsim_cfg), set by the caller before siminit: scfg
32note 0 busy_reads, 1 cmd_reads, 2 mask_reads, 3 args_reads, 4 lockdown_reads, 5 fmc_error, 6 riscv_dead,
33note 7 emem_no_inc, 8 fmc_args_pa, 9 hwcfg2_zero_reads
34global scfg ulong 10
35global semem ulong 256
36note runtime PM state of the simulated device, set by the caller: 0 active, 1 suspended (D3).
37note siminit leaves it alone. Any access while suspended counts as a violation.
38global spm ulong 1
39note Test-only selected packet family; zero preserves GB10B independent oracle cases.
40global sprof ulong 1
41fn simpmok to bool
42ret eq get spm 0 0
43end
44note state words: ss[i]
45const SEMEMC ulong 0
46const SQHEAD ulong 1
47const SQTAIL ulong 2
48const SS2MB0 ulong 3
49const SS2MB1 ulong 4
50const SGMB0 ulong 5
51const SGMB1 ulong 6
52const SHWCFG2 ulong 7
53const SOS ulong 8
54const SCPUCTL ulong 9
55const SGQHW ulong 10
56note phase: 0 idle, 1 command posted, 2 handled (mask), 3 FMC running (lockdown), 4 released, 9 rejected
57const SPHASE ulong 11
58const SLEFT ulong 12
59const SZLEFT ulong 13
60const SPKTOK ulong 14
61const SOSPH ulong 15
62const SNLOG ulong 16
63const SVIOL ulong 17
64global ss ulong 18
65global slogo ulong 1024
66global slogv ulong 1024
67global slogw uchar 1024
68fn sg i ulong to ulong
69ret get ss i
70end
71fn sp i ulong v ulong to void
72put ss i v
73end
74fn sviol to void
75sp SVIOL add sg SVIOL 1
76end
77note a countdown word: 0 stays (the caller acts on 0), NOEND stays, anything else drops by one
78fn sdec i ulong to void
79l = sg i
80if and ne l 0 ne l NOEND
81sp i sub l 1
82end
83end
84fn slog off ulong v ulong w uchar to void
85n = sg SNLOG
86if lt n LOGMAX
87put slogo n off
88put slogv n v
89put slogw n w
90end
91sp SNLOG add n 1
92end
93fn siminit to void
94for i ulong 18
95sp i 0
96end
97for j ulong 256
98put semem j 0
99end
100note an old message in the channel: HEAD != TAIL until busy_reads HEAD reads have passed
101if ne get scfg 0 0
102sp SQHEAD 0
103sp SQTAIL 16
104end
105note SIM-CHOICE: target locked to SEC2, low byte 0xA7 (0xBADF41A7); idle SEC2 MAILBOX0 0
106sp SHWCFG2 3135193511
107sp SS2MB0 0
108sp SLEFT get scfg 0
109end
110note SEC2 checks the GB10B HAL constant MCTP dword 1, NVDM 0x1410DE7E, payload version 1, size 860,
111note TAIL 864. Anything else (SIM-CHOICE): consumed, the target mask is never released.
112fn simpkt to bool
113if eq get sprof 0 2
114a = and eq sg SQTAIL 864 eq get semem 0 3221225472
115b = and eq get semem 1 336649854 eq and get semem 2 65535 2
116ret and and a b eq shr get semem 2 16 860
117end
118a = and eq sg SQTAIL 864 eq get semem 0 1
119b = and eq get semem 1 336649854 eq and get semem 2 65535 1
120ret and and a b eq shr get semem 2 16 860
121end
122fn srqh to ulong
123if and eq sg SPHASE 0 ne sg SQHEAD sg SQTAIL
124if eq sg SLEFT 0
125sp SQHEAD sg SQTAIL
126else
127sdec SLEFT
128end
129end
130ret sg SQHEAD
131end
132fn srmb0 to ulong
133if eq sg SPHASE 1
134if eq sg SLEFT 0
135sp SS2MB0 0
136sp SQHEAD sg SQTAIL
137if ne sg SPKTOK 0
138sp SPHASE 2
139sp SLEFT get scfg 2
140sp SZLEFT get scfg 9
141else
142sp SPHASE 9
143end
144else
145sdec SLEFT
146end
147end
148ret sg SS2MB0
149end
150fn srfmc to void
151if eq sg SLEFT 0
152if ne get scfg 5 0
153sp SGMB0 get scfg 5
154else
155sp SHWCFG2 and sg SHWCFG2 not XLOCK
156sp SPHASE 4
157if eq get scfg 6 0
158sp SCPUCTL XACT
159end
160end
161else
162sdec SLEFT
163end
164end
165fn srhw to ulong
166ph = sg SPHASE
167if and eq ph 2 ne sg SZLEFT 0
168sdec SZLEFT
169ret 0
170end
171if eq ph 2
172if eq sg SLEFT 0
173sp SPHASE 3
174note SIM-CHOICE: other HWCFG2 bits 0x5, so HWCFG2 = 0x2005
175sp SHWCFG2 or XLOCK 5
176pa = get scfg 8
177sp SGMB0 and pa XM32
178sp SGMB1 shr pa 32
179sp SLEFT get scfg 4
180else
181sdec SLEFT
182end
183else
184if and eq ph 3 ne sg SGMB0 and get scfg 8 XM32
185srfmc
186end
187end
188ret sg SHWCFG2
189end
190fn srgmb0 to ulong
191if and eq sg SPHASE 3 eq sg SGMB0 and get scfg 8 XM32
192a = get scfg 3
193if ne a NOEND
194if eq a 0
195sp SGMB0 0
196sp SGMB1 0
197else
198put scfg 3 sub a 1
199end
200end
201end
202ret sg SGMB0
203end
204fn simrd off ulong to ulong
205if ne get spm 0 0
206sviol
207end
208v = ulong 0
209if eq off XS2QH
210v = srqh
211else
212if eq off XS2QT
213v = sg SQTAIL
214else
215if eq off XS2EMC
216v = sg SEMEMC
217else
218if eq off XS2EMD
219e = sg SEMEMC
220v = get semem and add mul and shr e 8 255 64 and shr e 2 63 255
221else
222if eq off XS2MB0
223v = srmb0
224else
225if eq off XS2MB1
226v = sg SS2MB1
227else
228if eq off XGHWCF2
229v = srhw
230else
231if eq off XGMB0
232v = srgmb0
233else
234if eq off XGMB1
235v = sg SGMB1
236else
237if eq off XGOS
238v = sg SOS
239else
240if eq off XGCPUCT
241v = sg SCPUCTL
242else
243sviol
244end
245end
246end
247end
248end
249end
250end
251end
252end
253end
254end
255slog off v 0
256ret v
257end
258fn swememd val ulong to void
259e = sg SEMEMC
260dw = add mul and shr e 8 255 64 and shr e 2 63
261if or or eq and e XAINCW 0 ge dw 256 ne sg SPHASE 0
262sviol
263ret
264end
265put semem dw val
266if eq get scfg 7 0
267dw = add dw 1
268note EMEMC keeps all but bits 2..15 (mask ~0xFFFC = 0xFFFF0003), then block << 8 | offset << 2
269sp SEMEMC or or and e 4294901763 shl and div dw 64 255 8 shl rem dw 64 2
270end
271end
272fn swqh val ulong to void
273ph = sg SPHASE
274note the doorbell: TAIL must already point at the last dword of a message starting at 0
275if or or ne ph 0 ne val 0 eq sg SQTAIL sg SQHEAD
276sviol
277end
278sp SQHEAD val
279if eq ph 0
280if simpkt
281sp SPKTOK 1
282else
283sp SPKTOK 0
284end
285sp SPHASE 1
286sp SS2MB0 XBUSY
287sp SLEFT get scfg 1
288end
289end
290fn simwr off ulong val ulong to void
291if ne get spm 0 0
292sviol
293end
294slog off val 1
295if eq off XS2EMC
296sp SEMEMC val
297ret
298end
299if eq off XS2EMD
300swememd val
301ret
302end
303if eq off XS2QT
304note the driver writes only into an empty channel
305if or ne sg SPHASE 0 ne sg SQHEAD sg SQTAIL
306sviol
307end
308sp SQTAIL val
309ret
310end
311if eq off XS2QH
312swqh val
313ret
314end
315if eq off XGOS
316sp SOS val
317sp SOSPH sg SPHASE
318note FALCON_OS before lockdown release
319if ne sg SPHASE 4
320sviol
321end
322ret
323end
324if eq off XGQH
325sp SGQHW add sg SGQHW 1
326if ne val 0
327sviol
328end
329ret
330end
331sviol
332end