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