Skip to content

Commit ce3aca0

Browse files
Kefeng Wangpalmer-dabbelt
authored andcommitted
riscv: Only initialize swiotlb when necessary
The SWIOTLB buffer is not needed unless the physical address space is beyond the limit of dma, only initialize swiotlb when swiotlb_force is true or not all system memory is DMA-able. Also move the swiotlb_init() into mem_init(). Signed-off-by: Kefeng Wang <[email protected]> Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent ae3d69b commit ce3aca0

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

arch/riscv/kernel/setup.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include <linux/of_fdt.h>
1818
#include <linux/of_platform.h>
1919
#include <linux/sched/task.h>
20-
#include <linux/swiotlb.h>
2120
#include <linux/smp.h>
2221
#include <linux/efi.h>
2322
#include <linux/crash_dump.h>
@@ -295,10 +294,6 @@ void __init setup_arch(char **cmdline_p)
295294
protect_kernel_linear_mapping_text_rodata();
296295
}
297296

298-
#ifdef CONFIG_SWIOTLB
299-
swiotlb_init(1);
300-
#endif
301-
302297
#ifdef CONFIG_KASAN
303298
kasan_init();
304299
#endif

arch/riscv/mm/init.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/memblock.h>
1212
#include <linux/initrd.h>
1313
#include <linux/swap.h>
14+
#include <linux/swiotlb.h>
1415
#include <linux/sizes.h>
1516
#include <linux/of_fdt.h>
1617
#include <linux/of_reserved_mem.h>
@@ -109,6 +110,13 @@ void __init mem_init(void)
109110
BUG_ON(!mem_map);
110111
#endif /* CONFIG_FLATMEM */
111112

113+
#ifdef CONFIG_SWIOTLB
114+
if (swiotlb_force == SWIOTLB_FORCE ||
115+
max_pfn > PFN_DOWN(dma32_phys_limit))
116+
swiotlb_init(1);
117+
else
118+
swiotlb_force = SWIOTLB_NO_FORCE;
119+
#endif
112120
high_memory = (void *)(__va(PFN_PHYS(max_low_pfn)));
113121
memblock_free_all();
114122

0 commit comments

Comments
 (0)