experiments: Add misc AGX experiments

A lot of these are broken/out of date with the current code, but it's
good to have them committed...

Signed-off-by: Asahi Lina <lina@asahilina.net>
This commit is contained in:
Asahi Lina 2022-08-17 14:48:53 +09:00
parent 2506ccf63f
commit cfca18b83a
7 changed files with 1460 additions and 0 deletions

View file

@ -0,0 +1,241 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: MIT
import sys, pathlib, time
sys.path.append(str(pathlib.Path(__file__).resolve().parents[1]))
import atexit, sys
from m1n1.agx import AGX
from m1n1.agx.render import *
from m1n1.setup import *
from m1n1 import asm
from m1n1.gpiola import GPIOLogicAnalyzer
analyzer_cpu = 1
p.pmgr_adt_clocks_enable("/arm-io/gfx-asc")
p.pmgr_adt_clocks_enable("/arm-io/sgx")
p.smp_start_secondaries()
p.mmu_init_secondary(analyzer_cpu)
iface.dev.timeout = 42
agx = AGX(u)
mon = RegMonitor(u, ascii=True, bufsize=0x8000000)
agx.mon = mon
sgx = agx.sgx_dev
atexit.register(p.reboot)
agx.start()
mon.poll()
agx.poll_objects()
ctx = GPUContext(agx)
ctx.bind(63)
f = GPUFrame(ctx, sys.argv[1], track=False)
r = GPURenderer(ctx, 128, bm_slot=0x10, queue=1)
dep_stamp = agx.kobj.new(StampCounter, name="Dep stamp")
dep_stamp.value = 0x100
dep_stamp.push()
#r.submit(f.cmdbuf, (dep_stamp._addr, 0x200, 0x10))
r.submit(f.cmdbuf)
r.submit(f.cmdbuf)
def t(addr):
paddr = agx.uat.iotranslate(0, addr, 4)[0][0]
if paddr is None:
raise Exception(f"Failed to iotranslate {addr:#x}")
return paddr
regs = {
"ta_cmds": t(agx.initdata.regionB.stats_ta.addrof("total_cmds")),
"ta_ts": t(agx.initdata.regionB.stats_ta.stats.addrof("unk_timestamp")),
}
pend_base = agx.initdata.regionC.addrof("pending_stamps")
for i in range(5):
regs[f"st{i}_info"] = t(pend_base + i*8)
regs[f"st{i}_val"] = t(pend_base + i*8 + 4)
for i in range(4):
regs[f"ta{i}_cq"] = t(agx.initdata.regionB.stats_ta.stats.queues[i].addrof("cur_cmdqueue"))
regs.update({
#"pwr_status": t(agx.initdata.regionB.hwdata_a.addrof("pwr_status")),
#"pstate": t(agx.initdata.regionB.hwdata_a.addrof("cur_pstate")),
#"temp_c": t(agx.initdata.regionB.hwdata_a.addrof("temp_c")),
#"pwr_mw": t(agx.initdata.regionB.hwdata_a.addrof("avg_power_mw")),
#"pwr_ts": t(agx.initdata.regionB.hwdata_a.addrof("update_ts")),
#"unk_10": t(agx.initdata.regionB.hwdata_a.addrof("unk_10")),
#"unk_14": t(agx.initdata.regionB.hwdata_a.addrof("unk_14")),
#"actual_pstate": t(agx.initdata.regionB.hwdata_a.addrof("actual_pstate")),
#"tgt_pstate": t(agx.initdata.regionB.hwdata_a.addrof("tgt_pstate")),
#"unk_40": t(agx.initdata.regionB.hwdata_a.addrof("unk_40")),
#"unk_44": t(agx.initdata.regionB.hwdata_a.addrof("unk_44")),
#"unk_48": t(agx.initdata.regionB.hwdata_a.addrof("unk_48")),
#"freq_mhz": t(agx.initdata.regionB.hwdata_a.addrof("freq_mhz")),
#"unk_748.0": t(agx.initdata.regionB.hwdata_a.addrof("unk_748")),
#"unk_748.1": t(agx.initdata.regionB.hwdata_a.addrof("unk_748")+4),
#"unk_748.2": t(agx.initdata.regionB.hwdata_a.addrof("unk_748")+8),
#"unk_748.3": t(agx.initdata.regionB.hwdata_a.addrof("unk_748")+12),
#"use_percent": t(agx.initdata.regionB.hwdata_a.addrof("use_percent")),
#"unk_83c": t(agx.initdata.regionB.hwdata_a.addrof("unk_83c")),
#"freq_with_off": t(agx.initdata.regionB.hwdata_a.addrof("freq_with_off")),
#"unk_ba0": t(agx.initdata.regionB.hwdata_a.addrof("unk_ba0")),
#"unk_bb0": t(agx.initdata.regionB.hwdata_a.addrof("unk_bb0")),
#"unk_c44": t(agx.initdata.regionB.hwdata_a.addrof("unk_c44")),
#"unk_c58": t(agx.initdata.regionB.hwdata_a.addrof("unk_c58")),
#"unk_3ca0": t(agx.initdata.regionB.hwdata_a.addrof("unk_3ca0")),
#"unk_3ca8": t(agx.initdata.regionB.hwdata_a.addrof("unk_3ca8")),
#"unk_3cb0": t(agx.initdata.regionB.hwdata_a.addrof("unk_3cb0")),
#"ts_last_idle": t(agx.initdata.regionB.hwdata_a.addrof("ts_last_idle")),
#"ts_last_poweron": t(agx.initdata.regionB.hwdata_a.addrof("ts_last_poweron")),
#"ts_last_poweroff": t(agx.initdata.regionB.hwdata_a.addrof("ts_last_poweroff")),
#"unk_3cd0": t(agx.initdata.regionB.hwdata_a.addrof("unk_3cd0")),
"halt_count": t(agx.initdata.fw_status.addrof("halt_count")),
"halted": t(agx.initdata.fw_status.addrof("halted")),
"resume": t(agx.initdata.fw_status.addrof("resume")),
"unk_40": t(agx.initdata.fw_status.addrof("unk_40")),
"unk_ctr": t(agx.initdata.fw_status.addrof("unk_ctr")),
"unk_60": t(agx.initdata.fw_status.addrof("unk_60")),
"unk_70": t(agx.initdata.fw_status.addrof("unk_70")),
"c_118c0": t(agx.initdata.regionC._addr + 0x118c0),
"c_118c4": t(agx.initdata.regionC._addr + 0x118c4),
"c_118c8": t(agx.initdata.regionC._addr + 0x118c8),
"c_118cc": t(agx.initdata.regionC._addr + 0x118cc),
"c_118d0": t(agx.initdata.regionC._addr + 0x118d0),
"c_118d4": t(agx.initdata.regionC._addr + 0x118d4),
"c_118d8": t(agx.initdata.regionC._addr + 0x118d8),
"c_118dc": t(agx.initdata.regionC._addr + 0x118dc),
"3d_cmds": t(agx.initdata.regionB.stats_3d.addrof("total_cmds")),
#"3d_tvb_oflws_1": t(agx.initdata.regionB.stats_3d.stats.addrof("tvb_overflows_1")),
#"3d_tvb_oflws_2": t(agx.initdata.regionB.stats_3d.stats.addrof("tvb_overflows_2")),
"3d_cur_stamp_id": t(agx.initdata.regionB.stats_3d.stats.addrof("cur_stamp_id")),
"3d_ts": t(agx.initdata.regionB.stats_3d.stats.addrof("unk_timestamp")),
#"3d_cur_stamp_id": t(agx.initdata.regionB.stats_3d.stats.addrof("cur_stamp_id")),
})
for i in range(4):
regs[f"3d{i}_cq"] = t(agx.initdata.regionB.stats_3d.stats.queues[i].addrof("cur_cmdqueue"))
i = 0
regs.update({
f"r{i}_3d_done": t(r.wq_3d.info.pointers.addrof("gpu_doneptr")),
#f"r{i}_3d_rptr": t(r.wq_3d.info.pointers.addrof("gpu_rptr")),
f"r{i}_3d_busy": t(r.wq_3d.info.addrof("busy")),
#f"r{i}_3d_blk": t(r.wq_3d.info.addrof("blocked_on_barrier")),
#f"r{i}_3d_2c": t(r.wq_3d.info.addrof("unk_2c")),
#f"r{i}_3d_54": t(r.wq_3d.info.addrof("unk_54")),
f"r{i}_ta_done": t(r.wq_ta.info.pointers.addrof("gpu_doneptr")),
#f"r{i}_ta_rptr": t(r.wq_ta.info.pointers.addrof("gpu_rptr")),
f"r{i}_ta_busy": t(r.wq_ta.info.addrof("busy")),
#f"r{i}_ta_blk": t(r.wq_ta.info.addrof("blocked_on_barrier")),
#f"r{i}_ta_2c": t(r.wq_ta.info.addrof("unk_2c")),
#f"r{i}_ta_54": t(r.wq_ta.info.addrof("unk_54")),
f"r{i}_ta_stamp1": t(r.stamp_ta1._addr),
f"r{i}_ta_stamp2":t(r.stamp_ta2._addr),
f"r{i}_3d_stamp1": t(r.stamp_3d1._addr),
f"r{i}_3d_stamp2":t(r.stamp_3d2._addr),
f"r{i}_ev_cnt":t(r.event_control.event_count._addr),
f"r{i}_ev_cur":t(r.event_control.addrof("cur_count")),
f"r{i}_ev_10":t(r.event_control.addrof("unk_10")),
})
div=4
ticks = 24000000 // div * 25
la = GPIOLogicAnalyzer(u, regs=regs, cpu=analyzer_cpu, div=div)
print("Queues:")
print(f" TA: {r.wq_ta.info._addr:#x} (stamp {r.work[0].ev_ta.id})")
#print(r.wq_ta.info)
print(f" 3D: {r.wq_3d.info._addr:#x} (stamp {r.work[0].ev_3d.id})")
#print(r.wq_3d.info)
print("==========================================")
print("## Run")
print("==========================================")
la.start(ticks, bufsize=0x8000000)
t = time.time()
buf = agx.kobj.new_buf(0x1000, "foo")
buf.val = b"A" * 0x1000
buf.push()
agx.uat.flush_dirty()
try:
r.run()
#for a in range(8):
#for b in range(8):
#agx.ch.devctrl.dc_1e(a, b)
#agx.uat.flush_dirty()
#agx.ch.devctrl.write32(dep_stamp._addr, 0x200)
#data = struct.pack("<QQQQQI", 0xaaaa, buf._addr, 0xbbbb, 0, 0, 0)
#agx.poll_objects()
#mon.poll()
#agx.ch.devctrl.send_foo(9, data)
#agx.ch.devctrl.dc_09(0xaaaa, buf._addr, 0xbbbb)
#for i in range(0x28, 0xff):
#print(hex(i))
#data = struct.pack("<QQQQQI", dep_stamp._addr, 0x10_00000200, buf._addr, 0x12_00000010, 0x13_00000010, 0x10)
#agx.ch.devctrl.send_foo(i, data)
#agx.asc.work()
#time.sleep(0.1)
#agx.poll_objects()
#mon.poll()
#time.sleep(0.1)
#agx.asc.work()
#chexdump(buf.pull().val)
agx.kick_firmware()
while not r.ev_3d.fired:
agx.asc.work()
agx.poll_channels()
print("==========================================")
#agx.poll_objects()
#mon.poll()
agx.kick_firmware()
if time.time() > t + 2:
raise Exception("Timeout")
r.wait()
finally:
dep_stamp.pull()
print(f"Stamp value: {dep_stamp.value:#x}")
#agx.poll_objects()
#mon.poll()
la.complete()
la.show()
time.sleep(2)

View file

@ -0,0 +1,237 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: MIT
import sys, pathlib, time
sys.path.append(str(pathlib.Path(__file__).resolve().parents[1]))
import atexit, sys
from m1n1.agx import AGX
from m1n1.agx.render import *
from m1n1.setup import *
from m1n1 import asm
from m1n1.gpiola import GPIOLogicAnalyzer
analyzer_cpu = 1
p.pmgr_adt_clocks_enable("/arm-io/gfx-asc")
p.pmgr_adt_clocks_enable("/arm-io/sgx")
p.smp_start_secondaries()
p.mmu_init_secondary(analyzer_cpu)
iface.dev.timeout = 42
agx = AGX(u)
mon = RegMonitor(u, ascii=True, bufsize=0x8000000)
agx.mon = mon
sgx = agx.sgx_dev
#mon.add(sgx.gpu_region_base, sgx.gpu_region_size, "contexts")
#mon.add(sgx.gfx_shared_region_base, sgx.gfx_shared_region_size, "gfx-shared")
#mon.add(sgx.gfx_handoff_base, sgx.gfx_handoff_size, "gfx-handoff")
#mon.add(agx.initdasgx.gfx_handoff_base, sgx.gfx_handoff_size, "gfx-handoff")
atexit.register(p.reboot)
agx.start()
print("==========================================")
print("## After init")
print("==========================================")
mon.poll()
agx.poll_objects()
ctx = GPUContext(agx)
ctx.bind(63)
f = GPUFrame(ctx, sys.argv[1], track=False)
RENDERERS = 4
renderers = []
for i in range(RENDERERS):
r = GPURenderer(ctx, 128, bm_slot=0x10 + i, queue=1)
renderers.append(r)
for q in (r.wq_3d, r.wq_ta):
q.info.set_prio(2)
q.info.push()
print("==========================================")
print("## Submitting")
print("==========================================")
w = renderers[3].submit(f.cmdbuf)
w = renderers[0].submit(f.cmdbuf, w)
w = renderers[2].submit(f.cmdbuf, w)
w = renderers[1].submit(f.cmdbuf, w)
w = renderers[3].submit(f.cmdbuf, w)
w = renderers[3].submit(f.cmdbuf, w)
w = renderers[1].submit(f.cmdbuf, w)
w = renderers[1].submit(f.cmdbuf, w)
w = renderers[0].submit(f.cmdbuf, w)
for i, r in enumerate(renderers):
r.submit(f.cmdbuf)
print("==========================================")
print("## Submitted")
print("==========================================")
def t(addr):
paddr = agx.uat.iotranslate(0, addr, 4)[0][0]
if paddr is None:
raise Exception(f"Failed to iotranslate {addr:#x}")
return paddr
regs = {
"ta_cmds": t(agx.initdata.regionB.stats_ta.addrof("total_cmds")),
"ta_ts": t(agx.initdata.regionB.stats_ta.stats.addrof("unk_timestamp")),
}
pend_base = agx.initdata.regionC.addrof("pending_stamps")
for i in range(5):
regs[f"st{i}_info"] = t(pend_base + i*8)
regs[f"st{i}_val"] = t(pend_base + i*8 + 4)
for i in range(4):
regs[f"ta{i}_cq"] = t(agx.initdata.regionB.stats_ta.stats.queues[i].addrof("cur_cmdqueue"))
regs.update({
#"pwr_status": t(agx.initdata.regionB.hwdata_a.addrof("pwr_status")),
#"pstate": t(agx.initdata.regionB.hwdata_a.addrof("cur_pstate")),
#"temp_c": t(agx.initdata.regionB.hwdata_a.addrof("temp_c")),
#"pwr_mw": t(agx.initdata.regionB.hwdata_a.addrof("avg_power_mw")),
#"pwr_ts": t(agx.initdata.regionB.hwdata_a.addrof("update_ts")),
#"unk_10": t(agx.initdata.regionB.hwdata_a.addrof("unk_10")),
#"unk_14": t(agx.initdata.regionB.hwdata_a.addrof("unk_14")),
#"actual_pstate": t(agx.initdata.regionB.hwdata_a.addrof("actual_pstate")),
#"tgt_pstate": t(agx.initdata.regionB.hwdata_a.addrof("tgt_pstate")),
#"unk_40": t(agx.initdata.regionB.hwdata_a.addrof("unk_40")),
#"unk_44": t(agx.initdata.regionB.hwdata_a.addrof("unk_44")),
#"unk_48": t(agx.initdata.regionB.hwdata_a.addrof("unk_48")),
#"freq_mhz": t(agx.initdata.regionB.hwdata_a.addrof("freq_mhz")),
#"unk_748.0": t(agx.initdata.regionB.hwdata_a.addrof("unk_748")),
#"unk_748.1": t(agx.initdata.regionB.hwdata_a.addrof("unk_748")+4),
#"unk_748.2": t(agx.initdata.regionB.hwdata_a.addrof("unk_748")+8),
#"unk_748.3": t(agx.initdata.regionB.hwdata_a.addrof("unk_748")+12),
#"use_percent": t(agx.initdata.regionB.hwdata_a.addrof("use_percent")),
#"unk_83c": t(agx.initdata.regionB.hwdata_a.addrof("unk_83c")),
#"freq_with_off": t(agx.initdata.regionB.hwdata_a.addrof("freq_with_off")),
#"unk_ba0": t(agx.initdata.regionB.hwdata_a.addrof("unk_ba0")),
#"unk_bb0": t(agx.initdata.regionB.hwdata_a.addrof("unk_bb0")),
#"unk_c44": t(agx.initdata.regionB.hwdata_a.addrof("unk_c44")),
#"unk_c58": t(agx.initdata.regionB.hwdata_a.addrof("unk_c58")),
#"unk_3ca0": t(agx.initdata.regionB.hwdata_a.addrof("unk_3ca0")),
#"unk_3ca8": t(agx.initdata.regionB.hwdata_a.addrof("unk_3ca8")),
#"unk_3cb0": t(agx.initdata.regionB.hwdata_a.addrof("unk_3cb0")),
#"ts_last_idle": t(agx.initdata.regionB.hwdata_a.addrof("ts_last_idle")),
#"ts_last_poweron": t(agx.initdata.regionB.hwdata_a.addrof("ts_last_poweron")),
#"ts_last_poweroff": t(agx.initdata.regionB.hwdata_a.addrof("ts_last_poweroff")),
#"unk_3cd0": t(agx.initdata.regionB.hwdata_a.addrof("unk_3cd0")),
"halt_count": t(agx.initdata.fw_status.addrof("halt_count")),
"halted": t(agx.initdata.fw_status.addrof("halted")),
"resume": t(agx.initdata.fw_status.addrof("resume")),
"unk_40": t(agx.initdata.fw_status.addrof("unk_40")),
"unk_ctr": t(agx.initdata.fw_status.addrof("unk_ctr")),
"unk_60": t(agx.initdata.fw_status.addrof("unk_60")),
"unk_70": t(agx.initdata.fw_status.addrof("unk_70")),
"c_118c0": t(agx.initdata.regionC._addr + 0x118c0),
"c_118c4": t(agx.initdata.regionC._addr + 0x118c4),
"c_118c8": t(agx.initdata.regionC._addr + 0x118c8),
"c_118cc": t(agx.initdata.regionC._addr + 0x118cc),
"c_118d0": t(agx.initdata.regionC._addr + 0x118d0),
"c_118d4": t(agx.initdata.regionC._addr + 0x118d4),
"c_118d8": t(agx.initdata.regionC._addr + 0x118d8),
"c_118dc": t(agx.initdata.regionC._addr + 0x118dc),
"3d_cmds": t(agx.initdata.regionB.stats_3d.addrof("total_cmds")),
#"3d_tvb_oflws_1": t(agx.initdata.regionB.stats_3d.stats.addrof("tvb_overflows_1")),
#"3d_tvb_oflws_2": t(agx.initdata.regionB.stats_3d.stats.addrof("tvb_overflows_2")),
"3d_cur_stamp_id": t(agx.initdata.regionB.stats_3d.stats.addrof("cur_stamp_id")),
"3d_ts": t(agx.initdata.regionB.stats_3d.stats.addrof("unk_timestamp")),
#"3d_cur_stamp_id": t(agx.initdata.regionB.stats_3d.stats.addrof("cur_stamp_id")),
})
for i in range(4):
regs[f"3d{i}_cq"] = t(agx.initdata.regionB.stats_3d.stats.queues[i].addrof("cur_cmdqueue"))
for i, r in enumerate(renderers):
regs.update({
f"r{i}_3d_done": t(r.wq_3d.info.pointers.addrof("gpu_doneptr")),
#f"r{i}_3d_rptr": t(r.wq_3d.info.pointers.addrof("gpu_rptr")),
f"r{i}_3d_busy": t(r.wq_3d.info.addrof("busy")),
#f"r{i}_3d_blk": t(r.wq_3d.info.addrof("blocked_on_barrier")),
#f"r{i}_3d_2c": t(r.wq_3d.info.addrof("unk_2c")),
#f"r{i}_3d_54": t(r.wq_3d.info.addrof("unk_54")),
f"r{i}_ta_done": t(r.wq_ta.info.pointers.addrof("gpu_doneptr")),
#f"r{i}_ta_rptr": t(r.wq_ta.info.pointers.addrof("gpu_rptr")),
f"r{i}_ta_busy": t(r.wq_ta.info.addrof("busy")),
#f"r{i}_ta_blk": t(r.wq_ta.info.addrof("blocked_on_barrier")),
#f"r{i}_ta_2c": t(r.wq_ta.info.addrof("unk_2c")),
#f"r{i}_ta_54": t(r.wq_ta.info.addrof("unk_54")),
f"r{i}_ta_stamp1": t(r.stamp_ta1._addr),
f"r{i}_ta_stamp2":t(r.stamp_ta2._addr),
f"r{i}_3d_stamp1": t(r.stamp_3d1._addr),
f"r{i}_3d_stamp2":t(r.stamp_3d2._addr),
f"r{i}_ev_cnt":t(r.event_control.event_count._addr),
f"r{i}_ev_cur":t(r.event_control.addrof("cur_count")),
f"r{i}_ev_10":t(r.event_control.addrof("unk_10")),
})
div=4
ticks = 24000000 // div * 25
la = GPIOLogicAnalyzer(u, regs=regs, cpu=analyzer_cpu, div=div)
print("Queues:")
for i, r in enumerate(renderers):
print(f" Renderer {i}")
print(f" TA: {r.wq_ta.info._addr:#x} (stamp {r.work[0].ev_ta.id})")
#print(r.wq_ta.info)
print(f" 3D: {r.wq_3d.info._addr:#x} (stamp {r.work[0].ev_3d.id})")
#print(r.wq_3d.info)
print("==========================================")
print("## Run")
print("==========================================")
la.start(ticks, bufsize=0x8000000)
t = time.time()
try:
for r in renderers[:RENDERERS]:
r.run()
for r in renderers[:RENDERERS]:
while not r.ev_3d.fired:
agx.asc.work()
agx.poll_channels()
print("==========================================")
#agx.poll_objects()
#mon.poll()
agx.kick_firmware()
if time.time() > t + 10:
raise Exception("Timeout")
r.wait()
finally:
#agx.poll_objects()
#mon.poll()
la.complete()
la.show()
time.sleep(2)

View file

@ -0,0 +1,15 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: MIT
import sys, pathlib, time
sys.path.append(str(pathlib.Path(__file__).resolve().parents[1]))
from m1n1.constructutils import *
from m1n1.fw.agx import initdata
#for v in initdata.__all__:
for v in initdata.__dict__:
struct = getattr(initdata, v)
if isinstance(struct, type) and issubclass(struct, ConstructClass) and struct is not ConstructClass:
print(struct.to_rust())
print()

View file

@ -0,0 +1,336 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: MIT
import sys, pathlib, time
sys.path.append(str(pathlib.Path(__file__).resolve().parents[1]))
import atexit, sys
from m1n1.agx import AGX
from m1n1.agx.render import *
from m1n1.setup import *
from m1n1 import asm
from m1n1.gpiola import GPIOLogicAnalyzer
analyzer_cpu = 1
p.pmgr_adt_clocks_enable("/arm-io/gfx-asc")
p.pmgr_adt_clocks_enable("/arm-io/sgx")
p.smp_start_secondaries()
p.mmu_init_secondary(analyzer_cpu)
iface.dev.timeout = 42
## heater code
if True:
code = u.malloc(0x1000)
util = asm.ARMAsm("""
bench:
mrs x1, CNTPCT_EL0
1:
sub x0, x0, #1
cbnz x0, 1b
mrs x2, CNTPCT_EL0
sub x0, x2, x1
ret
""", code)
iface.writemem(code, util.data)
p.dc_cvau(code, len(util.data))
p.ic_ivau(code, len(util.data))
LOOPS = 80000000000
for idx in range(2, 8):
print(f"bench {idx}")
p.smp_call(idx, util.bench, LOOPS)
agx = AGX(u)
mon = RegMonitor(u, ascii=True, bufsize=0x8000000)
agx.mon = mon
sgx = agx.sgx_dev
#mon.add(sgx.gpu_region_base, sgx.gpu_region_size, "contexts")
#mon.add(sgx.gfx_shared_region_base, sgx.gfx_shared_region_size, "gfx-shared")
#mon.add(sgx.gfx_handoff_base, sgx.gfx_handoff_size, "gfx-handoff")
#mon.add(agx.initdasgx.gfx_handoff_base, sgx.gfx_handoff_size, "gfx-handoff")
atexit.register(p.reboot)
agx.start()
print("==========================================")
print("## After init")
print("==========================================")
mon.poll()
agx.poll_objects()
ctx = GPUContext(agx)
ctx.bind(63)
ctx0 = GPUContext(agx)
ctx0.bind(62)
f = GPUFrame(ctx, sys.argv[1], track=False)
f2 = GPUFrame(ctx0, sys.argv[1], track=False)
RENDERERS = 4
FRAMES = 8
renderers = []
fault_cmdbuf = f.cmdbuf.clone()
#fault_cmdbuf.depth_buffer = 0xdeadb000
for i in range(RENDERERS):
c = ctx0 if i == 0 else ctx
r = GPURenderer(c, 8, bm_slot=0x10 + i, queue=1)
renderers.append(r)
for q in (r.wq_3d, r.wq_ta):
q.info.set_prio(2)
q.info.push()
#for r in renderers[2:4]:
#for q in (r.wq_3d, r.wq_ta):
#q.info.set_prio(3)
#q.info.push()
#for r in renderers[4:6]:
#for q in (r.wq_3d, r.wq_ta):
#q.info.set_prio(0)
#q.info.push()
#for r in renderers[6:8]:
#for q in (r.wq_3d, r.wq_ta):
#q.info.set_prio(1)
#q.info.push()
print("==========================================")
print("## Submitting")
print("==========================================")
for i, r in enumerate(renderers):
for j in range(FRAMES):
if (i, j) in ((1, 0), (2, 1), (3, 1)):
r.submit(fault_cmdbuf)
elif i == 0:
r.submit(f2.cmdbuf)
else:
r.submit(f.cmdbuf)
print("==========================================")
print("## Submitted")
print("==========================================")
def t(addr):
paddr = agx.uat.iotranslate(0, addr, 4)[0][0]
if paddr is None:
raise Exception(f"Failed to iotranslate {addr:#x}")
return paddr
regs = {
"ta_cmds": t(agx.initdata.regionB.stats_ta.addrof("total_cmds")),
"ta_ts": t(agx.initdata.regionB.stats_ta.stats.addrof("unk_timestamp")),
}
pend_base = agx.initdata.regionC.addrof("pending_stamps")
for i in range(5):
regs[f"st{i}_info"] = t(pend_base + i*8)
regs[f"st{i}_val"] = t(pend_base + i*8 + 4)
for i in range(4):
regs[f"ta{i}_cq"] = t(agx.initdata.regionB.stats_ta.stats.queues[i].addrof("cur_cmdqueue"))
regs.update({
#"pwr_status": t(agx.initdata.regionB.hwdata_a.addrof("pwr_status")),
#"pstate": t(agx.initdata.regionB.hwdata_a.addrof("cur_pstate")),
#"temp_c": t(agx.initdata.regionB.hwdata_a.addrof("temp_c")),
#"pwr_mw": t(agx.initdata.regionB.hwdata_a.addrof("avg_power_mw")),
#"pwr_ts": t(agx.initdata.regionB.hwdata_a.addrof("update_ts")),
#"unk_10": t(agx.initdata.regionB.hwdata_a.addrof("unk_10")),
#"unk_14": t(agx.initdata.regionB.hwdata_a.addrof("unk_14")),
#"actual_pstate": t(agx.initdata.regionB.hwdata_a.addrof("actual_pstate")),
#"tgt_pstate": t(agx.initdata.regionB.hwdata_a.addrof("tgt_pstate")),
#"unk_40": t(agx.initdata.regionB.hwdata_a.addrof("unk_40")),
#"unk_44": t(agx.initdata.regionB.hwdata_a.addrof("unk_44")),
#"unk_48": t(agx.initdata.regionB.hwdata_a.addrof("unk_48")),
#"freq_mhz": t(agx.initdata.regionB.hwdata_a.addrof("freq_mhz")),
#"unk_748.0": t(agx.initdata.regionB.hwdata_a.addrof("unk_748")),
#"unk_748.1": t(agx.initdata.regionB.hwdata_a.addrof("unk_748")+4),
#"unk_748.2": t(agx.initdata.regionB.hwdata_a.addrof("unk_748")+8),
#"unk_748.3": t(agx.initdata.regionB.hwdata_a.addrof("unk_748")+12),
#"use_percent": t(agx.initdata.regionB.hwdata_a.addrof("use_percent")),
#"unk_83c": t(agx.initdata.regionB.hwdata_a.addrof("unk_83c")),
#"freq_with_off": t(agx.initdata.regionB.hwdata_a.addrof("freq_with_off")),
#"unk_ba0": t(agx.initdata.regionB.hwdata_a.addrof("unk_ba0")),
#"unk_bb0": t(agx.initdata.regionB.hwdata_a.addrof("unk_bb0")),
#"unk_c44": t(agx.initdata.regionB.hwdata_a.addrof("unk_c44")),
#"unk_c58": t(agx.initdata.regionB.hwdata_a.addrof("unk_c58")),
#"unk_3ca0": t(agx.initdata.regionB.hwdata_a.addrof("unk_3ca0")),
#"unk_3ca8": t(agx.initdata.regionB.hwdata_a.addrof("unk_3ca8")),
#"unk_3cb0": t(agx.initdata.regionB.hwdata_a.addrof("unk_3cb0")),
#"ts_last_idle": t(agx.initdata.regionB.hwdata_a.addrof("ts_last_idle")),
#"ts_last_poweron": t(agx.initdata.regionB.hwdata_a.addrof("ts_last_poweron")),
#"ts_last_poweroff": t(agx.initdata.regionB.hwdata_a.addrof("ts_last_poweroff")),
#"unk_3cd0": t(agx.initdata.regionB.hwdata_a.addrof("unk_3cd0")),
"halt_count": t(agx.initdata.fw_status.addrof("halt_count")),
"halted": t(agx.initdata.fw_status.addrof("halted")),
"resume": t(agx.initdata.fw_status.addrof("resume")),
"unk_40": t(agx.initdata.fw_status.addrof("unk_40")),
"unk_ctr": t(agx.initdata.fw_status.addrof("unk_ctr")),
"unk_60": t(agx.initdata.fw_status.addrof("unk_60")),
"unk_70": t(agx.initdata.fw_status.addrof("unk_70")),
"c_118c0": t(agx.initdata.regionC._addr + 0x118c0),
"c_118c4": t(agx.initdata.regionC._addr + 0x118c4),
"c_118c8": t(agx.initdata.regionC._addr + 0x118c8),
"c_118cc": t(agx.initdata.regionC._addr + 0x118cc),
"c_118d0": t(agx.initdata.regionC._addr + 0x118d0),
"c_118d4": t(agx.initdata.regionC._addr + 0x118d4),
"c_118d8": t(agx.initdata.regionC._addr + 0x118d8),
"c_118dc": t(agx.initdata.regionC._addr + 0x118dc),
"3d_cmds": t(agx.initdata.regionB.stats_3d.addrof("total_cmds")),
#"3d_tvb_oflws_1": t(agx.initdata.regionB.stats_3d.stats.addrof("tvb_overflows_1")),
#"3d_tvb_oflws_2": t(agx.initdata.regionB.stats_3d.stats.addrof("tvb_overflows_2")),
"3d_cur_stamp_id": t(agx.initdata.regionB.stats_3d.stats.addrof("cur_stamp_id")),
"3d_ts": t(agx.initdata.regionB.stats_3d.stats.addrof("unk_timestamp")),
#"3d_cur_stamp_id": t(agx.initdata.regionB.stats_3d.stats.addrof("cur_stamp_id")),
})
for i in range(4):
regs[f"3d{i}_cq"] = t(agx.initdata.regionB.stats_3d.stats.queues[i].addrof("cur_cmdqueue"))
for i, r in enumerate(renderers):
regs.update({
f"r{i}_3d_done": t(r.wq_3d.info.pointers.addrof("gpu_doneptr")),
#f"r{i}_3d_rptr": t(r.wq_3d.info.pointers.addrof("gpu_rptr")),
f"r{i}_3d_busy": t(r.wq_3d.info.addrof("busy")),
#f"r{i}_3d_blk": t(r.wq_3d.info.addrof("blocked_on_barrier")),
#f"r{i}_3d_2c": t(r.wq_3d.info.addrof("unk_2c")),
#f"r{i}_3d_54": t(r.wq_3d.info.addrof("unk_54")),
f"r{i}_ta_done": t(r.wq_ta.info.pointers.addrof("gpu_doneptr")),
#f"r{i}_ta_rptr": t(r.wq_ta.info.pointers.addrof("gpu_rptr")),
f"r{i}_ta_busy": t(r.wq_ta.info.addrof("busy")),
#f"r{i}_ta_blk": t(r.wq_ta.info.addrof("blocked_on_barrier")),
#f"r{i}_ta_2c": t(r.wq_ta.info.addrof("unk_2c")),
#f"r{i}_ta_54": t(r.wq_ta.info.addrof("unk_54")),
f"r{i}_f{j}_ta_stamp1": t(r.stamp_ta1._addr),
f"r{i}_ta_stamp2":t(r.stamp_ta2._addr),
f"r{i}_f{j}_3d_stamp1": t(r.stamp_3d1._addr),
f"r{i}_3d_stamp2":t(r.stamp_3d2._addr),
})
for j in range(FRAMES):
work = r.work[j]
regs.update({
f"r{i}_f{j}_3d_ts": t(work.wc_3d.ts1._addr),
f"r{i}_f{j}_ta_ts": t(work.wc_ta.ts1._addr),
})
div=4
ticks = 24000000 // div * 25
la = GPIOLogicAnalyzer(u, regs=regs, cpu=analyzer_cpu, div=div)
print("==========================================")
print("## Poll prior to job start")
print("==========================================")
#mon.poll()
#agx.poll_objects()
print("==========================================")
print("## After start")
print("==========================================")
#agx.poll_objects()
#mon.poll()
print("==========================================")
print("## Waiting")
print("==========================================")
print("Queues:")
for i, r in enumerate(renderers):
print(f" Renderer {i}")
print(f" TA: {r.wq_ta.info._addr:#x} (stamp {r.work[0].ev_ta.id})")
#print(r.wq_ta.info)
print(f" 3D: {r.wq_3d.info._addr:#x} (stamp {r.work[0].ev_3d.id})")
#print(r.wq_3d.info)
print("==========================================")
print("## Run")
print("==========================================")
la.start(ticks, bufsize=0x8000000)
try:
for r in renderers[:RENDERERS]:
r.run()
for r in renderers[:RENDERERS]:
while not r.ev_3d.fired:
agx.asc.work()
agx.poll_channels()
print("==========================================")
agx.poll_objects()
mon.poll()
r.wait()
#agx.poll_objects()
#print("==========================================")
#print("## Stop ASC")
#print("==========================================")
#agx.asc.stop()
##time.sleep(0.1)
##agx.poll_objects()
#print("==========================================")
#print("## Start ASC")
#print("==========================================")
#agx.asc.start()
##agx.poll_objects()
#print("==========================================")
#print("## Run 2")
#print("==========================================")
#for r in renderers[RENDERERS//2:]:
#r.run()
#for r in renderers[RENDERERS//2:]:
#while not r.ev_3d.fired:
#agx.asc.work()
#agx.poll_channels()
#print("==========================================")
#r.wait()
#agx.poll_objects()
#mon.poll()
finally:
#agx.poll_objects()
#mon.poll()
la.complete()
la.show()
time.sleep(2)

View file

@ -0,0 +1,42 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: MIT
import sys, pathlib, time
sys.path.append(str(pathlib.Path(__file__).resolve().parents[1]))
import atexit, sys
from m1n1.agx import AGX
from m1n1.agx.render import *
from m1n1.setup import *
p.pmgr_adt_clocks_enable("/arm-io/gfx-asc")
p.pmgr_adt_clocks_enable("/arm-io/sgx")
agx = AGX(u)
mon = RegMonitor(u, ascii=True, bufsize=0x8000000)
agx.mon = mon
sgx = agx.sgx_dev
#mon.add(sgx.gpu_region_base, sgx.gpu_region_size, "contexts")
#mon.add(sgx.gfx_shared_region_base, sgx.gfx_shared_region_size, "gfx-shared")
#mon.add(sgx.gfx_handoff_base, sgx.gfx_handoff_size, "gfx-handoff")
#mon.add(agx.initdasgx.gfx_handoff_base, sgx.gfx_handoff_size, "gfx-handoff")
atexit.register(p.reboot)
agx.start()
ctx = GPUContext(agx)
ctx.bind(2)
renderer = GPURenderer(ctx, 256, bm_slot=2, queue=1)
f = GPUFrame(ctx, sys.argv[1], track=False)
renderer.submit(f.cmdbuf)
renderer.wait()
time.sleep(2)

View file

@ -0,0 +1,279 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: MIT
import sys, pathlib, time
sys.path.append(str(pathlib.Path(__file__).resolve().parents[1]))
import atexit, sys
from m1n1.agx import AGX
from m1n1.agx.render import *
from m1n1.setup import *
from m1n1 import asm
from m1n1.gpiola import GPIOLogicAnalyzer
analyzer_cpu = 1
p.pmgr_adt_clocks_enable("/arm-io/gfx-asc")
p.pmgr_adt_clocks_enable("/arm-io/sgx")
p.smp_start_secondaries()
p.mmu_init_secondary(analyzer_cpu)
iface.dev.timeout = 42
agx = AGX(u)
mon = RegMonitor(u, ascii=True, bufsize=0x8000000)
agx.mon = mon
sgx = agx.sgx_dev
#mon.add(sgx.gpu_region_base, sgx.gpu_region_size, "contexts")
#mon.add(sgx.gfx_shared_region_base, sgx.gfx_shared_region_size, "gfx-shared")
#mon.add(sgx.gfx_handoff_base, sgx.gfx_handoff_size, "gfx-handoff")
#mon.add(agx.initdasgx.gfx_handoff_base, sgx.gfx_handoff_size, "gfx-handoff")
atexit.register(p.reboot)
agx.start()
print("==========================================")
print("## After init")
print("==========================================")
mon.poll()
agx.poll_objects()
ctx = GPUContext(agx)
ctx.bind(3)
f = GPUFrame(ctx, sys.argv[1], track=False)
RENDERERS = 1
FRAMES = 1
renderers = []
for i in range(RENDERERS):
r = GPURenderer(ctx, 4, bm_slot=0x10 + i, queue=1)
renderers.append(r)
for q in (r.wq_3d, r.wq_ta):
q.info.set_prio(2)
q.info.push()
print("==========================================")
print("## Submitting")
print("==========================================")
for i, r in enumerate(renderers):
for j in range(FRAMES):
r.submit(f.cmdbuf)
print("==========================================")
print("## Submitted")
print("==========================================")
def t(addr):
paddr = agx.uat.iotranslate(0, addr, 4)[0][0]
if paddr is None:
raise Exception(f"Failed to iotranslate {addr:#x}")
return paddr
regs = {
"ta_cmds": t(agx.initdata.regionB.stats_ta.addrof("total_cmds")),
"ta_ts": t(agx.initdata.regionB.stats_ta.stats.addrof("unk_timestamp")),
}
#pend_base = agx.initdata.regionC.addrof("pending_stamps")
#for i in range(5):
#regs[f"st{i}_info"] = t(pend_base + i*8)
#regs[f"st{i}_val"] = t(pend_base + i*8 + 4)
#for i in range(4):
#regs[f"ta{i}_cq"] = t(agx.initdata.regionB.stats_ta.stats.queues[i].addrof("cur_cmdqueue"))
regs.update({
"pwr_status": t(agx.initdata.regionB.hwdata_a.addrof("pwr_status")),
"pstate": t(agx.initdata.regionB.hwdata_a.addrof("cur_pstate")),
"temp_c": t(agx.initdata.regionB.hwdata_a.addrof("temp_c")),
"pwr_mw": t(agx.initdata.regionB.hwdata_a.addrof("avg_power_mw")),
"pwr_ts": t(agx.initdata.regionB.hwdata_a.addrof("update_ts")),
"unk_10": t(agx.initdata.regionB.hwdata_a.addrof("unk_10")),
"unk_14": t(agx.initdata.regionB.hwdata_a.addrof("unk_14")),
"actual_pstate": t(agx.initdata.regionB.hwdata_a.addrof("actual_pstate")),
"tgt_pstate": t(agx.initdata.regionB.hwdata_a.addrof("tgt_pstate")),
"unk_40": t(agx.initdata.regionB.hwdata_a.addrof("unk_40")),
"unk_44": t(agx.initdata.regionB.hwdata_a.addrof("unk_44")),
"unk_48": t(agx.initdata.regionB.hwdata_a.addrof("unk_48")),
"freq_mhz": t(agx.initdata.regionB.hwdata_a.addrof("freq_mhz")),
"unk_748.0": t(agx.initdata.regionB.hwdata_a.addrof("unk_748")),
"unk_748.1": t(agx.initdata.regionB.hwdata_a.addrof("unk_748")+4),
"unk_748.2": t(agx.initdata.regionB.hwdata_a.addrof("unk_748")+8),
"unk_748.3": t(agx.initdata.regionB.hwdata_a.addrof("unk_748")+12),
"use_percent": t(agx.initdata.regionB.hwdata_a.addrof("use_percent")),
"unk_83c": t(agx.initdata.regionB.hwdata_a.addrof("unk_83c")),
"freq_with_off": t(agx.initdata.regionB.hwdata_a.addrof("freq_with_off")),
"unk_ba0": t(agx.initdata.regionB.hwdata_a.addrof("unk_ba0")),
"unk_bb0": t(agx.initdata.regionB.hwdata_a.addrof("unk_bb0")),
"unk_c44": t(agx.initdata.regionB.hwdata_a.addrof("unk_c44")),
"unk_c58": t(agx.initdata.regionB.hwdata_a.addrof("unk_c58")),
"unk_3ca0": t(agx.initdata.regionB.hwdata_a.addrof("unk_3ca0")),
"unk_3ca8": t(agx.initdata.regionB.hwdata_a.addrof("unk_3ca8")),
"unk_3cb0": t(agx.initdata.regionB.hwdata_a.addrof("unk_3cb0")),
"ts_last_idle": t(agx.initdata.regionB.hwdata_a.addrof("ts_last_idle")),
"ts_last_poweron": t(agx.initdata.regionB.hwdata_a.addrof("ts_last_poweron")),
"ts_last_poweroff": t(agx.initdata.regionB.hwdata_a.addrof("ts_last_poweroff")),
"unk_3cd0": t(agx.initdata.regionB.hwdata_a.addrof("unk_3cd0")),
"halt_count": t(agx.initdata.fw_status.addrof("halt_count")),
"halted": t(agx.initdata.fw_status.addrof("halted")),
"resume": t(agx.initdata.fw_status.addrof("resume")),
"unk_40": t(agx.initdata.fw_status.addrof("unk_40")),
"unk_ctr": t(agx.initdata.fw_status.addrof("unk_ctr")),
"unk_60": t(agx.initdata.fw_status.addrof("unk_60")),
"unk_70": t(agx.initdata.fw_status.addrof("unk_70")),
"c_118c0": t(agx.initdata.regionC._addr + 0x118c0),
"c_118c4": t(agx.initdata.regionC._addr + 0x118c4),
"c_118c8": t(agx.initdata.regionC._addr + 0x118c8),
"c_118cc": t(agx.initdata.regionC._addr + 0x118cc),
"c_118d0": t(agx.initdata.regionC._addr + 0x118d0),
"c_118d4": t(agx.initdata.regionC._addr + 0x118d4),
"c_118d8": t(agx.initdata.regionC._addr + 0x118d8),
"c_118dc": t(agx.initdata.regionC._addr + 0x118dc),
"3d_cmds": t(agx.initdata.regionB.stats_3d.addrof("total_cmds")),
"3d_cq": t(agx.initdata.regionB.stats_3d.stats.addrof("cur_cmdqueue")),
#"3d_tvb_oflws_1": t(agx.initdata.regionB.stats_3d.stats.addrof("tvb_overflows_1")),
#"3d_tvb_oflws_2": t(agx.initdata.regionB.stats_3d.stats.addrof("tvb_overflows_2")),
"3d_cur_stamp_id": t(agx.initdata.regionB.stats_3d.stats.addrof("cur_stamp_id")),
"3d_ts": t(agx.initdata.regionB.stats_3d.stats.addrof("unk_timestamp")),
})
for i, r in enumerate(renderers):
regs.update({
f"r{i}_3d_done": t(r.wq_3d.info.pointers.addrof("gpu_doneptr")),
#f"r{i}_3d_rptr": t(r.wq_3d.info.pointers.addrof("gpu_rptr")),
f"r{i}_3d_busy": t(r.wq_3d.info.addrof("busy")),
#f"r{i}_3d_blk": t(r.wq_3d.info.addrof("blocked_on_barrier")),
#f"r{i}_3d_2c": t(r.wq_3d.info.addrof("unk_2c")),
#f"r{i}_3d_54": t(r.wq_3d.info.addrof("unk_54")),
f"r{i}_ta_done": t(r.wq_ta.info.pointers.addrof("gpu_doneptr")),
#f"r{i}_ta_rptr": t(r.wq_ta.info.pointers.addrof("gpu_rptr")),
f"r{i}_ta_busy": t(r.wq_ta.info.addrof("busy")),
#f"r{i}_ta_blk": t(r.wq_ta.info.addrof("blocked_on_barrier")),
#f"r{i}_ta_2c": t(r.wq_ta.info.addrof("unk_2c")),
#f"r{i}_ta_54": t(r.wq_ta.info.addrof("unk_54")),
f"r{i}_f{j}_ta_stamp1": t(r.stamp_ta1._addr),
f"r{i}_ta_stamp2":t(r.stamp_ta2._addr),
f"r{i}_f{j}_3d_stamp1": t(r.stamp_3d1._addr),
f"r{i}_3d_stamp2":t(r.stamp_3d2._addr),
})
for j in range(FRAMES):
work = r.work[j]
regs.update({
f"r{i}_f{j}_3d_ts": t(work.wc_3d.ts1._addr),
f"r{i}_f{j}_ta_ts": t(work.wc_ta.ts1._addr),
})
div=4
ticks = 24000000 // div * 25
la = GPIOLogicAnalyzer(u, regs=regs, cpu=analyzer_cpu, div=div)
print("==========================================")
print("## Run")
print("==========================================")
la.start(ticks, bufsize=0x8000000)
depth_len = align_up(1920*1080*4, 0x4000)
#agx.uat.iomap_at(ctx.ctx, f.cmdbuf.depth_buffer, 0, depth_len, VALID=0)
#agx.uat.flush_dirty()
fb = r.work[0].fb
#agx.uat.iomap_at(ctx.ctx, fb, 0, depth_len, VALID=0)
#agx.uat.flush_dirty()
agx.kick_firmware()
agx.show_stats = False
count_pa = renderers[0].event_control.event_count._paddr
print(f"count: {p.read32(count_pa)}")
agx.uat.invalidate_cache()
agx.uat.dump(ctx.ctx)
mon.add(0x9fff74000, 0x4000)
try:
for r in renderers:
r.run()
for r in renderers:
while not r.ev_ta.fired:
agx.asc.work()
agx.poll_channels()
print("TA fired")
print(f"count: {p.read32(count_pa)}")
for r in renderers:
while not r.ev_3d.fired:
agx.asc.work()
agx.poll_channels()
#print("==========================================")
r.wait()
print("3D fired")
print("Timestamps:")
print(f" 3D 1: {r.ts3d_1.pull().val}")
print(f" 3D 2: {r.ts3d_2.pull().val}")
print(f" TA 1: {r.tsta_1.pull().val}")
print(f" TA 2: {r.tsta_2.pull().val}")
print("CPU flag:", r.buffer_mgr.misc_obj.pull().cpu_flag)
mon.poll()
#agx.uat.iomap_at(ctx.ctx, fb, 0, depth_len, VALID=0)
#agx.uat.flush_dirty()
print(f"fb: {fb:#x}")
for i, r in enumerate(renderers):
for j in range(FRAMES):
r.submit(f.cmdbuf)
r.run()
for r in renderers:
while not r.ev_3d.fired:
agx.asc.work()
r.wait()
print("3D fired again")
print("Timestamps:")
print(f" 3D 1: {r.ts3d_1.pull().val}")
print(f" 3D 2: {r.ts3d_2.pull().val}")
print(f" TA 1: {r.tsta_1.pull().val}")
print(f" TA 2: {r.tsta_2.pull().val}")
print("CPU flag:", r.buffer_mgr.misc_obj.pull().cpu_flag)
time.sleep(0.5)
finally:
agx.poll_channels()
#agx.poll_objects()
#mon.poll()
la.complete()
la.show()
time.sleep(2)

View file

@ -0,0 +1,310 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: MIT
import sys, pathlib, time
sys.path.append(str(pathlib.Path(__file__).resolve().parents[1]))
import atexit, sys
from m1n1.agx import AGX
from m1n1.agx.render import *
from m1n1.setup import *
from m1n1.gpiola import GPIOLogicAnalyzer
analyzer_cpu = 1
p.pmgr_adt_clocks_enable("/arm-io/gfx-asc")
p.pmgr_adt_clocks_enable("/arm-io/sgx")
p.smp_start_secondaries()
p.mmu_init_secondary(analyzer_cpu)
iface.dev.timeout = 10
agx = AGX(u)
mon = RegMonitor(u, ascii=True, bufsize=0x8000000)
agx.mon = mon
sgx = agx.sgx_dev
#mon.add(sgx.gpu_region_base, sgx.gpu_region_size, "contexts")
#mon.add(sgx.gfx_shared_region_base, sgx.gfx_shared_region_size, "gfx-shared")
#mon.add(sgx.gfx_handoff_base, sgx.gfx_handoff_size, "gfx-handoff")
#mon.add(agx.initdasgx.gfx_handoff_base, sgx.gfx_handoff_size, "gfx-handoff")
atexit.register(p.reboot)
agx.start()
print("==========================================")
print("## After init")
print("==========================================")
mon.poll()
agx.poll_objects()
ctx = GPUContext(agx)
ctx.bind(1)
renderer = GPURenderer(ctx, 64, bm_slot=0, queue=0)
renderer2 = GPURenderer(ctx, 64, bm_slot=1, queue=1)
#for q in (renderer.wq_3d, renderer.wq_ta):#, renderer2.wq_3d, renderer2.wq_ta):
#q.info.unk_30 = 2
#q.info.unk_34 = 2
#q.info.unk_38 = 0xffff000000000000
#q.info.unk_40 = 0
#q.info.unk_44 = 0
#q.info.unk_48 = 2
#q.info.unk_50 = 0x1
#q.info.push()
f = GPUFrame(ctx, sys.argv[1], track=False)
#f2 = GPUFrame(renderer2.ctx, sys.argv[1], track=False)
print("==========================================")
print("## Pre submit")
print("==========================================")
mon.poll()
agx.poll_objects()
print("==========================================")
print("## Submitting")
print("==========================================")
work = renderer.submit(f.cmdbuf)
work2 = renderer2.submit(f.cmdbuf)
workb = renderer.submit(f.cmdbuf)
work2b = renderer2.submit(f.cmdbuf)
print(work.wc_3d)
print(work.wc_ta)
print(work2.wc_3d)
print(work2.wc_ta)
print("==========================================")
print("## Submitted")
print("==========================================")
def t(addr):
paddr = agx.uat.iotranslate(0, addr, 4)[0][0]
if paddr is None:
raise Exception(f"Failed to iotranslate {addr:#x}")
return paddr
regs = {
"ta_cmds": t(agx.initdata.regionB.stats_ta.addrof("total_cmds")),
"ta0_busy": t(agx.initdata.regionB.stats_ta.stats.queues[0].addrof("busy")),
"ta0_unk4": t(agx.initdata.regionB.stats_ta.stats.queues[0].addrof("unk_4")),
"ta0_cq": t(agx.initdata.regionB.stats_ta.stats.queues[0].addrof("cur_cmdqueue")),
"ta0_cnt": t(agx.initdata.regionB.stats_ta.stats.queues[0].addrof("cur_count")),
"ta1_busy": t(agx.initdata.regionB.stats_ta.stats.queues[1].addrof("busy")),
"ta1_unk4": t(agx.initdata.regionB.stats_ta.stats.queues[1].addrof("unk_4")),
"ta1_cq": t(agx.initdata.regionB.stats_ta.stats.queues[1].addrof("cur_cmdqueue")),
"ta1_cnt": t(agx.initdata.regionB.stats_ta.stats.queues[1].addrof("cur_count")),
"ta_ts": t(agx.initdata.regionB.stats_ta.stats.addrof("unk_timestamp")),
"3d_cmds": t(agx.initdata.regionB.stats_3d.addrof("total_cmds")),
"3d_cq": t(agx.initdata.regionB.stats_3d.stats.addrof("cur_cmdqueue")),
"3d_tvb_oflws_1": t(agx.initdata.regionB.stats_3d.stats.addrof("tvb_overflows_1")),
"3d_tvb_oflws_2": t(agx.initdata.regionB.stats_3d.stats.addrof("tvb_overflows_2")),
"3d_cur_stamp_id": t(agx.initdata.regionB.stats_3d.stats.addrof("cur_stamp_id")),
"3d_ts": t(agx.initdata.regionB.stats_3d.stats.addrof("unk_timestamp")),
"bmctl_0": t(agx.initdata.regionB.buffer_mgr_ctl._addr + 0),
"bmctl_8": t(agx.initdata.regionB.buffer_mgr_ctl._addr + 8),
"2_bmctl_0": t(agx.initdata.regionB.buffer_mgr_ctl._addr + 16),
"2_bmctl_8": t(agx.initdata.regionB.buffer_mgr_ctl._addr + 24),
"bmmisc_0": t(renderer.buffer_mgr.info.misc.addrof("gpu_0")),
"bmmisc_4": t(renderer.buffer_mgr.info.misc.addrof("gpu_4")),
"bmmisc_8": t(renderer.buffer_mgr.info.misc.addrof("gpu_8")),
"bmmisc_c": t(renderer.buffer_mgr.info.misc.addrof("gpu_c")),
"bmi_gpuc": t(renderer.buffer_mgr.info.addrof("gpu_counter")),
"bmi_18": t(renderer.buffer_mgr.info.addrof("unk_18")),
"bmi_gpuc2": t(renderer.buffer_mgr.info.addrof("gpu_counter2")),
"2_bmmisc_0": t(renderer2.buffer_mgr.info.misc.addrof("gpu_0")),
"2_bmmisc_4": t(renderer2.buffer_mgr.info.misc.addrof("gpu_4")),
"2_bmmisc_8": t(renderer2.buffer_mgr.info.misc.addrof("gpu_8")),
"2_bmmisc_c": t(renderer2.buffer_mgr.info.misc.addrof("gpu_c")),
"2_bmi_gpuc": t(renderer2.buffer_mgr.info.addrof("gpu_counter")),
"2_bmi_18": t(renderer2.buffer_mgr.info.addrof("unk_18")),
"2_bmi_gpuc2": t(renderer2.buffer_mgr.info.addrof("gpu_counter2")),
"ctxdat_0": t(renderer.ctx.gpu_context._addr + 0),
"ctxdat_4": t(renderer.ctx.gpu_context._addr + 4),
"ctxdat_8": t(renderer.ctx.gpu_context._addr + 8),
"ctxdat_c": t(renderer.ctx.gpu_context._addr + 0xc),
"2_ctxdat_0": t(renderer2.ctx.gpu_context._addr + 0),
"2_ctxdat_4": t(renderer2.ctx.gpu_context._addr + 4),
"2_ctxdat_8": t(renderer2.ctx.gpu_context._addr + 8),
"2_ctxdat_c": t(renderer2.ctx.gpu_context._addr + 0xc),
"evctl_ta": t(renderer.event_control.addrof("has_ta")),
"evctl_pta": t(renderer.event_control.addrof("pstamp_ta")),
"evctl_3d": t(renderer.event_control.addrof("has_3d")),
"evctl_p3d": t(renderer.event_control.addrof("pstamp_3d")),
"evctl_in_list": t(renderer.event_control.addrof("in_list")),
"evctl_prev": t(renderer.event_control.list_head.addrof("prev")),
"evctl_next": t(renderer.event_control.list_head.addrof("next")),
"2_evctl_ta": t(renderer2.event_control.addrof("has_ta")),
"2_evctl_pta": t(renderer2.event_control.addrof("pstamp_ta")),
"2_evctl_3d": t(renderer2.event_control.addrof("has_3d")),
"2_evctl_p3d": t(renderer2.event_control.addrof("pstamp_3d")),
"2_evctl_in_list":t(renderer2.event_control.addrof("in_list")),
"2_evctl_prev": t(renderer2.event_control.list_head.addrof("prev")),
"2_evctl_next": t(renderer2.event_control.list_head.addrof("next")),
"jl_first": t(renderer.job_list.addrof("first_job")),
"jl_last": t(renderer.job_list.addrof("last_head")),
"jl_10": t(renderer.job_list.addrof("unkptr_10")),
"2_jl_first": t(renderer2.job_list.addrof("first_job")),
"2_jl_last": t(renderer2.job_list.addrof("last_head")),
"2_jl_10": t(renderer2.job_list.addrof("unkptr_10")),
"3d_done": t(renderer.wq_3d.info.pointers.addrof("gpu_doneptr")),
"3d_rptr": t(renderer.wq_3d.info.pointers.addrof("gpu_rptr")),
"3d_rptr1": t(renderer.wq_3d.info.addrof("gpu_rptr1")),
"3d_rptr2": t(renderer.wq_3d.info.addrof("gpu_rptr2")),
"3d_rptr3": t(renderer.wq_3d.info.addrof("gpu_rptr3")),
"3d_busy": t(renderer.wq_3d.info.addrof("busy")),
"3d_blk": t(renderer.wq_3d.info.addrof("blocked_on_barrier")),
"3d_2c": t(renderer.wq_3d.info.addrof("unk_2c")),
"3d_54": t(renderer.wq_3d.info.addrof("unk_54")),
"3d_58": t(renderer.wq_3d.info.addrof("unk_58")),
"2_3d_done": t(renderer2.wq_3d.info.pointers.addrof("gpu_doneptr")),
"2_3d_rptr": t(renderer2.wq_3d.info.pointers.addrof("gpu_rptr")),
"2_3d_busy": t(renderer2.wq_3d.info.addrof("busy")),
"2_3d_blk": t(renderer2.wq_3d.info.addrof("blocked_on_barrier")),
"2_3d_2c": t(renderer2.wq_3d.info.addrof("unk_2c")),
"2_3d_54": t(renderer2.wq_3d.info.addrof("unk_54")),
"ta_done": t(renderer.wq_ta.info.pointers.addrof("gpu_doneptr")),
"ta_rptr": t(renderer.wq_ta.info.pointers.addrof("gpu_rptr")),
"ta_rptr1": t(renderer.wq_ta.info.addrof("gpu_rptr1")),
"ta_rptr2": t(renderer.wq_ta.info.addrof("gpu_rptr2")),
"ta_rptr3": t(renderer.wq_ta.info.addrof("gpu_rptr3")),
"ta_busy": t(renderer.wq_ta.info.addrof("busy")),
"ta_blk": t(renderer.wq_ta.info.addrof("blocked_on_barrier")),
"ta_2c": t(renderer.wq_ta.info.addrof("unk_2c")),
"ta_54": t(renderer.wq_ta.info.addrof("unk_54")),
"ta_58": t(renderer.wq_ta.info.addrof("unk_58")),
"2_ta_done": t(renderer2.wq_ta.info.pointers.addrof("gpu_doneptr")),
"2_ta_rptr": t(renderer2.wq_ta.info.pointers.addrof("gpu_rptr")),
"2_ta_busy": t(renderer2.wq_ta.info.addrof("busy")),
"2_ta_blk": t(renderer2.wq_ta.info.addrof("blocked_on_barrier")),
"2_ta_2c": t(renderer2.wq_ta.info.addrof("unk_2c")),
"2_ta_54": t(renderer2.wq_ta.info.addrof("unk_54")),
"3d_ts1": t(work.wc_3d.ts1._addr),
"3d_ts1b": t(workb.wc_3d.ts1._addr),
"3d_ts2": t(work.wc_3d.ts2._addr),
"3d_ts3": t(work.wc_3d.ts3._addr),
"ta_ts1": t(work.wc_ta.ts1._addr),
"ta_ts1b": t(workb.wc_ta.ts1._addr),
"ta_ts2": t(work.wc_ta.ts2._addr),
"ta_ts3": t(work.wc_ta.ts3._addr),
"2_3d_ts1": t(work2.wc_3d.ts1._addr),
"2_3d_ts1b": t(work2b.wc_3d.ts1._addr),
"2_3d_ts2": t(work2.wc_3d.ts2._addr),
"2_3d_ts3": t(work2.wc_3d.ts3._addr),
"2_ta_ts1": t(work2.wc_ta.ts1._addr),
"2_ta_ts1b": t(work2b.wc_ta.ts1._addr),
"2_ta_ts2": t(work2.wc_ta.ts2._addr),
"2_ta_ts3": t(work2.wc_ta.ts3._addr),
"ta_stamp1": t(renderer.stamp_ta1._addr),
"ta_stamp2": t(renderer.stamp_ta2._addr),
"3d_stamp1": t(renderer.stamp_3d1._addr),
"3d_stamp2": t(renderer.stamp_3d2._addr),
"2_ta_stamp1": t(renderer2.stamp_ta1._addr),
"2_ta_stamp2": t(renderer2.stamp_ta2._addr),
"2_3d_stamp1": t(renderer2.stamp_3d1._addr),
"2_3d_stamp2": t(renderer2.stamp_3d2._addr),
}
div=4
ticks = 24000000 // div * 3
la = GPIOLogicAnalyzer(u, regs=regs, cpu=analyzer_cpu, div=div)
print("==========================================")
print("## Poll prior to job start")
print("==========================================")
mon.poll()
agx.poll_objects()
print("==========================================")
print("## Run")
print("==========================================")
la.start(ticks, bufsize=0x400000)
renderer.run()
print("==========================================")
print("## After r1 start")
print("==========================================")
#agx.poll_objects()
#time.sleep(0.1)
#mon.poll()
#time.sleep(0.15)
#mon.poll()
renderer2.run()
print("==========================================")
print("## After r2 start")
print("==========================================")
agx.poll_objects()
#mon.poll()
print("==========================================")
print("## Waiting")
print("==========================================")
try:
#while not work.ev_3d.fired:
#agx.asc.work()
##mon.poll()
#agx.poll_objects()
#agx.poll_channels()
#print("==========================================")
##time.sleep(0.1)
#print("==========================================")
#print("## Ev1 Fired")
#print("==========================================")
while not work2.ev_3d.fired:
agx.asc.work()
#mon.poll()
agx.poll_objects()
agx.poll_channels()
print("==========================================")
#time.sleep(0.1)
print("==========================================")
print("## Ev2 Fired")
print("==========================================")
renderer.wait()
renderer2.wait()
agx.poll_objects()
#mon.poll()
finally:
la.complete()
la.show()
time.sleep(2)