drm: prime: add common helper to check scatterlist contiguity
It is a common operation done by DRM drivers to check the contiguity of the DMA-mapped buffer described by a scatterlist in the sg_table object. Let's add a common helper for this operation. Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com> Reviewed-by: Andrzej Hajda <a.hajda@samsung.com> Reviewed-by: Robin Murphy <robin.murphy@arm.com>
This commit is contained in:
@@ -825,6 +825,37 @@ out:
|
||||
}
|
||||
EXPORT_SYMBOL(drm_prime_pages_to_sg);
|
||||
|
||||
/**
|
||||
* drm_prime_get_contiguous_size - returns the contiguous size of the buffer
|
||||
* @sgt: sg_table describing the buffer to check
|
||||
*
|
||||
* This helper calculates the contiguous size in the DMA address space
|
||||
* of the the buffer described by the provided sg_table.
|
||||
*
|
||||
* This is useful for implementing
|
||||
* &drm_gem_object_funcs.gem_prime_import_sg_table.
|
||||
*/
|
||||
unsigned long drm_prime_get_contiguous_size(struct sg_table *sgt)
|
||||
{
|
||||
dma_addr_t expected = sg_dma_address(sgt->sgl);
|
||||
struct scatterlist *sg;
|
||||
unsigned long size = 0;
|
||||
int i;
|
||||
|
||||
for_each_sgtable_dma_sg(sgt, sg, i) {
|
||||
unsigned int len = sg_dma_len(sg);
|
||||
|
||||
if (!len)
|
||||
break;
|
||||
if (sg_dma_address(sg) != expected)
|
||||
break;
|
||||
expected += len;
|
||||
size += len;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
EXPORT_SYMBOL(drm_prime_get_contiguous_size);
|
||||
|
||||
/**
|
||||
* drm_gem_prime_export - helper library implementation of the export callback
|
||||
* @obj: GEM object to export
|
||||
|
Reference in New Issue
Block a user