Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/aienux/kernel/hal/pcie_smmu_test.om # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / aienux / kernel / hal / pcie_smmu_test.om` 739 lines ยท 20432 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note aienux/kernel/hal/pcie_smmu_test.om: Pure-Omega host/model verification suite for Piece 2 3 note (bar0_mmio.om, pcie.om, smmuv3.om, irqbm.om, irq.om iqmode=2, irqcc.om). 4 note Compose with: 5 note cat si/directives/om2.om aienux/kernel/hal/iort.om aienux/kernel/hal/bar0_mmio.om \ 6 note aienux/kernel/hal/pcie.om aienux/kernel/hal/smmuv3.om gpu/driver/gsp/logdec.om \ 7 note gpu/driver/gsp/irqbm.om gpu/driver/gsp/irq.om gpu/driver/gsp/irqcc.om \ 8 note aienux/kernel/hal/pcie_smmu_test.om | seed/out/omc > pcie_smmu_test 9 10 text ps_pass "PASS " 11 text ps_fail "FAIL " 12 text ps_nl "\n" 13 text ps_t1 "t01_bar0_mmio_exclusive_and_gb20b_id" 14 text ps_t2 "t02_pcie_mcfg_and_ecam_ngnrne" 15 text ps_t3 "t03_pcie_caps_quiesce_and_flr_guard" 16 text ps_t4 "t04_smmu_preconditions_and_fail_closed" 17 text ps_t5 "t05_smmu_abc_deterministic_bringup" 18 text ps_t6 "t06_smmu_disjoint_dma_and_rmr" 19 text ps_t7 "t07_smmu_eventq_fault_drain" 20 text ps_t8 "t08_irq_iqmode2_bar0_and_crashcat" 21 text ps_t9 "t09_smmu_open_teardown_and_iort_base_check" 22 text ps_sum "PCIE_SMMU_TEST_PASS total=9 failed=0\n" 23 text ps_fsum "PCIE_SMMU_TEST_FAIL\n" 24 25 global ps_mcfg uchar 128 26 global ps_iort uchar 512 27 global ps_mmio_stub ulong 4 28 29 note Host-side stubs for bar0_mmio.om mode 1 (bare-metal uses fwops.om fwld/fwst + dsb sy). 30 fn arm64_mmio_r32 addr ulong to ulong 31 put ps_mmio_stub 0 addr 32 ret and get ps_mmio_stub 1 `4294967295` 33 end 34 35 fn arm64_mmio_w32 addr ulong val ulong to void 36 put ps_mmio_stub 0 addr 37 put ps_mmio_stub 1 and val `4294967295` 38 end 39 40 fn arm64_mmio_r64 addr ulong to ulong 41 put ps_mmio_stub 2 addr 42 ret get ps_mmio_stub 3 43 end 44 45 fn arm64_mmio_w64 addr ulong val ulong to void 46 put ps_mmio_stub 2 addr 47 put ps_mmio_stub 3 val 48 end 49 50 fn ps_wstr s view uchar * to void 51 n = len s 52 r = write 1 s 0 n 53 end 54 55 fn ps_rep name view uchar * ok bool to ulong 56 if ok 57 ps_wstr ps_pass 58 ps_wstr name 59 ps_wstr ps_nl 60 ret ulong 0 61 end 62 ps_wstr ps_fail 63 ps_wstr name 64 ps_wstr ps_nl 65 ret ulong 1 66 end 67 68 fn ps_mput16 off ulong v ulong to void 69 put ps_mcfg off uchar and v 0xff 70 put ps_mcfg add off 1 uchar and shr v 8 0xff 71 end 72 73 fn ps_mput32 off ulong v ulong to void 74 ps_mput16 off and v 0xffff 75 ps_mput16 add off 2 and shr v 16 0xffff 76 end 77 78 fn ps_mput64 off ulong v ulong to void 79 ps_mput32 off and v 0xffffffff 80 ps_mput32 add off 4 and shr v 32 0xffffffff 81 end 82 83 fn ps_mcfg_checksum n ulong to void 84 put ps_mcfg 9 0 85 acc = ulong 0 86 for i ulong n bound 128 87 acc = and add acc ulong get ps_mcfg i 0xff 88 end 89 put ps_mcfg 9 uchar and sub 256 acc 0xff 90 end 91 92 fn ps_build_spark_mcfg to ulong 93 for i ulong 128 94 put ps_mcfg i 0 95 end 96 put ps_mcfg 0 77 97 put ps_mcfg 1 67 98 put ps_mcfg 2 70 99 put ps_mcfg 3 71 100 tlen = ulong 108 101 ps_mput32 4 tlen 102 note Entry 0: seg 4 (NVMe) base 0xF340000000 bus 0..1 103 ps_mput64 44 SPARK_ECAM_SEG4_PA 104 ps_mput16 52 4 105 put ps_mcfg 54 0 106 put ps_mcfg 55 1 107 note Entry 1: seg 7 (RTL8127) base 0xF370000000 bus 0..1 108 ps_mput64 60 SPARK_ECAM_SEG7_PA 109 ps_mput16 68 7 110 put ps_mcfg 70 0 111 put ps_mcfg 71 1 112 note Entry 2: seg 9 (unused Wi-Fi) base 0xF390000000 bus 0..1 113 ps_mput64 76 0xf390000000 114 ps_mput16 84 9 115 put ps_mcfg 86 0 116 put ps_mcfg 87 1 117 note Entry 3: seg 15 (GB20B) base 0x29000000 bus 0..1 118 ps_mput64 92 SPARK_ECAM_SEG15_PA 119 ps_mput16 100 15 120 put ps_mcfg 102 0 121 put ps_mcfg 103 1 122 ps_mcfg_checksum tlen 123 ret tlen 124 end 125 126 fn ps_iput16 off ulong v ulong to void 127 put ps_iort off uchar and v 0xff 128 put ps_iort add off 1 uchar and shr v 8 0xff 129 end 130 131 fn ps_iput32 off ulong v ulong to void 132 ps_iput16 off and v 0xffff 133 ps_iput16 add off 2 and shr v 16 0xffff 134 end 135 136 fn ps_iput64 off ulong v ulong to void 137 ps_iput32 off and v 0xffffffff 138 ps_iput32 add off 4 and shr v 32 0xffffffff 139 end 140 141 fn ps_iort_checksum n ulong to void 142 put ps_iort 9 0 143 acc = ulong 0 144 for i ulong n bound 512 145 acc = and add acc ulong get ps_iort i 0xff 146 end 147 put ps_iort 9 uchar and sub 256 acc 0xff 148 end 149 150 note Build Spark-shape IORT: 3 SMMUs (A=0x13800000, B=0x13000000, C=0x14900000), 151 note 3 RCs (seg 4 -> A out=0x50000, seg 7 -> A out=0x80000, seg 15 -> B out=0), 152 note 1 RMR on B (SID 0..0x100, 3 Spark ranges). Total 7 nodes. 153 fn ps_build_spark_iort to ulong 154 for i ulong 512 155 put ps_iort i 0 156 end 157 put ps_iort 0 73 158 put ps_iort 1 79 159 put ps_iort 2 82 160 put ps_iort 3 84 161 note Header: 48 bytes, 7 nodes starting at offset 48 162 ps_iput32 36 7 163 ps_iput32 40 48 164 note Node 0 @ 48 (len 24): SMMUv3 A = 0x13800000 165 put ps_iort 48 IORT_NODE_SMMUV3 166 ps_iput16 49 24 167 ps_iput64 64 SPARK_SMMU_A_PA 168 note Node 1 @ 72 (len 24): SMMUv3 B = 0x13000000 169 put ps_iort 72 IORT_NODE_SMMUV3 170 ps_iput16 73 24 171 ps_iput64 88 SPARK_SMMU_B_PA 172 note Node 2 @ 96 (len 24): SMMUv3 C = 0x14900000 173 put ps_iort 96 IORT_NODE_SMMUV3 174 ps_iput16 97 24 175 ps_iput64 112 SPARK_SMMU_C_PA 176 note Node 3 @ 120 (len 52 = 32 hdr + 20 map): RC seg 4 -> SMMUv3 A (off 48), in 0..0xffff -> out 0x50000 177 put ps_iort 120 IORT_NODE_RC 178 ps_iput16 121 52 179 ps_iput32 128 1 180 ps_iput32 132 32 181 ps_iput32 148 4 182 ps_iput32 152 0 183 ps_iput32 156 0xffff 184 ps_iput32 160 0x50000 185 ps_iput32 164 48 186 note Node 4 @ 172 (len 52): RC seg 7 -> SMMUv3 A (off 48), in 0..0xffff -> out 0x80000 187 put ps_iort 172 IORT_NODE_RC 188 ps_iput16 173 52 189 ps_iput32 180 1 190 ps_iput32 184 32 191 ps_iput32 200 7 192 ps_iput32 204 0 193 ps_iput32 208 0xffff 194 ps_iput32 212 0x80000 195 ps_iput32 216 48 196 note Node 5 @ 224 (len 52): RC seg 15 -> SMMUv3 B (off 72), in 0..0xffff -> out 0 197 put ps_iort 224 IORT_NODE_RC 198 ps_iput16 225 52 199 ps_iput32 232 1 200 ps_iput32 236 32 201 ps_iput32 252 15 202 ps_iput32 256 0 203 ps_iput32 260 0xffff 204 ps_iput32 264 0 205 ps_iput32 268 72 206 note Node 6 @ 276 (len 108 = 28 hdr + 60 descs + 20 map): RMR on B (off 72), SID 0..0x100 207 put ps_iort 276 IORT_NODE_RMR 208 ps_iput16 277 108 209 ps_iput32 284 1 210 ps_iput32 288 88 211 ps_iput32 292 0x10 212 ps_iput32 296 3 213 ps_iput32 300 28 214 note Desc 0 @ 304: 0xa1600000 + 386 MiB (0x18200000) 215 ps_iput64 304 0xa1600000 216 ps_iput64 312 0x18200000 217 note Desc 1 @ 324: 0x280000000 + 2 GiB (0x80000000) 218 ps_iput64 324 0x280000000 219 ps_iput64 332 0x80000000 220 note Desc 2 @ 344: 0x300000000 + 48 MiB (0x3000000) 221 ps_iput64 344 0x300000000 222 ps_iput64 352 0x3000000 223 note Map @ 364: in=0, cnt=0x100, out=0, ref=72 (SMMUv3 B) 224 ps_iput32 364 0 225 ps_iput32 368 0x100 226 ps_iput32 372 0 227 ps_iput32 376 72 228 tlen = ulong 384 229 ps_iput32 4 tlen 230 ps_iort_checksum tlen 231 ret tlen 232 end 233 234 fn t01_bar0 to bool 235 bmmio_reset 236 note Reject non-Device-nGnRnE (attr=1 Device-nGnRE), va==0, unaligned va, va+sz wrap 237 if ne bmmio_register SPARK_GB20B_BAR0_PA SPARK_GB20B_BAR0_PA SPARK_GB20B_BAR0_SZ 1 BMMIO_EATTR 238 ret false 239 end 240 if ne bmmio_register SPARK_GB20B_BAR0_PA 0 SPARK_GB20B_BAR0_SZ BMMIO_ATTR_NGNRNE BMMIO_EARG 241 ret false 242 end 243 if ne bmmio_register SPARK_GB20B_BAR0_PA add SPARK_GB20B_BAR0_PA 1 SPARK_GB20B_BAR0_SZ BMMIO_ATTR_NGNRNE BMMIO_EALIGN 244 ret false 245 end 246 if ne bmmio_register SPARK_GB20B_BAR0_PA 0xfffffffffffff000 0x2000 BMMIO_ATTR_NGNRNE BMMIO_EARG 247 ret false 248 end 249 hb = bmmio_register SPARK_GB20B_BAR0_PA SPARK_GB20B_BAR0_PA SPARK_GB20B_BAR0_SZ BMMIO_ATTR_NGNRNE 250 if le hb 0 251 ret false 252 end 253 note Reject overlapping BAR 254 if ne bmmio_register add SPARK_GB20B_BAR0_PA 4096 add SPARK_GB20B_BAR0_PA 4096 4096 BMMIO_ATTR_NGNRNE BMMIO_EOVERLAP 255 ret false 256 end 257 hn = bmmio_register SPARK_NVME_BAR0_PA SPARK_NVME_BAR0_PA SPARK_NVME_BAR0_SZ BMMIO_ATTR_NGNRNE 258 hr = bmmio_register SPARK_RTL8127_BAR2_PA SPARK_RTL8127_BAR2_PA SPARK_RTL8127_BAR2_SZ BMMIO_ATTR_NGNRNE 259 if or le hn 0 le hr 0 260 ret false 261 end 262 note Reject unaligned & OOB reads 263 v1 = bmmio_r32 hb 2 264 if ne get bmmio_err 0 BMMIO_EALIGN 265 ret false 266 end 267 v2 = bmmio_r32 hb SPARK_GB20B_BAR0_SZ 268 if ne get bmmio_err 0 BMMIO_EBOUNDS 269 ret false 270 end 271 note Verify GB20B BOOT_0 / BOOT_42 identity check 272 z1 = bmmio_w32 hb GB20B_OFF_BOOT0 GB20B_VAL_BOOT0 273 z2 = bmmio_w32 hb GB20B_OFF_BOOT42 GB20B_VAL_BOOT42 274 if not bmmio_verify_gb20b hb 275 ret false 276 end 277 z3 = bmmio_w32 hb GB20B_OFF_BOOT42 0x1ba00000 278 if bmmio_verify_gb20b hb 279 ret false 280 end 281 ret true 282 end 283 284 fn t02_mcfg to bool 285 bmmio_reset 286 pcie_reset 287 n = ps_build_spark_mcfg 288 loc = new uchar 128 0 289 for i ulong 128 290 put loc i get ps_mcfg i 291 end 292 if ne pcie_mcfg_parse part loc 0 n PCIE_OK 293 ret false 294 end 295 if ne get pcie_nsegs 0 4 296 ret false 297 end 298 note Corrupt checksum must fail closed 299 put loc 9 xor get loc 9 1 300 if eq pcie_mcfg_parse part loc 0 n PCIE_OK 301 ret false 302 end 303 put loc 9 xor get loc 9 1 304 if ne pcie_mcfg_parse part loc 0 n PCIE_OK 305 ret false 306 end 307 note Map ECAM windows for segs 4, 7, 9, 15 as Device-nGnRnE XN 308 h4 = pcie_map_seg_ecam 4 309 h7 = pcie_map_seg_ecam 7 310 h9 = pcie_map_seg_ecam 9 311 h15 = pcie_map_seg_ecam 15 312 if or le h4 0 or le h7 0 or le h9 0 le h15 0 313 ret false 314 end 315 ret true 316 end 317 318 fn t03_caps_quiesce to bool 319 note Populate GB20B 000f:01:00.0 (PM D0 @ 0x60, MSI-X 9 vecs @ 0x70 BAR0+0x00b90000/0x00ba0000) 320 note Seed STATUS=0x0010 (CapList) + RW1C error bit 0x8000 -> must NOT be written back as 1 when updating COMMAND! 321 z = pcie_cfg_w32 15 1 0 0 0 0x2e1210de 322 z = pcie_cfg_w32 15 1 0 0 4 0x80100003 323 z = pcie_cfg_w32 15 1 0 0 52 0x60 324 z = pcie_cfg_w32 15 1 0 0 0x60 0x00007001 325 z = pcie_cfg_w32 15 1 0 0 0x64 0x00000000 326 z = pcie_cfg_w32 15 1 0 0 0x70 0x80080011 327 z = pcie_cfg_w32 15 1 0 0 0x74 0x00b90000 328 z = pcie_cfg_w32 15 1 0 0 0x78 0x00ba0000 329 note Populate unused Wi-Fi 0009:01:00.0 (BME=1) + multi-function 0009:01:02.0 (HTYPE=0x80) / 0009:01:02.1 (BME=1) 330 z = pcie_cfg_w32 9 1 0 0 0 0x792514c3 331 z = pcie_cfg_w32 9 1 0 0 4 0x00100006 332 z = pcie_cfg_w32 9 1 2 0 0 0x123410de 333 z = pcie_cfg_w32 9 1 2 0 4 0x00000006 334 z = pcie_cfg_w32 9 1 2 0 12 0x00800000 335 z = pcie_cfg_w32 9 1 2 1 0 0x123510de 336 z = pcie_cfg_w32 9 1 2 1 4 0x00000006 337 note off>=4096 must fail (no wrap to 0) 338 if ne pcie_cfg_r16 15 1 0 0 4096 0xffff 339 ret false 340 end 341 if ne pcie_cfg_w16 15 1 0 0 4096 0 PCIE_EARG 342 ret false 343 end 344 note Quiesce unused endpoints before GBPA.ABORT (must quiesce 3: 0009:01:00.0, 0009:01:02.0, 0009:01:02.1) 345 if ne pcie_quiesce_unused PCIE_OK 346 ret false 347 end 348 if or ne get pcie_quiesced 0 1 ne get pcie_quiesced_cnt 0 3 349 ret false 350 end 351 if ne and pcie_cfg_r16 9 1 0 0 4 PCIE_CMD_BME 0 352 ret false 353 end 354 if ne and pcie_cfg_r16 9 1 2 1 4 PCIE_CMD_BME 0 355 ret false 356 end 357 note Enable GB20B: verifies D0, masks MSI-X, sets Mem+BME+DisINTx, writes 0 to RW1C STATUS upper 16 bits 358 if ne pcie_enable_endpoint 15 1 0 0 PCIE_OK 359 ret false 360 end 361 if or ne get pcie_cap_info 3 9 or ne get pcie_cap_info 5 0x00b90000 ne get pcie_cap_info 7 0x00ba0000 362 ret false 363 end 364 mctl = pcie_cfg_r16 15 1 0 0 0x72 365 if or ne and mctl PCIE_MSIX_ENABLE 0 eq and mctl PCIE_MSIX_FMASK 0 366 ret false 367 end 368 note Verify RW1C STATUS upper 16 bits were written as 0 (not 0x8010 echoed back) 369 cs_after = pcie_cfg_r32 15 1 0 0 4 370 if ne shr cs_after 16 0 371 ret false 372 end 373 if ne and cs_after 0x0406 0x0406 374 ret false 375 end 376 note Out-of-bounds cap pointer (cp=252 for PM cap needs cp+4=256) must fail PCIE_ECAP 377 z = pcie_cfg_w32 7 1 0 0 0 0x812710ec 378 z = pcie_cfg_w32 7 1 0 0 4 0x00100006 379 z = pcie_cfg_w32 7 1 0 0 52 252 380 z = pcie_cfg_w32 7 1 0 0 252 0x00000001 381 if ne pcie_walk_caps 7 1 0 0 PCIE_ECAP 382 ret false 383 end 384 note D3 endpoint must be refused 385 z = pcie_cfg_w32 4 1 0 0 0 0xa80d144d 386 z = pcie_cfg_w32 4 1 0 0 4 0x00100006 387 z = pcie_cfg_w32 4 1 0 0 52 0x60 388 z = pcie_cfg_w32 4 1 0 0 0x60 0x00000001 389 z = pcie_cfg_w32 4 1 0 0 0x64 0x00000003 390 if ne pcie_enable_endpoint 4 1 0 0 PCIE_ED3 391 ret false 392 end 393 note GB20B FLR hard refusal (Trap 18) 394 if ne pcie_flr_refuse 15 1 0 0 PCIE_EFLR 395 ret false 396 end 397 ret true 398 end 399 400 fn t04_smmu_neg to bool 401 smmu_reset 402 note Must refuse before pcie_quiesced==1 403 put pcie_quiesced 0 0 404 if ne smmu_init_instance 0 SPARK_SMMU_A_PA 20 0x10000000 0x10100000 0x10200000 SMMU_ENOQUIESCE 405 ret false 406 end 407 put pcie_quiesced 0 1 408 note Misaligned L1 STRTAB_BASE (4 KiB aligned but not 128 KiB aligned for log2sz=20) -> SMMU_EARG 409 if ne smmu_init_instance 0 SPARK_SMMU_A_PA 20 0x10001000 0x10100000 0x10200000 SMMU_EARG 410 ret false 411 end 412 note Pre-register SMMUv3 A with missing S1P (bit 1==0) -> SMMU_EIDR 413 ha = bmmio_register SPARK_SMMU_A_PA SPARK_SMMU_A_PA SPARK_SMMU_SZ BMMIO_ATTR_NGNRNE 414 put smmu_inst_h 0 ha 415 put smmu_inst_base 0 SPARK_SMMU_A_PA 416 z = bmmio_w32 ha SMMU_REG_IDR0 0x08000000 417 z = bmmio_w32 ha SMMU_REG_IDR1 0x00840019 418 if ne smmu_init_instance 0 SPARK_SMMU_A_PA 20 0x10000000 0x10100000 0x10200000 SMMU_EIDR 419 ret false 420 end 421 note Good IDR0 (ST_LEVEL=1 | S1P=1 = 0x08000002), bad SIDSIZE=16 (< 20 for A) -> SMMU_EIDR 422 z = bmmio_w32 ha SMMU_REG_IDR0 0x08000002 423 z = bmmio_w32 ha SMMU_REG_IDR1 0x00840010 424 if ne smmu_init_instance 0 SPARK_SMMU_A_PA 20 0x10000000 0x10100000 0x10200000 SMMU_EIDR 425 ret false 426 end 427 note Inject CMDQ_CONS.ERR[30:24] = 1 (CERROR_ILL) -> SMMU_ECMDERR and CR0 rolled back to 0 428 z = bmmio_w32 ha SMMU_REG_IDR1 0x00840019 429 put smmu_sim_cmd_err 0 1 430 if ne smmu_init_instance 0 SPARK_SMMU_A_PA 20 0x10000000 0x10100000 0x10200000 SMMU_ECMDERR 431 ret false 432 end 433 put smmu_sim_cmd_err 0 0 434 if ne bmmio_r32 ha SMMU_REG_CR0 0 435 ret false 436 end 437 ret true 438 end 439 440 fn t05_smmu_abc to bool 441 bmmio_reset 442 smmu_reset 443 put pcie_quiesced 0 1 444 ilen = ps_build_spark_iort 445 ib = new uchar 512 0 446 for i ulong 512 447 put ib i get ps_iort i 448 end 449 if ne iort_parse part ib 0 ilen 1 450 ret false 451 end 452 note Pre-seed IDR0 (ST_LEVEL=1 | S1P=1 = 0x08000002) and IDR1 (CMDQS=4 | EVENTQS=4 | SIDSIZE=25 = 0x00840019) on A and B 453 ha = bmmio_register SPARK_SMMU_A_PA SPARK_SMMU_A_PA SPARK_SMMU_SZ BMMIO_ATTR_NGNRNE 454 hb = bmmio_register SPARK_SMMU_B_PA SPARK_SMMU_B_PA SPARK_SMMU_SZ BMMIO_ATTR_NGNRNE 455 put smmu_inst_h 0 ha 456 put smmu_inst_base 0 SPARK_SMMU_A_PA 457 put smmu_inst_h 1 hb 458 put smmu_inst_base 1 SPARK_SMMU_B_PA 459 z = bmmio_w32 ha SMMU_REG_IDR0 0x08000002 460 z = bmmio_w32 ha SMMU_REG_IDR1 0x00840019 461 z = bmmio_w32 hb SMMU_REG_IDR0 0x08000002 462 z = bmmio_w32 hb SMMU_REG_IDR1 0x00840019 463 if ne smmu_init_instance 0 SPARK_SMMU_A_PA 20 0x10000000 0x10100000 0x10200000 SMMU_OK 464 ret false 465 end 466 if ne smmu_init_instance 1 SPARK_SMMU_B_PA 9 0x10300000 0x10400000 0x10500000 SMMU_OK 467 ret false 468 end 469 if ne smmu_abort_only 2 SPARK_SMMU_C_PA SMMU_OK 470 ret false 471 end 472 note Verify all 7 deterministic bring-up stages (0x7f) and CR0==0x0d on A and B, ABORT_ONLY on C 473 if or ne get smmu_trace 0 0x7f ne get smmu_trace 1 0x7f 474 ret false 475 end 476 if or ne bmmio_r32 ha SMMU_REG_CR0 SMMU_CR0_ALL ne bmmio_r32 hb SMMU_REG_CR0 SMMU_CR0_ALL 477 ret false 478 end 479 if ne get smmu_inst_state 2 2 480 ret false 481 end 482 ret true 483 end 484 485 fn t06_smmu_dma to bool 486 note Open GB20B SID 0x100 on SMMUv3 B -> auto-maps 3 mandatory Spark RMRs 487 sgpu = smmu_open_stream 15 0x0100 0x11000000 0x11001000 488 if le sgpu 0 489 ret false 490 end 491 note Open NVMe SID 0x50100 and RTL8127 SID 0x80100 on SMMUv3 A 492 snvme = smmu_open_stream 4 0x0100 0x11002000 0x11003000 493 snic = smmu_open_stream 7 0x0100 0x11004000 0x11005000 494 if or le snvme 0 le snic 0 495 ret false 496 end 497 note Verify exact CD word 0 (ENDI==0, AA64==1, R==1, A==1, T0SZ==16, NC walk), STE word 1 == 0 (S1CIR/COR/CSH==0), and PTE SH=2 498 if ne get smmu_cd_words 0 0x00006202c0000010 499 ret false 500 end 501 if or ne and get smmu_ste_words 0 0xf 0xb ne get smmu_ste_words 1 0 502 ret false 503 end 504 if ne get smmu_cd_words 3 SMMU_CD_MAIR0 505 ret false 506 end 507 if ne get smmu_sp_pte 0 0x006000000000064c 508 ret false 509 end 510 note Map disjoint spans: GB20B GSP arena 80 MiB, NVMe weights dest 64 MiB, RTL8127 rdma 72 KiB 511 if ne smmu_map_span sgpu 0x340000000 0x5000000 0 SMMU_OK 512 ret false 513 end 514 if ne smmu_map_span snvme 0x400000000 0x4000000 0 SMMU_OK 515 ret false 516 end 517 if ne smmu_map_span snic 0x380000000 0x12000 0 SMMU_OK 518 ret false 519 end 520 note Cross-stream overlap (GB20B trying to map NVMe's weights dest before unmap) MUST FAIL 521 if ne smmu_map_span sgpu 0x400000000 0x4000000 0 SMMU_EOVERLAP 522 ret false 523 end 524 note Wildcard RAM (>32 GiB) and >=40-bit PA MUST FAIL 525 if ne smmu_map_span sgpu 0x500000000 0x1000000000 0 SMMU_EWILDCARD 526 ret false 527 end 528 if ne smmu_map_span sgpu 0x10000000000 0x1000 0 SMMU_EWILDCARD 529 ret false 530 end 531 note Unmap RMR MUST FAIL 532 if ne smmu_unmap_span sgpu 0xa1600000 0x18200000 SMMU_EARG 533 ret false 534 end 535 note Unmap weights dest from NVMe -> then GB20B maps it -> SUCCEEDS! 536 if ne smmu_unmap_span snvme 0x400000000 0x4000000 SMMU_OK 537 ret false 538 end 539 if ne smmu_map_span sgpu 0x400000000 0x4000000 0 SMMU_OK 540 ret false 541 end 542 note Regression: CMDQ wrap past 32 commands (mask 0x1f) must succeed cleanly 543 for w ulong 35 544 if ne smmu_cmd_sync 1 SMMU_OK 545 ret false 546 end 547 end 548 ret true 549 end 550 551 fn t07_eventq to bool 552 hb = get smmu_inst_h 1 553 note Inject F_TRANSLATION (code=0x10, SID=0x100) at SMMUv3 B eventq slot 0 (Page 1 0x100a8/0x100ac, 32 B/record stride=4 u64 -> inst*64=64) 554 note Also set OVFLG (bit 31 = 0x80000000) in PROD to verify OVACKFLG preservation/ack in CONS 555 put smmu_evtq_buf 64 or ulong 0x10 shl ulong 0x100 32 556 z = bmmio_w32 hb SMMU_REG_EVTQ_PROD 0x80000001 557 n = smmu_drain_events 1 558 if or ne n 1 ne get smmu_inst_evt_cnt 1 1 559 ret false 560 end 561 if ne and get smmu_inst_last_evt 1 0xff 0x10 562 ret false 563 end 564 ret eq bmmio_r32 hb SMMU_REG_EVTQ_CONS 0x80000001 565 end 566 567 fn ps_ccput64 o ulong v ulong to void 568 for i ulong 8 569 put ccbuf add o i uchar and shr v mul i 8 0xff 570 end 571 end 572 573 fn t08_irq_bm to bool 574 bmmio_reset 575 ibm_reset 576 hg = bmmio_register SPARK_GB20B_BAR0_PA SPARK_GB20B_BAR0_PA SPARK_GB20B_BAR0_SZ BMMIO_ATTR_NGNRNE 577 if ne ibm_bind hg 1 0 578 ret false 579 end 580 note Reset irq.om state 581 put iqmode 0 1 582 put iqstate 0 0 583 put iqgen 0 0 584 put iqdone 0 0 585 put iqpend 0 0 586 put iqhalt 0 0 587 if ne iqinit 1 0 588 ret false 589 end 590 note iqmode=1 must still return -9 591 if ne iqservice 1 8 -9 592 ret false 593 end 594 note Switch to bare-metal GB20B polling mode (iqmode=2) 595 put iqmode 0 2 596 note Seed verified GB20B IRQ regs: RISCV_IRQMASK=0x50 (0x111528), RISCV_IRQDEST=0x50 (0x11152c), FALCON_IRQSTAT=0x40 (0x110008) 597 z = bmmio_w32 hg IBM_RVMASK 0x50 598 z = bmmio_w32 hg IBM_RVDEST 0x50 599 z = bmmio_w32 hg IBM_IRQSTAT 0x40 600 put ibm_rpc_avail 0 2 601 r1 = iqservicecc 1 8 -1 8 602 if or ne r1 2 or ne get ibm_clears 0 1 ne get ibm_order_err 0 0 603 ret false 604 end 605 if ne bmmio_r32 hg IBM_IRQSTAT 0 606 ret false 607 end 608 note Regression: 2nd iqservicecc call with SWGEN0 must keep ibm_order_err == 0 609 z = bmmio_w32 hg IBM_IRQSTAT 0x40 610 put ibm_rpc_avail 0 1 611 if ne iqservicecc 1 8 -1 8 1 612 ret false 613 end 614 if or ne get ibm_clears 0 2 ne get ibm_order_err 0 0 615 ret false 616 end 617 note Inject HALT (0x10) + valid CrashCat V1 report packet (48 bytes) in ccbuf 618 for i ulong 48 619 put ccbuf i 0 620 end 621 ps_ccput64 0 `14587176806713922100` 622 ps_ccput64 8 0x1234 623 ps_ccput64 16 0x6f 624 ps_ccput64 24 0xde 625 ps_ccput64 32 0x14d 626 ps_ccput64 40 0x1bc 627 if ne iqccbind 1 0x340000000 48 0 628 ret false 629 end 630 z = bmmio_w32 hg IBM_IRQSTAT 0x10 631 if ne iqservicecc 1 8 -1 8 -13 632 ret false 633 end 634 if ne get iqhalt 0 1 635 ret false 636 end 637 if ne get ibm_masks 0 1 638 ret false 639 end 640 if ne get iqccpkts 0 1 641 ret false 642 end 643 note Verify sticky lockdown stops ALL further BAR0 accesses 644 put iqstate 0 0 645 put iqgen 0 0 646 put iqhalt 0 0 647 put ibm_locked 0 0 648 if ne iqinit 2 0 649 ret false 650 end 651 z = bmmio_w32 hg IBM_IRQSTAT 0x40 652 put ibm_rpc_avail 0 2 653 put ibm_rpc_lock_at 0 1 654 put ibm_rpc_done 0 0 655 if ne iqservicecc 2 8 -1 8 1 656 ret false 657 end 658 if ne get iqstate 0 3 659 ret false 660 end 661 if ne get ibm_locked 0 1 662 ret false 663 end 664 rd_before = get bmmio_rd_ops 0 665 wr_before = get bmmio_wr_ops 0 666 if ne iqservicecc 2 8 -1 8 -14 667 ret false 668 end 669 if ne get bmmio_rd_ops 0 rd_before 670 ret false 671 end 672 ret eq get bmmio_wr_ops 0 wr_before 673 end 674 675 fn ps_live_spans to ulong 676 c = ulong 0 677 for k ulong SMMU_MAX_SPANS 678 if ne get smmu_sp_live k 0 679 c = add c 1 680 end 681 end 682 ret c 683 end 684 685 note Error-path teardown: a GB20B open whose CMD_SYNC fails must leave no stream, no live span (RMRs 686 note included) and zeroed STE/CD words, so a retry reuses slot 0 and re-maps the RMRs cleanly. 687 note IORT base cross-check: an instance brought up at a base other than the IORT node's -> SMMU_EBASE. 688 fn t09_teardown to bool 689 if not t05_smmu_abc 690 ret false 691 end 692 put smmu_sim_cmd_err 1 1 693 if ne smmu_open_stream 15 0x0100 0x11000000 0x11001000 SMMU_ECMDERR 694 ret false 695 end 696 put smmu_sim_cmd_err 1 0 697 if or ne get smmu_str_n 0 0 ne get smmu_str_live 0 0 698 ret false 699 end 700 if or ne ps_live_spans 0 ne get smmu_ste_words 0 0 701 ret false 702 end 703 if ne get smmu_cd_words 0 0 704 ret false 705 end 706 note Model hardware recovery: clear CONS.ERR (real HW: GERROR/GERRORN ack + CONS resume). 707 z = bmmio_w32 get smmu_inst_h 1 SMMU_REG_CMDQ_CONS get smmu_inst_cmd_prod 1 708 if ne smmu_open_stream 15 0x0100 0x11000000 0x11001000 1 709 ret false 710 end 711 if eq ps_live_spans 0 712 ret false 713 end 714 put smmu_inst_base 0 0x12345000 715 if ne smmu_open_stream 4 0x0100 0x11002000 0x11003000 SMMU_EBASE 716 ret false 717 end 718 put smmu_inst_base 0 SPARK_SMMU_A_PA 719 ret gt smmu_open_stream 4 0x0100 0x11002000 0x11003000 0 720 end 721 722 fn main to int 723 fail = ulong 0 724 fail = add fail ps_rep ps_t1 t01_bar0 725 fail = add fail ps_rep ps_t2 t02_mcfg 726 fail = add fail ps_rep ps_t3 t03_caps_quiesce 727 fail = add fail ps_rep ps_t4 t04_smmu_neg 728 fail = add fail ps_rep ps_t5 t05_smmu_abc 729 fail = add fail ps_rep ps_t6 t06_smmu_dma 730 fail = add fail ps_rep ps_t7 t07_eventq 731 fail = add fail ps_rep ps_t8 t08_irq_bm 732 fail = add fail ps_rep ps_t9 t09_teardown 733 if eq fail 0 734 ps_wstr ps_sum 735 ret 0 736 end 737 ps_wstr ps_fsum 738 ret 1 739 end