import struct, sys from tinygrad import Device adev = Device["AMD"].iface.dev_impl # locate the USB controller object (has pcie_mem_read + usb.control_write) def find_ctrl(root): seen=set(); stack=[root] while stack: o=stack.pop() if id(o) in seen: continue seen.add(id(o)) if hasattr(o,'pcie_mem_read') and hasattr(o,'usb'): return o for a in ('iface','dev_impl','usb','controller','ctrl','backend','_iface','pci'): if hasattr(o,a): try: stack.append(getattr(o,a)) except Exception: pass return None c1=Device["AMD"].iface.ctrl; ctrl=c1 if hasattr(c1,"pcie_mem_read") else adev.doorbell64.usb print("controller:", type(ctrl).__name__ if ctrl else None) assert ctrl is not None, "could not find USB controller" # scratch VRAM page -> PCIe/MC address the TLP engine targets pa = adev.mm.palloc(0x1000, align=0x1000, zero=True, boot=False) mc = adev.paddr2mc(pa) print("scratch paddr=%#x mc(TLP addr)=%#x" % (pa, mc)) def eb(addr, valA, valB, iters, fmt=0x60, byte_en=0x0F): payload = struct.pack('", "PASS" if v1==0xCAFEBABE else "FAIL") eb(mc, 0x11223344, 0xAABBCCDD, 2000) v2 = rd(mc); print("after A/B x2000 :", hex(v2), "-> last=B=AABBCCDD:", "PASS" if v2==0xAABBCCDD else "FAIL") # no-magic safety: wrong magic must be a no-op (value stays v2) bad = struct.pack(' must stay AABBCCDD (gated):", "PASS" if v3==0xAABBCCDD else "FAIL")