xref: /linux/Documentation/userspace-api/dma-buf-heaps.rst (revision face6a3615a649456eb4549f6d474221d877d604)
1.. SPDX-License-Identifier: GPL-2.0
2
3==============================
4Allocating dma-buf using heaps
5==============================
6
7Dma-buf Heaps are a way for userspace to allocate dma-buf objects. They are
8typically used to allocate buffers from a specific allocation pool, or to share
9buffers across frameworks.
10
11Heaps
12=====
13
14A heap represents a specific allocator. The Linux kernel currently supports the
15following heaps:
16
17 - The ``system`` heap allocates virtually contiguous, cacheable, buffers.
18
19 - The ``default_cma_region`` heap allocates physically contiguous,
20   cacheable, buffers. Only present if a CMA region is present. Such a
21   region is usually created either through the kernel commandline
22   through the ``cma`` parameter, a memory region Device-Tree node with
23   the ``linux,cma-default`` property set, or through the
24   ``CMA_SIZE_MBYTES`` or ``CMA_SIZE_PERCENTAGE`` Kconfig options. Prior
25   to Linux 6.17, its name wasn't stable and could be called
26   ``reserved``, ``linux,cma``, or ``default-pool``, depending on the
27   platform.
28
29 - A heap will be created for each reusable region in the device tree
30   with the ``shared-dma-pool`` compatible, using the full device tree
31   node name as its name. The buffer semantics are identical to
32   ``default-cma-region``.
33
34Naming Convention
35=================
36
37``dma-buf`` heaps name should meet a number of constraints:
38
39- The name must be stable, and must not change from one version to the other.
40  Userspace identifies heaps by their name, so if the names ever change, we
41  would be likely to introduce regressions.
42
43- The name must describe the memory region the heap will allocate from, and
44  must uniquely identify it in a given platform. Since userspace applications
45  use the heap name as the discriminant, it must be able to tell which heap it
46  wants to use reliably if there's multiple heaps.
47
48- The name must not mention implementation details, such as the allocator. The
49  heap driver will change over time, and implementation details when it was
50  introduced might not be relevant in the future.
51
52- The name should describe properties of the buffers that would be allocated.
53  Doing so will make heap identification easier for userspace. Such properties
54  are:
55
56  - ``contiguous`` for physically contiguous buffers;
57
58  - ``protected`` for encrypted buffers not accessible the OS;
59
60- The name may describe intended usage. Doing so will make heap identification
61  easier for userspace applications and users.
62
63For example, assuming a platform with a reserved memory region located
64at the RAM address 0x42000000, intended to allocate video framebuffers,
65physically contiguous, and backed by the CMA kernel allocator, good
66names would be ``memory@42000000-contiguous`` or ``video@42000000``, but
67``cma-video`` wouldn't.
68