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

326 lines · 8584 bytes Raw Blame History
1note chan/chan.om: GPFIFO compute channel (ring, USERD, instance block, doorbell), ported from aienux
2note PR #441 native/kernel/gpu/gpu_chan.c and gpu_chan.h (branch pr441 @ c5bb3a4b). Library unit: no main.
3note Prefix ch / CH. Needs chan/gmmu.om and chan/mem.om before it, and chan/sim.om (mode 0 ops).
4note
5note A channel is a slot 0..3 (CHSLOTS); its buffers are chan/mem.om slots. The CPU writes the ring,
6note USERD GPPut and the instance block through mmrd/mmwr (array or owned mapping); doorbell mmregwr.
7note
8note Channel ops (C: a function-pointer table): chbindop / chdisop / chidlop. mmmode 0 calls the
9note simulator (chan/sim.om gsbind / gsdisable / gsidle). On GB10 the channel is allocated, scheduled
10note and torn down by GSP-RM (RM_ALLOC BLACKWELL_CHANNEL_GPFIFO_A, encoded by chan/params.om), not by
11note register writes, so any other mode traps 9 here: the hardware ops are the GSP RPC path.
12note
13note API (state in globals; a global is never an argument):
14note chinit -> void all slots closed and empty
15note chcreate c chid rl ent -> long ck_gpu_chan_create (chid, rl, ent uint)
16note chsubmit c pb off n -> long ck_gpu_chan_submit (pb a mem slot, off and n uint)
17note chretire c upto -> void ck_gpu_chan_retire (upto uint)
18note chteardown c budget nx -> long ck_gpu_chan_teardown; extras: the first nx slots of chx
19note (GMNONE entries are skipped, as C null pointers)
20note chtoken rl chid -> uint ck_gpu_submit_token
21note chrluserd pa -> long ck_gpu_rl_userd, the two words in chrlo
22note chgpent va n -> ulong ck_gpu_gp_entry; chmthd: ck_gpu_mthd
23note per slot: chchid chrl chtok chent chpdb chgpva chupa chipa chrl0 chrl1 (descriptor), chgp chud
24note chin (ring, USERD, instance mem slots), chput chret (uint, wrap as uint32), chopen
25note codes (enum ck_gpu_chan_status): 0 CHOK, 1 CHEINVAL, 2 CHENOMEM, 3 CHESTATE, 4 CHEFULL, 5 CHEBIND,
26note 6 CHETIME
27const CHOK long 0
28const CHEINVAL long 1
29const CHENOMEM long 2
30const CHESTATE long 3
31const CHEFULL long 4
32const CHEBIND long 5
33const CHETIME long 6
34const CHSLOTS ulong 4
35note CHID_MAX 0xFFF, RUNLIST_INVALID 0x7F, GP length max 0x1FFFFF, GP VA limit 1<<40
36const CHIDMAX uint 4095
37const CHRLINV uint 127
38const CHLENMX uint 2097151
39const CHVALIM ulong 1099511627776
40note USERD 512 bytes, GPPut at 0x8C; instance block 4096 bytes, page directory at word 128 (byte 512)
41const CHUDSZ ulong 512
42const CHGPPUT ulong 140
43const CHINSZ ulong 4096
44const CHPDBW ulong 512
45note RAMIN PDB: target sysmem coherent 2, BIG_PAGE_SIZE_64K bit 11 (2048); low address mask 0xFFFFF000
46const CHTSYS uint 2
47const CHBIG64 uint 2048
48const CHLOM uint 4294963200
49note doorbell VF base 0xB80000 + 0x30090 = 0xBB0090
50const CHDBELL ulong 12255376
51note GP entry: va & ~3 (mask 2^64-4), LENGTH at bit 42, LEVEL bit 41 set as physics nvrm_gp_entry does
52const CHVAM ulong 18446744073709551612
53const CHGPB41 ulong 2199023255552
54note method header (nvrm_mthd, INC_METHOD): 2 << 28
55const CHNINC uint 536870912
56global chchid uint 4
57global chrl uint 4
58global chtok uint 4
59global chent uint 4
60global chpdb ulong 4
61global chgpva ulong 4
62global chupa ulong 4
63global chipa ulong 4
64global chrl0 uint 4
65global chrl1 uint 4
66global chgp ulong 4
67global chud ulong 4
68global chin ulong 4
69global chput uint 4
70global chret uint 4
71global chopen uchar 4
72global chepoch ulong 4
73global chrlo uint 2
74global chx ulong 8
75fn chtoken rl uint chid uint to uint
76ret or shl and rl CHRLINV 16 and chid CHIDMAX
77end
78fn chrluserd pa ulong to long
79if or ne and pa 255 0 ge pa MMPALIM
80ret CHEINVAL
81end
82put chrlo 0 and uint and pa 4294967295 4294967040
83put chrlo 1 and uint and shr pa 32 4294967295 1048575
84ret CHOK
85end
86fn chgpent va ulong n uint to ulong
87ret or or and va CHVAM shl and ulong n 2097151 42 CHGPB41
88end
89fn chmthd subc uint mthd uint count uint to uint
90ret or or or CHNINC shl count 16 shl subc 13 shr mthd 2
91end
92fn chbindop c ulong to long
93if eq get mmwkind 0 1
94note Hardware channel RPC is absent here. Refuse before publication; never walk unrelated mmwin.
95ret -95
96end
97if ne get mmmode 0 0
98trap 9
99end
100ret gsbind get chchid c get chtok c get chent c get chgpva c get chupa c get chipa c
101end
102fn chdisop chid uint to long
103if ne get mmmode 0 0
104trap 9
105end
106ret gsdisable chid
107end
108fn chidlop chid uint to long
109if ne get mmmode 0 0
110trap 9
111end
112ret gsidle chid
113end
114fn chinit to void
115if and eq get mmwkind 0 1 not mmwmutable
116trap 9
117end
118for c ulong CHSLOTS
119put chopen c 0
120put chgp c GMNONE
121put chud c GMNONE
122put chin c GMNONE
123put chput c 0
124put chret c 0
125end
126end
127note create's error path: free whichever of the three buffers exist, ENOMEM
128fn chnomem c ulong to long
129if ne get chin c GMNONE
130r = gmfree get chin c
131end
132if ne get chud c GMNONE
133r = gmfree get chud c
134end
135if ne get chgp c GMNONE
136r = gmfree get chgp c
137end
138put chgp c GMNONE
139put chud c GMNONE
140put chin c GMNONE
141ret CHENOMEM
142end
143note Separate backing preparation from RPC allocation/scheduling; state2 cannot submit.
144fn chcreate c ulong chid uint rl uint ent uint to long
145r = chprep c chid rl ent
146if ne r CHOK
147ret r
148end
149if ne chbindop c 0
150r = gmfree get chin c
151r = gmfree get chud c
152r = gmfree get chgp c
153put chopen c 0
154ret CHEBIND
155end
156put chopen c 1
157ret CHOK
158end
159fn chprep c ulong chid uint rl uint ent uint to long
160if or not mmwmutable ne get gmepoch 0 get mmwgen 0
161ret CHESTATE
162end
163if ge c CHSLOTS
164ret CHEINVAL
165end
166if or gt chid CHIDMAX ge rl CHRLINV
167ret CHEINVAL
168end
169if or or lt ent 2 gt ent 65536 ne and ent sub ent 1 0
170ret CHEINVAL
171end
172put chopen c 0
173put chepoch c get mmwgen 0
174put chput c 0
175put chret c 0
176put chgp c GMNONE
177put chud c GMNONE
178put chin c GMNONE
179if ne gmalloc mul ulong ent 8 1 GMGPURO GMOK
180ret chnomem c
181end
182put chgp c get gmout 0
183if ne gmalloc CHUDSZ 1 GMHPOLL GMOK
184ret chnomem c
185end
186put chud c get gmout 0
187if ne gmalloc CHINSZ 1 0 GMOK
188ret chnomem c
189end
190put chin c get gmout 0
191ret chfill c chid rl ent
192end
193note zero gpfifo, USERD and instance block; write the RAMIN page-directory words
194fn chzero c ulong to ulong
195g = get chgp c
196u = get chud c
197n = get chin c
198mmzero get gmbpa g get gmbsz g
199mmzero get gmbpa u get gmbsz u
200mmzero get gmbpa n get gmbsz n
201pdb = get mmroot 0
202ip = get gmbpa n
203mmwr32 add ip CHPDBW ulong or or and uint and pdb 4294967295 CHLOM CHBIG64 CHTSYS
204mmwr32 add ip add CHPDBW 4 shr pdb 32
205ret pdb
206end
207note fill the descriptor, the runlist entry, then bind through the channel ops
208fn chfill c ulong chid uint rl uint ent uint to long
209pdb = chzero c
210put chchid c chid
211put chrl c rl
212put chtok c chtoken rl chid
213put chent c ent
214put chpdb c pdb
215put chgpva c get gmbva get chgp c
216put chupa c get gmbpa get chud c
217put chipa c get gmbpa get chin c
218if ne chrluserd get gmbpa get chud c CHOK
219ret chnomem c
220end
221put chrl0 c get chrlo 0
222put chrl1 c get chrlo 1
223put chopen c 2
224ret CHOK
225end
226fn chsubmit c ulong pb ulong off uint n uint to long
227if or ge c CHSLOTS ne get chopen c 1
228ret CHESTATE
229end
230if ne get chepoch c get mmwgen 0
231ret CHESTATE
232end
233if not gmlive pb
234ret CHEINVAL
235end
236if or or ne and off 3 0 eq n 0 gt n CHLENMX
237ret CHEINVAL
238end
239span = mul ulong n 4
240sz = get gmbsz pb
241if or gt ulong off sz gt span sub sz ulong off
242ret CHEINVAL
243end
244va = add get gmbva pb ulong off
245if or ge va CHVALIM gt span sub CHVALIM va
246ret CHEINVAL
247end
248ret chpush c va n
249end
250note ring full check, GP entry at put % entries, GPPut in USERD, doorbell
251fn chpush c ulong va ulong n uint to long
252p = get chput c
253e = get chent c
254if ge sub p get chret c sub e 1
255ret CHEFULL
256end
257mmwr64 add get gmbpa get chgp c mul ulong rem p e 8 chgpent va n
258p = add p 1
259put chput c p
260mmwr32 add get gmbpa get chud c CHGPPUT ulong rem p e
261mmregwr CHDBELL ulong get chtok c
262ret CHOK
263end
264fn chretire c ulong upto uint to void
265if ge c CHSLOTS
266ret
267end
268if ne get chepoch c get mmwgen 0
269ret
270end
271r = get chret c
272if le sub upto r sub get chput c r
273put chret c upto
274end
275end
276fn chteardown c ulong budget uint nx ulong to long
277if or ge c CHSLOTS eq get chopen c 0
278ret CHESTATE
279end
280if ne get chepoch c get mmwgen 0
281ret CHESTATE
282end
283put chopen c 0
284chid = get chchid c
285d = chdisop chid
286idle = false
287for i uint budget
288if and eq d 0 eq chidlop chid 1
289idle = true
290break
291end
292end
293if and not idle eq get mmwkind 0 1
294r = mmwquar get mmwgen 0
295end
296rc = CHOK
297for k ulong 3
298b = get chin c
299if eq k 1
300b = get chud c
301end
302if eq k 2
303b = get chgp c
304end
305if not idle
306r = gmquar b
307else
308if ne gmfree b GMOK
309rc = CHETIME
310end
311end
312end
313if not idle
314for i ulong nx
315b = get chx i
316if gmlive b
317r = gmquar b
318end
319end
320rc = CHETIME
321end
322put chgp c GMNONE
323put chud c GMNONE
324put chin c GMNONE
325ret rc
326end