diff --git a/src/kboot_display_handoff.c b/src/kboot_display_handoff.c index 21f61b3b4..a71a5155b 100644 --- a/src/kboot_display_handoff.c +++ b/src/kboot_display_handoff.c @@ -115,7 +115,8 @@ * same handoff checks those against the ADT instead of adding them. A board without a panel (the * J775D, Mac Studio, M5 Ultra), whose display subsystem scans out through one external engine's * display DART: t6050_headless_handoff() hands its external engines over with the display - * subsystem. + * subsystem. The ESP Stage 2 also hands off the external engines beside a panel the device tree + * enables itself (t6050_adopted()) and pins the images whose DCP ABI is not the OS firmware's. * * Fail-soft: dt_set_display_handoff() always returns 0; a failed check is logged and changes * nothing. Transactional: DT edits are made on a scratch copy that replaces the DT only if every @@ -5091,12 +5092,26 @@ static bool dcp6_dt_describes(void *dt) * iBoot leaves the DCP running and both of its DARTs locked on four-level roots. The kernel adopts * that session and resolves firmware DVAs through the live tables, so this publishes no * iommu-addresses: only what the ADT says, checked against the device tree and the registers. - * The image is pinned per OS firmware because 27.0 and 27.0.1 report the same iBoot version. + * A row is picked by the image id the nub reports (ADT uuid). A row without dcp_fw gives the DCP + * nodes the OS firmware's version, so it also pins that OS firmware (27.0 and 27.0.1 report the + * same iBoot version). A row with dcp_fw names the image's DCP ABI itself and is picked by its + * image id alone: no other handoff step reads the OS firmware. */ +#ifdef ESP_STAGE2 +/* + * The DCP image of 27.3 beta 1 takes the 27.3 method table: its nodes get 27.3.0, which the kernel + * maps to that table, rather than the beta's OS firmware numbers (27.2.98.1). Its row is built + * into the ESP Stage 2 only: a Stage 1 booting Linux directly keeps the boot framebuffer on it. + */ +static const struct fw_version_info t6050_fw_27_3 = {V27_3B, "27.3", {27, 3, 0}, 3, NULL}; +#endif + static const struct { - u32 os_fw; + u32 os_fw; /* the OS firmware the image was measured on; matched only without dcp_fw */ char uuid[37]; bool ext; /* also hand off the external display engines running this image */ + /* The firmware version the DCP nodes get, if not the OS firmware's (see t6050_fw_27_3) */ + const struct fw_version_info *dcp_fw; } t6050_images[] = { {V27_0, "64863924-B56B-3E32-87FE-038677F52709", true}, /* K116s (16" M5 Pro, OLED), 26B8125 */ @@ -5105,6 +5120,10 @@ static const struct { * machine; the image id is not shared across T6050 boards, so the rows pair with the * image the ADT reports below. The J775D's (M5 Ultra) dcpext engines run it too */ {V27_2, "C51FB0C8-C45D-39B0-85BC-520E600FC950", true}, +#ifdef ESP_STAGE2 + /* J714c (14" M5 Max) on 27.3 beta 1 (26C5035, mBoot-20457.60.65.0.1) */ + {V27_3B, "58CB3FFC-B2BA-352E-B20B-71A91B15FA9F", true, &t6050_fw_27_3}, +#endif }; #define T6050_NDISP 5 /* disp0 reg[0..4] are the dcp's disp-0..disp-4 */ #define T6050_BW_BASE 0x20000 /* bandwidth agent 0's scratch in the PMC metadata */ @@ -5148,7 +5167,8 @@ static struct { const char *uuid; /* the pinned image of the running OS firmware */ u32 ext_aura; /* external engines Aura enabled itself (bit n for dcpextN) */ bool ext; - bool headless; /* no panel: t6050_headless_handoff() */ + const struct fw_version_info *dcp_fw; /* the version the DCP nodes get */ + bool headless; /* no panel: t6050_headless_handoff() */ bool prewired; /* clocks and bandwidth scratch prewired: t6050_prewired() */ } t6050; @@ -5252,17 +5272,19 @@ static T6050_TEXT bool t6050_prewired(void *dt) } /* - * Picks the row of the running OS firmware and the image a nub reports: the internal DCP's, or on - * a board without a panel the engine the display subsystem scans out through. False if no row - * pairs the two. + * Picks the row of the image a nub reports: the internal DCP's, or on a board without a panel the + * engine the display subsystem scans out through. A row whose DCP nodes take the OS firmware's + * version must also be the running OS firmware's; one with its own dcp_fw is picked by the image + * alone. False if no row matches. */ static T6050_TEXT bool t6050_pick_image(const char *uuid, u32 len) { for (size_t i = 0; i < ARRAY_SIZE(t6050_images); i++) - if (os_firmware.version == t6050_images[i].os_fw && dcp6_is_uuid(uuid, len) && - !strcmp(uuid, t6050_images[i].uuid)) { + if (dcp6_is_uuid(uuid, len) && !strcmp(uuid, t6050_images[i].uuid) && + (t6050_images[i].dcp_fw || os_firmware.version == t6050_images[i].os_fw)) { t6050.uuid = t6050_images[i].uuid; t6050.ext = t6050_images[i].ext; + t6050.dcp_fw = t6050_images[i].dcp_fw ? t6050_images[i].dcp_fw : &os_firmware; return true; } return false; @@ -5888,9 +5910,9 @@ static T6050_TEXT int t6050_publish(void *dt) fdt32_t v[1]; if (firmware_set_fdt(dt, kboot_fdt_path_exact(dt, t6050.path[T6050_DCP]), - "apple,firmware-version", &os_firmware) || + "apple,firmware-version", t6050.dcp_fw) || firmware_set_fdt(dt, kboot_fdt_path_exact(dt, t6050.path[T6050_DCP]), - "apple,firmware-compat", &os_firmware) || + "apple,firmware-compat", t6050.dcp_fw) || t6050_setprop(dt, T6050_DCP, "apple,firmware-uuid", t6050.uuid, strlen(t6050.uuid) + 1) || (t6050.prewired ? t6050_publish_prewired(dt) : t6050_publish_wiring(dt))) return -1; @@ -6130,9 +6152,9 @@ static T6050_TEXT int t6050_ext_one(void *dt, int n) if (fdt_get_path(dt, targets[i], path[i], T6050_PATH)) return -1; if (firmware_set_fdt(dt, kboot_fdt_path_exact(dt, path[0]), "apple,firmware-version", - &os_firmware) || + t6050.dcp_fw) || firmware_set_fdt(dt, kboot_fdt_path_exact(dt, path[0]), "apple,firmware-compat", - &os_firmware) || + t6050.dcp_fw) || fdt_setprop(dt, kboot_fdt_path_exact(dt, path[0]), "apple,firmware-uuid", t6050.uuid, strlen(t6050.uuid) + 1) || fdt_setprop(dt, kboot_fdt_path_exact(dt, path[0]), "apple,bw-scratch", v, sizeof(v))) @@ -6175,6 +6197,92 @@ static T6050_TEXT void t6050_ext_handoff(void *dt, int engines, int skip) } } +#ifdef ESP_STAGE2 +/* + * Node `n` is the PMC metadata: reg , 3 cells, and that window reaching the CPU at the + * ADT's address through every bus above it (t6050_identity_reg()), as the OS resolves + * apple,bw-scratch: an identity bus below a translating one does not match. + */ +static T6050_TEXT bool t6050_pmc_matches(void *dt, int n) +{ + int len; + const fdt64_t *reg = fdt_getprop(dt, n, "reg", &len); + if (!reg || len != 16 || fdt64_ld(®[0]) != t6050.pmc || + fdt64_ld(®[1]) != t6050.pmc_size || !t6050_identity_reg(dt, n)) + return false; + const fdt32_t *cells = fdt_getprop(dt, n, "#apple,bw-scratch-cells", &len); + return cells && len == 4 && fdt32_ld(cells) == 3; +} + +/* + * A device tree whose dcp and disp0 are enabled already: a kernel that adopts the internal DCP on + * its own. The external engines run the same image and are still handed off. They need the PMC + * metadata node their bandwidth scratch points into, which only the internal handoff publishes: + * published here beside the dcp, or a matching node already there or on another bus reused. Returns + * 0 with t6050.pmc_ph set; nonzero, with the device tree unchanged, if it is not that case. + * Built into the ESP Stage 2 only: a Stage 1 booting Linux directly leaves such a tree's external + * engines with iBoot. + */ +static T6050_TEXT int t6050_adopted(void *dt) +{ + char name[40], parent[T6050_PATH], node[T6050_PATH + 40]; + int dcp = kboot_fdt_path_exact(dt, "dcp"); + int disp = kboot_fdt_path_exact(dt, "disp0"); + u32 ph = 0; + + if (dcp < 0 || disp < 0 || fdt_node_check_compatible(dt, dcp, dcp6.soc->dcp_compat) || + fdt_node_check_compatible(dt, disp, dcp6.soc->disp_compat) || !t6050_available(dt, dcp) || + !t6050_available(dt, disp) || !t6050.pmc || !t6050.pmc_size || + fdt_get_path(dt, dcp, t6050.path[T6050_DCP], T6050_PATH) || + fdt_get_path(dt, disp, t6050.path[T6050_DISP], T6050_PATH)) + return -1; + /* As t6050_check_dt(): the dcp's windows reach the CPU at their own addresses */ + if (dcp6_cells_2_2(dt, dcp, "dcp") || !t6050_identity_reg(dt, dcp)) + bail("dcp is not on an identity-mapped bus: external engines not handed off\n"); + + strcpy(parent, t6050.path[T6050_DCP]); + *strrchr(parent, '/') = 0; + snprintf(name, sizeof(name), "pmc-metadata@%lx", t6050.pmc); + snprintf(node, sizeof(node), "%s/%s", parent, name); + + void *scratch = dcp6_scratch(dt); + if (!scratch) + return -1; + /* + * One beside the dcp decides; otherwise a matching one elsewhere. Either, and a new one, must + * reach the CPU at the ADT's address through every bus above it (t6050_pmc_matches()). + */ + int n = kboot_fdt_path_exact(scratch, node); + for (int o = 0; n < 0 && (o = fdt_next_node(scratch, o, NULL)) >= 0;) + if (!strcmp(fdt_get_name(scratch, o, NULL), name) && t6050_pmc_matches(scratch, o)) + n = o; + if (n >= 0) { + if (t6050_pmc_matches(scratch, n)) { + ph = fdt_get_phandle(scratch, n); + if (!ph && + (fdt_generate_phandle(scratch, &ph) || fdt_setprop_u32(scratch, n, "phandle", ph))) + ph = 0; + } + } else { + fdt64_t reg[2] = {cpu_to_fdt64(t6050.pmc), cpu_to_fdt64(t6050.pmc_size)}; + ph = t6050_add_node(scratch, parent[0] ? parent : "/", name); + n = kboot_fdt_path_exact(scratch, node); + if (!ph || fdt_setprop(scratch, n, "reg", reg, sizeof(reg)) || + fdt_setprop_u32(scratch, n, "#apple,bw-scratch-cells", 3) || + !t6050_pmc_matches(scratch, kboot_fdt_path_exact(scratch, node))) + ph = 0; + } + if (!ph) { + free(scratch); + bail("%s: could not publish the PMC metadata for the external engines\n", node); + } + if (dcp6_commit(dt, scratch)) + return -1; + t6050.pmc_ph = ph; + return 0; +} +#endif /* ESP_STAGE2 */ + /* * The ADT dcpextN index whose coprocessor is at `node`'s identity-mapped reg[0], or -1. * When `unique` is non-NULL, sets `*unique` to whether `node` is the only apple,t6050-dcpext @@ -6404,11 +6512,11 @@ static T6050_TEXT void t6050_ext_reject(void *dt) } /* - * Write `os_firmware` to `apple,firmware-compat` and any existing `apple,firmware-version` on - * `at` in one scratch transaction. Returns 0 on success, -1 if scratch allocation, any FDT - * property write, or commit failed (leaving `dt` untouched and `scratch` freed). + * Write `fw` to `apple,firmware-compat` and any existing `apple,firmware-version` on `at` in one + * scratch transaction. Returns 0 on success, -1 if scratch allocation, any FDT property write, or + * commit failed (leaving `dt` untouched and `scratch` freed). */ -static T6050_TEXT int t6050_ext_version_one(void *dt, int at) +static T6050_TEXT int t6050_ext_version_one(void *dt, int at, const struct fw_version_info *fw) { static const char *const props[] = {"apple,firmware-compat", "apple,firmware-version"}; void *scratch = dcp6_scratch(dt); @@ -6420,7 +6528,7 @@ static T6050_TEXT int t6050_ext_version_one(void *dt, int at) /* apple,firmware-compat (props[0]) always; apple,firmware-version only if present */ if (i && !fdt_getprop(scratch, at, props[i], NULL)) continue; - err = firmware_set_fdt(scratch, at, props[i], &os_firmware); + err = firmware_set_fdt(scratch, at, props[i], fw); } if (err || dcp6_commit(dt, scratch)) { if (err) @@ -6443,18 +6551,20 @@ static T6050_TEXT int t6050_ext_version_one(void *dt, int at) * Each surviving engine's version edit runs in its own scratch transaction; if the live/ADT check * fails during versioning or if allocation, writing, or commit fails, that engine is disabled (or * deleted on a packed DT) and stripped from scanout rather than leaving stale apple,firmware-compat - * enabled. + * enabled. The version is the DCP ABI of the image row this boot picked (t6050_pick_image(); the + * engines must run that image), or the OS firmware's when no row was picked. */ static T6050_TEXT void t6050_ext_version(void *dt) { + const struct fw_version_info *fw = t6050.dcp_fw ? t6050.dcp_fw : &os_firmware; u32 done = 0; int count = 0, err = 0, at = -1; t6050_ext_reject(dt); - if (os_firmware.version == V_UNKNOWN || !os_firmware.num_length) { + if (fw->version == V_UNKNOWN || !fw->num_length) { dlog("firmware %s is unknown: the external engines keep the tree's version\n", - os_firmware.string ? os_firmware.string : ""); + fw->string ? fw->string : ""); return; } while ((at = fdt_node_offset_by_compatible(dt, at, "apple,t6050-dcpext")) >= 0) { @@ -6467,7 +6577,7 @@ static T6050_TEXT void t6050_ext_version(void *dt) const char *why = NULL; if (t6050_check_ext_adt(n)) { why = "rejected"; - } else if (t6050_ext_version_one(dt, at)) { + } else if (t6050_ext_version_one(dt, at, fw)) { why = "could not take firmware version"; } else { done |= 1u << n; @@ -6486,8 +6596,7 @@ static T6050_TEXT void t6050_ext_version(void *dt) if (err || at != -FDT_ERR_NOTFOUND) dlog("could not give the external engines the firmware version\n"); if (count) - dlog("firmware %s on %d external engine(s) the device tree enables\n", os_firmware.string, - count); + dlog("firmware %s on %d external engine(s) the device tree enables\n", fw->string, count); } /* Any failure leaves the display nodes disabled: the boot framebuffer keeps the panel */ @@ -6495,7 +6604,8 @@ static T6050_TEXT void t6050_handoff(void *dt, bool prewired) { memset(&t6050, 0, sizeof(t6050)); t6050.prewired = prewired; - if (!t6050_check_adt() && !t6050_check_dt(dt) && !t6050_check_darts(dt)) { + int adt_ok = !t6050_check_adt(); + if (adt_ok && !t6050_check_dt(dt) && !t6050_check_darts(dt)) { void *scratch = dcp6_scratch(dt); if (scratch && t6050_publish(scratch)) { dlog("DT write failed (full?)\n"); @@ -6514,6 +6624,14 @@ static T6050_TEXT void t6050_handoff(void *dt, bool prewired) } if (t6050_setprop(dt, -1, T6050_STATUS, "refused", sizeof("refused"))) dlog("could not set /chosen/" T6050_STATUS "\n"); +#ifdef ESP_STAGE2 + if (adt_ok && t6050.ext && !t6050_adopted(dt)) { + dlog("dcp and disp0 are enabled already: the kernel adopts the internal DCP; handing off " + "the external engines\n"); + t6050_ext_handoff(dt, 4, -1); + return; + } +#endif dlog("internal display handoff refused; the boot framebuffer keeps the panel\n"); } diff --git a/tests/python/test_t6041_display_handoff.py b/tests/python/test_t6041_display_handoff.py index 71e5917ff..574fb7883 100644 --- a/tests/python/test_t6041_display_handoff.py +++ b/tests/python/test_t6041_display_handoff.py @@ -219,3 +219,67 @@ def test_unknown_profile_does_not_match_unknown_firmware(tmp_path): assert "no qualified OS firmware for apple,t6041-dcp: nothing done" in result.stdout assert "nothing done: the device tree is byte for byte unchanged" in result.stdout assert "nothing done: no MMIO access at all" in result.stdout + + +@pytest.fixture(scope="module") +def t6050_host(tmp_path_factory): + return build_host(tmp_path_factory.mktemp("t6050"), host_source="t6050_display_host.c", + defines=("ESP_STAGE2",)) + + +@pytest.fixture(scope="module") +def t6050_stage1_host(tmp_path_factory): + return build_host(tmp_path_factory.mktemp("t6050s1"), host_source="t6050_display_host.c") + + +T6050_SCENARIOS = re.findall(r'^ \{"(t6050-[a-z0-9.-]+)",\s+"', + (ROOT / "tests/t6050_display_host.c").read_text(), re.M) +T6050_ADOPTED = "dcp and disp0 are enabled already: the kernel adopts the internal DCP" +T6050_REFUSED = "internal display handoff refused; the boot framebuffer keeps the panel" +# As REASONS: the log line of the path each T6050 scenario is meant to take +T6050_REASONS = { + "t6050-27.3": "internal display handed off: firmware ", + "t6050-27.3-any-os": "internal display handed off: firmware ", + "t6050-adopted": T6050_ADOPTED, + "t6050-adopted-existing-pmc": T6050_ADOPTED, + "t6050-adopted-pmc-other-bus": T6050_ADOPTED, + "t6050-adopted-pmc-nested-bus": T6050_ADOPTED, + "t6050-adopted-pmc-mismatch": "could not publish the PMC metadata for the external engines", + "t6050-adopted-no-status": T6050_ADOPTED, + "t6050-adopted-dcp-only": T6050_REFUSED, + "t6050-adopted-reserved": T6050_REFUSED, + "t6050-adopted-wrong-compat": T6050_REFUSED, + "t6050-adopted-dangling-alias": T6050_REFUSED, + "t6050-adopted-mapped-bus": "dcp is not on an identity-mapped bus: external engines not handed off", +} + + +def test_t6050_scenario_list_matches(t6050_host): + assert scenarios(t6050_host) == T6050_SCENARIOS + assert sorted(T6050_REASONS) == sorted(T6050_SCENARIOS) + + +@pytest.mark.parametrize("scenario", T6050_SCENARIOS) +def test_t6050_scenario(t6050_host, scenario): + result = run(t6050_host, scenario) + assert result.returncode == 0, result.stdout + result.stderr + assert T6050_REASONS[scenario] in result.stdout, result.stdout + if T6050_REASONS[scenario] != T6050_ADOPTED: + assert T6050_ADOPTED not in result.stdout, result.stdout + handed_off = scenario in ("t6050-27.3", "t6050-27.3-any-os", "t6050-adopted", "t6050-adopted-existing-pmc", + "t6050-adopted-pmc-other-bus", "t6050-adopted-pmc-nested-bus", + "t6050-adopted-no-status") + assert ("dcpext0 handed off: bw-scratch" in result.stdout) == handed_off, result.stdout + assert result.stdout.rstrip().endswith(f"{scenario}: pass"), result.stdout + assert "FAIL" not in result.stdout, result.stdout + + +@pytest.mark.parametrize("scenario", T6050_SCENARIOS) +def test_t6050_stage1_scenario(t6050_stage1_host, scenario): + """A Stage 1 can boot Linux directly: the 27.3 beta row and the adopted path are not in it.""" + result = run(t6050_stage1_host, scenario) + assert result.returncode == 0, result.stdout + result.stderr + assert T6050_REFUSED in result.stdout, result.stdout + assert T6050_ADOPTED not in result.stdout, result.stdout + assert "dcpext0 handed off" not in result.stdout, result.stdout + assert result.stdout.rstrip().endswith(f"{scenario}: pass"), result.stdout diff --git a/tests/python/test_t6050_tree_shape.py b/tests/python/test_t6050_tree_shape.py index dc3cf7a2e..0247d2d45 100644 --- a/tests/python/test_t6050_tree_shape.py +++ b/tests/python/test_t6050_tree_shape.py @@ -765,7 +765,7 @@ def test_t6050_external_engines_get_the_stub_version(tmp_path): ''' + layout + r''' static struct fw_version_info os_firmware; static struct { u64 phys_base, mem_size; } cur_boot_args = {0x10000000000UL, 0x200000000UL}; -static struct { const char *uuid; u32 ext_aura; } t6050; +static struct { const char *uuid; u32 ext_aura; const struct fw_version_info *dcp_fw; } t6050; static struct { const char *name; } soc = {"t6050"}; static struct { const typeof(soc) *soc; } dcp6 = {&soc}; static void *adt; @@ -1128,6 +1128,23 @@ def test_t6050_external_engines_get_the_stub_version(tmp_path): assert(is_disabled("/dcpext1") && is("/dcpext1", "apple,firmware-compat", &old)); assert(has_scanout_dart(PH_DISP0) && !has_scanout_dart(PH_DART0) && !has_scanout_dart(PH_DART1)); cases++; + /* An image row with its own DCP ABI (27.3 beta 1's 27.3.0): the engines take that, not the + * OS firmware's numbers, even when the OS firmware is unknown. */ + { + static const struct fw_version_info abi = {V27_3, "27.3", {27, 3, 0}, 3, NULL}; + static const struct fw_version_info beta = {V27_3, "27.3 beta", {27, 2, 98, 1}, 4, NULL}; + for (int unknown = 0; unknown < 2; unknown++) { + world(); + os_firmware = unknown ? (struct fw_version_info){V_UNKNOWN, NULL, {0}, 0, NULL} : beta; + t6050.dcp_fw = &abi; + t6050_ext_version(tree); + t6050.dcp_fw = NULL; + assert(is("/dcpext0", "apple,firmware-compat", &abi)); + assert(is("/dcpext0", "apple,firmware-version", &abi)); + assert(is("/dcpext1", "apple,firmware-compat", &abi)); + assert(is("/dcpext2", "apple,firmware-compat", &old)); cases++; + } + } /* An unknown firmware: nothing changes. */ world(); os_firmware = (struct fw_version_info){V_UNKNOWN, NULL, {0}, 0, NULL}; @@ -1475,4 +1492,4 @@ def test_t6050_external_engines_get_the_stub_version(tmp_path): return 0; } ''' - run(tmp_path, "ext-version", code, "PASS dcpext version 34 cases") + run(tmp_path, "ext-version", code, "PASS dcpext version 36 cases") diff --git a/tests/t6041_display_host.c b/tests/t6041_display_host.c index f773fdc55..ab82f18e5 100644 --- a/tests/t6041_display_host.c +++ b/tests/t6041_display_host.c @@ -48,7 +48,7 @@ u32 chip_id; volatile enum exc_guard_t exc_guard; volatile int exc_count; struct fw_version_info os_firmware; -const struct fw_version_info fw_versions[V27_2 + 1] = { +const struct fw_version_info fw_versions[V27_3B + 1] = { [V14_7] = {V14_7, "14.7", {14, 7, 0}, 3, "iBoot"}, [V26_6_2] = {V26_6_2, "26.6.2", {26, 6, 2}, 3, "mBoot-18000.161.10"}, [V27_0] = {V27_0, "27.0", {27, 0, 0}, 3, "mBoot-20457.1.29"}, diff --git a/tests/t6050_display_host.c b/tests/t6050_display_host.c new file mode 100644 index 000000000..abf3e03cd --- /dev/null +++ b/tests/t6050_display_host.c @@ -0,0 +1,507 @@ +/* SPDX-License-Identifier: MIT */ +/* + * Host integration test for the T6050 (J714c-shaped) display handoff of + * src/kboot_display_handoff.c: the 27.3 beta image row, whose DCP nodes get 27.3.0 rather than the + * OS firmware numbers, and a device tree that enables dcp and disp0 already, where only the + * external engines are handed off and the PMC metadata node they point into is published or + * reused. + * + * Built as the ESP Stage 2 (-DESP_STAGE2), every scenario takes its path. Built as Stage 1, which + * can boot Linux directly, the 27.3 beta row and the adopted-panel path are absent: every scenario + * is refused and leaves the device tree unchanged. + * + * Reuses the fake ADT, MMIO and libfdt harness of t6041_display_host.c. This file models the T6050 + * helpers that t6050_unmodelled.h makes abort. Every address and value is synthetic; the image id + * is the one the T6050 image table pins. + * + * t6050-display-host list + * t6050-display-host + */ +#include "xnuboot.h" + +#define T6050_UNMODELLED_H /* modelled below */ +#define main t6041_main +#include "t6041_display_host.c" +#undef main + +#define T50_UUID "58CB3FFC-B2BA-352E-B20B-71A91B15FA9F" +#define T50_STATUS "asahi,t6050-dcp-handoff" +#define T50_COPROC 0x512e00000ULL +#define T50_DART_DCP 0x512340000ULL +#define T50_DART_DISP 0x512300000ULL +#define T50_DISP 0x510200000ULL /* disp0 reg[0..3], 0x100000 apart */ +#define T50_PMC 0x510f00000ULL /* disp0 reg[4] */ +#define T50_PMC_SIZE 0x100000ULL +#define T50_EXT 0x522e00000ULL +#define T50_EXT_DCP 0x522340000ULL /* dart-dcpext0 */ +#define T50_EXT_DISP 0x522300000ULL /* dart-dispext0 */ +#define T50_PS_EXT (PMGR_BASE + 0x300) +#define T50_L1 (TB + 0x2f0000000ULL) /* the five four-level roots, 0x100000 apart */ +#define T50_VM_SIZE 0x1000000000ULL +#define T50_BW (0x20000 + 2 * 0x4000) /* bandwidth agent 2: the panel's */ +#define T50_BW_EXT (0x20000 + 5 * 0x4000) /* bandwidth agent 5: dcpext0's */ +#define T50_DCP_PATH "/soc/dcp@512e00000" +#define T50_EXT_PATH "/soc/dcp@522e00000" +#define T50_PMC_NAME "pmc-metadata@510f00000" +#define T50_PMC_PATH "/soc/" T50_PMC_NAME + +enum { + T50_PH_DART_DCP = 1, + T50_PH_DART_DISP, + T50_PH_MBOX, + T50_PH_EXT_DCP, + T50_PH_EXT_DISP, + T50_PH_EXT_MBOX +}; + +/* ---- the T6050 helpers of src/kboot.c, src/adt.c and src/pmgr.c ---- */ + +struct boot_args cur_boot_args; + +/* As src/kboot.c: an alias or an absolute path, each component matched by its whole name */ +int kboot_fdt_path_exact(const void *fdt, const char *path) +{ + if (path && path[0] != '/') + path = fdt_get_alias(fdt, path); + if (!path || path[0] != '/') + return -FDT_ERR_NOTFOUND; + + int node = 0; + while (node >= 0 && *path) { + while (*path == '/') + path++; + const char *end = strchr(path, '/'); + int len = end ? end - path : (int)strlen(path), child, nlen; + if (!len) + break; + int found = -FDT_ERR_NOTFOUND; + fdt_for_each_subnode(child, fdt, node) + { + const char *name = fdt_get_name(fdt, child, &nlen); + if (name && nlen == len && !memcmp(name, path, len)) { + found = child; + break; + } + } + node = found; + path += len; + } + return node; +} + +int adt_getprop_copy(const void *tree, int node, const char *name, void *out, size_t len) +{ + u32 plen = 0; + const void *p = adt_getprop(tree, node, name, &plen); + if (!p || plen != len) + return -1; + memcpy(out, p, len); + return len; +} + +int pmgr_adt_is_powered(const char *path) +{ + return adt_path_offset(adt, path) < 0 ? -1 : 1; +} + +/* dcpext0 has one power word; nothing else is asked for */ +int pmgr_adt_collect_psregs(const char *path, u64 *out, u8 *flags, int max) +{ + UNUSED(flags); + if (strcmp(path, "/arm-io/dcpext0") || max < 1) + return -1; + out[0] = T50_PS_EXT; + return 1; +} + +/* ---- the J714c-shaped world: the panel's DCP and one external engine, both left running ---- */ + +/* A DART as iBoot leaves it: locked, `sid` translating through the four-level root `l1` */ +static void t50_dart(const char *path, u64 base, u32 sid, u64 l1) +{ + char name[16]; + if (node_find(path) < 0) { + reg_add(path, base, 0x4000); + prop_u64(path, "vm-base", TB); + prop_u64(path, "vm-size", T50_VM_SIZE); + region_add(base, 0x4000); + poke32(base + 0x200, 1); + } + snprintf(name, sizeof(name), "l1-tt-%u", sid); + prop_pair(path, name, l1, 1); + poke32(base + 0x1000 + 4 * sid, 0x9); + poke32(base + 0x1400 + 4 * sid, ttbr_of(l1)); +} + +/* A bandwidth agent record: kind 1, the agent's index, its interrupt */ +static void t50_agent(u8 *rec, u8 index, u32 birq) +{ + rec[0] = 1; + rec[2] = index; + memcpy(rec + 4, &birq, 4); +} + +static void world_t6050(void) +{ + chip_id = T6050; + os_firmware = (struct fw_version_info){V27_3B, "27.3b1", {27, 2, 98, 1}, 4, NULL}; + ram_base = TB + 0x800000; + ram_size = 0x200000000ULL - 0x800000; + cur_boot_args.phys_base = ram_base; + cur_boot_args.mem_size = ram_size; + cur_boot_args.video.base = fb_base = segs[SEG_VRAM].phys + 0x4000; + cur_boot_args.video.stride = 0x1000; + cur_boot_args.video.height = 0x40; + prop_u64("/chosen", "dram-base", TB); + prop_u64("/chosen", "dram-size", 0x300000000ULL); + mcc_carveout_count = 0; + + const char *nub = "/arm-io/dcp/iop-dcp-nub"; + prop_set(nub, "segment-ranges", segs, sizeof(segs)); + prop_str(nub, "segment-names", "__TEXT;__DATA;__OS_LOG;unknown;unknown;unknown;unknown"); + prop_str(nub, "uuid", T50_UUID); + prop_u32(nub, "running", 1); + reg_add("/vram", segs[SEG_VRAM].phys, segs[SEG_VRAM].size); + + reg_add("/arm-io/dcp", T50_COPROC, 0x6c000); + reg_add("/arm-io/dcp", T50_COPROC + 0x100000, 0x4000); + for (int i = 0; i < 4; i++) + reg_add("/arm-io/disp0", T50_DISP + i * 0x100000ULL, 0x4000); + reg_add("/arm-io/disp0", T50_PMC, T50_PMC_SIZE); + region_add(T50_COPROC, 0x4000); + poke32(T50_COPROC + 0x44, 0x10); + t50_dart("/arm-io/dart-dcp", T50_DART_DCP, 23, T50_L1); + t50_dart("/arm-io/dart-disp0", T50_DART_DISP, 0, T50_L1 + 0x100000); + t50_dart("/arm-io/dart-disp0", T50_DART_DISP, 16, T50_L1 + 0x200000); + + /* The PMGR's bandwidth agents, and the interrupt each display block names */ + u8 agents[2 * 24] = {0}; + u32 fn[3] = {77, 0, 0x30}; + t50_agent(agents, 2, 0x30); + t50_agent(agents + 24, 5, 0x41); + prop_u32("/arm-io/pmgr", "AAPL,phandle", 77); + prop_set("/arm-io/pmgr", "bwr-agent", agents, sizeof(agents)); + prop_set("/arm-io/disp0", "function-bw_req_interrupt0", fn, sizeof(fn)); + fn[2] = 0x41; + prop_set("/arm-io/dispext0", "function-bw_req_interrupt0", fn, sizeof(fn)); + + u32 ids[] = {300, 301}, hz[64] = {0}; + hz[300 - 256] = 600000000; + hz[301 - 256] = 24000000; + prop_set("/arm-io/disp0", "clock-ids", ids, sizeof(ids)); + prop_set("/arm-io", "clock-frequencies", hz, sizeof(hz)); + prop_u32("/backlight", "user-accessible-max-nits", 500u << 16); + + /* dcpext0, running the panel's image */ + struct seg ext[2] = { + {TB + 0x281200000ULL, 0, TB + 0x51000000, 0x8000, 0}, + {TB + 0x28030000ULL, 0, TB + 0x28030000ULL, 0x4000, 0xa}, + }; + nub = "/arm-io/dcpext0/iop-dcpext0-nub"; + prop_set(nub, "segment-ranges", ext, sizeof(ext)); + prop_str(nub, "segment-names", "__DATA;__OS_LOG"); + prop_str(nub, "uuid", T50_UUID); + prop_u32(nub, "running", 1); + reg_add("/arm-io/dcpext0", T50_EXT, 0x6c000); + region_add(T50_EXT, 0x4000); + poke32(T50_EXT + 0x44, 0x10); + t50_dart("/arm-io/dart-dcpext0", T50_EXT_DCP, 23, T50_L1 + 0x300000); + t50_dart("/arm-io/dart-dispext0", T50_EXT_DISP, 16, T50_L1 + 0x400000); + region_add(PMGR_BASE, 0x1000); + poke32(T50_PS_EXT, 0xff); +} + +/* ---- the device tree: the display block and dcpext0, as a kernel DT describes them ---- */ + +static int t50_mbox(void *dt, int soc, const char *name, u64 base, u32 ph) +{ + int n = OK(fdt_add_subnode(dt, soc, name)); + OK(fdt_setprop_string(dt, n, "compatible", "apple,asc-mailbox-v4")); + reg2(dt, n, base, 0x4000); + OK(fdt_setprop_string(dt, n, "status", "disabled")); + OK(fdt_setprop_u32(dt, n, "phandle", ph)); + return n; +} + +static void t50_pmc(void *dt, const char *bus, u64 size) +{ + int n = OK(fdt_add_subnode(dt, fdt_path_offset(dt, bus), T50_PMC_NAME)); + reg2(dt, n, T50_PMC, size); + OK(fdt_setprop_u32(dt, n, "#apple,bw-scratch-cells", 3)); +} + +static void build_t6050(void *dt, const char *dcp_status, const char *disp_status) +{ + static const char root[] = "apple,j714c\0apple,t6050\0apple,arm-platform"; + static const char names[] = "coproc\0iop-vbar\0disp-0\0disp-1\0disp-2\0disp-3\0disp-4"; + + OK(fdt_create_empty_tree(dt, DT_SIZE)); + OK(fdt_setprop(dt, 0, "compatible", root, sizeof(root))); + cells(dt, 0); + OK(fdt_add_subnode(dt, 0, "chosen")); + int resv = OK(fdt_add_subnode(dt, 0, "reserved-memory")); + cells(dt, resv); + OK(fdt_setprop_empty(dt, resv, "ranges")); + + int soc = OK(fdt_add_subnode(dt, 0, "soc")); + cells(dt, soc); + OK(fdt_setprop_empty(dt, soc, "ranges")); + dart(dt, soc, "iommu@512340000", T50_DART_DCP, T50_PH_DART_DCP); + dart(dt, soc, "iommu@512300000", T50_DART_DISP, T50_PH_DART_DISP); + dart(dt, soc, "iommu@522340000", T50_EXT_DCP, T50_PH_EXT_DCP); + dart(dt, soc, "iommu@522300000", T50_EXT_DISP, T50_PH_EXT_DISP); + t50_mbox(dt, soc, "mbox@512e08000", T50_COPROC + 0x8000, T50_PH_MBOX); + t50_mbox(dt, soc, "mbox@522e08000", T50_EXT + 0x8000, T50_PH_EXT_MBOX); + + fdt64_t reg[14]; + for (int i = 0; i < 7; i++) { + u64 base = i == 0 ? T50_COPROC : i == 1 ? T50_COPROC + 0x100000 : T50_DISP; + base = i == 6 ? T50_PMC : i > 1 ? base + (i - 2) * 0x100000ULL : base; + reg[2 * i] = cpu_to_fdt64(base); + reg[2 * i + 1] = cpu_to_fdt64(i == 0 ? 0x6c000 : i == 6 ? T50_PMC_SIZE : 0x4000); + } + int dcp = OK(fdt_add_subnode(dt, soc, "dcp@512e00000")); + OK(fdt_setprop_string(dt, dcp, "compatible", "apple,t6050-dcp")); + OK(fdt_setprop(dt, dcp, "reg", reg, sizeof(reg))); + OK(fdt_setprop(dt, dcp, "reg-names", names, sizeof(names))); + cells(dt, dcp); + iommus(dt, dcp, T50_PH_DART_DCP, 23); + OK(fdt_setprop_u32(dt, dcp, "mboxes", T50_PH_MBOX)); + OK(fdt_setprop_string(dt, dcp, "status", dcp_status)); + OK(fdt_add_subnode(dt, dcp, "panel")); + int pio = OK(fdt_add_subnode(dt, dcp, "piodma")); + iommus(dt, pio, T50_PH_DART_DISP, 16); + + int ext = OK(fdt_add_subnode(dt, soc, "dcp@522e00000")); + OK(fdt_setprop_string(dt, ext, "compatible", "apple,t6050-dcpext")); + reg2(dt, ext, T50_EXT, 0x6c000); + iommus(dt, ext, T50_PH_EXT_DCP, 23); + OK(fdt_setprop_u32(dt, ext, "mboxes", T50_PH_EXT_MBOX)); + OK(fdt_setprop_string(dt, ext, "apple,connector-type", "USB-C")); + OK(fdt_setprop_string(dt, ext, "status", "disabled")); + pio = OK(fdt_add_subnode(dt, ext, "piodma")); + iommus(dt, pio, T50_PH_EXT_DISP, 16); + + int disp = OK(fdt_add_subnode(dt, 0, "display-subsystem")); + OK(fdt_setprop_string(dt, disp, "compatible", "apple,display-subsystem")); + iommus(dt, disp, T50_PH_DART_DISP, 0); + OK(fdt_setprop_string(dt, disp, "status", disp_status)); + + int aliases = OK(fdt_add_subnode(dt, 0, "aliases")); + OK(fdt_setprop_string(dt, aliases, "dcp", T50_DCP_PATH)); + OK(fdt_setprop_string(dt, aliases, "disp0", "/display-subsystem")); +} + +/* ---- checks ---- */ + +static const u32 t50_ver[3] = {27, 3, 0}; + +static const char *t50_status(const void *dt) +{ + return fdt_getprop(dt, fdt_path_offset(dt, "/chosen"), T50_STATUS, NULL); +} + +static int t50_pmc_count(const void *dt) +{ + int count = 0; + for (int node = 0; node >= 0; node = fdt_next_node(dt, node, NULL)) + count += !strncmp(fdt_get_name(dt, node, NULL), "pmc-metadata", 12); + return count; +} + +/* The PMC metadata node at `path`, one of `count`: reg, cells and a phandle. Returns the phandle */ +static u32 t50_pmc_check(const void *dt, const char *path, int count) +{ + int node = fdt_path_offset(dt, path); + u64 base = 0, size = 0; + const u32 three = 3; + u32 ph = node < 0 ? 0 : fdt_get_phandle(dt, node); + check(node >= 0 && t50_pmc_count(dt) == count, "%d PMC metadata node(s), one at %s", count, + path); + check(node >= 0 && reg_of(dt, node, &base, &size) && base == T50_PMC && size == T50_PMC_SIZE && + u32s_are(dt, node, "#apple,bw-scratch-cells", &three, 1) && ph, + "it has reg , #apple,bw-scratch-cells = <3> and a phandle"); + return ph; +} + +/* dcpext0 handed off against the PMC node `ph`, or left exactly as the device tree had it */ +static void t50_ext_check(const void *dt, bool want, u32 ph) +{ + int ext = fdt_path_offset(dt, T50_EXT_PATH); + if (!want) { + check(ext >= 0 && status_is(dt, ext, "disabled") && + !fdt_getprop(dt, ext, "apple,firmware-version", NULL) && + !fdt_getprop(dt, ext, "apple,bw-scratch", NULL) && + status_is(dt, fdt_node_offset_by_phandle(dt, T50_PH_EXT_DCP), "disabled"), + "dcpext0 is not handed off"); + return; + } + const u32 scratch[4] = {ph, 0, 5, T50_BW_EXT}; + const u32 scanout[4] = {T50_PH_DART_DISP, 0, T50_PH_EXT_DISP, 0}; + const char *uuid = ext < 0 ? NULL : fdt_getprop(dt, ext, "apple,firmware-uuid", NULL); + check(ext >= 0 && status_is(dt, ext, "okay") && + status_is(dt, fdt_node_offset_by_phandle(dt, T50_PH_EXT_MBOX), "okay") && + status_is(dt, fdt_node_offset_by_phandle(dt, T50_PH_EXT_DCP), "okay") && + status_is(dt, fdt_node_offset_by_phandle(dt, T50_PH_EXT_DISP), "okay"), + "dcpext0, its mailbox and both of its DARTs are enabled"); + check(ext >= 0 && u32s_are(dt, ext, "apple,firmware-version", t50_ver, 3) && + u32s_are(dt, ext, "apple,firmware-compat", t50_ver, 3) && uuid && + !strcmp(uuid, T50_UUID), + "dcpext0 apple,firmware-version and -compat are <27 3 0>, with the image id"); + check(ext >= 0 && ph && u32s_are(dt, ext, "apple,bw-scratch", scratch, 4), + "dcpext0 apple,bw-scratch points at the PMC metadata node, agent 5"); + check(u32s_are(dt, alias_node(dt, "disp0"), "iommus", scanout, 4), + "the display subsystem scans out through dart-dispext0 too"); +} + +/* Nothing but /chosen and the __OS_LOG reservations, which are their own transaction, differs */ +static void t50_unchanged_check(const void *in, const void *dt) +{ + static u8 copy[DT_SIZE]; + const char *const extra[] = {"/reserved-memory/dcp-oslog@", NULL}; + memcpy(copy, dt, fdt_totalsize(dt)); + fdt_delprop(copy, fdt_path_offset(copy, "/chosen"), T50_STATUS); + check(dt_diff(in, copy, extra) == 0, + "the device tree is unchanged apart from /chosen and the __OS_LOG reservations"); + check(t50_pmc_count(dt) == t50_pmc_count(in), "no PMC metadata node published"); + t50_ext_check(dt, false, 0); +} + +/* ---- scenarios ---- */ + +static const struct { + const char *name, *what; +} t50_scenarios[] = { + {"t6050-27.3", "the 27.3 beta image: the DCP nodes get 27.3.0, not the OS firmware numbers"}, + {"t6050-27.3-any-os", "the 27.3 beta image on an unknown OS firmware: picked by its image id"}, + {"t6050-adopted", "dcp and disp0 enabled already: PMC metadata published, dcpext0 handed off"}, + {"t6050-adopted-existing-pmc", "a matching PMC metadata node is reused and gets a phandle"}, + {"t6050-adopted-pmc-other-bus", "a matching PMC metadata node on another bus is reused"}, + {"t6050-adopted-pmc-nested-bus", + "a PMC metadata node on an identity bus below a translating one is not reused"}, + {"t6050-adopted-pmc-mismatch", "a PMC metadata node of another size: nothing handed off"}, + {"t6050-adopted-no-status", + "dcp and disp0 without a status are enabled: handed off as adopted"}, + {"t6050-adopted-dcp-only", "dcp enabled, disp0 disabled: nothing handed off"}, + {"t6050-adopted-reserved", "dcp status \"reserved\": nothing handed off"}, + {"t6050-adopted-wrong-compat", "an enabled dcp of another SoC: nothing handed off"}, + {"t6050-adopted-dangling-alias", "the dcp alias names no node: nothing handed off"}, + {"t6050-adopted-mapped-bus", "the dcp's bus translates addresses: nothing handed off"}, +}; + +int main(int argc, char **argv) +{ + if (argc == 2 && is(argv[1], "list")) { + for (size_t i = 0; i < ARRAY_SIZE(t50_scenarios); i++) + printf("%s\n", t50_scenarios[i].name); + return 0; + } + const char *s = NULL; + for (size_t i = 0; argc == 2 && i < ARRAY_SIZE(t50_scenarios); i++) + if (is(argv[1], t50_scenarios[i].name)) + s = t50_scenarios[i].name; + if (!s) { + fprintf(stderr, "usage: %s list | \n", argv[0]); + return 2; + } + + static u8 dt[DT_SIZE], in[DT_SIZE]; +#ifdef ESP_STAGE2 + const bool stage2 = true; +#else + const bool stage2 = false; +#endif + bool internal = is(s, "t6050-27.3") || is(s, "t6050-27.3-any-os"); + world_t6050(); + if (is(s, "t6050-27.3-any-os")) + os_firmware = (struct fw_version_info){V_UNKNOWN, "unknown", {0, 0, 0}, 3, NULL}; + build_t6050(dt, internal ? "disabled" : "okay", + internal || is(s, "t6050-adopted-dcp-only") ? "disabled" : "okay"); + if (is(s, "t6050-adopted-existing-pmc")) + t50_pmc(dt, "/soc", T50_PMC_SIZE); + if (is(s, "t6050-adopted-pmc-mismatch")) + t50_pmc(dt, "/soc", T50_PMC_SIZE / 2); + if (is(s, "t6050-adopted-pmc-other-bus")) { + int bus = OK(fdt_add_subnode(dt, 0, "bus@200000000")); + cells(dt, bus); + OK(fdt_setprop_empty(dt, bus, "ranges")); + t50_pmc(dt, "/bus@200000000", T50_PMC_SIZE); + } + if (is(s, "t6050-adopted-pmc-nested-bus")) { + /* bus@300000000 moves 0x5_0000_0000.. to 0x6_0000_0000..; bus@0 below it is identity */ + const fdt32_t ranges[6] = {cpu_to_fdt32(5), 0, cpu_to_fdt32(6), 0, cpu_to_fdt32(1), 0}; + int bus = OK(fdt_add_subnode(dt, 0, "bus@300000000")); + cells(dt, bus); + OK(fdt_setprop(dt, bus, "ranges", ranges, sizeof(ranges))); + bus = OK(fdt_add_subnode(dt, bus, "bus@0")); + cells(dt, bus); + OK(fdt_setprop_empty(dt, bus, "ranges")); + t50_pmc(dt, "/bus@300000000/bus@0", T50_PMC_SIZE); + } + if (is(s, "t6050-adopted-no-status")) { + OK(fdt_delprop(dt, fdt_path_offset(dt, T50_DCP_PATH), "status")); + OK(fdt_delprop(dt, fdt_path_offset(dt, "/display-subsystem"), "status")); + } + if (is(s, "t6050-adopted-reserved")) + OK(fdt_setprop_string(dt, fdt_path_offset(dt, T50_DCP_PATH), "status", "reserved")); + if (is(s, "t6050-adopted-wrong-compat")) + OK(fdt_setprop_string(dt, fdt_path_offset(dt, T50_DCP_PATH), "compatible", + "apple,t6020-dcp")); + if (is(s, "t6050-adopted-dangling-alias")) + OK(fdt_setprop_string(dt, fdt_path_offset(dt, "/aliases"), "dcp", "/soc/dcp@0")); + if (is(s, "t6050-adopted-mapped-bus")) { + const fdt32_t ranges[6] = {0, 0, 0, cpu_to_fdt32(0x10), 0, cpu_to_fdt32(0x10000000)}; + OK(fdt_setprop(dt, fdt_path_offset(dt, "/soc"), "ranges", ranges, sizeof(ranges))); + } + OK(fdt_pack(dt)); + OK(fdt_open_into(dt, dt, DT_SIZE)); + + memcpy(in, dt, fdt_totalsize(dt)); + mmio_reads = mmio_writes = 0; + check(dt_set_display_handoff(dt) == 0, "dt_set_display_handoff() returns 0"); + check(exc_count == 0 && mmio_writes == 0, "no MMIO fault and no MMIO write"); + + const char *status = t50_status(dt); + int dcp = fdt_path_offset(dt, T50_DCP_PATH); + if (!stage2) { + check(status && !strcmp(status, "refused"), + "Stage 1: /chosen/" T50_STATUS " = \"refused\""); + t50_unchanged_check(in, dt); + } else if (internal) { + check(status && !strcmp(status, "published"), "/chosen/" T50_STATUS " = \"published\""); + check(status_is(dt, dcp, "okay") && status_is(dt, alias_node(dt, "disp0"), "okay"), + "dcp and disp0 are enabled"); + check(u32s_are(dt, dcp, "apple,firmware-version", t50_ver, 3) && + u32s_are(dt, dcp, "apple,firmware-compat", t50_ver, 3), + "dcp apple,firmware-version and -compat are exactly <27 3 0>"); + const u32 scratch[4] = {t50_pmc_check(dt, T50_PMC_PATH, 1), 0, 5, T50_BW}; + check(u32s_are(dt, dcp, "apple,bw-scratch", scratch, 4), + "dcp apple,bw-scratch points at the PMC metadata node, agent 2"); + t50_ext_check(dt, true, scratch[0]); + } else if (is(s, "t6050-adopted") || is(s, "t6050-adopted-existing-pmc") || + is(s, "t6050-adopted-pmc-other-bus") || is(s, "t6050-adopted-pmc-nested-bus") || + is(s, "t6050-adopted-no-status")) { + bool nested = is(s, "t6050-adopted-pmc-nested-bus"); + check(status && !strcmp(status, "refused"), "/chosen/" T50_STATUS " = \"refused\""); + check(!fdt_getprop(dt, dcp, "apple,firmware-version", NULL) && + !fdt_getprop(dt, dcp, "apple,bw-scratch", NULL) && + !fdt_getprop(dt, dcp, "memory-region", NULL), + "the internal dcp gets nothing: the kernel adopts it"); + t50_ext_check(dt, true, + t50_pmc_check(dt, + is(s, "t6050-adopted-pmc-other-bus") + ? "/bus@200000000/" T50_PMC_NAME + : T50_PMC_PATH, + nested ? 2 : 1)); + if (nested) { + int stale = fdt_path_offset(dt, "/bus@300000000/bus@0/" T50_PMC_NAME); + check(stale >= 0 && !fdt_get_phandle(dt, stale), + "the translated PMC metadata node is left as it was, without a phandle"); + } + } else { + check(status && !strcmp(status, "refused"), "/chosen/" T50_STATUS " = \"refused\""); + t50_unchanged_check(in, dt); + } + printf("%s: %s\n", s, failures ? "FAIL" : "pass"); + return failures ? 1 : 0; +} diff --git a/tests/t8122_display_host.c b/tests/t8122_display_host.c index d8d1c9e95..b3eea4719 100644 --- a/tests/t8122_display_host.c +++ b/tests/t8122_display_host.c @@ -58,7 +58,7 @@ u32 chip_id; volatile enum exc_guard_t exc_guard; volatile int exc_count; struct fw_version_info os_firmware = {V14_7, "14.7", {14, 7, 0}, 3, "iBoot-10151.140.19.700.2"}; -const struct fw_version_info fw_versions[V27_2 + 1] = { +const struct fw_version_info fw_versions[V27_3B + 1] = { [V14_7] = {V14_7, "14.7", {14, 7, 0}, 3, "iBoot"}, [V26_6_2] = {V26_6_2, "26.6.2", {26, 6, 2}, 3, "mBoot-18000.161.10"}, [V27_2] = {V27_2, "27.2", {27, 2, 0}, 3, "mBoot-20457.41.3"}, diff --git a/tests/t8122_display_host/firmware.h b/tests/t8122_display_host/firmware.h index a8dd1517f..8afa60244 100644 --- a/tests/t8122_display_host/firmware.h +++ b/tests/t8122_display_host/firmware.h @@ -13,6 +13,7 @@ enum fw_version { V26_7 = 103, V27_0 = 104, V27_2 = 105, + V27_3B = 106, }; struct fw_version_info { enum fw_version version;