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 <redacted>
Reviewed-by: Scott Branden <scott.branden@broadcom.com>
Signed-off-by: Oza Pawandeep <redacted>
Signed-off-by: Oza Pawandeep <redacted>
@@ -283,6 +283,52 @@ int of_pci_get_host_bridge_resources(struct device_node *dev,returnerr;}EXPORT_SYMBOL_GPL(of_pci_get_host_bridge_resources);++intof_pci_get_dma_ranges(structdevice_node*np,u64*dma_addr,u64*paddr,u64*size)+{+structdevice_node*node=of_node_get(np);+intrlen,ret=0;+constintna=3,ns=2;+structof_pci_range_parserparser;+structof_pci_rangerange;++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;+gotoout;+}++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);+returnret;++}+EXPORT_SYMBOL_GPL(of_pci_get_dma_ranges);#endif /* CONFIG_OF_ADDRESS */#ifdef CONFIG_PCI_MSI
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.
this patch is inspired by
http://www.mail-archive.com/linux-kernel at vger.kernel.org/msg1306545.html
http://www.spinics.net/lists/arm-kernel/msg566947.html
but above inspiraiton solves the half of the problem.
the rest of the problem is descrbied below, what we face on iproc based
SOCs.
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 <redacted>
Reviewed-by: Scott Branden <scott.branden@broadcom.com>
Signed-off-by: Oza Pawandeep <redacted>
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 <redacted>
Signed-off-by: Oza Pawandeep <redacted>
From: Rob Herring <robh@kernel.org> Date: 2017-03-27 14:35:25
On Sat, Mar 25, 2017 at 12:31 AM, Oza Pawandeep [off-list ref] 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
From: Robin Murphy <robin.murphy@arm.com> Date: 2017-03-27 14:45:29
Hi Rob,
On 27/03/17 15:34, Rob Herring wrote:
On Sat, Mar 25, 2017 at 12:31 AM, Oza Pawandeep [off-list ref] wrote:
quoted
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.
From: Rob Herring <robh@kernel.org> Date: 2017-03-27 15:11:19
On Sat, Mar 25, 2017 at 12:31 AM, Oza Pawandeep [off-list ref] 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
please find my comments inline.
On Mon, Mar 27, 2017 at 8:15 PM, Robin Murphy [off-list ref] wrote:
Hi Rob,
On 27/03/17 15:34, Rob Herring wrote:
quoted
On Sat, Mar 25, 2017 at 12:31 AM, Oza Pawandeep [off-list ref] wrote:
quoted
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? ;)
quoted
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).
current parsing of dma-ranges assume that dma-ranges always to be
found in parent node.
based on that, my thinking is following:
couple of options
1)
instead while(1) some meaningful condition such as while(!node)
the following bail out is not required.
if (!ranges)
break;
2)
have check based on dt-property to distinguish between pci and handle
dma-ranges root bridge
but again these changes do not solve the entire problem for choosing
right dma_mask.
neither it actually correctly address root bridge pci dma-ranges.
and hence I have written
https://lkml.org/lkml/2017/3/27/540
my final take is: this function does not need to change, let it parse
memory mapped dma-ranges as it is doing.
I am more inclined to have generic pci dma-ranges and parsing.
which following already addresses.
https://lkml.org/lkml/2017/3/27/540
Regards,
Oza.
On Mon, Mar 27, 2017 at 8:16 PM, Rob Herring [off-list ref] wrote:
On Sat, Mar 25, 2017 at 12:31 AM, Oza Pawandeep [off-list ref] wrote:
quoted
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.
the common function should be similar to what
of_pci_get_host_bridge_resources is doing right now.
it parses ranges property right now.
the new function would look look following.
of_pci_get_dma_ranges(struct device_node *dev, struct list_head *resources)
where resources would return the dma-ranges.
but right now if you see the patch, of_dma_configure calls the new
function, which actually returns the largest possible size.
so this new function has to be generic in a way where other PCI hosts
can use it. but certainly iproc(Broadcom SOC) , rcar based SOCs can
use it for sure.
although having powerpc using it; is a separate exercise, since I do
not have any access to other PCI hosts such as powerpc. but we can
workout with them on thsi forum if required.
so overall, of_pci_get_dma_ranges has to serve following 2 purposes.
1) it has to return largest possible size to of_dma_configure to
generate largest possible dma_mask.
2) it also has to return resources (dma-ranges) parsed, to the users.
so to address above needs
of_pci_get_dma_ranges(struct device_node *dev, struct list_head
*resources, u64 *size)
dev -> device node.
resources -> dma-ranges in allocated list.
size -> highest possible size to generate possible dma_mask for
of_dma_configure.
let em know how this sounds.
Regards,
Oza.
From: Rob Herring <robh@kernel.org> Date: 2017-03-28 14:18:47
On Tue, Mar 28, 2017 at 12:27 AM, Oza Oza [off-list ref] wrote:
On Mon, Mar 27, 2017 at 8:16 PM, Rob Herring [off-list ref] wrote:
quoted
On Sat, Mar 25, 2017 at 12:31 AM, Oza Pawandeep [off-list ref] wrote:
quoted
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.
the common function should be similar to what
of_pci_get_host_bridge_resources is doing right now.
it parses ranges property right now.
the new function would look look following.
of_pci_get_dma_ranges(struct device_node *dev, struct list_head *resources)
where resources would return the dma-ranges.
but right now if you see the patch, of_dma_configure calls the new
function, which actually returns the largest possible size.
so this new function has to be generic in a way where other PCI hosts
can use it. but certainly iproc(Broadcom SOC) , rcar based SOCs can
use it for sure.
although having powerpc using it; is a separate exercise, since I do
not have any access to other PCI hosts such as powerpc. but we can
workout with them on thsi forum if required.
You don't need h/w. You can analyze what parts are common, write
patches to convert to common implementation, and build test. The PPC
and rcar folks can test on h/w.
Rob
From: Robin Murphy <robin.murphy@arm.com> Date: 2017-03-28 14:30:03
On 28/03/17 06:27, Oza Oza wrote:
On Mon, Mar 27, 2017 at 8:16 PM, Rob Herring [off-list ref] wrote:
quoted
On Sat, Mar 25, 2017 at 12:31 AM, Oza Pawandeep [off-list ref] wrote:
quoted
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.
the common function should be similar to what
of_pci_get_host_bridge_resources is doing right now.
it parses ranges property right now.
the new function would look look following.
of_pci_get_dma_ranges(struct device_node *dev, struct list_head *resources)
where resources would return the dma-ranges.
but right now if you see the patch, of_dma_configure calls the new
function, which actually returns the largest possible size.
so this new function has to be generic in a way where other PCI hosts
can use it. but certainly iproc(Broadcom SOC) , rcar based SOCs can
use it for sure.
although having powerpc using it; is a separate exercise, since I do
not have any access to other PCI hosts such as powerpc. but we can
workout with them on thsi forum if required.
so overall, of_pci_get_dma_ranges has to serve following 2 purposes.
1) it has to return largest possible size to of_dma_configure to
generate largest possible dma_mask.
2) it also has to return resources (dma-ranges) parsed, to the users.
so to address above needs
of_pci_get_dma_ranges(struct device_node *dev, struct list_head
*resources, u64 *size)
dev -> device node.
resources -> dma-ranges in allocated list.
size -> highest possible size to generate possible dma_mask for
of_dma_configure.
let em know how this sounds.
Note that the point of passing PCI host bridges into of_dma_configure()
in the first place was to avoid having some separate PCI-specific path
for DMA configuration. I worry that introducing bus-specific dma-ranges
parsing largely defeats that, since we end up with the worst of both
worlds; effectively-duplicated code, and/or a load of extra complexity
to then attempt to reconverge the divergent paths (there really
shouldn't be any need to allocate a list of anything). Given that
of_translate_dma_address() is already bus-agnostic, it hardly seems
justifiable for its caller not to be so as well, especially when it
mostly just comes down to getting the right #address-cells value.
The patch below is actually enough to make typical cases work, but is
vile, so I'm not seriously considering it (hence I've not bothered
making IOMMU configuration handle all circumstances). What it has served
to do, though, is give me a clear idea of how to properly sort out the
not-quite-right device/parent assumptions between of_dma_configure() and
of_dma_get_range() rather than bodging around them any further - stay tuned.
Robin.
----->8-----
From: Robin Murphy <robin.murphy@arm.com>
Subject: [PATCH] of/pci: Use child node for DMA configuration
of_dma_configure() expects to be passed an OF node representing the
device being configured - for PCI devices we currently pass the node of
the appropriate host controller, which sort of works for inherited
properties which may appear at any level, like "dma-coherent", but falls
apart for properties which actually care about specific device-parent
relationships, like "dma-ranges".
Solve this by attempting to find a suitable child node if the PCI
hierarchy is actually represented in DT, and if not then faking one up
as a last resort, to make all of DMA configuration work as expected.
Signed-off-by: Robin Murphy <robin.murphy@arm.com>
---
drivers/iommu/of_iommu.c | 3 ++-
drivers/pci/of.c | 24 ++++++++++++++++++++++++
drivers/pci/probe.c | 14 +++++++++++++-
include/linux/pci.h | 3 +++
4 files changed, 42 insertions(+), 2 deletions(-)
device *dev,
int idx = 0;
if (dev_is_pci(dev))
- return of_pci_iommu_configure(to_pci_dev(dev), master_np);
+ return of_pci_iommu_configure(to_pci_dev(dev),
+ of_get_next_parent(master_np));
/*
* We don't currently walk up the tree looking for a parent IOMMU.
On Tue, Mar 28, 2017 at 7:59 PM, Robin Murphy [off-list ref] wrote:
quoted hunk
On 28/03/17 06:27, Oza Oza wrote:
quoted
On Mon, Mar 27, 2017 at 8:16 PM, Rob Herring [off-list ref] wrote:
quoted
On Sat, Mar 25, 2017 at 12:31 AM, Oza Pawandeep [off-list ref] wrote:
quoted
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.
the common function should be similar to what
of_pci_get_host_bridge_resources is doing right now.
it parses ranges property right now.
the new function would look look following.
of_pci_get_dma_ranges(struct device_node *dev, struct list_head *resources)
where resources would return the dma-ranges.
but right now if you see the patch, of_dma_configure calls the new
function, which actually returns the largest possible size.
so this new function has to be generic in a way where other PCI hosts
can use it. but certainly iproc(Broadcom SOC) , rcar based SOCs can
use it for sure.
although having powerpc using it; is a separate exercise, since I do
not have any access to other PCI hosts such as powerpc. but we can
workout with them on thsi forum if required.
so overall, of_pci_get_dma_ranges has to serve following 2 purposes.
1) it has to return largest possible size to of_dma_configure to
generate largest possible dma_mask.
2) it also has to return resources (dma-ranges) parsed, to the users.
so to address above needs
of_pci_get_dma_ranges(struct device_node *dev, struct list_head
*resources, u64 *size)
dev -> device node.
resources -> dma-ranges in allocated list.
size -> highest possible size to generate possible dma_mask for
of_dma_configure.
let em know how this sounds.
Note that the point of passing PCI host bridges into of_dma_configure()
in the first place was to avoid having some separate PCI-specific path
for DMA configuration. I worry that introducing bus-specific dma-ranges
parsing largely defeats that, since we end up with the worst of both
worlds; effectively-duplicated code, and/or a load of extra complexity
to then attempt to reconverge the divergent paths (there really
shouldn't be any need to allocate a list of anything). Given that
of_translate_dma_address() is already bus-agnostic, it hardly seems
justifiable for its caller not to be so as well, especially when it
mostly just comes down to getting the right #address-cells value.
The patch below is actually enough to make typical cases work, but is
vile, so I'm not seriously considering it (hence I've not bothered
making IOMMU configuration handle all circumstances). What it has served
to do, though, is give me a clear idea of how to properly sort out the
not-quite-right device/parent assumptions between of_dma_configure() and
of_dma_get_range() rather than bodging around them any further - stay tuned.
Robin.
----->8-----
From: Robin Murphy <robin.murphy@arm.com>
Subject: [PATCH] of/pci: Use child node for DMA configuration
of_dma_configure() expects to be passed an OF node representing the
device being configured - for PCI devices we currently pass the node of
the appropriate host controller, which sort of works for inherited
properties which may appear at any level, like "dma-coherent", but falls
apart for properties which actually care about specific device-parent
relationships, like "dma-ranges".
Solve this by attempting to find a suitable child node if the PCI
hierarchy is actually represented in DT, and if not then faking one up
as a last resort, to make all of DMA configuration work as expected.
Signed-off-by: Robin Murphy <robin.murphy@arm.com>
---
drivers/iommu/of_iommu.c | 3 ++-
drivers/pci/of.c | 24 ++++++++++++++++++++++++
drivers/pci/probe.c | 14 +++++++++++++-
include/linux/pci.h | 3 +++
4 files changed, 42 insertions(+), 2 deletions(-)
device *dev,
int idx = 0;
if (dev_is_pci(dev))
- return of_pci_iommu_configure(to_pci_dev(dev), master_np);
+ return of_pci_iommu_configure(to_pci_dev(dev),
+ of_get_next_parent(master_np));
/*
* We don't currently walk up the tree looking for a parent IOMMU.
pci and memory mapped device world is different. of course if you talk
from iommu perspective, all the master are same for IOMMU
but the original intention of the patch is to try to solve 2 problems.
1) expose generic API for pci world clients to configure their
dma-ranges. right now there is none.
2) same API can be used by IOMMU to derive dma_mask.
the implementation tries to handle dma-ranges for both memory mapped
and pci devices, which I think is overkill.
besides we have different configuration of dma-ranges based on iommu
is enabled or not enabled.
#define PCIE_DMA_RANGES dma-ranges = <0x43000000 0x00 0x80000000 0x00
0x80000000 0x00 0x80000000 \
0x43000000 0x08 0x00000000 0x08
0x00000000 0x08 0x00000000 \
0x43000000 0x80 0x00000000 0x80
0x00000000 0x40 0x00000000>;
the of_dma_get_range is written with respect to traditional memory
ranges, they were not meant for pci dma-ranges.
Regards,
Oza.
On Wed, Mar 29, 2017 at 10:13 AM, Oza Oza [off-list ref] wrote:
On Tue, Mar 28, 2017 at 7:59 PM, Robin Murphy [off-list ref] wrote:
quoted
On 28/03/17 06:27, Oza Oza wrote:
quoted
On Mon, Mar 27, 2017 at 8:16 PM, Rob Herring [off-list ref] wrote:
quoted
On Sat, Mar 25, 2017 at 12:31 AM, Oza Pawandeep [off-list ref] wrote:
quoted
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.
the common function should be similar to what
of_pci_get_host_bridge_resources is doing right now.
it parses ranges property right now.
the new function would look look following.
of_pci_get_dma_ranges(struct device_node *dev, struct list_head *resources)
where resources would return the dma-ranges.
but right now if you see the patch, of_dma_configure calls the new
function, which actually returns the largest possible size.
so this new function has to be generic in a way where other PCI hosts
can use it. but certainly iproc(Broadcom SOC) , rcar based SOCs can
use it for sure.
although having powerpc using it; is a separate exercise, since I do
not have any access to other PCI hosts such as powerpc. but we can
workout with them on thsi forum if required.
so overall, of_pci_get_dma_ranges has to serve following 2 purposes.
1) it has to return largest possible size to of_dma_configure to
generate largest possible dma_mask.
2) it also has to return resources (dma-ranges) parsed, to the users.
so to address above needs
of_pci_get_dma_ranges(struct device_node *dev, struct list_head
*resources, u64 *size)
dev -> device node.
resources -> dma-ranges in allocated list.
size -> highest possible size to generate possible dma_mask for
of_dma_configure.
let em know how this sounds.
Note that the point of passing PCI host bridges into of_dma_configure()
in the first place was to avoid having some separate PCI-specific path
for DMA configuration. I worry that introducing bus-specific dma-ranges
parsing largely defeats that, since we end up with the worst of both
worlds; effectively-duplicated code, and/or a load of extra complexity
to then attempt to reconverge the divergent paths (there really
shouldn't be any need to allocate a list of anything). Given that
of_translate_dma_address() is already bus-agnostic, it hardly seems
justifiable for its caller not to be so as well, especially when it
mostly just comes down to getting the right #address-cells value.
The patch below is actually enough to make typical cases work, but is
vile, so I'm not seriously considering it (hence I've not bothered
making IOMMU configuration handle all circumstances). What it has served
to do, though, is give me a clear idea of how to properly sort out the
not-quite-right device/parent assumptions between of_dma_configure() and
of_dma_get_range() rather than bodging around them any further - stay tuned.
Robin.
----->8-----
From: Robin Murphy <robin.murphy@arm.com>
Subject: [PATCH] of/pci: Use child node for DMA configuration
of_dma_configure() expects to be passed an OF node representing the
device being configured - for PCI devices we currently pass the node of
the appropriate host controller, which sort of works for inherited
properties which may appear at any level, like "dma-coherent", but falls
apart for properties which actually care about specific device-parent
relationships, like "dma-ranges".
Solve this by attempting to find a suitable child node if the PCI
hierarchy is actually represented in DT, and if not then faking one up
as a last resort, to make all of DMA configuration work as expected.
Signed-off-by: Robin Murphy <robin.murphy@arm.com>
---
drivers/iommu/of_iommu.c | 3 ++-
drivers/pci/of.c | 24 ++++++++++++++++++++++++
drivers/pci/probe.c | 14 +++++++++++++-
include/linux/pci.h | 3 +++
4 files changed, 42 insertions(+), 2 deletions(-)
device *dev,
int idx = 0;
if (dev_is_pci(dev))
- return of_pci_iommu_configure(to_pci_dev(dev), master_np);
+ return of_pci_iommu_configure(to_pci_dev(dev),
+ of_get_next_parent(master_np));
/*
* We don't currently walk up the tree looking for a parent IOMMU.
pci and memory mapped device world is different. of course if you talk
from iommu perspective, all the master are same for IOMMU
but the original intention of the patch is to try to solve 2 problems.
1) expose generic API for pci world clients to configure their
dma-ranges. right now there is none.
2) same API can be used by IOMMU to derive dma_mask.
the implementation tries to handle dma-ranges for both memory mapped
and pci devices, which I think is overkill.
besides we have different configuration of dma-ranges based on iommu
is enabled or not enabled.
#define PCIE_DMA_RANGES dma-ranges = <0x43000000 0x00 0x80000000 0x00
0x80000000 0x00 0x80000000 \
0x43000000 0x08 0x00000000 0x08
0x00000000 0x08 0x00000000 \
0x43000000 0x80 0x00000000 0x80
0x00000000 0x40 0x00000000>;
the of_dma_get_range is written with respect to traditional memory
ranges, they were not meant for pci dma-ranges.
Regards,
Oza.
Rob, gentle reminder on your viewpoint. my take on whole thing is as follows:
1) of_dma_get_range is supposed to handle traditional dma-ranges
(not pci one)
2) we need separate function for pci users such as iproc or rcar SOCs
to have their dma-ranges parsed,
which can be extended later for e.g. pci flags have some meanings.
besides of_dma_configure is written to pass only single out parameter
(..., *dma_addr, *size)
handling multiple ranges here, and passing only one range out is not desirable.
also you would not like to handle pci flags in of_dma_get_range (the
first portion of DT
entry) in this function if required in future.
this new function will be similar to of_pci_get_host_bridge_resources
which I am writing/improving right now..
Regards,
Oza.
On Tue, Mar 28, 2017 at 7:43 PM, Rob Herring [off-list ref] wrote:
On Tue, Mar 28, 2017 at 12:27 AM, Oza Oza [off-list ref] wrote:
quoted
On Mon, Mar 27, 2017 at 8:16 PM, Rob Herring [off-list ref] wrote:
quoted
On Sat, Mar 25, 2017 at 12:31 AM, Oza Pawandeep [off-list ref] wrote:
quoted
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.
the common function should be similar to what
of_pci_get_host_bridge_resources is doing right now.
it parses ranges property right now.
the new function would look look following.
of_pci_get_dma_ranges(struct device_node *dev, struct list_head *resources)
where resources would return the dma-ranges.
but right now if you see the patch, of_dma_configure calls the new
function, which actually returns the largest possible size.
so this new function has to be generic in a way where other PCI hosts
can use it. but certainly iproc(Broadcom SOC) , rcar based SOCs can
use it for sure.
although having powerpc using it; is a separate exercise, since I do
not have any access to other PCI hosts such as powerpc. but we can
workout with them on thsi forum if required.
You don't need h/w. You can analyze what parts are common, write
patches to convert to common implementation, and build test. The PPC
and rcar folks can test on h/w.
Rob
Hi Rob,
I have addressed your comment and made generic function.
Gentle request to have a look at following approach and patch.
[RFC PATCH 2/2] of/pci: call pci specific dma-ranges instead of memory-mapped.
[RFC PATCH 1/2] of/pci: implement inbound dma-ranges for PCI
I have tested this on our platform, with and without iommu, and seems to work.
let me know your view on this.
Regards,
Oza.