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-kernel / mm_iommu_test.om
| 1 | note aienux/crates/aienos-kernel/mm_iommu_test.om |
| 2 | note Comprehensive behavioral tests for mm_iommu.om covering all 9 subsystems |
| 3 | note and all Rust unit tests with distinct non-zero exit codes on every failure. |
| 4 | |
| 5 | note ======================================================================== |
| 6 | note 1. Frame Allocator Tests (exit codes 1..15) |
| 7 | note ======================================================================== |
| 8 | |
| 9 | fn kmi_test_frame_allocator to int |
| 10 | st = new ulong 16 0 |
| 11 | out_a = new ulong 1 0 |
| 12 | batch = new ulong 160 0 |
| 13 | |
| 14 | note test_allocator_basic |
| 15 | if ne kmi_fa_init st 0x10000000 256 4 0 |
| 16 | ret 1 |
| 17 | end |
| 18 | if ne kmi_fa_total_frames st 256 |
| 19 | ret 2 |
| 20 | end |
| 21 | if ne kmi_fa_free_count st 256 |
| 22 | ret 3 |
| 23 | end |
| 24 | if not kmi_fa_alloc st out_a |
| 25 | ret 4 |
| 26 | end |
| 27 | if ne get out_a 0 0x10000000 |
| 28 | ret 4 |
| 29 | end |
| 30 | if ne kmi_fa_allocated_count st 1 |
| 31 | ret 4 |
| 32 | end |
| 33 | if not kmi_fa_alloc st out_a |
| 34 | ret 5 |
| 35 | end |
| 36 | if ne get out_a 0 0x10001000 |
| 37 | ret 5 |
| 38 | end |
| 39 | if not kmi_fa_free st 0x10000000 |
| 40 | ret 6 |
| 41 | end |
| 42 | if kmi_fa_free st 0x10000000 |
| 43 | ret 6 |
| 44 | end |
| 45 | if ne kmi_fa_allocated_count st 1 |
| 46 | ret 6 |
| 47 | end |
| 48 | if not kmi_fa_alloc st out_a |
| 49 | ret 7 |
| 50 | end |
| 51 | if ne get out_a 0 0x10000000 |
| 52 | ret 7 |
| 53 | end |
| 54 | |
| 55 | note test_alloc_contiguous |
| 56 | if ne kmi_fa_init st 0x20000000 128 2 0 |
| 57 | ret 8 |
| 58 | end |
| 59 | if not kmi_fa_alloc_contig st 4 out_a |
| 60 | ret 8 |
| 61 | end |
| 62 | if ne get out_a 0 0x20000000 |
| 63 | ret 8 |
| 64 | end |
| 65 | if ne kmi_fa_allocated_count st 4 |
| 66 | ret 8 |
| 67 | end |
| 68 | |
| 69 | note allocator_rejects_unaligned_deallocation |
| 70 | if ne kmi_fa_init st 0x20000000 64 1 0 |
| 71 | ret 9 |
| 72 | end |
| 73 | if not kmi_fa_alloc st out_a |
| 74 | ret 9 |
| 75 | end |
| 76 | if kmi_fa_free st add get out_a 0 1 |
| 77 | ret 10 |
| 78 | end |
| 79 | if ne kmi_fa_allocated_count st 1 |
| 80 | ret 10 |
| 81 | end |
| 82 | if not kmi_fa_free st get out_a 0 |
| 83 | ret 10 |
| 84 | end |
| 85 | |
| 86 | note batch_reservation_is_bounded_and_released_as_a_unit |
| 87 | if ne kmi_fa_init st 0x30000000 8 1 0 |
| 88 | ret 11 |
| 89 | end |
| 90 | if ne kmi_fa_alloc_batch st 6 batch 6 |
| 91 | ret 11 |
| 92 | end |
| 93 | if ne kmi_fa_free_count st 2 |
| 94 | ret 11 |
| 95 | end |
| 96 | if not kmi_fa_release_batch st batch 6 |
| 97 | ret 12 |
| 98 | end |
| 99 | if ne kmi_fa_free_count st 8 |
| 100 | ret 12 |
| 101 | end |
| 102 | if ne kmi_fa_alloc_batch st 161 batch 0 |
| 103 | ret 12 |
| 104 | end |
| 105 | |
| 106 | note insufficient_batch_reservation_leaves_no_partial_allocations |
| 107 | if ne kmi_fa_init st 0x40000000 8 1 0 |
| 108 | ret 13 |
| 109 | end |
| 110 | if not kmi_fa_alloc st out_a |
| 111 | ret 13 |
| 112 | end |
| 113 | if ne kmi_fa_alloc_batch st 8 batch 0 |
| 114 | ret 13 |
| 115 | end |
| 116 | if ne kmi_fa_allocated_count st 1 |
| 117 | ret 14 |
| 118 | end |
| 119 | if ne kmi_fa_free_count st 7 |
| 120 | ret 14 |
| 121 | end |
| 122 | |
| 123 | note allocator_rejects_capacity_overflow and unaligned base |
| 124 | if eq kmi_fa_init st 0x20000000 65 1 0 |
| 125 | ret 15 |
| 126 | end |
| 127 | if eq kmi_fa_init st 0x20000001 8 1 0 |
| 128 | ret 15 |
| 129 | end |
| 130 | ret 0 |
| 131 | end |
| 132 | |
| 133 | note ======================================================================== |
| 134 | note 2. Map Plan Tests (exit codes 16..35) |
| 135 | note ======================================================================== |
| 136 | |
| 137 | fn kmi_test_map_plan_regs to int |
| 138 | m = kmi_mair_el1 |
| 139 | if ne and m 0xff 0xff |
| 140 | ret 16 |
| 141 | end |
| 142 | if ne and shr m 8 0xff 0x04 |
| 143 | ret 16 |
| 144 | end |
| 145 | if ne m 0x04ff |
| 146 | ret 16 |
| 147 | end |
| 148 | tcr = kmi_tcr_el1 uchar 5 |
| 149 | if ne and tcr 0x3f 16 |
| 150 | ret 17 |
| 151 | end |
| 152 | if ne and shr tcr 8 3 1 |
| 153 | ret 17 |
| 154 | end |
| 155 | if ne and shr tcr 10 3 1 |
| 156 | ret 17 |
| 157 | end |
| 158 | if ne and shr tcr 12 3 3 |
| 159 | ret 17 |
| 160 | end |
| 161 | if ne and shr tcr 14 3 0 |
| 162 | ret 18 |
| 163 | end |
| 164 | if ne and shr tcr 16 0x3f 16 |
| 165 | ret 18 |
| 166 | end |
| 167 | if eq and tcr shl ulong 1 23 0 |
| 168 | ret 18 |
| 169 | end |
| 170 | if ne and shr tcr 30 3 2 |
| 171 | ret 19 |
| 172 | end |
| 173 | if ne and shr tcr 32 7 5 |
| 174 | ret 19 |
| 175 | end |
| 176 | s = kmi_sctlr_el1 |
| 177 | if ne and s 0x30d00800 0x30d00800 |
| 178 | ret 20 |
| 179 | end |
| 180 | mci = or ulong 1 or shl ulong 1 2 shl ulong 1 12 |
| 181 | if ne and s mci mci |
| 182 | ret 20 |
| 183 | end |
| 184 | bad_b = or shl ulong 1 1 or shl ulong 1 19 shl ulong 1 25 |
| 185 | if ne and s bad_b 0 |
| 186 | ret 21 |
| 187 | end |
| 188 | ret 0 |
| 189 | end |
| 190 | |
| 191 | fn kmi_test_map_plan_rt_mmio to int |
| 192 | meta = new ulong 4 0 |
| 193 | plan = new ulong 48 0 |
| 194 | rt_reg = new ulong 3 0 |
| 195 | rt_attrs = new ulong 8 0 |
| 196 | mmio = new ulong 4 0 |
| 197 | |
| 198 | note missing_mat_maps_runtime_code_rx_without_wx |
| 199 | kmi_plan_init meta 16 |
| 200 | put rt_reg 0 0x400000 |
| 201 | put rt_reg 1 4096 |
| 202 | put rt_reg 2 0 |
| 203 | if ne kmi_plan_add_runtime meta plan rt_reg rt_attrs KMI_PLAN_OK |
| 204 | ret 28 |
| 205 | end |
| 206 | if ne get meta 0 1 |
| 207 | ret 28 |
| 208 | end |
| 209 | if ne get meta 1 KMI_RT_DECISION_RX_UNSPLIT |
| 210 | ret 28 |
| 211 | end |
| 212 | if eq and get plan 2 KMI_FLAG_EXECUTABLE 0 |
| 213 | ret 29 |
| 214 | end |
| 215 | if ne and get plan 2 KMI_FLAG_WRITABLE 0 |
| 216 | ret 29 |
| 217 | end |
| 218 | |
| 219 | note runtime_code_needs_ro_xp_split |
| 220 | kmi_plan_init meta 16 |
| 221 | put rt_reg 0 0x400000 |
| 222 | put rt_reg 1 8192 |
| 223 | put rt_reg 2 1 |
| 224 | put rt_attrs 0 0x400000 |
| 225 | put rt_attrs 1 4096 |
| 226 | put rt_attrs 2 1 |
| 227 | put rt_attrs 3 0 |
| 228 | put rt_attrs 4 0x401000 |
| 229 | put rt_attrs 5 4096 |
| 230 | put rt_attrs 6 0 |
| 231 | put rt_attrs 7 1 |
| 232 | if ne kmi_plan_add_runtime meta plan rt_reg rt_attrs KMI_PLAN_OK |
| 233 | ret 30 |
| 234 | end |
| 235 | if ne get meta 0 2 |
| 236 | ret 30 |
| 237 | end |
| 238 | if eq and get plan 2 KMI_FLAG_EXECUTABLE 0 |
| 239 | ret 31 |
| 240 | end |
| 241 | if ne and get plan 2 KMI_FLAG_WRITABLE 0 |
| 242 | ret 31 |
| 243 | end |
| 244 | if eq and get plan 5 KMI_FLAG_WRITABLE 0 |
| 245 | ret 31 |
| 246 | end |
| 247 | if ne and get plan 5 KMI_FLAG_EXECUTABLE 0 |
| 248 | ret 31 |
| 249 | end |
| 250 | |
| 251 | note writable_executable_runtime_code_is_mapped_rx |
| 252 | kmi_plan_init meta 16 |
| 253 | put rt_reg 0 0x400000 |
| 254 | put rt_reg 1 4096 |
| 255 | put rt_reg 2 1 |
| 256 | put rt_attrs 0 0x400000 |
| 257 | put rt_attrs 1 4096 |
| 258 | put rt_attrs 2 0 |
| 259 | put rt_attrs 3 0 |
| 260 | if ne kmi_plan_add_runtime meta plan rt_reg rt_attrs KMI_PLAN_OK |
| 261 | ret 32 |
| 262 | end |
| 263 | if ne get meta 1 KMI_RT_DECISION_RX_UNSPLIT |
| 264 | ret 32 |
| 265 | end |
| 266 | if eq and get plan 2 KMI_FLAG_EXECUTABLE 0 |
| 267 | ret 33 |
| 268 | end |
| 269 | if ne and get plan 2 KMI_FLAG_WRITABLE 0 |
| 270 | ret 33 |
| 271 | end |
| 272 | |
| 273 | note mmio_is_device_nx_and_overlap_rejected |
| 274 | kmi_plan_init meta 16 |
| 275 | put mmio 0 0x90000000 |
| 276 | put mmio 1 4096 |
| 277 | if ne kmi_plan_add_mmio meta plan 0 part mmio 0 2 KMI_PLAN_OK |
| 278 | ret 34 |
| 279 | end |
| 280 | if eq and get plan 2 KMI_FLAG_DEVICE 0 |
| 281 | ret 34 |
| 282 | end |
| 283 | if ne and get plan 2 KMI_FLAG_EXECUTABLE 0 |
| 284 | ret 34 |
| 285 | end |
| 286 | kmi_plan_init meta 16 |
| 287 | put mmio 0 4096 |
| 288 | put mmio 1 8192 |
| 289 | put mmio 2 8192 |
| 290 | put mmio 3 4096 |
| 291 | if ne kmi_plan_add_mmio meta plan 0 mmio KMI_PLAN_OK |
| 292 | ret 35 |
| 293 | end |
| 294 | if ne kmi_plan_validate_overlaps meta plan KMI_PLAN_ERR_OVERLAP |
| 295 | ret 35 |
| 296 | end |
| 297 | ret 0 |
| 298 | end |
| 299 | |
| 300 | fn kmi_test_map_plan to int |
| 301 | rc_r = kmi_test_map_plan_regs |
| 302 | if ne rc_r 0 |
| 303 | ret rc_r |
| 304 | end |
| 305 | meta = new ulong 4 0 |
| 306 | plan = new ulong 48 0 |
| 307 | img_reg = new ulong 4 0 |
| 308 | secs = new ulong 6 0 |
| 309 | rx_ch = or ulong 0x40000000 KMI_SCN_MEM_EXECUTE |
| 310 | rw_ch = or ulong 0x40000000 KMI_SCN_MEM_WRITE |
| 311 | |
| 312 | note section_permissions_are_wx_safe |
| 313 | kmi_plan_init meta 16 |
| 314 | put img_reg 0 0x100000 |
| 315 | put img_reg 1 16384 |
| 316 | put img_reg 2 0x100000 |
| 317 | put img_reg 3 16384 |
| 318 | put secs 0 0x100000 |
| 319 | put secs 1 4096 |
| 320 | put secs 2 rx_ch |
| 321 | put secs 3 0x101000 |
| 322 | put secs 4 4096 |
| 323 | put secs 5 rw_ch |
| 324 | if ne kmi_plan_add_loader meta plan img_reg secs KMI_PLAN_OK |
| 325 | ret 22 |
| 326 | end |
| 327 | if ne kmi_plan_validate_overlaps meta plan KMI_PLAN_OK |
| 328 | ret 22 |
| 329 | end |
| 330 | if ne get meta 1 KMI_RT_DECISION_NONE |
| 331 | ret 23 |
| 332 | end |
| 333 | if ne get meta 0 2 |
| 334 | ret 23 |
| 335 | end |
| 336 | if eq and get plan 2 KMI_FLAG_EXECUTABLE 0 |
| 337 | ret 24 |
| 338 | end |
| 339 | if ne and get plan 2 KMI_FLAG_WRITABLE 0 |
| 340 | ret 24 |
| 341 | end |
| 342 | if eq and get plan 5 KMI_FLAG_WRITABLE 0 |
| 343 | ret 25 |
| 344 | end |
| 345 | if ne and get plan 5 KMI_FLAG_EXECUTABLE 0 |
| 346 | ret 25 |
| 347 | end |
| 348 | |
| 349 | note W+X section rejected as Overlap |
| 350 | kmi_plan_init meta 16 |
| 351 | put secs 2 or KMI_SCN_MEM_EXECUTE KMI_SCN_MEM_WRITE |
| 352 | if ne kmi_plan_add_loader meta plan img_reg secs KMI_PLAN_ERR_OVERLAP |
| 353 | ret 26 |
| 354 | end |
| 355 | |
| 356 | note section outside allocation rejected |
| 357 | kmi_plan_init meta 16 |
| 358 | put secs 0 0x500000 |
| 359 | put secs 2 rx_ch |
| 360 | if ne kmi_plan_add_loader meta plan img_reg secs KMI_PLAN_ERR_SEC_OUTSIDE |
| 361 | ret 27 |
| 362 | end |
| 363 | ret kmi_test_map_plan_rt_mmio |
| 364 | end |
| 365 | |
| 366 | note ======================================================================== |
| 367 | note 3. SMMUv3 Tests (exit codes 36..80) |
| 368 | note ======================================================================== |
| 369 | |
| 370 | fn kmi_test_smmu_desc_and_geom to int |
| 371 | ste = new ulong 8 0 |
| 372 | cd = new ulong 8 0 |
| 373 | cur = new uint 2 0 |
| 374 | geom = new ulong 7 0 |
| 375 | |
| 376 | note descriptor_layouts |
| 377 | kmi_ste_abort ste |
| 378 | if ne get ste 0 1 |
| 379 | ret 36 |
| 380 | end |
| 381 | kmi_ste_stage1 0x123456780 ste |
| 382 | if ne and get ste 0 1 1 |
| 383 | ret 37 |
| 384 | end |
| 385 | if ne and shr get ste 0 1 7 5 |
| 386 | ret 37 |
| 387 | end |
| 388 | if ne and shr get ste 0 4 3 0 |
| 389 | ret 37 |
| 390 | end |
| 391 | if ne and get ste 0 0x000fffffffffffc0 0x123456780 |
| 392 | ret 38 |
| 393 | end |
| 394 | for i ulong 7 |
| 395 | if ne get ste add i 1 0 |
| 396 | ret 38 |
| 397 | end |
| 398 | end |
| 399 | if ne kmi_cd_stage1 0x4000 ushort 0x1234 0xff00 uchar 16 cd KMI_SMMU_OK |
| 400 | ret 39 |
| 401 | end |
| 402 | exp0 = ulong 16 |
| 403 | exp0 = or exp0 shl ulong 1 8 |
| 404 | exp0 = or exp0 shl ulong 1 10 |
| 405 | exp0 = or exp0 shl ulong 3 12 |
| 406 | exp0 = or exp0 shl ulong 1 30 |
| 407 | exp0 = or exp0 shl ulong 1 31 |
| 408 | exp0 = or exp0 shl ulong 5 32 |
| 409 | exp0 = or exp0 shl ulong 1 41 |
| 410 | exp0 = or exp0 shl ulong 1 45 |
| 411 | exp0 = or exp0 shl ulong 1 46 |
| 412 | exp0 = or exp0 shl ulong 0x1234 48 |
| 413 | if ne get cd 0 exp0 |
| 414 | ret 40 |
| 415 | end |
| 416 | if ne get cd 1 0x4000 |
| 417 | ret 40 |
| 418 | end |
| 419 | if ne get cd 2 0 |
| 420 | ret 40 |
| 421 | end |
| 422 | if ne get cd 3 0xff00 |
| 423 | ret 40 |
| 424 | end |
| 425 | if ne kmi_cd_stage1 0x4001 ushort 1 0xff uchar 16 cd KMI_SMMU_ERR_INVALID_WINDOW |
| 426 | ret 41 |
| 427 | end |
| 428 | if ne kmi_cd_stage1 0x4000 ushort 1 0xff uchar 40 cd KMI_SMMU_ERR_INVALID_WINDOW |
| 429 | ret 41 |
| 430 | end |
| 431 | |
| 432 | note command_words_and_queue_wrap |
| 433 | if ne kmi_smmu_cmd_w0 KMI_CMD_CFGI_STE uint 7 or ulong 3 shl ulong 7 32 |
| 434 | ret 42 |
| 435 | end |
| 436 | if ne kmi_smmu_cmd_w1 KMI_CMD_CFGI_STE true 1 |
| 437 | ret 42 |
| 438 | end |
| 439 | if ne kmi_smmu_cmd_w0 KMI_CMD_CFGI_ALL uint 0 4 |
| 440 | ret 43 |
| 441 | end |
| 442 | if ne kmi_smmu_cmd_w1 KMI_CMD_CFGI_ALL false 31 |
| 443 | ret 43 |
| 444 | end |
| 445 | if ne kmi_smmu_cmd_w0 KMI_CMD_TLBI_NSNH_ALL uint 0 0x30 |
| 446 | ret 43 |
| 447 | end |
| 448 | if ne kmi_smmu_cmd_w0 KMI_CMD_SYNC uint 0 0x46 |
| 449 | ret 43 |
| 450 | end |
| 451 | put cur 0 uint 1 |
| 452 | put cur 1 uint 0 |
| 453 | kmi_qcursor_advance cur uint 2 |
| 454 | if ne get cur 0 0 |
| 455 | ret 44 |
| 456 | end |
| 457 | if ne get cur 1 1 |
| 458 | ret 44 |
| 459 | end |
| 460 | if ne kmi_qcursor_encode get cur 0 true uint 2 2 |
| 461 | ret 44 |
| 462 | end |
| 463 | if ne kmi_qcursor_encode uint 5 true uint 16 0x15 |
| 464 | ret 45 |
| 465 | end |
| 466 | if ne kmi_qcursor_decode_idx uint 0x15 uint 16 5 |
| 467 | ret 45 |
| 468 | end |
| 469 | if not kmi_qcursor_decode_wrap uint 0x15 uint 16 |
| 470 | ret 45 |
| 471 | end |
| 472 | if kmi_qcursor_decode_wrap uint 0x80000005 uint 16 |
| 473 | ret 45 |
| 474 | end |
| 475 | |
| 476 | note tables_reject_misaligned_or_bad_geometry |
| 477 | put geom 0 0x100000 |
| 478 | put geom 1 16 |
| 479 | put geom 2 0x101000 |
| 480 | put geom 3 16 |
| 481 | put geom 4 0x102000 |
| 482 | put geom 5 16 |
| 483 | put geom 6 0x103000 |
| 484 | if not kmi_smmu_tables_valid geom |
| 485 | ret 46 |
| 486 | end |
| 487 | put geom 1 12 |
| 488 | if kmi_smmu_tables_valid geom |
| 489 | ret 47 |
| 490 | end |
| 491 | put geom 1 16 |
| 492 | put geom 3 1 |
| 493 | if kmi_smmu_tables_valid geom |
| 494 | ret 47 |
| 495 | end |
| 496 | put geom 3 16 |
| 497 | put geom 4 0x102100 |
| 498 | if kmi_smmu_tables_valid geom |
| 499 | ret 48 |
| 500 | end |
| 501 | put geom 4 0x102000 |
| 502 | put geom 6 0x103008 |
| 503 | if kmi_smmu_tables_valid geom |
| 504 | ret 48 |
| 505 | end |
| 506 | ret 0 |
| 507 | end |
| 508 | |
| 509 | fn kmi_test_smmu_bringup to int |
| 510 | sm = new ulong 512 0 |
| 511 | cd = new ulong 8 0 |
| 512 | ste_exp = new ulong 8 0 |
| 513 | if ne kmi_cd_stage1 0x4000 ushort 1 0x00ff uchar 16 cd KMI_SMMU_OK |
| 514 | ret 49 |
| 515 | end |
| 516 | |
| 517 | note bring_up_keeps_global_abort_through_smmuen |
| 518 | kmi_smmu_init sm |
| 519 | if ne kmi_smmu_configure_linear sm uint 3 cd 4 KMI_SMMU_OK |
| 520 | ret 50 |
| 521 | end |
| 522 | if ne get sm KMI_SM_FIRST_WR_REG ulong KMI_SMMU_GBPA |
| 523 | ret 50 |
| 524 | end |
| 525 | if ne get sm KMI_SM_ALL_ABORT 1 |
| 526 | ret 51 |
| 527 | end |
| 528 | if ne get sm KMI_SM_LAST_REG ulong KMI_SMMU_CR0 |
| 529 | ret 51 |
| 530 | end |
| 531 | if ne get sm KMI_SM_LAST_VAL 0x0d |
| 532 | ret 51 |
| 533 | end |
| 534 | if ne get sm KMI_SM_CR0ACK 0x0d |
| 535 | ret 52 |
| 536 | end |
| 537 | if not kmi_smmu_abort_in_effect sm |
| 538 | ret 52 |
| 539 | end |
| 540 | kmi_ste_stage1 get sm KMI_SM_CD_ADDR ste_exp |
| 541 | for s ulong 16 |
| 542 | sb = add KMI_SM_STE_BASE mul s 8 |
| 543 | if eq s 3 |
| 544 | if ne get sm sb get ste_exp 0 |
| 545 | ret 53 |
| 546 | end |
| 547 | else |
| 548 | if ne get sm sb 1 |
| 549 | ret 53 |
| 550 | end |
| 551 | end |
| 552 | end |
| 553 | if ne get sm KMI_SM_CONS_CNT 3 |
| 554 | ret 54 |
| 555 | end |
| 556 | if ne get sm KMI_SM_STRTAB_CFG 4 |
| 557 | ret 54 |
| 558 | end |
| 559 | |
| 560 | note bring_up_cleans_tables_after_writing_before_programming |
| 561 | gbpa_seq = get sm KMI_SM_FIRST_GBPA |
| 562 | cr0_seq = get sm KMI_SM_FIRST_CR0 |
| 563 | str_seq = get sm KMI_SM_FIRST_STRTAB |
| 564 | cs = get sm KMI_SM_CLEAN_STREAM |
| 565 | cc = get sm KMI_SM_CLEAN_CD |
| 566 | cm = get sm KMI_SM_CLEAN_CMD |
| 567 | ie = get sm KMI_SM_INV_EV |
| 568 | if le cs gbpa_seq |
| 569 | ret 55 |
| 570 | end |
| 571 | if ge cs cr0_seq |
| 572 | ret 55 |
| 573 | end |
| 574 | if ge cs str_seq |
| 575 | ret 55 |
| 576 | end |
| 577 | if ge cc cr0_seq |
| 578 | ret 55 |
| 579 | end |
| 580 | if ge cm cr0_seq |
| 581 | ret 55 |
| 582 | end |
| 583 | if ge ie cr0_seq |
| 584 | ret 55 |
| 585 | end |
| 586 | ret 0 |
| 587 | end |
| 588 | |
| 589 | fn kmi_test_smmu_failures to int |
| 590 | sm = new ulong 512 0 |
| 591 | cd = new ulong 8 0 |
| 592 | if ne kmi_cd_stage1 0x4000 ushort 1 0x00ff uchar 16 cd KMI_SMMU_OK |
| 593 | ret 56 |
| 594 | end |
| 595 | |
| 596 | note gbpa_update_timeout_fails_closed |
| 597 | kmi_smmu_init sm |
| 598 | put sm KMI_SM_GBPA_STUCK ulong 1 |
| 599 | if ne kmi_smmu_configure_linear sm uint 3 cd 4 KMI_SMMU_ERR_TIMEOUT |
| 600 | ret 56 |
| 601 | end |
| 602 | if eq and get sm KMI_SM_GBPA ulong KMI_GBPA_ABORT 0 |
| 603 | ret 57 |
| 604 | end |
| 605 | if ne get sm KMI_SM_WR_CNT 1 |
| 606 | ret 57 |
| 607 | end |
| 608 | |
| 609 | note smmuen_ack_failure_fails_closed |
| 610 | kmi_smmu_init sm |
| 611 | put sm KMI_SM_ACK_NEVER ulong KMI_CR0_SMMUEN |
| 612 | if ne kmi_smmu_configure_linear sm uint 3 cd 4 KMI_SMMU_ERR_TIMEOUT |
| 613 | ret 58 |
| 614 | end |
| 615 | if not kmi_smmu_abort_in_effect sm |
| 616 | ret 58 |
| 617 | end |
| 618 | if ne get sm KMI_SM_LAST_REG ulong KMI_SMMU_CR0 |
| 619 | ret 59 |
| 620 | end |
| 621 | if ne get sm KMI_SM_LAST_VAL 0 |
| 622 | ret 59 |
| 623 | end |
| 624 | if ne get sm KMI_SM_ALL_ABORT 1 |
| 625 | ret 59 |
| 626 | end |
| 627 | |
| 628 | note command_timeout_and_error_fail_closed |
| 629 | kmi_smmu_init sm |
| 630 | put sm KMI_SM_CMDQ_STUCK ulong 1 |
| 631 | if ne kmi_smmu_configure_linear sm uint 3 cd 4 KMI_SMMU_ERR_TIMEOUT |
| 632 | ret 60 |
| 633 | end |
| 634 | if ne get sm KMI_SM_SMMUEN_SEEN 0 |
| 635 | ret 60 |
| 636 | end |
| 637 | if ne get sm KMI_SM_CR0 0 |
| 638 | ret 60 |
| 639 | end |
| 640 | |
| 641 | kmi_smmu_init sm |
| 642 | put sm KMI_SM_CMDQ_ERROR ulong 1 |
| 643 | if ne kmi_smmu_configure_linear sm uint 3 cd 4 KMI_SMMU_ERR_CMDQ |
| 644 | ret 61 |
| 645 | end |
| 646 | if ne get sm KMI_SM_SMMUEN_SEEN 0 |
| 647 | ret 61 |
| 648 | end |
| 649 | if ne get sm KMI_SM_CR0 0 |
| 650 | ret 61 |
| 651 | end |
| 652 | |
| 653 | note unsupported_hardware_or_bad_sid_fails_closed |
| 654 | kmi_smmu_init sm |
| 655 | kmi_smmu_reg_write sm KMI_SMMU_CR0 or KMI_CR0_SMMUEN KMI_CR0_CMDQEN |
| 656 | kmi_smmu_reset_log sm |
| 657 | put sm KMI_SM_IDR1 ulong 2 |
| 658 | if ne kmi_smmu_configure_linear sm uint 3 cd 4 KMI_SMMU_ERR_UNSUPPORTED |
| 659 | ret 62 |
| 660 | end |
| 661 | if ne get sm KMI_SM_CR0ACK 0 |
| 662 | ret 62 |
| 663 | end |
| 664 | if ne get sm KMI_SM_STE_BASE 0xdead |
| 665 | ret 62 |
| 666 | end |
| 667 | |
| 668 | kmi_smmu_init sm |
| 669 | put sm KMI_SM_IDR0 ulong 0 |
| 670 | if ne kmi_smmu_configure_linear sm uint 3 cd 4 KMI_SMMU_ERR_UNSUPPORTED |
| 671 | ret 63 |
| 672 | end |
| 673 | |
| 674 | kmi_smmu_init sm |
| 675 | if ne kmi_smmu_configure_linear sm uint 16 cd 4 KMI_SMMU_ERR_INVALID_WINDOW |
| 676 | ret 64 |
| 677 | end |
| 678 | |
| 679 | note gbpa_that_will_not_abort_is_an_error |
| 680 | kmi_smmu_init sm |
| 681 | put sm KMI_SM_GBPA_NO_ABORT ulong 1 |
| 682 | if ne kmi_smmu_configure_linear sm uint 3 cd 4 KMI_SMMU_ERR_ABORT_NOT_LATCHED |
| 683 | ret 65 |
| 684 | end |
| 685 | if ne get sm KMI_SM_WR_CNT 1 |
| 686 | ret 65 |
| 687 | end |
| 688 | ret 0 |
| 689 | end |
| 690 | |
| 691 | fn kmi_test_smmu_ops_and_events to int |
| 692 | sm = new ulong 512 0 |
| 693 | cd = new ulong 8 0 |
| 694 | ste = new ulong 8 0 |
| 695 | sync_cmds = new ulong 34 0 |
| 696 | ev_out = new ulong 6 0 |
| 697 | drain = new ulong 2 0 |
| 698 | wins = new ulong 3 0 |
| 699 | if ne kmi_cd_stage1 0x4000 ushort 1 0x00ff uchar 16 cd KMI_SMMU_OK |
| 700 | ret 66 |
| 701 | end |
| 702 | kmi_smmu_init sm |
| 703 | if ne kmi_smmu_configure_linear sm uint 3 cd 4 KMI_SMMU_OK |
| 704 | ret 66 |
| 705 | end |
| 706 | |
| 707 | note install_and_abort_ste_invalidate_that_stream |
| 708 | kmi_smmu_reset_log sm |
| 709 | kmi_ste_stage1 get sm KMI_SM_CD_ADDR ste |
| 710 | if ne kmi_smmu_install_ste sm uint 7 ste 4 KMI_SMMU_OK |
| 711 | ret 67 |
| 712 | end |
| 713 | if ne get sm add KMI_SM_STE_BASE 56 get ste 0 |
| 714 | ret 67 |
| 715 | end |
| 716 | if ne get sm KMI_SM_CONS_CNT 6 |
| 717 | ret 68 |
| 718 | end |
| 719 | if ne kmi_smmu_abort_ste sm uint 7 4 KMI_SMMU_OK |
| 720 | ret 69 |
| 721 | end |
| 722 | if ne get sm add KMI_SM_STE_BASE 56 1 |
| 723 | ret 69 |
| 724 | end |
| 725 | if ne kmi_smmu_install_ste sm uint 16 ste 4 KMI_SMMU_ERR_INVALID_WINDOW |
| 726 | ret 70 |
| 727 | end |
| 728 | if ne kmi_smmu_abort_ste sm uint 16 4 KMI_SMMU_ERR_INVALID_WINDOW |
| 729 | ret 70 |
| 730 | end |
| 731 | |
| 732 | note command_queue_wraps_and_times_out |
| 733 | kmi_smmu_init sm |
| 734 | if ne kmi_smmu_configure_linear sm uint 3 cd 4 KMI_SMMU_OK |
| 735 | ret 71 |
| 736 | end |
| 737 | for i ulong 11 |
| 738 | if ne kmi_smmu_abort_ste sm uint 5 4 KMI_SMMU_OK |
| 739 | ret 71 |
| 740 | end |
| 741 | end |
| 742 | if ne get sm KMI_SM_CONS_CNT 36 |
| 743 | ret 72 |
| 744 | end |
| 745 | if ne get sm KMI_SM_CMDQ_PROD 4 |
| 746 | ret 72 |
| 747 | end |
| 748 | for i ulong 4 |
| 749 | if ne kmi_smmu_abort_ste sm uint 5 4 KMI_SMMU_OK |
| 750 | ret 73 |
| 751 | end |
| 752 | end |
| 753 | if ne get sm KMI_SM_CMDQ_PROD 0x10 |
| 754 | ret 73 |
| 755 | end |
| 756 | put sm KMI_SM_CMDQ_STUCK ulong 1 |
| 757 | if ne kmi_smmu_abort_ste sm uint 5 4 KMI_SMMU_ERR_TIMEOUT |
| 758 | ret 74 |
| 759 | end |
| 760 | |
| 761 | note submit_refuses_to_overwrite_a_full_queue |
| 762 | kmi_smmu_init sm |
| 763 | if ne kmi_smmu_configure_linear sm uint 3 cd 4 KMI_SMMU_OK |
| 764 | ret 75 |
| 765 | end |
| 766 | put sm KMI_SM_CMDQ_STUCK ulong 1 |
| 767 | for i ulong 17 |
| 768 | put sync_cmds mul i 2 kmi_smmu_cmd_w0 KMI_CMD_SYNC uint 0 |
| 769 | put sync_cmds add mul i 2 1 kmi_smmu_cmd_w1 KMI_CMD_SYNC false |
| 770 | end |
| 771 | if ne kmi_smmu_submit_cmds sm sync_cmds 17 4 KMI_SMMU_ERR_TIMEOUT |
| 772 | ret 75 |
| 773 | end |
| 774 | p_raw = uint and get sm KMI_SM_CMDQ_PROD 0xffffffff |
| 775 | c_raw = uint and get sm KMI_SM_CMDQ_CONS 0xffffffff |
| 776 | if ne kmi_qcursor_decode_idx p_raw uint 16 kmi_qcursor_decode_idx c_raw uint 16 |
| 777 | ret 76 |
| 778 | end |
| 779 | if eq kmi_qcursor_decode_wrap p_raw uint 16 kmi_qcursor_decode_wrap c_raw uint 16 |
| 780 | ret 76 |
| 781 | end |
| 782 | |
| 783 | note event_reader_decodes_and_consumes_records |
| 784 | kmi_smmu_init sm |
| 785 | if ne kmi_smmu_configure_linear sm uint 3 cd 4 KMI_SMMU_OK |
| 786 | ret 77 |
| 787 | end |
| 788 | put sm add KMI_SM_EV_BASE 56 or ulong KMI_EVENT_F_TRANSLATION shl ulong 3 32 |
| 789 | put sm add KMI_SM_EV_BASE 58 ulong 0x12345000 |
| 790 | put sm add KMI_SM_EV_BASE 60 or ulong KMI_EVENT_C_BAD_STE shl ulong 9 32 |
| 791 | put sm add KMI_SM_EV_BASE 0 or ulong KMI_EVENT_F_PERMISSION shl ulong 3 32 |
| 792 | put sm add KMI_SM_EV_BASE 2 ulong 0xdeadb000 |
| 793 | put sm KMI_SM_EVENTQ_CONS ulong 14 |
| 794 | put sm KMI_SM_EVENTQ_PROD ulong 0x11 |
| 795 | kmi_smmu_read_events sm ev_out 2 drain |
| 796 | if ne get drain 0 2 |
| 797 | ret 77 |
| 798 | end |
| 799 | if ne get drain 1 0 |
| 800 | ret 77 |
| 801 | end |
| 802 | if ne get ev_out 0 ulong KMI_EVENT_F_TRANSLATION |
| 803 | ret 78 |
| 804 | end |
| 805 | if ne get ev_out 1 3 |
| 806 | ret 78 |
| 807 | end |
| 808 | if ne get ev_out 2 0x12345000 |
| 809 | ret 78 |
| 810 | end |
| 811 | if ne get ev_out 3 ulong KMI_EVENT_C_BAD_STE |
| 812 | ret 78 |
| 813 | end |
| 814 | if ne get sm KMI_SM_EVENTQ_CONS 0x10 |
| 815 | ret 78 |
| 816 | end |
| 817 | kmi_smmu_read_events sm ev_out 2 drain |
| 818 | if ne get drain 0 1 |
| 819 | ret 79 |
| 820 | end |
| 821 | if ne get ev_out 0 ulong KMI_EVENT_F_PERMISSION |
| 822 | ret 79 |
| 823 | end |
| 824 | if ne get ev_out 2 0xdeadb000 |
| 825 | ret 79 |
| 826 | end |
| 827 | if ne get sm KMI_SM_EVENTQ_CONS 0x11 |
| 828 | ret 79 |
| 829 | end |
| 830 | |
| 831 | note event_reader_acknowledges_overflow |
| 832 | kmi_smmu_init sm |
| 833 | put sm KMI_SM_EVENTQ_PROD ulong KMI_EVENTQ_OVERFLOW |
| 834 | kmi_smmu_read_events sm ev_out 1 drain |
| 835 | if ne get drain 1 1 |
| 836 | ret 80 |
| 837 | end |
| 838 | if ne get sm KMI_SM_EVENTQ_CONS ulong KMI_EVENTQ_OVERFLOW |
| 839 | ret 80 |
| 840 | end |
| 841 | kmi_smmu_read_events sm ev_out 1 drain |
| 842 | if ne get drain 1 0 |
| 843 | ret 80 |
| 844 | end |
| 845 | |
| 846 | note policy_maps_only_allowed_windows |
| 847 | put wins 0 0x1000 |
| 848 | put wins 1 0x1000 |
| 849 | put wins 2 4096 |
| 850 | if ne kmi_smmu_validate_policy_windows wins KMI_SMMU_OK |
| 851 | ret 80 |
| 852 | end |
| 853 | put wins 0 0x2000 |
| 854 | if ne kmi_smmu_validate_policy_windows wins KMI_SMMU_ERR_INVALID_WINDOW |
| 855 | ret 80 |
| 856 | end |
| 857 | ret 0 |
| 858 | end |
| 859 | |
| 860 | note ======================================================================== |
| 861 | note 4. DMA Gate Tests (exit codes 81..100) |
| 862 | note ======================================================================== |
| 863 | |
| 864 | fn kmi_test_dma_gate to int |
| 865 | cfg = new uint 516 0 |
| 866 | sw = new ulong 40 0 |
| 867 | |
| 868 | note command_bits |
| 869 | if not kmi_bme_enabled ushort 0x0007 |
| 870 | ret 81 |
| 871 | end |
| 872 | if kmi_bme_enabled ushort 0x0003 |
| 873 | ret 81 |
| 874 | end |
| 875 | if ne kmi_without_bme ushort 0x0407 ushort 0x0403 |
| 876 | ret 82 |
| 877 | end |
| 878 | if ne kmi_with_bme ushort 0x0400 ushort 0x0406 |
| 879 | ret 82 |
| 880 | end |
| 881 | |
| 882 | note grant_requires_smmu_or_explicit_bypass_without_smmu |
| 883 | if ne kmi_dma_grant true true false KMI_DMA_GRANT_CONFINED |
| 884 | ret 83 |
| 885 | end |
| 886 | if ne kmi_dma_grant true true true KMI_DMA_GRANT_CONFINED |
| 887 | ret 83 |
| 888 | end |
| 889 | if ne kmi_dma_grant false false false KMI_DMA_DENIED_NO_SMMU |
| 890 | ret 84 |
| 891 | end |
| 892 | if ne kmi_dma_grant false false true KMI_DMA_GRANT_UNSAFE_BYPASS |
| 893 | ret 84 |
| 894 | end |
| 895 | |
| 896 | note failed_smmu_never_falls_back_to_bypass |
| 897 | if ne kmi_dma_grant false true false KMI_DMA_DENIED_SMMU_NOT_READY |
| 898 | ret 85 |
| 899 | end |
| 900 | if ne kmi_dma_grant false true true KMI_DMA_DENIED_SMMU_NOT_READY |
| 901 | ret 85 |
| 902 | end |
| 903 | |
| 904 | note sweep_clears_endpoints_and_leaves_bridges |
| 905 | kmi_pci_cfg_init cfg |
| 906 | i0 = kmi_pci_cfg_add cfg kmi_bdf_rid uchar 0 uchar 0 uchar 0 uint 0x00081b36 uchar 0 |
| 907 | kmi_pci_cfg_set_reg cfg ulong i0 1 uint 0x00100000 |
| 908 | i1 = kmi_pci_cfg_add cfg kmi_bdf_rid uchar 0 uchar 1 uchar 0 uint 0x10421af4 uchar 0 |
| 909 | kmi_pci_cfg_set_reg cfg ulong i1 1 uint 0x00100007 |
| 910 | i2 = kmi_pci_cfg_add cfg kmi_bdf_rid uchar 0 uchar 2 uchar 0 uint 0x000d1b36 uchar 0 |
| 911 | kmi_pci_cfg_set_reg cfg ulong i2 1 uint 0x00100002 |
| 912 | i3 = kmi_pci_cfg_add cfg kmi_bdf_rid uchar 0 uchar 3 uchar 0 uint 0x000c1b36 uchar 1 |
| 913 | kmi_pci_cfg_set_reg cfg ulong i3 1 uint 0x00100007 |
| 914 | i4 = kmi_pci_cfg_add cfg kmi_bdf_rid uchar 1 uchar 0 uchar 0 uint 0x1234abcd uchar 0 |
| 915 | kmi_pci_cfg_set_reg cfg ulong i4 1 uint 0x00100006 |
| 916 | kmi_sweep_bus_master cfg uchar 0 uchar 1 sw |
| 917 | if ne get sw 0 5 |
| 918 | ret 86 |
| 919 | end |
| 920 | if ne get sw 1 1 |
| 921 | ret 86 |
| 922 | end |
| 923 | if ne get sw 2 1 |
| 924 | ret 87 |
| 925 | end |
| 926 | if ne get sw 3 2 |
| 927 | ret 87 |
| 928 | end |
| 929 | if ne get sw 4 0 |
| 930 | ret 88 |
| 931 | end |
| 932 | if ne get sw 8 ulong kmi_bdf_rid uchar 0 uchar 1 uchar 0 |
| 933 | ret 89 |
| 934 | end |
| 935 | if ne get sw 9 0x0007 |
| 936 | ret 89 |
| 937 | end |
| 938 | if ne get sw 10 0x0003 |
| 939 | ret 89 |
| 940 | end |
| 941 | if ne get sw 12 ulong kmi_bdf_rid uchar 1 uchar 0 uchar 0 |
| 942 | ret 90 |
| 943 | end |
| 944 | if ne and kmi_pci_cfg_get_reg cfg ulong i1 1 0xffff 0x0003 |
| 945 | ret 91 |
| 946 | end |
| 947 | if ne and kmi_pci_cfg_get_reg cfg ulong i3 1 0xffff 0x0007 |
| 948 | ret 91 |
| 949 | end |
| 950 | if ne and kmi_pci_cfg_get_reg cfg ulong i2 1 0xffff 0x0002 |
| 951 | ret 91 |
| 952 | end |
| 953 | if ne get cfg 2 2 |
| 954 | ret 92 |
| 955 | end |
| 956 | |
| 957 | note sweep_reports_a_bus_master_bit_that_will_not_clear |
| 958 | kmi_pci_cfg_init cfg |
| 959 | i0 = kmi_pci_cfg_add cfg kmi_bdf_rid uchar 0 uchar 4 uchar 0 uint 0x5678abcd uchar 0 |
| 960 | kmi_pci_cfg_set_reg cfg ulong i0 1 uint 0x00100006 |
| 961 | kmi_pci_cfg_set_stuck cfg ulong i0 true |
| 962 | kmi_sweep_bus_master cfg uchar 0 uchar 0 sw |
| 963 | if ne get sw 3 1 |
| 964 | ret 93 |
| 965 | end |
| 966 | if ne get sw 4 1 |
| 967 | ret 93 |
| 968 | end |
| 969 | if ne get sw 11 0 |
| 970 | ret 94 |
| 971 | end |
| 972 | |
| 973 | note sweep_walks_multifunction_devices_only_when_marked |
| 974 | kmi_pci_cfg_init cfg |
| 975 | i0 = kmi_pci_cfg_add cfg kmi_bdf_rid uchar 0 uchar 5 uchar 0 uint 0x1111abcd uchar 0 |
| 976 | kmi_pci_cfg_set_reg cfg ulong i0 1 uint 0x0004 |
| 977 | i1 = kmi_pci_cfg_add cfg kmi_bdf_rid uchar 0 uchar 5 uchar 1 uint 0x2222abcd uchar 0 |
| 978 | kmi_pci_cfg_set_reg cfg ulong i1 1 uint 0x0004 |
| 979 | i2 = kmi_pci_cfg_add cfg kmi_bdf_rid uchar 0 uchar 6 uchar 0 uint 0x3333abcd uchar 0x80 |
| 980 | kmi_pci_cfg_set_reg cfg ulong i2 1 uint 0x0004 |
| 981 | i3 = kmi_pci_cfg_add cfg kmi_bdf_rid uchar 0 uchar 6 uchar 1 uint 0x4444abcd uchar 0 |
| 982 | kmi_pci_cfg_set_reg cfg ulong i3 1 uint 0x0004 |
| 983 | kmi_sweep_bus_master cfg uchar 0 uchar 0 sw |
| 984 | if ne get sw 0 3 |
| 985 | ret 95 |
| 986 | end |
| 987 | if ne get sw 3 3 |
| 988 | ret 95 |
| 989 | end |
| 990 | if ne and kmi_pci_cfg_get_reg cfg ulong i1 1 0xffff 0x0004 |
| 991 | ret 96 |
| 992 | end |
| 993 | |
| 994 | note sweep_keeps_counting_past_the_recorded_findings |
| 995 | kmi_pci_cfg_init cfg |
| 996 | for d ulong 12 |
| 997 | ix = kmi_pci_cfg_add cfg kmi_bdf_rid uchar 0 uchar and d 31 uchar 0 uint 0x9999abcd uchar 0 |
| 998 | kmi_pci_cfg_set_reg cfg ulong ix 1 uint 0x0004 |
| 999 | end |
| 1000 | kmi_sweep_bus_master cfg uchar 0 uchar 0 sw |
| 1001 | if ne get sw 3 12 |
| 1002 | ret 97 |
| 1003 | end |
| 1004 | if ne get sw 4 0 |
| 1005 | ret 98 |
| 1006 | end |
| 1007 | ret 0 |
| 1008 | end |
| 1009 | |
| 1010 | note ======================================================================== |
| 1011 | note 5. PCI Tests (exit codes 101..130) |
| 1012 | note ======================================================================== |
| 1013 | |
| 1014 | fn kmi_test_pci_bars to int |
| 1015 | cfg = new uint 516 0 |
| 1016 | fi = new uint 6 0 |
| 1017 | bar = new ulong 4 0 |
| 1018 | sz = new ulong 2 0 |
| 1019 | |
| 1020 | note decodes_32_and_64_bit_memory_bars_and_io_bars |
| 1021 | if ne kmi_pci_decode_bar uint 0xfe000000 false uint 0 bar KMI_BAR_OK |
| 1022 | ret 112 |
| 1023 | end |
| 1024 | if ne get bar 0 KMI_BAR_MEM32 |
| 1025 | ret 112 |
| 1026 | end |
| 1027 | if ne get bar 1 0xfe000000 |
| 1028 | ret 112 |
| 1029 | end |
| 1030 | if ne get bar 2 0 |
| 1031 | ret 112 |
| 1032 | end |
| 1033 | if ne kmi_pci_decode_bar uint 0x1000000c true uint 0x80 bar KMI_BAR_OK |
| 1034 | ret 113 |
| 1035 | end |
| 1036 | if ne get bar 0 KMI_BAR_MEM64 |
| 1037 | ret 113 |
| 1038 | end |
| 1039 | if ne get bar 1 0x8010000000 |
| 1040 | ret 113 |
| 1041 | end |
| 1042 | if ne get bar 2 1 |
| 1043 | ret 113 |
| 1044 | end |
| 1045 | if ne kmi_pci_decode_bar uint 0xc001 false uint 0 bar KMI_BAR_OK |
| 1046 | ret 114 |
| 1047 | end |
| 1048 | if ne get bar 0 KMI_BAR_IO |
| 1049 | ret 114 |
| 1050 | end |
| 1051 | if ne get bar 1 0xc000 |
| 1052 | ret 114 |
| 1053 | end |
| 1054 | if ne kmi_pci_decode_bar uint 0x4 false uint 0 bar KMI_BAR_ERR_MISSING_HIGH |
| 1055 | ret 115 |
| 1056 | end |
| 1057 | if ne kmi_pci_decode_bar uint 0x6 true uint 0 bar KMI_BAR_ERR_RESERVED |
| 1058 | ret 115 |
| 1059 | end |
| 1060 | if ne kmi_pci_decode_bar uint 0x2 false uint 0 bar KMI_BAR_ERR_RESERVED |
| 1061 | ret 115 |
| 1062 | end |
| 1063 | |
| 1064 | note read_bar_respects_header_type_and_slots |
| 1065 | kmi_pci_cfg_init cfg |
| 1066 | rid2 = kmi_bdf_rid uchar 0 uchar 2 uchar 0 |
| 1067 | rid3 = kmi_bdf_rid uchar 0 uchar 3 uchar 0 |
| 1068 | i0 = kmi_pci_cfg_add cfg rid2 uint 0x11e81234 uchar 0 |
| 1069 | kmi_pci_cfg_set_reg cfg ulong i0 4 uint 0x10000000 |
| 1070 | kmi_pci_cfg_set_reg cfg ulong i0 5 uint 0x20000004 |
| 1071 | kmi_pci_cfg_set_reg cfg ulong i0 6 uint 0x00000001 |
| 1072 | kmi_pci_cfg_set_reg cfg ulong i0 9 uint 0x00000004 |
| 1073 | i1 = kmi_pci_cfg_add cfg rid3 uint 0x00011b36 uchar 1 |
| 1074 | kmi_pci_cfg_set_reg cfg ulong i1 4 uint 0x30000000 |
| 1075 | if not kmi_pci_read_fn cfg rid2 fi |
| 1076 | ret 116 |
| 1077 | end |
| 1078 | if ne kmi_pci_read_bar cfg fi uchar 0 bar KMI_BAR_OK |
| 1079 | ret 116 |
| 1080 | end |
| 1081 | if ne get bar 1 0x10000000 |
| 1082 | ret 116 |
| 1083 | end |
| 1084 | if ne kmi_pci_read_bar cfg fi uchar 1 bar KMI_BAR_OK |
| 1085 | ret 117 |
| 1086 | end |
| 1087 | if ne get bar 3 1 |
| 1088 | ret 117 |
| 1089 | end |
| 1090 | if ne get bar 1 0x120000000 |
| 1091 | ret 117 |
| 1092 | end |
| 1093 | if ne kmi_pci_read_bar cfg fi uchar 5 bar KMI_BAR_ERR_MISSING_HIGH |
| 1094 | ret 118 |
| 1095 | end |
| 1096 | if ne kmi_pci_read_bar cfg fi uchar 6 bar KMI_BAR_ERR_NO_SUCH |
| 1097 | ret 118 |
| 1098 | end |
| 1099 | if not kmi_pci_read_fn cfg rid3 fi |
| 1100 | ret 119 |
| 1101 | end |
| 1102 | if ne kmi_pci_read_bar cfg fi uchar 0 bar KMI_BAR_OK |
| 1103 | ret 119 |
| 1104 | end |
| 1105 | if ne get bar 1 0x30000000 |
| 1106 | ret 119 |
| 1107 | end |
| 1108 | if ne kmi_pci_read_bar cfg fi uchar 2 bar KMI_BAR_ERR_NO_SUCH |
| 1109 | ret 119 |
| 1110 | end |
| 1111 | |
| 1112 | note probes_bar_sizes_and_restores_state |
| 1113 | kmi_pci_cfg_init cfg |
| 1114 | i0 = kmi_pci_cfg_add cfg rid2 uint 0x11e81234 uchar 0 |
| 1115 | kmi_pci_cfg_set_reg cfg ulong i0 1 uint or KMI_PCI_CMD_MEMORY KMI_PCI_CMD_BUS_MASTER |
| 1116 | kmi_pci_cfg_set_reg cfg ulong i0 4 uint 0x10000000 |
| 1117 | kmi_pci_cfg_set_reg cfg ulong i0 5 uint 0x0000000c |
| 1118 | kmi_pci_cfg_set_reg cfg ulong i0 6 uint 0x00000080 |
| 1119 | kmi_pci_cfg_set_bar_mask cfg ulong i0 0 uint 0xfff00000 |
| 1120 | kmi_pci_cfg_set_bar_mask cfg ulong i0 1 uint 0xffffc000 |
| 1121 | kmi_pci_cfg_set_bar_mask cfg ulong i0 2 uint 0xffffffff |
| 1122 | kmi_pci_cfg_set_bar_mask cfg ulong i0 3 uint 0 |
| 1123 | if not kmi_pci_read_fn cfg rid2 fi |
| 1124 | ret 120 |
| 1125 | end |
| 1126 | if ne kmi_pci_probe_bar_size cfg fi uchar 0 sz KMI_BAR_OK |
| 1127 | ret 120 |
| 1128 | end |
| 1129 | if ne get sz 0 1 |
| 1130 | ret 120 |
| 1131 | end |
| 1132 | if ne get sz 1 0x100000 |
| 1133 | ret 120 |
| 1134 | end |
| 1135 | if ne kmi_pci_probe_bar_size cfg fi uchar 1 sz KMI_BAR_OK |
| 1136 | ret 121 |
| 1137 | end |
| 1138 | if ne get sz 0 1 |
| 1139 | ret 121 |
| 1140 | end |
| 1141 | if ne get sz 1 16384 |
| 1142 | ret 121 |
| 1143 | end |
| 1144 | if ne kmi_pci_probe_bar_size cfg fi uchar 3 sz KMI_BAR_OK |
| 1145 | ret 122 |
| 1146 | end |
| 1147 | if ne get sz 0 0 |
| 1148 | ret 122 |
| 1149 | end |
| 1150 | if ne kmi_pci_cfg_get_reg cfg ulong i0 4 0x10000000 |
| 1151 | ret 123 |
| 1152 | end |
| 1153 | if ne kmi_pci_cfg_get_reg cfg ulong i0 5 0x0000000c |
| 1154 | ret 123 |
| 1155 | end |
| 1156 | if ne kmi_pci_cfg_get_reg cfg ulong i0 6 0x00000080 |
| 1157 | ret 123 |
| 1158 | end |
| 1159 | if ne and kmi_pci_cfg_get_reg cfg ulong i0 1 0xffff uint or KMI_PCI_CMD_MEMORY KMI_PCI_CMD_BUS_MASTER |
| 1160 | ret 124 |
| 1161 | end |
| 1162 | |
| 1163 | note update_command_sets_and_clears_bits_without_touching_status |
| 1164 | kmi_pci_cfg_init cfg |
| 1165 | i0 = kmi_pci_cfg_add cfg rid2 uint 0x11e81234 uchar 0 |
| 1166 | st_bits = or shl uint 1 13 shl uint 1 4 |
| 1167 | kmi_pci_cfg_set_reg cfg ulong i0 1 or shl st_bits 16 shl uint 1 10 |
| 1168 | on_v = kmi_pci_update_cmd cfg rid2 or KMI_PCI_CMD_MEMORY KMI_PCI_CMD_BUS_MASTER ushort 0 |
| 1169 | if ne on_v or shl ushort 1 10 or KMI_PCI_CMD_MEMORY KMI_PCI_CMD_BUS_MASTER |
| 1170 | ret 125 |
| 1171 | end |
| 1172 | off_v = kmi_pci_update_cmd cfg rid2 ushort 0 KMI_PCI_CMD_BUS_MASTER |
| 1173 | if ne off_v or shl ushort 1 10 KMI_PCI_CMD_MEMORY |
| 1174 | ret 126 |
| 1175 | end |
| 1176 | if ne shr kmi_pci_cfg_get_reg cfg ulong i0 1 16 st_bits |
| 1177 | ret 127 |
| 1178 | end |
| 1179 | ret 0 |
| 1180 | end |
| 1181 | |
| 1182 | fn kmi_test_pci to int |
| 1183 | cfg = new uint 516 0 |
| 1184 | fi = new uint 6 0 |
| 1185 | found = new uint 60 0 |
| 1186 | |
| 1187 | note requester_id_packs_bus_device_function |
| 1188 | if ne kmi_bdf_rid uchar 0 uchar 0 uchar 0 0 |
| 1189 | ret 101 |
| 1190 | end |
| 1191 | if ne kmi_bdf_rid uchar 0 uchar 2 uchar 0 0x10 |
| 1192 | ret 101 |
| 1193 | end |
| 1194 | if ne kmi_bdf_rid uchar 1 uchar 3 uchar 5 0x11d |
| 1195 | ret 102 |
| 1196 | end |
| 1197 | if ne kmi_bdf_rid uchar 255 uchar 31 uchar 7 0xffff |
| 1198 | ret 102 |
| 1199 | end |
| 1200 | if kmi_bdf_valid uchar 32 uchar 0 |
| 1201 | ret 103 |
| 1202 | end |
| 1203 | if kmi_bdf_valid uchar 0 uchar 8 |
| 1204 | ret 103 |
| 1205 | end |
| 1206 | |
| 1207 | note finds_device_by_vendor_and_device_id |
| 1208 | kmi_pci_cfg_init cfg |
| 1209 | i0 = kmi_pci_cfg_add cfg kmi_bdf_rid uchar 0 uchar 0 uchar 0 uint 0x00081b36 uchar 0 |
| 1210 | i0 = kmi_pci_cfg_add cfg kmi_bdf_rid uchar 0 uchar 1 uchar 0 uint 0x10001af4 uchar 0 |
| 1211 | i0 = kmi_pci_cfg_add cfg kmi_bdf_rid uchar 0 uchar 3 uchar 0 uint 0x11e81234 uchar 0 |
| 1212 | kmi_pci_cfg_set_reg cfg ulong i0 2 uint 0x00ff0010 |
| 1213 | if not kmi_pci_find_device cfg uchar 0 uchar 0 uint 0x11e81234 fi |
| 1214 | ret 104 |
| 1215 | end |
| 1216 | if ne get fi 0 0x18 |
| 1217 | ret 105 |
| 1218 | end |
| 1219 | if ne get fi 3 0 |
| 1220 | ret 105 |
| 1221 | end |
| 1222 | if ne get fi 4 0 |
| 1223 | ret 105 |
| 1224 | end |
| 1225 | if ne get fi 5 0x00ff0010 |
| 1226 | ret 105 |
| 1227 | end |
| 1228 | if kmi_pci_find_device cfg uchar 0 uchar 0 uint 0x00011234 fi |
| 1229 | ret 106 |
| 1230 | end |
| 1231 | |
| 1232 | note walk_skips_functions_1_to_7_unless_multi_function |
| 1233 | kmi_pci_cfg_init cfg |
| 1234 | i0 = kmi_pci_cfg_add cfg kmi_bdf_rid uchar 0 uchar 1 uchar 0 uint 0x00011111 uchar 0 |
| 1235 | i0 = kmi_pci_cfg_add cfg kmi_bdf_rid uchar 0 uchar 1 uchar 2 uint 0x00021111 uchar 0 |
| 1236 | i0 = kmi_pci_cfg_add cfg kmi_bdf_rid uchar 0 uchar 4 uchar 0 uint 0x00012222 uchar 0x80 |
| 1237 | i0 = kmi_pci_cfg_add cfg kmi_bdf_rid uchar 0 uchar 4 uchar 2 uint 0x00022222 uchar 0 |
| 1238 | i0 = kmi_pci_cfg_add cfg kmi_bdf_rid uchar 0 uchar 4 uchar 7 uint 0x00032222 uchar 0 |
| 1239 | i0 = kmi_pci_cfg_add cfg kmi_bdf_rid uchar 0 uchar 6 uchar 1 uint 0x00013333 uchar 0 |
| 1240 | i0 = kmi_pci_cfg_add cfg kmi_bdf_rid uchar 2 uchar 0 uchar 0 uint 0x00014444 uchar 1 |
| 1241 | cnt = kmi_pci_walk cfg uchar 0 uchar 2 found |
| 1242 | if ne cnt 5 |
| 1243 | ret 107 |
| 1244 | end |
| 1245 | if ne get found 0 kmi_bdf_rid uchar 0 uchar 1 uchar 0 |
| 1246 | ret 108 |
| 1247 | end |
| 1248 | if ne get found 6 kmi_bdf_rid uchar 0 uchar 4 uchar 0 |
| 1249 | ret 108 |
| 1250 | end |
| 1251 | if ne get found 12 kmi_bdf_rid uchar 0 uchar 4 uchar 2 |
| 1252 | ret 108 |
| 1253 | end |
| 1254 | if ne get found 18 kmi_bdf_rid uchar 0 uchar 4 uchar 7 |
| 1255 | ret 108 |
| 1256 | end |
| 1257 | if ne get found 24 kmi_bdf_rid uchar 2 uchar 0 uchar 0 |
| 1258 | ret 108 |
| 1259 | end |
| 1260 | if ne kmi_pci_walk cfg uchar 0 uchar 1 found 4 |
| 1261 | ret 109 |
| 1262 | end |
| 1263 | |
| 1264 | note walk_covers_last_bus_and_device_without_overflow |
| 1265 | kmi_pci_cfg_init cfg |
| 1266 | i0 = kmi_pci_cfg_add cfg kmi_bdf_rid uchar 255 uchar 31 uchar 0 uint 0x00015555 uchar 0x80 |
| 1267 | i0 = kmi_pci_cfg_add cfg kmi_bdf_rid uchar 255 uchar 31 uchar 7 uint 0x00025555 uchar 0 |
| 1268 | if ne kmi_pci_walk cfg uchar 255 uchar 255 found 2 |
| 1269 | ret 110 |
| 1270 | end |
| 1271 | put cfg 1 uint 0 |
| 1272 | if ne kmi_pci_walk cfg uchar 5 uchar 4 found 0 |
| 1273 | ret 111 |
| 1274 | end |
| 1275 | if ne get cfg 1 0 |
| 1276 | ret 111 |
| 1277 | end |
| 1278 | ret kmi_test_pci_bars |
| 1279 | end |
| 1280 | |
| 1281 | note ======================================================================== |
| 1282 | note 6. Device Registry and Authority Tests (exit codes 131..195) |
| 1283 | note ======================================================================== |
| 1284 | |
| 1285 | fn kmi_setup_std_device dtab edit ulong 128 to void |
| 1286 | spec = new ulong 8 0 |
| 1287 | kmi_dtab_init dtab 4 |
| 1288 | put spec 0 0x100 |
| 1289 | put spec 1 3 |
| 1290 | put spec 2 0x10 |
| 1291 | put spec 3 0x10 |
| 1292 | put spec 4 KMI_DMA_QUIESCED |
| 1293 | put spec 5 0 |
| 1294 | put spec 6 0 |
| 1295 | put spec 7 0 |
| 1296 | ign = kmi_dtab_register dtab spec |
| 1297 | ign2 = kmi_dtab_set_window dtab 0x100 0x40000000 uint 4 |
| 1298 | end |
| 1299 | |
| 1300 | fn kmi_dev_state dtab view ulong 128 res ulong to ulong |
| 1301 | idx = kmi_dtab_find dtab res |
| 1302 | if lt idx 0 |
| 1303 | ret 99 |
| 1304 | end |
| 1305 | off = add 4 mul ulong idx 12 |
| 1306 | ret get dtab add off 5 |
| 1307 | end |
| 1308 | |
| 1309 | fn kmi_check_teardown_effects hw view ulong 128 start_idx ulong to bool |
| 1310 | if lt get hw 0 add start_idx 5 |
| 1311 | ret false |
| 1312 | end |
| 1313 | o0 = add 8 mul start_idx 3 |
| 1314 | if ne get hw o0 KMI_EFF_STOP_WORK |
| 1315 | ret false |
| 1316 | end |
| 1317 | if ne get hw add o0 3 KMI_EFF_BME_OFF |
| 1318 | ret false |
| 1319 | end |
| 1320 | if ne get hw add o0 6 KMI_EFF_QUIESCE |
| 1321 | ret false |
| 1322 | end |
| 1323 | if ne get hw add o0 9 KMI_EFF_ABORT |
| 1324 | ret false |
| 1325 | end |
| 1326 | if ne get hw add o0 12 KMI_EFF_INVALIDATE |
| 1327 | ret false |
| 1328 | end |
| 1329 | ret true |
| 1330 | end |
| 1331 | |
| 1332 | fn kmi_test_device_1 to int |
| 1333 | c0 = new ulong 64 0 |
| 1334 | c1 = new ulong 64 0 |
| 1335 | dtab = new ulong 128 0 |
| 1336 | hw = new ulong 128 0 |
| 1337 | h0 = new ulong 1 0 |
| 1338 | h1 = new ulong 1 0 |
| 1339 | res_b = new ulong 1 0 |
| 1340 | req = new ulong 3 0 |
| 1341 | |
| 1342 | note activate_installs_translation_before_bus_master |
| 1343 | kmi_cap_init c0 1 4 |
| 1344 | ign = kmi_cap_insert c0 0x100 KMI_RIGHT_MAP h0 |
| 1345 | kmi_setup_std_device dtab |
| 1346 | kmi_hw_init hw KMI_HW_NONE |
| 1347 | if ne kmi_dev_activate c0 get h0 0 dtab hw KMI_DEV_OK |
| 1348 | ret 131 |
| 1349 | end |
| 1350 | if ne get hw 0 2 |
| 1351 | ret 132 |
| 1352 | end |
| 1353 | if ne get hw 8 KMI_EFF_INSTALL |
| 1354 | ret 132 |
| 1355 | end |
| 1356 | if ne get hw 11 KMI_EFF_BME_ON |
| 1357 | ret 132 |
| 1358 | end |
| 1359 | if ne kmi_dev_state dtab 0x100 KMI_DMA_ACTIVE |
| 1360 | ret 133 |
| 1361 | end |
| 1362 | |
| 1363 | note revoke_runs_exact_teardown_then_removes_capability_tree |
| 1364 | kmi_cap_init c0 1 4 |
| 1365 | kmi_cap_init c1 2 4 |
| 1366 | ign = kmi_cap_insert c0 0x100 KMI_RIGHT_ALL h0 |
| 1367 | if ne kmi_cap_derive_into c0 get h0 0 c1 KMI_RIGHT_MAP h1 KMI_DEV_OK |
| 1368 | ret 134 |
| 1369 | end |
| 1370 | kmi_setup_std_device dtab |
| 1371 | kmi_hw_init hw KMI_HW_NONE |
| 1372 | if ne kmi_dev_activate c1 get h1 0 dtab hw KMI_DEV_OK |
| 1373 | ret 134 |
| 1374 | end |
| 1375 | kmi_hw_clear_effects hw |
| 1376 | put req 0 1 |
| 1377 | put req 1 get h0 0 |
| 1378 | put req 2 1 |
| 1379 | if ne kmi_dev_revoke req c0 c1 dtab hw KMI_DEV_OK |
| 1380 | ret 135 |
| 1381 | end |
| 1382 | if not kmi_check_teardown_effects hw 0 |
| 1383 | ret 136 |
| 1384 | end |
| 1385 | if ne kmi_dev_state dtab 0x100 KMI_DMA_QUIESCED |
| 1386 | ret 137 |
| 1387 | end |
| 1388 | if ne kmi_cap_lookup c0 get h0 0 KMI_RIGHT_NONE res_b KMI_DEV_ERR_CAP_INVALID |
| 1389 | ret 138 |
| 1390 | end |
| 1391 | if ne kmi_cap_lookup c1 get h1 0 KMI_RIGHT_NONE res_b KMI_DEV_ERR_CAP_INVALID |
| 1392 | ret 138 |
| 1393 | end |
| 1394 | |
| 1395 | note activate_with_revoked_handle_fails_without_effects |
| 1396 | kmi_hw_clear_effects hw |
| 1397 | if ne kmi_dev_activate c0 get h0 0 dtab hw KMI_DEV_ERR_CAP_INVALID |
| 1398 | ret 139 |
| 1399 | end |
| 1400 | if ne get hw 0 0 |
| 1401 | ret 139 |
| 1402 | end |
| 1403 | |
| 1404 | note missing_capability_causes_no_effects |
| 1405 | kmi_cap_init c0 1 4 |
| 1406 | kmi_setup_std_device dtab |
| 1407 | kmi_hw_init hw KMI_HW_NONE |
| 1408 | bogus = kmi_cap_pack_handle 0 1 |
| 1409 | if ne kmi_dev_activate c0 bogus dtab hw KMI_DEV_ERR_CAP_INVALID |
| 1410 | ret 140 |
| 1411 | end |
| 1412 | put req 0 1 |
| 1413 | put req 1 bogus |
| 1414 | put req 2 0 |
| 1415 | if ne kmi_dev_revoke req c0 c1 dtab hw KMI_DEV_ERR_CAP_INVALID |
| 1416 | ret 140 |
| 1417 | end |
| 1418 | if ne get hw 0 0 |
| 1419 | ret 141 |
| 1420 | end |
| 1421 | |
| 1422 | note read_only_capability_causes_no_effects |
| 1423 | kmi_cap_init c0 1 4 |
| 1424 | ign = kmi_cap_insert c0 0x100 KMI_RIGHT_READ h0 |
| 1425 | if ne kmi_dev_activate c0 get h0 0 dtab hw KMI_DEV_ERR_CAP_RIGHTS |
| 1426 | ret 142 |
| 1427 | end |
| 1428 | put req 1 get h0 0 |
| 1429 | if ne kmi_dev_revoke req c0 c1 dtab hw KMI_DEV_ERR_CAP_RIGHTS |
| 1430 | ret 142 |
| 1431 | end |
| 1432 | if ne get hw 0 0 |
| 1433 | ret 143 |
| 1434 | end |
| 1435 | |
| 1436 | note map_without_revoke_cannot_tear_down_an_active_device |
| 1437 | kmi_cap_init c0 1 4 |
| 1438 | ign = kmi_cap_insert c0 0x100 KMI_RIGHT_MAP h0 |
| 1439 | kmi_setup_std_device dtab |
| 1440 | kmi_hw_init hw KMI_HW_NONE |
| 1441 | if ne kmi_dev_activate c0 get h0 0 dtab hw KMI_DEV_OK |
| 1442 | ret 144 |
| 1443 | end |
| 1444 | kmi_hw_clear_effects hw |
| 1445 | put req 1 get h0 0 |
| 1446 | if ne kmi_dev_revoke req c0 c1 dtab hw KMI_DEV_ERR_CAP_RIGHTS |
| 1447 | ret 144 |
| 1448 | end |
| 1449 | if ne get hw 0 0 |
| 1450 | ret 145 |
| 1451 | end |
| 1452 | if ne kmi_dev_state dtab 0x100 KMI_DMA_ACTIVE |
| 1453 | ret 145 |
| 1454 | end |
| 1455 | |
| 1456 | note capability_for_other_resource_is_not_a_device |
| 1457 | kmi_cap_init c0 1 4 |
| 1458 | ign = kmi_cap_insert c0 1 KMI_RIGHT_ALL h0 |
| 1459 | kmi_setup_std_device dtab |
| 1460 | kmi_hw_init hw KMI_HW_NONE |
| 1461 | if ne kmi_dev_activate c0 get h0 0 dtab hw KMI_DEV_ERR_NOT_DEVICE |
| 1462 | ret 146 |
| 1463 | end |
| 1464 | put req 1 get h0 0 |
| 1465 | if ne kmi_dev_revoke req c0 c1 dtab hw KMI_DEV_ERR_NOT_DEVICE |
| 1466 | ret 146 |
| 1467 | end |
| 1468 | if ne get hw 0 0 |
| 1469 | ret 147 |
| 1470 | end |
| 1471 | |
| 1472 | note activation_refused_without_window_or_when_already_active |
| 1473 | kmi_cap_init c0 1 4 |
| 1474 | ign = kmi_cap_insert c0 0x100 KMI_RIGHT_MAP h0 |
| 1475 | spec = new ulong 8 0 |
| 1476 | kmi_dtab_init dtab 4 |
| 1477 | put spec 0 0x100 |
| 1478 | put spec 1 3 |
| 1479 | put spec 2 0x10 |
| 1480 | put spec 3 0x10 |
| 1481 | put spec 4 KMI_DMA_QUIESCED |
| 1482 | ign2 = kmi_dtab_register dtab spec |
| 1483 | kmi_hw_init hw KMI_HW_NONE |
| 1484 | if ne kmi_dev_activate c0 get h0 0 dtab hw KMI_DEV_ERR_NO_WINDOW |
| 1485 | ret 148 |
| 1486 | end |
| 1487 | if ne get hw 0 0 |
| 1488 | ret 148 |
| 1489 | end |
| 1490 | if ne kmi_dtab_set_window dtab 0x100 0x40000000 uint 4 KMI_DEV_OK |
| 1491 | ret 149 |
| 1492 | end |
| 1493 | if ne kmi_dev_activate c0 get h0 0 dtab hw KMI_DEV_OK |
| 1494 | ret 149 |
| 1495 | end |
| 1496 | kmi_hw_clear_effects hw |
| 1497 | if ne kmi_dev_activate c0 get h0 0 dtab hw KMI_DEV_ERR_WRONG_STATE |
| 1498 | ret 150 |
| 1499 | end |
| 1500 | if ne kmi_dtab_set_window dtab 0x100 0x40000000 uint 4 KMI_DEV_ERR_WRONG_STATE |
| 1501 | ret 150 |
| 1502 | end |
| 1503 | if ne get hw 0 0 |
| 1504 | ret 150 |
| 1505 | end |
| 1506 | ret 0 |
| 1507 | end |
| 1508 | |
| 1509 | fn kmi_test_device_reg_sweep to int |
| 1510 | c0 = new ulong 64 0 |
| 1511 | c1 = new ulong 64 0 |
| 1512 | dtab = new ulong 128 0 |
| 1513 | hw = new ulong 128 0 |
| 1514 | h0 = new ulong 1 0 |
| 1515 | h1 = new ulong 1 0 |
| 1516 | spec = new ulong 8 0 |
| 1517 | |
| 1518 | note register_rejects_clashes_and_live_devices and window_validation |
| 1519 | kmi_dtab_init dtab 2 |
| 1520 | put spec 0 0x100 |
| 1521 | put spec 1 3 |
| 1522 | put spec 2 0x10 |
| 1523 | put spec 3 0x10 |
| 1524 | put spec 4 KMI_DMA_QUIESCED |
| 1525 | put spec 5 0 |
| 1526 | if ne kmi_dtab_register dtab spec KMI_DEV_OK |
| 1527 | ret 172 |
| 1528 | end |
| 1529 | put spec 1 9 |
| 1530 | put spec 2 1 |
| 1531 | put spec 3 99 |
| 1532 | if ne kmi_dtab_register dtab spec KMI_DEV_ERR_DUPLICATE |
| 1533 | ret 172 |
| 1534 | end |
| 1535 | put spec 0 7 |
| 1536 | put spec 1 3 |
| 1537 | if ne kmi_dtab_register dtab spec KMI_DEV_ERR_DUPLICATE |
| 1538 | ret 173 |
| 1539 | end |
| 1540 | put spec 1 9 |
| 1541 | put spec 2 0x10 |
| 1542 | if ne kmi_dtab_register dtab spec KMI_DEV_ERR_DUPLICATE |
| 1543 | ret 173 |
| 1544 | end |
| 1545 | put spec 2 1 |
| 1546 | put spec 3 0x10 |
| 1547 | if ne kmi_dtab_register dtab spec KMI_DEV_ERR_DUPLICATE |
| 1548 | ret 173 |
| 1549 | end |
| 1550 | put spec 3 99 |
| 1551 | put spec 5 1 |
| 1552 | put spec 6 1 |
| 1553 | put spec 7 1 |
| 1554 | if ne kmi_dtab_register dtab spec KMI_DEV_ERR_BAD_WINDOW |
| 1555 | ret 174 |
| 1556 | end |
| 1557 | put spec 5 0 |
| 1558 | put spec 4 KMI_DMA_ACTIVE |
| 1559 | if ne kmi_dtab_register dtab spec KMI_DEV_ERR_WRONG_STATE |
| 1560 | ret 174 |
| 1561 | end |
| 1562 | put spec 4 KMI_DMA_QUIESCED |
| 1563 | if ne kmi_dtab_register dtab spec KMI_DEV_OK |
| 1564 | ret 175 |
| 1565 | end |
| 1566 | put spec 0 8 |
| 1567 | put spec 1 10 |
| 1568 | put spec 2 2 |
| 1569 | put spec 3 100 |
| 1570 | if ne kmi_dtab_register dtab spec KMI_DEV_ERR_FULL |
| 1571 | ret 175 |
| 1572 | end |
| 1573 | if ne kmi_dtab_set_window dtab 0x100 0x1000 uint 0 KMI_DEV_ERR_BAD_WINDOW |
| 1574 | ret 176 |
| 1575 | end |
| 1576 | if ne kmi_dtab_set_window dtab 0x100 0x1001 uint 1 KMI_DEV_ERR_BAD_WINDOW |
| 1577 | ret 176 |
| 1578 | end |
| 1579 | if ne kmi_dtab_set_window dtab 0x100 0xfffffffffffff000 uint 2 KMI_DEV_ERR_BAD_WINDOW |
| 1580 | ret 176 |
| 1581 | end |
| 1582 | if ne kmi_dtab_set_window dtab 0x999 0x40000000 uint 4 KMI_DEV_ERR_NOT_DEVICE |
| 1583 | ret 177 |
| 1584 | end |
| 1585 | |
| 1586 | note sweep_leaves_live_alone, tears_down_ancestor_revoked, removed_reused, table_gone |
| 1587 | kmi_cap_init c0 1 4 |
| 1588 | kmi_cap_init c1 2 4 |
| 1589 | ign = kmi_cap_insert c0 0x100 KMI_RIGHT_ALL h0 |
| 1590 | ign_i = kmi_cap_derive_into c0 get h0 0 c1 KMI_RIGHT_MAP h1 |
| 1591 | kmi_setup_std_device dtab |
| 1592 | kmi_hw_init hw KMI_HW_NONE |
| 1593 | ign_i = kmi_dev_activate c1 get h1 0 dtab hw |
| 1594 | kmi_hw_clear_effects hw |
| 1595 | if ne kmi_dtab_sweep dtab 2 c0 c1 hw KMI_DEV_OK |
| 1596 | ret 178 |
| 1597 | end |
| 1598 | if ne get hw 0 0 |
| 1599 | ret 178 |
| 1600 | end |
| 1601 | if ne kmi_dev_state dtab 0x100 KMI_DMA_ACTIVE |
| 1602 | ret 178 |
| 1603 | end |
| 1604 | ign_i = kmi_cap_revoke2 1 get h0 0 c0 c1 true |
| 1605 | if ne kmi_dtab_sweep dtab 2 c0 c1 hw KMI_DEV_OK |
| 1606 | ret 179 |
| 1607 | end |
| 1608 | if not kmi_check_teardown_effects hw 0 |
| 1609 | ret 179 |
| 1610 | end |
| 1611 | if ne kmi_dev_state dtab 0x100 KMI_DMA_QUIESCED |
| 1612 | ret 179 |
| 1613 | end |
| 1614 | |
| 1615 | note slot reuse generation check + table gone |
| 1616 | kmi_cap_init c0 1 1 |
| 1617 | ign = kmi_cap_insert c0 0x100 KMI_RIGHT_MAP h0 |
| 1618 | kmi_setup_std_device dtab |
| 1619 | kmi_hw_init hw KMI_HW_NONE |
| 1620 | ign_i = kmi_dev_activate c0 get h0 0 dtab hw |
| 1621 | ign = kmi_cap_remove c0 get h0 0 |
| 1622 | ign = kmi_cap_insert c0 0x100 KMI_RIGHT_MAP h1 |
| 1623 | kmi_hw_clear_effects hw |
| 1624 | if ne kmi_dtab_sweep dtab 1 c0 c1 hw KMI_DEV_OK |
| 1625 | ret 180 |
| 1626 | end |
| 1627 | if not kmi_check_teardown_effects hw 0 |
| 1628 | ret 180 |
| 1629 | end |
| 1630 | if ne kmi_dev_state dtab 0x100 KMI_DMA_QUIESCED |
| 1631 | ret 180 |
| 1632 | end |
| 1633 | ign_i = kmi_dtab_set_window dtab 0x100 0x40000000 uint 4 |
| 1634 | ign_i = kmi_dev_activate c0 get h1 0 dtab hw |
| 1635 | kmi_hw_clear_effects hw |
| 1636 | if ne kmi_dtab_sweep dtab 0 c0 c1 hw KMI_DEV_OK |
| 1637 | ret 181 |
| 1638 | end |
| 1639 | if ne kmi_dev_state dtab 0x100 KMI_DMA_QUIESCED |
| 1640 | ret 181 |
| 1641 | end |
| 1642 | |
| 1643 | note state_discriminants_are_stable |
| 1644 | if ne KMI_DMA_QUIESCED 0 |
| 1645 | ret 182 |
| 1646 | end |
| 1647 | if ne KMI_DMA_TRANSLATION_INSTALLED 1 |
| 1648 | ret 182 |
| 1649 | end |
| 1650 | if ne KMI_DMA_ACTIVE 2 |
| 1651 | ret 182 |
| 1652 | end |
| 1653 | if ne KMI_DMA_REVOKING 3 |
| 1654 | ret 182 |
| 1655 | end |
| 1656 | ret 0 |
| 1657 | end |
| 1658 | |
| 1659 | fn kmi_test_device_2 to int |
| 1660 | c0 = new ulong 64 0 |
| 1661 | c1 = new ulong 64 0 |
| 1662 | dtab = new ulong 128 0 |
| 1663 | hw = new ulong 128 0 |
| 1664 | h0 = new ulong 1 0 |
| 1665 | h1 = new ulong 1 0 |
| 1666 | res_b = new ulong 1 0 |
| 1667 | req = new ulong 3 0 |
| 1668 | |
| 1669 | note activation_failure_at_each_step |
| 1670 | for stp ulong 2 |
| 1671 | fstep = add stp 1 |
| 1672 | kmi_cap_init c0 1 4 |
| 1673 | ign = kmi_cap_insert c0 0x100 KMI_RIGHT_MAP h0 |
| 1674 | kmi_setup_std_device dtab |
| 1675 | kmi_hw_init hw fstep |
| 1676 | if ne kmi_dev_activate c0 get h0 0 dtab hw KMI_DEV_ERR_HARDWARE |
| 1677 | ret 161 |
| 1678 | end |
| 1679 | if ne get hw 4 fstep |
| 1680 | ret 161 |
| 1681 | end |
| 1682 | if ne get hw 2 0 |
| 1683 | ret 162 |
| 1684 | end |
| 1685 | if ne get hw 3 1 |
| 1686 | ret 162 |
| 1687 | end |
| 1688 | if ne kmi_dev_state dtab 0x100 KMI_DMA_QUIESCED |
| 1689 | ret 162 |
| 1690 | end |
| 1691 | end |
| 1692 | |
| 1693 | note failed_teardown_blocks_activation_until_a_clean_retry |
| 1694 | kmi_cap_init c0 1 4 |
| 1695 | ign = kmi_cap_insert c0 0x100 KMI_RIGHT_ALL h0 |
| 1696 | kmi_setup_std_device dtab |
| 1697 | kmi_hw_init hw KMI_HW_QUIESCE |
| 1698 | if ne kmi_dev_activate c0 get h0 0 dtab hw KMI_DEV_OK |
| 1699 | ret 163 |
| 1700 | end |
| 1701 | put req 0 1 |
| 1702 | put req 1 get h0 0 |
| 1703 | put req 2 0 |
| 1704 | if ne kmi_dev_revoke req c0 c1 dtab hw KMI_DEV_ERR_HARDWARE |
| 1705 | ret 164 |
| 1706 | end |
| 1707 | if ne kmi_dev_state dtab 0x100 KMI_DMA_REVOKING |
| 1708 | ret 164 |
| 1709 | end |
| 1710 | ign = kmi_cap_insert c0 0x100 KMI_RIGHT_MAP h1 |
| 1711 | kmi_hw_clear_effects hw |
| 1712 | if ne kmi_dev_activate c0 get h1 0 dtab hw KMI_DEV_ERR_WRONG_STATE |
| 1713 | ret 165 |
| 1714 | end |
| 1715 | if ne get hw 0 0 |
| 1716 | ret 165 |
| 1717 | end |
| 1718 | put hw 1 KMI_HW_NONE |
| 1719 | if ne kmi_dtab_force_quiesce dtab 0x100 hw KMI_DEV_OK |
| 1720 | ret 166 |
| 1721 | end |
| 1722 | if not kmi_check_teardown_effects hw 0 |
| 1723 | ret 166 |
| 1724 | end |
| 1725 | if ne kmi_dev_state dtab 0x100 KMI_DMA_QUIESCED |
| 1726 | ret 166 |
| 1727 | end |
| 1728 | |
| 1729 | note revoke_failure_at_each_step_still_closes_gates_and_revokes |
| 1730 | for s ulong 4 |
| 1731 | fstep = add s KMI_HW_DISABLE_BME |
| 1732 | kmi_cap_init c0 1 4 |
| 1733 | kmi_cap_init c1 2 4 |
| 1734 | ign = kmi_cap_insert c0 0x100 KMI_RIGHT_ALL h0 |
| 1735 | ign_i = kmi_cap_derive_into c0 get h0 0 c1 KMI_RIGHT_MAP h1 |
| 1736 | kmi_setup_std_device dtab |
| 1737 | kmi_hw_init hw KMI_HW_NONE |
| 1738 | ign_i = kmi_dev_activate c1 get h1 0 dtab hw |
| 1739 | kmi_hw_clear_effects hw |
| 1740 | put hw 1 fstep |
| 1741 | put req 0 1 |
| 1742 | put req 1 get h0 0 |
| 1743 | put req 2 1 |
| 1744 | if ne kmi_dev_revoke req c0 c1 dtab hw KMI_DEV_ERR_HARDWARE |
| 1745 | ret 167 |
| 1746 | end |
| 1747 | if ne get hw 4 fstep |
| 1748 | ret 167 |
| 1749 | end |
| 1750 | if not kmi_check_teardown_effects hw 0 |
| 1751 | ret 168 |
| 1752 | end |
| 1753 | if ne kmi_dev_state dtab 0x100 KMI_DMA_REVOKING |
| 1754 | ret 168 |
| 1755 | end |
| 1756 | if ne kmi_cap_lookup c0 get h0 0 KMI_RIGHT_NONE res_b KMI_DEV_ERR_CAP_INVALID |
| 1757 | ret 169 |
| 1758 | end |
| 1759 | if ne kmi_cap_lookup c1 get h1 0 KMI_RIGHT_NONE res_b KMI_DEV_ERR_CAP_INVALID |
| 1760 | ret 169 |
| 1761 | end |
| 1762 | end |
| 1763 | |
| 1764 | note duplicate_or_missing_table_in_revoke_set |
| 1765 | kmi_cap_init c0 1 4 |
| 1766 | kmi_cap_init c1 2 4 |
| 1767 | ign = kmi_cap_insert c0 0x100 KMI_RIGHT_ALL h0 |
| 1768 | kmi_setup_std_device dtab |
| 1769 | kmi_hw_init hw KMI_HW_NONE |
| 1770 | put req 0 1 |
| 1771 | put req 1 get h0 0 |
| 1772 | put req 2 0 |
| 1773 | if ne kmi_dev_revoke req c1 c0 dtab hw KMI_DEV_ERR_CAP_DUP_TABLE |
| 1774 | ret 170 |
| 1775 | end |
| 1776 | kmi_cap_init c1 1 4 |
| 1777 | put req 2 1 |
| 1778 | if ne kmi_dev_revoke req c0 c1 dtab hw KMI_DEV_ERR_CAP_DUP_TABLE |
| 1779 | ret 170 |
| 1780 | end |
| 1781 | if ne get hw 0 0 |
| 1782 | ret 171 |
| 1783 | end |
| 1784 | ret kmi_test_device_reg_sweep |
| 1785 | end |
| 1786 | |
| 1787 | note ======================================================================== |
| 1788 | note 7. EDU DMA Tests (exit codes 196..215) |
| 1789 | note ======================================================================== |
| 1790 | |
| 1791 | fn kmi_test_edu to int |
| 1792 | st = new ulong 24 0 |
| 1793 | dev_buf = new uchar 4096 0 |
| 1794 | ram_buf = new uchar 16384 0 |
| 1795 | |
| 1796 | note probe_reads_version_and_checks_liveness |
| 1797 | kmi_edu_init st |
| 1798 | if ne kmi_edu_probe st KMI_EDU_OK |
| 1799 | ret 196 |
| 1800 | end |
| 1801 | if ne get st 18 1 |
| 1802 | ret 196 |
| 1803 | end |
| 1804 | if ne get st 19 0 |
| 1805 | ret 196 |
| 1806 | end |
| 1807 | put st 0 ulong 0x1af41000 |
| 1808 | if ne kmi_edu_probe st KMI_EDU_ERR_NOT_EDU |
| 1809 | ret 197 |
| 1810 | end |
| 1811 | kmi_edu_init st |
| 1812 | put st 16 ulong 0 |
| 1813 | if ne kmi_edu_probe st KMI_EDU_ERR_LIVENESS |
| 1814 | ret 198 |
| 1815 | end |
| 1816 | |
| 1817 | note round_trips_bytes_through_the_device_buffer |
| 1818 | kmi_edu_init st |
| 1819 | for i ulong 200 |
| 1820 | put ram_buf add 0x100 i uchar and xor i 0xa5 255 |
| 1821 | end |
| 1822 | src_a = add get st 9 0x100 |
| 1823 | dst_a = add get st 9 0x2000 |
| 1824 | if ne kmi_edu_transfer st dev_buf ram_buf src_a 200 false KMI_EDU_OK |
| 1825 | ret 199 |
| 1826 | end |
| 1827 | if ne kmi_edu_transfer st dev_buf ram_buf dst_a 200 true KMI_EDU_OK |
| 1828 | ret 199 |
| 1829 | end |
| 1830 | for i ulong 200 |
| 1831 | if ne get ram_buf add 0x2000 i get ram_buf add 0x100 i |
| 1832 | ret 200 |
| 1833 | end |
| 1834 | end |
| 1835 | if ne get st 15 2 |
| 1836 | ret 201 |
| 1837 | end |
| 1838 | if ne get st 3 KMI_EDU_DMA_BUF_ADDR |
| 1839 | ret 201 |
| 1840 | end |
| 1841 | if ne get st 4 dst_a |
| 1842 | ret 201 |
| 1843 | end |
| 1844 | if ne get st 6 KMI_EDU_DMA_TO_RAM |
| 1845 | ret 201 |
| 1846 | end |
| 1847 | if ne get st 2 0 |
| 1848 | ret 201 |
| 1849 | end |
| 1850 | |
| 1851 | note full_buffer_transfer_is_allowed |
| 1852 | kmi_edu_init st |
| 1853 | at_a = get st 9 |
| 1854 | if ne kmi_edu_transfer st dev_buf ram_buf at_a KMI_EDU_DMA_BUF_SIZE false KMI_EDU_OK |
| 1855 | ret 202 |
| 1856 | end |
| 1857 | if ne kmi_edu_transfer st dev_buf ram_buf add at_a KMI_EDU_DMA_BUF_SIZE KMI_EDU_DMA_BUF_SIZE true KMI_EDU_OK |
| 1858 | ret 202 |
| 1859 | end |
| 1860 | |
| 1861 | note blocked_transfer_completes_but_leaves_ram_untouched |
| 1862 | kmi_edu_init st |
| 1863 | for i ulong 64 |
| 1864 | put dev_buf i uchar 0x77 |
| 1865 | put ram_buf add 0x3000 i uchar 0 |
| 1866 | end |
| 1867 | forb = add get st 9 0x3000 |
| 1868 | put st 10 forb |
| 1869 | put st 11 add forb 0x1000 |
| 1870 | if ne kmi_edu_transfer st dev_buf ram_buf forb 64 true KMI_EDU_OK |
| 1871 | ret 203 |
| 1872 | end |
| 1873 | for i ulong 64 |
| 1874 | if ne get ram_buf add 0x3000 i 0 |
| 1875 | ret 204 |
| 1876 | end |
| 1877 | end |
| 1878 | |
| 1879 | note rejects_bad_lengths_and_addresses_before_touching_the_device |
| 1880 | kmi_edu_init st |
| 1881 | top = add KMI_EDU_DEFAULT_DMA_MASK 1 |
| 1882 | if ne kmi_edu_transfer st dev_buf ram_buf 0x1000 0 false KMI_EDU_ERR_EMPTY |
| 1883 | ret 205 |
| 1884 | end |
| 1885 | if ne kmi_edu_transfer st dev_buf ram_buf 0x1000 4097 false KMI_EDU_ERR_TOO_LONG |
| 1886 | ret 205 |
| 1887 | end |
| 1888 | if ne kmi_edu_transfer st dev_buf ram_buf top 16 true KMI_EDU_ERR_IOVA_RANGE |
| 1889 | ret 206 |
| 1890 | end |
| 1891 | if ne kmi_edu_transfer st dev_buf ram_buf sub top 8 16 true KMI_EDU_ERR_IOVA_RANGE |
| 1892 | ret 206 |
| 1893 | end |
| 1894 | if ne kmi_edu_transfer st dev_buf ram_buf sub ulong 0xffffffffffffffff 3 16 true KMI_EDU_ERR_IOVA_RANGE |
| 1895 | ret 206 |
| 1896 | end |
| 1897 | if ne get st 3 0 |
| 1898 | ret 207 |
| 1899 | end |
| 1900 | if ne get st 6 0 |
| 1901 | ret 207 |
| 1902 | end |
| 1903 | |
| 1904 | note last_byte_below_the_mask_is_accepted |
| 1905 | kmi_edu_init st |
| 1906 | put st 9 sub top 0x2000 |
| 1907 | if ne kmi_edu_transfer st dev_buf ram_buf sub top 16 16 true KMI_EDU_OK |
| 1908 | ret 208 |
| 1909 | end |
| 1910 | |
| 1911 | note wider_dma_mask_accepts_higher_addresses |
| 1912 | kmi_edu_init st |
| 1913 | put st 7 0xffffffffffffffff |
| 1914 | put st 17 0xffffffffffffffff |
| 1915 | put st 9 0x80000000 |
| 1916 | if ne kmi_edu_transfer st dev_buf ram_buf 0x80000000 16 true KMI_EDU_OK |
| 1917 | ret 209 |
| 1918 | end |
| 1919 | |
| 1920 | note times_out_when_the_transfer_never_finishes |
| 1921 | kmi_edu_init st |
| 1922 | put st 12 ulong 0 |
| 1923 | put st 8 ulong 100 |
| 1924 | at_a = get st 9 |
| 1925 | if ne kmi_edu_transfer st dev_buf ram_buf at_a 16 false KMI_EDU_ERR_TIMEOUT |
| 1926 | ret 210 |
| 1927 | end |
| 1928 | if ne kmi_edu_transfer st dev_buf ram_buf at_a 16 true KMI_EDU_ERR_BUSY |
| 1929 | ret 211 |
| 1930 | end |
| 1931 | if ne get st 6 KMI_EDU_DMA_START |
| 1932 | ret 211 |
| 1933 | end |
| 1934 | if ne get st 15 0 |
| 1935 | ret 211 |
| 1936 | end |
| 1937 | |
| 1938 | note spin_budget_covers_a_slow_transfer |
| 1939 | kmi_edu_init st |
| 1940 | put st 13 ulong 1000 |
| 1941 | put st 8 ulong 1001 |
| 1942 | if ne kmi_edu_transfer st dev_buf ram_buf get st 9 16 false KMI_EDU_OK |
| 1943 | ret 212 |
| 1944 | end |
| 1945 | kmi_edu_init st |
| 1946 | put st 13 ulong 1000 |
| 1947 | put st 8 ulong 1000 |
| 1948 | if ne kmi_edu_transfer st dev_buf ram_buf get st 9 16 false KMI_EDU_ERR_TIMEOUT |
| 1949 | ret 213 |
| 1950 | end |
| 1951 | |
| 1952 | note interrupt_status_and_acknowledge |
| 1953 | kmi_edu_init st |
| 1954 | put st 2 ulong or KMI_EDU_IRQ_BIT 1 |
| 1955 | kmi_edu_irq_ack st KMI_EDU_IRQ_BIT |
| 1956 | if ne get st 2 1 |
| 1957 | ret 214 |
| 1958 | end |
| 1959 | ret 0 |
| 1960 | end |
| 1961 | |
| 1962 | note ======================================================================== |
| 1963 | note 8. Block RamDisk Tests (exit codes 216..230) |
| 1964 | note ======================================================================== |
| 1965 | |
| 1966 | fn kmi_test_block to int |
| 1967 | st = new ulong 12 0 |
| 1968 | disk = new uchar 2048 0 |
| 1969 | wbuf = new uchar 512 0 |
| 1970 | rbuf = new uchar 512 0 |
| 1971 | bad_buf = new uchar 100 0 |
| 1972 | |
| 1973 | note ram_disk_rejects_block_size_that_would_truncate |
| 1974 | if ne kmi_ramdisk_init st 0x100000000 4 2048 KMI_BLK_INVALID_INPUT |
| 1975 | ret 216 |
| 1976 | end |
| 1977 | if ne kmi_ramdisk_init st 32 4 2048 KMI_BLK_INVALID_INPUT |
| 1978 | ret 216 |
| 1979 | end |
| 1980 | if ne kmi_ramdisk_init st 512 3 2048 KMI_BLK_INVALID_INPUT |
| 1981 | ret 216 |
| 1982 | end |
| 1983 | if ne kmi_ramdisk_init st 512 4 2048 KMI_BLK_OK |
| 1984 | ret 217 |
| 1985 | end |
| 1986 | |
| 1987 | note read/write round-trip and validation |
| 1988 | for i ulong 512 |
| 1989 | put wbuf i uchar and add i 17 255 |
| 1990 | end |
| 1991 | if ne kmi_ramdisk_write st disk 1 wbuf KMI_BLK_OK |
| 1992 | ret 218 |
| 1993 | end |
| 1994 | if ne kmi_ramdisk_read st disk 1 rbuf KMI_BLK_OK |
| 1995 | ret 218 |
| 1996 | end |
| 1997 | for i ulong 512 |
| 1998 | if ne get rbuf i get wbuf i |
| 1999 | ret 219 |
| 2000 | end |
| 2001 | end |
| 2002 | if ne kmi_ramdisk_read st disk 0 bad_buf KMI_BLK_INVALID_INPUT |
| 2003 | ret 220 |
| 2004 | end |
| 2005 | if ne kmi_ramdisk_read st disk 4 rbuf KMI_BLK_OUT_OF_RANGE |
| 2006 | ret 220 |
| 2007 | end |
| 2008 | |
| 2009 | note fail_after_blocks torn write |
| 2010 | kmi_ramdisk_fail_after st true 0 |
| 2011 | put wbuf 0 uchar 0xee |
| 2012 | if ne kmi_ramdisk_write st disk 2 wbuf KMI_BLK_DEVICE_ERROR |
| 2013 | ret 221 |
| 2014 | end |
| 2015 | if ne get disk 1024 0 |
| 2016 | ret 221 |
| 2017 | end |
| 2018 | |
| 2019 | note tear_write persists prefix and marks failed |
| 2020 | kmi_ramdisk_tear_write st 1 16 |
| 2021 | for i ulong 512 |
| 2022 | put wbuf i uchar 0xaa |
| 2023 | end |
| 2024 | if ne kmi_ramdisk_write st disk 2 wbuf KMI_BLK_DEVICE_ERROR |
| 2025 | ret 222 |
| 2026 | end |
| 2027 | if ne get disk 1024 0xaa |
| 2028 | ret 223 |
| 2029 | end |
| 2030 | if ne get disk 1039 0xaa |
| 2031 | ret 223 |
| 2032 | end |
| 2033 | if ne get disk 1040 0 |
| 2034 | ret 223 |
| 2035 | end |
| 2036 | if ne kmi_ramdisk_write st disk 0 wbuf KMI_BLK_DEVICE_ERROR |
| 2037 | ret 224 |
| 2038 | end |
| 2039 | |
| 2040 | note corrupt_byte |
| 2041 | if ne kmi_ramdisk_corrupt st disk 5 uchar 0x55 KMI_BLK_OK |
| 2042 | ret 225 |
| 2043 | end |
| 2044 | if ne get disk 5 0x55 |
| 2045 | ret 225 |
| 2046 | end |
| 2047 | if ne kmi_ramdisk_corrupt st disk 2048 uchar 0x55 KMI_BLK_OUT_OF_RANGE |
| 2048 | ret 226 |
| 2049 | end |
| 2050 | ret 0 |
| 2051 | end |
| 2052 | |
| 2053 | note ======================================================================== |
| 2054 | note 9. NVMe Atomicity Tests (exit codes 231..250) |
| 2055 | note ======================================================================== |
| 2056 | |
| 2057 | fn kmi_set_af af edit ulong 8 bs ulong has_aw ulong aw ulong has_naw ulong naw ulong to void |
| 2058 | put af 0 bs |
| 2059 | put af 1 has_aw |
| 2060 | put af 2 aw |
| 2061 | put af 3 has_naw |
| 2062 | put af 4 naw |
| 2063 | put af 5 ulong 0 |
| 2064 | put af 6 ulong 0 |
| 2065 | put af 7 ulong 0 |
| 2066 | end |
| 2067 | |
| 2068 | fn kmi_test_nvme_atomicity to int |
| 2069 | af = new ulong 8 0 |
| 2070 | info = new ulong 4 0 |
| 2071 | lba = new ulong 2 0 |
| 2072 | raw = new uchar 3 0 |
| 2073 | u16_o = new ushort 1 0 |
| 2074 | |
| 2075 | note insufficient_controller_awupf_rejects |
| 2076 | kmi_set_af af 512 1 6 0 0 |
| 2077 | if ne kmi_nvme_write_atomic af 0 8 info KMI_ATOM_EXCEEDS |
| 2078 | ret 231 |
| 2079 | end |
| 2080 | if ne get info 1 8 |
| 2081 | ret 231 |
| 2082 | end |
| 2083 | if ne get info 2 7 |
| 2084 | ret 231 |
| 2085 | end |
| 2086 | |
| 2087 | note sufficient_decoded_awupf_accepts |
| 2088 | kmi_set_af af 512 1 7 0 0 |
| 2089 | if ne kmi_nvme_write_atomic af 0 8 info KMI_ATOM_ATOMIC |
| 2090 | ret 232 |
| 2091 | end |
| 2092 | if ne get info 0 8 |
| 2093 | ret 232 |
| 2094 | end |
| 2095 | |
| 2096 | note namespace_override_wins_over_controller |
| 2097 | kmi_set_af af 512 1 15 1 3 |
| 2098 | if ne kmi_nvme_effective_pf af 4 |
| 2099 | ret 233 |
| 2100 | end |
| 2101 | if ne kmi_nvme_write_atomic af 0 8 info KMI_ATOM_EXCEEDS |
| 2102 | ret 233 |
| 2103 | end |
| 2104 | if ne get info 2 4 |
| 2105 | ret 233 |
| 2106 | end |
| 2107 | |
| 2108 | note namespace_zero_falls_back_to_controller |
| 2109 | kmi_set_af af 512 1 7 1 0 |
| 2110 | if ne kmi_nvme_effective_pf af 8 |
| 2111 | ret 234 |
| 2112 | end |
| 2113 | if ne kmi_nvme_write_atomic af 0 8 info KMI_ATOM_ATOMIC |
| 2114 | ret 234 |
| 2115 | end |
| 2116 | |
| 2117 | note sufficient_unit_but_crosses_boundary_rejects |
| 2118 | kmi_set_af af 512 1 15 0 0 |
| 2119 | put af 5 ulong 1 |
| 2120 | put af 6 ulong 3 |
| 2121 | if ne kmi_nvme_write_atomic af 0 8 info KMI_ATOM_CROSSES |
| 2122 | ret 235 |
| 2123 | end |
| 2124 | if ne get info 0 4 |
| 2125 | ret 235 |
| 2126 | end |
| 2127 | if ne kmi_nvme_write_atomic af 0 4 info KMI_ATOM_ATOMIC |
| 2128 | ret 236 |
| 2129 | end |
| 2130 | |
| 2131 | note boundary_safe_write_accepts |
| 2132 | kmi_set_af af 512 1 7 0 0 |
| 2133 | if ne kmi_nvme_write_atomic af 8 8 info KMI_ATOM_ATOMIC |
| 2134 | ret 237 |
| 2135 | end |
| 2136 | |
| 2137 | note boundary_offset_is_respected |
| 2138 | kmi_set_af af 512 1 15 0 0 |
| 2139 | put af 5 ulong 1 |
| 2140 | put af 6 ulong 7 |
| 2141 | put af 7 ulong 4 |
| 2142 | if ne kmi_nvme_write_atomic af 0 8 info KMI_ATOM_CROSSES |
| 2143 | ret 238 |
| 2144 | end |
| 2145 | if ne kmi_nvme_write_atomic af 4 8 info KMI_ATOM_ATOMIC |
| 2146 | ret 239 |
| 2147 | end |
| 2148 | |
| 2149 | note store_root_512_geometry |
| 2150 | kmi_set_af af 512 1 7 0 0 |
| 2151 | if not kmi_nvme_store_unit_lba af uint 0 lba |
| 2152 | ret 240 |
| 2153 | end |
| 2154 | if ne get lba 0 0 |
| 2155 | ret 240 |
| 2156 | end |
| 2157 | if ne get lba 1 8 |
| 2158 | ret 240 |
| 2159 | end |
| 2160 | if not kmi_nvme_store_unit_lba af uint 1 lba |
| 2161 | ret 241 |
| 2162 | end |
| 2163 | if ne get lba 0 8 |
| 2164 | ret 241 |
| 2165 | end |
| 2166 | if ne get lba 1 8 |
| 2167 | ret 241 |
| 2168 | end |
| 2169 | if ne kmi_nvme_store_root_decision af uint 0 info KMI_ATOM_ATOMIC |
| 2170 | ret 242 |
| 2171 | end |
| 2172 | if ne kmi_nvme_store_root_decision af uint 1 info KMI_ATOM_ATOMIC |
| 2173 | ret 242 |
| 2174 | end |
| 2175 | |
| 2176 | note store_root_4096_geometry |
| 2177 | kmi_set_af af 4096 1 0 0 0 |
| 2178 | if not kmi_nvme_store_unit_lba af uint 0 lba |
| 2179 | ret 243 |
| 2180 | end |
| 2181 | if ne get lba 1 1 |
| 2182 | ret 243 |
| 2183 | end |
| 2184 | if ne kmi_nvme_store_root_decision af uint 1 info KMI_ATOM_ATOMIC |
| 2185 | ret 243 |
| 2186 | end |
| 2187 | |
| 2188 | note encoding_edge_zero_and_max |
| 2189 | kmi_set_af af 512 1 0 0 0 |
| 2190 | if ne kmi_nvme_effective_pf af 1 |
| 2191 | ret 244 |
| 2192 | end |
| 2193 | kmi_set_af af 512 1 65535 0 0 |
| 2194 | if ne kmi_nvme_effective_pf af 65536 |
| 2195 | ret 244 |
| 2196 | end |
| 2197 | |
| 2198 | note unknown_state_fails_closed |
| 2199 | kmi_set_af af 512 0 0 0 0 |
| 2200 | if ne kmi_nvme_write_atomic af 0 8 info KMI_ATOM_NO_GUARANTEE |
| 2201 | ret 245 |
| 2202 | end |
| 2203 | |
| 2204 | note unsupported_geometry_fails_closed |
| 2205 | kmi_set_af af 600 1 15 0 0 |
| 2206 | if ne kmi_nvme_store_root_decision af uint 0 info KMI_ATOM_BAD_GEOMETRY |
| 2207 | ret 246 |
| 2208 | end |
| 2209 | |
| 2210 | note empty_write_rejects |
| 2211 | kmi_set_af af 512 1 15 0 0 |
| 2212 | if ne kmi_nvme_write_atomic af 0 0 info KMI_ATOM_EMPTY |
| 2213 | ret 247 |
| 2214 | end |
| 2215 | |
| 2216 | note read_u16_le_bounds |
| 2217 | put raw 0 uchar 7 |
| 2218 | put raw 1 uchar 0 |
| 2219 | put raw 2 uchar 255 |
| 2220 | if not kmi_read_u16_le raw 0 u16_o |
| 2221 | ret 248 |
| 2222 | end |
| 2223 | if ne get u16_o 0 7 |
| 2224 | ret 248 |
| 2225 | end |
| 2226 | if kmi_read_u16_le raw 2 u16_o |
| 2227 | ret 249 |
| 2228 | end |
| 2229 | if kmi_read_u16_le raw 99 u16_o |
| 2230 | ret 249 |
| 2231 | end |
| 2232 | ret 0 |
| 2233 | end |
| 2234 | |
| 2235 | note ======================================================================== |
| 2236 | note Main Test Runner |
| 2237 | note ======================================================================== |
| 2238 | |
| 2239 | fn main to int |
| 2240 | rc = kmi_test_frame_allocator |
| 2241 | if ne rc 0 |
| 2242 | ret rc |
| 2243 | end |
| 2244 | rc = kmi_test_map_plan |
| 2245 | if ne rc 0 |
| 2246 | ret rc |
| 2247 | end |
| 2248 | rc = kmi_test_smmu_desc_and_geom |
| 2249 | if ne rc 0 |
| 2250 | ret rc |
| 2251 | end |
| 2252 | rc = kmi_test_smmu_bringup |
| 2253 | if ne rc 0 |
| 2254 | ret rc |
| 2255 | end |
| 2256 | rc = kmi_test_smmu_failures |
| 2257 | if ne rc 0 |
| 2258 | ret rc |
| 2259 | end |
| 2260 | rc = kmi_test_smmu_ops_and_events |
| 2261 | if ne rc 0 |
| 2262 | ret rc |
| 2263 | end |
| 2264 | rc = kmi_test_dma_gate |
| 2265 | if ne rc 0 |
| 2266 | ret rc |
| 2267 | end |
| 2268 | rc = kmi_test_pci |
| 2269 | if ne rc 0 |
| 2270 | ret rc |
| 2271 | end |
| 2272 | rc = kmi_test_device_1 |
| 2273 | if ne rc 0 |
| 2274 | ret rc |
| 2275 | end |
| 2276 | rc = kmi_test_device_2 |
| 2277 | if ne rc 0 |
| 2278 | ret rc |
| 2279 | end |
| 2280 | rc = kmi_test_edu |
| 2281 | if ne rc 0 |
| 2282 | ret rc |
| 2283 | end |
| 2284 | rc = kmi_test_block |
| 2285 | if ne rc 0 |
| 2286 | ret rc |
| 2287 | end |
| 2288 | rc = kmi_test_nvme_atomicity |
| 2289 | if ne rc 0 |
| 2290 | ret rc |
| 2291 | end |
| 2292 | ret 0 |
| 2293 | end |