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-mv/blob/main/gpu/driver/gsp/compute.om # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / gpu / driver / gsp / compute.om` 758 lines ยท 17607 bytes Raw Blame History 1 note gsp/compute.om: GB20B compute bring-up RPC builders, canonical PACKED_REGISTRY_TABLE encoder, 2 note BLACKWELL_COMPUTE_B (0xcec0) / BLACKWELL_CHANNEL_GPFIFO_B (0xca6f) / usermode alloc & control 3 note helpers, GB20B bit-30 work-submit token encoder, INC_METHOD pushbuffer builder, GP entry 4 note encoder (LEVEL bit 41), USERD GPPut (+0x8C) update and BAR0/usermode doorbell kick helpers. 5 note Source of record: NVIDIA open-gpu-kernel-modules 580.173.02 (MIT), docs/gpu/GSP_RPC_REGISTRY_REFERENCE.md, 6 note and gb20b-gsp-boot.md. Pure seeded OM-1 library unit, no fn main. Prefix cb / CB. 7 note Compose after: chan/gmmu.om, chan/mem.om, chan/chan.om, gsp/rpc.om, chan/params.om, gsp/boot.om. 8 const CBOK long 0 9 const CBEINVAL long -1 10 const CBERANGE long -2 11 const CBEFULL long -3 12 const CBEALIGN long -4 13 const CBESTATE long -5 14 const CBU32MAX ulong `4294967295` 15 note RPC function IDs: SET_GUEST_SYSTEM_INFO 1, GET_GSP_STATIC_INFO 65, SET_REGISTRY 73, 16 note GSP_RM_CONTROL 76, GSP_RM_ALLOC 103 17 const CBRPCGUEST ulong 1 18 const CBRPCSTAT ulong 65 19 const CBRPCREG ulong 73 20 const CBRPCCTRL ulong 76 21 const CBRPCALLOC ulong 103 22 note SET_GUEST_SYSTEM_INFO v03_00: 6*4 + 3*256 = 792 bytes 23 const CBSZGUEST ulong 792 24 const CBGSTRMAX ulong 256 25 note PACKED_REGISTRY_TABLE bounds matching arena.om arregok and boot.om breg 26 const CBREGMIN ulong 8 27 const CBREGMAX ulong 65456 28 const CBRMAX ulong 32 29 const CBRDWORD uchar 1 30 const CBRBIN uchar 2 31 const CBRSTR uchar 3 32 note GB20B bring-up registry key selectors 33 const CBKFW ulong 0 34 const CBKLOG ulong 1 35 const CBKRC ulong 2 36 const CBKDPM ulong 3 37 const CBKPW2 ulong 4 38 const CBKDISP ulong 5 39 note RM class IDs: BLACKWELL_CHANNEL_GPFIFO_A 0xc96f, BLACKWELL_CHANNEL_GPFIFO_B 0xca6f, 40 note BLACKWELL_COMPUTE_B 0xcec0, VOLTA_USERMODE_A 0xc361, HOPPER_USERMODE_A 0xc661 41 const CBCGPFA ulong 51567 42 const CBCGPFB ulong 51823 43 const CBCCMP ulong 52928 44 const CBCUMVA ulong 50017 45 const CBCUMHA ulong 50785 46 note RM control IDs: NVA06C_CTRL_CMD_GPFIFO_SCHEDULE 0xa06c0101, 47 note NVC36F_CTRL_CMD_GPFIFO_GET_WORK_SUBMIT_TOKEN 0xc36f0108 48 const CBCMSCH ulong `2691432705` 49 const CBCMWST ulong `3278831880` 50 note GB20B work-submit token bit 30 RUNLIST_DOORBELL_ENABLE (0x40000000, active-high), 51 note runlist <= 127 (0x7F), chId <= 4095 (0xFFF), BAR0 doorbell 0x00BB0090, usermode +0x90, USERD GPPut +0x8C 52 const CBDBEN uint `1073741824` 53 const CBRLMAX uint 127 54 const CBCHMAX uint 4095 55 const CBDBBAR0 ulong `12255376` 56 const CBDBUM ulong 144 57 const CBGPPUT ulong 140 58 note Pushbuffer INC_METHOD (2<<28), compute setup 0x0184 + 18-word bare-metal windows, 59 note PCAS 0x02b4/0x02c0, WFI 0x0110, INVALIDATE_SHADER_CACHES 0x021c, inline QMD 0x0318 (96 dwords), 60 note L2 flush 0x0028 (0x80000000), host semaphore 0x005C..0x006C (release 1 / WFI 0x100001). 61 note Bare-metal disjoint 40-bit shader windows: shared 0x70_0000_0000 (hi 112), local 0x72_0000_0000 (hi 114). 62 const CBINC uint `536870912` 63 const CBMSETUP uint 388 64 const CBMSET1 uint 584 65 const CBMSET2 uint 672 66 const CBMSHWIN uint 5492 67 const CBMSHLO uint 5496 68 const CBMSHSZ uint 5500 69 const CBMLMWIN uint 5468 70 const CBMLMLO uint 5472 71 const CBMLMSZ uint 5476 72 const CBSHWINHI uint 112 73 const CBLMWINHI uint 114 74 const CBSHSZ uint `1048575` 75 const CBMWFI uint 272 76 const CBMICACHE uint 540 77 const CBICALL uint 4113 78 const CBICDATA uint 16 79 const CBICFLUSH uint 20 80 const CBMPCASA uint 692 81 const CBMPCASB uint 704 82 const CBPCASACT uint 3 83 const CBMIQMD uint 792 84 const CBML2 uint 40 85 const CBMSEM uint 92 86 const CBQMDWDS ulong 96 87 const CBSEMREL uint 1 88 const CBSEMWFI uint `1048577` 89 const CBL2EXEC uint `2147483648` 90 const CBPBMAX ulong 16384 91 note GP entry: va & ~3, LEVEL bit 41 (1<<41), VA limit 1<<40, length max 0x1FFFFF 92 const CBVAMASK ulong `18446744073709551612` 93 const CBGPB41 ulong `2199023255552` 94 const CBVALIM ulong `1099511627776` 95 const CBLENMAX uint `2097151` 96 note Built-in GB20B bring-up registry key names (GSP_RPC_REGISTRY_REFERENCE.md 3.2) 97 text CBKEY0 "EnableGpuFirmware" 98 text CBKEY1 "RMGspLogLevel" 99 text CBKEY2 "RmLogonRC" 100 text CBKEY3 "RMEnableDynamicPowerManagement" 101 text CBKEY4 "RMPowerFeature2" 102 text CBKEY5 "RMDisableDisplay" 103 note Guest string staging buffer for SET_GUEST_SYSTEM_INFO (max 256 bytes per slot) 104 global cbstrin uchar 256 105 note PACKED_REGISTRY_TABLE staging arrays 106 global cbrcnt ulong 1 107 global cbrtyp uchar 32 108 global cbrval ulong 32 109 global cbrvlen ulong 32 110 global cbrnoff ulong 32 111 global cbrnlen ulong 32 112 global cbrnames uchar 2048 113 global cbrnpos ulong 1 114 global cbrblob uchar 4096 115 global cbrbpos ulong 1 116 global cbrkin uchar 128 117 global cbrvin uchar 512 118 note Pushbuffer (64 KiB = 16384 dwords) and inline QMD staging arrays 119 global cbpb uint 16384 120 global cbpblen ulong 1 121 global cbqmd uint 96 122 123 note Section 1: SET_GUEST_SYSTEM_INFO (RPC 1, 792 B) and GET_GSP_STATIC_INFO (RPC 65) 124 note Initialize rpc_set_guest_system_info_v03_00 (792 B) in rqpay with caller-supplied version fields. 125 fn cbguestinit ver0 ulong ver1 ulong guestos ulong to long 126 if or gt ver0 CBU32MAX or gt ver1 CBU32MAX gt guestos CBU32MAX 127 ret CBERANGE 128 end 129 rqclear CBSZGUEST 130 rqput32 4 0 ver0 131 rqput32 4 4 ver1 132 rqput32 4 20 guestos 133 ret long CBSZGUEST 134 end 135 136 note Populate one of the three 256-byte string buffers of rpc_set_guest_system_info_v03_00 from cbstrin: 137 note slot 0 = driverVersionBuffer (+24, len at +8), slot 1 = driverBranchBuffer (+280, len at +12), 138 note slot 2 = guestOsInfoBuffer (+536, len at +16). Never fabricates version strings. 139 fn cbgueststr slot ulong n ulong to long 140 if or gt slot 2 gt n CBGSTRMAX 141 ret CBERANGE 142 end 143 rqput32 4 add 8 mul slot 4 n 144 base = add 24 mul slot CBGSTRMAX 145 for i ulong CBGSTRMAX 146 put rqpay add base i 0 147 end 148 for i ulong n 149 put rqpay add base i get cbstrin i 150 end 151 ret CBOK 152 end 153 154 note Prepare zeroed request payload for GET_GSP_STATIC_INFO (RPC 65) in rqpay. 155 fn cbstaticprep n ulong to long 156 if or eq n 0 gt n CBREGMAX 157 ret CBERANGE 158 end 159 rqclear n 160 ret long n 161 end 162 163 note Read a little-endian u32 at byte offset off from GET_GSP_STATIC_INFO reply payload in rqout. 164 fn cbstaticrd32 off ulong to long 165 n = get rqlen 0 166 if or gt off n gt 4 sub n off 167 ret CBERANGE 168 end 169 ret long rqget32 3 add 80 off 170 end 171 172 note Section 2: SET_REGISTRY (RPC 73) canonical PACKED_REGISTRY_TABLE builder 173 fn cbrinit to void 174 put cbrcnt 0 0 175 put cbrnpos 0 0 176 put cbrbpos 0 0 177 end 178 179 fn cbrchkname nlen ulong to bool 180 if or eq nlen 0 gt nlen 128 181 ret false 182 end 183 for i ulong nlen 184 if eq get cbrkin i 0 185 ret false 186 end 187 end 188 ret true 189 end 190 191 fn cbradddw nlen ulong val ulong to long 192 if not cbrchkname nlen 193 ret CBEINVAL 194 end 195 if gt val CBU32MAX 196 ret CBERANGE 197 end 198 cnt = get cbrcnt 0 199 if ge cnt CBRMAX 200 ret CBEFULL 201 end 202 npos = get cbrnpos 0 203 if gt add npos nlen 2048 204 ret CBEFULL 205 end 206 for i ulong nlen 207 put cbrnames add npos i get cbrkin i 208 end 209 put cbrtyp cnt CBRDWORD 210 put cbrval cnt val 211 put cbrvlen cnt 4 212 put cbrnoff cnt npos 213 put cbrnlen cnt nlen 214 put cbrnpos 0 add npos nlen 215 put cbrcnt 0 add cnt 1 216 ret CBOK 217 end 218 219 fn cbraddblob typ uchar nlen ulong vlen ulong to long 220 if not cbrchkname nlen 221 ret CBEINVAL 222 end 223 if or eq vlen 0 gt vlen 512 224 ret CBERANGE 225 end 226 cnt = get cbrcnt 0 227 if ge cnt CBRMAX 228 ret CBEFULL 229 end 230 npos = get cbrnpos 0 231 if gt add npos nlen 2048 232 ret CBEFULL 233 end 234 bpos = get cbrbpos 0 235 if gt add bpos vlen 4096 236 ret CBEFULL 237 end 238 for i ulong nlen 239 put cbrnames add npos i get cbrkin i 240 end 241 for i ulong vlen 242 put cbrblob add bpos i get cbrvin i 243 end 244 put cbrtyp cnt typ 245 put cbrval cnt bpos 246 put cbrvlen cnt vlen 247 put cbrnoff cnt npos 248 put cbrnlen cnt nlen 249 put cbrnpos 0 add npos nlen 250 put cbrbpos 0 add bpos vlen 251 put cbrcnt 0 add cnt 1 252 ret CBOK 253 end 254 255 fn cbraddbin nlen ulong vlen ulong to long 256 ret cbraddblob CBRBIN nlen vlen 257 end 258 259 fn cbraddstr nlen ulong vlen ulong to long 260 ret cbraddblob CBRSTR nlen vlen 261 end 262 263 fn cbrloadkey kid ulong to long 264 if eq kid CBKFW 265 for i ulong len CBKEY0 266 put cbrkin i get CBKEY0 i 267 end 268 ret long len CBKEY0 269 end 270 if eq kid CBKLOG 271 for i ulong len CBKEY1 272 put cbrkin i get CBKEY1 i 273 end 274 ret long len CBKEY1 275 end 276 if eq kid CBKRC 277 for i ulong len CBKEY2 278 put cbrkin i get CBKEY2 i 279 end 280 ret long len CBKEY2 281 end 282 if eq kid CBKDPM 283 for i ulong len CBKEY3 284 put cbrkin i get CBKEY3 i 285 end 286 ret long len CBKEY3 287 end 288 if eq kid CBKPW2 289 for i ulong len CBKEY4 290 put cbrkin i get CBKEY4 i 291 end 292 ret long len CBKEY4 293 end 294 if eq kid CBKDISP 295 for i ulong len CBKEY5 296 put cbrkin i get CBKEY5 i 297 end 298 ret long len CBKEY5 299 end 300 ret CBERANGE 301 end 302 303 fn cbraddkey kid ulong val ulong to long 304 nlen = cbrloadkey kid 305 if lt nlen 0 306 ret nlen 307 end 308 ret cbradddw ulong nlen val 309 end 310 311 note Populate the 6 proposed GB20B compute bring-up registry DWORD keys. 312 fn cbrgb20b loglvl ulong nodisp ulong to long 313 if or gt loglvl 5 gt nodisp 1 314 ret CBERANGE 315 end 316 r = cbraddkey CBKFW 1 317 if lt r 0 318 ret r 319 end 320 r = cbraddkey CBKLOG loglvl 321 if lt r 0 322 ret r 323 end 324 r = cbraddkey CBKRC 1 325 if lt r 0 326 ret r 327 end 328 r = cbraddkey CBKDPM 0 329 if lt r 0 330 ret r 331 end 332 r = cbraddkey CBKPW2 0 333 if lt r 0 334 ret r 335 end 336 ret cbraddkey CBKDISP nodisp 337 end 338 339 note Serialize one staged entry i at byte cursor pos into rqpay; returns next pos or negative error. 340 fn cbrputent i ulong pos ulong to long 341 e = add 8 mul i 16 342 t = get cbrtyp i 343 nlen = get cbrnlen i 344 noff = get cbrnoff i 345 if gt add pos add nlen 1 CBREGMAX 346 ret CBEFULL 347 end 348 rqput32 4 e pos 349 put rqpay add e 4 t 350 put rqpay add e 5 0 351 put rqpay add e 6 0 352 put rqpay add e 7 0 353 for j ulong nlen 354 put rqpay add pos j get cbrnames add noff j 355 end 356 put rqpay add pos nlen 0 357 pos = add pos add nlen 1 358 if eq t CBRDWORD 359 rqput32 4 add e 8 get cbrval i 360 rqput32 4 add e 12 4 361 ret long pos 362 end 363 vlen = get cbrvlen i 364 voff = get cbrval i 365 if gt add pos vlen CBREGMAX 366 ret CBEFULL 367 end 368 rqput32 4 add e 8 pos 369 rqput32 4 add e 12 vlen 370 for j ulong vlen 371 b = get cbrblob add voff j 372 put rqpay add pos j b 373 end 374 ret long add pos vlen 375 end 376 377 note Build canonical PACKED_REGISTRY_TABLE into rqpay; returns wire byte length (0 if empty) for breg. 378 fn cbrbuild to long 379 cnt = get cbrcnt 0 380 if eq cnt 0 381 ret 0 382 end 383 pos = add 8 mul cnt 16 384 rqclear pos 385 rqput32 4 4 cnt 386 for i ulong cnt 387 next = cbrputent i pos 388 if lt next 0 389 ret next 390 end 391 pos = ulong next 392 end 393 rqput32 4 0 pos 394 ret long pos 395 end 396 397 note Section 3: Compute bring-up RM alloc (RPC 103) and RM control (RPC 76) helpers 398 note Allocate Blackwell GPFIFO channel (0xca6f for GB20B, 0xc96f for GB10B) using pain[]. 399 fn cballocch cli ulong parent ulong hchan ulong gb20b bool budget ulong to long 400 r = pachan 401 if lt r 0 402 ret r 403 end 404 ret brmalloc cli parent hchan pacgpcls gb20b budget 405 end 406 407 note Allocate BLACKWELL_COMPUTE_B (0xcec0 / 52928) with 0-byte params under hchan. 408 fn cballoccmp cli ulong hchan ulong hcmp ulong budget ulong to long 409 r = paempty 410 if lt r 0 411 ret r 412 end 413 ret brmalloc cli hchan hcmp CBCCMP budget 414 end 415 416 note Allocate VOLTA_USERMODE_A (0xc361) or HOPPER_USERMODE_A (0xc661) with 0-byte params under hsub. 417 fn cballocum cli ulong hsub ulong hum ulong cls ulong budget ulong to long 418 if and ne cls CBCUMVA ne cls CBCUMHA 419 ret CBEINVAL 420 end 421 r = paempty 422 if lt r 0 423 ret r 424 end 425 ret brmalloc cli hsub hum cls budget 426 end 427 428 note Issue NVA06C_CTRL_CMD_GPFIFO_SCHEDULE (0xa06c0101, 3 B) on TSG handle htsg. 429 fn cbsched cli ulong htsg ulong en ulong skipsub ulong skipen ulong budget ulong to long 430 r = pasched en skipsub skipen 431 if lt r 0 432 ret r 433 end 434 ret brmctrl cli htsg CBCMSCH budget 435 end 436 437 note Issue NVC36F_CTRL_CMD_GPFIFO_GET_WORK_SUBMIT_TOKEN (0xc36f0108, 4 B) on channel handle hchan. 438 fn cbgetwst cli ulong hchan ulong budget ulong to long 439 r = pawstreq 440 if lt r 0 441 ret r 442 end 443 ret brmctrl cli hchan CBCMWST budget 444 end 445 446 note Decode u32 workSubmitToken from the completed GET_WORK_SUBMIT_TOKEN reply in pareply. 447 fn cbdecwst to long 448 ret pawstdec get bplen 0 449 end 450 451 note Section 4: GB20B work-submit token encoder and doorbell write helpers 452 note kfifoGenerateWorkSubmitTokenHal_GB202: 0x40000000 | ((runlist & 0x7F) << 16) | (chId & 0xFFF). 453 note Rejects rl >= 127 (0x7F is RUNLIST_ID_INVALID_RUNLIST, gb100/dev_vm.h:625). 454 fn cbtoken rl uint chid uint to long 455 if or ge rl CBRLMAX gt chid CBCHMAX 456 ret CBERANGE 457 end 458 tok = or CBDBEN or shl rl 16 chid 459 ret long ulong tok 460 end 461 462 note Direct BAR0 VF doorbell write (0x00BB0090) ordered after prior GP entry and USERD GPPut writes. 463 fn cbdbbar0 tok uint to void 464 cpufence 465 mmregwr CBDBBAR0 ulong tok 466 end 467 468 note Mapped usermode page doorbell write (umbase + 0x90) ordered after prior GP/USERD writes. 469 fn cbdbum umbase ulong tok uint to long 470 if ne and umbase 3 0 471 ret CBEALIGN 472 end 473 if or ge umbase MMPALIM gt CBDBUM sub MMPALIM umbase 474 ret CBERANGE 475 end 476 cpufence 477 mmwr32 add umbase CBDBUM ulong tok 478 ret CBOK 479 end 480 481 note Section 5: INC_METHOD pushbuffer builder, GP entry encoder, USERD GPPut and kick helpers 482 fn cbmthd subc uint mthd uint count uint to uint 483 ret or or or CBINC shl and count 4095 16 shl and subc 7 13 and shr mthd 2 8191 484 end 485 486 fn cbpbinit to void 487 put cbpblen 0 0 488 end 489 490 fn cbpbemit w uint to long 491 n = get cbpblen 0 492 if ge n CBPBMAX 493 ret CBEFULL 494 end 495 put cbpb n w 496 put cbpblen 0 add n 1 497 ret CBOK 498 end 499 500 note Compute setup (subc 1, method 0x0184, count 1, class 0xcec0). 501 fn cbpbsetup cls uint to long 502 n = get cbpblen 0 503 if gt add n 2 CBPBMAX 504 ret CBEFULL 505 end 506 r = cbpbemit cbmthd 1 CBMSETUP 1 507 if lt r 0 508 ret r 509 end 510 ret cbpbemit cls 511 end 512 513 note Emit one single-word INC_METHOD pair (subc 1) into cbpb; caller checks capacity. 514 fn cbpbpair mthd uint val uint to long 515 r = cbpbemit cbmthd 1 mthd 1 516 if lt r 0 517 ret r 518 end 519 ret cbpbemit val 520 end 521 522 note Full 18-word bare-metal compute setup with disjoint 40-bit shader windows: 523 note shared=0x70_0000_0000 (size 0x000fffff), local=0x72_0000_0000 (size 0). 524 fn cbpbsetup18 cls uint to long 525 n = get cbpblen 0 526 if gt add n 18 CBPBMAX 527 ret CBEFULL 528 end 529 r = cbpbpair CBMSETUP cls 530 if lt r 0 531 ret r 532 end 533 r = cbpbpair CBMSET1 1 534 if lt r 0 535 ret r 536 end 537 r = cbpbpair CBMSET2 15 538 if lt r 0 539 ret r 540 end 541 r = cbpbpair CBMSHWIN CBSHWINHI 542 if lt r 0 543 ret r 544 end 545 r = cbpbpair CBMSHLO 0 546 if lt r 0 547 ret r 548 end 549 r = cbpbpair CBMSHSZ CBSHSZ 550 if lt r 0 551 ret r 552 end 553 r = cbpbpair CBMLMWIN CBLMWINHI 554 if lt r 0 555 ret r 556 end 557 r = cbpbpair CBMLMLO 0 558 if lt r 0 559 ret r 560 end 561 ret cbpbpair CBMLMSZ 0 562 end 563 564 note Inter-launch WAIT_FOR_IDLE (subc 1, method 0x0110, payload 0; 2 words). 565 fn cbpbwfi to long 566 n = get cbpblen 0 567 if gt add n 2 CBPBMAX 568 ret CBEFULL 569 end 570 ret cbpbpair CBMWFI 0 571 end 572 573 note Inter-launch INVALIDATE_SHADER_CACHES (subc 1, method 0x021c, flags e.g. CBICALL 0x1011; 2 words). 574 fn cbpbicache flags uint to long 575 n = get cbpblen 0 576 if gt add n 2 CBPBMAX 577 ret CBEFULL 578 end 579 ret cbpbpair CBMICACHE flags 580 end 581 582 note PCAS QMD dispatch (subc 1, SEND_PCAS_A 0x02b4 + SEND_SIGNALING_PCAS2_B 0x02c0 action 3; 4 words). 583 fn cbpbpcas qmdva ulong to long 584 if or eq qmdva 0 ge qmdva CBVALIM 585 ret CBERANGE 586 end 587 if ne and qmdva 255 0 588 ret CBEALIGN 589 end 590 n = get cbpblen 0 591 if gt add n 4 CBPBMAX 592 ret CBEFULL 593 end 594 r = cbpbpair CBMPCASA uint and shr qmdva 8 CBU32MAX 595 if lt r 0 596 ret r 597 end 598 ret cbpbpair CBMPCASB CBPCASACT 599 end 600 601 note Inline 384-byte (96-dword) QMD launch packet (subc 1, method 0x0318, count 98). 602 fn cbpbiqmd qmdva ulong to long 603 if ne and qmdva 255 0 604 ret CBEALIGN 605 end 606 if ge qmdva CBVALIM 607 ret CBERANGE 608 end 609 n = get cbpblen 0 610 if gt add n 99 CBPBMAX 611 ret CBEFULL 612 end 613 r = cbpbemit cbmthd 1 CBMIQMD 98 614 if lt r 0 615 ret r 616 end 617 r = cbpbemit or CBDBEN uint and shr qmdva 40 511 618 if lt r 0 619 ret r 620 end 621 r = cbpbemit uint and shr qmdva 8 CBU32MAX 622 if lt r 0 623 ret r 624 end 625 for i ulong CBQMDWDS 626 r = cbpbemit get cbqmd i 627 if lt r 0 628 ret r 629 end 630 end 631 ret CBOK 632 end 633 634 note GPU L2 cache flush before CPU readback (subc 0, method 0x0028, count 4). 635 fn cbpbl2flush to long 636 n = get cbpblen 0 637 if gt add n 5 CBPBMAX 638 ret CBEFULL 639 end 640 r = cbpbemit cbmthd 0 CBML2 4 641 if lt r 0 642 ret r 643 end 644 r = cbpbemit 0 645 if lt r 0 646 ret r 647 end 648 r = cbpbemit 0 649 if lt r 0 650 ret r 651 end 652 r = cbpbemit 0 653 if lt r 0 654 ret r 655 end 656 ret cbpbemit CBL2EXEC 657 end 658 659 note Host semaphore release (subc 0, methods 0x005C..0x006C, count 5; wfi=true uses 0x100001). 660 fn cbpbsem va ulong val uint wfi bool to long 661 if ne and va 3 0 662 ret CBEALIGN 663 end 664 if or eq va 0 ge va CBVALIM 665 ret CBERANGE 666 end 667 n = get cbpblen 0 668 if gt add n 6 CBPBMAX 669 ret CBEFULL 670 end 671 r = cbpbemit cbmthd 0 CBMSEM 5 672 if lt r 0 673 ret r 674 end 675 r = cbpbemit uint and va CBU32MAX 676 if lt r 0 677 ret r 678 end 679 r = cbpbemit uint and shr va 32 `33554431` 680 if lt r 0 681 ret r 682 end 683 r = cbpbemit val 684 if lt r 0 685 ret r 686 end 687 r = cbpbemit 0 688 if lt r 0 689 ret r 690 end 691 exec = CBSEMREL 692 if wfi 693 exec = CBSEMWFI 694 end 695 ret cbpbemit exec 696 end 697 698 note Flush staged pushbuffer words to physical/window address pbpa via mmwr32, then DSB SY. 699 fn cbpbflush pbpa ulong to long 700 if ne and pbpa 3 0 701 ret CBEALIGN 702 end 703 n = get cbpblen 0 704 if eq n 0 705 ret CBEINVAL 706 end 707 for i ulong n 708 mmwr32 add pbpa mul i 4 ulong get cbpb i 709 end 710 cpufence 711 ret long n 712 end 713 714 note GP entry encoder with LEVEL bit 41 set: (va & ~3) | ((words & 0x1FFFFF) << 42) | (1 << 41). 715 fn cbgpent va ulong words uint to ulong 716 ret or or and va CBVAMASK shl and ulong words ulong CBLENMAX 42 CBGPB41 717 end 718 719 fn cbgpentok va ulong words uint to bool 720 ret and eq and va 3 0 and lt va CBVALIM and gt words 0 le words CBLENMAX 721 end 722 723 note Write 64-bit GP entry to GPFIFO ring at (gpput % ent) * 8, then DSB SY; returns nextput = (gpput + 1) % ent. 724 fn cbwrgp gppa ulong gpput uint ent uint gpent ulong to long 725 if or or lt ent 2 gt ent 65536 ne and ent sub ent 1 0 726 ret CBEINVAL 727 end 728 if ne and gppa 7 0 729 ret CBEALIGN 730 end 731 idx = ulong rem gpput ent 732 mmwr64 add gppa mul idx 8 gpent 733 cpufence 734 ret long ulong rem add gpput 1 ent 735 end 736 737 note Update USERD GPPut (+0x8C / 140), then DSB SY before doorbell. 738 fn cbwruserd userdpa ulong nextput uint to void 739 mmwr32 add userdpa CBGPPUT ulong nextput 740 cpufence 741 end 742 743 note Full BAR0 kick sequence: write GP entry, advance USERD GPPut, fence, write BAR0 0xBB0090 doorbell. 744 fn cbkickbar0 gppa ulong userdpa ulong gpent ulong gpput uint ent uint tok uint to long 745 next = cbwrgp gppa gpput ent gpent 746 if lt next 0 747 ret next 748 end 749 cbwruserd userdpa uint next 750 cbdbbar0 tok 751 ret next 752 end 753 754 note Usermode doorbell kick after GP entry write: advance USERD GPPut, fence, write umbase + 0x90. 755 fn cbkickum userdpa ulong umbase ulong nextput uint tok uint to long 756 cbwruserd userdpa nextput 757 ret cbdbum umbase tok 758 end