linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] dmaengine: care sd_dma_address/len in dmaengine_prep_slave_single()
@ 2012-01-30  9:25 Kuninori Morimoto
  2012-01-30  9:56 ` Vinod Koul
  0 siblings, 1 reply; 10+ messages in thread
From: Kuninori Morimoto @ 2012-01-30  9:25 UTC (permalink / raw)
  To: Vinod Koul, Dan Williams, Russell King; +Cc: linux-kernel

dmaengine_prep_slave_single() is helper macro of dmaengine.
But it doesn't have sg_dma_address/len() settings which are required.
And it used void *buf in parameter, but it should be dma_addr_t.
This patch fixes up it.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
 include/linux/dmaengine.h |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
index 75f53f8..f47c578 100644
--- a/include/linux/dmaengine.h
+++ b/include/linux/dmaengine.h
@@ -521,11 +521,16 @@ static inline int dmaengine_slave_config(struct dma_chan *chan,
 }
 
 static inline struct dma_async_tx_descriptor *dmaengine_prep_slave_single(
-	struct dma_chan *chan, void *buf, size_t len,
+	struct dma_chan *chan, dma_addr_t buf, size_t len,
 	enum dma_data_direction dir, unsigned long flags)
 {
 	struct scatterlist sg;
-	sg_init_one(&sg, buf, len);
+
+	sg_init_table(&sg, 1);
+	sg_set_page(&sg, pfn_to_page(PFN_DOWN(buf)),
+		    len, offset_in_page(buf));
+	sg_dma_address(&sg) = buf;
+	sg_dma_len(&sg) = len;
 
 	return chan->device->device_prep_slave_sg(chan, &sg, 1, dir, flags);
 }
-- 
1.7.5.4


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

* Re: [PATCH] dmaengine: care sd_dma_address/len in dmaengine_prep_slave_single()
  2012-01-30  9:25 [PATCH] dmaengine: care sd_dma_address/len in dmaengine_prep_slave_single() Kuninori Morimoto
@ 2012-01-30  9:56 ` Vinod Koul
  2012-01-31  1:13   ` [PATCH v2] " Kuninori Morimoto
  0 siblings, 1 reply; 10+ messages in thread
From: Vinod Koul @ 2012-01-30  9:56 UTC (permalink / raw)
  To: Kuninori Morimoto; +Cc: Dan Williams, Russell King, linux-kernel

On Mon, 2012-01-30 at 01:25 -0800, Kuninori Morimoto wrote:
> dmaengine_prep_slave_single() is helper macro of dmaengine.
> But it doesn't have sg_dma_address/len() settings which are required.
> And it used void *buf in parameter, but it should be dma_addr_t.
> This patch fixes up it.
> 
> Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
> ---
>  include/linux/dmaengine.h |    9 +++++++--
>  1 files changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
> index 75f53f8..f47c578 100644
> --- a/include/linux/dmaengine.h
> +++ b/include/linux/dmaengine.h
> @@ -521,11 +521,16 @@ static inline int dmaengine_slave_config(struct dma_chan *chan,
>  }
>  
>  static inline struct dma_async_tx_descriptor *dmaengine_prep_slave_single(
> -	struct dma_chan *chan, void *buf, size_t len,
> +	struct dma_chan *chan, dma_addr_t buf, size_t len,
>  	enum dma_data_direction dir, unsigned long flags)
dma_transfer_direction... this is not based on 3.3-rc1 or
slave-dma/next?

>  {
>  	struct scatterlist sg;
> -	sg_init_one(&sg, buf, len);
> +
> +	sg_init_table(&sg, 1);
> +	sg_set_page(&sg, pfn_to_page(PFN_DOWN(buf)),
> +		    len, offset_in_page(buf));
> +	sg_dma_address(&sg) = buf;
> +	sg_dma_len(&sg) = len;
>  
>  	return chan->device->device_prep_slave_sg(chan, &sg, 1, dir, flags);
>  }


-- 
~Vinod


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

* [PATCH v2] dmaengine: care sd_dma_address/len in dmaengine_prep_slave_single()
  2012-01-30  9:56 ` Vinod Koul
@ 2012-01-31  1:13   ` Kuninori Morimoto
  2012-02-01 18:22     ` Russell King - ARM Linux
  2012-03-08  9:48     ` Lars-Peter Clausen
  0 siblings, 2 replies; 10+ messages in thread
From: Kuninori Morimoto @ 2012-01-31  1:13 UTC (permalink / raw)
  To: Vinod Koul; +Cc: Dan Williams, Russell King, linux-kernel

dmaengine_prep_slave_single() is helper macro of dmaengine.
But it doesn't have sg_dma_address/len() settings which are required.
And it used void *buf in parameter, but it should be dma_addr_t.
This patch fixes up it.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
V1 -> v2

- based on latest linus/master branch

 include/linux/dmaengine.h |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
index 679b349..97eaf57 100644
--- a/include/linux/dmaengine.h
+++ b/include/linux/dmaengine.h
@@ -606,11 +606,16 @@ static inline int dmaengine_slave_config(struct dma_chan *chan,
 }
 
 static inline struct dma_async_tx_descriptor *dmaengine_prep_slave_single(
-	struct dma_chan *chan, void *buf, size_t len,
+	struct dma_chan *chan, dma_addr_t buf, size_t len,
 	enum dma_transfer_direction dir, unsigned long flags)
 {
 	struct scatterlist sg;
-	sg_init_one(&sg, buf, len);
+
+	sg_init_table(&sg, 1);
+	sg_set_page(&sg, pfn_to_page(PFN_DOWN(buf)),
+		    len, offset_in_page(buf));
+	sg_dma_address(&sg) = buf;
+	sg_dma_len(&sg) = len;
 
 	return chan->device->device_prep_slave_sg(chan, &sg, 1, dir, flags);
 }
-- 
1.7.5.4


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

* Re: [PATCH v2] dmaengine: care sd_dma_address/len in dmaengine_prep_slave_single()
  2012-01-31  1:13   ` [PATCH v2] " Kuninori Morimoto
@ 2012-02-01 18:22     ` Russell King - ARM Linux
  2012-04-25 14:18       ` Lars-Peter Clausen
  2012-03-08  9:48     ` Lars-Peter Clausen
  1 sibling, 1 reply; 10+ messages in thread
From: Russell King - ARM Linux @ 2012-02-01 18:22 UTC (permalink / raw)
  To: Kuninori Morimoto; +Cc: Vinod Koul, Dan Williams, linux-kernel

On Mon, Jan 30, 2012 at 05:13:30PM -0800, Kuninori Morimoto wrote:
> +	sg_init_table(&sg, 1);
> +	sg_set_page(&sg, pfn_to_page(PFN_DOWN(buf)),
> +		    len, offset_in_page(buf));

There's not much point setting this - the page/virtual address should
not be used by DMA engines as that may not reflect what's being requested
(especially if there's an IOMMU in the way.)

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

* Re: [PATCH v2] dmaengine: care sd_dma_address/len in dmaengine_prep_slave_single()
  2012-01-31  1:13   ` [PATCH v2] " Kuninori Morimoto
  2012-02-01 18:22     ` Russell King - ARM Linux
@ 2012-03-08  9:48     ` Lars-Peter Clausen
  2012-03-09  0:18       ` Kuninori Morimoto
  1 sibling, 1 reply; 10+ messages in thread
From: Lars-Peter Clausen @ 2012-03-08  9:48 UTC (permalink / raw)
  To: Kuninori Morimoto; +Cc: Vinod Koul, Dan Williams, Russell King, linux-kernel

On 01/31/2012 02:13 AM, Kuninori Morimoto wrote:
> dmaengine_prep_slave_single() is helper macro of dmaengine.
> But it doesn't have sg_dma_address/len() settings which are required.
> And it used void *buf in parameter, but it should be dma_addr_t.
> This patch fixes up it.
> 
> Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>

Hi,

Any news regarding this patch? The dmaengine_prep_slave_single in upstream
is not really usable as it is right now.

Thanks,
- Lars

> ---
> V1 -> v2
> 
> - based on latest linus/master branch
> 
>  include/linux/dmaengine.h |    9 +++++++--
>  1 files changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
> index 679b349..97eaf57 100644
> --- a/include/linux/dmaengine.h
> +++ b/include/linux/dmaengine.h
> @@ -606,11 +606,16 @@ static inline int dmaengine_slave_config(struct dma_chan *chan,
>  }
>  
>  static inline struct dma_async_tx_descriptor *dmaengine_prep_slave_single(
> -	struct dma_chan *chan, void *buf, size_t len,
> +	struct dma_chan *chan, dma_addr_t buf, size_t len,
>  	enum dma_transfer_direction dir, unsigned long flags)
>  {
>  	struct scatterlist sg;
> -	sg_init_one(&sg, buf, len);
> +
> +	sg_init_table(&sg, 1);
> +	sg_set_page(&sg, pfn_to_page(PFN_DOWN(buf)),
> +		    len, offset_in_page(buf));
> +	sg_dma_address(&sg) = buf;
> +	sg_dma_len(&sg) = len;
>  
>  	return chan->device->device_prep_slave_sg(chan, &sg, 1, dir, flags);
>  }


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

* Re: [PATCH v2] dmaengine: care sd_dma_address/len in dmaengine_prep_slave_single()
  2012-03-08  9:48     ` Lars-Peter Clausen
@ 2012-03-09  0:18       ` Kuninori Morimoto
  2012-03-10 11:12         ` Lars-Peter Clausen
  0 siblings, 1 reply; 10+ messages in thread
From: Kuninori Morimoto @ 2012-03-09  0:18 UTC (permalink / raw)
  To: Lars-Peter Clausen; +Cc: Vinod Koul, Dan Williams, Russell King, linux-kernel


Hi Lars

> On 01/31/2012 02:13 AM, Kuninori Morimoto wrote:
> > dmaengine_prep_slave_single() is helper macro of dmaengine.
> > But it doesn't have sg_dma_address/len() settings which are required.
> > And it used void *buf in parameter, but it should be dma_addr_t.
> > This patch fixes up it.
> > 
> > Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
> 
> Hi,
> 
> Any news regarding this patch? The dmaengine_prep_slave_single in upstream
> is not really usable as it is right now.

Sorry. I have no news/update for this.
I'm not good at IOMMU which was pointed by Russell.

Best regards
---
Kuninori Morimoto

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

* Re: [PATCH v2] dmaengine: care sd_dma_address/len in dmaengine_prep_slave_single()
  2012-03-09  0:18       ` Kuninori Morimoto
@ 2012-03-10 11:12         ` Lars-Peter Clausen
  2012-03-13  0:46           ` Kuninori Morimoto
  0 siblings, 1 reply; 10+ messages in thread
From: Lars-Peter Clausen @ 2012-03-10 11:12 UTC (permalink / raw)
  To: Kuninori Morimoto; +Cc: Vinod Koul, Dan Williams, Russell King, linux-kernel

On 03/09/2012 01:18 AM, Kuninori Morimoto wrote:
> 
> Hi Lars
> 
>> On 01/31/2012 02:13 AM, Kuninori Morimoto wrote:
>>> dmaengine_prep_slave_single() is helper macro of dmaengine.
>>> But it doesn't have sg_dma_address/len() settings which are required.
>>> And it used void *buf in parameter, but it should be dma_addr_t.
>>> This patch fixes up it.
>>>
>>> Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
>>
>> Hi,
>>
>> Any news regarding this patch? The dmaengine_prep_slave_single in upstream
>> is not really usable as it is right now.
> 
> Sorry. I have no news/update for this.
> I'm not good at IOMMU which was pointed by Russell.
> 
> Best regards
> ---
> Kuninori Morimoto


Well, he pointed out a minor and easy to fix flaw with the patch. But if you
don't want to resend the patch is it OK for you, if I resend the patch with the
flaw fixed? And is it OK, if I keep your Signed-off-by on that patch?

Thanks,
- Lars

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

* Re: [PATCH v2] dmaengine: care sd_dma_address/len in dmaengine_prep_slave_single()
  2012-03-10 11:12         ` Lars-Peter Clausen
@ 2012-03-13  0:46           ` Kuninori Morimoto
  0 siblings, 0 replies; 10+ messages in thread
From: Kuninori Morimoto @ 2012-03-13  0:46 UTC (permalink / raw)
  To: Lars-Peter Clausen; +Cc: Vinod Koul, Dan Williams, Russell King, linux-kernel


Hi Lars

> > Sorry. I have no news/update for this.
> > I'm not good at IOMMU which was pointed by Russell.
(snip)
> Well, he pointed out a minor and easy to fix flaw with the patch. But if you
> don't want to resend the patch is it OK for you, if I resend the patch with the
> flaw fixed? And is it OK, if I keep your Signed-off-by on that patch?

Thank you for your help.
Yes I agree.
I want Reported-by for it

Best regards
---
Kuninori Morimoto

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

* Re: [PATCH v2] dmaengine: care sd_dma_address/len in dmaengine_prep_slave_single()
  2012-02-01 18:22     ` Russell King - ARM Linux
@ 2012-04-25 14:18       ` Lars-Peter Clausen
  2012-04-25 14:29         ` Russell King - ARM Linux
  0 siblings, 1 reply; 10+ messages in thread
From: Lars-Peter Clausen @ 2012-04-25 14:18 UTC (permalink / raw)
  To: Russell King - ARM Linux
  Cc: Kuninori Morimoto, Vinod Koul, Dan Williams, linux-kernel

On 02/01/2012 07:22 PM, Russell King - ARM Linux wrote:
> On Mon, Jan 30, 2012 at 05:13:30PM -0800, Kuninori Morimoto wrote:
>> +	sg_init_table(&sg, 1);
>> +	sg_set_page(&sg, pfn_to_page(PFN_DOWN(buf)),
>> +		    len, offset_in_page(buf));
> 
> There's not much point setting this - the page/virtual address should
> not be used by DMA engines as that may not reflect what's being requested
> (especially if there's an IOMMU in the way.)

I was just looking at this again and there are actually quite a few dma
engine drivers which use sg->length and sg_phys(sg). I guess these would
break if the sg_set_page was to be removed. Should these drivers be changed
to use sg_dma_len and sg_dma_address?

Thanks
- Lars

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

* Re: [PATCH v2] dmaengine: care sd_dma_address/len in dmaengine_prep_slave_single()
  2012-04-25 14:18       ` Lars-Peter Clausen
@ 2012-04-25 14:29         ` Russell King - ARM Linux
  0 siblings, 0 replies; 10+ messages in thread
From: Russell King - ARM Linux @ 2012-04-25 14:29 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: Kuninori Morimoto, Vinod Koul, Dan Williams, linux-kernel

On Wed, Apr 25, 2012 at 04:18:23PM +0200, Lars-Peter Clausen wrote:
> On 02/01/2012 07:22 PM, Russell King - ARM Linux wrote:
> > On Mon, Jan 30, 2012 at 05:13:30PM -0800, Kuninori Morimoto wrote:
> >> +	sg_init_table(&sg, 1);
> >> +	sg_set_page(&sg, pfn_to_page(PFN_DOWN(buf)),
> >> +		    len, offset_in_page(buf));
> > 
> > There's not much point setting this - the page/virtual address should
> > not be used by DMA engines as that may not reflect what's being requested
> > (especially if there's an IOMMU in the way.)
> 
> I was just looking at this again and there are actually quite a few dma
> engine drivers which use sg->length and sg_phys(sg). I guess these would
> break if the sg_set_page was to be removed. Should these drivers be changed
> to use sg_dma_len and sg_dma_address?

sg->length is meaningless to something performing DMA - and that's probably
a bug you've found.

In cases where sg_dma_len(sg) and sg->length are the same storage, then
there's no problem.  But scatterlists _can_ (and one some architectures)
do split them - especially when you have an IOMMU which can allow you to
combine a scatterlist into fewer entries.

So, anything using sg->length for the size of a scatterlist's DMA transfer
_after_ a call to dma_map_sg() is almost certainly buggy.

sg_phys(sg) of course has nothing to do with DMA addresses.  It's the
physical address _to the CPU_ of the memory associated with the scatterlist
entry.  That may, or may not have the same value for the DMA engine,
particularly if IOMMUs are involved.  So again, that's a bug.

And if these drivers are used on ARM, they must be fixed, sooner rather
than later.  There's patches in the works which will mean we will end up
with IOMMU support in the DMA mapping later, which means everything I've
said above will become reality.

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

end of thread, other threads:[~2012-04-25 14:29 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-30  9:25 [PATCH] dmaengine: care sd_dma_address/len in dmaengine_prep_slave_single() Kuninori Morimoto
2012-01-30  9:56 ` Vinod Koul
2012-01-31  1:13   ` [PATCH v2] " Kuninori Morimoto
2012-02-01 18:22     ` Russell King - ARM Linux
2012-04-25 14:18       ` Lars-Peter Clausen
2012-04-25 14:29         ` Russell King - ARM Linux
2012-03-08  9:48     ` Lars-Peter Clausen
2012-03-09  0:18       ` Kuninori Morimoto
2012-03-10 11:12         ` Lars-Peter Clausen
2012-03-13  0:46           ` Kuninori Morimoto

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).