blob: f2dd7723424034a0626c28ca2cc9762f79123984 [file] [log] [blame]
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +00001/*
2 * Support PCI/PCIe on PowerNV platforms
3 *
4 * Currently supports only P5IOC2
5 *
6 * Copyright 2011 Benjamin Herrenschmidt, IBM Corp.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version
11 * 2 of the License, or (at your option) any later version.
12 */
13
14#include <linux/kernel.h>
15#include <linux/pci.h>
16#include <linux/delay.h>
17#include <linux/string.h>
18#include <linux/init.h>
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +000019#include <linux/irq.h>
20#include <linux/io.h>
Benjamin Herrenschmidtc1a25622011-09-19 17:45:06 +000021#include <linux/msi.h>
Alexey Kardashevskiy4e13c1a2013-05-21 13:33:09 +100022#include <linux/iommu.h>
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +000023
24#include <asm/sections.h>
25#include <asm/io.h>
26#include <asm/prom.h>
27#include <asm/pci-bridge.h>
28#include <asm/machdep.h>
Gavin Shanfb1b55d2013-03-05 21:12:37 +000029#include <asm/msi_bitmap.h>
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +000030#include <asm/ppc-pci.h>
31#include <asm/opal.h>
32#include <asm/iommu.h>
33#include <asm/tce.h>
Stephen Rothwellf5339272012-03-15 18:18:00 +000034#include <asm/firmware.h>
Gavin Shanbe7e7442013-06-20 13:21:15 +080035#include <asm/eeh_event.h>
36#include <asm/eeh.h>
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +000037
38#include "powernv.h"
39#include "pci.h"
40
Benjamin Herrenschmidt82ba1292011-09-19 17:45:07 +000041/* Delay in usec */
42#define PCI_RESET_DELAY_US 3000000
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +000043
44#define cfg_dbg(fmt...) do { } while(0)
45//#define cfg_dbg(fmt...) printk(fmt)
46
Benjamin Herrenschmidtc1a25622011-09-19 17:45:06 +000047#ifdef CONFIG_PCI_MSI
Daniel Axtens92ae0352015-04-28 15:12:05 +100048int pnv_setup_msi_irqs(struct pci_dev *pdev, int nvec, int type)
Benjamin Herrenschmidtc1a25622011-09-19 17:45:06 +000049{
50 struct pci_controller *hose = pci_bus_to_host(pdev->bus);
51 struct pnv_phb *phb = hose->private_data;
52 struct msi_desc *entry;
53 struct msi_msg msg;
Gavin Shanfb1b55d2013-03-05 21:12:37 +000054 int hwirq;
55 unsigned int virq;
Benjamin Herrenschmidtc1a25622011-09-19 17:45:06 +000056 int rc;
57
Alexander Gordeev6b2fd7ef2014-09-07 20:57:53 +020058 if (WARN_ON(!phb) || !phb->msi_bmp.bitmap)
59 return -ENODEV;
60
Benjamin Herrenschmidt36074382014-10-07 16:12:36 +110061 if (pdev->no_64bit_msi && !phb->msi32_support)
Benjamin Herrenschmidtc1a25622011-09-19 17:45:06 +000062 return -ENODEV;
63
Jiang Liu2921d172015-07-09 16:00:38 +080064 for_each_pci_msi_entry(entry, pdev) {
Benjamin Herrenschmidtc1a25622011-09-19 17:45:06 +000065 if (!entry->msi_attrib.is_64 && !phb->msi32_support) {
66 pr_warn("%s: Supports only 64-bit MSIs\n",
67 pci_name(pdev));
68 return -ENXIO;
69 }
Gavin Shanfb1b55d2013-03-05 21:12:37 +000070 hwirq = msi_bitmap_alloc_hwirqs(&phb->msi_bmp, 1);
71 if (hwirq < 0) {
Benjamin Herrenschmidtc1a25622011-09-19 17:45:06 +000072 pr_warn("%s: Failed to find a free MSI\n",
73 pci_name(pdev));
74 return -ENOSPC;
75 }
Gavin Shanfb1b55d2013-03-05 21:12:37 +000076 virq = irq_create_mapping(NULL, phb->msi_base + hwirq);
Benjamin Herrenschmidtc1a25622011-09-19 17:45:06 +000077 if (virq == NO_IRQ) {
78 pr_warn("%s: Failed to map MSI to linux irq\n",
79 pci_name(pdev));
Gavin Shanfb1b55d2013-03-05 21:12:37 +000080 msi_bitmap_free_hwirqs(&phb->msi_bmp, hwirq, 1);
Benjamin Herrenschmidtc1a25622011-09-19 17:45:06 +000081 return -ENOMEM;
82 }
Gavin Shanfb1b55d2013-03-05 21:12:37 +000083 rc = phb->msi_setup(phb, pdev, phb->msi_base + hwirq,
Gavin Shan137436c2013-04-25 19:20:59 +000084 virq, entry->msi_attrib.is_64, &msg);
Benjamin Herrenschmidtc1a25622011-09-19 17:45:06 +000085 if (rc) {
86 pr_warn("%s: Failed to setup MSI\n", pci_name(pdev));
87 irq_dispose_mapping(virq);
Gavin Shanfb1b55d2013-03-05 21:12:37 +000088 msi_bitmap_free_hwirqs(&phb->msi_bmp, hwirq, 1);
Benjamin Herrenschmidtc1a25622011-09-19 17:45:06 +000089 return rc;
90 }
91 irq_set_msi_desc(virq, entry);
Jiang Liu83a18912014-11-09 23:10:34 +080092 pci_write_msi_msg(virq, &msg);
Benjamin Herrenschmidtc1a25622011-09-19 17:45:06 +000093 }
94 return 0;
95}
96
Daniel Axtens92ae0352015-04-28 15:12:05 +100097void pnv_teardown_msi_irqs(struct pci_dev *pdev)
Benjamin Herrenschmidtc1a25622011-09-19 17:45:06 +000098{
99 struct pci_controller *hose = pci_bus_to_host(pdev->bus);
100 struct pnv_phb *phb = hose->private_data;
101 struct msi_desc *entry;
Paul Mackerrase297c932015-09-10 14:36:21 +1000102 irq_hw_number_t hwirq;
Benjamin Herrenschmidtc1a25622011-09-19 17:45:06 +0000103
104 if (WARN_ON(!phb))
105 return;
106
Jiang Liu2921d172015-07-09 16:00:38 +0800107 for_each_pci_msi_entry(entry, pdev) {
Benjamin Herrenschmidtc1a25622011-09-19 17:45:06 +0000108 if (entry->irq == NO_IRQ)
109 continue;
Paul Mackerrase297c932015-09-10 14:36:21 +1000110 hwirq = virq_to_hw(entry->irq);
Benjamin Herrenschmidtc1a25622011-09-19 17:45:06 +0000111 irq_set_msi_desc(entry->irq, NULL);
Benjamin Herrenschmidtc1a25622011-09-19 17:45:06 +0000112 irq_dispose_mapping(entry->irq);
Paul Mackerrase297c932015-09-10 14:36:21 +1000113 msi_bitmap_free_hwirqs(&phb->msi_bmp, hwirq - phb->msi_base, 1);
Benjamin Herrenschmidtc1a25622011-09-19 17:45:06 +0000114 }
115}
116#endif /* CONFIG_PCI_MSI */
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000117
Gavin Shan93aef2a2013-11-22 16:28:45 +0800118static void pnv_pci_dump_p7ioc_diag_data(struct pci_controller *hose,
119 struct OpalIoPhbErrorCommon *common)
Benjamin Herrenschmidtcee72d52011-11-29 18:22:53 +0000120{
Gavin Shan93aef2a2013-11-22 16:28:45 +0800121 struct OpalIoP7IOCPhbErrorData *data;
Benjamin Herrenschmidtcee72d52011-11-29 18:22:53 +0000122 int i;
123
Gavin Shan93aef2a2013-11-22 16:28:45 +0800124 data = (struct OpalIoP7IOCPhbErrorData *)common;
Gavin Shanb34497d2014-04-24 18:00:10 +1000125 pr_info("P7IOC PHB#%d Diag-data (Version: %d)\n",
Gavin Shanf18440f2014-07-17 14:41:42 +1000126 hose->global_number, be32_to_cpu(common->version));
Benjamin Herrenschmidtcee72d52011-11-29 18:22:53 +0000127
Gavin Shanaf87d2f2014-02-25 15:28:38 +0800128 if (data->brdgCtl)
Gavin Shanb34497d2014-04-24 18:00:10 +1000129 pr_info("brdgCtl: %08x\n",
Gavin Shanf18440f2014-07-17 14:41:42 +1000130 be32_to_cpu(data->brdgCtl));
Gavin Shanaf87d2f2014-02-25 15:28:38 +0800131 if (data->portStatusReg || data->rootCmplxStatus ||
132 data->busAgentStatus)
Gavin Shanb34497d2014-04-24 18:00:10 +1000133 pr_info("UtlSts: %08x %08x %08x\n",
Gavin Shanf18440f2014-07-17 14:41:42 +1000134 be32_to_cpu(data->portStatusReg),
135 be32_to_cpu(data->rootCmplxStatus),
136 be32_to_cpu(data->busAgentStatus));
Gavin Shanaf87d2f2014-02-25 15:28:38 +0800137 if (data->deviceStatus || data->slotStatus ||
138 data->linkStatus || data->devCmdStatus ||
139 data->devSecStatus)
Gavin Shanb34497d2014-04-24 18:00:10 +1000140 pr_info("RootSts: %08x %08x %08x %08x %08x\n",
Gavin Shanf18440f2014-07-17 14:41:42 +1000141 be32_to_cpu(data->deviceStatus),
142 be32_to_cpu(data->slotStatus),
143 be32_to_cpu(data->linkStatus),
144 be32_to_cpu(data->devCmdStatus),
145 be32_to_cpu(data->devSecStatus));
Gavin Shanaf87d2f2014-02-25 15:28:38 +0800146 if (data->rootErrorStatus || data->uncorrErrorStatus ||
147 data->corrErrorStatus)
Gavin Shanb34497d2014-04-24 18:00:10 +1000148 pr_info("RootErrSts: %08x %08x %08x\n",
Gavin Shanf18440f2014-07-17 14:41:42 +1000149 be32_to_cpu(data->rootErrorStatus),
150 be32_to_cpu(data->uncorrErrorStatus),
151 be32_to_cpu(data->corrErrorStatus));
Gavin Shanaf87d2f2014-02-25 15:28:38 +0800152 if (data->tlpHdr1 || data->tlpHdr2 ||
153 data->tlpHdr3 || data->tlpHdr4)
Gavin Shanb34497d2014-04-24 18:00:10 +1000154 pr_info("RootErrLog: %08x %08x %08x %08x\n",
Gavin Shanf18440f2014-07-17 14:41:42 +1000155 be32_to_cpu(data->tlpHdr1),
156 be32_to_cpu(data->tlpHdr2),
157 be32_to_cpu(data->tlpHdr3),
158 be32_to_cpu(data->tlpHdr4));
Gavin Shanaf87d2f2014-02-25 15:28:38 +0800159 if (data->sourceId || data->errorClass ||
160 data->correlator)
Gavin Shanb34497d2014-04-24 18:00:10 +1000161 pr_info("RootErrLog1: %08x %016llx %016llx\n",
Gavin Shanf18440f2014-07-17 14:41:42 +1000162 be32_to_cpu(data->sourceId),
163 be64_to_cpu(data->errorClass),
164 be64_to_cpu(data->correlator));
Gavin Shanaf87d2f2014-02-25 15:28:38 +0800165 if (data->p7iocPlssr || data->p7iocCsr)
Gavin Shanb34497d2014-04-24 18:00:10 +1000166 pr_info("PhbSts: %016llx %016llx\n",
Gavin Shanf18440f2014-07-17 14:41:42 +1000167 be64_to_cpu(data->p7iocPlssr),
168 be64_to_cpu(data->p7iocCsr));
Gavin Shanb34497d2014-04-24 18:00:10 +1000169 if (data->lemFir)
170 pr_info("Lem: %016llx %016llx %016llx\n",
Gavin Shanf18440f2014-07-17 14:41:42 +1000171 be64_to_cpu(data->lemFir),
172 be64_to_cpu(data->lemErrorMask),
173 be64_to_cpu(data->lemWOF));
Gavin Shanb34497d2014-04-24 18:00:10 +1000174 if (data->phbErrorStatus)
175 pr_info("PhbErr: %016llx %016llx %016llx %016llx\n",
Gavin Shanf18440f2014-07-17 14:41:42 +1000176 be64_to_cpu(data->phbErrorStatus),
177 be64_to_cpu(data->phbFirstErrorStatus),
178 be64_to_cpu(data->phbErrorLog0),
179 be64_to_cpu(data->phbErrorLog1));
Gavin Shanb34497d2014-04-24 18:00:10 +1000180 if (data->mmioErrorStatus)
181 pr_info("OutErr: %016llx %016llx %016llx %016llx\n",
Gavin Shanf18440f2014-07-17 14:41:42 +1000182 be64_to_cpu(data->mmioErrorStatus),
183 be64_to_cpu(data->mmioFirstErrorStatus),
184 be64_to_cpu(data->mmioErrorLog0),
185 be64_to_cpu(data->mmioErrorLog1));
Gavin Shanb34497d2014-04-24 18:00:10 +1000186 if (data->dma0ErrorStatus)
187 pr_info("InAErr: %016llx %016llx %016llx %016llx\n",
Gavin Shanf18440f2014-07-17 14:41:42 +1000188 be64_to_cpu(data->dma0ErrorStatus),
189 be64_to_cpu(data->dma0FirstErrorStatus),
190 be64_to_cpu(data->dma0ErrorLog0),
191 be64_to_cpu(data->dma0ErrorLog1));
Gavin Shanb34497d2014-04-24 18:00:10 +1000192 if (data->dma1ErrorStatus)
193 pr_info("InBErr: %016llx %016llx %016llx %016llx\n",
Gavin Shanf18440f2014-07-17 14:41:42 +1000194 be64_to_cpu(data->dma1ErrorStatus),
195 be64_to_cpu(data->dma1FirstErrorStatus),
196 be64_to_cpu(data->dma1ErrorLog0),
197 be64_to_cpu(data->dma1ErrorLog1));
Benjamin Herrenschmidtcee72d52011-11-29 18:22:53 +0000198
199 for (i = 0; i < OPAL_P7IOC_NUM_PEST_REGS; i++) {
200 if ((data->pestA[i] >> 63) == 0 &&
201 (data->pestB[i] >> 63) == 0)
202 continue;
Gavin Shan93aef2a2013-11-22 16:28:45 +0800203
Gavin Shanb34497d2014-04-24 18:00:10 +1000204 pr_info("PE[%3d] A/B: %016llx %016llx\n",
Gavin Shanf18440f2014-07-17 14:41:42 +1000205 i, be64_to_cpu(data->pestA[i]),
206 be64_to_cpu(data->pestB[i]));
Benjamin Herrenschmidtcee72d52011-11-29 18:22:53 +0000207 }
208}
209
Gavin Shan93aef2a2013-11-22 16:28:45 +0800210static void pnv_pci_dump_phb3_diag_data(struct pci_controller *hose,
211 struct OpalIoPhbErrorCommon *common)
Benjamin Herrenschmidtcee72d52011-11-29 18:22:53 +0000212{
Gavin Shan93aef2a2013-11-22 16:28:45 +0800213 struct OpalIoPhb3ErrorData *data;
214 int i;
215
216 data = (struct OpalIoPhb3ErrorData*)common;
Gavin Shanb34497d2014-04-24 18:00:10 +1000217 pr_info("PHB3 PHB#%d Diag-data (Version: %d)\n",
Guo Chaoddf0322a2014-06-09 16:58:51 +0800218 hose->global_number, be32_to_cpu(common->version));
Gavin Shanaf87d2f2014-02-25 15:28:38 +0800219 if (data->brdgCtl)
Gavin Shanb34497d2014-04-24 18:00:10 +1000220 pr_info("brdgCtl: %08x\n",
Guo Chaoddf0322a2014-06-09 16:58:51 +0800221 be32_to_cpu(data->brdgCtl));
Gavin Shanaf87d2f2014-02-25 15:28:38 +0800222 if (data->portStatusReg || data->rootCmplxStatus ||
223 data->busAgentStatus)
Gavin Shanb34497d2014-04-24 18:00:10 +1000224 pr_info("UtlSts: %08x %08x %08x\n",
Guo Chaoddf0322a2014-06-09 16:58:51 +0800225 be32_to_cpu(data->portStatusReg),
226 be32_to_cpu(data->rootCmplxStatus),
227 be32_to_cpu(data->busAgentStatus));
Gavin Shanaf87d2f2014-02-25 15:28:38 +0800228 if (data->deviceStatus || data->slotStatus ||
229 data->linkStatus || data->devCmdStatus ||
230 data->devSecStatus)
Gavin Shanb34497d2014-04-24 18:00:10 +1000231 pr_info("RootSts: %08x %08x %08x %08x %08x\n",
Guo Chaoddf0322a2014-06-09 16:58:51 +0800232 be32_to_cpu(data->deviceStatus),
233 be32_to_cpu(data->slotStatus),
234 be32_to_cpu(data->linkStatus),
235 be32_to_cpu(data->devCmdStatus),
236 be32_to_cpu(data->devSecStatus));
Gavin Shanaf87d2f2014-02-25 15:28:38 +0800237 if (data->rootErrorStatus || data->uncorrErrorStatus ||
238 data->corrErrorStatus)
Gavin Shanb34497d2014-04-24 18:00:10 +1000239 pr_info("RootErrSts: %08x %08x %08x\n",
Guo Chaoddf0322a2014-06-09 16:58:51 +0800240 be32_to_cpu(data->rootErrorStatus),
241 be32_to_cpu(data->uncorrErrorStatus),
242 be32_to_cpu(data->corrErrorStatus));
Gavin Shanaf87d2f2014-02-25 15:28:38 +0800243 if (data->tlpHdr1 || data->tlpHdr2 ||
244 data->tlpHdr3 || data->tlpHdr4)
Gavin Shanb34497d2014-04-24 18:00:10 +1000245 pr_info("RootErrLog: %08x %08x %08x %08x\n",
Guo Chaoddf0322a2014-06-09 16:58:51 +0800246 be32_to_cpu(data->tlpHdr1),
247 be32_to_cpu(data->tlpHdr2),
248 be32_to_cpu(data->tlpHdr3),
249 be32_to_cpu(data->tlpHdr4));
Gavin Shanaf87d2f2014-02-25 15:28:38 +0800250 if (data->sourceId || data->errorClass ||
251 data->correlator)
Gavin Shanb34497d2014-04-24 18:00:10 +1000252 pr_info("RootErrLog1: %08x %016llx %016llx\n",
Guo Chaoddf0322a2014-06-09 16:58:51 +0800253 be32_to_cpu(data->sourceId),
254 be64_to_cpu(data->errorClass),
255 be64_to_cpu(data->correlator));
Gavin Shanb34497d2014-04-24 18:00:10 +1000256 if (data->nFir)
257 pr_info("nFir: %016llx %016llx %016llx\n",
Guo Chaoddf0322a2014-06-09 16:58:51 +0800258 be64_to_cpu(data->nFir),
259 be64_to_cpu(data->nFirMask),
260 be64_to_cpu(data->nFirWOF));
Gavin Shanaf87d2f2014-02-25 15:28:38 +0800261 if (data->phbPlssr || data->phbCsr)
Gavin Shanb34497d2014-04-24 18:00:10 +1000262 pr_info("PhbSts: %016llx %016llx\n",
Guo Chaoddf0322a2014-06-09 16:58:51 +0800263 be64_to_cpu(data->phbPlssr),
264 be64_to_cpu(data->phbCsr));
Gavin Shanb34497d2014-04-24 18:00:10 +1000265 if (data->lemFir)
266 pr_info("Lem: %016llx %016llx %016llx\n",
Guo Chaoddf0322a2014-06-09 16:58:51 +0800267 be64_to_cpu(data->lemFir),
268 be64_to_cpu(data->lemErrorMask),
269 be64_to_cpu(data->lemWOF));
Gavin Shanb34497d2014-04-24 18:00:10 +1000270 if (data->phbErrorStatus)
271 pr_info("PhbErr: %016llx %016llx %016llx %016llx\n",
Guo Chaoddf0322a2014-06-09 16:58:51 +0800272 be64_to_cpu(data->phbErrorStatus),
273 be64_to_cpu(data->phbFirstErrorStatus),
274 be64_to_cpu(data->phbErrorLog0),
275 be64_to_cpu(data->phbErrorLog1));
Gavin Shanb34497d2014-04-24 18:00:10 +1000276 if (data->mmioErrorStatus)
277 pr_info("OutErr: %016llx %016llx %016llx %016llx\n",
Guo Chaoddf0322a2014-06-09 16:58:51 +0800278 be64_to_cpu(data->mmioErrorStatus),
279 be64_to_cpu(data->mmioFirstErrorStatus),
280 be64_to_cpu(data->mmioErrorLog0),
281 be64_to_cpu(data->mmioErrorLog1));
Gavin Shanb34497d2014-04-24 18:00:10 +1000282 if (data->dma0ErrorStatus)
283 pr_info("InAErr: %016llx %016llx %016llx %016llx\n",
Guo Chaoddf0322a2014-06-09 16:58:51 +0800284 be64_to_cpu(data->dma0ErrorStatus),
285 be64_to_cpu(data->dma0FirstErrorStatus),
286 be64_to_cpu(data->dma0ErrorLog0),
287 be64_to_cpu(data->dma0ErrorLog1));
Gavin Shanb34497d2014-04-24 18:00:10 +1000288 if (data->dma1ErrorStatus)
289 pr_info("InBErr: %016llx %016llx %016llx %016llx\n",
Guo Chaoddf0322a2014-06-09 16:58:51 +0800290 be64_to_cpu(data->dma1ErrorStatus),
291 be64_to_cpu(data->dma1FirstErrorStatus),
292 be64_to_cpu(data->dma1ErrorLog0),
293 be64_to_cpu(data->dma1ErrorLog1));
Gavin Shan93aef2a2013-11-22 16:28:45 +0800294
295 for (i = 0; i < OPAL_PHB3_NUM_PEST_REGS; i++) {
Guo Chaoddf0322a2014-06-09 16:58:51 +0800296 if ((be64_to_cpu(data->pestA[i]) >> 63) == 0 &&
297 (be64_to_cpu(data->pestB[i]) >> 63) == 0)
Gavin Shan93aef2a2013-11-22 16:28:45 +0800298 continue;
299
Gavin Shanb34497d2014-04-24 18:00:10 +1000300 pr_info("PE[%3d] A/B: %016llx %016llx\n",
Guo Chaoddf0322a2014-06-09 16:58:51 +0800301 i, be64_to_cpu(data->pestA[i]),
302 be64_to_cpu(data->pestB[i]));
Gavin Shan93aef2a2013-11-22 16:28:45 +0800303 }
304}
305
306void pnv_pci_dump_phb_diag_data(struct pci_controller *hose,
307 unsigned char *log_buff)
308{
309 struct OpalIoPhbErrorCommon *common;
310
311 if (!hose || !log_buff)
312 return;
313
314 common = (struct OpalIoPhbErrorCommon *)log_buff;
Guo Chaoddf0322a2014-06-09 16:58:51 +0800315 switch (be32_to_cpu(common->ioType)) {
Gavin Shan93aef2a2013-11-22 16:28:45 +0800316 case OPAL_PHB_ERROR_DATA_TYPE_P7IOC:
317 pnv_pci_dump_p7ioc_diag_data(hose, common);
318 break;
319 case OPAL_PHB_ERROR_DATA_TYPE_PHB3:
320 pnv_pci_dump_phb3_diag_data(hose, common);
Benjamin Herrenschmidtcee72d52011-11-29 18:22:53 +0000321 break;
322 default:
Gavin Shan93aef2a2013-11-22 16:28:45 +0800323 pr_warn("%s: Unrecognized ioType %d\n",
Guo Chaoddf0322a2014-06-09 16:58:51 +0800324 __func__, be32_to_cpu(common->ioType));
Benjamin Herrenschmidtcee72d52011-11-29 18:22:53 +0000325 }
326}
327
328static void pnv_pci_handle_eeh_config(struct pnv_phb *phb, u32 pe_no)
329{
330 unsigned long flags, rc;
Gavin Shan98fd7002014-07-21 14:42:35 +1000331 int has_diag, ret = 0;
Benjamin Herrenschmidtcee72d52011-11-29 18:22:53 +0000332
333 spin_lock_irqsave(&phb->lock, flags);
334
Gavin Shan98fd7002014-07-21 14:42:35 +1000335 /* Fetch PHB diag-data */
Gavin Shan23773232013-06-20 13:21:05 +0800336 rc = opal_pci_get_phb_diag_data2(phb->opal_id, phb->diag.blob,
337 PNV_PCI_DIAG_BUF_SIZE);
Benjamin Herrenschmidtcee72d52011-11-29 18:22:53 +0000338 has_diag = (rc == OPAL_SUCCESS);
339
Gavin Shan98fd7002014-07-21 14:42:35 +1000340 /* If PHB supports compound PE, to handle it */
341 if (phb->unfreeze_pe) {
342 ret = phb->unfreeze_pe(phb,
343 pe_no,
Benjamin Herrenschmidtcee72d52011-11-29 18:22:53 +0000344 OPAL_EEH_ACTION_CLEAR_FREEZE_ALL);
Gavin Shan98fd7002014-07-21 14:42:35 +1000345 } else {
346 rc = opal_pci_eeh_freeze_clear(phb->opal_id,
347 pe_no,
348 OPAL_EEH_ACTION_CLEAR_FREEZE_ALL);
349 if (rc) {
350 pr_warn("%s: Failure %ld clearing frozen "
351 "PHB#%x-PE#%x\n",
352 __func__, rc, phb->hose->global_number,
353 pe_no);
354 ret = -EIO;
355 }
Benjamin Herrenschmidtcee72d52011-11-29 18:22:53 +0000356 }
357
Gavin Shan98fd7002014-07-21 14:42:35 +1000358 /*
359 * For now, let's only display the diag buffer when we fail to clear
360 * the EEH status. We'll do more sensible things later when we have
361 * proper EEH support. We need to make sure we don't pollute ourselves
362 * with the normal errors generated when probing empty slots
363 */
364 if (has_diag && ret)
365 pnv_pci_dump_phb_diag_data(phb->hose, phb->diag.blob);
366
Benjamin Herrenschmidtcee72d52011-11-29 18:22:53 +0000367 spin_unlock_irqrestore(&phb->lock, flags);
368}
369
Gavin Shan3532a7412015-03-17 16:15:03 +1100370static void pnv_pci_config_check_eeh(struct pci_dn *pdn)
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000371{
Gavin Shan3532a7412015-03-17 16:15:03 +1100372 struct pnv_phb *phb = pdn->phb->private_data;
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000373 u8 fstate;
Benjamin Herrenschmidt3a1a4662013-09-23 12:05:01 +1000374 __be16 pcierr;
Gavin Shan98fd7002014-07-21 14:42:35 +1000375 int pe_no;
376 s64 rc;
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000377
Gavin Shan9bf41be2013-06-27 13:46:48 +0800378 /*
379 * Get the PE#. During the PCI probe stage, we might not
380 * setup that yet. So all ER errors should be mapped to
Gavin Shan36954dc2013-11-04 16:32:47 +0800381 * reserved PE.
Gavin Shan9bf41be2013-06-27 13:46:48 +0800382 */
Gavin Shan3532a7412015-03-17 16:15:03 +1100383 pe_no = pdn->pe_number;
Gavin Shan36954dc2013-11-04 16:32:47 +0800384 if (pe_no == IODA_INVALID_PE) {
385 if (phb->type == PNV_PHB_P5IOC2)
386 pe_no = 0;
387 else
388 pe_no = phb->ioda.reserved_pe;
389 }
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000390
Gavin Shan98fd7002014-07-21 14:42:35 +1000391 /*
392 * Fetch frozen state. If the PHB support compound PE,
393 * we need handle that case.
394 */
395 if (phb->get_pe_state) {
396 fstate = phb->get_pe_state(phb, pe_no);
397 } else {
398 rc = opal_pci_eeh_freeze_status(phb->opal_id,
399 pe_no,
400 &fstate,
401 &pcierr,
402 NULL);
403 if (rc) {
404 pr_warn("%s: Failure %lld getting PHB#%x-PE#%x state\n",
405 __func__, rc, phb->hose->global_number, pe_no);
406 return;
407 }
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000408 }
Gavin Shan98fd7002014-07-21 14:42:35 +1000409
Gavin Shan9bf41be2013-06-27 13:46:48 +0800410 cfg_dbg(" -> EEH check, bdfn=%04x PE#%d fstate=%x\n",
Gavin Shan3532a7412015-03-17 16:15:03 +1100411 (pdn->busno << 8) | (pdn->devfn), pe_no, fstate);
Gavin Shan98fd7002014-07-21 14:42:35 +1000412
413 /* Clear the frozen state if applicable */
414 if (fstate == OPAL_EEH_STOPPED_MMIO_FREEZE ||
415 fstate == OPAL_EEH_STOPPED_DMA_FREEZE ||
416 fstate == OPAL_EEH_STOPPED_MMIO_DMA_FREEZE) {
417 /*
418 * If PHB supports compound PE, freeze it for
419 * consistency.
420 */
421 if (phb->freeze_pe)
422 phb->freeze_pe(phb, pe_no);
423
Benjamin Herrenschmidtcee72d52011-11-29 18:22:53 +0000424 pnv_pci_handle_eeh_config(phb, pe_no);
Gavin Shan98fd7002014-07-21 14:42:35 +1000425 }
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000426}
427
Gavin Shan3532a7412015-03-17 16:15:03 +1100428int pnv_pci_cfg_read(struct pci_dn *pdn,
Gavin Shan9bf41be2013-06-27 13:46:48 +0800429 int where, int size, u32 *val)
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000430{
Gavin Shan9bf41be2013-06-27 13:46:48 +0800431 struct pnv_phb *phb = pdn->phb->private_data;
432 u32 bdfn = (pdn->busno << 8) | pdn->devfn;
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000433 s64 rc;
434
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000435 switch (size) {
436 case 1: {
437 u8 v8;
438 rc = opal_pci_config_read_byte(phb->opal_id, bdfn, where, &v8);
439 *val = (rc == OPAL_SUCCESS) ? v8 : 0xff;
440 break;
441 }
442 case 2: {
Benjamin Herrenschmidt3a1a4662013-09-23 12:05:01 +1000443 __be16 v16;
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000444 rc = opal_pci_config_read_half_word(phb->opal_id, bdfn, where,
445 &v16);
Benjamin Herrenschmidt3a1a4662013-09-23 12:05:01 +1000446 *val = (rc == OPAL_SUCCESS) ? be16_to_cpu(v16) : 0xffff;
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000447 break;
448 }
449 case 4: {
Benjamin Herrenschmidt3a1a4662013-09-23 12:05:01 +1000450 __be32 v32;
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000451 rc = opal_pci_config_read_word(phb->opal_id, bdfn, where, &v32);
Benjamin Herrenschmidt3a1a4662013-09-23 12:05:01 +1000452 *val = (rc == OPAL_SUCCESS) ? be32_to_cpu(v32) : 0xffffffff;
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000453 break;
454 }
455 default:
456 return PCIBIOS_FUNC_NOT_SUPPORTED;
457 }
Gavin Shand0914f52014-04-24 18:00:12 +1000458
Gavin Shan9bf41be2013-06-27 13:46:48 +0800459 cfg_dbg("%s: bus: %x devfn: %x +%x/%x -> %08x\n",
460 __func__, pdn->busno, pdn->devfn, where, size, *val);
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000461 return PCIBIOS_SUCCESSFUL;
462}
463
Gavin Shan3532a7412015-03-17 16:15:03 +1100464int pnv_pci_cfg_write(struct pci_dn *pdn,
Gavin Shan9bf41be2013-06-27 13:46:48 +0800465 int where, int size, u32 val)
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000466{
Gavin Shan9bf41be2013-06-27 13:46:48 +0800467 struct pnv_phb *phb = pdn->phb->private_data;
468 u32 bdfn = (pdn->busno << 8) | pdn->devfn;
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000469
Gavin Shan9bf41be2013-06-27 13:46:48 +0800470 cfg_dbg("%s: bus: %x devfn: %x +%x/%x -> %08x\n",
471 pdn->busno, pdn->devfn, where, size, val);
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000472 switch (size) {
473 case 1:
474 opal_pci_config_write_byte(phb->opal_id, bdfn, where, val);
475 break;
476 case 2:
477 opal_pci_config_write_half_word(phb->opal_id, bdfn, where, val);
478 break;
479 case 4:
480 opal_pci_config_write_word(phb->opal_id, bdfn, where, val);
481 break;
482 default:
483 return PCIBIOS_FUNC_NOT_SUPPORTED;
484 }
Gavin Shanbe7e7442013-06-20 13:21:15 +0800485
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000486 return PCIBIOS_SUCCESSFUL;
487}
488
Gavin Shand0914f52014-04-24 18:00:12 +1000489#if CONFIG_EEH
Gavin Shan3532a7412015-03-17 16:15:03 +1100490static bool pnv_pci_cfg_check(struct pci_dn *pdn)
Gavin Shand0914f52014-04-24 18:00:12 +1000491{
492 struct eeh_dev *edev = NULL;
Gavin Shan3532a7412015-03-17 16:15:03 +1100493 struct pnv_phb *phb = pdn->phb->private_data;
Gavin Shand0914f52014-04-24 18:00:12 +1000494
495 /* EEH not enabled ? */
496 if (!(phb->flags & PNV_PHB_FLAG_EEH))
497 return true;
498
Gavin Shand2b0f6f2014-04-24 18:00:19 +1000499 /* PE reset or device removed ? */
Gavin Shan3532a7412015-03-17 16:15:03 +1100500 edev = pdn->edev;
Gavin Shand2b0f6f2014-04-24 18:00:19 +1000501 if (edev) {
502 if (edev->pe &&
Gavin Shan8a6b3712014-10-01 17:07:50 +1000503 (edev->pe->state & EEH_PE_CFG_BLOCKED))
Gavin Shand2b0f6f2014-04-24 18:00:19 +1000504 return false;
505
506 if (edev->mode & EEH_DEV_REMOVED)
507 return false;
508 }
Gavin Shand0914f52014-04-24 18:00:12 +1000509
510 return true;
511}
512#else
Gavin Shan3532a7412015-03-17 16:15:03 +1100513static inline pnv_pci_cfg_check(struct pci_dn *pdn)
Gavin Shand0914f52014-04-24 18:00:12 +1000514{
515 return true;
516}
517#endif /* CONFIG_EEH */
518
Gavin Shan9bf41be2013-06-27 13:46:48 +0800519static int pnv_pci_read_config(struct pci_bus *bus,
520 unsigned int devfn,
521 int where, int size, u32 *val)
522{
Gavin Shan9bf41be2013-06-27 13:46:48 +0800523 struct pci_dn *pdn;
Gavin Shand0914f52014-04-24 18:00:12 +1000524 struct pnv_phb *phb;
Gavin Shand0914f52014-04-24 18:00:12 +1000525 int ret;
Gavin Shan9bf41be2013-06-27 13:46:48 +0800526
527 *val = 0xFFFFFFFF;
Gavin Shan3532a7412015-03-17 16:15:03 +1100528 pdn = pci_get_pdn_by_devfn(bus, devfn);
529 if (!pdn)
Gavin Shand0914f52014-04-24 18:00:12 +1000530 return PCIBIOS_DEVICE_NOT_FOUND;
531
Gavin Shan3532a7412015-03-17 16:15:03 +1100532 if (!pnv_pci_cfg_check(pdn))
533 return PCIBIOS_DEVICE_NOT_FOUND;
534
535 ret = pnv_pci_cfg_read(pdn, where, size, val);
536 phb = pdn->phb->private_data;
537 if (phb->flags & PNV_PHB_FLAG_EEH && pdn->edev) {
Gavin Shand0914f52014-04-24 18:00:12 +1000538 if (*val == EEH_IO_ERROR_VALUE(size) &&
Gavin Shan3532a7412015-03-17 16:15:03 +1100539 eeh_dev_check_failure(pdn->edev))
Gavin Shand0914f52014-04-24 18:00:12 +1000540 return PCIBIOS_DEVICE_NOT_FOUND;
541 } else {
Gavin Shan3532a7412015-03-17 16:15:03 +1100542 pnv_pci_config_check_eeh(pdn);
Gavin Shand0914f52014-04-24 18:00:12 +1000543 }
544
545 return ret;
Gavin Shan9bf41be2013-06-27 13:46:48 +0800546}
547
548static int pnv_pci_write_config(struct pci_bus *bus,
549 unsigned int devfn,
550 int where, int size, u32 val)
551{
Gavin Shan9bf41be2013-06-27 13:46:48 +0800552 struct pci_dn *pdn;
Gavin Shand0914f52014-04-24 18:00:12 +1000553 struct pnv_phb *phb;
Gavin Shand0914f52014-04-24 18:00:12 +1000554 int ret;
Gavin Shan9bf41be2013-06-27 13:46:48 +0800555
Gavin Shan3532a7412015-03-17 16:15:03 +1100556 pdn = pci_get_pdn_by_devfn(bus, devfn);
557 if (!pdn)
Gavin Shand0914f52014-04-24 18:00:12 +1000558 return PCIBIOS_DEVICE_NOT_FOUND;
559
Gavin Shan3532a7412015-03-17 16:15:03 +1100560 if (!pnv_pci_cfg_check(pdn))
561 return PCIBIOS_DEVICE_NOT_FOUND;
562
563 ret = pnv_pci_cfg_write(pdn, where, size, val);
564 phb = pdn->phb->private_data;
Gavin Shand0914f52014-04-24 18:00:12 +1000565 if (!(phb->flags & PNV_PHB_FLAG_EEH))
Gavin Shan3532a7412015-03-17 16:15:03 +1100566 pnv_pci_config_check_eeh(pdn);
Gavin Shand0914f52014-04-24 18:00:12 +1000567
568 return ret;
Gavin Shan9bf41be2013-06-27 13:46:48 +0800569}
570
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000571struct pci_ops pnv_pci_ops = {
Gavin Shan9bf41be2013-06-27 13:46:48 +0800572 .read = pnv_pci_read_config,
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000573 .write = pnv_pci_write_config,
574};
575
Alexey Kardashevskiyc5bb44e2015-06-05 16:35:14 +1000576static __be64 *pnv_tce(struct iommu_table *tbl, long idx)
577{
578 __be64 *tmp = ((__be64 *)tbl->it_base);
Alexey Kardashevskiybbb845c2015-06-05 16:35:19 +1000579 int level = tbl->it_indirect_levels;
580 const long shift = ilog2(tbl->it_level_size);
581 unsigned long mask = (tbl->it_level_size - 1) << (level * shift);
582
583 while (level) {
584 int n = (idx & mask) >> (level * shift);
585 unsigned long tce = be64_to_cpu(tmp[n]);
586
587 tmp = __va(tce & ~(TCE_PCI_READ | TCE_PCI_WRITE));
588 idx &= ~mask;
589 mask >>= shift;
590 --level;
591 }
Alexey Kardashevskiyc5bb44e2015-06-05 16:35:14 +1000592
593 return tmp + idx;
594}
595
Alexey Kardashevskiyda004c32015-06-05 16:35:06 +1000596int pnv_tce_build(struct iommu_table *tbl, long index, long npages,
597 unsigned long uaddr, enum dma_data_direction direction,
598 struct dma_attrs *attrs)
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000599{
Alexey Kardashevskiy10b35b22015-06-05 16:35:05 +1000600 u64 proto_tce = iommu_direction_to_tce_perm(direction);
Alexey Kardashevskiyc5bb44e2015-06-05 16:35:14 +1000601 u64 rpn = __pa(uaddr) >> tbl->it_page_shift;
602 long i;
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000603
Alexey Kardashevskiyc5bb44e2015-06-05 16:35:14 +1000604 for (i = 0; i < npages; i++) {
605 unsigned long newtce = proto_tce |
606 ((rpn + i) << tbl->it_page_shift);
607 unsigned long idx = index - tbl->it_offset + i;
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000608
Alexey Kardashevskiyc5bb44e2015-06-05 16:35:14 +1000609 *(pnv_tce(tbl, idx)) = cpu_to_be64(newtce);
610 }
Benjamin Herrenschmidt1f1616e2011-11-06 18:55:59 +0000611
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000612 return 0;
613}
614
Alexey Kardashevskiy05c6cfb2015-06-05 16:35:15 +1000615#ifdef CONFIG_IOMMU_API
616int pnv_tce_xchg(struct iommu_table *tbl, long index,
617 unsigned long *hpa, enum dma_data_direction *direction)
618{
619 u64 proto_tce = iommu_direction_to_tce_perm(*direction);
620 unsigned long newtce = *hpa | proto_tce, oldtce;
621 unsigned long idx = index - tbl->it_offset;
622
623 BUG_ON(*hpa & ~IOMMU_PAGE_MASK(tbl));
624
625 oldtce = xchg(pnv_tce(tbl, idx), cpu_to_be64(newtce));
626 *hpa = be64_to_cpu(oldtce) & ~(TCE_PCI_READ | TCE_PCI_WRITE);
627 *direction = iommu_tce_direction(oldtce);
628
629 return 0;
630}
631#endif
632
Alexey Kardashevskiyda004c32015-06-05 16:35:06 +1000633void pnv_tce_free(struct iommu_table *tbl, long index, long npages)
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000634{
Alexey Kardashevskiyc5bb44e2015-06-05 16:35:14 +1000635 long i;
Benjamin Herrenschmidt1f1616e2011-11-06 18:55:59 +0000636
Alexey Kardashevskiyc5bb44e2015-06-05 16:35:14 +1000637 for (i = 0; i < npages; i++) {
638 unsigned long idx = index - tbl->it_offset + i;
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000639
Alexey Kardashevskiyc5bb44e2015-06-05 16:35:14 +1000640 *(pnv_tce(tbl, idx)) = cpu_to_be64(0);
641 }
Alexey Kardashevskiy8e0a1612013-08-28 18:37:43 +1000642}
643
Alexey Kardashevskiyda004c32015-06-05 16:35:06 +1000644unsigned long pnv_tce_get(struct iommu_table *tbl, long index)
Alexey Kardashevskiy11f63d32012-09-04 15:19:35 +0000645{
Alexey Kardashevskiyc5bb44e2015-06-05 16:35:14 +1000646 return *(pnv_tce(tbl, index - tbl->it_offset));
Alexey Kardashevskiy11f63d32012-09-04 15:19:35 +0000647}
648
Alexey Kardashevskiy0eaf4de2015-06-05 16:35:09 +1000649struct iommu_table *pnv_pci_table_alloc(int nid)
650{
651 struct iommu_table *tbl;
652
653 tbl = kzalloc_node(sizeof(struct iommu_table), GFP_KERNEL, nid);
654 INIT_LIST_HEAD_RCU(&tbl->it_group_list);
655
656 return tbl;
657}
658
659long pnv_pci_link_table_and_group(int node, int num,
660 struct iommu_table *tbl,
661 struct iommu_table_group *table_group)
662{
663 struct iommu_table_group_link *tgl = NULL;
664
665 if (WARN_ON(!tbl || !table_group))
666 return -EINVAL;
667
668 tgl = kzalloc_node(sizeof(struct iommu_table_group_link), GFP_KERNEL,
669 node);
670 if (!tgl)
671 return -ENOMEM;
672
673 tgl->table_group = table_group;
674 list_add_rcu(&tgl->next, &tbl->it_group_list);
675
676 table_group->tables[num] = tbl;
677
678 return 0;
679}
680
681static void pnv_iommu_table_group_link_free(struct rcu_head *head)
682{
683 struct iommu_table_group_link *tgl = container_of(head,
684 struct iommu_table_group_link, rcu);
685
686 kfree(tgl);
687}
688
689void pnv_pci_unlink_table_and_group(struct iommu_table *tbl,
690 struct iommu_table_group *table_group)
691{
692 long i;
693 bool found;
694 struct iommu_table_group_link *tgl;
695
696 if (!tbl || !table_group)
697 return;
698
699 /* Remove link to a group from table's list of attached groups */
700 found = false;
701 list_for_each_entry_rcu(tgl, &tbl->it_group_list, next) {
702 if (tgl->table_group == table_group) {
703 list_del_rcu(&tgl->next);
704 call_rcu(&tgl->rcu, pnv_iommu_table_group_link_free);
705 found = true;
706 break;
707 }
708 }
709 if (WARN_ON(!found))
710 return;
711
712 /* Clean a pointer to iommu_table in iommu_table_group::tables[] */
713 found = false;
714 for (i = 0; i < IOMMU_TABLE_GROUP_MAX_TABLES; ++i) {
715 if (table_group->tables[i] == tbl) {
716 table_group->tables[i] = NULL;
717 found = true;
718 break;
719 }
720 }
721 WARN_ON(!found);
722}
723
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000724void pnv_pci_setup_iommu_table(struct iommu_table *tbl,
725 void *tce_mem, u64 tce_size,
Alexey Kardashevskiy8fa5d452014-06-06 18:44:03 +1000726 u64 dma_offset, unsigned page_shift)
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000727{
728 tbl->it_blocksize = 16;
729 tbl->it_base = (unsigned long)tce_mem;
Alexey Kardashevskiy8fa5d452014-06-06 18:44:03 +1000730 tbl->it_page_shift = page_shift;
Alistair Popple3a553172013-12-09 18:17:02 +1100731 tbl->it_offset = dma_offset >> tbl->it_page_shift;
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000732 tbl->it_index = 0;
733 tbl->it_size = tce_size >> 3;
734 tbl->it_busno = 0;
735 tbl->it_type = TCE_PCI;
736}
737
Daniel Axtens92ae0352015-04-28 15:12:05 +1000738void pnv_pci_dma_dev_setup(struct pci_dev *pdev)
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000739{
740 struct pci_controller *hose = pci_bus_to_host(pdev->bus);
741 struct pnv_phb *phb = hose->private_data;
Wei Yang781a8682015-03-25 16:23:57 +0800742#ifdef CONFIG_PCI_IOV
743 struct pnv_ioda_pe *pe;
744 struct pci_dn *pdn;
745
746 /* Fix the VF pdn PE number */
747 if (pdev->is_virtfn) {
748 pdn = pci_get_pdn(pdev);
749 WARN_ON(pdn->pe_number != IODA_INVALID_PE);
750 list_for_each_entry(pe, &phb->ioda.pe_list, list) {
751 if (pe->rid == ((pdev->bus->number << 8) |
752 (pdev->devfn & 0xff))) {
753 pdn->pe_number = pe->pe_number;
754 pe->pdev = pdev;
755 break;
756 }
757 }
758 }
759#endif /* CONFIG_PCI_IOV */
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000760
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000761 if (phb && phb->dma_dev_setup)
762 phb->dma_dev_setup(phb, pdev);
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000763}
764
Benjamin Herrenschmidt73ed1482013-05-10 16:59:18 +1000765void pnv_pci_shutdown(void)
766{
767 struct pci_controller *hose;
768
Michael Neuling7a8e6bb2015-05-27 16:06:59 +1000769 list_for_each_entry(hose, &hose_list, list_node)
770 if (hose->controller_ops.shutdown)
771 hose->controller_ops.shutdown(hose);
Benjamin Herrenschmidt73ed1482013-05-10 16:59:18 +1000772}
773
Gavin Shanaa0c0332013-04-25 19:20:57 +0000774/* Fixup wrong class code in p7ioc and p8 root complex */
Greg Kroah-Hartmancad5cef2012-12-21 14:04:10 -0800775static void pnv_p7ioc_rc_quirk(struct pci_dev *dev)
Benjamin Herrenschmidtca45cfe2011-11-06 18:56:00 +0000776{
777 dev->class = PCI_CLASS_BRIDGE_PCI << 8;
778}
779DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_IBM, 0x3b9, pnv_p7ioc_rc_quirk);
780
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000781void __init pnv_pci_init(void)
782{
783 struct device_node *np;
Michael Ellerman646b54f2015-03-12 17:27:11 +1100784 bool found_ioda = false;
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000785
Bjorn Helgaas673c9752012-02-23 20:18:58 -0700786 pci_add_flags(PCI_CAN_SKIP_ISA_ALIGN);
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000787
Michael Ellerman646b54f2015-03-12 17:27:11 +1100788 /* If we don't have OPAL, eg. in sim, just skip PCI probe */
789 if (!firmware_has_feature(FW_FEATURE_OPAL))
790 return;
791
792 /* Look for IODA IO-Hubs. We don't support mixing IODA
793 * and p5ioc2 due to the need to change some global
794 * probing flags
795 */
796 for_each_compatible_node(np, NULL, "ibm,ioda-hub") {
797 pnv_pci_init_ioda_hub(np);
798 found_ioda = true;
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000799 }
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000800
Michael Ellerman646b54f2015-03-12 17:27:11 +1100801 /* Look for p5ioc2 IO-Hubs */
802 if (!found_ioda)
803 for_each_compatible_node(np, NULL, "ibm,p5ioc2")
804 pnv_pci_init_p5ioc2_hub(np);
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000805
Michael Ellerman646b54f2015-03-12 17:27:11 +1100806 /* Look for ioda2 built-in PHB3's */
807 for_each_compatible_node(np, NULL, "ibm,ioda2-phb")
808 pnv_pci_init_ioda2_phb(np);
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000809
810 /* Setup the linkage between OF nodes and PHBs */
811 pci_devs_phb_init();
812
813 /* Configure IOMMU DMA hooks */
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000814 set_pci_dma_ops(&dma_iommu_ops);
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000815}
Alexey Kardashevskiyd905c5d2013-11-21 17:43:14 +1100816
Michael Ellermanb14726c2014-07-15 22:22:24 +1000817machine_subsys_initcall_sync(powernv, tce_iommu_bus_notifier_init);