[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <20211216215145.21981-1-daniel.thompson@linaro.org>
Date: Thu, 16 Dec 2021 21:51:45 +0000
From: Daniel Thompson <daniel.thompson@...aro.org>
To: Maarten Lankhorst <maarten.lankhorst@...ux.intel.com>,
Maxime Ripard <mripard@...nel.org>,
Thomas Zimmermann <tzimmermann@...e.de>,
David Airlie <airlied@...ux.ie>,
Daniel Vetter <daniel@...ll.ch>
Cc: Daniel Thompson <daniel.thompson@...aro.org>,
dri-devel@...ts.freedesktop.org, linux-kernel@...r.kernel.org
Subject: [PATCH v2] 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@...aro.org>
---
Notes:
Changes in v2:
- Oops. I did a final proof read and acidentally committed these
changes as a seperate patch. This means that v1 contains only
one tenth of the actual patch. This is fixed in v2. Many apologies
for the noise!
drivers/gpu/drm/drm_gem_cma_helper.c | 35 ++++++++++++++++++++--------
1 file changed, 25 insertions(+), 10 deletions(-)
diff --git a/drivers/gpu/drm/drm_gem_cma_helper.c b/drivers/gpu/drm/drm_gem_cma_helper.c
index 9d05674550a4..81d7181deebd 100644
--- a/drivers/gpu/drm/drm_gem_cma_helper.c
+++ b/drivers/gpu/drm/drm_gem_cma_helper.c
@@ -25,12 +25,18 @@
/**
* DOC: cma helpers
*
- * The Contiguous Memory Allocator reserves a pool of memory at early boot
- * that is used to service requests for large blocks of contiguous memory.
+ * The DRM GEM/CMA helpers are a means to provide buffer objects that are
+ * 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 a built-in IOMMU).
*
- * The DRM GEM/CMA helpers use this allocator as a means to provide buffer
- * objects that are physically contiguous in memory. This is useful for
- * display drivers that are unable to map scattered buffers via an IOMMU.
+ * For devices the access the memory bus through an (external) IOMMU then
+ * the buffer objects can be scattered in physical memory but linearized
+ * in the IOVA space by the IOMMU.
+ *
+ * For other devices we must rely on the Contiguous Memory Allocator to
+ * reserve a pool of memory at early boot. This is then used to service requests
+ * for large blocks of physically contiguous memory.
*/
static const struct drm_gem_object_funcs drm_gem_cma_default_funcs = {
@@ -103,8 +109,14 @@ __drm_gem_cma_create(struct drm_device *drm, size_t size, bool private)
* @drm: DRM device
* @size: size of the object to allocate
*
- * This function creates a CMA GEM object and allocates a contiguous chunk of
- * memory as backing store.
+ * This function creates a CMA GEM object and allocates 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:
* A struct drm_gem_cma_object * on success or an ERR_PTR()-encoded negative
@@ -154,9 +166,12 @@ EXPORT_SYMBOL_GPL(drm_gem_cma_create);
* @size: size of the object to allocate
* @handle: return location for the GEM handle
*
- * This function creates a CMA GEM object, allocating a physically contiguous
- * chunk of memory as backing store. The GEM object is then added to the list
- * of object associated with the given file and a handle to it is returned.
+ * This function creates a CMA GEM object, allocating a chunk of memory as
+ * backing store. The GEM object is then added to the list of object associated
+ * 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:
* A struct drm_gem_cma_object * on success or an ERR_PTR()-encoded negative
base-commit: 2585cf9dfaaddf00b069673f27bb3f8530e2039c
--
2.34.1
Powered by blists - more mailing lists