|
1 | 1 | # SPDX-License-Identifier: MIT |
2 | 2 |
|
3 | | -import textwrap, os.path, json, datetime |
| 3 | +import textwrap, os.path, json, datetime, ctypes |
4 | 4 | from .asc import * |
5 | 5 | from ..hw.uat import UAT, MemoryAttr, PTE, Page_PTE, TTBR |
6 | 6 | from ..hw.agx import * |
@@ -416,6 +416,54 @@ def __init__(self, hv, devpath, verbose=False): |
416 | 416 | self.last_3d = None |
417 | 417 | self.last_cp = None |
418 | 418 |
|
| 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 | + |
419 | 467 | def get_cmdqueue(self, info_addr, new_queue, queue_type): |
420 | 468 | if info_addr in self.cmdqueues and not new_queue: |
421 | 469 | return self.cmdqueues[info_addr] |
@@ -813,6 +861,8 @@ def read(off, size): |
813 | 861 | size -= block |
814 | 862 | return data |
815 | 863 |
|
| 864 | + self.read_func = read |
| 865 | + |
816 | 866 | #chexdump(kread(wi0.addr, 0x600), print_fn=self.log) |
817 | 867 | self.log(f" context_id = {context:#x}") |
818 | 868 | self.dump_buffer_manager(wi0.buffer_mgr, kread, read) |
@@ -874,7 +924,10 @@ def read(off, size): |
874 | 924 | data = read(wi0.struct_2.tvb_tilemap, 0x100000) |
875 | 925 | self.log(f" tilemaps @ {wi0.struct_2.tvb_tilemap:#x}: ({len(data):#x})") |
876 | 926 | 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) |
878 | 931 |
|
879 | 932 | regs = getattr(wi0, "registers", None) |
880 | 933 | if regs is not None: |
|
0 commit comments