Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1609096 > unrolled thread
| Started by | Oza Pawandeep <oza.oza@broadcom.com> |
|---|---|
| First post | 2017-03-25 06:40 +0100 |
| Last post | 2017-03-27 17:20 +0200 |
| Articles | 5 — 3 participants |
Back to article view | Back to linux.kernel
[RFC PATCH 1/3] of/pci: dma-ranges to account highest possible host bridge dma_mask Oza Pawandeep <oza.oza@broadcom.com> - 2017-03-25 06:40 +0100
[RFC PATCH 3/3] of: fix node traversing in of_dma_get_range Oza Pawandeep <oza.oza@broadcom.com> - 2017-03-25 06:40 +0100
Re: [RFC PATCH 3/3] of: fix node traversing in of_dma_get_range Rob Herring <robh@kernel.org> - 2017-03-27 16:40 +0200
Re: [RFC PATCH 3/3] of: fix node traversing in of_dma_get_range Robin Murphy <robin.murphy@arm.com> - 2017-03-27 16:50 +0200
Re: [RFC PATCH 1/3] of/pci: dma-ranges to account highest possible host bridge dma_mask Rob Herring <robh@kernel.org> - 2017-03-27 17:20 +0200
| From | Oza Pawandeep <oza.oza@broadcom.com> |
|---|---|
| Date | 2017-03-25 06:40 +0100 |
| Subject | [RFC PATCH 1/3] of/pci: dma-ranges to account highest possible host bridge dma_mask |
| Message-ID | <toMAF-4Hq-3@gated-at.bofh.it> |
it is possible that PCI device supports 64-bit DMA addressing,
and thus it's driver sets device's dma_mask to DMA_BIT_MASK(64),
however PCI host bridge may have limitations on the inbound
transaction addressing. As an example, consider NVME SSD device
connected to iproc-PCIe controller.
Currently, the IOMMU DMA ops only considers PCI device dma_mask
when allocating an IOVA. This is particularly problematic on
ARM/ARM64 SOCs where the IOMMU (i.e. SMMU) translates IOVA to
PA for in-bound transactions only after PCI Host has forwarded
these transactions on SOC IO bus. This means on such ARM/ARM64
SOCs the IOVA of in-bound transactions has to honor the addressing
restrictions of the PCI Host.
current pcie frmework and of framework integration assumes dma-ranges
in a way where memory-mapped devices define their dma-ranges.
dma-ranges: (child-bus-address, parent-bus-address, length).
but iproc based SOCs and even Rcar based SOCs has PCI world dma-ranges.
dma-ranges = <0x43000000 0x00 0x00 0x00 0x00 0x80 0x00>;
of_dma_configure is specifically witten to take care of memory mapped devices.
but no implementation exists for pci to take care of pcie based memory ranges.
in fact pci world doesnt seem to define standard dma-ranges
this patch implements of_pci_get_dma_ranges to cater to pci world dma-ranges.
so then the returned size get best possible (largest) dma_mask.
for e.g.
dma-ranges = <0x43000000 0x00 0x00 0x00 0x00 0x80 0x00>;
we should get dev->coherent_dma_mask=0x7fffffffff.
Reviewed-by: Anup Patel <anup.patel@broadcom.com>
Reviewed-by: Scott Branden <scott.branden@broadcom.com>
Signed-off-by: Oza Pawandeep <oza.oza@broadcom.com>
Signed-off-by: Oza Pawandeep <oza.oza@broadcom.com>
diff --git a/drivers/of/device.c b/drivers/of/device.c
index b1e6beb..d362a98 100644
--- a/drivers/of/device.c
+++ b/drivers/of/device.c
@@ -9,6 +9,7 @@
#include <linux/module.h>
#include <linux/mod_devicetable.h>
#include <linux/slab.h>
+#include <linux/of_pci.h>
#include <asm/errno.h>
#include "of_private.h"
@@ -104,7 +105,11 @@ void of_dma_configure(struct device *dev, struct device_node *np)
if (!dev->dma_mask)
dev->dma_mask = &dev->coherent_dma_mask;
- ret = of_dma_get_range(np, &dma_addr, &paddr, &size);
+ if (dev_is_pci(dev))
+ ret = of_pci_get_dma_ranges(np, &dma_addr, &paddr, &size);
+ else
+ ret = of_dma_get_range(np, &dma_addr, &paddr, &size);
+
if (ret < 0) {
dma_addr = offset = 0;
size = dev->coherent_dma_mask + 1;
diff --git a/drivers/of/of_pci.c b/drivers/of/of_pci.c
index 0ee42c3..c7f8626 100644
--- a/drivers/of/of_pci.c
+++ b/drivers/of/of_pci.c
@@ -283,6 +283,52 @@ int of_pci_get_host_bridge_resources(struct device_node *dev,
return err;
}
EXPORT_SYMBOL_GPL(of_pci_get_host_bridge_resources);
+
+int of_pci_get_dma_ranges(struct device_node *np, u64 *dma_addr, u64 *paddr, u64 *size)
+{
+ struct device_node *node = of_node_get(np);
+ int rlen, ret = 0;
+ const int na = 3, ns = 2;
+ struct of_pci_range_parser parser;
+ struct of_pci_range range;
+
+ if (!node)
+ return -EINVAL;
+
+ parser.node = node;
+ parser.pna = of_n_addr_cells(node);
+ parser.np = parser.pna + na + ns;
+
+ parser.range = of_get_property(node, "dma-ranges", &rlen);
+
+ if (!parser.range) {
+ pr_debug("pcie device has no dma-ranges defined for node(%s)\n", np->full_name);
+ ret = -ENODEV;
+ goto out;
+ }
+
+ parser.end = parser.range + rlen / sizeof(__be32);
+ *size = 0;
+
+ for_each_of_pci_range(&parser, &range) {
+ if (*size < range.size) {
+ *dma_addr = range.pci_addr;
+ *size = range.size;
+ *paddr = range.cpu_addr;
+ }
+ }
+
+ pr_debug("dma_addr(%llx) cpu_addr(%llx) size(%llx)\n",
+ *dma_addr, *paddr, *size);
+ *dma_addr = range.pci_addr;
+ *size = range.size;
+
+out:
+ of_node_put(node);
+ return ret;
+
+}
+EXPORT_SYMBOL_GPL(of_pci_get_dma_ranges);
#endif /* CONFIG_OF_ADDRESS */
#ifdef CONFIG_PCI_MSI
diff --git a/include/linux/of_pci.h b/include/linux/of_pci.h
index 0e0974e..907ace0 100644
--- a/include/linux/of_pci.h
+++ b/include/linux/of_pci.h
@@ -76,6 +76,7 @@ static inline void of_pci_check_probe_only(void) { }
int of_pci_get_host_bridge_resources(struct device_node *dev,
unsigned char busno, unsigned char bus_max,
struct list_head *resources, resource_size_t *io_base);
+int of_pci_get_dma_ranges(struct device_node *np, u64 *dma_addr, u64 *paddr, u64 *size);
#else
static inline int of_pci_get_host_bridge_resources(struct device_node *dev,
unsigned char busno, unsigned char bus_max,
@@ -83,6 +84,11 @@ static inline int of_pci_get_host_bridge_resources(struct device_node *dev,
{
return -EINVAL;
}
+
+static inline int of_pci_get_dma_ranges(struct device_node *np, u64 *dma_addr, u64 *paddr, u64 *size)
+{
+ return -EINVAL;
+}
#endif
#if defined(CONFIG_OF) && defined(CONFIG_PCI_MSI)
--
1.9.1
[toc] | [next] | [standalone]
| From | Oza Pawandeep <oza.oza@broadcom.com> |
|---|---|
| Date | 2017-03-25 06:40 +0100 |
| Subject | [RFC PATCH 3/3] of: fix node traversing in of_dma_get_range |
| Message-ID | <toMAF-4Hq-11@gated-at.bofh.it> |
| In reply to | #1609096 |
it jumps to the parent node without examining the child node.
also with that, it throws "no dma-ranges found for node"
for pci dma-ranges.
this patch fixes device node traversing for dma-ranges.
Reviewed-by: Anup Patel <anup.patel@broadcom.com>
Signed-off-by: Oza Pawandeep <oza.oza@broadcom.com>
diff --git a/drivers/of/address.c b/drivers/of/address.c
index 02b2903..3293d55 100644
--- a/drivers/of/address.c
+++ b/drivers/of/address.c
@@ -836,9 +836,6 @@ int of_dma_get_range(struct device_node *np, u64 *dma_addr, u64 *paddr, u64 *siz
while (1) {
naddr = of_n_addr_cells(node);
nsize = of_n_size_cells(node);
- node = of_get_next_parent(node);
- if (!node)
- break;
ranges = of_get_property(node, "dma-ranges", &len);
@@ -852,6 +849,10 @@ int of_dma_get_range(struct device_node *np, u64 *dma_addr, u64 *paddr, u64 *siz
*/
if (!ranges)
break;
+
+ node = of_get_next_parent(node);
+ if (!node)
+ break;
}
if (!ranges) {
--
1.9.1
[toc] | [prev] | [next] | [standalone]
| From | Rob Herring <robh@kernel.org> |
|---|---|
| Date | 2017-03-27 16:40 +0200 |
| Subject | Re: [RFC PATCH 3/3] of: fix node traversing in of_dma_get_range |
| Message-ID | <tpDYm-XG-27@gated-at.bofh.it> |
| In reply to | #1609098 |
On Sat, Mar 25, 2017 at 12:31 AM, Oza Pawandeep <oza.oza@broadcom.com> wrote: > it jumps to the parent node without examining the child node. > also with that, it throws "no dma-ranges found for node" > for pci dma-ranges. > > this patch fixes device node traversing for dma-ranges. What's the DT look like that doesn't work? dma-ranges is supposed to be a bus property, not a device's property. So looking at the parent is correct behavior generally. Rob
[toc] | [prev] | [next] | [standalone]
| From | Robin Murphy <robin.murphy@arm.com> |
|---|---|
| Date | 2017-03-27 16:50 +0200 |
| Subject | Re: [RFC PATCH 3/3] of: fix node traversing in of_dma_get_range |
| Message-ID | <tpE82-11f-23@gated-at.bofh.it> |
| In reply to | #1609894 |
Hi Rob, On 27/03/17 15:34, Rob Herring wrote: > On Sat, Mar 25, 2017 at 12:31 AM, Oza Pawandeep <oza.oza@broadcom.com> wrote: >> it jumps to the parent node without examining the child node. >> also with that, it throws "no dma-ranges found for node" >> for pci dma-ranges. >> >> this patch fixes device node traversing for dma-ranges. > > What's the DT look like that doesn't work? The problem is the bodge in pci_dma_configure() where we don't have an OF node for the actual device itself, so pass in the host bridge's OF node instead. This happens to work well enough for dma-coherent, but I don't think dma-ranges was even considered at the time. As it happens I'm currently halfway through writing an experiment wherein pci_dma_configure() creates a temporary child node for the of_dma_configure() call if no other suitable alternative (e.g. some intermediate bridge node) exists. How hard are you likely to NAK that approach? ;) > dma-ranges is supposed to be a bus property, not a device's property. > So looking at the parent is correct behavior generally. Indeed, this patch as-is will break currently correct DTs (because we won't find dma-ranges on the device, so will bail before even looking at the parent as we should). Robin. > > Rob >
[toc] | [prev] | [next] | [standalone]
| From | Rob Herring <robh@kernel.org> |
|---|---|
| Date | 2017-03-27 17:20 +0200 |
| Subject | Re: [RFC PATCH 1/3] of/pci: dma-ranges to account highest possible host bridge dma_mask |
| Message-ID | <tpEB4-1AA-23@gated-at.bofh.it> |
| In reply to | #1609096 |
On Sat, Mar 25, 2017 at 12:31 AM, Oza Pawandeep <oza.oza@broadcom.com> wrote: > it is possible that PCI device supports 64-bit DMA addressing, > and thus it's driver sets device's dma_mask to DMA_BIT_MASK(64), > however PCI host bridge may have limitations on the inbound > transaction addressing. As an example, consider NVME SSD device > connected to iproc-PCIe controller. > > Currently, the IOMMU DMA ops only considers PCI device dma_mask > when allocating an IOVA. This is particularly problematic on > ARM/ARM64 SOCs where the IOMMU (i.e. SMMU) translates IOVA to > PA for in-bound transactions only after PCI Host has forwarded > these transactions on SOC IO bus. This means on such ARM/ARM64 > SOCs the IOVA of in-bound transactions has to honor the addressing > restrictions of the PCI Host. > > current pcie frmework and of framework integration assumes dma-ranges > in a way where memory-mapped devices define their dma-ranges. > dma-ranges: (child-bus-address, parent-bus-address, length). > > but iproc based SOCs and even Rcar based SOCs has PCI world dma-ranges. > dma-ranges = <0x43000000 0x00 0x00 0x00 0x00 0x80 0x00>; If you implement a common function, then I expect to see other users converted to use it. There's also PCI hosts in arch/powerpc that parse dma-ranges. Rob
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web