Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Daniel Thompson <daniel.thompson@linaro.org>
Reviewed-by: Lucas Stach <l.stach@pengutronix.de>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20220608135821.1153346-1-daniel.thompson@linaro.org

authored by

Daniel Thompson and committed by
Daniel Vetter
faa406f4 59474049

+29 -10
+29 -10
drivers/gpu/drm/drm_gem_cma_helper.c
··· 26 26 /** 27 27 * DOC: cma helpers 28 28 * 29 - * The Contiguous Memory Allocator reserves a pool of memory at early boot 30 - * that is used to service requests for large blocks of contiguous memory. 29 + * The DRM GEM/CMA helpers are a means to provide buffer objects that are 30 + * presented to the device as a contiguous chunk of memory. This is useful 31 + * for devices that do not support scatter-gather DMA (either directly or 32 + * by using an intimately attached IOMMU). 31 33 * 32 - * The DRM GEM/CMA helpers use this allocator as a means to provide buffer 33 - * objects that are physically contiguous in memory. This is useful for 34 - * display drivers that are unable to map scattered buffers via an IOMMU. 34 + * Despite the name, the DRM GEM/CMA helpers are not hardwired to use the 35 + * Contiguous Memory Allocator (CMA). 36 + * 37 + * For devices that access the memory bus through an (external) IOMMU then 38 + * the buffer objects are allocated using a traditional page-based 39 + * allocator and may be scattered through physical memory. However they 40 + * are contiguous in the IOVA space so appear contiguous to devices using 41 + * them. 42 + * 43 + * For other devices then the helpers rely on CMA to provide buffer 44 + * objects that are physically contiguous in memory. 35 45 * 36 46 * For GEM callback helpers in struct &drm_gem_object functions, see likewise 37 47 * named functions with an _object_ infix (e.g., drm_gem_cma_object_vmap() wraps ··· 121 111 * @drm: DRM device 122 112 * @size: size of the object to allocate 123 113 * 124 - * This function creates a CMA GEM object and allocates a contiguous chunk of 125 - * memory as backing store. 114 + * This function creates a CMA GEM object and allocates memory as backing store. 115 + * The allocated memory will occupy a contiguous chunk of bus address space. 116 + * 117 + * For devices that are directly connected to the memory bus then the allocated 118 + * memory will be physically contiguous. For devices that access through an 119 + * IOMMU, then the allocated memory is not expected to be physically contiguous 120 + * because having contiguous IOVAs is sufficient to meet a devices DMA 121 + * requirements. 126 122 * 127 123 * Returns: 128 124 * A struct drm_gem_cma_object * on success or an ERR_PTR()-encoded negative ··· 178 162 * @size: size of the object to allocate 179 163 * @handle: return location for the GEM handle 180 164 * 181 - * This function creates a CMA GEM object, allocating a physically contiguous 182 - * chunk of memory as backing store. The GEM object is then added to the list 183 - * of object associated with the given file and a handle to it is returned. 165 + * This function creates a CMA GEM object, allocating a chunk of memory as 166 + * backing store. The GEM object is then added to the list of object associated 167 + * with the given file and a handle to it is returned. 168 + * 169 + * The allocated memory will occupy a contiguous chunk of bus address space. 170 + * See drm_gem_cma_create() for more details. 184 171 * 185 172 * Returns: 186 173 * A struct drm_gem_cma_object * on success or an ERR_PTR()-encoded negative