Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/scripts/gb10_profile.sh # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / scripts / gb10_profile.sh` 553 lines ยท 26321 bytes Raw Blame History 1 #!/usr/bin/env bash 2 # SPDX-License-Identifier: Apache-2.0 3 # Copyright 2026 Drake Stapleton (AIEN / aien-dev) 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 # Read-only GB10 hardware characterization collector for Linux (Machine 1). 18 # 19 # This script only reads. It opens no sysfs attribute for writing, changes no 20 # PCI command bit, resizes no BAR, resets no device, unbinds no driver, writes 21 # no MMIO, and touches no /dev/mem. Every source is a kernel-exposed read-only 22 # interface. 23 # 24 # Output is a deterministic structured profile (JSON) plus a human-readable 25 # report. Every field records: 26 # - the value 27 # - the source (which kernel interface) 28 # - the collection method 29 # - whether Linux interpreted the value (true for sysfs attributes, false for 30 # raw configuration-space bytes that this script decodes itself) 31 # - whether native AIENOS has independently verified it (always false here; 32 # this collector runs under Linux) 33 # 34 # Privilege: by default the collector runs unprivileged and reads only the 35 # first 64 bytes of PCI configuration space, which excludes the capability 36 # list. Extended configuration space (256 bytes) and the ACPI table copies are 37 # readable only by root on this platform. Pass --allow-sudo (or set 38 # GB10_PROFILE_ALLOW_SUDO=1) to perform those specific, strictly read-only 39 # reads through `sudo -n`. Nothing else is escalated. 40 41 set -euo pipefail 42 43 SCHEMA="aienos.gb10.profile.v1" 44 GB10_VENDOR="0x10de" 45 GB10_DEVICE="0x2e12" 46 47 JSON_OUT="-" 48 REPORT_OUT="/dev/stderr" 49 ALLOW_SUDO="${GB10_PROFILE_ALLOW_SUDO:-0}" 50 EMIT_TIMESTAMP=0 51 GENERATED_AT="${GB10_PROFILE_GENERATED_AT:-}" 52 53 usage() { 54 cat <<'EOF' 55 usage: bash scripts/gb10_profile.sh [options] 56 57 --json PATH write the structured profile to PATH ('-' for stdout; default -) 58 --report PATH write the human report to PATH (default stderr) 59 --allow-sudo allow the specific read-only privileged reads described above 60 --generated-at S set a fixed collection timestamp; default is omitted so 61 repeated runs on unchanged hardware are byte-identical 62 -h, --help show this help 63 64 This collector is read-only. It never writes configuration space, MMIO, driver 65 state, firmware variables, or storage. 66 EOF 67 } 68 69 while [[ $# -gt 0 ]]; do 70 case "$1" in 71 --json) JSON_OUT="$2"; shift 2 ;; 72 --report) REPORT_OUT="$2"; shift 2 ;; 73 --allow-sudo) ALLOW_SUDO=1; shift ;; 74 --generated-at) GENERATED_AT="$2"; EMIT_TIMESTAMP=1; shift 2 ;; 75 -h|--help) usage; exit 0 ;; 76 *) echo "unknown argument: $1" >&2; usage >&2; exit 2 ;; 77 esac 78 done 79 80 if [[ "$ALLOW_SUDO" == "1" ]]; then 81 if ! sudo -n true 2>/dev/null; then 82 echo "warning: --allow-sudo requested but sudo -n is unavailable; continuing unprivileged" >&2 83 ALLOW_SUDO=0 84 fi 85 fi 86 87 TMP_CONFIG="$(mktemp "${TMPDIR:-/tmp}/gb10-config.XXXXXX")" 88 TMP_ACPI="$(mktemp "${TMPDIR:-/tmp}/gb10-acpi.XXXXXX")" 89 TMP_PROFILE="$(mktemp "${TMPDIR:-/tmp}/gb10-profile.XXXXXX")" 90 cleanup() { rm -f "$TMP_CONFIG" "$TMP_ACPI" "$TMP_PROFILE"; } 91 trap cleanup EXIT 92 93 # --- small helpers --------------------------------------------------------- 94 95 read_attr() { # dir name 96 local path="$1/$2" 97 [[ -r "$path" ]] && tr -d '\n' < "$path" || true 98 } 99 100 read_attr_or_null() { # dir name -> JSON null when absent 101 local value 102 value="$(read_attr "$1" "$2")" 103 if [[ -z "$value" ]]; then printf 'null'; else printf '"%s"' "$value"; fi 104 } 105 106 read_resource_line() { # dir index -> "start end flags" (empty when absent) 107 local file="$1/resource" 108 [[ -r "$file" ]] || return 0 109 awk -v n="$2" 'NR == n+1 { print $1, $2, $3 }' "$file" 110 } 111 112 attr_present() { [[ -e "$1/$2" ]]; } 113 114 config_byte() { # offset -> hex byte from TMP_CONFIG 115 od -An -tx1 -j "$1" -N 1 "$TMP_CONFIG" 2>/dev/null | tr -d ' \n' 116 } 117 118 # --- capability decoding from raw configuration bytes ---------------------- 119 # The capability list lives above offset 0x40 and needs a 256-byte read, which 120 # requires --allow-sudo. When only 64 bytes are available these decode to 121 # unknown rather than to zero. 122 123 CFG=() 124 load_config() { # dir bytes 125 local dir="$1" count="$2" 126 : > "$TMP_CONFIG" 127 if [[ "$ALLOW_SUDO" == "1" ]]; then 128 sudo -n dd if="$dir/config" bs=1 count="$count" status=none 2>/dev/null > "$TMP_CONFIG" || true 129 else 130 dd if="$dir/config" bs=1 count="$count" status=none 2>/dev/null > "$TMP_CONFIG" || true 131 fi 132 mapfile -t CFG < <(od -An -tx1 -v "$TMP_CONFIG" 2>/dev/null | tr -s ' ' '\n' | grep -E '^[0-9a-f]{2}$' || true) 133 } 134 135 cfg_len() { printf '%s' "${#CFG[@]}"; } 136 137 cfg_u8() { # offset 138 printf '%s' "${CFG[$1]:-}" 139 } 140 141 cfg_u16() { # offset 142 local lo hi 143 lo="$(cfg_u8 "$1")"; hi="$(cfg_u8 "$(($1 + 1))")" 144 [[ -n "$lo" && -n "$hi" ]] || { printf ''; return; } 145 printf '%s' "$(( 16#$lo + 16#$hi * 256 ))" 146 } 147 148 cfg_u32() { # offset 149 local b0 b1 b2 b3 150 b0="$(cfg_u8 "$1")"; b1="$(cfg_u8 "$(($1 + 1))")" 151 b2="$(cfg_u8 "$(($1 + 2))")"; b3="$(cfg_u8 "$(($1 + 3))")" 152 [[ -n "$b0" && -n "$b1" && -n "$b2" && -n "$b3" ]] || { printf ''; return; } 153 printf '%s' "$(( 16#$b0 + 16#$b1 * 256 + 16#$b2 * 65536 + 16#$b3 * `16777216` ))" 154 } 155 156 speed_name() { # pcie link speed encoding 157 case "$1" in 158 1) printf '2.5 GT/s' ;; 2) printf '5.0 GT/s' ;; 3) printf '8.0 GT/s' ;; 159 4) printf '16.0 GT/s' ;; 5) printf '32.0 GT/s' ;; 6) printf '64.0 GT/s' ;; 160 *) printf 'unknown' ;; 161 esac 162 } 163 164 # Walk the standard capability list. Sets CAP_IDS, CAP_PCIE, CAP_MSI, CAP_MSIX 165 # (as "present offset", or empty) so the caller can build JSON. 166 decode_capabilities() { 167 CAP_IDS=""; CAP_PCIE=""; CAP_MSI=""; CAP_MSIX="" 168 if [[ "$(cfg_len)" -lt 256 ]]; then 169 CAP_STATUS="requires-256-byte-config-read" 170 return 171 fi 172 local status 173 status="$(cfg_u16 0x06)" 174 if [[ -z "$status" ]]; then CAP_STATUS="unreadable"; return; fi 175 if (( (status & 0x10) == 0 )); then CAP_STATUS="capability-list-absent"; return; fi 176 local pointer 177 pointer="$(cfg_u8 0x34)" 178 [[ -n "$pointer" ]] || { CAP_STATUS="unreadable"; return; } 179 [[ "$pointer" == "00" ]] && { CAP_STATUS="capability-list-absent"; return; } 180 CAP_STATUS="decoded" 181 local offset=$((16#$pointer)) steps=0 seen="" 182 while (( offset != 0 )); do 183 if (( steps >= 48 )); then CAP_STATUS="too-many-capabilities"; return; fi 184 if (( offset < 0x40 || offset % 4 != 0 || offset + 2 > 256 )); then 185 CAP_STATUS="malformed-capability-pointer"; return 186 fi 187 case ",$seen," in *",$offset,"*) CAP_STATUS="capability-loop"; return ;; esac 188 seen="$seen,$offset" 189 local id next 190 id="$(cfg_u8 "$offset")" 191 next="$(cfg_u8 "$((offset + 1))")" 192 [[ -n "$id" && -n "$next" ]] || { CAP_STATUS="unreadable"; return; } 193 CAP_IDS="$CAP_IDS $id:$offset" 194 case "$id" in 195 05) CAP_MSI="$offset" ;; 196 10) CAP_PCIE="$offset" ;; 197 11) CAP_MSIX="$offset" ;; 198 esac 199 offset=$((16#$next)) 200 steps=$((steps + 1)) 201 done 202 } 203 204 # --- per-device extraction ------------------------------------------------- 205 206 device_profile() { # sysfs device dir 207 local dir="$1" 208 local bdf; bdf="$(basename "$dir")" 209 local domain_hex="${bdf%%:*}" 210 local rest="${bdf#*:}" 211 local bus_hex="${rest%%:*}" 212 local devfn="${rest#*:}" 213 local device_hex="${devfn%%.*}" 214 local function_hex="${devfn#*.}" 215 local domain=$((16#$domain_hex)) bus=$((16#$bus_hex)) 216 local device=$((16#$device_hex)) function=$((16#$function_hex)) 217 218 load_config "$dir" 256 219 decode_capabilities 220 221 local vendor device_id class revision sub_vendor sub_device 222 vendor="$(read_attr "$dir" vendor)" 223 device_id="$(read_attr "$dir" device)" 224 class="$(read_attr "$dir" class)" 225 revision="$(read_attr "$dir" revision)" 226 sub_vendor="$(read_attr "$dir" subsystem_vendor)" 227 sub_device="$(read_attr "$dir" subsystem_device)" 228 229 # Convert the "0x...." sysfs hex strings to numbers for the structured 230 # profile. An unreadable attribute stays null. 231 hex_to_num() { 232 local value="$1" 233 if [[ "$value" == 0x* && ${#value} -le 6 ]]; then 234 printf '%s' "$((16#${value#0x}))" 235 else 236 printf 'null' 237 fi 238 } 239 local vendor_num device_num revision_num sub_vendor_num sub_device_num 240 vendor_num="$(hex_to_num "$vendor")" 241 device_num="$(hex_to_num "$device_id")" 242 revision_num="$(hex_to_num "$revision")" 243 sub_vendor_num="$(hex_to_num "$sub_vendor")" 244 sub_device_num="$(hex_to_num "$sub_device")" 245 246 local command="null" status="null" 247 local raw_cmd; raw_cmd="$(od -An -tx4 -j 4 -N 4 "$TMP_CONFIG" 2>/dev/null | tr -d ' \n')" 248 if [[ -n "$raw_cmd" ]]; then 249 command="$((16#$raw_cmd & 0xffff))" 250 status="$(( (16#$raw_cmd >> 16) & 0xffff ))" 251 fi 252 253 # BARs from the kernel resource file: base, size, and flags are already 254 # decoded by Linux, so they are a Linux-observed fact. 255 local bars="[]" 256 local index line start end flags size kind prefetch is64 257 for index in 0 1 2 3 4 5; do 258 line="$(read_resource_line "$dir" "$index" || true)" 259 [[ -n "$line" ]] || continue 260 read -r start end flags <<< "$line" 261 if [[ "$end" == "0x0000000000000000" ]]; then 262 continue 263 fi 264 start=$((start)); end=$((end)); flags=$((flags)) 265 size=$((end - start + 1)) 266 kind="memory"; prefetch=false; is64=false 267 if (( flags & 0x100 )); then kind="io"; fi 268 if (( flags & 0x2000 )); then prefetch=true; fi 269 if (( flags & 0x100000 )); then is64=true; fi 270 bars="$(jq -c --argjson i "$index" --argjson base "$start" --arg base_hex "$(printf '0x%x' "$start")" \ 271 --argjson size "$size" --arg kind "$kind" --argjson prefetch "$prefetch" --argjson is64 "$is64" \ 272 '. + [{index:$i, base:$base, base_hex:$base_hex, size:$size, kind:$kind, prefetchable:$prefetch, is_64_bit:$is64}]' <<<"$bars")" 273 done 274 275 local pcie="null" msi="null" msix="null" 276 if [[ -n "$CAP_PCIE" ]]; then 277 local cap lc ls dev_caps max_speed max_width cur_speed cur_width dtype 278 dev_caps="$(cfg_u32 "$((CAP_PCIE + 4))")" 279 cap="$(cfg_u16 "$((CAP_PCIE + 2))")" 280 dtype=$(( (cap >> 4) & 0x0f )) 281 lc="$(cfg_u32 "$((CAP_PCIE + 0x0c))")" 282 ls="$(cfg_u16 "$((CAP_PCIE + 0x12))")" 283 max_speed=$((lc & 0x0f)); max_width=$(( (lc >> 4) & 0x3f )) 284 cur_speed=$((ls & 0x0f)); cur_width=$(( (ls >> 4) & 0x3f )) 285 pcie="$(jq -n --argjson ver "$((cap & 0x0f))" --argjson dtype "$dtype" \ 286 --argjson max_payload "$((128 << (dev_caps & 7)))" \ 287 --arg max_speed "$(speed_name "$max_speed")" --argjson max_width "$max_width" \ 288 --arg cur_speed "$(speed_name "$cur_speed")" --argjson cur_width "$cur_width" \ 289 '{present:true, version:$ver, device_type:$dtype, max_payload_bytes:$max_payload, 290 max_speed:$max_speed, max_width:$max_width, current_speed:$cur_speed, current_width:$cur_width}')" 291 fi 292 if [[ -n "$CAP_MSI" ]]; then 293 local mc 294 mc="$(cfg_u16 "$((CAP_MSI + 2))")" 295 msi="$(jq -n --argjson enabled "$(( (mc & 1) != 0 ))" --argjson is64 "$(( (mc & 0x80) != 0 ))" \ 296 --argjson maskable "$(( (mc & 0x100) != 0 ))" \ 297 --argjson capable "$(( 1 << ((mc >> 1) & 7) ))" \ 298 '{present:true, enabled:$enabled, is_64_bit:$is64, maskable:$maskable, capable_vectors:$capable}')" 299 fi 300 if [[ -n "$CAP_MSIX" ]]; then 301 local mc table pba 302 mc="$(cfg_u16 "$((CAP_MSIX + 2))")" 303 table="$(cfg_u32 "$((CAP_MSIX + 4))")" 304 pba="$(cfg_u32 "$((CAP_MSIX + 8))")" 305 msix="$(jq -n --argjson enabled "$(( (mc & 0x8000) != 0 ))" \ 306 --argjson masked "$(( (mc & 0x4000) != 0 ))" --argjson vectors "$(( (mc & 0x7ff) + 1 ))" \ 307 --argjson bir "$((table & 7))" --argjson toff "$((table & ~7))" \ 308 --argjson pbir "$((pba & 7))" --argjson poff "$((pba & ~7))" \ 309 '{present:true, enabled:$enabled, function_masked:$masked, vectors:$vectors, 310 table_bir:$bir, table_offset:$toff, pba_bir:$pbir, pba_offset:$poff}')" 311 fi 312 313 local iommu_group="" numa="" driver="" firmware="" irq="" msi_count=0 314 [[ -e "$dir/iommu_group" ]] && iommu_group="$(basename "$(readlink -f "$dir/iommu_group")")" 315 numa="$(read_attr "$dir" numa_node)" 316 [[ -e "$dir/driver" ]] && driver="$(basename "$(readlink -f "$dir/driver")")" 317 [[ -e "$dir/firmware_node" ]] && firmware="$(readlink -f "$dir/firmware_node")" 318 irq="$(read_attr "$dir" irq)" 319 if [[ -d "$dir/msi_irqs" ]]; then 320 msi_count="$(find "$dir/msi_irqs" -mindepth 1 -maxdepth 1 2>/dev/null | wc -l | tr -d ' ')" 321 fi 322 323 local cur_link_speed max_link_speed cur_link_width max_link_width 324 cur_link_speed="$(read_attr "$dir" current_link_speed)" 325 max_link_speed="$(read_attr "$dir" max_link_speed)" 326 cur_link_width="$(read_attr "$dir" current_link_width)" 327 max_link_width="$(read_attr "$dir" max_link_width)" 328 329 local cap_ids_json="[]" 330 if [[ -n "$CAP_IDS" ]]; then 331 local pair id off 332 for pair in $CAP_IDS; do 333 id="${pair%%:*}"; off="${pair#*:}" 334 cap_ids_json="$(jq -c --argjson id "$((16#$id))" --argjson off "$off" \ 335 '. + [{id:$id, offset:$off}]' <<<"$cap_ids_json")" 336 done 337 fi 338 339 jq -n \ 340 --arg bdf "$bdf" --argjson domain "$domain" --argjson bus "$bus" \ 341 --argjson device "$device" --argjson function "$function" \ 342 --argjson vendor "$vendor_num" --argjson device_id "$device_num" \ 343 --arg vendor_hex "$vendor" --arg device_hex "$device_id" \ 344 --arg class "$class" --argjson revision "$revision_num" \ 345 --argjson sub_vendor "$sub_vendor_num" --argjson sub_device "$sub_device_num" \ 346 --argjson command "$command" --argjson status "$status" \ 347 --argjson bars "$bars" --arg cap_status "$CAP_STATUS" --argjson cap_ids "$cap_ids_json" \ 348 --argjson pcie "$pcie" --argjson msi "$msi" --argjson msix "$msix" \ 349 --argjson config_bytes "$(cfg_len)" \ 350 --argjson iommu_group "${iommu_group:-null}" --argjson numa "${numa:-null}" \ 351 --arg driver "$driver" --arg firmware "$firmware" --argjson irq "${irq:-null}" \ 352 --argjson msi_count "$msi_count" \ 353 --arg cur_link_speed "$cur_link_speed" --arg max_link_speed "$max_link_speed" \ 354 --arg cur_link_width "$cur_link_width" --arg max_link_width "$max_link_width" \ 355 'def obs(v; s; m; li): {value:v, source:s, method:m, linux_interpreted:li, native_verified:false}; 356 def unk(r): {value:null, source:null, method:null, linux_interpreted:false, native_verified:false, state:"unknown", reason:r}; 357 { 358 bdf:$bdf, 359 vendor_hex:$vendor_hex, 360 device_hex:$device_hex, 361 location:{domain:$domain, bus:$bus, device:$device, function:$function, 362 source:"linux-sysfs", method:"sysfs device path", linux_interpreted:true}, 363 vendor_id:obs($vendor; "linux-sysfs"; "read vendor"; true), 364 device_id:obs($device_id; "linux-sysfs"; "read device"; true), 365 class:obs($class; "linux-sysfs"; "read class"; true), 366 revision:obs($revision; "linux-sysfs"; "read revision"; true), 367 subsystem_vendor_id:obs($sub_vendor; "linux-sysfs"; "read subsystem_vendor"; true), 368 subsystem_id:obs($sub_device; "linux-sysfs"; "read subsystem_device"; true), 369 command:obs($command; "linux-sysfs"; "raw config dword at 0x04"; false), 370 status:obs($status; "linux-sysfs"; "raw config dword at 0x04"; false), 371 bars:($bars | map(. + {source:"linux-sysfs", method:"read resource (kernel-sized)", linux_interpreted:true, native_verified:false})), 372 bar_size_note:"kernel resource size; native AIENOS has not independently decoded it", 373 capability_status:$cap_status, 374 capabilities:$cap_ids, 375 pcie:(if $pcie == null then unk($cap_status) else ($pcie + {source:"linux-sysfs", method:"raw config capability decode", linux_interpreted:false, native_verified:false}) end), 376 msi:(if $msi == null then unk($cap_status) else ($msi + {source:"linux-sysfs", method:"raw config capability decode", linux_interpreted:false, native_verified:false}) end), 377 msix:(if $msix == null then unk($cap_status) else ($msix + {source:"linux-sysfs", method:"raw config capability decode", linux_interpreted:false, native_verified:false}) end), 378 iommu_group:(if $iommu_group == null then unk("no iommu_group attribute") else {value:$iommu_group, source:"linux-sysfs", method:"readlink iommu_group", linux_interpreted:true, native_verified:false} end), 379 numa_node:(if $numa == null then unk("no numa_node attribute") else {value:$numa, source:"linux-sysfs", method:"read numa_node", linux_interpreted:true, native_verified:false} end), 380 driver:(if $driver == "" then unk("no driver bound") else {value:$driver, source:"linux-sysfs", method:"readlink driver", linux_interpreted:true, native_verified:false} end), 381 firmware_node:(if $firmware == "" then unk("no ACPI firmware node") else {value:$firmware, source:"linux-sysfs", method:"readlink firmware_node", linux_interpreted:true, native_verified:false} end), 382 irq:(if $irq == null then unk("no irq attribute") else {value:$irq, source:"linux-sysfs", method:"read irq", linux_interpreted:true, native_verified:false} end), 383 msi_irq_count:(if $msi_count == 0 then unk("no msi_irqs") else {value:$msi_count, source:"linux-sysfs", method:"count msi_irqs", linux_interpreted:true, native_verified:false} end), 384 current_link_speed:(if $cur_link_speed == "" then unk("not exposed") else {value:$cur_link_speed, source:"linux-sysfs", method:"read current_link_speed", linux_interpreted:true, native_verified:false} end), 385 max_link_speed:(if $max_link_speed == "" then unk("not exposed") else {value:$max_link_speed, source:"linux-sysfs", method:"read max_link_speed", linux_interpreted:true, native_verified:false} end), 386 current_link_width:(if $cur_link_width == "" then unk("not exposed") else {value:$cur_link_width, source:"linux-sysfs", method:"read current_link_width", linux_interpreted:true, native_verified:false} end), 387 max_link_width:(if $max_link_width == "" then unk("not exposed") else {value:$max_link_width, source:"linux-sysfs", method:"read max_link_width", linux_interpreted:true, native_verified:false} end), 388 config_bytes_read:$config_bytes 389 }' 390 } 391 392 # --- firmware topology ----------------------------------------------------- 393 394 acpi_presence() { 395 local dir="/sys/firmware/acpi/tables" 396 local table list="[]" 397 [[ -d "$dir" ]] || { printf '[]'; return; } 398 for table in MCFG IORT PPTT SPCR GTDT APIC DSDT TPM2 WSMT; do 399 if [[ -e "$dir/$table" ]]; then 400 local size digest 401 size="$(stat -c %s "$dir/$table" 2>/dev/null || printf 'null')" 402 digest="" 403 if [[ "$ALLOW_SUDO" == "1" ]]; then 404 digest="$(sudo -n sha256sum "$dir/$table" 2>/dev/null | awk '{print $1}' || true)" 405 fi 406 list="$(jq -c --arg name "$table" --argjson size "${size:-null}" --arg digest "$digest" \ 407 '. + [{name:$name, size_bytes:$size, sha256:(if $digest == "" then null else $digest end)}]' <<<"$list")" 408 fi 409 done 410 printf '%s' "$list" 411 } 412 413 # Parse the MCFG base-address allocation entries: each maps a PCI segment to an 414 # ECAM base and a bus range. Requires a privileged read-only table copy. 415 mcfg_segments() { 416 local table="/sys/firmware/acpi/tables/MCFG" 417 if [[ "$ALLOW_SUDO" != "1" ]]; then 418 printf 'null'; return 419 fi 420 if [[ ! -e "$table" ]]; then 421 printf 'null'; return 422 fi 423 : > "$TMP_ACPI" 424 sudo -n dd if="$table" bs=1 status=none 2>/dev/null > "$TMP_ACPI" || { printf 'null'; return; } 425 local length 426 length="$(od -An -tu4 -j 4 -N 4 "$TMP_ACPI" 2>/dev/null | tr -d ' \n')" 427 [[ -n "$length" ]] || { printf 'null'; return; } 428 local count=$(( (length - 44) / 16 )) 429 local entries="[]" i off 430 for (( i = 0; i < count; i++ )); do 431 off=$((44 + i * 16)) 432 local base_lo base_hi base segment start end 433 base_lo="$(od -An -tu4 -j "$off" -N 4 "$TMP_ACPI" 2>/dev/null | tr -d ' \n')" 434 base_hi="$(od -An -tu4 -j "$((off + 4))" -N 4 "$TMP_ACPI" 2>/dev/null | tr -d ' \n')" 435 segment="$(od -An -tu2 -j "$((off + 8))" -N 2 "$TMP_ACPI" 2>/dev/null | tr -d ' \n')" 436 start="$(od -An -tu1 -j "$((off + 10))" -N 1 "$TMP_ACPI" 2>/dev/null | tr -d ' \n')" 437 end="$(od -An -tu1 -j "$((off + 11))" -N 1 "$TMP_ACPI" 2>/dev/null | tr -d ' \n')" 438 base=$(( base_lo + base_hi * `4294967296` )) 439 entries="$(jq -c --argjson seg "$segment" --argjson base "$base" \ 440 --argjson start "$start" --argjson end "$end" \ 441 --arg base_hex "$(printf '0x%x' "$base")" \ 442 '. + [{segment:$seg, ecam_base:$base, ecam_base_hex:$base_hex, start_bus:$start, end_bus:$end}]' <<<"$entries")" 443 done 444 printf '%s' "$entries" 445 } 446 447 bridge_topology() { 448 local list="[]" dir class 449 for dir in /sys/bus/pci/devices/*; do 450 [[ -r "$dir/class" ]] || continue 451 class="$(read_attr "$dir" class)" 452 case "$class" in 453 0x0604*|0x0600*) ;; # PCI bridge, host bridge 454 *) continue ;; 455 esac 456 list="$(jq -c --arg bdf "$(basename "$dir")" --arg class "$class" \ 457 '. + [{bdf:$bdf, class:$class, source:"linux-sysfs", linux_interpreted:true}]' <<<"$list")" 458 done 459 jq -c 'sort_by(.bdf)' <<<"$list" 460 } 461 462 gb10_devices() { 463 local list="[]" dir vendor device_id 464 for dir in /sys/bus/pci/devices/*; do 465 [[ -r "$dir/vendor" && -r "$dir/device" ]] || continue 466 vendor="$(read_attr "$dir" vendor)" 467 device_id="$(read_attr "$dir" device)" 468 if [[ "$vendor" == "$GB10_VENDOR" && "$device_id" == "$GB10_DEVICE" ]]; then 469 list="$(jq -c --argjson dev "$(device_profile "$dir")" '. + [$dev]' <<<"$list")" 470 fi 471 done 472 jq -c 'sort_by(.bdf)' <<<"$list" 473 } 474 475 # --- assemble -------------------------------------------------------------- 476 477 DEVICES="$(gb10_devices)" 478 DEVICE_COUNT="$(jq 'length' <<<"$DEVICES")" 479 480 if [[ "$EMIT_TIMESTAMP" == "1" ]]; then 481 TIMESTAMP_FIELD="$GENERATED_AT" 482 else 483 TIMESTAMP_FIELD="" 484 fi 485 486 GIT_COMMIT="" 487 if git -C "$(dirname "$0")/.." rev-parse HEAD >/dev/null 2>&1; then 488 GIT_COMMIT="$(git -C "$(dirname "$0")/.." rev-parse HEAD)" 489 fi 490 491 PROFILE="$(jq -n \ 492 --arg schema "$SCHEMA" \ 493 --arg product "$(read_attr /sys/class/dmi/id product_name)" \ 494 --arg sys_vendor "$(read_attr /sys/class/dmi/id sys_vendor)" \ 495 --arg commit "$GIT_COMMIT" \ 496 --argjson sudo "$([[ "$ALLOW_SUDO" == "1" ]] && echo true || echo false)" \ 497 --arg timestamp "${TIMESTAMP_FIELD}" \ 498 --argjson cmdline_iommu "$(tr ' ' '\n' < /proc/cmdline 2>/dev/null | grep -i iommu | jq -Rsc 'split("\n") | map(select(length>0))' || printf '[]')" \ 499 --argjson devices "$DEVICES" \ 500 --argjson acpi "$(acpi_presence)" \ 501 --argjson mcfg "$(mcfg_segments)" \ 502 --argjson bridges "$(bridge_topology)" \ 503 '{ 504 schema:$schema, 505 generated_at_utc:(if $timestamp == "" then null else $timestamp end), 506 collector:{name:"scripts/gb10_profile.sh", git_commit:$commit, read_only:true, sudo_used:$sudo}, 507 platform:{product_name:$product, system_vendor:$sys_vendor, source:"linux-sysfs", linux_interpreted:true}, 508 machine_identity_note:"Linux-observed facts only; not a native AIENOS proof.", 509 iommu_kernel_parameters:$cmdline_iommu, 510 acpi_tables:$acpi, 511 mcfg_segments:$mcfg, 512 pci_bridge_topology:$bridges, 513 gb10_device_count:$devices|length, 514 gb10_devices:$devices 515 }' | jq -S '.')" 516 517 printf '%s' "$PROFILE" > "$TMP_PROFILE" 518 if [[ "$JSON_OUT" == "-" ]]; then 519 printf '%s\n' "$PROFILE" 520 else 521 printf '%s\n' "$PROFILE" > "$JSON_OUT" 522 fi 523 524 { 525 echo "# GB10 read-only hardware characterization (Linux-observed)" 526 echo 527 echo "schema: $SCHEMA" 528 echo "collector commit: ${GIT_COMMIT:-unknown}" 529 echo "sudo used for read-only config/ACPI: $([[ "$ALLOW_SUDO" == "1" ]] && echo yes || echo no)" 530 echo "GB10 devices found: $DEVICE_COUNT" 531 echo 532 if [[ "$DEVICE_COUNT" == "0" ]]; then 533 echo "No NVIDIA 10de:2e12 device is present in /sys/bus/pci/devices." 534 else 535 jq -r '.gb10_devices[] | 536 "## \(.bdf)", 537 " vendor:device \(.vendor_hex):\(.device_hex) class \(.class.value)", 538 " location domain=\(.location.domain) bus=\(.location.bus) device=\(.location.device) function=\(.location.function)", 539 " iommu_group \(.iommu_group.value // "unknown")", 540 " driver \(.driver.value // "none")", 541 " numa_node \(.numa_node.value // "unknown")", 542 " firmware_node \(.firmware_node.value // "unknown")", 543 " pcie link current \(.current_link_speed.value // "?") x\(.current_link_width.value // "?") max \(.max_link_speed.value // "?") x\(.max_link_width.value // "?")", 544 " capability status \(.capability_status)", 545 " BARs:" , 546 ( .bars[] | " [\(.index)] \(.kind) base=\(.base_hex) size=\(.size) 64bit=\(.is_64_bit) prefetch=\(.prefetchable)" ), 547 ""' "$TMP_PROFILE" 548 fi 549 echo "The structured profile records source, method, whether Linux interpreted" 550 echo "the value, and whether AIENOS independently verified it. No observation" 551 echo "here is a native AIENOS proof, and none of it involved a GPU command." 552 } > "$REPORT_OUT" 553 rm -f "$TMP_PROFILE"