dma-buf-heaps.rst 2.7 KB

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