Skip to content

Commit 854acbe

Browse files
rh-jkangassumitsemwal
authored andcommitted
dma-buf: heaps: Give default CMA heap a fixed name
The CMA heap's name in devtmpfs can vary depending on how the heap is defined. Its name defaults to "reserved", but if a CMA area is defined in the devicetree, the heap takes on the devicetree node's name, such as "default-pool" or "linux,cma". To simplify naming, unconditionally name it "default_cma_region", but keep a legacy node in place backed by the same underlying allocator for backwards compatibility. Reviewed-by: Maxime Ripard <[email protected]> Signed-off-by: Jared Kangas <[email protected]> Signed-off-by: Sumit Semwal <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 86e59cc commit 854acbe

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

Documentation/userspace-api/dma-buf-heaps.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,8 @@ following heaps:
2121
usually created either through the kernel commandline through the
2222
``cma`` parameter, a memory region Device-Tree node with the
2323
``linux,cma-default`` property set, or through the ``CMA_SIZE_MBYTES`` or
24-
``CMA_SIZE_PERCENTAGE`` Kconfig options. Depending on the platform, it
25-
might be called ``reserved``, ``linux,cma``, or ``default-pool``.
24+
``CMA_SIZE_PERCENTAGE`` Kconfig options. The heap's name in devtmpfs is
25+
``default_cma_region``. For backwards compatibility, when the
26+
``DMABUF_HEAPS_CMA_LEGACY`` Kconfig option is set, a duplicate node is
27+
created following legacy naming conventions; the legacy name might be
28+
``reserved``, ``linux,cma``, or ``default-pool``.

drivers/dma-buf/heaps/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,13 @@ config DMABUF_HEAPS_CMA
1212
Choose this option to enable dma-buf CMA heap. This heap is backed
1313
by the Contiguous Memory Allocator (CMA). If your system has these
1414
regions, you should say Y here.
15+
16+
config DMABUF_HEAPS_CMA_LEGACY
17+
bool "Legacy DMA-BUF CMA Heap"
18+
default y
19+
depends on DMABUF_HEAPS_CMA
20+
help
21+
Add a duplicate CMA-backed dma-buf heap with legacy naming derived
22+
from the CMA area's devicetree node, or "reserved" if the area is not
23+
defined in the devicetree. This uses the same underlying allocator as
24+
CONFIG_DMABUF_HEAPS_CMA.

drivers/dma-buf/heaps/cma_heap.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
* Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/
1010
* Andrew F. Davis <[email protected]>
1111
*/
12+
13+
#define pr_fmt(fmt) "cma_heap: " fmt
14+
1215
#include <linux/cma.h>
1316
#include <linux/dma-buf.h>
1417
#include <linux/dma-heap.h>
@@ -22,6 +25,7 @@
2225
#include <linux/slab.h>
2326
#include <linux/vmalloc.h>
2427

28+
#define DEFAULT_CMA_NAME "default_cma_region"
2529

2630
struct cma_heap {
2731
struct dma_heap *heap;
@@ -394,15 +398,29 @@ static int __init __add_cma_heap(struct cma *cma, const char *name)
394398
static int __init add_default_cma_heap(void)
395399
{
396400
struct cma *default_cma = dev_get_cma_area(NULL);
401+
const char *legacy_cma_name;
397402
int ret;
398403

399404
if (!default_cma)
400405
return 0;
401406

402-
ret = __add_cma_heap(default_cma, cma_get_name(default_cma));
407+
ret = __add_cma_heap(default_cma, DEFAULT_CMA_NAME);
403408
if (ret)
404409
return ret;
405410

411+
if (IS_ENABLED(CONFIG_DMABUF_HEAPS_CMA_LEGACY)) {
412+
legacy_cma_name = cma_get_name(default_cma);
413+
if (!strcmp(legacy_cma_name, DEFAULT_CMA_NAME)) {
414+
pr_warn("legacy name and default name are the same, skipping legacy heap\n");
415+
return 0;
416+
}
417+
418+
ret = __add_cma_heap(default_cma, legacy_cma_name);
419+
if (ret)
420+
pr_warn("failed to add legacy heap: %pe\n",
421+
ERR_PTR(ret));
422+
}
423+
406424
return 0;
407425
}
408426
module_init(add_default_cma_heap);

0 commit comments

Comments
 (0)