Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

dma-buf: heaps: cma: Register list of CMA regions at boot

In order to create a CMA heap instance for each CMA region found in the
system, we need to register each of these instances.

While it would appear trivial, the CMA regions are created super early
in the kernel boot process, before most of the subsystems are
initialized. Thus, we can't just create an exported function to create a
heap from the CMA region being initialized.

What we can do however is create a two-step process, where we collect
all the CMA regions into an array early on, and then when we initialize
the heaps we iterate over that array and create the heaps from the CMA
regions we collected.

Reviewed-by: T.J. Mercier <tjmercier@google.com>
Signed-off-by: Maxime Ripard <mripard@kernel.org>
Signed-off-by: Sumit Semwal <sumit.semwal@linaro.org>
Link: https://lore.kernel.org/r/20251013-dma-buf-ecc-heap-v8-2-04ce150ea3d9@kernel.org

authored by

Maxime Ripard and committed by
Sumit Semwal
8b5690d5 2034134d

+31
+1
MAINTAINERS
··· 7308 7308 F: drivers/dma-buf/ 7309 7309 F: include/linux/*fence.h 7310 7310 F: include/linux/dma-buf.h 7311 + F: include/linux/dma-buf/ 7311 7312 F: include/linux/dma-resv.h 7312 7313 K: \bdma_(?:buf|fence|resv)\b 7313 7314
+14
drivers/dma-buf/heaps/cma_heap.c
··· 14 14 15 15 #include <linux/cma.h> 16 16 #include <linux/dma-buf.h> 17 + #include <linux/dma-buf/heaps/cma.h> 17 18 #include <linux/dma-heap.h> 18 19 #include <linux/dma-map-ops.h> 19 20 #include <linux/err.h> ··· 27 26 #include <linux/vmalloc.h> 28 27 29 28 #define DEFAULT_CMA_NAME "default_cma_region" 29 + 30 + static struct cma *dma_areas[MAX_CMA_AREAS] __initdata; 31 + static unsigned int dma_areas_num __initdata; 32 + 33 + int __init dma_heap_cma_register_heap(struct cma *cma) 34 + { 35 + if (dma_areas_num >= ARRAY_SIZE(dma_areas)) 36 + return -EINVAL; 37 + 38 + dma_areas[dma_areas_num++] = cma; 39 + 40 + return 0; 41 + } 30 42 31 43 struct cma_heap { 32 44 struct dma_heap *heap;
+16
include/linux/dma-buf/heaps/cma.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef DMA_BUF_HEAP_CMA_H_ 3 + #define DMA_BUF_HEAP_CMA_H_ 4 + 5 + struct cma; 6 + 7 + #ifdef CONFIG_DMABUF_HEAPS_CMA 8 + int dma_heap_cma_register_heap(struct cma *cma); 9 + #else 10 + static inline int dma_heap_cma_register_heap(struct cma *cma) 11 + { 12 + return 0; 13 + } 14 + #endif // CONFIG_DMABUF_HEAPS_CMA 15 + 16 + #endif // DMA_BUF_HEAP_CMA_H_