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/aienux/crates/aienos-accel/accel.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 / aienux / crates / aienos-accel / accel.om` 1602 lines ยท 43982 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note aienux/crates/aienos-accel/accel.om: Pure-Omega AIENOS GB10 accelerator PCI, 3 note capability, BAR, hardware profile, diagnostics, and register ledger decoders. 4 note Converted from aienux crates/aienos-accel/src/{lib,pci,profile,registers}.rs. 5 note Compose with: si/directives/om2.om aienux/crates/aienos-accel/accel.om ... 6 7 note PCI identity and read-only PMC register offsets observed for GB10 on DGX Spark 8 const ACCEL_NVIDIA_VENDOR_ID ulong 0x10de 9 const ACCEL_GB10_DEVICE_ID ulong 0x2e12 10 const ACCEL_PMC_BOOT_0 ulong 0 11 const ACCEL_PMC_BOOT_42 ulong 0x0a00 12 13 note PCI configuration space sizes and capability identifiers 14 const ACCEL_CONFIG_HEADER_SIZE ulong 64 15 const ACCEL_CONFIG_SPACE_SIZE ulong 256 16 const ACCEL_CONFIG_EXTENDED_SIZE ulong 4096 17 const ACCEL_STATUS_CAPS_LIST ulong 0x0010 18 19 const ACCEL_CAP_ID_PM uchar 0x01 20 const ACCEL_CAP_ID_MSI uchar 0x05 21 const ACCEL_CAP_ID_VENDOR uchar 0x09 22 const ACCEL_CAP_ID_PCIE uchar 0x10 23 const ACCEL_CAP_ID_MSIX uchar 0x11 24 25 const ACCEL_MAX_CAPS ulong 48 26 const ACCEL_MAX_EXT_CAPS ulong 64 27 const ACCEL_MAX_EXT_WORDS ulong 64 28 29 note PciError codes 30 const ACCEL_PCI_OK int 0 31 const ACCEL_PCI_ERR_TRUNCATED int -1 32 const ACCEL_PCI_ERR_OUT_OF_BOUNDS int -2 33 const ACCEL_PCI_ERR_INVALID_BAR int -3 34 const ACCEL_PCI_ERR_CAP_LOOP int -4 35 const ACCEL_PCI_ERR_TOO_MANY_CAPS int -5 36 const ACCEL_PCI_ERR_INVALID_HDR_TYPE int -6 37 const ACCEL_PCI_ERR_WRONG_CAP int -7 38 39 note Bar / BarKind tags 40 const ACCEL_BAR_NONE ulong 0 41 const ACCEL_BAR_MEMORY ulong 1 42 const ACCEL_BAR_IO ulong 2 43 44 note BarSize tags 45 const ACCEL_BAR_SIZE_UNKNOWN ulong 0 46 const ACCEL_BAR_SIZE_KNOWN ulong 1 47 48 note LinkSpeed tags 49 const ACCEL_LINK_UNKNOWN ulong 0 50 const ACCEL_LINK_GEN1 ulong 1 51 const ACCEL_LINK_GEN2 ulong 2 52 const ACCEL_LINK_GEN3 ulong 3 53 const ACCEL_LINK_GEN4 ulong 4 54 const ACCEL_LINK_GEN5 ulong 5 55 const ACCEL_LINK_GEN6 ulong 6 56 57 note Provenance Source tags 58 const ACCEL_SRC_NONE ulong 0 59 const ACCEL_SRC_UEFI_FW ulong 1 60 const ACCEL_SRC_NATIVE_PCI ulong 2 61 const ACCEL_SRC_LINUX_SYSFS ulong 3 62 const ACCEL_SRC_LINUX_PROCFS ulong 4 63 const ACCEL_SRC_LINUX_ACPI ulong 5 64 const ACCEL_SRC_SYNTHETIC ulong 6 65 const ACCEL_SRC_DERIVED ulong 7 66 67 note Fact State tags 68 const ACCEL_STATE_UNKNOWN ulong 0 69 const ACCEL_STATE_OBSERVED ulong 1 70 const ACCEL_STATE_DERIVED ulong 2 71 72 note Gb10Rejection codes 73 const ACCEL_GB10_OK int 0 74 const ACCEL_REJ_NOT_NVIDIA int -1 75 const ACCEL_REJ_WRONG_DEVICE int -2 76 const ACCEL_REJ_MEM_DISABLED int -3 77 const ACCEL_REJ_BAR0_MISSING int -4 78 const ACCEL_REJ_BAR0_NOT_MEM int -5 79 const ACCEL_REJ_BAR0_UNPROGRAMMED int -6 80 const ACCEL_REJ_BAR0_NOT_64BIT int -7 81 82 note Register ledger enums 83 const ACCEL_REG_ACCESS_RO ulong 0 84 const ACCEL_REG_ACCESS_RW ulong 1 85 const ACCEL_REG_ACCESS_UNKNOWN ulong 2 86 const ACCEL_REG_SAFETY_ESTABLISHED ulong 0 87 const ACCEL_REG_SAFETY_APPROVAL ulong 1 88 const ACCEL_REG_COUNT ulong 2 89 90 note RootBridgeOutcome tags 91 const ACCEL_ROOT_NONE ulong 0 92 const ACCEL_ROOT_REFUSED ulong 1 93 const ACCEL_ROOT_SCANNED ulong 2 94 const ACCEL_MAX_ROOTS ulong 16 95 96 note Gb10Profile fact indices (0..27) 97 const ACCEL_FACT_VENDOR_ID ulong 0 98 const ACCEL_FACT_DEVICE_ID ulong 1 99 const ACCEL_FACT_SUBSYS_VENDOR ulong 2 100 const ACCEL_FACT_SUBSYS_ID ulong 3 101 const ACCEL_FACT_REVISION ulong 4 102 const ACCEL_FACT_CLASS ulong 5 103 const ACCEL_FACT_COMMAND ulong 6 104 const ACCEL_FACT_STATUS ulong 7 105 const ACCEL_FACT_BAR0 ulong 8 106 const ACCEL_FACT_BAR_SIZE0 ulong 14 107 const ACCEL_FACT_PCIE ulong 20 108 const ACCEL_FACT_MSI ulong 21 109 const ACCEL_FACT_MSIX ulong 22 110 const ACCEL_FACT_IOMMU_GROUP ulong 23 111 const ACCEL_FACT_NUMA_NODE ulong 24 112 const ACCEL_FACT_FW_PATH ulong 25 113 const ACCEL_FACT_PMC_BOOT_0 ulong 26 114 const ACCEL_FACT_PMC_BOOT_42 ulong 27 115 const ACCEL_FACT_COUNT ulong 28 116 117 note Text constants for deterministic rendering and register ledger 118 text accel_hex_digits "`0123456789abcdef`" 119 text accel_t_true "true" 120 text accel_t_false "false" 121 text accel_t_unknown "unknown" 122 text accel_t_obs " [observed source=" 123 text accel_t_der " [derived source=" 124 text accel_t_nver " native_verified=" 125 text accel_t_rbrk "]\n" 126 text accel_t_colon_sp ": " 127 text accel_t_nl "\n" 128 129 text accel_src_uefi "uefi-firmware-service" 130 text accel_src_native "aienos-native-pci" 131 text accel_src_sysfs "linux-sysfs" 132 text accel_src_procfs "linux-procfs" 133 text accel_src_acpi "linux-acpi" 134 text accel_src_synth "synthetic-fixture" 135 text accel_src_deriv "derived" 136 137 text accel_d_bridges "gb10_pci_root_bridges: " 138 text accel_d_failed "lookup failed\n" 139 text accel_d_open_p "gb10_pci_root_open[" 140 text accel_d_refused "]: refused (" 141 text accel_d_rparen ")\n" 142 text accel_d_root_p "gb10_pci_root[" 143 text accel_d_seg "]: segment " 144 text accel_d_devs " devices " 145 text accel_d_br " bridges " 146 text accel_d_wins " windows " 147 text accel_d_cand_p "gb10_pci_candidate[" 148 text accel_d_cs "]: command_status " 149 text accel_d_bar0 " bar0 " 150 151 text accel_p_loc "gb10.profile.location: segment " 152 text accel_p_bus " bus " 153 text accel_p_dev " device " 154 text accel_p_fn " function " 155 text accel_p_vid "gb10.profile.vendor_id" 156 text accel_p_did "gb10.profile.device_id" 157 text accel_p_svid "gb10.profile.subsystem_vendor_id" 158 text accel_p_sid "gb10.profile.subsystem_id" 159 text accel_p_rev "gb10.profile.revision" 160 text accel_p_cls "gb10.profile.class" 161 text accel_p_cmd "gb10.profile.command" 162 text accel_p_sts "gb10.profile.status" 163 text accel_p_bar "gb10.profile.bar[" 164 text accel_p_bsz "gb10.profile.bar_size[" 165 text accel_p_pcie "gb10.profile.pcie" 166 text accel_p_msi "gb10.profile.msi" 167 text accel_p_msix "gb10.profile.msix" 168 text accel_p_iommu "gb10.profile.iommu_group" 169 text accel_p_numa "gb10.profile.numa_node" 170 text accel_p_fw "gb10.profile.firmware_path" 171 text accel_p_b0 "gb10.profile.pmc_boot_0" 172 text accel_p_b42 "gb10.profile.pmc_boot_42" 173 174 text accel_f_cls0 "ClassCode { base: " 175 text accel_f_cls1 ", subclass: " 176 text accel_f_cls2 ", prog_if: " 177 text accel_f_rbrace " }" 178 text accel_f_bar0 "BarFacts { index: " 179 text accel_f_bar1 ", kind: " 180 text accel_f_bar2 ", base: " 181 text accel_f_bar3 ", is_64_bit: " 182 text accel_f_bar4 ", prefetchable: " 183 text accel_f_none "None" 184 text accel_f_mem "Memory" 185 text accel_f_io "Io" 186 text accel_f_pcie0 "PcieFacts { present: " 187 text accel_f_pcie1 ", max_payload_bytes: " 188 text accel_f_pcie2 ", link: " 189 text accel_f_msi0 "MsiFacts { present: " 190 text accel_f_msi1 ", enabled: " 191 text accel_f_msi2 ", is_64_bit: " 192 text accel_f_msi3 ", maskable: " 193 text accel_f_msi4 ", capable_vectors: " 194 text accel_f_msix0 "MsixFacts { present: " 195 text accel_f_msix1 ", enabled: " 196 text accel_f_msix2 ", function_masked: " 197 text accel_f_msix3 ", vectors: " 198 text accel_f_msix4 ", table_bir: " 199 text accel_f_msix5 ", table_offset: " 200 text accel_f_msix6 ", pba_bir: " 201 text accel_f_msix7 ", pba_offset: " 202 text accel_f_some_link "Some(PcieLink)" 203 204 text accel_reg_block "GB10 PMC" 205 text accel_reg_name_0 "BOOT_0" 206 text accel_reg_name_1 "BOOT_42" 207 text accel_reg_ev "crates/aienos-accel PMC_BOOT_0/PMC_BOOT_42 offsets used by the UEFI handoff; meaning not established" 208 text accel_r_pfx "gb10.register " 209 text accel_r_off ": offset " 210 text accel_r_wid " width " 211 text accel_r_acc " access ReadOnly safety EstablishedRead native_observed false semantics_known false observed_value unknown observed_by none evidence \"" 212 text accel_r_end "\"\n" 213 214 note Global decoded state buffers 215 216 note Gb10Bar result: 0=segment, 1=bus, 2=device, 3=function, 4=physical_base 217 global accel_gb10_bar ulong 5 218 219 note Gb10Identity result: 0..3=loc, 4=physical_base, 5=pmc_boot_0, 6=pmc_boot_42 220 global accel_gb10_id ulong 7 221 222 note Decoded type 0 PCI Header 223 note 0=vendor_id, 1=device_id, 2=command, 3=status, 4=revision, 5=prog_if, 224 note 6=subclass, 7=class_code, 8=header_type, 9=multifunction, 225 note 10=subsystem_vendor_id, 11=subsystem_id, 12=capability_pointer, 226 note 13=interrupt_line, 14=interrupt_pin 227 global accel_hdr ulong 15 228 global accel_hdr_bar_kind ulong 6 229 global accel_hdr_bar_base ulong 6 230 global accel_hdr_bar_64 ulong 6 231 global accel_hdr_bar_pref ulong 6 232 global accel_hdr_bar_sz_known ulong 6 233 global accel_hdr_bar_sz ulong 6 234 235 note Decoded type 1 PCI BridgeHeader: 0=vid, 1=did, 2=class, 3=subclass, 4=sec_bus, 5=sub_bus 236 global accel_bridge ulong 6 237 238 note Standard capability list (up to 48 entries) 239 global accel_cap_cnt ulong 1 240 global accel_cap_id uchar 48 241 global accel_cap_off uchar 48 242 global accel_cap_next uchar 48 243 244 note Decoded MSI capability: 0=off, 1=en, 2=cap_vec, 3=en_vec, 4=is64, 5=mask, 6=addr, 7=data 245 global accel_msi ulong 8 246 247 note Decoded MSI-X capability: 0=off, 1=en, 2=fmask, 3=vec, 4=tbir, 5=toff, 6=pbir, 7=poff 248 global accel_msix ulong 8 249 250 note Decoded PCIe capability + link: 251 note 0=off, 1=ver, 2=dev_type, 3=slot_impl, 4=max_payload, 5=has_link, 252 note 6=max_speed, 7=max_width, 8=supp_speeds, 9=cur_speed, 10=cur_width, 11=downgraded 253 global accel_pcie ulong 12 254 255 note Extended capability list (up to 64 entries) 256 global accel_ecap_cnt ulong 1 257 global accel_ecap_id ushort 64 258 global accel_ecap_ver uchar 64 259 global accel_ecap_off ushort 64 260 261 note Gb10Match result: 0..3=loc, 4=bar0_base, 5=bar0_64, 6=bar0_pref, 7=bar0_sz_known 262 global accel_match ulong 8 263 264 note Gb10Profile state 265 global accel_prof_loc ulong 4 266 global accel_prof_state ulong 28 267 global accel_prof_src ulong 28 268 global accel_prof_nver ulong 28 269 global accel_prof_val ulong 28 270 global accel_prof_numa long 1 271 global accel_prof_class ulong 3 272 global accel_prof_bar_kind ulong 6 273 global accel_prof_bar_base ulong 6 274 global accel_prof_bar_64 ulong 6 275 global accel_prof_bar_pref ulong 6 276 global accel_prof_pcie ulong 9 277 global accel_prof_msi ulong 5 278 global accel_prof_msix ulong 8 279 global accel_prof_fw_len ulong 1 280 global accel_prof_fw uchar 128 281 282 note RootBridgeOutcome array for discovery diagnostics 283 global accel_root_cnt ulong 1 284 global accel_root_kind ulong 16 285 global accel_root_seg ulong 16 286 global accel_root_devs ulong 16 287 global accel_root_bridges ulong 16 288 global accel_root_wins ulong 16 289 global accel_root_has_cand ulong 16 290 global accel_root_cand_cs ulong 16 291 global accel_root_cand_lo ulong 16 292 global accel_root_cand_hi ulong 16 293 global accel_root_st_len ulong 16 294 global accel_root_st uchar 512 295 296 note === Low-level little-endian readers and formatting helpers === 297 298 fn accel_u16_le buf view uchar * off ulong to ulong 299 b0 = ulong get buf off 300 b1 = ulong get buf add off 1 301 ret or b0 shl b1 8 302 end 303 304 fn accel_u32_le buf view uchar * off ulong to ulong 305 b0 = ulong get buf off 306 b1 = ulong get buf add off 1 307 b2 = ulong get buf add off 2 308 b3 = ulong get buf add off 3 309 ret or or b0 shl b1 8 or shl b2 16 shl b3 24 310 end 311 312 fn accel_put_u16_le buf edit uchar * off ulong v ulong to void 313 put buf off uchar and v 0xff 314 put buf add off 1 uchar and shr v 8 0xff 315 end 316 317 fn accel_put_u32_le buf edit uchar * off ulong v ulong to void 318 put buf off uchar and v 0xff 319 put buf add off 1 uchar and shr v 8 0xff 320 put buf add off 2 uchar and shr v 16 0xff 321 put buf add off 3 uchar and shr v 24 0xff 322 end 323 324 fn accel_make_loc dst edit ulong 4 seg ulong bus ulong dev ulong func ulong to void 325 put dst 0 seg 326 put dst 1 bus 327 put dst 2 dev 328 put dst 3 func 329 end 330 331 fn accel_buf_put_byte dst edit uchar * pos ulong ch uchar to ulong 332 if lt pos len dst 333 put dst pos ch 334 ret add pos 1 335 end 336 ret pos 337 end 338 339 fn accel_buf_put_str dst edit uchar * pos ulong src view uchar * to ulong 340 slen = len src 341 cap = len dst 342 cur = pos 343 for i ulong slen bound 1024 344 if lt cur cap 345 put dst cur get src i 346 cur = add cur 1 347 end 348 end 349 ret cur 350 end 351 352 fn accel_buf_put_u64_dec dst edit uchar * pos ulong v ulong to ulong 353 if eq v 0 354 ret accel_buf_put_byte dst pos uchar 48 355 end 356 tmp = new uchar 20 0 357 n = ulong 0 358 x = v 359 while gt x 0 bound 20 360 put tmp n uchar add 48 rem x 10 361 x = div x 10 362 n = add n 1 363 end 364 cur = pos 365 i = n 366 while gt i 0 bound 20 367 i = sub i 1 368 cur = accel_buf_put_byte dst cur get tmp i 369 end 370 ret cur 371 end 372 373 fn accel_buf_put_i64_dec dst edit uchar * pos ulong v long to ulong 374 if lt v 0 375 cur = accel_buf_put_byte dst pos uchar 45 376 mag = ulong sub 0 v 377 ret accel_buf_put_u64_dec dst cur mag 378 end 379 ret accel_buf_put_u64_dec dst pos ulong v 380 end 381 382 fn accel_buf_put_hex_w dst edit uchar * pos ulong v ulong digits ulong to ulong 383 cur = accel_buf_put_byte dst pos uchar 48 384 cur = accel_buf_put_byte dst cur uchar 120 385 if or eq digits 0 gt digits 16 386 ret cur 387 end 388 for i ulong digits bound 16 389 sh = mul sub sub digits 1 i 4 390 nib = and shr v sh 0x0f 391 cur = accel_buf_put_byte dst cur get accel_hex_digits nib 392 end 393 ret cur 394 end 395 396 fn accel_buf_put_bool dst edit uchar * pos ulong flag ulong to ulong 397 if ne flag 0 398 ret accel_buf_put_str dst pos accel_t_true 399 end 400 ret accel_buf_put_str dst pos accel_t_false 401 end 402 403 fn accel_buf_contains hay view uchar * hlen ulong needle view uchar * to bool 404 if gt hlen len hay 405 ret false 406 end 407 nlen = len needle 408 if eq nlen 0 409 ret true 410 end 411 if gt nlen hlen 412 ret false 413 end 414 limit = add sub hlen nlen 1 415 for i ulong limit bound 8192 416 matched = true 417 for j ulong nlen bound 512 418 if ne get hay add i j get needle j 419 matched = false 420 break 421 end 422 end 423 if matched 424 ret true 425 end 426 end 427 ret false 428 end 429 430 fn accel_buf_eq hay view uchar * hlen ulong expected view uchar * to bool 431 if ne hlen len expected 432 ret false 433 end 434 if gt hlen len hay 435 ret false 436 end 437 for i ulong hlen bound 4096 438 if ne get hay i get expected i 439 ret false 440 end 441 end 442 ret true 443 end 444 445 note === lib.rs: Gb10Bar::from_config & discovery diagnostics === 446 447 fn accel_gb10_bar_from_config loc view ulong 4 vd ulong cs ulong bar0_lo ulong bar0_hi ulong to bool 448 exp_vd = or shl ACCEL_GB10_DEVICE_ID 16 ACCEL_NVIDIA_VENDOR_ID 449 if ne and vd 0xffffffff exp_vd 450 ret false 451 end 452 if eq and cs 0x2 0 453 ret false 454 end 455 if ne and bar0_lo 0x7 0x4 456 ret false 457 end 458 lo_addr = and bar0_lo 0xfffffff0 459 hi_addr = and bar0_hi 0xffffffff 460 phys = or shl hi_addr 32 lo_addr 461 if eq phys 0 462 ret false 463 end 464 max_base = sub 0xffffffffffffffff add ACCEL_PMC_BOOT_42 4 465 if gt phys max_base 466 ret false 467 end 468 for i ulong 4 469 put accel_gb10_bar i get loc i 470 end 471 put accel_gb10_bar 4 phys 472 ret true 473 end 474 475 fn accel_gb10_id_set pmc0 ulong pmc42 ulong to void 476 for i ulong 5 477 put accel_gb10_id i get accel_gb10_bar i 478 end 479 put accel_gb10_id 5 and pmc0 0xffffffff 480 put accel_gb10_id 6 and pmc42 0xffffffff 481 end 482 483 fn accel_roots_clear to void 484 put accel_root_cnt 0 0 485 for i ulong ACCEL_MAX_ROOTS 486 put accel_root_kind i ACCEL_ROOT_NONE 487 put accel_root_seg i 0 488 put accel_root_devs i 0 489 put accel_root_bridges i 0 490 put accel_root_wins i 0 491 put accel_root_has_cand i 0 492 put accel_root_cand_cs i 0 493 put accel_root_cand_lo i 0 494 put accel_root_cand_hi i 0 495 put accel_root_st_len i 0 496 end 497 end 498 499 fn accel_roots_push_none to int 500 cnt = get accel_root_cnt 0 501 if ge cnt ACCEL_MAX_ROOTS 502 ret -1 503 end 504 put accel_root_kind cnt ACCEL_ROOT_NONE 505 put accel_root_cnt 0 add cnt 1 506 ret 0 507 end 508 509 fn accel_roots_push_refused status view uchar * to int 510 cnt = get accel_root_cnt 0 511 if ge cnt ACCEL_MAX_ROOTS 512 ret -1 513 end 514 slen = len status 515 if gt slen 32 516 slen = ulong 32 517 end 518 put accel_root_kind cnt ACCEL_ROOT_REFUSED 519 put accel_root_st_len cnt slen 520 base = mul cnt 32 521 for i ulong slen bound 32 522 put accel_root_st add base i get status i 523 end 524 put accel_root_cnt 0 add cnt 1 525 ret 0 526 end 527 528 fn accel_roots_push_scanned seg ulong devs ulong bridges ulong wins ulong to int 529 cnt = get accel_root_cnt 0 530 if ge cnt ACCEL_MAX_ROOTS 531 ret -1 532 end 533 put accel_root_kind cnt ACCEL_ROOT_SCANNED 534 put accel_root_seg cnt seg 535 put accel_root_devs cnt devs 536 put accel_root_bridges cnt bridges 537 put accel_root_wins cnt wins 538 put accel_root_has_cand cnt 0 539 put accel_root_cnt 0 add cnt 1 540 ret int cnt 541 end 542 543 fn accel_roots_set_candidate idx ulong cs ulong bar0_lo ulong bar0_hi ulong to void 544 if lt idx ACCEL_MAX_ROOTS 545 put accel_root_has_cand idx 1 546 put accel_root_cand_cs idx and cs 0xffffffff 547 put accel_root_cand_lo idx and bar0_lo 0xffffffff 548 put accel_root_cand_hi idx and bar0_hi 0xffffffff 549 end 550 end 551 552 fn accel_write_diag_refused dst edit uchar * pos ulong vis ulong idx ulong to ulong 553 cur = accel_buf_put_str dst pos accel_d_open_p 554 cur = accel_buf_put_u64_dec dst cur vis 555 cur = accel_buf_put_str dst cur accel_d_refused 556 slen = get accel_root_st_len idx 557 base = mul idx 32 558 for j ulong slen bound 32 559 cur = accel_buf_put_byte dst cur get accel_root_st add base j 560 end 561 ret accel_buf_put_str dst cur accel_d_rparen 562 end 563 564 fn accel_write_diag_scanned dst edit uchar * pos ulong vis ulong idx ulong to ulong 565 cur = accel_buf_put_str dst pos accel_d_root_p 566 cur = accel_buf_put_u64_dec dst cur vis 567 cur = accel_buf_put_str dst cur accel_d_seg 568 cur = accel_buf_put_u64_dec dst cur get accel_root_seg idx 569 cur = accel_buf_put_str dst cur accel_d_devs 570 cur = accel_buf_put_u64_dec dst cur get accel_root_devs idx 571 cur = accel_buf_put_str dst cur accel_d_br 572 cur = accel_buf_put_u64_dec dst cur get accel_root_bridges idx 573 cur = accel_buf_put_str dst cur accel_d_wins 574 cur = accel_buf_put_u64_dec dst cur get accel_root_wins idx 575 cur = accel_buf_put_str dst cur accel_t_nl 576 if ne get accel_root_has_cand idx 0 577 cur = accel_buf_put_str dst cur accel_d_cand_p 578 cur = accel_buf_put_u64_dec dst cur vis 579 cur = accel_buf_put_str dst cur accel_d_cs 580 cur = accel_buf_put_hex_w dst cur get accel_root_cand_cs idx 8 581 cur = accel_buf_put_str dst cur accel_d_bar0 582 cur = accel_buf_put_hex_w dst cur get accel_root_cand_hi idx 8 583 cur = accel_buf_put_byte dst cur uchar 58 584 cur = accel_buf_put_hex_w dst cur get accel_root_cand_lo idx 8 585 cur = accel_buf_put_str dst cur accel_t_nl 586 end 587 ret cur 588 end 589 590 fn accel_write_discovery_diagnostics dst edit uchar * has_handles bool handles ulong to ulong 591 cur = accel_buf_put_str dst 0 accel_d_bridges 592 if not has_handles 593 ret accel_buf_put_str dst cur accel_d_failed 594 end 595 cur = accel_buf_put_u64_dec dst cur handles 596 cur = accel_buf_put_str dst cur accel_t_nl 597 cnt = get accel_root_cnt 0 598 vis = ulong 0 599 for i ulong cnt bound 16 600 knd = get accel_root_kind i 601 if eq knd ACCEL_ROOT_REFUSED 602 cur = accel_write_diag_refused dst cur vis i 603 vis = add vis 1 604 else 605 if eq knd ACCEL_ROOT_SCANNED 606 cur = accel_write_diag_scanned dst cur vis i 607 vis = add vis 1 608 end 609 end 610 end 611 ret cur 612 end 613 614 note === pci.rs: PCI configuration header, BARs, capabilities, extended capabilities === 615 616 fn accel_pci_decode_bars bytes view uchar * offset ulong to int 617 for i ulong 6 618 put accel_hdr_bar_kind i ACCEL_BAR_NONE 619 put accel_hdr_bar_base i 0 620 put accel_hdr_bar_64 i 0 621 put accel_hdr_bar_pref i 0 622 put accel_hdr_bar_sz_known i 0 623 put accel_hdr_bar_sz i 0 624 end 625 blen = len bytes 626 idx = ulong 0 627 while lt idx 6 bound 6 628 lo_off = add offset mul idx 4 629 if gt add lo_off 4 blen 630 ret ACCEL_PCI_ERR_OUT_OF_BOUNDS 631 end 632 lo = accel_u32_le bytes lo_off 633 if eq lo 0 634 idx = add idx 1 635 continue 636 end 637 if eq and lo 0x1 0x1 638 if ne and lo 0x6 0 639 ret ACCEL_PCI_ERR_INVALID_BAR 640 end 641 put accel_hdr_bar_kind idx ACCEL_BAR_IO 642 put accel_hdr_bar_base idx and lo 0xfffffffc 643 idx = add idx 1 644 continue 645 end 646 btype = and shr lo 1 0x3 647 pref = ulong 0 648 if ne and lo 0x8 0 649 pref = ulong 1 650 end 651 if eq btype 0 652 put accel_hdr_bar_kind idx ACCEL_BAR_MEMORY 653 put accel_hdr_bar_base idx and lo 0xfffffff0 654 put accel_hdr_bar_64 idx 0 655 put accel_hdr_bar_pref idx pref 656 idx = add idx 1 657 else 658 if eq btype 2 659 if ge add idx 1 6 660 ret ACCEL_PCI_ERR_INVALID_BAR 661 end 662 hi_off = add lo_off 4 663 if gt add hi_off 4 blen 664 ret ACCEL_PCI_ERR_OUT_OF_BOUNDS 665 end 666 hi = accel_u32_le bytes hi_off 667 put accel_hdr_bar_kind idx ACCEL_BAR_MEMORY 668 put accel_hdr_bar_base idx or shl hi 32 and lo 0xfffffff0 669 put accel_hdr_bar_64 idx 1 670 put accel_hdr_bar_pref idx pref 671 idx = add idx 2 672 else 673 ret ACCEL_PCI_ERR_INVALID_BAR 674 end 675 end 676 end 677 ret ACCEL_PCI_OK 678 end 679 680 fn accel_pci_header_parse bytes view uchar * to int 681 if lt len bytes ACCEL_CONFIG_HEADER_SIZE 682 ret ACCEL_PCI_ERR_TRUNCATED 683 end 684 htype = ulong get bytes 0x0e 685 if ne and htype 0x7f 0 686 ret ACCEL_PCI_ERR_INVALID_HDR_TYPE 687 end 688 rc = accel_pci_decode_bars bytes 0x10 689 if ne rc ACCEL_PCI_OK 690 ret rc 691 end 692 put accel_hdr 0 accel_u16_le bytes 0x00 693 put accel_hdr 1 accel_u16_le bytes 0x02 694 put accel_hdr 2 accel_u16_le bytes 0x04 695 put accel_hdr 3 accel_u16_le bytes 0x06 696 put accel_hdr 4 ulong get bytes 0x08 697 put accel_hdr 5 ulong get bytes 0x09 698 put accel_hdr 6 ulong get bytes 0x0a 699 put accel_hdr 7 ulong get bytes 0x0b 700 put accel_hdr 8 htype 701 mf = ulong 0 702 if ne and htype 0x80 0 703 mf = ulong 1 704 end 705 put accel_hdr 9 mf 706 put accel_hdr 10 accel_u16_le bytes 0x2c 707 put accel_hdr 11 accel_u16_le bytes 0x2e 708 put accel_hdr 12 ulong get bytes 0x34 709 put accel_hdr 13 ulong get bytes 0x3c 710 put accel_hdr 14 ulong get bytes 0x3d 711 ret ACCEL_PCI_OK 712 end 713 714 fn accel_pci_header_memory_enabled to bool 715 ret ne and get accel_hdr 2 0x0002 0 716 end 717 718 fn accel_pci_header_has_cap_list to bool 719 ret ne and get accel_hdr 3 ACCEL_STATUS_CAPS_LIST 0 720 end 721 722 fn accel_pci_memory_bar_size low ulong high ulong is_64_bit bool to ulong 723 if is_64_bit 724 lo_m = and low 0xfffffff0 725 hi_m = and high 0xffffffff 726 mask = or shl hi_m 32 lo_m 727 if or eq mask 0 eq mask 0xffffffffffffffff 728 ret 0 729 end 730 inv = xor mask 0xffffffffffffffff 731 sz = add inv 1 732 if ne and sz sub sz 1 0 733 ret 0 734 end 735 if gt sz shl ulong 1 46 736 ret 0 737 end 738 ret sz 739 end 740 mask32 = and low 0xfffffff0 741 if or eq mask32 0 eq mask32 0xffffffff 742 ret 0 743 end 744 inv32 = xor mask32 0xffffffff 745 sz32 = add inv32 1 746 if ne and sz32 sub sz32 1 0 747 ret 0 748 end 749 if gt sz32 shl ulong 1 32 750 ret 0 751 end 752 ret sz32 753 end 754 755 fn accel_pci_io_bar_size low ulong to ulong 756 mask32 = and low 0xfffffffc 757 if or eq mask32 0 eq mask32 0xffffffff 758 ret 0 759 end 760 inv32 = xor mask32 0xffffffff 761 sz32 = add inv32 1 762 if ne and sz32 sub sz32 1 0 763 ret 0 764 end 765 if gt sz32 shl ulong 1 32 766 ret 0 767 end 768 ret sz32 769 end 770 771 fn accel_pci_walk_capabilities bytes view uchar * to int 772 if lt len bytes ACCEL_CONFIG_SPACE_SIZE 773 ret ACCEL_PCI_ERR_TRUNCATED 774 end 775 put accel_cap_cnt 0 0 776 st = accel_u16_le bytes 0x06 777 if eq and st ACCEL_STATUS_CAPS_LIST 0 778 ret ACCEL_PCI_OK 779 end 780 off = ulong get bytes 0x34 781 seen = new ulong 4 0 782 while ne off 0 bound 64 783 if or lt off 0x40 ne rem off 4 0 784 ret ACCEL_PCI_ERR_OUT_OF_BOUNDS 785 end 786 if gt add off 2 ACCEL_CONFIG_SPACE_SIZE 787 ret ACCEL_PCI_ERR_OUT_OF_BOUNDS 788 end 789 word = div off 64 790 bit = shl ulong 1 rem off 64 791 if ne and get seen word bit 0 792 ret ACCEL_PCI_ERR_CAP_LOOP 793 end 794 put seen word or get seen word bit 795 cid = get bytes off 796 nxt = get bytes add off 1 797 cnt = get accel_cap_cnt 0 798 if eq cnt ACCEL_MAX_CAPS 799 ret ACCEL_PCI_ERR_TOO_MANY_CAPS 800 end 801 put accel_cap_id cnt cid 802 put accel_cap_off cnt uchar off 803 put accel_cap_next cnt nxt 804 put accel_cap_cnt 0 add cnt 1 805 off = ulong nxt 806 end 807 ret ACCEL_PCI_OK 808 end 809 810 fn accel_pci_cap_find cid uchar to long 811 cnt = get accel_cap_cnt 0 812 for i ulong cnt bound 48 813 if eq get accel_cap_id i cid 814 ret long i 815 end 816 end 817 ret -1 818 end 819 820 fn accel_pci_decode_msi bytes view uchar * cap_id uchar cap_off uchar to int 821 if ne cap_id ACCEL_CAP_ID_MSI 822 ret ACCEL_PCI_ERR_WRONG_CAP 823 end 824 off = ulong cap_off 825 if gt add off 8 len bytes 826 ret ACCEL_PCI_ERR_OUT_OF_BOUNDS 827 end 828 ctrl = accel_u16_le bytes add off 2 829 put accel_msi 0 off 830 if ne and ctrl 0x0001 0 831 put accel_msi 1 1 832 else 833 put accel_msi 1 0 834 end 835 put accel_msi 2 shl ulong 1 and shr ctrl 1 0x7 836 put accel_msi 3 shl ulong 1 and shr ctrl 4 0x7 837 if ne and ctrl 0x0100 0 838 put accel_msi 5 1 839 else 840 put accel_msi 5 0 841 end 842 addr = accel_u32_le bytes add off 4 843 data_off = add off 8 844 if ne and ctrl 0x0080 0 845 put accel_msi 4 1 846 if gt add off 12 len bytes 847 ret ACCEL_PCI_ERR_OUT_OF_BOUNDS 848 end 849 addr = or shl accel_u32_le bytes add off 8 32 addr 850 data_off = add off 12 851 else 852 put accel_msi 4 0 853 end 854 if gt add data_off 2 len bytes 855 ret ACCEL_PCI_ERR_OUT_OF_BOUNDS 856 end 857 put accel_msi 6 addr 858 put accel_msi 7 accel_u16_le bytes data_off 859 ret ACCEL_PCI_OK 860 end 861 862 fn accel_pci_decode_msix bytes view uchar * cap_id uchar cap_off uchar to int 863 if ne cap_id ACCEL_CAP_ID_MSIX 864 ret ACCEL_PCI_ERR_WRONG_CAP 865 end 866 off = ulong cap_off 867 if gt add off 12 len bytes 868 ret ACCEL_PCI_ERR_OUT_OF_BOUNDS 869 end 870 put accel_msix 0 off 871 ctrl = accel_u16_le bytes add off 2 872 if ne and ctrl 0x8000 0 873 put accel_msix 1 1 874 else 875 put accel_msix 1 0 876 end 877 if ne and ctrl 0x4000 0 878 put accel_msix 2 1 879 else 880 put accel_msix 2 0 881 end 882 put accel_msix 3 add and ctrl 0x07ff 1 883 tbl = accel_u32_le bytes add off 4 884 put accel_msix 4 and tbl 0x7 885 put accel_msix 5 and tbl 0xfffffff8 886 pba = accel_u32_le bytes add off 8 887 put accel_msix 6 and pba 0x7 888 put accel_msix 7 and pba 0xfffffff8 889 ret ACCEL_PCI_OK 890 end 891 892 fn accel_link_speed_from_enc enc ulong to ulong 893 if and ge enc 1 le enc 6 894 ret enc 895 end 896 ret ACCEL_LINK_UNKNOWN 897 end 898 899 fn accel_link_speed_gt speed ulong to ulong 900 if eq speed ACCEL_LINK_GEN1 901 ret 2 902 end 903 if eq speed ACCEL_LINK_GEN2 904 ret 5 905 end 906 if eq speed ACCEL_LINK_GEN3 907 ret 8 908 end 909 if eq speed ACCEL_LINK_GEN4 910 ret 16 911 end 912 if eq speed ACCEL_LINK_GEN5 913 ret 32 914 end 915 if eq speed ACCEL_LINK_GEN6 916 ret 64 917 end 918 ret 0 919 end 920 921 fn accel_pci_decode_pcie_link bytes view uchar * off ulong to int 922 if gt add off 0x14 len bytes 923 ret ACCEL_PCI_ERR_OUT_OF_BOUNDS 924 end 925 put accel_pcie 5 1 926 lcaps = accel_u32_le bytes add off 0x0c 927 max_spd = accel_link_speed_from_enc and lcaps 0x0f 928 max_wid = and shr lcaps 4 0x3f 929 put accel_pcie 6 max_spd 930 put accel_pcie 7 max_wid 931 if le add off 0x20 len bytes 932 put accel_pcie 8 and accel_u32_le bytes add off 0x1c 0x7f 933 else 934 put accel_pcie 8 0 935 end 936 lsts = accel_u16_le bytes add off 0x12 937 cur_spd = accel_link_speed_from_enc and lsts 0x0f 938 cur_wid = and shr lsts 4 0x3f 939 put accel_pcie 9 cur_spd 940 put accel_pcie 10 cur_wid 941 down = ulong 0 942 if and ne max_spd ACCEL_LINK_UNKNOWN ne cur_spd ACCEL_LINK_UNKNOWN 943 if ne cur_spd max_spd 944 down = ulong 1 945 end 946 end 947 if lt cur_wid max_wid 948 down = ulong 1 949 end 950 put accel_pcie 11 down 951 ret ACCEL_PCI_OK 952 end 953 954 fn accel_pci_decode_pcie bytes view uchar * cap_id uchar cap_off uchar to int 955 if ne cap_id ACCEL_CAP_ID_PCIE 956 ret ACCEL_PCI_ERR_WRONG_CAP 957 end 958 off = ulong cap_off 959 if gt add off 8 len bytes 960 ret ACCEL_PCI_ERR_OUT_OF_BOUNDS 961 end 962 cap = accel_u16_le bytes add off 2 963 dev_type = and shr cap 4 0x0f 964 dcaps = accel_u32_le bytes add off 4 965 max_pay = shl ulong 128 and dcaps 0x7 966 slot_im = ulong 0 967 if ne and cap 0x0100 0 968 slot_im = ulong 1 969 end 970 put accel_pcie 0 off 971 put accel_pcie 1 and cap 0x0f 972 put accel_pcie 2 dev_type 973 put accel_pcie 3 slot_im 974 put accel_pcie 4 max_pay 975 if or eq dev_type 0x8 eq dev_type 0x9 976 for i ulong 7 977 put accel_pcie add 5 i 0 978 end 979 ret ACCEL_PCI_OK 980 end 981 ret accel_pci_decode_pcie_link bytes off 982 end 983 984 fn accel_pci_walk_ext_capabilities bytes view uchar * to int 985 put accel_ecap_cnt 0 0 986 if gt add ACCEL_CONFIG_SPACE_SIZE 4 len bytes 987 ret ACCEL_PCI_OK 988 end 989 off = ulong ACCEL_CONFIG_SPACE_SIZE 990 seen = new ulong 64 0 991 cnt = ulong 0 992 while ne off 0 bound 70 993 if or ne rem off 4 0 gt add off 4 ACCEL_CONFIG_EXTENDED_SIZE 994 ret ACCEL_PCI_ERR_OUT_OF_BOUNDS 995 end 996 if gt add off 4 len bytes 997 ret ACCEL_PCI_ERR_OUT_OF_BOUNDS 998 end 999 word = div off 64 1000 bit = shl ulong 1 rem off 64 1001 if ne and get seen word bit 0 1002 ret ACCEL_PCI_ERR_CAP_LOOP 1003 end 1004 put seen word or get seen word bit 1005 if eq cnt ACCEL_MAX_EXT_CAPS 1006 ret ACCEL_PCI_ERR_TOO_MANY_CAPS 1007 end 1008 hdr = accel_u32_le bytes off 1009 put accel_ecap_id cnt ushort and hdr 0xffff 1010 put accel_ecap_ver cnt uchar and shr hdr 16 0x0f 1011 put accel_ecap_off cnt ushort off 1012 cnt = add cnt 1 1013 put accel_ecap_cnt 0 cnt 1014 if eq and hdr 0xffff 0xffff 1015 break 1016 end 1017 off = and shr hdr 20 0x0fff 1018 end 1019 ret ACCEL_PCI_OK 1020 end 1021 1022 fn accel_pci_ecap_find cid ushort to long 1023 cnt = get accel_ecap_cnt 0 1024 for i ulong cnt bound 64 1025 if eq get accel_ecap_id i cid 1026 ret long i 1027 end 1028 end 1029 ret -1 1030 end 1031 1032 fn accel_pci_bridge_parse bytes view uchar * to int 1033 if lt len bytes ACCEL_CONFIG_HEADER_SIZE 1034 ret ACCEL_PCI_ERR_TRUNCATED 1035 end 1036 htype = ulong get bytes 0x0e 1037 if ne and htype 0x7f 0x01 1038 ret ACCEL_PCI_ERR_INVALID_HDR_TYPE 1039 end 1040 put accel_bridge 0 accel_u16_le bytes 0x00 1041 put accel_bridge 1 accel_u16_le bytes 0x02 1042 put accel_bridge 2 ulong get bytes 0x0b 1043 put accel_bridge 3 ulong get bytes 0x0a 1044 put accel_bridge 4 ulong get bytes 0x19 1045 put accel_bridge 5 ulong get bytes 0x1a 1046 ret ACCEL_PCI_OK 1047 end 1048 1049 fn accel_pci_bridge_has_window to bool 1050 sec = get accel_bridge 4 1051 sub_bus = get accel_bridge 5 1052 if eq sec 0 1053 ret false 1054 end 1055 ret ge sub_bus sec 1056 end 1057 1058 note === profile.rs: Provenance-tagged Gb10Profile & GB10 contract validation === 1059 1060 fn accel_source_linux_interpreted src ulong to bool 1061 if eq src ACCEL_SRC_LINUX_SYSFS 1062 ret true 1063 end 1064 if eq src ACCEL_SRC_LINUX_PROCFS 1065 ret true 1066 end 1067 ret eq src ACCEL_SRC_LINUX_ACPI 1068 end 1069 1070 fn accel_buf_put_source dst edit uchar * pos ulong src ulong to ulong 1071 if eq src ACCEL_SRC_UEFI_FW 1072 ret accel_buf_put_str dst pos accel_src_uefi 1073 end 1074 if eq src ACCEL_SRC_NATIVE_PCI 1075 ret accel_buf_put_str dst pos accel_src_native 1076 end 1077 if eq src ACCEL_SRC_LINUX_SYSFS 1078 ret accel_buf_put_str dst pos accel_src_sysfs 1079 end 1080 if eq src ACCEL_SRC_LINUX_PROCFS 1081 ret accel_buf_put_str dst pos accel_src_procfs 1082 end 1083 if eq src ACCEL_SRC_LINUX_ACPI 1084 ret accel_buf_put_str dst pos accel_src_acpi 1085 end 1086 if eq src ACCEL_SRC_SYNTHETIC 1087 ret accel_buf_put_str dst pos accel_src_synth 1088 end 1089 ret accel_buf_put_str dst pos accel_src_deriv 1090 end 1091 1092 fn accel_prof_set_observed fid ulong src ulong to void 1093 put accel_prof_state fid ACCEL_STATE_OBSERVED 1094 put accel_prof_src fid src 1095 nv = ulong 0 1096 if eq src ACCEL_SRC_NATIVE_PCI 1097 nv = ulong 1 1098 end 1099 put accel_prof_nver fid nv 1100 end 1101 1102 fn accel_prof_set_derived fid ulong src ulong to void 1103 put accel_prof_state fid ACCEL_STATE_DERIVED 1104 put accel_prof_src fid src 1105 put accel_prof_nver fid 0 1106 end 1107 1108 fn accel_prof_mark_native_verified fid ulong to void 1109 put accel_prof_nver fid 1 1110 end 1111 1112 fn accel_prof_with_source fid ulong src ulong to void 1113 put accel_prof_src fid src 1114 end 1115 1116 fn accel_prof_is_known fid ulong to bool 1117 ret ne get accel_prof_state fid ACCEL_STATE_UNKNOWN 1118 end 1119 1120 fn accel_profile_init_unknown loc view ulong 4 to void 1121 for i ulong 4 1122 put accel_prof_loc i get loc i 1123 end 1124 for i ulong ACCEL_FACT_COUNT 1125 put accel_prof_state i ACCEL_STATE_UNKNOWN 1126 put accel_prof_src i ACCEL_SRC_NONE 1127 put accel_prof_nver i 0 1128 put accel_prof_val i 0 1129 end 1130 put accel_prof_numa 0 0 1131 for i ulong 3 1132 put accel_prof_class i 0 1133 end 1134 for i ulong 6 1135 put accel_prof_bar_kind i ACCEL_BAR_NONE 1136 put accel_prof_bar_base i 0 1137 put accel_prof_bar_64 i 0 1138 put accel_prof_bar_pref i 0 1139 end 1140 for i ulong 9 1141 put accel_prof_pcie i 0 1142 end 1143 for i ulong 5 1144 put accel_prof_msi i 0 1145 end 1146 for i ulong 8 1147 put accel_prof_msix i 0 1148 end 1149 put accel_prof_fw_len 0 0 1150 end 1151 1152 fn accel_profile_fill_caps bytes view uchar * src ulong to void 1153 pi = accel_pci_cap_find ACCEL_CAP_ID_PCIE 1154 if ge pi 0 1155 idx = ulong pi 1156 rc = accel_pci_decode_pcie bytes get accel_cap_id idx get accel_cap_off idx 1157 if eq rc ACCEL_PCI_OK 1158 put accel_prof_pcie 0 1 1159 put accel_prof_pcie 1 get accel_pcie 4 1160 for k ulong 7 1161 put accel_prof_pcie add 2 k get accel_pcie add 5 k 1162 end 1163 end 1164 end 1165 accel_prof_set_observed ACCEL_FACT_PCIE src 1166 1167 mi = accel_pci_cap_find ACCEL_CAP_ID_MSI 1168 if ge mi 0 1169 idx = ulong mi 1170 rc = accel_pci_decode_msi bytes get accel_cap_id idx get accel_cap_off idx 1171 if eq rc ACCEL_PCI_OK 1172 put accel_prof_msi 0 1 1173 put accel_prof_msi 1 get accel_msi 1 1174 put accel_prof_msi 2 get accel_msi 4 1175 put accel_prof_msi 3 get accel_msi 5 1176 put accel_prof_msi 4 get accel_msi 2 1177 end 1178 end 1179 accel_prof_set_observed ACCEL_FACT_MSI src 1180 1181 xi = accel_pci_cap_find ACCEL_CAP_ID_MSIX 1182 if ge xi 0 1183 idx = ulong xi 1184 rc = accel_pci_decode_msix bytes get accel_cap_id idx get accel_cap_off idx 1185 if eq rc ACCEL_PCI_OK 1186 put accel_prof_msix 0 1 1187 put accel_prof_msix 1 get accel_msix 1 1188 put accel_prof_msix 2 get accel_msix 2 1189 put accel_prof_msix 3 get accel_msix 3 1190 put accel_prof_msix 4 get accel_msix 4 1191 put accel_prof_msix 5 get accel_msix 5 1192 put accel_prof_msix 6 get accel_msix 6 1193 put accel_prof_msix 7 get accel_msix 7 1194 end 1195 end 1196 accel_prof_set_observed ACCEL_FACT_MSIX src 1197 end 1198 1199 fn accel_profile_from_pci_config loc view ulong 4 bytes view uchar * src ulong to int 1200 rc = accel_pci_header_parse bytes 1201 if ne rc ACCEL_PCI_OK 1202 ret rc 1203 end 1204 accel_profile_init_unknown loc 1205 put accel_prof_val ACCEL_FACT_VENDOR_ID get accel_hdr 0 1206 accel_prof_set_observed ACCEL_FACT_VENDOR_ID src 1207 put accel_prof_val ACCEL_FACT_DEVICE_ID get accel_hdr 1 1208 accel_prof_set_observed ACCEL_FACT_DEVICE_ID src 1209 put accel_prof_val ACCEL_FACT_SUBSYS_VENDOR get accel_hdr 10 1210 accel_prof_set_observed ACCEL_FACT_SUBSYS_VENDOR src 1211 put accel_prof_val ACCEL_FACT_SUBSYS_ID get accel_hdr 11 1212 accel_prof_set_observed ACCEL_FACT_SUBSYS_ID src 1213 put accel_prof_val ACCEL_FACT_REVISION get accel_hdr 4 1214 accel_prof_set_observed ACCEL_FACT_REVISION src 1215 put accel_prof_class 0 get accel_hdr 7 1216 put accel_prof_class 1 get accel_hdr 6 1217 put accel_prof_class 2 get accel_hdr 5 1218 accel_prof_set_observed ACCEL_FACT_CLASS src 1219 put accel_prof_val ACCEL_FACT_COMMAND get accel_hdr 2 1220 accel_prof_set_observed ACCEL_FACT_COMMAND src 1221 put accel_prof_val ACCEL_FACT_STATUS get accel_hdr 3 1222 accel_prof_set_observed ACCEL_FACT_STATUS src 1223 for i ulong 6 1224 put accel_prof_bar_kind i get accel_hdr_bar_kind i 1225 put accel_prof_bar_base i get accel_hdr_bar_base i 1226 put accel_prof_bar_64 i get accel_hdr_bar_64 i 1227 put accel_prof_bar_pref i get accel_hdr_bar_pref i 1228 accel_prof_set_observed add ACCEL_FACT_BAR0 i src 1229 end 1230 rc = accel_pci_walk_capabilities bytes 1231 if ne rc ACCEL_PCI_OK 1232 ret rc 1233 end 1234 accel_profile_fill_caps bytes src 1235 ret ACCEL_PCI_OK 1236 end 1237 1238 fn accel_write_fact_tail dst edit uchar * pos ulong fid ulong to ulong 1239 st = get accel_prof_state fid 1240 cur = pos 1241 if eq st ACCEL_STATE_OBSERVED 1242 cur = accel_buf_put_str dst cur accel_t_obs 1243 else 1244 cur = accel_buf_put_str dst cur accel_t_der 1245 end 1246 cur = accel_buf_put_source dst cur get accel_prof_src fid 1247 cur = accel_buf_put_str dst cur accel_t_nver 1248 cur = accel_buf_put_bool dst cur get accel_prof_nver fid 1249 ret accel_buf_put_str dst cur accel_t_rbrk 1250 end 1251 1252 fn accel_write_u64_fact dst edit uchar * pos ulong label view uchar * fid ulong to ulong 1253 cur = accel_buf_put_str dst pos label 1254 cur = accel_buf_put_str dst cur accel_t_colon_sp 1255 if eq get accel_prof_state fid ACCEL_STATE_UNKNOWN 1256 cur = accel_buf_put_str dst cur accel_t_unknown 1257 ret accel_buf_put_str dst cur accel_t_nl 1258 end 1259 cur = accel_buf_put_u64_dec dst cur get accel_prof_val fid 1260 ret accel_write_fact_tail dst cur fid 1261 end 1262 1263 fn accel_write_bar_size_fact dst edit uchar * pos ulong idx ulong to ulong 1264 fid = add ACCEL_FACT_BAR_SIZE0 idx 1265 cur = accel_buf_put_str dst pos accel_p_bsz 1266 cur = accel_buf_put_u64_dec dst cur idx 1267 cur = accel_buf_put_byte dst cur uchar 93 1268 cur = accel_buf_put_str dst cur accel_t_colon_sp 1269 if eq get accel_prof_state fid ACCEL_STATE_UNKNOWN 1270 cur = accel_buf_put_str dst cur accel_t_unknown 1271 ret accel_buf_put_str dst cur accel_t_nl 1272 end 1273 cur = accel_buf_put_u64_dec dst cur get accel_prof_val fid 1274 ret accel_write_fact_tail dst cur fid 1275 end 1276 1277 fn accel_write_class_fact dst edit uchar * pos ulong to ulong 1278 cur = accel_buf_put_str dst pos accel_p_cls 1279 cur = accel_buf_put_str dst cur accel_t_colon_sp 1280 if eq get accel_prof_state ACCEL_FACT_CLASS ACCEL_STATE_UNKNOWN 1281 cur = accel_buf_put_str dst cur accel_t_unknown 1282 ret accel_buf_put_str dst cur accel_t_nl 1283 end 1284 cur = accel_buf_put_str dst cur accel_f_cls0 1285 cur = accel_buf_put_u64_dec dst cur get accel_prof_class 0 1286 cur = accel_buf_put_str dst cur accel_f_cls1 1287 cur = accel_buf_put_u64_dec dst cur get accel_prof_class 1 1288 cur = accel_buf_put_str dst cur accel_f_cls2 1289 cur = accel_buf_put_u64_dec dst cur get accel_prof_class 2 1290 cur = accel_buf_put_str dst cur accel_f_rbrace 1291 ret accel_write_fact_tail dst cur ACCEL_FACT_CLASS 1292 end 1293 1294 fn accel_write_bar_fact dst edit uchar * pos ulong idx ulong to ulong 1295 fid = add ACCEL_FACT_BAR0 idx 1296 cur = accel_buf_put_str dst pos accel_p_bar 1297 cur = accel_buf_put_u64_dec dst cur idx 1298 cur = accel_buf_put_byte dst cur uchar 93 1299 cur = accel_buf_put_str dst cur accel_t_colon_sp 1300 if eq get accel_prof_state fid ACCEL_STATE_UNKNOWN 1301 cur = accel_buf_put_str dst cur accel_t_unknown 1302 ret accel_buf_put_str dst cur accel_t_nl 1303 end 1304 cur = accel_buf_put_str dst cur accel_f_bar0 1305 cur = accel_buf_put_u64_dec dst cur idx 1306 cur = accel_buf_put_str dst cur accel_f_bar1 1307 knd = get accel_prof_bar_kind idx 1308 if eq knd ACCEL_BAR_MEMORY 1309 cur = accel_buf_put_str dst cur accel_f_mem 1310 else 1311 if eq knd ACCEL_BAR_IO 1312 cur = accel_buf_put_str dst cur accel_f_io 1313 else 1314 cur = accel_buf_put_str dst cur accel_f_none 1315 end 1316 end 1317 cur = accel_buf_put_str dst cur accel_f_bar2 1318 cur = accel_buf_put_u64_dec dst cur get accel_prof_bar_base idx 1319 cur = accel_buf_put_str dst cur accel_f_bar3 1320 cur = accel_buf_put_bool dst cur get accel_prof_bar_64 idx 1321 cur = accel_buf_put_str dst cur accel_f_bar4 1322 cur = accel_buf_put_bool dst cur get accel_prof_bar_pref idx 1323 cur = accel_buf_put_str dst cur accel_f_rbrace 1324 ret accel_write_fact_tail dst cur fid 1325 end 1326 1327 fn accel_write_cap_facts dst edit uchar * pos ulong to ulong 1328 cur = accel_buf_put_str dst pos accel_p_pcie 1329 cur = accel_buf_put_str dst cur accel_t_colon_sp 1330 if eq get accel_prof_state ACCEL_FACT_PCIE ACCEL_STATE_UNKNOWN 1331 cur = accel_buf_put_str dst cur accel_t_unknown 1332 cur = accel_buf_put_str dst cur accel_t_nl 1333 else 1334 cur = accel_buf_put_str dst cur accel_f_pcie0 1335 cur = accel_buf_put_bool dst cur get accel_prof_pcie 0 1336 cur = accel_buf_put_str dst cur accel_f_pcie1 1337 cur = accel_buf_put_u64_dec dst cur get accel_prof_pcie 1 1338 cur = accel_buf_put_str dst cur accel_f_pcie2 1339 if ne get accel_prof_pcie 2 0 1340 cur = accel_buf_put_str dst cur accel_f_some_link 1341 else 1342 cur = accel_buf_put_str dst cur accel_f_none 1343 end 1344 cur = accel_buf_put_str dst cur accel_f_rbrace 1345 cur = accel_write_fact_tail dst cur ACCEL_FACT_PCIE 1346 end 1347 cur = accel_buf_put_str dst cur accel_p_msi 1348 cur = accel_buf_put_str dst cur accel_t_colon_sp 1349 if eq get accel_prof_state ACCEL_FACT_MSI ACCEL_STATE_UNKNOWN 1350 cur = accel_buf_put_str dst cur accel_t_unknown 1351 cur = accel_buf_put_str dst cur accel_t_nl 1352 else 1353 cur = accel_buf_put_str dst cur accel_f_msi0 1354 cur = accel_buf_put_bool dst cur get accel_prof_msi 0 1355 cur = accel_buf_put_str dst cur accel_f_msi1 1356 cur = accel_buf_put_bool dst cur get accel_prof_msi 1 1357 cur = accel_buf_put_str dst cur accel_f_msi2 1358 cur = accel_buf_put_bool dst cur get accel_prof_msi 2 1359 cur = accel_buf_put_str dst cur accel_f_msi3 1360 cur = accel_buf_put_bool dst cur get accel_prof_msi 3 1361 cur = accel_buf_put_str dst cur accel_f_msi4 1362 cur = accel_buf_put_u64_dec dst cur get accel_prof_msi 4 1363 cur = accel_buf_put_str dst cur accel_f_rbrace 1364 cur = accel_write_fact_tail dst cur ACCEL_FACT_MSI 1365 end 1366 cur = accel_buf_put_str dst cur accel_p_msix 1367 cur = accel_buf_put_str dst cur accel_t_colon_sp 1368 if eq get accel_prof_state ACCEL_FACT_MSIX ACCEL_STATE_UNKNOWN 1369 cur = accel_buf_put_str dst cur accel_t_unknown 1370 cur = accel_buf_put_str dst cur accel_t_nl 1371 else 1372 cur = accel_buf_put_str dst cur accel_f_msix0 1373 cur = accel_buf_put_bool dst cur get accel_prof_msix 0 1374 cur = accel_buf_put_str dst cur accel_f_msix1 1375 cur = accel_buf_put_bool dst cur get accel_prof_msix 1 1376 cur = accel_buf_put_str dst cur accel_f_msix2 1377 cur = accel_buf_put_bool dst cur get accel_prof_msix 2 1378 cur = accel_buf_put_str dst cur accel_f_msix3 1379 cur = accel_buf_put_u64_dec dst cur get accel_prof_msix 3 1380 cur = accel_buf_put_str dst cur accel_f_msix4 1381 cur = accel_buf_put_u64_dec dst cur get accel_prof_msix 4 1382 cur = accel_buf_put_str dst cur accel_f_msix5 1383 cur = accel_buf_put_u64_dec dst cur get accel_prof_msix 5 1384 cur = accel_buf_put_str dst cur accel_f_msix6 1385 cur = accel_buf_put_u64_dec dst cur get accel_prof_msix 6 1386 cur = accel_buf_put_str dst cur accel_f_msix7 1387 cur = accel_buf_put_u64_dec dst cur get accel_prof_msix 7 1388 cur = accel_buf_put_str dst cur accel_f_rbrace 1389 cur = accel_write_fact_tail dst cur ACCEL_FACT_MSIX 1390 end 1391 ret cur 1392 end 1393 1394 fn accel_write_tail_facts dst edit uchar * pos ulong to ulong 1395 cur = accel_write_u64_fact dst pos accel_p_iommu ACCEL_FACT_IOMMU_GROUP 1396 cur = accel_buf_put_str dst cur accel_p_numa 1397 cur = accel_buf_put_str dst cur accel_t_colon_sp 1398 if eq get accel_prof_state ACCEL_FACT_NUMA_NODE ACCEL_STATE_UNKNOWN 1399 cur = accel_buf_put_str dst cur accel_t_unknown 1400 cur = accel_buf_put_str dst cur accel_t_nl 1401 else 1402 cur = accel_buf_put_i64_dec dst cur get accel_prof_numa 0 1403 cur = accel_write_fact_tail dst cur ACCEL_FACT_NUMA_NODE 1404 end 1405 cur = accel_buf_put_str dst cur accel_p_fw 1406 cur = accel_buf_put_str dst cur accel_t_colon_sp 1407 if eq get accel_prof_state ACCEL_FACT_FW_PATH ACCEL_STATE_UNKNOWN 1408 cur = accel_buf_put_str dst cur accel_t_unknown 1409 cur = accel_buf_put_str dst cur accel_t_nl 1410 else 1411 cur = accel_buf_put_byte dst cur uchar 34 1412 flen = get accel_prof_fw_len 0 1413 for i ulong flen bound 128 1414 cur = accel_buf_put_byte dst cur get accel_prof_fw i 1415 end 1416 cur = accel_buf_put_byte dst cur uchar 34 1417 cur = accel_write_fact_tail dst cur ACCEL_FACT_FW_PATH 1418 end 1419 cur = accel_write_u64_fact dst cur accel_p_b0 ACCEL_FACT_PMC_BOOT_0 1420 cur = accel_write_u64_fact dst cur accel_p_b42 ACCEL_FACT_PMC_BOOT_42 1421 ret cur 1422 end 1423 1424 fn accel_profile_write dst edit uchar * to ulong 1425 cur = accel_buf_put_str dst 0 accel_p_loc 1426 cur = accel_buf_put_u64_dec dst cur get accel_prof_loc 0 1427 cur = accel_buf_put_str dst cur accel_p_bus 1428 cur = accel_buf_put_u64_dec dst cur get accel_prof_loc 1 1429 cur = accel_buf_put_str dst cur accel_p_dev 1430 cur = accel_buf_put_u64_dec dst cur get accel_prof_loc 2 1431 cur = accel_buf_put_str dst cur accel_p_fn 1432 cur = accel_buf_put_u64_dec dst cur get accel_prof_loc 3 1433 cur = accel_buf_put_str dst cur accel_t_nl 1434 cur = accel_write_u64_fact dst cur accel_p_vid ACCEL_FACT_VENDOR_ID 1435 cur = accel_write_u64_fact dst cur accel_p_did ACCEL_FACT_DEVICE_ID 1436 cur = accel_write_u64_fact dst cur accel_p_svid ACCEL_FACT_SUBSYS_VENDOR 1437 cur = accel_write_u64_fact dst cur accel_p_sid ACCEL_FACT_SUBSYS_ID 1438 cur = accel_write_u64_fact dst cur accel_p_rev ACCEL_FACT_REVISION 1439 cur = accel_write_class_fact dst cur 1440 cur = accel_write_u64_fact dst cur accel_p_cmd ACCEL_FACT_COMMAND 1441 cur = accel_write_u64_fact dst cur accel_p_sts ACCEL_FACT_STATUS 1442 for i ulong 6 1443 cur = accel_write_bar_fact dst cur i 1444 end 1445 for i ulong 6 1446 cur = accel_write_bar_size_fact dst cur i 1447 end 1448 cur = accel_write_cap_facts dst cur 1449 ret accel_write_tail_facts dst cur 1450 end 1451 1452 fn accel_match_gb10 loc view ulong 4 to int 1453 if ne get accel_hdr 0 ACCEL_NVIDIA_VENDOR_ID 1454 ret ACCEL_REJ_NOT_NVIDIA 1455 end 1456 if ne get accel_hdr 1 ACCEL_GB10_DEVICE_ID 1457 ret ACCEL_REJ_WRONG_DEVICE 1458 end 1459 if not accel_pci_header_memory_enabled 1460 ret ACCEL_REJ_MEM_DISABLED 1461 end 1462 knd = get accel_hdr_bar_kind 0 1463 if eq knd ACCEL_BAR_NONE 1464 ret ACCEL_REJ_BAR0_MISSING 1465 end 1466 if eq knd ACCEL_BAR_IO 1467 ret ACCEL_REJ_BAR0_NOT_MEM 1468 end 1469 base = get accel_hdr_bar_base 0 1470 if eq base 0 1471 ret ACCEL_REJ_BAR0_UNPROGRAMMED 1472 end 1473 if eq get accel_hdr_bar_64 0 0 1474 ret ACCEL_REJ_BAR0_NOT_64BIT 1475 end 1476 for i ulong 4 1477 put accel_match i get loc i 1478 end 1479 put accel_match 4 base 1480 put accel_match 5 get accel_hdr_bar_64 0 1481 put accel_match 6 get accel_hdr_bar_pref 0 1482 put accel_match 7 get accel_hdr_bar_sz_known 0 1483 ret ACCEL_GB10_OK 1484 end 1485 1486 fn accel_gb10_bar_from_header loc view ulong 4 vd ulong cs ulong bar0_lo ulong bar0_hi ulong to int 1487 if ne and vd 0xffff ACCEL_NVIDIA_VENDOR_ID 1488 ret ACCEL_REJ_NOT_NVIDIA 1489 end 1490 if ne and shr vd 16 0xffff ACCEL_GB10_DEVICE_ID 1491 ret ACCEL_REJ_WRONG_DEVICE 1492 end 1493 if eq and cs 0x0002 0 1494 ret ACCEL_REJ_MEM_DISABLED 1495 end 1496 if eq and bar0_lo 0x1 0x1 1497 ret ACCEL_REJ_BAR0_NOT_MEM 1498 end 1499 lo32 = and bar0_lo 0xffffffff 1500 hi32 = and bar0_hi 0xffffffff 1501 if and eq lo32 0 eq hi32 0 1502 ret ACCEL_REJ_BAR0_UNPROGRAMMED 1503 end 1504 if ne and lo32 0x7 0x4 1505 ret ACCEL_REJ_BAR0_NOT_64BIT 1506 end 1507 phys = or shl hi32 32 and lo32 0xfffffff0 1508 if eq phys 0 1509 ret ACCEL_REJ_BAR0_UNPROGRAMMED 1510 end 1511 for i ulong 4 1512 put accel_gb10_bar i get loc i 1513 end 1514 put accel_gb10_bar 4 phys 1515 ret ACCEL_GB10_OK 1516 end 1517 1518 note === registers.rs: Source-backed GB10 register inventory === 1519 1520 fn accel_reg_name_eq name view uchar * expected view uchar * to bool 1521 if ne len name len expected 1522 ret false 1523 end 1524 for i ulong len expected bound 32 1525 if ne get name i get expected i 1526 ret false 1527 end 1528 end 1529 ret true 1530 end 1531 1532 fn accel_reg_find name view uchar * to long 1533 if accel_reg_name_eq name accel_reg_name_0 1534 ret 0 1535 end 1536 if accel_reg_name_eq name accel_reg_name_1 1537 ret 1 1538 end 1539 ret -1 1540 end 1541 1542 fn accel_reg_offset idx ulong to ulong 1543 if eq idx 0 1544 ret ACCEL_PMC_BOOT_0 1545 end 1546 if eq idx 1 1547 ret ACCEL_PMC_BOOT_42 1548 end 1549 ret 0 1550 end 1551 1552 fn accel_reg_width idx ulong to ulong 1553 if lt idx ACCEL_REG_COUNT 1554 ret 32 1555 end 1556 ret 0 1557 end 1558 1559 fn accel_reg_access idx ulong to ulong 1560 if lt idx ACCEL_REG_COUNT 1561 ret ACCEL_REG_ACCESS_RO 1562 end 1563 ret ACCEL_REG_ACCESS_UNKNOWN 1564 end 1565 1566 fn accel_reg_safety idx ulong to ulong 1567 if lt idx ACCEL_REG_COUNT 1568 ret ACCEL_REG_SAFETY_ESTABLISHED 1569 end 1570 ret ACCEL_REG_SAFETY_APPROVAL 1571 end 1572 1573 fn accel_reg_native_observed idx ulong to bool 1574 ret false 1575 end 1576 1577 fn accel_reg_semantics_known idx ulong to bool 1578 ret false 1579 end 1580 1581 fn accel_reg_has_observed_value idx ulong to bool 1582 ret false 1583 end 1584 1585 fn accel_reg_write_one dst edit uchar * pos ulong name view uchar * off ulong to ulong 1586 cur = accel_buf_put_str dst pos accel_r_pfx 1587 cur = accel_buf_put_str dst cur accel_reg_block 1588 cur = accel_buf_put_byte dst cur uchar 46 1589 cur = accel_buf_put_str dst cur name 1590 cur = accel_buf_put_str dst cur accel_r_off 1591 cur = accel_buf_put_hex_w dst cur off 4 1592 cur = accel_buf_put_str dst cur accel_r_wid 1593 cur = accel_buf_put_u64_dec dst cur 32 1594 cur = accel_buf_put_str dst cur accel_r_acc 1595 cur = accel_buf_put_str dst cur accel_reg_ev 1596 ret accel_buf_put_str dst cur accel_r_end 1597 end 1598 1599 fn accel_reg_write_ledger dst edit uchar * to ulong 1600 cur = accel_reg_write_one dst 0 accel_reg_name_0 ACCEL_PMC_BOOT_0 1601 ret accel_reg_write_one dst cur accel_reg_name_1 ACCEL_PMC_BOOT_42 1602 end