mirror of
https://github.com/QuixiAI/nvdriver.git
synced 2026-12-06 06:28:39 +00:00
92 lines
4.1 KiB
Python
92 lines
4.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Decode PMC_BOOT_42 from a first-open inventory and gate on the result.
|
|
|
|
`src/nvidia/src/gpu/chip_arch.rs` reproduces `_nv030823rm`'s decode of
|
|
(PMC_BOOT_0, PMC_BOOT_42); this is the same arithmetic on the inventory word
|
|
`000a00` that `hardware_inventory=1` logs, so a run can assert the card it
|
|
tested instead of reading the report by hand.
|
|
|
|
tools/arch_gate.py reports/hardware-first-open-<label>.json \
|
|
--expect-arch 0x1b --forbid-impl 0xb
|
|
|
|
Exit 0 when the word is present and the expectations hold, 1 otherwise.
|
|
"""
|
|
import argparse
|
|
import json
|
|
from pathlib import Path
|
|
|
|
# 6-bit PMC_BOOT_42 architecture -> family, as ArchFamily::from_boot42_arch.
|
|
FAMILIES = {0x11: "Maxwell1", 0x12: "Maxwell2", 0x13: "Pascal", 0x14: "Volta",
|
|
0x16: "Turing", 0x17: "Ampere", 0x18: "Hopper", 0x19: "Ada",
|
|
0x1a: "Blackwell1", 0x1b: "Blackwell2", 0x1c: "Rubin"}
|
|
|
|
|
|
def decode(boot42):
|
|
"""The decoded `000a00` word, with the fields chip_arch::BootId reads."""
|
|
arch = (boot42 >> 24) & 0x3f
|
|
return {"word_000a00": f"{boot42:08x}", "arch": arch, "arch_hex": f"{arch:02x}",
|
|
"family": FAMILIES.get(arch), "implementation": (boot42 >> 20) & 0xf,
|
|
"chip": (boot42 >> 20) & 0x3ff,
|
|
"major_rev": (boot42 >> 16) & 0xf, "minor_rev": (boot42 >> 12) & 0xf,
|
|
"minor_ext_rev": (boot42 >> 8) & 0xf}
|
|
|
|
|
|
def from_inventory(inventory, expect_arch=None, forbid_impl=None):
|
|
"""Decode the inventory's `000a00` and apply the caller's expectations."""
|
|
if not isinstance(inventory, dict):
|
|
return {"passed": False, "reason": "the inventory is not a mapping"}
|
|
word = inventory.get("000a00")
|
|
if word is None:
|
|
return {"passed": False, "reason": "the inventory has no 000a00 (PMC_BOOT_42)"}
|
|
if not isinstance(word, str):
|
|
return {"passed": False, "reason": f"000a00 is not a hex string: {word!r}"}
|
|
try:
|
|
raw = int(word.strip(), 16)
|
|
except ValueError:
|
|
return {"passed": False, "reason": f"000a00 is not valid hexadecimal: {word!r}"}
|
|
if raw < 0 or raw > 0xffff_ffff:
|
|
return {"passed": False, "reason": f"000a00 is out of 32-bit range: {word!r}"}
|
|
if raw == 0 or raw == 0xffff_ffff or (raw >> 20) == 0xbad:
|
|
return {
|
|
"passed": False,
|
|
"word_000a00": f"{raw:08x}",
|
|
"reason": f"000a00 is a bus-error/invalid readback ({raw:08x})",
|
|
}
|
|
result = decode(raw)
|
|
reasons = []
|
|
if expect_arch is not None and result["arch"] != expect_arch:
|
|
reasons.append(f"arch {result['arch_hex']} is not the expected {expect_arch:02x}")
|
|
if forbid_impl is not None and result["implementation"] == forbid_impl:
|
|
reasons.append(f"implementation {result['implementation']:x} is the forbidden "
|
|
f"{forbid_impl:x}")
|
|
result["passed"] = not reasons
|
|
if reasons:
|
|
result["reason"] = "; ".join(reasons)
|
|
return result
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("report", type=Path, help="a hardware-first-open-*.json report")
|
|
parser.add_argument("--expect-arch", type=lambda text: int(text, 0), metavar="N",
|
|
help="require this 6-bit PMC_BOOT_42 architecture (0x1b = Blackwell2)")
|
|
parser.add_argument("--forbid-impl", type=lambda text: int(text, 0), metavar="N",
|
|
help="fail if the implementation is N (0xb = GB20y/Tegra)")
|
|
arguments = parser.parse_args()
|
|
try:
|
|
report = json.loads(arguments.report.read_text(encoding="utf-8"))
|
|
except (OSError, UnicodeError, json.JSONDecodeError) as exc:
|
|
print(json.dumps({"passed": False, "reason": f"failed to read report: {exc}"}, indent=2))
|
|
raise SystemExit(1)
|
|
if not isinstance(report, dict):
|
|
print(json.dumps({"passed": False, "reason": "report root is not a JSON object"}, indent=2))
|
|
raise SystemExit(1)
|
|
result = from_inventory(report.get("inventory") or {},
|
|
arguments.expect_arch, arguments.forbid_impl)
|
|
print(json.dumps(result, indent=2))
|
|
raise SystemExit(0 if result["passed"] else 1)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|