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

Commit 59ad288b authored by Liam Mark's avatar Liam Mark
Browse files

ion: add support for lazy mapping



Now that ION dma mapping is done through dma_buf_map_attachemnt
add support in ION to be able to do lazy mapping via a new
dma mapping attribute called DMA_ATTR_DELAYED_UNMAP.

Change-Id: Ibcc2e0e1ef1cf1bf2fcb61147333d8417ec7fbd3
Signed-off-by: default avatarLiam Mark <lmark@codeaurora.org>
parent bca90e2f
Loading
Loading
Loading
Loading
+22 −4
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@
#include <linux/idr.h>
#include <linux/sched/task.h>
#include <linux/bitops.h>
#include <linux/msm_dma_iommu_mapping.h>
#include <soc/qcom/secure_buffer.h>

#include "ion.h"
@@ -235,6 +236,8 @@ static void _ion_buffer_destroy(struct ion_buffer *buffer)
	struct ion_heap *heap = buffer->heap;
	struct ion_device *dev = buffer->dev;

	msm_dma_buf_freed(buffer);

	mutex_lock(&dev->buffer_lock);
	rb_erase(&buffer->node, &dev->buffers);
	mutex_unlock(&dev->buffer_lock);
@@ -361,12 +364,22 @@ static struct sg_table *ion_map_dma_buf(struct dma_buf_attachment *attachment,
{
	struct ion_dma_buf_attachment *a = attachment->priv;
	struct sg_table *table;
	int ret;
	int ret, count, map_attrs;

	table = a->table;
	map_attrs = attachment->dma_map_attrs;

	if (map_attrs & DMA_ATTR_DELAYED_UNMAP) {
		count = msm_dma_map_sg_attrs(attachment->dev, table->sgl,
					     table->nents, direction,
					     attachment->dmabuf, map_attrs);
	} else {
		count = dma_map_sg_attrs(attachment->dev, table->sgl,
					 table->nents, direction,
					 map_attrs);
	}

	if (!dma_map_sg_attrs(attachment->dev, table->sgl, table->nents,
			      direction, attachment->dma_map_attrs)){
	if (count <= 0) {
		ret = -ENOMEM;
		goto err;
	}
@@ -381,7 +394,12 @@ static void ion_unmap_dma_buf(struct dma_buf_attachment *attachment,
			      struct sg_table *table,
			      enum dma_data_direction direction)
{
	dma_unmap_sg(attachment->dev, table->sgl, table->nents, direction);
	if (attachment->dma_map_attrs & DMA_ATTR_DELAYED_UNMAP)
		msm_dma_unmap_sg(attachment->dev, table->sgl, table->nents,
				 direction, attachment->dmabuf);
	else
		dma_unmap_sg_attrs(attachment->dev, table->sgl, table->nents,
				   direction, attachment->dma_map_attrs);
}

void ion_pages_sync_for_device(struct device *dev, struct page *page,
+5 −0
Original line number Diff line number Diff line
@@ -100,6 +100,11 @@
 * coherent.
 */
#define DMA_ATTR_FORCE_NON_COHERENT		(1UL << 15)
/*
 * DMA_ATTR_DELAYED_UNMAP: Used by ION, it will ensure that mappings are not
 * removed on unmap but instead are removed when the ion_buffer is freed.
 */
#define DMA_ATTR_DELAYED_UNMAP		(1UL << 16)

/*
 * DMA_ATTR_PRIVILEGED: used to indicate that the buffer is fully