xref: /openbmc/linux/arch/powerpc/sysdev/fsl_pci.c (revision c900529f3d9161bfde5cca0754f83b4d3c3e0220)
12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
255c44991SRoy Zang /*
35b70a097SJohn Rigby  * MPC83xx/85xx/86xx PCI/PCIE support routing.
455c44991SRoy Zang  *
507e4f801SScott Wood  * Copyright 2007-2012 Freescale Semiconductor, Inc.
6598804cdSAnton Vorontsov  * Copyright 2008-2009 MontaVista Software, Inc.
79ac4dd30SZang Roy-r61911  *
855c44991SRoy Zang  * Initial author: Xianghua Xiao <x.xiao@freescale.com>
99ac4dd30SZang Roy-r61911  * Recode: ZHANG WEI <wei.zhang@freescale.com>
109ac4dd30SZang Roy-r61911  * Rewrite the routing for Frescale PCI and PCI Express
119ac4dd30SZang Roy-r61911  * 	Roy Zang <tie-fei.zang@freescale.com>
12598804cdSAnton Vorontsov  * MPC83xx PCI-Express support:
13598804cdSAnton Vorontsov  * 	Tony Li <tony.li@freescale.com>
14598804cdSAnton Vorontsov  * 	Anton Vorontsov <avorontsov@ru.mvista.com>
1555c44991SRoy Zang  */
169ac4dd30SZang Roy-r61911 #include <linux/kernel.h>
1755c44991SRoy Zang #include <linux/pci.h>
189ac4dd30SZang Roy-r61911 #include <linux/delay.h>
199ac4dd30SZang Roy-r61911 #include <linux/string.h>
20666db563SScott Wood #include <linux/fsl/edac.h>
219ac4dd30SZang Roy-r61911 #include <linux/init.h>
2248b16180SWang Dongsheng #include <linux/interrupt.h>
2395f72d1eSYinghai Lu #include <linux/memblock.h>
2454c18193SKumar Gala #include <linux/log2.h>
25e6f6390aSChristophe Leroy #include <linux/of_address.h>
26e6f6390aSChristophe Leroy #include <linux/of_irq.h>
27666db563SScott Wood #include <linux/platform_device.h>
285a0e3ad6STejun Heo #include <linux/slab.h>
2948b16180SWang Dongsheng #include <linux/suspend.h>
3048b16180SWang Dongsheng #include <linux/syscore_ops.h>
314e0e3435SHongtao Jia #include <linux/uaccess.h>
3255c44991SRoy Zang 
3355c44991SRoy Zang #include <asm/io.h>
3455c44991SRoy Zang #include <asm/pci-bridge.h>
354e0e3435SHongtao Jia #include <asm/ppc-pci.h>
369ac4dd30SZang Roy-r61911 #include <asm/machdep.h>
37a8165d42Schenhui zhao #include <asm/mpc85xx.h>
384e0e3435SHongtao Jia #include <asm/disassemble.h>
394e0e3435SHongtao Jia #include <asm/ppc-opcode.h>
404a605e2dSChristoph Hellwig #include <asm/swiotlb.h>
41113fe88eSChristophe Leroy #include <asm/setup.h>
4255c44991SRoy Zang #include <sysdev/fsl_soc.h>
4355c44991SRoy Zang #include <sysdev/fsl_pci.h>
4455c44991SRoy Zang 
45b8f44ec2SKumar Gala static int fsl_pcie_bus_fixup, is_mpc83xx_pci;
46598804cdSAnton Vorontsov 
quirk_fsl_pcie_early(struct pci_dev * dev)47bbd234b1SChunhe Lan static void quirk_fsl_pcie_early(struct pci_dev *dev)
48598804cdSAnton Vorontsov {
4959c58c32SMinghuan Lian 	u8 hdr_type;
50470788d4SKumar Gala 
51598804cdSAnton Vorontsov 	/* if we aren't a PCIe don't bother */
52f0308261SYijing Wang 	if (!pci_is_pcie(dev))
53598804cdSAnton Vorontsov 		return;
54598804cdSAnton Vorontsov 
55470788d4SKumar Gala 	/* if we aren't in host mode don't bother */
5659c58c32SMinghuan Lian 	pci_read_config_byte(dev, PCI_HEADER_TYPE, &hdr_type);
5759c58c32SMinghuan Lian 	if ((hdr_type & 0x7f) != PCI_HEADER_TYPE_BRIDGE)
58470788d4SKumar Gala 		return;
59470788d4SKumar Gala 
60904b10fbSPali Rohár 	dev->class = PCI_CLASS_BRIDGE_PCI_NORMAL;
61598804cdSAnton Vorontsov 	fsl_pcie_bus_fixup = 1;
62598804cdSAnton Vorontsov 	return;
63598804cdSAnton Vorontsov }
64598804cdSAnton Vorontsov 
6550d8f87dSRojhalat Ibrahim static int fsl_indirect_read_config(struct pci_bus *, unsigned int,
6650d8f87dSRojhalat Ibrahim 				    int, int, u32 *);
6750d8f87dSRojhalat Ibrahim 
fsl_pcie_check_link(struct pci_controller * hose)6850d8f87dSRojhalat Ibrahim static int fsl_pcie_check_link(struct pci_controller *hose)
69598804cdSAnton Vorontsov {
7050d8f87dSRojhalat Ibrahim 	u32 val = 0;
71598804cdSAnton Vorontsov 
7234642bbbSKumar Gala 	if (hose->indirect_type & PPC_INDIRECT_TYPE_FSL_CFG_REG_LINK) {
736d5f6a0eSKim Phillips 		if (hose->ops->read == fsl_indirect_read_config)
746d5f6a0eSKim Phillips 			__indirect_read_config(hose, hose->first_busno, 0,
756d5f6a0eSKim Phillips 					       PCIE_LTSSM, 4, &val);
766d5f6a0eSKim Phillips 		else
7734642bbbSKumar Gala 			early_read_config_dword(hose, 0, 0, PCIE_LTSSM, &val);
7834642bbbSKumar Gala 		if (val < PCIE_LTSSM_L0)
7934642bbbSKumar Gala 			return 1;
8034642bbbSKumar Gala 	} else {
8134642bbbSKumar Gala 		struct ccsr_pci __iomem *pci = hose->private_data;
82cc6ea0ddSRoy ZANG 		/* for PCIe IP rev 3.0 or greater use CSR0 for link state */
83cc6ea0ddSRoy ZANG 		val = (in_be32(&pci->pex_csr0) & PEX_CSR0_LTSSM_MASK)
84cc6ea0ddSRoy ZANG 				>> PEX_CSR0_LTSSM_SHIFT;
85cc6ea0ddSRoy ZANG 		if (val != PEX_CSR0_LTSSM_L0)
86cc6ea0ddSRoy ZANG 			return 1;
87cc6ea0ddSRoy ZANG 	}
88cc6ea0ddSRoy ZANG 
89598804cdSAnton Vorontsov 	return 0;
90598804cdSAnton Vorontsov }
91598804cdSAnton Vorontsov 
fsl_indirect_read_config(struct pci_bus * bus,unsigned int devfn,int offset,int len,u32 * val)9250d8f87dSRojhalat Ibrahim static int fsl_indirect_read_config(struct pci_bus *bus, unsigned int devfn,
9350d8f87dSRojhalat Ibrahim 				    int offset, int len, u32 *val)
9450d8f87dSRojhalat Ibrahim {
9550d8f87dSRojhalat Ibrahim 	struct pci_controller *hose = pci_bus_to_host(bus);
9650d8f87dSRojhalat Ibrahim 
9750d8f87dSRojhalat Ibrahim 	if (fsl_pcie_check_link(hose))
9850d8f87dSRojhalat Ibrahim 		hose->indirect_type |= PPC_INDIRECT_TYPE_NO_PCIE_LINK;
9950d8f87dSRojhalat Ibrahim 	else
10050d8f87dSRojhalat Ibrahim 		hose->indirect_type &= ~PPC_INDIRECT_TYPE_NO_PCIE_LINK;
10150d8f87dSRojhalat Ibrahim 
10250d8f87dSRojhalat Ibrahim 	return indirect_read_config(bus, devfn, offset, len, val);
10350d8f87dSRojhalat Ibrahim }
10450d8f87dSRojhalat Ibrahim 
105b37e1613SRojhalat Ibrahim #if defined(CONFIG_FSL_SOC_BOOKE) || defined(CONFIG_PPC_86xx)
106b37e1613SRojhalat Ibrahim 
107b37e1613SRojhalat Ibrahim static struct pci_ops fsl_indirect_pcie_ops =
10850d8f87dSRojhalat Ibrahim {
10950d8f87dSRojhalat Ibrahim 	.read = fsl_indirect_read_config,
11050d8f87dSRojhalat Ibrahim 	.write = indirect_write_config,
11150d8f87dSRojhalat Ibrahim };
11250d8f87dSRojhalat Ibrahim 
11363f1de88SScott Wood static u64 pci64_dma_offset;
11496ea3b4aSKumar Gala 
11597884e00SDaniel Axtens #ifdef CONFIG_SWIOTLB
pci_dma_dev_setup_swiotlb(struct pci_dev * pdev)116391133fdSChristoph Hellwig static void pci_dma_dev_setup_swiotlb(struct pci_dev *pdev)
117391133fdSChristoph Hellwig {
118391133fdSChristoph Hellwig 	struct pci_controller *hose = pci_bus_to_host(pdev->bus);
119391133fdSChristoph Hellwig 
120a7ba70f1SNicolas Saenz Julienne 	pdev->dev.bus_dma_limit =
121a7ba70f1SNicolas Saenz Julienne 		hose->dma_window_base_cur + hose->dma_window_size - 1;
122391133fdSChristoph Hellwig }
123391133fdSChristoph Hellwig 
setup_swiotlb_ops(struct pci_controller * hose)12497884e00SDaniel Axtens static void setup_swiotlb_ops(struct pci_controller *hose)
12597884e00SDaniel Axtens {
12668005b67SChristoph Hellwig 	if (ppc_swiotlb_enable)
12797884e00SDaniel Axtens 		hose->controller_ops.dma_dev_setup = pci_dma_dev_setup_swiotlb;
12897884e00SDaniel Axtens }
12997884e00SDaniel Axtens #else
setup_swiotlb_ops(struct pci_controller * hose)13097884e00SDaniel Axtens static inline void setup_swiotlb_ops(struct pci_controller *hose) {}
13197884e00SDaniel Axtens #endif
13297884e00SDaniel Axtens 
fsl_pci_dma_set_mask(struct device * dev,u64 dma_mask)13311ddce15SChristoph Hellwig static void fsl_pci_dma_set_mask(struct device *dev, u64 dma_mask)
13496ea3b4aSKumar Gala {
13596ea3b4aSKumar Gala 	/*
13663f1de88SScott Wood 	 * Fix up PCI devices that are able to DMA to the large inbound
13763f1de88SScott Wood 	 * mapping that allows addressing any RAM address from across PCI.
13896ea3b4aSKumar Gala 	 */
13963f1de88SScott Wood 	if (dev_is_pci(dev) && dma_mask >= pci64_dma_offset * 2 - 1) {
140a7ba70f1SNicolas Saenz Julienne 		dev->bus_dma_limit = 0;
1410617fc0cSChristoph Hellwig 		dev->archdata.dma_offset = pci64_dma_offset;
14296ea3b4aSKumar Gala 	}
14396ea3b4aSKumar Gala }
14496ea3b4aSKumar Gala 
setup_one_atmu(struct ccsr_pci __iomem * pci,unsigned int index,const struct resource * res,resource_size_t offset)145a393d897SJia Hongtao static int setup_one_atmu(struct ccsr_pci __iomem *pci,
146a097a78cSTrent Piepho 	unsigned int index, const struct resource *res,
147a097a78cSTrent Piepho 	resource_size_t offset)
148a097a78cSTrent Piepho {
149a097a78cSTrent Piepho 	resource_size_t pci_addr = res->start - offset;
150a097a78cSTrent Piepho 	resource_size_t phys_addr = res->start;
15128f65c11SJoe Perches 	resource_size_t size = resource_size(res);
152a097a78cSTrent Piepho 	u32 flags = 0x80044000; /* enable & mem R/W */
153a097a78cSTrent Piepho 	unsigned int i;
154a097a78cSTrent Piepho 
155a097a78cSTrent Piepho 	pr_debug("PCI MEM resource start 0x%016llx, size 0x%016llx.\n",
156a097a78cSTrent Piepho 		(u64)res->start, (u64)size);
157a097a78cSTrent Piepho 
158565f3764STrent Piepho 	if (res->flags & IORESOURCE_PREFETCH)
159565f3764STrent Piepho 		flags |= 0x10000000; /* enable relaxed ordering */
160565f3764STrent Piepho 
161a097a78cSTrent Piepho 	for (i = 0; size > 0; i++) {
1626e4c632cSAnton Blanchard 		unsigned int bits = min_t(u32, ilog2(size),
163a097a78cSTrent Piepho 					__ffs(pci_addr | phys_addr));
164a097a78cSTrent Piepho 
165a097a78cSTrent Piepho 		if (index + i >= 5)
166a097a78cSTrent Piepho 			return -1;
167a097a78cSTrent Piepho 
168a097a78cSTrent Piepho 		out_be32(&pci->pow[index + i].potar, pci_addr >> 12);
169a097a78cSTrent Piepho 		out_be32(&pci->pow[index + i].potear, (u64)pci_addr >> 44);
170a097a78cSTrent Piepho 		out_be32(&pci->pow[index + i].powbar, phys_addr >> 12);
171a097a78cSTrent Piepho 		out_be32(&pci->pow[index + i].powar, flags | (bits - 1));
172a097a78cSTrent Piepho 
173a097a78cSTrent Piepho 		pci_addr += (resource_size_t)1U << bits;
174a097a78cSTrent Piepho 		phys_addr += (resource_size_t)1U << bits;
175a097a78cSTrent Piepho 		size -= (resource_size_t)1U << bits;
176a097a78cSTrent Piepho 	}
177a097a78cSTrent Piepho 
178a097a78cSTrent Piepho 	return i;
179a097a78cSTrent Piepho }
180a097a78cSTrent Piepho 
is_kdump(void)1811930bb5cSScott Wood static bool is_kdump(void)
1821930bb5cSScott Wood {
1831930bb5cSScott Wood 	struct device_node *node;
1843d31adc4SLiang He 	bool ret;
1851930bb5cSScott Wood 
1861930bb5cSScott Wood 	node = of_find_node_by_type(NULL, "memory");
1871930bb5cSScott Wood 	if (!node) {
1881930bb5cSScott Wood 		WARN_ON_ONCE(1);
1891930bb5cSScott Wood 		return false;
1901930bb5cSScott Wood 	}
1911930bb5cSScott Wood 
1923d31adc4SLiang He 	ret = of_property_read_bool(node, "linux,usable-memory");
1933d31adc4SLiang He 	of_node_put(node);
1943d31adc4SLiang He 
1953d31adc4SLiang He 	return ret;
1961930bb5cSScott Wood }
1971930bb5cSScott Wood 
1989ac4dd30SZang Roy-r61911 /* atmu setup for fsl pci/pcie controller */
setup_pci_atmu(struct pci_controller * hose)19934642bbbSKumar Gala static void setup_pci_atmu(struct pci_controller *hose)
20055c44991SRoy Zang {
20134642bbbSKumar Gala 	struct ccsr_pci __iomem *pci = hose->private_data;
202f4154e16SPrabhakar Kushwaha 	int i, j, n, mem_log, win_idx = 3, start_idx = 1, end_idx = 4;
20354c18193SKumar Gala 	u64 mem, sz, paddr_hi = 0;
2043fd47f06SBenjamin Herrenschmidt 	u64 offset = 0, paddr_lo = ULLONG_MAX;
20554c18193SKumar Gala 	u32 pcicsrbar = 0, pcicsrbar_sz;
20654c18193SKumar Gala 	u32 piwar = PIWAR_EN | PIWAR_PF | PIWAR_TGI_LOCAL |
20754c18193SKumar Gala 			PIWAR_READ_SNOOP | PIWAR_WRITE_SNOOP;
208446bc1ffSTimur Tabi 	const u64 *reg;
209446bc1ffSTimur Tabi 	int len;
2101930bb5cSScott Wood 	bool setup_inbound;
2111930bb5cSScott Wood 
2121930bb5cSScott Wood 	/*
2131930bb5cSScott Wood 	 * If this is kdump, we don't want to trigger a bunch of PCI
2141930bb5cSScott Wood 	 * errors by closing the window on in-flight DMA.
2151930bb5cSScott Wood 	 *
2161930bb5cSScott Wood 	 * We still run most of the function's logic so that things like
2171930bb5cSScott Wood 	 * hose->dma_window_size still get set.
2181930bb5cSScott Wood 	 */
2191930bb5cSScott Wood 	setup_inbound = !is_kdump();
22055c44991SRoy Zang 
221720d7aebSHarninder Rai 	if (of_device_is_compatible(hose->dn, "fsl,bsc9132-pcie")) {
222720d7aebSHarninder Rai 		/*
223720d7aebSHarninder Rai 		 * BSC9132 Rev1.0 has an issue where all the PEX inbound
224720d7aebSHarninder Rai 		 * windows have implemented the default target value as 0xf
225720d7aebSHarninder Rai 		 * for CCSR space.In all Freescale legacy devices the target
226720d7aebSHarninder Rai 		 * of 0xf is reserved for local memory space. 9132 Rev1.0
2271fd02f66SJulia Lawall 		 * now has local memory space mapped to target 0x0 instead of
228720d7aebSHarninder Rai 		 * 0xf. Hence adding a workaround to remove the target 0xf
229720d7aebSHarninder Rai 		 * defined for memory space from Inbound window attributes.
230720d7aebSHarninder Rai 		 */
231720d7aebSHarninder Rai 		piwar &= ~PIWAR_TGI_LOCAL;
232720d7aebSHarninder Rai 	}
233720d7aebSHarninder Rai 
2349e67886bSRoy Zang 	if (early_find_capability(hose, 0, 0, PCI_CAP_ID_EXP)) {
2359e67886bSRoy Zang 		if (in_be32(&pci->block_rev1) >= PCIE_IP_REV_2_2) {
2369e67886bSRoy Zang 			win_idx = 2;
2379e67886bSRoy Zang 			start_idx = 0;
2389e67886bSRoy Zang 			end_idx = 3;
2399e67886bSRoy Zang 		}
2409e67886bSRoy Zang 	}
2419e67886bSRoy Zang 
242a097a78cSTrent Piepho 	/* Disable all windows (except powar0 since it's ignored) */
2439ac4dd30SZang Roy-r61911 	for(i = 1; i < 5; i++)
2449ac4dd30SZang Roy-r61911 		out_be32(&pci->pow[i].powar, 0);
2451930bb5cSScott Wood 
2461930bb5cSScott Wood 	if (setup_inbound) {
247f4154e16SPrabhakar Kushwaha 		for (i = start_idx; i < end_idx; i++)
2489ac4dd30SZang Roy-r61911 			out_be32(&pci->piw[i].piwar, 0);
2491930bb5cSScott Wood 	}
25055c44991SRoy Zang 
25155c44991SRoy Zang 	/* Setup outbound MEM window */
252a097a78cSTrent Piepho 	for(i = 0, j = 1; i < 3; i++) {
253a097a78cSTrent Piepho 		if (!(hose->mem_resources[i].flags & IORESOURCE_MEM))
254a097a78cSTrent Piepho 			continue;
255a097a78cSTrent Piepho 
25654c18193SKumar Gala 		paddr_lo = min(paddr_lo, (u64)hose->mem_resources[i].start);
25754c18193SKumar Gala 		paddr_hi = max(paddr_hi, (u64)hose->mem_resources[i].end);
25854c18193SKumar Gala 
2593fd47f06SBenjamin Herrenschmidt 		/* We assume all memory resources have the same offset */
2603fd47f06SBenjamin Herrenschmidt 		offset = hose->mem_offset[i];
2613fd47f06SBenjamin Herrenschmidt 		n = setup_one_atmu(pci, j, &hose->mem_resources[i], offset);
262a097a78cSTrent Piepho 
263a097a78cSTrent Piepho 		if (n < 0 || j >= 5) {
264a097a78cSTrent Piepho 			pr_err("Ran out of outbound PCI ATMUs for resource %d!\n", i);
265a097a78cSTrent Piepho 			hose->mem_resources[i].flags |= IORESOURCE_DISABLED;
266a097a78cSTrent Piepho 		} else
267a097a78cSTrent Piepho 			j += n;
26855c44991SRoy Zang 	}
26955c44991SRoy Zang 
27055c44991SRoy Zang 	/* Setup outbound IO window */
27155c44991SRoy Zang 	if (hose->io_resource.flags & IORESOURCE_IO) {
272a097a78cSTrent Piepho 		if (j >= 5) {
273a097a78cSTrent Piepho 			pr_err("Ran out of outbound PCI ATMUs for IO resource\n");
274a097a78cSTrent Piepho 		} else {
27572b122ccSKumar Gala 			pr_debug("PCI IO resource start 0x%016llx, size 0x%016llx, "
27672b122ccSKumar Gala 				 "phy base 0x%016llx.\n",
27772b122ccSKumar Gala 				 (u64)hose->io_resource.start,
27828f65c11SJoe Perches 				 (u64)resource_size(&hose->io_resource),
27972b122ccSKumar Gala 				 (u64)hose->io_base_phys);
280a097a78cSTrent Piepho 			out_be32(&pci->pow[j].potar, (hose->io_resource.start >> 12));
281a097a78cSTrent Piepho 			out_be32(&pci->pow[j].potear, 0);
282a097a78cSTrent Piepho 			out_be32(&pci->pow[j].powbar, (hose->io_base_phys >> 12));
28355c44991SRoy Zang 			/* Enable, IO R/W */
284a097a78cSTrent Piepho 			out_be32(&pci->pow[j].powar, 0x80088000
2852b4a8bd2SRoy Zang 				| (ilog2(hose->io_resource.end
2869ac4dd30SZang Roy-r61911 				- hose->io_resource.start + 1) - 1));
28755c44991SRoy Zang 		}
288a097a78cSTrent Piepho 	}
28955c44991SRoy Zang 
29054c18193SKumar Gala 	/* convert to pci address space */
2913fd47f06SBenjamin Herrenschmidt 	paddr_hi -= offset;
2923fd47f06SBenjamin Herrenschmidt 	paddr_lo -= offset;
293a097a78cSTrent Piepho 
29454c18193SKumar Gala 	if (paddr_hi == paddr_lo) {
295b7c670d6SRob Herring 		pr_err("%pOF: No outbound window space\n", hose->dn);
29604aa99cdSKevin Hao 		return;
29754c18193SKumar Gala 	}
29854c18193SKumar Gala 
29954c18193SKumar Gala 	if (paddr_lo == 0) {
300b7c670d6SRob Herring 		pr_err("%pOF: No space for inbound window\n", hose->dn);
30104aa99cdSKevin Hao 		return;
30254c18193SKumar Gala 	}
30354c18193SKumar Gala 
30454c18193SKumar Gala 	/* setup PCSRBAR/PEXCSRBAR */
30554c18193SKumar Gala 	early_write_config_dword(hose, 0, 0, PCI_BASE_ADDRESS_0, 0xffffffff);
30654c18193SKumar Gala 	early_read_config_dword(hose, 0, 0, PCI_BASE_ADDRESS_0, &pcicsrbar_sz);
30754c18193SKumar Gala 	pcicsrbar_sz = ~pcicsrbar_sz + 1;
30854c18193SKumar Gala 
30954c18193SKumar Gala 	if (paddr_hi < (0x100000000ull - pcicsrbar_sz) ||
31054c18193SKumar Gala 		(paddr_lo > 0x100000000ull))
31154c18193SKumar Gala 		pcicsrbar = 0x100000000ull - pcicsrbar_sz;
31254c18193SKumar Gala 	else
31354c18193SKumar Gala 		pcicsrbar = (paddr_lo - pcicsrbar_sz) & -pcicsrbar_sz;
31454c18193SKumar Gala 	early_write_config_dword(hose, 0, 0, PCI_BASE_ADDRESS_0, pcicsrbar);
31554c18193SKumar Gala 
31654c18193SKumar Gala 	paddr_lo = min(paddr_lo, (u64)pcicsrbar);
31754c18193SKumar Gala 
318b7c670d6SRob Herring 	pr_info("%pOF: PCICSRBAR @ 0x%x\n", hose->dn, pcicsrbar);
31954c18193SKumar Gala 
32054c18193SKumar Gala 	/* Setup inbound mem window */
32195f72d1eSYinghai Lu 	mem = memblock_end_of_DRAM();
3221930bb5cSScott Wood 	pr_info("%s: end of DRAM %llx\n", __func__, mem);
323446bc1ffSTimur Tabi 
324446bc1ffSTimur Tabi 	/*
325446bc1ffSTimur Tabi 	 * The msi-address-64 property, if it exists, indicates the physical
326446bc1ffSTimur Tabi 	 * address of the MSIIR register.  Normally, this register is located
327446bc1ffSTimur Tabi 	 * inside CCSR, so the ATMU that covers all of CCSR is used. But if
328446bc1ffSTimur Tabi 	 * this property exists, then we normally need to create a new ATMU
329446bc1ffSTimur Tabi 	 * for it.  For now, however, we cheat.  The only entity that creates
330446bc1ffSTimur Tabi 	 * this property is the Freescale hypervisor, and the address is
331446bc1ffSTimur Tabi 	 * specified in the partition configuration.  Typically, the address
332446bc1ffSTimur Tabi 	 * is located in the page immediately after the end of DDR.  If so, we
333446bc1ffSTimur Tabi 	 * can avoid allocating a new ATMU by extending the DDR ATMU by one
334446bc1ffSTimur Tabi 	 * page.
335446bc1ffSTimur Tabi 	 */
336446bc1ffSTimur Tabi 	reg = of_get_property(hose->dn, "msi-address-64", &len);
337446bc1ffSTimur Tabi 	if (reg && (len == sizeof(u64))) {
338446bc1ffSTimur Tabi 		u64 address = be64_to_cpup(reg);
339446bc1ffSTimur Tabi 
340446bc1ffSTimur Tabi 		if ((address >= mem) && (address < (mem + PAGE_SIZE))) {
341b7c670d6SRob Herring 			pr_info("%pOF: extending DDR ATMU to cover MSIIR", hose->dn);
342446bc1ffSTimur Tabi 			mem += PAGE_SIZE;
343446bc1ffSTimur Tabi 		} else {
344446bc1ffSTimur Tabi 			/* TODO: Create a new ATMU for MSIIR */
345b7c670d6SRob Herring 			pr_warn("%pOF: msi-address-64 address of %llx is "
346b7c670d6SRob Herring 				"unsupported\n", hose->dn, address);
347446bc1ffSTimur Tabi 		}
348446bc1ffSTimur Tabi 	}
349446bc1ffSTimur Tabi 
35054c18193SKumar Gala 	sz = min(mem, paddr_lo);
3512b4a8bd2SRoy Zang 	mem_log = ilog2(sz);
35254c18193SKumar Gala 
35354c18193SKumar Gala 	/* PCIe can overmap inbound & outbound since RX & TX are separated */
35454c18193SKumar Gala 	if (early_find_capability(hose, 0, 0, PCI_CAP_ID_EXP)) {
35554c18193SKumar Gala 		/* Size window to exact size if power-of-two or one size up */
35654c18193SKumar Gala 		if ((1ull << mem_log) != mem) {
3572d49c42aSKevin Hao 			mem_log++;
35854c18193SKumar Gala 			if ((1ull << mem_log) > mem)
359b7c670d6SRob Herring 				pr_info("%pOF: Setting PCI inbound window "
360b7c670d6SRob Herring 					"greater than memory size\n", hose->dn);
36154c18193SKumar Gala 		}
36254c18193SKumar Gala 
363f4154e16SPrabhakar Kushwaha 		piwar |= ((mem_log - 1) & PIWAR_SZ_MASK);
36454c18193SKumar Gala 
3651930bb5cSScott Wood 		if (setup_inbound) {
36654c18193SKumar Gala 			/* Setup inbound memory window */
36754c18193SKumar Gala 			out_be32(&pci->piw[win_idx].pitar,  0x00000000);
36854c18193SKumar Gala 			out_be32(&pci->piw[win_idx].piwbar, 0x00000000);
36954c18193SKumar Gala 			out_be32(&pci->piw[win_idx].piwar,  piwar);
3701930bb5cSScott Wood 		}
37154c18193SKumar Gala 
3721930bb5cSScott Wood 		win_idx--;
37389d93347SBecky Bruce 		hose->dma_window_base_cur = 0x00000000;
37454c18193SKumar Gala 		hose->dma_window_size = (resource_size_t)sz;
37596ea3b4aSKumar Gala 
37696ea3b4aSKumar Gala 		/*
37796ea3b4aSKumar Gala 		 * if we have >4G of memory setup second PCI inbound window to
37896ea3b4aSKumar Gala 		 * let devices that are 64-bit address capable to work w/o
37996ea3b4aSKumar Gala 		 * SWIOTLB and access the full range of memory
38096ea3b4aSKumar Gala 		 */
38196ea3b4aSKumar Gala 		if (sz != mem) {
3822b4a8bd2SRoy Zang 			mem_log = ilog2(mem);
38396ea3b4aSKumar Gala 
38496ea3b4aSKumar Gala 			/* Size window up if we dont fit in exact power-of-2 */
38596ea3b4aSKumar Gala 			if ((1ull << mem_log) != mem)
38696ea3b4aSKumar Gala 				mem_log++;
38796ea3b4aSKumar Gala 
38896ea3b4aSKumar Gala 			piwar = (piwar & ~PIWAR_SZ_MASK) | (mem_log - 1);
38963f1de88SScott Wood 			pci64_dma_offset = 1ULL << mem_log;
39096ea3b4aSKumar Gala 
3911930bb5cSScott Wood 			if (setup_inbound) {
39296ea3b4aSKumar Gala 				/* Setup inbound memory window */
39396ea3b4aSKumar Gala 				out_be32(&pci->piw[win_idx].pitar,  0x00000000);
39496ea3b4aSKumar Gala 				out_be32(&pci->piw[win_idx].piwbear,
39596ea3b4aSKumar Gala 						pci64_dma_offset >> 44);
39696ea3b4aSKumar Gala 				out_be32(&pci->piw[win_idx].piwbar,
39796ea3b4aSKumar Gala 						pci64_dma_offset >> 12);
39896ea3b4aSKumar Gala 				out_be32(&pci->piw[win_idx].piwar,  piwar);
3991930bb5cSScott Wood 			}
40096ea3b4aSKumar Gala 
40196ea3b4aSKumar Gala 			/*
40296ea3b4aSKumar Gala 			 * install our own dma_set_mask handler to fixup dma_ops
40396ea3b4aSKumar Gala 			 * and dma_offset
40496ea3b4aSKumar Gala 			 */
40596ea3b4aSKumar Gala 			ppc_md.dma_set_mask = fsl_pci_dma_set_mask;
40696ea3b4aSKumar Gala 
407b7c670d6SRob Herring 			pr_info("%pOF: Setup 64-bit PCI DMA window\n", hose->dn);
40896ea3b4aSKumar Gala 		}
40954c18193SKumar Gala 	} else {
41054c18193SKumar Gala 		u64 paddr = 0;
41154c18193SKumar Gala 
4121930bb5cSScott Wood 		if (setup_inbound) {
41354c18193SKumar Gala 			/* Setup inbound memory window */
41454c18193SKumar Gala 			out_be32(&pci->piw[win_idx].pitar,  paddr >> 12);
41554c18193SKumar Gala 			out_be32(&pci->piw[win_idx].piwbar, paddr >> 12);
4161930bb5cSScott Wood 			out_be32(&pci->piw[win_idx].piwar,
4171930bb5cSScott Wood 				 (piwar | (mem_log - 1)));
4181930bb5cSScott Wood 		}
41954c18193SKumar Gala 
4201930bb5cSScott Wood 		win_idx--;
42154c18193SKumar Gala 		paddr += 1ull << mem_log;
42254c18193SKumar Gala 		sz -= 1ull << mem_log;
42354c18193SKumar Gala 
42454c18193SKumar Gala 		if (sz) {
4252b4a8bd2SRoy Zang 			mem_log = ilog2(sz);
42654c18193SKumar Gala 			piwar |= (mem_log - 1);
42754c18193SKumar Gala 
4281930bb5cSScott Wood 			if (setup_inbound) {
4291930bb5cSScott Wood 				out_be32(&pci->piw[win_idx].pitar,
4301930bb5cSScott Wood 					 paddr >> 12);
4311930bb5cSScott Wood 				out_be32(&pci->piw[win_idx].piwbar,
4321930bb5cSScott Wood 					 paddr >> 12);
43354c18193SKumar Gala 				out_be32(&pci->piw[win_idx].piwar, piwar);
4341930bb5cSScott Wood 			}
43554c18193SKumar Gala 
4361930bb5cSScott Wood 			win_idx--;
43754c18193SKumar Gala 			paddr += 1ull << mem_log;
43854c18193SKumar Gala 		}
43954c18193SKumar Gala 
44054c18193SKumar Gala 		hose->dma_window_base_cur = 0x00000000;
44154c18193SKumar Gala 		hose->dma_window_size = (resource_size_t)paddr;
44254c18193SKumar Gala 	}
44354c18193SKumar Gala 
44454c18193SKumar Gala 	if (hose->dma_window_size < mem) {
445c45e9183SKevin Hao #ifdef CONFIG_SWIOTLB
446c45e9183SKevin Hao 		ppc_swiotlb_enable = 1;
447c45e9183SKevin Hao #else
448b7c670d6SRob Herring 		pr_err("%pOF: ERROR: Memory size exceeds PCI ATMU ability to "
44954c18193SKumar Gala 			"map - enable CONFIG_SWIOTLB to avoid dma errors.\n",
450b7c670d6SRob Herring 			 hose->dn);
45154c18193SKumar Gala #endif
45254c18193SKumar Gala 		/* adjusting outbound windows could reclaim space in mem map */
45354c18193SKumar Gala 		if (paddr_hi < 0xffffffffull)
454f2c2cbccSJoe Perches 			pr_warn("%pOF: WARNING: Outbound window cfg leaves "
45554c18193SKumar Gala 				"gaps in memory map. Adjusting the memory map "
45654c18193SKumar Gala 				"could reduce unnecessary bounce buffering.\n",
457b7c670d6SRob Herring 				hose->dn);
45854c18193SKumar Gala 
459b7c670d6SRob Herring 		pr_info("%pOF: DMA window size is 0x%llx\n", hose->dn,
46054c18193SKumar Gala 			(u64)hose->dma_window_size);
46154c18193SKumar Gala 	}
46255c44991SRoy Zang }
46355c44991SRoy Zang 
setup_pci_cmd(struct pci_controller * hose)464b7787805SMichael Ellerman static void setup_pci_cmd(struct pci_controller *hose)
46555c44991SRoy Zang {
46655c44991SRoy Zang 	u16 cmd;
467eb12af43SKumar Gala 	int cap_x;
468eb12af43SKumar Gala 
46955c44991SRoy Zang 	early_read_config_word(hose, 0, 0, PCI_COMMAND, &cmd);
47055c44991SRoy Zang 	cmd |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY
47155c44991SRoy Zang 		| PCI_COMMAND_IO;
47255c44991SRoy Zang 	early_write_config_word(hose, 0, 0, PCI_COMMAND, cmd);
473eb12af43SKumar Gala 
474eb12af43SKumar Gala 	cap_x = early_find_capability(hose, 0, 0, PCI_CAP_ID_PCIX);
475eb12af43SKumar Gala 	if (cap_x) {
476eb12af43SKumar Gala 		int pci_x_cmd = cap_x + PCI_X_CMD;
477eb12af43SKumar Gala 		cmd = PCI_X_CMD_MAX_SPLIT | PCI_X_CMD_MAX_READ
478eb12af43SKumar Gala 			| PCI_X_CMD_ERO | PCI_X_CMD_DPERR_E;
479eb12af43SKumar Gala 		early_write_config_word(hose, 0, 0, pci_x_cmd, cmd);
480eb12af43SKumar Gala 	} else {
48155c44991SRoy Zang 		early_write_config_byte(hose, 0, 0, PCI_LATENCY_TIMER, 0x80);
48255c44991SRoy Zang 	}
483eb12af43SKumar Gala }
48455c44991SRoy Zang 
fsl_pcibios_fixup_bus(struct pci_bus * bus)4856c0a11c1SKumar Gala void fsl_pcibios_fixup_bus(struct pci_bus *bus)
4866c0a11c1SKumar Gala {
4878206a110SKumar Gala 	struct pci_controller *hose = pci_bus_to_host(bus);
48813635dfdSBenjamin Herrenschmidt 	int i, is_pcie = 0, no_link;
4896c0a11c1SKumar Gala 
49013635dfdSBenjamin Herrenschmidt 	/* The root complex bridge comes up with bogus resources,
49113635dfdSBenjamin Herrenschmidt 	 * we copy the PHB ones in.
49213635dfdSBenjamin Herrenschmidt 	 *
49313635dfdSBenjamin Herrenschmidt 	 * With the current generic PCI code, the PHB bus no longer
49413635dfdSBenjamin Herrenschmidt 	 * has bus->resource[0..4] set, so things are a bit more
49513635dfdSBenjamin Herrenschmidt 	 * tricky.
49613635dfdSBenjamin Herrenschmidt 	 */
49713635dfdSBenjamin Herrenschmidt 
49813635dfdSBenjamin Herrenschmidt 	if (fsl_pcie_bus_fixup)
49913635dfdSBenjamin Herrenschmidt 		is_pcie = early_find_capability(hose, 0, 0, PCI_CAP_ID_EXP);
50013635dfdSBenjamin Herrenschmidt 	no_link = !!(hose->indirect_type & PPC_INDIRECT_TYPE_NO_PCIE_LINK);
50113635dfdSBenjamin Herrenschmidt 
50213635dfdSBenjamin Herrenschmidt 	if (bus->parent == hose->bus && (is_pcie || no_link)) {
50313635dfdSBenjamin Herrenschmidt 		for (i = 0; i < PCI_BRIDGE_RESOURCE_NUM; ++i) {
50472b122ccSKumar Gala 			struct resource *res = bus->resource[i];
50513635dfdSBenjamin Herrenschmidt 			struct resource *par;
50613635dfdSBenjamin Herrenschmidt 
50713635dfdSBenjamin Herrenschmidt 			if (!res)
50813635dfdSBenjamin Herrenschmidt 				continue;
50913635dfdSBenjamin Herrenschmidt 			if (i == 0)
51013635dfdSBenjamin Herrenschmidt 				par = &hose->io_resource;
51113635dfdSBenjamin Herrenschmidt 			else if (i < 4)
51213635dfdSBenjamin Herrenschmidt 				par = &hose->mem_resources[i-1];
51313635dfdSBenjamin Herrenschmidt 			else par = NULL;
51413635dfdSBenjamin Herrenschmidt 
51513635dfdSBenjamin Herrenschmidt 			res->start = par ? par->start : 0;
51613635dfdSBenjamin Herrenschmidt 			res->end   = par ? par->end   : 0;
51713635dfdSBenjamin Herrenschmidt 			res->flags = par ? par->flags : 0;
5186c0a11c1SKumar Gala 		}
5196c0a11c1SKumar Gala 	}
5206c0a11c1SKumar Gala }
5216c0a11c1SKumar Gala 
fsl_add_bridge(struct platform_device * pdev,int is_primary)5226960c53cSChristophe Leroy static int fsl_add_bridge(struct platform_device *pdev, int is_primary)
52355c44991SRoy Zang {
52455c44991SRoy Zang 	int len;
52555c44991SRoy Zang 	struct pci_controller *hose;
52655c44991SRoy Zang 	struct resource rsrc;
52755c44991SRoy Zang 	const int *bus_range;
52859c58c32SMinghuan Lian 	u8 hdr_type, progif;
5290c551abfSPali Rohár 	u32 class_code;
53052c5affcSVarun Sethi 	struct device_node *dev;
53134642bbbSKumar Gala 	struct ccsr_pci __iomem *pci;
532a8165d42Schenhui zhao 	u16 temp;
533a8165d42Schenhui zhao 	u32 svr = mfspr(SPRN_SVR);
53452c5affcSVarun Sethi 
53552c5affcSVarun Sethi 	dev = pdev->dev.of_node;
53655c44991SRoy Zang 
537ef1fd2dfSPrabhakar Kushwaha 	if (!of_device_is_available(dev)) {
538f2c2cbccSJoe Perches 		pr_warn("%pOF: disabled\n", dev);
539ef1fd2dfSPrabhakar Kushwaha 		return -ENODEV;
540ef1fd2dfSPrabhakar Kushwaha 	}
541ef1fd2dfSPrabhakar Kushwaha 
542b7c670d6SRob Herring 	pr_debug("Adding PCI host bridge %pOF\n", dev);
54355c44991SRoy Zang 
54455c44991SRoy Zang 	/* Fetch host bridge registers address */
5459ac4dd30SZang Roy-r61911 	if (of_address_to_resource(dev, 0, &rsrc)) {
5469ac4dd30SZang Roy-r61911 		printk(KERN_WARNING "Can't get pci register base!");
5479ac4dd30SZang Roy-r61911 		return -ENOMEM;
5489ac4dd30SZang Roy-r61911 	}
54955c44991SRoy Zang 
55055c44991SRoy Zang 	/* Get bus range if any */
55155c44991SRoy Zang 	bus_range = of_get_property(dev, "bus-range", &len);
55255c44991SRoy Zang 	if (bus_range == NULL || len < 2 * sizeof(int))
553b7c670d6SRob Herring 		printk(KERN_WARNING "Can't get bus-range for %pOF, assume"
554b7c670d6SRob Herring 			" bus 0\n", dev);
55555c44991SRoy Zang 
5560e47ff1cSRob Herring 	pci_add_flags(PCI_REASSIGN_ALL_BUS);
55755c44991SRoy Zang 	hose = pcibios_alloc_controller(dev);
55855c44991SRoy Zang 	if (!hose)
55955c44991SRoy Zang 		return -ENOMEM;
56055c44991SRoy Zang 
56152c5affcSVarun Sethi 	/* set platform device as the parent */
56252c5affcSVarun Sethi 	hose->parent = &pdev->dev;
56355c44991SRoy Zang 	hose->first_busno = bus_range ? bus_range[0] : 0x0;
56455c44991SRoy Zang 	hose->last_busno = bus_range ? bus_range[1] : 0xff;
56555c44991SRoy Zang 
56634642bbbSKumar Gala 	pr_debug("PCI memory map start 0x%016llx, size 0x%016llx\n",
56734642bbbSKumar Gala 		 (u64)rsrc.start, (u64)resource_size(&rsrc));
56834642bbbSKumar Gala 
56934642bbbSKumar Gala 	pci = hose->private_data = ioremap(rsrc.start, resource_size(&rsrc));
57034642bbbSKumar Gala 	if (!hose->private_data)
57134642bbbSKumar Gala 		goto no_bridge;
57234642bbbSKumar Gala 
573b37e1613SRojhalat Ibrahim 	setup_indirect_pci(hose, rsrc.start, rsrc.start + 0x4,
5742e56ff20SKumar Gala 			   PPC_INDIRECT_TYPE_BIG_ENDIAN);
57508871c09SPrabhakar Kushwaha 
57634642bbbSKumar Gala 	if (in_be32(&pci->block_rev1) < PCIE_IP_REV_3_0)
57734642bbbSKumar Gala 		hose->indirect_type |= PPC_INDIRECT_TYPE_FSL_CFG_REG_LINK;
57834642bbbSKumar Gala 
57959c58c32SMinghuan Lian 	if (early_find_capability(hose, 0, 0, PCI_CAP_ID_EXP)) {
580b37e1613SRojhalat Ibrahim 		/* use fsl_indirect_read_config for PCIe */
581b37e1613SRojhalat Ibrahim 		hose->ops = &fsl_indirect_pcie_ops;
582446957baSAdam Buchbinder 		/* For PCIE read HEADER_TYPE to identify controller mode */
58359c58c32SMinghuan Lian 		early_read_config_byte(hose, 0, 0, PCI_HEADER_TYPE, &hdr_type);
58459c58c32SMinghuan Lian 		if ((hdr_type & 0x7f) != PCI_HEADER_TYPE_BRIDGE)
58559c58c32SMinghuan Lian 			goto no_bridge;
58659c58c32SMinghuan Lian 
58759c58c32SMinghuan Lian 	} else {
58859c58c32SMinghuan Lian 		/* For PCI read PROG to identify controller mode */
58908871c09SPrabhakar Kushwaha 		early_read_config_byte(hose, 0, 0, PCI_CLASS_PROG, &progif);
59000406e87SAaron Sierra 		if ((progif & 1) &&
59100406e87SAaron Sierra 		    !of_property_read_bool(dev, "fsl,pci-agent-force-enum"))
59259c58c32SMinghuan Lian 			goto no_bridge;
59308871c09SPrabhakar Kushwaha 	}
59408871c09SPrabhakar Kushwaha 
5959ac4dd30SZang Roy-r61911 	setup_pci_cmd(hose);
5969ac4dd30SZang Roy-r61911 
5979ac4dd30SZang Roy-r61911 	/* check PCI express link status */
598957ecffcSKumar Gala 	if (early_find_capability(hose, 0, 0, PCI_CAP_ID_EXP)) {
5997659c038SKumar Gala 		hose->indirect_type |= PPC_INDIRECT_TYPE_EXT_REG |
600957ecffcSKumar Gala 			PPC_INDIRECT_TYPE_SURPRESS_PRIMARY_BUS;
60134642bbbSKumar Gala 		if (fsl_pcie_check_link(hose))
602957ecffcSKumar Gala 			hose->indirect_type |= PPC_INDIRECT_TYPE_NO_PCIE_LINK;
6030c551abfSPali Rohár 		/* Fix Class Code to PCI_CLASS_BRIDGE_PCI_NORMAL for pre-3.0 controller */
6040c551abfSPali Rohár 		if (in_be32(&pci->block_rev1) < PCIE_IP_REV_3_0) {
6050c551abfSPali Rohár 			early_read_config_dword(hose, 0, 0, PCIE_FSL_CSR_CLASSCODE, &class_code);
6060c551abfSPali Rohár 			class_code &= 0xff;
6070c551abfSPali Rohár 			class_code |= PCI_CLASS_BRIDGE_PCI_NORMAL << 8;
6080c551abfSPali Rohár 			early_write_config_dword(hose, 0, 0, PCIE_FSL_CSR_CLASSCODE, class_code);
6090c551abfSPali Rohár 		}
610a8165d42Schenhui zhao 	} else {
611a8165d42Schenhui zhao 		/*
612a8165d42Schenhui zhao 		 * Set PBFR(PCI Bus Function Register)[10] = 1 to
613a8165d42Schenhui zhao 		 * disable the combining of crossing cacheline
614a8165d42Schenhui zhao 		 * boundary requests into one burst transaction.
615a8165d42Schenhui zhao 		 * PCI-X operation is not affected.
616a8165d42Schenhui zhao 		 * Fix erratum PCI 5 on MPC8548
617a8165d42Schenhui zhao 		 */
618a8165d42Schenhui zhao #define PCI_BUS_FUNCTION 0x44
619a8165d42Schenhui zhao #define PCI_BUS_FUNCTION_MDS 0x400	/* Master disable streaming */
620a8165d42Schenhui zhao 		if (((SVR_SOC_VER(svr) == SVR_8543) ||
621a8165d42Schenhui zhao 		     (SVR_SOC_VER(svr) == SVR_8545) ||
622a8165d42Schenhui zhao 		     (SVR_SOC_VER(svr) == SVR_8547) ||
623a8165d42Schenhui zhao 		     (SVR_SOC_VER(svr) == SVR_8548)) &&
624a8165d42Schenhui zhao 		    !early_find_capability(hose, 0, 0, PCI_CAP_ID_PCIX)) {
625a8165d42Schenhui zhao 			early_read_config_word(hose, 0, 0,
626a8165d42Schenhui zhao 					PCI_BUS_FUNCTION, &temp);
627a8165d42Schenhui zhao 			temp |= PCI_BUS_FUNCTION_MDS;
628a8165d42Schenhui zhao 			early_write_config_word(hose, 0, 0,
629a8165d42Schenhui zhao 					PCI_BUS_FUNCTION, temp);
630a8165d42Schenhui zhao 		}
631957ecffcSKumar Gala 	}
63255c44991SRoy Zang 
6339ac4dd30SZang Roy-r61911 	printk(KERN_INFO "Found FSL PCI host bridge at 0x%016llx. "
63455c44991SRoy Zang 		"Firmware bus number: %d->%d\n",
6359ac4dd30SZang Roy-r61911 		(unsigned long long)rsrc.start, hose->first_busno,
6369ac4dd30SZang Roy-r61911 		hose->last_busno);
63755c44991SRoy Zang 
6389ac4dd30SZang Roy-r61911 	pr_debug(" ->Hose at 0x%p, cfg_addr=0x%p,cfg_data=0x%p\n",
63955c44991SRoy Zang 		hose, hose->cfg_addr, hose->cfg_data);
64055c44991SRoy Zang 
64155c44991SRoy Zang 	/* Interpret the "ranges" property */
64255c44991SRoy Zang 	/* This also maps the I/O region and sets isa_io/mem_base */
6439ac4dd30SZang Roy-r61911 	pci_process_bridge_OF_ranges(hose, dev, is_primary);
64455c44991SRoy Zang 
64555c44991SRoy Zang 	/* Setup PEX window registers */
64634642bbbSKumar Gala 	setup_pci_atmu(hose);
64755c44991SRoy Zang 
64897884e00SDaniel Axtens 	/* Set up controller operations */
64997884e00SDaniel Axtens 	setup_swiotlb_ops(hose);
65097884e00SDaniel Axtens 
65155c44991SRoy Zang 	return 0;
65259c58c32SMinghuan Lian 
65359c58c32SMinghuan Lian no_bridge:
65434642bbbSKumar Gala 	iounmap(hose->private_data);
65559c58c32SMinghuan Lian 	/* unmap cfg_data & cfg_addr separately if not on same page */
65659c58c32SMinghuan Lian 	if (((unsigned long)hose->cfg_data & PAGE_MASK) !=
65759c58c32SMinghuan Lian 	    ((unsigned long)hose->cfg_addr & PAGE_MASK))
65859c58c32SMinghuan Lian 		iounmap(hose->cfg_data);
65959c58c32SMinghuan Lian 	iounmap(hose->cfg_addr);
66059c58c32SMinghuan Lian 	pcibios_free_controller(hose);
66159c58c32SMinghuan Lian 	return -ENODEV;
66255c44991SRoy Zang }
6635753c082SKumar Gala #endif /* CONFIG_FSL_SOC_BOOKE || CONFIG_PPC_86xx */
66476fe1ffcSJohn Rigby 
665bbd234b1SChunhe Lan DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_FREESCALE, PCI_ANY_ID,
666bbd234b1SChunhe Lan 			quirk_fsl_pcie_early);
667598804cdSAnton Vorontsov 
668470788d4SKumar Gala #if defined(CONFIG_PPC_83xx) || defined(CONFIG_PPC_MPC512x)
669598804cdSAnton Vorontsov struct mpc83xx_pcie_priv {
670598804cdSAnton Vorontsov 	void __iomem *cfg_type0;
671598804cdSAnton Vorontsov 	void __iomem *cfg_type1;
672598804cdSAnton Vorontsov 	u32 dev_base;
673598804cdSAnton Vorontsov };
674598804cdSAnton Vorontsov 
675b8f44ec2SKumar Gala struct pex_inbound_window {
676b8f44ec2SKumar Gala 	u32 ar;
677b8f44ec2SKumar Gala 	u32 tar;
678b8f44ec2SKumar Gala 	u32 barl;
679b8f44ec2SKumar Gala 	u32 barh;
680b8f44ec2SKumar Gala };
681b8f44ec2SKumar Gala 
682598804cdSAnton Vorontsov /*
683598804cdSAnton Vorontsov  * With the convention of u-boot, the PCIE outbound window 0 serves
684598804cdSAnton Vorontsov  * as configuration transactions outbound.
685598804cdSAnton Vorontsov  */
686598804cdSAnton Vorontsov #define PEX_OUTWIN0_BAR		0xCA4
687598804cdSAnton Vorontsov #define PEX_OUTWIN0_TAL		0xCA8
688598804cdSAnton Vorontsov #define PEX_OUTWIN0_TAH		0xCAC
689b8f44ec2SKumar Gala #define PEX_RC_INWIN_BASE	0xE60
690b8f44ec2SKumar Gala #define PEX_RCIWARn_EN		0x1
691598804cdSAnton Vorontsov 
mpc83xx_pcie_exclude_device(struct pci_bus * bus,unsigned int devfn)692598804cdSAnton Vorontsov static int mpc83xx_pcie_exclude_device(struct pci_bus *bus, unsigned int devfn)
693598804cdSAnton Vorontsov {
6948206a110SKumar Gala 	struct pci_controller *hose = pci_bus_to_host(bus);
695598804cdSAnton Vorontsov 
696598804cdSAnton Vorontsov 	if (hose->indirect_type & PPC_INDIRECT_TYPE_NO_PCIE_LINK)
697598804cdSAnton Vorontsov 		return PCIBIOS_DEVICE_NOT_FOUND;
698598804cdSAnton Vorontsov 	/*
699598804cdSAnton Vorontsov 	 * Workaround for the HW bug: for Type 0 configure transactions the
700598804cdSAnton Vorontsov 	 * PCI-E controller does not check the device number bits and just
701598804cdSAnton Vorontsov 	 * assumes that the device number bits are 0.
702598804cdSAnton Vorontsov 	 */
703598804cdSAnton Vorontsov 	if (bus->number == hose->first_busno ||
704598804cdSAnton Vorontsov 			bus->primary == hose->first_busno) {
705598804cdSAnton Vorontsov 		if (devfn & 0xf8)
706598804cdSAnton Vorontsov 			return PCIBIOS_DEVICE_NOT_FOUND;
707598804cdSAnton Vorontsov 	}
708598804cdSAnton Vorontsov 
709598804cdSAnton Vorontsov 	if (ppc_md.pci_exclude_device) {
710598804cdSAnton Vorontsov 		if (ppc_md.pci_exclude_device(hose, bus->number, devfn))
711598804cdSAnton Vorontsov 			return PCIBIOS_DEVICE_NOT_FOUND;
712598804cdSAnton Vorontsov 	}
713598804cdSAnton Vorontsov 
714598804cdSAnton Vorontsov 	return PCIBIOS_SUCCESSFUL;
715598804cdSAnton Vorontsov }
716598804cdSAnton Vorontsov 
mpc83xx_pcie_remap_cfg(struct pci_bus * bus,unsigned int devfn,int offset)717598804cdSAnton Vorontsov static void __iomem *mpc83xx_pcie_remap_cfg(struct pci_bus *bus,
718598804cdSAnton Vorontsov 					    unsigned int devfn, int offset)
719598804cdSAnton Vorontsov {
7208206a110SKumar Gala 	struct pci_controller *hose = pci_bus_to_host(bus);
721598804cdSAnton Vorontsov 	struct mpc83xx_pcie_priv *pcie = hose->dn->data;
722f93611faSAnton Vorontsov 	u32 dev_base = bus->number << 24 | devfn << 16;
723598804cdSAnton Vorontsov 	int ret;
724598804cdSAnton Vorontsov 
725598804cdSAnton Vorontsov 	ret = mpc83xx_pcie_exclude_device(bus, devfn);
726598804cdSAnton Vorontsov 	if (ret)
727598804cdSAnton Vorontsov 		return NULL;
728598804cdSAnton Vorontsov 
729598804cdSAnton Vorontsov 	offset &= 0xfff;
730598804cdSAnton Vorontsov 
731598804cdSAnton Vorontsov 	/* Type 0 */
732598804cdSAnton Vorontsov 	if (bus->number == hose->first_busno)
733598804cdSAnton Vorontsov 		return pcie->cfg_type0 + offset;
734598804cdSAnton Vorontsov 
735598804cdSAnton Vorontsov 	if (pcie->dev_base == dev_base)
736598804cdSAnton Vorontsov 		goto mapped;
737598804cdSAnton Vorontsov 
738598804cdSAnton Vorontsov 	out_le32(pcie->cfg_type0 + PEX_OUTWIN0_TAL, dev_base);
739598804cdSAnton Vorontsov 
740598804cdSAnton Vorontsov 	pcie->dev_base = dev_base;
741598804cdSAnton Vorontsov mapped:
742598804cdSAnton Vorontsov 	return pcie->cfg_type1 + offset;
743598804cdSAnton Vorontsov }
744598804cdSAnton Vorontsov 
mpc83xx_pcie_write_config(struct pci_bus * bus,unsigned int devfn,int offset,int len,u32 val)745598804cdSAnton Vorontsov static int mpc83xx_pcie_write_config(struct pci_bus *bus, unsigned int devfn,
746598804cdSAnton Vorontsov 				     int offset, int len, u32 val)
747598804cdSAnton Vorontsov {
748f93611faSAnton Vorontsov 	struct pci_controller *hose = pci_bus_to_host(bus);
749598804cdSAnton Vorontsov 
750f93611faSAnton Vorontsov 	/* PPC_INDIRECT_TYPE_SURPRESS_PRIMARY_BUS */
751f93611faSAnton Vorontsov 	if (offset == PCI_PRIMARY_BUS && bus->number == hose->first_busno)
752f93611faSAnton Vorontsov 		val &= 0xffffff00;
753f93611faSAnton Vorontsov 
754933d275fSRob Herring 	return pci_generic_config_write(bus, devfn, offset, len, val);
755598804cdSAnton Vorontsov }
756598804cdSAnton Vorontsov 
757598804cdSAnton Vorontsov static struct pci_ops mpc83xx_pcie_ops = {
758933d275fSRob Herring 	.map_bus = mpc83xx_pcie_remap_cfg,
759933d275fSRob Herring 	.read = pci_generic_config_read,
760598804cdSAnton Vorontsov 	.write = mpc83xx_pcie_write_config,
761598804cdSAnton Vorontsov };
762598804cdSAnton Vorontsov 
mpc83xx_pcie_setup(struct pci_controller * hose,struct resource * reg)763598804cdSAnton Vorontsov static int __init mpc83xx_pcie_setup(struct pci_controller *hose,
764598804cdSAnton Vorontsov 				     struct resource *reg)
765598804cdSAnton Vorontsov {
766598804cdSAnton Vorontsov 	struct mpc83xx_pcie_priv *pcie;
767598804cdSAnton Vorontsov 	u32 cfg_bar;
768598804cdSAnton Vorontsov 	int ret = -ENOMEM;
769598804cdSAnton Vorontsov 
770*fabdb27dSMichael Ellerman 	pcie = kzalloc(sizeof(*pcie), GFP_KERNEL);
771598804cdSAnton Vorontsov 	if (!pcie)
772598804cdSAnton Vorontsov 		return ret;
773598804cdSAnton Vorontsov 
774598804cdSAnton Vorontsov 	pcie->cfg_type0 = ioremap(reg->start, resource_size(reg));
775598804cdSAnton Vorontsov 	if (!pcie->cfg_type0)
776598804cdSAnton Vorontsov 		goto err0;
777598804cdSAnton Vorontsov 
778598804cdSAnton Vorontsov 	cfg_bar = in_le32(pcie->cfg_type0 + PEX_OUTWIN0_BAR);
779598804cdSAnton Vorontsov 	if (!cfg_bar) {
780598804cdSAnton Vorontsov 		/* PCI-E isn't configured. */
781598804cdSAnton Vorontsov 		ret = -ENODEV;
782598804cdSAnton Vorontsov 		goto err1;
783598804cdSAnton Vorontsov 	}
784598804cdSAnton Vorontsov 
785598804cdSAnton Vorontsov 	pcie->cfg_type1 = ioremap(cfg_bar, 0x1000);
786598804cdSAnton Vorontsov 	if (!pcie->cfg_type1)
787598804cdSAnton Vorontsov 		goto err1;
788598804cdSAnton Vorontsov 
789598804cdSAnton Vorontsov 	WARN_ON(hose->dn->data);
790598804cdSAnton Vorontsov 	hose->dn->data = pcie;
791598804cdSAnton Vorontsov 	hose->ops = &mpc83xx_pcie_ops;
79234642bbbSKumar Gala 	hose->indirect_type |= PPC_INDIRECT_TYPE_FSL_CFG_REG_LINK;
793598804cdSAnton Vorontsov 
794598804cdSAnton Vorontsov 	out_le32(pcie->cfg_type0 + PEX_OUTWIN0_TAH, 0);
795598804cdSAnton Vorontsov 	out_le32(pcie->cfg_type0 + PEX_OUTWIN0_TAL, 0);
796598804cdSAnton Vorontsov 
79734642bbbSKumar Gala 	if (fsl_pcie_check_link(hose))
798598804cdSAnton Vorontsov 		hose->indirect_type |= PPC_INDIRECT_TYPE_NO_PCIE_LINK;
799598804cdSAnton Vorontsov 
800598804cdSAnton Vorontsov 	return 0;
801598804cdSAnton Vorontsov err1:
802598804cdSAnton Vorontsov 	iounmap(pcie->cfg_type0);
803598804cdSAnton Vorontsov err0:
804598804cdSAnton Vorontsov 	kfree(pcie);
805598804cdSAnton Vorontsov 	return ret;
806598804cdSAnton Vorontsov 
807598804cdSAnton Vorontsov }
808598804cdSAnton Vorontsov 
mpc83xx_add_bridge(struct device_node * dev)80976fe1ffcSJohn Rigby int __init mpc83xx_add_bridge(struct device_node *dev)
81076fe1ffcSJohn Rigby {
811598804cdSAnton Vorontsov 	int ret;
81276fe1ffcSJohn Rigby 	int len;
81376fe1ffcSJohn Rigby 	struct pci_controller *hose;
8145b70a097SJohn Rigby 	struct resource rsrc_reg;
8155b70a097SJohn Rigby 	struct resource rsrc_cfg;
81676fe1ffcSJohn Rigby 	const int *bus_range;
8175b70a097SJohn Rigby 	int primary;
81876fe1ffcSJohn Rigby 
819b8f44ec2SKumar Gala 	is_mpc83xx_pci = 1;
820b8f44ec2SKumar Gala 
821598804cdSAnton Vorontsov 	if (!of_device_is_available(dev)) {
822f2c2cbccSJoe Perches 		pr_warn("%pOF: disabled by the firmware.\n",
823b7c670d6SRob Herring 			dev);
824598804cdSAnton Vorontsov 		return -ENODEV;
825598804cdSAnton Vorontsov 	}
826b7c670d6SRob Herring 	pr_debug("Adding PCI host bridge %pOF\n", dev);
82776fe1ffcSJohn Rigby 
82876fe1ffcSJohn Rigby 	/* Fetch host bridge registers address */
8295b70a097SJohn Rigby 	if (of_address_to_resource(dev, 0, &rsrc_reg)) {
8305b70a097SJohn Rigby 		printk(KERN_WARNING "Can't get pci register base!\n");
8315b70a097SJohn Rigby 		return -ENOMEM;
8325b70a097SJohn Rigby 	}
8335b70a097SJohn Rigby 
8345b70a097SJohn Rigby 	memset(&rsrc_cfg, 0, sizeof(rsrc_cfg));
8355b70a097SJohn Rigby 
8365b70a097SJohn Rigby 	if (of_address_to_resource(dev, 1, &rsrc_cfg)) {
8375b70a097SJohn Rigby 		printk(KERN_WARNING
8385b70a097SJohn Rigby 			"No pci config register base in dev tree, "
8395b70a097SJohn Rigby 			"using default\n");
8405b70a097SJohn Rigby 		/*
8415b70a097SJohn Rigby 		 * MPC83xx supports up to two host controllers
8425b70a097SJohn Rigby 		 * 	one at 0x8500 has config space registers at 0x8300
8435b70a097SJohn Rigby 		 * 	one at 0x8600 has config space registers at 0x8380
8445b70a097SJohn Rigby 		 */
8455b70a097SJohn Rigby 		if ((rsrc_reg.start & 0xfffff) == 0x8500)
8465b70a097SJohn Rigby 			rsrc_cfg.start = (rsrc_reg.start & 0xfff00000) + 0x8300;
8475b70a097SJohn Rigby 		else if ((rsrc_reg.start & 0xfffff) == 0x8600)
8485b70a097SJohn Rigby 			rsrc_cfg.start = (rsrc_reg.start & 0xfff00000) + 0x8380;
8495b70a097SJohn Rigby 	}
8505b70a097SJohn Rigby 	/*
8515b70a097SJohn Rigby 	 * Controller at offset 0x8500 is primary
8525b70a097SJohn Rigby 	 */
8535b70a097SJohn Rigby 	if ((rsrc_reg.start & 0xfffff) == 0x8500)
8545b70a097SJohn Rigby 		primary = 1;
8555b70a097SJohn Rigby 	else
8565b70a097SJohn Rigby 		primary = 0;
85776fe1ffcSJohn Rigby 
85876fe1ffcSJohn Rigby 	/* Get bus range if any */
85976fe1ffcSJohn Rigby 	bus_range = of_get_property(dev, "bus-range", &len);
86076fe1ffcSJohn Rigby 	if (bus_range == NULL || len < 2 * sizeof(int)) {
861b7c670d6SRob Herring 		printk(KERN_WARNING "Can't get bus-range for %pOF, assume"
862b7c670d6SRob Herring 		       " bus 0\n", dev);
86376fe1ffcSJohn Rigby 	}
86476fe1ffcSJohn Rigby 
8650e47ff1cSRob Herring 	pci_add_flags(PCI_REASSIGN_ALL_BUS);
86676fe1ffcSJohn Rigby 	hose = pcibios_alloc_controller(dev);
86776fe1ffcSJohn Rigby 	if (!hose)
86876fe1ffcSJohn Rigby 		return -ENOMEM;
86976fe1ffcSJohn Rigby 
87076fe1ffcSJohn Rigby 	hose->first_busno = bus_range ? bus_range[0] : 0;
87176fe1ffcSJohn Rigby 	hose->last_busno = bus_range ? bus_range[1] : 0xff;
87276fe1ffcSJohn Rigby 
873598804cdSAnton Vorontsov 	if (of_device_is_compatible(dev, "fsl,mpc8314-pcie")) {
874598804cdSAnton Vorontsov 		ret = mpc83xx_pcie_setup(hose, &rsrc_reg);
875598804cdSAnton Vorontsov 		if (ret)
876598804cdSAnton Vorontsov 			goto err0;
877598804cdSAnton Vorontsov 	} else {
878b37e1613SRojhalat Ibrahim 		setup_indirect_pci(hose, rsrc_cfg.start,
879598804cdSAnton Vorontsov 				   rsrc_cfg.start + 4, 0);
880598804cdSAnton Vorontsov 	}
88176fe1ffcSJohn Rigby 
88235225802SJohn Rigby 	printk(KERN_INFO "Found FSL PCI host bridge at 0x%016llx. "
88376fe1ffcSJohn Rigby 	       "Firmware bus number: %d->%d\n",
8845b70a097SJohn Rigby 	       (unsigned long long)rsrc_reg.start, hose->first_busno,
88576fe1ffcSJohn Rigby 	       hose->last_busno);
88676fe1ffcSJohn Rigby 
88776fe1ffcSJohn Rigby 	pr_debug(" ->Hose at 0x%p, cfg_addr=0x%p,cfg_data=0x%p\n",
88876fe1ffcSJohn Rigby 	    hose, hose->cfg_addr, hose->cfg_data);
88976fe1ffcSJohn Rigby 
89076fe1ffcSJohn Rigby 	/* Interpret the "ranges" property */
89176fe1ffcSJohn Rigby 	/* This also maps the I/O region and sets isa_io/mem_base */
89276fe1ffcSJohn Rigby 	pci_process_bridge_OF_ranges(hose, dev, primary);
89376fe1ffcSJohn Rigby 
89476fe1ffcSJohn Rigby 	return 0;
895598804cdSAnton Vorontsov err0:
896598804cdSAnton Vorontsov 	pcibios_free_controller(hose);
897598804cdSAnton Vorontsov 	return ret;
89876fe1ffcSJohn Rigby }
89976fe1ffcSJohn Rigby #endif /* CONFIG_PPC_83xx */
900b8f44ec2SKumar Gala 
fsl_pci_immrbar_base(struct pci_controller * hose)901b8f44ec2SKumar Gala u64 fsl_pci_immrbar_base(struct pci_controller *hose)
902b8f44ec2SKumar Gala {
903b8f44ec2SKumar Gala #ifdef CONFIG_PPC_83xx
904b8f44ec2SKumar Gala 	if (is_mpc83xx_pci) {
905b8f44ec2SKumar Gala 		struct mpc83xx_pcie_priv *pcie = hose->dn->data;
906b8f44ec2SKumar Gala 		struct pex_inbound_window *in;
907b8f44ec2SKumar Gala 		int i;
908b8f44ec2SKumar Gala 
909b8f44ec2SKumar Gala 		/* Walk the Root Complex Inbound windows to match IMMR base */
910b8f44ec2SKumar Gala 		in = pcie->cfg_type0 + PEX_RC_INWIN_BASE;
911b8f44ec2SKumar Gala 		for (i = 0; i < 4; i++) {
912b8f44ec2SKumar Gala 			/* not enabled, skip */
9133894817fSHimangi Saraogi 			if (!(in_le32(&in[i].ar) & PEX_RCIWARn_EN))
914b8f44ec2SKumar Gala 				continue;
915b8f44ec2SKumar Gala 
916b8f44ec2SKumar Gala 			if (get_immrbase() == in_le32(&in[i].tar))
917b8f44ec2SKumar Gala 				return (u64)in_le32(&in[i].barh) << 32 |
918b8f44ec2SKumar Gala 					    in_le32(&in[i].barl);
919b8f44ec2SKumar Gala 		}
920b8f44ec2SKumar Gala 
921b8f44ec2SKumar Gala 		printk(KERN_WARNING "could not find PCI BAR matching IMMR\n");
922b8f44ec2SKumar Gala 	}
923b8f44ec2SKumar Gala #endif
924b8f44ec2SKumar Gala 
925b8f44ec2SKumar Gala #if defined(CONFIG_FSL_SOC_BOOKE) || defined(CONFIG_PPC_86xx)
926b8f44ec2SKumar Gala 	if (!is_mpc83xx_pci) {
927b8f44ec2SKumar Gala 		u32 base;
928b8f44ec2SKumar Gala 
929b8f44ec2SKumar Gala 		pci_bus_read_config_dword(hose->bus,
930b8f44ec2SKumar Gala 			PCI_DEVFN(0, 0), PCI_BASE_ADDRESS_0, &base);
931a424b97bSMinghuan Lian 
932a424b97bSMinghuan Lian 		/*
933a424b97bSMinghuan Lian 		 * For PEXCSRBAR, bit 3-0 indicate prefetchable and
934a424b97bSMinghuan Lian 		 * address type. So when getting base address, these
935a424b97bSMinghuan Lian 		 * bits should be masked
936a424b97bSMinghuan Lian 		 */
937a424b97bSMinghuan Lian 		base &= PCI_BASE_ADDRESS_MEM_MASK;
938a424b97bSMinghuan Lian 
939b8f44ec2SKumar Gala 		return base;
940b8f44ec2SKumar Gala 	}
941b8f44ec2SKumar Gala #endif
942b8f44ec2SKumar Gala 
943b8f44ec2SKumar Gala 	return 0;
944b8f44ec2SKumar Gala }
94507e4f801SScott Wood 
946688de017SChristophe Leroy #ifdef CONFIG_PPC_E500
mcheck_handle_load(struct pt_regs * regs,u32 inst)9474e0e3435SHongtao Jia static int mcheck_handle_load(struct pt_regs *regs, u32 inst)
9484e0e3435SHongtao Jia {
9494e0e3435SHongtao Jia 	unsigned int rd, ra, rb, d;
9504e0e3435SHongtao Jia 
9514e0e3435SHongtao Jia 	rd = get_rt(inst);
9524e0e3435SHongtao Jia 	ra = get_ra(inst);
9534e0e3435SHongtao Jia 	rb = get_rb(inst);
9544e0e3435SHongtao Jia 	d = get_d(inst);
9554e0e3435SHongtao Jia 
9564e0e3435SHongtao Jia 	switch (get_op(inst)) {
9574e0e3435SHongtao Jia 	case 31:
9584e0e3435SHongtao Jia 		switch (get_xop(inst)) {
9594e0e3435SHongtao Jia 		case OP_31_XOP_LWZX:
9604e0e3435SHongtao Jia 		case OP_31_XOP_LWBRX:
9614e0e3435SHongtao Jia 			regs->gpr[rd] = 0xffffffff;
9624e0e3435SHongtao Jia 			break;
9634e0e3435SHongtao Jia 
9644e0e3435SHongtao Jia 		case OP_31_XOP_LWZUX:
9654e0e3435SHongtao Jia 			regs->gpr[rd] = 0xffffffff;
9664e0e3435SHongtao Jia 			regs->gpr[ra] += regs->gpr[rb];
9674e0e3435SHongtao Jia 			break;
9684e0e3435SHongtao Jia 
9694e0e3435SHongtao Jia 		case OP_31_XOP_LBZX:
9704e0e3435SHongtao Jia 			regs->gpr[rd] = 0xff;
9714e0e3435SHongtao Jia 			break;
9724e0e3435SHongtao Jia 
9734e0e3435SHongtao Jia 		case OP_31_XOP_LBZUX:
9744e0e3435SHongtao Jia 			regs->gpr[rd] = 0xff;
9754e0e3435SHongtao Jia 			regs->gpr[ra] += regs->gpr[rb];
9764e0e3435SHongtao Jia 			break;
9774e0e3435SHongtao Jia 
9784e0e3435SHongtao Jia 		case OP_31_XOP_LHZX:
9794e0e3435SHongtao Jia 		case OP_31_XOP_LHBRX:
9804e0e3435SHongtao Jia 			regs->gpr[rd] = 0xffff;
9814e0e3435SHongtao Jia 			break;
9824e0e3435SHongtao Jia 
9834e0e3435SHongtao Jia 		case OP_31_XOP_LHZUX:
9844e0e3435SHongtao Jia 			regs->gpr[rd] = 0xffff;
9854e0e3435SHongtao Jia 			regs->gpr[ra] += regs->gpr[rb];
9864e0e3435SHongtao Jia 			break;
9874e0e3435SHongtao Jia 
9884e0e3435SHongtao Jia 		case OP_31_XOP_LHAX:
9894e0e3435SHongtao Jia 			regs->gpr[rd] = ~0UL;
9904e0e3435SHongtao Jia 			break;
9914e0e3435SHongtao Jia 
9924e0e3435SHongtao Jia 		case OP_31_XOP_LHAUX:
9934e0e3435SHongtao Jia 			regs->gpr[rd] = ~0UL;
9944e0e3435SHongtao Jia 			regs->gpr[ra] += regs->gpr[rb];
9954e0e3435SHongtao Jia 			break;
9964e0e3435SHongtao Jia 
9974e0e3435SHongtao Jia 		default:
9984e0e3435SHongtao Jia 			return 0;
9994e0e3435SHongtao Jia 		}
10004e0e3435SHongtao Jia 		break;
10014e0e3435SHongtao Jia 
10024e0e3435SHongtao Jia 	case OP_LWZ:
10034e0e3435SHongtao Jia 		regs->gpr[rd] = 0xffffffff;
10044e0e3435SHongtao Jia 		break;
10054e0e3435SHongtao Jia 
10064e0e3435SHongtao Jia 	case OP_LWZU:
10074e0e3435SHongtao Jia 		regs->gpr[rd] = 0xffffffff;
10084e0e3435SHongtao Jia 		regs->gpr[ra] += (s16)d;
10094e0e3435SHongtao Jia 		break;
10104e0e3435SHongtao Jia 
10114e0e3435SHongtao Jia 	case OP_LBZ:
10124e0e3435SHongtao Jia 		regs->gpr[rd] = 0xff;
10134e0e3435SHongtao Jia 		break;
10144e0e3435SHongtao Jia 
10154e0e3435SHongtao Jia 	case OP_LBZU:
10164e0e3435SHongtao Jia 		regs->gpr[rd] = 0xff;
10174e0e3435SHongtao Jia 		regs->gpr[ra] += (s16)d;
10184e0e3435SHongtao Jia 		break;
10194e0e3435SHongtao Jia 
10204e0e3435SHongtao Jia 	case OP_LHZ:
10214e0e3435SHongtao Jia 		regs->gpr[rd] = 0xffff;
10224e0e3435SHongtao Jia 		break;
10234e0e3435SHongtao Jia 
10244e0e3435SHongtao Jia 	case OP_LHZU:
10254e0e3435SHongtao Jia 		regs->gpr[rd] = 0xffff;
10264e0e3435SHongtao Jia 		regs->gpr[ra] += (s16)d;
10274e0e3435SHongtao Jia 		break;
10284e0e3435SHongtao Jia 
10294e0e3435SHongtao Jia 	case OP_LHA:
10304e0e3435SHongtao Jia 		regs->gpr[rd] = ~0UL;
10314e0e3435SHongtao Jia 		break;
10324e0e3435SHongtao Jia 
10334e0e3435SHongtao Jia 	case OP_LHAU:
10344e0e3435SHongtao Jia 		regs->gpr[rd] = ~0UL;
10354e0e3435SHongtao Jia 		regs->gpr[ra] += (s16)d;
10364e0e3435SHongtao Jia 		break;
10374e0e3435SHongtao Jia 
10384e0e3435SHongtao Jia 	default:
10394e0e3435SHongtao Jia 		return 0;
10404e0e3435SHongtao Jia 	}
10414e0e3435SHongtao Jia 
10424e0e3435SHongtao Jia 	return 1;
10434e0e3435SHongtao Jia }
10444e0e3435SHongtao Jia 
is_in_pci_mem_space(phys_addr_t addr)10454e0e3435SHongtao Jia static int is_in_pci_mem_space(phys_addr_t addr)
10464e0e3435SHongtao Jia {
10474e0e3435SHongtao Jia 	struct pci_controller *hose;
10484e0e3435SHongtao Jia 	struct resource *res;
10494e0e3435SHongtao Jia 	int i;
10504e0e3435SHongtao Jia 
10514e0e3435SHongtao Jia 	list_for_each_entry(hose, &hose_list, list_node) {
10524e0e3435SHongtao Jia 		if (!(hose->indirect_type & PPC_INDIRECT_TYPE_EXT_REG))
10534e0e3435SHongtao Jia 			continue;
10544e0e3435SHongtao Jia 
10554e0e3435SHongtao Jia 		for (i = 0; i < 3; i++) {
10564e0e3435SHongtao Jia 			res = &hose->mem_resources[i];
10574e0e3435SHongtao Jia 			if ((res->flags & IORESOURCE_MEM) &&
10584e0e3435SHongtao Jia 				addr >= res->start && addr <= res->end)
10594e0e3435SHongtao Jia 				return 1;
10604e0e3435SHongtao Jia 		}
10614e0e3435SHongtao Jia 	}
10624e0e3435SHongtao Jia 	return 0;
10634e0e3435SHongtao Jia }
10644e0e3435SHongtao Jia 
fsl_pci_mcheck_exception(struct pt_regs * regs)10654e0e3435SHongtao Jia int fsl_pci_mcheck_exception(struct pt_regs *regs)
10664e0e3435SHongtao Jia {
10674e0e3435SHongtao Jia 	u32 inst;
10684e0e3435SHongtao Jia 	int ret;
10694e0e3435SHongtao Jia 	phys_addr_t addr = 0;
10704e0e3435SHongtao Jia 
10714e0e3435SHongtao Jia 	/* Let KVM/QEMU deal with the exception */
10724e0e3435SHongtao Jia 	if (regs->msr & MSR_GS)
10734e0e3435SHongtao Jia 		return 0;
10744e0e3435SHongtao Jia 
10754e0e3435SHongtao Jia #ifdef CONFIG_PHYS_64BIT
10764e0e3435SHongtao Jia 	addr = mfspr(SPRN_MCARU);
10774e0e3435SHongtao Jia 	addr <<= 32;
10784e0e3435SHongtao Jia #endif
10794e0e3435SHongtao Jia 	addr += mfspr(SPRN_MCAR);
10804e0e3435SHongtao Jia 
10814e0e3435SHongtao Jia 	if (is_in_pci_mem_space(addr)) {
1082def0bfdbSChristophe Leroy 		if (user_mode(regs))
1083c0ee37e8SChristoph Hellwig 			ret = copy_from_user_nofault(&inst,
1084c0ee37e8SChristoph Hellwig 					(void __user *)regs->nip, sizeof(inst));
1085def0bfdbSChristophe Leroy 		else
108625f12ae4SChristoph Hellwig 			ret = get_kernel_nofault(inst, (void *)regs->nip);
10874e0e3435SHongtao Jia 
1088072daeedSScott Wood 		if (!ret && mcheck_handle_load(regs, inst)) {
108959dc5bfcSNicholas Piggin 			regs_add_return_ip(regs, 4);
10904e0e3435SHongtao Jia 			return 1;
10914e0e3435SHongtao Jia 		}
10924e0e3435SHongtao Jia 	}
10934e0e3435SHongtao Jia 
10944e0e3435SHongtao Jia 	return 0;
10954e0e3435SHongtao Jia }
10964e0e3435SHongtao Jia #endif
10974e0e3435SHongtao Jia 
109807e4f801SScott Wood #if defined(CONFIG_FSL_SOC_BOOKE) || defined(CONFIG_PPC_86xx)
109907e4f801SScott Wood static const struct of_device_id pci_ids[] = {
110007e4f801SScott Wood 	{ .compatible = "fsl,mpc8540-pci", },
110107e4f801SScott Wood 	{ .compatible = "fsl,mpc8548-pcie", },
110207e4f801SScott Wood 	{ .compatible = "fsl,mpc8610-pci", },
110307e4f801SScott Wood 	{ .compatible = "fsl,mpc8641-pcie", },
1104d064f30eSShengzhou Liu 	{ .compatible = "fsl,qoriq-pcie", },
110514bdc913STimur Tabi 	{ .compatible = "fsl,qoriq-pcie-v2.1", },
110607e4f801SScott Wood 	{ .compatible = "fsl,qoriq-pcie-v2.2", },
110714bdc913STimur Tabi 	{ .compatible = "fsl,qoriq-pcie-v2.3", },
110814bdc913STimur Tabi 	{ .compatible = "fsl,qoriq-pcie-v2.4", },
1109cc6ea0ddSRoy ZANG 	{ .compatible = "fsl,qoriq-pcie-v3.0", },
111014bdc913STimur Tabi 
111114bdc913STimur Tabi 	/*
111214bdc913STimur Tabi 	 * The following entries are for compatibility with older device
111314bdc913STimur Tabi 	 * trees.
111414bdc913STimur Tabi 	 */
111514bdc913STimur Tabi 	{ .compatible = "fsl,p1022-pcie", },
111614bdc913STimur Tabi 	{ .compatible = "fsl,p4080-pcie", },
111714bdc913STimur Tabi 
111807e4f801SScott Wood 	{},
111907e4f801SScott Wood };
112007e4f801SScott Wood 
112107e4f801SScott Wood struct device_node *fsl_pci_primary;
112207e4f801SScott Wood 
fsl_pci_assign_primary(void)11236c552983SNick Child void __init fsl_pci_assign_primary(void)
112407e4f801SScott Wood {
1125905e75c4SJia Hongtao 	struct device_node *np;
112607e4f801SScott Wood 
112707e4f801SScott Wood 	/* Callers can specify the primary bus using other means. */
1128905e75c4SJia Hongtao 	if (fsl_pci_primary)
1129905e75c4SJia Hongtao 		return;
1130905e75c4SJia Hongtao 
113107e4f801SScott Wood 	/* If a PCI host bridge contains an ISA node, it's primary. */
1132905e75c4SJia Hongtao 	np = of_find_node_by_type(NULL, "isa");
1133905e75c4SJia Hongtao 	while ((fsl_pci_primary = of_get_parent(np))) {
1134905e75c4SJia Hongtao 		of_node_put(np);
1135905e75c4SJia Hongtao 		np = fsl_pci_primary;
113607e4f801SScott Wood 
1137905e75c4SJia Hongtao 		if (of_match_node(pci_ids, np) && of_device_is_available(np))
1138905e75c4SJia Hongtao 			return;
113907e4f801SScott Wood 	}
114007e4f801SScott Wood 
114107e4f801SScott Wood 	/*
1142e082e99fSPali Rohár 	 * If there's no PCI host bridge with ISA then check for
1143e082e99fSPali Rohár 	 * PCI host bridge with alias "pci0" (first PCI host bridge).
1144e082e99fSPali Rohár 	 */
1145e082e99fSPali Rohár 	np = of_find_node_by_path("pci0");
1146e082e99fSPali Rohár 	if (np && of_match_node(pci_ids, np) && of_device_is_available(np)) {
1147e082e99fSPali Rohár 		fsl_pci_primary = np;
1148e082e99fSPali Rohár 		of_node_put(np);
1149e082e99fSPali Rohár 		return;
1150e082e99fSPali Rohár 	}
1151e082e99fSPali Rohár 	if (np)
1152e082e99fSPali Rohár 		of_node_put(np);
1153e082e99fSPali Rohár 
1154e082e99fSPali Rohár 	/*
115507e4f801SScott Wood 	 * If there's no PCI host bridge with ISA, arbitrarily
115607e4f801SScott Wood 	 * designate one as primary.  This can go away once
115707e4f801SScott Wood 	 * various bugs with primary-less systems are fixed.
115807e4f801SScott Wood 	 */
1159905e75c4SJia Hongtao 	for_each_matching_node(np, pci_ids) {
1160905e75c4SJia Hongtao 		if (of_device_is_available(np)) {
1161905e75c4SJia Hongtao 			fsl_pci_primary = np;
1162905e75c4SJia Hongtao 			return;
1163905e75c4SJia Hongtao 		}
1164905e75c4SJia Hongtao 	}
1165905e75c4SJia Hongtao }
116607e4f801SScott Wood 
116748b16180SWang Dongsheng #ifdef CONFIG_PM_SLEEP
fsl_pci_pme_handle(int irq,void * dev_id)116848b16180SWang Dongsheng static irqreturn_t fsl_pci_pme_handle(int irq, void *dev_id)
116948b16180SWang Dongsheng {
117048b16180SWang Dongsheng 	struct pci_controller *hose = dev_id;
117148b16180SWang Dongsheng 	struct ccsr_pci __iomem *pci = hose->private_data;
117248b16180SWang Dongsheng 	u32 dr;
117348b16180SWang Dongsheng 
117448b16180SWang Dongsheng 	dr = in_be32(&pci->pex_pme_mes_dr);
117548b16180SWang Dongsheng 	if (!dr)
117648b16180SWang Dongsheng 		return IRQ_NONE;
117748b16180SWang Dongsheng 
117848b16180SWang Dongsheng 	out_be32(&pci->pex_pme_mes_dr, dr);
117948b16180SWang Dongsheng 
118048b16180SWang Dongsheng 	return IRQ_HANDLED;
118148b16180SWang Dongsheng }
118248b16180SWang Dongsheng 
fsl_pci_pme_probe(struct pci_controller * hose)118348b16180SWang Dongsheng static int fsl_pci_pme_probe(struct pci_controller *hose)
118448b16180SWang Dongsheng {
118548b16180SWang Dongsheng 	struct ccsr_pci __iomem *pci;
118648b16180SWang Dongsheng 	struct pci_dev *dev;
118748b16180SWang Dongsheng 	int pme_irq;
118848b16180SWang Dongsheng 	int res;
118948b16180SWang Dongsheng 	u16 pms;
119048b16180SWang Dongsheng 
119148b16180SWang Dongsheng 	/* Get hose's pci_dev */
119248b16180SWang Dongsheng 	dev = list_first_entry(&hose->bus->devices, typeof(*dev), bus_list);
119348b16180SWang Dongsheng 
119448b16180SWang Dongsheng 	/* PME Disable */
119548b16180SWang Dongsheng 	pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pms);
119648b16180SWang Dongsheng 	pms &= ~PCI_PM_CTRL_PME_ENABLE;
119748b16180SWang Dongsheng 	pci_write_config_word(dev, dev->pm_cap + PCI_PM_CTRL, pms);
119848b16180SWang Dongsheng 
119948b16180SWang Dongsheng 	pme_irq = irq_of_parse_and_map(hose->dn, 0);
120048b16180SWang Dongsheng 	if (!pme_irq) {
120148b16180SWang Dongsheng 		dev_err(&dev->dev, "Failed to map PME interrupt.\n");
120248b16180SWang Dongsheng 
120348b16180SWang Dongsheng 		return -ENXIO;
120448b16180SWang Dongsheng 	}
120548b16180SWang Dongsheng 
120648b16180SWang Dongsheng 	res = devm_request_irq(hose->parent, pme_irq,
120748b16180SWang Dongsheng 			fsl_pci_pme_handle,
120848b16180SWang Dongsheng 			IRQF_SHARED,
120948b16180SWang Dongsheng 			"[PCI] PME", hose);
121048b16180SWang Dongsheng 	if (res < 0) {
1211971bd8faSMasanari Iida 		dev_err(&dev->dev, "Unable to request irq %d for PME\n", pme_irq);
121248b16180SWang Dongsheng 		irq_dispose_mapping(pme_irq);
121348b16180SWang Dongsheng 
121448b16180SWang Dongsheng 		return -ENODEV;
121548b16180SWang Dongsheng 	}
121648b16180SWang Dongsheng 
121748b16180SWang Dongsheng 	pci = hose->private_data;
121848b16180SWang Dongsheng 
121948b16180SWang Dongsheng 	/* Enable PTOD, ENL23D & EXL23D */
1220dd41d514SWang Dongsheng 	clrbits32(&pci->pex_pme_mes_disr,
122148b16180SWang Dongsheng 		  PME_DISR_EN_PTOD | PME_DISR_EN_ENL23D | PME_DISR_EN_EXL23D);
122248b16180SWang Dongsheng 
122348b16180SWang Dongsheng 	out_be32(&pci->pex_pme_mes_ier, 0);
122448b16180SWang Dongsheng 	setbits32(&pci->pex_pme_mes_ier,
122548b16180SWang Dongsheng 		  PME_DISR_EN_PTOD | PME_DISR_EN_ENL23D | PME_DISR_EN_EXL23D);
122648b16180SWang Dongsheng 
122748b16180SWang Dongsheng 	/* PME Enable */
122848b16180SWang Dongsheng 	pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pms);
122948b16180SWang Dongsheng 	pms |= PCI_PM_CTRL_PME_ENABLE;
123048b16180SWang Dongsheng 	pci_write_config_word(dev, dev->pm_cap + PCI_PM_CTRL, pms);
123148b16180SWang Dongsheng 
123248b16180SWang Dongsheng 	return 0;
123348b16180SWang Dongsheng }
123448b16180SWang Dongsheng 
send_pme_turnoff_message(struct pci_controller * hose)123548b16180SWang Dongsheng static void send_pme_turnoff_message(struct pci_controller *hose)
123648b16180SWang Dongsheng {
123748b16180SWang Dongsheng 	struct ccsr_pci __iomem *pci = hose->private_data;
123848b16180SWang Dongsheng 	u32 dr;
123948b16180SWang Dongsheng 	int i;
124048b16180SWang Dongsheng 
124148b16180SWang Dongsheng 	/* Send PME_Turn_Off Message Request */
124248b16180SWang Dongsheng 	setbits32(&pci->pex_pmcr, PEX_PMCR_PTOMR);
124348b16180SWang Dongsheng 
124448b16180SWang Dongsheng 	/* Wait trun off done */
124548b16180SWang Dongsheng 	for (i = 0; i < 150; i++) {
124648b16180SWang Dongsheng 		dr = in_be32(&pci->pex_pme_mes_dr);
124748b16180SWang Dongsheng 		if (dr) {
124848b16180SWang Dongsheng 			out_be32(&pci->pex_pme_mes_dr, dr);
124948b16180SWang Dongsheng 			break;
125048b16180SWang Dongsheng 		}
125148b16180SWang Dongsheng 
125248b16180SWang Dongsheng 		udelay(1000);
125348b16180SWang Dongsheng 	}
125448b16180SWang Dongsheng }
125548b16180SWang Dongsheng 
fsl_pci_syscore_do_suspend(struct pci_controller * hose)125648b16180SWang Dongsheng static void fsl_pci_syscore_do_suspend(struct pci_controller *hose)
125748b16180SWang Dongsheng {
125848b16180SWang Dongsheng 	send_pme_turnoff_message(hose);
125948b16180SWang Dongsheng }
126048b16180SWang Dongsheng 
fsl_pci_syscore_suspend(void)126148b16180SWang Dongsheng static int fsl_pci_syscore_suspend(void)
126248b16180SWang Dongsheng {
126348b16180SWang Dongsheng 	struct pci_controller *hose, *tmp;
126448b16180SWang Dongsheng 
126548b16180SWang Dongsheng 	list_for_each_entry_safe(hose, tmp, &hose_list, list_node)
126648b16180SWang Dongsheng 		fsl_pci_syscore_do_suspend(hose);
126748b16180SWang Dongsheng 
126848b16180SWang Dongsheng 	return 0;
126948b16180SWang Dongsheng }
127048b16180SWang Dongsheng 
fsl_pci_syscore_do_resume(struct pci_controller * hose)127148b16180SWang Dongsheng static void fsl_pci_syscore_do_resume(struct pci_controller *hose)
127248b16180SWang Dongsheng {
127348b16180SWang Dongsheng 	struct ccsr_pci __iomem *pci = hose->private_data;
127448b16180SWang Dongsheng 	u32 dr;
127548b16180SWang Dongsheng 	int i;
127648b16180SWang Dongsheng 
127748b16180SWang Dongsheng 	/* Send Exit L2 State Message */
127848b16180SWang Dongsheng 	setbits32(&pci->pex_pmcr, PEX_PMCR_EXL2S);
127948b16180SWang Dongsheng 
128048b16180SWang Dongsheng 	/* Wait exit done */
128148b16180SWang Dongsheng 	for (i = 0; i < 150; i++) {
128248b16180SWang Dongsheng 		dr = in_be32(&pci->pex_pme_mes_dr);
128348b16180SWang Dongsheng 		if (dr) {
128448b16180SWang Dongsheng 			out_be32(&pci->pex_pme_mes_dr, dr);
128548b16180SWang Dongsheng 			break;
128648b16180SWang Dongsheng 		}
128748b16180SWang Dongsheng 
128848b16180SWang Dongsheng 		udelay(1000);
128948b16180SWang Dongsheng 	}
129048b16180SWang Dongsheng 
129148b16180SWang Dongsheng 	setup_pci_atmu(hose);
129248b16180SWang Dongsheng }
129348b16180SWang Dongsheng 
fsl_pci_syscore_resume(void)129448b16180SWang Dongsheng static void fsl_pci_syscore_resume(void)
129548b16180SWang Dongsheng {
129648b16180SWang Dongsheng 	struct pci_controller *hose, *tmp;
129748b16180SWang Dongsheng 
129848b16180SWang Dongsheng 	list_for_each_entry_safe(hose, tmp, &hose_list, list_node)
129948b16180SWang Dongsheng 		fsl_pci_syscore_do_resume(hose);
130048b16180SWang Dongsheng }
130148b16180SWang Dongsheng 
130248b16180SWang Dongsheng static struct syscore_ops pci_syscore_pm_ops = {
130348b16180SWang Dongsheng 	.suspend = fsl_pci_syscore_suspend,
130448b16180SWang Dongsheng 	.resume = fsl_pci_syscore_resume,
130548b16180SWang Dongsheng };
130648b16180SWang Dongsheng #endif
130748b16180SWang Dongsheng 
fsl_pcibios_fixup_phb(struct pci_controller * phb)130848b16180SWang Dongsheng void fsl_pcibios_fixup_phb(struct pci_controller *phb)
130948b16180SWang Dongsheng {
131048b16180SWang Dongsheng #ifdef CONFIG_PM_SLEEP
131148b16180SWang Dongsheng 	fsl_pci_pme_probe(phb);
131248b16180SWang Dongsheng #endif
131348b16180SWang Dongsheng }
131448b16180SWang Dongsheng 
add_err_dev(struct platform_device * pdev)1315666db563SScott Wood static int add_err_dev(struct platform_device *pdev)
1316666db563SScott Wood {
1317666db563SScott Wood 	struct platform_device *errdev;
1318666db563SScott Wood 	struct mpc85xx_edac_pci_plat_data pd = {
1319666db563SScott Wood 		.of_node = pdev->dev.of_node
1320666db563SScott Wood 	};
1321666db563SScott Wood 
1322666db563SScott Wood 	errdev = platform_device_register_resndata(&pdev->dev,
1323666db563SScott Wood 						   "mpc85xx-pci-edac",
1324666db563SScott Wood 						   PLATFORM_DEVID_AUTO,
1325666db563SScott Wood 						   pdev->resource,
1326666db563SScott Wood 						   pdev->num_resources,
1327666db563SScott Wood 						   &pd, sizeof(pd));
1328666db563SScott Wood 
1329d038386aSVasyl Gomonovych 	return PTR_ERR_OR_ZERO(errdev);
1330666db563SScott Wood }
1331666db563SScott Wood 
fsl_pci_probe(struct platform_device * pdev)1332cad5cef6SGreg Kroah-Hartman static int fsl_pci_probe(struct platform_device *pdev)
1333905e75c4SJia Hongtao {
1334905e75c4SJia Hongtao 	struct device_node *node;
133548b16180SWang Dongsheng 	int ret;
1336905e75c4SJia Hongtao 
1337905e75c4SJia Hongtao 	node = pdev->dev.of_node;
133852c5affcSVarun Sethi 	ret = fsl_add_bridge(pdev, fsl_pci_primary == node);
1339666db563SScott Wood 	if (ret)
1340666db563SScott Wood 		return ret;
134107e4f801SScott Wood 
1342666db563SScott Wood 	ret = add_err_dev(pdev);
1343666db563SScott Wood 	if (ret)
1344666db563SScott Wood 		dev_err(&pdev->dev, "couldn't register error device: %d\n",
1345666db563SScott Wood 			ret);
1346905e75c4SJia Hongtao 
1347905e75c4SJia Hongtao 	return 0;
1348905e75c4SJia Hongtao }
1349905e75c4SJia Hongtao 
1350905e75c4SJia Hongtao static struct platform_driver fsl_pci_driver = {
1351905e75c4SJia Hongtao 	.driver = {
1352905e75c4SJia Hongtao 		.name = "fsl-pci",
1353905e75c4SJia Hongtao 		.of_match_table = pci_ids,
1354905e75c4SJia Hongtao 	},
1355905e75c4SJia Hongtao 	.probe = fsl_pci_probe,
1356139a57a9SJason Gunthorpe 	.driver_managed_dma = true,
1357905e75c4SJia Hongtao };
1358905e75c4SJia Hongtao 
fsl_pci_init(void)1359905e75c4SJia Hongtao static int __init fsl_pci_init(void)
1360905e75c4SJia Hongtao {
136148b16180SWang Dongsheng #ifdef CONFIG_PM_SLEEP
136248b16180SWang Dongsheng 	register_syscore_ops(&pci_syscore_pm_ops);
136348b16180SWang Dongsheng #endif
1364905e75c4SJia Hongtao 	return platform_driver_register(&fsl_pci_driver);
1365905e75c4SJia Hongtao }
1366905e75c4SJia Hongtao arch_initcall(fsl_pci_init);
1367905e75c4SJia Hongtao #endif
1368