#!/usr/bin/env python3 """Run the original GV100 PMU unbind, the address-space object's function at +48. The environment is that of tools/check_gpu_pmu_ls_start_binary.py, executed unchanged up to and including its traced V100 Load case: the PMU class is constructed, initialised and started, so the address-space object at PMU+c20 carries the function table its creator _nv006738rm bound. Executed original code (chip HAL 0x23, RM HAL 2): _nv052303rm(gpu, space), the function the page-level walker's root update reaches through _nv052304rm when the last mapping of the PMU address space is removed (class Unload), with the bind wait at +58 _nv052288rm, its body +60 _nv052284rm and the interrupt clear PMU+ac0 _nv052215rm. Varied: the request word 0x10a0a4, the bind status words 0x10ac0c and 0x10a0dc, the time checks, the GPU bytes +917, +918, +919, +926 and +4de4, the Falcon byte +3af and the Falcon mode word +650. No hardware. """ import hashlib import json from pathlib import Path import sys HERE = Path(__file__).resolve() START = HERE.with_name("check_gpu_pmu_ls_start_binary.py") _text = START.read_text() _end = 'if "--traced" in sys.argv:' assert _end in _text __file__ = str(START) exec(compile(_text[:_text.index(_end)], str(START), "exec"), globals()) # noqa: S102 __file__ = str(HERE) SPACE = PMU + 0xc20 assert pointer(SPACE + 0x48) == sym("_nv052303rm"), hex(pointer(SPACE + 0x48)) assert pointer(SPACE + 0x58) == sym("_nv052288rm") and pointer(SPACE + 0x60) == sym("_nv052284rm") LOADED = pmu_snapshot() GPU_SAVED = {offset: byte(GPU + offset) for offset in (0x917, 0x918, 0x919, 0x926, 0x4de4, 0x998)} assert GPU_SAVED[0x998] == 0 urows = [] def unbind(reads, checks=(), **settings): pmu_restore(LOADED) for offset, value in GPU_SAVED.items(): b(GPU + offset, value) del trace[:], diag[:], asserts[:] for key, value in settings.items(): if key.startswith("g"): b(GPU + int(key[1:], 16), value) elif key == "f3af": b(F_PMU + 0x3af, value) elif key == "f650": d(F_PMU + 0x650, value) else: raise KeyError(key) state.update(reads={offset: list(values) for offset, values in reads.items()}, checks=list(checks), counts={}, fail={}, idle_checks=0) status = call("_nv052303rm", GPU, SPACE) left = len(state["checks"]) events = [token for token in trace if token.split(":")[0] in ("r", "w", "tc")] urows.append("|".join(( "U", " ".join(f"{key}={value:x}" for key, value in settings.items()), " ".join(f"{offset:x}=" + ",".join(f"{value:x}" for value in values) for offset, values in reads.items()), ",".join(f"{value:x}" for value in list(checks)[:len(checks) - left]), f"{status & 0xffffffff:x}", " ".join(events)))) return status DONE = {0x10a0a4: [0], 0x10ac0c: [1], 0x10a0dc: [0xe003f]} assert unbind(DONE) == 0 # The request word keeps its other bits. for value in (1, 0xfffffffe, 0xffffffff, 0x80000000, 0x12345678): unbind({**DONE, 0x10a0a4: [value]}) # Bind status: done at once, or the state word decides. for done in (0, 2, 0xfffffffe, 0xffffffff): for states, checks in (([0xe003f], ()), ([0xed03d, 0xe003f], (0,)), ([0x2000, 0x2002], (0,)), ([0x5000, 0x5002], (0,)), ([0x2000, 0x5000, 0x3000, 2], (0, 0, 0)), ([0], (0x65,)), ([0x2000], (0, 0x65)), ([0x5000], (0x56,)), ([0, 0, 2], (0, 0)), ([0xfffffffd], (0, 0, 0x65)), ([0xffffffff], ())): unbind({0x10a0a4: [0], 0x10ac0c: [done], 0x10a0dc: states}, checks) # GPU bytes that skip the wait, and the Falcon byte that skips its body. for key in ("g917", "g918", "g919", "g926"): unbind(DONE, **{key: 1}) unbind({0x10a0a4: [4], 0x10ac0c: [0], 0x10a0dc: [0]}, (0x65,), **{key: 1}) for reads, checks in ((DONE, ()), ({0x10a0a4: [0], 0x10ac0c: [0], 0x10a0dc: [0]}, (0x65,))): unbind(reads, checks, f3af=1) # Falcon+650: 2 and 3 do nothing; 0 and 4 skip the interrupt clear. for mode in (0, 2, 3, 4): unbind(DONE, f650=mode) unbind({0x10a0a4: [0], 0x10ac0c: [0], 0x10a0dc: [0x2000, 0x2002]}, (0,), f650=mode) # GPU+4de4 alone (the space object's byte +80 is clear) changes nothing. assert byte(SPACE + 0x80) == 0 unbind(DONE, g4de4=1) oracle = "\n".join(urows) + "\n" out = ROOT / "target/gpu-stage" (out / "original-pmu-unbind.txt").write_text(oracle) report = { "original_sha256": DIGEST, "chip_hal": "0x23", "rm_hal": 2, "function": "_nv052303rm(gpu, PMU+c20) with _nv052288rm, _nv052284rm, _nv052215rm", "cases": len(urows), "oracle": "target/gpu-stage/original-pmu-unbind.txt", "oracle_sha256": hashlib.sha256(oracle.encode()).hexdigest(), "statuses": sorted({row.split("|")[4] for row in urows}), } (ROOT / "reports/gpu-pmu-unbind-original.json").write_text(json.dumps(report, indent=2) + "\n") print(f"{len(urows)} cases; oracle sha256 {report['oracle_sha256']}")