Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

riscv: add swiotlb support

All RISC-V platforms today lack an IOMMU. However, legacy PCI devices
sometimes require DMA-memory to be in the low 32 bits. To make this work,
we enable the software-based bounce buffers from swiotlb. They only impose
overhead when the device in question cannot address the full 64-bit address
space, so a perfect fit.

This patch assumes that DMA is coherent with the processor and the PCI
bus. It also assumes that the processor and devices share a common
address space. This is true for all RISC-V platforms so far.

[changelog stolen from an earlier patch by Palmer Dabbelt that did the
more complicated swiotlb wireup before the recent consolidation]

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Palmer Dabbelt <palmer@sifive.com>

+18
+1
arch/riscv/Kconfig
··· 114 114 select HAVE_FTRACE_MCOUNT_RECORD 115 115 select HAVE_DYNAMIC_FTRACE 116 116 select HAVE_DYNAMIC_FTRACE_WITH_REGS 117 + select SWIOTLB 117 118 118 119 endchoice 119 120
+15
arch/riscv/include/asm/dma-mapping.h
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + #ifndef _RISCV_ASM_DMA_MAPPING_H 3 + #define _RISCV_ASM_DMA_MAPPING_H 1 4 + 5 + #ifdef CONFIG_SWIOTLB 6 + #include <linux/swiotlb.h> 7 + static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus) 8 + { 9 + return &swiotlb_dma_ops; 10 + } 11 + #else 12 + #include <asm-generic/dma-mapping.h> 13 + #endif /* CONFIG_SWIOTLB */ 14 + 15 + #endif /* _RISCV_ASM_DMA_MAPPING_H */
+2
arch/riscv/kernel/setup.c
··· 29 29 #include <linux/of_fdt.h> 30 30 #include <linux/of_platform.h> 31 31 #include <linux/sched/task.h> 32 + #include <linux/swiotlb.h> 32 33 33 34 #include <asm/setup.h> 34 35 #include <asm/sections.h> ··· 207 206 setup_bootmem(); 208 207 paging_init(); 209 208 unflatten_device_tree(); 209 + swiotlb_init(1); 210 210 211 211 #ifdef CONFIG_SMP 212 212 setup_smp();