]> git.sur5r.net Git - u-boot/blobdiff - drivers/pci/pcie_layerscape_fixup.c
mtd: spi: Correct parameters for s25fs512s flash
[u-boot] / drivers / pci / pcie_layerscape_fixup.c
index d7591bcff02fe61d25c6bd04a1c1e287913bc49f..1a17bd98aa4ca3fe3081a99f20c61e351b718034 100644 (file)
@@ -1,8 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
+ * Copyright 2017 NXP
  * Copyright 2014-2015 Freescale Semiconductor, Inc.
  * Layerscape PCIe driver
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
 #include <asm/io.h>
 #include <errno.h>
 #ifdef CONFIG_OF_BOARD_SETUP
-#include <libfdt.h>
+#include <linux/libfdt.h>
 #include <fdt_support.h>
+#ifdef CONFIG_ARM
+#include <asm/arch/clock.h>
+#endif
 #include "pcie_layerscape.h"
 
 #if defined(CONFIG_FSL_LSCH3) || defined(CONFIG_FSL_LSCH2)
@@ -82,7 +85,8 @@ static void fdt_pcie_set_msi_map_entry(void *blob, struct ls_pcie *pcie,
 #ifdef CONFIG_FSL_PCIE_COMPAT /* Compatible with older version of dts node */
                svr = (get_svr() >> SVR_VAR_PER_SHIFT) & 0xFFFFFE;
                if (svr == SVR_LS2088A || svr == SVR_LS2084A ||
-                   svr == SVR_LS2048A || svr == SVR_LS2044A)
+                   svr == SVR_LS2048A || svr == SVR_LS2044A ||
+                   svr == SVR_LS2081A || svr == SVR_LS2041A)
                        compat = "fsl,ls2088a-pcie";
                else
                        compat = CONFIG_FSL_PCIE_COMPAT;
@@ -110,6 +114,67 @@ static void fdt_pcie_set_msi_map_entry(void *blob, struct ls_pcie *pcie,
        fdt_appendprop_u32(blob, nodeoffset, "msi-map", 1);
 }
 
+/*
+ * An iommu-map is a property to be added to the pci controller
+ * node.  It is a table, where each entry consists of 4 fields
+ * e.g.:
+ *
+ *      iommu-map = <[devid] [phandle-to-iommu-ctrl] [stream-id] [count]
+ *                 [devid] [phandle-to-iommu-ctrl] [stream-id] [count]>;
+ */
+static void fdt_pcie_set_iommu_map_entry(void *blob, struct ls_pcie *pcie,
+                                      u32 devid, u32 streamid)
+{
+       u32 *prop;
+       u32 iommu_map[4];
+       int nodeoffset;
+       int lenp;
+       uint svr;
+       char *compat = NULL;
+
+       /* find pci controller node */
+       nodeoffset = fdt_node_offset_by_compat_reg(blob, "fsl,ls-pcie",
+                                                  pcie->dbi_res.start);
+       if (nodeoffset < 0) {
+#ifdef CONFIG_FSL_PCIE_COMPAT /* Compatible with older version of dts node */
+               svr = (get_svr() >> SVR_VAR_PER_SHIFT) & 0xFFFFFE;
+               if (svr == SVR_LS2088A || svr == SVR_LS2084A ||
+                   svr == SVR_LS2048A || svr == SVR_LS2044A ||
+                   svr == SVR_LS2081A || svr == SVR_LS2041A)
+                       compat = "fsl,ls2088a-pcie";
+               else
+                       compat = CONFIG_FSL_PCIE_COMPAT;
+
+               if (compat)
+                       nodeoffset = fdt_node_offset_by_compat_reg(blob,
+                                               compat, pcie->dbi_res.start);
+#endif
+               if (nodeoffset < 0)
+                       return;
+       }
+
+       /* get phandle to iommu controller */
+       prop = fdt_getprop_w(blob, nodeoffset, "iommu-map", &lenp);
+       if (prop == NULL) {
+               debug("\n%s: ERROR: missing iommu-map: PCIe%d\n",
+                     __func__, pcie->idx);
+               return;
+       }
+
+       /* set iommu-map row */
+       iommu_map[0] = cpu_to_fdt32(devid);
+       iommu_map[1] = *++prop;
+       iommu_map[2] = cpu_to_fdt32(streamid);
+       iommu_map[3] = cpu_to_fdt32(1);
+
+       if (devid == 0) {
+               fdt_setprop_inplace(blob, nodeoffset, "iommu-map",
+                                   iommu_map, 16);
+       } else {
+               fdt_appendprop(blob, nodeoffset, "iommu-map", iommu_map, 16);
+       }
+}
+
 static void fdt_fixup_pcie(void *blob)
 {
        struct udevice *dev, *bus;
@@ -146,6 +211,9 @@ static void fdt_fixup_pcie(void *blob)
                /* update msi-map in device tree */
                fdt_pcie_set_msi_map_entry(blob, pcie, bdf >> 8,
                                           streamid);
+               /* update iommu-map in device tree */
+               fdt_pcie_set_iommu_map_entry(blob, pcie, bdf >> 8,
+                                            streamid);
        }
 }
 #endif
@@ -162,7 +230,8 @@ static void ft_pcie_ls_setup(void *blob, struct ls_pcie *pcie)
 #ifdef CONFIG_FSL_PCIE_COMPAT /* Compatible with older version of dts node */
                svr = (get_svr() >> SVR_VAR_PER_SHIFT) & 0xFFFFFE;
                if (svr == SVR_LS2088A || svr == SVR_LS2084A ||
-                   svr == SVR_LS2048A || svr == SVR_LS2044A)
+                   svr == SVR_LS2048A || svr == SVR_LS2044A ||
+                   svr == SVR_LS2081A || svr == SVR_LS2041A)
                        compat = "fsl,ls2088a-pcie";
                else
                        compat = CONFIG_FSL_PCIE_COMPAT;