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/nvidia/driver/client.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 / nvidia / driver / client.om` 1184 lines ยท 21122 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 2 note gpu/nvidia/driver/client.om: the setup and teardown sequences of CUDApp nvrm/nvrm.c and m16/m16_native.c 3 note (`84b524ca`) that were still C: nvrm_open, quarantine_allocation, alloc_with_cacheability, nvrm_free, 4 note chan_extra, chan_extra_destroy, nvrm_channel, nvrm_channel_n, nvrm_channel_destroy, nvrm_enqueue, 5 note nvrm_chan_submit, nvrm_close and m16_native_free_memory, and the wrappers around them that were marked 6 note device shell: nvrm_ring, nvrm_submit, m16_native_open, m16_native_create_channel, m16_native_ring_doorbell 7 note and m16_native_close. Each decides which driver command comes next, with which request fields, and how a 8 note refusal is unwound; the command itself is a dx_ effect. 9 note 10 note The dx_ effects are declared by the part composed with this one. fx.om answers them from a script and 11 note records each one (the host gate, seqgate.om). No device part exists yet: DEVICE.md lists, per effect, what 12 note it needs from the hardware and which existing Omega unit already does it. Request fields go to dx_fk (struct 13 note kind, as nvrm_struct.om numbers them) and dx_fa (one field) before the effect that sends them. 14 note 15 note One client per process: its state is the globals below (the C keeps it in one Nvrm). Memory descriptors 16 note (NvrmMem: handle, va, size, cpu) are rows of cm: 0 the main ring, 1 its notifier, 2 + 2i and 3 + 2i extra 17 note channel i's ring and notifier, 8 a scratch row for the descriptor the C builds on its stack, 9 m16's 18 note pushbuffer, 10 to 25 the caller's, 26 to 89 m16's legacy table. The live table lv has the C's NVRM_MAX_LIVE (4096) rows of 9: 19 note handle, va, size, cpu, uvm_live, dma_live, rm_live, cpu_live, quarantined. A refusal at 4096 rows is the 20 note C's defined answer ("live allocation table full"), reproduced here; the table is not grown silently. 21 22 const CS_FAULT ulong 0 23 const CS_ROOT ulong 1 24 const CS_DEV ulong 2 25 const CS_SUB ulong 3 26 const CS_VMEM ulong 4 27 const CS_UMODE ulong 5 28 const CS_VAS ulong 6 29 const CS_CHG ulong 7 30 const CS_CTX ulong 8 31 const CS_GPF ulong 9 32 const CS_COMP ulong 10 33 const CS_FDCTL ulong 11 34 const CS_FDDEV ulong 12 35 const CS_FDUVM ulong 13 36 const CS_FDUVM2 ulong 14 37 const CS_GREG ulong 15 38 const CS_VREG ulong 16 39 const CS_CREG ulong 17 40 const CS_NEXTRA ulong 18 41 const CS_LIVEN ulong 19 42 const CS_PUT ulong 20 43 const CS_RET ulong 21 44 const CS_ENT ulong 22 45 const CS_USERD ulong 23 46 const CS_TOKEN ulong 24 47 const CS_CHVA ulong 25 48 const CS_CHVASZ ulong 26 49 const CS_SLOT ulong 27 50 const CS_VANEXT ulong 28 51 const CS_TSM ulong 29 52 const CS_DISC ulong 30 53 const CS_CCLS ulong 31 54 const CS_GCLS ulong 32 55 const CS_UCLS ulong 33 56 const CS_SMV ulong 34 57 const CS_GPUID ulong 35 58 const CS_MINOR ulong 36 59 const CS_UCPU ulong 37 60 const CS_LRS ulong 38 61 const CS_RETRIES ulong 39 62 const CS_RETMS ulong 40 63 const CS_NEXTH ulong 41 64 const CS_UUID0 ulong 42 65 const CS_UUID1 ulong 43 66 const CS_DOOR ulong 44 67 const CN_MAPFAILED ulong `18446744073709551615` 68 const CN_U32 ulong `4294967295` 69 70 global cs ulong 64 71 global cm ulong 360 72 global lv ulong 36864 73 global cx ulong 48 74 75 fn cg i ulong to ulong 76 ret get cs i 77 end 78 79 fn cp i ulong v ulong to void 80 put cs i v 81 end 82 83 fn cn_fault to void 84 put cs CS_FAULT 1 85 end 86 87 fn cn_faulted to bool 88 ret ne get cs CS_FAULT 0 89 end 90 91 note memory descriptor rows 92 fn mh s ulong to ulong 93 ret get cm mul s 4 94 end 95 96 fn mva s ulong to ulong 97 ret get cm add mul s 4 1 98 end 99 100 fn msz s ulong to ulong 101 ret get cm add mul s 4 2 102 end 103 104 fn mcpu s ulong to ulong 105 ret get cm add mul s 4 3 106 end 107 108 fn mset s ulong h ulong va ulong sz ulong cpu ulong to void 109 put cm mul s 4 h 110 put cm add mul s 4 1 va 111 put cm add mul s 4 2 sz 112 put cm add mul s 4 3 cpu 113 end 114 115 fn mzero s ulong to void 116 mset s 0 0 0 0 117 end 118 119 note live rows 120 fn lg r ulong f ulong to ulong 121 ret get lv add mul r 9 f 122 end 123 124 fn lp r ulong f ulong v ulong to void 125 put lv add mul r 9 f v 126 end 127 128 note extra channel i (0 to 2) fields: 0 gpfifo, 1 compute_obj, 2 ctxshare, 3 entries, 4 userd_off, 5 token, 129 note 6 put, 7 retired, 8 channel_va, 9 channel_va_size, 10 registered 130 fn xg i ulong f ulong to ulong 131 ret get cx add mul i 16 f 132 end 133 134 fn xp i ulong f ulong v ulong to void 135 put cx add mul i 16 f v 136 end 137 138 note fail(): message code (the oracle's table, seqoracle.c g_msgs), its arguments, -1 139 fn cn_e0 code ulong to long 140 dx_er code 141 dx_ee 142 ret -1 143 end 144 145 fn cn_e1 code ulong a ulong to long 146 dx_er code 147 dx_eu a 148 dx_ee 149 ret -1 150 end 151 152 fn cn_e2 code ulong a ulong b ulong to long 153 dx_er code 154 dx_eu a 155 dx_eu b 156 dx_ee 157 ret -1 158 end 159 160 fn cn_ed code ulong d long to long 161 dx_er code 162 dx_ed d 163 dx_ee 164 ret -1 165 end 166 167 fn cn_bool b bool to ulong 168 if b 169 ret 1 170 end 171 ret 0 172 end 173 174 note the shell's va_release faults the client on every refused release 175 fn cn_varel va ulong sz ulong to bool 176 ok = dx_varel va sz 177 if not ok 178 cn_fault 179 end 180 ret ok 181 end 182 183 note client reset: the C's memset of the whole Nvrm (live table, extra channels, ring and notifier included) 184 fn cn_zero to void 185 for i ulong 64 186 put cs i 0 187 end 188 for i ulong 36864 189 put lv i 0 190 end 191 for i ulong 48 192 put cx i 0 193 end 194 for s ulong 9 195 mzero s 196 end 197 end 198 199 note uuid byte i (0 to 15) of the GPU, from the two little-endian words 200 fn cn_uuidb i ulong to ulong 201 w = get cs add CS_UUID0 div i 8 202 ret and shr w mul rem i 8 8 255 203 end 204 205 note RM_ALLOC under parent of class cls into client field i; false when refused (the field keeps its value) 206 fn cn_obj i ulong parent ulong cls ulong to bool 207 h = dx_alloc parent cls 208 if eq h 0 209 ret false 210 end 211 cp i h 212 ret true 213 end 214 215 note --- nvrm_open: admission, VA slot, the control nodes, the RM client, UVM, the card table --- 216 fn cn_open to long 217 cn_zero 218 if not dx_admit_open 219 ret -1 220 end 221 cp CS_NEXTH `3472883713` 222 va = dx_slot 223 cp CS_VANEXT va 224 if eq va 0 225 ret cn_e0 0 226 end 227 cp CS_SLOT va 228 cp CS_FDCTL bitcast ulong dx_fopen 1 229 cp CS_FDUVM bitcast ulong dx_fopen 2 230 cp CS_FDUVM2 bitcast ulong dx_fopen 2 231 if or or lt bitcast long cg CS_FDCTL 0 lt bitcast long cg CS_FDUVM 0 lt bitcast long cg CS_FDUVM2 0 232 ret cn_ed 1 dx_errno 233 end 234 if not cn_obj CS_ROOT 0 65 235 ret -1 236 end 237 dx_fk 18 238 dx_fa 0 239 if not dx_uvm bitcast long cg CS_FDUVM `805306369` 240 ret -1 241 end 242 dx_fk 19 243 dx_fa and cg CS_FDUVM CN_U32 244 dx_uvmraw bitcast long cg CS_FDUVM2 75 245 dx_fk 16 246 dx_fa 0 247 if not dx_ioctl bitcast long cg CS_FDCTL 200 248 ret cn_ed 2 dx_errno 249 end 250 found = dx_cardidx 251 if lt found 0 252 dx_er 3 253 dx_es 254 dx_ee 255 ret -1 256 end 257 if ne cn_open_card ulong found 0 258 ret -1 259 end 260 ret cn_open_vas 261 end 262 263 note nvrm_open on card index found: admission, the device node, device, subdevice, virtual memory, SM version, 264 note class list and the class selection, which must select the SM the admission admitted 265 fn cn_open_card found ulong to long 266 asm = dx_admit_card found 267 if lt asm 0 268 ret -1 269 end 270 cp CS_GPUID and dx_cardget found 5 CN_U32 271 cp CS_MINOR and dx_cardget found 6 CN_U32 272 fd = dx_opendev cg CS_MINOR 273 cp CS_FDDEV bitcast ulong fd 274 if lt fd 0 275 ret -1 276 end 277 dx_fk 1 278 dx_fa cg CS_GPUID 279 if not dx_ctrl cg CS_ROOT 517 280 ret -1 281 end 282 dx_fk 2 283 dx_fa dx_nsget 1 1 284 dx_fa cg CS_ROOT 285 dx_fa 0 286 if not cn_obj CS_DEV cg CS_ROOT 128 287 ret -1 288 end 289 dx_fk 3 290 dx_fa 0 291 if not cn_obj CS_SUB cg CS_DEV 8320 292 ret -1 293 end 294 dx_fk 4 295 dx_fa 0 296 dx_fa `562949953421311` 297 if not cn_obj CS_VMEM cg CS_DEV 112 298 ret -1 299 end 300 dx_fk 17 301 dx_fa 12 302 dx_fk 6 303 dx_fa 1 304 dx_fa 0 305 if not dx_ctrl cg CS_SUB `545264129` 306 ret -1 307 end 308 cp CS_SMV and dx_nsget 17 1 CN_U32 309 dx_fk 7 310 dx_fa 0 311 if not dx_ctrl cg CS_DEV `8389121` 312 ret -1 313 end 314 ncls = and dx_nsget 7 0 CN_U32 315 if gt ncls 512 316 ret cn_e0 4 317 end 318 dx_fk 7 319 dx_fa ncls 320 dx_fa 0 321 if not dx_ctrl cg CS_DEV `8389121` 322 ret -1 323 end 324 ncls = and dx_nsget 7 0 CN_U32 325 if gt ncls 512 326 ret -1 327 end 328 if not dx_select ncls and dx_cardget found 7 65535 and dx_cardget found 8 65535 329 ret -1 330 end 331 if ne cg CS_TSM ulong asm 332 ret cn_e2 5 ulong asm cg CS_TSM 333 end 334 ret 0 335 end 336 337 note nvrm_open last: usermode doorbell page, VA space, the GPU uuid, UVM registration of the GPU and its VA space 338 fn cn_open_vas to long 339 if not cn_obj CS_UMODE cg CS_SUB cg CS_UCLS 340 ret -1 341 end 342 mmio = dx_map cg CS_UMODE 65536 0 0 0 343 if eq mmio CN_MAPFAILED 344 ret -1 345 end 346 cp CS_UCPU mmio 347 cp CS_DOOR add mmio 144 348 dx_fk 8 349 dx_fa 0 350 dx_fa 72 351 dx_fa `562949869535232` 352 dx_fa 4096 353 if not cn_obj CS_VAS cg CS_DEV 37105 354 ret -1 355 end 356 dx_fk 9 357 dx_fa 0 358 dx_fa 2 359 dx_fa 16 360 if not dx_ctrl cg CS_SUB `545259850` 361 ret -1 362 end 363 for i ulong 16 364 w = add CS_UUID0 div i 8 365 cp w or cg w shl and dx_nsget 9 add 3 i 255 mul rem i 8 8 366 end 367 dx_fk 21 368 dx_fa cg CS_UUID0 369 dx_fa cg CS_UUID1 370 dx_fa CN_U32 371 if not dx_uvm bitcast long cg CS_FDUVM 37 372 ret -1 373 end 374 cp CS_GREG 1 375 dx_fk 23 376 dx_fa cg CS_UUID0 377 dx_fa cg CS_UUID1 378 dx_fa and cg CS_FDCTL CN_U32 379 dx_fa cg CS_ROOT 380 dx_fa cg CS_VAS 381 if not dx_uvm bitcast long cg CS_FDUVM 25 382 ret -1 383 end 384 cp CS_VREG 1 385 ret 0 386 end 387 388 note --- quarantine_allocation: a live row that is kept, quarantined, and the client faulted --- 389 fn cn_quar h ulong va ulong sz ulong cpu ulong uvml ulong dmal ulong to void 390 r = cg CS_LIVEN 391 cp CS_LIVEN add r 1 392 lp r 0 h 393 lp r 1 va 394 lp r 2 sz 395 lp r 3 cpu 396 lp r 4 uvml 397 lp r 5 dmal 398 lp r 6 1 399 lp r 7 1 400 lp r 8 1 401 dx_transfer h 402 cn_fault 403 end 404 405 note --- alloc_with_cacheability (cach: NVOS32_ATTR2_GPU_CACHEABLE 1 yes, 2 no; local: framebuffer) into row s --- 406 fn cn_alloc size ulong s ulong cach ulong local bool to long 407 sz = drv_asize cn_faulted size 408 if eq sz 0 409 ret cn_e0 7 410 end 411 if drv_livefull cg CS_LIVEN 4096 412 ret cn_ed 8 4096 413 end 414 va = dx_vatake sz 4096 415 if eq va 0 416 ret cn_e0 9 417 end 418 res = dx_reserve va sz 419 if ne res va 420 if ne res CN_MAPFAILED 421 q = dx_drop res sz 422 end 423 cn_fault 424 ret cn_e1 10 va 425 end 426 dx_fk 10 427 dx_fa cg CS_ROOT 428 dx_fa 0 429 dx_fa 49409 430 attr = ulong `436207616` 431 cls = ulong 62 432 system = long 1 433 if local 434 attr = ulong `402653184` 435 cls = ulong 64 436 system = long 0 437 end 438 dx_fa attr 439 dx_fa or shl cach 2 1 440 dx_fa 6 441 dx_fa sz 442 dx_fa 4096 443 dx_fa sub sz 1 444 h = dx_alloc cg CS_DEV cls 445 if eq h 0 446 if not dx_drop va sz 447 cn_fault 448 end 449 if local 450 if not cn_faulted 451 if ne cg CS_LRS 0 452 q = cn_varel va sz 453 ret -1 454 end 455 end 456 end 457 cn_fault 458 dx_ea sz 459 ret -1 460 end 461 cpu = dx_map h sz va 0 system 462 if ne cpu va 463 cn_quar h va sz va 0 0 464 if local 465 mset 8 h va sz va 466 if eq cn_free 8 0 467 cp CS_FAULT 0 468 end 469 end 470 dx_er 11 471 dx_eu va 472 dx_es 473 dx_ee 474 ret -1 475 end 476 um = dx_uvmmap va sz h 477 if ne um 0 478 cn_quar h va sz cpu cn_bool ge um 2 cn_bool ge um 3 479 if local 480 mset 8 h va sz cpu 481 if eq cn_free 8 0 482 cp CS_FAULT 0 483 end 484 end 485 ret -1 486 end 487 mset s h va sz cpu 488 dx_zero cpu sz 489 r = cg CS_LIVEN 490 lp r 0 h 491 lp r 1 va 492 lp r 2 sz 493 lp r 3 cpu 494 lp r 4 1 495 lp r 5 1 496 lp r 6 1 497 lp r 7 1 498 note FIX-1: the C leaves quarantined as the row's last tenant had it. After a local allocation whose CPU or UVM 499 note mapping failed and was released at once (its row quarantined, then removed, the client unfaulted), the next 500 note allocation took that row with quarantined 1 and copy_live refused it. A new row is not quarantined. 501 lp r 8 0 502 dx_transfer h 503 cp CS_LIVEN add r 1 504 ret 0 505 end 506 507 note nvrm_alloc (cacheable), nvrm_alloc_gpu_uncached and nvrm_alloc_vram 508 fn cn_alloc_mode size ulong s ulong mode ulong to long 509 if eq mode 0 510 ret cn_alloc size s 1 false 511 end 512 if eq mode 1 513 ret cn_alloc size s 2 false 514 end 515 if not drv_vramok ne cg CS_DISC 0 cg CS_TSM 516 ret cn_e0 6 517 end 518 ret cn_alloc size s 2 true 519 end 520 521 note the live row of descriptor s (same va, handle and size): its index; 2^64 - 1 none; 2^64 - 2 two rows 522 fn cn_find s ulong to ulong 523 idx = ulong `18446744073709551615` 524 for i ulong cg CS_LIVEN bound 4096 525 if and and eq lg i 1 mva s eq lg i 0 mh s eq lg i 2 msz s 526 if ne idx `18446744073709551615` 527 ret `18446744073709551614` 528 end 529 idx = i 530 end 531 end 532 ret idx 533 end 534 535 note --- nvrm_free of descriptor row s --- 536 fn cn_free s ulong to long 537 if and and and eq mh s 0 eq mva s 0 eq msz s 0 eq mcpu s 0 538 ret 0 539 end 540 idx = cn_find s 541 if eq idx `18446744073709551614` 542 cn_fault 543 ret cn_e0 12 544 end 545 if eq idx `18446744073709551615` 546 dx_er 13 547 dx_eu mva s 548 dx_eu mh s 549 dx_eu msz s 550 dx_ee 551 ret -1 552 end 553 h = mh s 554 va = mva s 555 sz = msz s 556 cpu = mcpu s 557 bad = ne lg idx 3 cpu 558 bad = or bad eq cpu 0 559 bad = or bad eq sz 0 560 bad = or bad ne and va 4095 0 561 bad = or bad ne and sz 4095 0 562 if bad 563 cn_fault 564 ret cn_e0 14 565 end 566 if ne lg idx 4 0 567 if not dx_uvmfree va sz 568 lp idx 8 1 569 cn_fault 570 ret -1 571 end 572 lp idx 4 0 573 end 574 if ne lg idx 5 0 575 if not dx_dmaunmap h va sz 576 lp idx 8 1 577 cn_fault 578 ret -1 579 end 580 lp idx 5 0 581 end 582 if ne lg idx 6 0 583 if not dx_free cg CS_DEV h 584 lp idx 8 1 585 cn_fault 586 ret -1 587 end 588 lp idx 6 0 589 end 590 if ne lg idx 7 0 591 if not dx_drop cpu sz 592 lp idx 8 1 593 cn_fault 594 dx_er 15 595 dx_eu va 596 dx_ed dx_errno 597 dx_ee 598 ret -1 599 end 600 lp idx 7 0 601 end 602 last = sub cg CS_LIVEN 1 603 for f ulong 9 604 lp idx f lg last f 605 end 606 cp CS_LIVEN last 607 if not cn_varel va sz 608 ret -1 609 end 610 mzero s 611 ret 0 612 end 613 614 note --- chan_extra: extra channel i (n_extra already counts it) --- 615 fn cn_chx i ulong to long 616 fifo = add 2 mul i 2 617 notif = add fifo 1 618 dx_fk 13 619 dx_fa cg CS_VAS 620 dx_fa 1 621 ctx = dx_alloc cg CS_CHG 36967 622 if eq ctx 0 623 ret -1 624 end 625 xp i 2 ctx 626 xp i 3 1024 627 if ne cn_alloc 65536 fifo 2 false 0 628 ret -1 629 end 630 if ne cn_alloc `1048576` notif 1 false 0 631 ret -1 632 end 633 xp i 4 and mul xg i 3 8 CN_U32 634 dx_fk 11 635 dx_fa mh notif 636 dx_fa mh fifo 637 dx_fa mva fifo 638 dx_fa xg i 3 639 dx_fa ctx 640 dx_fa 0 641 dx_fa mh fifo 642 dx_fa xg i 4 643 dx_fa 0 644 g = dx_alloc cg CS_CHG cg CS_GCLS 645 if eq g 0 646 ret -1 647 end 648 xp i 0 g 649 co = dx_alloc g cg CS_CCLS 650 if eq co 0 651 ret -1 652 end 653 xp i 1 co 654 dx_fk 14 655 dx_fa CN_U32 656 if not dx_ctrl g `3278831880` 657 ret -1 658 end 659 xp i 5 and dx_nsget 14 0 CN_U32 660 cva = dx_vatake `67108864` 4096 661 xp i 8 cva 662 if eq cva 0 663 cn_fault 664 ret cn_e0 16 665 end 666 xp i 9 `67108864` 667 dx_fk 24 668 dx_fa cg CS_UUID0 669 dx_fa cg CS_UUID1 670 dx_fa and cg CS_FDCTL CN_U32 671 dx_fa cg CS_ROOT 672 dx_fa g 673 dx_fa cva 674 dx_fa `67108864` 675 if not dx_uvm bitcast long cg CS_FDUVM 27 676 cn_fault 677 ret -1 678 end 679 xp i 10 1 680 xp i 6 0 681 xp i 7 0 682 ret 0 683 end 684 685 note --- chan_extra_destroy: extra channel i --- 686 fn cn_chxd i ulong to long 687 fifo = add 2 mul i 2 688 notif = add fifo 1 689 if ne xg i 10 0 690 dx_fk 25 691 dx_fa cg CS_UUID0 692 dx_fa cg CS_UUID1 693 dx_fa cg CS_ROOT 694 dx_fa xg i 0 695 if not dx_uvm bitcast long cg CS_FDUVM 28 696 ret -1 697 end 698 xp i 10 0 699 end 700 if ne xg i 1 0 701 if not dx_free xg i 0 xg i 1 702 ret -1 703 end 704 end 705 xp i 1 0 706 if ne xg i 0 0 707 if not dx_free cg CS_CHG xg i 0 708 ret -1 709 end 710 end 711 xp i 0 0 712 if ne xg i 2 0 713 if not dx_free cg CS_CHG xg i 2 714 ret -1 715 end 716 end 717 xp i 2 0 718 if ne mh fifo 0 719 if ne cn_free fifo 0 720 ret -1 721 end 722 end 723 if ne mh notif 0 724 if ne cn_free notif 0 725 ret -1 726 end 727 end 728 if ne xg i 9 0 729 if not cn_varel xg i 8 xg i 9 730 ret -1 731 end 732 xp i 8 0 733 xp i 9 0 734 end 735 xp i 6 0 736 xp i 7 0 737 ret 0 738 end 739 740 note --- nvrm_channel_n (nvrm_channel is extra 0) --- 741 fn cn_channel extra ulong to long 742 adm = nvrm_chadm cg CS_FAULT cg CS_CHG cg CS_CREG cg CS_NEXTRA extra 3 743 if eq adm 1 744 ret cn_e0 17 745 end 746 if eq adm 2 747 dx_er 18 748 dx_eu extra 749 dx_ed 3 750 dx_ee 751 ret -1 752 end 753 dx_fk 12 754 dx_fa 0 755 dx_fa 1 756 chg = dx_alloc cg CS_DEV 41068 757 if eq chg 0 758 ret -1 759 end 760 cp CS_CHG chg 761 dx_fk 13 762 dx_fa cg CS_VAS 763 dx_fa 1 764 ctx = dx_alloc chg 36967 765 if eq ctx 0 766 ret -1 767 end 768 cp CS_CTX ctx 769 cp CS_ENT 1024 770 if ne cn_alloc 65536 0 2 false 0 771 ret -1 772 end 773 if ne cn_alloc `1048576` 1 1 false 0 774 ret -1 775 end 776 cp CS_USERD and mul cg CS_ENT 8 CN_U32 777 dx_fk 11 778 dx_fa mh 1 779 dx_fa mh 0 780 dx_fa mva 0 781 dx_fa cg CS_ENT 782 dx_fa cg CS_CTX 783 dx_fa 0 784 dx_fa mh 0 785 dx_fa cg CS_USERD 786 dx_fa 0 787 g = dx_alloc cg CS_CHG cg CS_GCLS 788 if eq g 0 789 ret -1 790 end 791 cp CS_GPF g 792 delay = cg CS_RETMS 793 if eq delay 0 794 delay = ulong 100 795 end 796 cp CS_RETRIES 0 797 while true bound 1000 798 co = dx_alloc g cg CS_CCLS 799 arc = ulong 1 800 if ne co 0 801 cp CS_COMP co 802 arc = ulong 0 803 end 804 rd = nvrm_retry arc cg CS_RETRIES 50 cn_bool eq cg CS_LRS 81 805 if eq rd 0 806 break 807 end 808 if eq rd 3 809 ret -1 810 end 811 if eq rd 2 812 dx_en and add cg CS_RETRIES 1 CN_U32 delay 813 ret -1 814 end 815 cp CS_RETRIES and add cg CS_RETRIES 1 CN_U32 816 dx_sleep and mul delay 1000 CN_U32 817 end 818 dx_fk 14 819 dx_fa CN_U32 820 if not dx_ctrl g `3278831880` 821 ret -1 822 end 823 cp CS_TOKEN and dx_nsget 14 0 CN_U32 824 cva = dx_vatake `67108864` 4096 825 cp CS_CHVA cva 826 if eq cva 0 827 cn_fault 828 ret cn_e0 19 829 end 830 cp CS_CHVASZ `67108864` 831 dx_fk 24 832 dx_fa cg CS_UUID0 833 dx_fa cg CS_UUID1 834 dx_fa and cg CS_FDCTL CN_U32 835 dx_fa cg CS_ROOT 836 dx_fa g 837 dx_fa cva 838 dx_fa `67108864` 839 if not dx_uvm bitcast long cg CS_FDUVM 27 840 cn_fault 841 ret -1 842 end 843 cp CS_CREG 1 844 for i ulong extra bound 3 845 cp CS_NEXTRA add i 1 846 if ne cn_chx i 0 847 ret -1 848 end 849 end 850 dx_fk 15 851 dx_fa 1 852 if not dx_ctrl cg CS_CHG `2691432705` 853 ret -1 854 end 855 cp CS_PUT 0 856 cp CS_RET 0 857 ret 0 858 end 859 860 note --- nvrm_channel_destroy: extras last first, then the main channel; any refusal faults the client --- 861 fn cn_chdestroy to long 862 while ne cg CS_NEXTRA 0 bound 3 863 if ne cn_chxd sub cg CS_NEXTRA 1 0 864 cn_fault 865 ret -1 866 end 867 cp CS_NEXTRA sub cg CS_NEXTRA 1 868 end 869 if ne cg CS_CREG 0 870 dx_fk 25 871 dx_fa cg CS_UUID0 872 dx_fa cg CS_UUID1 873 dx_fa cg CS_ROOT 874 dx_fa cg CS_GPF 875 if not dx_uvm bitcast long cg CS_FDUVM 28 876 cn_fault 877 ret -1 878 end 879 cp CS_CREG 0 880 end 881 if ne cg CS_COMP 0 882 if not dx_free cg CS_GPF cg CS_COMP 883 cn_fault 884 ret -1 885 end 886 end 887 cp CS_COMP 0 888 if ne cg CS_GPF 0 889 if not dx_free cg CS_CHG cg CS_GPF 890 cn_fault 891 ret -1 892 end 893 end 894 cp CS_GPF 0 895 if ne cg CS_CTX 0 896 if not dx_free cg CS_CHG cg CS_CTX 897 cn_fault 898 ret -1 899 end 900 end 901 cp CS_CTX 0 902 if ne cg CS_CHG 0 903 if not dx_free cg CS_DEV cg CS_CHG 904 cn_fault 905 ret -1 906 end 907 end 908 cp CS_CHG 0 909 if ne mh 0 0 910 if ne cn_free 0 0 911 cn_fault 912 ret -1 913 end 914 end 915 if ne mh 1 0 916 if ne cn_free 1 0 917 cn_fault 918 ret -1 919 end 920 end 921 if ne cg CS_CHVASZ 0 922 if not cn_varel cg CS_CHVA cg CS_CHVASZ 923 cn_fault 924 ret -1 925 end 926 cp CS_CHVA 0 927 cp CS_CHVASZ 0 928 end 929 cp CS_PUT 0 930 cp CS_RET 0 931 ret 0 932 end 933 934 note --- nvrm_enqueue: pushbuffer row s, words [off, off + 4 nw) on the main channel --- 935 fn cn_enqueue s ulong off ulong nw ulong to long 936 if or or or ne cg CS_FAULT 0 eq cg CS_GPF 0 eq mcpu 0 0 lt cg CS_ENT 2 937 ret cn_e0 20 938 end 939 sp = nvrm_pspan off nw msz s mva s 940 if eq sp 1 941 ret cn_e0 21 942 end 943 if ne cg CS_DISC 0 944 if not dx_validate off nw 945 ret -1 946 end 947 end 948 if eq sp 2 949 ret cn_e0 22 950 end 951 if ne nvrm_pfull cg CS_PUT cg CS_RET cg CS_ENT 0 952 ret cn_e1 23 and sub cg CS_PUT cg CS_RET CN_U32 953 end 954 if not dx_publish mh 0 cg CS_ENT cg CS_PUT cg CS_USERD add mva s off nw 955 ret cn_e0 24 956 end 957 cp CS_PUT and add cg CS_PUT 1 CN_U32 958 ret 0 959 end 960 961 note --- nvrm_chan_submit: the same on extra channel ch (1 to n_extra), then its doorbell --- 962 fn cn_submit ch ulong s ulong off ulong nw ulong to long 963 if or or ne cg CS_FAULT 0 eq ch 0 gt ch cg CS_NEXTRA 964 ret cn_e1 25 ch 965 end 966 i = sub ch 1 967 if or or eq xg i 0 0 eq mcpu add 2 mul i 2 0 lt xg i 3 2 968 ret cn_e1 25 ch 969 end 970 sp = nvrm_pspan off nw msz s mva s 971 if eq sp 1 972 ret cn_e0 21 973 end 974 if eq sp 2 975 ret cn_e0 22 976 end 977 if ne cg CS_DISC 0 978 if not dx_validate off nw 979 ret -1 980 end 981 end 982 if ne nvrm_pfull xg i 6 xg i 7 xg i 3 0 983 ret cn_e2 26 ch and sub xg i 6 xg i 7 CN_U32 984 end 985 if not dx_publish mh add 2 mul i 2 xg i 3 xg i 6 xg i 4 add mva s off nw 986 ret cn_e1 27 ch 987 end 988 xp i 6 and add xg i 6 1 CN_U32 989 if not dx_doorbell xg i 5 990 ret cn_e1 28 ch 991 end 992 ret 0 993 end 994 995 note close a descriptor that is above 0 (the C closes fd > 0 and then forgets it) 996 fn cn_fdclose i ulong to void 997 fd = bitcast long cg i 998 if gt fd 0 999 q = dx_fclose fd 1000 end 1001 cp i 0 1002 end 1003 1004 note --- nvrm_close --- 1005 fn cn_close to long 1006 if ne cg CS_ROOT 0 1007 if ne cn_chdestroy 0 1008 cn_fault 1009 end 1010 end 1011 i = cg CS_LIVEN 1012 while gt i 0 bound `1000000` 1013 i = sub i 1 1014 eh = lg i 0 1015 eva = lg i 1 1016 esz = lg i 2 1017 ecpu = lg i 3 1018 ecl = lg i 7 1019 mset 8 eh eva esz ecpu 1020 rc = cn_free 8 1021 if ne rc 0 1022 cn_fault 1023 if and ne ecl 0 ne ecpu 0 1024 q = dx_drop ecpu esz 1025 end 1026 end 1027 if and eq rc 0 lt i cg CS_LIVEN 1028 i = add i 1 1029 end 1030 end 1031 if ne cg CS_UCPU 0 1032 if dx_drop cg CS_UCPU 65536 1033 cp CS_UCPU 0 1034 cp CS_DOOR 0 1035 else 1036 cn_fault 1037 end 1038 end 1039 if ne cg CS_VREG 0 1040 dx_fk 22 1041 dx_fa cg CS_UUID0 1042 dx_fa cg CS_UUID1 1043 if not dx_uvm bitcast long cg CS_FDUVM 26 1044 cn_fault 1045 end 1046 cp CS_VREG 0 1047 end 1048 if ne cg CS_GREG 0 1049 dx_fk 22 1050 dx_fa cg CS_UUID0 1051 dx_fa cg CS_UUID1 1052 if not dx_uvm bitcast long cg CS_FDUVM 38 1053 cn_fault 1054 end 1055 cp CS_GREG 0 1056 end 1057 if ne cg CS_UMODE 0 1058 if not dx_free cg CS_SUB cg CS_UMODE 1059 cn_fault 1060 end 1061 end 1062 cp CS_UMODE 0 1063 if ne cg CS_VAS 0 1064 if not dx_free cg CS_DEV cg CS_VAS 1065 cn_fault 1066 end 1067 end 1068 cp CS_VAS 0 1069 if ne cg CS_VMEM 0 1070 if not dx_free cg CS_DEV cg CS_VMEM 1071 cn_fault 1072 end 1073 end 1074 cp CS_VMEM 0 1075 if ne cg CS_SUB 0 1076 if not dx_free cg CS_DEV cg CS_SUB 1077 cn_fault 1078 end 1079 end 1080 cp CS_SUB 0 1081 if ne cg CS_DEV 0 1082 if not dx_free cg CS_ROOT cg CS_DEV 1083 cn_fault 1084 end 1085 end 1086 cp CS_DEV 0 1087 if ne cg CS_ROOT 0 1088 if not dx_free cg CS_ROOT cg CS_ROOT 1089 cn_fault 1090 end 1091 end 1092 cp CS_ROOT 0 1093 cn_fdclose CS_FDDEV 1094 cn_fdclose CS_FDUVM2 1095 cn_fdclose CS_FDUVM 1096 cn_fdclose CS_FDCTL 1097 if not dx_finish 1098 cn_fault 1099 end 1100 base = cg CS_SLOT 1101 vn = cg CS_VANEXT 1102 if and and and eq cg CS_FAULT 0 eq cg CS_LIVEN 0 eq cg CS_CREG 0 ne base 0 1103 if ge vn base 1104 if le sub vn base `4294967296` 1105 dx_recycle base 1106 end 1107 end 1108 end 1109 cp CS_SLOT 0 1110 if ne cg CS_FAULT 0 1111 ret -1 1112 end 1113 ret 0 1114 end 1115 1116 note --- m16_native_alloc_memory and m16_native_free_memory over the 64 legacy rows (26 to 89) --- 1117 fn cn_m16alloc size ulong to long 1118 for i ulong 64 1119 s = add 26 i 1120 if eq mh s 0 1121 if ne cn_alloc size s 1 false 0 1122 ret -1 1123 end 1124 ret 0 1125 end 1126 end 1127 ret -1 1128 end 1129 1130 fn cn_m16free cpu ulong to long 1131 if eq cpu 0 1132 ret -1 1133 end 1134 for i ulong 64 1135 s = add 26 i 1136 if and eq mcpu s cpu ne mh s 0 1137 ret cn_free s 1138 end 1139 end 1140 ret -1 1141 end 1142 1143 note --- m16_native_open, m16_native_create_channel and m16_native_close: the m16 context is the client, its 1144 note legacy rows (26 to 89) and its pushbuffer descriptor (row 9) --- 1145 fn cn_m16open to long 1146 for s ulong 81 1147 mzero add 9 s 1148 end 1149 if eq cn_open 0 1150 ret 0 1151 end 1152 r = cn_close 1153 ret -1 1154 end 1155 1156 note nvrm_channel, then the pushbuffer the CPU rewrites between submissions, uncached on the GPU 1157 fn cn_m16chan to long 1158 if ne cn_channel 0 0 1159 ret -1 1160 end 1161 if ne cn_alloc 4096 9 2 false 0 1162 ret -1 1163 end 1164 ret 0 1165 end 1166 1167 fn cn_m16close to long 1168 ret cn_close 1169 end 1170 1171 note --- nvrm_ring (also m16_native_ring_doorbell) and nvrm_submit: a refused doorbell faults the client --- 1172 fn cn_ring to void 1173 if not dx_doorbell cg CS_TOKEN 1174 cp CS_FAULT 1 1175 end 1176 end 1177 1178 fn cn_nsubmit s ulong off ulong nw ulong to long 1179 if ne cn_enqueue s off nw 0 1180 ret -1 1181 end 1182 cn_ring 1183 ret 0 1184 end