PCI: dwc: Program outbound ATU upper limit register
authorAlan Mikhak <alan.mikhak@sifive.com>
Wed, 1 Apr 2020 23:58:13 +0000 (16:58 -0700)
committerLorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Fri, 22 May 2020 14:05:23 +0000 (15:05 +0100)
Function dw_pcie_prog_outbound_atu_unroll() does not program the upper
32-bit ATU limit register. Since ATU programming functions limit the
size of the translated region to 4GB by using a u32 size parameter,
these issues may combine into undefined behavior for resource sizes
with non-zero upper 32-bits.

For example, a 128GB address space starting at physical CPU address of
0x2000000000 with size of 0x2000000000 needs the following values
programmed into the lower and upper 32-bit limit registers:
 0x3fffffff in the upper 32-bit limit register
 0xffffffff in the lower 32-bit limit register

Currently, only the lower 32-bit limit register is programmed with a
value of 0xffffffff but the upper 32-bit limit register is not being
programmed. As a result, the upper 32-bit limit register remains at its
default value after reset of 0x0.

These issues may combine to produce undefined behavior since the ATU
limit address may be lower than the ATU base address. Programming the
upper ATU limit address register prevents such undefined behavior despite
the region size getting truncated due to the 32-bit size limit.

Link: https://lore.kernel.org/r/1585785493-23210-1-git-send-email-alan.mikhak@sifive.com
Signed-off-by: Alan Mikhak <alan.mikhak@sifive.com>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Acked-by: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
drivers/pci/controller/dwc/pcie-designware.c
drivers/pci/controller/dwc/pcie-designware.h

index 681548c88282ce7e582fe4a11d55329f9a64177c..c92496e36fd5fa7f50f43340de1fff4b79cb63c7 100644 (file)
@@ -244,13 +244,16 @@ static void dw_pcie_prog_outbound_atu_unroll(struct dw_pcie *pci, int index,
                                             u64 pci_addr, u32 size)
 {
        u32 retries, val;
+       u64 limit_addr = cpu_addr + size - 1;
 
        dw_pcie_writel_ob_unroll(pci, index, PCIE_ATU_UNR_LOWER_BASE,
                                 lower_32_bits(cpu_addr));
        dw_pcie_writel_ob_unroll(pci, index, PCIE_ATU_UNR_UPPER_BASE,
                                 upper_32_bits(cpu_addr));
-       dw_pcie_writel_ob_unroll(pci, index, PCIE_ATU_UNR_LIMIT,
-                                lower_32_bits(cpu_addr + size - 1));
+       dw_pcie_writel_ob_unroll(pci, index, PCIE_ATU_UNR_LOWER_LIMIT,
+                                lower_32_bits(limit_addr));
+       dw_pcie_writel_ob_unroll(pci, index, PCIE_ATU_UNR_UPPER_LIMIT,
+                                upper_32_bits(limit_addr));
        dw_pcie_writel_ob_unroll(pci, index, PCIE_ATU_UNR_LOWER_TARGET,
                                 lower_32_bits(pci_addr));
        dw_pcie_writel_ob_unroll(pci, index, PCIE_ATU_UNR_UPPER_TARGET,
index d6e1f397e6b0fc6fc961dbdb4acfa802eab68bad..656e00f8fbeb49223af1747fb8caa3f1245276c4 100644 (file)
 #define PCIE_ATU_UNR_REGION_CTRL2      0x04
 #define PCIE_ATU_UNR_LOWER_BASE                0x08
 #define PCIE_ATU_UNR_UPPER_BASE                0x0C
-#define PCIE_ATU_UNR_LIMIT             0x10
+#define PCIE_ATU_UNR_LOWER_LIMIT       0x10
 #define PCIE_ATU_UNR_LOWER_TARGET      0x14
 #define PCIE_ATU_UNR_UPPER_TARGET      0x18
+#define PCIE_ATU_UNR_UPPER_LIMIT       0x20
 
 /*
  * The default address offset between dbi_base and atu_base. Root controller