From 00d0757376472c706be6e0ab8e39348e486673fe Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Thu, 12 Nov 2026 13:32:44 +1100 Subject: [PATCH 1/3] crypto: apple: support the revision 5 engine on T6040 and T8140 The revision 5 SIO AES engine on T6040 and T8140 takes DMA addresses up to 42 bits wide, and its SIO DART window starts above 4 GiB, so the 32-bit DMA mask the driver used could never be satisfied there and the upper address word of the crypt command has to be filled in. The upper address word carries bits 32 and up of the source address in its upper half and of the destination address in its lower half. Build it from the bounce buffer address once at probe and refuse a buffer the engine cannot reach. Each SoC entry now carries its DMA width: 42 bits on revision 5, and 32 bits on revision 3, which keeps that word at zero as before. The crypt length field is 24 bits wide; the 512 KiB bounce buffer stays well inside it. Assisted-by: LLM Signed-off-by: Ryan Murray --- drivers/crypto/Kconfig | 3 +- drivers/crypto/apple-aes.c | 72 ++++++++++-- drivers/soc/apple/apple-sio-aes.c | 187 ------------------------------ 3 files changed, 62 insertions(+), 200 deletions(-) delete mode 100644 drivers/soc/apple/apple-sio-aes.c diff --git a/drivers/crypto/Kconfig b/drivers/crypto/Kconfig index 34e790ca74207..5f24fbd4d201b 100644 --- a/drivers/crypto/Kconfig +++ b/drivers/crypto/Kconfig @@ -818,7 +818,8 @@ config CRYPTO_DEV_APPLE_SIO_AES select CRYPTO_LIB_AES help ECB, CBC and CTR AES on the SIO AES engine of Apple T6000 (M1 - Pro/Max/Ultra) and T8112 (M2) SoCs, with software keys only. + Pro/Max/Ultra), T8112 (M2), T6040 (M4 Pro) and T8140 SoCs, with + software keys only. The engine is slower than the ARMv8 Crypto Extensions, so it is registered at a lower priority and is only used when asked for by driver name. diff --git a/drivers/crypto/apple-aes.c b/drivers/crypto/apple-aes.c index 08365c99830bd..2ba3feae6540b 100644 --- a/drivers/crypto/apple-aes.c +++ b/drivers/crypto/apple-aes.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * Apple SIO AES engine (T6000/T8112 family) skcipher driver. + * Apple SIO AES engine skcipher driver (T6000, T8112, T6040 and T8140). * * The engine takes commands through a word FIFO: load a key into one of * two key slots, load an IV into an IV slot, then run a block operation @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -79,10 +80,16 @@ /* SET_IV */ #define AES_IV_SLOT GENMASK(27, 26) -/* CRYPT: followed by the upper address word, source and destination. */ +/* + * CRYPT: followed by the upper address word, then the low 32 bits of the + * source and destination addresses. The upper address word carries + * address bits 32 and up of the source in its upper half and of the + * destination in its lower half. + */ #define AES_CRYPT_KEY_SLOT BIT(27) #define AES_CRYPT_IV_SLOT GENMASK(26, 25) -#define AES_CRYPT_LEN GENMASK(24, 0) +#define AES_CRYPT_LEN GENMASK(23, 0) +#define AES_ADDR_HI_SRC_SHIFT 16 /* BARRIER */ #define AES_BARRIER_IRQ BIT(27) @@ -97,6 +104,8 @@ struct apple_sio_aes_data { u32 revision; + /* DMA address width the upper address word can carry. */ + u8 dma_bits; }; struct apple_sio_aes { @@ -108,8 +117,10 @@ struct apple_sio_aes { u32 irq_status; bool running; + const struct apple_sio_aes_data *data; void *bounce; dma_addr_t bounce_dma; + u32 bounce_hi; u64 requests; u64 bytes; @@ -226,9 +237,6 @@ static int apple_sio_aes_run(struct apple_sio_aes *aes, break; } - if (upper_32_bits(aes->bounce_dma)) - return -EIO; - reinit_completion(&aes->done); aes->irq_status = 0; apple_sio_aes_start(aes); @@ -260,10 +268,9 @@ static int apple_sio_aes_run(struct apple_sio_aes *aes, FIELD_PREP(AES_CRYPT_LEN, len); dma_sync_single_for_device(aes->dev, aes->bounce_dma, len, DMA_BIDIRECTIONAL); - /* A 32-bit DMA mask keeps the upper address word zero. */ ret = apple_sio_aes_push(aes, cmd); if (!ret) - ret = apple_sio_aes_push(aes, 0); + ret = apple_sio_aes_push(aes, aes->bounce_hi); if (!ret) ret = apple_sio_aes_push(aes, lower_32_bits(aes->bounce_dma)); if (!ret) @@ -496,6 +503,8 @@ static int apple_sio_aes_stats_show(struct seq_file *s, void *unused) { struct apple_sio_aes *aes = s->private; + seq_printf(s, "revision: %u\n", aes->data->revision); + seq_printf(s, "bounce_dma: %pad\n", &aes->bounce_dma); seq_printf(s, "readiness_at_probe: %#010x\n", aes->readiness); seq_printf(s, "requests: %llu\n", aes->requests); seq_printf(s, "bytes: %llu\n", aes->bytes); @@ -517,6 +526,23 @@ static void apple_sio_aes_free_bounce(void *data) aes->bounce_dma, DMA_BIDIRECTIONAL); } +/* + * Build the upper address word for an in-place operation on @addr. The + * engine drops address bits above its DMA width, so refuse such an + * address instead of letting it alias a lower one. + */ +static int apple_sio_aes_addr_hi(const struct apple_sio_aes_data *data, + dma_addr_t addr, u32 *hi) +{ + u32 upper = upper_32_bits(addr); + + if (data->dma_bits < 64 && (u64)addr >> data->dma_bits) + return -ERANGE; + + *hi = (upper << AES_ADDR_HI_SRC_SHIFT) | upper; + return 0; +} + static int apple_sio_aes_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -532,6 +558,9 @@ static int apple_sio_aes_probe(struct platform_device *pdev) if (!aes) return -ENOMEM; aes->dev = dev; + aes->data = device_get_match_data(dev); + if (!aes->data) + return -ENODEV; init_completion(&aes->done); platform_set_drvdata(pdev, aes); @@ -544,9 +573,9 @@ static int apple_sio_aes_probe(struct platform_device *pdev) if (aes->irq < 0) return aes->irq; - ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32)); + ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(aes->data->dma_bits)); if (ret) - return dev_err_probe(dev, ret, "no 32-bit DMA\n"); + return dev_err_probe(dev, ret, "no %u-bit DMA\n", aes->data->dma_bits); aes->bounce = dma_alloc_noncoherent(dev, AES_BOUNCE_SIZE, &aes->bounce_dma, DMA_BIDIRECTIONAL, GFP_KERNEL); @@ -555,6 +584,10 @@ static int apple_sio_aes_probe(struct platform_device *pdev) ret = devm_add_action_or_reset(dev, apple_sio_aes_free_bounce, aes); if (ret) return ret; + ret = apple_sio_aes_addr_hi(aes->data, aes->bounce_dma, &aes->bounce_hi); + if (ret) + return dev_err_probe(dev, ret, "bounce buffer at %pad is out of reach\n", + &aes->bounce_dma); ret = devm_request_irq(dev, aes->irq, apple_sio_aes_irq, 0, dev_name(dev), aes); @@ -602,8 +635,9 @@ static int apple_sio_aes_probe(struct platform_device *pdev) aes->debugfs = debugfs_create_dir(dev_name(dev), NULL); debugfs_create_file("stats", 0400, aes->debugfs, aes, &apple_sio_aes_stats_fops); - dev_info(dev, "AES engine ready (readiness %#010x, ECB/CBC/CTR, priority %d)\n", - aes->readiness, AES_PRIORITY); + dev_info(dev, "AES engine rev %u ready (readiness %#010x, %u-bit DMA, ECB/CBC/CTR, priority %d)\n", + aes->data->revision, aes->readiness, aes->data->dma_bits, + AES_PRIORITY); return 0; } @@ -644,13 +678,27 @@ static int apple_sio_aes_resume(struct device *dev) static DEFINE_SIMPLE_DEV_PM_OPS(apple_sio_aes_pm, apple_sio_aes_suspend, apple_sio_aes_resume); +/* + * Revision 3 decodes 36 address bits; this driver keeps it on a 32-bit + * mask, so its upper address word stays zero. Revision 5 decodes 42 + * address bits, ten in each half of the upper address word, and its SIO + * DART window starts above 4 GiB, so that word is always in use there. + */ static const struct apple_sio_aes_data apple_sio_aes_v3 = { .revision = 3, + .dma_bits = 32, +}; + +static const struct apple_sio_aes_data apple_sio_aes_v5 = { + .revision = 5, + .dma_bits = 42, }; static const struct of_device_id apple_sio_aes_of_match[] = { { .compatible = "apple,t6000-aes", .data = &apple_sio_aes_v3 }, { .compatible = "apple,t8112-aes", .data = &apple_sio_aes_v3 }, + { .compatible = "apple,t6041-aes", .data = &apple_sio_aes_v5 }, + { .compatible = "apple,t8140-aes", .data = &apple_sio_aes_v5 }, { } }; MODULE_DEVICE_TABLE(of, apple_sio_aes_of_match); diff --git a/drivers/soc/apple/apple-sio-aes.c b/drivers/soc/apple/apple-sio-aes.c deleted file mode 100644 index 4c7f29e51c4f0..0000000000000 --- a/drivers/soc/apple/apple-sio-aes.c +++ /dev/null @@ -1,187 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Probe-time diagnostics for the Apple S8000-family SIO AES engine. - * Only the readiness word and key-disable state are read. In particular, - * do not initialise the engine, acknowledge interrupts or touch the FIFO. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define APPLE_SIO_AES_READINESS 0x0c - -struct apple_sio_aes_data { - u32 revision; - /* Revision 3 has a shared word; revision 5 has per-slot words. */ - bool shared_disable; - u32 uid_offset; - u32 gid0_offset; - u32 gid1_offset; -}; - -struct apple_sio_aes { - const struct apple_sio_aes_data *data; - u32 readiness; - u32 disable; - u32 uid_disable; - u32 gid0_disable; - u32 gid1_disable; -}; - -static int apple_sio_aes_state_show(struct seq_file *s, void *unused) -{ - const struct apple_sio_aes *aes = s->private; - - seq_puts(s, "snapshot: probe\n"); - seq_printf(s, "revision_from_compatible: %u\n", aes->data->revision); - seq_printf(s, "readiness_raw: %#010x\n", aes->readiness); - seq_printf(s, "disable_raw: %#010x\n", aes->disable); - if (aes->data->shared_disable) { - seq_puts(s, "uid_gid_disable: shared word, slot bits undecoded\n"); - } else { - seq_printf(s, "uid_disable_raw: %#010x\n", aes->uid_disable); - seq_printf(s, "gid0_disable_raw: %#010x\n", aes->gid0_disable); - seq_printf(s, "gid1_disable_raw: %#010x\n", aes->gid1_disable); - } - - return 0; -} -DEFINE_SHOW_ATTRIBUTE(apple_sio_aes_state); - -static void apple_sio_aes_debugfs_remove(void *dir) -{ - debugfs_remove_recursive(dir); -} - -static void __iomem *apple_sio_aes_map(struct platform_device *pdev, - unsigned int index, resource_size_t min_size) -{ - struct resource *res; - - res = platform_get_resource(pdev, IORESOURCE_MEM, index); - if (!res || resource_size(res) < min_size) - return IOMEM_ERR_PTR(-EINVAL); - - return devm_ioremap_resource(&pdev->dev, res); -} - -static int apple_sio_aes_probe(struct platform_device *pdev) -{ - struct device *dev = &pdev->dev; - const struct apple_sio_aes_data *data; - void __iomem *engine, *disable; - struct apple_sio_aes *aes; - struct dentry *dir; - char *name; - int ret; - - data = of_device_get_match_data(dev); - if (!data) - return -ENODEV; - - /* The platform bus attaches the single power domain and SIO DART. */ - if (!dev->pm_domain || !of_property_present(dev->of_node, "power-domains")) - return dev_err_probe(dev, -EINVAL, "Missing AES power domain\n"); - if (!of_property_present(dev->of_node, "iommus") || - !iommu_get_domain_for_dev(dev)) - return dev_err_probe(dev, -ENODEV, "Missing SIO DART domain\n"); - - aes = devm_kzalloc(dev, sizeof(*aes), GFP_KERNEL); - if (!aes) - return -ENOMEM; - aes->data = data; - - /* apple,aes orders the banks as engine, key-disable, then optional DKEY. */ - engine = apple_sio_aes_map(pdev, 0, APPLE_SIO_AES_READINESS + 4); - if (IS_ERR(engine)) - return dev_err_probe(dev, PTR_ERR(engine), "Invalid engine aperture\n"); - disable = apple_sio_aes_map(pdev, 1, data->gid1_offset + 4); - if (IS_ERR(disable)) - return dev_err_probe(dev, PTR_ERR(disable), "Invalid key-disable aperture\n"); - - /* The DKEY aperture and IRQ are described by DT but never accessed. */ - ret = devm_pm_runtime_enable(dev); - if (ret) - return ret; - ret = pm_runtime_resume_and_get(dev); - if (ret < 0) - return dev_err_probe(dev, ret, "Failed to power AES for snapshot\n"); - - /* No polling or decoding of unverified readiness/disable bitfields. */ - aes->readiness = readl(engine + APPLE_SIO_AES_READINESS); - aes->disable = readl(disable); - if (!data->shared_disable) { - aes->uid_disable = readl(disable + data->uid_offset); - aes->gid0_disable = readl(disable + data->gid0_offset); - aes->gid1_disable = readl(disable + data->gid1_offset); - } - - ret = pm_runtime_put_sync_suspend(dev); - if (ret < 0) - return dev_err_probe(dev, ret, "Failed to release AES power\n"); - - if (data->shared_disable) - dev_info(dev, - "probe snapshot: revision %u (compatible), readiness %#010x, shared UID/GID disable %#010x (undecoded)\n", - data->revision, aes->readiness, aes->disable); - else - dev_info(dev, - "probe snapshot: revision %u (compatible), readiness %#010x, disable %#010x, UID %#010x, GID0 %#010x, GID1 %#010x (raw)\n", - data->revision, aes->readiness, aes->disable, - aes->uid_disable, aes->gid0_disable, aes->gid1_disable); - - name = devm_kasprintf(dev, GFP_KERNEL, "apple-sio-aes-%s", dev_name(dev)); - if (!name) - return -ENOMEM; - dir = debugfs_create_dir(name, NULL); - if (IS_ERR(dir)) - return 0; - ret = devm_add_action_or_reset(dev, apple_sio_aes_debugfs_remove, dir); - if (ret) - return ret; - debugfs_create_file("state", 0400, dir, aes, &apple_sio_aes_state_fops); - - return 0; -} - -static const struct apple_sio_aes_data apple_sio_aes_t6041 = { - .revision = 5, - .uid_offset = 0x04, - .gid0_offset = 0x08, - .gid1_offset = 0x0c, -}; - -static const struct apple_sio_aes_data apple_sio_aes_t8140 = { - .revision = 5, - .uid_offset = 0x40, - .gid0_offset = 0x44, - .gid1_offset = 0x48, -}; - -static const struct of_device_id apple_sio_aes_of_match[] = { - { .compatible = "apple,t6041-aes", .data = &apple_sio_aes_t6041 }, - { .compatible = "apple,t8140-aes", .data = &apple_sio_aes_t8140 }, - { } -}; -MODULE_DEVICE_TABLE(of, apple_sio_aes_of_match); - -static struct platform_driver apple_sio_aes_driver = { - .probe = apple_sio_aes_probe, - .driver = { - .name = "apple-sio-aes", - .of_match_table = apple_sio_aes_of_match, - }, -}; -module_platform_driver(apple_sio_aes_driver); - -MODULE_DESCRIPTION("Apple SIO AES probe-time read-only diagnostics"); -MODULE_AUTHOR("Ryan Murray <81541646+RyanTheTide@users.noreply.github.com>"); -MODULE_LICENSE("GPL"); From 3e0f5ea3f1d02f3260b23c15493d09f9c765609d Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Thu, 12 Nov 2026 13:32:44 +1100 Subject: [PATCH 2/3] soc: apple: remove the probe-only SIO AES diagnostics driver The skcipher driver now binds the T6040 and T8140 AES nodes, the only ones this driver matched. Two drivers for one compatible would race for the device, and the skcipher driver already reports the engine readiness word at probe. Assisted-by: LLM Signed-off-by: Ryan Murray --- drivers/soc/apple/Kconfig | 15 --------------- drivers/soc/apple/Makefile | 2 -- 2 files changed, 17 deletions(-) diff --git a/drivers/soc/apple/Kconfig b/drivers/soc/apple/Kconfig index 68b1ee93c13c8..f0f6080e11a5e 100644 --- a/drivers/soc/apple/Kconfig +++ b/drivers/soc/apple/Kconfig @@ -4,21 +4,6 @@ if ARCH_APPLE || COMPILE_TEST menu "Apple SoC drivers" -config APPLE_SIO_AES - tristate "Apple SIO AES probe-time diagnostics" - depends on OF && HAS_IOMEM && PM && IOMMU_API - help - Capture the S8000-family AES readiness and hardware-key disable - state once at probe on T6041 and T8140. T6000 and T8112 are served - by the CRYPTO_DEV_APPLE_SIO_AES skcipher driver instead. The snapshot - is logged and available in a root-readable debugfs state file. - Revision is reported from the SoC compatible; register words are - raw diagnostics, not a claim that a hardware key is usable. - - This does not enable the engine, submit commands, handle interrupts, - register crypto algorithms or provide a device node. Keep the DT - node disabled except during an explicitly enabled diagnostic boot. - config APPLE_DBGVIEW tristate "Apple SoC read-only debug register views" depends on ARCH_APPLE || COMPILE_TEST diff --git a/drivers/soc/apple/Makefile b/drivers/soc/apple/Makefile index 4b28f67cdc58c..5065bb7a1324a 100644 --- a/drivers/soc/apple/Makefile +++ b/drivers/soc/apple/Makefile @@ -1,7 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only -obj-$(CONFIG_APPLE_SIO_AES) += apple-sio-aes.o - obj-$(CONFIG_APPLE_DBGVIEW) += apple-dbgview.o apple-dbgview-y = dbgview.o From a47236d28f090585bb0fceed4ffc37add9f56ffd Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Thu, 12 Nov 2026 13:32:44 +1100 Subject: [PATCH 3/3] arm64: dts: apple: t6040-j616s: enable the SIO AES engine The skcipher driver now drives the revision 5 engine. Enable the engine and its power state on the J616s. Assisted-by: LLM Signed-off-by: Ryan Murray --- arch/arm64/boot/dts/apple/t6040-j616s.dts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t6040-j616s.dts b/arch/arm64/boot/dts/apple/t6040-j616s.dts index 4db35d6672053..5ceebc5d733b4 100644 --- a/arch/arm64/boot/dts/apple/t6040-j616s.dts +++ b/arch/arm64/boot/dts/apple/t6040-j616s.dts @@ -320,3 +320,12 @@ &ps_uart0 { status = "okay"; }; + +/* SIO AES engine, software keys only. */ +&ps_aes { + status = "okay"; +}; + +&aes { + status = "okay"; +};