Skip to contentSkip to conversation

DT property to reserve IOMMU regions

RFC New Jitendra Bhivare 3 participants 17 messages Mar 6, 2018 – Mar 15, 2018 1 message not in the archive

Subsystems (8)
lore
Share & tools
lore
#0 lore raw

cover DT property to reserve IOMMU regions

ARM SoCs need a way to reserve IOMMU regions. Some address ranges used by devices sitting behind IOMMU are treated specially. To prevent these ranges from getting mapped in IOVA space, use the existing framework and code to reserve the ranges using DT properties.

This patch set is created against 4.15-rc7.

Jitendra Bhivare (5):
dt-bindings: iommu: Add reserved-dma-region for IOMMU device
dt-bindings: brcm: Add reserved-dma-region for iPROC
dt-bindings: arm-smmu: Add reserved-msi-region iommu/of: Reserve IOMMU DMA regions using DT iommu/arm-smmu: Allow direct mapping for MSI region

 .../devicetree/bindings/iommu/arm,smmu.txt         |  12 +++
 Documentation/devicetree/bindings/iommu/iommu.txt  |  17 ++++
 .../devicetree/bindings/pci/brcm,iproc-pcie.txt    |   3 +
 drivers/iommu/arm-smmu.c                           |  14 ++-
 drivers/iommu/dma-iommu.c                          |   6 ++
 drivers/iommu/of_iommu.c                           | 100 +++++++++++----------
 include/linux/iommu.h                              |   3 +
 include/linux/of_iommu.h                           |  25 ++++--
 8 files changed, 126 insertions(+), 54 deletions(-)
Signature · 1 line
2.7.4
#1 lore raw

RFC 1/5 dt-bindings: iommu: Add reserved-dma-region for IOMMU device

Certain regions in IO virtual address space may need to be reserved to be not used for devices configured behind IOMMU.

Add documentation of the property to allow such regions to be specified in DT to be reserved using IOMMU_RESV_RESERVED type.

---
 Documentation/devicetree/bindings/iommu/iommu.txt | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
Documentation/devicetree/bindings/iommu/iommu.txt +17 -0
index 5a8b462..5a58ef2 100644
@@ -98,6 +98,20 @@ requirements of that use-case haven't been fully determined yet. Implementing
 this is therefore not recommended without further discussion and extension of
 this binding.
 
+Optional properties:
+--------------------
+- reserved-dma-region: This specifies DMA region to be reserved with specific
+  prot in IOVA space. It is in tuples of (busno,prot,bus_addr,size).
+
+- #region-address-cells: specifies number of cells needed to encode bus_addr
+
+- #region-size-cells: specifies number of cells needed to encode size
+
+Notes:
+======
+This can be applied to IOMMU master node or to children (such as PCI host
+bridges) on the bus behind IOMMU.
+
 
 Examples:
 =========
@@ -173,6 +187,9 @@ Multiple-master IOMMU with configurable DMA window:
 			 * master (i.e. the I/O virtual address space).
 			 */
 			#iommu-cells = <4>;
+			#region-address-cells = <2>;
+			#region-size-cells = <2>;
+			reserved-dma-region = <0x0 0x0 0x04 0x0 0x04 0x0>;
 		};
 
 		master {
Signature · 1 line
2.7.4
maintainer
#2 lore raw

RFC 1/5 dt-bindings: iommu: Add reserved-dma-region for IOMMU device

Quoted 5 lines · Jitendra Bhivare

Certain regions in IO virtual address space may need to be reserved to be not used for devices configured behind IOMMU.

Add documentation of the property to allow such regions to be specified in DT to be reserved using IOMMU_RESV_RESERVED type.

That sounds like software policy; DT is for describing hardware.

Quoted 13 lines
---
  Documentation/devicetree/bindings/iommu/iommu.txt | 17 +++++++++++++++++
  1 file changed, 17 insertions(+)
Documentation/devicetree/bindings/iommu/iommu.txt +0 -0
index 5a8b462..5a58ef2 100644

Documentation/devicetree/bindings/iommu/iommu.txt requirements of that use-case haven't been fully determined yet. Implementing · line 104

Quoted 7 lines
Documentation/devicetree/bindings/iommu/iommu.txt +4 -0
@@ -98,6 +98,20 @@ requirements of that use-case haven't been fully determined yet. Implementing
  this is therefore not recommended without further discussion and extension of
  this binding.
 
+Optional properties:
+--------------------
+- reserved-dma-region: This specifies DMA region to be reserved with specific
+  prot in IOVA space. It is in tuples of (busno,prot,bus_addr,size).

What do busno and prot actually mean, and what are valid values for them?

Robin.

Quoted 23 lines
Documentation/devicetree/bindings/iommu/iommu.txt +12 -0
+- #region-address-cells: specifies number of cells needed to encode bus_addr
+
+- #region-size-cells: specifies number of cells needed to encode size
+
+Notes:
+======
+This can be applied to IOMMU master node or to children (such as PCI host
+bridges) on the bus behind IOMMU.
+
 
  Examples:
  =========
@@ -173,6 +187,9 @@ Multiple-master IOMMU with configurable DMA window:
  			 * master (i.e. the I/O virtual address space).
  			 */
  			#iommu-cells = <4>;
+			#region-address-cells = <2>;
+			#region-size-cells = <2>;
+			reserved-dma-region = <0x0 0x0 0x04 0x0 0x04 0x0>;
  		};
 
  		master {

A message that is not in the archive (sent off-list or not yet received): 23f7c879-2dfe-dbdf-f259-dcc44f045c96-5wv7dgnIgG8@public.gmane.org

#4 lore raw

Re: [RFC 1/5] dt-bindings: iommu: Add reserved-dma-region for IOMMU device

Quoted 10 lines · Robin Murphy
Quoted 6 lines · Jitendra Bhivare

Certain regions in IO virtual address space may need to be reserved to be not used for devices configured behind IOMMU.

Add documentation of the property to allow such regions to be specified in DT to be reserved using IOMMU_RESV_RESERVED type.

That sounds like software policy; DT is for describing hardware.

It is to describe the holes in address space for which hardware can't provide mappings.

Quoted 21 lines
Quoted 18 lines
---
  Documentation/devicetree/bindings/iommu/iommu.txt | 17
+++++++++++++++++
  1 file changed, 17 insertions(+)
Documentation/devicetree/bindings/iommu/iommu.txt +0 -0
index 5a8b462..5a58ef2 100644
@@ -98,6 +98,20 @@ requirements of that use-case haven't been fully

determined yet. Implementing
this is therefore not recommended without further discussion and
extension of
this binding.

Quoted 8 lines
Quoted 6 lines

+Optional properties:

+--------------------
+- reserved-dma-region: This specifies DMA region to be reserved with

specific
+ prot in IOVA space. It is in tuples of (busno,prot,bus_addr,size).

What do busno and prot actually mean, and what are valid values for them?

busno was part of initial commit 4e0ee78f in implementation of of_get_dma_window.
I am not sure what was the use of it in Powerpc. Similar implementation can be seen
in of_parse_dma_window.
prot is access permission flags for the region for reserving in SW.This I will remove.

Quoted 28 lines

Robin.

+- #region-address-cells: specifies number of cells needed to encode

Quoted 22 lines

bus_addr

Documentation/devicetree/bindings/iommu/iommu.txt +11 -0
+
+- #region-size-cells: specifies number of cells needed to encode size
+
+Notes:
+======
+This can be applied to IOMMU master node or to children (such as PCI host
+bridges) on the bus behind IOMMU.
+
    Examples:
  =========
@@ -173,6 +187,9 @@ Multiple-master IOMMU with configurable DMA window:
                         * master (i.e. the I/O virtual address space).
                         */
                        #iommu-cells = <4>;
+                       #region-address-cells = <2>;
+                       #region-size-cells = <2>;
+                       reserved-dma-region = <0x0 0x0 0x04 0x0 0x04 0x0>;
                };
                master {
 
#5 lore raw

RFC 1/5 dt-bindings: iommu: Add reserved-dma-region for IOMMU device

In reply to Robin Murphy
Quoted 11 lines · Robin Murphy
Quoted 6 lines · Jitendra Bhivare

Certain regions in IO virtual address space may need to be reserved to be not used for devices configured behind IOMMU.

Add documentation of the property to allow such regions to be specified in DT to be reserved using IOMMU_RESV_RESERVED type.

That sounds like software policy; DT is for describing hardware.

It is to describe the holes in address space for which hardware can't provide mappings.

Quoted 24 lines
Quoted 14 lines
---
  Documentation/devicetree/bindings/iommu/iommu.txt | 17 +++++++++++++++++
  1 file changed, 17 insertions(+)
Documentation/devicetree/bindings/iommu/iommu.txt +0 -0
index 5a8b462..5a58ef2 100644

Documentation/devicetree/bindings/iommu/iommu.txt requirements of that use-case haven't been fully determined yet. Implementing · line 103

Quoted 6 lines
Documentation/devicetree/bindings/iommu/iommu.txt +3 -0
@@ -98,6 +98,20 @@ requirements of that use-case haven't been fully determined yet. Implementing
  this is therefore not recommended without further discussion and extension of
  this binding.
  +Optional properties:
+--------------------
+- reserved-dma-region: This specifies DMA region to be reserved with specific
+  prot in IOVA space. It is in tuples of (busno,prot,bus_addr,size).

What do busno and prot actually mean, and what are valid values for them?

Quoted 1 line

Robin.

busno was part of initial commit 4e0ee78f in implementation of of_get_dma_window.
I am not sure what was the use of it in PowerPC. Similar implementation can be seen
in of_parse_dma_window.
prot is access permission flags for the region for reserving in SW. This I will remove.

Quoted 23 lines
Quoted 23 lines
Documentation/devicetree/bindings/iommu/iommu.txt +12 -0
+- #region-address-cells: specifies number of cells needed to encode bus_addr
+
+- #region-size-cells: specifies number of cells needed to encode size
+
+Notes:
+======
+This can be applied to IOMMU master node or to children (such as PCI host
+bridges) on the bus behind IOMMU.
+
    Examples:
  =========
@@ -173,6 +187,9 @@ Multiple-master IOMMU with configurable DMA window:
                         * master (i.e. the I/O virtual address space).
                         */
                        #iommu-cells = <4>;
+                       #region-address-cells = <2>;
+                       #region-size-cells = <2>;
+                       reserved-dma-region = <0x0 0x0 0x04 0x0 0x04 0x0>;
                };
                master {
 
#6 lore raw

RFC 2/5 dt-bindings: brcm: Add reserved-dma-region for iPROC

In reply to Jitendra Bhivare

With SoC wide DMA mask of 40-bit, the mappings for entire IOVA space can't be specified in the PAXBv2 PCIe RC of SoC. The holes in IOVA space needs to be reserved to prevent any IOVA allocations in those spaces.

reserved-dma-region property is added to specify the ranges which should never be mapped and given to devices sitting behind.

---
 Documentation/devicetree/bindings/pci/brcm,iproc-pcie.txt | 3 +++
 1 file changed, 3 insertions(+)
Documentation/devicetree/bindings/pci/brcm,iproc-pcie.txt +3 -0
index b8e48b4..3be0fe3 100644
@@ -30,6 +30,9 @@ Optional properties:
 - dma-ranges: Some PAXB-based root complexes do not have inbound mapping done
   by the ASIC after power on reset.  In this case, SW is required to configure
 the mapping, based on inbound memory regions specified by this property.
+- reserved-dma-region: PAXBv2 with IOMMU enabled cannot provide mappings for
+  entire IOVA space specified by DMA mask. Hence this is used to reserve the
+  gaps in dma-ranges.
 
 - brcm,pcie-ob: Some iProc SoCs do not have the outbound address mapping done
 by the ASIC after power on reset. In this case, SW needs to configure it
Signature · 1 line
2.7.4
maintainer
#7 lore raw

RFC 2/5 dt-bindings: brcm: Add reserved-dma-region for iPROC

Quoted 3 lines · Jitendra Bhivare

With SoC wide DMA mask of 40-bit, the mappings for entire IOVA space can't be specified in the PAXBv2 PCIe RC of SoC. The holes in IOVA space needs to be reserved to prevent any IOVA allocations in those spaces.

Can you clarify why? If this is the PCI inbound window thing again, let me say once again that "dma-ranges" is the appropriate way for DT to describe the hardware.

Robin.

Quoted 26 lines

reserved-dma-region property is added to specify the ranges which should never be mapped and given to devices sitting behind.

---
  Documentation/devicetree/bindings/pci/brcm,iproc-pcie.txt | 3 +++
  1 file changed, 3 insertions(+)
Documentation/devicetree/bindings/pci/brcm,iproc-pcie.txt +3 -0
index b8e48b4..3be0fe3 100644
@@ -30,6 +30,9 @@ Optional properties:
  - dma-ranges: Some PAXB-based root complexes do not have inbound mapping done
    by the ASIC after power on reset.  In this case, SW is required to configure
  the mapping, based on inbound memory regions specified by this property.
+- reserved-dma-region: PAXBv2 with IOMMU enabled cannot provide mappings for
+  entire IOVA space specified by DMA mask. Hence this is used to reserve the
+  gaps in dma-ranges.
 
  - brcm,pcie-ob: Some iProc SoCs do not have the outbound address mapping done
  by the ASIC after power on reset. In this case, SW needs to configure it
#8 lore raw

RFC 2/5 dt-bindings: brcm: Add reserved-dma-region for iPROC

Quoted 8 lines · Robin Murphy
Quoted 5 lines · Jitendra Bhivare

With SoC wide DMA mask of 40-bit, the mappings for entire IOVA space can't be specified in the PAXBv2 PCIe RC of SoC. The holes in IOVA space needs to
be reserved to prevent any IOVA allocations in those spaces.

Quoted 5 lines

Can you clarify why? If this is the PCI inbound window thing again, let me say once again that "dma-ranges" is the appropriate way for DT to describe the hardware.

Robin.

dma-ranges = < \
0x43000000 0x00 0x00000000 0x00 0x80000000 0x00 0x80000000 \
0x43000000 0x08 0x00000000 0x08 0x00000000 0x08 0x00000000 \
0x43000000 0x80 0x00000000 0x80 0x00000000 0x80 0x00000000>

Yes, its for PCI inbound windows. In our HW, they are limited by sizes specified in
ARM memory maps which was done for non-IOMMU cases to catch any transfer outside the ranges.
dma-ranges are already being used to program these inbound windows and SoC wide DMA mask is already specified but IOMMU code can still allocate IOVAs in the gaps for which translation will fail in PCIe RC.

Quoted 34 lines
Quoted 33 lines

reserved-dma-region property is added to specify the ranges which should never be mapped and given to devices sitting behind.

---
  Documentation/devicetree/bindings/pci/brcm,iproc-pcie.txt | 3 +++
  1 file changed, 3 insertions(+)
Documentation/devicetree/bindings/pci/brcm,iproc-pcie.txt +0 -0
index b8e48b4..3be0fe3 100644
@@ -30,6 +30,9 @@ Optional properties:
  - dma-ranges: Some PAXB-based root complexes do not have inbound mapping

done
by the ASIC after power on reset. In this case, SW is required to
configure
the mapping, based on inbound memory regions specified by this property.
+- reserved-dma-region: PAXBv2 with IOMMU enabled cannot provide mappings for
+ entire IOVA space specified by DMA mask. Hence this is used to reserve the
+ gaps in dma-ranges.
- brcm,pcie-ob: Some iProc SoCs do not have the outbound address
mapping done
by the ASIC after power on reset. In this case, SW needs to configure it

maintainer
#9 lore raw

RFC 2/5 dt-bindings: brcm: Add reserved-dma-region for iPROC

Quoted 19 lines · Jitendra Bhivare
Quoted 8 lines · Robin Murphy
Quoted 5 lines · Jitendra Bhivare

With SoC wide DMA mask of 40-bit, the mappings for entire IOVA space can't be specified in the PAXBv2 PCIe RC of SoC. The holes in IOVA space needs to
be reserved to prevent any IOVA allocations in those spaces.

Quoted 5 lines

Can you clarify why? If this is the PCI inbound window thing again, let me say once again that "dma-ranges" is the appropriate way for DT to describe the hardware.

Robin.

dma-ranges = < \
0x43000000 0x00 0x00000000 0x00 0x80000000 0x00 0x80000000 \
0x43000000 0x08 0x00000000 0x08 0x00000000 0x08 0x00000000 \
0x43000000 0x80 0x00000000 0x80 0x00000000 0x80 0x00000000>

Quoted 7 lines

Yes, its for PCI inbound windows. In our HW, they are limited by sizes specified in
ARM memory maps which was done for non-IOMMU cases to catch any transfer outside the ranges.
dma-ranges are already being used to program these inbound windows and SoC wide DMA mask is already specified but IOMMU code can still allocate IOVAs in the gaps for which translation will fail in PCIe RC.

Right, so make iommu-dma reserve the gaps. No need to clutter up the DT with redundant information which gets handled pretty much identically anyway.

Robin.

Quoted 34 lines
Quoted 34 lines
Quoted 33 lines

reserved-dma-region property is added to specify the ranges which should never be mapped and given to devices sitting behind.

---
   Documentation/devicetree/bindings/pci/brcm,iproc-pcie.txt | 3 +++
   1 file changed, 3 insertions(+)
Documentation/devicetree/bindings/pci/brcm,iproc-pcie.txt +0 -0
index b8e48b4..3be0fe3 100644
@@ -30,6 +30,9 @@ Optional properties:
   - dma-ranges: Some PAXB-based root complexes do not have inbound mapping

done
by the ASIC after power on reset. In this case, SW is required to
configure
the mapping, based on inbound memory regions specified by this property.
+- reserved-dma-region: PAXBv2 with IOMMU enabled cannot provide mappings for
+ entire IOVA space specified by DMA mask. Hence this is used to reserve the
+ gaps in dma-ranges.
- brcm,pcie-ob: Some iProc SoCs do not have the outbound address
mapping done
by the ASIC after power on reset. In this case, SW needs to configure it

#10 lore raw

RFC 2/5 dt-bindings: brcm: Add reserved-dma-region for iPROC

Quoted 37 lines · Robin Murphy
Quoted 27 lines · Jitendra Bhivare
Quoted 12 lines · Robin Murphy
Quoted 7 lines · Jitendra Bhivare

With SoC wide DMA mask of 40-bit, the mappings for entire IOVA space can't
be specified in the PAXBv2 PCIe RC of SoC. The holes in IOVA space needs to
be reserved to prevent any IOVA allocations in those spaces.

Quoted 7 lines

Can you clarify why? If this is the PCI inbound window thing again, let me
say once again that "dma-ranges" is the appropriate way for DT to describe
the hardware.

Robin.

dma-ranges = < \
0x43000000 0x00 0x00000000 0x00 0x80000000 0x00 0x80000000 \
0x43000000 0x08 0x00000000 0x08 0x00000000 0x08 0x00000000 \
0x43000000 0x80 0x00000000 0x80 0x00000000 0x80 0x00000000>

Quoted 7 lines

Yes, its for PCI inbound windows. In our HW, they are limited by sizes specified in
ARM memory maps which was done for non-IOMMU cases to catch any transfer outside the ranges.
dma-ranges are already being used to program these inbound windows and SoC wide DMA mask is already specified but IOMMU code can still allocate IOVAs in the gaps for which translation will fail in PCIe RC.

Quoted 4 lines

Right, so make iommu-dma reserve the gaps. No need to clutter up the DT with redundant information which gets handled pretty much identically anyway.

Robin.

There was a mistake in pasting dma-ranges mentioned. This is what we use it in IOMMU case.
#define PCIE_DMA_RANGES dma-ranges = < \
0x43000000 0x00 0x00000000 0x00 0x00000000 0x04 0x00000000 \
0x43000000 0x08 0x00000000 0x08 0x00000000 0x08 0x00000000 \
0x43000000 0x80 0x00000000 0x80 0x00000000 0x80 0x00000000>

#define PCIE_RESERVED_DMA_REGION reserved-dma-region = < \
0x0 0x0 0x04 0x0 0x04 0x0 \
0x0 0x0 0x10 0x0 0x70 0x0>

This is non-iommu case which is per ARM memory map. #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>

In IOMMU case, we had to increase first in-bound window i.e. dma-ranges first entry
from 2GB-4GB (in non-iommu case) to 0-16GB because out-bound window specified from 2GB-4GB implicitly gets reserved by the PCI iommu code. This allowed IOVA allocations from 0-2GB and 4-16GB mapped through in-bound windows.

Basically, my point is that dma-ranges specified is being used to program our in-bound
windows and defines PCI space to CPU address space supported mappings of HW. In the same way, it would be better to explicitly specify reserved-dma-region to clarify
this as HW hole than implicity reserving the regions.

We can at least have single property 'reserved-dma-window' for MSI region and DMA regions
to help describe the holes in the HW than let SW compute it.

Quoted 40 lines
Quoted 39 lines
Quoted 39 lines
Quoted 38 lines

reserved-dma-region property is added to specify the ranges which should never be mapped and given to devices sitting behind.

---
   Documentation/devicetree/bindings/pci/brcm,iproc-pcie.txt | 3 +++
   1 file changed, 3 insertions(+)
Documentation/devicetree/bindings/pci/brcm,iproc-pcie.txt +0 -0
index b8e48b4..3be0fe3 100644
@@ -30,6 +30,9 @@ Optional properties:
   - dma-ranges: Some PAXB-based root complexes do not have inbound

mapping
done
by the ASIC after power on reset. In this case, SW is required to
configure
the mapping, based on inbound memory regions specified by this
property.
+- reserved-dma-region: PAXBv2 with IOMMU enabled cannot provide mappings
for
+ entire IOVA space specified by DMA mask. Hence this is used to reserve
the
+ gaps in dma-ranges.
- brcm,pcie-ob: Some iProc SoCs do not have the outbound address
mapping done
by the ASIC after power on reset. In this case, SW needs to configure
it

maintainer
#11 lore raw

RFC 2/5 dt-bindings: brcm: Add reserved-dma-region for iPROC

Quoted 65 lines · Jitendra Bhivare
Quoted 37 lines · Robin Murphy
Quoted 27 lines · Jitendra Bhivare
Quoted 12 lines · Robin Murphy
Quoted 7 lines · Jitendra Bhivare

With SoC wide DMA mask of 40-bit, the mappings for entire IOVA space can't
be specified in the PAXBv2 PCIe RC of SoC. The holes in IOVA space needs to
be reserved to prevent any IOVA allocations in those spaces.

Quoted 7 lines

Can you clarify why? If this is the PCI inbound window thing again, let me
say once again that "dma-ranges" is the appropriate way for DT to describe
the hardware.

Robin.

dma-ranges = < \
0x43000000 0x00 0x00000000 0x00 0x80000000 0x00 0x80000000 \
0x43000000 0x08 0x00000000 0x08 0x00000000 0x08 0x00000000 \
0x43000000 0x80 0x00000000 0x80 0x00000000 0x80 0x00000000>

Quoted 7 lines

Yes, its for PCI inbound windows. In our HW, they are limited by sizes specified in
ARM memory maps which was done for non-IOMMU cases to catch any transfer outside the ranges.
dma-ranges are already being used to program these inbound windows and SoC wide DMA mask is already specified but IOMMU code can still allocate IOVAs in the gaps for which translation will fail in PCIe RC.

Quoted 4 lines

Right, so make iommu-dma reserve the gaps. No need to clutter up the DT with redundant information which gets handled pretty much identically anyway.

Robin.

There was a mistake in pasting dma-ranges mentioned. This is what we use it in IOMMU case.
#define PCIE_DMA_RANGES dma-ranges = < \
0x43000000 0x00 0x00000000 0x00 0x00000000 0x04 0x00000000 \
0x43000000 0x08 0x00000000 0x08 0x00000000 0x08 0x00000000 \
0x43000000 0x80 0x00000000 0x80 0x00000000 0x80 0x00000000>

#define PCIE_RESERVED_DMA_REGION reserved-dma-region = < \
0x0 0x0 0x04 0x0 0x04 0x0 \
0x0 0x0 0x10 0x0 0x70 0x0>

This is non-iommu case which is per ARM memory map. #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>

In IOMMU case, we had to increase first in-bound window i.e. dma-ranges first entry
from 2GB-4GB (in non-iommu case) to 0-16GB because out-bound window specified from 2GB-4GB implicitly gets reserved by the PCI iommu code. This allowed IOVA allocations from 0-2GB and 4-16GB mapped through in-bound windows.

Quoted 6 lines

Basically, my point is that dma-ranges specified is being used to program our in-bound
windows and defines PCI space to CPU address space supported mappings of HW. In the same way, it would be better to explicitly specify reserved-dma-region to clarify
this as HW hole than implicity reserving the regions.

Why? If DMA traffic can only pass through inbound windows, and you program the inbound windows based on dma-ranges, then by definition dma-ranges tells you exactly the set of addresses that are usable for DMA, and by extension, IOMMU remapping. I fail to see how it's then "better" to add a second slightly different description of the exact same information with the bonus maintenance burden of then having to ensure the two actually match.

Robin.

Quoted 44 lines

We can at least have single property 'reserved-dma-window' for MSI region and DMA regions
to help describe the holes in the HW than let SW compute it.

Quoted 40 lines
Quoted 39 lines
Quoted 39 lines
Quoted 38 lines

reserved-dma-region property is added to specify the ranges which should never be mapped and given to devices sitting behind.

---
    Documentation/devicetree/bindings/pci/brcm,iproc-pcie.txt | 3 +++
    1 file changed, 3 insertions(+)
Documentation/devicetree/bindings/pci/brcm,iproc-pcie.txt +0 -0
index b8e48b4..3be0fe3 100644
@@ -30,6 +30,9 @@ Optional properties:
    - dma-ranges: Some PAXB-based root complexes do not have inbound

mapping
done
by the ASIC after power on reset. In this case, SW is required to
configure
the mapping, based on inbound memory regions specified by this
property.
+- reserved-dma-region: PAXBv2 with IOMMU enabled cannot provide mappings
for
+ entire IOVA space specified by DMA mask. Hence this is used to reserve
the
+ gaps in dma-ranges.
- brcm,pcie-ob: Some iProc SoCs do not have the outbound address
mapping done
by the ASIC after power on reset. In this case, SW needs to configure
it

#12 lore raw

RFC 3/5 dt-bindings: arm-smmu: Add reserved-msi-region

In reply to Jitendra Bhivare

iPROC SoC has a special device window to treat GICv3 ITS MSI.

Current code maps MSI to IOVA space. Add SMMU node property to use direct mappings for MSI region.

This property is read and reserved when arm_smmu_get_resv_regions gets called.

---
 Documentation/devicetree/bindings/iommu/arm,smmu.txt | 12 ++++++++++++
 1 file changed, 12 insertions(+)
Documentation/devicetree/bindings/iommu/arm,smmu.txt +12 -0
index 8a6ffce..13fa2b9 100644
@@ -71,6 +71,15 @@ conditions.
                   or using stream matching with #iommu-cells = <2>, and
                   may be ignored if present in such cases.
 
+- reserved-msi-region: MSI region to be reserved with specific prot in IOVA
+		  space for direct mapping. The region is specified in tuple
+		  of (busno,prot,bus_addr,size).
+
+- #region-address-cells: specifies number of cells needed to encode bus_addr
+
+- #region-size-cells: specifies number of cells needed to encode size
+
+
 ** Deprecated properties:
 
 - mmu-masters (deprecated in favour of the generic "iommus" binding) :
@@ -95,6 +104,9 @@ conditions.
                              <0 36 4>,
                              <0 37 4>;
                 #iommu-cells = <1>;
+		#region-address-cells = <1>;
+		#region-size-cells = <1>;
+		reserved-msi-region = <0x0 0x1a 0x63c3000 0x8000>;
         };
 
         /* device with two stream IDs, 0 and 7 */
Signature · 1 line
2.7.4
maintainer
#13 lore raw

RFC 3/5 dt-bindings: arm-smmu: Add reserved-msi-region

Quoted 1 line · Jitendra Bhivare

iPROC SoC has a special device window to treat GICv3 ITS MSI.

Ugh, really? After preferably printing out 100 copies of the SBSA, binding them all together and dropping the lot onto the hardware designers from a great height, could you clarify what exactly the special behaviour is here?

Robin.

Quoted 42 lines

Current code maps MSI to IOVA space. Add SMMU node property to use direct mappings for MSI region.

This property is read and reserved when arm_smmu_get_resv_regions gets called.

---
  Documentation/devicetree/bindings/iommu/arm,smmu.txt | 12 ++++++++++++
  1 file changed, 12 insertions(+)
Documentation/devicetree/bindings/iommu/arm,smmu.txt +12 -0
index 8a6ffce..13fa2b9 100644
@@ -71,6 +71,15 @@ conditions.
                    or using stream matching with #iommu-cells = <2>, and
                    may be ignored if present in such cases.
 
+- reserved-msi-region: MSI region to be reserved with specific prot in IOVA
+		  space for direct mapping. The region is specified in tuple
+		  of (busno,prot,bus_addr,size).
+
+- #region-address-cells: specifies number of cells needed to encode bus_addr
+
+- #region-size-cells: specifies number of cells needed to encode size
+
+
  ** Deprecated properties:
 
  - mmu-masters (deprecated in favour of the generic "iommus" binding) :
@@ -95,6 +104,9 @@ conditions.
                               <0 36 4>,
                               <0 37 4>;
                  #iommu-cells = <1>;
+		#region-address-cells = <1>;
+		#region-size-cells = <1>;
+		reserved-msi-region = <0x0 0x1a 0x63c3000 0x8000>;
          };
 
          /* device with two stream IDs, 0 and 7 */
#14 lore raw

RFC 3/5 dt-bindings: arm-smmu: Add reserved-msi-region

Quoted 11 lines · Robin Murphy
Quoted 2 lines · Jitendra Bhivare

iPROC SoC has a special device window to treat GICv3 ITS MSI.

Ugh, really? After preferably printing out 100 copies of the SBSA, binding them all together and dropping the lot onto the hardware designers from a great height, could you clarify what exactly the special behaviour is here?

Robin.

The special device window needs to programmed so that writes to specified address
region helps for specific ordering of traffic prior to it.

Quoted 45 lines
Quoted 44 lines

Current code maps MSI to IOVA space. Add SMMU node property to use direct mappings for MSI region.

This property is read and reserved when arm_smmu_get_resv_regions gets called.

---
  Documentation/devicetree/bindings/iommu/arm,smmu.txt | 12 ++++++++++++
  1 file changed, 12 insertions(+)
Documentation/devicetree/bindings/iommu/arm,smmu.txt +0 -0
index 8a6ffce..13fa2b9 100644
@@ -71,6 +71,15 @@ conditions.
                    or using stream matching with #iommu-cells = <2>, and
                    may be ignored if present in such cases.
  +- reserved-msi-region: MSI region to be reserved with specific prot in

IOVA
+ space for direct mapping. The region is specified in
tuple

Documentation/devicetree/bindings/iommu/arm,smmu.txt +3 -0
+                 of (busno,prot,bus_addr,size).
+
+- #region-address-cells: specifies number of cells needed to encode

bus_addr

Documentation/devicetree/bindings/iommu/arm,smmu.txt +7 -0
+
+- #region-size-cells: specifies number of cells needed to encode size
+
+
  ** Deprecated properties:
    - mmu-masters (deprecated in favour of the generic "iommus" binding) :
@@ -95,6 +104,9 @@ conditions.
                               <0 36 4>,
                               <0 37 4>;
                  #iommu-cells = <1>;
+               #region-address-cells = <1>;
+               #region-size-cells = <1>;
+               reserved-msi-region = <0x0 0x1a 0x63c3000 0x8000>;
          };
            /* device with two stream IDs, 0 and 7 */
 
maintainer
#15 lore raw

RFC 3/5 dt-bindings: arm-smmu: Add reserved-msi-region

Quoted 10 lines · Jitendra Bhivare
Quoted 9 lines · Robin Murphy
Quoted 2 lines · Jitendra Bhivare

iPROC SoC has a special device window to treat GICv3 ITS MSI.

Ugh, really? After preferably printing out 100 copies of the SBSA, binding them all together and dropping the lot onto the hardware designers from a great height, could you clarify what exactly the special behaviour is here?

Quoted 5 lines
Quoted 2 lines

Robin.

The special device window needs to programmed so that writes to specified address
region helps for specific ordering of traffic prior to it.

OK, I know of PCIe root complexes having address matching to give the MSI write the appropriate AXI memory type attributes when the SMMU is bypassed, but ordering is a new one. I guess you have some glue logic on the root complex master interface which injects an ACE barrier transaction in front of any write to the ITS doorbell address?

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Current code maps MSI to IOVA space. Add SMMU node property to use direct mappings for MSI region.

This property is read and reserved when arm_smmu_get_resv_regions gets called.

Either way, this should be a generic, not SMMU-specific, property - there are other platforms that would also make use of it to describe a similar hardware situation (which we currently only support via ACPI). The big question is where to put it: hardware-wise, the property of "MSIs won't work properly if the doorbell is remapped to a different address" belongs firmly to the root complex, not the IOMMU, while the address itself is already a property of the MSI controller. The IOMMU is just the innocent guy in the middle who has to discover and respect the constraints.

I'd like to think we could just have some flag to say "you can't remap my MSIs!" then go and chase the msi-parent/msi-map phandle to the MSI controller to get the address from its reg property, which is more or less the equivalent of what the current ACPI workaround does - see commit 8b4282e6b8e2 ("ACPI/IORT: Add msi address regions reservation helper") in linux-next - but I can already think of ways in which that might not work. For one, there's not necessarily any guarantee that the MSI controller's programming interface and doorbell are in the same place, so we probably do need to describe the specific MSI address(es) that the root complex cares about, from the root complex end :/

Robin.

Quoted 39 lines
Quoted 39 lines
Quoted 38 lines
---
   Documentation/devicetree/bindings/iommu/arm,smmu.txt | 12 ++++++++++++
   1 file changed, 12 insertions(+)
Documentation/devicetree/bindings/iommu/arm,smmu.txt +0 -0
index 8a6ffce..13fa2b9 100644
@@ -71,6 +71,15 @@ conditions.
                     or using stream matching with #iommu-cells = <2>, and
                     may be ignored if present in such cases.
   +- reserved-msi-region: MSI region to be reserved with specific prot in

IOVA
+ space for direct mapping. The region is specified in
tuple

Documentation/devicetree/bindings/iommu/arm,smmu.txt +3 -0
+                 of (busno,prot,bus_addr,size).
+
+- #region-address-cells: specifies number of cells needed to encode

bus_addr

Documentation/devicetree/bindings/iommu/arm,smmu.txt +7 -0
+
+- #region-size-cells: specifies number of cells needed to encode size
+
+
   ** Deprecated properties:
     - mmu-masters (deprecated in favour of the generic "iommus" binding) :
@@ -95,6 +104,9 @@ conditions.
                                <0 36 4>,
                                <0 37 4>;
                   #iommu-cells = <1>;
+               #region-address-cells = <1>;
+               #region-size-cells = <1>;
+               reserved-msi-region = <0x0 0x1a 0x63c3000 0x8000>;
           };
             /* device with two stream IDs, 0 and 7 */
 
#16 lore raw

RFC 4/5 iommu/of: Reserve IOMMU DMA regions using DT

In reply to Jitendra Bhivare

iPROC SoC provides restricted windows to access sparsed memory as per ARM memory map to the devices sitting behind IOMMU. The windows cover enough DDR space but not the entire 40-bit 1TB space used by IOMMU code as per the DMA mask set.

Current IOMMU code does not provide a hook to reserve these holes. Use defined but unused of_get_dma_window to get reserved DMA regions from DT.

To reserve the regions for IOVA allocation, ranges can be specified in DT as <busno prot bus_addr size>. These regions are marked as IOMMU_RESV_RESERVED when device behind SMMU gets added and arm_smmu_get_resv_regions gets called.

This provision is also used in reserving region for GICv3 ITS using IOMMU_RESV_DIRECT as it falls in special device window.

---
 drivers/iommu/dma-iommu.c |   6 +++
 drivers/iommu/of_iommu.c  | 100 ++++++++++++++++++++++++----------------------
 include/linux/iommu.h     |   3 ++
 include/linux/of_iommu.h  |  25 +++++++++---
 4 files changed, 81 insertions(+), 53 deletions(-)
drivers/iommu/dma-iommu.c +6 -0
index 25914d3..433d427 100644
@@ -27,6 +27,7 @@
 #include <linux/iova.h>
 #include <linux/irq.h>
 #include <linux/mm.h>
+#include <linux/of_iommu.h>
 #include <linux/pci.h>
 #include <linux/scatterlist.h>
 #include <linux/vmalloc.h>
@@ -173,6 +174,7 @@ void iommu_dma_get_resv_regions(struct device *dev, struct list_head *list)
 {
 	struct pci_host_bridge *bridge;
 	struct resource_entry *window;
+	struct device_node *np;
 
 	if (!dev_is_pci(dev))
 		return;
@@ -195,6 +197,10 @@ void iommu_dma_get_resv_regions(struct device *dev, struct list_head *list)
 
 		list_add_tail(&region->list, list);
 	}
+	/* check platform device representing bridge for reserved DMA windows */
+	np = bridge->dev.parent->of_node;
+	if (np)
+		of_iommu_resv_dma_regions(np, list);
 }
 EXPORT_SYMBOL(iommu_dma_get_resv_regions);
 
drivers/iommu/of_iommu.c +53 -47

125 lines not on this page · raw message

include/linux/iommu.h +3 -0
index 41b8c57..56bf906 100644
@@ -41,6 +41,9 @@
  * if the IOMMU page table format is equivalent.
  */
 #define IOMMU_PRIV	(1 << 5)
+#define IOMMU_PROT_FLAGS (IOMMU_READ | IOMMU_WRITE | \
+			  IOMMU_CACHE | IOMMU_NOEXEC | IOMMU_MMIO)
+
 
 struct iommu_ops;
 struct iommu_group;
include/linux/of_iommu.h +19 -6
index cddfaff..b891bac 100644
@@ -6,20 +6,27 @@
 #include <linux/iommu.h>
 #include <linux/of.h>
 
+struct of_iommu_resv_region {
+	u32 busno;
+	u32 prot;
+	u64 bus_addr;
+	u64 size;
+};
+
 #ifdef CONFIG_OF_IOMMU
 
-extern int of_get_dma_window(struct device_node *dn, const char *prefix,
-			     int index, unsigned long *busno, dma_addr_t *addr,
-			     size_t *size);
+int of_get_resv_region(struct device_node *dn, const char *region, int *index,
+		      struct of_iommu_resv_region *of_region);
 
 extern const struct iommu_ops *of_iommu_configure(struct device *dev,
 					struct device_node *master_np);
 
+void of_iommu_resv_dma_regions(struct device_node *np, struct list_head *list);
+
 #else
 
-static inline int of_get_dma_window(struct device_node *dn, const char *prefix,
-			    int index, unsigned long *busno, dma_addr_t *addr,
-			    size_t *size)
+static inline int of_get_resv_region(struct device_node *dn, const char *region,
+			int *index, struct of_iommu_resv_region *of_region)
 {
 	return -EINVAL;
 }
@@ -30,6 +37,12 @@ static inline const struct iommu_ops *of_iommu_configure(struct device *dev,
 	return NULL;
 }
 
+static inline int of_iommu_resv_dma_regions(struct device_node *np,
+					    struct list_head *list)
+{
+	return -EINVAL;
+}
+
 #endif	/* CONFIG_OF_IOMMU */
 
 extern struct of_device_id __iommu_of_table;
Signature · 1 line
2.7.4
#17 lore raw

RFC 5/5 iommu/arm-smmu: Allow direct mapping for MSI region

In reply to Jitendra Bhivare

Current ARM SMMU virtualizes MSI addresses to IOVA space.

In iProc SoCs, MSI needs to be steered. Allow reserving MSI address range using DT node entry as direct region.

---
 drivers/iommu/arm-smmu.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/iommu/arm-smmu.c +13 -1
index 78d4c6b..7b34980 100644
@@ -1533,8 +1533,11 @@ static int arm_smmu_of_xlate(struct device *dev, struct of_phandle_args *args)
 static void arm_smmu_get_resv_regions(struct device *dev,
 				      struct list_head *head)
 {
+	struct iommu_fwspec *fwspec = dev->iommu_fwspec;
+	struct arm_smmu_device *smmu = fwspec_smmu(fwspec);
 	struct iommu_resv_region *region;
-	int prot = IOMMU_WRITE | IOMMU_NOEXEC | IOMMU_MMIO;
+	struct of_iommu_resv_region of_region;
+	int index = 0, prot = IOMMU_WRITE | IOMMU_NOEXEC | IOMMU_MMIO;
 
 	region = iommu_alloc_resv_region(MSI_IOVA_BASE, MSI_IOVA_LENGTH,
 					 prot, IOMMU_RESV_SW_MSI);
@@ -1543,6 +1546,15 @@ static void arm_smmu_get_resv_regions(struct device *dev,
 
 	list_add_tail(&region->list, head);
 
+	if (!of_get_resv_region(smmu->dev->of_node, "msi", &index,
+				&of_region)) {
+		region = iommu_alloc_resv_region(of_region.bus_addr,
+						 of_region.size,
+						 of_region.prot,
+						 IOMMU_RESV_DIRECT);
+		if (region)
+			list_add_tail(&region->list, head);
+	}
 	iommu_dma_get_resv_regions(dev, head);
 }
 
Signature · 1 line
2.7.4