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 / driver / chan / rmchan.om
| 1 | note chan/rmchan.om: async RM object and channel allocation, scheduling, drain, and free |
| 2 | note state machine for Blackwell GPFIFO channels over GSP-RM RPCs. |
| 3 | note Layout source of record: NVIDIA open-gpu-kernel-modules 580.173.02 (MIT) clc96f.h, |
| 4 | note cla06c.h, kernel_channel.c:2814-2821. Library unit, no main. Prefix rm / RM. |
| 5 | note |
| 6 | note RM object hierarchy: |
| 7 | note Client -> Device; Device owns Subdevice, VASpace, ChannelGroup and ChannelGPFIFO. |
| 8 | note ChannelGroup owns ContextShare. Allocation order is not a chain of parent handles. |
| 9 | note |
| 10 | note Schedule control: |
| 11 | note NVA06C_CTRL_CMD_GPFIFO_SCHEDULE (PACMSCH 2691432705): bEnable 1 (start) / 0 (disable). |
| 12 | note |
| 13 | note Teardown order: |
| 14 | note Free Channel -> Free CtxShare -> Free ChannelGroup -> Free VASpace -> Free Subdev -> |
| 15 | note Free Device -> Free Client. |
| 16 | note |
| 17 | note Pure protocol: |
| 18 | note rminit -> long resets only unbound IDLE/DONE policy, refuses retained epoch |
| 19 | note rmcfg cli dev sub vas tsg ctx -> void configures handles |
| 20 | note rmcfgch chan chid tree pid -> void configures channel ID, tree mode, process ID |
| 21 | note rmcfgmem gpa gn upa ipa rpa -> void configures memory descriptors for pachan |
| 22 | note rmstart budget -> long initiates allocation sequence (Root or TSG) |
| 23 | note rmstep -> long steps state machine on bpoll (0 wait, 1 ok, 2 event, <0 err) |
| 24 | note rmsched budget -> long initiates channel group schedule enable |
| 25 | note rmdis budget -> long initiates channel group schedule disable |
| 26 | note rmdrain c budget -> long bounded semaphore progress ONLY, not engine/cache idle |
| 27 | note rmfree budget -> long object RPC teardown ONLY, never frees published backing |
| 28 | note |
| 29 | note Typed mapped effect adapter: |
| 30 | note rmbind c gen -> long binds live mapped slot/epoch; replay state9 is NOT admission |
| 31 | note rmpub gen -> long publishes DMA window once channel is active |
| 32 | note rmlose gen -> long quarantines channel buffers and window on timeout/error |
| 33 | note rmsub c pb off n -> long active bound submission with exact trailing release marker |
| 34 | note The pinned hosted effects are not an Omega kernel, DMA/coherency qualification, or production gate. |
| 35 | note |
| 36 | note Status codes: 0 RMOK, -1 RMEINVAL, -2 RMERANGE, -3 RMESTATE, -4 RMENOMEM, -5 RMEBIND, |
| 37 | note -6 RMECAP, -10 RMEGEN, -11 RMETIME, -12 RMEFAIL, -13 RMECORR, -14 RMEQUAR |
| 38 | const RMOK long 0 |
| 39 | const RMEINVAL long -1 |
| 40 | const RMERANGE long -2 |
| 41 | const RMESTATE long -3 |
| 42 | const RMENOMEM long -4 |
| 43 | const RMEBIND long -5 |
| 44 | const RMECAP long -6 |
| 45 | const RMEGEN long -10 |
| 46 | const RMETIME long -11 |
| 47 | const RMEFAIL long -12 |
| 48 | const RMECORR long -13 |
| 49 | const RMEQUAR long -14 |
| 50 | note State machine states |
| 51 | const RMSIDLE ulong 0 |
| 52 | const RMSAROOT ulong 1 |
| 53 | const RMSADEV ulong 2 |
| 54 | const RMSASUB ulong 3 |
| 55 | const RMSAVAS ulong 4 |
| 56 | const RMSATSG ulong 5 |
| 57 | const RMSACTX ulong 6 |
| 58 | const RMSACHAN ulong 7 |
| 59 | const RMSREADY ulong 8 |
| 60 | const RMSSCHED ulong 9 |
| 61 | const RMSACTV ulong 10 |
| 62 | const RMSDIS ulong 11 |
| 63 | const RMSDRAIN ulong 12 |
| 64 | const RMSDRND ulong 13 |
| 65 | const RMSFCHAN ulong 14 |
| 66 | const RMSFCTX ulong 15 |
| 67 | const RMSFTSG ulong 16 |
| 68 | const RMSFVAS ulong 17 |
| 69 | const RMSFSUB ulong 18 |
| 70 | const RMSFDEV ulong 19 |
| 71 | const RMSFROOT ulong 20 |
| 72 | const RMSDONE ulong 21 |
| 73 | const RMSTOUT ulong 22 |
| 74 | const RMSERR ulong 23 |
| 75 | const RMSQUAR ulong 24 |
| 76 | const RMSACMP ulong 25 |
| 77 | const RMSWST ulong 26 |
| 78 | const RMSFCMP ulong 27 |
| 79 | global rmst ulong 1 |
| 80 | global rmrc long 1 |
| 81 | global rmbudget ulong 1 |
| 82 | global rmepoch ulong 1 |
| 83 | global rmtree ulong 1 |
| 84 | global rmchid ulong 1 |
| 85 | global rmhcli ulong 1 |
| 86 | global rmhdev ulong 1 |
| 87 | global rmhsub ulong 1 |
| 88 | global rmhvas ulong 1 |
| 89 | global rmhtsg ulong 1 |
| 90 | global rmhctx ulong 1 |
| 91 | global rmhchan ulong 1 |
| 92 | global rmgb20b ulong 1 |
| 93 | global rmhcmp ulong 1 |
| 94 | global rmtok ulong 1 |
| 95 | global rmgpa ulong 1 |
| 96 | global rmgn ulong 1 |
| 97 | global rmupa ulong 1 |
| 98 | global rmipa ulong 1 |
| 99 | global rmrpa ulong 1 |
| 100 | global rmpid ulong 1 |
| 101 | global rmslot ulong 1 |
| 102 | fn rminit to long |
| 103 | s = get rmst 0 |
| 104 | if and ne s RMSIDLE ne s RMSDONE |
| 105 | ret RMESTATE |
| 106 | end |
| 107 | if ne get rmepoch 0 0 |
| 108 | ret RMESTATE |
| 109 | end |
| 110 | put rmst 0 RMSIDLE |
| 111 | put rmrc 0 RMOK |
| 112 | put rmbudget 0 0 |
| 113 | put rmepoch 0 0 |
| 114 | put rmtree 0 0 |
| 115 | put rmchid 0 0 |
| 116 | put rmhcli 0 0 |
| 117 | put rmhdev 0 0 |
| 118 | put rmhsub 0 0 |
| 119 | put rmhvas 0 0 |
| 120 | put rmhtsg 0 0 |
| 121 | put rmhctx 0 0 |
| 122 | put rmhchan 0 0 |
| 123 | put rmgb20b 0 0 |
| 124 | put rmhcmp 0 0 |
| 125 | put rmtok 0 0 |
| 126 | put rmgpa 0 0 |
| 127 | put rmgn 0 0 |
| 128 | put rmupa 0 0 |
| 129 | put rmipa 0 0 |
| 130 | put rmrpa 0 0 |
| 131 | put rmpid 0 0 |
| 132 | put rmslot 0 GMNONE |
| 133 | ret RMOK |
| 134 | end |
| 135 | fn rmcfg cli ulong dev ulong sdev ulong vas ulong tsg ulong ctx ulong to void |
| 136 | if ne get rmst 0 RMSIDLE |
| 137 | put rmrc 0 RMESTATE |
| 138 | ret |
| 139 | end |
| 140 | put rmhcli 0 cli |
| 141 | put rmhdev 0 dev |
| 142 | put rmhsub 0 sdev |
| 143 | put rmhvas 0 vas |
| 144 | put rmhtsg 0 tsg |
| 145 | put rmhctx 0 ctx |
| 146 | end |
| 147 | fn rmcfgch chan ulong chid ulong tree ulong pid ulong to void |
| 148 | if ne get rmst 0 RMSIDLE |
| 149 | put rmrc 0 RMESTATE |
| 150 | ret |
| 151 | end |
| 152 | put rmhchan 0 chan |
| 153 | put rmchid 0 chid |
| 154 | put rmtree 0 tree |
| 155 | put rmpid 0 pid |
| 156 | end |
| 157 | note Configure GB20B profile (0xca6f channel + 0xcec0 compute + 0xc36f0108 bit-30 token). |
| 158 | fn rmcfg20 gb20b bool hcmp ulong to void |
| 159 | if ne get rmst 0 RMSIDLE |
| 160 | put rmrc 0 RMESTATE |
| 161 | ret |
| 162 | end |
| 163 | if gb20b |
| 164 | put rmgb20b 0 1 |
| 165 | else |
| 166 | put rmgb20b 0 0 |
| 167 | end |
| 168 | put rmhcmp 0 hcmp |
| 169 | end |
| 170 | fn rmcfgmem gpa ulong gn ulong upa ulong ipa ulong rpa ulong to void |
| 171 | if ne get rmst 0 RMSIDLE |
| 172 | put rmrc 0 RMESTATE |
| 173 | ret |
| 174 | end |
| 175 | put rmgpa 0 gpa |
| 176 | put rmgn 0 gn |
| 177 | put rmupa 0 upa |
| 178 | put rmipa 0 ipa |
| 179 | put rmrpa 0 rpa |
| 180 | end |
| 181 | fn rmfillin to void |
| 182 | for i ulong 48 |
| 183 | put pain i 0 |
| 184 | end |
| 185 | put pain 0 0 |
| 186 | put pain 1 get rmgpa 0 |
| 187 | put pain 2 get rmgn 0 |
| 188 | put pain 3 0 |
| 189 | put pain 4 get rmhctx 0 |
| 190 | put pain 5 get rmhvas 0 |
| 191 | put pain 6 0 |
| 192 | put pain 7 get rmupa 0 |
| 193 | put pain 8 PAENGGR |
| 194 | put pain 9 0 |
| 195 | put pain 10 0 |
| 196 | put pain 11 get rmhtsg 0 |
| 197 | put pain 12 0 |
| 198 | put pain 13 0 |
| 199 | put pain 14 0 |
| 200 | put pain 15 get rmchid 0 |
| 201 | put pain 16 get rmipa 0 |
| 202 | put pain 17 4096 |
| 203 | put pain 18 2 |
| 204 | put pain 19 0 |
| 205 | put pain 20 get rmupa 0 |
| 206 | put pain 21 512 |
| 207 | put pain 22 2 |
| 208 | put pain 23 0 |
| 209 | put pain 24 get rmrpa 0 |
| 210 | put pain 25 512 |
| 211 | put pain 26 2 |
| 212 | put pain 27 0 |
| 213 | put pain 36 get rmpid 0 |
| 214 | end |
| 215 | fn rmstart budget ulong to long |
| 216 | if ne get rmst 0 RMSIDLE |
| 217 | ret RMESTATE |
| 218 | end |
| 219 | if ne get bstate 0 9 |
| 220 | ret RMESTATE |
| 221 | end |
| 222 | if eq budget 0 |
| 223 | ret RMEINVAL |
| 224 | end |
| 225 | put rmbudget 0 budget |
| 226 | if eq get rmtree 0 1 |
| 227 | r = paroot get rmhcli 0 get rmpid 0 |
| 228 | if lt r 0 |
| 229 | ret r |
| 230 | end |
| 231 | r = brmalloc get rmhcli 0 0 get rmhcli 0 PACROOT budget |
| 232 | if lt r 0 |
| 233 | ret r |
| 234 | end |
| 235 | put rmst 0 RMSAROOT |
| 236 | ret RMOK |
| 237 | end |
| 238 | r = patsg 0 0 get rmhvas 0 PAENGGR |
| 239 | if lt r 0 |
| 240 | ret r |
| 241 | end |
| 242 | r = brmalloc get rmhcli 0 get rmhdev 0 get rmhtsg 0 PACTSG budget |
| 243 | if lt r 0 |
| 244 | ret r |
| 245 | end |
| 246 | put rmst 0 RMSATSG |
| 247 | ret RMOK |
| 248 | end |
| 249 | fn rmsched budget ulong to long |
| 250 | st = get rmst 0 |
| 251 | if ne st RMSREADY |
| 252 | ret RMESTATE |
| 253 | end |
| 254 | if ne get bstate 0 9 |
| 255 | ret RMESTATE |
| 256 | end |
| 257 | if eq budget 0 |
| 258 | ret RMEINVAL |
| 259 | end |
| 260 | put rmbudget 0 budget |
| 261 | r = pasched 1 0 0 |
| 262 | if lt r 0 |
| 263 | ret r |
| 264 | end |
| 265 | r = brmctrl get rmhcli 0 get rmhtsg 0 PACMSCH budget |
| 266 | if lt r 0 |
| 267 | ret r |
| 268 | end |
| 269 | put rmst 0 RMSSCHED |
| 270 | ret RMOK |
| 271 | end |
| 272 | fn rmdis budget ulong to long |
| 273 | st = get rmst 0 |
| 274 | if and ne st RMSACTV ne st RMSREADY |
| 275 | ret RMESTATE |
| 276 | end |
| 277 | if ne get bstate 0 9 |
| 278 | ret RMESTATE |
| 279 | end |
| 280 | if eq budget 0 |
| 281 | ret RMEINVAL |
| 282 | end |
| 283 | put rmbudget 0 budget |
| 284 | r = pasched 0 0 0 |
| 285 | if lt r 0 |
| 286 | ret r |
| 287 | end |
| 288 | r = brmctrl get rmhcli 0 get rmhtsg 0 PACMSCH budget |
| 289 | if lt r 0 |
| 290 | ret r |
| 291 | end |
| 292 | put rmst 0 RMSDIS |
| 293 | ret RMOK |
| 294 | end |
| 295 | fn rmdrain c ulong budget uint to long |
| 296 | if ge c CMSLOTS |
| 297 | ret RMEINVAL |
| 298 | end |
| 299 | if ne c get rmslot 0 |
| 300 | ret RMEINVAL |
| 301 | end |
| 302 | if ne get rmepoch 0 get mmwgen 0 |
| 303 | ret RMEGEN |
| 304 | end |
| 305 | if ne get rmst 0 RMSDRAIN |
| 306 | ret RMESTATE |
| 307 | end |
| 308 | rc = cmdrain c budget |
| 309 | if ne rc CMOK |
| 310 | put rmrc 0 rc |
| 311 | put rmst 0 RMSTOUT |
| 312 | r = rmlose get rmepoch 0 |
| 313 | ret RMETIME |
| 314 | end |
| 315 | put rmst 0 RMSDRND |
| 316 | ret RMOK |
| 317 | end |
| 318 | fn rmfree budget ulong to long |
| 319 | st = get rmst 0 |
| 320 | if ne st RMSDRND |
| 321 | ret RMESTATE |
| 322 | end |
| 323 | if ne get bstate 0 9 |
| 324 | ret RMESTATE |
| 325 | end |
| 326 | if eq budget 0 |
| 327 | ret RMEINVAL |
| 328 | end |
| 329 | put rmbudget 0 budget |
| 330 | if and eq get rmgb20b 0 1 ne get rmhcmp 0 0 |
| 331 | r = brmfree get rmhcli 0 get rmhcmp 0 budget |
| 332 | if lt r 0 |
| 333 | ret r |
| 334 | end |
| 335 | put rmst 0 RMSFCMP |
| 336 | ret RMOK |
| 337 | end |
| 338 | r = brmfree get rmhcli 0 get rmhchan 0 budget |
| 339 | if lt r 0 |
| 340 | ret r |
| 341 | end |
| 342 | put rmst 0 RMSFCHAN |
| 343 | ret RMOK |
| 344 | end |
| 345 | fn rmerr rc long to long |
| 346 | put rmrc 0 rc |
| 347 | put rmst 0 RMSERR |
| 348 | if eq rc RMETIME |
| 349 | put rmst 0 RMSTOUT |
| 350 | end |
| 351 | if ne get rmepoch 0 0 |
| 352 | r = rmlose get rmepoch 0 |
| 353 | end |
| 354 | ret rc |
| 355 | end |
| 356 | fn rmstep to long |
| 357 | s = get rmst 0 |
| 358 | if or eq s RMSIDLE or eq s RMSREADY or eq s RMSACTV or eq s RMSDRND or eq s RMSDONE or eq s RMSTOUT or eq s RMSERR eq s RMSQUAR |
| 359 | ret 0 |
| 360 | end |
| 361 | if eq s RMSDRAIN |
| 362 | ret 0 |
| 363 | end |
| 364 | if eq get bstate 0 11 |
| 365 | ret 2 |
| 366 | end |
| 367 | r = bpoll |
| 368 | if eq r 0 |
| 369 | ret 0 |
| 370 | end |
| 371 | if eq r 2 |
| 372 | ret 2 |
| 373 | end |
| 374 | if lt r 0 |
| 375 | ret rmerr r |
| 376 | end |
| 377 | b = get rmbudget 0 |
| 378 | if eq s RMSAROOT |
| 379 | r = padevice 0 get rmhcli 0 3 2 1099511627776 |
| 380 | if lt r 0 |
| 381 | ret rmerr r |
| 382 | end |
| 383 | r = brmalloc get rmhcli 0 get rmhcli 0 get rmhdev 0 PACDEV b |
| 384 | if lt r 0 |
| 385 | ret rmerr r |
| 386 | end |
| 387 | put rmst 0 RMSADEV |
| 388 | ret 1 |
| 389 | end |
| 390 | if eq s RMSADEV |
| 391 | r = pasubdev 0 |
| 392 | if lt r 0 |
| 393 | ret rmerr r |
| 394 | end |
| 395 | r = brmalloc get rmhcli 0 get rmhdev 0 get rmhsub 0 PACSUB b |
| 396 | if lt r 0 |
| 397 | ret rmerr r |
| 398 | end |
| 399 | put rmst 0 RMSASUB |
| 400 | ret 1 |
| 401 | end |
| 402 | if eq s RMSASUB |
| 403 | r = pavaspace 0 72 1099511627776 8589934592 65536 |
| 404 | if lt r 0 |
| 405 | ret rmerr r |
| 406 | end |
| 407 | r = brmalloc get rmhcli 0 get rmhdev 0 get rmhvas 0 PACVAS b |
| 408 | if lt r 0 |
| 409 | ret rmerr r |
| 410 | end |
| 411 | put rmst 0 RMSAVAS |
| 412 | ret 1 |
| 413 | end |
| 414 | if eq s RMSAVAS |
| 415 | r = patsg 0 0 get rmhvas 0 PAENGGR |
| 416 | if lt r 0 |
| 417 | ret rmerr r |
| 418 | end |
| 419 | r = brmalloc get rmhcli 0 get rmhdev 0 get rmhtsg 0 PACTSG b |
| 420 | if lt r 0 |
| 421 | ret rmerr r |
| 422 | end |
| 423 | put rmst 0 RMSATSG |
| 424 | ret 1 |
| 425 | end |
| 426 | if eq s RMSATSG |
| 427 | r = pactxsh get rmhvas 0 PACTXAS 0 |
| 428 | if lt r 0 |
| 429 | ret rmerr r |
| 430 | end |
| 431 | r = brmalloc get rmhcli 0 get rmhtsg 0 get rmhctx 0 PACCTX b |
| 432 | if lt r 0 |
| 433 | ret rmerr r |
| 434 | end |
| 435 | put rmst 0 RMSACTX |
| 436 | ret 1 |
| 437 | end |
| 438 | if eq s RMSACTX |
| 439 | rmfillin |
| 440 | r = pachan |
| 441 | if lt r 0 |
| 442 | ret rmerr r |
| 443 | end |
| 444 | r = brmalloc get rmhcli 0 get rmhdev 0 get rmhchan 0 pacgpcls eq get rmgb20b 0 1 b |
| 445 | if lt r 0 |
| 446 | ret rmerr r |
| 447 | end |
| 448 | put rmst 0 RMSACHAN |
| 449 | ret 1 |
| 450 | end |
| 451 | if eq s RMSACHAN |
| 452 | if and eq get rmgb20b 0 1 ne get rmhcmp 0 0 |
| 453 | r = paempty |
| 454 | if lt r 0 |
| 455 | ret rmerr r |
| 456 | end |
| 457 | r = brmalloc get rmhcli 0 get rmhchan 0 get rmhcmp 0 PACCMP b |
| 458 | if lt r 0 |
| 459 | ret rmerr r |
| 460 | end |
| 461 | put rmst 0 RMSACMP |
| 462 | ret 1 |
| 463 | end |
| 464 | put rmst 0 RMSREADY |
| 465 | ret 1 |
| 466 | end |
| 467 | if eq s RMSACMP |
| 468 | put rmst 0 RMSREADY |
| 469 | ret 1 |
| 470 | end |
| 471 | if eq s RMSSCHED |
| 472 | if eq get rmgb20b 0 1 |
| 473 | r = pawstreq |
| 474 | if lt r 0 |
| 475 | ret rmerr r |
| 476 | end |
| 477 | r = brmctrl get rmhcli 0 get rmhchan 0 PACMWST b |
| 478 | if lt r 0 |
| 479 | ret rmerr r |
| 480 | end |
| 481 | put rmst 0 RMSWST |
| 482 | ret 1 |
| 483 | end |
| 484 | put chopen get rmslot 0 1 |
| 485 | put rmst 0 RMSACTV |
| 486 | ret 1 |
| 487 | end |
| 488 | if eq s RMSWST |
| 489 | tok = pawstdec get bplen 0 |
| 490 | if lt tok 0 |
| 491 | ret rmerr RMECORR |
| 492 | end |
| 493 | tu = ulong tok |
| 494 | if eq and tu ulong CHDBEN 0 |
| 495 | ret rmerr RMECORR |
| 496 | end |
| 497 | rl = and shr tu 16 127 |
| 498 | if ge rl ulong CHRLINV |
| 499 | ret rmerr RMECORR |
| 500 | end |
| 501 | put rmtok 0 tu |
| 502 | if ne chsettok get rmslot 0 uint tu CHOK |
| 503 | ret rmerr RMEBIND |
| 504 | end |
| 505 | put chopen get rmslot 0 1 |
| 506 | put rmst 0 RMSACTV |
| 507 | ret 1 |
| 508 | end |
| 509 | if eq s RMSDIS |
| 510 | put chopen get rmslot 0 2 |
| 511 | put rmst 0 RMSDRAIN |
| 512 | ret 1 |
| 513 | end |
| 514 | if eq s RMSFCMP |
| 515 | r = brmfree get rmhcli 0 get rmhchan 0 b |
| 516 | if lt r 0 |
| 517 | ret rmerr r |
| 518 | end |
| 519 | put rmst 0 RMSFCHAN |
| 520 | ret 1 |
| 521 | end |
| 522 | if eq s RMSFCHAN |
| 523 | r = brmfree get rmhcli 0 get rmhctx 0 b |
| 524 | if lt r 0 |
| 525 | ret rmerr r |
| 526 | end |
| 527 | put rmst 0 RMSFCTX |
| 528 | ret 1 |
| 529 | end |
| 530 | if eq s RMSFCTX |
| 531 | r = brmfree get rmhcli 0 get rmhtsg 0 b |
| 532 | if lt r 0 |
| 533 | ret rmerr r |
| 534 | end |
| 535 | put rmst 0 RMSFTSG |
| 536 | ret 1 |
| 537 | end |
| 538 | if eq s RMSFTSG |
| 539 | if eq get rmtree 0 1 |
| 540 | r = brmfree get rmhcli 0 get rmhvas 0 b |
| 541 | if lt r 0 |
| 542 | ret rmerr r |
| 543 | end |
| 544 | put rmst 0 RMSFVAS |
| 545 | ret 1 |
| 546 | end |
| 547 | put rmst 0 RMSDONE |
| 548 | ret 1 |
| 549 | end |
| 550 | if eq s RMSFVAS |
| 551 | r = brmfree get rmhcli 0 get rmhsub 0 b |
| 552 | if lt r 0 |
| 553 | ret rmerr r |
| 554 | end |
| 555 | put rmst 0 RMSFSUB |
| 556 | ret 1 |
| 557 | end |
| 558 | if eq s RMSFSUB |
| 559 | r = brmfree get rmhcli 0 get rmhdev 0 b |
| 560 | if lt r 0 |
| 561 | ret rmerr r |
| 562 | end |
| 563 | put rmst 0 RMSFDEV |
| 564 | ret 1 |
| 565 | end |
| 566 | if eq s RMSFDEV |
| 567 | r = brmfree get rmhcli 0 get rmhcli 0 b |
| 568 | if lt r 0 |
| 569 | ret rmerr r |
| 570 | end |
| 571 | put rmst 0 RMSFROOT |
| 572 | ret 1 |
| 573 | end |
| 574 | if eq s RMSFROOT |
| 575 | put rmst 0 RMSDONE |
| 576 | ret 1 |
| 577 | end |
| 578 | ret 0 |
| 579 | end |
| 580 | fn rmbind c ulong gen ulong to long |
| 581 | if ge c CMSLOTS |
| 582 | ret RMEINVAL |
| 583 | end |
| 584 | if or ne get rmst 0 RMSIDLE ne get rmepoch 0 0 |
| 585 | ret RMESTATE |
| 586 | end |
| 587 | if ne get mmwkind 0 1 |
| 588 | ret RMECAP |
| 589 | end |
| 590 | if or lt get mmwst 0 MMWDMA ge get mmwst 0 MMWQUAR |
| 591 | ret RMESTATE |
| 592 | end |
| 593 | if ne get mmwgen 0 gen |
| 594 | ret RMEGEN |
| 595 | end |
| 596 | if or ne get chopen c 2 ne get chepoch c gen |
| 597 | ret RMEBIND |
| 598 | end |
| 599 | in = get chin c |
| 600 | ud = get chud c |
| 601 | gp = get chgp c |
| 602 | if or or ge in GMMAXB ge ud GMMAXB ge gp GMMAXB |
| 603 | ret RMEINVAL |
| 604 | end |
| 605 | if or or not gmlive in not gmlive ud not gmlive gp |
| 606 | ret RMECAP |
| 607 | end |
| 608 | if or ne get rqdead 0 0 ne get bstate 0 9 |
| 609 | ret RMECAP |
| 610 | end |
| 611 | put rmslot 0 c |
| 612 | put rmepoch 0 gen |
| 613 | note Vendor mem_utils_gm107.c:1232 uses a GPU virtual address, not backing PA. |
| 614 | put rmgpa 0 get gmbva gp |
| 615 | put rmgn 0 ulong get chent c |
| 616 | put rmupa 0 get gmbpa ud |
| 617 | put rmipa 0 get gmbpa in |
| 618 | put rmrpa 0 get gmbpa in |
| 619 | put rmchid 0 ulong get chchid c |
| 620 | ret RMOK |
| 621 | end |
| 622 | fn rmpub gen ulong to long |
| 623 | if ne gen get rmepoch 0 |
| 624 | ret RMEGEN |
| 625 | end |
| 626 | if ne get rmst 0 RMSACTV |
| 627 | ret RMESTATE |
| 628 | end |
| 629 | ret mmwpublish gen |
| 630 | end |
| 631 | fn rmlose gen ulong to long |
| 632 | if ne gen get rmepoch 0 |
| 633 | ret RMEGEN |
| 634 | end |
| 635 | c = get rmslot 0 |
| 636 | if ne c GMNONE |
| 637 | in = get chin c |
| 638 | ud = get chud c |
| 639 | gp = get chgp c |
| 640 | if and lt in GMMAXB gmlive in |
| 641 | r = gmquar in |
| 642 | end |
| 643 | if and lt ud GMMAXB gmlive ud |
| 644 | r = gmquar ud |
| 645 | end |
| 646 | if and lt gp GMMAXB gmlive gp |
| 647 | r = gmquar gp |
| 648 | end |
| 649 | end |
| 650 | if eq get mmwst 0 MMWPUB |
| 651 | r = mmwquar gen |
| 652 | end |
| 653 | put rmst 0 RMSQUAR |
| 654 | ret RMOK |
| 655 | end |
| 656 | fn rmsub c ulong pb ulong off uint n uint to long |
| 657 | if ge c CMSLOTS |
| 658 | ret RMEINVAL |
| 659 | end |
| 660 | if ne c get rmslot 0 |
| 661 | ret RMEINVAL |
| 662 | end |
| 663 | if ne get rmst 0 RMSACTV |
| 664 | ret RMESTATE |
| 665 | end |
| 666 | if ne get rmepoch 0 get mmwgen 0 |
| 667 | ret RMEGEN |
| 668 | end |
| 669 | if ne get mmwst 0 MMWPUB |
| 670 | ret RMESTATE |
| 671 | end |
| 672 | if or ne get chopen c 1 ne get chepoch c get mmwgen 0 |
| 673 | ret RMESTATE |
| 674 | end |
| 675 | st = get cmst c |
| 676 | if and and ne st CMSBIND ne st CMSACTV ne st CMSIDLE |
| 677 | ret RMESTATE |
| 678 | end |
| 679 | if ne get cmgen c get mmwgen 0 |
| 680 | ret RMEGEN |
| 681 | end |
| 682 | if not gmlive get cmbuf c |
| 683 | ret RMEBIND |
| 684 | end |
| 685 | if ne get cmbgen c ulong get gmbgen get cmbuf c |
| 686 | ret RMEGEN |
| 687 | end |
| 688 | if not gmlive pb |
| 689 | ret RMEBIND |
| 690 | end |
| 691 | ent = get chent c |
| 692 | p = get cmput c |
| 693 | if or lt ent 2 ge sub p get cmret c sub ent 1 |
| 694 | ret RMEBIND |
| 695 | end |
| 696 | if or ne p get chput c ne get cmret c get chret c |
| 697 | ret RMEBIND |
| 698 | end |
| 699 | r = rmtail c pb off n |
| 700 | if ne r RMOK |
| 701 | ret r |
| 702 | end |
| 703 | r = chsubmit c pb off n |
| 704 | if ne r CHOK |
| 705 | ret r |
| 706 | end |
| 707 | note No fallible checks after publication: the preflight proves cmsub(c,1)'s predicates. |
| 708 | put cmput c add p uint 1 |
| 709 | put cmst c CMSACTV |
| 710 | ret RMOK |
| 711 | end |
| 712 | note Pure submission preflight; immutable backing is read before the ring entry is published. |
| 713 | fn rmtail c ulong pb ulong off uint n uint to long |
| 714 | if or ne and off 3 0 lt n uint CMCWDS |
| 715 | ret RMEINVAL |
| 716 | end |
| 717 | if gt n CHLENMX |
| 718 | ret RMERANGE |
| 719 | end |
| 720 | bytes = mul ulong n 4 |
| 721 | if gt add ulong off bytes get gmbsz pb |
| 722 | ret RMERANGE |
| 723 | end |
| 724 | va = add get gmbva pb ulong off |
| 725 | if ge va CHVALIM |
| 726 | ret RMERANGE |
| 727 | end |
| 728 | r = cmrel 0 get cmva c add get cmput c uint 1 |
| 729 | if ne r long CMCWDS |
| 730 | ret RMEBIND |
| 731 | end |
| 732 | va = add get gmbpa pb ulong off |
| 733 | va = add va bytes |
| 734 | va = sub va mul CMCWDS 4 |
| 735 | for i ulong CMCWDS |
| 736 | if ne uint mmrd32 add va mul i 4 get cmwds i |
| 737 | ret RMEBIND |
| 738 | end |
| 739 | end |
| 740 | ret RMOK |
| 741 | end |