aboutsummaryrefslogtreecommitdiffstats
path: root/psp_out/probe_c2p_mailbox.py
blob: 465d78f761c8636b92fd24d9847d1476954ccb39 (plain) (blame)
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
"""C2P / AGESA PSP mailbox sweep with the CORRECT command encoding.

bl_c2p_dispatch (sos2 0x13448) reads the command from bits[23:16] (BYTE2) of the
mailbox word; low 16 bits = status returned; bit31 = complete. The prior sweep
(ATTACK-SURFACE.md) wrote raw ids into C2PMSG_35 -> BYTE2==0 -> every command
decoded as 0 -> unknown -> uniform 0x8000000a. This retests with id in BYTE2.

Decision:
  * if KNOWN ids (0x03/0x05/0x14/0x1B/0x27/0x2F/0x33/0x34/0x38 etc.) return a
    status DIFFERENT from unknown ids -> the mailbox surface is host-reachable.
  * if everything is still uniform -> genuinely boot-only / vestigial on dGPU.

Protocol (from prior confirmed sweep): write C2PMSG_35 with bit31 clear = submit;
firmware replies with bit31 set. C2PMSG_36 carries a data/param word.

Non-destructive: only touches the C2PMSG_35/36 mailbox (separate from the GFX
ring at C2PMSG_64/67/69/70/81). The prior sweep did 256 of these safely.
"""
import time
from tinygrad import Device

d = Device["AMD"]; adev = d.iface.dev_impl; psp = adev.psp
pref = psp.reg_pref
def alive(): return adev.reg(f"{pref}_81").read() != 0

def mbox(word, param=0, timeout=1.0):
    adev.reg(f"{pref}_36").write(param & 0xFFFFFFFF)
    adev.reg(f"{pref}_35").write(word & 0x7FFFFFFF)   # bit31 clear = submit
    t0 = time.time()
    while time.time() - t0 < timeout:
        v = adev.reg(f"{pref}_35").read()
        if v & 0x80000000:
            return v, adev.reg(f"{pref}_36").read(), time.time() - t0
        time.sleep(0.001)
    return None, None, time.time() - t0

# ids bl_c2p_dispatch / bl_psp_mbox_dispatch recognise
KNOWN = [0x03,0x05,0x06,0x14,0x1B,0x1E,0x21,0x26,0x27,0x2C,0x2D,0x2F,
         0x30,0x31,0x33,0x34,0x35,0x36,0x38,0x49,0x4A,0x4B,0x50,0x51,0x53,0x54]
UNKNOWN = [0x00,0x02,0x08,0x0A,0x11,0x1F,0x40,0x5F,0x6B,0x77,0x99,0xAB,0xDE,0xFE]

print("alive:", alive())

def run(enc, ids, label):
    print("\n=== %s (%s) ===" % (label, enc))
    out = {}
    for i in ids:
        if not alive():
            print("  !! sOS dead at id 0x%02x" % i); break
        word = (i << 16) if enc == "BYTE2" else i
        v, data, dt = mbox(word)
        key = "TIMEOUT" if v is None else hex(v)
        out.setdefault(key, []).append(i)
        print("  id 0x%02x -> reply=%-12s data=%s dt=%.3f" %
              (i, key, "n/a" if data is None else hex(data), dt))
    return out

# control: reproduce the old result with low-byte encoding
run("raw", KNOWN[:6] + UNKNOWN[:4], "control: raw-id encoding (expect uniform)")
# the real test: id in BYTE2
kb = run("BYTE2", KNOWN, "known ids, BYTE2 encoding")
ub = run("BYTE2", UNKNOWN, "unknown ids, BYTE2 encoding")

print("\n=== VERDICT ===")
kset = set(kb.keys()); uset = set(ub.keys())
print("known-id replies :", {k: len(v) for k, v in kb.items()})
print("unknown-id replies:", {k: len(v) for k, v in ub.items()})
if kset - uset:
    print(">>> REACHABLE: known ids produce replies %s that unknowns do not" % (kset - uset))
elif len(kset | uset) > 1:
    print(">>> partial signal: multiple distinct replies %s" % (kset | uset))
else:
    print(">>> uniform -> mailbox not command-reachable this way (boot-only/vestigial)")
print("alive at end:", alive())