omega-gpu-driver
aien-dev/omega-gpu-driver
Brought by drakestapleton
omega-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 | global rmst ulong 1 |
| 77 | global rmrc long 1 |
| 78 | global rmbudget ulong 1 |
| 79 | global rmepoch ulong 1 |
| 80 | global rmtree ulong 1 |
| 81 | global rmchid ulong 1 |
| 82 | global rmhcli ulong 1 |
| 83 | global rmhdev ulong 1 |
| 84 | global rmhsub ulong 1 |
| 85 | global rmhvas ulong 1 |
| 86 | global rmhtsg ulong 1 |
| 87 | global rmhctx ulong 1 |
| 88 | global rmhchan ulong 1 |
| 89 | global rmgpa ulong 1 |
| 90 | global rmgn ulong 1 |
| 91 | global rmupa ulong 1 |
| 92 | global rmipa ulong 1 |
| 93 | global rmrpa ulong 1 |
| 94 | global rmpid ulong 1 |
| 95 | global rmslot ulong 1 |
| 96 | fn rminit to long |
| 97 | s = get rmst 0 |
| 98 | if and ne s RMSIDLE ne s RMSDONE |
| 99 | ret RMESTATE |
| 100 | end |
| 101 | if ne get rmepoch 0 0 |
| 102 | ret RMESTATE |
| 103 | end |
| 104 | put rmst 0 RMSIDLE |
| 105 | put rmrc 0 RMOK |
| 106 | put rmbudget 0 0 |
| 107 | put rmepoch 0 0 |
| 108 | put rmtree 0 0 |
| 109 | put rmchid 0 0 |
| 110 | put rmhcli 0 0 |
| 111 | put rmhdev 0 0 |
| 112 | put rmhsub 0 0 |
| 113 | put rmhvas 0 0 |
| 114 | put rmhtsg 0 0 |
| 115 | put rmhctx 0 0 |
| 116 | put rmhchan 0 0 |
| 117 | put rmgpa 0 0 |
| 118 | put rmgn 0 0 |
| 119 | put rmupa 0 0 |
| 120 | put rmipa 0 0 |
| 121 | put rmrpa 0 0 |
| 122 | put rmpid 0 0 |
| 123 | put rmslot 0 GMNONE |
| 124 | ret RMOK |
| 125 | end |
| 126 | fn rmcfg cli ulong dev ulong sdev ulong vas ulong tsg ulong ctx ulong to void |
| 127 | if ne get rmst 0 RMSIDLE |
| 128 | put rmrc 0 RMESTATE |
| 129 | ret |
| 130 | end |
| 131 | put rmhcli 0 cli |
| 132 | put rmhdev 0 dev |
| 133 | put rmhsub 0 sdev |
| 134 | put rmhvas 0 vas |
| 135 | put rmhtsg 0 tsg |
| 136 | put rmhctx 0 ctx |
| 137 | end |
| 138 | fn rmcfgch chan ulong chid ulong tree ulong pid ulong to void |
| 139 | if ne get rmst 0 RMSIDLE |
| 140 | put rmrc 0 RMESTATE |
| 141 | ret |
| 142 | end |
| 143 | put rmhchan 0 chan |
| 144 | put rmchid 0 chid |
| 145 | put rmtree 0 tree |
| 146 | put rmpid 0 pid |
| 147 | end |
| 148 | fn rmcfgmem gpa ulong gn ulong upa ulong ipa ulong rpa ulong to void |
| 149 | if ne get rmst 0 RMSIDLE |
| 150 | put rmrc 0 RMESTATE |
| 151 | ret |
| 152 | end |
| 153 | put rmgpa 0 gpa |
| 154 | put rmgn 0 gn |
| 155 | put rmupa 0 upa |
| 156 | put rmipa 0 ipa |
| 157 | put rmrpa 0 rpa |
| 158 | end |
| 159 | fn rmfillin to void |
| 160 | for i ulong 48 |
| 161 | put pain i 0 |
| 162 | end |
| 163 | put pain 0 0 |
| 164 | put pain 1 get rmgpa 0 |
| 165 | put pain 2 get rmgn 0 |
| 166 | put pain 3 0 |
| 167 | put pain 4 get rmhctx 0 |
| 168 | put pain 5 get rmhvas 0 |
| 169 | put pain 6 0 |
| 170 | put pain 7 get rmupa 0 |
| 171 | put pain 8 PAENGGR |
| 172 | put pain 9 0 |
| 173 | put pain 10 0 |
| 174 | put pain 11 get rmhtsg 0 |
| 175 | put pain 12 0 |
| 176 | put pain 13 0 |
| 177 | put pain 14 0 |
| 178 | put pain 15 get rmchid 0 |
| 179 | put pain 16 get rmipa 0 |
| 180 | put pain 17 4096 |
| 181 | put pain 18 2 |
| 182 | put pain 19 0 |
| 183 | put pain 20 get rmupa 0 |
| 184 | put pain 21 512 |
| 185 | put pain 22 2 |
| 186 | put pain 23 0 |
| 187 | put pain 24 get rmrpa 0 |
| 188 | put pain 25 512 |
| 189 | put pain 26 2 |
| 190 | put pain 27 0 |
| 191 | put pain 36 get rmpid 0 |
| 192 | end |
| 193 | fn rmstart budget ulong to long |
| 194 | if ne get rmst 0 RMSIDLE |
| 195 | ret RMESTATE |
| 196 | end |
| 197 | if ne get bstate 0 9 |
| 198 | ret RMESTATE |
| 199 | end |
| 200 | if eq budget 0 |
| 201 | ret RMEINVAL |
| 202 | end |
| 203 | put rmbudget 0 budget |
| 204 | if eq get rmtree 0 1 |
| 205 | r = paroot get rmhcli 0 get rmpid 0 |
| 206 | if lt r 0 |
| 207 | ret r |
| 208 | end |
| 209 | r = brmalloc get rmhcli 0 0 get rmhcli 0 PACROOT budget |
| 210 | if lt r 0 |
| 211 | ret r |
| 212 | end |
| 213 | put rmst 0 RMSAROOT |
| 214 | ret RMOK |
| 215 | end |
| 216 | r = patsg 0 0 get rmhvas 0 PAENGGR |
| 217 | if lt r 0 |
| 218 | ret r |
| 219 | end |
| 220 | r = brmalloc get rmhcli 0 get rmhdev 0 get rmhtsg 0 PACTSG budget |
| 221 | if lt r 0 |
| 222 | ret r |
| 223 | end |
| 224 | put rmst 0 RMSATSG |
| 225 | ret RMOK |
| 226 | end |
| 227 | fn rmsched budget ulong to long |
| 228 | st = get rmst 0 |
| 229 | if ne st RMSREADY |
| 230 | ret RMESTATE |
| 231 | end |
| 232 | if ne get bstate 0 9 |
| 233 | ret RMESTATE |
| 234 | end |
| 235 | if eq budget 0 |
| 236 | ret RMEINVAL |
| 237 | end |
| 238 | put rmbudget 0 budget |
| 239 | r = pasched 1 0 0 |
| 240 | if lt r 0 |
| 241 | ret r |
| 242 | end |
| 243 | r = brmctrl get rmhcli 0 get rmhtsg 0 PACMSCH budget |
| 244 | if lt r 0 |
| 245 | ret r |
| 246 | end |
| 247 | put rmst 0 RMSSCHED |
| 248 | ret RMOK |
| 249 | end |
| 250 | fn rmdis budget ulong to long |
| 251 | st = get rmst 0 |
| 252 | if and ne st RMSACTV ne st RMSREADY |
| 253 | ret RMESTATE |
| 254 | end |
| 255 | if ne get bstate 0 9 |
| 256 | ret RMESTATE |
| 257 | end |
| 258 | if eq budget 0 |
| 259 | ret RMEINVAL |
| 260 | end |
| 261 | put rmbudget 0 budget |
| 262 | r = pasched 0 0 0 |
| 263 | if lt r 0 |
| 264 | ret r |
| 265 | end |
| 266 | r = brmctrl get rmhcli 0 get rmhtsg 0 PACMSCH budget |
| 267 | if lt r 0 |
| 268 | ret r |
| 269 | end |
| 270 | put rmst 0 RMSDIS |
| 271 | ret RMOK |
| 272 | end |
| 273 | fn rmdrain c ulong budget uint to long |
| 274 | if ge c CMSLOTS |
| 275 | ret RMEINVAL |
| 276 | end |
| 277 | if ne c get rmslot 0 |
| 278 | ret RMEINVAL |
| 279 | end |
| 280 | if ne get rmepoch 0 get mmwgen 0 |
| 281 | ret RMEGEN |
| 282 | end |
| 283 | if ne get rmst 0 RMSDRAIN |
| 284 | ret RMESTATE |
| 285 | end |
| 286 | rc = cmdrain c budget |
| 287 | if ne rc CMOK |
| 288 | put rmrc 0 rc |
| 289 | put rmst 0 RMSTOUT |
| 290 | r = rmlose get rmepoch 0 |
| 291 | ret RMETIME |
| 292 | end |
| 293 | put rmst 0 RMSDRND |
| 294 | ret RMOK |
| 295 | end |
| 296 | fn rmfree budget ulong to long |
| 297 | st = get rmst 0 |
| 298 | if ne st RMSDRND |
| 299 | ret RMESTATE |
| 300 | end |
| 301 | if ne get bstate 0 9 |
| 302 | ret RMESTATE |
| 303 | end |
| 304 | if eq budget 0 |
| 305 | ret RMEINVAL |
| 306 | end |
| 307 | put rmbudget 0 budget |
| 308 | r = brmfree get rmhcli 0 get rmhchan 0 budget |
| 309 | if lt r 0 |
| 310 | ret r |
| 311 | end |
| 312 | put rmst 0 RMSFCHAN |
| 313 | ret RMOK |
| 314 | end |
| 315 | fn rmerr rc long to long |
| 316 | put rmrc 0 rc |
| 317 | put rmst 0 RMSERR |
| 318 | if eq rc RMETIME |
| 319 | put rmst 0 RMSTOUT |
| 320 | end |
| 321 | if ne get rmepoch 0 0 |
| 322 | r = rmlose get rmepoch 0 |
| 323 | end |
| 324 | ret rc |
| 325 | end |
| 326 | fn rmstep to long |
| 327 | s = get rmst 0 |
| 328 | 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 |
| 329 | ret 0 |
| 330 | end |
| 331 | if eq s RMSDRAIN |
| 332 | ret 0 |
| 333 | end |
| 334 | if eq get bstate 0 11 |
| 335 | ret 2 |
| 336 | end |
| 337 | r = bpoll |
| 338 | if eq r 0 |
| 339 | ret 0 |
| 340 | end |
| 341 | if eq r 2 |
| 342 | ret 2 |
| 343 | end |
| 344 | if lt r 0 |
| 345 | ret rmerr r |
| 346 | end |
| 347 | b = get rmbudget 0 |
| 348 | if eq s RMSAROOT |
| 349 | r = padevice 0 get rmhcli 0 3 2 1099511627776 |
| 350 | if lt r 0 |
| 351 | ret rmerr r |
| 352 | end |
| 353 | r = brmalloc get rmhcli 0 get rmhcli 0 get rmhdev 0 PACDEV b |
| 354 | if lt r 0 |
| 355 | ret rmerr r |
| 356 | end |
| 357 | put rmst 0 RMSADEV |
| 358 | ret 1 |
| 359 | end |
| 360 | if eq s RMSADEV |
| 361 | r = pasubdev 0 |
| 362 | if lt r 0 |
| 363 | ret rmerr r |
| 364 | end |
| 365 | r = brmalloc get rmhcli 0 get rmhdev 0 get rmhsub 0 PACSUB b |
| 366 | if lt r 0 |
| 367 | ret rmerr r |
| 368 | end |
| 369 | put rmst 0 RMSASUB |
| 370 | ret 1 |
| 371 | end |
| 372 | if eq s RMSASUB |
| 373 | r = pavaspace 0 72 1099511627776 8589934592 65536 |
| 374 | if lt r 0 |
| 375 | ret rmerr r |
| 376 | end |
| 377 | r = brmalloc get rmhcli 0 get rmhdev 0 get rmhvas 0 PACVAS b |
| 378 | if lt r 0 |
| 379 | ret rmerr r |
| 380 | end |
| 381 | put rmst 0 RMSAVAS |
| 382 | ret 1 |
| 383 | end |
| 384 | if eq s RMSAVAS |
| 385 | r = patsg 0 0 get rmhvas 0 PAENGGR |
| 386 | if lt r 0 |
| 387 | ret rmerr r |
| 388 | end |
| 389 | r = brmalloc get rmhcli 0 get rmhdev 0 get rmhtsg 0 PACTSG b |
| 390 | if lt r 0 |
| 391 | ret rmerr r |
| 392 | end |
| 393 | put rmst 0 RMSATSG |
| 394 | ret 1 |
| 395 | end |
| 396 | if eq s RMSATSG |
| 397 | r = pactxsh get rmhvas 0 PACTXAS 0 |
| 398 | if lt r 0 |
| 399 | ret rmerr r |
| 400 | end |
| 401 | r = brmalloc get rmhcli 0 get rmhtsg 0 get rmhctx 0 PACCTX b |
| 402 | if lt r 0 |
| 403 | ret rmerr r |
| 404 | end |
| 405 | put rmst 0 RMSACTX |
| 406 | ret 1 |
| 407 | end |
| 408 | if eq s RMSACTX |
| 409 | rmfillin |
| 410 | r = pachan |
| 411 | if lt r 0 |
| 412 | ret rmerr r |
| 413 | end |
| 414 | r = brmalloc get rmhcli 0 get rmhdev 0 get rmhchan 0 PACGPF b |
| 415 | if lt r 0 |
| 416 | ret rmerr r |
| 417 | end |
| 418 | put rmst 0 RMSACHAN |
| 419 | ret 1 |
| 420 | end |
| 421 | if eq s RMSACHAN |
| 422 | put rmst 0 RMSREADY |
| 423 | ret 1 |
| 424 | end |
| 425 | if eq s RMSSCHED |
| 426 | put chopen get rmslot 0 1 |
| 427 | put rmst 0 RMSACTV |
| 428 | ret 1 |
| 429 | end |
| 430 | if eq s RMSDIS |
| 431 | put chopen get rmslot 0 2 |
| 432 | put rmst 0 RMSDRAIN |
| 433 | ret 1 |
| 434 | end |
| 435 | if eq s RMSFCHAN |
| 436 | r = brmfree get rmhcli 0 get rmhctx 0 b |
| 437 | if lt r 0 |
| 438 | ret rmerr r |
| 439 | end |
| 440 | put rmst 0 RMSFCTX |
| 441 | ret 1 |
| 442 | end |
| 443 | if eq s RMSFCTX |
| 444 | r = brmfree get rmhcli 0 get rmhtsg 0 b |
| 445 | if lt r 0 |
| 446 | ret rmerr r |
| 447 | end |
| 448 | put rmst 0 RMSFTSG |
| 449 | ret 1 |
| 450 | end |
| 451 | if eq s RMSFTSG |
| 452 | if eq get rmtree 0 1 |
| 453 | r = brmfree get rmhcli 0 get rmhvas 0 b |
| 454 | if lt r 0 |
| 455 | ret rmerr r |
| 456 | end |
| 457 | put rmst 0 RMSFVAS |
| 458 | ret 1 |
| 459 | end |
| 460 | put rmst 0 RMSDONE |
| 461 | ret 1 |
| 462 | end |
| 463 | if eq s RMSFVAS |
| 464 | r = brmfree get rmhcli 0 get rmhsub 0 b |
| 465 | if lt r 0 |
| 466 | ret rmerr r |
| 467 | end |
| 468 | put rmst 0 RMSFSUB |
| 469 | ret 1 |
| 470 | end |
| 471 | if eq s RMSFSUB |
| 472 | r = brmfree get rmhcli 0 get rmhdev 0 b |
| 473 | if lt r 0 |
| 474 | ret rmerr r |
| 475 | end |
| 476 | put rmst 0 RMSFDEV |
| 477 | ret 1 |
| 478 | end |
| 479 | if eq s RMSFDEV |
| 480 | r = brmfree get rmhcli 0 get rmhcli 0 b |
| 481 | if lt r 0 |
| 482 | ret rmerr r |
| 483 | end |
| 484 | put rmst 0 RMSFROOT |
| 485 | ret 1 |
| 486 | end |
| 487 | if eq s RMSFROOT |
| 488 | put rmst 0 RMSDONE |
| 489 | ret 1 |
| 490 | end |
| 491 | ret 0 |
| 492 | end |
| 493 | fn rmbind c ulong gen ulong to long |
| 494 | if ge c CMSLOTS |
| 495 | ret RMEINVAL |
| 496 | end |
| 497 | if or ne get rmst 0 RMSIDLE ne get rmepoch 0 0 |
| 498 | ret RMESTATE |
| 499 | end |
| 500 | if ne get mmwkind 0 1 |
| 501 | ret RMECAP |
| 502 | end |
| 503 | if or lt get mmwst 0 MMWDMA ge get mmwst 0 MMWQUAR |
| 504 | ret RMESTATE |
| 505 | end |
| 506 | if ne get mmwgen 0 gen |
| 507 | ret RMEGEN |
| 508 | end |
| 509 | if or ne get chopen c 2 ne get chepoch c gen |
| 510 | ret RMEBIND |
| 511 | end |
| 512 | in = get chin c |
| 513 | ud = get chud c |
| 514 | gp = get chgp c |
| 515 | if or or ge in GMMAXB ge ud GMMAXB ge gp GMMAXB |
| 516 | ret RMEINVAL |
| 517 | end |
| 518 | if or or not gmlive in not gmlive ud not gmlive gp |
| 519 | ret RMECAP |
| 520 | end |
| 521 | if or ne get rqdead 0 0 ne get bstate 0 9 |
| 522 | ret RMECAP |
| 523 | end |
| 524 | put rmslot 0 c |
| 525 | put rmepoch 0 gen |
| 526 | note Vendor mem_utils_gm107.c:1232 uses a GPU virtual address, not backing PA. |
| 527 | put rmgpa 0 get gmbva gp |
| 528 | put rmgn 0 ulong get chent c |
| 529 | put rmupa 0 get gmbpa ud |
| 530 | put rmipa 0 get gmbpa in |
| 531 | put rmrpa 0 get gmbpa in |
| 532 | put rmchid 0 ulong get chchid c |
| 533 | ret RMOK |
| 534 | end |
| 535 | fn rmpub gen ulong to long |
| 536 | if ne gen get rmepoch 0 |
| 537 | ret RMEGEN |
| 538 | end |
| 539 | if ne get rmst 0 RMSACTV |
| 540 | ret RMESTATE |
| 541 | end |
| 542 | ret mmwpublish gen |
| 543 | end |
| 544 | fn rmlose gen ulong to long |
| 545 | if ne gen get rmepoch 0 |
| 546 | ret RMEGEN |
| 547 | end |
| 548 | c = get rmslot 0 |
| 549 | if ne c GMNONE |
| 550 | in = get chin c |
| 551 | ud = get chud c |
| 552 | gp = get chgp c |
| 553 | if and lt in GMMAXB gmlive in |
| 554 | r = gmquar in |
| 555 | end |
| 556 | if and lt ud GMMAXB gmlive ud |
| 557 | r = gmquar ud |
| 558 | end |
| 559 | if and lt gp GMMAXB gmlive gp |
| 560 | r = gmquar gp |
| 561 | end |
| 562 | end |
| 563 | if eq get mmwst 0 MMWPUB |
| 564 | r = mmwquar gen |
| 565 | end |
| 566 | put rmst 0 RMSQUAR |
| 567 | ret RMOK |
| 568 | end |
| 569 | fn rmsub c ulong pb ulong off uint n uint to long |
| 570 | if ge c CMSLOTS |
| 571 | ret RMEINVAL |
| 572 | end |
| 573 | if ne c get rmslot 0 |
| 574 | ret RMEINVAL |
| 575 | end |
| 576 | if ne get rmst 0 RMSACTV |
| 577 | ret RMESTATE |
| 578 | end |
| 579 | if ne get rmepoch 0 get mmwgen 0 |
| 580 | ret RMEGEN |
| 581 | end |
| 582 | if ne get mmwst 0 MMWPUB |
| 583 | ret RMESTATE |
| 584 | end |
| 585 | if or ne get chopen c 1 ne get chepoch c get mmwgen 0 |
| 586 | ret RMESTATE |
| 587 | end |
| 588 | st = get cmst c |
| 589 | if and and ne st CMSBIND ne st CMSACTV ne st CMSIDLE |
| 590 | ret RMESTATE |
| 591 | end |
| 592 | if ne get cmgen c get mmwgen 0 |
| 593 | ret RMEGEN |
| 594 | end |
| 595 | if not gmlive get cmbuf c |
| 596 | ret RMEBIND |
| 597 | end |
| 598 | if ne get cmbgen c ulong get gmbgen get cmbuf c |
| 599 | ret RMEGEN |
| 600 | end |
| 601 | if not gmlive pb |
| 602 | ret RMEBIND |
| 603 | end |
| 604 | ent = get chent c |
| 605 | p = get cmput c |
| 606 | if or lt ent 2 ge sub p get cmret c sub ent 1 |
| 607 | ret RMEBIND |
| 608 | end |
| 609 | if or ne p get chput c ne get cmret c get chret c |
| 610 | ret RMEBIND |
| 611 | end |
| 612 | r = rmtail c pb off n |
| 613 | if ne r RMOK |
| 614 | ret r |
| 615 | end |
| 616 | r = chsubmit c pb off n |
| 617 | if ne r CHOK |
| 618 | ret r |
| 619 | end |
| 620 | note No fallible checks after publication: the preflight proves cmsub(c,1)'s predicates. |
| 621 | put cmput c add p uint 1 |
| 622 | put cmst c CMSACTV |
| 623 | ret RMOK |
| 624 | end |
| 625 | note Pure submission preflight; immutable backing is read before the ring entry is published. |
| 626 | fn rmtail c ulong pb ulong off uint n uint to long |
| 627 | if or ne and off 3 0 lt n uint CMCWDS |
| 628 | ret RMEINVAL |
| 629 | end |
| 630 | if gt n CHLENMX |
| 631 | ret RMERANGE |
| 632 | end |
| 633 | bytes = mul ulong n 4 |
| 634 | if gt add ulong off bytes get gmbsz pb |
| 635 | ret RMERANGE |
| 636 | end |
| 637 | va = add get gmbva pb ulong off |
| 638 | if ge va CHVALIM |
| 639 | ret RMERANGE |
| 640 | end |
| 641 | r = cmrel 0 get cmva c add get cmput c uint 1 |
| 642 | if ne r long CMCWDS |
| 643 | ret RMEBIND |
| 644 | end |
| 645 | va = add get gmbpa pb ulong off |
| 646 | va = add va bytes |
| 647 | va = sub va mul CMCWDS 4 |
| 648 | for i ulong CMCWDS |
| 649 | if ne uint mmrd32 add va mul i 4 get cmwds i |
| 650 | ret RMEBIND |
| 651 | end |
| 652 | end |
| 653 | ret RMOK |
| 654 | end |