diff --git a/arch/arm64/boot/dts/apple/t6030-coprocessors.dtsi b/arch/arm64/boot/dts/apple/t6030-coprocessors.dtsi index 8ffda682587ef..bf1ff9bb89e71 100644 --- a/arch/arm64/boot/dts/apple/t6030-coprocessors.dtsi +++ b/arch/arm64/boot/dts/apple/t6030-coprocessors.dtsi @@ -2,12 +2,21 @@ /* Disabled coprocessor interfaces; firmware handoff remains a loader job. */ &soc { + /* + * iBoot hands over a running SEP (ADT sepfw-load-at-boot). Keep Linux + * off its DART at boot; apple_sep enables it when the driver binds. The + * SEP only accepts IOVAs in the window iBoot programmed (ADT vm-base + * 0x10000004000, vm-size 0xffff0000), which carries the BIT(40) alias + * the DART translates. + */ sep_dart: iommu@29cac0000 { compatible = "apple,t6030-dart", "apple,t8110-dart"; reg = <0x2 0x9cac0000 0 0x4000>; interrupt-parent = <&aic>; interrupts = ; #iommu-cells = <1>; + apple,dma-range = /bits/ 64 <0x10000004000 0xffff0000>; + apple,dma-offset = /bits/ 64 <0x0>; status = "disabled"; }; diff --git a/arch/arm64/boot/dts/apple/t6030-j514s.dts b/arch/arm64/boot/dts/apple/t6030-j514s.dts index 1ccf2f1294d6b..cc1070d099267 100644 --- a/arch/arm64/boot/dts/apple/t6030-j514s.dts +++ b/arch/arm64/boot/dts/apple/t6030-j514s.dts @@ -18,6 +18,10 @@ compatible = "apple,j514s", "apple,t6030", "apple,arm-platform"; model = "Apple MacBook Pro (14-inch, M3 Pro, Nov 2023)"; + aliases { + sep = &sep; + }; + chosen { asahi,t6030-dispext = "1"; }; @@ -115,3 +119,27 @@ status = "disabled"; }; }; + +/* apple_sep enables the SEP and its DART when it loads. */ +&sep_mbox { + status = "okay"; +}; + +/* + * Touch ID sensor (Mesa 0x3352, J514s ADT /arm-io/spi2/mesa): power on + * NUB GPIO 33, active high. As on J613, the data-ready line (AP GPIO 200) + * is left out, so the driver polls until its trigger is confirmed. Native + * chip select only. + */ +&spi2 { + status = "okay"; +}; + +&mesa { + status = "okay"; + enable-gpios = <&pinctrl_nub 33 GPIO_ACTIVE_HIGH>; + spi-cs-setup-delay-ns = <20>; + spi-cs-hold-delay-ns = <20>; + /* Per-device factory data from this Mac's own iBoot system container. */ + firmware-name = "apple/mesacal-j514s.bin"; +}; diff --git a/arch/arm64/boot/dts/apple/t6030-peripheral-buses.dtsi b/arch/arm64/boot/dts/apple/t6030-peripheral-buses.dtsi index b03254c622758..691f07f160880 100644 --- a/arch/arm64/boot/dts/apple/t6030-peripheral-buses.dtsi +++ b/arch/arm64/boot/dts/apple/t6030-peripheral-buses.dtsi @@ -2,6 +2,11 @@ /* Unclaimed T6030 peripheral buses. */ &soc { + /* + * Touch ID (J514s ADT /arm-io/spi2). iBoot leaves the pads muxed and + * the controller uses its native chip select, so there is no pinctrl + * here. + */ spi2: spi@289108000 { compatible = "apple,t6030-spi", "apple,t8103-spi"; reg = <0x2 0x89108000 0 0x4000>; @@ -12,6 +17,14 @@ #address-cells = <1>; #size-cells = <0>; status = "disabled"; + + mesa: fingerprint@0 { + compatible = "apple,mesa-fingerprint"; + reg = <0>; + spi-max-frequency = <8000000>; + spi-cpha; + status = "disabled"; + }; }; spi4: spi@289110000 { diff --git a/drivers/soc/apple/profile.rs b/drivers/soc/apple/profile.rs index 87904639a780f..eba72215fba9b 100644 --- a/drivers/soc/apple/profile.rs +++ b/drivers/soc/apple/profile.rs @@ -430,6 +430,26 @@ pub(crate) const T8122: PlatformProfile = PlatformProfile { ..T8112 }; +/// MacBook Pro 14" M3 Pro (J514s). The J514s ADT (system firmware 27.0) records +/// a pre-booted SEP (`sepfw-load-at-boot`), an `iop-sep,ascwrap-v6` SEP and +/// its DART at the same addresses as T8122's, with the same BIT(40) aperture +/// (`vm-base` 0x10000004000, `vm-size` 0xffff0000). The Mesa sensor is the +/// `0x3352` part T8122 carries, on spi2 at `0x289108000`, 8 MHz, chip select +/// 0. Its power is NUB GPIO 33 and its data-ready line AP GPIO 200. +/// `/defaults` carries `cpx-encryption-mode = 2`. +/// +/// Otherwise T8122's warm-registration profile. J514s on system firmware 27.0 +/// attaches, provisions the keybag, enrols, matches, and still matches after a +/// reboot and after suspend; macOS Touch ID keeps working alongside it. +pub(crate) const T6030: PlatformProfile = PlatformProfile { + name: "T6030", + sensor: SensorProfile { + controller_base: 0x2_8910_8000, + ..T8122.sensor + }, + ..T8122 +}; + /// MacBook Pro 16" M4 Pro (J616s). The J616s ADT (26.6.2, 25G83) records a /// pre-booted SEP (`sepfw-load-at-boot`), an `iop-sep,ascwrap-v6` SEP whose /// DART aperture starts at the BIT(40) alias (`vm-base` 0x10000004000), and @@ -534,6 +554,9 @@ static_assert!(T8112.sensor.controller_base == T8103.sensor.controller_base); static_assert!(T8122.shmem_capacity == T8112.shmem_capacity); static_assert!(T8122.sensor.controller_base == 0x2a1108000); static_assert!(T8122.wide_dma_mask); +static_assert!(T6030.sensor.controller_base == 0x289108000); +static_assert!(T6030.sensor.expected_id == T8122.sensor.expected_id); +static_assert!(T6030.wide_dma_mask); static_assert!(T6040.sensor.controller_base == 0x429108000); static_assert!(T6040.sensor.expected_id == T8140.sensor.expected_id); static_assert!(T8132.sensor.controller_base == 0x3ad108000); @@ -697,6 +720,14 @@ fn select( if has(b"apple,t8122") && (has(b"apple,j613") || has(b"apple,j615")) { return Ok(&T8122); } + // Selected by the SoC. The SEP, its DART and spi2 are T6030 blocks at the + // same addresses on every T6030 Mac. Whether a board has the sensor wired + // is the board device tree's job: a board enables sep_mbox, spi2 and the + // mesa node only once its ADT has been read (J514s today); on the others + // they stay disabled and nothing binds. + if has(b"apple,t6030") { + return Ok(&T6030); + } // The T6040 profile is tested on J614s and J616s. if has(b"apple,t6040") && (has(b"apple,j616s") || has(b"apple,j614s")) { return Ok(&T6040); @@ -791,6 +822,9 @@ mod tests { assert_eq!(picked(&[b"apple,j713", b"apple,t8122"]), None); assert_eq!(picked(&[b"apple,j613", b"apple,t8122"]), Some(T8122.name)); assert_eq!(picked(&[b"apple,j700", b"apple,t8140"]), Some(T8140.name)); + assert_eq!(picked(&[b"apple,j514s", b"apple,t6030"]), Some(T6030.name)); + assert_eq!(picked(&[b"apple,j516s", b"apple,t6030"]), Some(T6030.name)); + assert_eq!(picked(&[b"apple,t6030"]), Some(T6030.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)); @@ -813,7 +847,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]]; 17] = [ &[b"apple,j313", b"apple,t8103"], &[b"apple,j316s", b"apple,t6000"], &[b"apple,j316c", b"apple,t6001"], @@ -823,6 +857,7 @@ mod tests { &[b"apple,j415", b"apple,t8112"], &[b"apple,j613", b"apple,t8122"], &[b"apple,j615", b"apple,t8122"], + &[b"apple,j514s", b"apple,t6030"], &[b"apple,j614s", b"apple,t6040"], &[b"apple,j616s", b"apple,t6040"], &[b"apple,j616c", b"apple,t6041"], diff --git a/drivers/soc/apple/xart_guard.rs b/drivers/soc/apple/xart_guard.rs index f5e9b9490b44e..90b88579bc901 100644 --- a/drivers/soc/apple/xart_guard.rs +++ b/drivers/soc/apple/xart_guard.rs @@ -1083,6 +1083,7 @@ mod tests { assert_eq!(level(-1, profile::T6020_SEPOS13.xart_guard), Some(1)); assert_eq!(level(-1, profile::T8112.xart_guard), Some(1)); assert_eq!(level(-1, profile::T8122.xart_guard), Some(1)); + assert_eq!(level(-1, profile::T6030.xart_guard), Some(1)); // Off on the Neo, whose Linux records predate the list. assert_eq!(level(-1, profile::T8140.xart_guard), None); assert_eq!(level(i8::MIN, 1), Some(1)); diff --git a/tools/aurora-sep/tests/test_t6030_sep.py b/tools/aurora-sep/tests/test_t6030_sep.py new file mode 100644 index 0000000000000..01ca822a8797c --- /dev/null +++ b/tools/aurora-sep/tests/test_t6030_sep.py @@ -0,0 +1,134 @@ +"""T6030 (MacBook Pro 14" M3 Pro, J514s) SEP and Mesa sensor device tree and profile. + +Set DTC to this kernel's built scripts/dtc/dtc for Apple floating-point cells. +""" + +from pathlib import Path +import os +import re +import shutil +import subprocess +import tempfile +import unittest + + +ROOT = Path(__file__).resolve().parents[3] +DTS = ROOT / "arch/arm64/boot/dts/apple" +DTC = os.environ.get("DTC", "dtc") +PROFILE = (ROOT / "drivers/soc/apple/profile.rs").read_text() + +SEP_DART = "/soc/iommu@29cac0000" +SEP = "/soc/sep@29e400000" +BUS = "/soc/spi@289108000" +SENSOR = BUS + "/fingerprint@0" +PINCTRL_NUB = "/soc/pinctrl@3641f0000" +MBOX = "/soc/mailbox@29e408000" +# AIC_IRQ cells: , IRQ_TYPE_LEVEL_HIGH = 4. +LEVEL_HIGH = 4 + + +@unittest.skipUnless(all(shutil.which(tool) for tool in ("cpp", DTC, "fdtget")), + "requires cpp, dtc and fdtget") +class T6030SepTest(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.temp = tempfile.TemporaryDirectory(prefix="aurora-t6030-sep-") + cls.addClassCleanup(cls.temp.cleanup) + cls.out = Path(cls.temp.name) + + def compile_board(self, board): + pp = subprocess.run(["cpp", "-nostdinc", "-undef", "-D__DTS__", "-x", + "assembler-with-cpp", "-I", str(ROOT / "include"), + "-I", str(DTS), str(DTS / f"t6030-{board}.dts")], + check=True, capture_output=True) + output = self.out / f"{board}.dtb" + subprocess.run([DTC, "-q", "-I", "dts", "-O", "dtb", "-o", str(output)], + input=pp.stdout, check=True, capture_output=True) + return output + + def prop(self, dtb, node, name, kind="x"): + return subprocess.run(["fdtget", "-t", kind, str(dtb), node, name], + check=True, capture_output=True, text=True).stdout.split() + + def props(self, dtb, node): + return subprocess.run(["fdtget", "-p", str(dtb), node], + check=True, capture_output=True, text=True).stdout.split() + + def cells(self, dtb, node, name): + return [int(cell, 16) for cell in self.prop(dtb, node, name)] + + def irqs(self, dtb, node): + cells = self.cells(dtb, node, "interrupts") + self.assertEqual(len(cells) % 3, 0) + triples = [cells[i:i + 3] for i in range(0, len(cells), 3)] + for kind, _, flags in triples: + self.assertEqual((kind, flags), (0, LEVEL_HIGH)) + return [irq for _, irq, _ in triples] + + def test_j514s_describes_sep_and_sensor(self): + dtb = self.compile_board("j514s") + # apple_sep enables the SEP and its DART at module load. + self.assertEqual(self.prop(dtb, SEP_DART, "status", "s"), ["disabled"]) + self.assertEqual(self.prop(dtb, SEP, "status", "s"), ["disabled"]) + self.assertEqual(self.prop(dtb, MBOX, "status", "s"), ["okay"]) + # ADT vm-base 0x10000004000, vm-size 0xffff0000, as on t8122. + self.assertEqual(self.cells(dtb, SEP_DART, "apple,dma-range"), + [0x100, 0x4000, 0, 0xffff0000]) + self.assertEqual(self.cells(dtb, SEP_DART, "apple,dma-offset"), [0, 0]) + self.assertEqual(self.prop(dtb, "/aliases", "sep", "s"), [SEP]) + + self.assertEqual(self.prop(dtb, BUS, "status", "s"), ["okay"]) + self.assertEqual(self.prop(dtb, SENSOR, "status", "s"), ["okay"]) + self.assertEqual(self.prop(dtb, SENSOR, "firmware-name", "s"), + ["apple/mesacal-j514s.bin"]) + nub = int(self.prop(dtb, PINCTRL_NUB, "phandle")[0], 16) + self.assertEqual(self.cells(dtb, SENSOR, "enable-gpios"), [nub, 33, 0]) + self.assertEqual(self.prop(dtb, SENSOR, "spi-max-frequency", "u"), ["8000000"]) + self.assertEqual(self.prop(dtb, SENSOR, "spi-cs-setup-delay-ns", "u"), ["20"]) + self.assertEqual(self.prop(dtb, SENSOR, "spi-cs-hold-delay-ns", "u"), ["20"]) + properties = self.props(dtb, SENSOR) + self.assertIn("spi-cpha", properties) + self.assertNotIn("spi-cpol", properties) + self.assertNotIn("interrupts", properties) + self.assertNotIn("cs-gpios", self.props(dtb, BUS)) + + def test_addresses_and_interrupts_match_the_adt(self): + # The J514s ADT values (system firmware 27.0), /arm-io base 0x210000000 added. + dtb = self.compile_board("j514s") + self.assertEqual(self.cells(dtb, SEP_DART, "reg"), [0x2, 0x9cac0000, 0, 0x4000]) + self.assertEqual(self.irqs(dtb, SEP_DART), [372]) + self.assertEqual(self.cells(dtb, SEP, "reg")[:4], [0x2, 0x9e400000, 0, 0x6c000]) + self.assertEqual(self.cells(dtb, MBOX, "reg"), [0x2, 0x9e408000, 0, 0x4000]) + self.assertEqual(self.prop(dtb, MBOX, "interrupt-names", "s"), + ["send-empty", "send-not-empty", "recv-empty", "recv-not-empty"]) + self.assertEqual(self.irqs(dtb, MBOX), [366, 367, 368, 369]) + mbox = int(self.prop(dtb, MBOX, "phandle")[0], 16) + dart = int(self.prop(dtb, SEP_DART, "phandle")[0], 16) + self.assertEqual(self.cells(dtb, SEP, "mboxes"), [mbox]) + self.assertEqual(self.cells(dtb, SEP, "iommus"), [dart, 0]) + self.assertEqual(self.cells(dtb, BUS, "reg"), [0x2, 0x89108000, 0, 0x4000]) + self.assertEqual(self.irqs(dtb, BUS), [876]) + self.assertEqual(self.cells(dtb, SENSOR, "reg"), [0]) + + def test_j516s_leaves_sep_and_sensor_off(self): + dtb = self.compile_board("j516s") + self.assertNotIn("sep", self.props(dtb, "/aliases")) + self.assertEqual(self.prop(dtb, MBOX, "status", "s"), ["disabled"]) + self.assertEqual(self.prop(dtb, BUS, "status", "s"), ["disabled"]) + self.assertEqual(self.prop(dtb, SENSOR, "status", "s"), ["disabled"]) + + def test_profile_selected_by_soc(self): + # The SoC picks the profile; the board device tree decides whether + # the SEP and the sensor are enabled (see the J516s test above). + select = PROFILE.split("fn select(", 1)[1] + line = next(line for line in select.splitlines() if 'b"apple,t6030"' in line) + self.assertEqual(line.strip(), 'if has(b"apple,t6030") {') + profile = re.search(r"const T6030: PlatformProfile = PlatformProfile \{(.*?)\n\};", + PROFILE, re.S).group(1) + self.assertIn("..T8122", profile) + # The diagnostic controller base is spi2's, not T8122's. + self.assertIn("controller_base: 0x2_8910_8000", profile) + + +if __name__ == "__main__": + unittest.main()