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
|
#!/usr/bin/env python3
"""Map what the host can actually reach over the SMN aperture on THIS card.
An "echo" result for an NV22 address is ambiguous: it could mean the block is
blocked from the host, or that NV31 puts it somewhere else. Sweeping settles it
without trusting the NV22 map at all -- if a region decodes anywhere, the
aperture reaches that neighbourhood.
READ ONLY.
"""
import struct, sys, time
from tinygrad import Device
adev = Device["AMD"].iface.dev_impl
idx = adev.reg("regBIF_BX0_PCIE_INDEX2")
dat = adev.reg("regBIF_BX0_PCIE_DATA2")
def smn_read(addr):
idx.write(addr & 0xFFFFFFFF)
return dat.read()
def bswap(x):
return struct.unpack("<I", struct.pack(">I", x & 0xFFFFFFFF))[0]
def decoded(addr):
v = smn_read(addr)
return v != bswap(addr) and v != 0xFFFFFFFF, v
lo, hi, step = 0x03000000, 0x04000000, 0x10000
t0 = time.time()
hits = []
for a in range(lo, hi, step):
ok, v = decoded(a)
if ok:
hits.append((a, v))
print("coarse sweep %#x..%#x step %#x : %d/%d decoded in %.1fs"
% (lo, hi, step, len(hits), (hi - lo) // step, time.time() - t0))
for a, v in hits[:40]:
print(" %#010x = %#010x" % (a, v))
# control: the C2PMSG window must show up as decoded under the same test
ok, v = decoded(0x581E8)
print("\n control C2PMSG_58 decoded=%s value=%#x" % (ok, v))
|