Commit faa406f4 authored by Daniel Thompson's avatar Daniel Thompson Committed by Daniel Vetter

drm/cma-helper: Describe what a "contiguous chunk" actually means

Since it's inception in 2012 it has been understood that the DRM GEM CMA
helpers do not depend on CMA as the backend allocator. In fact the first
bug fix to ensure the cma-helpers work correctly with an IOMMU backend
appeared in 2014. However currently the documentation for
drm_gem_cma_create() talks about "a contiguous chunk of memory" without
making clear which address space it will be a contiguous part of.
Additionally the CMA introduction is actively misleading because it only
contemplates the CMA backend.

This matters because when the device accesses the bus through an IOMMU
(and don't use the CMA backend) then the allocated memory is contiguous
only in the IOVA space. This is a significant difference compared to the
CMA backend and the behaviour can be a surprise even to someone who does
a reasonable level of code browsing (but doesn't find all the relevant
function pointers ;-) ).

Improve the kernel doc comments accordingly.
Signed-off-by: default avatarDaniel Thompson <daniel.thompson@linaro.org>
Reviewed-by: default avatarLucas Stach <l.stach@pengutronix.de>
Signed-off-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20220608135821.1153346-1-daniel.thompson@linaro.org
parent 59474049
...@@ -26,12 +26,22 @@ ...@@ -26,12 +26,22 @@
/** /**
* DOC: cma helpers * DOC: cma helpers
* *
* The Contiguous Memory Allocator reserves a pool of memory at early boot * The DRM GEM/CMA helpers are a means to provide buffer objects that are
* that is used to service requests for large blocks of contiguous memory. * presented to the device as a contiguous chunk of memory. This is useful
* for devices that do not support scatter-gather DMA (either directly or
* by using an intimately attached IOMMU).
* *
* The DRM GEM/CMA helpers use this allocator as a means to provide buffer * Despite the name, the DRM GEM/CMA helpers are not hardwired to use the
* objects that are physically contiguous in memory. This is useful for * Contiguous Memory Allocator (CMA).
* display drivers that are unable to map scattered buffers via an IOMMU. *
* For devices that access the memory bus through an (external) IOMMU then
* the buffer objects are allocated using a traditional page-based
* allocator and may be scattered through physical memory. However they
* are contiguous in the IOVA space so appear contiguous to devices using
* them.
*
* For other devices then the helpers rely on CMA to provide buffer
* objects that are physically contiguous in memory.
* *
* For GEM callback helpers in struct &drm_gem_object functions, see likewise * For GEM callback helpers in struct &drm_gem_object functions, see likewise
* named functions with an _object_ infix (e.g., drm_gem_cma_object_vmap() wraps * named functions with an _object_ infix (e.g., drm_gem_cma_object_vmap() wraps
...@@ -111,8 +121,14 @@ __drm_gem_cma_create(struct drm_device *drm, size_t size, bool private) ...@@ -111,8 +121,14 @@ __drm_gem_cma_create(struct drm_device *drm, size_t size, bool private)
* @drm: DRM device * @drm: DRM device
* @size: size of the object to allocate * @size: size of the object to allocate
* *
* This function creates a CMA GEM object and allocates a contiguous chunk of * This function creates a CMA GEM object and allocates memory as backing store.
* memory as backing store. * The allocated memory will occupy a contiguous chunk of bus address space.
*
* For devices that are directly connected to the memory bus then the allocated
* memory will be physically contiguous. For devices that access through an
* IOMMU, then the allocated memory is not expected to be physically contiguous
* because having contiguous IOVAs is sufficient to meet a devices DMA
* requirements.
* *
* Returns: * Returns:
* A struct drm_gem_cma_object * on success or an ERR_PTR()-encoded negative * A struct drm_gem_cma_object * on success or an ERR_PTR()-encoded negative
...@@ -162,9 +178,12 @@ EXPORT_SYMBOL_GPL(drm_gem_cma_create); ...@@ -162,9 +178,12 @@ EXPORT_SYMBOL_GPL(drm_gem_cma_create);
* @size: size of the object to allocate * @size: size of the object to allocate
* @handle: return location for the GEM handle * @handle: return location for the GEM handle
* *
* This function creates a CMA GEM object, allocating a physically contiguous * This function creates a CMA GEM object, allocating a chunk of memory as
* chunk of memory as backing store. The GEM object is then added to the list * backing store. The GEM object is then added to the list of object associated
* of object associated with the given file and a handle to it is returned. * with the given file and a handle to it is returned.
*
* The allocated memory will occupy a contiguous chunk of bus address space.
* See drm_gem_cma_create() for more details.
* *
* Returns: * Returns:
* A struct drm_gem_cma_object * on success or an ERR_PTR()-encoded negative * A struct drm_gem_cma_object * on success or an ERR_PTR()-encoded negative
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment