aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc/sysdev/fsl_pci.c
diff options
context:
space:
mode:
authorBenjamin Herrenschmidt <benh@kernel.crashing.org>2013-04-29 21:10:09 -0400
committerBenjamin Herrenschmidt <benh@kernel.crashing.org>2013-04-29 21:10:09 -0400
commitbc23100a0d646aedb6e17fbcecdc35a24cd3bf2a (patch)
treeafbf44b177d17a8450d606b6d976e76e8e964273 /arch/powerpc/sysdev/fsl_pci.c
parent28bf41a1fedad76e9b4de70c9573bb3f8afc3709 (diff)
parent9e2ecdbba3b0745f9ed454ab86961e3ccf9dc224 (diff)
Merge remote-tracking branch 'kumar/next' into next
From Kumar Gala: << Add support for T4 and B4 SoC families from Freescale, e6500 altivec support, some various board fixes and other minor cleanups. >>
Diffstat (limited to 'arch/powerpc/sysdev/fsl_pci.c')
-rw-r--r--arch/powerpc/sysdev/fsl_pci.c112
1 files changed, 80 insertions, 32 deletions
diff --git a/arch/powerpc/sysdev/fsl_pci.c b/arch/powerpc/sysdev/fsl_pci.c
index 682084dba19b..cf81d6516514 100644
--- a/arch/powerpc/sysdev/fsl_pci.c
+++ b/arch/powerpc/sysdev/fsl_pci.c
@@ -54,16 +54,63 @@ static void quirk_fsl_pcie_header(struct pci_dev *dev)
54 return; 54 return;
55} 55}
56 56
57static int __init fsl_pcie_check_link(struct pci_controller *hose) 57static int fsl_indirect_read_config(struct pci_bus *, unsigned int,
58 int, int, u32 *);
59
60static int fsl_pcie_check_link(struct pci_controller *hose)
58{ 61{
59 u32 val; 62 u32 val = 0;
63
64 if (hose->indirect_type & PPC_INDIRECT_TYPE_FSL_CFG_REG_LINK) {
65 if (hose->ops->read == fsl_indirect_read_config) {
66 struct pci_bus bus;
67 bus.number = 0;
68 bus.sysdata = hose;
69 bus.ops = hose->ops;
70 indirect_read_config(&bus, 0, PCIE_LTSSM, 4, &val);
71 } else
72 early_read_config_dword(hose, 0, 0, PCIE_LTSSM, &val);
73 if (val < PCIE_LTSSM_L0)
74 return 1;
75 } else {
76 struct ccsr_pci __iomem *pci = hose->private_data;
77 /* for PCIe IP rev 3.0 or greater use CSR0 for link state */
78 val = (in_be32(&pci->pex_csr0) & PEX_CSR0_LTSSM_MASK)
79 >> PEX_CSR0_LTSSM_SHIFT;
80 if (val != PEX_CSR0_LTSSM_L0)
81 return 1;
82 }
60 83
61 early_read_config_dword(hose, 0, 0, PCIE_LTSSM, &val);
62 if (val < PCIE_LTSSM_L0)
63 return 1;
64 return 0; 84 return 0;
65} 85}
66 86
87static int fsl_indirect_read_config(struct pci_bus *bus, unsigned int devfn,
88 int offset, int len, u32 *val)
89{
90 struct pci_controller *hose = pci_bus_to_host(bus);
91
92 if (fsl_pcie_check_link(hose))
93 hose->indirect_type |= PPC_INDIRECT_TYPE_NO_PCIE_LINK;
94 else
95 hose->indirect_type &= ~PPC_INDIRECT_TYPE_NO_PCIE_LINK;
96
97 return indirect_read_config(bus, devfn, offset, len, val);
98}
99
100static struct pci_ops fsl_indirect_pci_ops =
101{
102 .read = fsl_indirect_read_config,
103 .write = indirect_write_config,
104};
105
106static void __init fsl_setup_indirect_pci(struct pci_controller* hose,
107 resource_size_t cfg_addr,
108 resource_size_t cfg_data, u32 flags)
109{
110 setup_indirect_pci(hose, cfg_addr, cfg_data, flags);
111 hose->ops = &fsl_indirect_pci_ops;
112}
113
67#if defined(CONFIG_FSL_SOC_BOOKE) || defined(CONFIG_PPC_86xx) 114#if defined(CONFIG_FSL_SOC_BOOKE) || defined(CONFIG_PPC_86xx)
68 115
69#define MAX_PHYS_ADDR_BITS 40 116#define MAX_PHYS_ADDR_BITS 40
@@ -106,7 +153,7 @@ static int setup_one_atmu(struct ccsr_pci __iomem *pci,
106 flags |= 0x10000000; /* enable relaxed ordering */ 153 flags |= 0x10000000; /* enable relaxed ordering */
107 154
108 for (i = 0; size > 0; i++) { 155 for (i = 0; size > 0; i++) {
109 unsigned int bits = min(__ilog2(size), 156 unsigned int bits = min(ilog2(size),
110 __ffs(pci_addr | phys_addr)); 157 __ffs(pci_addr | phys_addr));
111 158
112 if (index + i >= 5) 159 if (index + i >= 5)
@@ -126,10 +173,9 @@ static int setup_one_atmu(struct ccsr_pci __iomem *pci,
126} 173}
127 174
128/* atmu setup for fsl pci/pcie controller */ 175/* atmu setup for fsl pci/pcie controller */
129static void setup_pci_atmu(struct pci_controller *hose, 176static void setup_pci_atmu(struct pci_controller *hose)
130 struct resource *rsrc)
131{ 177{
132 struct ccsr_pci __iomem *pci; 178 struct ccsr_pci __iomem *pci = hose->private_data;
133 int i, j, n, mem_log, win_idx = 3, start_idx = 1, end_idx = 4; 179 int i, j, n, mem_log, win_idx = 3, start_idx = 1, end_idx = 4;
134 u64 mem, sz, paddr_hi = 0; 180 u64 mem, sz, paddr_hi = 0;
135 u64 paddr_lo = ULLONG_MAX; 181 u64 paddr_lo = ULLONG_MAX;
@@ -140,15 +186,6 @@ static void setup_pci_atmu(struct pci_controller *hose,
140 const u64 *reg; 186 const u64 *reg;
141 int len; 187 int len;
142 188
143 pr_debug("PCI memory map start 0x%016llx, size 0x%016llx\n",
144 (u64)rsrc->start, (u64)resource_size(rsrc));
145
146 pci = ioremap(rsrc->start, resource_size(rsrc));
147 if (!pci) {
148 dev_err(hose->parent, "Unable to map ATMU registers\n");
149 return;
150 }
151
152 if (early_find_capability(hose, 0, 0, PCI_CAP_ID_EXP)) { 189 if (early_find_capability(hose, 0, 0, PCI_CAP_ID_EXP)) {
153 if (in_be32(&pci->block_rev1) >= PCIE_IP_REV_2_2) { 190 if (in_be32(&pci->block_rev1) >= PCIE_IP_REV_2_2) {
154 win_idx = 2; 191 win_idx = 2;
@@ -196,7 +233,7 @@ static void setup_pci_atmu(struct pci_controller *hose,
196 out_be32(&pci->pow[j].powbar, (hose->io_base_phys >> 12)); 233 out_be32(&pci->pow[j].powbar, (hose->io_base_phys >> 12));
197 /* Enable, IO R/W */ 234 /* Enable, IO R/W */
198 out_be32(&pci->pow[j].powar, 0x80088000 235 out_be32(&pci->pow[j].powar, 0x80088000
199 | (__ilog2(hose->io_resource.end 236 | (ilog2(hose->io_resource.end
200 - hose->io_resource.start + 1) - 1)); 237 - hose->io_resource.start + 1) - 1));
201 } 238 }
202 } 239 }
@@ -207,12 +244,12 @@ static void setup_pci_atmu(struct pci_controller *hose,
207 244
208 if (paddr_hi == paddr_lo) { 245 if (paddr_hi == paddr_lo) {
209 pr_err("%s: No outbound window space\n", name); 246 pr_err("%s: No outbound window space\n", name);
210 goto out; 247 return;
211 } 248 }
212 249
213 if (paddr_lo == 0) { 250 if (paddr_lo == 0) {
214 pr_err("%s: No space for inbound window\n", name); 251 pr_err("%s: No space for inbound window\n", name);
215 goto out; 252 return;
216 } 253 }
217 254
218 /* setup PCSRBAR/PEXCSRBAR */ 255 /* setup PCSRBAR/PEXCSRBAR */
@@ -261,7 +298,7 @@ static void setup_pci_atmu(struct pci_controller *hose,
261 } 298 }
262 299
263 sz = min(mem, paddr_lo); 300 sz = min(mem, paddr_lo);
264 mem_log = __ilog2_u64(sz); 301 mem_log = ilog2(sz);
265 302
266 /* PCIe can overmap inbound & outbound since RX & TX are separated */ 303 /* PCIe can overmap inbound & outbound since RX & TX are separated */
267 if (early_find_capability(hose, 0, 0, PCI_CAP_ID_EXP)) { 304 if (early_find_capability(hose, 0, 0, PCI_CAP_ID_EXP)) {
@@ -290,7 +327,7 @@ static void setup_pci_atmu(struct pci_controller *hose,
290 * SWIOTLB and access the full range of memory 327 * SWIOTLB and access the full range of memory
291 */ 328 */
292 if (sz != mem) { 329 if (sz != mem) {
293 mem_log = __ilog2_u64(mem); 330 mem_log = ilog2(mem);
294 331
295 /* Size window up if we dont fit in exact power-of-2 */ 332 /* Size window up if we dont fit in exact power-of-2 */
296 if ((1ull << mem_log) != mem) 333 if ((1ull << mem_log) != mem)
@@ -327,7 +364,7 @@ static void setup_pci_atmu(struct pci_controller *hose,
327 sz -= 1ull << mem_log; 364 sz -= 1ull << mem_log;
328 365
329 if (sz) { 366 if (sz) {
330 mem_log = __ilog2_u64(sz); 367 mem_log = ilog2(sz);
331 piwar |= (mem_log - 1); 368 piwar |= (mem_log - 1);
332 369
333 out_be32(&pci->piw[win_idx].pitar, paddr >> 12); 370 out_be32(&pci->piw[win_idx].pitar, paddr >> 12);
@@ -358,9 +395,6 @@ static void setup_pci_atmu(struct pci_controller *hose,
358 pr_info("%s: DMA window size is 0x%llx\n", name, 395 pr_info("%s: DMA window size is 0x%llx\n", name,
359 (u64)hose->dma_window_size); 396 (u64)hose->dma_window_size);
360 } 397 }
361
362out:
363 iounmap(pci);
364} 398}
365 399
366static void __init setup_pci_cmd(struct pci_controller *hose) 400static void __init setup_pci_cmd(struct pci_controller *hose)
@@ -429,6 +463,7 @@ int __init fsl_add_bridge(struct platform_device *pdev, int is_primary)
429 const int *bus_range; 463 const int *bus_range;
430 u8 hdr_type, progif; 464 u8 hdr_type, progif;
431 struct device_node *dev; 465 struct device_node *dev;
466 struct ccsr_pci __iomem *pci;
432 467
433 dev = pdev->dev.of_node; 468 dev = pdev->dev.of_node;
434 469
@@ -461,8 +496,18 @@ int __init fsl_add_bridge(struct platform_device *pdev, int is_primary)
461 hose->first_busno = bus_range ? bus_range[0] : 0x0; 496 hose->first_busno = bus_range ? bus_range[0] : 0x0;
462 hose->last_busno = bus_range ? bus_range[1] : 0xff; 497 hose->last_busno = bus_range ? bus_range[1] : 0xff;
463 498
464 setup_indirect_pci(hose, rsrc.start, rsrc.start + 0x4, 499 pr_debug("PCI memory map start 0x%016llx, size 0x%016llx\n",
465 PPC_INDIRECT_TYPE_BIG_ENDIAN); 500 (u64)rsrc.start, (u64)resource_size(&rsrc));
501
502 pci = hose->private_data = ioremap(rsrc.start, resource_size(&rsrc));
503 if (!hose->private_data)
504 goto no_bridge;
505
506 fsl_setup_indirect_pci(hose, rsrc.start, rsrc.start + 0x4,
507 PPC_INDIRECT_TYPE_BIG_ENDIAN);
508
509 if (in_be32(&pci->block_rev1) < PCIE_IP_REV_3_0)
510 hose->indirect_type |= PPC_INDIRECT_TYPE_FSL_CFG_REG_LINK;
466 511
467 if (early_find_capability(hose, 0, 0, PCI_CAP_ID_EXP)) { 512 if (early_find_capability(hose, 0, 0, PCI_CAP_ID_EXP)) {
468 /* For PCIE read HEADER_TYPE to identify controler mode */ 513 /* For PCIE read HEADER_TYPE to identify controler mode */
@@ -500,11 +545,12 @@ int __init fsl_add_bridge(struct platform_device *pdev, int is_primary)
500 pci_process_bridge_OF_ranges(hose, dev, is_primary); 545 pci_process_bridge_OF_ranges(hose, dev, is_primary);
501 546
502 /* Setup PEX window registers */ 547 /* Setup PEX window registers */
503 setup_pci_atmu(hose, &rsrc); 548 setup_pci_atmu(hose);
504 549
505 return 0; 550 return 0;
506 551
507no_bridge: 552no_bridge:
553 iounmap(hose->private_data);
508 /* unmap cfg_data & cfg_addr separately if not on same page */ 554 /* unmap cfg_data & cfg_addr separately if not on same page */
509 if (((unsigned long)hose->cfg_data & PAGE_MASK) != 555 if (((unsigned long)hose->cfg_data & PAGE_MASK) !=
510 ((unsigned long)hose->cfg_addr & PAGE_MASK)) 556 ((unsigned long)hose->cfg_addr & PAGE_MASK))
@@ -681,6 +727,7 @@ static int __init mpc83xx_pcie_setup(struct pci_controller *hose,
681 WARN_ON(hose->dn->data); 727 WARN_ON(hose->dn->data);
682 hose->dn->data = pcie; 728 hose->dn->data = pcie;
683 hose->ops = &mpc83xx_pcie_ops; 729 hose->ops = &mpc83xx_pcie_ops;
730 hose->indirect_type |= PPC_INDIRECT_TYPE_FSL_CFG_REG_LINK;
684 731
685 out_le32(pcie->cfg_type0 + PEX_OUTWIN0_TAH, 0); 732 out_le32(pcie->cfg_type0 + PEX_OUTWIN0_TAH, 0);
686 out_le32(pcie->cfg_type0 + PEX_OUTWIN0_TAL, 0); 733 out_le32(pcie->cfg_type0 + PEX_OUTWIN0_TAL, 0);
@@ -766,8 +813,8 @@ int __init mpc83xx_add_bridge(struct device_node *dev)
766 if (ret) 813 if (ret)
767 goto err0; 814 goto err0;
768 } else { 815 } else {
769 setup_indirect_pci(hose, rsrc_cfg.start, 816 fsl_setup_indirect_pci(hose, rsrc_cfg.start,
770 rsrc_cfg.start + 4, 0); 817 rsrc_cfg.start + 4, 0);
771 } 818 }
772 819
773 printk(KERN_INFO "Found FSL PCI host bridge at 0x%016llx. " 820 printk(KERN_INFO "Found FSL PCI host bridge at 0x%016llx. "
@@ -836,6 +883,7 @@ static const struct of_device_id pci_ids[] = {
836 { .compatible = "fsl,qoriq-pcie-v2.2", }, 883 { .compatible = "fsl,qoriq-pcie-v2.2", },
837 { .compatible = "fsl,qoriq-pcie-v2.3", }, 884 { .compatible = "fsl,qoriq-pcie-v2.3", },
838 { .compatible = "fsl,qoriq-pcie-v2.4", }, 885 { .compatible = "fsl,qoriq-pcie-v2.4", },
886 { .compatible = "fsl,qoriq-pcie-v3.0", },
839 887
840 /* 888 /*
841 * The following entries are for compatibility with older device 889 * The following entries are for compatibility with older device