Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/kboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ extern u64 relocated_from;

int dt_set_gpu(void *dt);
int dt_set_display_handoff(void *dt);
bool dt_t8132_external_display(void);

u64 kboot_ram_base(void)
{
Expand Down Expand Up @@ -8504,6 +8505,8 @@ static int dt_set_display(void)
disp0_piodma_alias = compat_piodma_alias;

if (chip_id == T8132) {
if (dt_t8132_external_display())
return dt_set_display_handoff(dt);
if (dt_set_m4_dcp_handoff())
printf("FDT: M4 DCP handoff refused; keeping the boot framebuffer\n");
else
Expand Down
381 changes: 274 additions & 107 deletions src/kboot_display_handoff.c

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion tests/python/test_t6041_display_handoff.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def run(binary, scenario):
return subprocess.run([str(binary), scenario], capture_output=True, text=True, env=env)


SCENARIOS = re.findall(r'^ \{"([a-z0-9-]+)", (?:PUBLISH|NOTHING|REFUSE|REFUSE_NO_OSLOG),',
SCENARIOS = re.findall(r'^ \{"([a-z0-9-]+)", (?:PUBLISH|HEADLESS|NOTHING|REFUSE|REFUSE_NO_OSLOG),',
(ROOT / "tests/t6041_display_host.c").read_text(), re.M)


Expand Down Expand Up @@ -107,6 +107,7 @@ def test_scenario_list_matches(host):
"j614c": PUBLISHED,
"j614c-external": PUBLISHED,
"j614c-on-t6040": "not a J616C/J614C/J575C (chip 0x6040): nothing done",
"j575c-headless": "display subsystem and its DART enabled for the external processors",
"no-display-dt": NOT_DESCRIBED,
"no-dcp-alias": NOT_DESCRIBED,
"wrong-dcp-compat": NOT_DESCRIBED,
Expand Down
187 changes: 187 additions & 0 deletions tests/python/test_t8132_display_route.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
# SPDX-License-Identifier: MIT
"""Which display handoff a T8132 boot gets, via the shared kboot_display_handoff.c helper.

Failure model:
- Any headless T8132 (/arm-io/disp0 marked external or absent) whose OS firmware matches a
qualified row of dcp_soc_t8132 (dcp6_select_fw()) and whose ADT has a running dcpext0 or
dcpext1 nub carrying that row's pinned DCP image goes to dt_set_display_handoff().
- Every other T8132 boot keeps the M4 handoff (dt_set_m4_dcp_handoff()):
- any board with an internal panel (/arm-io/disp0 present without `external`);
- a headless board on an unqualified OS firmware (26.6.2, 27.0, unknown), even if the UUID
matches, so kboot routing and dt_set_display_handoff() cannot disagree;
- a headless board running any other DCP image (e.g. 27.2.1 or missing UUID);
- a headless board whose external DCP nubs are not running;
- any non-T8132 chip.
- The pinned UUID and dcp6_select_fw() live in one place (src/kboot_display_handoff.c), not
duplicated in src/kboot.c.
- dt_set_display() asks before it takes the M4 path, and returns what the external handoff
returns (always 0).
"""

import re
import shutil
import subprocess
import sys
from pathlib import Path

import pytest
from host_compiler import host_cc
from test_t6041_display_handoff import LIBFDT, ROOT

HARNESS = r'''
#define main desktop26_main
#include "t6041_display_host.c"
#undef main

bool dt_t8132_external_display(void);

struct route_case {
u32 chip;
enum fw_version fw;
bool has_disp0;
bool disp0_external;
const char *uuid[2];
u32 running[2];
bool has_running[2];
};

static void reset_adt(void)
{
for (int i = 0; i < nnodes; i++) {
for (int j = 0; j < nodes[i].nprops; j++)
free(nodes[i].props[j]);
nodes[i].nprops = 0;
nodes[i].nreg = 0;
nodes[i].path[0] = 0;
}
nnodes = 0;
}

static int check_case(const char *desc, struct route_case cfg, int want)
{
static const char *const nubs[2] = {
"/arm-io/dcpext0/iop-dcpext0-nub",
"/arm-io/dcpext1/iop-dcpext1-nub",
};

reset_adt();
chip_id = cfg.chip;
os_firmware = fw_versions[cfg.fw];
if (cfg.has_disp0) {
prop_str("/arm-io/disp0", "compatible", "disp0,t8132");
if (cfg.disp0_external)
prop_set("/arm-io/disp0", "external", "", 0);
}
for (int i = 0; i < 2; i++) {
if (cfg.uuid[i])
prop_str(nubs[i], "uuid", cfg.uuid[i]);
if (cfg.has_running[i])
prop_u32(nubs[i], "running", cfg.running[i]);
}
int got = dt_t8132_external_display();
printf("%s %s: %s\n", got == want ? "ok " : "FAIL", desc,
got ? "external handoff" : "M4 handoff");
return got != want;
}

int main(void)
{
static const char PINNED[] = "B3BA603C-3CA7-3E21-B393-44EB20BD2AEF";
static const char OTHER[] = "0F1E2D3C-4B5A-3968-8776-A5B4C3D2E1F0";
int fails = 0;

fails += check_case("headless disp0 external + 27.2 + dcpext0 pinned running",
(struct route_case){T8132, V27_2, true, true, {PINNED, PINNED},
{1, 1}, {true, true}},
1);
fails += check_case("headless disp0 absent + 27.2 + dcpext1 pinned running",
(struct route_case){T8132, V27_2, false, false, {OTHER, PINNED},
{0, 1}, {true, true}},
1);
fails += check_case("headless + 26.6.2 (dcp6_select_fw refuses even with pinned UUID)",
(struct route_case){T8132, V26_6_2, true, true, {PINNED, PINNED},
{1, 1}, {true, true}},
0);
fails += check_case("headless + 27.0 (dcp6_select_fw refuses even with pinned UUID)",
(struct route_case){T8132, V27_0, true, true, {PINNED, PINNED},
{1, 1}, {true, true}},
0);
fails += check_case("headless + 27.2 + other UUID (27.2.1)",
(struct route_case){T8132, V27_2, true, true, {OTHER, OTHER},
{1, 1}, {true, true}},
0);
fails += check_case("headless + 27.2 + pinned UUID but not running",
(struct route_case){T8132, V27_2, true, true, {PINNED, PINNED},
{0, 0}, {true, true}},
0);
fails += check_case("headless + 27.2 + missing UUID",
(struct route_case){T8132, V27_2, true, true, {NULL, NULL},
{1, 1}, {true, true}},
0);
fails += check_case("internal panel (disp0 not external) + 27.2 + dcpext0 pinned running",
(struct route_case){T8132, V27_2, true, false, {PINNED, PINNED},
{1, 1}, {true, true}},
0);
fails += check_case("wrong chip (T6041) + headless + 27.2 + dcpext0 pinned running",
(struct route_case){T6041, V27_2, true, true, {PINNED, PINNED},
{1, 1}, {true, true}},
0);
return fails != 0;
}
'''


def function(source, name, kind="static int "):
start = source.index(kind + name + "(")
return source[start:source.index("\n}", start) + 2] + "\n"


def test_t8132_route_follows_adt_and_fw_state(tmp_path):
cc = host_cc()
if not shutil.which(cc[0]):
pytest.skip("no host C compiler")
src = tmp_path / "src"
src.mkdir()
code = (ROOT / "src/kboot_display_handoff.c").read_text()
if sys.platform == "darwin":
code = code.replace('section(".init.t6050")', 'section("__TEXT,__t6050_init")')
(src / "kboot_display_handoff.c").write_text(code)
shutil.copy(ROOT / "tests/t6041_display_host.c", src)
for header in (ROOT / "tests/t8122_display_host").glob("*.h"):
shutil.copy(header, src)
driver = src / "route_host.c"
driver.write_text(HARNESS)
binary = tmp_path / "t8132-route-host"
subprocess.run(
[*cc, "-std=gnu11", "-D_GNU_SOURCE", "-O1", "-g", "-Wall", "-Wno-unused-function",
"-Wno-format", "-Wno-format-truncation", "-fsanitize=address,undefined",
"-fno-omit-frame-pointer", "-fno-sanitize-recover=undefined",
"-I", str(src), "-I", str(ROOT / "src"),
str(driver), str(src / "kboot_display_handoff.c"),
*(str(ROOT / "src/libfdt" / f) for f in LIBFDT), "-o", str(binary)],
check=True,
)
result = subprocess.run([str(binary)], capture_output=True, text=True,
env={"ASAN_OPTIONS": "detect_leaks=0", "PATH": "/usr/bin:/bin"})
assert result.returncode == 0, result.stdout + result.stderr


def test_route_uses_shared_helper_and_single_uuid():
kboot = (ROOT / "src/kboot.c").read_text()
handoff = (ROOT / "src/kboot_display_handoff.c").read_text()
uuid = "B3BA603C-3CA7-3E21-B393-44EB20BD2AEF"
assert uuid not in kboot
assert handoff.count(uuid) == 1
body = function(handoff, "dt_t8132_external_display", "bool ")
assert "apple,j773g" not in body
assert "dcp6_adt_headless()" in body
assert "dcp6_select_fw(&dcp_soc_t8132)" in body


def test_dt_set_display_asks_before_the_m4_handoff():
kboot = (ROOT / "src/kboot.c").read_text()
body = function(kboot, "dt_set_display", "static int ")
branch = body[body.index("if (chip_id == T8132) {"):]
branch = branch[:branch.index("dt_set_m4_dcp_handoff()")]
assert re.search(r"if \(dt_t8132_external_display\(\)\)\s+return dt_set_display_handoff\(dt\);",
branch), branch
126 changes: 126 additions & 0 deletions tests/python/test_t8132_j773g_27_display_handoff.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# SPDX-License-Identifier: MIT
"""T8132 Mac mini (J773g) display handoff on macOS 27.2 (26B123): external processors only.

Failure model, recorded before src/kboot_display_handoff.c learnt the J773g:
- On 27.2, macOS drives the J773g's HDMI port from dcpext0. iBoot leaves dcp, dcpext0 and
dcpext1 running the same DCP image, B3BA603C-3CA7-3E21-B393-44EB20BD2AEF. The dcpext nubs have
four segments (__TEXT, __DATA, __OS_LOG, heap), and __TEXT is one buffer shared by all three
processors. /arm-io/dispextN clock-ids index /arm-io clock-frequencies from 256, like disp0's
(dispext0: 369 = 533333328 Hz, 432 = 0 Hz).
- Like the J575c, the board is headless: the internal DCP is never handed over. Its node, DARTs
and mailbox stay as the device tree has them, and it gets no marker, memory-region, clock or
firmware property. No MMIO is written at all: dart-dcp is not locked.
- Each apple,t8132-dcpext node the device tree describes, at /dcp@286e00000 or /dcp@48ae00000,
is handed over as the J575c's are. Requirements:
- the node and its DART (iommus <&dart 23>, an apple,t8110-dart) are status "disabled";
- it has three disabled apple,asc-mem placeholders named text, data and heap;
- its nub has the pinned UUID, is pre-loaded and running, and has the four-segment layout;
- data and heap lie outside the kernel's RAM;
- its __TEXT is the first processor's.
Then:
- data and heap are filled and enabled with their DART alias;
- text points at the shared dcp-text region, which carries one iommu-addresses tuple per
processor;
- apple,firmware-version and -compat <27 2 0> and apple,firmware-uuid are published;
- the node and its DART stay disabled for the kernel's display gate.
- Unlike the J575c's, a J773g dcpext gets its own pipe's firmware clocks:
- fixed-clock providers, clock-names firmware-0..N and apple,clock-ids = the /arm-io/dispextN
clock-ids, where T6041's get empty apple,clock-ids. The firmware asks for them (D408), and
macOS answers with these rates.
- A /clock-dcp-firmware-<id> node already in the device tree (the 26.6.2 tree has static
ones) is reused when it is a fixed-clock of the same rate; with another rate the processor
is refused.
- A single static `clocks` on the node is replaced. Existing clock-names or apple,clock-ids
refuse it.
- Any failed check refuses that processor only: its placeholders stay disabled and it gets no
firmware, UUID or clock property, and no clock node. The other processor is unaffected.
- Once a processor is published, the display subsystem (disp0 alias) and its DART are enabled,
with iBoot's boot framebuffer as the display's "framebuffer" memory-region. If the device tree
already enables them (the 26.6.2 J773g tree does), that step is refused and logged, and the
display node is left as it is; the published processors stay published. With no processor
published, the display is not touched.
- __OS_LOG of dcp, dcpext0 and dcpext1 is reserved, as on every supported boot.
- Nothing at all (no MMIO, the device tree byte for byte unchanged) unless:
- the chip is T8132 and the ADT describes a headless machine (/arm-io/disp0 has `external` or is
absent; an internal-panel T8132 gets nothing from this path, while any headless T8132 board
takes it without a board table entry);
- the OS firmware is 27.2 (26.6.2 and 27.0 get nothing);
- the internal nub runs the pinned UUID (26B131's 27.2.1 image gets nothing);
- /arm-io/disp0 has valid clock-ids;
- the device tree has the dcp and disp0 aliases on apple,t8132-dcp and
apple,t8132-display-subsystem nodes.
- A second call changes nothing. A device tree with no room refuses transactionally: no partial
clock nodes, properties or regions.
- T6041 (J616c/J614c/J575c) behaviour is unchanged (test_t6041_*_display_handoff.py).
"""

import re

import pytest
from test_t6041_display_handoff import ROOT, build_host, run

HOST = "t8132_j773g_27_display_host.c"
SCENARIOS = re.findall(r'^ \{"([a-z0-9-]+)", ', (ROOT / "tests" / HOST).read_text(), re.M)


PUBLISHED = "dcpext0 firmware memory published"
BOTH = "dcpext1 firmware memory published"
DISPLAY = "display subsystem and its DART enabled for the external processors"
NOTHING = "nothing done"
# The log line of the check each scenario is meant to reach, so that none passes for another reason
REASONS = {
"publish": [PUBLISHED, BOTH, DISPLAY],
"other-headless-board": [PUBLISHED, BOTH, DISPLAY],
"dcpext0-only": [PUBLISHED, DISPLAY],
"repeat": ["3 __OS_LOG reservation(s) already present", "dcpext0 already has firmware clocks"],
"static-clock-nodes": [PUBLISHED, BOTH, DISPLAY],
"display-preenabled": [PUBLISHED, BOTH, 'display subsystem is not status "disabled"'],
"ext-uuid-mismatch": [PUBLISHED, "dcpext1: ADT image uuid is not B3BA603C-"],
"ext-not-running": [BOTH, "dcpext0: iBoot did not leave its four-segment firmware loaded"],
"ext-enabled": [BOTH, 'dcpext0 is not status "disabled"'],
"ext-dart-enabled": [BOTH, 'dcpext0 DART is not status "disabled"'],
"ext-wrong-compat": [BOTH, "dcpext0 is not apple,t8132-dcpext"],
"ext-no-placeholders": [BOTH, "dcpext0: no text, data and heap memory-region placeholders"],
"ext-text-not-shared": [PUBLISHED, "dcpext1: __TEXT 0x10284000000 is not the shared one"],
"ext-data-in-ram": [BOTH, "dcpext0: segment 1 0x10010000000+0x8000 at 0x10002490000 is kernel RAM"],
"ext-clock-missing": [BOTH, "27.2 /arm-io/dispext0 clock metadata is missing or invalid"],
"ext-clock-zero": [BOTH, "27.2 /arm-io/dispext0 primary clock frequency is zero"],
"ext-clock-names": [BOTH, "dcpext0 already has firmware clocks"],
"ext-clock-conflict": [BOTH, "/clock-dcp-firmware-369 exists with another rate"],
"ext-all-refused": ["dcpext0: iBoot did not leave", "dcpext1: iBoot did not leave"],
"wrong-chip": ["not a T8132 (chip 0x6041): " + NOTHING],
"j713": ["internal panel present: " + NOTHING],
"os-26-6-2": ["no qualified OS firmware for apple,t8132-dcp: " + NOTHING],
"os-27-0": ["no qualified OS firmware for apple,t8132-dcp: " + NOTHING],
"wrong-uuid": ["27.2 DCP image mismatch: " + NOTHING],
"disp0-clocks-missing": ["27.2 /arm-io/disp0 clock metadata is missing or invalid"],
"no-display-dt": ["the device tree does not describe the display block"],
"dt-full": ["could not add the __OS_LOG reservations", "dcpext0 firmware memory refused"],
}


def test_every_scenario_has_its_reason():
assert sorted(REASONS) == sorted(SCENARIOS)


@pytest.fixture(scope="module")
def host(tmp_path_factory):
return build_host(tmp_path_factory.mktemp("t8132-27"), host_source=HOST)


def test_scenarios_cover_the_failure_model():
for required in ("publish", "repeat", "display-preenabled", "static-clock-nodes",
"ext-uuid-mismatch", "ext-text-not-shared", "ext-clock-missing",
"ext-clock-conflict", "ext-all-refused", "j713", "os-26-6-2",
"wrong-uuid", "dt-full"):
assert required in SCENARIOS


@pytest.mark.parametrize("scenario", SCENARIOS)
def test_t8132_j773g_27_2_display_handoff(host, scenario):
result = run(host, scenario)
assert result.returncode == 0, result.stdout + result.stderr
assert result.stdout.rstrip().endswith(f"{scenario}: pass"), result.stdout
assert "FAIL" not in result.stdout, result.stdout
for reason in REASONS[scenario]:
assert reason in result.stdout, (reason, result.stdout)
Loading
Loading