From 25bd73562941b04cfba1a278d8c84f2b1c69b8e9 Mon Sep 17 00:00:00 2001 From: Maxime Ripard Date: Tue, 31 Mar 2026 12:00:10 +0200 Subject: dma: contiguous: Turn heap registration logic around The CMA heap instantiation was initially developed by having the contiguous DMA code call into the CMA heap to create a new instance every time a reserved memory area is probed. Turning the CMA heap into a module would create a dependency of the kernel on a module, which doesn't work. Let's turn the logic around and do the opposite: store all the reserved memory CMA regions into the contiguous DMA code, and provide an iterator for the heap to use when it probes. Signed-off-by: Maxime Ripard Signed-off-by: Marek Szyprowski Link: https://lore.kernel.org/r/20260331-dma-buf-heaps-as-modules-v4-1-e18fda504419@kernel.org --- include/linux/dma-buf/heaps/cma.h | 16 ---------------- include/linux/dma-map-ops.h | 5 +++++ 2 files changed, 5 insertions(+), 16 deletions(-) delete mode 100644 include/linux/dma-buf/heaps/cma.h (limited to 'include/linux') diff --git a/include/linux/dma-buf/heaps/cma.h b/include/linux/dma-buf/heaps/cma.h deleted file mode 100644 index e751479e21e7..000000000000 --- a/include/linux/dma-buf/heaps/cma.h +++ /dev/null @@ -1,16 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef DMA_BUF_HEAP_CMA_H_ -#define DMA_BUF_HEAP_CMA_H_ - -struct cma; - -#ifdef CONFIG_DMABUF_HEAPS_CMA -int dma_heap_cma_register_heap(struct cma *cma); -#else -static inline int dma_heap_cma_register_heap(struct cma *cma) -{ - return 0; -} -#endif // CONFIG_DMABUF_HEAPS_CMA - -#endif // DMA_BUF_HEAP_CMA_H_ diff --git a/include/linux/dma-map-ops.h b/include/linux/dma-map-ops.h index 60b63756df82..c4c93c72ff6f 100644 --- a/include/linux/dma-map-ops.h +++ b/include/linux/dma-map-ops.h @@ -99,6 +99,7 @@ static inline struct cma *dev_get_cma_area(struct device *dev) return dev->cma_area; return dma_contiguous_default_area; } +struct cma *dma_contiguous_get_area_by_idx(unsigned int idx); void dma_contiguous_reserve(phys_addr_t addr_limit); int __init dma_contiguous_reserve_area(phys_addr_t size, phys_addr_t base, @@ -117,6 +118,10 @@ static inline struct cma *dev_get_cma_area(struct device *dev) { return NULL; } +static inline struct cma *dma_contiguous_get_area_by_idx(unsigned int idx) +{ + return NULL; +} static inline void dma_contiguous_reserve(phys_addr_t limit) { } -- cgit v1.2.3 From b3707be95f045c4e526e419435af29dc9dd1c267 Mon Sep 17 00:00:00 2001 From: Maxime Ripard Date: Tue, 31 Mar 2026 12:00:11 +0200 Subject: dma: contiguous: Make dev_get_cma_area() a proper function As we try to enable dma-buf heaps, and the CMA one in particular, to compile as modules, we need to export dev_get_cma_area(). It's currently implemented as an inline function that returns either the content of device->cma_area or dma_contiguous_default_area. Thus, it means we need to export dma_contiguous_default_area, which isn't really something we want any module to have access to. Instead, let's make dev_get_cma_area() a proper function we will be able to export so we can avoid exporting dma_contiguous_default_area. Signed-off-by: Maxime Ripard Signed-off-by: Marek Szyprowski Link: https://lore.kernel.org/r/20260331-dma-buf-heaps-as-modules-v4-2-e18fda504419@kernel.org --- include/linux/dma-map-ops.h | 7 +------ kernel/dma/contiguous.c | 8 ++++++++ 2 files changed, 9 insertions(+), 6 deletions(-) (limited to 'include/linux') diff --git a/include/linux/dma-map-ops.h b/include/linux/dma-map-ops.h index c4c93c72ff6f..8604106c0c01 100644 --- a/include/linux/dma-map-ops.h +++ b/include/linux/dma-map-ops.h @@ -93,12 +93,7 @@ static inline void set_dma_ops(struct device *dev, #ifdef CONFIG_DMA_CMA extern struct cma *dma_contiguous_default_area; -static inline struct cma *dev_get_cma_area(struct device *dev) -{ - if (dev && dev->cma_area) - return dev->cma_area; - return dma_contiguous_default_area; -} +struct cma *dev_get_cma_area(struct device *dev); struct cma *dma_contiguous_get_area_by_idx(unsigned int idx); void dma_contiguous_reserve(phys_addr_t addr_limit); diff --git a/kernel/dma/contiguous.c b/kernel/dma/contiguous.c index afa9fd313040..40a0ead24979 100644 --- a/kernel/dma/contiguous.c +++ b/kernel/dma/contiguous.c @@ -131,6 +131,14 @@ bool __init cma_skip_dt_default_reserved_mem(void) return size_cmdline != -1; } +struct cma *dev_get_cma_area(struct device *dev) +{ + if (dev && dev->cma_area) + return dev->cma_area; + + return dma_contiguous_default_area; +} + #ifdef CONFIG_DMA_NUMA_CMA static struct cma *dma_contiguous_numa_area[MAX_NUMNODES]; -- cgit v1.2.3 From 633040f853467a490437ace26d6a5413e64c0dd0 Mon Sep 17 00:00:00 2001 From: Maxime Ripard Date: Tue, 31 Mar 2026 12:00:12 +0200 Subject: dma: contiguous: Make dma_contiguous_default_area static Now that dev_get_cma_area() is no longer inline, we don't have any user of dma_contiguous_default_area() outside of contiguous.c so we can make it static. Signed-off-by: Maxime Ripard Signed-off-by: Marek Szyprowski Link: https://lore.kernel.org/r/20260331-dma-buf-heaps-as-modules-v4-3-e18fda504419@kernel.org --- include/linux/dma-map-ops.h | 2 -- kernel/dma/contiguous.c | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) (limited to 'include/linux') diff --git a/include/linux/dma-map-ops.h b/include/linux/dma-map-ops.h index 8604106c0c01..bef279ebeae7 100644 --- a/include/linux/dma-map-ops.h +++ b/include/linux/dma-map-ops.h @@ -91,8 +91,6 @@ static inline void set_dma_ops(struct device *dev, #endif /* CONFIG_ARCH_HAS_DMA_OPS */ #ifdef CONFIG_DMA_CMA -extern struct cma *dma_contiguous_default_area; - struct cma *dev_get_cma_area(struct device *dev); struct cma *dma_contiguous_get_area_by_idx(unsigned int idx); diff --git a/kernel/dma/contiguous.c b/kernel/dma/contiguous.c index 40a0ead24979..fd8d3518a232 100644 --- a/kernel/dma/contiguous.c +++ b/kernel/dma/contiguous.c @@ -83,7 +83,7 @@ struct cma *dma_contiguous_get_area_by_idx(unsigned int idx) } EXPORT_SYMBOL_GPL(dma_contiguous_get_area_by_idx); -struct cma *dma_contiguous_default_area; +static struct cma *dma_contiguous_default_area; /* * Default global CMA area size can be defined in kernel's .config. -- cgit v1.2.3