1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355
|
#!/usr/bin/env python3
# SPDX-License-Identifier: MIT
import sys, pathlib
sys.path.append(str(pathlib.Path(__file__).resolve().parents[1]))
import struct
from construct import *
from m1n1.setup import *
from m1n1.shell import run_shell
from m1n1 import asm
from m1n1.hw.dart import DART
from m1n1.fw.dcp.client import DCPClient
from m1n1.fw.dcp.manager import DCPManager
from m1n1.fw.dcp.ipc import ByRef
from m1n1.proxyutils import RegMonitor
disp_name = "/arm-io/disp0"
external = hasattr(u.adt[disp_name], "external") and u.adt[disp_name].external != 0
compat = u.adt[disp_name].compatible[0].split(",")[-1]
mon = RegMonitor(u)
if compat == 't8103':
#mon.add(0x230000000, 0x18000)
#mon.add(0x230018000, 0x4000)
#mon.add(0x230068000, 0x8000)
#mon.add(0x2300b0000, 0x8000)
#mon.add(0x2300f0000, 0x4000)
#mon.add(0x230100000, 0x10000)
#mon.add(0x230170000, 0x10000)
#mon.add(0x230180000, 0x1c000)
#mon.add(0x2301a0000, 0x10000)
#mon.add(0x2301d0000, 0x4000)
#mon.add(0x230230000, 0x10000)
#mon.add(0x23038c000, 0x10000)
#mon.add(0x230800000, 0x10000)
#mon.add(0x230840000, 0xc000)
#mon.add(0x230850000, 0x2000)
##mon.add(0x230852000, 0x5000) # big curve / gamma table
#mon.add(0x230858000, 0x18000)
#mon.add(0x230870000, 0x4000)
#mon.add(0x230880000, 0x8000)
#mon.add(0x230894000, 0x4000)
#mon.add(0x2308a8000, 0x8000)
#mon.add(0x2308b0000, 0x8000)
#mon.add(0x2308f0000, 0x4000)
##mon.add(0x2308fc000, 0x4000) # stats / RGB color histogram
#mon.add(0x230900000, 0x10000)
#mon.add(0x230970000, 0x10000)
#mon.add(0x230980000, 0x10000)
#mon.add(0x2309a0000, 0x10000)
#mon.add(0x2309d0000, 0x4000)
#mon.add(0x230a30000, 0x20000)
#mon.add(0x230b8c000, 0x10000)
#mon.add(0x231100000, 0x8000)
#mon.add(0x231180000, 0x4000)
#mon.add(0x2311bc000, 0x10000)
#mon.add(0x231300000, 0x8000)
##mon.add(0x23130c000, 0x4000) # - DCP dart
#mon.add(0x231310000, 0x8000)
#mon.add(0x231340000, 0x8000)
##mon.add(0x231800000, 0x8000) # breaks DCP
##mon.add(0x231840000, 0x8000) # breaks DCP
##mon.add(0x231850000, 0x8000) # something DCP?
##mon.add(0x231920000, 0x8000) # breaks DCP
##mon.add(0x231960000, 0x8000) # breaks DCP
##mon.add(0x231970000, 0x10000) # breaks DCP
##mon.add(0x231c00000, 0x10000) # DCP mailbox
mon.add(0x230845840, 0x40) # error regs
def get_color_mode(mgr):
best_id = None
best_score = -1
for mode in mgr.dcpav_prop['ColorElements']:
if mode['IsVirtual']:
continue
if mode['Depth'] != 8:
continue
if mode['Score'] > best_score:
best_score = mode['Score']
best_id = mode['ID']
return best_id
def get_timing_mode(mgr):
best_id = None
best_score = -1
for mode in mgr.dcpav_prop['TimingElements']:
if mode['IsVirtual']:
continue
if int(mode['Score']) > best_score:
best_score = int(mode['Score'])
best_id = int(mode['ID'])
return best_id
mon.poll()
dart = DART.from_adt(u, "arm-io/dart-dcp")
disp_dart = DART.from_adt(u, "arm-io/dart-disp0")
print("DCP DART:")
dart.dart.regs.dump_regs()
print("DISP DART:")
disp_dart.dart.regs.dump_regs()
dcp_addr = u.adt["arm-io/dcp"].get_reg(0)[0]
dcp = DCPClient(u, dcp_addr, dart, disp_dart)
dcp.dva_offset = getattr(u.adt["/arm-io/dcp"][0], "asc_dram_mask", 0)
dcp.start()
dcp.start_ep(0x20)
dcp.start_ep(0x37)
dcp.dcpep.initialize()
dcp.system.wait_for("system")
dcp.system.system.setProperty("gAFKConfigLogMask", 0xffff)
mgr = DCPManager(dcp.dcpep, compat)
mon.poll()
mgr.start_signal()
mon.poll()
mgr.get_color_remap_mode(6)
mgr.enable_disable_video_power_savings(0)
mgr.update_notify_clients_dcp([0,0,0,0,0,0,1,1,1,0,1,1,1,1])
mgr.first_client_open()
print(f"keep on: {mgr.isKeepOnScreen()}")
print(f"main display: {mgr.is_main_display()}")
assert mgr.setPowerState(1, False, ByRef(0)) == 0
mon.poll()
if external:
assert mgr.set_display_device(2) == 0
else:
assert mgr.set_display_device(0) == 2
assert mgr.set_parameter_dcp(14, [0], 1) == 0
color_mode = get_color_mode(mgr)
timing_mode = get_timing_mode(mgr)
mgr.SetDigitalOutMode(color_mode, timing_mode)
mon.poll()
while mgr.iomfb_prop['DPTimingModeId'] != timing_mode:
print("Try re-setting mode")
mgr.SetDigitalOutMode(color_mode, timing_mode)
mon.poll()
if external:
assert mgr.set_display_device(2) == 0
else:
assert mgr.set_display_device(0) == 2
assert mgr.set_parameter_dcp(14, [0], 1) == 0
t = ByRef(b"\x00" * 0xc0c)
assert mgr.get_gamma_table(t) == 2
assert mgr.set_contrast(0) == 0
assert mgr.setBrightnessCorrection(65536) == 0
if external:
assert mgr.set_display_device(2) == 0
else:
assert mgr.set_display_device(0) == 2
assert mgr.set_parameter_dcp(14, [0], 1) == 0
mon.poll()
swapid = ByRef(0)
def start():
# arg: IOUserClient
ret = mgr.swap_start(swapid, {
"addr": 0xFFFFFE1667BA4A00,
"unk": 0,
"flag1": 0,
"flag2": 1
})
assert ret == 0
print(f"swap ID: {swapid.val:#x}")
start()
mgr.set_matrix(9, [[1<<32, 0, 0],
[0, 1<<32, 0],
[0, 0, 1<<32]])
mgr.setBrightnessCorrection(65536)
mgr.set_parameter_dcp(3, [65536], 1)
mgr.set_parameter_dcp(6, [65536], 1)
width = mgr.display_width()
height = mgr.display_height()
surface_id = 3
swap_rec = Container(
flags1 = 0x861202,
flags2 = 0x04,
swap_id = swapid.val,
surf_ids = [surface_id, 0, 0, 0],
src_rect = [[0, 0, width, height],[0,0,0,0],[0,0,0,0],[0,0,0,0]],
surf_flags = [1, 0, 0, 0],
surf_unk = [0, 0, 0, 0],
dst_rect = [[0, 0, width, height],[0,0,0,0],[0,0,0,0],[0,0,0,0]],
swap_enabled = 0x80000007,
swap_completed = 0x80000007,
bl_unk = 0x1,
bl_val = 0x58f058d0, # ~99 nits
bl_power = 0x40,
)
surf = Container(
is_tiled = False,
unk_1 = False,
unk_2 = False,
plane_cnt = 0,
plane_cnt2 = 0,
format = "BGRA",
xfer_func = 13,
colorspace = 1,
stride = width * 4,
pix_size = 4,
pel_w = 1,
pel_h = 1,
offset = 0,
width = width,
height = height,
buf_size = width * height * 4,
surface_id = surface_id,
has_comp = True,
has_planes = True,
has_compr_info = False,
unk_1f5 = 0,
unk_1f9 = 0,
)
compressed_surf = Container(
is_tiled = False,
unk_1 = False,
unk_2 = False,
plane_cnt = 2,
plane_cnt2 = 2,
format = 'b3a8',
unk_f = 0x00000000,
xfer_func = 13,
colorspace = 2,
stride = width,
pix_size = 1,
pel_w = 1,
pel_h = 1,
offset = 0,
width = width,
height = height,
buf_size = 0x00A36000,
unk_2d = 0,
unk_31 = 0,
surface_id = 5,
comp_types = [
Container(count = 0, types =[]),
Container(count = 0, types =[]),
],
has_comp = True,
planes = [
Container(
width = width,
height = height,
base = 0,
offset = 0,
stride = 0x1e000,
size = 0x818000,
tile_size = 1024,
tile_w = 16,
tile_h = 16,
unk2 = 0x05,
),
Container(
width = width,
height = height,
base = 0x818000,
offset = 0x818000,
stride = 0x7800,
size = 0x21e000,
tile_size = 256,
tile_w = 16,
tile_h = 16,
unk2 = 0x05,
)
],
has_planes = True,
compression_info = [
unhex("""
10 00 00 00 10 00 00 00 00 80 7F 00 00 00 00 00
08 00 00 00 78 00 00 00 44 00 00 00 00 00 00 00
03 00 00 00 00 00 00 00 AA AA AA 00 04 00 00 00
E0 01 00 AA
"""),
unhex("""
10 00 00 00 10 00 00 00 00 60 A1 00 00 80 81 00
08 00 00 00 78 00 00 00 44 00 00 00 00 00 00 00
03 00 00 00 00 00 00 00 AA AA AA 00 01 00 00 00
78 00 00 AA
"""),
],
has_compr_info = True,
unk_1f5 = 0x100000,
unk_1f9 = 0x100000,
)
outB = ByRef(False)
swaps = mgr.swaps
mon.poll()
fb_size = align_up(width * height * 4, 8 * 0x4000)
print(f"Display {width}x{height}, fb size: {fb_size}")
buf = u.memalign(0x4000, fb_size)
colors = [0xDD0000, 0xFE6230, 0xFEF600, 0x00BB00, 0x009BFE, 0x000083, 0x30009B]
for i, color in enumerate(colors):
lines = height // len(colors)
offset = i * lines * width * 4
p.memset32(buf + offset, color, lines * width * 4)
iova = disp_dart.iomap(0, buf, fb_size)
surfaces = [surf, None, None, None]
#surfaces = [compressed_surf, None, None, None]
surfAddr = [iova, 0, 0, 0]
def submit():
swap_rec.swap_id = swapid.val
ret = mgr.swap_submit_dcp(swap_rec=swap_rec, surfaces=surfaces, surfAddr=surfAddr,
unkBool=False, unkFloat=0.0, unkInt=0, unkOutBool=outB)
print(f"swap returned {ret} / {outB}")
dcp.work()
if ret == 0:
while swaps == mgr.swaps:
dcp.work()
print("swap complete!")
submit()
run_shell(globals(), msg="Have fun!")
|