public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] MIPS: DMA: fix coherent alloc in non-coherent systems
@ 2014-10-30  1:48 Leonid Yegoshin
  2014-10-30  9:48 ` Markos Chandras
  2014-10-30 10:07 ` James Hogan
  0 siblings, 2 replies; 6+ messages in thread
From: Leonid Yegoshin @ 2014-10-30  1:48 UTC (permalink / raw)
  To: linux-mips, nbd, yanh, linux-kernel, ralf, alex.smith, taohl,
	chenhc, blogic

A default dma_alloc_coherent() fails to alloc a coherent memory on non-coherent
systems in case of device->coherent_dma_mask covering the whole memory space.

In case of non-coherent systems the coherent memory on MIPS is restricted by
size of un-cachable segment and should be located in ZONE_DMA.

Added __GFP_DMA flag in case of non-coherent systems to enforce an allocation
of coherent memory in ZONE_DMA.

Signed-off-by: Leonid Yegoshin <Leonid.Yegoshin@imgtec.com>
---
 .../include/asm/mach-cavium-octeon/dma-coherence.h |    2 +-
 arch/mips/include/asm/mach-generic/dma-coherence.h |    2 +-
 arch/mips/include/asm/mach-ip27/dma-coherence.h    |    2 +-
 arch/mips/include/asm/mach-ip32/dma-coherence.h    |    2 +-
 arch/mips/include/asm/mach-jazz/dma-coherence.h    |    2 +-
 .../mips/include/asm/mach-loongson/dma-coherence.h |    2 +-
 arch/mips/mm/dma-default.c                         |   11 ++++++++---
 7 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h b/arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h
index f9f4486..fe0b465 100644
--- a/arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h
+++ b/arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h
@@ -52,7 +52,7 @@ static inline int plat_dma_supported(struct device *dev, u64 mask)
 	return 0;
 }
 
-static inline int plat_device_is_coherent(struct device *dev)
+static inline int plat_device_is_coherent(const struct device *dev)
 {
 	return 1;
 }
diff --git a/arch/mips/include/asm/mach-generic/dma-coherence.h b/arch/mips/include/asm/mach-generic/dma-coherence.h
index b4563df..2283996 100644
--- a/arch/mips/include/asm/mach-generic/dma-coherence.h
+++ b/arch/mips/include/asm/mach-generic/dma-coherence.h
@@ -47,7 +47,7 @@ static inline int plat_dma_supported(struct device *dev, u64 mask)
 	return 1;
 }
 
-static inline int plat_device_is_coherent(struct device *dev)
+static inline int plat_device_is_coherent(const struct device *dev)
 {
 #ifdef CONFIG_DMA_COHERENT
 	return 1;
diff --git a/arch/mips/include/asm/mach-ip27/dma-coherence.h b/arch/mips/include/asm/mach-ip27/dma-coherence.h
index 4ffddfd..c7767e3 100644
--- a/arch/mips/include/asm/mach-ip27/dma-coherence.h
+++ b/arch/mips/include/asm/mach-ip27/dma-coherence.h
@@ -58,7 +58,7 @@ static inline int plat_dma_supported(struct device *dev, u64 mask)
 	return 1;
 }
 
-static inline int plat_device_is_coherent(struct device *dev)
+static inline int plat_device_is_coherent(const struct device *dev)
 {
 	return 1;		/* IP27 non-cohernet mode is unsupported */
 }
diff --git a/arch/mips/include/asm/mach-ip32/dma-coherence.h b/arch/mips/include/asm/mach-ip32/dma-coherence.h
index 104cfbc..a6b6a55 100644
--- a/arch/mips/include/asm/mach-ip32/dma-coherence.h
+++ b/arch/mips/include/asm/mach-ip32/dma-coherence.h
@@ -80,7 +80,7 @@ static inline int plat_dma_supported(struct device *dev, u64 mask)
 	return 1;
 }
 
-static inline int plat_device_is_coherent(struct device *dev)
+static inline int plat_device_is_coherent(const struct device *dev)
 {
 	return 0;		/* IP32 is non-cohernet */
 }
diff --git a/arch/mips/include/asm/mach-jazz/dma-coherence.h b/arch/mips/include/asm/mach-jazz/dma-coherence.h
index 949003e..57c1a6c 100644
--- a/arch/mips/include/asm/mach-jazz/dma-coherence.h
+++ b/arch/mips/include/asm/mach-jazz/dma-coherence.h
@@ -48,7 +48,7 @@ static inline int plat_dma_supported(struct device *dev, u64 mask)
 	return 1;
 }
 
-static inline int plat_device_is_coherent(struct device *dev)
+static inline int plat_device_is_coherent(const struct device *dev)
 {
 	return 0;
 }
diff --git a/arch/mips/include/asm/mach-loongson/dma-coherence.h b/arch/mips/include/asm/mach-loongson/dma-coherence.h
index 6a90275..555d21b 100644
--- a/arch/mips/include/asm/mach-loongson/dma-coherence.h
+++ b/arch/mips/include/asm/mach-loongson/dma-coherence.h
@@ -69,7 +69,7 @@ static inline int plat_dma_supported(struct device *dev, u64 mask)
 	return 1;
 }
 
-static inline int plat_device_is_coherent(struct device *dev)
+static inline int plat_device_is_coherent(const struct device *dev)
 {
 #ifdef CONFIG_DMA_NONCOHERENT
 	return 0;
diff --git a/arch/mips/mm/dma-default.c b/arch/mips/mm/dma-default.c
index 42c819a..36e2237 100644
--- a/arch/mips/mm/dma-default.c
+++ b/arch/mips/mm/dma-default.c
@@ -69,7 +69,7 @@ static inline int cpu_needs_post_dma_flush(struct device *dev)
 		boot_cpu_type() == CPU_BMIPS5000);
 }
 
-static gfp_t massage_gfp_flags(const struct device *dev, gfp_t gfp)
+static gfp_t massage_gfp_flags(const struct device *dev, gfp_t gfp, int coherent)
 {
 	gfp_t dma_flag;
 
@@ -81,6 +81,11 @@ static gfp_t massage_gfp_flags(const struct device *dev, gfp_t gfp)
 		dma_flag = __GFP_DMA;
 	else
 #endif
+#ifdef CONFIG_ZONE_DMA
+	     if (coherent && !plat_device_is_coherent(dev))
+			dma_flag = __GFP_DMA;
+	else
+#endif
 #if defined(CONFIG_ZONE_DMA32) && defined(CONFIG_ZONE_DMA)
 	     if (dev->coherent_dma_mask < DMA_BIT_MASK(32))
 			dma_flag = __GFP_DMA;
@@ -111,7 +116,7 @@ void *dma_alloc_noncoherent(struct device *dev, size_t size,
 {
 	void *ret;
 
-	gfp = massage_gfp_flags(dev, gfp);
+	gfp = massage_gfp_flags(dev, gfp, 0);
 
 	ret = (void *) __get_free_pages(gfp, get_order(size));
 
@@ -132,7 +137,7 @@ static void *mips_dma_alloc_coherent(struct device *dev, size_t size,
 	if (dma_alloc_from_coherent(dev, size, dma_handle, &ret))
 		return ret;
 
-	gfp = massage_gfp_flags(dev, gfp);
+	gfp = massage_gfp_flags(dev, gfp, 1);
 
 	ret = (void *) __get_free_pages(gfp, get_order(size));
 


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

* Re: [PATCH] MIPS: DMA: fix coherent alloc in non-coherent systems
  2014-10-30  1:48 [PATCH] MIPS: DMA: fix coherent alloc in non-coherent systems Leonid Yegoshin
@ 2014-10-30  9:48 ` Markos Chandras
  2014-10-30  9:51   ` James Hogan
  2014-10-30 10:07 ` James Hogan
  1 sibling, 1 reply; 6+ messages in thread
From: Markos Chandras @ 2014-10-30  9:48 UTC (permalink / raw)
  To: Leonid Yegoshin, linux-mips, nbd, yanh, linux-kernel, ralf,
	alex.smith, taohl, chenhc, blogic

Hi,

On 10/30/2014 01:48 AM, Leonid Yegoshin wrote:
> A default dma_alloc_coherent() fails to alloc a coherent memory on non-coherent
> systems in case of device->coherent_dma_mask covering the whole memory space.
> 
> In case of non-coherent systems the coherent memory on MIPS is restricted by
> size of un-cachable segment and should be located in ZONE_DMA.
> 
> Added __GFP_DMA flag in case of non-coherent systems to enforce an allocation
> of coherent memory in ZONE_DMA.
> 
> Signed-off-by: Leonid Yegoshin <Leonid.Yegoshin@imgtec.com>
> ---
>  .../include/asm/mach-cavium-octeon/dma-coherence.h |    2 +-
>  arch/mips/include/asm/mach-generic/dma-coherence.h |    2 +-
>  arch/mips/include/asm/mach-ip27/dma-coherence.h    |    2 +-
>  arch/mips/include/asm/mach-ip32/dma-coherence.h    |    2 +-
>  arch/mips/include/asm/mach-jazz/dma-coherence.h    |    2 +-
>  .../mips/include/asm/mach-loongson/dma-coherence.h |    2 +-
>  arch/mips/mm/dma-default.c                         |   11 ++++++++---
>  7 files changed, 14 insertions(+), 9 deletions(-)
> 
> diff --git a/arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h b/arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h
> index f9f4486..fe0b465 100644
> --- a/arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h
> +++ b/arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h
> @@ -52,7 +52,7 @@ static inline int plat_dma_supported(struct device *dev, u64 mask)
>  	return 0;
>  }
>  
> -static inline int plat_device_is_coherent(struct device *dev)
> +static inline int plat_device_is_coherent(const struct device *dev)

Why adding const here?

>  {
>  	return 1;
>  }
> diff --git a/arch/mips/include/asm/mach-generic/dma-coherence.h b/arch/mips/include/asm/mach-generic/dma-coherence.h
> index b4563df..2283996 100644
> --- a/arch/mips/include/asm/mach-generic/dma-coherence.h
> +++ b/arch/mips/include/asm/mach-generic/dma-coherence.h
> @@ -47,7 +47,7 @@ static inline int plat_dma_supported(struct device *dev, u64 mask)
>  	return 1;
>  }
>  
> -static inline int plat_device_is_coherent(struct device *dev)
> +static inline int plat_device_is_coherent(const struct device *dev)

likewise

>  {
>  #ifdef CONFIG_DMA_COHERENT
>  	return 1;
> diff --git a/arch/mips/include/asm/mach-ip27/dma-coherence.h b/arch/mips/include/asm/mach-ip27/dma-coherence.h
> index 4ffddfd..c7767e3 100644
> --- a/arch/mips/include/asm/mach-ip27/dma-coherence.h
> +++ b/arch/mips/include/asm/mach-ip27/dma-coherence.h
> @@ -58,7 +58,7 @@ static inline int plat_dma_supported(struct device *dev, u64 mask)
>  	return 1;
>  }
>  
> -static inline int plat_device_is_coherent(struct device *dev)
> +static inline int plat_device_is_coherent(const struct device *dev)

likewise

>  {
>  	return 1;		/* IP27 non-cohernet mode is unsupported */
>  }
> diff --git a/arch/mips/include/asm/mach-ip32/dma-coherence.h b/arch/mips/include/asm/mach-ip32/dma-coherence.h
> index 104cfbc..a6b6a55 100644
> --- a/arch/mips/include/asm/mach-ip32/dma-coherence.h
> +++ b/arch/mips/include/asm/mach-ip32/dma-coherence.h
> @@ -80,7 +80,7 @@ static inline int plat_dma_supported(struct device *dev, u64 mask)
>  	return 1;
>  }
>  
> -static inline int plat_device_is_coherent(struct device *dev)
> +static inline int plat_device_is_coherent(const struct device *dev)

likewise etc

Is it just a matter of consistence with the rest of the interfaces? Do
you need to move these into a separate patch since they don't quite fit
here.

-- 
markos

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

* Re: [PATCH] MIPS: DMA: fix coherent alloc in non-coherent systems
  2014-10-30  9:48 ` Markos Chandras
@ 2014-10-30  9:51   ` James Hogan
  2014-10-30  9:54     ` Markos Chandras
  0 siblings, 1 reply; 6+ messages in thread
From: James Hogan @ 2014-10-30  9:51 UTC (permalink / raw)
  To: Markos Chandras, Leonid Yegoshin, linux-mips, nbd, yanh,
	linux-kernel, ralf, alex.smith, taohl, chenhc, blogic

Hi Markos,

On 30/10/14 09:48, Markos Chandras wrote:
>> diff --git a/arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h b/arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h
>> index f9f4486..fe0b465 100644
>> --- a/arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h
>> +++ b/arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h
>> @@ -52,7 +52,7 @@ static inline int plat_dma_supported(struct device *dev, u64 mask)
>>  	return 0;
>>  }
>>  
>> -static inline int plat_device_is_coherent(struct device *dev)
>> +static inline int plat_device_is_coherent(const struct device *dev)
> 
> Why adding const here?
> 

<snip>

> Is it just a matter of consistence with the rest of the interfaces? Do
> you need to move these into a separate patch since they don't quite fit
> here.

See the new new call to plat_device_is_coherent(), which passes dev,
which is const.

Cheers
James

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

* Re: [PATCH] MIPS: DMA: fix coherent alloc in non-coherent systems
  2014-10-30  9:51   ` James Hogan
@ 2014-10-30  9:54     ` Markos Chandras
  0 siblings, 0 replies; 6+ messages in thread
From: Markos Chandras @ 2014-10-30  9:54 UTC (permalink / raw)
  To: James Hogan, Leonid Yegoshin, linux-mips, nbd, yanh, linux-kernel,
	ralf, alex.smith, taohl, chenhc, blogic

On 10/30/2014 09:51 AM, James Hogan wrote:
> Hi Markos,
> 
> On 30/10/14 09:48, Markos Chandras wrote:
>>> diff --git a/arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h b/arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h
>>> index f9f4486..fe0b465 100644
>>> --- a/arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h
>>> +++ b/arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h
>>> @@ -52,7 +52,7 @@ static inline int plat_dma_supported(struct device *dev, u64 mask)
>>>  	return 0;
>>>  }
>>>  
>>> -static inline int plat_device_is_coherent(struct device *dev)
>>> +static inline int plat_device_is_coherent(const struct device *dev)
>>
>> Why adding const here?
>>
> 
> <snip>
> 
>> Is it just a matter of consistence with the rest of the interfaces? Do
>> you need to move these into a separate patch since they don't quite fit
>> here.
> 
> See the new new call to plat_device_is_coherent(), which passes dev,
> which is const.
> 
> Cheers
> James
> 
Ah yes you are right. Thanks!

-- 
markos

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

* Re: [PATCH] MIPS: DMA: fix coherent alloc in non-coherent systems
  2014-10-30  1:48 [PATCH] MIPS: DMA: fix coherent alloc in non-coherent systems Leonid Yegoshin
  2014-10-30  9:48 ` Markos Chandras
@ 2014-10-30 10:07 ` James Hogan
  2014-10-30 18:38   ` Leonid Yegoshin
  1 sibling, 1 reply; 6+ messages in thread
From: James Hogan @ 2014-10-30 10:07 UTC (permalink / raw)
  To: Leonid Yegoshin, linux-mips, nbd, yanh, linux-kernel, ralf,
	alex.smith, taohl, chenhc, blogic

Hi Leonid,

On 30/10/14 01:48, Leonid Yegoshin wrote:
> A default dma_alloc_coherent() fails to alloc a coherent memory on non-coherent
> systems in case of device->coherent_dma_mask covering the whole memory space.
> 
> In case of non-coherent systems the coherent memory on MIPS is restricted by
> size of un-cachable segment and should be located in ZONE_DMA.

Has this pretty much always been broken?

> @@ -81,6 +81,11 @@ static gfp_t massage_gfp_flags(const struct device *dev, gfp_t gfp)
>  		dma_flag = __GFP_DMA;
>  	else
>  #endif
> +#ifdef CONFIG_ZONE_DMA
> +	     if (coherent && !plat_device_is_coherent(dev))

Broken indentation. Please fix to use tabs.

> +			dma_flag = __GFP_DMA;
> +	else
> +#endif
>  #if defined(CONFIG_ZONE_DMA32) && defined(CONFIG_ZONE_DMA)
>  	     if (dev->coherent_dma_mask < DMA_BIT_MASK(32))
>  			dma_flag = __GFP_DMA;

Other than that, this patch looks okay to me (but those with more
experience with MIPS DMA than me may know better).

Reviewed-by: James Hogan <james.hogan@imgtec.com>

Thanks
James

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

* Re: [PATCH] MIPS: DMA: fix coherent alloc in non-coherent systems
  2014-10-30 10:07 ` James Hogan
@ 2014-10-30 18:38   ` Leonid Yegoshin
  0 siblings, 0 replies; 6+ messages in thread
From: Leonid Yegoshin @ 2014-10-30 18:38 UTC (permalink / raw)
  To: James Hogan
  Cc: linux-mips, nbd, yanh, linux-kernel, ralf, alex.smith, taohl,
	chenhc, blogic

On 10/30/2014 03:07 AM, James Hogan wrote:
> Hi Leonid,
>
> On 30/10/14 01:48, Leonid Yegoshin wrote:
>> A default dma_alloc_coherent() fails to alloc a coherent memory on non-coherent
>> systems in case of device->coherent_dma_mask covering the whole memory space.
>>
>> In case of non-coherent systems the coherent memory on MIPS is restricted by
>> size of un-cachable segment and should be located in ZONE_DMA.
> Has this pretty much always been broken?
>
>
Yes, but it can be seen on MIPS32 EVA-based CPUs.

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

end of thread, other threads:[~2014-10-30 18:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-30  1:48 [PATCH] MIPS: DMA: fix coherent alloc in non-coherent systems Leonid Yegoshin
2014-10-30  9:48 ` Markos Chandras
2014-10-30  9:51   ` James Hogan
2014-10-30  9:54     ` Markos Chandras
2014-10-30 10:07 ` James Hogan
2014-10-30 18:38   ` Leonid Yegoshin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox