linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] dma-heap: Let dma heap use dma_map_attrs to map & unmap iova
@ 2021-07-08 10:14 guangming.cao
  2021-07-15  6:24 ` guangming.cao
  0 siblings, 1 reply; 8+ messages in thread
From: guangming.cao @ 2021-07-08 10:14 UTC (permalink / raw)
  To: Sumit Semwal, Christian König, Matthias Brugger
  Cc: Benjamin Gaignard, Liam Mark, Laura Abbott, Brian Starkey,
	John Stultz, linux-media, dri-devel, linaro-mm-sig, linux-kernel,
	linux-arm-kernel, linux-mediatek, Guangming Cao

From: Guangming Cao <Guangming.Cao@mediatek.com>

For dma-heap users, they can't bypass cache sync when map/unmap iova
with dma heap. But they can do it by adding DMA_ATTR_SKIP_CPU_SYNC
into dma_alloc_attrs.

To keep alignment, at dma_heap side, also use
dma_buf_attachment.dma_map_attrs to do iova map & unmap.

Signed-off-by: Guangming Cao <Guangming.Cao@mediatek.com>
---
 drivers/dma-buf/heaps/cma_heap.c    | 6 ++++--
 drivers/dma-buf/heaps/system_heap.c | 6 ++++--
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/dma-buf/heaps/cma_heap.c b/drivers/dma-buf/heaps/cma_heap.c
index 0c05b79870f9..2c9feb3bfc3e 100644
--- a/drivers/dma-buf/heaps/cma_heap.c
+++ b/drivers/dma-buf/heaps/cma_heap.c
@@ -99,9 +99,10 @@ static struct sg_table *cma_heap_map_dma_buf(struct dma_buf_attachment *attachme
 {
 	struct dma_heap_attachment *a = attachment->priv;
 	struct sg_table *table = &a->table;
+	int attrs = attachment->dma_map_attrs;
 	int ret;
 
-	ret = dma_map_sgtable(attachment->dev, table, direction, 0);
+	ret = dma_map_sgtable(attachment->dev, table, direction, attrs);
 	if (ret)
 		return ERR_PTR(-ENOMEM);
 	a->mapped = true;
@@ -113,9 +114,10 @@ static void cma_heap_unmap_dma_buf(struct dma_buf_attachment *attachment,
 				   enum dma_data_direction direction)
 {
 	struct dma_heap_attachment *a = attachment->priv;
+	int attrs = attachment->dma_map_attrs;
 
 	a->mapped = false;
-	dma_unmap_sgtable(attachment->dev, table, direction, 0);
+	dma_unmap_sgtable(attachment->dev, table, direction, attrs);
 }
 
 static int cma_heap_dma_buf_begin_cpu_access(struct dma_buf *dmabuf,
diff --git a/drivers/dma-buf/heaps/system_heap.c b/drivers/dma-buf/heaps/system_heap.c
index 23a7e74ef966..fc7b1e02988e 100644
--- a/drivers/dma-buf/heaps/system_heap.c
+++ b/drivers/dma-buf/heaps/system_heap.c
@@ -130,9 +130,10 @@ static struct sg_table *system_heap_map_dma_buf(struct dma_buf_attachment *attac
 {
 	struct dma_heap_attachment *a = attachment->priv;
 	struct sg_table *table = a->table;
+	int attrs = attachment->dma_map_attrs;
 	int ret;
 
-	ret = dma_map_sgtable(attachment->dev, table, direction, 0);
+	ret = dma_map_sgtable(attachment->dev, table, direction, attrs);
 	if (ret)
 		return ERR_PTR(ret);
 
@@ -145,9 +146,10 @@ static void system_heap_unmap_dma_buf(struct dma_buf_attachment *attachment,
 				      enum dma_data_direction direction)
 {
 	struct dma_heap_attachment *a = attachment->priv;
+	int attrs = attachment->dma_map_attrs;
 
 	a->mapped = false;
-	dma_unmap_sgtable(attachment->dev, table, direction, 0);
+	dma_unmap_sgtable(attachment->dev, table, direction, attrs);
 }
 
 static int system_heap_dma_buf_begin_cpu_access(struct dma_buf *dmabuf,
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH] dma-heap: Let dma heap use dma_map_attrs to map & unmap iova
  2021-07-08 10:14 [PATCH] dma-heap: Let dma heap use dma_map_attrs to map & unmap iova guangming.cao
@ 2021-07-15  6:24 ` guangming.cao
  2021-07-21  9:43   ` guangming.cao
  0 siblings, 1 reply; 8+ messages in thread
From: guangming.cao @ 2021-07-15  6:24 UTC (permalink / raw)
  To: guangming.cao
  Cc: Brian.Starkey, benjamin.gaignard, christian.koenig, dri-devel,
	john.stultz, labbott, linaro-mm-sig, linux-arm-kernel,
	linux-kernel, linux-media, linux-mediatek, lmark, matthias.bgg,
	sumit.semwal, Guangming Cao

From: Guangming Cao <Guangming.Cao@mediatek.com>

On Thu, 2021-07-08 at 18:14 +0800, guangming.cao@mediatek.com wrote:

Hi Sumit, Christian, Matthias,

gentle ping for this patch :)

BRs!
Guangming

> From: Guangming Cao <Guangming.Cao@mediatek.com>
> 
> For dma-heap users, they can't bypass cache sync when map/unmap iova
> with dma heap. But they can do it by adding DMA_ATTR_SKIP_CPU_SYNC
> into dma_alloc_attrs.
> 
> To keep alignment, at dma_heap side, also use
> dma_buf_attachment.dma_map_attrs to do iova map & unmap.
> 
> Signed-off-by: Guangming Cao <Guangming.Cao@mediatek.com>
> ---
>  drivers/dma-buf/heaps/cma_heap.c    | 6 ++++--
>  drivers/dma-buf/heaps/system_heap.c | 6 ++++--
>  2 files changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/dma-buf/heaps/cma_heap.c b/drivers/dma-
> buf/heaps/cma_heap.c
> index 0c05b79870f9..2c9feb3bfc3e 100644
> --- a/drivers/dma-buf/heaps/cma_heap.c
> +++ b/drivers/dma-buf/heaps/cma_heap.c
> @@ -99,9 +99,10 @@ static struct sg_table
> *cma_heap_map_dma_buf(struct dma_buf_attachment *attachme
>  {
>  	struct dma_heap_attachment *a = attachment->priv;
>  	struct sg_table *table = &a->table;
> +	int attrs = attachment->dma_map_attrs;
>  	int ret;
>  
> -	ret = dma_map_sgtable(attachment->dev, table, direction, 0);
> +	ret = dma_map_sgtable(attachment->dev, table, direction,
> attrs);
>  	if (ret)
>  		return ERR_PTR(-ENOMEM);
>  	a->mapped = true;
> @@ -113,9 +114,10 @@ static void cma_heap_unmap_dma_buf(struct
> dma_buf_attachment *attachment,
>  				   enum dma_data_direction direction)
>  {
>  	struct dma_heap_attachment *a = attachment->priv;
> +	int attrs = attachment->dma_map_attrs;
>  
>  	a->mapped = false;
> -	dma_unmap_sgtable(attachment->dev, table, direction, 0);
> +	dma_unmap_sgtable(attachment->dev, table, direction, attrs);
>  }
>  
>  static int cma_heap_dma_buf_begin_cpu_access(struct dma_buf *dmabuf,
> diff --git a/drivers/dma-buf/heaps/system_heap.c b/drivers/dma-
> buf/heaps/system_heap.c
> index 23a7e74ef966..fc7b1e02988e 100644
> --- a/drivers/dma-buf/heaps/system_heap.c
> +++ b/drivers/dma-buf/heaps/system_heap.c
> @@ -130,9 +130,10 @@ static struct sg_table
> *system_heap_map_dma_buf(struct dma_buf_attachment *attac
>  {
>  	struct dma_heap_attachment *a = attachment->priv;
>  	struct sg_table *table = a->table;
> +	int attrs = attachment->dma_map_attrs;
>  	int ret;
>  
> -	ret = dma_map_sgtable(attachment->dev, table, direction, 0);
> +	ret = dma_map_sgtable(attachment->dev, table, direction,
> attrs);
>  	if (ret)
>  		return ERR_PTR(ret);
>  
> @@ -145,9 +146,10 @@ static void system_heap_unmap_dma_buf(struct
> dma_buf_attachment *attachment,
>  				      enum dma_data_direction
> direction)
>  {
>  	struct dma_heap_attachment *a = attachment->priv;
> +	int attrs = attachment->dma_map_attrs;
>  
>  	a->mapped = false;
> -	dma_unmap_sgtable(attachment->dev, table, direction, 0);
> +	dma_unmap_sgtable(attachment->dev, table, direction, attrs);
>  }
>  
>  static int system_heap_dma_buf_begin_cpu_access(struct dma_buf
> *dmabuf,
> -- 
> 2.17.1
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH] dma-heap: Let dma heap use dma_map_attrs to map & unmap iova
  2021-07-15  6:24 ` guangming.cao
@ 2021-07-21  9:43   ` guangming.cao
  2021-08-10  2:02     ` [PATCH] dma_heap: enable map_attrs when (un)map_attachment guangming.cao
  0 siblings, 1 reply; 8+ messages in thread
From: guangming.cao @ 2021-07-21  9:43 UTC (permalink / raw)
  To: Brian.Starkey, benjamin.gaignard, christian.koenig, dri-devel,
	john.stultz, labbott, linaro-mm-sig, linux-arm-kernel,
	linux-kernel, linux-media, linux-mediatek, lmark, matthias.bgg,
	sumit.semwal
  Cc: wsd_upstream, Guangming Cao

From: Guangming Cao <Guangming.Cao@mediatek.com>

On Thu, 2021-07-15 at 14:24 +0800, guangming.cao@mediatek.com wrote:
> From: Guangming Cao <Guangming.Cao@mediatek.com>
> 
> On Thu, 2021-07-08 at 18:14 +0800, guangming.cao@mediatek.com wrote:
> 
> Hi Sumit, Christian, Matthias,
> 
> gentle ping for this patch :)

move receviers to '--to' list.
gentle ping for this patch  :)

> 
> BRs!
> Guangming
> 
> > From: Guangming Cao <Guangming.Cao@mediatek.com>
> > 
> > For dma-heap users, they can't bypass cache sync when map/unmap
> > iova
> > with dma heap. But they can do it by adding DMA_ATTR_SKIP_CPU_SYNC
> > into dma_alloc_attrs.
> > 
> > To keep alignment, at dma_heap side, also use
> > dma_buf_attachment.dma_map_attrs to do iova map & unmap.
> > 
> > Signed-off-by: Guangming Cao <Guangming.Cao@mediatek.com>
> > ---
> >  drivers/dma-buf/heaps/cma_heap.c    | 6 ++++--
> >  drivers/dma-buf/heaps/system_heap.c | 6 ++++--
> >  2 files changed, 8 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/dma-buf/heaps/cma_heap.c b/drivers/dma-
> > buf/heaps/cma_heap.c
> > index 0c05b79870f9..2c9feb3bfc3e 100644
> > --- a/drivers/dma-buf/heaps/cma_heap.c
> > +++ b/drivers/dma-buf/heaps/cma_heap.c
> > @@ -99,9 +99,10 @@ static struct sg_table
> > *cma_heap_map_dma_buf(struct dma_buf_attachment *attachme
> >  {
> >  	struct dma_heap_attachment *a = attachment->priv;
> >  	struct sg_table *table = &a->table;
> > +	int attrs = attachment->dma_map_attrs;
> >  	int ret;
> >  
> > -	ret = dma_map_sgtable(attachment->dev, table, direction, 0);
> > +	ret = dma_map_sgtable(attachment->dev, table, direction,
> > attrs);
> >  	if (ret)
> >  		return ERR_PTR(-ENOMEM);
> >  	a->mapped = true;
> > @@ -113,9 +114,10 @@ static void cma_heap_unmap_dma_buf(struct
> > dma_buf_attachment *attachment,
> >  				   enum dma_data_direction direction)
> >  {
> >  	struct dma_heap_attachment *a = attachment->priv;
> > +	int attrs = attachment->dma_map_attrs;
> >  
> >  	a->mapped = false;
> > -	dma_unmap_sgtable(attachment->dev, table, direction, 0);
> > +	dma_unmap_sgtable(attachment->dev, table, direction, attrs);
> >  }
> >  
> >  static int cma_heap_dma_buf_begin_cpu_access(struct dma_buf
> > *dmabuf,
> > diff --git a/drivers/dma-buf/heaps/system_heap.c b/drivers/dma-
> > buf/heaps/system_heap.c
> > index 23a7e74ef966..fc7b1e02988e 100644
> > --- a/drivers/dma-buf/heaps/system_heap.c
> > +++ b/drivers/dma-buf/heaps/system_heap.c
> > @@ -130,9 +130,10 @@ static struct sg_table
> > *system_heap_map_dma_buf(struct dma_buf_attachment *attac
> >  {
> >  	struct dma_heap_attachment *a = attachment->priv;
> >  	struct sg_table *table = a->table;
> > +	int attrs = attachment->dma_map_attrs;
> >  	int ret;
> >  
> > -	ret = dma_map_sgtable(attachment->dev, table, direction, 0);
> > +	ret = dma_map_sgtable(attachment->dev, table, direction,
> > attrs);
> >  	if (ret)
> >  		return ERR_PTR(ret);
> >  
> > @@ -145,9 +146,10 @@ static void system_heap_unmap_dma_buf(struct
> > dma_buf_attachment *attachment,
> >  				      enum dma_data_direction
> > direction)
> >  {
> >  	struct dma_heap_attachment *a = attachment->priv;
> > +	int attrs = attachment->dma_map_attrs;
> >  
> >  	a->mapped = false;
> > -	dma_unmap_sgtable(attachment->dev, table, direction, 0);
> > +	dma_unmap_sgtable(attachment->dev, table, direction, attrs);
> >  }
> >  
> >  static int system_heap_dma_buf_begin_cpu_access(struct dma_buf
> > *dmabuf,
> > -- 
> > 2.17.1
> > 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH] dma_heap: enable map_attrs when (un)map_attachment
  2021-07-21  9:43   ` guangming.cao
@ 2021-08-10  2:02     ` guangming.cao
  2021-08-26  6:42       ` [PATCH] dma-buf: Add support for mapping buffers with DMA attributes guangming.cao
  0 siblings, 1 reply; 8+ messages in thread
From: guangming.cao @ 2021-08-10  2:02 UTC (permalink / raw)
  To: Sumit Semwal, Benjamin Gaignard, Liam Mark, Laura Abbott,
	Brian Starkey, John Stultz, Christian König,
	Matthias Brugger, open list:DMA-BUF HEAPS FRAMEWORK,
	open list:DMA-BUF HEAPS FRAMEWORK,
	moderated list:DMA-BUF HEAPS FRAMEWORK, open list,
	moderated list:ARM/Mediatek SoC support,
	moderated list:ARM/Mediatek SoC support
  Cc: wsd_upstream, Guangming Cao

From: Guangming Cao <Guangming.Cao@mediatek.com>

For dma-heap users, they can't bypass cache sync when (un)map
iova with dma heap. But they can do it by adding
DMA_ATTR_SKIP_CPU_SYNC into dma_alloc_attrs.

To Keep alignment, add map_attrs support for dma_heap when
(un)map_attachment.

Signed-off-by: Guangming Cao <Guangming.Cao@mediatek.com>
---
 drivers/dma-buf/heaps/cma_heap.c    | 6 ++++--
 drivers/dma-buf/heaps/system_heap.c | 6 ++++--
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/dma-buf/heaps/cma_heap.c b/drivers/dma-buf/heaps/cma_heap.c
index 0c05b79870f9..2c9feb3bfc3e 100644
--- a/drivers/dma-buf/heaps/cma_heap.c
+++ b/drivers/dma-buf/heaps/cma_heap.c
@@ -99,9 +99,10 @@ static struct sg_table *cma_heap_map_dma_buf(struct dma_buf_attachment *attachme
 {
 	struct dma_heap_attachment *a = attachment->priv;
 	struct sg_table *table = &a->table;
+	int attrs = attachment->dma_map_attrs;
 	int ret;
 
-	ret = dma_map_sgtable(attachment->dev, table, direction, 0);
+	ret = dma_map_sgtable(attachment->dev, table, direction, attrs);
 	if (ret)
 		return ERR_PTR(-ENOMEM);
 	a->mapped = true;
@@ -113,9 +114,10 @@ static void cma_heap_unmap_dma_buf(struct dma_buf_attachment *attachment,
 				   enum dma_data_direction direction)
 {
 	struct dma_heap_attachment *a = attachment->priv;
+	int attrs = attachment->dma_map_attrs;
 
 	a->mapped = false;
-	dma_unmap_sgtable(attachment->dev, table, direction, 0);
+	dma_unmap_sgtable(attachment->dev, table, direction, attrs);
 }
 
 static int cma_heap_dma_buf_begin_cpu_access(struct dma_buf *dmabuf,
diff --git a/drivers/dma-buf/heaps/system_heap.c b/drivers/dma-buf/heaps/system_heap.c
index 23a7e74ef966..fc7b1e02988e 100644
--- a/drivers/dma-buf/heaps/system_heap.c
+++ b/drivers/dma-buf/heaps/system_heap.c
@@ -130,9 +130,10 @@ static struct sg_table *system_heap_map_dma_buf(struct dma_buf_attachment *attac
 {
 	struct dma_heap_attachment *a = attachment->priv;
 	struct sg_table *table = a->table;
+	int attrs = attachment->dma_map_attrs;
 	int ret;
 
-	ret = dma_map_sgtable(attachment->dev, table, direction, 0);
+	ret = dma_map_sgtable(attachment->dev, table, direction, attrs);
 	if (ret)
 		return ERR_PTR(ret);
 
@@ -145,9 +146,10 @@ static void system_heap_unmap_dma_buf(struct dma_buf_attachment *attachment,
 				      enum dma_data_direction direction)
 {
 	struct dma_heap_attachment *a = attachment->priv;
+	int attrs = attachment->dma_map_attrs;
 
 	a->mapped = false;
-	dma_unmap_sgtable(attachment->dev, table, direction, 0);
+	dma_unmap_sgtable(attachment->dev, table, direction, attrs);
 }
 
 static int system_heap_dma_buf_begin_cpu_access(struct dma_buf *dmabuf,
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH] dma-buf: Add support for mapping buffers with DMA attributes
  2021-08-10  2:02     ` [PATCH] dma_heap: enable map_attrs when (un)map_attachment guangming.cao
@ 2021-08-26  6:42       ` guangming.cao
  0 siblings, 0 replies; 8+ messages in thread
From: guangming.cao @ 2021-08-26  6:42 UTC (permalink / raw)
  To: Sumit Semwal, Benjamin Gaignard, Liam Mark, Laura Abbott,
	Brian Starkey, John Stultz, Christian König,
	Matthias Brugger, open list:DMA-BUF HEAPS FRAMEWORK,
	open list:DMA-BUF HEAPS FRAMEWORK,
	moderated list:DMA-BUF HEAPS FRAMEWORK, open list,
	moderated list:ARM/Mediatek SoC support,
	moderated list:ARM/Mediatek SoC support
  Cc: wsd_upstream, isaacm, sspatil, hridya, Guangming Cao

From: Guangming Cao <Guangming.Cao@mediatek.com>

When mapping the memory represented by a dma-buf into a device's
address space, it might be desireable to map the memory with
certain DMA attributes. Thus, introduce the dma_mapping_attrs
field in the dma_buf_attachment structure so that when
the memory is mapped with dma_buf_map_attachment, it is mapped
with the desired DMA attributes.

Signed-off-by: Isaac J. Manjarres <isaacm@codeaurora.org>
Signed-off-by: Sandeep Patil <sspatil@google.com>
Signed-off-by: Guangming Cao <Guangming.Cao@mediatek.com>
---
 drivers/dma-buf/heaps/cma_heap.c    | 6 ++++--
 drivers/dma-buf/heaps/system_heap.c | 6 ++++--
 include/linux/dma-buf.h             | 3 +++
 3 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/dma-buf/heaps/cma_heap.c b/drivers/dma-buf/heaps/cma_heap.c
index 0c05b79870f9..2c9feb3bfc3e 100644
--- a/drivers/dma-buf/heaps/cma_heap.c
+++ b/drivers/dma-buf/heaps/cma_heap.c
@@ -99,9 +99,10 @@ static struct sg_table *cma_heap_map_dma_buf(struct dma_buf_attachment *attachme
 {
 	struct dma_heap_attachment *a = attachment->priv;
 	struct sg_table *table = &a->table;
+	int attrs = attachment->dma_map_attrs;
 	int ret;
 
-	ret = dma_map_sgtable(attachment->dev, table, direction, 0);
+	ret = dma_map_sgtable(attachment->dev, table, direction, attrs);
 	if (ret)
 		return ERR_PTR(-ENOMEM);
 	a->mapped = true;
@@ -113,9 +114,10 @@ static void cma_heap_unmap_dma_buf(struct dma_buf_attachment *attachment,
 				   enum dma_data_direction direction)
 {
 	struct dma_heap_attachment *a = attachment->priv;
+	int attrs = attachment->dma_map_attrs;
 
 	a->mapped = false;
-	dma_unmap_sgtable(attachment->dev, table, direction, 0);
+	dma_unmap_sgtable(attachment->dev, table, direction, attrs);
 }
 
 static int cma_heap_dma_buf_begin_cpu_access(struct dma_buf *dmabuf,
diff --git a/drivers/dma-buf/heaps/system_heap.c b/drivers/dma-buf/heaps/system_heap.c
index 23a7e74ef966..fc7b1e02988e 100644
--- a/drivers/dma-buf/heaps/system_heap.c
+++ b/drivers/dma-buf/heaps/system_heap.c
@@ -130,9 +130,10 @@ static struct sg_table *system_heap_map_dma_buf(struct dma_buf_attachment *attac
 {
 	struct dma_heap_attachment *a = attachment->priv;
 	struct sg_table *table = a->table;
+	int attrs = attachment->dma_map_attrs;
 	int ret;
 
-	ret = dma_map_sgtable(attachment->dev, table, direction, 0);
+	ret = dma_map_sgtable(attachment->dev, table, direction, attrs);
 	if (ret)
 		return ERR_PTR(ret);
 
@@ -145,9 +146,10 @@ static void system_heap_unmap_dma_buf(struct dma_buf_attachment *attachment,
 				      enum dma_data_direction direction)
 {
 	struct dma_heap_attachment *a = attachment->priv;
+	int attrs = attachment->dma_map_attrs;
 
 	a->mapped = false;
-	dma_unmap_sgtable(attachment->dev, table, direction, 0);
+	dma_unmap_sgtable(attachment->dev, table, direction, attrs);
 }
 
 static int system_heap_dma_buf_begin_cpu_access(struct dma_buf *dmabuf,
diff --git a/include/linux/dma-buf.h b/include/linux/dma-buf.h
index efdc56b9d95f..4d650731766e 100644
--- a/include/linux/dma-buf.h
+++ b/include/linux/dma-buf.h
@@ -379,6 +379,8 @@ struct dma_buf_attach_ops {
  * @importer_ops: importer operations for this attachment, if provided
  * dma_buf_map/unmap_attachment() must be called with the dma_resv lock held.
  * @importer_priv: importer specific attachment data.
+ * @dma_map_attrs: DMA attributes to be used when the exporter maps the buffer
+ * through dma_buf_map_attachment.
  *
  * This structure holds the attachment information between the dma_buf buffer
  * and its user device(s). The list contains one attachment struct per device
@@ -399,6 +401,7 @@ struct dma_buf_attachment {
 	const struct dma_buf_attach_ops *importer_ops;
 	void *importer_priv;
 	void *priv;
+	unsigned long dma_map_attrs;
 };
 
 /**
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] dma-buf: Add support for mapping buffers with DMA attributes
  2021-08-31 12:47 ` Daniel Vetter
@ 2021-10-18  6:25   ` guangming.cao
  0 siblings, 0 replies; 8+ messages in thread
From: guangming.cao @ 2021-10-18  6:25 UTC (permalink / raw)
  To: daniel
  Cc: Brian.Starkey, benjamin.gaignard, christian.koenig, dri-devel,
	guangming.cao, hridya, isaacm, john.stultz, labbott,
	linaro-mm-sig, linux-arm-kernel, linux-kernel, linux-media,
	linux-mediatek, lmark, matthias.bgg, sspatil, sumit.semwal,
	wsd_upstream, Guangming Cao

From: Guangming Cao <Guangming.Cao@mediatek.com>

On Tue, 2021-08-31 at 14:47 +0200, Daniel Vetter wrote:
> On Mon, Aug 30, 2021 at 10:39:11AM +0800, guangming.cao@mediatek.com
> wrote:
> > From: Guangming Cao <Guangming.Cao@mediatek.com>
> > 
> > When mapping the memory represented by a dma-buf into a device's
> > address space, it might be desireable to map the memory with
> > certain DMA attributes. Thus, introduce the dma_mapping_attrs
> > field in the dma_buf_attachment structure so that when
> > the memory is mapped with dma_buf_map_attachment, it is mapped
> > with the desired DMA attributes.
> > 
> > Signed-off-by: Isaac J. Manjarres <isaacm@codeaurora.org>
> > Signed-off-by: Sandeep Patil <sspatil@google.com>
> > Signed-off-by: Guangming Cao <Guangming.Cao@mediatek.com>
> 
> Can you pls include the code that's going to use this here too?
> 
> At a glance all the attributes you might want to set are supposed to
> be
> under the control of the exporter, not the importer.
> -Daniel
> 
Hi Daniel,

Sorry for the late. Currently I couldn't upload the coding going to use
this part because of some miscellaneous reasons.

Just as I said in commit message, for dma_heap, users can't skip cache
sync or other opetrations when map iova[dma_buf_map_attachment] by
fill (struct dma_buf_attachment).dma_map_attrs, it's not dma_map_attrs
expected(link: 
https://github.com/torvalds/linux/blob/master/Documentation/core-api/dma-attributes.rst#dma_attr_skip_cpu_sync
).

Correspondingly, if they use dma_buf to map iova[dma_buf_map_attrs],
they will not meet this issue. So, I think it's a design flaw for
dma_heap.

BRs!
Guangming
> > ---
> >  drivers/dma-buf/heaps/cma_heap.c    | 6 ++++--
> >  drivers/dma-buf/heaps/system_heap.c | 6 ++++--
> >  include/linux/dma-buf.h             | 3 +++
> >  3 files changed, 11 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/dma-buf/heaps/cma_heap.c b/drivers/dma-
> > buf/heaps/cma_heap.c
> > index 0c05b79870f9..2c9feb3bfc3e 100644
> > --- a/drivers/dma-buf/heaps/cma_heap.c
> > +++ b/drivers/dma-buf/heaps/cma_heap.c
> > @@ -99,9 +99,10 @@ static struct sg_table
> > *cma_heap_map_dma_buf(struct dma_buf_attachment *attachme
> >  {
> >     struct dma_heap_attachment *a = attachment->priv;
> >     struct sg_table *table = &a->table;
> > +   int attrs = attachment->dma_map_attrs;
> >     int ret;
> >  
> > -   ret = dma_map_sgtable(attachment->dev, table, direction, 0);
> > +   ret = dma_map_sgtable(attachment->dev, table, direction,
> > attrs);
> >     if (ret)
> >             return ERR_PTR(-ENOMEM);
> >     a->mapped = true;
> > @@ -113,9 +114,10 @@ static void cma_heap_unmap_dma_buf(struct
> > dma_buf_attachment *attachment,
> >                                enum dma_data_direction direction)
> >  {
> >     struct dma_heap_attachment *a = attachment->priv;
> > +   int attrs = attachment->dma_map_attrs;
> >  
> >     a->mapped = false;
> > -   dma_unmap_sgtable(attachment->dev, table, direction, 0);
> > +   dma_unmap_sgtable(attachment->dev, table, direction, attrs);
> >  }
> >  
> >  static int cma_heap_dma_buf_begin_cpu_access(struct dma_buf
> > *dmabuf,
> > diff --git a/drivers/dma-buf/heaps/system_heap.c b/drivers/dma-
> > buf/heaps/system_heap.c
> > index 23a7e74ef966..fc7b1e02988e 100644
> > --- a/drivers/dma-buf/heaps/system_heap.c
> > +++ b/drivers/dma-buf/heaps/system_heap.c
> > @@ -130,9 +130,10 @@ static struct sg_table
> > *system_heap_map_dma_buf(struct dma_buf_attachment *attac
> >  {
> >     struct dma_heap_attachment *a = attachment->priv;
> >     struct sg_table *table = a->table;
> > +   int attrs = attachment->dma_map_attrs;
> >     int ret;
> >  
> > -   ret = dma_map_sgtable(attachment->dev, table, direction, 0);
> > +   ret = dma_map_sgtable(attachment->dev, table, direction,
> > attrs);
> >     if (ret)
> >             return ERR_PTR(ret);
> >  
> > @@ -145,9 +146,10 @@ static void system_heap_unmap_dma_buf(struct
> > dma_buf_attachment *attachment,
> >                                   enum dma_data_direction
> > direction)
> >  {
> >     struct dma_heap_attachment *a = attachment->priv;
> > +   int attrs = attachment->dma_map_attrs;
> >  
> >     a->mapped = false;
> > -   dma_unmap_sgtable(attachment->dev, table, direction, 0);
> > +   dma_unmap_sgtable(attachment->dev, table, direction, attrs);
> >  }
> >  
> >  static int system_heap_dma_buf_begin_cpu_access(struct dma_buf
> > *dmabuf,
> > diff --git a/include/linux/dma-buf.h b/include/linux/dma-buf.h
> > index efdc56b9d95f..4d650731766e 100644
> > --- a/include/linux/dma-buf.h
> > +++ b/include/linux/dma-buf.h
> > @@ -379,6 +379,8 @@ struct dma_buf_attach_ops {
> >   * @importer_ops: importer operations for this attachment, if
> > provided
> >   * dma_buf_map/unmap_attachment() must be called with the dma_resv
> > lock held.
> >   * @importer_priv: importer specific attachment data.
> > + * @dma_map_attrs: DMA attributes to be used when the exporter
> > maps the buffer
> > + * through dma_buf_map_attachment.
> >   *
> >   * This structure holds the attachment information between the
> > dma_buf buffer
> >   * and its user device(s). The list contains one attachment struct
> > per device
> > @@ -399,6 +401,7 @@ struct dma_buf_attachment {
> >     const struct dma_buf_attach_ops *importer_ops;
> >     void *importer_priv;
> >     void *priv;
> > +   unsigned long dma_map_attrs;
> >  };
> >  
> >  /**
> > -- 
> > 2.17.1
> > 
> 
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] dma-buf: Add support for mapping buffers with DMA attributes
  2021-08-30  2:39 guangming.cao
@ 2021-08-31 12:47 ` Daniel Vetter
  2021-10-18  6:25   ` guangming.cao
  0 siblings, 1 reply; 8+ messages in thread
From: Daniel Vetter @ 2021-08-31 12:47 UTC (permalink / raw)
  To: guangming.cao
  Cc: Sumit Semwal, Benjamin Gaignard, Liam Mark, Laura Abbott,
	Brian Starkey, John Stultz, Christian König,
	Matthias Brugger, open list:DMA-BUF HEAPS FRAMEWORK,
	open list:DMA-BUF HEAPS FRAMEWORK,
	moderated list:DMA-BUF HEAPS FRAMEWORK, open list,
	moderated list:ARM/Mediatek SoC support,
	moderated list:ARM/Mediatek SoC support, wsd_upstream, isaacm,
	sspatil, hridya

On Mon, Aug 30, 2021 at 10:39:11AM +0800, guangming.cao@mediatek.com wrote:
> From: Guangming Cao <Guangming.Cao@mediatek.com>
> 
> When mapping the memory represented by a dma-buf into a device's
> address space, it might be desireable to map the memory with
> certain DMA attributes. Thus, introduce the dma_mapping_attrs
> field in the dma_buf_attachment structure so that when
> the memory is mapped with dma_buf_map_attachment, it is mapped
> with the desired DMA attributes.
> 
> Signed-off-by: Isaac J. Manjarres <isaacm@codeaurora.org>
> Signed-off-by: Sandeep Patil <sspatil@google.com>
> Signed-off-by: Guangming Cao <Guangming.Cao@mediatek.com>

Can you pls include the code that's going to use this here too?

At a glance all the attributes you might want to set are supposed to be
under the control of the exporter, not the importer.
-Daniel

> ---
>  drivers/dma-buf/heaps/cma_heap.c    | 6 ++++--
>  drivers/dma-buf/heaps/system_heap.c | 6 ++++--
>  include/linux/dma-buf.h             | 3 +++
>  3 files changed, 11 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/dma-buf/heaps/cma_heap.c b/drivers/dma-buf/heaps/cma_heap.c
> index 0c05b79870f9..2c9feb3bfc3e 100644
> --- a/drivers/dma-buf/heaps/cma_heap.c
> +++ b/drivers/dma-buf/heaps/cma_heap.c
> @@ -99,9 +99,10 @@ static struct sg_table *cma_heap_map_dma_buf(struct dma_buf_attachment *attachme
>  {
>  	struct dma_heap_attachment *a = attachment->priv;
>  	struct sg_table *table = &a->table;
> +	int attrs = attachment->dma_map_attrs;
>  	int ret;
>  
> -	ret = dma_map_sgtable(attachment->dev, table, direction, 0);
> +	ret = dma_map_sgtable(attachment->dev, table, direction, attrs);
>  	if (ret)
>  		return ERR_PTR(-ENOMEM);
>  	a->mapped = true;
> @@ -113,9 +114,10 @@ static void cma_heap_unmap_dma_buf(struct dma_buf_attachment *attachment,
>  				   enum dma_data_direction direction)
>  {
>  	struct dma_heap_attachment *a = attachment->priv;
> +	int attrs = attachment->dma_map_attrs;
>  
>  	a->mapped = false;
> -	dma_unmap_sgtable(attachment->dev, table, direction, 0);
> +	dma_unmap_sgtable(attachment->dev, table, direction, attrs);
>  }
>  
>  static int cma_heap_dma_buf_begin_cpu_access(struct dma_buf *dmabuf,
> diff --git a/drivers/dma-buf/heaps/system_heap.c b/drivers/dma-buf/heaps/system_heap.c
> index 23a7e74ef966..fc7b1e02988e 100644
> --- a/drivers/dma-buf/heaps/system_heap.c
> +++ b/drivers/dma-buf/heaps/system_heap.c
> @@ -130,9 +130,10 @@ static struct sg_table *system_heap_map_dma_buf(struct dma_buf_attachment *attac
>  {
>  	struct dma_heap_attachment *a = attachment->priv;
>  	struct sg_table *table = a->table;
> +	int attrs = attachment->dma_map_attrs;
>  	int ret;
>  
> -	ret = dma_map_sgtable(attachment->dev, table, direction, 0);
> +	ret = dma_map_sgtable(attachment->dev, table, direction, attrs);
>  	if (ret)
>  		return ERR_PTR(ret);
>  
> @@ -145,9 +146,10 @@ static void system_heap_unmap_dma_buf(struct dma_buf_attachment *attachment,
>  				      enum dma_data_direction direction)
>  {
>  	struct dma_heap_attachment *a = attachment->priv;
> +	int attrs = attachment->dma_map_attrs;
>  
>  	a->mapped = false;
> -	dma_unmap_sgtable(attachment->dev, table, direction, 0);
> +	dma_unmap_sgtable(attachment->dev, table, direction, attrs);
>  }
>  
>  static int system_heap_dma_buf_begin_cpu_access(struct dma_buf *dmabuf,
> diff --git a/include/linux/dma-buf.h b/include/linux/dma-buf.h
> index efdc56b9d95f..4d650731766e 100644
> --- a/include/linux/dma-buf.h
> +++ b/include/linux/dma-buf.h
> @@ -379,6 +379,8 @@ struct dma_buf_attach_ops {
>   * @importer_ops: importer operations for this attachment, if provided
>   * dma_buf_map/unmap_attachment() must be called with the dma_resv lock held.
>   * @importer_priv: importer specific attachment data.
> + * @dma_map_attrs: DMA attributes to be used when the exporter maps the buffer
> + * through dma_buf_map_attachment.
>   *
>   * This structure holds the attachment information between the dma_buf buffer
>   * and its user device(s). The list contains one attachment struct per device
> @@ -399,6 +401,7 @@ struct dma_buf_attachment {
>  	const struct dma_buf_attach_ops *importer_ops;
>  	void *importer_priv;
>  	void *priv;
> +	unsigned long dma_map_attrs;
>  };
>  
>  /**
> -- 
> 2.17.1
> 

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH] dma-buf: Add support for mapping buffers with DMA attributes
@ 2021-08-30  2:39 guangming.cao
  2021-08-31 12:47 ` Daniel Vetter
  0 siblings, 1 reply; 8+ messages in thread
From: guangming.cao @ 2021-08-30  2:39 UTC (permalink / raw)
  To: Sumit Semwal, Benjamin Gaignard, Liam Mark, Laura Abbott,
	Brian Starkey, John Stultz, Christian König,
	Matthias Brugger, open list:DMA-BUF HEAPS FRAMEWORK,
	open list:DMA-BUF HEAPS FRAMEWORK,
	moderated list:DMA-BUF HEAPS FRAMEWORK, open list,
	moderated list:ARM/Mediatek SoC support,
	moderated list:ARM/Mediatek SoC support
  Cc: wsd_upstream, isaacm, sspatil, hridya, Guangming Cao

From: Guangming Cao <Guangming.Cao@mediatek.com>

When mapping the memory represented by a dma-buf into a device's
address space, it might be desireable to map the memory with
certain DMA attributes. Thus, introduce the dma_mapping_attrs
field in the dma_buf_attachment structure so that when
the memory is mapped with dma_buf_map_attachment, it is mapped
with the desired DMA attributes.

Signed-off-by: Isaac J. Manjarres <isaacm@codeaurora.org>
Signed-off-by: Sandeep Patil <sspatil@google.com>
Signed-off-by: Guangming Cao <Guangming.Cao@mediatek.com>
---
 drivers/dma-buf/heaps/cma_heap.c    | 6 ++++--
 drivers/dma-buf/heaps/system_heap.c | 6 ++++--
 include/linux/dma-buf.h             | 3 +++
 3 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/dma-buf/heaps/cma_heap.c b/drivers/dma-buf/heaps/cma_heap.c
index 0c05b79870f9..2c9feb3bfc3e 100644
--- a/drivers/dma-buf/heaps/cma_heap.c
+++ b/drivers/dma-buf/heaps/cma_heap.c
@@ -99,9 +99,10 @@ static struct sg_table *cma_heap_map_dma_buf(struct dma_buf_attachment *attachme
 {
 	struct dma_heap_attachment *a = attachment->priv;
 	struct sg_table *table = &a->table;
+	int attrs = attachment->dma_map_attrs;
 	int ret;
 
-	ret = dma_map_sgtable(attachment->dev, table, direction, 0);
+	ret = dma_map_sgtable(attachment->dev, table, direction, attrs);
 	if (ret)
 		return ERR_PTR(-ENOMEM);
 	a->mapped = true;
@@ -113,9 +114,10 @@ static void cma_heap_unmap_dma_buf(struct dma_buf_attachment *attachment,
 				   enum dma_data_direction direction)
 {
 	struct dma_heap_attachment *a = attachment->priv;
+	int attrs = attachment->dma_map_attrs;
 
 	a->mapped = false;
-	dma_unmap_sgtable(attachment->dev, table, direction, 0);
+	dma_unmap_sgtable(attachment->dev, table, direction, attrs);
 }
 
 static int cma_heap_dma_buf_begin_cpu_access(struct dma_buf *dmabuf,
diff --git a/drivers/dma-buf/heaps/system_heap.c b/drivers/dma-buf/heaps/system_heap.c
index 23a7e74ef966..fc7b1e02988e 100644
--- a/drivers/dma-buf/heaps/system_heap.c
+++ b/drivers/dma-buf/heaps/system_heap.c
@@ -130,9 +130,10 @@ static struct sg_table *system_heap_map_dma_buf(struct dma_buf_attachment *attac
 {
 	struct dma_heap_attachment *a = attachment->priv;
 	struct sg_table *table = a->table;
+	int attrs = attachment->dma_map_attrs;
 	int ret;
 
-	ret = dma_map_sgtable(attachment->dev, table, direction, 0);
+	ret = dma_map_sgtable(attachment->dev, table, direction, attrs);
 	if (ret)
 		return ERR_PTR(ret);
 
@@ -145,9 +146,10 @@ static void system_heap_unmap_dma_buf(struct dma_buf_attachment *attachment,
 				      enum dma_data_direction direction)
 {
 	struct dma_heap_attachment *a = attachment->priv;
+	int attrs = attachment->dma_map_attrs;
 
 	a->mapped = false;
-	dma_unmap_sgtable(attachment->dev, table, direction, 0);
+	dma_unmap_sgtable(attachment->dev, table, direction, attrs);
 }
 
 static int system_heap_dma_buf_begin_cpu_access(struct dma_buf *dmabuf,
diff --git a/include/linux/dma-buf.h b/include/linux/dma-buf.h
index efdc56b9d95f..4d650731766e 100644
--- a/include/linux/dma-buf.h
+++ b/include/linux/dma-buf.h
@@ -379,6 +379,8 @@ struct dma_buf_attach_ops {
  * @importer_ops: importer operations for this attachment, if provided
  * dma_buf_map/unmap_attachment() must be called with the dma_resv lock held.
  * @importer_priv: importer specific attachment data.
+ * @dma_map_attrs: DMA attributes to be used when the exporter maps the buffer
+ * through dma_buf_map_attachment.
  *
  * This structure holds the attachment information between the dma_buf buffer
  * and its user device(s). The list contains one attachment struct per device
@@ -399,6 +401,7 @@ struct dma_buf_attachment {
 	const struct dma_buf_attach_ops *importer_ops;
 	void *importer_priv;
 	void *priv;
+	unsigned long dma_map_attrs;
 };
 
 /**
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-10-18  6:25 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-08 10:14 [PATCH] dma-heap: Let dma heap use dma_map_attrs to map & unmap iova guangming.cao
2021-07-15  6:24 ` guangming.cao
2021-07-21  9:43   ` guangming.cao
2021-08-10  2:02     ` [PATCH] dma_heap: enable map_attrs when (un)map_attachment guangming.cao
2021-08-26  6:42       ` [PATCH] dma-buf: Add support for mapping buffers with DMA attributes guangming.cao
2021-08-30  2:39 guangming.cao
2021-08-31 12:47 ` Daniel Vetter
2021-10-18  6:25   ` guangming.cao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).