Skip to content
Open
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
65 changes: 41 additions & 24 deletions src/kboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -9013,30 +9013,46 @@ static int dt_reserve_t8132_aop_windows(const char *path)
return 0;
}

/* dt_display_transaction has an integer-only callback; the handoff is single-threaded. */
static const char *t8132_aop_path;

/*
* Every FDT edit of the AOP handoff, then the one hardware write, last: the DAPF is programmed
* only once the segments and windows are reserved, and dapf_init_t8132_halted() puts every
* slice back if its own read-back fails. Run as a transaction, so a failure at any step leaves
* neither the tree nor the DAPF half done.
*/
static int dt_set_t8132_aop_one(unsigned int unused)
{
UNUSED(unused);
if (dt_reserve_asc_segments("/arm-io/aop/iop-aop-nub", NULL, t8132_aop_path, true, 0, true))
bail("FDT: %s: AOP firmware segments are not reserved\n", t8132_aop_path);
if (dt_reserve_t8132_aop_windows(t8132_aop_path))
bail("FDT: %s: AOP DAPF windows are not reserved\n", t8132_aop_path);
if (dapf_init_t8132_halted("/arm-io/dart-aop", 1))
bail("FDT: %s: AOP DAPF is not programmed\n", t8132_aop_path);
return 0;
}

/*
* J713 and J604: iBoot leaves the AOP halted, its DART's DAPF empty, its
* T8132: iBoot leaves the AOP halted, its DART's DAPF empty, its
* external code (__ETEXT) in DRAM at a fixed address and its log (__OS_LOG) at
* a new one every boot. When the OS asks for the AOP's handoff, program the
* 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.
* a new one every boot. When the OS asks for the AOP's handoff, 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, then
* program the DAPF. Without all of it the firmware cannot run, so on any
* failure the AOP is disabled. Nothing here depends on the board. A tree that
* does not ask for the handoff is left as it is.
*/
static int dt_set_t8132_aop(const char *path)
{
const char *why;
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. */

int chosen = fdt_path_offset(dt, "/chosen");
if (chosen < 0 ||
fdt_stringlist_search(dt, chosen, "linux-enablement-mac,dapf-handoff", "/arm-io/aop") < 0) {
why = "its handoff was not requested";
goto disable;
}
fdt_stringlist_search(dt, chosen, "linux-enablement-mac,dapf-handoff", "/arm-io/aop") < 0)
return 0;

asc_dev_t *asc = asc_init("/arm-io/aop");
if (!asc) {
Expand All @@ -9050,16 +9066,11 @@ static int dt_set_t8132_aop(const char *path)
goto disable;
}

if (dapf_init_t8132_halted("/arm-io/dart-aop", 1)) {
why = "its DAPF is not programmed";
goto disable;
}
if (dt_reserve_asc_segments("/arm-io/aop/iop-aop-nub", NULL, path, true, 0, true)) {
why = "its firmware segments are not reserved";
goto disable;
}
if (dt_reserve_t8132_aop_windows(path)) {
why = "its DAPF windows are not reserved";
t8132_aop_path = path;
int ret = dt_display_transaction(dt_set_t8132_aop_one, 0);
t8132_aop_path = NULL;
if (ret) {
why = "its handoff is incomplete";
goto disable;
}

Expand Down Expand Up @@ -11615,6 +11626,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))
printf("FDT: T8132 absent-ISP rule failed; the ISP nodes stay as the tree has them\n");
if (dt_set_isp())
return -1;
dt_set_j713_isp();
Expand Down
3 changes: 3 additions & 0 deletions src/kboot.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/* 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);
Expand Down
9 changes: 5 additions & 4 deletions src/kboot_atc.c
Original file line number Diff line number Diff line change
Expand Up @@ -872,10 +872,11 @@ static void dt_copy_atc_tunables(void *dt, const char *adt_path, const char *dt_
if (adt_node < 0)
return;

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, fdt_node, "apple,t8132-atcphy") &&
/*
* Any T8132 PHY, whatever the board: a PHY whose ADT node has the whole USB3 bundle gets
* it, one that lacks a group keeps its USB2 fallback.
*/
if (!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);
return;
Expand Down
74 changes: 74 additions & 0 deletions src/kboot_t8132.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/* SPDX-License-Identifier: MIT */
/*
* T8132 (M4) 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 "utils.h"

#include "libfdt/libfdt.h"

#define bail(...) \
do { \
printf(__VA_ARGS__); \
return -1; \
} while (0)

/* 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 (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;
Comment on lines +48 to +49

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Run the absence gate before generic ISP setup

On a camera-less T8132 with an isp alias and enabled ISP/DART nodes, kboot_prepare_dt() executes dt_set_isp() before this helper (src/kboot.c:11457–11460). The generic step fails to find either ADT ISP node and sets the ISP to disabled, so this early skip bypasses all DART cleanup and leaves the unused ISP DARTs enabled in the handed-off tree. Running both production steps in order reproduces an exclusively owned DART remaining okay; move the absence gate before generic ISP setup, or allow it to clean up DARTs when the preceding step disabled the ISP.

Useful? React with 👍 / 👎.


/* 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;
}
Loading
Loading