From e07097bd1ad8683e4583e1a455586895b3dfd086 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Thu, 19 Nov 2026 23:30:30 +1100 Subject: [PATCH] soc: apple: sep: pick the platform profile by SoC; the board DT decides select() matched T8122, T6040, T6041, T6050, T8132 and T8142 only together with a list of board compatibles, the boards whose ADTs had been read. Each new board on one of these SoCs needed a driver patch (J614s, J614c, J715, J716c, K116s, J813, and K114s in review), although nothing the driver reads from these profiles is board-specific: - shared-memory geometry, handoff, key-store dialect and keybag encoding follow the SoC's sepOS; - the DART window and the wide DMA mask follow the SoC's SEP DART aperture, which the SoC .dtsi also describes; - xart_guard is a safety policy; - the sensor's bus, chip select and SPI mode come from the board's apple,mesa-fingerprint node; the profile's sensor constants are not read at run time; - nonce_session follows the sensor generation, which is the same on every board of each SoC read so far. Pick these profiles by SoC alone, as T8103, T6000/T6001, T6020/T6021, T8112 and T8140 already are. The SEP node's status cannot be the board selector here: the warm-attach path enables the SEP node and its DART at module load, and the trees leave both disabled for it. The SEP mailbox's status is what the board device trees set: on T6040, T6041, T6050 and T8142 it is enabled on exactly the boards the old lists named. enable_sep_and_dart() now leaves the SEP disabled when its mailbox is disabled, and when there is no SEP node (J704) it logs and returns instead of failing module init. From compiled DTBs of all 66 Apple silicon boards in the tree: - every board that had a profile keeps it and attaches as before (J700, J616s, J316s and J413 among them); - J773s, J575c, J714c, J716s, J775c, J775d, J873s, K114c, K114s and J704 now get their SoC's profile, but their mailbox is disabled (or there is no SEP node), so nothing binds, as before; - J433, J434, J504 (T8122) and J604, J623, J624, J773g (T8132): the SoC .dtsi enables the SEP mailbox on every board, so the SEP now attaches there with the SoC's profile, as it already does on the T6020/T6021 and T8112 desktops. Update the selection KUnit test to match. Link: https://github.com/aurora-silicon/linux/pull/2115 Signed-off-by: Ryan Murray --- drivers/soc/apple/dt.rs | 31 +++++++++++--- drivers/soc/apple/profile.rs | 81 +++++++++++++++++++++++++----------- 2 files changed, 82 insertions(+), 30 deletions(-) diff --git a/drivers/soc/apple/dt.rs b/drivers/soc/apple/dt.rs index d6f83b5586235..cc11f36f9378e 100644 --- a/drivers/soc/apple/dt.rs +++ b/drivers/soc/apple/dt.rs @@ -11,6 +11,7 @@ use kernel::prelude::*; const SEP_COMPATIBLE: &CStr = c"apple,sep"; const IOMMUS_PROP: &CStr = c"iommus"; +const MBOXES_PROP: &CStr = c"mboxes"; const STATUS_PROP: &CStr = c"status"; const STATUS_OKAY: &CStr = c"okay"; @@ -185,14 +186,34 @@ pub(crate) fn preboot_uuid() -> Option<[u8; 16]> { Some(uuid.b) } +/// Enables the SEP and its DART for a warm attach, on boards whose device +/// tree describes a usable enclave. +/// +/// Most device trees leave the SEP node and its DART `disabled` for this +/// function to enable, so their status cannot say whether a board has a +/// usable enclave. The SEP mailbox's status does: the SEP cannot be reached +/// without it, and the device tree enables it (in the board file, or in the +/// SoC .dtsi for every board of that SoC) where the SEP is described for the +/// machine. A board with no SEP node, or one that keeps the mailbox +/// disabled, is left untouched and the module probes nothing. pub(crate) fn enable_sep_and_dart(window: &crate::profile::DartWindow) -> Result<()> { - let sep = sep_node().ok_or_else(|| { - pr_err!( - "apple_sep: no device-tree node with compatible '{}'\n", + let Some(sep) = sep_node() else { + pr_info!( + "apple_sep: no device-tree node with compatible '{}'; the SEP stays disabled\n", SEP_COMPATIBLE ); - ENODEV - })?; + return Ok(()); + }; + + if !sep + .parse_phandle(MBOXES_PROP, 0) + .is_some_and(|mbox| mbox.is_available()) + { + pr_info!( + "apple_sep: the device tree leaves the SEP mailbox disabled on this board; the SEP stays disabled\n" + ); + return Ok(()); + } let dart = sep.parse_phandle(IOMMUS_PROP, 0).ok_or_else(|| { pr_err!( diff --git a/drivers/soc/apple/profile.rs b/drivers/soc/apple/profile.rs index 87904639a780f..d80a127203c95 100644 --- a/drivers/soc/apple/profile.rs +++ b/drivers/soc/apple/profile.rs @@ -692,30 +692,36 @@ fn select( if has(b"apple,t8112") { return Ok(&T8112); } - // Only the boards whose ADTs were read: the other T8122 Macs (J433, J434, - // J504) share the SoC but their sensor wiring is unchecked. - if has(b"apple,t8122") && (has(b"apple,j613") || has(b"apple,j615")) { + // The SoC alone picks the profile below, as it does above. Whether a + // board has an enclave to attach to is the board device tree's call: + // `dt::enable_sep_and_dart` leaves the SEP disabled when the board keeps + // the SEP mailbox disabled or has no SEP node. + // + // What these profiles carry beyond the device tree is per SoC: the + // shared-memory geometry and handoff the SoC's sepOS expects, the SEP + // DART aperture (which the SoC .dtsi also describes), the key-store + // dialect and the xART guard level. The sensor's bus, chip select and + // SPI mode come from the board's `apple,mesa-fingerprint` node; the + // `sensor` constants are not read at run time. `nonce_session` follows + // the sensor generation, which is the same on every board of each SoC + // read so far (R3 on T8122; V3 on T6040, T6041, T6050, T8132, T8142). + // A board without a sensor node has no Touch ID for it to apply to. + if has(b"apple,t8122") { return Ok(&T8122); } - // The T6040 profile is tested on J614s and J616s. - if has(b"apple,t6040") && (has(b"apple,j616s") || has(b"apple,j614s")) { + if has(b"apple,t6040") { return Ok(&T6040); } - if has(b"apple,t6041") && (has(b"apple,j616c") || has(b"apple,j614c")) { + if has(b"apple,t6041") { return Ok(&T6041); } - if has(b"apple,t6050") - && (has(b"apple,j714s") || has(b"apple,k116s") || has(b"apple,j716c")) - { + if has(b"apple,t6050") { return Ok(&T6050); } - // Only the M4 MacBook Airs: the other T8132 Macs are unread. - if has(b"apple,t8132") && (has(b"apple,j713") || has(b"apple,j715")) { + if has(b"apple,t8132") { return Ok(&T8132); } - // The J815 and the J813, whose ADTs were read: both have the sensor (mesa) on spi2 - // at 0x3a5108000. - if has(b"apple,t8142") && (has(b"apple,j815") || has(b"apple,j813")) { + if has(b"apple,t8142") { return Ok(&T8142); } Err(ENODEV) @@ -781,28 +787,48 @@ mod tests { select(&has, &|| &T6020).ok().map(|p| p.name) } + /// The SoC picks the profile; the board name plays no part. Boards that + /// were outside the old per-board lists (J604, J504, K114s, J704) get + /// their SoC's profile, and a board compatible on the wrong SoC does not + /// drag its old profile along. #[test] - fn t8132_selection_is_limited_to_the_m4_airs() { + fn selection_follows_the_soc_alone() { assert_eq!(picked(&[b"apple,j713", b"apple,t8132"]), Some(T8132.name)); assert_eq!(picked(&[b"apple,j715", b"apple,t8132"]), Some(T8132.name)); - assert_eq!(picked(&[b"apple,j604", b"apple,t8132"]), None); - assert_eq!(picked(&[b"apple,t8132"]), None); - assert_eq!(picked(&[b"apple,j613", b"apple,t8132"]), None); - assert_eq!(picked(&[b"apple,j713", b"apple,t8122"]), None); + assert_eq!(picked(&[b"apple,j604", b"apple,t8132"]), Some(T8132.name)); + assert_eq!(picked(&[b"apple,j773g", b"apple,t8132"]), Some(T8132.name)); + assert_eq!(picked(&[b"apple,t8132"]), Some(T8132.name)); + assert_eq!(picked(&[b"apple,j613", b"apple,t8132"]), Some(T8132.name)); + assert_eq!(picked(&[b"apple,j713", b"apple,t8122"]), Some(T8122.name)); assert_eq!(picked(&[b"apple,j613", b"apple,t8122"]), Some(T8122.name)); + assert_eq!(picked(&[b"apple,j504", b"apple,t8122"]), Some(T8122.name)); assert_eq!(picked(&[b"apple,j700", b"apple,t8140"]), Some(T8140.name)); assert_eq!(picked(&[b"apple,j616s", b"apple,t6040"]), Some(T6040.name)); - assert_eq!(picked(&[b"apple,t6040"]), None); assert_eq!(picked(&[b"apple,j614s", b"apple,t6040"]), Some(T6040.name)); + assert_eq!(picked(&[b"apple,t6040"]), Some(T6040.name)); assert_eq!(picked(&[b"apple,j616c", b"apple,t6041"]), Some(T6041.name)); assert_eq!(picked(&[b"apple,j614c", b"apple,t6041"]), Some(T6041.name)); - assert_eq!(picked(&[b"apple,t6041"]), None); - assert_eq!(picked(&[b"apple,j713", b"apple,t6041"]), None); + assert_eq!(picked(&[b"apple,j713", b"apple,t6041"]), Some(T6041.name)); + assert_eq!(picked(&[b"apple,j716c", b"apple,t6041"]), Some(T6041.name)); assert_eq!(picked(&[b"apple,j714s", b"apple,t6050"]), Some(T6050.name)); assert_eq!(picked(&[b"apple,k116s", b"apple,t6050"]), Some(T6050.name)); assert_eq!(picked(&[b"apple,j716c", b"apple,t6050"]), Some(T6050.name)); - assert_eq!(picked(&[b"apple,j716c", b"apple,t6041"]), None); - assert_eq!(picked(&[b"apple,t6050"]), None); + assert_eq!(picked(&[b"apple,k114s", b"apple,t6050"]), Some(T6050.name)); + assert_eq!(picked(&[b"apple,j815", b"apple,t8142"]), Some(T8142.name)); + assert_eq!(picked(&[b"apple,j813", b"apple,t8142"]), Some(T8142.name)); + assert_eq!(picked(&[b"apple,j704", b"apple,t8142"]), Some(T8142.name)); + assert_eq!(picked(&[b"apple,j316s", b"apple,t6000"]), Some(T6000.name)); + assert_eq!(picked(&[b"apple,j413", b"apple,t8112"]), Some(T8112.name)); + } + + /// SoCs without a profile are still refused, whatever the board. + #[test] + fn unprofiled_socs_are_refused() { + assert_eq!(picked(&[b"apple,j375d", b"apple,t6002"]), None); + assert_eq!(picked(&[b"apple,j514c", b"apple,t6031"]), None); + assert_eq!(picked(&[b"apple,j804", b"apple,t8152"]), None); + assert_eq!(picked(&[b"apple,j713"]), None); + assert_eq!(picked(&[]), None); } /// Touch ID has one path for every Mac. The retry limits, the lock @@ -813,7 +839,7 @@ mod tests { /// profile naming one of the known Mesa revisions. #[test] fn every_touch_id_mac_gets_a_sensor_the_shared_path_decodes() { - let macs: [&[&[u8]]; 16] = [ + let macs: [&[&[u8]]; 21] = [ &[b"apple,j313", b"apple,t8103"], &[b"apple,j316s", b"apple,t6000"], &[b"apple,j316c", b"apple,t6001"], @@ -827,9 +853,14 @@ mod tests { &[b"apple,j616s", b"apple,t6040"], &[b"apple,j616c", b"apple,t6041"], &[b"apple,j713", b"apple,t8132"], + &[b"apple,j715", b"apple,t8132"], + &[b"apple,j604", b"apple,t8132"], &[b"apple,j700", b"apple,t8140"], &[b"apple,j714s", b"apple,t6050"], &[b"apple,j716c", b"apple,t6050"], + &[b"apple,k114s", b"apple,t6050"], + &[b"apple,j813", b"apple,t8142"], + &[b"apple,j815", b"apple,t8142"], ]; for compatibles in macs { let has = |c: &[u8]| compatibles.iter().any(|x| *x == c);