Skip to content

Commit 6e40dd9

Browse files
committed
m1n1.trace.agx: Add AGXDECODE solib support & trace VDM
Signed-off-by: Asahi Lina <[email protected]>
1 parent 825fbaf commit 6e40dd9

1 file changed

Lines changed: 55 additions & 2 deletions

File tree

proxyclient/m1n1/trace/agx.py

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SPDX-License-Identifier: MIT
22

3-
import textwrap, os.path, json, datetime
3+
import textwrap, os.path, json, datetime, ctypes
44
from .asc import *
55
from ..hw.uat import UAT, MemoryAttr, PTE, Page_PTE, TTBR
66
from ..hw.agx import *
@@ -416,6 +416,54 @@ def __init__(self, hv, devpath, verbose=False):
416416
self.last_3d = None
417417
self.last_cp = None
418418

419+
self.agxdecode = None
420+
421+
libagxdecode = os.getenv("AGXDECODE", None)
422+
if libagxdecode:
423+
self.init_agxdecode(libagxdecode)
424+
425+
def init_agxdecode(self, path):
426+
# Hack to make sure we reload the lib when it changes
427+
# tpath = os.getenv("XDG_RUNTIME_DIR", "/tmp") + "/" + str(time.time()) + ".so"
428+
# os.symlink(path, tpath)
429+
# lib = ctypes.cdll.LoadLibrary(tpath)
430+
lib = ctypes.cdll.LoadLibrary(path)
431+
432+
self.agxdecode = lib
433+
434+
read_gpu_mem = ctypes.CFUNCTYPE(ctypes.c_size_t, ctypes.c_uint64, ctypes.c_size_t, ctypes.c_void_p)
435+
stream_write = ctypes.CFUNCTYPE(ctypes.c_ssize_t, ctypes.POINTER(ctypes.c_char), ctypes.c_size_t)
436+
437+
class libagxdecode_config(ctypes.Structure):
438+
_fields_ = [
439+
("chip_id", ctypes.c_uint32),
440+
("read_gpu_mem", read_gpu_mem),
441+
("stream_write", stream_write),
442+
]
443+
444+
def _read_gpu_mem(addr, size, data):
445+
if addr < 0x100000000:
446+
addr |= 0x1100000000
447+
buf = self.read_func(addr, size)
448+
ctypes.memmove(data, buf, len(buf))
449+
return len(buf)
450+
451+
def _stream_write(buf, size):
452+
self.log(buf[:size].decode("ascii"))
453+
return size
454+
455+
# Keep refs
456+
self._read_gpu_mem = read_gpu_mem(_read_gpu_mem)
457+
self._stream_write = stream_write(_stream_write)
458+
459+
config = libagxdecode_config(self.chip_id, self._read_gpu_mem, self._stream_write)
460+
461+
self.agxdecode.libagxdecode_init(ctypes.pointer(config))
462+
463+
self.agxdecode.libagxdecode_vdm.argtypes = [ctypes.c_uint64, ctypes.c_char_p, ctypes.c_bool]
464+
self.agxdecode.libagxdecode_cdm.argtypes = [ctypes.c_uint64, ctypes.c_char_p, ctypes.c_bool]
465+
self.agxdecode.libagxdecode_usc.argtypes = [ctypes.c_uint64, ctypes.c_char_p, ctypes.c_bool]
466+
419467
def get_cmdqueue(self, info_addr, new_queue, queue_type):
420468
if info_addr in self.cmdqueues and not new_queue:
421469
return self.cmdqueues[info_addr]
@@ -813,6 +861,8 @@ def read(off, size):
813861
size -= block
814862
return data
815863

864+
self.read_func = read
865+
816866
#chexdump(kread(wi0.addr, 0x600), print_fn=self.log)
817867
self.log(f" context_id = {context:#x}")
818868
self.dump_buffer_manager(wi0.buffer_mgr, kread, read)
@@ -874,7 +924,10 @@ def read(off, size):
874924
data = read(wi0.struct_2.tvb_tilemap, 0x100000)
875925
self.log(f" tilemaps @ {wi0.struct_2.tvb_tilemap:#x}: ({len(data):#x})")
876926
chexdump(data, print_fn=self.log)
877-
#self.uat.dump(context, self.log)
927+
928+
if self.agxdecode:
929+
self.log("Decode VDM")
930+
self.agxdecode.libagxdecode_vdm(wi0.struct_2.encoder_addr, b"VDM", True)
878931

879932
regs = getattr(wi0, "registers", None)
880933
if regs is not None:

0 commit comments

Comments
 (0)