interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / gpu / driver / gsp / mmio.om

304 lines · 8185 bytes Raw Blame History
1note gsp/mmio.om: the register-level GSP start-up on GB10B in seeded Omega, a port of
2note aien-dev/aienux PR #441 native/kernel/gpu/gsp_mmio.{h,c} (ck_gsp_mmio_boot, ck_gsp_mmio_notify).
3note GB10B has no FSP: SEC2 boots the GSP-FMC (open-gpu-kernel-modules 580.173.02, kgspBootstrap_GH100,
4note kernel_gsp_gh100.c:833-995, SEC2 branch :868-872). The eleven steps:
5note 1 wait until SEC2 EMEM channel 0 is empty, QUEUE_HEAD(0) == QUEUE_TAIL(0), HEAD read first
6note (ksec2CanSendPacket_GB10B kernel_sec2_gb10b.c:343-357, _ksec2GetQueueHeadTail_GB10B :103-104)
7note 2 EMEMC(0) = offset 0 with auto-increment on write (AINCW bit 24) (:118-154, :723)
8note 3 EMEMD(0) = the packet one dword at a time, a short tail zero-padded (:166-213)
9note 4 EMEMC(0) read back: the write pointer moved by exactly the dwords written (:204-210)
10note 5 QUEUE_TAIL(0) = padded size - 4, THEN QUEUE_HEAD(0) = 0, which interrupts SEC2 (:72-84, :730)
11note 6 wait until SEC2 MAILBOX0 no longer reads 0xc001cafe (:285-311, :640)
12note 7 wait until GSP HWCFG2 is non-zero and not 0xBADF41xx (target mask released) (:264-283, :367-379)
13note 8 wait until HWCFG2 bit 13 (RISCV_BR_PRIV_LOCKDOWN) is clear or GSP MAILBOX0 is non-zero; MAILBOX0:1
14note equal to the FMC boot-argument address means not read yet (kernel_gsp_gh100.c:492-533)
15note 9 GSP MAILBOX0 non-zero after that is an FMC error code (:940-946)
16note 10 GSP FALCON_OS = GspRmBoot appVersion (:954-956)
17note 11 RISC-V CPUCTL bit 7 ACTIVE_STAT must read ACTIVE (kernel_falcon_ga102.c:47-55)
18note Notify (kgspSetCmdQueueHead_TU102, kernel_gsp_tu102.c:343-355): GSP QUEUE_HEAD(0) = 0.
19note Library unit: no main. Build after it gsp/sim.om (the mode 0 device) and a driver with main.
20note Register seam: every device access is gsprd / gspwr. gspmode 0 = the in-.om simulator (simrd/simwr),
21note gspmode 1 = BAR0 through a vfiomapw handle in gspbar (mapget/mapset, 4 bytes). Mode 1 runs only in a
22note hardware window; host tests never set it. Nothing here has run on the chip.
23note BAR0 offsets, GB10B (dev_sec_pri.h:27-56, dev_gsp.h:27, dev_falcon_v4.h, dev_riscv_pri.h:58,68),
24note written in decimal because OM-1 has no hex literal: 0x840040 0x840044 0x840ac0 0x840ac4 0x840c00
25note 0x840c04 0x110040 0x110044 0x110080 0x1100f4 0x110c00 0x111388.
26const S2MB0 ulong 8650816
27const S2MB1 ulong 8650820
28const S2EMC ulong 8653504
29const S2EMD ulong 8653508
30const S2QH ulong 8653824
31const S2QT ulong 8653828
32const GMB0 ulong 1114176
33const GMB1 ulong 1114180
34const GOS ulong 1114240
35const GHWCFG2 ulong 1114356
36const GQH ulong 1117184
37const GCPUCTL ulong 1119112
38note EMEMC AINCW 1<<24; 64 dwords per EMEM block; channel 1024 bytes; SEC2 busy 0xc001cafe;
39note target locked 0xBADF4100 under mask 0xFFFFFF00; HWCFG2 lockdown 1<<13; CPUCTL active 1<<7.
40const AINCW ulong 16777216
41const DWBLK ulong 64
42const CHBYTES ulong 1024
43const CMDBUSY ulong 3221342974
44const PRIVLCK ulong 3135193344
45const PRIVMSK ulong 4294967040
46const LOCKDN ulong 8192
47const CPUACT ulong 128
48const M32 ulong 4294967295
49note stage codes (enum ck_gsp_mmio_err)
50const EOK long 0
51const EARG long -1
52const EBUSY long -2
53const EEMEM long -3
54const ESEC2 long -4
55const EMASK long -5
56const ELOCK long -6
57const EFMC long -7
58const ERISCV long -8
59note -9: the device is not runtime-active (arm64: a BAR read of a D3 device is an external abort);
60note checked before the first register access, so a refused start makes no access at all
61const EPM long -9
62note runtime PM: mode 0 asks the simulator (spm 0 = active); mode 1 reads the sysfs file whose path
63note the caller puts in gpmp[0..gpmn) (.../power/runtime_status) and requires exactly "active\n"
64text pmact "active\n"
65global gpmp uchar 128
66global gpmn ulong 1
67global gpmb uchar 16
68note seam state: mode, BAR0 handle (mode 1), pause between polls in nanoseconds (mode 1)
69global gspmode ulong 1
70global gspbar long 1
71global gsppns long 1
72note input (struct ck_gsp_mmio_in): the packet bytes, then gin 0 len, 1 fmc_args_pa, 2 app_version,
73note 3..6 poll budgets of steps 1, 6, 7, 8 (0 = check once)
74global gpkt uchar 1024
75global gin ulong 7
76note output (struct ck_gsp_mmio_out): gstage, then gout 0..3 polls of steps 1, 6, 7, 8, 4 dwords,
77note 5 ememc_after, 6 sec2_mb0, 7 sec2_mb1, 8 hwcfg2, 9 gsp_mb0, 10 gsp_mb1, 11 cpuctl
78global gstage long 1
79global gout ulong 12
80fn gsprd off ulong to ulong
81m = get gspmode 0
82if eq m 0
83ret simrd off
84end
85if ne m 1
86trap 9
87end
88ret mapget get gspbar 0 off 4
89end
90fn gspwr off ulong v ulong to void
91m = get gspmode 0
92if eq m 0
93simwr off v
94ret
95end
96if ne m 1
97trap 9
98end
99r = mapset get gspbar 0 off 4 v
100if ne r 0
101trap 9
102end
103end
104fn gsppause to void
105if eq get gspmode 0 1
106r = sleepns get gsppns 0
107end
108end
109fn gspdelay us ulong to long
110if eq get gspmode 0 1
111ret sleepns long mul us 1000
112end
113ret 0
114end
115fn ememdw c ulong to ulong
116ret add mul and shr c 8 255 DWBLK and shr c 2 63
117end
118fn maskrel h ulong to bool
119if eq h 0
120ret false
121end
122ret ne and h PRIVMSK PRIVLCK
123end
124fn gsppm to bool
125if eq get gspmode 0 0
126ret simpmok
127end
128fd = fopen gpmp 0 get gpmn 0 524288 0
129if lt fd 0
130ret false
131end
132n = read int fd gpmb ulong 0 16
133r = fclose int fd
134if ne n long len pmact
135ret false
136end
137for i ulong len pmact
138if ne get gpmb i get pmact i
139ret false
140end
141end
142ret true
143end
144note step 8 condition: MAILBOX0, MAILBOX1 only when MAILBOX0 is the argument address, then HWCFG2
145fn lockdone to bool
146m0 = gsprd GMB0
147put gout 9 m0
148pa = get gin 1
149if ne m0 0
150if eq m0 and pa M32
151m1 = gsprd GMB1
152put gout 10 m1
153if eq m1 shr pa 32
154ret false
155end
156end
157end
158h = gsprd GHWCFG2
159put gout 8 h
160if not maskrel h
161ret false
162end
163if eq and m0 PRIVMSK PRIVLCK
164ret false
165end
166ret or eq and h LOCKDN 0 ne m0 0
167end
168note one check of wait k (0 step 1, 1 step 6, 2 step 7, 3 step 8): true when it is over
169fn pollonce k ulong to bool
170if eq k 0
171hd = gsprd S2QH
172ret eq hd gsprd S2QT
173end
174if eq k 1
175mb = gsprd S2MB0
176put gout 6 mb
177ret ne mb CMDBUSY
178end
179if eq k 2
180hw = gsprd GHWCFG2
181put gout 8 hw
182ret maskrel hw
183end
184ret lockdone
185end
186note wait k with budget gin 3+k (a uint32): checks, then budget, then pause, as the C loop; the polls
187note used go to gout k. Inner loops stop themselves at 999998 passes, so no loop reaches its bound.
188fn pollstep k ulong to bool
189b = get gin add 3 k
190n = ulong 0
191ok = false
192stop = false
193while not stop bound 4400
194c = ulong 0
195while true bound 999999
196if pollonce k
197ok = true
198stop = true
199break
200end
201if ge n b
202stop = true
203break
204end
205gsppause
206n = add n 1
207c = add c 1
208if eq c 999998
209break
210end
211end
212end
213put gout k n
214ret ok
215end
216note step 3: whole dwords little-endian, then a short tail zero-padded
217fn ememput ln ulong to void
218i = ulong 0
219while le add i 4 ln bound 300
220v = or ulong get gpkt i shl ulong get gpkt add i 1 8
221v = or v or shl ulong get gpkt add i 2 16 shl ulong get gpkt add i 3 24
222gspwr S2EMD v
223i = add i 4
224end
225if lt i ln
226t = ulong 0
227k = ulong 0
228while lt add i k ln bound 4
229t = or t shl ulong get gpkt add i k mul 8 k
230k = add k 1
231end
232gspwr S2EMD t
233end
234end
235fn gspfail e long to long
236put gstage 0 e
237ret e
238end
239note steps 1-11; returns the stage (also in gstage). Budgets and app_version are uint32 in the C
240note struct: a value above that range is refused as an argument error.
241fn gspboot to long
242for i ulong 12
243put gout i 0
244end
245put gstage 0 EARG
246ln = get gin 0
247if or eq ln 0 gt ln CHBYTES
248ret EARG
249end
250for j ulong 5
251if gt get gin add 2 j M32
252ret EARG
253end
254end
255if not gsppm
256ret gspfail EPM
257end
258if not pollstep 0
259ret gspfail EBUSY
260end
261gspwr S2EMC AINCW
262st = ememdw gsprd S2EMC
263ememput ln
264dw = div add ln 3 4
265put gout 4 dw
266ea = gsprd S2EMC
267put gout 5 ea
268if ne and sub ememdw ea st M32 dw
269ret gspfail EEMEM
270end
271gspwr S2QT sub mul dw 4 4
272gspwr S2QH 0
273if not pollstep 1
274put gout 7 gsprd S2MB1
275ret gspfail ESEC2
276end
277ret gspfinish
278end
279note Shared GSP FMC completion, selected only after the profile-specific SEC2 exchange.
280fn gspfinish to long
281if not pollstep 2
282ret gspfail EMASK
283end
284if not pollstep 3
285put gout 10 gsprd GMB1
286ret gspfail ELOCK
287end
288m0 = gsprd GMB0
289put gout 9 m0
290if ne m0 0
291ret gspfail EFMC
292end
293gspwr GOS get gin 2
294cp = gsprd GCPUCTL
295put gout 11 cp
296if eq and cp CPUACT 0
297ret gspfail ERISCV
298end
299ret gspfail EOK
300end
301note announce new command-queue elements to GSP-RM (after the ring write and its fence)
302fn gspnotify to void
303gspwr GQH 0
304end