diff --git a/.crumb b/.crumb index bd8ac4d4..34da263e 100644 --- a/.crumb +++ b/.crumb @@ -27,8 +27,8 @@ "purpose": "Directory crates. Purpose not yet described by a human." }, { - "digest": "b52fed726bbf13ba8bae39bf6a5fd76fea7c2eca620cc5ddb6518820982dd864", - "last_commit": "036cef6", + "digest": "bfae16a004b9057c96f70f68337d95ae4ff6d456fa2a624576f9566b8f23cf2b", + "last_commit": "89fcc57", "name": "docs", "purpose": "Directory docs. Purpose not yet described by a human." }, @@ -39,21 +39,21 @@ "purpose": "Directory native. Purpose not yet described by a human." }, { - "digest": "72ac07324618c0fce9dc8a227666dec8ee62d66865103810f494e7d7e12b924f", - "last_commit": "a9b15b9", + "digest": "d9cd564824903777dd323019bb8d5673331383e961bc3da703d5589be1eb6b4c", + "last_commit": "89fcc57", "name": "scripts", "purpose": "Directory scripts. Purpose not yet described by a human." } ], - "children_root": "sha256:98ddd37f0f56b5601e6d7dd0434544462baad800f24158803264e603e403721a", - "compiled_at": "2026-10-10T01:37:30Z", + "children_root": "sha256:f92832f19d1cf1f9b6ebcfa7ced8e4e2c0f47b28074a7f93642b9383123fbe74", + "compiled_at": "2026-10-10T02:47:01Z", "compiler": "crumb-compile/1", - "digest": "sha256:d1a0004d7aa63c4f4ead2b4b45f9352a025f627f663ada6237c64e21ca508554", + "digest": "sha256:b9c0208a3abe68373fa3005fd5312243fafb51fec65d4201dd8e524cf169349b", "evidence_files": 155, "evidence_root": "sha256:d59c0cef4e7dd5172923754a95b411ca54b01f35baca4587f792f1b259f1eaf7", - "files": 3033, - "generated_at_commit": "036cef68db02d23e8cce93bfb6aa7c8581a65d40", - "source_tree": "sha256:b20800d14a3706109848fcf6a44c4b13202ed195098befa4de9a9da3d029eacd" + "files": 3036, + "generated_at_commit": "89fcc57c5bf7a5003eea52de0ac3bf2f752e2c04", + "source_tree": "sha256:864db176a2e3dd3cfff21247e1ed018f779178481b5c3939433ffae93c4bce27" }, "owner_lane": "", "provenance": { diff --git a/docs/.crumb b/docs/.crumb index eaf3e4a7..91e2eeee 100644 --- a/docs/.crumb +++ b/docs/.crumb @@ -24,20 +24,20 @@ }, { "digest": "e9e804e088a0b2316d035b957c09289bf9f6176eece959d43c40c6e66005fe5e", - "last_commit": "31ed9f8", + "last_commit": "7e15a57", "name": "crumbs", "purpose": "Directory docs/crumbs. Purpose not yet described by a human." } ], "children_root": "sha256:55bcc89f5282eb2e3f4e86d882abdfb5f4ea39e427ef97ef620b2267e5701eb1", - "compiled_at": "2026-10-10T01:37:30Z", + "compiled_at": "2026-10-10T02:47:01Z", "compiler": "crumb-compile/1", - "digest": "sha256:b52fed726bbf13ba8bae39bf6a5fd76fea7c2eca620cc5ddb6518820982dd864", + "digest": "sha256:bfae16a004b9057c96f70f68337d95ae4ff6d456fa2a624576f9566b8f23cf2b", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 65, - "generated_at_commit": "036cef68db02d23e8cce93bfb6aa7c8581a65d40", - "source_tree": "sha256:0514cd046293fe02accf66ed9b2dc859d107920b0d4bf705a37839133d4f5da2" + "files": 66, + "generated_at_commit": "89fcc57c5bf7a5003eea52de0ac3bf2f752e2c04", + "source_tree": "sha256:767260ee7c6d528b0fe584e48e529b414fc8d0a3af327ad2cd2f7513710fa1e2" }, "owner_lane": "", "provenance": { diff --git a/docs/GB10_DMA_ROUTE_INVENTORY.md b/docs/GB10_DMA_ROUTE_INVENTORY.md index 93b81638..be97780e 100644 --- a/docs/GB10_DMA_ROUTE_INVENTORY.md +++ b/docs/GB10_DMA_ROUTE_INVENTORY.md @@ -32,6 +32,7 @@ lines cited below match the pinned lines in that map). | IORT table is present (3904 bytes); Linux reports one Arm SMMUv3, 40-bit output, 2-level stream table covering 25 of 32 stream-ID bits, default domain Translated | [SOURCE docs/GB10_PLATFORM_TOPOLOGY.md:68-74] (Linux observed) | | GB10 is alone in IOMMU group 20 | [SOURCE docs/GB10_PLATFORM_TOPOLOGY.md:73-74] | | The GB10's IORT stream ID and stream table entry are not decoded by this project | [SOURCE docs/GB10_PLATFORM_TOPOLOGY.md:76-78,165] | +| Resolved in cut B5: GB10 = StreamID 0x100 on the IORT's second SMMUv3 node (base 0x13000000); the kernel today drives only the first (0x13800000) | [SOURCE docs/GB10_IORT_DECODE.md] | | Which SMMU node the GB10's IORT mapping points at (the kernel drives only the IORT's first SMMUv3 node) | [UNKNOWN] | | Whether the GB10's stream ID is below the 4096 stream IDs the aienos stream table covers (`STE_N`) | [UNKNOWN] | | Number of SMMUs on the machine, beyond "an Arm SMMUv3" | [UNKNOWN] (platform USB nodes may sit behind a second one; see `CK_SMMU_OTHER`, native/kernel/include/ck.h:99-100) | diff --git a/docs/GB10_IORT_DECODE.md b/docs/GB10_IORT_DECODE.md new file mode 100644 index 00000000..139dde85 --- /dev/null +++ b/docs/GB10_IORT_DECODE.md @@ -0,0 +1,142 @@ +# GB10 IORT decode: stream id, SMMU node, reserved regions (aienos#286, cut B5) + +Report only. Host only. Read-only. No kernel code was changed, no hardware +register was touched, no QEMU run was made. Base commit of aienos read: +`be514b5` (main). Firmware table read on the Spark on 2026-10-10 +(`/sys/firmware/acpi/tables/IORT`, 3904 bytes, sha256 +`5e0096a2be83ce2025c5c6395455c6814c16e01ff433791e8057c245f4939cb1`). + +Tags: [SOURCE file:line] read in the named file or table. [INFERRED] reasoned +from sources, not directly shown. [UNKNOWN] nothing read answers it. +Paths without a repo prefix are in aienos. `actbl2.h` is +`/usr/src/linux-headers-6.11.0-1014-nvidia/include/acpi/actbl2.h` on the Spark +(ACPICA layout of the IORT, ARM DEN 0049). `linux iort.c` is +`drivers/acpi/arm64/iort.c` at torvalds/linux master, fetched 2026-10-10. + +## 1. Short answer + +- The GB10 (PCI segment 15, requester id 0x0100 = bus 1, device 0, function 0) + resolves to the SMMUv3 at base `0x13000000` with **StreamID 0x100**, and + from there to ITS group 0 with **MSI DeviceID 0x100**. [SOURCE IORT node + offsets 0x72c, 0xa0, 0x30; section 4] +- That SMMU is the **second** SMMUv3 node in the table (node offset 0xa0). The + first SMMUv3 node (offset 0x48, base `0x13800000`) serves PCI segments 0 to 14 + and the USB named components. [SOURCE IORT; section 3] +- aienos keeps only the first SMMUv3 node and only the root-complex mappings + that point at it, so the segment 15 mapping is dropped at parse time and + `ck_dma_confine(15, 0x0100, ...)` returns `CK_SMMU_NOSTREAM` on this + machine. It fails closed, which is right, but it means **no GB10 DMA can be + confined until the kernel drives a second SMMUv3 instance**. + [SOURCE native/kernel/core/acpi.c:368-375,384-387; native/kernel/core/smmu_svc.c:110,142-143] +- StreamID 0x100 is inside the 4096-entry stream table aienos allocates + (`STE_N`), so table size is not the obstacle. [SOURCE native/kernel/core/smmu_svc.c:14] +- The table carries one RMR node (reserved memory ranges) for stream ids 0x0 + to 0x100 inclusive on the GB10's SMMU, so it covers the GB10. Three physical + ranges must stay identity-mapped (Normal Non-cacheable, remap not + permitted) for those streams: `0x280000000` + 2 GiB, `0x300000000` + 48 MiB, + `0xa1600000` + 386 MiB. Linux exposes exactly these as `direct` reserved + regions of the GB10's IOMMU group. [SOURCE IORT node 0xc18; /sys/kernel/iommu_groups/20/reserved_regions] + What those ranges hold is [UNKNOWN] (`/proc/iomem` lists + `280000000-3237fffff : reserved`, no owner name). +- Segment 15 is the only root complex with ATS marked supported. Its DMA + address limit is 40 bits and it is marked cache coherent. [SOURCE IORT node 0x72c] + +## 2. Method + +1. Read the layout first: `actbl2.h` structs `acpi_iort_node` (:470), + `acpi_iort_id_mapping` (:492), `acpi_iort_root_complex` (:549), + `acpi_iort_smmu_v3` (:603), `acpi_iort_rmr` and `acpi_iort_rmr_desc` + (:640-651), and the id-range rule from `linux iort.c:361` + (`rid_in > map->input_base + map->id_count` means ranges are inclusive; + `id_count` is the number of ids minus one). Both recorded with `docs-read`. +2. Dumped the table (root read of `/sys/firmware/acpi/tables/IORT`) and decoded + it with `scripts/iort_decode.rs` (Rust, standard library only, reads a file, + touches no hardware). `scripts/gb10_iort_decode.sh` does both steps. +3. Ground check against Linux (section 5) before trusting the decode. + +## 3. What the table contains + +68 nodes, revision 6, OEM `MEDTEK`. [SOURCE IORT header] + +| Node | Offset | What | Mappings | +|---|---|---|---| +| ITS group 0 | 0x30 | ITS id 0 | none (terminal) | +| SMMUv3 A | 0x48 | base `0x13800000`, flags 0x1 (COHACC override), event/pri/gerr/sync GSIV 342/347/340/341 | stream 0x10000..=0x110000 to ITS group, DeviceID = stream + 0x200000 | +| SMMUv3 B | 0xa0 | base `0x13000000`, flags 0x1, GSIV 366/371/364/365 | stream 0x0..=0x10000 to ITS group, DeviceID = stream | +| SMMUv3 C | 0xf8 | base `0x14900000`, flags 0x1, GSIV 397/0/395/396 | none (no MSI path) | +| Named USB0..USB5, UBF0..UBF3 | 0x150..0x36c | platform USB controllers | single stream 0x0..0x9 on SMMUv3 A | +| Root complex seg 0..14 | 0x3a8..0x6f0 | ATS 0, 40-bit, coherent | rid 0x0..=0xffff to SMMUv3 A, stream base 0x10000 * (seg + 1) | +| Root complex seg 15 | 0x72c | **ATS 1**, 40-bit, coherent | rid 0x0..=0xffff to **SMMUv3 B**, stream = rid | +| Named HDA0 | 0x768 | audio | single stream 0x500 on SMMUv3 B | +| Named ROT0/1, DSP1..3, CNT0, ASD0, I2C0..6, SPI0/2/3, PMU0, DMA0 | 0x7a4..0xbdc | platform peripherals | single streams on SMMUv3 C | +| RMR | 0xc18 | flags 0x10: remap NOT permitted, unprivileged, attributes Normal NC; 3 ranges (section 1) | stream 0x0..=0x100 on SMMUv3 B | +| PMCG x17 | 0xc98..0xf18 | performance monitor pages per SMMU | none | + +[SOURCE IORT decode, full listing reproduced by `scripts/gb10_iort_decode.sh`] + +## 4. Resolution walk for the GB10 + +``` +segment 15, rid 0x0100 + root complex @0x72c map in 0x0..=0xffff out 0x0 -> SMMUv3 B @0xa0 StreamID 0x100 + SMMUv3 B @0xa0 map in 0x0..=0x10000 out 0x0 -> ITS group @0x30 DeviceID 0x100 +``` + +The PCIe root port of that segment (`000f:00:00.0`, rid 0x0000) is StreamID +0x0 on the same SMMU. [INFERRED from the same mapping] + +## 5. Ground checks (Linux on the same machine, read-only) + +| Check | Decode says | Linux says | Result | +|---|---|---|---| +| GB10 SMMU | SMMUv3 B, base 0x13000000 | `/sys/bus/pci/devices/000f:01:00.0/iommu` -> `smmu3.0x0000000013000000` | match | +| Negative control: segments 0 to 9 devices (8 functions) | SMMUv3 A, base 0x13800000 | every `/sys/bus/pci/devices/000[0-9]:*/iommu` -> `smmu3.0x0000000013800000` | match | +| Number of SMMUs | 3 | `/sys/class/iommu`: 0x13000000, 0x13800000, 0x14900000 | match | +| RMR covers the GB10 stream | yes (0x0..=0x100 inclusive) | group 20 `reserved_regions`: `a1600000-b97fffff direct`, `280000000-302ffffff direct` (= RMR ranges 2, 1+0 merged) | match | +| MSI doorbell | ITS group 0 | group 20 `reserved_regions`: `8000000-80fffff msi` | consistent | + +The inclusive id-range rule is what makes the RMR cover the GB10: with an +exclusive reading the RMR would stop at 0xff and Linux would not list those +regions for group 20. [SOURCE linux iort.c:361; sysfs above] + +## 6. What this means for aienos + +| Fact | Where in the kernel | Consequence | +|---|---|---| +| Parser keeps only the first SMMUv3 node (`pass == 0 && type == IORT_NODE_SMMUV3 && !found`) | native/kernel/core/acpi.c:368-375 | SMMUv3 A is the only SMMU aienos can bring up; SMMUv3 B (GB10) is never programmed | +| Root-complex mappings whose output is another SMMU are skipped (`rd32(e + 12) != s.node_off`) | native/kernel/core/acpi.c:386-387 | segment 15 has no mapping in `g.iort`; `ck_iort_stream_id(15, 0x100)` returns -1 | +| `ck_dma_confine` then returns `CK_SMMU_NOSTREAM` | native/kernel/core/smmu_svc.c:142-143 | fail closed: a GB10 DMA window is refused today, never granted unconfined | +| Only the named-component path knows the "other SMMU" case (`CK_SMMU_OTHER`) | native/kernel/core/smmu_svc.c:162-167; native/kernel/include/ck.h:116 | the PCI path reports NOSTREAM where OTHER is the truth; a report-only mismatch, not a safety hole | +| Range test `rel > m->id_count` | native/kernel/core/acpi.c:430 | inclusive, agrees with Linux; no change needed | +| `STE_N 4096` | native/kernel/core/smmu_svc.c:14 | StreamID 0x100 fits | +| Window leaf is Normal Non-cacheable | native/kernel/core/smmu_svc.c:16-19 | same attribute the RMR demands (Normal NC), so the RMR ranges could be expressed as windows [INFERRED] | +| One contiguous span per stream | native/kernel/core/smmu_svc.c:15-19 (B4 report section 1) | the three RMR ranges plus a ring/completion window need at least four spans for StreamID 0x100 [INFERRED] | + +Gaps a future cut would have to close before any GB10 DMA (design facts, not a plan): +1. Bring up SMMUv3 B (base 0x13000000) in addition to or instead of A: own + stream table, command and event queues, GSIVs 366/371/364/365. +2. Select the SMMU per root complex, not "the first node"; `ck_iort_parse` + would have to carry several SMMU nodes or be called per node. +3. Honour the RMR for StreamID 0x100: identity windows for the three ranges + with Normal NC, or the GPU's firmware traffic into them faults. [INFERRED; + what the ranges hold is UNKNOWN] +4. Keep DMA addresses under 40 bits for segment 15 (address limit 40). +5. MSI: DeviceID 0x100 at ITS 0 if interrupts are ever used instead of polling. + +## 7. Unknowns + +- What lives in the three RMR ranges (GPU firmware carveout is a guess, not a + reading). [UNKNOWN] +- Whether SMMUv3 B shares the stream table format and feature set of A (the + table says model 0, generic, for all three; the hardware ID registers were + not read in this cut). [UNKNOWN] +- Whether Linux's stream table entry for 0x100 uses stage 1, stage 2 or + bypass (not decoded; needs a register read, out of scope here). [UNKNOWN] + +## 8. Next candidate cut + +B6 (needs coordinator approval): QEMU-only design and test of multi-SMMU IORT +parsing in `ck_iort_parse` (keep every SMMUv3 node; resolve root complex to its +own node) with an `iort-mutants` case carrying two SMMUv3 nodes, so the GB10 +path reports `CK_SMMU_OTHER` instead of `CK_SMMU_NOSTREAM` and a later cut can +bring SMMUv3 B up. No hardware step is proposed. diff --git a/docs/GB10_PLATFORM_TOPOLOGY.md b/docs/GB10_PLATFORM_TOPOLOGY.md index 67d53c38..4aafead7 100644 --- a/docs/GB10_PLATFORM_TOPOLOGY.md +++ b/docs/GB10_PLATFORM_TOPOLOGY.md @@ -162,7 +162,7 @@ on the boot and handoff code: ## Unresolved unknowns -- The IORT stream ID and SMMUv3 stream table entry for the GB10. +- The SMMUv3 stream table entry for the GB10 (its stream ID is now decoded: StreamID 0x100 on the SMMUv3 at 0x13000000, see docs/GB10_IORT_DECODE.md). - The disposition of the ninth MSI-X vector. - Whether the negotiated PCIe width stays at x1 after link training settles, and why the current speed reads 2.5 GT/s while the link can go wider. Kernel diff --git a/scripts/.crumb b/scripts/.crumb index 7f604eb7..550a4868 100644 --- a/scripts/.crumb +++ b/scripts/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-09T02:51:28Z", + "compiled_at": "2026-10-10T02:47:01Z", "compiler": "crumb-compile/1", - "digest": "sha256:72ac07324618c0fce9dc8a227666dec8ee62d66865103810f494e7d7e12b924f", + "digest": "sha256:d9cd564824903777dd323019bb8d5673331383e961bc3da703d5589be1eb6b4c", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 76, - "generated_at_commit": "0c53308f596bbccc2c3a8345b139f082ab2532e9", - "source_tree": "sha256:e3ec588343b886b34fec7208ae0c7746f5121d99e759682ffe00c0205176978c" + "files": 78, + "generated_at_commit": "89fcc57c5bf7a5003eea52de0ac3bf2f752e2c04", + "source_tree": "sha256:14ef9ea3fcd3fdf3133ec04c2c401a2cc46321abd39bee7e1f54c7b199a5b4a8" }, "owner_lane": "", "provenance": { diff --git a/scripts/gb10_iort_decode.sh b/scripts/gb10_iort_decode.sh new file mode 100755 index 00000000..77d13ae3 --- /dev/null +++ b/scripts/gb10_iort_decode.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +# gb10_iort_decode.sh: dump the firmware IORT table (read-only) and resolve the +# GB10 (PCI segment 15, requester id 0x0100) to its SMMUv3 node and stream id. +# Host only. Needs root to read /sys/firmware/acpi/tables/IORT. Changes nothing. +# aienos#286 cut B5; see docs/GB10_IORT_DECODE.md. +set -euo pipefail +here=$(cd "$(dirname "$0")" && pwd) +out=${1:-/tmp/aienos-iort} +seg=${2:-15} +rid=${3:-0x0100} +mkdir -p "$out" +sudo cat /sys/firmware/acpi/tables/IORT > "$out/IORT.bin" +rustc --edition 2021 -O -o "$out/iort_decode" "$here/iort_decode.rs" +sha256sum "$out/IORT.bin" +"$out/iort_decode" "$out/IORT.bin" "$seg" "$rid" diff --git a/scripts/iort_decode.rs b/scripts/iort_decode.rs new file mode 100644 index 00000000..5f4b78da --- /dev/null +++ b/scripts/iort_decode.rs @@ -0,0 +1,49 @@ +// scripts/iort_decode.rs: read-only ACPI IORT decoder (host tool, std only, no deps). +// Build: rustc --edition 2021 -O -o iort_decode scripts/iort_decode.rs +// Run: sudo cat /sys/firmware/acpi/tables/IORT > IORT.bin && ./iort_decode IORT.bin [segment rid_hex] +// Layout: linux include/acpi/actbl2.h (packed), ARM DEN 0049. ID ranges are inclusive +// (id_count = number of ids minus one), as linux drivers/acpi/arm64/iort.c iort_id_map does. +// Added for aienos#286 cut B5 (docs/GB10_IORT_DECODE.md). Reads a file; touches no hardware. +// Read-only ACPI IORT decoder (layout: linux include/acpi/actbl2.h, ARM DEN 0049, packed). +use std::fs; use std::env; +fn u8_(b:&[u8],o:usize)->u8{b[o]} fn u16_(b:&[u8],o:usize)->u16{u16::from_le_bytes([b[o],b[o+1]])} +fn u32_(b:&[u8],o:usize)->u32{u32::from_le_bytes(b[o..o+4].try_into().unwrap())} +fn u64_(b:&[u8],o:usize)->u64{u64::from_le_bytes(b[o..o+8].try_into().unwrap())} +#[derive(Clone)] struct Map{ib:u32,cnt:u32,ob:u32,oref:u32,fl:u32} +#[derive(Clone)] struct Node{off:usize,ty:u8,len:u16,id:u32,maps:Vec,seg:Option,smmu_base:Option,name:Option} +fn main(){ + let a:Vec=env::args().collect(); let b=fs::read(&a[1]).unwrap(); + assert_eq!(&b[0..4],b"IORT"); let tlen=u32_(&b,4) as usize; assert_eq!(tlen,b.len()); + let rev=u8_(&b,8); let ncount=u32_(&b,36) as usize; let noff=u32_(&b,40) as usize; + println!("IORT len={} rev={} oem={} node_count={} node_offset={}",tlen,rev,String::from_utf8_lossy(&b[10..16]).trim(),ncount,noff); + let mut nodes=Vec::new(); let mut o=noff; + for _ in 0..ncount{ + let ty=u8_(&b,o); let len=u16_(&b,o+1) as usize; let id=u32_(&b,o+4); let mc=u32_(&b,o+8) as usize; let mo=u32_(&b,o+12) as usize; + let mut n=Node{off:o,ty,len:len as u16,id,maps:vec![],seg:None,smmu_base:None,name:None}; + let d=o+16; // node_data + match ty{ + 2=>{ n.seg=Some(u32_(&b,d+12)); println!("node@{:#06x} type=2 PCI_ROOT_COMPLEX id={} len={} memprops={:#x} ats={} segment={} addr_limit={} maps={}",o,id,len,u64_(&b,d),u32_(&b,d+8),u32_(&b,d+12),u8_(&b,d+16),mc); } + 4=>{ n.smmu_base=Some(u64_(&b,d)); println!("node@{:#06x} type=4 SMMU_V3 id={} len={} base={:#x} flags={:#x} model={} event_gsiv={} pri={} gerr={} sync={} pxm={} idmap_index={} maps={}",o,id,len,u64_(&b,d),u32_(&b,d+8),u32_(&b,d+24),u32_(&b,d+28),u32_(&b,d+32),u32_(&b,d+36),u32_(&b,d+40),u32_(&b,d+44),u32_(&b,d+48),mc); } + 0=>{ let c=u32_(&b,d) as usize; let ids:Vec=(0..c).map(|i|format!("{}",u32_(&b,d+4+4*i))).collect(); println!("node@{:#06x} type=0 ITS_GROUP id={} len={} its_ids=[{}] maps={}",o,id,len,ids.join(","),mc); } + 1=>{ let s=&b[d+13..o+len]; let name=String::from_utf8_lossy(&s[..s.iter().position(|&c|c==0).unwrap_or(s.len())]).to_string(); n.name=Some(name.clone()); println!("node@{:#06x} type=1 NAMED_COMPONENT id={} len={} flags={:#x} memprops={:#x} addr_limit={} name={} maps={}",o,id,len,u32_(&b,d),u64_(&b,d+4),u8_(&b,d+12),name,mc); } + 5=>{ println!("node@{:#06x} type=5 PMCG id={} len={} page0={:#x} ovf_gsiv={} node_ref={:#x} maps={}",o,id,len,u64_(&b,d),u32_(&b,d+8),u32_(&b,d+12),mc); } + 6=>{ let fl=u32_(&b,d); let rc=u32_(&b,d+4) as usize; let ro=u32_(&b,d+8) as usize; println!("node@{:#06x} type=6 RMR id={} len={} flags={:#x} rmr_count={} maps={}",o,id,len,fl,rc,mc); for i in 0..rc{ let r=o+ro+20*i; println!(" rmr[{}] base={:#x} len={:#x}",i,u64_(&b,r),u64_(&b,r+8)); } } + t=>{ println!("node@{:#06x} type={} (undecoded) id={} len={} maps={}",o,t,id,len,mc); } + } + for i in 0..mc{ let m=o+mo+20*i; let mp=Map{ib:u32_(&b,m),cnt:u32_(&b,m+4),ob:u32_(&b,m+8),oref:u32_(&b,m+12),fl:u32_(&b,m+16)}; + println!(" map[{}] in={:#x}..={:#x} out={:#x} -> node@{:#06x} flags={:#x}{}",i,mp.ib,mp.ib.wrapping_add(mp.cnt),mp.ob,mp.oref,mp.fl,if mp.fl&1==1{" (single)"}else{""}); n.maps.push(mp);} + nodes.push(n); o+=len; + } + if a.len()>3 { let seg:u32=a[2].parse().unwrap(); let rid=u32::from_str_radix(a[3].trim_start_matches("0x"),16).unwrap(); + println!("\nRESOLVE segment={} rid={:#06x}",seg,rid); + let rc=nodes.iter().find(|n|n.ty==2&&n.seg==Some(seg)); let Some(mut cur)=rc.cloned() else {println!(" no root complex for segment {}",seg); return;}; + let mut idv=rid; let mut hops=0; + loop{ hops+=1; if hops>8{println!(" loop guard");break;} + let m=cur.maps.iter().find(|m| m.fl&1==0 && idv>=m.ib && idv <= m.ib.wrapping_add(m.cnt)); + let Some(m)=m else { println!(" node@{:#06x} type={}: no mapping covers id {:#x} -> UNMAPPED",cur.off,cur.ty,idv); break; }; + let out=m.ob + (idv-m.ib); let Some(next)=nodes.iter().find(|n|n.off==m.oref as usize) else {println!(" dangling ref {:#x}",m.oref);break;}; + println!(" node@{:#06x} type={} id {:#x} -> node@{:#06x} type={} id {:#x}{}",cur.off,cur.ty,idv,next.off,next.ty,out, match (next.ty,next.smmu_base){(4,Some(bs))=>format!(" [SMMUv3 base {:#x}, StreamID {:#x}]",bs,out),(0,_)=>" [ITS group, DeviceID]".to_string(),_=>String::new()}); + idv=out; cur=next.clone(); if cur.maps.is_empty(){break;} + } + } +}