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

292 lines · 8017 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 ememdw c ulong to ulong
110ret add mul and shr c 8 255 DWBLK and shr c 2 63
111end
112fn maskrel h ulong to bool
113if eq h 0
114ret false
115end
116ret ne and h PRIVMSK PRIVLCK
117end
118fn gsppm to bool
119if eq get gspmode 0 0
120ret simpmok
121end
122fd = fopen gpmp 0 get gpmn 0 524288 0
123if lt fd 0
124ret false
125end
126n = read int fd gpmb ulong 0 16
127r = fclose int fd
128if ne n long len pmact
129ret false
130end
131for i ulong len pmact
132if ne get gpmb i get pmact i
133ret false
134end
135end
136ret true
137end
138note step 8 condition: MAILBOX0, MAILBOX1 only when MAILBOX0 is the argument address, then HWCFG2
139fn lockdone to bool
140m0 = gsprd GMB0
141put gout 9 m0
142pa = get gin 1
143if ne m0 0
144if eq m0 and pa M32
145m1 = gsprd GMB1
146put gout 10 m1
147if eq m1 shr pa 32
148ret false
149end
150end
151end
152h = gsprd GHWCFG2
153put gout 8 h
154ret or eq and h LOCKDN 0 ne m0 0
155end
156note one check of wait k (0 step 1, 1 step 6, 2 step 7, 3 step 8): true when it is over
157fn pollonce k ulong to bool
158if eq k 0
159hd = gsprd S2QH
160ret eq hd gsprd S2QT
161end
162if eq k 1
163mb = gsprd S2MB0
164put gout 6 mb
165ret ne mb CMDBUSY
166end
167if eq k 2
168hw = gsprd GHWCFG2
169put gout 8 hw
170ret maskrel hw
171end
172ret lockdone
173end
174note wait k with budget gin 3+k (a uint32): checks, then budget, then pause, as the C loop; the polls
175note used go to gout k. Inner loops stop themselves at 999998 passes, so no loop reaches its bound.
176fn pollstep k ulong to bool
177b = get gin add 3 k
178n = ulong 0
179ok = false
180stop = false
181while not stop bound 4400
182c = ulong 0
183while true bound 999999
184if pollonce k
185ok = true
186stop = true
187break
188end
189if ge n b
190stop = true
191break
192end
193gsppause
194n = add n 1
195c = add c 1
196if eq c 999998
197break
198end
199end
200end
201put gout k n
202ret ok
203end
204note step 3: whole dwords little-endian, then a short tail zero-padded
205fn ememput ln ulong to void
206i = ulong 0
207while le add i 4 ln bound 300
208v = or ulong get gpkt i shl ulong get gpkt add i 1 8
209v = or v or shl ulong get gpkt add i 2 16 shl ulong get gpkt add i 3 24
210gspwr S2EMD v
211i = add i 4
212end
213if lt i ln
214t = ulong 0
215k = ulong 0
216while lt add i k ln bound 4
217t = or t shl ulong get gpkt add i k mul 8 k
218k = add k 1
219end
220gspwr S2EMD t
221end
222end
223fn gspfail e long to long
224put gstage 0 e
225ret e
226end
227note steps 1-11; returns the stage (also in gstage). Budgets and app_version are uint32 in the C
228note struct: a value above that range is refused as an argument error.
229fn gspboot to long
230for i ulong 12
231put gout i 0
232end
233put gstage 0 EARG
234ln = get gin 0
235if or eq ln 0 gt ln CHBYTES
236ret EARG
237end
238for j ulong 5
239if gt get gin add 2 j M32
240ret EARG
241end
242end
243if not gsppm
244ret gspfail EPM
245end
246if not pollstep 0
247ret gspfail EBUSY
248end
249gspwr S2EMC AINCW
250st = ememdw gsprd S2EMC
251ememput ln
252dw = div add ln 3 4
253put gout 4 dw
254ea = gsprd S2EMC
255put gout 5 ea
256if ne and sub ememdw ea st M32 dw
257ret gspfail EEMEM
258end
259gspwr S2QT sub mul dw 4 4
260gspwr S2QH 0
261if not pollstep 1
262put gout 7 gsprd S2MB1
263ret gspfail ESEC2
264end
265ret gspfinish
266end
267note Shared GSP FMC completion, selected only after the profile-specific SEC2 exchange.
268fn gspfinish to long
269if not pollstep 2
270ret gspfail EMASK
271end
272if not pollstep 3
273put gout 10 gsprd GMB1
274ret gspfail ELOCK
275end
276m0 = gsprd GMB0
277put gout 9 m0
278if ne m0 0
279ret gspfail EFMC
280end
281gspwr GOS get gin 2
282cp = gsprd GCPUCTL
283put gout 11 cp
284if eq and cp CPUACT 0
285ret gspfail ERISCV
286end
287ret gspfail EOK
288end
289note announce new command-queue elements to GSP-RM (after the ring write and its fence)
290fn gspnotify to void
291gspwr GQH 0
292end