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
|
#!/usr/bin/env python3
"""Does loading other TAs first make FP cmd 2 stall?
In isolation FP runs cmds 0-11 cleanly with cmd_buf_len=0x1000 (pass 80). In a corpus sweep
that loaded ta_16 and ta_18 first (each unloaded before the next), FP stalled at cmd 2.
If the preceding loads are what change FP's behaviour, that is cross-TA state contamination
in the platform, not a property of FP.
A FP alone, cmd 2 -> pass 80 says clean
B ta_16 loaded+unloaded, then FP -> ?
C ta_16 and ta_18 both, then FP -> the sweep's exact prefix
"""
import glob, struct, sys, time
sys.path.insert(0,'/root/psp/hw')
from tinygrad import Device
import tinygrad.runtime.autogen.am.am as am
from ring_wrap import install
adev=Device["AMD"].iface.dev_impl; psp=adev.psp
submit=install(psp,adev)
def alloc(n):
pa=adev.mm.palloc(n,align=0x1000,zero=True,boot=False); return pa,adev.paddr2mc(pa)
def load(path):
blob=open(path,'rb').read()
ap_,amc=alloc(0x80000); cp,cmc=alloc(0x8000)
n=(len(blob)+3)&~3
adev.vram.view(ap_,n)[:]=blob+b'\x00'*(n-len(blob)); adev.gmc.flush_hdp()
c=am.struct_psp_gfx_cmd_resp(cmd_id=am.GFX_CMD_ID_LOAD_TA); t=c.cmd.cmd_load_ta
t.app_phy_addr_lo,t.app_phy_addr_hi=amc&0xFFFFFFFF,amc>>32; t.app_len=len(blob)
t.cmd_buf_phy_addr_lo,t.cmd_buf_phy_addr_hi=cmc&0xFFFFFFFF,cmc>>32; t.cmd_buf_len=0x1000
try: r=submit(c); return r.resp.status&0xFFFFFFFF, r.resp.session_id, cp
except Exception as e:
try: return int(str(e).strip().split()[-1])&0xFFFFFFFF,None,cp
except Exception: return -1,None,cp
def unload(sid):
c=am.struct_psp_gfx_cmd_resp(cmd_id=am.GFX_CMD_ID_UNLOAD_TA); c.cmd.cmd_unload_ta.session_id=sid
try: return submit(c).resp.status&0xFFFFFFFF
except Exception: return -1
def inv(sid,shm,cid):
buf=bytearray(0x1000); struct.pack_into('<I',buf,0,cid)
adev.vram.view(shm,0x1000)[:]=bytes(buf); adev.gmc.flush_hdp()
c=am.struct_psp_gfx_cmd_resp(cmd_id=am.GFX_CMD_ID_INVOKE_CMD)
iv=c.cmd.cmd_invoke_cmd; iv.session_id,iv.ta_cmd_id=sid,cid
t0=time.time()
try: st=submit(c).resp.status&0xFFFFFFFF
except Exception as e:
try: st=int(str(e).strip().split()[-1])&0xFFFFFFFF
except Exception: st=-1
return st,time.time()-t0
FP=glob.glob('/root/psp/contall/ta_19-0-0-8_7e8be282*')[0]
pre=[p for p in (glob.glob('/root/psp/contall/ta_16-0-0-9_9e9044cf*')+
glob.glob('/root/psp/contall/ta_18-0-4-19_376639d1*'))]
case=sys.argv[1]
if case in ('B','C'):
for p in (pre if case=='C' else pre[:1]):
st,sid,shm=load(p)
print(' prefix %-34s load %#x sid=%s'%(p.rsplit('/',1)[1],st,sid), flush=True)
if sid is not None:
for cid in range(0,3):
s,dt=inv(sid,shm,cid)
if dt>5: print(' prefix stalled at cmd %d'%cid, flush=True); sys.exit(3)
unload(sid)
st,sid,shm=load(FP)
print('FP load %#x sid=%s'%(st,sid), flush=True)
for cid in (0,1,2,3):
s,dt=inv(sid,shm,cid)
print(' FP cmd %d -> %#-12x %.1fs%s'%(cid,s,dt,' <<< STALL' if dt>5 else ''), flush=True)
if dt>5: break
|