xref: /openbmc/u-boot/drivers/pci/fsl_pci_init.c (revision b71d9e8b)
183d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
293a686eeSJean-Christophe PLAGNIOL-VILLARD /*
3505f3e6fSMinghuan Lian  * Copyright 2007-2012 Freescale Semiconductor, Inc.
493a686eeSJean-Christophe PLAGNIOL-VILLARD  */
593a686eeSJean-Christophe PLAGNIOL-VILLARD 
693a686eeSJean-Christophe PLAGNIOL-VILLARD #include <common.h>
7a4aafcc9SKumar Gala #include <malloc.h>
8a4aafcc9SKumar Gala #include <asm/fsl_serdes.h>
993a686eeSJean-Christophe PLAGNIOL-VILLARD 
10b9a1fa97SKumar Gala DECLARE_GLOBAL_DATA_PTR;
11b9a1fa97SKumar Gala 
1293a686eeSJean-Christophe PLAGNIOL-VILLARD /*
1393a686eeSJean-Christophe PLAGNIOL-VILLARD  * PCI/PCIE Controller initialization for mpc85xx/mpc86xx soc's
1493a686eeSJean-Christophe PLAGNIOL-VILLARD  *
1593a686eeSJean-Christophe PLAGNIOL-VILLARD  * Initialize controller and call the common driver/pci pci_hose_scan to
1693a686eeSJean-Christophe PLAGNIOL-VILLARD  * scan for bridges and devices.
1793a686eeSJean-Christophe PLAGNIOL-VILLARD  *
1893a686eeSJean-Christophe PLAGNIOL-VILLARD  * Hose fields which need to be pre-initialized by board specific code:
1993a686eeSJean-Christophe PLAGNIOL-VILLARD  *   regions[]
2093a686eeSJean-Christophe PLAGNIOL-VILLARD  *   first_busno
2193a686eeSJean-Christophe PLAGNIOL-VILLARD  *
2293a686eeSJean-Christophe PLAGNIOL-VILLARD  * Fields updated:
2393a686eeSJean-Christophe PLAGNIOL-VILLARD  *   last_busno
2493a686eeSJean-Christophe PLAGNIOL-VILLARD  */
2593a686eeSJean-Christophe PLAGNIOL-VILLARD 
2693a686eeSJean-Christophe PLAGNIOL-VILLARD #include <pci.h>
27ad19e7a5SKumar Gala #include <asm/io.h>
28c8514622SKumar Gala #include <asm/fsl_pci.h>
2993a686eeSJean-Christophe PLAGNIOL-VILLARD 
30b9a1fa97SKumar Gala #ifndef CONFIG_SYS_PCI_MEMORY_BUS
31b9a1fa97SKumar Gala #define CONFIG_SYS_PCI_MEMORY_BUS 0
32b9a1fa97SKumar Gala #endif
33b9a1fa97SKumar Gala 
34b9a1fa97SKumar Gala #ifndef CONFIG_SYS_PCI_MEMORY_PHYS
35b9a1fa97SKumar Gala #define CONFIG_SYS_PCI_MEMORY_PHYS 0
36b9a1fa97SKumar Gala #endif
37b9a1fa97SKumar Gala 
38b9a1fa97SKumar Gala #if defined(CONFIG_SYS_PCI_64BIT) && !defined(CONFIG_SYS_PCI64_MEMORY_BUS)
39b9a1fa97SKumar Gala #define CONFIG_SYS_PCI64_MEMORY_BUS (64ull*1024*1024*1024)
40b9a1fa97SKumar Gala #endif
41b9a1fa97SKumar Gala 
42ad19e7a5SKumar Gala /* Setup one inbound ATMU window.
43ad19e7a5SKumar Gala  *
44ad19e7a5SKumar Gala  * We let the caller decide what the window size should be
45ad19e7a5SKumar Gala  */
set_inbound_window(volatile pit_t * pi,struct pci_region * r,u64 size)46ad19e7a5SKumar Gala static void set_inbound_window(volatile pit_t *pi,
47ad19e7a5SKumar Gala 				struct pci_region *r,
48ad19e7a5SKumar Gala 				u64 size)
49b9a1fa97SKumar Gala {
50ad19e7a5SKumar Gala 	u32 sz = (__ilog2_u64(size) - 1);
51f1a96ec1SChunhe Lan #ifdef CONFIG_SYS_FSL_ERRATUM_A005434
52f1a96ec1SChunhe Lan 	u32 flag = 0;
53f1a96ec1SChunhe Lan #else
54f1a96ec1SChunhe Lan 	u32 flag = PIWAR_LOCAL;
55f1a96ec1SChunhe Lan #endif
56f1a96ec1SChunhe Lan 
57f1a96ec1SChunhe Lan 	flag |= PIWAR_EN | PIWAR_READ_SNOOP | PIWAR_WRITE_SNOOP;
58ad19e7a5SKumar Gala 
59ad19e7a5SKumar Gala 	out_be32(&pi->pitar, r->phys_start >> 12);
60ad19e7a5SKumar Gala 	out_be32(&pi->piwbar, r->bus_start >> 12);
61ad19e7a5SKumar Gala #ifdef CONFIG_SYS_PCI_64BIT
62ad19e7a5SKumar Gala 	out_be32(&pi->piwbear, r->bus_start >> 44);
63ad19e7a5SKumar Gala #else
64ad19e7a5SKumar Gala 	out_be32(&pi->piwbear, 0);
65ad19e7a5SKumar Gala #endif
66ad19e7a5SKumar Gala 	if (r->flags & PCI_REGION_PREFETCH)
67ad19e7a5SKumar Gala 		flag |= PIWAR_PF;
68ad19e7a5SKumar Gala 	out_be32(&pi->piwar, flag | sz);
69ad19e7a5SKumar Gala }
70ad19e7a5SKumar Gala 
fsl_setup_hose(struct pci_controller * hose,unsigned long addr)71ee53650dSKumar Gala int fsl_setup_hose(struct pci_controller *hose, unsigned long addr)
72ee53650dSKumar Gala {
73ee53650dSKumar Gala 	volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) addr;
74ee53650dSKumar Gala 
7596d61603SJohn Schmoller 	/* Reset hose to make sure its in a clean state */
7696d61603SJohn Schmoller 	memset(hose, 0, sizeof(struct pci_controller));
7796d61603SJohn Schmoller 
78ee53650dSKumar Gala 	pci_setup_indirect(hose, (u32)&pci->cfg_addr, (u32)&pci->cfg_data);
79ee53650dSKumar Gala 
80ee53650dSKumar Gala 	return fsl_is_pci_agent(hose);
81ee53650dSKumar Gala }
82ee53650dSKumar Gala 
fsl_pci_setup_inbound_windows(struct pci_controller * hose,u64 out_lo,u8 pcie_cap,volatile pit_t * pi)83ad19e7a5SKumar Gala static int fsl_pci_setup_inbound_windows(struct pci_controller *hose,
84ad19e7a5SKumar Gala 					 u64 out_lo, u8 pcie_cap,
85ad19e7a5SKumar Gala 					 volatile pit_t *pi)
86ad19e7a5SKumar Gala {
87ad19e7a5SKumar Gala 	struct pci_region *r = hose->regions + hose->region_count;
88ad19e7a5SKumar Gala 	u64 sz = min((u64)gd->ram_size, (1ull << 32));
89b9a1fa97SKumar Gala 
90b9a1fa97SKumar Gala 	phys_addr_t phys_start = CONFIG_SYS_PCI_MEMORY_PHYS;
91b9a1fa97SKumar Gala 	pci_addr_t bus_start = CONFIG_SYS_PCI_MEMORY_BUS;
92ad19e7a5SKumar Gala 	pci_size_t pci_sz;
93b9a1fa97SKumar Gala 
94ad19e7a5SKumar Gala 	/* we have no space available for inbound memory mapping */
95ad19e7a5SKumar Gala 	if (bus_start > out_lo) {
96ad19e7a5SKumar Gala 		printf ("no space for inbound mapping of memory\n");
97ad19e7a5SKumar Gala 		return 0;
98ad19e7a5SKumar Gala 	}
99ad19e7a5SKumar Gala 
100ad19e7a5SKumar Gala 	/* limit size */
101ad19e7a5SKumar Gala 	if ((bus_start + sz) > out_lo) {
102ad19e7a5SKumar Gala 		sz = out_lo - bus_start;
103ad19e7a5SKumar Gala 		debug ("limiting size to %llx\n", sz);
104ad19e7a5SKumar Gala 	}
105ad19e7a5SKumar Gala 
106ad19e7a5SKumar Gala 	pci_sz = 1ull << __ilog2_u64(sz);
107ad19e7a5SKumar Gala 	/*
108ad19e7a5SKumar Gala 	 * we can overlap inbound/outbound windows on PCI-E since RX & TX
109ad19e7a5SKumar Gala 	 * links a separate
110ad19e7a5SKumar Gala 	 */
111ad19e7a5SKumar Gala 	if ((pcie_cap == PCI_CAP_ID_EXP) && (pci_sz < sz)) {
112b9a1fa97SKumar Gala 		debug ("R0 bus_start: %llx phys_start: %llx size: %llx\n",
113ad19e7a5SKumar Gala 			(u64)bus_start, (u64)phys_start, (u64)sz);
114ad19e7a5SKumar Gala 		pci_set_region(r, bus_start, phys_start, sz,
115ff4e66e9SKumar Gala 				PCI_REGION_MEM | PCI_REGION_SYS_MEMORY |
116b9a1fa97SKumar Gala 				PCI_REGION_PREFETCH);
117b9a1fa97SKumar Gala 
118ad19e7a5SKumar Gala 		/* if we aren't an exact power of two match, pci_sz is smaller
119ad19e7a5SKumar Gala 		 * round it up to the next power of two.  We report the actual
120ad19e7a5SKumar Gala 		 * size to pci region tracking.
121ad19e7a5SKumar Gala 		 */
122ad19e7a5SKumar Gala 		if (pci_sz != sz)
123ad19e7a5SKumar Gala 			sz = 2ull << __ilog2_u64(sz);
124ad19e7a5SKumar Gala 
125ad19e7a5SKumar Gala 		set_inbound_window(pi--, r++, sz);
126ad19e7a5SKumar Gala 		sz = 0; /* make sure we dont set the R2 window */
127ad19e7a5SKumar Gala 	} else {
128ad19e7a5SKumar Gala 		debug ("R0 bus_start: %llx phys_start: %llx size: %llx\n",
129ad19e7a5SKumar Gala 			(u64)bus_start, (u64)phys_start, (u64)pci_sz);
130ad19e7a5SKumar Gala 		pci_set_region(r, bus_start, phys_start, pci_sz,
131ad19e7a5SKumar Gala 				PCI_REGION_MEM | PCI_REGION_SYS_MEMORY |
132ad19e7a5SKumar Gala 				PCI_REGION_PREFETCH);
133ad19e7a5SKumar Gala 		set_inbound_window(pi--, r++, pci_sz);
134ad19e7a5SKumar Gala 
135b9a1fa97SKumar Gala 		sz -= pci_sz;
136b9a1fa97SKumar Gala 		bus_start += pci_sz;
137b9a1fa97SKumar Gala 		phys_start += pci_sz;
138b9a1fa97SKumar Gala 
139b9a1fa97SKumar Gala 		pci_sz = 1ull << __ilog2_u64(sz);
140b9a1fa97SKumar Gala 		if (sz) {
141b9a1fa97SKumar Gala 			debug ("R1 bus_start: %llx phys_start: %llx size: %llx\n",
142b9a1fa97SKumar Gala 				(u64)bus_start, (u64)phys_start, (u64)pci_sz);
143ad19e7a5SKumar Gala 			pci_set_region(r, bus_start, phys_start, pci_sz,
144ff4e66e9SKumar Gala 					PCI_REGION_MEM | PCI_REGION_SYS_MEMORY |
145b9a1fa97SKumar Gala 					PCI_REGION_PREFETCH);
146ad19e7a5SKumar Gala 			set_inbound_window(pi--, r++, pci_sz);
147b9a1fa97SKumar Gala 			sz -= pci_sz;
148b9a1fa97SKumar Gala 			bus_start += pci_sz;
149b9a1fa97SKumar Gala 			phys_start += pci_sz;
150b9a1fa97SKumar Gala 		}
151ad19e7a5SKumar Gala 	}
152b9a1fa97SKumar Gala 
153b9a1fa97SKumar Gala #if defined(CONFIG_PHYS_64BIT) && defined(CONFIG_SYS_PCI_64BIT)
154cd425162SBecky Bruce 	/*
155cd425162SBecky Bruce 	 * On 64-bit capable systems, set up a mapping for all of DRAM
156cd425162SBecky Bruce 	 * in high pci address space.
157cd425162SBecky Bruce 	 */
158b9a1fa97SKumar Gala 	pci_sz = 1ull << __ilog2_u64(gd->ram_size);
159b9a1fa97SKumar Gala 	/* round up to the next largest power of two */
160b9a1fa97SKumar Gala 	if (gd->ram_size > pci_sz)
161cd425162SBecky Bruce 		pci_sz = 1ull << (__ilog2_u64(gd->ram_size) + 1);
162b9a1fa97SKumar Gala 	debug ("R64 bus_start: %llx phys_start: %llx size: %llx\n",
163cd425162SBecky Bruce 		(u64)CONFIG_SYS_PCI64_MEMORY_BUS,
164b9a1fa97SKumar Gala 		(u64)CONFIG_SYS_PCI_MEMORY_PHYS,
165b9a1fa97SKumar Gala 		(u64)pci_sz);
166ad19e7a5SKumar Gala 	pci_set_region(r,
167cd425162SBecky Bruce 			CONFIG_SYS_PCI64_MEMORY_BUS,
168b9a1fa97SKumar Gala 			CONFIG_SYS_PCI_MEMORY_PHYS,
169b9a1fa97SKumar Gala 			pci_sz,
170ff4e66e9SKumar Gala 			PCI_REGION_MEM | PCI_REGION_SYS_MEMORY |
171b9a1fa97SKumar Gala 			PCI_REGION_PREFETCH);
172ad19e7a5SKumar Gala 	set_inbound_window(pi--, r++, pci_sz);
173b9a1fa97SKumar Gala #else
174b9a1fa97SKumar Gala 	pci_sz = 1ull << __ilog2_u64(sz);
175b9a1fa97SKumar Gala 	if (sz) {
176b9a1fa97SKumar Gala 		debug ("R2 bus_start: %llx phys_start: %llx size: %llx\n",
177b9a1fa97SKumar Gala 			(u64)bus_start, (u64)phys_start, (u64)pci_sz);
178ad19e7a5SKumar Gala 		pci_set_region(r, bus_start, phys_start, pci_sz,
179ff4e66e9SKumar Gala 				PCI_REGION_MEM | PCI_REGION_SYS_MEMORY |
180b9a1fa97SKumar Gala 				PCI_REGION_PREFETCH);
181b9a1fa97SKumar Gala 		sz -= pci_sz;
182b9a1fa97SKumar Gala 		bus_start += pci_sz;
183b9a1fa97SKumar Gala 		phys_start += pci_sz;
184ad19e7a5SKumar Gala 		set_inbound_window(pi--, r++, pci_sz);
185b9a1fa97SKumar Gala 	}
186b9a1fa97SKumar Gala #endif
187b9a1fa97SKumar Gala 
1884c253fdbSKumar Gala #ifdef CONFIG_PHYS_64BIT
189b9a1fa97SKumar Gala 	if (sz && (((u64)gd->ram_size) < (1ull << 32)))
190b9a1fa97SKumar Gala 		printf("Was not able to map all of memory via "
191b9a1fa97SKumar Gala 			"inbound windows -- %lld remaining\n", sz);
1924c253fdbSKumar Gala #endif
193b9a1fa97SKumar Gala 
194ad19e7a5SKumar Gala 	hose->region_count = r - hose->regions;
195ad19e7a5SKumar Gala 
196ad19e7a5SKumar Gala 	return 1;
197b9a1fa97SKumar Gala }
198b9a1fa97SKumar Gala 
199c8b28152SLiu Gang #ifdef CONFIG_SRIO_PCIE_BOOT_MASTER
fsl_pcie_boot_master(pit_t * pi)200b5f7c873SLiu Gang static void fsl_pcie_boot_master(pit_t *pi)
201b5f7c873SLiu Gang {
202b5f7c873SLiu Gang 	/* configure inbound window for slave's u-boot image */
203b5f7c873SLiu Gang 	debug("PCIEBOOT - MASTER: Inbound window for slave's image; "
204b5f7c873SLiu Gang 			"Local = 0x%llx, Bus = 0x%llx, Size = 0x%x\n",
205b5f7c873SLiu Gang 			(u64)CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_PHYS,
206b5f7c873SLiu Gang 			(u64)CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_BUS1,
207b5f7c873SLiu Gang 			CONFIG_SRIO_PCIE_BOOT_IMAGE_SIZE);
208b5f7c873SLiu Gang 	struct pci_region r_inbound;
209b5f7c873SLiu Gang 	u32 sz_inbound = __ilog2_u64(CONFIG_SRIO_PCIE_BOOT_IMAGE_SIZE)
210b5f7c873SLiu Gang 					- 1;
211b5f7c873SLiu Gang 	pci_set_region(&r_inbound,
212b5f7c873SLiu Gang 		CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_BUS1,
213b5f7c873SLiu Gang 		CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_PHYS,
214b5f7c873SLiu Gang 		sz_inbound,
215b5f7c873SLiu Gang 		PCI_REGION_MEM | PCI_REGION_SYS_MEMORY);
216b5f7c873SLiu Gang 
217b5f7c873SLiu Gang 	set_inbound_window(pi--, &r_inbound,
218b5f7c873SLiu Gang 		CONFIG_SRIO_PCIE_BOOT_IMAGE_SIZE);
219b5f7c873SLiu Gang 
220b5f7c873SLiu Gang 	/* configure inbound window for slave's u-boot image */
221b5f7c873SLiu Gang 	debug("PCIEBOOT - MASTER: Inbound window for slave's image; "
222b5f7c873SLiu Gang 			"Local = 0x%llx, Bus = 0x%llx, Size = 0x%x\n",
223b5f7c873SLiu Gang 			(u64)CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_PHYS,
224b5f7c873SLiu Gang 			(u64)CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_BUS2,
225b5f7c873SLiu Gang 			CONFIG_SRIO_PCIE_BOOT_IMAGE_SIZE);
226b5f7c873SLiu Gang 	pci_set_region(&r_inbound,
227b5f7c873SLiu Gang 		CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_BUS2,
228b5f7c873SLiu Gang 		CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_PHYS,
229b5f7c873SLiu Gang 		sz_inbound,
230b5f7c873SLiu Gang 		PCI_REGION_MEM | PCI_REGION_SYS_MEMORY);
231b5f7c873SLiu Gang 
232b5f7c873SLiu Gang 	set_inbound_window(pi--, &r_inbound,
233b5f7c873SLiu Gang 		CONFIG_SRIO_PCIE_BOOT_IMAGE_SIZE);
234b5f7c873SLiu Gang 
235b5f7c873SLiu Gang 	/* configure inbound window for slave's ucode and ENV */
236b5f7c873SLiu Gang 	debug("PCIEBOOT - MASTER: Inbound window for slave's "
237b5f7c873SLiu Gang 			"ucode and ENV; "
238b5f7c873SLiu Gang 			"Local = 0x%llx, Bus = 0x%llx, Size = 0x%x\n",
239b5f7c873SLiu Gang 			(u64)CONFIG_SRIO_PCIE_BOOT_UCODE_ENV_MEM_PHYS,
240b5f7c873SLiu Gang 			(u64)CONFIG_SRIO_PCIE_BOOT_UCODE_ENV_MEM_BUS,
241b5f7c873SLiu Gang 			CONFIG_SRIO_PCIE_BOOT_UCODE_ENV_SIZE);
242b5f7c873SLiu Gang 	sz_inbound = __ilog2_u64(CONFIG_SRIO_PCIE_BOOT_UCODE_ENV_SIZE)
243b5f7c873SLiu Gang 				- 1;
244b5f7c873SLiu Gang 	pci_set_region(&r_inbound,
245b5f7c873SLiu Gang 		CONFIG_SRIO_PCIE_BOOT_UCODE_ENV_MEM_BUS,
246b5f7c873SLiu Gang 		CONFIG_SRIO_PCIE_BOOT_UCODE_ENV_MEM_PHYS,
247b5f7c873SLiu Gang 		sz_inbound,
248b5f7c873SLiu Gang 		PCI_REGION_MEM | PCI_REGION_SYS_MEMORY);
249b5f7c873SLiu Gang 
250b5f7c873SLiu Gang 	set_inbound_window(pi--, &r_inbound,
251b5f7c873SLiu Gang 		CONFIG_SRIO_PCIE_BOOT_UCODE_ENV_SIZE);
252b5f7c873SLiu Gang }
253b5f7c873SLiu Gang 
fsl_pcie_boot_master_release_slave(int port)254b5f7c873SLiu Gang static void fsl_pcie_boot_master_release_slave(int port)
255b5f7c873SLiu Gang {
256b5f7c873SLiu Gang 	unsigned long release_addr;
257b5f7c873SLiu Gang 
258b5f7c873SLiu Gang 	/* now release slave's core 0 */
259b5f7c873SLiu Gang 	switch (port) {
260b5f7c873SLiu Gang 	case 1:
261b5f7c873SLiu Gang 		release_addr = CONFIG_SYS_PCIE1_MEM_VIRT
262b5f7c873SLiu Gang 			+ CONFIG_SRIO_PCIE_BOOT_BRR_OFFSET;
263b5f7c873SLiu Gang 		break;
264a1e4318cSYork Sun #ifdef CONFIG_SYS_PCIE2_MEM_VIRT
265b5f7c873SLiu Gang 	case 2:
266b5f7c873SLiu Gang 		release_addr = CONFIG_SYS_PCIE2_MEM_VIRT
267b5f7c873SLiu Gang 			+ CONFIG_SRIO_PCIE_BOOT_BRR_OFFSET;
268b5f7c873SLiu Gang 		break;
269a1e4318cSYork Sun #endif
270a1e4318cSYork Sun #ifdef CONFIG_SYS_PCIE3_MEM_VIRT
271b5f7c873SLiu Gang 	case 3:
272b5f7c873SLiu Gang 		release_addr = CONFIG_SYS_PCIE3_MEM_VIRT
273b5f7c873SLiu Gang 			+ CONFIG_SRIO_PCIE_BOOT_BRR_OFFSET;
274b5f7c873SLiu Gang 		break;
275a1e4318cSYork Sun #endif
276b5f7c873SLiu Gang 	default:
277b5f7c873SLiu Gang 		release_addr = 0;
278b5f7c873SLiu Gang 		break;
279b5f7c873SLiu Gang 	}
280b5f7c873SLiu Gang 	if (release_addr != 0) {
281b5f7c873SLiu Gang 		out_be32((void *)release_addr,
282b5f7c873SLiu Gang 			CONFIG_SRIO_PCIE_BOOT_RELEASE_MASK);
283b5f7c873SLiu Gang 		debug("PCIEBOOT - MASTER: "
284b5f7c873SLiu Gang 			"Release slave successfully! Now the slave should start up!\n");
285b5f7c873SLiu Gang 	} else {
286b5f7c873SLiu Gang 		debug("PCIEBOOT - MASTER: "
287b5f7c873SLiu Gang 			"Release slave failed!\n");
288b5f7c873SLiu Gang 	}
289b5f7c873SLiu Gang }
290b5f7c873SLiu Gang #endif
291b5f7c873SLiu Gang 
fsl_pci_init(struct pci_controller * hose,struct fsl_pci_info * pci_info)292213ac73eSPeter Tyser void fsl_pci_init(struct pci_controller *hose, struct fsl_pci_info *pci_info)
29393a686eeSJean-Christophe PLAGNIOL-VILLARD {
294213ac73eSPeter Tyser 	u32 cfg_addr = (u32)&((ccsr_fsl_pci_t *)pci_info->regs)->cfg_addr;
295213ac73eSPeter Tyser 	u32 cfg_data = (u32)&((ccsr_fsl_pci_t *)pci_info->regs)->cfg_data;
29693a686eeSJean-Christophe PLAGNIOL-VILLARD 	u16 temp16;
29793a686eeSJean-Christophe PLAGNIOL-VILLARD 	u32 temp32;
298b6ccd2c9SPrabhakar Kushwaha 	u32 block_rev;
2998295b944SKumar Gala 	int enabled, r, inbound = 0;
30093a686eeSJean-Christophe PLAGNIOL-VILLARD 	u16 ltssm;
3018295b944SKumar Gala 	u8 temp8, pcie_cap;
302287df01eSZhao Qiang 	int pcie_cap_pos;
303287df01eSZhao Qiang 	int pci_dcr;
304287df01eSZhao Qiang 	int pci_dsr;
305287df01eSZhao Qiang 	int pci_lsr;
306287df01eSZhao Qiang 
307287df01eSZhao Qiang #if defined(CONFIG_FSL_PCIE_DISABLE_ASPM)
308287df01eSZhao Qiang 	int pci_lcr;
309287df01eSZhao Qiang #endif
310287df01eSZhao Qiang 
311fb3143b3SKumar Gala 	volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *)cfg_addr;
312cb151aa2SKumar Gala 	struct pci_region *reg = hose->regions + hose->region_count;
3138295b944SKumar Gala 	pci_dev_t dev = PCI_BDF(hose->first_busno, 0, 0);
31493a686eeSJean-Christophe PLAGNIOL-VILLARD 
31593a686eeSJean-Christophe PLAGNIOL-VILLARD 	/* Initialize ATMU registers based on hose regions and flags */
31693a686eeSJean-Christophe PLAGNIOL-VILLARD 	volatile pot_t *po = &pci->pot[1];	/* skip 0 */
317b6ccd2c9SPrabhakar Kushwaha 	volatile pit_t *pi;
318ad19e7a5SKumar Gala 
319ad19e7a5SKumar Gala 	u64 out_hi = 0, out_lo = -1ULL;
320ad19e7a5SKumar Gala 	u32 pcicsrbar, pcicsrbar_sz;
32193a686eeSJean-Christophe PLAGNIOL-VILLARD 
322fb3143b3SKumar Gala 	pci_setup_indirect(hose, cfg_addr, cfg_data);
323fb3143b3SKumar Gala 
324*6ce83fb3SJoakim Tjernlund #ifdef PEX_CCB_DIV
325*6ce83fb3SJoakim Tjernlund 	/* Configure the PCIE controller core clock ratio */
326*6ce83fb3SJoakim Tjernlund 	pci_hose_write_config_dword(hose, dev, 0x440,
327*6ce83fb3SJoakim Tjernlund 				    ((gd->bus_clk / 1000000) *
328*6ce83fb3SJoakim Tjernlund 				     (16 / PEX_CCB_DIV)) / 333);
329*6ce83fb3SJoakim Tjernlund #endif
330b6ccd2c9SPrabhakar Kushwaha 	block_rev = in_be32(&pci->block_rev1);
331b6ccd2c9SPrabhakar Kushwaha 	if (PEX_IP_BLK_REV_2_2 <= block_rev) {
332b6ccd2c9SPrabhakar Kushwaha 		pi = &pci->pit[2];	/* 0xDC0 */
333b6ccd2c9SPrabhakar Kushwaha 	} else {
334b6ccd2c9SPrabhakar Kushwaha 		pi = &pci->pit[3];	/* 0xDE0 */
335b6ccd2c9SPrabhakar Kushwaha 	}
336b6ccd2c9SPrabhakar Kushwaha 
337ad19e7a5SKumar Gala 	/* Handle setup of outbound windows first */
33893a686eeSJean-Christophe PLAGNIOL-VILLARD 	for (r = 0; r < hose->region_count; r++) {
339ad19e7a5SKumar Gala 		unsigned long flags = hose->regions[r].flags;
340612ea010SKumar Gala 		u32 sz = (__ilog2_u64((u64)hose->regions[r].size) - 1);
341ad19e7a5SKumar Gala 
342ad19e7a5SKumar Gala 		flags &= PCI_REGION_SYS_MEMORY|PCI_REGION_TYPE;
343ad19e7a5SKumar Gala 		if (flags != PCI_REGION_SYS_MEMORY) {
344ad19e7a5SKumar Gala 			u64 start = hose->regions[r].bus_start;
345ad19e7a5SKumar Gala 			u64 end = start + hose->regions[r].size;
346ad19e7a5SKumar Gala 
347ad19e7a5SKumar Gala 			out_be32(&po->powbar, hose->regions[r].phys_start >> 12);
348ad19e7a5SKumar Gala 			out_be32(&po->potar, start >> 12);
349612ea010SKumar Gala #ifdef CONFIG_SYS_PCI_64BIT
350ad19e7a5SKumar Gala 			out_be32(&po->potear, start >> 44);
351612ea010SKumar Gala #else
352ad19e7a5SKumar Gala 			out_be32(&po->potear, 0);
353612ea010SKumar Gala #endif
354ad19e7a5SKumar Gala 			if (hose->regions[r].flags & PCI_REGION_IO) {
355ad19e7a5SKumar Gala 				out_be32(&po->powar, POWAR_EN | sz |
356ad19e7a5SKumar Gala 					POWAR_IO_READ | POWAR_IO_WRITE);
357ad19e7a5SKumar Gala 			} else {
358ad19e7a5SKumar Gala 				out_be32(&po->powar, POWAR_EN | sz |
359ad19e7a5SKumar Gala 					POWAR_MEM_READ | POWAR_MEM_WRITE);
360ad19e7a5SKumar Gala 				out_lo = min(start, out_lo);
361ad19e7a5SKumar Gala 				out_hi = max(end, out_hi);
362ad19e7a5SKumar Gala 			}
36393a686eeSJean-Christophe PLAGNIOL-VILLARD 			po++;
36493a686eeSJean-Christophe PLAGNIOL-VILLARD 		}
36593a686eeSJean-Christophe PLAGNIOL-VILLARD 	}
366ad19e7a5SKumar Gala 	debug("Outbound memory range: %llx:%llx\n", out_lo, out_hi);
367ad19e7a5SKumar Gala 
368ad19e7a5SKumar Gala 	/* setup PCSRBAR/PEXCSRBAR */
369ad19e7a5SKumar Gala 	pci_hose_write_config_dword(hose, dev, PCI_BASE_ADDRESS_0, 0xffffffff);
370ad19e7a5SKumar Gala 	pci_hose_read_config_dword (hose, dev, PCI_BASE_ADDRESS_0, &pcicsrbar_sz);
371ad19e7a5SKumar Gala 	pcicsrbar_sz = ~pcicsrbar_sz + 1;
372ad19e7a5SKumar Gala 
373ad19e7a5SKumar Gala 	if (out_hi < (0x100000000ull - pcicsrbar_sz) ||
374ad19e7a5SKumar Gala 		(out_lo > 0x100000000ull))
375ad19e7a5SKumar Gala 		pcicsrbar = 0x100000000ull - pcicsrbar_sz;
376ad19e7a5SKumar Gala 	else
377ad19e7a5SKumar Gala 		pcicsrbar = (out_lo - pcicsrbar_sz) & -pcicsrbar_sz;
378ad19e7a5SKumar Gala 	pci_hose_write_config_dword(hose, dev, PCI_BASE_ADDRESS_0, pcicsrbar);
379ad19e7a5SKumar Gala 
380ad19e7a5SKumar Gala 	out_lo = min(out_lo, (u64)pcicsrbar);
381ad19e7a5SKumar Gala 
382ad19e7a5SKumar Gala 	debug("PCICSRBAR @ 0x%x\n", pcicsrbar);
383ad19e7a5SKumar Gala 
384ad19e7a5SKumar Gala 	pci_set_region(reg++, pcicsrbar, CONFIG_SYS_CCSRBAR_PHYS,
385ad19e7a5SKumar Gala 			pcicsrbar_sz, PCI_REGION_SYS_MEMORY);
386ad19e7a5SKumar Gala 	hose->region_count++;
38793a686eeSJean-Christophe PLAGNIOL-VILLARD 
3888295b944SKumar Gala 	/* see if we are a PCIe or PCI controller */
389287df01eSZhao Qiang 	pcie_cap_pos = pci_hose_find_capability(hose, dev, PCI_CAP_ID_EXP);
390287df01eSZhao Qiang 	pci_dcr = pcie_cap_pos + 0x08;
391287df01eSZhao Qiang 	pci_dsr = pcie_cap_pos + 0x0a;
392287df01eSZhao Qiang 	pci_lsr = pcie_cap_pos + 0x12;
393287df01eSZhao Qiang 
394287df01eSZhao Qiang 	pci_hose_read_config_byte(hose, dev, pcie_cap_pos, &pcie_cap);
3958295b944SKumar Gala 
396c8b28152SLiu Gang #ifdef CONFIG_SRIO_PCIE_BOOT_MASTER
397b5f7c873SLiu Gang 	/* boot from PCIE --master */
39800caae6dSSimon Glass 	char *s = env_get("bootmaster");
399b5f7c873SLiu Gang 	char pcie[6];
400b5f7c873SLiu Gang 	sprintf(pcie, "PCIE%d", pci_info->pci_num);
401b5f7c873SLiu Gang 
402b5f7c873SLiu Gang 	if (s && (strcmp(s, pcie) == 0)) {
403b5f7c873SLiu Gang 		debug("PCIEBOOT - MASTER: Master port [ %d ] for pcie boot.\n",
404b5f7c873SLiu Gang 				pci_info->pci_num);
405b5f7c873SLiu Gang 		fsl_pcie_boot_master((pit_t *)pi);
406b5f7c873SLiu Gang 	} else {
407b5f7c873SLiu Gang 		/* inbound */
408b5f7c873SLiu Gang 		inbound = fsl_pci_setup_inbound_windows(hose,
409b5f7c873SLiu Gang 					out_lo, pcie_cap, pi);
410b5f7c873SLiu Gang 	}
411b5f7c873SLiu Gang #else
412ad19e7a5SKumar Gala 	/* inbound */
413ad19e7a5SKumar Gala 	inbound = fsl_pci_setup_inbound_windows(hose, out_lo, pcie_cap, pi);
414b5f7c873SLiu Gang #endif
415ad19e7a5SKumar Gala 
416ad19e7a5SKumar Gala 	for (r = 0; r < hose->region_count; r++)
417d015df8fSMarek Vasut 		debug("PCI reg:%d %016llx:%016llx %016llx %08lx\n", r,
418ad19e7a5SKumar Gala 			(u64)hose->regions[r].phys_start,
419d015df8fSMarek Vasut 			(u64)hose->regions[r].bus_start,
420d015df8fSMarek Vasut 			(u64)hose->regions[r].size,
421ad19e7a5SKumar Gala 			hose->regions[r].flags);
422ad19e7a5SKumar Gala 
42393a686eeSJean-Christophe PLAGNIOL-VILLARD 	pci_register_hose(hose);
42493a686eeSJean-Christophe PLAGNIOL-VILLARD 	pciauto_config_init(hose);	/* grab pci_{mem,prefetch,io} */
42593a686eeSJean-Christophe PLAGNIOL-VILLARD 	hose->current_busno = hose->first_busno;
42693a686eeSJean-Christophe PLAGNIOL-VILLARD 
427ad19e7a5SKumar Gala 	out_be32(&pci->pedr, 0xffffffff);	/* Clear any errors */
42816263087SMike Williams 	out_be32(&pci->peer, ~0x20140);	/* Enable All Error Interrupts except
42993a686eeSJean-Christophe PLAGNIOL-VILLARD 					 * - Master abort (pci)
43093a686eeSJean-Christophe PLAGNIOL-VILLARD 					 * - Master PERR (pci)
43193a686eeSJean-Christophe PLAGNIOL-VILLARD 					 * - ICCA (PCIe)
43293a686eeSJean-Christophe PLAGNIOL-VILLARD 					 */
433287df01eSZhao Qiang 	pci_hose_read_config_dword(hose, dev, pci_dcr, &temp32);
43493a686eeSJean-Christophe PLAGNIOL-VILLARD 	temp32 |= 0xf000e;		/* set URR, FER, NFER (but not CER) */
435287df01eSZhao Qiang 	pci_hose_write_config_dword(hose, dev, pci_dcr, temp32);
43693a686eeSJean-Christophe PLAGNIOL-VILLARD 
437b03a466dSPrabhakar Kushwaha #if defined(CONFIG_FSL_PCIE_DISABLE_ASPM)
438287df01eSZhao Qiang 	pci_lcr = pcie_cap_pos + 0x10;
439b03a466dSPrabhakar Kushwaha 	temp32 = 0;
440287df01eSZhao Qiang 	pci_hose_read_config_dword(hose, dev, pci_lcr, &temp32);
441b03a466dSPrabhakar Kushwaha 	temp32 &= ~0x03;		/* Disable ASPM  */
442287df01eSZhao Qiang 	pci_hose_write_config_dword(hose, dev, pci_lcr, temp32);
443b03a466dSPrabhakar Kushwaha 	udelay(1);
444b03a466dSPrabhakar Kushwaha #endif
4458295b944SKumar Gala 	if (pcie_cap == PCI_CAP_ID_EXP) {
4467b4e5844SZang Roy-R61911 		if (block_rev >= PEX_IP_BLK_REV_3_0) {
4477b4e5844SZang Roy-R61911 #define PEX_CSR0_LTSSM_MASK	0xFC
4487b4e5844SZang Roy-R61911 #define PEX_CSR0_LTSSM_SHIFT	2
4497b4e5844SZang Roy-R61911 			ltssm = (in_be32(&pci->pex_csr0)
4507b4e5844SZang Roy-R61911 				& PEX_CSR0_LTSSM_MASK) >> PEX_CSR0_LTSSM_SHIFT;
4517b4e5844SZang Roy-R61911 			enabled = (ltssm == 0x11) ? 1 : 0;
4525066e628SZhao Qiang #ifdef CONFIG_FSL_PCIE_RESET
4535066e628SZhao Qiang 			int i;
4545066e628SZhao Qiang 			/* assert PCIe reset */
4555066e628SZhao Qiang 			setbits_be32(&pci->pdb_stat, 0x08000000);
4565066e628SZhao Qiang 			(void) in_be32(&pci->pdb_stat);
4575066e628SZhao Qiang 			udelay(1000);
4585066e628SZhao Qiang 			/* clear PCIe reset */
4595066e628SZhao Qiang 			clrbits_be32(&pci->pdb_stat, 0x08000000);
4605066e628SZhao Qiang 			asm("sync;isync");
4615066e628SZhao Qiang 			for (i = 0; i < 100 && ltssm < PCI_LTSSM_L0; i++) {
4625066e628SZhao Qiang 				pci_hose_read_config_word(hose, dev, PCI_LTSSM,
4635066e628SZhao Qiang 							  &ltssm);
4645066e628SZhao Qiang 				udelay(1000);
4655066e628SZhao Qiang 			}
4665066e628SZhao Qiang #endif
4677b4e5844SZang Roy-R61911 		} else {
4687b4e5844SZang Roy-R61911 		/* pci_hose_read_config_word(hose, dev, PCI_LTSSM, &ltssm); */
4697b4e5844SZang Roy-R61911 		/* enabled = ltssm >= PCI_LTSSM_L0; */
47093a686eeSJean-Christophe PLAGNIOL-VILLARD 		pci_hose_read_config_word(hose, dev, PCI_LTSSM, &ltssm);
47193a686eeSJean-Christophe PLAGNIOL-VILLARD 		enabled = ltssm >= PCI_LTSSM_L0;
47293a686eeSJean-Christophe PLAGNIOL-VILLARD 
4738ff3de61SKumar Gala #ifdef CONFIG_FSL_PCIE_RESET
4748ff3de61SKumar Gala 		if (ltssm == 1) {
4758ff3de61SKumar Gala 			int i;
476ad19e7a5SKumar Gala 			debug("....PCIe link error. " "LTSSM=0x%02x.", ltssm);
477ad19e7a5SKumar Gala 			/* assert PCIe reset */
478ad19e7a5SKumar Gala 			setbits_be32(&pci->pdb_stat, 0x08000000);
479ad19e7a5SKumar Gala 			(void) in_be32(&pci->pdb_stat);
4808ff3de61SKumar Gala 			udelay(100);
481d015df8fSMarek Vasut 			debug("  Asserting PCIe reset @%p = %x\n",
482ad19e7a5SKumar Gala 			      &pci->pdb_stat, in_be32(&pci->pdb_stat));
483ad19e7a5SKumar Gala 			/* clear PCIe reset */
484ad19e7a5SKumar Gala 			clrbits_be32(&pci->pdb_stat, 0x08000000);
4858ff3de61SKumar Gala 			asm("sync;isync");
4868ff3de61SKumar Gala 			for (i=0; i<100 && ltssm < PCI_LTSSM_L0; i++) {
4878ff3de61SKumar Gala 				pci_hose_read_config_word(hose, dev, PCI_LTSSM,
4888ff3de61SKumar Gala 							&ltssm);
4898ff3de61SKumar Gala 				udelay(1000);
4908ff3de61SKumar Gala 				debug("....PCIe link error. "
4918ff3de61SKumar Gala 				      "LTSSM=0x%02x.\n", ltssm);
4928ff3de61SKumar Gala 			}
4938ff3de61SKumar Gala 			enabled = ltssm >= PCI_LTSSM_L0;
494ad19e7a5SKumar Gala 
495ad19e7a5SKumar Gala 			/* we need to re-write the bar0 since a reset will
496ad19e7a5SKumar Gala 			 * clear it
497ad19e7a5SKumar Gala 			 */
498ad19e7a5SKumar Gala 			pci_hose_write_config_dword(hose, dev,
499ad19e7a5SKumar Gala 					PCI_BASE_ADDRESS_0, pcicsrbar);
5008ff3de61SKumar Gala 		}
5018ff3de61SKumar Gala #endif
5027b4e5844SZang Roy-R61911 	}
5038ff3de61SKumar Gala 
504c0a4e6b8SYuanquan Chen #ifdef CONFIG_SYS_P4080_ERRATUM_PCIE_A003
505c0a4e6b8SYuanquan Chen 		if (enabled == 0) {
506c0a4e6b8SYuanquan Chen 			serdes_corenet_t *srds_regs = (void *)CONFIG_SYS_FSL_CORENET_SERDES_ADDR;
507c0a4e6b8SYuanquan Chen 			temp32 = in_be32(&srds_regs->srdspccr0);
508c0a4e6b8SYuanquan Chen 
509c0a4e6b8SYuanquan Chen 			if ((temp32 >> 28) == 3) {
510c0a4e6b8SYuanquan Chen 				int i;
511c0a4e6b8SYuanquan Chen 
512c0a4e6b8SYuanquan Chen 				out_be32(&srds_regs->srdspccr0, 2 << 28);
513c0a4e6b8SYuanquan Chen 				setbits_be32(&pci->pdb_stat, 0x08000000);
514c0a4e6b8SYuanquan Chen 				in_be32(&pci->pdb_stat);
515c0a4e6b8SYuanquan Chen 				udelay(100);
516c0a4e6b8SYuanquan Chen 				clrbits_be32(&pci->pdb_stat, 0x08000000);
517c0a4e6b8SYuanquan Chen 				asm("sync;isync");
518c0a4e6b8SYuanquan Chen 				for (i=0; i < 100 && ltssm < PCI_LTSSM_L0; i++) {
519c0a4e6b8SYuanquan Chen 					pci_hose_read_config_word(hose, dev, PCI_LTSSM, &ltssm);
520c0a4e6b8SYuanquan Chen 					udelay(1000);
521c0a4e6b8SYuanquan Chen 				}
522c0a4e6b8SYuanquan Chen 				enabled = ltssm >= PCI_LTSSM_L0;
523c0a4e6b8SYuanquan Chen 			}
524c0a4e6b8SYuanquan Chen 		}
525c0a4e6b8SYuanquan Chen #endif
52693a686eeSJean-Christophe PLAGNIOL-VILLARD 		if (!enabled) {
52732514d25SZang Roy-R61911 			/* Let the user know there's no PCIe link for root
52832514d25SZang Roy-R61911 			 * complex. for endpoint, the link may not setup, so
52932514d25SZang Roy-R61911 			 * print undetermined.
53032514d25SZang Roy-R61911 			 */
53132514d25SZang Roy-R61911 			if (fsl_is_pci_agent(hose))
53232514d25SZang Roy-R61911 				printf("undetermined, regs @ 0x%lx\n", pci_info->regs);
53332514d25SZang Roy-R61911 			else
534213ac73eSPeter Tyser 				printf("no link, regs @ 0x%lx\n", pci_info->regs);
53593a686eeSJean-Christophe PLAGNIOL-VILLARD 			hose->last_busno = hose->first_busno;
53693a686eeSJean-Christophe PLAGNIOL-VILLARD 			return;
53793a686eeSJean-Christophe PLAGNIOL-VILLARD 		}
53893a686eeSJean-Christophe PLAGNIOL-VILLARD 
539ad19e7a5SKumar Gala 		out_be32(&pci->pme_msg_det, 0xffffffff);
540ad19e7a5SKumar Gala 		out_be32(&pci->pme_msg_int_en, 0xffffffff);
541213ac73eSPeter Tyser 
542213ac73eSPeter Tyser 		/* Print the negotiated PCIe link width */
543287df01eSZhao Qiang 		pci_hose_read_config_word(hose, dev, pci_lsr, &temp16);
544aceea941SPrabhakar Kushwaha 		printf("x%d gen%d, regs @ 0x%lx\n", (temp16 & 0x3f0) >> 4,
545aceea941SPrabhakar Kushwaha 		       (temp16 & 0xf), pci_info->regs);
546213ac73eSPeter Tyser 
54793a686eeSJean-Christophe PLAGNIOL-VILLARD 		hose->current_busno++; /* Start scan with secondary */
54893a686eeSJean-Christophe PLAGNIOL-VILLARD 		pciauto_prescan_setup_bridge(hose, dev, hose->current_busno);
54993a686eeSJean-Christophe PLAGNIOL-VILLARD 	}
55093a686eeSJean-Christophe PLAGNIOL-VILLARD 
55109bfd962STony O'Brien #ifdef CONFIG_SYS_FSL_ERRATUM_A007815
55209bfd962STony O'Brien 	/* The Read-Only Write Enable bit defaults to 1 instead of 0.
55309bfd962STony O'Brien 	 * Set to 0 to protect the read-only registers.
55409bfd962STony O'Brien 	 */
55509bfd962STony O'Brien 	clrbits_be32(&pci->dbi_ro_wr_en, 0x01);
55609bfd962STony O'Brien #endif
55709bfd962STony O'Brien 
55893a686eeSJean-Christophe PLAGNIOL-VILLARD 	/* Use generic setup_device to initialize standard pci regs,
55993a686eeSJean-Christophe PLAGNIOL-VILLARD 	 * but do not allocate any windows since any BAR found (such
56093a686eeSJean-Christophe PLAGNIOL-VILLARD 	 * as PCSRBAR) is not in this cpu's memory space.
56193a686eeSJean-Christophe PLAGNIOL-VILLARD 	 */
56293a686eeSJean-Christophe PLAGNIOL-VILLARD 	pciauto_setup_device(hose, dev, 0, hose->pci_mem,
56393a686eeSJean-Christophe PLAGNIOL-VILLARD 			     hose->pci_prefetch, hose->pci_io);
56493a686eeSJean-Christophe PLAGNIOL-VILLARD 
56593a686eeSJean-Christophe PLAGNIOL-VILLARD 	if (inbound) {
56693a686eeSJean-Christophe PLAGNIOL-VILLARD 		pci_hose_read_config_word(hose, dev, PCI_COMMAND, &temp16);
56793a686eeSJean-Christophe PLAGNIOL-VILLARD 		pci_hose_write_config_word(hose, dev, PCI_COMMAND,
56893a686eeSJean-Christophe PLAGNIOL-VILLARD 					   temp16 | PCI_COMMAND_MEMORY);
56993a686eeSJean-Christophe PLAGNIOL-VILLARD 	}
57093a686eeSJean-Christophe PLAGNIOL-VILLARD 
57193a686eeSJean-Christophe PLAGNIOL-VILLARD #ifndef CONFIG_PCI_NOSCAN
572505f3e6fSMinghuan Lian 	if (!fsl_is_pci_agent(hose)) {
57337d03fceSPeter Tyser 		debug("           Scanning PCI bus %02x\n",
5746df0efd5SEd Swarthout 			hose->current_busno);
57593a686eeSJean-Christophe PLAGNIOL-VILLARD 		hose->last_busno = pci_hose_scan_bus(hose, hose->current_busno);
5766df0efd5SEd Swarthout 	} else {
5776df0efd5SEd Swarthout 		debug("           Not scanning PCI bus %02x. PI=%x\n",
5786df0efd5SEd Swarthout 			hose->current_busno, temp8);
5796df0efd5SEd Swarthout 		hose->last_busno = hose->current_busno;
5806df0efd5SEd Swarthout 	}
58193a686eeSJean-Christophe PLAGNIOL-VILLARD 
5828295b944SKumar Gala 	/* if we are PCIe - update limit regs and subordinate busno
5838295b944SKumar Gala 	 * for the virtual P2P bridge
5848295b944SKumar Gala 	 */
5858295b944SKumar Gala 	if (pcie_cap == PCI_CAP_ID_EXP) {
58693a686eeSJean-Christophe PLAGNIOL-VILLARD 		pciauto_postscan_setup_bridge(hose, dev, hose->last_busno);
58793a686eeSJean-Christophe PLAGNIOL-VILLARD 	}
58893a686eeSJean-Christophe PLAGNIOL-VILLARD #else
58993a686eeSJean-Christophe PLAGNIOL-VILLARD 	hose->last_busno = hose->current_busno;
59093a686eeSJean-Christophe PLAGNIOL-VILLARD #endif
59193a686eeSJean-Christophe PLAGNIOL-VILLARD 
59293a686eeSJean-Christophe PLAGNIOL-VILLARD 	/* Clear all error indications */
5938295b944SKumar Gala 	if (pcie_cap == PCI_CAP_ID_EXP)
594ad19e7a5SKumar Gala 		out_be32(&pci->pme_msg_det, 0xffffffff);
595ad19e7a5SKumar Gala 	out_be32(&pci->pedr, 0xffffffff);
59693a686eeSJean-Christophe PLAGNIOL-VILLARD 
597287df01eSZhao Qiang 	pci_hose_read_config_word(hose, dev, pci_dsr, &temp16);
59893a686eeSJean-Christophe PLAGNIOL-VILLARD 	if (temp16) {
599287df01eSZhao Qiang 		pci_hose_write_config_word(hose, dev, pci_dsr, 0xffff);
60093a686eeSJean-Christophe PLAGNIOL-VILLARD 	}
60193a686eeSJean-Christophe PLAGNIOL-VILLARD 
60293a686eeSJean-Christophe PLAGNIOL-VILLARD 	pci_hose_read_config_word (hose, dev, PCI_SEC_STATUS, &temp16);
60393a686eeSJean-Christophe PLAGNIOL-VILLARD 	if (temp16) {
60493a686eeSJean-Christophe PLAGNIOL-VILLARD 		pci_hose_write_config_word(hose, dev, PCI_SEC_STATUS, 0xffff);
60593a686eeSJean-Christophe PLAGNIOL-VILLARD 	}
60693a686eeSJean-Christophe PLAGNIOL-VILLARD }
607a2aab460SKumar Gala 
fsl_is_pci_agent(struct pci_controller * hose)608715d8f76SEd Swarthout int fsl_is_pci_agent(struct pci_controller *hose)
609715d8f76SEd Swarthout {
610287df01eSZhao Qiang 	int pcie_cap_pos;
611505f3e6fSMinghuan Lian 	u8 pcie_cap;
612715d8f76SEd Swarthout 	pci_dev_t dev = PCI_BDF(hose->first_busno, 0, 0);
613715d8f76SEd Swarthout 
614287df01eSZhao Qiang 	pcie_cap_pos = pci_hose_find_capability(hose, dev, PCI_CAP_ID_EXP);
615287df01eSZhao Qiang 	pci_hose_read_config_byte(hose, dev, pcie_cap_pos, &pcie_cap);
616505f3e6fSMinghuan Lian 	if (pcie_cap == PCI_CAP_ID_EXP) {
617505f3e6fSMinghuan Lian 		u8 header_type;
618715d8f76SEd Swarthout 
619505f3e6fSMinghuan Lian 		pci_hose_read_config_byte(hose, dev, PCI_HEADER_TYPE,
620505f3e6fSMinghuan Lian 					  &header_type);
621505f3e6fSMinghuan Lian 		return (header_type & 0x7f) == PCI_HEADER_TYPE_NORMAL;
622505f3e6fSMinghuan Lian 	} else {
623505f3e6fSMinghuan Lian 		u8 prog_if;
624505f3e6fSMinghuan Lian 
625505f3e6fSMinghuan Lian 		pci_hose_read_config_byte(hose, dev, PCI_CLASS_PROG, &prog_if);
6267b4e5844SZang Roy-R61911 		/* Programming Interface (PCI_CLASS_PROG)
6277b4e5844SZang Roy-R61911 		 * 0 == pci host or pcie root-complex,
6287b4e5844SZang Roy-R61911 		 * 1 == pci agent or pcie end-point
6297b4e5844SZang Roy-R61911 		 */
630715d8f76SEd Swarthout 		return (prog_if == FSL_PROG_IF_AGENT);
631715d8f76SEd Swarthout 	}
632505f3e6fSMinghuan Lian }
633715d8f76SEd Swarthout 
fsl_pci_init_port(struct fsl_pci_info * pci_info,struct pci_controller * hose,int busno)6340d3d68b2SPoonam Aggrwal int fsl_pci_init_port(struct fsl_pci_info *pci_info,
63501471d53SKumar Gala 			struct pci_controller *hose, int busno)
6360d3d68b2SPoonam Aggrwal {
6370d3d68b2SPoonam Aggrwal 	volatile ccsr_fsl_pci_t *pci;
6380d3d68b2SPoonam Aggrwal 	struct pci_region *r;
639a72dbae2SPeter Tyser 	pci_dev_t dev = PCI_BDF(busno,0,0);
640287df01eSZhao Qiang 	int pcie_cap_pos;
641a72dbae2SPeter Tyser 	u8 pcie_cap;
6420d3d68b2SPoonam Aggrwal 
6430d3d68b2SPoonam Aggrwal 	pci = (ccsr_fsl_pci_t *) pci_info->regs;
6440d3d68b2SPoonam Aggrwal 
6450d3d68b2SPoonam Aggrwal 	/* on non-PCIe controllers we don't have pme_msg_det so this code
6460d3d68b2SPoonam Aggrwal 	 * should do nothing since the read will return 0
6470d3d68b2SPoonam Aggrwal 	 */
6480d3d68b2SPoonam Aggrwal 	if (in_be32(&pci->pme_msg_det)) {
6490d3d68b2SPoonam Aggrwal 		out_be32(&pci->pme_msg_det, 0xffffffff);
6500d3d68b2SPoonam Aggrwal 		debug (" with errors.  Clearing.  Now 0x%08x",
6510d3d68b2SPoonam Aggrwal 			pci->pme_msg_det);
6520d3d68b2SPoonam Aggrwal 	}
6530d3d68b2SPoonam Aggrwal 
6540d3d68b2SPoonam Aggrwal 	r = hose->regions + hose->region_count;
6550d3d68b2SPoonam Aggrwal 
6560d3d68b2SPoonam Aggrwal 	/* outbound memory */
6570d3d68b2SPoonam Aggrwal 	pci_set_region(r++,
6580d3d68b2SPoonam Aggrwal 			pci_info->mem_bus,
6590d3d68b2SPoonam Aggrwal 			pci_info->mem_phys,
6600d3d68b2SPoonam Aggrwal 			pci_info->mem_size,
6610d3d68b2SPoonam Aggrwal 			PCI_REGION_MEM);
6620d3d68b2SPoonam Aggrwal 
6630d3d68b2SPoonam Aggrwal 	/* outbound io */
6640d3d68b2SPoonam Aggrwal 	pci_set_region(r++,
6650d3d68b2SPoonam Aggrwal 			pci_info->io_bus,
6660d3d68b2SPoonam Aggrwal 			pci_info->io_phys,
6670d3d68b2SPoonam Aggrwal 			pci_info->io_size,
6680d3d68b2SPoonam Aggrwal 			PCI_REGION_IO);
6690d3d68b2SPoonam Aggrwal 
6700d3d68b2SPoonam Aggrwal 	hose->region_count = r - hose->regions;
6710d3d68b2SPoonam Aggrwal 	hose->first_busno = busno;
6720d3d68b2SPoonam Aggrwal 
673213ac73eSPeter Tyser 	fsl_pci_init(hose, pci_info);
6740d3d68b2SPoonam Aggrwal 
675715d8f76SEd Swarthout 	if (fsl_is_pci_agent(hose)) {
676715d8f76SEd Swarthout 		fsl_pci_config_unlock(hose);
677715d8f76SEd Swarthout 		hose->last_busno = hose->first_busno;
678c8b28152SLiu Gang #ifdef CONFIG_SRIO_PCIE_BOOT_MASTER
679b5f7c873SLiu Gang 	} else {
680b5f7c873SLiu Gang 		/* boot from PCIE --master releases slave's core 0 */
68100caae6dSSimon Glass 		char *s = env_get("bootmaster");
682b5f7c873SLiu Gang 		char pcie[6];
683b5f7c873SLiu Gang 		sprintf(pcie, "PCIE%d", pci_info->pci_num);
684b5f7c873SLiu Gang 
685b5f7c873SLiu Gang 		if (s && (strcmp(s, pcie) == 0))
686b5f7c873SLiu Gang 			fsl_pcie_boot_master_release_slave(pci_info->pci_num);
687b5f7c873SLiu Gang #endif
688715d8f76SEd Swarthout 	}
689715d8f76SEd Swarthout 
690287df01eSZhao Qiang 	pcie_cap_pos = pci_hose_find_capability(hose, dev, PCI_CAP_ID_EXP);
691287df01eSZhao Qiang 	pci_hose_read_config_byte(hose, dev, pcie_cap_pos, &pcie_cap);
6928ca78f2cSPeter Tyser 	printf("PCI%s%x: Bus %02x - %02x\n", pcie_cap == PCI_CAP_ID_EXP ?
693213ac73eSPeter Tyser 		"e" : "", pci_info->pci_num,
6940d3d68b2SPoonam Aggrwal 		hose->first_busno, hose->last_busno);
6950d3d68b2SPoonam Aggrwal 	return(hose->last_busno + 1);
6960d3d68b2SPoonam Aggrwal }
6970d3d68b2SPoonam Aggrwal 
6987a897959SPeter Tyser /* Enable inbound PCI config cycles for agent/endpoint interface */
fsl_pci_config_unlock(struct pci_controller * hose)6997a897959SPeter Tyser void fsl_pci_config_unlock(struct pci_controller *hose)
7007a897959SPeter Tyser {
7017a897959SPeter Tyser 	pci_dev_t dev = PCI_BDF(hose->first_busno,0,0);
702287df01eSZhao Qiang 	int pcie_cap_pos;
7037a897959SPeter Tyser 	u8 pcie_cap;
7047a897959SPeter Tyser 	u16 pbfr;
7057a897959SPeter Tyser 
706505f3e6fSMinghuan Lian 	if (!fsl_is_pci_agent(hose))
7077a897959SPeter Tyser 		return;
7087a897959SPeter Tyser 
709287df01eSZhao Qiang 	pcie_cap_pos = pci_hose_find_capability(hose, dev, PCI_CAP_ID_EXP);
710287df01eSZhao Qiang 	pci_hose_read_config_byte(hose, dev, pcie_cap_pos, &pcie_cap);
7117a897959SPeter Tyser 	if (pcie_cap != 0x0) {
7121d0b59a9SMinghuan Lian 		ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *)hose->cfg_addr;
7131d0b59a9SMinghuan Lian 		u32 block_rev = in_be32(&pci->block_rev1);
7147a897959SPeter Tyser 		/* PCIe - set CFG_READY bit of Configuration Ready Register */
7151d0b59a9SMinghuan Lian 		if (block_rev >= PEX_IP_BLK_REV_3_0)
7161d0b59a9SMinghuan Lian 			setbits_be32(&pci->config, FSL_PCIE_V3_CFG_RDY);
7171d0b59a9SMinghuan Lian 		else
7181d0b59a9SMinghuan Lian 			pci_hose_write_config_byte(hose, dev,
7191d0b59a9SMinghuan Lian 						   FSL_PCIE_CFG_RDY, 0x1);
7207a897959SPeter Tyser 	} else {
7217a897959SPeter Tyser 		/* PCI - clear ACL bit of PBFR */
7227a897959SPeter Tyser 		pci_hose_read_config_word(hose, dev, FSL_PCI_PBFR, &pbfr);
7237a897959SPeter Tyser 		pbfr &= ~0x20;
7247a897959SPeter Tyser 		pci_hose_write_config_word(hose, dev, FSL_PCI_PBFR, pbfr);
7257a897959SPeter Tyser 	}
7267a897959SPeter Tyser }
7277a897959SPeter Tyser 
728a4aafcc9SKumar Gala #if defined(CONFIG_PCIE1) || defined(CONFIG_PCIE2) || \
729a4aafcc9SKumar Gala     defined(CONFIG_PCIE3) || defined(CONFIG_PCIE4)
fsl_configure_pcie(struct fsl_pci_info * info,struct pci_controller * hose,const char * connected,int busno)730a4aafcc9SKumar Gala int fsl_configure_pcie(struct fsl_pci_info *info,
731a4aafcc9SKumar Gala 			struct pci_controller *hose,
732a4aafcc9SKumar Gala 			const char *connected, int busno)
733a4aafcc9SKumar Gala {
734a4aafcc9SKumar Gala 	int is_endpoint;
735a4aafcc9SKumar Gala 
736a4aafcc9SKumar Gala 	set_next_law(info->mem_phys, law_size_bits(info->mem_size), info->law);
737a4aafcc9SKumar Gala 	set_next_law(info->io_phys, law_size_bits(info->io_size), info->law);
738213ac73eSPeter Tyser 
739a4aafcc9SKumar Gala 	is_endpoint = fsl_setup_hose(hose, info->regs);
740213ac73eSPeter Tyser 	printf("PCIe%u: %s", info->pci_num,
741213ac73eSPeter Tyser 		is_endpoint ? "Endpoint" : "Root Complex");
742213ac73eSPeter Tyser 	if (connected)
743213ac73eSPeter Tyser 		printf(" of %s", connected);
744213ac73eSPeter Tyser 	puts(", ");
745213ac73eSPeter Tyser 
746a4aafcc9SKumar Gala 	return fsl_pci_init_port(info, hose, busno);
747a4aafcc9SKumar Gala }
748a4aafcc9SKumar Gala 
749a4aafcc9SKumar Gala #if defined(CONFIG_FSL_CORENET)
7509e758758SYork Sun #ifdef CONFIG_SYS_FSL_QORIQ_CHASSIS2
7519e758758SYork Sun 	#define _DEVDISR_PCIE1 FSL_CORENET_DEVDISR3_PCIE1
7529e758758SYork Sun 	#define _DEVDISR_PCIE2 FSL_CORENET_DEVDISR3_PCIE2
7539e758758SYork Sun 	#define _DEVDISR_PCIE3 FSL_CORENET_DEVDISR3_PCIE3
7549e758758SYork Sun 	#define _DEVDISR_PCIE4 FSL_CORENET_DEVDISR3_PCIE4
7559e758758SYork Sun #else
756a4aafcc9SKumar Gala 	#define _DEVDISR_PCIE1 FSL_CORENET_DEVDISR_PCIE1
757a4aafcc9SKumar Gala 	#define _DEVDISR_PCIE2 FSL_CORENET_DEVDISR_PCIE2
758a4aafcc9SKumar Gala 	#define _DEVDISR_PCIE3 FSL_CORENET_DEVDISR_PCIE3
759a4aafcc9SKumar Gala 	#define _DEVDISR_PCIE4 FSL_CORENET_DEVDISR_PCIE4
7609e758758SYork Sun #endif
761a4aafcc9SKumar Gala 	#define CONFIG_SYS_MPC8xxx_GUTS_ADDR CONFIG_SYS_MPC85xx_GUTS_ADDR
762a4aafcc9SKumar Gala #elif defined(CONFIG_MPC85xx)
763a4aafcc9SKumar Gala 	#define _DEVDISR_PCIE1 MPC85xx_DEVDISR_PCIE
764a4aafcc9SKumar Gala 	#define _DEVDISR_PCIE2 MPC85xx_DEVDISR_PCIE2
765a4aafcc9SKumar Gala 	#define _DEVDISR_PCIE3 MPC85xx_DEVDISR_PCIE3
766a4aafcc9SKumar Gala 	#define _DEVDISR_PCIE4 0
767a4aafcc9SKumar Gala 	#define CONFIG_SYS_MPC8xxx_GUTS_ADDR CONFIG_SYS_MPC85xx_GUTS_ADDR
768a4aafcc9SKumar Gala #elif defined(CONFIG_MPC86xx)
769a4aafcc9SKumar Gala 	#define _DEVDISR_PCIE1 MPC86xx_DEVDISR_PCIE1
770a4aafcc9SKumar Gala 	#define _DEVDISR_PCIE2 MPC86xx_DEVDISR_PCIE2
771a4aafcc9SKumar Gala 	#define _DEVDISR_PCIE3 0
772a4aafcc9SKumar Gala 	#define _DEVDISR_PCIE4 0
773a4aafcc9SKumar Gala 	#define CONFIG_SYS_MPC8xxx_GUTS_ADDR \
774a4aafcc9SKumar Gala 		(&((immap_t *)CONFIG_SYS_IMMR)->im_gur)
775a4aafcc9SKumar Gala #else
776a4aafcc9SKumar Gala #error "No defines for DEVDISR_PCIE"
777a4aafcc9SKumar Gala #endif
778a4aafcc9SKumar Gala 
779a4aafcc9SKumar Gala /* Implement a dummy function for those platforms w/o SERDES */
__board_serdes_name(enum srds_prtcl device)780a4aafcc9SKumar Gala static const char *__board_serdes_name(enum srds_prtcl device)
781a4aafcc9SKumar Gala {
782a4aafcc9SKumar Gala 	switch (device) {
783a4aafcc9SKumar Gala #ifdef CONFIG_SYS_PCIE1_NAME
784a4aafcc9SKumar Gala 	case PCIE1:
785a4aafcc9SKumar Gala 		return CONFIG_SYS_PCIE1_NAME;
786a4aafcc9SKumar Gala #endif
787a4aafcc9SKumar Gala #ifdef CONFIG_SYS_PCIE2_NAME
788a4aafcc9SKumar Gala 	case PCIE2:
789a4aafcc9SKumar Gala 		return CONFIG_SYS_PCIE2_NAME;
790a4aafcc9SKumar Gala #endif
791a4aafcc9SKumar Gala #ifdef CONFIG_SYS_PCIE3_NAME
792a4aafcc9SKumar Gala 	case PCIE3:
793a4aafcc9SKumar Gala 		return CONFIG_SYS_PCIE3_NAME;
794a4aafcc9SKumar Gala #endif
795a4aafcc9SKumar Gala #ifdef CONFIG_SYS_PCIE4_NAME
796a4aafcc9SKumar Gala 	case PCIE4:
797a4aafcc9SKumar Gala 		return CONFIG_SYS_PCIE4_NAME;
798a4aafcc9SKumar Gala #endif
799a4aafcc9SKumar Gala 	default:
800a4aafcc9SKumar Gala 		return NULL;
801a4aafcc9SKumar Gala 	}
802a4aafcc9SKumar Gala 
803a4aafcc9SKumar Gala 	return NULL;
804a4aafcc9SKumar Gala }
805a4aafcc9SKumar Gala 
806a4aafcc9SKumar Gala __attribute__((weak, alias("__board_serdes_name"))) const char *
807a4aafcc9SKumar Gala board_serdes_name(enum srds_prtcl device);
808a4aafcc9SKumar Gala 
809a4aafcc9SKumar Gala static u32 devdisr_mask[] = {
810a4aafcc9SKumar Gala 	_DEVDISR_PCIE1,
811a4aafcc9SKumar Gala 	_DEVDISR_PCIE2,
812a4aafcc9SKumar Gala 	_DEVDISR_PCIE3,
813a4aafcc9SKumar Gala 	_DEVDISR_PCIE4,
814a4aafcc9SKumar Gala };
815a4aafcc9SKumar Gala 
fsl_pcie_init_ctrl(int busno,u32 devdisr,enum srds_prtcl dev,struct fsl_pci_info * pci_info)816a4aafcc9SKumar Gala int fsl_pcie_init_ctrl(int busno, u32 devdisr, enum srds_prtcl dev,
817a4aafcc9SKumar Gala 			struct fsl_pci_info *pci_info)
818a4aafcc9SKumar Gala {
819a4aafcc9SKumar Gala 	struct pci_controller *hose;
820a4aafcc9SKumar Gala 	int num = dev - PCIE1;
821a4aafcc9SKumar Gala 
822a4aafcc9SKumar Gala 	hose = calloc(1, sizeof(struct pci_controller));
823a4aafcc9SKumar Gala 	if (!hose)
824a4aafcc9SKumar Gala 		return busno;
825a4aafcc9SKumar Gala 
826a4aafcc9SKumar Gala 	if (is_serdes_configured(dev) && !(devdisr & devdisr_mask[num])) {
827a4aafcc9SKumar Gala 		busno = fsl_configure_pcie(pci_info, hose,
828a4aafcc9SKumar Gala 				board_serdes_name(dev), busno);
829a4aafcc9SKumar Gala 	} else {
830213ac73eSPeter Tyser 		printf("PCIe%d: disabled\n", num + 1);
831a4aafcc9SKumar Gala 	}
832a4aafcc9SKumar Gala 
833a4aafcc9SKumar Gala 	return busno;
834a4aafcc9SKumar Gala }
835a4aafcc9SKumar Gala 
fsl_pcie_init_board(int busno)836a4aafcc9SKumar Gala int fsl_pcie_init_board(int busno)
837a4aafcc9SKumar Gala {
838a4aafcc9SKumar Gala 	struct fsl_pci_info pci_info;
839a4aafcc9SKumar Gala 	ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC8xxx_GUTS_ADDR;
8409e758758SYork Sun 	u32 devdisr;
8419e758758SYork Sun 	u32 *addr;
8429e758758SYork Sun 
8439e758758SYork Sun #ifdef CONFIG_SYS_FSL_QORIQ_CHASSIS2
8449e758758SYork Sun 	addr = &gur->devdisr3;
8459e758758SYork Sun #else
8469e758758SYork Sun 	addr = &gur->devdisr;
8479e758758SYork Sun #endif
8489e758758SYork Sun 	devdisr = in_be32(addr);
849a4aafcc9SKumar Gala 
850a4aafcc9SKumar Gala #ifdef CONFIG_PCIE1
851a4aafcc9SKumar Gala 	SET_STD_PCIE_INFO(pci_info, 1);
852a4aafcc9SKumar Gala 	busno = fsl_pcie_init_ctrl(busno, devdisr, PCIE1, &pci_info);
853a4aafcc9SKumar Gala #else
8549e758758SYork Sun 	setbits_be32(addr, _DEVDISR_PCIE1); /* disable */
855a4aafcc9SKumar Gala #endif
856a4aafcc9SKumar Gala 
857a4aafcc9SKumar Gala #ifdef CONFIG_PCIE2
858a4aafcc9SKumar Gala 	SET_STD_PCIE_INFO(pci_info, 2);
859a4aafcc9SKumar Gala 	busno = fsl_pcie_init_ctrl(busno, devdisr, PCIE2, &pci_info);
860a4aafcc9SKumar Gala #else
8619e758758SYork Sun 	setbits_be32(addr, _DEVDISR_PCIE2); /* disable */
862a4aafcc9SKumar Gala #endif
863a4aafcc9SKumar Gala 
864a4aafcc9SKumar Gala #ifdef CONFIG_PCIE3
865a4aafcc9SKumar Gala 	SET_STD_PCIE_INFO(pci_info, 3);
866a4aafcc9SKumar Gala 	busno = fsl_pcie_init_ctrl(busno, devdisr, PCIE3, &pci_info);
867a4aafcc9SKumar Gala #else
8689e758758SYork Sun 	setbits_be32(addr, _DEVDISR_PCIE3); /* disable */
869a4aafcc9SKumar Gala #endif
870a4aafcc9SKumar Gala 
871a4aafcc9SKumar Gala #ifdef CONFIG_PCIE4
872a4aafcc9SKumar Gala 	SET_STD_PCIE_INFO(pci_info, 4);
873a4aafcc9SKumar Gala 	busno = fsl_pcie_init_ctrl(busno, devdisr, PCIE4, &pci_info);
874a4aafcc9SKumar Gala #else
8759e758758SYork Sun 	setbits_be32(addr, _DEVDISR_PCIE4); /* disable */
876a4aafcc9SKumar Gala #endif
877a4aafcc9SKumar Gala 
878a4aafcc9SKumar Gala  	return busno;
879a4aafcc9SKumar Gala }
880a4aafcc9SKumar Gala #else
fsl_pcie_init_ctrl(int busno,u32 devdisr,enum srds_prtcl dev,struct fsl_pci_info * pci_info)881a4aafcc9SKumar Gala int fsl_pcie_init_ctrl(int busno, u32 devdisr, enum srds_prtcl dev,
882a4aafcc9SKumar Gala 			struct fsl_pci_info *pci_info)
883a4aafcc9SKumar Gala {
884a4aafcc9SKumar Gala 	return busno;
885a4aafcc9SKumar Gala }
886a4aafcc9SKumar Gala 
fsl_pcie_init_board(int busno)887a4aafcc9SKumar Gala int fsl_pcie_init_board(int busno)
888a4aafcc9SKumar Gala {
889a4aafcc9SKumar Gala 	return busno;
890a4aafcc9SKumar Gala }
891a4aafcc9SKumar Gala #endif
892a4aafcc9SKumar Gala 
893a2aab460SKumar Gala #ifdef CONFIG_OF_BOARD_SETUP
894b08c8c48SMasahiro Yamada #include <linux/libfdt.h>
895a2aab460SKumar Gala #include <fdt_support.h>
896a2aab460SKumar Gala 
ft_fsl_pci_setup(void * blob,const char * pci_compat,unsigned long ctrl_addr)8976525d51fSKumar Gala void ft_fsl_pci_setup(void *blob, const char *pci_compat,
8983a0e3c27SKumar Gala 			unsigned long ctrl_addr)
899a2aab460SKumar Gala {
9006525d51fSKumar Gala 	int off;
901a2aab460SKumar Gala 	u32 bus_range[2];
9026525d51fSKumar Gala 	phys_addr_t p_ctrl_addr = (phys_addr_t)ctrl_addr;
9033a0e3c27SKumar Gala 	struct pci_controller *hose;
9043a0e3c27SKumar Gala 
9053a0e3c27SKumar Gala 	hose = find_hose_by_cfg_addr((void *)(ctrl_addr));
9066525d51fSKumar Gala 
9076525d51fSKumar Gala 	/* convert ctrl_addr to true physical address */
9086525d51fSKumar Gala 	p_ctrl_addr = (phys_addr_t)ctrl_addr - CONFIG_SYS_CCSRBAR;
9096525d51fSKumar Gala 	p_ctrl_addr += CONFIG_SYS_CCSRBAR_PHYS;
9106525d51fSKumar Gala 
9116525d51fSKumar Gala 	off = fdt_node_offset_by_compat_reg(blob, pci_compat, p_ctrl_addr);
912a2aab460SKumar Gala 
9135a85a309SKumar Gala 	if (off < 0)
9145a85a309SKumar Gala 		return;
9155a85a309SKumar Gala 
9165a85a309SKumar Gala 	/* We assume a cfg_addr not being set means we didn't setup the controller */
9175a85a309SKumar Gala 	if ((hose == NULL) || (hose->cfg_addr == NULL)) {
9186525d51fSKumar Gala 		fdt_del_node(blob, off);
9195a85a309SKumar Gala 	} else {
920a2aab460SKumar Gala 		bus_range[0] = 0;
921a2aab460SKumar Gala 		bus_range[1] = hose->last_busno - hose->first_busno;
922a2aab460SKumar Gala 		fdt_setprop(blob, off, "bus-range", &bus_range[0], 2*4);
923a2aab460SKumar Gala 		fdt_pci_dma_ranges(blob, off, hose);
924a2aab460SKumar Gala 	}
925a2aab460SKumar Gala }
926a2aab460SKumar Gala #endif
927