1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
#!/usr/bin/env python3
"""Determine the current gate state, then map which table indices are accepted.
Last run: PowerUpVcn returned 255 (likely "already on" -- VCN was powered in the
previous run and there has been no ATX cycle since), and a well-formed size=8
table returned 0xffff0006 rather than the gate error. If the gate is in fact
open, 0xffff0006 is an INDEX rejection and there is validation on the index that
FINDING-LOADIPFW-VCN-REGWRITE.md did not describe.
Establish the gate state first (oversize probe, no writes), then sweep indices
with a 1-entry table and classify.
Progress to /tmp/vcnidx.txt before every call.
"""
import struct, time
from tinygrad import Device
import tinygrad.runtime.autogen.am.am as am
OUT = "/tmp/vcnidx.txt"
def say(s):
with open(OUT, "a") as f:
f.write(s + "\n")
print(s, flush=True)
adev = Device["AMD"].iface.dev_impl
psp = adev.psp
hb = adev.reg("regMP0_SMN_C2PMSG_81")
def alive():
a = hb.read(); time.sleep(0.25); return hb.read() != a
def submit(fw_type, payload):
psp._prep_msg1(memoryview(bytes(payload)) if payload else memoryview(b"\x00" * 8))
cmd = am.struct_psp_gfx_cmd_resp(cmd_id=am.GFX_CMD_ID_LOAD_IP_FW)
cmd.cmd.cmd_load_ip_fw.fw_phy_addr_lo = psp.msg1_addr & 0xFFFFFFFF
cmd.cmd.cmd_load_ip_fw.fw_phy_addr_hi = psp.msg1_addr >> 32
cmd.cmd.cmd_load_ip_fw.fw_size = len(payload)
cmd.cmd.cmd_load_ip_fw.fw_type = fw_type
try:
return psp._ring_submit(cmd).resp.status & 0xFFFFFFFF
except RuntimeError as e:
return int(str(e).rsplit(" ", 1)[-1]) & 0xFFFFFFFF
say("\n######## gate state + index sweep ########")
say("psp alive %s / smu alive %s" % (alive(), adev.smu.is_smu_alive()))
g49 = submit(49, b"\x00" * 0x208)
g50 = submit(50, b"\x00" * 0x208)
g85 = submit(85, b"\x00" * 0x208)
say("oversize probe: type49=%#010x type50=%#010x type85=%#010x" % (g49, g50, g85))
say(" 0xffff3024 = gate closed, 0xffff300f = reached vf_table_lookup")
say(" => type 49 gate is %s" % ("OPEN" if g49 == 0xFFFF300F else
"CLOSED" if g49 == 0xFFFF3024 else "UNKNOWN"))
if g49 != 0xFFFF300F:
say("gate not open; trying PowerUpVcn(0)")
try:
adev.smu._send_msg(adev.smu.smu_mod.PPSMC_MSG_PowerUpVcn, 0)
say(" PowerUpVcn OK")
except Exception as e:
say(" PowerUpVcn: %s" % str(e)[:70])
g49 = submit(49, b"\x00" * 0x208)
say(" re-probe type49 = %#010x" % g49)
say("\nindex sweep, 1 entry {index, 0xA5A5A5A5}:")
res = {}
for idx in (0x0000, 0x0001, 0x0010, 0x0040, 0x0080, 0x00C0, 0x0100, 0x0180,
0x01FF, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000, 0xFFFF):
st = submit(49, struct.pack("<II", idx, 0xA5A5A5A5))
res[idx] = st
say(" index %#06x -> %#010x %s" % (idx, st, "ACCEPTED (write executed)" if st == 0 else ""))
if not alive():
say(" !! psp heartbeat stopped after index %#x -- stopping" % idx)
break
ok = [hex(k) for k, v in res.items() if v == 0]
say("\naccepted indices: %s" % (ok or "none"))
say("distinct statuses: %s" % {hex(v): sum(1 for x in res.values() if x == v) for v in set(res.values())})
say("psp alive %s / smu alive %s" % (alive(), adev.smu.is_smu_alive()))
|