diff options
| author | Marek Szyprowski <m.szyprowski@samsung.com> | 2026-03-31 13:31:53 +0200 |
|---|---|---|
| committer | Marek Szyprowski <m.szyprowski@samsung.com> | 2026-03-31 14:52:03 +0200 |
| commit | 27e2e9b9b49c5d5260969168b86cd238254b9105 (patch) | |
| tree | 360312000ffcb77b8d7078656821a18e13dc43f1 /kernel | |
| parent | ed734125ea6c7276aaac6e24b8fff72e51a47b18 (diff) | |
| parent | 7e72a8f8bb0d5ba89027d64e3e2aad1984d2e20d (diff) | |
| download | linux-27e2e9b9b49c5d5260969168b86cd238254b9105.tar.gz linux-27e2e9b9b49c5d5260969168b86cd238254b9105.zip | |
Merge branch 'dma-contig-for-7.1-modules-prep-v4' into dma-mapping-for-next
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Diffstat (limited to 'kernel')
| -rw-r--r-- | kernel/dma/contiguous.c | 66 |
1 files changed, 60 insertions, 6 deletions
diff --git a/kernel/dma/contiguous.c b/kernel/dma/contiguous.c index 65d216663e81..03f52bd17120 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,7 +52,38 @@ #define CMA_SIZE_MBYTES 0 #endif -struct cma *dma_contiguous_default_area; +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); + +static struct cma *dma_contiguous_default_area; /* * Default global CMA area size can be defined in kernel's .config. @@ -91,6 +121,15 @@ static int __init early_cma(char *p) } early_param("cma", early_cma); +struct cma *dev_get_cma_area(struct device *dev) +{ + if (dev && dev->cma_area) + return dev->cma_area; + + return dma_contiguous_default_area; +} +EXPORT_SYMBOL_GPL(dev_get_cma_area); + #ifdef CONFIG_DMA_NUMA_CMA static struct cma *dma_contiguous_numa_area[MAX_NUMNODES]; @@ -254,9 +293,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."); } } @@ -529,9 +583,9 @@ static int __init rmem_cma_setup(unsigned long node, 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); - ret = dma_heap_cma_register_heap(cma); + ret = dma_contiguous_insert_area(cma); if (ret) - pr_warn("Couldn't register CMA heap."); + pr_warn("Couldn't store CMA reserved area."); return 0; } |
