diff --git a/arch/arm64/boot/dts/apple/t6050-j775c.dts b/arch/arm64/boot/dts/apple/t6050-j775c.dts index b0cc617d2c849..1d8cb0f216fdb 100644 --- a/arch/arm64/boot/dts/apple/t6050-j775c.dts +++ b/arch/arm64/boot/dts/apple/t6050-j775c.dts @@ -3012,6 +3012,7 @@ interrupt-parent = <&aic>; interrupts = <0x00 0x00 0x3ba 0x04>, <0x00 0x00 0x3c7 0x04>; iommus = <&ane_dart0 0x00>, <&ane_dart1 0x00>, <&ane_dart2 0x00>; + dma-coherent; power-domains = <&ps_ane_sys>; memory-region = <&ane_fw_text>, <&ane_fw_data>; memory-region-names = "firmware-text", "firmware-data"; diff --git a/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi b/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi index 3f6945022e52b..7e36bb42f4228 100644 --- a/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi +++ b/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi @@ -3398,6 +3398,7 @@ interrupts = , ; iommus = <&ane0_dart 0>, <&ane0_dart1 0>, <&ane0_dart2 0>; + dma-coherent; power-domains = <&ps_ane_sys>; clocks = <&peripheral_clocks 335>, <&peripheral_clocks 334>, <&peripheral_clocks 381>; apple,firmware-preloaded; diff --git a/drivers/accel/ane/ane_fw_cold.c b/drivers/accel/ane/ane_fw_cold.c index 643ceb067e672..f66effcf67a4d 100644 --- a/drivers/accel/ane/ane_fw_cold.c +++ b/drivers/accel/ane/ane_fw_cold.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -1961,6 +1962,11 @@ static void ane_fw_pages_release(struct ane_fw_backend *b, struct ane_fw_mapping * its mapping only does the cache maintenance, so its addresses must be the * physical ones. */ +static bool ane_fw_program_coherent(const struct ane_fw_backend *b) +{ + return dev_is_dma_coherent(&b->pdev->dev); +} + static int ane_fw_alloc_pages(struct ane_fw_backend *b, size_t size, struct ane_fw_mapping *m) { struct scatterlist *sg; @@ -1985,7 +1991,9 @@ static int ane_fw_alloc_pages(struct ane_fw_backend *b, size_t size, struct ane_ GFP_KERNEL_ACCOUNT | __GFP_NOWARN); if (ret) return ret; - /* Writes the zeroes back before the engine sees the pages. */ + if (ane_fw_program_coherent(b)) + return 0; + /* Writes the zeroes back before a non-snooping engine sees the pages. */ ret = dma_map_sgtable(b->memory, &m->sgt, DMA_BIDIRECTIONAL, 0); if (ret) return ret; @@ -2672,11 +2680,13 @@ static int ane_fw_startup(struct ane_fw_backend *b) static int ane_fw_program_map(void *ctx, size_t size, bool write, struct ane_fw_surface *out) { struct ane_fw_backend *b = ctx; + int prot = IOMMU_READ | (write ? IOMMU_WRITE : 0); if (!size || !IS_ALIGNED(size, SZ_16K)) return -ENOSPC; - return ane_fw_alloc_mem(b, ANE_FW_WINDOW_ANY, size, - IOMMU_READ | (write ? IOMMU_WRITE : 0), true, out); + if (ane_fw_program_coherent(b)) + prot |= IOMMU_CACHE; + return ane_fw_alloc_mem(b, ANE_FW_WINDOW_ANY, size, prot, true, out); } /* @@ -2727,12 +2737,18 @@ static void ane_fw_program_log(void *ctx, const char *item, u64 a, u64 c) dev_info(&b->pdev->dev, "H17 %s %llx %llx\n", item, a, c); } -/* Program surfaces are cacheable: clean before the engine, invalidate after. */ +/* + * Program surfaces are cacheable: clean before and invalidate after when the + * engine does not snoop. Coherent devices map with IOMMU_CACHE and need no + * software cache maintenance. + */ static void ane_fw_program_sync(void *ctx, const struct ane_fw_surface *s, bool for_device) { struct ane_fw_backend *b = ctx; struct ane_fw_mapping *m = (struct ane_fw_mapping *)(uintptr_t)s->handle; + if (ane_fw_program_coherent(b)) + return; if (for_device) dma_sync_sgtable_for_device(b->memory, &m->sgt, DMA_BIDIRECTIONAL); else