From 17774a5b1115dcb181f81a965db69e31c316690c Mon Sep 17 00:00:00 2001 From: Etienne Carriere Date: Mon, 9 Oct 2017 13:47:40 +0200 Subject: [PATCH] staging:ion: add a no-map property to ion dmabuf attachment Ion unmapped heap aims at not being mapped. This change prevents Ion from calling dma-mapping support on dma_buf_attach for buffers in an unmapped heap. This change is a bit intrusive in the Ion driver. Maybe there is another way to deal with the dma-mapping resources used for the unmapped heap. Signed-off-by: Etienne Carriere --- drivers/staging/android/ion/ion.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c index 92c2914239e30d..5fb7b19953e029 100644 --- a/drivers/staging/android/ion/ion.c +++ b/drivers/staging/android/ion/ion.c @@ -207,6 +207,7 @@ struct ion_dma_buf_attachment { struct device *dev; struct sg_table *table; struct list_head list; + bool no_map; }; static int ion_dma_buf_attach(struct dma_buf *dmabuf, @@ -226,6 +227,9 @@ static int ion_dma_buf_attach(struct dma_buf *dmabuf, return -ENOMEM; } + if (buffer->heap->type == ION_HEAP_TYPE_UNMAPPED) + a->no_map = true; + a->table = table; a->dev = attachment->dev; INIT_LIST_HEAD(&a->list); @@ -261,6 +265,9 @@ static struct sg_table *ion_map_dma_buf(struct dma_buf_attachment *attachment, table = a->table; + if (a->no_map) + return table; + if (!dma_map_sg(attachment->dev, table->sgl, table->nents, direction)) return ERR_PTR(-ENOMEM); @@ -272,6 +279,11 @@ static void ion_unmap_dma_buf(struct dma_buf_attachment *attachment, struct sg_table *table, enum dma_data_direction direction) { + struct ion_dma_buf_attachment *a = attachment->priv; + + if (a->no_map) + return; + dma_unmap_sg(attachment->dev, table->sgl, table->nents, direction); }