From b3b52c0c545ba823ef87b5b2d485b83a1b04d425 Mon Sep 17 00:00:00 2001 From: Sean Dolbec Date: Sat, 7 Nov 2026 15:57:49 -0500 Subject: [PATCH 1/5] kboot: identify a live J773g on 26.6.2 together with its OS tree The J773g admissions that follow were checked against one J773g ADT, that of macOS 26.6.2: target-type J773gAP, board-id 0x2a, chip-id 0x8132 and iBoot mBoot-18000.161.10. Add kboot_is_j773g(), which is true only when the live ADT, the OS firmware and the OS tree all match that: the root compatible J773gAP, board-id 0x2a, os_firmware 26.6.2, and an OS tree that is both apple,j773g and apple,t8132. A J713 tree on a Mac mini, a Mac mini on 26.7, or any other T8132 board fails it. It goes in a new kboot_t8132.c, which the T8132 rules that follow share: kboot.c's code is linked into Stage 1's .init slot (aura-raw.ld), which has 96 bytes left in the GCC build. The host test breaks each of those facts in turn. Booted six times on one J773g (26.6.2, Stage 1 1.0.0b8), loaded into RAM through the Stage 1 proxy: each time the gate admitted the machine (the USB3 calibration copy that uses it later in this series ran). A J713 or a non-26.6.2 boot was not run. Assisted-by: LLM Signed-off-by: Sean Dolbec --- Makefile | 2 +- src/kboot.h | 3 ++ src/kboot_t8132.c | 25 +++++++++++ tests/python/test_j773g_board_gate.py | 61 +++++++++++++++++++++++++++ 4 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 src/kboot_t8132.c create mode 100644 tests/python/test_j773g_board_gate.py diff --git a/Makefile b/Makefile index 2bd9bdfb3..36d13abf5 100644 --- a/Makefile +++ b/Makefile @@ -258,7 +258,7 @@ OBJECTS := \ isp.o \ j873.o \ kboot.o kboot_atc.o kboot_audio.o kboot_mte.o kboot_gpu_t8122.o kboot_gpu_t8122_power.o kboot_pmp_t8122.o \ - kboot_t6020_compat.o \ + kboot_t6020_compat.o kboot_t8132.o \ kboot_display_handoff.o kboot_display_facts.o kboot_gpu26.o kboot_gpu_t6031.o kboot_t6031.o \ main.o boot_options.o \ mitigations.o \ diff --git a/src/kboot.h b/src/kboot.h index f9a1d46af..be9ce1f4c 100644 --- a/src/kboot.h +++ b/src/kboot.h @@ -35,6 +35,9 @@ int kboot_boot(void *kernel); /* Reserve the DMA a USB controller that could not be stopped keeps (main.c, after USB shutdown). */ int kboot_reserve_usb_dma(void); +/* True only when the live J773g on 26.6.2 boots an OS tree that describes it. */ +bool kboot_is_j773g(const void *fdt); + /* Boot-args RAM range and boot framebuffer base, for the kboot_* SoC helpers */ u64 kboot_ram_base(void); u64 kboot_ram_size(void); diff --git a/src/kboot_t8132.c b/src/kboot_t8132.c new file mode 100644 index 000000000..2c2aa20cf --- /dev/null +++ b/src/kboot_t8132.c @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: MIT */ +/* + * T8132 (M4) board rules. They live here, not in kboot.c: kboot.c's code is linked into Stage 1's + * .init slot (aura-raw.ld), which has almost no room left. + */ + +#include "kboot.h" +#include "adt.h" +#include "firmware.h" +#include "soc.h" +#include "utils.h" + +#include "libfdt/libfdt.h" + +/* + * J773g (Mac mini, M4): the J773g admissions in this tree were checked against one ADT, that + * of 26.6.2 (target J773gAP, board-id 0x2a, iBoot mBoot-18000.161.10). Admit them only when + * the live machine, its firmware and the OS tree all say J773g. + */ +bool kboot_is_j773g(const void *fdt) +{ + return fdt && chip_id == T8132 && board_id == 0x2a && adt_is_compatible(adt, 0, "J773gAP") && + os_firmware.version == V26_6_2 && !fdt_node_check_compatible(fdt, 0, "apple,j773g") && + !fdt_node_check_compatible(fdt, 0, "apple,t8132"); +} diff --git a/tests/python/test_j773g_board_gate.py b/tests/python/test_j773g_board_gate.py new file mode 100644 index 000000000..70dad0a89 --- /dev/null +++ b/tests/python/test_j773g_board_gate.py @@ -0,0 +1,61 @@ +# SPDX-License-Identifier: GPL-2.0-only +"""Admit J773g only when the live machine, its firmware and the OS tree all say so.""" +from pathlib import Path +import subprocess + +from test_j713_dapf_instance import block + + +def test_j773g_board_gate(tmp_path): + repo = Path(__file__).resolve().parents[2] + production = block((repo / "src/kboot_t8132.c").read_text(), "bool kboot_is_j773g(") + # Each case breaks one fact used by the J773g gate: target J773gAP, board-id 42, chip-id + # 0x8132, OS firmware 26.6.2, or the OS tree. + harness = r''' +#include +#include +#include +#include +#define T8132 0x8132 +enum fw_version { V_UNKNOWN, V26_6, V26_6_2, V26_7 }; +static struct { enum fw_version version; } os_firmware; +static unsigned chip_id, board_id; +static void *adt = (void *)1; +static const char *live, *board, *soc; +static bool adt_is_compatible(const void *tree, int node, const char *compatible) +{ + return tree == adt && node == 0 && !strcmp(compatible, live); +} +static int fdt_node_check_compatible(const void *fdt, int node, const char *compatible) +{ + assert(fdt && node == 0); + return strcmp(compatible, board) && strcmp(compatible, soc); +} +static void j773g(void) +{ + chip_id = T8132; board_id = 0x2a; os_firmware.version = V26_6_2; + live = "J773gAP"; board = "apple,j773g"; soc = "apple,t8132"; +} +''' + production + r''' +int main(void) +{ + static char tree; + j773g(); assert(kboot_is_j773g(&tree)); + assert(!kboot_is_j773g(NULL)); + j773g(); chip_id = 0x8122; assert(!kboot_is_j773g(&tree)); + j773g(); board_id = 0x2c; assert(!kboot_is_j773g(&tree)); + j773g(); live = "J713AP"; assert(!kboot_is_j773g(&tree)); + j773g(); board = "apple,j713"; assert(!kboot_is_j773g(&tree)); /* wrong OS tree */ + j773g(); soc = "apple,t8122"; assert(!kboot_is_j773g(&tree)); + j773g(); os_firmware.version = V26_6; assert(!kboot_is_j773g(&tree)); + j773g(); os_firmware.version = V26_7; assert(!kboot_is_j773g(&tree)); + j773g(); os_firmware.version = V_UNKNOWN; assert(!kboot_is_j773g(&tree)); + return 0; +} +''' + source = tmp_path / "j773g-board.c" + source.write_text(harness) + binary = tmp_path / "j773g-board" + subprocess.run(["cc", "-std=gnu11", "-Wall", "-Wextra", "-Werror", "-Wno-unused-parameter", + str(source), "-o", str(binary)], check=True) + subprocess.run([str(binary)], check=True) From b350362517968378ef354f4a3621dbe23ff4ddc7 Mon Sep 17 00:00:00 2001 From: Sean Dolbec Date: Thu, 12 Nov 2026 11:29:34 -0500 Subject: [PATCH 2/5] kboot: disable the T8132 AOP on boards without a qualified handoff dt_set_t8132_aop() returned early on every T8132 board but the J713 and the J604 and left the OS tree's AOP node as it found it. The shared M4 trees (t8132-jxxx.dtsi, so the J623, J624 and J773g) enable the AOP, its DART and its mailbox, and ask for its handoff in linux-enablement-mac,dapf-handoff, on the promise that the loader "programs the AOP DART's DAPF and reserves its firmware and DAPF windows ... or disables the AOP". On those boards aura did neither, so Linux started an AOP whose DAPF was empty and whose __ETEXT and __OS_LOG were not reserved. Disable the AOP there, as the J713 and J604 path already does on any failure, without reading the AOP or programming its DART. The J713 and J604 path is unchanged. The new host test runs the production gate on J713 and J604 trees (handoff, every refused step, a running AOP, no request) and on J623, J624, J715 and J773g trees with and without the request: the AOP ends disabled and nothing touches it. The shared source DTS enables the AOP, but the shipped 26.6.2 J773g OS DT used for the normal boots has it disabled; the TEST-DTB boot changed that node to `okay` and observed it return `disabled`. Booted on one J773g (26.6.2) with a test tree that enables the AOP: Linux received the AOP disabled and its DART as the tree had it. Not booted on the J623, J624 or J715. Assisted-by: LLM Signed-off-by: Sean Dolbec --- src/kboot.c | 9 ++- tests/python/test_t8132_aop_gate.py | 104 ++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+), 3 deletions(-) create mode 100644 tests/python/test_t8132_aop_gate.py diff --git a/src/kboot.c b/src/kboot.c index 8d11319bd..bf70d90be 100644 --- a/src/kboot.c +++ b/src/kboot.c @@ -9019,7 +9019,8 @@ static int dt_reserve_t8132_aop_windows(const char *path) * DAPF, then reserve both segments at the IOVAs the firmware uses (their remap * addresses: EC0p for __ETEXT, the physical address for __OS_LOG) and the * DAPF windows. Without all of it the firmware cannot run, so on any failure - * the AOP is disabled. + * the AOP is disabled. No other M4 board's AOP handoff is qualified: there the + * AOP is disabled too, without touching it or its DART. */ static int dt_set_t8132_aop(const char *path) { @@ -9027,8 +9028,10 @@ static int dt_set_t8132_aop(const char *path) int node; if (fdt_node_check_compatible(dt, 0, "apple,j713") && - fdt_node_check_compatible(dt, 0, "apple,j604")) - return 0; /* No other M4 board's AOP handoff is qualified. */ + fdt_node_check_compatible(dt, 0, "apple,j604")) { + why = "no handoff is qualified for this board"; + goto disable; + } int chosen = fdt_path_offset(dt, "/chosen"); if (chosen < 0 || diff --git a/tests/python/test_t8132_aop_gate.py b/tests/python/test_t8132_aop_gate.py new file mode 100644 index 000000000..38577ab0c --- /dev/null +++ b/tests/python/test_t8132_aop_gate.py @@ -0,0 +1,104 @@ +# SPDX-License-Identifier: GPL-2.0-only +"""Run the production T8132 AOP handoff gate on J713, J604 and boards it does not qualify.""" +from pathlib import Path + +from test_j713_dapf_instance import block +from test_siliconforest_handoff import run_c + +ROOT = Path(__file__).resolve().parents[2] + +# What can go wrong: an unqualified board keeps an enabled AOP that no loader handed over +# (the OS then starts it without its DAPF or its DRAM segments); the gate touches the AOP +# or its DART on a board it does not qualify; a J713 or J604 refusal leaves it enabled. +HARNESS = r''' +#include +#include +#include +#include +#include +#include "libfdt.h" +typedef uint32_t u32; +typedef unsigned long u64; +typedef struct { int unused; } asc_dev_t; +#define bail(...) do { printf(__VA_ARGS__); return -1; } while (0) +static void *dt; +static asc_dev_t the_asc; +static int touched, fail; +static bool running; +static asc_dev_t *asc_init(const char *path) +{ assert(!strcmp(path, "/arm-io/aop")); touched++; return fail == 1 ? NULL : &the_asc; } +static bool asc_cpu_running(asc_dev_t *asc) { return running; } +static void asc_free(asc_dev_t *asc) {} +static int dapf_init_t8132_halted(const char *path, int index) +{ assert(!strcmp(path, "/arm-io/dart-aop") && index == 1); touched++; return fail == 2 ? -1 : 0; } +static int dt_reserve_asc_segments(const char *adt_path, const char *alt, const char *path, + bool remap, u64 base, bool dram_only) +{ assert(!strcmp(adt_path, "/arm-io/aop/iop-aop-nub") && remap && dram_only); touched++; + return fail == 3 ? -1 : 0; } +static int dt_reserve_t8132_aop_windows(const char *path) { touched++; return fail == 4 ? -1 : 0; } +''' + +MAIN = r''' +static unsigned char blob[4096]; +static void tree(const char *board, bool requested) +{ + char compatible[64]; + int len = snprintf(compatible, sizeof(compatible), "%s%c%s", board, 0, "apple,t8132") + 1; + dt = blob; + assert(!fdt_create_empty_tree(dt, sizeof(blob))); + assert(!fdt_setprop(dt, 0, "compatible", compatible, len)); + int chosen = fdt_add_subnode(dt, 0, "chosen"); + if (requested) + assert(!fdt_setprop(dt, chosen, "linux-enablement-mac,dapf-handoff", + "/arm-io/aop\0/arm-io/pmp", sizeof("/arm-io/aop\0/arm-io/pmp"))); + int aop = fdt_add_subnode(dt, 0, "aop@390600000"); + assert(aop >= 0 && !fdt_setprop_string(dt, aop, "compatible", "apple,t8132-aop")); + assert(!fdt_setprop_string(dt, aop, "status", "okay")); + touched = fail = 0; + running = false; +} +static const char *status(void) +{ + return fdt_getprop(dt, fdt_path_offset(dt, "/aop@390600000"), "status", NULL); +} +int main(void) +{ + /* J713 and J604: a requested, halted AOP is handed over; any failed step disables it. */ + static const char *const qualified[] = {"apple,j713", "apple,j604"}; + for (unsigned i = 0; i < sizeof(qualified) / sizeof(*qualified); i++) { + tree(qualified[i], true); + assert(!dt_set_t8132_aop("/aop@390600000") && !strcmp(status(), "okay") && touched == 4); + for (int f = 1; f <= 4; f++) { + tree(qualified[i], true); + fail = f; + assert(!dt_set_t8132_aop("/aop@390600000") && !strcmp(status(), "disabled")); + } + tree(qualified[i], true); + running = true; + assert(!dt_set_t8132_aop("/aop@390600000") && !strcmp(status(), "disabled") && touched == 1); + tree(qualified[i], false); + assert(!dt_set_t8132_aop("/aop@390600000") && !strcmp(status(), "disabled") && !touched); + } + /* Other T8132 boards: the AOP ends disabled and neither it nor its DART is touched, + * whether or not the tree asks for the handoff. */ + static const char *const others[] = {"apple,j623", "apple,j624", "apple,j715", + "apple,j773g"}; + for (unsigned i = 0; i < sizeof(others) / sizeof(*others); i++) + for (int requested = 0; requested <= 1; requested++) { + tree(others[i], requested); + assert(!dt_set_t8132_aop("/aop@390600000")); + assert(!strcmp(status(), "disabled") && !touched); + } + return 0; +} +''' + + +def production(): + kboot = (ROOT / "src/kboot.c").read_text() + return block(kboot, "static int dt_set_t8132_aop(") + "\n" + + +def test_t8132_aop_gate(tmp_path): + run_c(tmp_path, "t8132-aop-gate", + HARNESS + production() + MAIN) From c53ae6bc2c22876eb51aa07056a9b66f3984ba34 Mon Sep 17 00:00:00 2001 From: Sean Dolbec Date: Sat, 7 Nov 2026 16:01:04 -0500 Subject: [PATCH 3/5] kboot: keep the T8132 ISP disabled on a Mac whose ADT has no camera The J773g (Mac mini) has no camera: its 26.6.2 ADT has no isp, isp0 or dart-isp node. t8132.dtsi describes the ISP and its three DARTs disabled and the J773g tree leaves them so, but nothing in aura held that: the J713 handoff only runs on the J713, and dt_set_isp() acts only through an "isp" alias. A tree that enabled the ISP would have the OS probe a camera and ISP power domains that are not there. On T8132, when the ADT has neither isp nor isp0, disable every enabled apple,t8132-isp node and the DARTs in its iommus list that no other node uses. A tree that already leaves the ISP disabled is not changed, and a Mac whose ADT has an ISP (the J713) is not touched. The rule goes in kboot_t8132.c, out of Stage 1's full .init slot. It runs before dt_set_isp(). On such a Mac that step cannot reserve the ISP firmware and disables the node the isp alias names, but not its DARTs; run after it, the rule would find the ISP already disabled and leave those DARTs enabled. The host tests cover an enabled ISP, a disabled one, a DART shared with another device, a malformed iommus list, a Mac with isp or isp0 in its ADT, and another SoC. A second test runs the real dt_set_isp() and the rule in kboot_prepare_dt()'s order. Booted on one J773g (26.6.2) with a test tree that adds an enabled ISP over three DARTs, one of them also used by another node: Linux received the ISP and its two unshared DARTs disabled and the shared DART enabled. The shipped 26.6.2 J773g OS DT used for normal boots has no ISP node; the TEST-DTB boot added an enabled one. Assisted-by: LLM Signed-off-by: Sean Dolbec --- src/kboot.c | 6 + src/kboot.h | 3 + src/kboot_t8132.c | 64 ++++++++++ tests/python/test_t8132_isp_absent.py | 177 ++++++++++++++++++++++++++ 4 files changed, 250 insertions(+) create mode 100644 tests/python/test_t8132_isp_absent.py diff --git a/src/kboot.c b/src/kboot.c index bf70d90be..85af98c88 100644 --- a/src/kboot.c +++ b/src/kboot.c @@ -11455,6 +11455,12 @@ int kboot_prepare_dt(void *fdt) return -1; if (dt_set_aop_firmware()) return -1; + /* + * Before dt_set_isp(): on a Mac with no ISP in its ADT that disables the ISP but not its + * DARTs, and this rule leaves an ISP that is already disabled as it is. + */ + if (dt_disable_t8132_absent_isp(dt)) + return -1; if (dt_set_isp()) return -1; dt_set_j713_isp(); diff --git a/src/kboot.h b/src/kboot.h index be9ce1f4c..cdeaf181d 100644 --- a/src/kboot.h +++ b/src/kboot.h @@ -38,6 +38,9 @@ int kboot_reserve_usb_dma(void); /* True only when the live J773g on 26.6.2 boots an OS tree that describes it. */ bool kboot_is_j773g(const void *fdt); +/* Disable the ISP and the DARTs only it uses on a T8132 Mac whose ADT has no camera. */ +int dt_disable_t8132_absent_isp(void *dt); + /* Boot-args RAM range and boot framebuffer base, for the kboot_* SoC helpers */ u64 kboot_ram_base(void); u64 kboot_ram_size(void); diff --git a/src/kboot_t8132.c b/src/kboot_t8132.c index 2c2aa20cf..e4e4d3c98 100644 --- a/src/kboot_t8132.c +++ b/src/kboot_t8132.c @@ -12,6 +12,12 @@ #include "libfdt/libfdt.h" +#define bail(...) \ + do { \ + printf(__VA_ARGS__); \ + return -1; \ + } while (0) + /* * J773g (Mac mini, M4): the J773g admissions in this tree were checked against one ADT, that * of 26.6.2 (target J773gAP, board-id 0x2a, iBoot mBoot-18000.161.10). Admit them only when @@ -23,3 +29,61 @@ bool kboot_is_j773g(const void *fdt) os_firmware.version == V26_6_2 && !fdt_node_check_compatible(fdt, 0, "apple,j773g") && !fdt_node_check_compatible(fdt, 0, "apple,t8132"); } + +/* Whether a node other than skip names the IOMMU phandle in its iommus list. */ +static bool dt_iommu_shared(const void *dt, u32 phandle, int skip) +{ + int node; + + for (node = fdt_next_node(dt, -1, NULL); node >= 0; node = fdt_next_node(dt, node, NULL)) { + int len; + const fdt32_t *iommus = node == skip ? NULL : fdt_getprop(dt, node, "iommus", &len); + + for (int i = 0; iommus && i + 1 < len / (int)sizeof(*iommus); i += 2) + if (fdt32_ld(&iommus[i]) == phandle) + return true; + } + return false; +} + +/* + * A T8132 Mac without a camera (the J773g) has no isp or isp0 in its ADT. A tree that enables + * the ISP there would have the OS probe a camera and power domains that do not exist: disable + * the ISP and the DARTs that only it uses. A tree that leaves it disabled is not changed. + */ +int dt_disable_t8132_absent_isp(void *dt) +{ + if (chip_id != T8132 || adt_path_offset(adt, "/arm-io/isp") >= 0 || + adt_path_offset(adt, "/arm-io/isp0") >= 0) + return 0; + + int isp = -1; + while ((isp = fdt_node_offset_by_compatible(dt, isp, "apple,t8132-isp")) >= 0) { + const char *status = fdt_getprop(dt, isp, "status", NULL); + if (status && !strcmp(status, "disabled")) + continue; + + /* One cell of stream ID per DART, as in t8132.dtsi. Decide before any write. */ + u32 darts[8]; + bool own[8]; + int len, count = 0; + const fdt32_t *iommus = fdt_getprop(dt, isp, "iommus", &len); + int cells = iommus && len > 0 && !(len % sizeof(*iommus)) ? len / sizeof(*iommus) : 0; + if (!(cells % 2) && cells / 2 <= (int)ARRAY_SIZE(darts)) + for (; count < cells / 2; count++) { + darts[count] = fdt32_ld(&iommus[2 * count]); + own[count] = !dt_iommu_shared(dt, darts[count], isp); + } + + if (fdt_setprop_string(dt, isp, "status", "disabled")) + bail("FDT: cannot disable the T8132 ISP\n"); + for (int i = 0; i < count; i++) { + int dart = own[i] ? fdt_node_offset_by_phandle(dt, darts[i]) : -1; + if (dart >= 0 && fdt_setprop_string(dt, dart, "status", "disabled")) + bail("FDT: cannot disable a T8132 ISP DART\n"); + } + printf("FDT: no ISP in the ADT; T8132 ISP disabled with the DARTs only it uses\n"); + isp = -1; /* Offsets moved; start over. Disabled nodes are skipped. */ + } + return 0; +} diff --git a/tests/python/test_t8132_isp_absent.py b/tests/python/test_t8132_isp_absent.py new file mode 100644 index 000000000..f7e40ff83 --- /dev/null +++ b/tests/python/test_t8132_isp_absent.py @@ -0,0 +1,177 @@ +# SPDX-License-Identifier: GPL-2.0-only +"""Run the production T8132 rule for a machine whose ADT has no camera (the J773g).""" +from pathlib import Path + +from test_j713_dapf_instance import block +from test_siliconforest_handoff import run_c + +ROOT = Path(__file__).resolve().parents[2] + +# What can go wrong: a tree that enables the T8132 ISP or its DARTs on a Mac with no ISP in +# its ADT (the J773g has none) makes the OS probe a camera and power domains that are not +# there; the rule touches a machine that does have an ISP, or another SoC; it disables a +# DART that another device shares; a malformed iommus list stops the boot; an earlier +# handoff step disables the ISP first, so the rule skips it and leaves its DARTs enabled. +TREE = r''' +static unsigned char blob[4096]; +static void tree(bool enabled, bool shared) +{ + dt = blob; + assert(!fdt_create_empty_tree(dt, sizeof(blob))); + int aliases = fdt_add_subnode(dt, 0, "aliases"); + assert(aliases >= 0 && !fdt_setprop_string(dt, aliases, "isp", "/isp@48c000000")); + static const char *const names[] = {"iommu@48e8c0000", "iommu@48e8e0000", "iommu@48e900000"}; + for (int i = 0; i < 3; i++) { + int dart = fdt_add_subnode(dt, 0, names[i]); + assert(dart >= 0 && !fdt_setprop_u32(dt, dart, "phandle", 10 + i)); + assert(!fdt_setprop_u32(dt, dart, "#iommu-cells", 1)); + } + int isp = fdt_add_subnode(dt, 0, "isp@48c000000"); + assert(isp >= 0 && !fdt_setprop(dt, isp, "compatible", "apple,t8132-isp\0apple,isp", + sizeof("apple,t8132-isp\0apple,isp"))); + fdt32_t iommus[] = {cpu_to_fdt32(10), 0, cpu_to_fdt32(11), 0, cpu_to_fdt32(12), 0}; + assert(!fdt_setprop(dt, isp, "iommus", iommus, sizeof(iommus))); + if (!enabled) + assert(!fdt_setprop_string(dt, isp, "status", "disabled")); + int other = fdt_add_subnode(dt, 0, "other@0"); + assert(other >= 0); + if (shared) { + fdt32_t ref[] = {cpu_to_fdt32(12), cpu_to_fdt32(1)}; + assert(!fdt_setprop(dt, other, "iommus", ref, sizeof(ref))); + } +} +static const char *status(const char *path) +{ + const char *s = fdt_getprop(dt, fdt_path_offset(dt, path), "status", NULL); + return s ? s : "okay"; +} +static bool off(const char *path) { return !strcmp(status(path), "disabled"); } +''' + +MAIN = TREE + r''' +int main(void) +{ + /* No ISP in the ADT: the ISP and its three DARTs end disabled. */ + tree(true, false); + assert(!dt_disable_t8132_absent_isp(dt)); + assert(off("/isp@48c000000") && off("/iommu@48e8c0000") && off("/iommu@48e8e0000") && + off("/iommu@48e900000") && !off("/other@0")); + /* A tree that already leaves it disabled is left exactly as it is. */ + tree(false, false); + unsigned char before[sizeof(blob)]; + memcpy(before, blob, sizeof(blob)); + assert(!dt_disable_t8132_absent_isp(dt) && !memcmp(before, blob, sizeof(blob))); + /* A DART another device also uses stays as it is. */ + tree(true, true); + assert(!dt_disable_t8132_absent_isp(dt)); + assert(off("/isp@48c000000") && off("/iommu@48e8c0000") && off("/iommu@48e8e0000") && + !off("/iommu@48e900000")); + /* A broken iommus list still leaves the ISP disabled. */ + tree(true, false); + assert(!fdt_setprop(dt, fdt_path_offset(dt, "/isp@48c000000"), "iommus", "\0\0\0\x63\0", 5)); + assert(!dt_disable_t8132_absent_isp(dt) && off("/isp@48c000000")); + assert(!off("/iommu@48e8c0000")); + /* A machine with an ISP (the J713), or another SoC, is not touched. */ + for (int c = 0; c < 3; c++) { + tree(true, false); + memcpy(before, blob, sizeof(blob)); + adt_isp = c == 0; adt_isp0 = c == 1; chip_id = c == 2 ? 0x8122 : T8132; + assert(!dt_disable_t8132_absent_isp(dt) && !memcmp(before, blob, sizeof(blob))); + adt_isp = adt_isp0 = false; chip_id = T8132; + } + return 0; +} +''' + + +HEADER = r''' +#include +#include +#include +#include +#include +#include "libfdt.h" +typedef uint32_t u32; +#define T8132 0x8132 +#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) +#define bail(...) do { printf(__VA_ARGS__); return -1; } while (0) +static void *dt, *adt; +static u32 chip_id = T8132; +static bool adt_isp, adt_isp0; +static int adt_path_offset(const void *tree, const char *path) +{ + if (!strcmp(path, "/arm-io/isp")) return adt_isp ? 1 : -1; + if (!strcmp(path, "/arm-io/isp0")) return adt_isp0 ? 2 : -1; + return -1; +} +''' + + +def rule(): + kboot = (ROOT / "src/kboot_t8132.c").read_text() + return (block(kboot, "static bool dt_iommu_shared(") + "\n" + + block(kboot, "int dt_disable_t8132_absent_isp(") + "\n") + + +def test_t8132_isp_absent(tmp_path): + run_c(tmp_path, "t8132-isp-absent", HEADER + rule() + MAIN) + + +# kboot_prepare_dt() runs the generic dt_set_isp() too. On a Mac with no ISP in its ADT it +# cannot reserve the ISP firmware and disables the node the isp alias names. Run the real +# dt_set_isp() and the real call sequence: the rule must still disable the DARTs only the +# ISP uses, and a machine with an ISP must still reach the generic step. +ORDER = r''' +#define T6040 0x6040 +#define T6050 0x6050 +#define T8140 0x8140 +#define T8142 0x8142 +typedef unsigned long u64; +static u32 board_id; +static int generic_ran; +static bool adt_is_compatible(const void *tree, int node, const char *c) { return false; } +static int dt_t6050_isp_transaction(void) { return -1; } +static int isp_get_heap(u64 *phys, u64 *iova, u64 *size) { return -1; } +static u64 isp_iova_base(void) { return 0; } +static int dt_set_isp_fwdata(void) { return 0; } +/* As dt_reserve_asc_segments_at(): no ADT node, no reservation. */ +static int dt_reserve_asc_firmware(const char *adt_path, const char *adt_path_alt, + const char *fdt_path, bool remap, u64 base) +{ + generic_ran++; + return adt_path_offset(adt, adt_path) < 0 && adt_path_offset(adt, adt_path_alt) < 0 ? -1 : 0; +} +static void dt_set_j713_isp(void) {} +''' + + +def test_t8132_isp_absent_in_handoff_order(tmp_path): + kboot = (ROOT / "src/kboot.c").read_text() + prepare = block(kboot, "int kboot_prepare_dt(") + start = prepare.index(" if (dt_set_aop_firmware())\n return -1;\n") + start = prepare.index("\n", prepare.index("return -1;", start)) + 1 + steps = prepare[start:prepare.index(" if (dt_set_pmgr())", start)] + assert "dt_set_isp()" in steps and "dt_disable_t8132_absent_isp(dt)" in steps + run_c(tmp_path, "t8132-isp-absent-order", HEADER + rule() + ORDER + + block(kboot, "static int dt_set_isp(void)") + TREE + + "static int handoff(void)\n{\n" + steps + " return 0;\n}\n" + r''' +int main(void) +{ + /* No ISP in the ADT: whichever step disables the ISP, its DARTs end disabled. */ + tree(true, false); + assert(!handoff() && generic_ran == 1); + assert(off("/isp@48c000000") && off("/iommu@48e8c0000") && off("/iommu@48e8e0000") && + off("/iommu@48e900000") && !off("/other@0")); + /* A DART another device also uses stays as it is. */ + tree(true, true); + assert(!handoff()); + assert(off("/iommu@48e8c0000") && off("/iommu@48e8e0000") && !off("/iommu@48e900000")); + /* With an ISP in the ADT the rule does nothing and the generic step reserves it. */ + adt_isp = true; + tree(true, false); + generic_ran = 0; + assert(!handoff() && generic_ran == 1); + assert(!off("/isp@48c000000") && !off("/iommu@48e8c0000")); + return 0; +} +''') From 24812c554030b8eb7b45d13570f0e6df2bfd32ed Mon Sep 17 00:00:00 2001 From: Sean Dolbec Date: Sat, 7 Nov 2026 16:05:20 -0500 Subject: [PATCH 4/5] kboot_atc: copy the T8132 USB3 calibration on the J773g The T8132 USB3 bundle (apple,tunable-usb3-*, the lane groups and the optional AUX group) was copied only for the J713 and the J604. On every other T8132 board the T8132 PHY nodes fell through to the older t8122 tunable path, whose properties the T8132 PHY driver does not read. The J773g's 26.6.2 ADT has all 27 groups of the bundle and tunable_AUX_TOP on each of atc-phy0..3 (compatible atc-phy,t8132), and every record is a 32-bit write inside its group's window. Most groups are byte for byte the J713's; the AUSPLL core, CIO3 PLL core, AUSCMN SHM and both lanes' RX EQ groups are the machine's own. The J773g tree describes atcphy0..3 as apple,t8132-atcphy with aliases. Copy the bundle on a live J773g on 26.6.2 too. The copy is unchanged: a missing or malformed required group still removes the whole bundle and leaves USB2. This only fills properties: whether a port runs USB3 stays the tree's choice. The existing J713 fixture exercises the T8132 USB3 copy and rejection path. There is no J773g fixture: J773g-specific calibration data is not covered by a host test. Booted six times on one J773g (26.6.2, Stage 1 1.0.0b8): the tree Linux received carried the bundle (seven apple,tunable-usb3-* properties) on each of atcphy0..3. USB3 link speed was not tested. Assisted-by: LLM Signed-off-by: Sean Dolbec --- src/kboot_atc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/kboot_atc.c b/src/kboot_atc.c index a8ab9d945..e571e1baf 100644 --- a/src/kboot_atc.c +++ b/src/kboot_atc.c @@ -5,6 +5,7 @@ #include "kboot_atc.h" #include "adt.h" #include "devicetree.h" +#include "kboot.h" #include "malloc.h" #include "pmgr.h" #include "utils.h" @@ -872,9 +873,10 @@ static void dt_copy_atc_tunables(void *dt, const char *adt_path, const char *dt_ if (adt_node < 0) return; + /* The J773g's 26.6.2 ADT has every group of this bundle on all four PHYs. */ if (chip_id == T8132 && (!fdt_node_check_compatible(dt, 0, "apple,j713") || - !fdt_node_check_compatible(dt, 0, "apple,j604")) && + !fdt_node_check_compatible(dt, 0, "apple,j604") || kboot_is_j773g(dt)) && !fdt_node_check_compatible(dt, fdt_node, "apple,t8132-atcphy") && adt_is_compatible_at(adt, adt_node, "atc-phy,t8132", 0)) { dt_copy_t8132_usb3_tunables(dt, adt_node, fdt_node); From 35c896e9e39b3d0ed6d16fde8b317186fd334da0 Mon Sep 17 00:00:00 2001 From: Diljit Singh Date: Thu, 19 Nov 2026 01:54:42 -0500 Subject: [PATCH 5/5] kboot: hand the J773g's AOP over to the OS The J773g tree states the same AOP handoff contract as the J713 (linux-enablement-mac,dapf-handoff lists /arm-io/aop), and its 26.6.2 ADT has the same AOP, DART and firmware segment layout. But only the J713 and J604 were qualified, so the Mac mini's AOP ended disabled. Its headphone jack's audio runs on the AOP (the M4 Pro Mac mini's does too), so the machine had no sound card. Qualify a live J773g (kboot_is_j773g()) as well. The host test now runs the J773g through the qualified path, every refusal included, and a J773g tree on any other machine still ends disabled and untouched. Signed-off-by: Diljit Singh --- src/kboot.c | 6 +++++- tests/python/test_t8132_aop_gate.py | 15 +++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/kboot.c b/src/kboot.c index 85af98c88..8aa11d9ba 100644 --- a/src/kboot.c +++ b/src/kboot.c @@ -9027,8 +9027,12 @@ static int dt_set_t8132_aop(const char *path) const char *why; int node; + /* + * The J773g (Mac mini) tree states the same handoff contract and its 26.6.2 ADT has the same + * AOP, DART and segment layout; its headphone jack's audio runs on the AOP. + */ if (fdt_node_check_compatible(dt, 0, "apple,j713") && - fdt_node_check_compatible(dt, 0, "apple,j604")) { + fdt_node_check_compatible(dt, 0, "apple,j604") && !kboot_is_j773g(dt)) { why = "no handoff is qualified for this board"; goto disable; } diff --git a/tests/python/test_t8132_aop_gate.py b/tests/python/test_t8132_aop_gate.py index 38577ab0c..458dcd865 100644 --- a/tests/python/test_t8132_aop_gate.py +++ b/tests/python/test_t8132_aop_gate.py @@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only -"""Run the production T8132 AOP handoff gate on J713, J604 and boards it does not qualify.""" +"""Run the production T8132 AOP handoff gate on J713, J604, J773g and boards it does not qualify.""" from pathlib import Path from test_j713_dapf_instance import block @@ -24,7 +24,10 @@ static void *dt; static asc_dev_t the_asc; static int touched, fail; -static bool running; +static bool running, live_j773g; +/* The live machine is a J773g on its qualified firmware and the tree says so. */ +static bool kboot_is_j773g(const void *fdt) +{ return live_j773g && !fdt_node_check_compatible(fdt, 0, "apple,j773g"); } static asc_dev_t *asc_init(const char *path) { assert(!strcmp(path, "/arm-io/aop")); touched++; return fail == 1 ? NULL : &the_asc; } static bool asc_cpu_running(asc_dev_t *asc) { return running; } @@ -56,6 +59,7 @@ assert(!fdt_setprop_string(dt, aop, "status", "okay")); touched = fail = 0; running = false; + live_j773g = !strcmp(board, "apple,j773g"); } static const char *status(void) { @@ -63,8 +67,9 @@ } int main(void) { - /* J713 and J604: a requested, halted AOP is handed over; any failed step disables it. */ - static const char *const qualified[] = {"apple,j713", "apple,j604"}; + /* J713, J604 and a live J773g: a requested, halted AOP is handed over; any failed step + * disables it. */ + static const char *const qualified[] = {"apple,j713", "apple,j604", "apple,j773g"}; for (unsigned i = 0; i < sizeof(qualified) / sizeof(*qualified); i++) { tree(qualified[i], true); assert(!dt_set_t8132_aop("/aop@390600000") && !strcmp(status(), "okay") && touched == 4); @@ -86,6 +91,8 @@ for (unsigned i = 0; i < sizeof(others) / sizeof(*others); i++) for (int requested = 0; requested <= 1; requested++) { tree(others[i], requested); + /* A J773g tree on any other machine or firmware is not qualified. */ + live_j773g = false; assert(!dt_set_t8132_aop("/aop@390600000")); assert(!strcmp(status(), "disabled") && !touched); }