CUDApp
CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit.
Brought by drakestapleton
CUDApp / native / nvrm / context.om
| 1 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | note Native continuation of canonical nvrm/nvrm.c, source349913f1, NVIDIA ABI580.173.02. |
| 3 | note One explicitly owned context, bounded buffers, channel, submission and completion. |
| 4 | text nvctl "/dev/nvidiactl" |
| 5 | text nvdev "/dev/nvidia0" |
| 6 | text nvuvm "/dev/nvidia-uvm" |
| 7 | global nvfd int 4 |
| 8 | global nvobj uint 16 |
| 9 | global nvhdr uchar 32 |
| 10 | global nvpar uchar 16384 |
| 11 | global nvcard uchar 4608 |
| 12 | global nvseq uint 1 |
| 13 | global nverr long 1 |
| 14 | global nvstage uint 1 |
| 15 | global nvid uint 1 |
| 16 | global nvinst uint 1 |
| 17 | global nvsm uint 1 |
| 18 | global nvcls uint 3 |
| 19 | global nvuuid uchar 16 |
| 20 | global nvreg uchar 2 |
| 21 | note Context phases:0 closed,1 driver resources live,2 descriptors closed with mapping cleanup pending. |
| 22 | global nvstate uchar 1 |
| 23 | global nvmm uint 1 |
| 24 | global nvfault uchar 1 |
| 25 | global nvnext ulong 1 |
| 26 | global nvbar long 1 |
| 27 | global nvfifo long 1 |
| 28 | global nvnotify long 1 |
| 29 | global nvchva long 1 |
| 30 | note A mapping not yet published to its caller remains owned after failed cleanup. |
| 31 | global nvunpub long 1 |
| 32 | global nvtoken uint 1 |
| 33 | global nvchreg uchar 1 |
| 34 | global nvsched uchar 1 |
| 35 | global nvput ulong 1 |
| 36 | global nvret ulong 1 |
| 37 | global nvretry uint 1 |
| 38 | global nvmobj uint 96 |
| 39 | global nvmmap long 96 |
| 40 | global nvmaddr ulong 96 |
| 41 | global nvmlen ulong 96 |
| 42 | global nvmflag uchar 96 |
| 43 | fn nhput off ulong v uint to void |
| 44 | for i ulong 4 |
| 45 | put nvhdr add off i uchar and shr v mul i 8 255 |
| 46 | end |
| 47 | end |
| 48 | fn nhget off ulong to uint |
| 49 | v = uint 0 |
| 50 | for i ulong 4 |
| 51 | v = or v shl uint get nvhdr add off i mul i 8 |
| 52 | end |
| 53 | ret v |
| 54 | end |
| 55 | fn npput off ulong v uint to void |
| 56 | for i ulong 4 |
| 57 | put nvpar add off i uchar and shr v mul i 8 255 |
| 58 | end |
| 59 | end |
| 60 | fn npget off ulong to uint |
| 61 | v = uint 0 |
| 62 | for i ulong 4 |
| 63 | v = or v shl uint get nvpar add off i mul i 8 |
| 64 | end |
| 65 | ret v |
| 66 | end |
| 67 | fn npp64 off ulong v ulong to void |
| 68 | for i ulong 8 |
| 69 | put nvpar add off i uchar and shr v mul i 8 255 |
| 70 | end |
| 71 | end |
| 72 | fn npg64 off ulong to ulong |
| 73 | v = ulong 0 |
| 74 | for i ulong 8 |
| 75 | v = or v shl ulong get nvpar add off i mul i 8 |
| 76 | end |
| 77 | ret v |
| 78 | end |
| 79 | fn npuuid to void |
| 80 | npzero |
| 81 | for i ulong 16 |
| 82 | put nvpar i get nvuuid i |
| 83 | end |
| 84 | end |
| 85 | fn ncget off ulong to uint |
| 86 | v = uint 0 |
| 87 | for i ulong 4 |
| 88 | v = or v shl uint get nvcard add off i mul i 8 |
| 89 | end |
| 90 | ret v |
| 91 | end |
| 92 | fn nhzero to void |
| 93 | for i ulong len nvhdr |
| 94 | put nvhdr i 0 |
| 95 | end |
| 96 | end |
| 97 | fn npzero to void |
| 98 | for i ulong len nvpar |
| 99 | put nvpar i 0 |
| 100 | end |
| 101 | end |
| 102 | fn nvos r long status uint to bool |
| 103 | if ne r 0 |
| 104 | put nverr 0 r |
| 105 | ret false |
| 106 | end |
| 107 | if ne status 0 |
| 108 | put nverr 0 long status |
| 109 | ret false |
| 110 | end |
| 111 | ret true |
| 112 | end |
| 113 | fn nvalc parent uint cls uint n ulong to uint |
| 114 | nhzero |
| 115 | nhput 0 get nvobj 0 |
| 116 | nhput 4 parent |
| 117 | if ne cls 65 |
| 118 | if eq get nvseq 0 4294967295 |
| 119 | put nverr 0 neg long 75 |
| 120 | ret 0 |
| 121 | end |
| 122 | nhput 8 get nvseq 0 |
| 123 | put nvseq 0 add get nvseq 0 1 |
| 124 | end |
| 125 | nhput 12 cls |
| 126 | r = devcall get nvfd 0 uint 3223340587 nvhdr 0 32 nvpar 0 n |
| 127 | if not nvos r nhget 28 |
| 128 | ret 0 |
| 129 | end |
| 130 | ret nhget 8 |
| 131 | end |
| 132 | fn nvctrl obj uint cmd uint n ulong to bool |
| 133 | nhzero |
| 134 | nhput 0 get nvobj 0 |
| 135 | nhput 4 obj |
| 136 | nhput 8 cmd |
| 137 | r = devcall get nvfd 0 uint 3223340586 nvhdr 0 32 nvpar 0 n |
| 138 | ret nvos r nhget 28 |
| 139 | end |
| 140 | fn nvfree parent uint obj uint to bool |
| 141 | if eq obj 0 |
| 142 | ret true |
| 143 | end |
| 144 | nhzero |
| 145 | nhput 0 get nvobj 0 |
| 146 | nhput 4 parent |
| 147 | nhput 8 obj |
| 148 | r = devctl get nvfd 0 uint 3222292009 nvhdr 0 16 |
| 149 | ret nvos r nhget 12 |
| 150 | end |
| 151 | fn nvstop to bool |
| 152 | if eq get nvstate 0 0 |
| 153 | ret true |
| 154 | end |
| 155 | if eq get nvstate 0 2 |
| 156 | ret nvmapfinish |
| 157 | end |
| 158 | ok = true |
| 159 | if nvchstop |
| 160 | if not nvmclose |
| 161 | ok = false |
| 162 | end |
| 163 | else |
| 164 | ok = false |
| 165 | end |
| 166 | if gt get nvbar 0 0 |
| 167 | r = mapdrop get nvbar 0 |
| 168 | if ne r 0 |
| 169 | put nverr 0 r |
| 170 | ok = false |
| 171 | else |
| 172 | put nvbar 0 0 |
| 173 | end |
| 174 | end |
| 175 | if ne get nvobj 5 0 |
| 176 | if not nvfree get nvobj 2 get nvobj 5 |
| 177 | ok = false |
| 178 | end |
| 179 | put nvobj 5 0 |
| 180 | end |
| 181 | if ne get nvreg 1 0 |
| 182 | npuuid |
| 183 | r = uvmctl get nvfd 2 uint 26 nvpar 0 20 |
| 184 | if not nvos r npget 16 |
| 185 | ok = false |
| 186 | end |
| 187 | put nvreg 1 0 |
| 188 | end |
| 189 | if ne get nvreg 0 0 |
| 190 | npuuid |
| 191 | r = uvmctl get nvfd 2 uint 38 nvpar 0 20 |
| 192 | if not nvos r npget 16 |
| 193 | ok = false |
| 194 | end |
| 195 | put nvreg 0 0 |
| 196 | end |
| 197 | if ne get nvobj 4 0 |
| 198 | if not nvfree get nvobj 1 get nvobj 4 |
| 199 | ok = false |
| 200 | end |
| 201 | put nvobj 4 0 |
| 202 | end |
| 203 | if ne get nvobj 3 0 |
| 204 | if not nvfree get nvobj 1 get nvobj 3 |
| 205 | ok = false |
| 206 | end |
| 207 | put nvobj 3 0 |
| 208 | end |
| 209 | if ne get nvobj 2 0 |
| 210 | if not nvfree get nvobj 1 get nvobj 2 |
| 211 | ok = false |
| 212 | end |
| 213 | put nvobj 2 0 |
| 214 | end |
| 215 | if ne get nvobj 1 0 |
| 216 | if not nvfree get nvobj 0 get nvobj 1 |
| 217 | ok = false |
| 218 | end |
| 219 | put nvobj 1 0 |
| 220 | end |
| 221 | if ne get nvobj 0 0 |
| 222 | if not nvfree get nvobj 0 get nvobj 0 |
| 223 | ok = false |
| 224 | end |
| 225 | put nvobj 0 0 |
| 226 | end |
| 227 | for j ulong len nvfd |
| 228 | i = sub 3 j |
| 229 | if ge get nvfd i 0 |
| 230 | if ne fclose get nvfd i 0 |
| 231 | ok = false |
| 232 | end |
| 233 | put nvfd i neg int 1 |
| 234 | end |
| 235 | end |
| 236 | note Close is attempted once per descriptor. Never repeat driver calls after this phase. |
| 237 | put nvstate 0 2 |
| 238 | put nvsched 0 0 |
| 239 | if not nvmapfinish |
| 240 | ok = false |
| 241 | end |
| 242 | if not ok |
| 243 | put nvfault 0 1 |
| 244 | end |
| 245 | ret ok |
| 246 | end |
| 247 | note The driver descriptors are closed; only owned CPU mappings may be retried here. |
| 248 | fn nvmapfinish to bool |
| 249 | if ne get nvstate 0 2 |
| 250 | put nverr 0 neg long 16 |
| 251 | ret false |
| 252 | end |
| 253 | ok = true |
| 254 | if gt get nvunpub 0 0 |
| 255 | r = mapdrop get nvunpub 0 |
| 256 | if ne r 0 |
| 257 | put nverr 0 r |
| 258 | ok = false |
| 259 | else |
| 260 | put nvunpub 0 0 |
| 261 | end |
| 262 | end |
| 263 | if gt get nvbar 0 0 |
| 264 | r = mapdrop get nvbar 0 |
| 265 | if ne r 0 |
| 266 | put nverr 0 r |
| 267 | ok = false |
| 268 | else |
| 269 | put nvbar 0 0 |
| 270 | end |
| 271 | end |
| 272 | if gt get nvchva 0 0 |
| 273 | r = mapdrop get nvchva 0 |
| 274 | if ne r 0 |
| 275 | put nverr 0 r |
| 276 | ok = false |
| 277 | else |
| 278 | put nvchva 0 0 |
| 279 | end |
| 280 | end |
| 281 | if not nvmforce |
| 282 | ok = false |
| 283 | end |
| 284 | if not ok |
| 285 | put nvfault 0 1 |
| 286 | ret false |
| 287 | end |
| 288 | note Descriptor closure retired every driver object, including a refused channel teardown. |
| 289 | for i ulong len nvobj |
| 290 | put nvobj i 0 |
| 291 | end |
| 292 | for i ulong len nvreg |
| 293 | put nvreg i 0 |
| 294 | end |
| 295 | put nvchreg 0 0 |
| 296 | put nvput 0 0 |
| 297 | put nvret 0 0 |
| 298 | put nvfifo 0 0 |
| 299 | put nvnotify 0 0 |
| 300 | put nvstate 0 0 |
| 301 | ret true |
| 302 | end |
| 303 | fn nvstart to bool |
| 304 | if ne get nvfault 0 0 |
| 305 | put nverr 0 neg long 5 |
| 306 | ret false |
| 307 | end |
| 308 | if ne get nvstate 0 0 |
| 309 | put nverr 0 neg long 16 |
| 310 | ret false |
| 311 | end |
| 312 | put nvstate 0 1 |
| 313 | put nvnext 0 68719476736 |
| 314 | for i ulong len nvfd |
| 315 | put nvfd i neg int 1 |
| 316 | end |
| 317 | for i ulong len nvobj |
| 318 | put nvobj i 0 |
| 319 | end |
| 320 | put nvseq 0 3472883713 |
| 321 | put nverr 0 0 |
| 322 | put nvstage 0 1 |
| 323 | r = fopen nvctl 0 len nvctl 524290 0 |
| 324 | if lt r 0 |
| 325 | put nverr 0 r |
| 326 | ret false |
| 327 | end |
| 328 | put nvfd 0 int r |
| 329 | put nvstage 0 2 |
| 330 | npzero |
| 331 | root = nvalc 0 65 0 |
| 332 | if eq root 0 |
| 333 | ret false |
| 334 | end |
| 335 | put nvobj 0 root |
| 336 | put nvstage 0 3 |
| 337 | for i ulong len nvcard |
| 338 | put nvcard i 0 |
| 339 | end |
| 340 | r = devctl get nvfd 0 uint 3523233480 nvcard 0 4608 |
| 341 | if not nvos r 0 |
| 342 | ret false |
| 343 | end |
| 344 | found = uint 0 |
| 345 | for i ulong 64 |
| 346 | off = mul i 72 |
| 347 | if ne get nvcard off 0 |
| 348 | found = add found 1 |
| 349 | if ne ncget add off 56 0 |
| 350 | put nverr 0 neg long 19 |
| 351 | ret false |
| 352 | end |
| 353 | put nvid 0 ncget add off 16 |
| 354 | end |
| 355 | end |
| 356 | if ne found 1 |
| 357 | put nverr 0 neg long 19 |
| 358 | ret false |
| 359 | end |
| 360 | put nvstage 0 4 |
| 361 | r = fopen nvdev 0 len nvdev 524290 0 |
| 362 | if lt r 0 |
| 363 | put nverr 0 r |
| 364 | ret false |
| 365 | end |
| 366 | put nvfd 1 int r |
| 367 | npzero |
| 368 | npput 0 uint get nvfd 0 |
| 369 | r = devctl get nvfd 1 uint 3221505737 nvpar 0 4 |
| 370 | if not nvos r 0 |
| 371 | ret false |
| 372 | end |
| 373 | put nvstage 0 5 |
| 374 | npzero |
| 375 | npput 0 get nvid 0 |
| 376 | if not nvctrl root 517 32 |
| 377 | ret false |
| 378 | end |
| 379 | put nvinst 0 npget 8 |
| 380 | put nvstage 0 6 |
| 381 | npzero |
| 382 | npput 0 get nvinst 0 |
| 383 | npput 4 root |
| 384 | dev = nvalc root 128 56 |
| 385 | if eq dev 0 |
| 386 | ret false |
| 387 | end |
| 388 | put nvobj 1 dev |
| 389 | put nvstage 0 7 |
| 390 | npzero |
| 391 | subd = nvalc dev 8320 4 |
| 392 | if eq subd 0 |
| 393 | ret false |
| 394 | end |
| 395 | put nvobj 2 subd |
| 396 | put nvstage 0 8 |
| 397 | npzero |
| 398 | if not nvctrl dev 8389266 804 |
| 399 | ret false |
| 400 | end |
| 401 | n = npget 0 |
| 402 | if gt n 200 |
| 403 | put nverr 0 neg long 75 |
| 404 | ret false |
| 405 | end |
| 406 | for i ulong 3 |
| 407 | put nvcls i 0 |
| 408 | end |
| 409 | for i ulong ulong n |
| 410 | c = npget add 4 mul i 4 |
| 411 | if eq c 52928 |
| 412 | put nvcls 0 c |
| 413 | end |
| 414 | if eq c 51567 |
| 415 | put nvcls 1 c |
| 416 | end |
| 417 | if eq c 50017 |
| 418 | put nvcls 2 c |
| 419 | end |
| 420 | end |
| 421 | for i ulong 3 |
| 422 | if eq get nvcls i 0 |
| 423 | put nverr 0 neg long 19 |
| 424 | ret false |
| 425 | end |
| 426 | end |
| 427 | put nvstage 0 9 |
| 428 | npzero |
| 429 | npput 0 1 |
| 430 | npput 4 12 |
| 431 | if not nvctrl subd 545264168 488 |
| 432 | ret false |
| 433 | end |
| 434 | put nvsm 0 npget 8 |
| 435 | note RM reports SM10.04 on GB10; CUDA target sm121 uses a different numbering contract. |
| 436 | note Matches canonical evidence/m16-blackwell-native-path-requalification-receipt.json. |
| 437 | if ne get nvsm 0 2564 |
| 438 | put nverr 0 neg long 19 |
| 439 | ret false |
| 440 | end |
| 441 | put nvstage 0 10 |
| 442 | ret true |
| 443 | end |
| 444 | |
| 445 | note Low GPU command addresses are reserved without replacement before an owned bind. |
| 446 | note BAR mappings may use Linux-selected addresses; GPU buffers stay below 40 bits. |
| 447 | fn nvcpumap obj uint size ulong system bool flags uint to long |
| 448 | if or ne get nvfault 0 0 ne get nvstate 0 1 |
| 449 | put nverr 0 neg long 5 |
| 450 | ret neg long 1 |
| 451 | end |
| 452 | fd = neg long 1 |
| 453 | if system |
| 454 | fd = fopen nvctl 0 len nvctl 524290 0 |
| 455 | else |
| 456 | fd = fopen nvdev 0 len nvdev 524290 0 |
| 457 | end |
| 458 | if lt fd 0 |
| 459 | put nverr 0 fd |
| 460 | ret fd |
| 461 | end |
| 462 | if not system |
| 463 | npzero |
| 464 | npput 0 uint get nvfd 0 |
| 465 | r = devctl int fd uint 3221505737 nvpar 0 4 |
| 466 | if not nvos r 0 |
| 467 | r = fclose int fd |
| 468 | ret neg long 1 |
| 469 | end |
| 470 | end |
| 471 | npzero |
| 472 | npput 0 get nvobj 0 |
| 473 | npput 4 get nvobj 1 |
| 474 | npput 8 obj |
| 475 | npp64 24 size |
| 476 | npput 44 flags |
| 477 | npput 48 uint fd |
| 478 | r = devctl get nvfd 0 uint 3224913486 nvpar 0 56 |
| 479 | if not nvos r npget 40 |
| 480 | r = fclose int fd |
| 481 | ret neg long 1 |
| 482 | end |
| 483 | m = neg long 1 |
| 484 | if system |
| 485 | if gt get nvnext 0 sub 1099511627776 size |
| 486 | put nverr 0 neg long 75 |
| 487 | r = fclose int fd |
| 488 | ret neg long 1 |
| 489 | end |
| 490 | m = maphold get nvnext 0 size |
| 491 | if gt m 0 |
| 492 | put nvnext 0 add get nvnext 0 size |
| 493 | r = mapbind m int fd 0 3 |
| 494 | if ne r 0 |
| 495 | m = r |
| 496 | end |
| 497 | end |
| 498 | else |
| 499 | m = mapnew int fd 0 size 3 1 |
| 500 | end |
| 501 | r = fclose int fd |
| 502 | if ne r 0 |
| 503 | put nverr 0 r |
| 504 | put nvfault 0 1 |
| 505 | if gt m 0 |
| 506 | r = mapdrop m |
| 507 | if ne r 0 |
| 508 | put nvunpub 0 m |
| 509 | end |
| 510 | end |
| 511 | ret neg long 1 |
| 512 | end |
| 513 | if lt m 0 |
| 514 | put nverr 0 m |
| 515 | end |
| 516 | ret m |
| 517 | end |
| 518 | |
| 519 | note Release flags change only after confirmed acceptance. Failed entries stay quarantined. |
| 520 | fn nvmrel slot ulong to bool |
| 521 | f = get nvmflag slot |
| 522 | if ne and f 4 0 |
| 523 | npzero |
| 524 | npp64 0 get nvmaddr slot |
| 525 | npp64 8 get nvmlen slot |
| 526 | r = uvmctl get nvfd 2 uint 34 nvpar 0 24 |
| 527 | if not nvos r npget 16 |
| 528 | put nvfault 0 1 |
| 529 | ret false |
| 530 | end |
| 531 | f = and f 251 |
| 532 | put nvmflag slot f |
| 533 | end |
| 534 | if ne and f 8 0 |
| 535 | npzero |
| 536 | npput 0 get nvobj 0 |
| 537 | npput 4 get nvobj 1 |
| 538 | npput 8 get nvobj 3 |
| 539 | npput 12 get nvmobj slot |
| 540 | npp64 24 get nvmaddr slot |
| 541 | npp64 32 get nvmlen slot |
| 542 | r = devctl get nvfd 0 uint 3224389208 nvpar 0 48 |
| 543 | if not nvos r npget 40 |
| 544 | put nvfault 0 1 |
| 545 | ret false |
| 546 | end |
| 547 | f = and f 247 |
| 548 | put nvmflag slot f |
| 549 | end |
| 550 | if ne and f 1 0 |
| 551 | if not nvfree get nvobj 1 get nvmobj slot |
| 552 | put nvfault 0 1 |
| 553 | ret false |
| 554 | end |
| 555 | f = and f 254 |
| 556 | put nvmflag slot f |
| 557 | end |
| 558 | if ne and f 2 0 |
| 559 | r = mapdrop get nvmmap slot |
| 560 | if not nvos r 0 |
| 561 | put nvfault 0 1 |
| 562 | ret false |
| 563 | end |
| 564 | end |
| 565 | put nvmflag slot 0 |
| 566 | put nvmobj slot 0 |
| 567 | put nvmmap slot 0 |
| 568 | put nvmaddr slot 0 |
| 569 | put nvmlen slot 0 |
| 570 | ret true |
| 571 | end |
| 572 | fn nvmclose to bool |
| 573 | ok = true |
| 574 | for i ulong len nvmflag |
| 575 | if ne get nvmflag i 0 |
| 576 | if not nvmrel i |
| 577 | ok = false |
| 578 | end |
| 579 | end |
| 580 | end |
| 581 | ret ok |
| 582 | end |
| 583 | note Called only after the owning driver context is closed, including error teardown. |
| 584 | fn nvmforce to bool |
| 585 | if ne get nvstate 0 2 |
| 586 | put nverr 0 neg long 16 |
| 587 | ret false |
| 588 | end |
| 589 | ok = true |
| 590 | for i ulong len nvmflag |
| 591 | note Driver-owned flags and handles retired when the descriptors closed. |
| 592 | put nvmflag i and get nvmflag i 2 |
| 593 | put nvmobj i 0 |
| 594 | if ne and get nvmflag i 2 0 |
| 595 | r = mapdrop get nvmmap i |
| 596 | if ne r 0 |
| 597 | put nverr 0 r |
| 598 | ok = false |
| 599 | else |
| 600 | put nvmflag i 0 |
| 601 | put nvmmap i 0 |
| 602 | put nvmaddr i 0 |
| 603 | put nvmlen i 0 |
| 604 | end |
| 605 | else |
| 606 | put nvmmap i 0 |
| 607 | put nvmaddr i 0 |
| 608 | put nvmlen i 0 |
| 609 | end |
| 610 | end |
| 611 | ret ok |
| 612 | end |
| 613 | fn nvdrop m long to bool |
| 614 | if ne get nvput 0 get nvret 0 |
| 615 | put nverr 0 neg long 16 |
| 616 | ret false |
| 617 | end |
| 618 | if and ne get nvobj 8 0 or eq m get nvfifo 0 eq m get nvnotify 0 |
| 619 | put nverr 0 neg long 16 |
| 620 | ret false |
| 621 | end |
| 622 | for i ulong len nvmmap |
| 623 | if and gt m 0 eq get nvmmap i m |
| 624 | ret nvmrel i |
| 625 | end |
| 626 | end |
| 627 | put nverr 0 neg long 22 |
| 628 | ret false |
| 629 | end |
| 630 | fn nvalloc want ulong cached bool to long |
| 631 | if or eq get nvreg 1 0 ne get nvfault 0 0 |
| 632 | put nverr 0 neg long 5 |
| 633 | ret neg long 1 |
| 634 | end |
| 635 | if or eq want 0 gt want 68719476736 |
| 636 | put nverr 0 neg long 22 |
| 637 | ret neg long 1 |
| 638 | end |
| 639 | size = mul div add want 4095 4096 4096 |
| 640 | slot = ulong 96 |
| 641 | for i ulong 96 |
| 642 | if and eq slot 96 eq get nvmflag i 0 |
| 643 | slot = i |
| 644 | end |
| 645 | end |
| 646 | if eq slot 96 |
| 647 | put nverr 0 neg long 24 |
| 648 | ret neg long 1 |
| 649 | end |
| 650 | put nvstage 0 21 |
| 651 | npzero |
| 652 | npput 0 get nvobj 0 |
| 653 | npput 8 49409 |
| 654 | npput 24 436207616 |
| 655 | attr = uint 9 |
| 656 | if cached |
| 657 | attr = 5 |
| 658 | end |
| 659 | npput 28 attr |
| 660 | npput 32 6 |
| 661 | npp64 64 size |
| 662 | npp64 72 4096 |
| 663 | npp64 88 sub size 1 |
| 664 | h = nvalc get nvobj 1 62 128 |
| 665 | if eq h 0 |
| 666 | put nvfault 0 1 |
| 667 | ret neg long 1 |
| 668 | end |
| 669 | put nvmobj slot h |
| 670 | put nvmlen slot size |
| 671 | put nvmflag slot 1 |
| 672 | put nvstage 0 22 |
| 673 | m = nvcpumap h size true 0 |
| 674 | if le m 0 |
| 675 | put nvfault 0 1 |
| 676 | ret neg long 1 |
| 677 | end |
| 678 | put nvmmap slot m |
| 679 | put nvmaddr slot mapaddr m |
| 680 | put nvmflag slot 3 |
| 681 | va = get nvmaddr slot |
| 682 | if or ne and va 4095 0 gt va sub 562949869535232 size |
| 683 | put nverr 0 neg long 75 |
| 684 | put nvfault 0 1 |
| 685 | ret neg long 1 |
| 686 | end |
| 687 | put nvstage 0 23 |
| 688 | npzero |
| 689 | npp64 0 va |
| 690 | npp64 8 size |
| 691 | r = uvmctl get nvfd 2 uint 73 nvpar 0 24 |
| 692 | if not nvos r npget 16 |
| 693 | put nvfault 0 1 |
| 694 | ret neg long 1 |
| 695 | end |
| 696 | put nvmflag slot 7 |
| 697 | put nvstage 0 24 |
| 698 | npzero |
| 699 | npput 0 get nvobj 0 |
| 700 | npput 4 get nvobj 1 |
| 701 | npput 8 get nvobj 3 |
| 702 | npput 12 h |
| 703 | npp64 24 size |
| 704 | npput 32 33040 |
| 705 | npp64 48 va |
| 706 | r = devctl get nvfd 0 uint 3225437783 nvpar 0 64 |
| 707 | if not nvos r npget 56 |
| 708 | put nvfault 0 1 |
| 709 | ret neg long 1 |
| 710 | end |
| 711 | put nvmflag slot 15 |
| 712 | if ne npg64 48 va |
| 713 | put nverr 0 neg long 22 |
| 714 | put nvfault 0 1 |
| 715 | ret neg long 1 |
| 716 | end |
| 717 | put nvstage 0 25 |
| 718 | npzero |
| 719 | npp64 0 va |
| 720 | npp64 8 size |
| 721 | for i ulong 16 |
| 722 | put nvpar add i 24 get nvuuid i |
| 723 | end |
| 724 | npput 40 1 |
| 725 | npp64 9240 1 |
| 726 | npput 9248 uint get nvfd 0 |
| 727 | npput 9252 get nvobj 0 |
| 728 | npput 9256 h |
| 729 | r = uvmctl get nvfd 2 uint 33 nvpar 0 9264 |
| 730 | if not nvos r npget 9260 |
| 731 | put nvfault 0 1 |
| 732 | ret neg long 1 |
| 733 | end |
| 734 | npzero |
| 735 | off = ulong 0 |
| 736 | while lt off size |
| 737 | n = sub size off |
| 738 | if gt n 16384 |
| 739 | n = ulong 16384 |
| 740 | end |
| 741 | r = mapwrite m off nvpar 0 n |
| 742 | off = add off n |
| 743 | end |
| 744 | put nvstage 0 26 |
| 745 | ret m |
| 746 | end |
| 747 | |
| 748 | note Register this private GPU virtual address space with UVM, no buffers or kernels. |
| 749 | fn nvfull to bool |
| 750 | if not nvstart |
| 751 | ret false |
| 752 | end |
| 753 | put nvstage 0 11 |
| 754 | for i ulong 2 |
| 755 | r = fopen nvuvm 0 len nvuvm 524290 0 |
| 756 | if lt r 0 |
| 757 | put nverr 0 r |
| 758 | ret false |
| 759 | end |
| 760 | put nvfd add i 2 int r |
| 761 | end |
| 762 | npzero |
| 763 | r = uvmctl get nvfd 2 uint 805306369 nvpar 0 16 |
| 764 | if not nvos r npget 8 |
| 765 | ret false |
| 766 | end |
| 767 | put nvstage 0 12 |
| 768 | npzero |
| 769 | npput 0 uint get nvfd 2 |
| 770 | r = uvmctl get nvfd 3 uint 75 nvpar 0 8 |
| 771 | if ne r 0 |
| 772 | put nverr 0 r |
| 773 | ret false |
| 774 | end |
| 775 | note Driver platforms may return NV_WARN_NOTHING_TO_DO. Retain the returned status. |
| 776 | put nvmm 0 npget 4 |
| 777 | if and ne get nvmm 0 0 ne get nvmm 0 65542 |
| 778 | put nverr 0 long get nvmm 0 |
| 779 | ret false |
| 780 | end |
| 781 | put nvstage 0 13 |
| 782 | npzero |
| 783 | npp64 8 562949953421311 |
| 784 | v = nvalc get nvobj 1 112 24 |
| 785 | if eq v 0 |
| 786 | ret false |
| 787 | end |
| 788 | put nvobj 3 v |
| 789 | put nvstage 0 14 |
| 790 | npzero |
| 791 | npput 4 72 |
| 792 | npp64 8 562949869535232 |
| 793 | npp64 40 4096 |
| 794 | v = nvalc get nvobj 1 37105 56 |
| 795 | if eq v 0 |
| 796 | ret false |
| 797 | end |
| 798 | put nvobj 4 v |
| 799 | put nvstage 0 15 |
| 800 | npzero |
| 801 | npput 4 2 |
| 802 | npput 8 16 |
| 803 | if not nvctrl get nvobj 2 545259850 268 |
| 804 | ret false |
| 805 | end |
| 806 | if ne npget 8 16 |
| 807 | put nverr 0 neg long 22 |
| 808 | ret false |
| 809 | end |
| 810 | for i ulong 16 |
| 811 | put nvuuid i get nvpar add i 12 |
| 812 | end |
| 813 | npuuid |
| 814 | npput 24 4294967295 |
| 815 | r = uvmctl get nvfd 2 uint 37 nvpar 0 40 |
| 816 | if not nvos r npget 36 |
| 817 | ret false |
| 818 | end |
| 819 | put nvreg 0 1 |
| 820 | put nvstage 0 16 |
| 821 | npuuid |
| 822 | npput 16 uint get nvfd 0 |
| 823 | npput 20 get nvobj 0 |
| 824 | npput 24 get nvobj 4 |
| 825 | r = uvmctl get nvfd 2 uint 25 nvpar 0 32 |
| 826 | if not nvos r npget 28 |
| 827 | ret false |
| 828 | end |
| 829 | put nvreg 1 1 |
| 830 | put nvstage 0 17 |
| 831 | ret true |
| 832 | end |
| 833 | |
| 834 | fn nvfind m long to ulong |
| 835 | for i ulong len nvmmap |
| 836 | if and gt m 0 eq get nvmmap i m |
| 837 | ret i |
| 838 | end |
| 839 | end |
| 840 | ret 96 |
| 841 | end |
| 842 | note Reverse partial channel construction before releasing its buffers or address space. |
| 843 | fn nvchstop to bool |
| 844 | if ne get nvchreg 0 0 |
| 845 | npuuid |
| 846 | npput 16 get nvobj 0 |
| 847 | npput 20 get nvobj 8 |
| 848 | r = uvmctl get nvfd 2 uint 28 nvpar 0 28 |
| 849 | if not nvos r npget 24 |
| 850 | put nvfault 0 1 |
| 851 | ret false |
| 852 | end |
| 853 | put nvchreg 0 0 |
| 854 | end |
| 855 | for i ulong 4 |
| 856 | obj = sub 9 i |
| 857 | parent = ulong 6 |
| 858 | if eq obj 9 |
| 859 | parent = ulong 8 |
| 860 | end |
| 861 | if eq obj 6 |
| 862 | parent = ulong 1 |
| 863 | end |
| 864 | if ne get nvobj obj 0 |
| 865 | if not nvfree get nvobj parent get nvobj obj |
| 866 | put nvfault 0 1 |
| 867 | ret false |
| 868 | end |
| 869 | put nvobj obj 0 |
| 870 | end |
| 871 | end |
| 872 | if gt get nvchva 0 0 |
| 873 | r = mapdrop get nvchva 0 |
| 874 | if not nvos r 0 |
| 875 | put nvfault 0 1 |
| 876 | ret false |
| 877 | end |
| 878 | put nvchva 0 0 |
| 879 | end |
| 880 | put nvsched 0 0 |
| 881 | put nvput 0 0 |
| 882 | put nvret 0 0 |
| 883 | put nvfifo 0 0 |
| 884 | put nvnotify 0 0 |
| 885 | ret true |
| 886 | end |
| 887 | |
| 888 | note Empty queue creation and scheduling; this routine submits no command packets. |
| 889 | fn nvchan to bool |
| 890 | if or eq get nvreg 1 0 ne get nvfault 0 0 |
| 891 | put nverr 0 neg long 16 |
| 892 | ret false |
| 893 | end |
| 894 | if or ne get nvobj 6 0 ne get nvobj 5 0 |
| 895 | put nverr 0 neg long 16 |
| 896 | ret false |
| 897 | end |
| 898 | put nvstage 0 31 |
| 899 | npzero |
| 900 | u = nvalc get nvobj 2 50017 0 |
| 901 | if eq u 0 |
| 902 | ret false |
| 903 | end |
| 904 | put nvobj 5 u |
| 905 | m = nvcpumap u 65536 false 0 |
| 906 | if le m 0 |
| 907 | ret false |
| 908 | end |
| 909 | put nvbar 0 m |
| 910 | put nvstage 0 32 |
| 911 | npzero |
| 912 | npput 12 1 |
| 913 | g = nvalc get nvobj 1 41068 20 |
| 914 | if eq g 0 |
| 915 | ret false |
| 916 | end |
| 917 | put nvobj 6 g |
| 918 | put nvstage 0 33 |
| 919 | npzero |
| 920 | npput 0 get nvobj 4 |
| 921 | npput 4 1 |
| 922 | c = nvalc g 36967 12 |
| 923 | if eq c 0 |
| 924 | ret false |
| 925 | end |
| 926 | put nvobj 7 c |
| 927 | m = nvalloc 65536 false |
| 928 | if le m 0 |
| 929 | ret false |
| 930 | end |
| 931 | put nvfifo 0 m |
| 932 | m = nvalloc 1048576 true |
| 933 | if le m 0 |
| 934 | ret false |
| 935 | end |
| 936 | put nvnotify 0 m |
| 937 | put nvstage 0 34 |
| 938 | npzero |
| 939 | npput 0 get nvmobj nvfind get nvnotify 0 |
| 940 | npput 4 get nvmobj nvfind get nvfifo 0 |
| 941 | npp64 8 mapaddr get nvfifo 0 |
| 942 | npput 16 1024 |
| 943 | npput 24 c |
| 944 | npput 32 get nvmobj nvfind get nvfifo 0 |
| 945 | npp64 64 8192 |
| 946 | f = nvalc g 51567 368 |
| 947 | if eq f 0 |
| 948 | ret false |
| 949 | end |
| 950 | put nvobj 8 f |
| 951 | put nvstage 0 35 |
| 952 | npzero |
| 953 | put nvretry 0 0 |
| 954 | k = nvalc f 52928 0 |
| 955 | while eq k 0 |
| 956 | if or ne get nverr 0 81 ge get nvretry 0 50 |
| 957 | ret false |
| 958 | end |
| 959 | put nvretry 0 add get nvretry 0 1 |
| 960 | r = sleepns long 100000000 |
| 961 | if ne r 0 |
| 962 | put nverr 0 r |
| 963 | ret false |
| 964 | end |
| 965 | k = nvalc f 52928 0 |
| 966 | end |
| 967 | put nvobj 9 k |
| 968 | put nverr 0 0 |
| 969 | put nvstage 0 36 |
| 970 | npzero |
| 971 | npput 0 4294967295 |
| 972 | if not nvctrl f 3278831880 4 |
| 973 | ret false |
| 974 | end |
| 975 | put nvtoken 0 npget 0 |
| 976 | put nvstage 0 37 |
| 977 | if gt get nvnext 0 1099444518912 |
| 978 | put nverr 0 neg long 75 |
| 979 | ret false |
| 980 | end |
| 981 | v = maphold get nvnext 0 67108864 |
| 982 | if le v 0 |
| 983 | put nverr 0 v |
| 984 | ret false |
| 985 | end |
| 986 | put nvchva 0 v |
| 987 | put nvnext 0 add get nvnext 0 67108864 |
| 988 | npuuid |
| 989 | npput 16 uint get nvfd 0 |
| 990 | npput 20 get nvobj 0 |
| 991 | npput 24 f |
| 992 | npp64 32 mapaddr v |
| 993 | npp64 40 67108864 |
| 994 | r = uvmctl get nvfd 2 uint 27 nvpar 0 56 |
| 995 | if not nvos r npget 48 |
| 996 | ret false |
| 997 | end |
| 998 | put nvchreg 0 1 |
| 999 | put nvstage 0 38 |
| 1000 | npzero |
| 1001 | put nvpar 0 1 |
| 1002 | if not nvctrl g 2691432705 3 |
| 1003 | ret false |
| 1004 | end |
| 1005 | put nvsched 0 1 |
| 1006 | put nvstage 0 39 |
| 1007 | ret true |
| 1008 | end |
| 1009 | |
| 1010 | note One outstanding packet. Completion must be observed before reuse or any buffer release. |
| 1011 | fn nvsend m long off ulong words uint to bool |
| 1012 | if or ne get nvfault 0 0 eq get nvsched 0 0 |
| 1013 | put nverr 0 neg long 5 |
| 1014 | ret false |
| 1015 | end |
| 1016 | if ne get nvput 0 get nvret 0 |
| 1017 | put nverr 0 neg long 16 |
| 1018 | ret false |
| 1019 | end |
| 1020 | s = nvfind m |
| 1021 | if eq s 96 |
| 1022 | put nverr 0 neg long 22 |
| 1023 | ret false |
| 1024 | end |
| 1025 | if or or eq words 0 gt words 2097151 ne and off 3 0 |
| 1026 | put nverr 0 neg long 22 |
| 1027 | ret false |
| 1028 | end |
| 1029 | size = get nvmlen s |
| 1030 | if gt off size |
| 1031 | put nverr 0 neg long 22 |
| 1032 | ret false |
| 1033 | end |
| 1034 | if gt mul ulong words 4 sub size off |
| 1035 | put nverr 0 neg long 22 |
| 1036 | ret false |
| 1037 | end |
| 1038 | va = add get nvmaddr s off |
| 1039 | if ge va 1099511627776 |
| 1040 | put nverr 0 neg long 75 |
| 1041 | ret false |
| 1042 | end |
| 1043 | p = get nvput 0 |
| 1044 | if eq p 18446744073709551615 |
| 1045 | put nverr 0 neg long 75 |
| 1046 | ret false |
| 1047 | end |
| 1048 | entry = or or va shl ulong words 42 2199023255552 |
| 1049 | ret nvpush p entry |
| 1050 | end |
| 1051 | fn nvpush p ulong entry ulong to bool |
| 1052 | r = mapset get nvfifo 0 mul rem p 1024 8 8 entry |
| 1053 | p = add p 1 |
| 1054 | put nvput 0 p |
| 1055 | r = mapset get nvfifo 0 8332 4 rem p 1024 |
| 1056 | r = mapset get nvbar 0 144 4 ulong get nvtoken 0 |
| 1057 | ret true |
| 1058 | end |
| 1059 | |
| 1060 | fn nvwait m long off ulong value uint budget ulong to bool |
| 1061 | if or ne get nvfault 0 0 eq get nvsched 0 0 |
| 1062 | put nverr 0 neg long 22 |
| 1063 | ret false |
| 1064 | end |
| 1065 | if eq get nvput 0 get nvret 0 |
| 1066 | put nverr 0 neg long 22 |
| 1067 | ret false |
| 1068 | end |
| 1069 | s = nvfind m |
| 1070 | if or eq s 96 or eq budget 0 gt budget 30000000000 |
| 1071 | put nverr 0 neg long 22 |
| 1072 | ret false |
| 1073 | end |
| 1074 | size = get nvmlen s |
| 1075 | if or gt off sub size 4 ne and off 3 0 |
| 1076 | put nverr 0 neg long 22 |
| 1077 | ret false |
| 1078 | end |
| 1079 | start = monons |
| 1080 | if lt start 0 |
| 1081 | put nverr 0 start |
| 1082 | put nvfault 0 1 |
| 1083 | ret false |
| 1084 | end |
| 1085 | while true |
| 1086 | if eq mapget m off 4 ulong value |
| 1087 | put nvret 0 get nvput 0 |
| 1088 | ret true |
| 1089 | end |
| 1090 | now = monons |
| 1091 | if or lt now start ge sub now start long budget |
| 1092 | put nverr 0 neg long 110 |
| 1093 | put nvfault 0 1 |
| 1094 | ret false |
| 1095 | end |
| 1096 | r = sleepns long 100000 |
| 1097 | if ne r 0 |
| 1098 | put nverr 0 r |
| 1099 | put nvfault 0 1 |
| 1100 | ret false |
| 1101 | end |
| 1102 | end |
| 1103 | ret false |
| 1104 | end |