aboutsummaryrefslogtreecommitdiffstats
path: root/bridge/ctl2.py
blob: e32ed03edf4126e4a99205ae1fec9354ced7d3b8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import struct
from tinygrad import Device
adev = Device["AMD"].iface.dev_impl
ctrl = adev.doorbell64.usb
def rd(mc): adev.gmc.flush_hdp(); return struct.unpack('<I', ctrl.pcie_mem_read(mc,4))[0]
def wr(mc,v): ctrl.pcie_mem_write(mc, struct.pack('<I',v)); adev.gmc.flush_hdp()
# two FAR-separated pages (1 MB apart)
p1=adev.mm.palloc(0x1000, align=0x1000, zero=True, boot=False); m1=adev.paddr2mc(p1)
p2=adev.mm.palloc(0x100000, align=0x100000, zero=True, boot=False); m2=adev.paddr2mc(p2)+0x80000
print("m1=%#x m2=%#x (delta=%#x)"%(m1,m2,m2-m1))
wr(m1,0x11111111)
print("after wr m1: rd(m1)=%#x"%rd(m1))
wr(m2,0x22222222)
print("after wr m2: rd(m2)=%#x  rd(m1)=%#x (aliasing if m1 shows 22222222)"%(rd(m2),rd(m1)))
# read m1 twice more to see if it's stable
print("rd(m1) again=%#x  rd(m2) again=%#x"%(rd(m1),rd(m2)))
import os,sys; sys.stdout.flush(); os._exit(0)