Skip to content

Commit 10314e0

Browse files
author
Christoph Hellwig
committed
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>
1 parent f1306f0 commit 10314e0

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

arch/riscv/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ config ARCH_RV64I
114114
select HAVE_FTRACE_MCOUNT_RECORD
115115
select HAVE_DYNAMIC_FTRACE
116116
select HAVE_DYNAMIC_FTRACE_WITH_REGS
117+
select SWIOTLB
117118

118119
endchoice
119120

arch/riscv/include/asm/dma-mapping.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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 */

arch/riscv/kernel/setup.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <linux/of_fdt.h>
3030
#include <linux/of_platform.h>
3131
#include <linux/sched/task.h>
32+
#include <linux/swiotlb.h>
3233

3334
#include <asm/setup.h>
3435
#include <asm/sections.h>
@@ -206,6 +207,7 @@ void __init setup_arch(char **cmdline_p)
206207
setup_bootmem();
207208
paging_init();
208209
unflatten_device_tree();
210+
swiotlb_init(1);
209211

210212
#ifdef CONFIG_SMP
211213
setup_smp();

0 commit comments

Comments
 (0)