Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1642215 > unrolled thread
| Started by | Oza Pawandeep <oza.oza@broadcom.com> |
|---|---|
| First post | 2017-05-16 07:30 +0200 |
| Last post | 2017-05-19 03:30 +0200 |
| Articles | 4 — 3 participants |
Back to article view | Back to linux.kernel
[PATCH v6 0/3] OF/PCI address PCI inbound memory limitations Oza Pawandeep <oza.oza@broadcom.com> - 2017-05-16 07:30 +0200
[PATCH v6 2/3] iommu/pci: reserve IOVA for PCI masters Oza Pawandeep <oza.oza@broadcom.com> - 2017-05-16 07:30 +0200
Re: [PATCH v6 2/3] iommu/pci: reserve IOVA for PCI masters Bjorn Helgaas <helgaas@kernel.org> - 2017-05-17 19:20 +0200
Re: [PATCH v6 2/3] iommu/pci: reserve IOVA for PCI masters Oza Oza <oza.oza@broadcom.com> - 2017-05-19 03:30 +0200
| From | Oza Pawandeep <oza.oza@broadcom.com> |
|---|---|
| Date | 2017-05-16 07:30 +0200 |
| Subject | [PATCH v6 0/3] OF/PCI address PCI inbound memory limitations |
| Message-ID | <tHDdv-1qC-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. 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 device framework and OF framework integration assumes dma-ranges in a way where memory-mapped devices define their dma-ranges. (child-bus-address, parent-bus-address, length). of_dma_configure is specifically written to take care of memory mapped devices but no implementation exists for pci devices. For e.g. iproc based SOCs and other SOCs (such as rcar) have PCI world dma-ranges. dma-ranges = <0x43000000 0x00 0x00 0x00 0x00 0x80 0x00>; This patchset reserves the IOVA ranges for PCI masters based on the PCI world dma-ranges. fix of_dma_get_range to cater to PCI dma-ranges. fix of_dma_get_range which currently returns size 0 for PCI devices. IOVA allocation patch: [PATCH 2/3] iommu/pci: reserve iova for PCI masters Fix of_dma_get_range bug and address PCI master. [PATCH 3/3] PCI/of fix of_dma_get_range; get PCI specific this patch fixes the following problems of_dma_get_range. 1) return of wrong size as 0. 2) not handling absence of dma-ranges, which is valid for PCI master. 3) not handling multipe inbound windows. 4) in order to get largest possible dma_mask. this patch also retuns the largest possible size based on dma-ranges, Base patch for both of the above patches: [PATCH 1/3] of/pci/dma: fix DMA configuration for PCI masters Changes since v6: - Robin's comments addressed. Changes since v5: Changes since v4: Changes since v3: Changes since v2: - minor changes, redudant checkes removed - removed internal review Changes since v1: - address Rob's comments. - Add a get_dma_ranges() function to of_bus struct.. - Convert existing contents of of_dma_get_range function to of_bus_default_dma_get_ranges and adding that to the default of_bus struct. - Make of_dma_get_range call of_bus_match() and then bus->get_dma_ranges. Oza Pawandeep (3): of/pci/dma: fix DMA configuration for PCI masters iommu/pci: reserve IOVA for PCI masters PCI/of fix of_dma_get_range; get PCI specific dma-ranges drivers/iommu/dma-iommu.c | 35 ++++++++ drivers/of/address.c | 215 ++++++++++++++++++++++++++++++++-------------- drivers/of/of_pci.c | 95 ++++++++++++++++++++ include/linux/of_pci.h | 7 ++ 4 files changed, 288 insertions(+), 64 deletions(-) -- 1.9.1
[toc] | [next] | [standalone]
| From | Oza Pawandeep <oza.oza@broadcom.com> |
|---|---|
| Date | 2017-05-16 07:30 +0200 |
| Subject | [PATCH v6 2/3] iommu/pci: reserve IOVA for PCI masters |
| Message-ID | <tHDdw-1qC-17@gated-at.bofh.it> |
| In reply to | #1642215 |
this patch reserves the IOVA for PCI masters.
ARM64 based SOCs may have scattered memory banks.
such as iproc based SOC has
<0x00000000 0x80000000 0x0 0x80000000>, /* 2G @ 2G */
<0x00000008 0x80000000 0x3 0x80000000>, /* 14G @ 34G */
<0x00000090 0x00000000 0x4 0x00000000>, /* 16G @ 576G */
<0x000000a0 0x00000000 0x4 0x00000000>; /* 16G @ 640G */
but incoming PCI transcation addressing capability is limited
by host bridge, for example if max incoming window capability
is 512 GB, then 0x00000090 and 0x000000a0 will fall beyond it.
to address this problem, iommu has to avoid allocating IOVA which
are reserved. which inturn does not allocate IOVA if it falls into hole.
Signed-off-by: Oza Pawandeep <oza.oza@broadcom.com>
diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
index 48d36ce..08764b0 100644
--- a/drivers/iommu/dma-iommu.c
+++ b/drivers/iommu/dma-iommu.c
@@ -27,6 +27,7 @@
#include <linux/iova.h>
#include <linux/irq.h>
#include <linux/mm.h>
+#include <linux/of_pci.h>
#include <linux/pci.h>
#include <linux/scatterlist.h>
#include <linux/vmalloc.h>
@@ -171,8 +172,12 @@ static void iova_reserve_pci_windows(struct pci_dev *dev,
struct iova_domain *iovad)
{
struct pci_host_bridge *bridge = pci_find_host_bridge(dev->bus);
+ struct device_node *np = bridge->dev.parent->of_node;
struct resource_entry *window;
unsigned long lo, hi;
+ int ret;
+ dma_addr_t tmp_dma_addr = 0, dma_addr;
+ LIST_HEAD(res);
resource_list_for_each_entry(window, &bridge->windows) {
if (resource_type(window->res) != IORESOURCE_MEM &&
@@ -183,6 +188,36 @@ static void iova_reserve_pci_windows(struct pci_dev *dev,
hi = iova_pfn(iovad, window->res->end - window->offset);
reserve_iova(iovad, lo, hi);
}
+
+ /* PCI inbound memory reservation. */
+ ret = of_pci_get_dma_ranges(np, &res);
+ if (!ret) {
+ resource_list_for_each_entry(window, &res) {
+ struct resource *res_dma = window->res;
+
+ dma_addr = res_dma->start - window->offset;
+ if (tmp_dma_addr > dma_addr) {
+ pr_warn("PCI: failed to reserve iovas; ranges should be sorted\n");
+ return;
+ }
+ if (tmp_dma_addr != dma_addr) {
+ lo = iova_pfn(iovad, tmp_dma_addr);
+ hi = iova_pfn(iovad, dma_addr - 1);
+ reserve_iova(iovad, lo, hi);
+ }
+ tmp_dma_addr = window->res->end - window->offset;
+ }
+ /*
+ * the last dma-range should honour based on the
+ * 32/64-bit dma addresses.
+ */
+ if (tmp_dma_addr < DMA_BIT_MASK(sizeof(dma_addr_t) * 8)) {
+ lo = iova_pfn(iovad, tmp_dma_addr);
+ hi = iova_pfn(iovad,
+ DMA_BIT_MASK(sizeof(dma_addr_t) * 8) - 1);
+ reserve_iova(iovad, lo, hi);
+ }
+ }
}
/**
--
1.9.1
[toc] | [prev] | [next] | [standalone]
| From | Bjorn Helgaas <helgaas@kernel.org> |
|---|---|
| Date | 2017-05-17 19:20 +0200 |
| Subject | Re: [PATCH v6 2/3] iommu/pci: reserve IOVA for PCI masters |
| Message-ID | <tIaM9-5Vz-19@gated-at.bofh.it> |
| In reply to | #1642219 |
On Tue, May 16, 2017 at 10:52:06AM +0530, Oza Pawandeep wrote: > this patch reserves the IOVA for PCI masters. > ARM64 based SOCs may have scattered memory banks. > such as iproc based SOC has > > <0x00000000 0x80000000 0x0 0x80000000>, /* 2G @ 2G */ > <0x00000008 0x80000000 0x3 0x80000000>, /* 14G @ 34G */ > <0x00000090 0x00000000 0x4 0x00000000>, /* 16G @ 576G */ > <0x000000a0 0x00000000 0x4 0x00000000>; /* 16G @ 640G */ > > but incoming PCI transcation addressing capability is limited s/transcation/transaction/ > by host bridge, for example if max incoming window capability > is 512 GB, then 0x00000090 and 0x000000a0 will fall beyond it. > > to address this problem, iommu has to avoid allocating IOVA which s/iommu/IOMMU/ > are reserved. which inturn does not allocate IOVA if it falls into hole. s/inturn/in turn/
[toc] | [prev] | [next] | [standalone]
| From | Oza Oza <oza.oza@broadcom.com> |
|---|---|
| Date | 2017-05-19 03:30 +0200 |
| Subject | Re: [PATCH v6 2/3] iommu/pci: reserve IOVA for PCI masters |
| Message-ID | <tIETV-39a-49@gated-at.bofh.it> |
| In reply to | #1643534 |
On Wed, May 17, 2017 at 10:41 PM, Bjorn Helgaas <helgaas@kernel.org> wrote: > On Tue, May 16, 2017 at 10:52:06AM +0530, Oza Pawandeep wrote: >> this patch reserves the IOVA for PCI masters. >> ARM64 based SOCs may have scattered memory banks. >> such as iproc based SOC has >> >> <0x00000000 0x80000000 0x0 0x80000000>, /* 2G @ 2G */ >> <0x00000008 0x80000000 0x3 0x80000000>, /* 14G @ 34G */ >> <0x00000090 0x00000000 0x4 0x00000000>, /* 16G @ 576G */ >> <0x000000a0 0x00000000 0x4 0x00000000>; /* 16G @ 640G */ >> >> but incoming PCI transcation addressing capability is limited > > s/transcation/transaction/ > >> by host bridge, for example if max incoming window capability >> is 512 GB, then 0x00000090 and 0x000000a0 will fall beyond it. >> >> to address this problem, iommu has to avoid allocating IOVA which > > s/iommu/IOMMU/ > >> are reserved. which inturn does not allocate IOVA if it falls into hole. > > s/inturn/in turn/ Hi Bjorn, Thank you for the comments. Will take care of all your comments. Regards, Oza.
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web