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 <wangkefeng.wang@huawei.com>
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
This commit is contained in:
Kefeng Wang 2021-06-02 16:55:16 +08:00 committed by Palmer Dabbelt
parent ae3d69bcc4
commit ce3aca0465
No known key found for this signature in database
GPG Key ID: 2E1319F35FBB1889
2 changed files with 8 additions and 5 deletions

View File

@ -17,7 +17,6 @@
#include <linux/of_fdt.h> #include <linux/of_fdt.h>
#include <linux/of_platform.h> #include <linux/of_platform.h>
#include <linux/sched/task.h> #include <linux/sched/task.h>
#include <linux/swiotlb.h>
#include <linux/smp.h> #include <linux/smp.h>
#include <linux/efi.h> #include <linux/efi.h>
#include <linux/crash_dump.h> #include <linux/crash_dump.h>
@ -295,10 +294,6 @@ void __init setup_arch(char **cmdline_p)
protect_kernel_linear_mapping_text_rodata(); protect_kernel_linear_mapping_text_rodata();
} }
#ifdef CONFIG_SWIOTLB
swiotlb_init(1);
#endif
#ifdef CONFIG_KASAN #ifdef CONFIG_KASAN
kasan_init(); kasan_init();
#endif #endif

View File

@ -11,6 +11,7 @@
#include <linux/memblock.h> #include <linux/memblock.h>
#include <linux/initrd.h> #include <linux/initrd.h>
#include <linux/swap.h> #include <linux/swap.h>
#include <linux/swiotlb.h>
#include <linux/sizes.h> #include <linux/sizes.h>
#include <linux/of_fdt.h> #include <linux/of_fdt.h>
#include <linux/of_reserved_mem.h> #include <linux/of_reserved_mem.h>
@ -109,6 +110,13 @@ void __init mem_init(void)
BUG_ON(!mem_map); BUG_ON(!mem_map);
#endif /* CONFIG_FLATMEM */ #endif /* CONFIG_FLATMEM */
#ifdef CONFIG_SWIOTLB
if (swiotlb_force == SWIOTLB_FORCE ||
max_pfn > PFN_DOWN(dma32_phys_limit))
swiotlb_init(1);
else
swiotlb_force = SWIOTLB_NO_FORCE;
#endif
high_memory = (void *)(__va(PFN_PHYS(max_low_pfn))); high_memory = (void *)(__va(PFN_PHYS(max_low_pfn)));
memblock_free_all(); memblock_free_all();