[RFC 4/4] arm64: mm: set direct_dma_min_mask according to dma-ranges

From: Nicolas Saenz Julienne
Date: Wed Jul 17 2019 - 11:31:55 EST


Now that we parse the dma-ranges during initialization we can fine-tune
the DMA mask used by the direct DMA implementation.

We set the mask based on the size of the DMA addressable memory, and if
bigger than 4GB we force it to DMA_BIT_MASK(32) as it's always been.

Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@xxxxxxx>
---
arch/arm64/mm/init.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
index 5708adf0db52..f8af2c99667c 100644
--- a/arch/arm64/mm/init.c
+++ b/arch/arm64/mm/init.c
@@ -52,6 +52,8 @@ EXPORT_SYMBOL(memstart_addr);

phys_addr_t arm64_dma_phys_limit __ro_after_init;

+extern u64 dma_direct_min_mask;
+
#ifdef CONFIG_KEXEC_CORE
/*
* reserve_crashkernel() - reserves memory for crash kernel
@@ -198,8 +200,12 @@ static int __init early_init_dt_scan_dma_ranges(unsigned long node,
if (size > (1ULL << 32))
size = 1ULL << 32;

- if (*dma_phys_limit > (phys_addr + size))
+ if (*dma_phys_limit > (phys_addr + size)) {
+ /* Set min DMA mask in case is was smaller than 32 */
+ dma_direct_min_mask = size - 1;
+
*dma_phys_limit = phys_addr + size;
+ }

return 0;
}
--
2.22.0