* [PATCH v1] of: calculate masks of the device based on dma-range size
@ 2015-02-11 17:53 Murali Karicheri
2015-02-11 18:47 ` Catalin Marinas
2015-02-26 0:20 ` Bjorn Helgaas
0 siblings, 2 replies; 6+ messages in thread
From: Murali Karicheri @ 2015-02-11 17:53 UTC (permalink / raw)
To: linux-arm-kernel, linux-kernel, devicetree, linux-pci
Cc: Murali Karicheri, Joerg Roedel, Grant Likely, Rob Herring,
Bjorn Helgaas, Will Deacon, Russell King, Arnd Bergmann,
Suravee Suthikulpanit
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 <joro@8bytes.org>
Cc: Grant Likely <grant.likely@linaro.org>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Suravee Suthikulpanit <Suravee.Suthikulpanit@amd.com>
Signed-off-by: Murali Karicheri <m-karicheri2@ti.com>
---
- apply on top of the series "[PATCH v6 0/7] PCI: get DMA configuration
from parent device" at 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
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v1] of: calculate masks of the device based on dma-range size
2015-02-11 17:53 [PATCH v1] of: calculate masks of the device based on dma-range size Murali Karicheri
@ 2015-02-11 18:47 ` Catalin Marinas
2015-02-26 0:20 ` Bjorn Helgaas
1 sibling, 0 replies; 6+ messages in thread
From: Catalin Marinas @ 2015-02-11 18:47 UTC (permalink / raw)
To: Murali Karicheri
Cc: linux-arm-kernel, linux-kernel, devicetree, linux-pci,
Russell King, Arnd Bergmann, Joerg Roedel, Will Deacon,
Rob Herring, Bjorn Helgaas, Suravee Suthikulpanit, Grant Likely
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 <catalin.marinas@arm.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v1] of: calculate masks of the device based on dma-range size
2015-02-11 17:53 [PATCH v1] of: calculate masks of the device based on dma-range size Murali Karicheri
2015-02-11 18:47 ` Catalin Marinas
@ 2015-02-26 0:20 ` Bjorn Helgaas
2015-02-27 20:41 ` Murali Karicheri
2015-03-03 17:59 ` Murali Karicheri
1 sibling, 2 replies; 6+ messages in thread
From: Bjorn Helgaas @ 2015-02-26 0:20 UTC (permalink / raw)
To: Murali Karicheri
Cc: linux-arm-kernel, linux-kernel, devicetree, linux-pci,
Joerg Roedel, Grant Likely, Rob Herring, Will Deacon,
Russell King, Arnd Bergmann, Suravee Suthikulpanit,
Catalin Marinas
[+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 <joro@8bytes.org>
> Cc: Grant Likely <grant.likely@linaro.org>
> Cc: Rob Herring <robh+dt@kernel.org>
> Cc: Bjorn Helgaas <bhelgaas@google.com>
> Cc: Will Deacon <will.deacon@arm.com>
> Cc: Russell King <linux@arm.linux.org.uk>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: Suravee Suthikulpanit <Suravee.Suthikulpanit@amd.com>
>
> Signed-off-by: Murali Karicheri <m-karicheri2@ti.com>
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 <m-karicheri2@ti.com>
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 <m-karicheri2@ti.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
CC: Joerg Roedel <joro@8bytes.org>
CC: Grant Likely <grant.likely@linaro.org>
CC: Rob Herring <robh+dt@kernel.org>
CC: Will Deacon <will.deacon@arm.com>
CC: Russell King <linux@arm.linux.org.uk>
CC: Arnd Bergmann <arnd@arndb.de>
CC: Suravee Suthikulpanit <Suravee.Suthikulpanit@amd.com>
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 ");
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v1] of: calculate masks of the device based on dma-range size
2015-02-26 0:20 ` Bjorn Helgaas
@ 2015-02-27 20:41 ` Murali Karicheri
2015-03-03 17:59 ` Murali Karicheri
1 sibling, 0 replies; 6+ messages in thread
From: Murali Karicheri @ 2015-02-27 20:41 UTC (permalink / raw)
To: Bjorn Helgaas
Cc: linux-arm-kernel, linux-kernel, devicetree, linux-pci,
Joerg Roedel, Grant Likely, Rob Herring, Will Deacon,
Russell King, Arnd Bergmann, Suravee Suthikulpanit,
Catalin Marinas
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<joro@8bytes.org>
>> Cc: Grant Likely<grant.likely@linaro.org>
>> Cc: Rob Herring<robh+dt@kernel.org>
>> Cc: Bjorn Helgaas<bhelgaas@google.com>
>> Cc: Will Deacon<will.deacon@arm.com>
>> Cc: Russell King<linux@arm.linux.org.uk>
>> Cc: Arnd Bergmann<arnd@arndb.de>
>> Cc: Suravee Suthikulpanit<Suravee.Suthikulpanit@amd.com>
>>
>> Signed-off-by: Murali Karicheri<m-karicheri2@ti.com>
>
> 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<m-karicheri2@ti.com>
> 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<m-karicheri2@ti.com>
> Signed-off-by: Bjorn Helgaas<bhelgaas@google.com>
> Reviewed-by: Catalin Marinas<catalin.marinas@arm.com>
> CC: Joerg Roedel<joro@8bytes.org>
> CC: Grant Likely<grant.likely@linaro.org>
> CC: Rob Herring<robh+dt@kernel.org>
> CC: Will Deacon<will.deacon@arm.com>
> CC: Russell King<linux@arm.linux.org.uk>
> CC: Arnd Bergmann<arnd@arndb.de>
> CC: Suravee Suthikulpanit<Suravee.Suthikulpanit@amd.com>
>
> 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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v1] of: calculate masks of the device based on dma-range size
2015-02-26 0:20 ` Bjorn Helgaas
2015-02-27 20:41 ` Murali Karicheri
@ 2015-03-03 17:59 ` Murali Karicheri
[not found] ` <54F5F698.6000604-l0cyMroinI0@public.gmane.org>
1 sibling, 1 reply; 6+ messages in thread
From: Murali Karicheri @ 2015-03-03 17:59 UTC (permalink / raw)
To: Bjorn Helgaas
Cc: linux-arm-kernel, linux-kernel, devicetree, linux-pci,
Joerg Roedel, Grant Likely, Rob Herring, Will Deacon,
Russell King, Arnd Bergmann, Suravee Suthikulpanit,
Catalin Marinas
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<joro@8bytes.org>
>> Cc: Grant Likely<grant.likely@linaro.org>
>> Cc: Rob Herring<robh+dt@kernel.org>
>> Cc: Bjorn Helgaas<bhelgaas@google.com>
>> Cc: Will Deacon<will.deacon@arm.com>
>> Cc: Russell King<linux@arm.linux.org.uk>
>> Cc: Arnd Bergmann<arnd@arndb.de>
>> Cc: Suravee Suthikulpanit<Suravee.Suthikulpanit@amd.com>
>>
>> Signed-off-by: Murali Karicheri<m-karicheri2@ti.com>
>
> Applied with Catalin's reviewed-by to pci/iommu for v4.1, thanks!
Bjorn,
Could you point me to this? I didn't see it on pci/iommu of your repo below.
arm-pci git://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci.git
(fetch)
a0868495@ula0868495 ~/Project/linux-keystone $ gitlog arm-pci/pci/iommu
dd8a11b0f0d4ed0ad87c8d09e650f354021d7953 arm: dma-mapping: limit IOMMU
mapping size
2a101e79dcd8733e3a353b0df2fa384980f94e1e PCI: Update DMA configuration
from DT
3fd29d06e9aa92d9a4513e14b2dd3f0d69d4d2b7 of/pci: Add
of_pci_dma_configure() to update DMA configuration
8243352097c468f982a9f386cb1f455672b473a2 PCI: Add helper functions
pci_get[put]_host_bridge_device()
039f346ac880d4f894425ef6c540f3ff5c1b8dcf of: Fix size when dma-range is
not used
2743a957f6a6317be06d02cc93d78bb2a847e427 of: Move of_dma_configure() to
device.c to help re-use
f454cd01b5bdffb1bf26a5cddac30439fa5f27a1 of: iommu: Add ptr to OF node
arg to of_iommu_configure()
c517d838eb7d07bbe9507871fab3931deccff539 Linux 4.0-rc1
Murali
>
> 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<m-karicheri2@ti.com>
> 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<m-karicheri2@ti.com>
> Signed-off-by: Bjorn Helgaas<bhelgaas@google.com>
> Reviewed-by: Catalin Marinas<catalin.marinas@arm.com>
> CC: Joerg Roedel<joro@8bytes.org>
> CC: Grant Likely<grant.likely@linaro.org>
> CC: Rob Herring<robh+dt@kernel.org>
> CC: Will Deacon<will.deacon@arm.com>
> CC: Russell King<linux@arm.linux.org.uk>
> CC: Arnd Bergmann<arnd@arndb.de>
> CC: Suravee Suthikulpanit<Suravee.Suthikulpanit@amd.com>
>
> 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 ");
--
Murali Karicheri
Linux Kernel, Texas Instruments
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2015-03-03 20:49 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-11 17:53 [PATCH v1] of: calculate masks of the device based on dma-range size Murali Karicheri
2015-02-11 18:47 ` Catalin Marinas
2015-02-26 0:20 ` Bjorn Helgaas
2015-02-27 20:41 ` Murali Karicheri
2015-03-03 17:59 ` Murali Karicheri
[not found] ` <54F5F698.6000604-l0cyMroinI0@public.gmane.org>
2015-03-03 20:49 ` Bjorn Helgaas
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).