interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / aienux / crates / aienos-accel / accel.om

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