Skip to content

Commit b67a8b2

Browse files
Jisheng Zhangctmarinas
authored andcommitted
arm64: mm: only initialize swiotlb when necessary
we only initialize swiotlb when swiotlb_force is true or not all system memory is DMA-able, this trivial optimization saves us 64MB when swiotlb is not necessary. Signed-off-by: Jisheng Zhang <jszhang@marvell.com> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
1 parent 83ce0ef commit b67a8b2

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

arch/arm64/mm/dma-mapping.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include <linux/gfp.h>
2121
#include <linux/acpi.h>
22+
#include <linux/bootmem.h>
2223
#include <linux/export.h>
2324
#include <linux/slab.h>
2425
#include <linux/genalloc.h>
@@ -29,6 +30,8 @@
2930

3031
#include <asm/cacheflush.h>
3132

33+
static int swiotlb __read_mostly;
34+
3235
static pgprot_t __get_dma_pgprot(struct dma_attrs *attrs, pgprot_t prot,
3336
bool coherent)
3437
{
@@ -341,6 +344,13 @@ static int __swiotlb_get_sgtable(struct device *dev, struct sg_table *sgt,
341344
return ret;
342345
}
343346

347+
static int __swiotlb_dma_supported(struct device *hwdev, u64 mask)
348+
{
349+
if (swiotlb)
350+
return swiotlb_dma_supported(hwdev, mask);
351+
return 1;
352+
}
353+
344354
static struct dma_map_ops swiotlb_dma_ops = {
345355
.alloc = __dma_alloc,
346356
.free = __dma_free,
@@ -354,7 +364,7 @@ static struct dma_map_ops swiotlb_dma_ops = {
354364
.sync_single_for_device = __swiotlb_sync_single_for_device,
355365
.sync_sg_for_cpu = __swiotlb_sync_sg_for_cpu,
356366
.sync_sg_for_device = __swiotlb_sync_sg_for_device,
357-
.dma_supported = swiotlb_dma_supported,
367+
.dma_supported = __swiotlb_dma_supported,
358368
.mapping_error = swiotlb_dma_mapping_error,
359369
};
360370

@@ -513,6 +523,9 @@ EXPORT_SYMBOL(dummy_dma_ops);
513523

514524
static int __init arm64_dma_init(void)
515525
{
526+
if (swiotlb_force || max_pfn > (arm64_dma_phys_limit >> PAGE_SHIFT))
527+
swiotlb = 1;
528+
516529
return atomic_pool_init();
517530
}
518531
arch_initcall(arm64_dma_init);

arch/arm64/mm/init.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,8 @@ static void __init free_unused_memmap(void)
403403
*/
404404
void __init mem_init(void)
405405
{
406-
swiotlb_init(1);
406+
if (swiotlb_force || max_pfn > (arm64_dma_phys_limit >> PAGE_SHIFT))
407+
swiotlb_init(1);
407408

408409
set_max_mapnr(pfn_to_page(max_pfn) - mem_map);
409410

0 commit comments

Comments
 (0)