Files
nvdriver/tools/check_gpu_pmu_service_binary.py
nvidia-driver-rs 4526e6a816 Baseline: validated 30/30 tree with passing Level 7 hardware regression
- Updated tools/post_reboot.sh to check kernel oops taint bit and stuck driver tasks instead of <86400s uptime
- Level 7 hardware regression passed on 0000:b3:00.0 (module 37e6fa430835eee2b426019db3ad70eeb7a9e9070c09c84bd9b973cf56cbe529, 107 inventory words, 0 static mismatches, CUDA baseline verified before and after)
- Updated .gitignore to exclude build archives (*.a, *.rlib), __pycache__, and raw trace dumps
2026-11-23 23:48:38 +00:00

568 lines
26 KiB
Python

#!/usr/bin/env python3
"""Run the original GV100 PMU interrupt service, event dispatch and unload.
The environment is that of tools/check_gpu_pmu_fbq_binary.py (its setup part
is executed unchanged): the PMU class constructed, initialised and started,
the surface backed by emulator memory. Here the interrupt service pass
fixture (_nv037739rm) continues in the PMU class's own interrupt service
function, as the interrupt dispatcher calls it, instead of in the message
function, so the whole original path above the message function runs.
Executed original code (chip HAL 0x23, RM HAL 2):
service the class function _nv052477rm (vtable +408; record engine 0xe,
kernel-side state through _nv051829rm), PMU+290 _nv052485rm (GPU
bytes +915, +917, +918/+919, +926), PMU+288 _nv052510rm with the
pending word _nv028510rm -> _nv028663rm (IRQSTAT & IRQMASK &
IRQDEST), PMU+298 _nv052467rm (bit 5), the mailbox marker test,
_nv052479rm -> the transport's message function _nv052433rm,
PMU+b58 _nv052008rm, PMU+ac0 _nv052215rm (IRQSCLR), the queue
test and the IRQSSET write, and the second pending word.
messages _nv052433rm: INIT branch, and the message loop with the reader
_nv028644rm (_nv013398rm, _nv013399rm, _nv013410rm, _nv013403rm,
_nv013384rm), the validity test _nv051827rm, the reply branch
and the event branch _nv052036rm (handler list at PMU+d98, always
empty: no function of the object stores a non-null pointer there)
and _nv052457rm with its statistics _nv052459rm.
requests _nv052461rm / _nv052441rm on both command queues and
_nv043191rm -> _nv016743rm, with the awaited sequence stored at
transport +9b0 and every wait pass entering the service above.
unload the class's Unload _nv052517rm with _nv052000rm (the detach
command of unit 0x0f on the high-priority queue, PMU+aa0
_nv052235rm, the client list functions, the kernel-side object's
_nv051831rm, the transport's _nv052443rm), _nv015277rm, the
surface functions _nv052598rm, _nv052624rm, _nv052322rm; and the
event function _nv021459rm that ends the detach wait.
Fixture-supplied: everything the queue harness supplies, and: the event
handlers of the other engines (41 functions; each records its name and the
message), the timer read _nv059599rm, the halt handler _nv052476rm (bit 4),
the MemorySystem function _nv044310rm, the reset _nv052253rm that follows a
failed detach, an OBJBIF object for the word the unload stores at +b9c. The firmware side is a fixture: message elements are
built here to meet or to miss, one at a time, each check the original
applies. No hardware.
A message whose length field is 0 while its size is above 4 is recorded as
status `skew`: the original finishes the element with the header and copies
the "body" from the next element, here until the positions meet again.
A message the original cannot get past (it reads the same element again
without end) is run with an instruction limit and recorded as status `loop`
with the accesses of its first iteration. A first message that is not an
accepted INIT leaves the queues unbuilt; the service then calls through
a null function pointer of the unbuilt message queue, which is recorded as
status `fault` with the accesses up to that call.
"""
import hashlib
import json
from pathlib import Path
import sys
from unicorn import UcError
HERE = Path(__file__).resolve()
FBQ = HERE.with_name("check_gpu_pmu_fbq_binary.py")
_text = FBQ.read_text()
_end = "# ------------------------------------------------------------------- INIT"
assert _end in _text
__file__ = str(FBQ)
exec(compile(_text[:_text.index(_end)], str(FBQ), "exec"), globals()) # noqa: S102
__file__ = str(HERE)
HPQ = 0x200
REC = SCRATCH + 0x2000
KERNEL = pointer(PMU + 0xb08) - 8
READ_BACK.add(0x10a800)
LIMIT = 1500000
rows, counts = [], {}
hstat = {"value": 0}
tick = [0x1000]
delivered = []
# (unit << 8 | type) -> event function, as _nv052457rm selects it; the sweep
# below executes the original for every key and checks this table.
EVENT_FUNCTIONS = {
0x300: "_nv043072rm", 0x301: "_nv043075rm", 0x302: "_nv043073rm", 0x303: "_nv043074rm",
0x304: "_nv043070rm", 0x305: "_nv043071rm", 0x306: "_nv043069rm", 0x307: "_nv043076rm",
0x800: "_nv056653rm", 0x900: "_nv029236rm", 0x901: "_nv029235rm", 0x902: "_nv029234rm",
0xd00: "_nv020703rm", 0xd01: "_nv020704rm", 0xf00: "_nv021461rm", 0xf01: "_nv021459rm",
0xf02: "_nv021460rm", 0xf03: "_nv021463rm", 0xf04: "_nv021464rm", 0x1100: "_nv051095rm",
0x1101: "_nv051096rm", 0x1300: "_nv050826rm", 0x1301: "_nv050835rm", 0x1302: "_nv050836rm",
0x1303: "_nv050834rm", 0x1304: "_nv050831rm", 0x1305: "_nv050832rm", 0x1306: "_nv050827rm",
0x1307: "_nv050833rm", 0x1308: "_nv050828rm", 0x1309: "_nv050830rm", 0x1400: "_nv059137rm",
0x1401: "_nv059136rm", 0x1600: "_nv024042rm", 0x1800: "_nv051625rm", 0x1801: "_nv051624rm",
0x1b00: "_nv017675rm", 0x1b01: "_nv017674rm", 0x1b02: "_nv017673rm", 0x1c00: "_nv051084rm",
}
ORIGINAL_HANDLER = "_nv021459rm" # the PMU class's own: clears PMU+f70
def _handler(name):
def function(a):
emit(f"h:{name[3:9]}:{bytes(cpu.mem_read(a[2], 0x14)).hex()}")
return None if name == ORIGINAL_HANDLER else hstat["value"]
return function
for _name in sorted(set(EVENT_FUNCTIONS.values())):
conditional(_name, _handler(_name))
@hook("_nv059599rm")
def timer(a, low):
tick[0] += 0x10
emit(f"tm:{tick[0]:x}")
return tick[0]
@hook("_nv052476rm")
def halt_handler(a, low):
emit("halt")
return 0
@hook("_nv044310rm")
def memory_system(a, low):
emit(f"ms:{low[2]:x}")
return 0
@hook("_nv052253rm")
def reset_sequence(a, low):
"""The reset a failed detach ends with. With the Falcon running it is the
hold and release sequence tools/check_gpu_acr_unload_binary.py executes
(halt request, engine reset); here only the call is recorded."""
assert a[1] == PMU + 0xa00
emit("rst")
return 0
def bounded(name, *arguments):
"""call() with an instruction limit; None when the limit ends the run."""
for register, argument in zip(ARGUMENTS, arguments):
cpu.reg_write(register, argument)
rsp = STACK + 0xfff00
cpu.reg_write(UC_X86_REG_RSP, rsp)
cpu.reg_write(UC_X86_REG_RBP, STACK + 0x80000)
q(rsp, STOP)
install_hooks()
cpu.emu_start(text(name), STOP, count=LIMIT)
if cpu.reg_read(UC_X86_REG_RIP) != STOP:
return None
return cpu.reg_read(UC_X86_REG_RAX) & 0xffffffff
def message(unit=3, size=0x18, b5=3, b6=0, seq=0, flags=0, number=1, length=None, bad=0,
control=0, b4=0, stamp=0x1000, fill=0):
"""A message element. Bytes 0-3 are the header (unit, size, control,
sequence); byte 5 and 6 classify it; +a length, +c number, +e checksum;
+10 the PMU's time stamp (events) ; +14 sequence and +15 flags (replies)."""
m = bytearray([fill]) * MESSAGE
m[0:8] = bytes([unit, size, control, seq, b4, b5, b6, 0])
m[8:0x10] = bytes(8)
m[0xa:0xc] = ((size - 4) & 0xffff if length is None else length).to_bytes(2, "little")
m[0xc:0xe] = number.to_bytes(2, "little")
m[0x10:0x14] = stamp.to_bytes(4, "little")
m[0x14], m[0x15] = seq, flags
covered = min((int.from_bytes(m[0xa:0xc], "little") + 7) & ~3, MESSAGE)
total = sum(int.from_bytes(m[i:i + 2], "little") for i in range(0, covered, 2))
m[0xe:0x10] = ((bad - total) & 0xffff).to_bytes(2, "little")
return bytes(m)
def reply(queue, number, status=0, flags=0, extra=None, **changes):
"""Deferred: a reply to the command last posted on `queue` (0 high, 1 low)."""
return ("reply", queue, number, status, flags, extra or {}, changes)
def event(**fields):
return ("event", fields)
def start(state_word=4, tail=0, head=None, stat=(0x40,), mask=0x387d, dest=0x10072, mailbox=0):
"""A fresh PMU after INIT (or before it for state 2) and the register model."""
if state_word == 2:
begin("S", tail)
else:
# INIT is accepted at position 0 only; a later position is the
# register model's (the queue reads its position from the register)
ready()
tail = tail or 1
state["reads"][0x10a4cc] = [tail]
del trace[:], diag[:], asserts[:], delivered[:]
cpu.mem_write(REC, (0xe).to_bytes(2, "little") + bytes(0x3e))
state["reads"].update({0x10a008: list(stat), 0x10a018: [mask], 0x10a01c: [dest],
0x10a094: [mailbox], 0x10a16c: [0x80000005],
0x10a4c8: [tail if head is None else head],
# the engine reset of an unload before INIT
0x1221fc: [0], 0x10a3c4: [0x77], 0x10a3c0: [0]})
if state_word not in (2, 4):
d(KERNEL + 0x80, state_word)
irq["pending"] = []
irq["entry"] = lambda: ("_nv052477rm", GPU, PMU, REC)
hstat["value"] = 0
tick[0] = 0x1000
return tail
def place(position, items):
"""Write message elements from `position` on and move the PMU's head."""
out = []
for item in items:
if item[0] == "reply":
unused, queue, number, status, flags, extra, changes = item
register = 0x10a804 if queue else 0x10a800
index = (state["reads"][register][0] - 1) % 16
base = (LPQ if queue else HPQ) + ELEMENT * index
sequence = byte(SURF + base + 0xb)
patch = {0x14 + 4: 0, 0x14 + 5: status}
patch.update(extra)
for offset, value in sorted(patch.items()):
b(SURF + base + offset, value)
out.append(f"{base + offset:x}={value:02x}")
fields = dict(unit=0xf, b5=0xf, b6=4, seq=sequence, flags=flags, number=number)
fields.update(changes)
raw = message(**fields)
elif item[0] == "event":
raw = message(**item[1])
else:
raw = item[1]
cpu.mem_write(SURF + MSGQ + MESSAGE * position, raw)
out.append(f"{MSGQ + MESSAGE * position:x}={raw.hex()}")
position = (position + 1) % 16
state["reads"][0x10a4c8] = [position]
return out, position
def schedule(plan, position):
"""plan: list of (pass number, items); passes count interrupt service passes."""
pending = []
cursor = [position]
for number, items in plan:
while len(pending) < number - 1:
pending.append(None)
def action(number=number, items=items):
written, cursor[0] = place(cursor[0], items)
delivered.append(f"{number}@{cursor[0]:x}@" + ",".join(written))
pending.append(action)
irq["pending"] = pending
def snapshot_fields():
transport = pointer(TRANSPORT + 0x9c8) if pointer(TRANSPORT + 0x9c8) else 0
statistics = (f"{pointer(transport + 0x188):x}:{pointer(transport + 0x198):x}:"
f"{word(transport + 0x1a0):x}:{word(transport + 0x1a4):x}") if transport else "-"
return (f"state={word(KERNEL + 0x80):x} ready={byte(F_PMU + 0x583):x} "
f"tail={state['reads'][0x10a4cc][0]:x} stats={statistics} f70={byte(PMU + 0xf70):x}")
def finish(kind, label, status, extra=""):
counts[kind] = counts.get(kind, 0) + 1
shown = "loop" if status is None else status if isinstance(status, str) else f"{status:x}"
rows.append("|".join((kind, label, shown, extra, " ".join(trace))))
del trace[:]
def guarded(label, function, *arguments):
try:
return function(*arguments)
except Exception:
print("FAILED", label, function_at(cpu.reg_read(UC_X86_REG_RIP)), calls[-8:], trace[-30:],
[(name, hex(code)) for name, code in diag[-8:]], file=sys.stderr)
raise
# ------------------------------------------------------------ service entry
def service_case(label, messages=(), gpu=(), limit=False, handler=0, skew=False, **settings):
tail = start(**settings)
written, unused = place(tail, messages) if messages else ([], tail)
saved = [(offset, byte(GPU + offset)) for offset, unused in gpu]
for offset, value in gpu:
b(GPU + offset, value)
hstat["value"] = handler
status = guarded(label, bounded if limit else call, "_nv052477rm", GPU, PMU, REC)
for offset, value in saved:
b(GPU + offset, value)
if status is None:
# keep the first iteration: up to the second read of the same element
copies = [index for index, token in enumerate(trace) if token.startswith("l:")]
del trace[copies[1] - 4:]
if skew:
status = "skew"
text_settings = " ".join(
f"{key}=" + ("/".join(f"{value:x}" for value in item) if isinstance(item, tuple)
else f"{item:x}") for key, item in sorted(settings.items()))
gpu_text = ",".join(f"{offset:x}={value:x}" for offset, value in gpu) or "-"
finish("S", f"{label} {text_settings} gpu={gpu_text} handler={handler:x} "
f"msgs={','.join(written) or '-'}", status, snapshot_fields())
return status
# gating
service_case("nothing", stat=(0,))
service_case("empty-queue")
for value in (0x1, 0x10, 0x20, 0x30, 0x50, 0x60, 0x70, 0x80, 0xc0, 0xffff):
service_case("bits", stat=(value, value & 0x8f))
service_case("masked", mask=0x383d)
service_case("not-routed", dest=0x10032)
service_case("marker", mailbox=0xfeedfeed)
service_case("marker-with-bits", stat=(0x70,), mailbox=0xfeedfeed)
service_case("not-started", state_word=0)
for offset in (0x915, 0x917, 0x918, 0x919, 0x926):
service_case("gpu", gpu=((offset, 0 if offset == 0x915 else 1),))
service_case("second-pending", stat=(0x40, 0))
# INIT through the service
def init_through_service(label, raw, tail=0):
start(state_word=2, tail=tail, head=(tail + 1) % 16)
if raw:
cpu.mem_write(SURF + MSGQ, raw)
try:
status = call("_nv052477rm", GPU, PMU, REC)
except UcError:
# the message queue's functions (queue table +1a0) are bound by the
# INIT handler only: the call through +1a8 goes to address 0
table = pointer(pointer(F_PMU + 0x610) + 0x48)
assert pointer(table + 0x1a8) == 0 and cpu.reg_read(UC_X86_REG_RIP) == 0, hex(table)
assert trace[-1] == "w:10a004:40", trace
status = "fault"
finish("I", f"{label} tail={tail:x} head={(tail + 1) % 16:x} msgs="
+ (f"{MSGQ:x}={raw.hex()}" if raw else "-"), status,
snapshot_fields() + f" value={half(F_PMU + 0x5d0):x}")
return status
assert init_through_service("init", init_message()) == 0x40
for changes in (dict(status=3), dict(unit=0xe), dict(kind=1), dict(offset=0x400, size=0x1000)):
init_through_service("init", init_message(**changes))
init_through_service("init-tail", None, tail=1)
# events: every key the original handles, through the whole service
for key, name in sorted(EVENT_FUNCTIONS.items()):
if key == 0xf04:
continue # that pair of bytes is a reply
service_case("event", [event(unit=key >> 8, b5=key >> 8, b6=key & 0xff, stamp=0xff0)])
service_case("event-handler-fails", [event(b5=3, b6=5)], handler=0x56)
service_case("event-unit-differs", [event(unit=0x21, b5=0x13, b6=4)])
for b5, b6 in ((0, 0), (3, 8), (4, 0), (0xf, 5), (0x13, 0xa), (0x1c, 1), (0x21, 0), (0xff, 0xff)):
service_case("event-unhandled", [event(unit=3, b5=b5, b6=b6, control=0x55)])
service_case("events", [event(), event(unit=9, b5=9, b6=1, number=2, stamp=0x1010),
event(unit=0x13, b5=0x13, b6=4, number=3, stamp=0x1038)])
service_case("event-wrap", [event(), event(number=2)], tail=14)
service_case("stamp-later", [event(stamp=0x2000)])
# the reader's checks, one boundary at a time
for unit in (1, 0x21):
service_case("unit-accepted", [event(unit=unit)])
for unit in (0x22, 0x80, 0xff):
service_case("unit-rejected", [event(unit=unit)])
for size in (5, 6, 8, 0x17, 0x30):
service_case("size-accepted", [event(size=size)])
for size in (0x31, 0x40, 0xff):
service_case("size-rejected", [event(size=size)])
for size in (0, 1, 4):
service_case("header-only", [event(size=size, length=0)])
service_case("header-only-stale-reply-class", [event(size=4, length=0, b5=0xf, b6=4)])
for length in (1, 0x13, 0x14):
service_case("length-accepted", [event(length=length)])
# done with the element after the header: the body comes from the next one
service_case("length-zero-with-body", [event(length=0)], skew=True)
for size, length in ((0x18, 0x15), (0x18, 0x3b), (4, 1), (0x30, 0x2d)):
service_case("length-beyond-size", [event(size=size, length=length)], limit=True)
for length in (0x3c, 0x40, 0xffff):
service_case("length-rejected", [event(length=length)])
service_case("unit-zero", [event(unit=0)], limit=True)
for number in (0, 2, 0xffff):
service_case("number", [event(number=number)])
service_case("checksum", [event(bad=1)])
service_case("checksum-and-number", [event(bad=0x8000, number=9)])
service_case("rejected-after-event", [event(), event(unit=0x22, number=2)])
service_case("fill", [event(fill=0xa5)])
# ------------------------------------------------------------ event key sweep
def sweep():
start()
transport = pointer(TRANSPORT + 0x9c8)
seen = {}
for unit in range(0x24):
for kind in range(0xc):
raw = message(unit=unit, b5=unit, b6=kind, control=unit ^ 0x5a, stamp=0x1000 + kind)
cpu.mem_write(SCRATCH + 0x3000, raw)
del trace[:], diag[:]
status = call("_nv052457rm", GPU, transport, SCRATCH + 0x3000)
handlers = [token for token in trace if token.startswith("h:")]
name = handlers[0].split(":")[1] if handlers else "-"
expected = EVENT_FUNCTIONS.get(unit << 8 | kind)
assert (expected[3:9] if expected else "-") == name, (unit, kind, name)
seen[unit << 8 | kind] = name
finish("K", f"unit={unit:x} type={kind:x} msg={raw.hex()}", status,
f"handler={name} " + snapshot_fields().split()[3])
assert sum(1 for name in seen.values() if name != "-") == len(EVENT_FUNCTIONS)
sweep()
# ------------------------------------------------------------ requests
def request_label(prefix, payload, queue, checks, used, fresh):
return (f"{prefix} fresh={int(fresh)} queue={queue:x} rpc={payload.hex()} "
f"d={';'.join(delivered) or '-'} "
f"checks={','.join(f'{value:x}' for value in used) or '-'}")
def rpc_case(prefix, payload, queue, plan, checks=(), fresh=True, limit=False):
"""_nv052461rm(gpu, queue object, rpc, bytes, 0, 0, queue) with every wait
pass that delivers entering the PMU class's interrupt service."""
if fresh:
start()
del delivered[:]
register = 0x10a804 if queue else 0x10a800
head = state["reads"][register][0]
state["checks"] = list(checks)
schedule(plan, state["reads"][0x10a4cc][0])
cpu.mem_write(SCRATCH + 0x1000, payload)
q(STACK + 0xfff00 + 8, queue)
status = guarded(prefix, bounded if limit else call, "_nv052461rm", GPU, TRANSPORT + 8,
SCRATCH + 0x1000, len(payload), 0, 0, queue)
used = list(checks)[:len(checks) - len(state["checks"])]
posted = (state["reads"][register][0] - head) % 16
after = bytes(cpu.mem_read(SCRATCH + 0x1000, len(payload)))
base = LPQ if queue else HPQ
digest = ",".join(hashlib.sha256(bytes(cpu.mem_read(
SURF + base + ELEMENT * ((head + index) % 16), ELEMENT))).hexdigest()[:16]
for index in range(posted))
finish("P", request_label(prefix, payload, queue, checks, used, fresh), status,
f"after={after.hex()} sha={digest or '-'} " + snapshot_fields())
return status
RPC = bytes([0, 0x0a, 2, 0]) + bytes(range(0x14))
assert rpc_case("reply", RPC, 1, [(1, [reply(1, 1)])], checks=(0,) * 4) == 0
assert rpc_case("reply-high", RPC, 0, [(1, [reply(0, 1)])], checks=(0,) * 4) == 0
rpc_case("reply-pass-3", RPC, 1, [(3, [reply(1, 1)])], checks=(0,) * 6)
rpc_case("event-then-reply", RPC, 1, [(1, [event(), reply(1, 2)])], checks=(0,) * 4)
rpc_case("reply-then-event", RPC, 1, [(1, [reply(1, 1), event(number=2)])], checks=(0,) * 4)
rpc_case("reply-then-event-high", RPC, 0, [(1, [reply(0, 1), event(number=2)])],
checks=(0,) * 4)
rpc_case("event-pass-then-reply-pass", RPC, 1, [(1, [event()]), (2, [reply(1, 2)])],
checks=(0,) * 6)
rpc_case("events-around", RPC, 1,
[(2, [event(b5=0x13, b6=4), reply(1, 2), event(b5=9, b6=0, number=3)])],
checks=(0,) * 6)
rpc_case("firmware-status", RPC, 0, [(1, [reply(0, 1, status=3)])], checks=(0,) * 4)
rpc_case("short-reply", RPC, 0, [(1, [reply(0, 1, flags=2)])], checks=(0,) * 4)
rpc_case("no-reply", RPC, 0, [], checks=(0, 0, 0x65))
rpc_case("event-only", RPC, 1, [(1, [event()])], checks=(0, 0, 0x65))
rpc_case("rejected-message", RPC, 1, [(1, [event(unit=0x22)])], checks=(0, 0, 0x65))
for size in (0x10, 0x14, 0x7f0):
rpc_case("sizes-high", bytes([0, 0x0f, 1, 0]) + bytes((3 * index + size) & 0xff
for index in range(size - 4)),
0, [(1, [reply(0, 1)])], checks=(0,) * 4)
rpc_case("too-large-high", bytes([0, 0x0f, 1, 0]) + bytes(0x7f1 - 4), 0, [])
# both queues in one sequence: positions and sequence numbers are per transport
start()
number = 1
for index in range(18):
queue = index % 3 == 0
assert rpc_case("mixed", RPC, int(queue), [(1, [reply(int(queue), number)])],
checks=(0,) * 4, fresh=False) == 0
number += 1
def falcon_case(prefix, falcon, plan, checks=(), fresh=True):
if fresh:
start()
del delivered[:]
head = state["reads"][0x10a804][0]
state["checks"] = list(checks)
schedule(plan, state["reads"][0x10a4cc][0])
status = guarded(prefix, call, "_nv043191rm", GPU, LSFM, falcon, 0, 0)
used = list(checks)[:len(checks) - len(state["checks"])]
posted = (state["reads"][0x10a804][0] - head) % 16
digest = ",".join(hashlib.sha256(bytes(cpu.mem_read(
SURF + LPQ + ELEMENT * ((head + index) % 16), ELEMENT))).hexdigest()[:16]
for index in range(posted))
finish("R", f"{prefix} fresh={int(fresh)} falcon={falcon:x} d={';'.join(delivered) or '-'} "
f"checks={','.join(f'{value:x}' for value in used) or '-'}", status,
f"a37d={byte(ACR + 0x37d):x} sha={digest or '-'} " + snapshot_fields())
return status
# first open: region and SEC2, FECS, GPCCS, with an event before and between
assert falcon_case("first-open", 7, [(1, [event(), reply(1, 2)]), (2, [reply(1, 3)])],
checks=(0,) * 8) == 0
assert falcon_case("first-open", 2, [(1, [reply(1, 4), event(number=5, b5=0x13, b6=4)])],
checks=(0,) * 8, fresh=False) == 0
assert falcon_case("first-open", 3, [(1, [reply(1, 6)])], checks=(0,) * 8, fresh=False) == 0
falcon_case("plain", 7, [(1, [reply(1, 1)]), (2, [reply(1, 2)])], checks=(0,) * 8)
# ------------------------------------------------------------ unload
def unload_case(label, plan, checks=(), state_word=4, flags=0, gpu=(), pmu=(), limit=False):
start(state_word=state_word)
del delivered[:]
bif = fixture(0x1000)
q(GPU + 0x1e88, bif)
for offset, value in gpu:
b(GPU + offset, value)
for offset, value in pmu:
b(PMU + offset, value)
state["checks"] = list(checks)
schedule(plan, state["reads"][0x10a4cc][0])
head = state["reads"][0x10a800][0]
status = guarded(label, bounded if limit else call, "_nv052517rm", GPU, PMU, flags)
used = list(checks)[:len(checks) - len(state["checks"])]
posted = (state["reads"][0x10a800][0] - head) % 16
digest = ",".join(hashlib.sha256(bytes(cpu.mem_read(
SURF + HPQ + ELEMENT * ((head + index) % 16), ELEMENT))).hexdigest()[:16]
for index in range(posted))
first = bytes(cpu.mem_read(SURF + HPQ + ELEMENT * head, 0x28)).hex() if posted else "-"
extra = (f"element={first} sha={digest or '-'} bif={word(bif + 0xb9c):x} "
f"f3a7={byte(F_PMU + 0x3a7):x}:{byte(F_PMU + 0x3aa):x}:{byte(F_PMU + 0x3af):x} "
f"t9b4={half(pointer(TRANSPORT + 0x9c8) + 0x9b4):x} " + snapshot_fields())
for offset, value in gpu:
b(GPU + offset, 0)
finish("U", f"{label} sw={state_word:x} flags={flags:x} "
f"gpu={','.join(f'{offset:x}={value:x}' for offset, value in gpu) or '-'} "
f"pmu={','.join(f'{offset:x}={value:x}' for offset, value in pmu) or '-'} "
f"d={';'.join(delivered) or '-'} "
f"checks={','.join(f'{value:x}' for value in used) or '-'}", status, extra)
return status
DETACHED = dict(unit=0xf, b5=0xf, b6=1)
assert unload_case("ready", [(1, [reply(0, 1)])], checks=(0,) * 4) == 0
unload_case("ready-flags", [(1, [reply(0, 1)])], checks=(0,) * 4, flags=1)
unload_case("ready-late-reply", [(3, [reply(0, 1)])], checks=(0,) * 6)
unload_case("ready-event-first", [(1, [event(), reply(0, 2)])], checks=(0,) * 4)
unload_case("ready-no-reply", [], checks=(0, 0, 0x65))
unload_case("ready-firmware-status", [(1, [reply(0, 1, status=3)])], checks=(0,) * 4)
# the reply asks the driver to wait for the detach event (reply byte +0x10)
unload_case("wait-event-same-pass",
[(1, [reply(0, 1, extra={0x24: 1}), event(number=2, **DETACHED)])],
checks=(0,) * 6)
unload_case("wait-event-next-pass",
[(1, [reply(0, 1, extra={0x24: 1})]), (2, [event(number=2, **DETACHED)])],
checks=(0,) * 8)
unload_case("wait-event-never", [(1, [reply(0, 1, extra={0x24: 1})])],
checks=(0, 0, 0, 0, 0x65))
unload_case("not-initialised", [], state_word=2,
checks=(0,) * 4)
unload_case("pmu-9a2", [], pmu=((0x9a2, 1),))
out = ROOT / "target/gpu-stage"
oracle = "\n".join(rows) + "\n"
(out / "original-pmu-service.txt").write_text(oracle)
report = {
"original_sha256": DIGEST, "chip_hal": "0x23", "rm_hal": 2,
"environment": "tools/check_gpu_pmu_fbq_binary.py setup; interrupt passes enter _nv052477rm",
"cases": len(rows), "cases_by_kind": counts,
"event_functions": {f"{key:#06x}": name for key, name in sorted(EVENT_FUNCTIONS.items())},
"oracle": "target/gpu-stage/original-pmu-service.txt",
"oracle_sha256": hashlib.sha256(oracle.encode()).hexdigest(),
"scope": "Original GV100 PMU interrupt service entry, message reader checks, event "
"dispatch, requests on both command queues with the service in the wait, and "
"the class's Unload. The firmware side is a fixture; no hardware executed."}
(ROOT / "reports/gpu-pmu-service-original.json").write_text(json.dumps(report, indent=2) + "\n")
print(f"{len(rows)} original PMU service cases {counts}; oracle sha256 {report['oracle_sha256']}")