Files
nvdriver/tools/check_gpu_pmu_level_binary.py

584 lines
27 KiB
Python

#!/usr/bin/env python3
"""Run the original functions of other objects that the GV100 PMU start, the queue
transport and the PMU unload call, and write an oracle for core gpu::pmu_level.
The environment is that of tools/check_gpu_pmu_fbq_binary.py (its setup part is executed
unchanged): the ACR load harness up to its traced V100 Load, the PMU class constructed,
initialised and started. Executed original code (chip HAL 0x23, RM HAL 2):
C ClockManager+198 _nv021004rm for clock domain 0x13, on the clock schematic the
original ClockManager+138 _nv020155rm builds (level builder +140 _nv020153rm with its
helpers, the invalidation _nv021109rm and _nv021101rm): the domain object
(_nv021042rm), the multiplexer _nv021062rm (register 0x137190, table of 14 mask and
value pairs), the divider _nv021061rm (register 0x137280), the wrapper _nv021043rm,
the PLL _nv021066rm (registers 0xe800 and 0xe804) and the fixed 27000 kHz source;
inputs 3 and 0xb are objects read by _nv021051rm, input 0xd a second divider and PLL
(these three are executed here and refused in Rust).
CT is the traced V100: transcript lines 147426-147429.
F OBJFUSE+150 _nv028946rm with the OBJFUSE functions the binder _nv005974rm binds
(+118 _nv029006rm for id 0xff00003b, +100 _nv029045rm, +168 _nv029047rm) and the Jtag
function _nv039060rm. FT: transcript lines 147430-147431.
G the function PMU Load calls through the GCX child (GCX+258 -> object+8, slot +30
_nv003596rm -> _nv029092rm) with GPU+998 clear and set.
K KernelBus+4a8 _nv039391rm with KernelBus+390 _nv039387rm for the arguments PMU Load
(1) and the command post (3) pass, and argument 4.
Q the gates of the synchronous request _nv052461rm that return before anything is
posted.
L the Lpwr function _nv043006rm the MemorySystem function calls first and last, on
the control object dword (Lpwr+11c0 object, +e0) a GV100 has (0) and others.
M the MemorySystem function _nv044310rm(gpu, MemorySystem, mode) of the PMU unload
with the LTC register objects the original _nv044445rm builds (MemorySystem+8d00),
+b10 _nv044754rm and +b28 _nv044978rm and the polled read _nv053908rm.
B bytes of the PMU object after the property initialiser, the class constructor and
ConstructEngine, and the Falcon bytes the light-secure manager's lookup
_nv043198rm returns for Falcons 7, 2 and 3.
D the boot vector and OS word PMU Load writes, with the descriptor fields they are
read from (Falcon+3e8 descriptor, +60 and +c).
Fixture-supplied: everything the queue harness supplies; register values; the registry
(no key has a value); the allocator of the clock schematic; MemorySystem+8c0 (a memory
partition mask, not read by clock domain 0x13); the PMU surface mapping function
_nv052610rm behind the GCX child function; time. No hardware.
"""
import hashlib
import json
from pathlib import Path
import sys
if str(Path(__file__).resolve().parent) not in sys.path:
sys.path.insert(0, str(Path(__file__).resolve().parent))
from _gpu_pmu_oracle_check import require, write_or_check_json, write_or_check_text # noqa: E402
SELF = HERE = Path(__file__).resolve()
def memory_mode():
"""M rows: the MemorySystem function of the PMU unload, on the LTC register objects
the original _nv044445rm builds in the Graphics harness environment."""
sys.path.insert(0, str(HERE.parent))
saved_argv = list(sys.argv)
sys.argv = sys.argv[:1]
try:
import check_gpu_graphics_zbc_binary as z
finally:
sys.argv = saved_argv
h = z.h
prepared = h.default_load()
z.prepare(prepared)
h.state["case"] = prepared
memory = z.M
slots = {offset: h.function_at(h.q(memory + offset)) for offset in (0xb10, 0xb28)}
require(slots == {0xb10: "_nv044754rm", 0xb28: "_nv044978rm"}, slots)
objects, count = h.q(memory + 0x8d00), h.d(memory + 0x8d08)
bases = [h.d(objects + 0x88 * index + 0x7c) for index in range(count)]
lines = ["MB|%x|%s" % (count, ",".join(f"{base:x}" for base in bases))]
answers = []
h.hook("_nv043006rm", lambda a: h.emit(f"lp:{a[2] & 0xffffffff:x}") or answers.pop(0))
lpwr = h.allocate(0x100)
# The register access object names its GPU; no OBJSEQ script is being recorded.
require(h.q(h.GPU + 0x4120) == 0 and h.q(h.GPU + 0x1f48) == 0)
h.wq(h.GPU + 0x4120, h.GPU)
def case(mode, reads, checks=(), lpwr_status=(0, 0), default=0, lpwr_present=1):
h.wq(h.GPU + 0x22c8, lpwr if lpwr_present else 0)
h.state["events"].clear()
h.state["checks"] = 0
h.state["case"] = dict(h.state["case"], reads={k: list(v) for k, v in reads.items()},
default_read=lambda offset: default, check=list(checks))
answers[:] = list(lpwr_status)
status = h.call("_nv044310rm", h.GPU, memory, mode) & 0xffffffff
events = " ".join(event for event in h.state["events"]
if event.split(":")[0] in ("r", "w", "tc", "y", "lp", "ts"))
lines.append("|".join((
"M", f"{mode:x}", f"{default:x}",
" ".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 checks),
",".join(f"{value:x}" for value in lpwr_status), f"{lpwr_present:x}",
f"{status:x}", events)))
transcript = h.TRANSCRIPT.read_text().splitlines()
traced = {0x12006c: [0x10]}
for number in range(167044, 167060):
kind, offset, value, unused = transcript[number - 1].split()
traced[int(offset, 16)] = [int(value, 16)]
require(len(traced) == 17)
case(0, traced)
case(1, traced)
case(2, traced)
case(0, traced, lpwr_status=(0x40,))
case(0, traced, lpwr_status=(0, 0x40))
case(0, traced, lpwr_present=0)
for ltcs in (0, 1, 2, 0x10, 0x11, 0x1f, 0x20, 0x31):
case(0, {0x12006c: [ltcs]}, default=0x10000000)
case(0, {0x12006c: [ltcs]}, default=0)
case(0, {0x12006c: [2], 0x140480: [0x30000000], 0x142480: [0xf0000000]})
# Slices that are busy at first, and slices that never become idle.
case(0, {0x12006c: [1], 0x140480: [0x20000000], 0x14046c: [1, 1, 0], 0x14066c: [3, 0]},
checks=(0, 0, 0))
case(0, {0x12006c: [2], 0x140480: [0x20000000], 0x142480: [0x10000000],
0x14046c: [1], 0x14066c: [0], 0x14246c: [0]}, checks=(0, 0x65))
case(0, {0x12006c: [2], 0x140480: [0x20000000], 0x142480: [0x10000000],
0x14046c: [0], 0x14066c: [1], 0x14246c: [1, 0]}, checks=(0x65, 0))
case(0, {0x12006c: [1], 0x140480: [0x10000000], 0x14046c: [0xfffffffe]})
case(0, {0x12006c: [1], 0x140480: [0x10000000], 0x14046c: [0xffffffff]}, checks=(0x65,))
case(0, {0x12006c: [1], 0x140480: [0x10000000], 0x14046c: [1]}, checks=(0x56, 0x65))
print(json.dumps({"rows": lines, "slots": slots, "count": count,
"bases": [f"{base:#x}" for base in bases]}))
if "--memory" in sys.argv:
memory_mode()
sys.exit(0)
FBQ = HERE.with_name("check_gpu_pmu_fbq_binary.py")
_text = FBQ.read_text()
_end = "# ------------------------------------------------------------------- INIT"
require(_end in _text)
__file__ = str(FBQ)
exec(compile(_text[:_text.index(_end)], str(FBQ), "exec"), globals()) # noqa: S102
__file__ = str(SELF)
rows, counts = [], {}
STARTED_STATE = pmu_snapshot()
def name_at(address):
return entries.get(address - TEXT, hex(address))
def row(kind, *fields):
counts[kind[0]] = counts.get(kind[0], 0) + 1
rows.append("|".join((kind,) + tuple(fields)))
def accesses():
return " ".join(token for token in trace if token[:2] in ("r:", "w:") or
token.split(":")[0] in ("as", "tc", "y", "sm", "lp", "ts", "gs"))
class Random:
def __init__(self, seed):
self.state = seed
def word(self):
self.state = (self.state * 6364136223846793005 + 1442695040888963407) & (2 ** 64 - 1)
return self.state >> 32
def pick(self, values):
return values[self.word() % len(values)]
class Reads(dict):
"""Register values for a case; an unlisted register reads as `default`."""
def __init__(self, values, default=None):
super().__init__({offset: list(value) for offset, value in values.items()})
self.default = default
def get(self, offset, unused=None):
if offset not in self and self.default is not None:
self[offset] = [self.default]
return dict.get(self, offset)
# --------------------------------------------------------------- C: clock domain 0x13
CLOCK, POOL, OUT = fixture(0x2000), fixture(0x2b000), fixture(0x40)
POOL_BYTES = 0x2a498
DOMAIN = 0x13
@service("MemorySystem+8c0 (memory partition mask)")
def partition_mask(a, low):
q(a[2], 1)
return 0
def clock_schematic(display, memory_word):
"""ClockManager as its binder and property initialiser leave it, the settle time
_nv020549rm stores (64000) and the schematic _nv020155rm builds."""
cpu.mem_write(CLOCK, bytes(0x2000))
call("_nv005865rm", CLOCK, CHIP, RM)
call("_nv005774rm", CLOCK, CHIP, RM)
require(name_at(pointer(CLOCK + 0x198)) == "_nv021004rm")
require(name_at(pointer(CLOCK + 0x138)) == "_nv020155rm")
require(name_at(pointer(CLOCK + 0x140)) == "_nv020153rm")
require(call("_nv020549rm", GPU, CLOCK) == 0 and word(CLOCK + 0x1300) == 64000)
saved = pointer(GPU + 0x2058), pointer(GPU + 0x1f70), pointer(MEMSYS + 0x8c0), word(
MEMSYS + 0x4384)
q(GPU + 0x2058, CLOCK)
q(GPU + 0x1f70, fixture(0x2000) if display else 0)
q(MEMSYS + 0x8c0, partition_mask)
d(MEMSYS + 0x4384, memory_word)
state["reads"] = Reads({0x101000: [0]})
call("_nv020155rm", GPU, CLOCK)
require(pointer(CLOCK + 0x8a0) == POOL)
q(GPU + 0x1f70, saved[1])
q(MEMSYS + 0x8c0, saved[2])
d(MEMSYS + 0x4384, saved[3])
return saved[0]
hooks[text("_nv044886rm")] = ("_nv044886rm", lambda a, low: (d(a[2], 0x3f), 0)[1])
hooks[text("_nv029329rm")] = ("_nv029329rm",
lambda a, low: (cpu.mem_write(POOL, bytes(0x2b000)), POOL)[1])
_registry_saved = hooks.get(text("_nv049786rm"))
hooks[text("_nv049786rm")] = ("_nv049786rm", lambda a, low: 0x56)
CLOCK_REGISTERS = (0x137190, 0x137280, 0xe800, 0xe804)
SCHEMATICS = {}
for display in (0, 1):
for memory_word in (13, 14, 15, 16):
saved_clock = clock_schematic(display, memory_word)
image = bytes(cpu.mem_read(POOL, POOL_BYTES))
SCHEMATICS[(display, memory_word)] = image
base = POOL + 0x910
domain = pointer(POOL + 0x5b58 + 8 * DOMAIN)
mux = pointer(domain + 8)
# The chain of the traced selection: domain -> multiplexer -> input 0xc (divider)
# -> wrapper -> PLL -> fixed source; and input 8, the fixed source itself.
table, inputs, count = pointer(mux + 0x78), pointer(mux + 0x90), byte(mux + 0x98)
divider = pointer(inputs + 8 * 0xc)
pll = pointer(pointer(divider + 0x60) + 0x60)
source = pointer(pll + 0x60)
described = (
name_at(pointer(pointer(domain))), name_at(pointer(mux + 0x20)), count,
byte(mux + 0x99), word(pointer(mux + 0x60)),
tuple((word(table + 8 * index), word(table + 8 * index + 4))
for index in range(count)),
tuple(bool(pointer(inputs + 8 * index)) for index in range(count)),
name_at(pointer(divider + 0x20)), word(pointer(divider + 0x68)),
bytes(cpu.mem_read(divider + 0x70, 3)).hex(),
name_at(pointer(pointer(divider + 0x60) + 0x20)), name_at(pointer(pll + 0x20)),
word(pointer(pll + 0x68)), word(pointer(pll + 0x70)), byte(pll + 0x97),
pointer(inputs + 8 * 8) == source, name_at(pointer(source + 0x20)),
word(source + 0x50),
tuple((name_at(pointer(pointer(inputs + 8 * index) + 0x20)),
word(pointer(inputs + 8 * index) + 0x50)) for index in (3, 0xb)))
SCHEMATICS[(display, memory_word, "chain")] = described
CHAINS = {value for key, value in SCHEMATICS.items() if len(key) == 3}
require(len(CHAINS) == 1, CHAINS)
CHAIN = CHAINS.pop()
require(CHAIN[0] == "_nv021042rm" and CHAIN[1] == "_nv021062rm" and CHAIN[7] == "_nv021061rm")
require(CHAIN[10] == "_nv021043rm" and CHAIN[11] == "_nv021066rm" and CHAIN[16] == "_nv021059rm")
# Inputs 3 and 0xb are objects of another kind (_nv021051rm), not reproduced in Rust.
require(all(name == "_nv021051rm" for name, unused in CHAIN[18]), CHAIN[18])
row("CS", f"{CHAIN[2]:x}", f"{CHAIN[3]:x}", f"{CHAIN[4]:x}",
",".join(f"{mask:x}:{value:x}" for mask, value in CHAIN[5]),
"".join("1" if present else "0" for present in CHAIN[6]),
f"{CHAIN[8]:x}", CHAIN[9], f"{CHAIN[12]:x}", f"{CHAIN[13]:x}", f"{CHAIN[14]:x}",
f"{CHAIN[17]:x}")
def clock_case(kind, values, schematic=(0, 13), g90e=0, g4de2=0):
cpu.mem_write(POOL, SCHEMATICS[schematic])
b(GPU + 0x90e, g90e)
b(GPU + 0x4de2, g4de2)
state["reads"] = Reads(dict(zip(CLOCK_REGISTERS, ([value] for value in values))), default=0)
del trace[:]
cpu.mem_write(OUT, bytes(0x40))
status = call("_nv021004rm", GPU, CLOCK, DOMAIN, OUT, 0, 0)
b(GPU + 0x90e, 0)
b(GPU + 0x4de2, 0)
row(kind, " ".join(f"{value:x}" for value in values), f"{g90e:x}{g4de2:x}", f"{status:x}",
f"{word(OUT):x}", accesses())
return status, word(OUT)
q(GPU + 0x2058, CLOCK)
TRACED_CLOCK = [int(TRANSCRIPT_LINES[line - 1].split()[2], 16) for line in range(147426, 147430)]
require([int(TRANSCRIPT_LINES[line - 1].split()[1], 16)
for line in range(147426, 147430)] == list(CLOCK_REGISTERS))
for schematic in sorted(key for key in SCHEMATICS if len(key) == 2):
require(clock_case("CT", TRACED_CLOCK, schematic) == (0, 540000))
require(trace == [f"r:{offset:x}:{value:x}" for offset, value in zip(CLOCK_REGISTERS,
TRACED_CLOCK)])
random = Random(0x13)
MUX_WORDS = [3, 0x103, 0, 0x10000, 0x20000, 0x30000, 2, 0x1000002, 0x2000002, 0x3000002,
0x4000002, 0x5000002, 0x6000002, 0x7000002, 1, 0xffffffff, 0x10000103, 0x7000003]
for mux in MUX_WORDS:
clock_case("C", [mux, 0x87100004, 0x2020015, 0x63c01])
for divider in list(range(0, 0x40)) + [0xffffffc4, 0x87100044, 0x80]:
clock_case("C", [3, divider, 0x2020015, 0x63c01])
for config in (0, 1, 2, 3, 0x2020014, 0x2020017, 0xffffffff, 0xfffffffe):
for flags in ((0, 0), (1, 0), (0, 1)):
clock_case("C", [3, 0x87100004, config, 0x63c01], g90e=flags[0], g4de2=flags[1])
for coefficient in (0, 1, 0x100, 0x101, 0x63c00, 0x60001, 0x6ff01, 0x601ff, 0x6ffff, 0x10701,
0x10801, 0xffffffff, 0x3c02, 0xc803):
clock_case("C", [3, 0x87100004, 0x2020015, coefficient])
clock_case("C", [3, 0x87100004, 0x2020017, coefficient], g90e=1)
for unused in range(120):
clock_case("C", [random.pick(MUX_WORDS[:6] + [3] * 8), random.word(),
random.pick((1, 0x2020015, random.word() | 1, random.word())),
random.pick((0x63c01, random.word(), random.word() & 0xffff))],
g90e=random.word() & 1)
q(GPU + 0x2058, saved_clock)
if _registry_saved:
hooks[text("_nv049786rm")] = _registry_saved
# ------------------------------------------------------------------ F: OBJFUSE+150
FUSE_OBJECT, JTAG, BYTE = fixture(0x1000), fixture(0x1000), fixture(8)
call("_nv005974rm", FUSE_OBJECT, CHIP, RM)
FUSE_SLOTS = {offset: name_at(pointer(FUSE_OBJECT + offset)) for offset in (0x100, 0x118, 0x150,
0x168)}
require(FUSE_SLOTS == {0x100: "_nv029045rm", 0x118: "_nv029006rm", 0x150: "_nv028946rm",
0x168: "_nv029047rm"}, FUSE_SLOTS)
q(JTAG + 0x100, text("_nv039060rm"))
saved_1e70 = pointer(GPU + 0x1e70)
q(GPU + 0x1e70, JTAG)
def fuse_case(kind, jtag, value, jtag_108=1, g92b=0):
require(pointer(FUSE_OBJECT + 0x2f0) == 0 and byte(GPU + 0x4de4) == 0)
b(JTAG + 0x108, jtag_108)
b(GPU + 0x92b, g92b)
b(BYTE, 0xa5)
state["reads"] = Reads({0x1373a0: [jtag]}, default=value)
del trace[:]
status = call("_nv028946rm", GPU, FUSE_OBJECT, BYTE)
b(GPU + 0x92b, 0)
row(kind, f"{jtag:x}", f"{value:x}", f"{jtag_108:x}", f"{status:x}", f"{byte(BYTE):x}",
accesses())
return status, byte(BYTE)
require(TRANSCRIPT_LINES[147429].split()[:3] == ["R", "1373a0", "0xa"])
require(TRANSCRIPT_LINES[147430].split()[:3] == ["R", "021c04", "0x1"])
require(fuse_case("FT", 0xa, 1) == (0, 0))
require([token for token in trace if token[0] == "r"] == ["r:1373a0:a", "r:21c04:1"])
for jtag in (0xa, 0x8, 0x2, 0, 0xffffffff):
for value in (0, 1, 2, 0x80000000, 0xffffffff, 0xfffffffe):
fuse_case("F", jtag, value)
fuse_case("F", jtag, 0, jtag_108=0)
fuse_case("F", jtag, 1, jtag_108=0)
q(GPU + 0x1e70, saved_1e70)
# -------------------------------------------------------------- G: the GCX child
# _nv029250rm (GCX InitLocked) creates the child with _nv006498rm when GCX+1ef is clear
# (GV100 property) and stores object+8 at GCX+258; the rtti block of that base is
# .rodata 0x05ee9118 in the analysis addressing, its slot +30 the thunk _nv003596rm,
# which calls slot +c0 of the object's own block 0x05ee9100.
ANALYSIS_RODATA = 0x0111d660
def analysis_rodata(address):
return pointer(RODATA + address - ANALYSIS_RODATA)
require(name_at(analysis_rodata(0x05ee9118 + 0x30)) == "_nv003596rm")
require(name_at(analysis_rodata(0x05ee9100 + 0xc0)) == "_nv029092rm")
CHILD = fixture(0x100)
_map_saved = hooks.get(text("_nv052610rm"))
hooks[text("_nv052610rm")] = ("_nv052610rm", lambda a, low: (emit(f"sm:{a[1]:x}"), 0)[1])
for g998, surfaces in ((0, 0), (0, 5), (1, 1), (1, 5)):
cpu.mem_write(CHILD, bytes(0x100))
for index in range(surfaces):
q(CHILD + 0x68 + 8 * index, 0x1000 + index)
b(GPU + 0x998, g998)
del trace[:]
status = call("_nv029092rm", GPU, CHILD)
row("G", f"{g998:x}", f"{surfaces:x}", f"{status:x}", accesses())
b(GPU + 0x998, 0)
if _map_saved:
hooks[text("_nv052610rm")] = _map_saved
else:
hooks.pop(text("_nv052610rm"))
# --------------------------------------------------------------- K: KernelBus+4a8
KBUS_OBJECT = fixture(0xb000)
call("_nv005902rm", KBUS_OBJECT, CHIP, RM)
call("_nv005903rm", KBUS_OBJECT, CHIP, RM)
KBUS_SLOTS = {offset: name_at(pointer(KBUS_OBJECT + offset)) for offset in (0x390, 0x398, 0x4a8)}
require(KBUS_SLOTS == {0x390: "_nv039387rm", 0x398: "_nv039552rm", 0x4a8: "_nv039391rm"}, KBUS_SLOTS)
saved_1f80 = pointer(GPU + 0x1f80)
q(GPU + 0x1f80, KBUS_OBJECT)
_section_saved = hooks[text("_nv031478rm")]
hooks[text("_nv031478rm")] = ("_nv031478rm",
lambda a, low: (emit(f"gs:{low[1]:x}:{low[2]:x}:{low[3]:x}"), 0)[1])
GPU_GATES = (0xe00, 0x4de7, 0x52f9, 0x91c, 0x917, 0x918, 0x919, 0x926, 0x91e, 0x915)
FLUSH_WORD = fixture(0x10)
saved_gates = {offset: byte(GPU + offset) for offset in GPU_GATES}
require(word(GPU + 0xcac) == 0x20)
def bus_case(argument, gpu=None, bus=None):
for offset in GPU_GATES:
b(GPU + offset, 1 if offset == 0x915 else 0)
for offset, value in (gpu or {}).items():
b(GPU + offset, value)
cpu.mem_write(KBUS_OBJECT + 0xacb8, bytes(0x28))
q(KBUS_OBJECT + 0x7c48, 0)
for offset, value in (bus or {}).items():
(q if offset in (0xacd0, 0x7c48) else b)(KBUS_OBJECT + offset, value)
state["reads"] = Reads({}, default=0x1234)
del trace[:]
status = call("_nv039391rm", GPU, KBUS_OBJECT, argument)
row("K", f"{argument:x}",
" ".join(f"g{offset:x}={value:x}" for offset, value in (gpu or {}).items()),
" ".join(f"b{offset:x}={min(value, 1):x}" for offset, value in (bus or {}).items()),
f"{status:x}", accesses())
for argument in (1, 3, 4, 5, 7, 0, 2):
bus_case(argument)
bus_case(argument, bus={0xacd8: 1})
bus_case(argument, bus={0xacd8: 1, 0xacd0: FLUSH_WORD})
bus_case(argument, bus={0xacd8: 1, 0x7c48: FLUSH_WORD})
bus_case(argument, bus={0xacbc: 1})
for offset in GPU_GATES:
bus_case(argument, gpu={offset: 0 if offset == 0x915 else 1})
bus_case(argument, gpu={0xe00: 1, 0x4de7: 1})
bus_case(argument, gpu={0xe00: 1, 0x4de7: 1, 0x52f9: 1})
for offset, value in saved_gates.items():
b(GPU + offset, value)
q(GPU + 0x1f80, saved_1f80)
hooks[text("_nv031478rm")] = _section_saved
# ------------------------------------------------- Q: the gates of the request
REQUEST = fixture(0x40)
KERNEL = pointer(PMU + 0xb08) # the object the PMU class and Lpwr test: byte +48
REQUEST_GATES = (0x917, 0x918, 0x919, 0x926, 0xc98, 0xd78)
# The PCI presence test behind GPU+d78; answered "absent" here.
hooks[text("_nv030949rm")] = ("_nv030949rm", lambda a, low: (emit("pci"), 0)[1])
def gate_case(gpu=None, prepared=1, kernel_48=0, size=0x18, first=0):
ready()
for offset, value in (gpu or {}).items():
b(GPU + offset, value)
b(F_PMU + 0x583, prepared)
b(KERNEL + 0x48, kernel_48)
request = bytearray(0x40)
request[0], request[1] = first, 0x0a
cpu.mem_write(REQUEST, bytes(request))
irq["pending"] = [None] * 64
state["checks"] = [0x65] * 4
q(STACK + 0xfff00 + 8, 1) # seventh argument: the low-priority command queue
status = call("_nv052461rm", GPU, TRANSPORT + 8, REQUEST, size, 0, 0, 1)
posted = any(token.startswith("w:10a804") for token in trace)
row("Q", " ".join(f"g{offset:x}={value:x}" for offset, value in (gpu or {}).items()),
f"{prepared:x}{kernel_48:x}", f"{size:x}", f"{first:x}", f"{status:x}", f"{int(posted)}",
f"{byte(TRANSPORT + 8 + 0x9b4):x}{byte(TRANSPORT + 8 + 0x9b5):x}")
for offset in (gpu or {}):
b(GPU + offset, 0)
pmu_restore(STARTED)
if True:
saved_request_gates = {offset: byte(GPU + offset) for offset in REQUEST_GATES}
for offset in (0x917, 0x918, 0x919, 0x926, 0xd78):
gate_case(gpu={offset: 1})
gate_case(gpu={0x917: 1, 0xd78: 1})
gate_case(kernel_48=1)
gate_case(size=0x7f1)
for offset, value in saved_request_gates.items():
b(GPU + offset, value)
hooks.pop(text("_nv030949rm"))
# ------------------------------------------------------------- L: _nv043006rm
ready()
LPWR_OBJECT, CONTROLS = fixture(0x2000), fixture(0x2000)
MUTEX = fixture(0x1000)
saved_lpwr = pointer(GPU + 0x22c8), pointer(GPU + 0x1f50)
hooks[text("_nv042849rm")] = ("_nv042849rm", lambda a, low: (emit(f"lp:on:{low[2]:x}"), 0)[1])
hooks[text("_nv042853rm")] = ("_nv042853rm", lambda a, low: (emit(f"lp:off:{low[2]:x}"), 0)[1])
hooks[text("_nv031518rm")] = ("_nv031518rm", lambda a, low: (emit(f"lp:mx:{low[1]:x}"), 0)[1])
hooks[text("_nv031522rm")] = ("_nv031522rm", lambda a, low: (emit(f"lp:mr:{low[1]:x}"), 0)[1])
def lpwr_case(controls, features_4, enable, ready=1, kernel_48=0, object_present=1):
cpu.mem_write(LPWR_OBJECT, bytes(0x2000))
cpu.mem_write(CONTROLS, bytes(0x2000))
q(LPWR_OBJECT + 0x11c0, CONTROLS if object_present else 0)
d(CONTROLS + 0xe0, controls)
d(CONTROLS + 0x130 + 0x108 * 4, features_4)
b(F_PMU + 0x583, ready)
b(KERNEL + 0x48, kernel_48)
q(GPU + 0x1f50, MUTEX)
del trace[:]
status = call("_nv043006rm", GPU, LPWR_OBJECT, enable)
row("L", f"{controls:x}", f"{features_4:x}", f"{enable:x}",
f"{ready:x}{kernel_48:x}{object_present:x}", f"{status:x}", f"{byte(LPWR_OBJECT + 0x122a):x}",
accesses())
b(F_PMU + 0x583, 1)
b(KERNEL + 0x48, 0)
for enable in (1, 0):
lpwr_case(0, 0, enable)
lpwr_case(0, 0xffffffff, enable)
lpwr_case(0x1ffff7, 0x100000, enable)
lpwr_case(0x200, 0, enable)
lpwr_case(0x210, 0x100000, enable)
lpwr_case(0x230, 0x100000, enable)
lpwr_case(0x10, 0x100000, enable)
lpwr_case(0x1ffff7, 0x100000, enable, ready=0)
lpwr_case(0x1ffff7, 0x100000, enable, kernel_48=1)
lpwr_case(0x1ffff7, 0x100000, enable, object_present=0)
for name in ("_nv042849rm", "_nv042853rm", "_nv031518rm", "_nv031522rm"):
hooks.pop(text(name))
q(GPU + 0x1f50, saved_lpwr[1])
# ------------------------------------------------------------- M: _nv044310rm
# Executed in the environment of tools/check_gpu_graphics_zbc_binary.py, in a process of
# its own (`--memory` below); its rows are appended here.
import subprocess # noqa: E402
MEMORY = json.loads(subprocess.run([sys.executable, str(SELF), "--memory"], check=True,
capture_output=True, text=True).stdout.splitlines()[-1])
for line in MEMORY["rows"]:
row(*line.split("|"))
q(GPU + 0x22c8, saved_lpwr[0])
# -------------------------------------------------------------- B: object bytes
pmu_restore(STARTED)
PMU_BYTES = (0x42a, 0x42b, 0x435, 0x438, 0x43b, 0x43c, 0x563, 0x56c, 0x570, 0x58c, 0x5c7, 0x5de,
0x9a2, 0xaf8)
row("B", "pmu", " ".join(f"{offset:x}={byte(PMU + offset):x}" for offset in PMU_BYTES),
f"cb0={word(PMU + 0xcb0):x}")
LOOKUP = fixture(8)
for falcon in (7, 2, 3, 0, 5):
q(LOOKUP, 0)
status = call("_nv043198rm", GPU, LSFM, falcon, LOOKUP)
found = pointer(LOOKUP) if status == 0 else 0
row("B", f"falcon{falcon:x}", f"{status:x}",
" ".join(f"{offset:x}={byte(found + offset):x}"
for offset in (0x3a2, 0x3a3, 0x3a4, 0x3a7, 0x3ac, 0x583)) if found else "",
f"608={word(found + 0x608):x}" if found else "")
# ---------------------------------------------------- D: boot vector and OS word
DESCRIPTOR = pointer(F_PMU + 0x3e8)
require(DESCRIPTOR)
row("D", f"{word(DESCRIPTOR + 8):x}", f"{word(DESCRIPTOR + 0x50):x}",
f"{word(DESCRIPTOR + 0x60):x}", f"{word(DESCRIPTOR + 0xc):x}")
require((word(DESCRIPTOR + 0x60), word(DESCRIPTOR + 0xc)) == (0x5e00, 0x2498436))
CHECK_MODE = "--check" in sys.argv
out = ROOT / "target/gpu-stage"
oracle = "\n".join(rows) + "\n"
write_or_check_text(out / "original-pmu-level.txt", oracle, check=CHECK_MODE)
report = {
"original_sha256": DIGEST, "chip_hal": "0x23", "rm_hal": 2,
"environment": "tools/check_gpu_pmu_fbq_binary.py setup part",
"cases": len(rows), "cases_by_kind": counts,
"oracle": "target/gpu-stage/original-pmu-level.txt",
"oracle_sha256": hashlib.sha256(oracle.encode()).hexdigest(),
"clock_domain_0x13": {
"schematics_built": len([key for key in SCHEMATICS if len(key) == 2]),
"schematic_sha256": {f"display={key[0]} memory_word={key[1]}":
hashlib.sha256(value).hexdigest()
for key, value in SCHEMATICS.items() if len(key) == 2},
"chain_equal_in_all": True,
"traced_registers": [f"{offset:#x}={value:#x}" for offset, value in
zip(CLOCK_REGISTERS, TRACED_CLOCK)],
"traced_result_khz": 540000, "transcript_lines": [147426, 147429]},
"fuse_slots": {f"{offset:#x}": name for offset, name in FUSE_SLOTS.items()},
"kernel_bus_slots": {f"{offset:#x}": name for offset, name in KBUS_SLOTS.items()},
"memory_system_slots": MEMORY["slots"],
"ltc_register_objects": {"count": MEMORY["count"], "bases": MEMORY["bases"],
"environment": "tools/check_gpu_graphics_zbc_binary.py"},
"scope": "Original GV100 functions of other objects called by the PMU start, the queue "
"transport and the PMU unload. Register values, time and the listed services "
"are fixture-supplied; no hardware executed."}
write_or_check_json(ROOT / "reports/gpu-pmu-level-original.json", report, check=CHECK_MODE)
print(f"{len(rows)} original PMU level cases {counts}; oracle sha256 {report['oracle_sha256']}")