From 09f7a20166f58b5524057c9a9c9ec31a9e800575 Mon Sep 17 00:00:00 2001 From: Jagadeesh Pagadala Date: Sat, 13 Jun 2026 09:25:14 +0530 Subject: [PATCH] QCLINUX: dma: swiotlb: introduce CONFIG_SWIOTLB_DEFAULT_SIZE_MB Kconfig MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SWIOTLB default pool size is currently fixed at 64 MB via IO_TLB_DEFAULT_SIZE, with runtime override only possible through "swiotlb=" kernel parameter. Introduce CONFIG_SWIOTLB_DEFAULT_SIZE_MB to allow setting the default SWIOTLB size at compile time. This integer option (range: 1–64 MB) depends on CONFIG_SWIOTLB and defaults to 64 MB, preserving existing behavior. Update IO_TLB_DEFAULT_SIZE to derive from this Kconfig option, with fallback to 64 MB when SWIOTLB is disabled. Set CONFIG_SWIOTLB_DEFAULT_SIZE_MB to 2 MB to reduce default SWIOTLB memory footprint. Default behavior remains unchanged unless configured. Runtime "swiotlb=" override remains supported. Signed-off-by: Jagadeesh Pagadala --- arch/arm64/configs/qcom.config | 1 + include/linux/swiotlb.h | 12 ++++++++++-- kernel/dma/Kconfig | 21 +++++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/arch/arm64/configs/qcom.config b/arch/arm64/configs/qcom.config index 9466461272165..8d923fd7854d3 100644 --- a/arch/arm64/configs/qcom.config +++ b/arch/arm64/configs/qcom.config @@ -57,6 +57,7 @@ CONFIG_STM_PROTO_SYS_T=m CONFIG_STM_SOURCE_CONSOLE=m CONFIG_STM_SOURCE_FTRACE=m CONFIG_STM_SOURCE_HEARTBEAT=m +CONFIG_SWIOTLB_DEFAULT_SIZE_MB=2 CONFIG_SENSORS_AMC6821=y CONFIG_SENSORS_EMC2305=y CONFIG_SENSORS_QCOM_BCL=y diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h index 3dae0f592063e..aef861f1e2d7e 100644 --- a/include/linux/swiotlb.h +++ b/include/linux/swiotlb.h @@ -32,8 +32,16 @@ struct scatterlist; #define IO_TLB_SHIFT 11 #define IO_TLB_SIZE (1 << IO_TLB_SHIFT) -/* default to 64MB */ -#define IO_TLB_DEFAULT_SIZE (64UL<<20) +/* + * Default SWIOTLB bounce buffer pool size. + * Configurable at compile time via CONFIG_SWIOTLB_DEFAULT_SIZE_MB. + * Falls back to 64 MB if not set via Kconfig. + */ +#if defined(CONFIG_SWIOTLB) && defined(CONFIG_SWIOTLB_DEFAULT_SIZE_MB) +#define IO_TLB_DEFAULT_SIZE ((unsigned long)CONFIG_SWIOTLB_DEFAULT_SIZE_MB << 20) +#else +#define IO_TLB_DEFAULT_SIZE (64UL << 20) +#endif unsigned long swiotlb_size_or_default(void); void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags, diff --git a/kernel/dma/Kconfig b/kernel/dma/Kconfig index 31cfdb6b4bc3e..5f225adf9f837 100644 --- a/kernel/dma/Kconfig +++ b/kernel/dma/Kconfig @@ -89,6 +89,27 @@ config SWIOTLB bool select NEED_DMA_MAP_STATE +config SWIOTLB_DEFAULT_SIZE_MB + int "Default SWIOTLB bounce buffer size in MB" + depends on SWIOTLB + range 1 64 + default 64 + help + Sets the default size of the software IO TLB (SWIOTLB) bounce buffer + pool allocated at boot time. The default is 64 MB. + + On memory-constrained embedded or mobile platforms (e.g., those with + a hardware IOMMU such as ARM SMMU covering most DMA-capable devices), + a smaller value such as 4 or 8 MB may be sufficient. The SWIOTLB is + then only needed for devices that bypass the IOMMU or have restricted + DMA address ranges. + + The minimum allowed value is 1 MB. This compile-time default can be + overridden at runtime using the "swiotlb=" kernel command line + parameter, where nslabs = (desired_size_in_bytes / 2048). + + If unsure, leave at the default value of 64. + config SWIOTLB_DYNAMIC bool "Dynamic allocation of DMA bounce buffers" default n