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