[PATCH v3 2/4] pci: layerscape: move pci node search in a common function

laurentiu.tudor at nxp.com laurentiu.tudor at nxp.com
Tue Aug 18 12:35:09 CEST 2020


From: Laurentiu Tudor <laurentiu.tudor at nxp.com>

Fix duplication of this code by placing it in a common function.
Furthermore, the resulting function will be re-used in upcoming
patches.

Signed-off-by: Laurentiu Tudor <laurentiu.tudor at nxp.com>
---
 drivers/pci/pcie_layerscape_fixup.c | 68 +++++++++++++----------------
 1 file changed, 30 insertions(+), 38 deletions(-)

diff --git a/drivers/pci/pcie_layerscape_fixup.c b/drivers/pci/pcie_layerscape_fixup.c
index 7c55e3d249..9e93841ccd 100644
--- a/drivers/pci/pcie_layerscape_fixup.c
+++ b/drivers/pci/pcie_layerscape_fixup.c
@@ -111,32 +111,18 @@ static void fdt_pcie_set_msi_map_entry_ls(void *blob,
 	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_ls(void *blob,
-					    struct ls_pcie_rc *pcie_rc,
-					    u32 devid, u32 streamid)
+static int fdt_pcie_get_nodeoffset(void *blob, struct ls_pcie_rc *pcie_rc)
 {
-	u32 *prop;
-	u32 iommu_map[4];
 	int nodeoffset;
-	int lenp;
 	uint svr;
 	char *compat = NULL;
-	struct ls_pcie *pcie = pcie_rc->pcie;
 
 	/* find pci controller node */
 	nodeoffset = fdt_node_offset_by_compat_reg(blob, "fsl,ls-pcie",
 						   pcie_rc->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;
+		svr = SVR_SOC_VER(get_svr());
 		if (svr == SVR_LS2088A || svr == SVR_LS2084A ||
 		    svr == SVR_LS2048A || svr == SVR_LS2044A ||
 		    svr == SVR_LS2081A || svr == SVR_LS2041A)
@@ -148,10 +134,33 @@ static void fdt_pcie_set_iommu_map_entry_ls(void *blob,
 			nodeoffset = fdt_node_offset_by_compat_reg(blob,
 						compat, pcie_rc->dbi_res.start);
 #endif
-		if (nodeoffset < 0)
-			return;
 	}
 
+	return nodeoffset;
+}
+
+/*
+ * 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_ls(void *blob,
+					    struct ls_pcie_rc *pcie_rc,
+					    u32 devid, u32 streamid)
+{
+	u32 *prop;
+	u32 iommu_map[4];
+	int nodeoffset;
+	int lenp;
+	struct ls_pcie *pcie = pcie_rc->pcie;
+
+	nodeoffset = fdt_pcie_get_nodeoffset(blob, pcie_rc);
+	if (nodeoffset < 0)
+		return;
+
 	/* get phandle to iommu controller */
 	prop = fdt_getprop_w(blob, nodeoffset, "iommu-map", &lenp);
 	if (prop == NULL) {
@@ -232,28 +241,11 @@ static void fdt_fixup_pcie_ls(void *blob)
 static void ft_pcie_rc_fix(void *blob, struct ls_pcie_rc *pcie_rc)
 {
 	int off;
-	uint svr;
-	char *compat = NULL;
 	struct ls_pcie *pcie = pcie_rc->pcie;
 
-	off = fdt_node_offset_by_compat_reg(blob, "fsl,ls-pcie",
-					    pcie_rc->dbi_res.start);
-	if (off < 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)
-			off = fdt_node_offset_by_compat_reg(blob,
-					compat, pcie_rc->dbi_res.start);
-#endif
-		if (off < 0)
-			return;
-	}
+	off = fdt_pcie_get_nodeoffset(blob, pcie_rc);
+	if (off < 0)
+		return;
 
 	if (pcie_rc->enabled && pcie->mode == PCI_HEADER_TYPE_BRIDGE)
 		fdt_set_node_status(blob, off, FDT_STATUS_OKAY, 0);
-- 
2.17.1



More information about the U-Boot mailing list