Skip to content
20 changes: 4 additions & 16 deletions proxyclient/hv/trace_dcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

Ver.set_version(hv.u)

from m1n1.fw.dcp.ipc import *

class DCPDevType(IntEnum):
DCP = 0
DART_DCP = 1
Expand Down Expand Up @@ -810,22 +812,8 @@ def call(self, msg, dir):
state.out_addr = self.buf + msg.OFF + 12 + in_len
state.out_len = out_len

verb = self.dcpep.get_verbosity(tag)
if verb >= 1:
self.log(f"{dir}{self.name}.{msg.OFF:x} {tag}:{KNOWN_MSGS.get(tag, 'unk')} ({msg})")
if verb >= 2:
print(f"Message: {tag} ({KNOWN_MSGS.get(tag, 'unk')}): (in {in_len:#x}, out {out_len:#x})")
if data_in:
print(f"{dir} Input ({len(data_in):#x} bytes):")
chexdump(data_in[:self.state.max_len])

#if tag not in KNOWN_MSGS:
#hv.run_shell()

if self.state.dumpfile:
dump = f"CALL {dir} {msg.value:#018x} {self.name} {state.off:#x} {state.tag} {in_len:#x} {out_len:#x} {data_in.hex()}\n"
Comment thread
svenpeter42 marked this conversation as resolved.
Resolved
self.state.dumpfile.write(dump)
self.state.dumpfile.flush()
c = Call(dir, self.name, msg.OFF, tag, in_len, out_len, data_in)
c.print_req(logger = self.log)

self.state.ch.setdefault(self.name, []).append(state)

Expand Down
2 changes: 1 addition & 1 deletion proxyclient/m1n1/constructutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ class Ver(Subconstruct):
"G": os.environ.get("AGX_GPU", "G13")}

MATRIX = {
"V": ["V12_1", "V12_3", "V12_4", "V13_0B4", "V13_0B5", "V13_0B6", "V13_2", "V13_3", "V13_5B4", "V13_5"],
"V": ["V12_1", "V12_3", "V12_4", "V13_0B4", "V13_0B5", "V13_0B6", "V13_2", "V13_3", "V13_5B4", "V13_5", "V14_7"],
"G": ["G13", "G14", "G14X"],
}

Expand Down
149 changes: 108 additions & 41 deletions proxyclient/m1n1/fw/dcp/ipc.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def fmt_args(self, in_vals, out_vals=None):

return ", ".join(s)

def print_long_args(self, indent, in_vals, out_vals=None):
def print_long_args(self, indent, in_vals, out_vals=None, logger=print):
for i, (name, field) in enumerate(self.args):
if name == "ret":
continue
Expand All @@ -204,15 +204,15 @@ def print_long_args(self, indent, in_vals, out_vals=None):
if self.is_long(val):
hdr = f"{indent} {name} = "
if isinstance(val, (ListContainer, Container)):
print(hdr + str(val).replace("\n", "\n" + indent))
logger(hdr + str(val).replace("\n", "\n" + indent))
elif isinstance(val, bytes):
print(hdr + f"({len(val):#x} bytes)")
logger(hdr + f"({len(val):#x} bytes)")
chexdump(val, indent=indent + " ")
else:
dindent = " " * len(hdr)
if isinstance(val, dict) and "_io" in val:
del val["_io"]
print(hdr + pprint.pformat(val, sort_dicts=False).replace("\n", "\n" + dindent))
logger(hdr + pprint.pformat(val, sort_dicts=False).replace("\n", "\n" + dindent))

def is_long(self, arg):
if isinstance(arg, (list, bytes)):
Expand Down Expand Up @@ -446,6 +446,7 @@ def methods(cls):
"unk_38" / Default(Int64ul, 0),
"flags1" / Hex(Int64ul),
"flags2" / Hex(Int64ul),
Ver("V >= V14_7", "unk_v14_7" / UnkBytes(0x48)),
"swap_id" / Int32ul,
"surf_ids" / Int32ul[SWAP_SURFACES],
"src_rect" / Rect[SWAP_SURFACES],
Expand All @@ -460,15 +461,19 @@ def methods(cls):
"active_regions" / Default(ActiveRegion[SWAP_SURFACES], [(0,0,0,0)] * SWAP_SURFACES),
"unk_190" / UnkBytes(0x138),
"unk_2c8" / Hex(Default(Int32ul, 0)),
"unk_2cc" / UnkBytes(0x14),
"unk_2e0" / Hex(Default(Int32ul, 0)),
Ver("V < V14_7", "unk_2cc" / UnkBytes(0x14)),
Ver("V >= V14_7", "unk_2cc" / UnkBytes(0x40)),
Ver("V < V14_7", "unk_2e0" / Hex(Default(Int32ul, 0))),
Ver("V >= V14_7", "bl_update" / Hex(Default(Int32ul, 0))),
Ver("V < V13_5", "unk_2e2" / UnkBytes(0x2)),
Ver("V >= V13_5", "unk_2e2" / UnkBytes(0x3)),
"bl_unk" / Hex(Int64ul), # seen: 0x0, 0x1, 0x101, 0x1_0000, 0x101_010101
Ver("V < V14_7", "bl_unk" / Hex(Int64ul)), # seen: 0x0, 0x1, 0x101, 0x1_0000, 0x101_010101
Ver("V >= V14_7", "bl_unk" / Hex(Int32ul)),
"bl_val" / Hex(Int32ul), # range 0x10000000 - approximately 0x7fe07fc0 for 4 - 510 nits
"bl_power" / Hex(Int8ul), # constant 0x40, 0x00: backlight off
"unk_2f3" / UnkBytes(0x2d),
Ver("V >= V13_5", "unk_320" / UnkBytes(0x147)),
Ver("V >= V14_7", "unk_467" / UnkBytes(0x30)),
)

MAX_PLANES = 3
Expand Down Expand Up @@ -617,8 +622,12 @@ class UnifiedPipeline2(IPCObject):
A357 = set_create_DFB
A358 = vi_set_temperature_hint
else:
A373 = set_create_DFB
A374 = vi_set_temperature_hint
if Ver.check("V >= V14_7"):
A377 = set_create_DFB
A378 = vi_set_temperature_hint
else:
A373 = set_create_DFB
A374 = vi_set_temperature_hint

A352 = Call(bool_, "applyProperty", uint, uint)
A353 = Call(uint, "get_system_type")
Expand Down Expand Up @@ -676,15 +685,23 @@ class UnifiedPipeline2(IPCObject):
D113 = cb_create_nvram_service
D114 = Callback(bool_, "get_tiling_state", event=uint, para=uint, val=InOutPtr(uint))
D115 = Callback(bool_, "set_tiling_state", event=uint, para=uint, val=InPtr(uint))
D116 = cb_set_idle_caching_state_ap
D120 = cb_start_hardware_boot
D121 = cb_is_dark_boot
D122 = cb_is_waking_from_hibernate
D124 = cb_read_edt_data
D126 = cb_setDCPAVPropStart
D127 = cb_setDCPAVPropChunk
D128 = cb_setDCPAVPropEnd
D129 = cb_allocate_bandwidth
if Ver.check("V >= V14_7"):
D117 = cb_set_idle_caching_state_ap
D121 = cb_start_hardware_boot
D125 = cb_read_edt_data
D127 = cb_setDCPAVPropStart
D128 = cb_setDCPAVPropChunk
D129 = cb_setDCPAVPropEnd
else:
D116 = cb_set_idle_caching_state_ap
D120 = cb_start_hardware_boot
D121 = cb_is_dark_boot
D124 = cb_read_edt_data
D126 = cb_setDCPAVPropStart
D127 = cb_setDCPAVPropChunk
D128 = cb_setDCPAVPropEnd
D129 = cb_allocate_bandwidth

class UPPipe2(IPCObject):
A102 = Call(uint64_t, "test_control", cmd=uint64_t, arg=uint)
Expand Down Expand Up @@ -720,7 +737,29 @@ class PropRelay(IPCObject):

class IOMobileFramebufferAP(IPCObject):
# FW version dependent Calls
if Ver.check("V < V13_5"):
if Ver.check("V >= V14_7"):
swap_submit_dcp = Call(uint32_t, "swap_submit_dcp",
swap_rec=InPtr(IOMFBSwapRec),
surfaces=Array(SWAP_SURFACES, InPtr(IOSurface)),
surfAddr=Array(SWAP_SURFACES, Hex(ulong)),
unkU64Array=Array(SWAP_SURFACES, Hex(ulong)),
surfaces2=Array(5, InPtr(IOSurface)),
surfAddr2=Array(5, Hex(ulong)),
unkBool=bool_,
unkFloat=Float64l,
unkU64=ulong,
unkBool2=bool_,
clear_surfs=Hex(uint),
unkAddr=Hex(uint),
swap_null=bool_,
surf_null=Array(SWAP_SURFACES, Bool(Int8ul)),
surf2_null=Array(5, Bool(Int8ul)),
unkOutBool=OutPtr(bool_),
unkU32Ptr_null=Hex(Int8ul),
unk32out_null=Hex(Int8ul),
padding=Hex(Int8ul),
unkb=UnkBytes(0x228))
elif Ver.check("V < V13_5"):
swap_submit_dcp = Call(uint32_t, "swap_submit_dcp",
swap_rec=InPtr(IOMFBSwapRec),
surfaces=Array(4, InPtr(IOSurface)),
Expand All @@ -747,19 +786,31 @@ class IOMobileFramebufferAP(IPCObject):
unkUintPtr=OutPtr(uint))

A401 = Call(uint32_t, "start_signal")
A407 = Call(uint32_t, "swap_start", swap_id=InOutPtr(uint), client=InOutPtr(IOUserClient))
A408 = swap_submit_dcp
A410 = Call(uint32_t, "set_display_device", uint)
A411 = Call(bool_, "is_main_display")

A412 = Call(uint32_t, "set_digital_out_mode", uint, uint)
A413 = Call(uint32_t, "get_digital_out_state", InOutPtr(uint))
A414 = Call(uint32_t, "get_display_area", InOutPtr(ulong))
A419 = Call(uint32_t, "get_gamma_table", InOutPtr(Bytes(0xc0c)))
A422 = Call(uint32_t, "set_matrix", uint, InPtr(Array(3, Array(3, ulong))))
A423 = Call(uint32_t, "set_contrast", InOutPtr(Float32l))
A426 = Call(uint32_t, "get_color_remap_mode", InOutPtr(uint32_t))
A427 = Call(uint32_t, "setBrightnessCorrection", uint)

if Ver.check("V >= V14_7"):
A406 = Call(uint32_t, "swap_start", client=InOutPtr(IOUserClient))
A407 = swap_submit_dcp
A409 = Call(uint32_t, "set_display_device", uint)
A410 = Call(bool_, "is_main_display")
A411 = Call(uint32_t, "set_digital_out_mode", uint, uint)
A421 = Call(uint32_t, "set_matrix", uint, InPtr(Array(3, Array(3, ulong))))
A425 = Call(uint32_t, "get_color_remap_mode", InOutPtr(uint32_t))
A426 = Call(uint32_t, "setBrightnessCorrection", uint)
A429 = Call(UnkBytes(4), "some_thing_v14_7", UnkBytes(4))
else:
A407 = Call(uint32_t, "swap_start", swap_id=InOutPtr(uint), client=InOutPtr(IOUserClient))
A408 = swap_submit_dcp
A410 = Call(uint32_t, "set_display_device", uint)
A411 = Call(bool_, "is_main_display")
A412 = Call(uint32_t, "set_digital_out_mode", uint, uint)
A422 = Call(uint32_t, "set_matrix", uint, InPtr(Array(3, Array(3, ulong))))
A427 = Call(uint32_t, "setBrightnessCorrection", uint)
A426 = Call(uint32_t, "get_color_remap_mode", InOutPtr(uint32_t))

# FW version dependent Call tags
set_block_dcp = Call(uint32_t, "set_block_dcp", arg1=uint64_t, arg2=uint, arg3=uint, arg4=Array(8, ulong), arg5=uint, data=SizedBytes(0x1000, "length"), length=ulong, unknArry=Array(4, uint))
Expand Down Expand Up @@ -807,16 +858,9 @@ class IOMobileFramebufferAP(IPCObject):
A468 = setPowerState
A469 = isKeepOnScreen
else:
A437 = set_block_dcp
A438 = get_block_dcp
A440 = swap_set_color_matrix
A441 = set_parameter_dcp
A442 = display_width
A443 = display_height
A444 = get_display_size
A445 = do_create_default_frame_buffer
A446 = printRegs
A449 = enable_disable_video_power_savings
A456 = first_client_open
A457 = last_client_close_dcp
A458 = writeDebugInfo
Expand All @@ -826,16 +870,38 @@ class IOMobileFramebufferAP(IPCObject):
A466 = flush_supportsPower
A467 = abort_swaps_dcp
A468 = Call(uint, "remove_gain_maps", InOutPtr(IOMobileFramebufferUserClient))
A470 = update_dfb
A472 = setPowerState
A473 = isKeepOnScreen

if Ver.check("V >= V14_7"):
A436 = set_block_dcp
A437 = get_block_dcp
A439 = swap_set_color_matrix
A440 = set_parameter_dcp
A444 = do_create_default_frame_buffer
A448 = enable_disable_video_power_savings
A455 = first_client_open
A471 = update_dfb
A477 = Call(uint, "some_getter_v14_7")
else:
A437 = set_block_dcp
A438 = get_block_dcp
A440 = swap_set_color_matrix
A441 = set_parameter_dcp
A444 = get_display_size
A445 = do_create_default_frame_buffer
A449 = enable_disable_video_power_savings
A470 = update_dfb

# FW version dependent callbacks
if Ver.check("V < V13_5"):
hotPlug_notify_gated = Callback(void, "hotPlug_notify_gated", ulong)
else:
# TODO: is this sensible?
hotPlug_notify_gated = Callback(void, "hotPlug_notify_gated", uint, InOutPtr(Bytes(0x4c)))
if Ver.check("V < V14_7"):
hotPlug_notify_gated = Callback(void, "hotPlug_notify_gated", uint, InOutPtr(Bytes(0x4c)))
else:
hotPlug_notify_gated = Callback(void, "hotPlug_notify_gated", uint, InOutPtr(Bytes(0x50)))

D552 = Callback(bool_, "setProperty_dict", key=string(0x40), value=InPtr(Padded(0x1000, OSDictionary())))
D561 = Callback(bool_, "setProperty_dict", key=string(0x40), value=InPtr(Padded(0x1000, OSDictionary())))
Expand Down Expand Up @@ -937,31 +1003,32 @@ def ack(self, out_data):
self.out_data = out_data
self.complete = True

def print_req(self, indent=""):
def print_req(self, logger=print, indent=""):
log = f"{indent}{self.dir}{SHORT_CHANNELS[self.chan]}[{self.off:#x}] {self.msg} "

cls, method = ALL_METHODS.get(self.msg, (None, None))
if cls is None:
print(log + f"unknown: {self.in_size:#x}/{self.out_size:#x}")
logger(log + f"unknown: {self.in_size:#x}/{self.out_size:#x}")
chexdump(self.in_data, print_fn = logger)
return

log += f"{cls.__name__}::{method.name}("
in_size = method.in_struct.sizeof()

if in_size != len(self.in_data):
print(f"{log} !! Expected {in_size:#x} bytes, got {len(self.in_data):#x} bytes (in)")
logger(f"{log} !! Expected {in_size:#x} bytes, got {len(self.in_data):#x} bytes (in)")
dump_fields(method.in_fields)
chexdump(self.in_data)
chexdump(self.in_data, print_fn = logger)
self.in_vals = {}
return

self.in_vals = method.parse_input(self.in_data)

log += f"{method.fmt_args(self.in_vals)})"

print(log)
logger(log)

method.print_long_args(indent, self.in_vals)
method.print_long_args(indent, self.in_vals, logger = logger)
#if method.in_fields:
#print(self.in_vals)

Expand Down
1 change: 1 addition & 0 deletions proxyclient/m1n1/proxyutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"iBoot-8422.100.650": "V13_3",
"iBoot-8422.140.50.0.2": "V13_5B4",
"iBoot-8422.141.2": "V13_5",
"iBoot-10151.140.19.700.2": "V14_7"
}

class ProxyUtils(Reloadable):
Expand Down
5 changes: 4 additions & 1 deletion proxyclient/m1n1/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ def display(val):
desc = obj_name + str(signature(obj))
except:
continue
qn = obj.__qualname__
try:
qn = obj.__qualname__
except:
continue
if qn.find('.') > 0:
a = qn.split('.')
if a[0] not in subcmd_list:
Expand Down
3 changes: 3 additions & 0 deletions src/kboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -1516,6 +1516,9 @@ static int dt_set_dcp_firmware(const char *alias)
case V13_6_1:
compat = &fw_versions[V13_5];
break;
case V14_7:
compat = &fw_versions[V14_7];
break;
default:
compat = &os_firmware;
break;
Expand Down
Loading