linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] arm64: Implement arch_setup_pdev_archdata hook
@ 2016-06-07  8:29 Baolin Wang
  2016-06-07  8:43 ` Arnd Bergmann
  2016-06-07  9:15 ` Robin Murphy
  0 siblings, 2 replies; 7+ messages in thread
From: Baolin Wang @ 2016-06-07  8:29 UTC (permalink / raw)
  To: catalin.marinas, will.deacon
  Cc: robin.murphy, jroedel, akpm, jszhang, Suravee.Suthikulpanit,
	arnd, linux-arm-kernel, linux-kernel, broonie, balbi,
	baolin.wang

Now on ARM64 platform, it will set 'dummy_dma_ops' for device dma_ops if
it did not call 'arch_setup_dma_ops' at device creation time by issuing
platform_device_alloc() function, that will cause failure when setting
the dma mask for device.

Hence We need to hook the archdata to setup proper dma_ops for these devices.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
 arch/arm64/mm/dma-mapping.c |   21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c
index c566ec8..04e057b 100644
--- a/arch/arm64/mm/dma-mapping.c
+++ b/arch/arm64/mm/dma-mapping.c
@@ -26,6 +26,7 @@
 #include <linux/dma-contiguous.h>
 #include <linux/vmalloc.h>
 #include <linux/swiotlb.h>
+#include <linux/platform_device.h>
 
 #include <asm/cacheflush.h>
 
@@ -961,3 +962,23 @@ void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size,
 	dev->archdata.dma_coherent = coherent;
 	__iommu_setup_dma_ops(dev, dma_base, size, iommu);
 }
+
+void arch_setup_pdev_archdata(struct platform_device *pdev)
+{
+	if (!pdev->dev.archdata.dma_ops)
+		pdev->dev.archdata.dma_ops = &swiotlb_dma_ops;
+
+	/*
+	 * Set default coherent_dma_mask to 32 bit. Drivers are expected to
+	 * setup the correct supported mask.
+	 */
+	if (!pdev->dev.coherent_dma_mask)
+		pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
+
+	/*
+	 * Set it to coherent_dma_mask by default if the architecture
+	 * code has not set it.
+	 */
+	if (!pdev->dev.dma_mask)
+		pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
+}
-- 
1.7.9.5

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

* Re: [PATCH] arm64: Implement arch_setup_pdev_archdata hook
  2016-06-07  8:29 [PATCH] arm64: Implement arch_setup_pdev_archdata hook Baolin Wang
@ 2016-06-07  8:43 ` Arnd Bergmann
  2016-06-13  8:26   ` Baolin Wang
  2016-06-07  9:15 ` Robin Murphy
  1 sibling, 1 reply; 7+ messages in thread
From: Arnd Bergmann @ 2016-06-07  8:43 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: Baolin Wang, catalin.marinas, will.deacon, jszhang, balbi,
	jroedel, linux-kernel, broonie, Suravee.Suthikulpanit, akpm,
	robin.murphy

On Tuesday, June 7, 2016 4:29:21 PM CEST Baolin Wang wrote:
> Now on ARM64 platform, it will set 'dummy_dma_ops' for device dma_ops if
> it did not call 'arch_setup_dma_ops' at device creation time by issuing
> platform_device_alloc() function, that will cause failure when setting
> the dma mask for device.
> 
> Hence We need to hook the archdata to setup proper dma_ops for these devices.
> 
> Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
> ---
>  arch/arm64/mm/dma-mapping.c |   21 +++++++++++++++++++++
>  1 file changed, 21 insertions(+)
> 
> diff --git a/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c
> index c566ec8..04e057b 100644
> --- a/arch/arm64/mm/dma-mapping.c
> +++ b/arch/arm64/mm/dma-mapping.c
> @@ -26,6 +26,7 @@
>  #include <linux/dma-contiguous.h>
>  #include <linux/vmalloc.h>
>  #include <linux/swiotlb.h>
> +#include <linux/platform_device.h>
>  
>  #include <asm/cacheflush.h>
>  
> @@ -961,3 +962,23 @@ void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size,
>  	dev->archdata.dma_coherent = coherent;
>  	__iommu_setup_dma_ops(dev, dma_base, size, iommu);
>  }
> +
> +void arch_setup_pdev_archdata(struct platform_device *pdev)
> +{
> +	if (!pdev->dev.archdata.dma_ops)
> +		pdev->dev.archdata.dma_ops = &swiotlb_dma_ops;

You need to check the DT here to see if these are the right ops,
or if you have to go through an IOMMU. Also, you have to set up the
other fields that are controlled by arch_setup_dma_ops: whether
it's coherent and what the offset is.

> +	/*
> +	 * Set default coherent_dma_mask to 32 bit. Drivers are expected to
> +	 * setup the correct supported mask.
> +	 */
> +	if (!pdev->dev.coherent_dma_mask)
> +		pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
> +
> +	/*
> +	 * Set it to coherent_dma_mask by default if the architecture
> +	 * code has not set it.
> +	 */
> +	if (!pdev->dev.dma_mask)
> +		pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
> +}

We still have an open bug about the dma_set_mask() function on ARM64:
we have to check the dma-ranges property to ensure that no device can
set a mask wider than what its parent bus can support.

What is your plan for this in case of these devices?

	Arnd

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

* Re: [PATCH] arm64: Implement arch_setup_pdev_archdata hook
  2016-06-07  8:29 [PATCH] arm64: Implement arch_setup_pdev_archdata hook Baolin Wang
  2016-06-07  8:43 ` Arnd Bergmann
@ 2016-06-07  9:15 ` Robin Murphy
  2016-06-07  9:22   ` Baolin Wang
  1 sibling, 1 reply; 7+ messages in thread
From: Robin Murphy @ 2016-06-07  9:15 UTC (permalink / raw)
  To: Baolin Wang, catalin.marinas, will.deacon
  Cc: jroedel, akpm, jszhang, Suravee.Suthikulpanit, arnd,
	linux-arm-kernel, linux-kernel, broonie, balbi

On 07/06/16 09:29, Baolin Wang wrote:
> Now on ARM64 platform, it will set 'dummy_dma_ops' for device dma_ops if
> it did not call 'arch_setup_dma_ops' at device creation time by issuing
> platform_device_alloc() function, that will cause failure when setting
> the dma mask for device.

Yes, that's rather the whole point. DMA-capable devices are real 
hardware, therefore don't spring out of thin air without being described 
in DT or ACPI.

Please elaborate on the situation that you're attempting to address here 
(please don't let it be the ongoing Designware USB catastrophe ;))

Robin.

> Hence We need to hook the archdata to setup proper dma_ops for these devices.
>
> Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
> ---
>   arch/arm64/mm/dma-mapping.c |   21 +++++++++++++++++++++
>   1 file changed, 21 insertions(+)
>
> diff --git a/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c
> index c566ec8..04e057b 100644
> --- a/arch/arm64/mm/dma-mapping.c
> +++ b/arch/arm64/mm/dma-mapping.c
> @@ -26,6 +26,7 @@
>   #include <linux/dma-contiguous.h>
>   #include <linux/vmalloc.h>
>   #include <linux/swiotlb.h>
> +#include <linux/platform_device.h>
>
>   #include <asm/cacheflush.h>
>
> @@ -961,3 +962,23 @@ void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size,
>   	dev->archdata.dma_coherent = coherent;
>   	__iommu_setup_dma_ops(dev, dma_base, size, iommu);
>   }
> +
> +void arch_setup_pdev_archdata(struct platform_device *pdev)
> +{
> +	if (!pdev->dev.archdata.dma_ops)
> +		pdev->dev.archdata.dma_ops = &swiotlb_dma_ops;
> +
> +	/*
> +	 * Set default coherent_dma_mask to 32 bit. Drivers are expected to
> +	 * setup the correct supported mask.
> +	 */
> +	if (!pdev->dev.coherent_dma_mask)
> +		pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
> +
> +	/*
> +	 * Set it to coherent_dma_mask by default if the architecture
> +	 * code has not set it.
> +	 */
> +	if (!pdev->dev.dma_mask)
> +		pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
> +}
>

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

* Re: [PATCH] arm64: Implement arch_setup_pdev_archdata hook
  2016-06-07  9:15 ` Robin Murphy
@ 2016-06-07  9:22   ` Baolin Wang
  2016-06-14 14:43     ` Catalin Marinas
  0 siblings, 1 reply; 7+ messages in thread
From: Baolin Wang @ 2016-06-07  9:22 UTC (permalink / raw)
  To: Robin Murphy
  Cc: catalin.marinas, will.deacon, jroedel, Andrew Morton,
	Jisheng Zhang, Suravee.Suthikulpanit, Arnd Bergmann,
	linux-arm-kernel, LKML, Mark Brown, Felipe Balbi

On 7 June 2016 at 17:15, Robin Murphy <robin.murphy@arm.com> wrote:
> On 07/06/16 09:29, Baolin Wang wrote:
>>
>> Now on ARM64 platform, it will set 'dummy_dma_ops' for device dma_ops if
>> it did not call 'arch_setup_dma_ops' at device creation time by issuing
>> platform_device_alloc() function, that will cause failure when setting
>> the dma mask for device.
>
>
> Yes, that's rather the whole point. DMA-capable devices are real hardware,
> therefore don't spring out of thin air without being described in DT or
> ACPI.

OK.

>
> Please elaborate on the situation that you're attempting to address here
> (please don't let it be the ongoing Designware USB catastrophe ;))

Yes, like you mentioned, we met problems at DesignWare USB3 controller
host glue, do you have any better solutions to solve this problem?
Thanks.

>
> Robin.
>
>
>> Hence We need to hook the archdata to setup proper dma_ops for these
>> devices.
>>
>> Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
>> ---
>>   arch/arm64/mm/dma-mapping.c |   21 +++++++++++++++++++++
>>   1 file changed, 21 insertions(+)
>>
>> diff --git a/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c
>> index c566ec8..04e057b 100644
>> --- a/arch/arm64/mm/dma-mapping.c
>> +++ b/arch/arm64/mm/dma-mapping.c
>> @@ -26,6 +26,7 @@
>>   #include <linux/dma-contiguous.h>
>>   #include <linux/vmalloc.h>
>>   #include <linux/swiotlb.h>
>> +#include <linux/platform_device.h>
>>
>>   #include <asm/cacheflush.h>
>>
>> @@ -961,3 +962,23 @@ void arch_setup_dma_ops(struct device *dev, u64
>> dma_base, u64 size,
>>         dev->archdata.dma_coherent = coherent;
>>         __iommu_setup_dma_ops(dev, dma_base, size, iommu);
>>   }
>> +
>> +void arch_setup_pdev_archdata(struct platform_device *pdev)
>> +{
>> +       if (!pdev->dev.archdata.dma_ops)
>> +               pdev->dev.archdata.dma_ops = &swiotlb_dma_ops;
>> +
>> +       /*
>> +        * Set default coherent_dma_mask to 32 bit. Drivers are expected
>> to
>> +        * setup the correct supported mask.
>> +        */
>> +       if (!pdev->dev.coherent_dma_mask)
>> +               pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
>> +
>> +       /*
>> +        * Set it to coherent_dma_mask by default if the architecture
>> +        * code has not set it.
>> +        */
>> +       if (!pdev->dev.dma_mask)
>> +               pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
>> +}
>>
>



-- 
Baolin.wang
Best Regards

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

* Re: [PATCH] arm64: Implement arch_setup_pdev_archdata hook
  2016-06-07  8:43 ` Arnd Bergmann
@ 2016-06-13  8:26   ` Baolin Wang
  0 siblings, 0 replies; 7+ messages in thread
From: Baolin Wang @ 2016-06-13  8:26 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: linux-arm-kernel, Catalin Marinas, Will Deacon, Jisheng Zhang,
	Felipe Balbi, jroedel, LKML, Mark Brown, Suravee.Suthikulpanit,
	Andrew Morton, Robin Murphy

On 7 June 2016 at 16:43, Arnd Bergmann <arnd@arndb.de> wrote:
> On Tuesday, June 7, 2016 4:29:21 PM CEST Baolin Wang wrote:
>> Now on ARM64 platform, it will set 'dummy_dma_ops' for device dma_ops if
>> it did not call 'arch_setup_dma_ops' at device creation time by issuing
>> platform_device_alloc() function, that will cause failure when setting
>> the dma mask for device.
>>
>> Hence We need to hook the archdata to setup proper dma_ops for these devices.
>>
>> Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
>> ---
>>  arch/arm64/mm/dma-mapping.c |   21 +++++++++++++++++++++
>>  1 file changed, 21 insertions(+)
>>
>> diff --git a/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c
>> index c566ec8..04e057b 100644
>> --- a/arch/arm64/mm/dma-mapping.c
>> +++ b/arch/arm64/mm/dma-mapping.c
>> @@ -26,6 +26,7 @@
>>  #include <linux/dma-contiguous.h>
>>  #include <linux/vmalloc.h>
>>  #include <linux/swiotlb.h>
>> +#include <linux/platform_device.h>
>>
>>  #include <asm/cacheflush.h>
>>
>> @@ -961,3 +962,23 @@ void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size,
>>       dev->archdata.dma_coherent = coherent;
>>       __iommu_setup_dma_ops(dev, dma_base, size, iommu);
>>  }
>> +
>> +void arch_setup_pdev_archdata(struct platform_device *pdev)
>> +{
>> +     if (!pdev->dev.archdata.dma_ops)
>> +             pdev->dev.archdata.dma_ops = &swiotlb_dma_ops;
>
> You need to check the DT here to see if these are the right ops,
> or if you have to go through an IOMMU. Also, you have to set up the
> other fields that are controlled by arch_setup_dma_ops: whether
> it's coherent and what the offset is.

That's right. This is just set the platform device arch data, after
that the dma ops will be re-setup by issuing arch_setup_dma_ops(). But
some platform devices created by platform_device_alloc() will not
issue the arch_setup_dma_ops() function to setup the dma ops. So I
want to set the default dma ops by arch_setup_pdev_archdata(), but
that is not reasonable according to Robin's explanation.

>
>> +     /*
>> +      * Set default coherent_dma_mask to 32 bit. Drivers are expected to
>> +      * setup the correct supported mask.
>> +      */
>> +     if (!pdev->dev.coherent_dma_mask)
>> +             pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
>> +
>> +     /*
>> +      * Set it to coherent_dma_mask by default if the architecture
>> +      * code has not set it.
>> +      */
>> +     if (!pdev->dev.dma_mask)
>> +             pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
>> +}
>
> We still have an open bug about the dma_set_mask() function on ARM64:
> we have to check the dma-ranges property to ensure that no device can
> set a mask wider than what its parent bus can support.
>
> What is your plan for this in case of these devices?

I think these are just default setup for dma mask. I suppose the
checking you mentioned should be added in of_dma_configure()?

-- 
Baolin.wang
Best Regards

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

* Re: [PATCH] arm64: Implement arch_setup_pdev_archdata hook
  2016-06-07  9:22   ` Baolin Wang
@ 2016-06-14 14:43     ` Catalin Marinas
  2016-06-15  2:13       ` Baolin Wang
  0 siblings, 1 reply; 7+ messages in thread
From: Catalin Marinas @ 2016-06-14 14:43 UTC (permalink / raw)
  To: Baolin Wang
  Cc: Robin Murphy, Jisheng Zhang, Felipe Balbi, jroedel,
	Arnd Bergmann, will.deacon, LKML, Mark Brown,
	Suravee.Suthikulpanit, Andrew Morton, linux-arm-kernel

On Tue, Jun 07, 2016 at 05:22:25PM +0800, Baolin Wang wrote:
> On 7 June 2016 at 17:15, Robin Murphy <robin.murphy@arm.com> wrote:
> > Please elaborate on the situation that you're attempting to address here
> > (please don't let it be the ongoing Designware USB catastrophe ;))
> 
> Yes, like you mentioned, we met problems at DesignWare USB3 controller
> host glue, do you have any better solutions to solve this problem?

There has been a recent thread on this topic:

http://thread.gmane.org/gmane.linux.usb.general/140374

And a subsequent patch with another long discussion:

http://thread.gmane.org/gmane.linux.kernel/2207020

Please have a look, maybe you can make more sense of it ;). AFAICT,
there was no clear conclusion reached.

-- 
Catalin

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

* Re: [PATCH] arm64: Implement arch_setup_pdev_archdata hook
  2016-06-14 14:43     ` Catalin Marinas
@ 2016-06-15  2:13       ` Baolin Wang
  0 siblings, 0 replies; 7+ messages in thread
From: Baolin Wang @ 2016-06-15  2:13 UTC (permalink / raw)
  To: Catalin Marinas
  Cc: Robin Murphy, Jisheng Zhang, Felipe Balbi, jroedel,
	Arnd Bergmann, Will Deacon, LKML, Mark Brown,
	Suravee.Suthikulpanit, Andrew Morton, linux-arm-kernel

On 14 June 2016 at 22:43, Catalin Marinas <catalin.marinas@arm.com> wrote:
> On Tue, Jun 07, 2016 at 05:22:25PM +0800, Baolin Wang wrote:
>> On 7 June 2016 at 17:15, Robin Murphy <robin.murphy@arm.com> wrote:
>> > Please elaborate on the situation that you're attempting to address here
>> > (please don't let it be the ongoing Designware USB catastrophe ;))
>>
>> Yes, like you mentioned, we met problems at DesignWare USB3 controller
>> host glue, do you have any better solutions to solve this problem?
>
> There has been a recent thread on this topic:
>
> http://thread.gmane.org/gmane.linux.usb.general/140374
>
> And a subsequent patch with another long discussion:
>
> http://thread.gmane.org/gmane.linux.kernel/2207020
>
> Please have a look, maybe you can make more sense of it ;). AFAICT,
> there was no clear conclusion reached.

OK. Thanks for your updating.

>
> --
> Catalin



-- 
Baolin.wang
Best Regards

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

end of thread, other threads:[~2016-06-15  2:14 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-07  8:29 [PATCH] arm64: Implement arch_setup_pdev_archdata hook Baolin Wang
2016-06-07  8:43 ` Arnd Bergmann
2016-06-13  8:26   ` Baolin Wang
2016-06-07  9:15 ` Robin Murphy
2016-06-07  9:22   ` Baolin Wang
2016-06-14 14:43     ` Catalin Marinas
2016-06-15  2:13       ` Baolin Wang

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