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
omega-mv / gpu / nvidia / driver / fx.om
| 1 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | note gpu/nvidia/driver/fx.om: the dx_ effects of client.om answered from a script and recorded, for the host |
| 3 | note gate (seqgate.om). It is the Omega twin of the recorder in the C oracle (seqoracle.c, outside this tree): |
| 4 | note the same event per effect, the same answers, the same failure script. Each effect is one event |
| 5 | note "NAME ARGS =RESULT;" appended to fo; request fields set with dx_fk and dx_fa are printed with the effect |
| 6 | note that sends them (" kKIND V V ..."). |
| 7 | note |
| 8 | note Script: the effects are numbered from 1 in the order they happen. Effect K (0: none) and the next effects |
| 9 | note of the same type, R in all, fail with flavour F, if their type can fail (fx_eff's nfl: how many flavours). |
| 10 | note Otherwise every effect succeeds with an answer derived from its number n: an RM handle 3238002688 + n |
| 11 | note (0xc1000000 + n), a GPU VA 137438953472 + n * 2^20, a usermode mapping 5497558138880 + n * 2^16, a file |
| 12 | note descriptor 10 + n, a work-submit token 4096 + n. A refused effect answers errno 5. |
| 13 | note Scenario of nvrm_open (fx_scen): the admitted SM, the SM the classes select, discrete, the class count. |
| 14 | note The card table the CARD_INFO answer fills holds the same record at every index i: PCI 0000:01:00.0, |
| 15 | note vendor 4318 (0x10de), device 11794 (0x2e12), gpu_id 256 + i, minor i; card_index answers 2. |
| 16 | |
| 17 | global fo uchar 65536 |
| 18 | note fz: 0 length of fo, 1 effects so far (n), 2 K, 3 F, 4 failures left (R), 5 type of effect K, 6 admitted SM, |
| 19 | note 7 selected SM, 8 discrete, 9 class count, 10 pending fill words, 11 fo overflowed, 12 a script the |
| 20 | note recorder cannot follow (a flavour the effect does not have, an unknown request value) |
| 21 | global fz ulong 16 |
| 22 | global ff ulong 64 |
| 23 | |
| 24 | fn fx_c c ulong to void |
| 25 | l = get fz 0 |
| 26 | if lt l 65536 |
| 27 | put fo l uchar c |
| 28 | put fz 0 add l 1 |
| 29 | else |
| 30 | put fz 11 1 |
| 31 | end |
| 32 | end |
| 33 | |
| 34 | fn fx_num v ulong to void |
| 35 | d = new uchar 20 0 |
| 36 | k = ulong 0 |
| 37 | x = v |
| 38 | while true bound 20 |
| 39 | put d k uchar add 48 rem x 10 |
| 40 | k = add k 1 |
| 41 | x = div x 10 |
| 42 | if eq x 0 |
| 43 | break |
| 44 | end |
| 45 | end |
| 46 | for j ulong k bound 20 |
| 47 | fx_c ulong get d sub sub k j 1 |
| 48 | end |
| 49 | end |
| 50 | |
| 51 | note " V" unsigned, " V" signed |
| 52 | fn fx_su v ulong to void |
| 53 | fx_c 32 |
| 54 | fx_num v |
| 55 | end |
| 56 | |
| 57 | fn fx_sd v long to void |
| 58 | fx_c 32 |
| 59 | if lt v 0 |
| 60 | fx_c 45 |
| 61 | fx_num ulong sub long 0 v |
| 62 | else |
| 63 | fx_num ulong v |
| 64 | end |
| 65 | end |
| 66 | |
| 67 | fn fx_semi to void |
| 68 | fx_c 59 |
| 69 | end |
| 70 | |
| 71 | note " =V;" unsigned and signed |
| 72 | fn fx_ru v ulong to void |
| 73 | fx_c 32 |
| 74 | fx_c 61 |
| 75 | fx_num v |
| 76 | fx_semi |
| 77 | end |
| 78 | |
| 79 | fn fx_rd v long to void |
| 80 | fx_c 32 |
| 81 | fx_c 61 |
| 82 | if lt v 0 |
| 83 | fx_c 45 |
| 84 | fx_num ulong sub long 0 v |
| 85 | else |
| 86 | fx_num ulong v |
| 87 | end |
| 88 | fx_semi |
| 89 | end |
| 90 | |
| 91 | note " =1;" when refused, " =0;" when not |
| 92 | fn fx_rf f long to void |
| 93 | if ge f 0 |
| 94 | fx_ru 1 |
| 95 | else |
| 96 | fx_ru 0 |
| 97 | end |
| 98 | end |
| 99 | |
| 100 | fn fx_reset k ulong f ulong r ulong to void |
| 101 | for i ulong 16 |
| 102 | put fz i 0 |
| 103 | end |
| 104 | put fz 2 k |
| 105 | put fz 3 f |
| 106 | put fz 4 r |
| 107 | end |
| 108 | |
| 109 | fn fx_scen asm ulong ssm ulong disc ulong ncls ulong to void |
| 110 | put fz 6 asm |
| 111 | put fz 7 ssm |
| 112 | put fz 8 disc |
| 113 | put fz 9 ncls |
| 114 | end |
| 115 | |
| 116 | note start effect of type t with nfl failure flavours, named c1 c2; the flavour when it fails, else -1 |
| 117 | fn fx_eff t ulong nfl ulong c1 ulong c2 ulong to long |
| 118 | n = add get fz 1 1 |
| 119 | put fz 1 n |
| 120 | k = get fz 2 |
| 121 | if and ne k 0 eq n k |
| 122 | put fz 5 t |
| 123 | end |
| 124 | fx_c c1 |
| 125 | fx_c c2 |
| 126 | hit = and gt nfl 0 ne k 0 |
| 127 | hit = and hit ge n k |
| 128 | hit = and hit gt get fz 4 0 |
| 129 | hit = and hit eq t get fz 5 |
| 130 | if hit |
| 131 | put fz 4 sub get fz 4 1 |
| 132 | if ge get fz 3 nfl |
| 133 | put fz 12 1 |
| 134 | end |
| 135 | ret long get fz 3 |
| 136 | end |
| 137 | ret -1 |
| 138 | end |
| 139 | |
| 140 | fn fx_n to ulong |
| 141 | ret get fz 1 |
| 142 | end |
| 143 | |
| 144 | note the pending request fields, then none |
| 145 | fn fx_fills to void |
| 146 | for i ulong get fz 10 bound 64 |
| 147 | v = get ff i |
| 148 | if ne shr v 63 0 |
| 149 | fx_c 32 |
| 150 | fx_c 107 |
| 151 | fx_num and v 255 |
| 152 | else |
| 153 | fx_su v |
| 154 | end |
| 155 | end |
| 156 | put fz 10 0 |
| 157 | end |
| 158 | |
| 159 | fn dx_fk kind ulong to void |
| 160 | n = get fz 10 |
| 161 | if lt n 64 |
| 162 | put ff n or 9223372036854775808 kind |
| 163 | put fz 10 add n 1 |
| 164 | else |
| 165 | put fz 12 1 |
| 166 | end |
| 167 | end |
| 168 | |
| 169 | fn dx_fa v ulong to void |
| 170 | n = get fz 10 |
| 171 | if lt n 64 |
| 172 | put ff n v |
| 173 | put fz 10 add n 1 |
| 174 | else |
| 175 | put fz 12 1 |
| 176 | end |
| 177 | end |
| 178 | |
| 179 | fn dx_errno to long |
| 180 | ret 5 |
| 181 | end |
| 182 | |
| 183 | fn dx_admit_open to bool |
| 184 | f = fx_eff 1 1 97 111 |
| 185 | fx_rf f |
| 186 | ret lt f 0 |
| 187 | end |
| 188 | |
| 189 | fn dx_slot to ulong |
| 190 | f = fx_eff 2 1 118 115 |
| 191 | b = ulong 68719476736 |
| 192 | if ge f 0 |
| 193 | b = ulong 0 |
| 194 | end |
| 195 | fx_ru b |
| 196 | ret b |
| 197 | end |
| 198 | |
| 199 | fn dx_recycle base ulong to void |
| 200 | f = fx_eff 20 0 114 99 |
| 201 | fx_su base |
| 202 | fx_semi |
| 203 | end |
| 204 | |
| 205 | note path 1 /dev/nvidiactl, 2 /dev/nvidia-uvm |
| 206 | fn dx_fopen path ulong to long |
| 207 | f = fx_eff 3 1 111 112 |
| 208 | fd = long add 10 fx_n |
| 209 | if ge f 0 |
| 210 | fd = long -1 |
| 211 | end |
| 212 | fx_su path |
| 213 | fx_rd fd |
| 214 | ret fd |
| 215 | end |
| 216 | |
| 217 | fn dx_fclose fd long to long |
| 218 | f = fx_eff 3 1 99 108 |
| 219 | fx_sd fd |
| 220 | fx_rf f |
| 221 | if ge f 0 |
| 222 | ret -1 |
| 223 | end |
| 224 | ret 0 |
| 225 | end |
| 226 | |
| 227 | note RM_ALLOC: the new handle, 0 when refused (last_rm_status: flavour 0 status 31, 1 NV_ERR_NO_MEMORY 81, 2 errno) |
| 228 | fn dx_alloc parent ulong cls ulong to ulong |
| 229 | f = fx_eff 4 3 97 108 |
| 230 | fx_su parent |
| 231 | fx_su cls |
| 232 | fx_fills |
| 233 | if ge f 0 |
| 234 | st = ulong 0 |
| 235 | if eq f 0 |
| 236 | st = ulong 31 |
| 237 | end |
| 238 | if eq f 1 |
| 239 | st = ulong 81 |
| 240 | end |
| 241 | cp CS_LRS st |
| 242 | fx_ru 0 |
| 243 | ret 0 |
| 244 | end |
| 245 | cp CS_LRS 0 |
| 246 | h = add 3238002688 fx_n |
| 247 | fx_ru h |
| 248 | ret h |
| 249 | end |
| 250 | |
| 251 | fn dx_free parent ulong obj ulong to bool |
| 252 | f = fx_eff 24 1 102 114 |
| 253 | fx_su parent |
| 254 | fx_su obj |
| 255 | fx_rf f |
| 256 | ret lt f 0 |
| 257 | end |
| 258 | |
| 259 | fn dx_ctrl obj ulong cmd ulong to bool |
| 260 | f = fx_eff 10 1 99 116 |
| 261 | fx_su obj |
| 262 | fx_su cmd |
| 263 | fx_fills |
| 264 | fx_rf f |
| 265 | ret lt f 0 |
| 266 | end |
| 267 | |
| 268 | fn dx_uvm fd long cmd ulong to bool |
| 269 | f = fx_eff 11 1 117 118 |
| 270 | fx_sd fd |
| 271 | fx_su cmd |
| 272 | fx_fills |
| 273 | fx_rf f |
| 274 | ret lt f 0 |
| 275 | end |
| 276 | |
| 277 | fn dx_uvmraw fd long cmd ulong to void |
| 278 | f = fx_eff 5 0 117 109 |
| 279 | fx_sd fd |
| 280 | fx_su cmd |
| 281 | fx_fills |
| 282 | fx_semi |
| 283 | end |
| 284 | |
| 285 | fn dx_ioctl fd long nr ulong to bool |
| 286 | f = fx_eff 6 1 105 111 |
| 287 | fx_sd fd |
| 288 | fx_su nr |
| 289 | fx_fills |
| 290 | fx_rf f |
| 291 | ret lt f 0 |
| 292 | end |
| 293 | |
| 294 | fn dx_cardidx to long |
| 295 | f = fx_eff 7 1 99 105 |
| 296 | r = long 2 |
| 297 | if ge f 0 |
| 298 | r = long -1 |
| 299 | end |
| 300 | fx_rd r |
| 301 | ret r |
| 302 | end |
| 303 | |
| 304 | note admit the card at index i: the admitted SM, -1 when refused |
| 305 | fn dx_admit_card i ulong to long |
| 306 | f = fx_eff 8 1 97 99 |
| 307 | fx_su 0 |
| 308 | fx_su 1 |
| 309 | fx_su 0 |
| 310 | fx_su 0 |
| 311 | fx_su 4318 |
| 312 | fx_su 11794 |
| 313 | fx_rf f |
| 314 | if ge f 0 |
| 315 | ret -1 |
| 316 | end |
| 317 | ret long get fz 6 |
| 318 | end |
| 319 | |
| 320 | note card record i field: 5 gpu_id, 6 minor, 7 vendor, 8 device |
| 321 | fn dx_cardget i ulong fl ulong to ulong |
| 322 | if eq fl 5 |
| 323 | ret add 256 i |
| 324 | end |
| 325 | if eq fl 6 |
| 326 | ret i |
| 327 | end |
| 328 | if eq fl 7 |
| 329 | ret 4318 |
| 330 | end |
| 331 | if eq fl 8 |
| 332 | ret 11794 |
| 333 | end |
| 334 | put fz 12 1 |
| 335 | ret 0 |
| 336 | end |
| 337 | |
| 338 | fn dx_opendev minor ulong to long |
| 339 | f = fx_eff 9 1 111 100 |
| 340 | fd = long add 10 fx_n |
| 341 | if ge f 0 |
| 342 | fd = long -1 |
| 343 | end |
| 344 | fx_su minor |
| 345 | fx_rd fd |
| 346 | ret fd |
| 347 | end |
| 348 | |
| 349 | note a field of the last answer: kind 1 field 1 device instance, 17/1 SM version, 7/0 class count, |
| 350 | note 14/0 work-submit token, 9/3+i uuid byte i |
| 351 | fn dx_nsget kind ulong fl ulong to ulong |
| 352 | if and eq kind 1 eq fl 1 |
| 353 | ret 3 |
| 354 | end |
| 355 | if and eq kind 17 eq fl 1 |
| 356 | ret 2564 |
| 357 | end |
| 358 | if and eq kind 7 eq fl 0 |
| 359 | ret get fz 9 |
| 360 | end |
| 361 | if and eq kind 14 eq fl 0 |
| 362 | ret add 4096 fx_n |
| 363 | end |
| 364 | if and and eq kind 9 ge fl 3 lt fl 19 |
| 365 | ret and add mul sub fl 3 37 11 255 |
| 366 | end |
| 367 | put fz 12 1 |
| 368 | ret 0 |
| 369 | end |
| 370 | |
| 371 | note select_classes: on success the target SM, discrete flag and the compute, GPFIFO and usermode classes |
| 372 | fn dx_select count ulong vendor ulong device ulong to bool |
| 373 | f = fx_eff 12 1 115 99 |
| 374 | fx_su count |
| 375 | fx_su vendor |
| 376 | fx_su device |
| 377 | fx_rf f |
| 378 | cp CS_CCLS 0 |
| 379 | cp CS_GCLS 0 |
| 380 | cp CS_UCLS 0 |
| 381 | cp CS_TSM 0 |
| 382 | cp CS_DISC 0 |
| 383 | if ge f 0 |
| 384 | ret false |
| 385 | end |
| 386 | d = get fz 8 |
| 387 | cp CS_TSM get fz 7 |
| 388 | cp CS_DISC d |
| 389 | if ne d 0 |
| 390 | cp CS_CCLS 51136 |
| 391 | cp CS_GCLS 50543 |
| 392 | cp CS_UCLS 50017 |
| 393 | else |
| 394 | cp CS_CCLS 52928 |
| 395 | cp CS_GCLS 51567 |
| 396 | cp CS_UCLS 50785 |
| 397 | end |
| 398 | ret true |
| 399 | end |
| 400 | |
| 401 | note map_to_cpu: the CPU address (target, or a new one when target is 0), 2^64 - 1 when refused |
| 402 | fn dx_map h ulong size ulong target ulong flags ulong system long to ulong |
| 403 | f = fx_eff 13 1 109 112 |
| 404 | p = target |
| 405 | if eq target 0 |
| 406 | p = add 5497558138880 shl fx_n 16 |
| 407 | end |
| 408 | if ge f 0 |
| 409 | p = CN_MAPFAILED |
| 410 | end |
| 411 | fx_su h |
| 412 | fx_su size |
| 413 | fx_su target |
| 414 | fx_su flags |
| 415 | fx_sd system |
| 416 | fx_ru p |
| 417 | ret p |
| 418 | end |
| 419 | |
| 420 | note nvrm_cpu_reserve: va; flavour 0 refused (2^64 - 1), flavour 1 another address (va + 4096) |
| 421 | fn dx_reserve va ulong size ulong to ulong |
| 422 | f = fx_eff 14 2 114 115 |
| 423 | p = va |
| 424 | if eq f 0 |
| 425 | p = CN_MAPFAILED |
| 426 | end |
| 427 | if eq f 1 |
| 428 | p = add va 4096 |
| 429 | end |
| 430 | fx_su va |
| 431 | fx_su size |
| 432 | fx_ru p |
| 433 | ret p |
| 434 | end |
| 435 | |
| 436 | fn dx_drop cpu ulong size ulong to bool |
| 437 | f = fx_eff 15 1 100 112 |
| 438 | fx_su cpu |
| 439 | fx_su size |
| 440 | fx_rf f |
| 441 | ret lt f 0 |
| 442 | end |
| 443 | |
| 444 | fn dx_transfer h ulong to void |
| 445 | f = fx_eff 16 0 116 114 |
| 446 | fx_su h |
| 447 | fx_semi |
| 448 | end |
| 449 | |
| 450 | fn dx_finish to bool |
| 451 | f = fx_eff 17 1 102 110 |
| 452 | fx_rf f |
| 453 | ret lt f 0 |
| 454 | end |
| 455 | |
| 456 | fn dx_vatake size ulong align ulong to ulong |
| 457 | f = fx_eff 18 1 118 116 |
| 458 | va = add 137438953472 shl fx_n 20 |
| 459 | if ge f 0 |
| 460 | va = ulong 0 |
| 461 | end |
| 462 | fx_su size |
| 463 | fx_su align |
| 464 | fx_ru va |
| 465 | ret va |
| 466 | end |
| 467 | |
| 468 | fn dx_varel va ulong size ulong to bool |
| 469 | f = fx_eff 19 1 118 114 |
| 470 | fx_su va |
| 471 | fx_su size |
| 472 | fx_rf f |
| 473 | ret lt f 0 |
| 474 | end |
| 475 | |
| 476 | note uvm_map: 0 mapped; refused 1 before anything, 2 after the UVM range was created, 3 after the DMA map too |
| 477 | fn dx_uvmmap va ulong size ulong h ulong to ulong |
| 478 | f = fx_eff 21 3 117 120 |
| 479 | r = ulong 0 |
| 480 | if ge f 0 |
| 481 | r = add ulong f 1 |
| 482 | end |
| 483 | fx_su va |
| 484 | fx_su size |
| 485 | fx_su h |
| 486 | fx_ru r |
| 487 | ret r |
| 488 | end |
| 489 | |
| 490 | fn dx_uvmfree va ulong size ulong to bool |
| 491 | f = fx_eff 22 1 117 102 |
| 492 | fx_su va |
| 493 | fx_su size |
| 494 | fx_rf f |
| 495 | ret lt f 0 |
| 496 | end |
| 497 | |
| 498 | fn dx_dmaunmap h ulong va ulong size ulong to bool |
| 499 | f = fx_eff 23 1 100 117 |
| 500 | fx_su h |
| 501 | fx_su va |
| 502 | fx_su size |
| 503 | fx_rf f |
| 504 | ret lt f 0 |
| 505 | end |
| 506 | |
| 507 | fn dx_validate off ulong nw ulong to bool |
| 508 | f = fx_eff 25 1 118 97 |
| 509 | fx_su off |
| 510 | fx_su nw |
| 511 | fx_rf f |
| 512 | ret lt f 0 |
| 513 | end |
| 514 | |
| 515 | fn dx_publish fifoh ulong entries ulong putv ulong userd ulong va ulong nw ulong to bool |
| 516 | f = fx_eff 26 1 112 98 |
| 517 | fx_su fifoh |
| 518 | fx_su entries |
| 519 | fx_su putv |
| 520 | fx_su userd |
| 521 | fx_su va |
| 522 | fx_su nw |
| 523 | fx_rf f |
| 524 | ret lt f 0 |
| 525 | end |
| 526 | |
| 527 | fn dx_doorbell token ulong to bool |
| 528 | f = fx_eff 27 1 100 98 |
| 529 | fx_su token |
| 530 | fx_rf f |
| 531 | ret lt f 0 |
| 532 | end |
| 533 | |
| 534 | fn dx_sleep us ulong to void |
| 535 | f = fx_eff 28 0 115 108 |
| 536 | fx_su us |
| 537 | fx_semi |
| 538 | end |
| 539 | |
| 540 | fn dx_zero cpu ulong size ulong to void |
| 541 | f = fx_eff 29 0 122 98 |
| 542 | fx_su cpu |
| 543 | fx_su size |
| 544 | fx_semi |
| 545 | end |
| 546 | |
| 547 | note fail(): "ER CODE ARGS;" (string arguments print as s) |
| 548 | fn dx_er code ulong to void |
| 549 | fx_c 69 |
| 550 | fx_c 82 |
| 551 | fx_su code |
| 552 | end |
| 553 | |
| 554 | fn dx_eu v ulong to void |
| 555 | fx_su v |
| 556 | end |
| 557 | |
| 558 | fn dx_ed v long to void |
| 559 | fx_sd v |
| 560 | end |
| 561 | |
| 562 | fn dx_es to void |
| 563 | fx_c 32 |
| 564 | fx_c 115 |
| 565 | end |
| 566 | |
| 567 | fn dx_ee to void |
| 568 | fx_semi |
| 569 | end |
| 570 | |
| 571 | fn dx_ea size ulong to void |
| 572 | fx_c 69 |
| 573 | fx_c 65 |
| 574 | fx_su size |
| 575 | fx_semi |
| 576 | end |
| 577 | |
| 578 | fn dx_en attempts ulong delay ulong to void |
| 579 | fx_c 69 |
| 580 | fx_c 78 |
| 581 | fx_su attempts |
| 582 | fx_su delay |
| 583 | fx_semi |
| 584 | end |