summaryrefslogtreecommitdiff
path: root/kernel/dma/contiguous.c
diff options
context:
space:
mode:
authorMaxime Ripard <mripard@kernel.org>2026-03-31 12:00:10 +0200
committerMarek Szyprowski <m.szyprowski@samsung.com>2026-03-31 13:27:20 +0200
commit25bd73562941b04cfba1a278d8c84f2b1c69b8e9 (patch)
tree3a02911ae2bdbbf0407f143c1622d5716c88f58f /kernel/dma/contiguous.c
parent6de23f81a5e08be8fbf5e8d7e9febc72a5b5f27f (diff)
downloadlinux-next-25bd73562941b04cfba1a278d8c84f2b1c69b8e9.tar.gz
linux-next-25bd73562941b04cfba1a278d8c84f2b1c69b8e9.zip
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 <mripard@kernel.org> Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com> Link: https://lore.kernel.org/r/20260331-dma-buf-heaps-as-modules-v4-1-e18fda504419@kernel.org
Diffstat (limited to 'kernel/dma/contiguous.c')
-rw-r--r--kernel/dma/contiguous.c55
1 files changed, 50 insertions, 5 deletions
diff --git a/kernel/dma/contiguous.c b/kernel/dma/contiguous.c
index c56004d314dc..afa9fd313040 100644
--- a/kernel/dma/contiguous.c
+++ b/kernel/dma/contiguous.c
@@ -42,7 +42,6 @@
#include <linux/memblock.h>
#include <linux/err.h>
#include <linux/sizes.h>
-#include <linux/dma-buf/heaps/cma.h>
#include <linux/dma-map-ops.h>
#include <linux/cma.h>
#include <linux/nospec.h>
@@ -53,6 +52,37 @@
#define CMA_SIZE_MBYTES 0
#endif
+static struct cma *dma_contiguous_areas[MAX_CMA_AREAS];
+static unsigned int dma_contiguous_areas_num;
+
+static int dma_contiguous_insert_area(struct cma *cma)
+{
+ if (dma_contiguous_areas_num >= ARRAY_SIZE(dma_contiguous_areas))
+ return -EINVAL;
+
+ dma_contiguous_areas[dma_contiguous_areas_num++] = cma;
+
+ return 0;
+}
+
+/**
+ * dma_contiguous_get_area_by_idx() - Get contiguous area at given index
+ * @idx: index of the area we query
+ *
+ * Queries for the contiguous area located at index @idx.
+ *
+ * Returns:
+ * A pointer to the requested contiguous area, or NULL otherwise.
+ */
+struct cma *dma_contiguous_get_area_by_idx(unsigned int idx)
+{
+ if (idx >= dma_contiguous_areas_num)
+ return NULL;
+
+ return dma_contiguous_areas[idx];
+}
+EXPORT_SYMBOL_GPL(dma_contiguous_get_area_by_idx);
+
struct cma *dma_contiguous_default_area;
/*
@@ -264,9 +294,24 @@ void __init dma_contiguous_reserve(phys_addr_t limit)
if (ret)
return;
- ret = dma_heap_cma_register_heap(dma_contiguous_default_area);
+ /*
+ * We need to insert the new area in our list to avoid
+ * any inconsistencies between having the default area
+ * listed in the DT or not.
+ *
+ * The DT case is handled by rmem_cma_setup() and will
+ * always insert all its areas in our list. However, if
+ * it didn't run (because OF_RESERVED_MEM isn't set, or
+ * there's no DT region specified), then we don't have a
+ * default area yet, and no area in our list.
+ *
+ * This block creates the default area in such a case,
+ * but we also need to insert it in our list to avoid
+ * having a default area but an empty list.
+ */
+ ret = dma_contiguous_insert_area(dma_contiguous_default_area);
if (ret)
- pr_warn("Couldn't register default CMA heap.");
+ pr_warn("Couldn't queue default CMA region for heap creation.");
}
}
@@ -506,9 +551,9 @@ static int __init rmem_cma_setup(struct reserved_mem *rmem)
pr_info("Reserved memory: created CMA memory pool at %pa, size %ld MiB\n",
&rmem->base, (unsigned long)rmem->size / SZ_1M);
- err = dma_heap_cma_register_heap(cma);
+ err = dma_contiguous_insert_area(cma);
if (err)
- pr_warn("Couldn't register CMA heap.");
+ pr_warn("Couldn't store CMA reserved area.");
return 0;
}