2015-02-11 17:54:28

by Karicheri, Muralidharan

[permalink] [raw]
Subject: [PATCH v1] of: calculate masks of the device based on dma-range size

This patch update of_dma_configure() API to calculate the
masks (dma_mask and coherent_dma_mask) based on the dma-range
values set in DT for the device. Also limit the mask to lower
of the default mask and mask calculated.

Cc: Joerg Roedel <[email protected]>
Cc: Grant Likely <[email protected]>
Cc: Rob Herring <[email protected]>
Cc: Bjorn Helgaas <[email protected]>
Cc: Will Deacon <[email protected]>
Cc: Russell King <[email protected]>
Cc: Arnd Bergmann <[email protected]>
Cc: Suravee Suthikulpanit <[email protected]>

Signed-off-by: Murali Karicheri <[email protected]>
---
- apply on top of the series "[PATCH v6 0/7] PCI: get DMA configuration
from parent device" at http://www.spinics.net/lists/linux-pci/msg38699.html

v1 - updated based on comments. Reverted to original
code for of_dma_get_range() within the of_dma_configure()

drivers/of/device.c | 21 ++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/drivers/of/device.c b/drivers/of/device.c
index 314c8a9..167ad2d 100644
--- a/drivers/of/device.c
+++ b/drivers/of/device.c
@@ -90,10 +90,11 @@ void of_dma_configure(struct device *dev, struct device_node *np)
struct iommu_ops *iommu;

/*
- * Set default dma-mask to 32 bit. Drivers are expected to setup
- * the correct supported dma_mask.
+ * Set default coherent_dma_mask to 32 bit. Drivers are expected to
+ * setup the correct supported mask.
*/
- dev->coherent_dma_mask = DMA_BIT_MASK(32);
+ if (!dev->coherent_dma_mask)
+ dev->coherent_dma_mask = DMA_BIT_MASK(32);

/*
* Set it to coherent_dma_mask by default if the architecture
@@ -102,6 +103,11 @@ void of_dma_configure(struct device *dev, struct device_node *np)
if (!dev->dma_mask)
dev->dma_mask = &dev->coherent_dma_mask;

+ /*
+ * Use default size to cover 32 bit. Drivers need to set this in DT
+ * to override the same.
+ */
+ size = 1ULL << 32;
ret = of_dma_get_range(np, &dma_addr, &paddr, &size);
if (ret < 0) {
dma_addr = offset = 0;
@@ -128,6 +134,15 @@ void of_dma_configure(struct device *dev, struct device_node *np)

dev->dma_pfn_offset = offset;

+ /*
+ * Limit coherent and dma mask based on size and default mask
+ * set by the driver.
+ */
+ dev->coherent_dma_mask = min(dev->coherent_dma_mask,
+ DMA_BIT_MASK(ilog2(dma_addr + size)));
+ *dev->dma_mask = min((*dev->dma_mask),
+ DMA_BIT_MASK(ilog2(dma_addr + size)));
+
coherent = of_dma_is_coherent(np);
dev_dbg(dev, "device is%sdma coherent\n",
coherent ? " " : " not ");
--
1.7.9.5


2015-02-11 18:48:07

by Catalin Marinas

[permalink] [raw]
Subject: Re: [PATCH v1] of: calculate masks of the device based on dma-range size

On Wed, Feb 11, 2015 at 12:53:35PM -0500, Murali Karicheri wrote:
> diff --git a/drivers/of/device.c b/drivers/of/device.c
> index 314c8a9..167ad2d 100644
> --- a/drivers/of/device.c
> +++ b/drivers/of/device.c
> @@ -90,10 +90,11 @@ void of_dma_configure(struct device *dev, struct device_node *np)
> struct iommu_ops *iommu;
>
> /*
> - * Set default dma-mask to 32 bit. Drivers are expected to setup
> - * the correct supported dma_mask.
> + * Set default coherent_dma_mask to 32 bit. Drivers are expected to
> + * setup the correct supported mask.
> */
> - dev->coherent_dma_mask = DMA_BIT_MASK(32);
> + if (!dev->coherent_dma_mask)
> + dev->coherent_dma_mask = DMA_BIT_MASK(32);
>
> /*
> * Set it to coherent_dma_mask by default if the architecture
> @@ -102,6 +103,11 @@ void of_dma_configure(struct device *dev, struct device_node *np)
> if (!dev->dma_mask)
> dev->dma_mask = &dev->coherent_dma_mask;
>
> + /*
> + * Use default size to cover 32 bit. Drivers need to set this in DT
> + * to override the same.
> + */
> + size = 1ULL << 32;

I'm not sure this is needed since on error path the original code would
set the size to coherent_dma_mask.

> ret = of_dma_get_range(np, &dma_addr, &paddr, &size);
> if (ret < 0) {
> dma_addr = offset = 0;

Here we already have (not seen in the context):

size = dev->coherent_dma_mask + 1;

> @@ -128,6 +134,15 @@ void of_dma_configure(struct device *dev, struct device_node *np)
>
> dev->dma_pfn_offset = offset;
>
> + /*
> + * Limit coherent and dma mask based on size and default mask
> + * set by the driver.
> + */
> + dev->coherent_dma_mask = min(dev->coherent_dma_mask,
> + DMA_BIT_MASK(ilog2(dma_addr + size)));
> + *dev->dma_mask = min((*dev->dma_mask),
> + DMA_BIT_MASK(ilog2(dma_addr + size)));
> +
> coherent = of_dma_is_coherent(np);
> dev_dbg(dev, "device is%sdma coherent\n",
> coherent ? " " : " not ");

Otherwise it looks fine to me.

Reviewed-by: Catalin Marinas <[email protected]>

2015-02-26 00:20:39

by Bjorn Helgaas

[permalink] [raw]
Subject: Re: [PATCH v1] of: calculate masks of the device based on dma-range size

[+cc Catalin]

On Wed, Feb 11, 2015 at 12:53:35PM -0500, Murali Karicheri wrote:
> This patch update of_dma_configure() API to calculate the
> masks (dma_mask and coherent_dma_mask) based on the dma-range
> values set in DT for the device. Also limit the mask to lower
> of the default mask and mask calculated.
>
> Cc: Joerg Roedel <[email protected]>
> Cc: Grant Likely <[email protected]>
> Cc: Rob Herring <[email protected]>
> Cc: Bjorn Helgaas <[email protected]>
> Cc: Will Deacon <[email protected]>
> Cc: Russell King <[email protected]>
> Cc: Arnd Bergmann <[email protected]>
> Cc: Suravee Suthikulpanit <[email protected]>
>
> Signed-off-by: Murali Karicheri <[email protected]>

Applied with Catalin's reviewed-by to pci/iommu for v4.1, thanks!

I agree with Catalin's comment about the "size = 1ULL << 32" line.
I don't see how that will make a difference, so I dropped it. The
patch I merged is below. Let me know if you think we do need that
line or any other tweaks.

Bjorn

commit a5a1dd69080dfcf53bfd6e179f3db68e824aeaae
Author: Murali Karicheri <[email protected]>
Date: Wed Feb 25 17:21:04 2015 -0600

of: Calculate device DMA masks based on DT dma-range size

Calculate the dma_mask and coherent_dma_mask based on the dma-range values
set in DT for the device.

Limit the mask to lower of the default mask and mask calculated.

Signed-off-by: Murali Karicheri <[email protected]>
Signed-off-by: Bjorn Helgaas <[email protected]>
Reviewed-by: Catalin Marinas <[email protected]>
CC: Joerg Roedel <[email protected]>
CC: Grant Likely <[email protected]>
CC: Rob Herring <[email protected]>
CC: Will Deacon <[email protected]>
CC: Russell King <[email protected]>
CC: Arnd Bergmann <[email protected]>
CC: Suravee Suthikulpanit <[email protected]>

diff --git a/drivers/of/device.c b/drivers/of/device.c
index 28e743888402..20c1332a0018 100644
--- a/drivers/of/device.c
+++ b/drivers/of/device.c
@@ -90,10 +90,11 @@ void of_dma_configure(struct device *dev, struct device_node *np)
struct iommu_ops *iommu;

/*
- * Set default dma-mask to 32 bit. Drivers are expected to setup
- * the correct supported dma_mask.
+ * Set default coherent_dma_mask to 32 bit. Drivers are expected to
+ * setup the correct supported mask.
*/
- dev->coherent_dma_mask = DMA_BIT_MASK(32);
+ if (!dev->coherent_dma_mask)
+ dev->coherent_dma_mask = DMA_BIT_MASK(32);

/*
* Set it to coherent_dma_mask by default if the architecture
@@ -128,6 +129,15 @@ void of_dma_configure(struct device *dev, struct device_node *np)

dev->dma_pfn_offset = offset;

+ /*
+ * Limit coherent and dma mask based on size and default mask
+ * set by the driver.
+ */
+ dev->coherent_dma_mask = min(dev->coherent_dma_mask,
+ DMA_BIT_MASK(ilog2(dma_addr + size)));
+ *dev->dma_mask = min((*dev->dma_mask),
+ DMA_BIT_MASK(ilog2(dma_addr + size)));
+
coherent = of_dma_is_coherent(np);
dev_dbg(dev, "device is%sdma coherent\n",
coherent ? " " : " not ");

2015-02-27 20:42:42

by Karicheri, Muralidharan

[permalink] [raw]
Subject: Re: [PATCH v1] of: calculate masks of the device based on dma-range size

On 02/25/2015 07:20 PM, Bjorn Helgaas wrote:
> [+cc Catalin]
>
> On Wed, Feb 11, 2015 at 12:53:35PM -0500, Murali Karicheri wrote:
>> This patch update of_dma_configure() API to calculate the
>> masks (dma_mask and coherent_dma_mask) based on the dma-range
>> values set in DT for the device. Also limit the mask to lower
>> of the default mask and mask calculated.
>>
>> Cc: Joerg Roedel<[email protected]>
>> Cc: Grant Likely<[email protected]>
>> Cc: Rob Herring<[email protected]>
>> Cc: Bjorn Helgaas<[email protected]>
>> Cc: Will Deacon<[email protected]>
>> Cc: Russell King<[email protected]>
>> Cc: Arnd Bergmann<[email protected]>
>> Cc: Suravee Suthikulpanit<[email protected]>
>>
>> Signed-off-by: Murali Karicheri<[email protected]>
>
> Applied with Catalin's reviewed-by to pci/iommu for v4.1, thanks!
>
> I agree with Catalin's comment about the "size = 1ULL<< 32" line.
> I don't see how that will make a difference, so I dropped it. The
> patch I merged is below. Let me know if you think we do need that
> line or any other tweaks.
>
> Bjorn
>
> commit a5a1dd69080dfcf53bfd6e179f3db68e824aeaae
> Author: Murali Karicheri<[email protected]>
> Date: Wed Feb 25 17:21:04 2015 -0600
>
> of: Calculate device DMA masks based on DT dma-range size
>
> Calculate the dma_mask and coherent_dma_mask based on the dma-range values
> set in DT for the device.
>
> Limit the mask to lower of the default mask and mask calculated.
>
> Signed-off-by: Murali Karicheri<[email protected]>
> Signed-off-by: Bjorn Helgaas<[email protected]>
> Reviewed-by: Catalin Marinas<[email protected]>
> CC: Joerg Roedel<[email protected]>
> CC: Grant Likely<[email protected]>
> CC: Rob Herring<[email protected]>
> CC: Will Deacon<[email protected]>
> CC: Russell King<[email protected]>
> CC: Arnd Bergmann<[email protected]>
> CC: Suravee Suthikulpanit<[email protected]>
>
> diff --git a/drivers/of/device.c b/drivers/of/device.c
> index 28e743888402..20c1332a0018 100644
> --- a/drivers/of/device.c
> +++ b/drivers/of/device.c
> @@ -90,10 +90,11 @@ void of_dma_configure(struct device *dev, struct device_node *np)
> struct iommu_ops *iommu;
>
> /*
> - * Set default dma-mask to 32 bit. Drivers are expected to setup
> - * the correct supported dma_mask.
> + * Set default coherent_dma_mask to 32 bit. Drivers are expected to
> + * setup the correct supported mask.
> */
> - dev->coherent_dma_mask = DMA_BIT_MASK(32);
> + if (!dev->coherent_dma_mask)
> + dev->coherent_dma_mask = DMA_BIT_MASK(32);
>
> /*
> * Set it to coherent_dma_mask by default if the architecture
> @@ -128,6 +129,15 @@ void of_dma_configure(struct device *dev, struct device_node *np)
>
> dev->dma_pfn_offset = offset;
>
> + /*
> + * Limit coherent and dma mask based on size and default mask
> + * set by the driver.
> + */
> + dev->coherent_dma_mask = min(dev->coherent_dma_mask,
> + DMA_BIT_MASK(ilog2(dma_addr + size)));
> + *dev->dma_mask = min((*dev->dma_mask),
> + DMA_BIT_MASK(ilog2(dma_addr + size)));
> +
> coherent = of_dma_is_coherent(np);
> dev_dbg(dev, "device is%sdma coherent\n",
> coherent ? " " : " not ");
Bjorn,

Thanks. Looks good to me.

Murali

--
Murali Karicheri
Linux Kernel, Texas Instruments