Skip to content
Merged
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
1 change: 1 addition & 0 deletions arch/arm64/boot/dts/apple/t6050-j775c.dts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
1 change: 1 addition & 0 deletions arch/arm64/boot/dts/apple/t6050-peripherals.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -3398,6 +3398,7 @@
interrupts = <AIC_IRQ 0 954 IRQ_TYPE_LEVEL_HIGH>,
<AIC_IRQ 0 967 IRQ_TYPE_LEVEL_HIGH>;
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;
Expand Down
24 changes: 20 additions & 4 deletions drivers/accel/ane/ane_fw_cold.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <linux/crash_dump.h>
#include <linux/debugfs.h>
#include <linux/delay.h>
#include <linux/dma-map-ops.h>
#include <linux/dma-mapping.h>
#include <linux/io.h>
#include <linux/iommu.h>
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}

/*
Expand Down Expand Up @@ -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
Expand Down
Loading