Skip to contentSkip to conversation

Unify pci/pcie initialization code

PATCH Superseded Jia Hongtao 2 participants 4 messages Oct 28, 2011 – Oct 31, 2011

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Unify pci/pcie initialization code

In previous version pci/pcie initialization is in platform code which Initialize PCI bridge base on EP/RC or host/agent settings. We unified pci/pcie initialization as common APIs named fsl_pci_setup which can be called by platform code.

---
We only changed MPC85xxDS board as an example.
If no problem in the review we will change other boards also.

 arch/powerpc/platforms/85xx/mpc85xx_ds.c |   30 ++-----------------
 arch/powerpc/sysdev/fsl_pci.c            |   48 ++++++++++++++++++++++++++++++
 arch/powerpc/sysdev/fsl_pci.h            |    5 +++
 3 files changed, 56 insertions(+), 27 deletions(-)
arch/powerpc/platforms/85xx/mpc85xx_ds.c +3 -27
index 10e7db0..7188c0b 100644
@@ -157,33 +157,12 @@ extern void __init mpc85xx_smp_init(void);
 #endif
 static void __init mpc85xx_ds_setup_arch(void)
 {
-#ifdef CONFIG_PCI
-	struct device_node *np;
-	struct pci_controller *hose;
-#endif
-	dma_addr_t max = 0xffffffff;
-
 	if (ppc_md.progress)
 		ppc_md.progress("mpc85xx_ds_setup_arch()", 0);
 
-#ifdef CONFIG_PCI
-	for_each_node_by_type(np, "pci") {
-		if (of_device_is_compatible(np, "fsl,mpc8540-pci") ||
-		    of_device_is_compatible(np, "fsl,mpc8548-pcie") ||
-		    of_device_is_compatible(np, "fsl,p2020-pcie")) {
-			struct resource rsrc;
-			of_address_to_resource(np, 0, &rsrc);
-			if ((rsrc.start & 0xfffff) == primary_phb_addr)
-				fsl_add_bridge(np, 1);
-			else
-				fsl_add_bridge(np, 0);
-
-			hose = pci_find_hose_for_OF_device(np);
-			max = min(max, hose->dma_window_base_cur +
-					hose->dma_window_size);
-		}
-	}
+	fsl_pci_setup(primary_phb_addr);
 
+#ifdef CONFIG_PCI
 	ppc_md.pci_exclude_device = mpc85xx_exclude_device;
 #endif
 
@@ -192,11 +171,8 @@ static void __init mpc85xx_ds_setup_arch(void)
 #endif
 
 #ifdef CONFIG_SWIOTLB
-	if (memblock_end_of_DRAM() > max) {
+	if (memblock_end_of_DRAM() > 0xffffffff)
 		ppc_swiotlb_enable = 1;
-		set_pci_dma_ops(&swiotlb_dma_ops);
-		ppc_md.pci_dma_dev_setup = pci_dma_dev_setup_swiotlb;
-	}
 #endif
 
 	printk("MPC85xx DS board from Freescale Semiconductor\n");
arch/powerpc/sysdev/fsl_pci.c +48 -0

54 lines not on this page · raw message

arch/powerpc/sysdev/fsl_pci.h +5 -0
index a39ed5c..775ea21 100644
@@ -89,6 +89,11 @@ struct ccsr_pci {
 };
 
 extern int fsl_add_bridge(struct device_node *dev, int is_primary);
+#ifndef CONFIG_PCI
+#define fsl_pci_setup(p)
+#else
+extern void fsl_pci_setup(int primary_phb_addr);
+#endif
 extern void fsl_pcibios_fixup_bus(struct pci_bus *bus);
 extern int mpc83xx_add_bridge(struct device_node *dev);
 u64 fsl_pci_immrbar_base(struct pci_controller *hose);
Signature · 1 line
1.7.5.1
#1 lore raw

PATCH 2/2 powerpc/fsl-pci: Only scan PCI bus if configured as a host

If we're an agent/end-point or fsl_add_bridge doesn't succeed due to some resource failure we should not scan the PCI bus. We change fsl_add_bridge() to return -ENODEV in the case we're an agent/end-point.

---
 arch/powerpc/sysdev/fsl_pci.c |   17 ++++++++++-------
 1 files changed, 10 insertions(+), 7 deletions(-)
arch/powerpc/sysdev/fsl_pci.c +10 -7
index 4d4536f..caa7801 100644
@@ -370,7 +370,7 @@ int __init fsl_add_bridge(struct device_node *dev, int is_primary)
 			iounmap(hose->cfg_data);
 		iounmap(hose->cfg_addr);
 		pcibios_free_controller(hose);
-		return 0;
+		return -ENODEV;
 	}
 
 	setup_pci_cmd(hose);
@@ -418,6 +418,7 @@ void fsl_pci_setup(int primary_phb_addr)
 {
 	struct device_node *np;
 	struct pci_controller *hose;
+	int ret;
 	dma_addr_t min_dma_addr = 0xffffffff;
 
 	for_each_node_by_type(np, "pci") {
@@ -425,14 +426,16 @@ void fsl_pci_setup(int primary_phb_addr)
 			struct resource rsrc;
 			of_address_to_resource(np, 0, &rsrc);
 			if ((rsrc.start & 0xfffff) == primary_phb_addr)
-				fsl_add_bridge(np, 1);
+				ret = fsl_add_bridge(np, 1);
 			else
-				fsl_add_bridge(np, 0);
+				ret = fsl_add_bridge(np, 0);
 
-			hose = pci_find_hose_for_OF_device(np);
-			min_dma_addr = min(min_dma_addr,
-					hose->dma_window_base_cur
-					+ hose->dma_window_size);
+			if (ret == 0) {
+				hose = pci_find_hose_for_OF_device(np);
+				min_dma_addr = min(min_dma_addr,
+						hose->dma_window_base_cur
+						+ hose->dma_window_size);
+			}
 
 		}
 	}
Signature · 1 line
1.7.5.1
#2 lore raw

Re: [PATCH 2/2] powerpc/fsl-pci: Only scan PCI bus if configured as a host

Quoted 1 line · Jia Hongtao

If we're an agent/end-point or fsl_add_bridge doesn't succeed due to =

some

Quoted 1 line

resource failure we should not scan the PCI bus. We change =

fsl_add_bridge()

=

Quoted 9 lines

to return -ENODEV in the case we're an agent/end-point. =20

---
arch/powerpc/sysdev/fsl_pci.c | 17 ++++++++++-------

1 files changed, 10 insertions(+), 7 deletions(-)

=20

= renamed from arch/powerpc/sysdev/fsl_pci.c +0 -0

b/arch/powerpc/sysdev/fsl_pci.c

arch/powerpc/sysdev/fsl_pci.c int __init fsl_add_bridge(struct device_node *dev, =

Quoted 4 lines

index 4d4536f..caa7801 100644

arch/powerpc/sysdev/fsl_pci.c +0 -0
@@ -370,7 +370,7 @@ int __init fsl_add_bridge(struct device_node *dev, =

int is_primary)

Quoted 17 lines
arch/powerpc/sysdev/fsl_pci.c +1 -1
 			iounmap(hose->cfg_data);
 		iounmap(hose->cfg_addr);
 		pcibios_free_controller(hose);
-		return 0;
+		return -ENODEV;
 	}

=20

	setup_pci_cmd(hose);
arch/powerpc/sysdev/fsl_pci.c +1 -0
@@ -418,6 +418,7 @@ void fsl_pci_setup(int primary_phb_addr)
 {
 	struct device_node *np;
 	struct pci_controller *hose;
+	int ret;
 	dma_addr_t min_dma_addr =3D 0xffffffff;

=20

	for_each_node_by_type(np, "pci") {

arch/powerpc/sysdev/fsl_pci.c void fsl_pci_setup(int primary_phb_addr) · line 428

Quoted 3 lines
arch/powerpc/sysdev/fsl_pci.c +0 -0
@@ -425,14 +426,16 @@ void fsl_pci_setup(int primary_phb_addr)
 			struct resource rsrc;
 			of_address_to_resource(np, 0, &rsrc);
 			if ((rsrc.start & 0xfffff) =3D=3D =

primary_phb_addr)

arch/powerpc/sysdev/fsl_pci.c

Quoted 12 lines
arch/powerpc/sysdev/fsl_pci.c +2 -2
-				fsl_add_bridge(np, 1);
+				ret =3D fsl_add_bridge(np, 1);
 			else
-				fsl_add_bridge(np, 0);
+				ret =3D fsl_add_bridge(np, 0);

=20

arch/powerpc/sysdev/fsl_pci.c +2 -4
-			hose =3D pci_find_hose_for_OF_device(np);
-			min_dma_addr =3D min(min_dma_addr,
-					hose->dma_window_base_cur
-					+ hose->dma_window_size);
+			if (ret =3D=3D 0) {
+				hose =3D =

pci_find_hose_for_OF_device(np);

arch/powerpc/sysdev/fsl_pci.c

Quoted 2 lines
arch/powerpc/sysdev/fsl_pci.c +2 -0
+				min_dma_addr =3D min(min_dma_addr,
+						=

hose->dma_window_base_cur

arch/powerpc/sysdev/fsl_pci.c

Quoted 1 line
arch/powerpc/sysdev/fsl_pci.c +1 -0
+						+ =

hose->dma_window_size);

Quoted 4 lines
arch/powerpc/sysdev/fsl_pci.c +1 -0
+			}

=20

		}
	}

In the failure case (i.e. when ret !=3D 0), what about the following = code:

+#ifdef CONFIG_SWIOTLB
+ /*
+ * if we couldn't map all of DRAM via the dma windows we need =
SWIOTLB
+ * to handle buffers located outside of dma capable memory =
region
+ */
+ if (memblock_end_of_DRAM() > min_dma_addr) {
+ ppc_swiotlb_enable =3D 1;
+ set_pci_dma_ops(&swiotlb_dma_ops);
+ ppc_md.pci_dma_dev_setup =3D pci_dma_dev_setup_swiotlb;
+ }
+#endif

This should get updated to be:

	if ((ret =3D=3D 0) && (memblock_end_of_DRAM() > min_dma_arr)) {
#3 lore raw

RE: [PATCH 2/2] powerpc/fsl-pci: Only scan PCI bus if configured as a host

-----Original Message-----
From: [email protected] [mailto:= [email protected]] On Behalf Of = Kumar Gala
Sent: Friday, October 28, 2011 9:10 PM
To: Jia Hongtao-B38951
Cc: Gala Kumar-B11780; [email protected]
Subject: Re: [PATCH 2/2] powerpc/fsl-pci: Only scan PCI bus if configured a= s a host

arch/powerpc/sysdev/fsl_pci.c int __init fsl_add_bridge(struct device_node *dev, in=

Quoted 15 lines · Jia Hongtao

If we're an agent/end-point or fsl_add_bridge doesn't succeed due to=20 some resource failure we should not scan the PCI bus. We change=20 fsl_add_bridge() to return -ENODEV in the case we're an agent/end-point. =20

---
arch/powerpc/sysdev/fsl_pci.c | 17 ++++++++++-------

1 files changed, 10 insertions(+), 7 deletions(-)

=20

(quoted diff) +0 -0

b/arch/powerpc/sysdev/fsl_pci.c index 4d4536f..caa7801 100644

arch/powerpc/sysdev/fsl_pci.c +0 -0
@@ -370,7 +370,7 @@ int __init fsl_add_bridge(struct device_node *dev, in=

t is_primary)

Quoted 36 lines
arch/powerpc/sysdev/fsl_pci.c +1 -1
 			iounmap(hose->cfg_data);
 		iounmap(hose->cfg_addr);
 		pcibios_free_controller(hose);
-		return 0;
+		return -ENODEV;
 	}

=20

	setup_pci_cmd(hose);
arch/powerpc/sysdev/fsl_pci.c +1 -0
@@ -418,6 +418,7 @@ void fsl_pci_setup(int primary_phb_addr) {
 	struct device_node *np;
 	struct pci_controller *hose;
+	int ret;
 	dma_addr_t min_dma_addr =3D 0xffffffff;

=20

	for_each_node_by_type(np, "pci") {
arch/powerpc/sysdev/fsl_pci.c +2 -2
@@ -425,14 +426,16 @@ void fsl_pci_setup(int primary_phb_addr)
 			struct resource rsrc;
 			of_address_to_resource(np, 0, &rsrc);
 			if ((rsrc.start & 0xfffff) =3D=3D primary_phb_addr)
-				fsl_add_bridge(np, 1);
+				ret =3D fsl_add_bridge(np, 1);
 			else
-				fsl_add_bridge(np, 0);
+				ret =3D fsl_add_bridge(np, 0);

=20

arch/powerpc/sysdev/fsl_pci.c +6 -4
-			hose =3D pci_find_hose_for_OF_device(np);
-			min_dma_addr =3D min(min_dma_addr,
-					hose->dma_window_base_cur
-					+ hose->dma_window_size);
+			if (ret =3D=3D 0) {
+				hose =3D pci_find_hose_for_OF_device(np);
+				min_dma_addr =3D min(min_dma_addr,
+						hose->dma_window_base_cur
+						+ hose->dma_window_size);
+			}

=20

Quoted 2 lines
		}
	}

In the failure case (i.e. when ret !=3D 0), what about the following code:

+#ifdef CONFIG_SWIOTLB
+ /*
+ * if we couldn't map all of DRAM via the dma windows we need SWIOTLB
+ * to handle buffers located outside of dma capable memory region
+ */
+ if (memblock_end_of_DRAM() > min_dma_addr) {
+ ppc_swiotlb_enable =3D 1;
+ set_pci_dma_ops(&swiotlb_dma_ops);
+ ppc_md.pci_dma_dev_setup =3D pci_dma_dev_setup_swiotlb;
+ }
+#endif

This should get updated to be:

	if ((ret =3D=3D 0) && (memblock_end_of_DRAM() > min_dma_arr)) {

[Jia Hongtao-B38951] A board could have more than one pci controllers, so t= his update is not right for it only checked the last one. I will submit ano= ther patch to solve this issue.

_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://lists.ozlabs.org/listinfo/linuxppc-dev