Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 998fb1a0 authored by Liviu Dudau's avatar Liviu Dudau Committed by Noralf Trønnes
Browse files

drm: gem_cma_helper.c: Allow importing of contiguous scatterlists with nents > 1



drm_gem_cma_prime_import_sg_table() will fail if the number of entries
in the sg_table > 1. However, you can have a device that uses an IOMMU
engine and can map a discontiguous buffer with multiple entries that
have consecutive sg_dma_addresses, effectively making it contiguous.
Allow for that scenario by testing the entries in the sg_table for
contiguous coverage.

Reviewed-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: default avatarLiviu Dudau <liviu.dudau@arm.com>
Signed-off-by: default avatarNoralf Trønnes <noralf@tronnes.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20171110133310.1225-1-Liviu.Dudau@arm.com
parent 1f2d9bdc
Loading
Loading
Loading
Loading
+20 −2
Original line number Diff line number Diff line
@@ -475,9 +475,27 @@ drm_gem_cma_prime_import_sg_table(struct drm_device *dev,
{
	struct drm_gem_cma_object *cma_obj;

	if (sgt->nents != 1)
	if (sgt->nents != 1) {
		/* check if the entries in the sg_table are contiguous */
		dma_addr_t next_addr = sg_dma_address(sgt->sgl);
		struct scatterlist *s;
		unsigned int i;

		for_each_sg(sgt->sgl, s, sgt->nents, i) {
			/*
			 * sg_dma_address(s) is only valid for entries
			 * that have sg_dma_len(s) != 0
			 */
			if (!sg_dma_len(s))
				continue;

			if (sg_dma_address(s) != next_addr)
				return ERR_PTR(-EINVAL);

			next_addr = sg_dma_address(s) + sg_dma_len(s);
		}
	}

	/* Create a CMA GEM buffer. */
	cma_obj = __drm_gem_cma_create(dev, attach->dmabuf->size);
	if (IS_ERR(cma_obj))
+3 −1
Original line number Diff line number Diff line
@@ -8,7 +8,9 @@
 * struct drm_gem_cma_object - GEM object backed by CMA memory allocations
 * @base: base GEM object
 * @paddr: physical address of the backing memory
 * @sgt: scatter/gather table for imported PRIME buffers
 * @sgt: scatter/gather table for imported PRIME buffers. The table can have
 *       more than one entry but they are guaranteed to have contiguous
 *       DMA addresses.
 * @vaddr: kernel virtual address of the backing memory
 */
struct drm_gem_cma_object {