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_test.om

801 lines · 19095 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note aienux/crates/aienos-accel/accel_test.om: Behavioral self-test for aienos-accel.
3note Ports all unit tests from src/{lib,pci,profile,registers}.rs and tests/gb10_fixtures.rs.
4note Compose with: si/directives/om2.om aienux/crates/aienos-accel/accel.om aienux/crates/aienos-accel/accel_test.om
5
6text t_access_denied "ACCESS_DENIED"
7text t_diag_l0 "gb10_pci_root_bridges: 2\n"
8text t_diag_l1 "gb10_pci_root_open[0]: refused (ACCESS_DENIED)\n"
9text t_diag_l2 "gb10_pci_root[1]: segment 15 devices 4 bridges 1 windows 1\n"
10text t_diag_l3 "gb10_pci_candidate[1]: command_status 0x00100004 bar0 0x00000000:0x00000000\n"
11text t_diag_fail "gb10_pci_root_bridges: lookup failed\n"
12text t_diag_zero "gb10_pci_root_bridges: 0\n"
13
14text t_prof_vid "gb10.profile.vendor_id: 4318 [observed source=aienos-native-pci native_verified=true]"
15text t_prof_iommu "gb10.profile.iommu_group: unknown"
16text t_prof_bsz0 "gb10.profile.bar_size[0]: unknown"
17
18text t_boot0 "BOOT_0"
19text t_boot42 "BOOT_42"
20text t_boot1 "BOOT_1"
21text t_reg_b0 "GB10 PMC.BOOT_0: offset 0x0000"
22text t_reg_b42 "GB10 PMC.BOOT_42: offset 0x0a00"
23text t_reg_sem "semantics_known false"
24text t_reg_nat "native_observed false"
25
26fn t_fill_base_header buf edit uchar * to void
27for i ulong 256
28put buf i 0
29end
30accel_put_u16_le buf 0x00 0x10de
31accel_put_u16_le buf 0x02 0x2e12
32accel_put_u16_le buf 0x04 0x0007
33accel_put_u16_le buf 0x06 0x0010
34put buf 0x08 uchar 0xa1
35put buf 0x0b uchar 0x03
36end
37
38fn t_fill_gb10_endpoint buf edit uchar * to void
39t_fill_base_header buf
40accel_put_u32_le buf 0x10 0x2400000c
41accel_put_u32_le buf 0x14 0x00000000
42accel_put_u16_le buf 0x2c 0x10de
43accel_put_u16_le buf 0x2e 0x0000
44put buf 0x34 uchar 0x40
45note MSI at 0x40: id 0x05, next 0x50, control 0x0388 (64-bit, maskable, 16 vectors)
46put buf 0x40 ACCEL_CAP_ID_MSI
47put buf 0x41 uchar 0x50
48accel_put_u16_le buf 0x42 0x0388
49accel_put_u32_le buf 0x44 0xfee00000
50accel_put_u16_le buf 0x4c 0x0041
51note PCIe at 0x50: id 0x10, next 0x80, cap 0x0002, max payload 1024, link caps/status
52put buf 0x50 ACCEL_CAP_ID_PCIE
53put buf 0x51 uchar 0x80
54accel_put_u16_le buf 0x52 0x0002
55accel_put_u32_le buf 0x54 0x00000003
56accel_put_u32_le buf 0x5c 0x00457901
57accel_put_u16_le buf 0x62 0x8010
58note MSI-X at 0x80: id 0x11, next 0, control 0x8008 (enabled, 9 vectors), table, pba
59put buf 0x80 ACCEL_CAP_ID_MSIX
60put buf 0x81 uchar 0x00
61accel_put_u16_le buf 0x82 0x8008
62accel_put_u32_le buf 0x84 0x00b90000
63accel_put_u32_le buf 0x88 0x00ba0000
64end
65
66note === Test group 1: lib.rs Gb10Bar::from_config and discovery diagnostics ===
67
68fn test_lib_bar_and_diag to int
69loc = new ulong 4 0
70accel_make_loc loc 15 1 0 0
71if not accel_gb10_bar_from_config loc 0x2e1210de 0x6 0x24000004 0
72ret 1
73end
74if ne get accel_gb10_bar 4 0x24000000
75ret 2
76end
77if accel_gb10_bar_from_config loc 0x2e1210df 0x6 0x24000004 0
78ret 3
79end
80if accel_gb10_bar_from_config loc 0x2e1210de 0x4 0x24000004 0
81ret 4
82end
83if accel_gb10_bar_from_config loc 0x2e1210de 0x6 0x24000000 0
84ret 5
85end
86if accel_gb10_bar_from_config loc 0x2e1210de 0x6 0x00000004 0
87ret 6
88end
89if accel_gb10_bar_from_config loc 0x2e1210de 0x6 0xfffffff4 0xffffffff
90ret 7
91end
92
93note Diagnostics test
94accel_roots_clear
95rc = accel_roots_push_refused t_access_denied
96if ne rc 0
97ret 8
98end
99idx = accel_roots_push_scanned 15 4 1 1
100if lt idx 0
101ret 9
102end
103accel_roots_set_candidate ulong idx 0x100004 0 0
104rc = accel_roots_push_none
105if ne rc 0
106ret 10
107end
108dbuf = new uchar 512 0
109dlen = accel_write_discovery_diagnostics dbuf true 2
110if not accel_buf_contains dbuf dlen t_diag_l0
111ret 11
112end
113if not accel_buf_contains dbuf dlen t_diag_l1
114ret 12
115end
116if not accel_buf_contains dbuf dlen t_diag_l2
117ret 13
118end
119if not accel_buf_contains dbuf dlen t_diag_l3
120ret 14
121end
122accel_roots_clear
123rc = accel_roots_push_none
124dlen = accel_write_discovery_diagnostics dbuf false 0
125if not accel_buf_eq dbuf dlen t_diag_fail
126ret 15
127end
128dlen = accel_write_discovery_diagnostics dbuf true 0
129if not accel_buf_eq dbuf dlen t_diag_zero
130ret 16
131end
132ret 0
133end
134
135note === Test group 2: pci.rs header, BARs, capabilities, bridge ===
136
137fn test_pci_header_and_bars to int
138buf = new uchar 256 0
139t_fill_base_header buf
140accel_put_u32_le buf 0x10 0x2400000c
141accel_put_u32_le buf 0x14 0x00000001
142accel_put_u16_le buf 0x2c 0x10de
143if ne accel_pci_header_parse buf ACCEL_PCI_OK
144ret 20
145end
146if ne get accel_hdr 0 0x10de
147ret 21
148end
149if ne get accel_hdr 1 0x2e12
150ret 22
151end
152if ne get accel_hdr 7 0x03
153ret 23
154end
155if not accel_pci_header_memory_enabled
156ret 24
157end
158if ne get accel_hdr_bar_kind 0 ACCEL_BAR_MEMORY
159ret 25
160end
161if ne get accel_hdr_bar_base 0 0x0000000124000000
162ret 26
163end
164if or eq get accel_hdr_bar_64 0 0 eq get accel_hdr_bar_pref 0 0
165ret 27
166end
167if ne get accel_hdr_bar_kind 1 ACCEL_BAR_NONE
168ret 28
169end
170
171note Reject reserved BAR encodings and 64-bit BAR in last slot
172t_fill_base_header buf
173accel_put_u32_le buf 0x10 0x00000006
174if ne accel_pci_header_parse buf ACCEL_PCI_ERR_INVALID_BAR
175ret 29
176end
177t_fill_base_header buf
178accel_put_u32_le buf 0x24 0x0000000a
179if ne accel_pci_header_parse buf ACCEL_PCI_ERR_INVALID_BAR
180ret 30
181end
182t_fill_base_header buf
183accel_put_u32_le buf 0x24 0x00000004
184if ne accel_pci_header_parse buf ACCEL_PCI_ERR_INVALID_BAR
185ret 31
186end
187t_fill_base_header buf
188accel_put_u32_le buf 0x10 0x00000003
189if ne accel_pci_header_parse buf ACCEL_PCI_ERR_INVALID_BAR
190ret 32
191end
192
193note Truncated header and bridge header type
194trunc = new uchar 16 0
195if ne accel_pci_header_parse trunc ACCEL_PCI_ERR_TRUNCATED
196ret 33
197end
198t_fill_base_header buf
199put buf 0x0e uchar 0x01
200if ne accel_pci_header_parse buf ACCEL_PCI_ERR_INVALID_HDR_TYPE
201ret 34
202end
203
204note BridgeHeader parse and bus window
205put buf 0x19 uchar 0x01
206put buf 0x1a uchar 0x0f
207if ne accel_pci_bridge_parse buf ACCEL_PCI_OK
208ret 35
209end
210if or ne get accel_bridge 4 1 ne get accel_bridge 5 0x0f
211ret 36
212end
213if not accel_pci_bridge_has_window
214ret 37
215end
216put buf 0x19 uchar 0x00
217if ne accel_pci_bridge_parse buf ACCEL_PCI_OK
218ret 38
219end
220if accel_pci_bridge_has_window
221ret 39
222end
223t_fill_base_header buf
224if ne accel_pci_bridge_parse buf ACCEL_PCI_ERR_INVALID_HDR_TYPE
225ret 40
226end
227ret 0
228end
229
230fn test_pci_caps_and_sizes to int
231buf = new uchar 256 0
232
233note Reject capability loop and out-of-bounds
234t_fill_base_header buf
235put buf 0x34 uchar 0x40
236put buf 0x40 ACCEL_CAP_ID_MSI
237put buf 0x41 uchar 0x40
238if ne accel_pci_walk_capabilities buf ACCEL_PCI_ERR_CAP_LOOP
239ret 41
240end
241t_fill_base_header buf
242put buf 0x34 uchar 0xff
243if ne accel_pci_walk_capabilities buf ACCEL_PCI_ERR_OUT_OF_BOUNDS
244ret 42
245end
246t_fill_base_header buf
247put buf 0x34 uchar 0x42
248if ne accel_pci_walk_capabilities buf ACCEL_PCI_ERR_OUT_OF_BOUNDS
249ret 43
250end
251hdr64 = new uchar 64 0
252if ne accel_pci_walk_capabilities hdr64 ACCEL_PCI_ERR_TRUNCATED
253ret 44
254end
255
256note Capability list absence is empty, not error
257t_fill_base_header buf
258accel_put_u16_le buf 0x06 0
259if ne accel_pci_walk_capabilities buf ACCEL_PCI_OK
260ret 45
261end
262if ne get accel_cap_cnt 0 0
263ret 46
264end
265zeros = new uchar 256 0
266if ne accel_pci_walk_capabilities zeros ACCEL_PCI_OK
267ret 47
268end
269if ne get accel_cap_cnt 0 0
270ret 48
271end
272
273note Decode MSI, PCIe, MSI-X from full config space
274t_fill_gb10_endpoint buf
275if ne accel_pci_walk_capabilities buf ACCEL_PCI_OK
276ret 49
277end
278if ne get accel_cap_cnt 0 3
279ret 50
280end
281mi = accel_pci_cap_find ACCEL_CAP_ID_MSI
282if lt mi 0
283ret 51
284end
285if ne accel_pci_decode_msi buf get accel_cap_id ulong mi get accel_cap_off ulong mi ACCEL_PCI_OK
286ret 52
287end
288if or eq get accel_msi 4 0 eq get accel_msi 5 0
289ret 53
290end
291if or ne get accel_msi 1 0 ne get accel_msi 2 16
292ret 54
293end
294if or ne get accel_msi 7 0x0041 ne get accel_msi 6 0xfee00000
295ret 55
296end
297pi = accel_pci_cap_find ACCEL_CAP_ID_PCIE
298if lt pi 0
299ret 56
300end
301if ne accel_pci_decode_pcie buf get accel_cap_id ulong pi get accel_cap_off ulong pi ACCEL_PCI_OK
302ret 57
303end
304if or eq get accel_pcie 5 0 ne get accel_pcie 6 ACCEL_LINK_GEN1
305ret 58
306end
307if or ne get accel_pcie 7 16 ne get accel_pcie 10 1
308ret 59
309end
310if or eq get accel_pcie 11 0 ne get accel_pcie 4 1024
311ret 60
312end
313if or ne accel_link_speed_gt ACCEL_LINK_GEN1 2 ne accel_link_speed_gt ACCEL_LINK_GEN6 64
314ret 61
315end
316xi = accel_pci_cap_find ACCEL_CAP_ID_MSIX
317if lt xi 0
318ret 62
319end
320if ne accel_pci_decode_msix buf get accel_cap_id ulong xi get accel_cap_off ulong xi ACCEL_PCI_OK
321ret 63
322end
323if or eq get accel_msix 1 0 ne get accel_msix 2 0
324ret 64
325end
326if or ne get accel_msix 3 9 ne get accel_msix 4 0
327ret 65
328end
329if or ne get accel_msix 5 0x00b90000 ne get accel_msix 7 0x00ba0000
330ret 66
331end
332if ne accel_pci_decode_msi buf get accel_cap_id ulong xi get accel_cap_off ulong xi ACCEL_PCI_ERR_WRONG_CAP
333ret 67
334end
335
336note BAR size decoding with bounds (all 10 pci.rs assertions + 64 GB BAR)
337if ne accel_pci_memory_bar_size 0xf0000004 0xffffffff true 0x10000000
338ret 68
339end
340if ne accel_pci_memory_bar_size 0xf0000004 0 false 0x10000000
341ret 69
342end
343if ne accel_pci_memory_bar_size 0x00000004 0xffffffff true 0x100000000
344ret 70
345end
346if ne accel_pci_memory_bar_size 0xfff00004 0xffffffff true 0x100000
347ret 71
348end
349if ne accel_pci_memory_bar_size 0x2400000c 0 false 0
350ret 72
351end
352if ne accel_pci_memory_bar_size 0x00000000 0 false 0
353ret 73
354end
355if ne accel_pci_memory_bar_size 0xfffff004 0 false 0x1000
356ret 74
357end
358if ne accel_pci_memory_bar_size 0xf0001004 0xffffffff true 0
359ret 75
360end
361if ne accel_pci_io_bar_size 0xfffff001 0x1000
362ret 76
363end
364if ne accel_pci_io_bar_size 0x00000001 0
365ret 77
366end
367if ne accel_pci_memory_bar_size 0x00000004 0xfffffff0 true 0x1000000000
368ret 78
369end
370ret 0
371end
372
373fn test_pci_extended_caps to int
374ext = new uchar 4096 0
375first = or or ulong 0x19 shl ulong 1 16 shl ulong 0x12c 20
376accel_put_u32_le ext 0x100 first
377second = or ulong 0x01 shl ulong 2 16
378accel_put_u32_le ext 0x12c second
379if ne accel_pci_walk_ext_capabilities ext ACCEL_PCI_OK
380ret 80
381end
382if ne get accel_ecap_cnt 0 2
383ret 81
384end
385i1 = accel_pci_ecap_find ushort 0x19
386i2 = accel_pci_ecap_find ushort 0x01
387if or lt i1 0 lt i2 0
388ret 82
389end
390if or ne get accel_ecap_ver ulong i1 1 ne get accel_ecap_ver ulong i2 2
391ret 83
392end
393
394note Extended capability loop
395for i ulong 4096
396put ext i 0
397end
398looped = or ulong 0x19 shl ulong 0x100 20
399accel_put_u32_le ext 0x100 looped
400if ne accel_pci_walk_ext_capabilities ext ACCEL_PCI_ERR_CAP_LOOP
401ret 84
402end
403
404note Next pointer past 4096-byte space
405for i ulong 4096
406put ext i 0
407end
408oob = or ulong 0x19 shl ulong 0xfff 20
409accel_put_u32_le ext 0x100 oob
410if ne accel_pci_walk_ext_capabilities ext ACCEL_PCI_ERR_OUT_OF_BOUNDS
411ret 85
412end
413
414note 256-byte slice yields empty extended cap list
415short_buf = new uchar 256 0
416if ne accel_pci_walk_ext_capabilities short_buf ACCEL_PCI_OK
417ret 86
418end
419if ne get accel_ecap_cnt 0 0
420ret 87
421end
422ret 0
423end
424
425note === Test group 3: profile.rs & registers.rs ===
426
427fn test_profile_and_registers to int
428buf = new uchar 256 0
429t_fill_gb10_endpoint buf
430loc = new ulong 4 0
431accel_make_loc loc 15 1 0 0
432
433note LinuxSysfs source classification
434if ne accel_profile_from_pci_config loc buf ACCEL_SRC_LINUX_SYSFS ACCEL_PCI_OK
435ret 90
436end
437if ne get accel_prof_val ACCEL_FACT_VENDOR_ID 0x10de
438ret 91
439end
440if ne get accel_prof_src ACCEL_FACT_VENDOR_ID ACCEL_SRC_LINUX_SYSFS
441ret 92
442end
443if ne get accel_prof_nver ACCEL_FACT_VENDOR_ID 0
444ret 93
445end
446if not accel_source_linux_interpreted ACCEL_SRC_LINUX_SYSFS
447ret 94
448end
449if accel_source_linux_interpreted ACCEL_SRC_NATIVE_PCI
450ret 95
451end
452
453note AienosNativePci source classification & unknown facts
454if ne accel_profile_from_pci_config loc buf ACCEL_SRC_NATIVE_PCI ACCEL_PCI_OK
455ret 96
456end
457if eq get accel_prof_nver ACCEL_FACT_VENDOR_ID 0
458ret 97
459end
460if ne get accel_prof_msix 3 9
461ret 98
462end
463if eq get accel_prof_pcie 8 0
464ret 99
465end
466if ne get accel_prof_state ACCEL_FACT_IOMMU_GROUP ACCEL_STATE_UNKNOWN
467ret 100
468end
469if ne get accel_prof_state ACCEL_FACT_NUMA_NODE ACCEL_STATE_UNKNOWN
470ret 101
471end
472if ne get accel_prof_state ACCEL_FACT_BAR_SIZE0 ACCEL_STATE_UNKNOWN
473ret 102
474end
475
476note Deterministic profile rendering
477pbuf = new uchar 4096 0
478plen = accel_profile_write pbuf
479if not accel_buf_contains pbuf plen t_prof_vid
480ret 103
481end
482if not accel_buf_contains pbuf plen t_prof_iommu
483ret 104
484end
485if not accel_buf_contains pbuf plen t_prof_bsz0
486ret 105
487end
488
489note Register ledger: exactly two established offsets, no claimed semantics
490if ne ACCEL_REG_COUNT 2
491ret 106
492end
493r0 = accel_reg_find t_boot0
494r1 = accel_reg_find t_boot42
495rbad = accel_reg_find t_boot1
496if or ne r0 0 ne r1 1
497ret 107
498end
499if ge rbad 0
500ret 108
501end
502if or ne accel_reg_offset 0 ACCEL_PMC_BOOT_0 ne accel_reg_offset 1 ACCEL_PMC_BOOT_42
503ret 109
504end
505for i ulong 2
506if ne accel_reg_safety i ACCEL_REG_SAFETY_ESTABLISHED
507ret 110
508end
509if or accel_reg_native_observed i accel_reg_semantics_known i
510ret 111
511end
512if accel_reg_has_observed_value i
513ret 112
514end
515end
516rbuf = new uchar 1024 0
517rlen = accel_reg_write_ledger rbuf
518nl_cnt = ulong 0
519for i ulong rlen bound 1024
520if eq get rbuf i 10
521nl_cnt = add nl_cnt 1
522end
523end
524if ne nl_cnt 2
525ret 113
526end
527if not accel_buf_contains rbuf rlen t_reg_b0
528ret 114
529end
530if not accel_buf_contains rbuf rlen t_reg_b42
531ret 115
532end
533if not accel_buf_contains rbuf rlen t_reg_sem
534ret 116
535end
536if not accel_buf_contains rbuf rlen t_reg_nat
537ret 117
538end
539ret 0
540end
541
542note === Test group 4: tests/gb10_fixtures.rs ===
543
544fn test_gb10_fixtures_relocation_and_rejections to int
545buf = new uchar 256 0
546t_fill_gb10_endpoint buf
547if ne accel_pci_header_parse buf ACCEL_PCI_OK
548ret 120
549end
550loc = new ulong 4 0
551note 4 distinct BDF locations must all match by property
552accel_make_loc loc 15 1 0 0
553if ne accel_match_gb10 loc ACCEL_GB10_OK
554ret 121
555end
556if or ne get accel_match 4 0x24000000 eq get accel_match 5 0
557ret 122
558end
559if eq get accel_match 6 0
560ret 123
561end
562accel_make_loc loc 0 0 0 0
563if ne accel_match_gb10 loc ACCEL_GB10_OK
564ret 124
565end
566accel_make_loc loc 3 0x44 0x1f 7
567if ne accel_match_gb10 loc ACCEL_GB10_OK
568ret 125
569end
570if or ne get accel_match 0 3 ne get accel_match 1 0x44
571ret 126
572end
573accel_make_loc loc 0xffff 0xff 0x1f 7
574if ne accel_match_gb10 loc ACCEL_GB10_OK
575ret 127
576end
577
578note Rejection variants
579accel_make_loc loc 15 1 0 0
580t_fill_gb10_endpoint buf
581accel_put_u16_le buf 0x02 0x2684
582rc = accel_pci_header_parse buf
583if ne accel_match_gb10 loc ACCEL_REJ_WRONG_DEVICE
584ret 128
585end
586t_fill_gb10_endpoint buf
587accel_put_u16_le buf 0x00 0x1234
588rc = accel_pci_header_parse buf
589if ne accel_match_gb10 loc ACCEL_REJ_NOT_NVIDIA
590ret 129
591end
592t_fill_gb10_endpoint buf
593accel_put_u16_le buf 0x04 0x0005
594rc = accel_pci_header_parse buf
595if ne accel_match_gb10 loc ACCEL_REJ_MEM_DISABLED
596ret 130
597end
598t_fill_gb10_endpoint buf
599accel_put_u32_le buf 0x10 0x00000000
600accel_put_u32_le buf 0x14 0x00000000
601rc = accel_pci_header_parse buf
602if ne accel_match_gb10 loc ACCEL_REJ_BAR0_MISSING
603ret 131
604end
605t_fill_gb10_endpoint buf
606accel_put_u32_le buf 0x10 0x00000004
607accel_put_u32_le buf 0x14 0x00000000
608rc = accel_pci_header_parse buf
609if ne accel_match_gb10 loc ACCEL_REJ_BAR0_UNPROGRAMMED
610ret 132
611end
612t_fill_gb10_endpoint buf
613accel_put_u32_le buf 0x10 0x24000000
614accel_put_u32_le buf 0x14 0x00000000
615rc = accel_pci_header_parse buf
616if ne accel_match_gb10 loc ACCEL_REJ_BAR0_NOT_64BIT
617ret 133
618end
619t_fill_gb10_endpoint buf
620accel_put_u32_le buf 0x10 0x0000c001
621rc = accel_pci_header_parse buf
622if ne accel_match_gb10 loc ACCEL_REJ_BAR0_NOT_MEM
623ret 134
624end
625
626note Gb10Bar::from_header direct rejection parity
627if ne accel_gb10_bar_from_header loc 0x2e121234 0x6 0x24000004 0 ACCEL_REJ_NOT_NVIDIA
628ret 135
629end
630if ne accel_gb10_bar_from_header loc 0x268410de 0x6 0x24000004 0 ACCEL_REJ_WRONG_DEVICE
631ret 136
632end
633if ne accel_gb10_bar_from_header loc 0x2e1210de 0x4 0x24000004 0 ACCEL_REJ_MEM_DISABLED
634ret 137
635end
636if ne accel_gb10_bar_from_header loc 0x2e1210de 0x6 0x0000c001 0 ACCEL_REJ_BAR0_NOT_MEM
637ret 138
638end
639if ne accel_gb10_bar_from_header loc 0x2e1210de 0x6 0 0 ACCEL_REJ_BAR0_UNPROGRAMMED
640ret 139
641end
642if ne accel_gb10_bar_from_header loc 0x2e1210de 0x6 0x24000000 0 ACCEL_REJ_BAR0_NOT_64BIT
643ret 140
644end
645if ne accel_gb10_bar_from_header loc 0x2e1210de 0x6 0x00000004 0 ACCEL_REJ_BAR0_UNPROGRAMMED
646ret 141
647end
648if ne accel_gb10_bar_from_header loc 0x2e1210de 0x6 0x2400000c 0 ACCEL_GB10_OK
649ret 142
650end
651if ne get accel_gb10_bar 4 0x24000000
652ret 143
653end
654ret 0
655end
656
657fn test_gb10_fixtures_multi_bridge_caps to int
658loc = new ulong 4 0
659accel_make_loc loc 15 1 0 0
660
661note Select GB10 among multiple NVIDIA devices
662other = new uchar 256 0
663t_fill_gb10_endpoint other
664accel_put_u16_le other 0x02 0x2684
665gb10 = new uchar 256 0
666t_fill_gb10_endpoint gb10
667matched_cnt = ulong 0
668rc = accel_pci_header_parse other
669if eq accel_match_gb10 loc ACCEL_GB10_OK
670matched_cnt = add matched_cnt 1
671end
672rc = accel_pci_header_parse gb10
673if eq accel_match_gb10 loc ACCEL_GB10_OK
674matched_cnt = add matched_cnt 1
675end
676if or ne matched_cnt 1 ne get accel_match 4 0x24000000
677ret 144
678end
679
680note Follow secondary bus window to downstream GB10
681bridge = new uchar 64 0
682accel_put_u16_le bridge 0x00 0x10de
683accel_put_u16_le bridge 0x02 0x22d1
684put bridge 0x0b uchar 0x06
685put bridge 0x0e uchar 0x01
686put bridge 0x19 uchar 0x01
687put bridge 0x1a uchar 0x0f
688if ne accel_pci_bridge_parse bridge ACCEL_PCI_OK
689ret 145
690end
691if not accel_pci_bridge_has_window
692ret 146
693end
694if or gt get accel_bridge 4 1 lt get accel_bridge 5 1
695ret 147
696end
697rc = accel_pci_header_parse gb10
698if ne accel_match_gb10 loc ACCEL_GB10_OK
699ret 148
700end
701
702note Malformed capability loops and below-0x40 boundary
703bad = new uchar 256 0
704t_fill_gb10_endpoint bad
705put bad 0x41 uchar 0x40
706if ne accel_pci_walk_capabilities bad ACCEL_PCI_ERR_CAP_LOOP
707ret 149
708end
709t_fill_gb10_endpoint bad
710put bad 0x34 uchar 0x40
711put bad 0x40 ACCEL_CAP_ID_MSI
712put bad 0x41 uchar 0x30
713if ne accel_pci_walk_capabilities bad ACCEL_PCI_ERR_OUT_OF_BOUNDS
714ret 150
715end
716
717note Missing MSI and MSI-X reported as absent, not zero
718no_msi = new uchar 256 0
719t_fill_gb10_endpoint no_msi
720put no_msi 0x34 uchar 0x50
721if ne accel_pci_walk_capabilities no_msi ACCEL_PCI_OK
722ret 151
723end
724if or ge accel_pci_cap_find ACCEL_CAP_ID_MSI 0 lt accel_pci_cap_find ACCEL_CAP_ID_PCIE 0
725ret 152
726end
727if ne accel_profile_from_pci_config loc no_msi ACCEL_SRC_SYNTHETIC ACCEL_PCI_OK
728ret 153
729end
730if or ne get accel_prof_msi 0 0 ne get accel_prof_msix 3 9
731ret 154
732end
733
734no_msix = new uchar 256 0
735t_fill_gb10_endpoint no_msix
736put no_msix 0x51 uchar 0x00
737if ne accel_profile_from_pci_config loc no_msix ACCEL_SRC_SYNTHETIC ACCEL_PCI_OK
738ret 155
739end
740if or ne get accel_prof_msix 0 0 eq get accel_prof_msi 0 0
741ret 156
742end
743if ne get accel_prof_msix 3 0
744ret 157
745end
746
747note Profile decodes BAR kinds and keeps sizes unknown
748if ne accel_profile_from_pci_config loc gb10 ACCEL_SRC_SYNTHETIC ACCEL_PCI_OK
749ret 158
750end
751if ne get accel_prof_bar_kind 0 ACCEL_BAR_MEMORY
752ret 159
753end
754if or eq get accel_prof_bar_64 0 0 eq get accel_prof_bar_pref 0 0
755ret 160
756end
757if ne get accel_prof_bar_base 0 0x24000000
758ret 161
759end
760for i ulong 6
761if accel_prof_is_known add ACCEL_FACT_BAR_SIZE0 i
762ret 162
763end
764end
765if ne get accel_prof_bar_kind 1 ACCEL_BAR_NONE
766ret 163
767end
768ret 0
769end
770
771fn main to int
772rc = test_lib_bar_and_diag
773if ne rc 0
774ret rc
775end
776rc = test_pci_header_and_bars
777if ne rc 0
778ret rc
779end
780rc = test_pci_caps_and_sizes
781if ne rc 0
782ret rc
783end
784rc = test_pci_extended_caps
785if ne rc 0
786ret rc
787end
788rc = test_profile_and_registers
789if ne rc 0
790ret rc
791end
792rc = test_gb10_fixtures_relocation_and_rejections
793if ne rc 0
794ret rc
795end
796rc = test_gb10_fixtures_multi_bridge_caps
797if ne rc 0
798ret rc
799end
800ret 0
801end