diff options
author | Emil Renner Berthing <kernel@esmil.dk> | 2021-06-13 02:48:31 +0300 |
---|---|---|
committer | Emil Renner Berthing <emil.renner.berthing@canonical.com> | 2022-10-25 18:36:45 +0300 |
commit | 7063bc78178e49f38c3f41fd25c8240e4f27491f (patch) | |
tree | 0aee72f0bffe106b005e5a88930751971a07f4dd | |
parent | b61c2bc9dc06cadacfdceadc4a6ee6b2f4976c0e (diff) | |
download | linux-7063bc78178e49f38c3f41fd25c8240e4f27491f.tar.xz |
RISC-V: Add non-coherent DMA support
This implements the cache management operations to support non-coherent
DMAs on RISC-V.
Signed-off-by: Atish Patra <atish.patra@wdc.com>
Signed-off-by: Emil Renner Berthing <kernel@esmil.dk>
-rw-r--r-- | arch/riscv/Kconfig | 10 | ||||
-rw-r--r-- | arch/riscv/include/asm/cache.h | 4 | ||||
-rw-r--r-- | arch/riscv/mm/Makefile | 1 | ||||
-rw-r--r-- | arch/riscv/mm/dma-noncoherent.c | 52 |
4 files changed, 67 insertions, 0 deletions
diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 696279ce03c9..e96c8a27c140 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -218,6 +218,16 @@ config PGTABLE_LEVELS config LOCKDEP_SUPPORT def_bool y +config RISCV_DMA_NONCOHERENT + bool "Support non-coherent DMA" + default SOC_STARFIVE + select ARCH_HAS_DMA_PREP_COHERENT + select ARCH_HAS_DMA_SET_UNCACHED + select ARCH_HAS_DMA_CLEAR_UNCACHED + select ARCH_HAS_SYNC_DMA_FOR_DEVICE + select ARCH_HAS_SYNC_DMA_FOR_CPU + select ARCH_HAS_SETUP_DMA_OPS + source "arch/riscv/Kconfig.socs" source "arch/riscv/Kconfig.erratas" diff --git a/arch/riscv/include/asm/cache.h b/arch/riscv/include/asm/cache.h index 9b58b104559e..d3036df23ccb 100644 --- a/arch/riscv/include/asm/cache.h +++ b/arch/riscv/include/asm/cache.h @@ -11,6 +11,10 @@ #define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT) +#ifdef CONFIG_RISCV_DMA_NONCOHERENT +#define ARCH_DMA_MINALIGN L1_CACHE_BYTES +#endif + /* * RISC-V requires the stack pointer to be 16-byte aligned, so ensure that * the flat loader aligns it accordingly. diff --git a/arch/riscv/mm/Makefile b/arch/riscv/mm/Makefile index ac7a25298a04..d76aabf4b94d 100644 --- a/arch/riscv/mm/Makefile +++ b/arch/riscv/mm/Makefile @@ -30,3 +30,4 @@ endif endif obj-$(CONFIG_DEBUG_VIRTUAL) += physaddr.o +obj-$(CONFIG_RISCV_DMA_NONCOHERENT) += dma-noncoherent.o diff --git a/arch/riscv/mm/dma-noncoherent.c b/arch/riscv/mm/dma-noncoherent.c new file mode 100644 index 000000000000..86d23046b958 --- /dev/null +++ b/arch/riscv/mm/dma-noncoherent.c @@ -0,0 +1,52 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * RISC-V specific functions to support DMA for non-coherent devices + * + * Copyright (c) 2021 Western Digital Corporation or its affiliates. + */ + +#include <linux/dma-map-ops.h> + +#include <soc/sifive/sifive_l2_cache.h> + +void arch_sync_dma_for_device(phys_addr_t paddr, size_t size, enum dma_data_direction dir) +{ + if (sifive_l2_handle_noncoherent()) + sifive_l2_flush_range(paddr, size); +} + +void arch_sync_dma_for_cpu(phys_addr_t paddr, size_t size, enum dma_data_direction dir) +{ + if (sifive_l2_handle_noncoherent()) + sifive_l2_flush_range(paddr, size); +} + +void *arch_dma_set_uncached(void *addr, size_t size) +{ + if (sifive_l2_handle_noncoherent()) + return sifive_l2_set_uncached(addr, size); + + return addr; +} + +void arch_dma_clear_uncached(void *addr, size_t size) +{ + if (sifive_l2_handle_noncoherent()) + sifive_l2_clear_uncached(addr, size); +} + +void arch_dma_prep_coherent(struct page *page, size_t size) +{ + void *flush_addr = page_address(page); + + memset(flush_addr, 0, size); + if (sifive_l2_handle_noncoherent()) + sifive_l2_flush_range(__pa(flush_addr), size); +} + +void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size, + const struct iommu_ops *iommu, bool coherent) +{ + /* If a specific device is dma-coherent, set it here */ + dev->dma_coherent = coherent; +} |