blob: 3c35487e97787ff7f595f4d18698f08d80aa34e3 [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
64 list_for_each_entry(entry, &pdev->msi_list, list) {
65 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;
102
103 if (WARN_ON(!phb))
104 return;
105
106 list_for_each_entry(entry, &pdev->msi_list, list) {
107 if (entry->irq == NO_IRQ)
108 continue;
109 irq_set_msi_desc(entry->irq, NULL);
Gavin Shanfb1b55d2013-03-05 21:12:37 +0000110 msi_bitmap_free_hwirqs(&phb->msi_bmp,
111 virq_to_hw(entry->irq) - phb->msi_base, 1);
Benjamin Herrenschmidtc1a25622011-09-19 17:45:06 +0000112 irq_dispose_mapping(entry->irq);
113 }
114}
115#endif /* CONFIG_PCI_MSI */
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000116
Gavin Shan93aef2a2013-11-22 16:28:45 +0800117static void pnv_pci_dump_p7ioc_diag_data(struct pci_controller *hose,
118 struct OpalIoPhbErrorCommon *common)
Benjamin Herrenschmidtcee72d52011-11-29 18:22:53 +0000119{
Gavin Shan93aef2a2013-11-22 16:28:45 +0800120 struct OpalIoP7IOCPhbErrorData *data;
Benjamin Herrenschmidtcee72d52011-11-29 18:22:53 +0000121 int i;
122
Gavin Shan93aef2a2013-11-22 16:28:45 +0800123 data = (struct OpalIoP7IOCPhbErrorData *)common;
Gavin Shanb34497d2014-04-24 18:00:10 +1000124 pr_info("P7IOC PHB#%d Diag-data (Version: %d)\n",
Gavin Shanf18440f2014-07-17 14:41:42 +1000125 hose->global_number, be32_to_cpu(common->version));
Benjamin Herrenschmidtcee72d52011-11-29 18:22:53 +0000126
Gavin Shanaf87d2f2014-02-25 15:28:38 +0800127 if (data->brdgCtl)
Gavin Shanb34497d2014-04-24 18:00:10 +1000128 pr_info("brdgCtl: %08x\n",
Gavin Shanf18440f2014-07-17 14:41:42 +1000129 be32_to_cpu(data->brdgCtl));
Gavin Shanaf87d2f2014-02-25 15:28:38 +0800130 if (data->portStatusReg || data->rootCmplxStatus ||
131 data->busAgentStatus)
Gavin Shanb34497d2014-04-24 18:00:10 +1000132 pr_info("UtlSts: %08x %08x %08x\n",
Gavin Shanf18440f2014-07-17 14:41:42 +1000133 be32_to_cpu(data->portStatusReg),
134 be32_to_cpu(data->rootCmplxStatus),
135 be32_to_cpu(data->busAgentStatus));
Gavin Shanaf87d2f2014-02-25 15:28:38 +0800136 if (data->deviceStatus || data->slotStatus ||
137 data->linkStatus || data->devCmdStatus ||
138 data->devSecStatus)
Gavin Shanb34497d2014-04-24 18:00:10 +1000139 pr_info("RootSts: %08x %08x %08x %08x %08x\n",
Gavin Shanf18440f2014-07-17 14:41:42 +1000140 be32_to_cpu(data->deviceStatus),
141 be32_to_cpu(data->slotStatus),
142 be32_to_cpu(data->linkStatus),
143 be32_to_cpu(data->devCmdStatus),
144 be32_to_cpu(data->devSecStatus));
Gavin Shanaf87d2f2014-02-25 15:28:38 +0800145 if (data->rootErrorStatus || data->uncorrErrorStatus ||
146 data->corrErrorStatus)
Gavin Shanb34497d2014-04-24 18:00:10 +1000147 pr_info("RootErrSts: %08x %08x %08x\n",
Gavin Shanf18440f2014-07-17 14:41:42 +1000148 be32_to_cpu(data->rootErrorStatus),
149 be32_to_cpu(data->uncorrErrorStatus),
150 be32_to_cpu(data->corrErrorStatus));
Gavin Shanaf87d2f2014-02-25 15:28:38 +0800151 if (data->tlpHdr1 || data->tlpHdr2 ||
152 data->tlpHdr3 || data->tlpHdr4)
Gavin Shanb34497d2014-04-24 18:00:10 +1000153 pr_info("RootErrLog: %08x %08x %08x %08x\n",
Gavin Shanf18440f2014-07-17 14:41:42 +1000154 be32_to_cpu(data->tlpHdr1),
155 be32_to_cpu(data->tlpHdr2),
156 be32_to_cpu(data->tlpHdr3),
157 be32_to_cpu(data->tlpHdr4));
Gavin Shanaf87d2f2014-02-25 15:28:38 +0800158 if (data->sourceId || data->errorClass ||
159 data->correlator)
Gavin Shanb34497d2014-04-24 18:00:10 +1000160 pr_info("RootErrLog1: %08x %016llx %016llx\n",
Gavin Shanf18440f2014-07-17 14:41:42 +1000161 be32_to_cpu(data->sourceId),
162 be64_to_cpu(data->errorClass),
163 be64_to_cpu(data->correlator));
Gavin Shanaf87d2f2014-02-25 15:28:38 +0800164 if (data->p7iocPlssr || data->p7iocCsr)
Gavin Shanb34497d2014-04-24 18:00:10 +1000165 pr_info("PhbSts: %016llx %016llx\n",
Gavin Shanf18440f2014-07-17 14:41:42 +1000166 be64_to_cpu(data->p7iocPlssr),
167 be64_to_cpu(data->p7iocCsr));
Gavin Shanb34497d2014-04-24 18:00:10 +1000168 if (data->lemFir)
169 pr_info("Lem: %016llx %016llx %016llx\n",
Gavin Shanf18440f2014-07-17 14:41:42 +1000170 be64_to_cpu(data->lemFir),
171 be64_to_cpu(data->lemErrorMask),
172 be64_to_cpu(data->lemWOF));
Gavin Shanb34497d2014-04-24 18:00:10 +1000173 if (data->phbErrorStatus)
174 pr_info("PhbErr: %016llx %016llx %016llx %016llx\n",
Gavin Shanf18440f2014-07-17 14:41:42 +1000175 be64_to_cpu(data->phbErrorStatus),
176 be64_to_cpu(data->phbFirstErrorStatus),
177 be64_to_cpu(data->phbErrorLog0),
178 be64_to_cpu(data->phbErrorLog1));
Gavin Shanb34497d2014-04-24 18:00:10 +1000179 if (data->mmioErrorStatus)
180 pr_info("OutErr: %016llx %016llx %016llx %016llx\n",
Gavin Shanf18440f2014-07-17 14:41:42 +1000181 be64_to_cpu(data->mmioErrorStatus),
182 be64_to_cpu(data->mmioFirstErrorStatus),
183 be64_to_cpu(data->mmioErrorLog0),
184 be64_to_cpu(data->mmioErrorLog1));
Gavin Shanb34497d2014-04-24 18:00:10 +1000185 if (data->dma0ErrorStatus)
186 pr_info("InAErr: %016llx %016llx %016llx %016llx\n",
Gavin Shanf18440f2014-07-17 14:41:42 +1000187 be64_to_cpu(data->dma0ErrorStatus),
188 be64_to_cpu(data->dma0FirstErrorStatus),
189 be64_to_cpu(data->dma0ErrorLog0),
190 be64_to_cpu(data->dma0ErrorLog1));
Gavin Shanb34497d2014-04-24 18:00:10 +1000191 if (data->dma1ErrorStatus)
192 pr_info("InBErr: %016llx %016llx %016llx %016llx\n",
Gavin Shanf18440f2014-07-17 14:41:42 +1000193 be64_to_cpu(data->dma1ErrorStatus),
194 be64_to_cpu(data->dma1FirstErrorStatus),
195 be64_to_cpu(data->dma1ErrorLog0),
196 be64_to_cpu(data->dma1ErrorLog1));
Benjamin Herrenschmidtcee72d52011-11-29 18:22:53 +0000197
198 for (i = 0; i < OPAL_P7IOC_NUM_PEST_REGS; i++) {
199 if ((data->pestA[i] >> 63) == 0 &&
200 (data->pestB[i] >> 63) == 0)
201 continue;
Gavin Shan93aef2a2013-11-22 16:28:45 +0800202
Gavin Shanb34497d2014-04-24 18:00:10 +1000203 pr_info("PE[%3d] A/B: %016llx %016llx\n",
Gavin Shanf18440f2014-07-17 14:41:42 +1000204 i, be64_to_cpu(data->pestA[i]),
205 be64_to_cpu(data->pestB[i]));
Benjamin Herrenschmidtcee72d52011-11-29 18:22:53 +0000206 }
207}
208
Gavin Shan93aef2a2013-11-22 16:28:45 +0800209static void pnv_pci_dump_phb3_diag_data(struct pci_controller *hose,
210 struct OpalIoPhbErrorCommon *common)
Benjamin Herrenschmidtcee72d52011-11-29 18:22:53 +0000211{
Gavin Shan93aef2a2013-11-22 16:28:45 +0800212 struct OpalIoPhb3ErrorData *data;
213 int i;
214
215 data = (struct OpalIoPhb3ErrorData*)common;
Gavin Shanb34497d2014-04-24 18:00:10 +1000216 pr_info("PHB3 PHB#%d Diag-data (Version: %d)\n",
Guo Chaoddf0322a2014-06-09 16:58:51 +0800217 hose->global_number, be32_to_cpu(common->version));
Gavin Shanaf87d2f2014-02-25 15:28:38 +0800218 if (data->brdgCtl)
Gavin Shanb34497d2014-04-24 18:00:10 +1000219 pr_info("brdgCtl: %08x\n",
Guo Chaoddf0322a2014-06-09 16:58:51 +0800220 be32_to_cpu(data->brdgCtl));
Gavin Shanaf87d2f2014-02-25 15:28:38 +0800221 if (data->portStatusReg || data->rootCmplxStatus ||
222 data->busAgentStatus)
Gavin Shanb34497d2014-04-24 18:00:10 +1000223 pr_info("UtlSts: %08x %08x %08x\n",
Guo Chaoddf0322a2014-06-09 16:58:51 +0800224 be32_to_cpu(data->portStatusReg),
225 be32_to_cpu(data->rootCmplxStatus),
226 be32_to_cpu(data->busAgentStatus));
Gavin Shanaf87d2f2014-02-25 15:28:38 +0800227 if (data->deviceStatus || data->slotStatus ||
228 data->linkStatus || data->devCmdStatus ||
229 data->devSecStatus)
Gavin Shanb34497d2014-04-24 18:00:10 +1000230 pr_info("RootSts: %08x %08x %08x %08x %08x\n",
Guo Chaoddf0322a2014-06-09 16:58:51 +0800231 be32_to_cpu(data->deviceStatus),
232 be32_to_cpu(data->slotStatus),
233 be32_to_cpu(data->linkStatus),
234 be32_to_cpu(data->devCmdStatus),
235 be32_to_cpu(data->devSecStatus));
Gavin Shanaf87d2f2014-02-25 15:28:38 +0800236 if (data->rootErrorStatus || data->uncorrErrorStatus ||
237 data->corrErrorStatus)
Gavin Shanb34497d2014-04-24 18:00:10 +1000238 pr_info("RootErrSts: %08x %08x %08x\n",
Guo Chaoddf0322a2014-06-09 16:58:51 +0800239 be32_to_cpu(data->rootErrorStatus),
240 be32_to_cpu(data->uncorrErrorStatus),
241 be32_to_cpu(data->corrErrorStatus));
Gavin Shanaf87d2f2014-02-25 15:28:38 +0800242 if (data->tlpHdr1 || data->tlpHdr2 ||
243 data->tlpHdr3 || data->tlpHdr4)
Gavin Shanb34497d2014-04-24 18:00:10 +1000244 pr_info("RootErrLog: %08x %08x %08x %08x\n",
Guo Chaoddf0322a2014-06-09 16:58:51 +0800245 be32_to_cpu(data->tlpHdr1),
246 be32_to_cpu(data->tlpHdr2),
247 be32_to_cpu(data->tlpHdr3),
248 be32_to_cpu(data->tlpHdr4));
Gavin Shanaf87d2f2014-02-25 15:28:38 +0800249 if (data->sourceId || data->errorClass ||
250 data->correlator)
Gavin Shanb34497d2014-04-24 18:00:10 +1000251 pr_info("RootErrLog1: %08x %016llx %016llx\n",
Guo Chaoddf0322a2014-06-09 16:58:51 +0800252 be32_to_cpu(data->sourceId),
253 be64_to_cpu(data->errorClass),
254 be64_to_cpu(data->correlator));
Gavin Shanb34497d2014-04-24 18:00:10 +1000255 if (data->nFir)
256 pr_info("nFir: %016llx %016llx %016llx\n",
Guo Chaoddf0322a2014-06-09 16:58:51 +0800257 be64_to_cpu(data->nFir),
258 be64_to_cpu(data->nFirMask),
259 be64_to_cpu(data->nFirWOF));
Gavin Shanaf87d2f2014-02-25 15:28:38 +0800260 if (data->phbPlssr || data->phbCsr)
Gavin Shanb34497d2014-04-24 18:00:10 +1000261 pr_info("PhbSts: %016llx %016llx\n",
Guo Chaoddf0322a2014-06-09 16:58:51 +0800262 be64_to_cpu(data->phbPlssr),
263 be64_to_cpu(data->phbCsr));
Gavin Shanb34497d2014-04-24 18:00:10 +1000264 if (data->lemFir)
265 pr_info("Lem: %016llx %016llx %016llx\n",
Guo Chaoddf0322a2014-06-09 16:58:51 +0800266 be64_to_cpu(data->lemFir),
267 be64_to_cpu(data->lemErrorMask),
268 be64_to_cpu(data->lemWOF));
Gavin Shanb34497d2014-04-24 18:00:10 +1000269 if (data->phbErrorStatus)
270 pr_info("PhbErr: %016llx %016llx %016llx %016llx\n",
Guo Chaoddf0322a2014-06-09 16:58:51 +0800271 be64_to_cpu(data->phbErrorStatus),
272 be64_to_cpu(data->phbFirstErrorStatus),
273 be64_to_cpu(data->phbErrorLog0),
274 be64_to_cpu(data->phbErrorLog1));
Gavin Shanb34497d2014-04-24 18:00:10 +1000275 if (data->mmioErrorStatus)
276 pr_info("OutErr: %016llx %016llx %016llx %016llx\n",
Guo Chaoddf0322a2014-06-09 16:58:51 +0800277 be64_to_cpu(data->mmioErrorStatus),
278 be64_to_cpu(data->mmioFirstErrorStatus),
279 be64_to_cpu(data->mmioErrorLog0),
280 be64_to_cpu(data->mmioErrorLog1));
Gavin Shanb34497d2014-04-24 18:00:10 +1000281 if (data->dma0ErrorStatus)
282 pr_info("InAErr: %016llx %016llx %016llx %016llx\n",
Guo Chaoddf0322a2014-06-09 16:58:51 +0800283 be64_to_cpu(data->dma0ErrorStatus),
284 be64_to_cpu(data->dma0FirstErrorStatus),
285 be64_to_cpu(data->dma0ErrorLog0),
286 be64_to_cpu(data->dma0ErrorLog1));
Gavin Shanb34497d2014-04-24 18:00:10 +1000287 if (data->dma1ErrorStatus)
288 pr_info("InBErr: %016llx %016llx %016llx %016llx\n",
Guo Chaoddf0322a2014-06-09 16:58:51 +0800289 be64_to_cpu(data->dma1ErrorStatus),
290 be64_to_cpu(data->dma1FirstErrorStatus),
291 be64_to_cpu(data->dma1ErrorLog0),
292 be64_to_cpu(data->dma1ErrorLog1));
Gavin Shan93aef2a2013-11-22 16:28:45 +0800293
294 for (i = 0; i < OPAL_PHB3_NUM_PEST_REGS; i++) {
Guo Chaoddf0322a2014-06-09 16:58:51 +0800295 if ((be64_to_cpu(data->pestA[i]) >> 63) == 0 &&
296 (be64_to_cpu(data->pestB[i]) >> 63) == 0)
Gavin Shan93aef2a2013-11-22 16:28:45 +0800297 continue;
298
Gavin Shanb34497d2014-04-24 18:00:10 +1000299 pr_info("PE[%3d] A/B: %016llx %016llx\n",
Guo Chaoddf0322a2014-06-09 16:58:51 +0800300 i, be64_to_cpu(data->pestA[i]),
301 be64_to_cpu(data->pestB[i]));
Gavin Shan93aef2a2013-11-22 16:28:45 +0800302 }
303}
304
305void pnv_pci_dump_phb_diag_data(struct pci_controller *hose,
306 unsigned char *log_buff)
307{
308 struct OpalIoPhbErrorCommon *common;
309
310 if (!hose || !log_buff)
311 return;
312
313 common = (struct OpalIoPhbErrorCommon *)log_buff;
Guo Chaoddf0322a2014-06-09 16:58:51 +0800314 switch (be32_to_cpu(common->ioType)) {
Gavin Shan93aef2a2013-11-22 16:28:45 +0800315 case OPAL_PHB_ERROR_DATA_TYPE_P7IOC:
316 pnv_pci_dump_p7ioc_diag_data(hose, common);
317 break;
318 case OPAL_PHB_ERROR_DATA_TYPE_PHB3:
319 pnv_pci_dump_phb3_diag_data(hose, common);
Benjamin Herrenschmidtcee72d52011-11-29 18:22:53 +0000320 break;
321 default:
Gavin Shan93aef2a2013-11-22 16:28:45 +0800322 pr_warn("%s: Unrecognized ioType %d\n",
Guo Chaoddf0322a2014-06-09 16:58:51 +0800323 __func__, be32_to_cpu(common->ioType));
Benjamin Herrenschmidtcee72d52011-11-29 18:22:53 +0000324 }
325}
326
327static void pnv_pci_handle_eeh_config(struct pnv_phb *phb, u32 pe_no)
328{
329 unsigned long flags, rc;
Gavin Shan98fd7002014-07-21 14:42:35 +1000330 int has_diag, ret = 0;
Benjamin Herrenschmidtcee72d52011-11-29 18:22:53 +0000331
332 spin_lock_irqsave(&phb->lock, flags);
333
Gavin Shan98fd7002014-07-21 14:42:35 +1000334 /* Fetch PHB diag-data */
Gavin Shan23773232013-06-20 13:21:05 +0800335 rc = opal_pci_get_phb_diag_data2(phb->opal_id, phb->diag.blob,
336 PNV_PCI_DIAG_BUF_SIZE);
Benjamin Herrenschmidtcee72d52011-11-29 18:22:53 +0000337 has_diag = (rc == OPAL_SUCCESS);
338
Gavin Shan98fd7002014-07-21 14:42:35 +1000339 /* If PHB supports compound PE, to handle it */
340 if (phb->unfreeze_pe) {
341 ret = phb->unfreeze_pe(phb,
342 pe_no,
Benjamin Herrenschmidtcee72d52011-11-29 18:22:53 +0000343 OPAL_EEH_ACTION_CLEAR_FREEZE_ALL);
Gavin Shan98fd7002014-07-21 14:42:35 +1000344 } else {
345 rc = opal_pci_eeh_freeze_clear(phb->opal_id,
346 pe_no,
347 OPAL_EEH_ACTION_CLEAR_FREEZE_ALL);
348 if (rc) {
349 pr_warn("%s: Failure %ld clearing frozen "
350 "PHB#%x-PE#%x\n",
351 __func__, rc, phb->hose->global_number,
352 pe_no);
353 ret = -EIO;
354 }
Benjamin Herrenschmidtcee72d52011-11-29 18:22:53 +0000355 }
356
Gavin Shan98fd7002014-07-21 14:42:35 +1000357 /*
358 * For now, let's only display the diag buffer when we fail to clear
359 * the EEH status. We'll do more sensible things later when we have
360 * proper EEH support. We need to make sure we don't pollute ourselves
361 * with the normal errors generated when probing empty slots
362 */
363 if (has_diag && ret)
364 pnv_pci_dump_phb_diag_data(phb->hose, phb->diag.blob);
365
Benjamin Herrenschmidtcee72d52011-11-29 18:22:53 +0000366 spin_unlock_irqrestore(&phb->lock, flags);
367}
368
Gavin Shan3532a7412015-03-17 16:15:03 +1100369static void pnv_pci_config_check_eeh(struct pci_dn *pdn)
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000370{
Gavin Shan3532a7412015-03-17 16:15:03 +1100371 struct pnv_phb *phb = pdn->phb->private_data;
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000372 u8 fstate;
Benjamin Herrenschmidt3a1a4662013-09-23 12:05:01 +1000373 __be16 pcierr;
Gavin Shan98fd7002014-07-21 14:42:35 +1000374 int pe_no;
375 s64 rc;
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000376
Gavin Shan9bf41be2013-06-27 13:46:48 +0800377 /*
378 * Get the PE#. During the PCI probe stage, we might not
379 * setup that yet. So all ER errors should be mapped to
Gavin Shan36954dc2013-11-04 16:32:47 +0800380 * reserved PE.
Gavin Shan9bf41be2013-06-27 13:46:48 +0800381 */
Gavin Shan3532a7412015-03-17 16:15:03 +1100382 pe_no = pdn->pe_number;
Gavin Shan36954dc2013-11-04 16:32:47 +0800383 if (pe_no == IODA_INVALID_PE) {
384 if (phb->type == PNV_PHB_P5IOC2)
385 pe_no = 0;
386 else
387 pe_no = phb->ioda.reserved_pe;
388 }
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000389
Gavin Shan98fd7002014-07-21 14:42:35 +1000390 /*
391 * Fetch frozen state. If the PHB support compound PE,
392 * we need handle that case.
393 */
394 if (phb->get_pe_state) {
395 fstate = phb->get_pe_state(phb, pe_no);
396 } else {
397 rc = opal_pci_eeh_freeze_status(phb->opal_id,
398 pe_no,
399 &fstate,
400 &pcierr,
401 NULL);
402 if (rc) {
403 pr_warn("%s: Failure %lld getting PHB#%x-PE#%x state\n",
404 __func__, rc, phb->hose->global_number, pe_no);
405 return;
406 }
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000407 }
Gavin Shan98fd7002014-07-21 14:42:35 +1000408
Gavin Shan9bf41be2013-06-27 13:46:48 +0800409 cfg_dbg(" -> EEH check, bdfn=%04x PE#%d fstate=%x\n",
Gavin Shan3532a7412015-03-17 16:15:03 +1100410 (pdn->busno << 8) | (pdn->devfn), pe_no, fstate);
Gavin Shan98fd7002014-07-21 14:42:35 +1000411
412 /* Clear the frozen state if applicable */
413 if (fstate == OPAL_EEH_STOPPED_MMIO_FREEZE ||
414 fstate == OPAL_EEH_STOPPED_DMA_FREEZE ||
415 fstate == OPAL_EEH_STOPPED_MMIO_DMA_FREEZE) {
416 /*
417 * If PHB supports compound PE, freeze it for
418 * consistency.
419 */
420 if (phb->freeze_pe)
421 phb->freeze_pe(phb, pe_no);
422
Benjamin Herrenschmidtcee72d52011-11-29 18:22:53 +0000423 pnv_pci_handle_eeh_config(phb, pe_no);
Gavin Shan98fd7002014-07-21 14:42:35 +1000424 }
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000425}
426
Gavin Shan3532a7412015-03-17 16:15:03 +1100427int pnv_pci_cfg_read(struct pci_dn *pdn,
Gavin Shan9bf41be2013-06-27 13:46:48 +0800428 int where, int size, u32 *val)
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000429{
Gavin Shan9bf41be2013-06-27 13:46:48 +0800430 struct pnv_phb *phb = pdn->phb->private_data;
431 u32 bdfn = (pdn->busno << 8) | pdn->devfn;
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000432 s64 rc;
433
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000434 switch (size) {
435 case 1: {
436 u8 v8;
437 rc = opal_pci_config_read_byte(phb->opal_id, bdfn, where, &v8);
438 *val = (rc == OPAL_SUCCESS) ? v8 : 0xff;
439 break;
440 }
441 case 2: {
Benjamin Herrenschmidt3a1a4662013-09-23 12:05:01 +1000442 __be16 v16;
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000443 rc = opal_pci_config_read_half_word(phb->opal_id, bdfn, where,
444 &v16);
Benjamin Herrenschmidt3a1a4662013-09-23 12:05:01 +1000445 *val = (rc == OPAL_SUCCESS) ? be16_to_cpu(v16) : 0xffff;
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000446 break;
447 }
448 case 4: {
Benjamin Herrenschmidt3a1a4662013-09-23 12:05:01 +1000449 __be32 v32;
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000450 rc = opal_pci_config_read_word(phb->opal_id, bdfn, where, &v32);
Benjamin Herrenschmidt3a1a4662013-09-23 12:05:01 +1000451 *val = (rc == OPAL_SUCCESS) ? be32_to_cpu(v32) : 0xffffffff;
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000452 break;
453 }
454 default:
455 return PCIBIOS_FUNC_NOT_SUPPORTED;
456 }
Gavin Shand0914f52014-04-24 18:00:12 +1000457
Gavin Shan9bf41be2013-06-27 13:46:48 +0800458 cfg_dbg("%s: bus: %x devfn: %x +%x/%x -> %08x\n",
459 __func__, pdn->busno, pdn->devfn, where, size, *val);
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000460 return PCIBIOS_SUCCESSFUL;
461}
462
Gavin Shan3532a7412015-03-17 16:15:03 +1100463int pnv_pci_cfg_write(struct pci_dn *pdn,
Gavin Shan9bf41be2013-06-27 13:46:48 +0800464 int where, int size, u32 val)
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000465{
Gavin Shan9bf41be2013-06-27 13:46:48 +0800466 struct pnv_phb *phb = pdn->phb->private_data;
467 u32 bdfn = (pdn->busno << 8) | pdn->devfn;
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000468
Gavin Shan9bf41be2013-06-27 13:46:48 +0800469 cfg_dbg("%s: bus: %x devfn: %x +%x/%x -> %08x\n",
470 pdn->busno, pdn->devfn, where, size, val);
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000471 switch (size) {
472 case 1:
473 opal_pci_config_write_byte(phb->opal_id, bdfn, where, val);
474 break;
475 case 2:
476 opal_pci_config_write_half_word(phb->opal_id, bdfn, where, val);
477 break;
478 case 4:
479 opal_pci_config_write_word(phb->opal_id, bdfn, where, val);
480 break;
481 default:
482 return PCIBIOS_FUNC_NOT_SUPPORTED;
483 }
Gavin Shanbe7e7442013-06-20 13:21:15 +0800484
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000485 return PCIBIOS_SUCCESSFUL;
486}
487
Gavin Shand0914f52014-04-24 18:00:12 +1000488#if CONFIG_EEH
Gavin Shan3532a7412015-03-17 16:15:03 +1100489static bool pnv_pci_cfg_check(struct pci_dn *pdn)
Gavin Shand0914f52014-04-24 18:00:12 +1000490{
491 struct eeh_dev *edev = NULL;
Gavin Shan3532a7412015-03-17 16:15:03 +1100492 struct pnv_phb *phb = pdn->phb->private_data;
Gavin Shand0914f52014-04-24 18:00:12 +1000493
494 /* EEH not enabled ? */
495 if (!(phb->flags & PNV_PHB_FLAG_EEH))
496 return true;
497
Gavin Shand2b0f6f2014-04-24 18:00:19 +1000498 /* PE reset or device removed ? */
Gavin Shan3532a7412015-03-17 16:15:03 +1100499 edev = pdn->edev;
Gavin Shand2b0f6f2014-04-24 18:00:19 +1000500 if (edev) {
501 if (edev->pe &&
Gavin Shan8a6b3712014-10-01 17:07:50 +1000502 (edev->pe->state & EEH_PE_CFG_BLOCKED))
Gavin Shand2b0f6f2014-04-24 18:00:19 +1000503 return false;
504
505 if (edev->mode & EEH_DEV_REMOVED)
506 return false;
507 }
Gavin Shand0914f52014-04-24 18:00:12 +1000508
509 return true;
510}
511#else
Gavin Shan3532a7412015-03-17 16:15:03 +1100512static inline pnv_pci_cfg_check(struct pci_dn *pdn)
Gavin Shand0914f52014-04-24 18:00:12 +1000513{
514 return true;
515}
516#endif /* CONFIG_EEH */
517
Gavin Shan9bf41be2013-06-27 13:46:48 +0800518static int pnv_pci_read_config(struct pci_bus *bus,
519 unsigned int devfn,
520 int where, int size, u32 *val)
521{
Gavin Shan9bf41be2013-06-27 13:46:48 +0800522 struct pci_dn *pdn;
Gavin Shand0914f52014-04-24 18:00:12 +1000523 struct pnv_phb *phb;
Gavin Shand0914f52014-04-24 18:00:12 +1000524 int ret;
Gavin Shan9bf41be2013-06-27 13:46:48 +0800525
526 *val = 0xFFFFFFFF;
Gavin Shan3532a7412015-03-17 16:15:03 +1100527 pdn = pci_get_pdn_by_devfn(bus, devfn);
528 if (!pdn)
Gavin Shand0914f52014-04-24 18:00:12 +1000529 return PCIBIOS_DEVICE_NOT_FOUND;
530
Gavin Shan3532a7412015-03-17 16:15:03 +1100531 if (!pnv_pci_cfg_check(pdn))
532 return PCIBIOS_DEVICE_NOT_FOUND;
533
534 ret = pnv_pci_cfg_read(pdn, where, size, val);
535 phb = pdn->phb->private_data;
536 if (phb->flags & PNV_PHB_FLAG_EEH && pdn->edev) {
Gavin Shand0914f52014-04-24 18:00:12 +1000537 if (*val == EEH_IO_ERROR_VALUE(size) &&
Gavin Shan3532a7412015-03-17 16:15:03 +1100538 eeh_dev_check_failure(pdn->edev))
Gavin Shand0914f52014-04-24 18:00:12 +1000539 return PCIBIOS_DEVICE_NOT_FOUND;
540 } else {
Gavin Shan3532a7412015-03-17 16:15:03 +1100541 pnv_pci_config_check_eeh(pdn);
Gavin Shand0914f52014-04-24 18:00:12 +1000542 }
543
544 return ret;
Gavin Shan9bf41be2013-06-27 13:46:48 +0800545}
546
547static int pnv_pci_write_config(struct pci_bus *bus,
548 unsigned int devfn,
549 int where, int size, u32 val)
550{
Gavin Shan9bf41be2013-06-27 13:46:48 +0800551 struct pci_dn *pdn;
Gavin Shand0914f52014-04-24 18:00:12 +1000552 struct pnv_phb *phb;
Gavin Shand0914f52014-04-24 18:00:12 +1000553 int ret;
Gavin Shan9bf41be2013-06-27 13:46:48 +0800554
Gavin Shan3532a7412015-03-17 16:15:03 +1100555 pdn = pci_get_pdn_by_devfn(bus, devfn);
556 if (!pdn)
Gavin Shand0914f52014-04-24 18:00:12 +1000557 return PCIBIOS_DEVICE_NOT_FOUND;
558
Gavin Shan3532a7412015-03-17 16:15:03 +1100559 if (!pnv_pci_cfg_check(pdn))
560 return PCIBIOS_DEVICE_NOT_FOUND;
561
562 ret = pnv_pci_cfg_write(pdn, where, size, val);
563 phb = pdn->phb->private_data;
Gavin Shand0914f52014-04-24 18:00:12 +1000564 if (!(phb->flags & PNV_PHB_FLAG_EEH))
Gavin Shan3532a7412015-03-17 16:15:03 +1100565 pnv_pci_config_check_eeh(pdn);
Gavin Shand0914f52014-04-24 18:00:12 +1000566
567 return ret;
Gavin Shan9bf41be2013-06-27 13:46:48 +0800568}
569
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000570struct pci_ops pnv_pci_ops = {
Gavin Shan9bf41be2013-06-27 13:46:48 +0800571 .read = pnv_pci_read_config,
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000572 .write = pnv_pci_write_config,
573};
574
575static int pnv_tce_build(struct iommu_table *tbl, long index, long npages,
576 unsigned long uaddr, enum dma_data_direction direction,
Alexey Kardashevskiy8e0a1612013-08-28 18:37:43 +1000577 struct dma_attrs *attrs, bool rm)
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000578{
579 u64 proto_tce;
Benjamin Herrenschmidt3a1a4662013-09-23 12:05:01 +1000580 __be64 *tcep, *tces;
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000581 u64 rpn;
582
583 proto_tce = TCE_PCI_READ; // Read allowed
584
585 if (direction != DMA_TO_DEVICE)
586 proto_tce |= TCE_PCI_WRITE;
587
Anton Blanchard5e4da532013-09-23 12:05:06 +1000588 tces = tcep = ((__be64 *)tbl->it_base) + index - tbl->it_offset;
Alexey Kardashevskiybc320572014-06-06 18:44:02 +1000589 rpn = __pa(uaddr) >> tbl->it_page_shift;
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000590
Benjamin Herrenschmidt1f1616e2011-11-06 18:55:59 +0000591 while (npages--)
Alexey Kardashevskiybc320572014-06-06 18:44:02 +1000592 *(tcep++) = cpu_to_be64(proto_tce |
593 (rpn++ << tbl->it_page_shift));
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000594
Benjamin Herrenschmidt1f1616e2011-11-06 18:55:59 +0000595 /* Some implementations won't cache invalid TCEs and thus may not
596 * need that flush. We'll probably turn it_type into a bit mask
597 * of flags if that becomes the case
598 */
599 if (tbl->it_type & TCE_PCI_SWINV_CREATE)
Alexey Kardashevskiy8e0a1612013-08-28 18:37:43 +1000600 pnv_pci_ioda_tce_invalidate(tbl, tces, tcep - 1, rm);
Benjamin Herrenschmidt1f1616e2011-11-06 18:55:59 +0000601
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000602 return 0;
603}
604
Alexey Kardashevskiy8e0a1612013-08-28 18:37:43 +1000605static int pnv_tce_build_vm(struct iommu_table *tbl, long index, long npages,
606 unsigned long uaddr,
607 enum dma_data_direction direction,
608 struct dma_attrs *attrs)
609{
610 return pnv_tce_build(tbl, index, npages, uaddr, direction, attrs,
611 false);
612}
613
614static void pnv_tce_free(struct iommu_table *tbl, long index, long npages,
615 bool rm)
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000616{
Benjamin Herrenschmidt3a1a4662013-09-23 12:05:01 +1000617 __be64 *tcep, *tces;
Benjamin Herrenschmidt1f1616e2011-11-06 18:55:59 +0000618
Anton Blanchard5e4da532013-09-23 12:05:06 +1000619 tces = tcep = ((__be64 *)tbl->it_base) + index - tbl->it_offset;
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000620
621 while (npages--)
Benjamin Herrenschmidt3a1a4662013-09-23 12:05:01 +1000622 *(tcep++) = cpu_to_be64(0);
Benjamin Herrenschmidt1f1616e2011-11-06 18:55:59 +0000623
Benjamin Herrenschmidt605e44d2013-05-20 17:25:15 +0000624 if (tbl->it_type & TCE_PCI_SWINV_FREE)
Alexey Kardashevskiy8e0a1612013-08-28 18:37:43 +1000625 pnv_pci_ioda_tce_invalidate(tbl, tces, tcep - 1, rm);
626}
627
628static void pnv_tce_free_vm(struct iommu_table *tbl, long index, long npages)
629{
630 pnv_tce_free(tbl, index, npages, false);
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000631}
632
Alexey Kardashevskiy11f63d32012-09-04 15:19:35 +0000633static unsigned long pnv_tce_get(struct iommu_table *tbl, long index)
634{
635 return ((u64 *)tbl->it_base)[index - tbl->it_offset];
636}
637
Alexey Kardashevskiy8e0a1612013-08-28 18:37:43 +1000638static int pnv_tce_build_rm(struct iommu_table *tbl, long index, long npages,
639 unsigned long uaddr,
640 enum dma_data_direction direction,
641 struct dma_attrs *attrs)
642{
643 return pnv_tce_build(tbl, index, npages, uaddr, direction, attrs, true);
644}
645
646static void pnv_tce_free_rm(struct iommu_table *tbl, long index, long npages)
647{
648 pnv_tce_free(tbl, index, npages, true);
649}
650
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000651void pnv_pci_setup_iommu_table(struct iommu_table *tbl,
652 void *tce_mem, u64 tce_size,
Alexey Kardashevskiy8fa5d452014-06-06 18:44:03 +1000653 u64 dma_offset, unsigned page_shift)
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000654{
655 tbl->it_blocksize = 16;
656 tbl->it_base = (unsigned long)tce_mem;
Alexey Kardashevskiy8fa5d452014-06-06 18:44:03 +1000657 tbl->it_page_shift = page_shift;
Alistair Popple3a553172013-12-09 18:17:02 +1100658 tbl->it_offset = dma_offset >> tbl->it_page_shift;
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000659 tbl->it_index = 0;
660 tbl->it_size = tce_size >> 3;
661 tbl->it_busno = 0;
662 tbl->it_type = TCE_PCI;
663}
664
Daniel Axtens92ae0352015-04-28 15:12:05 +1000665void pnv_pci_dma_dev_setup(struct pci_dev *pdev)
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000666{
667 struct pci_controller *hose = pci_bus_to_host(pdev->bus);
668 struct pnv_phb *phb = hose->private_data;
Wei Yang781a8682015-03-25 16:23:57 +0800669#ifdef CONFIG_PCI_IOV
670 struct pnv_ioda_pe *pe;
671 struct pci_dn *pdn;
672
673 /* Fix the VF pdn PE number */
674 if (pdev->is_virtfn) {
675 pdn = pci_get_pdn(pdev);
676 WARN_ON(pdn->pe_number != IODA_INVALID_PE);
677 list_for_each_entry(pe, &phb->ioda.pe_list, list) {
678 if (pe->rid == ((pdev->bus->number << 8) |
679 (pdev->devfn & 0xff))) {
680 pdn->pe_number = pe->pe_number;
681 pe->pdev = pdev;
682 break;
683 }
684 }
685 }
686#endif /* CONFIG_PCI_IOV */
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000687
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000688 if (phb && phb->dma_dev_setup)
689 phb->dma_dev_setup(phb, pdev);
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000690}
691
Gavin Shanfe7e85c2014-09-30 12:39:10 +1000692u64 pnv_pci_dma_get_required_mask(struct pci_dev *pdev)
693{
694 struct pci_controller *hose = pci_bus_to_host(pdev->bus);
695 struct pnv_phb *phb = hose->private_data;
696
697 if (phb && phb->dma_get_required_mask)
698 return phb->dma_get_required_mask(phb, pdev);
699
700 return __dma_get_required_mask(&pdev->dev);
701}
702
Benjamin Herrenschmidt73ed1482013-05-10 16:59:18 +1000703void pnv_pci_shutdown(void)
704{
705 struct pci_controller *hose;
706
Michael Neuling7a8e6bb2015-05-27 16:06:59 +1000707 list_for_each_entry(hose, &hose_list, list_node)
708 if (hose->controller_ops.shutdown)
709 hose->controller_ops.shutdown(hose);
Benjamin Herrenschmidt73ed1482013-05-10 16:59:18 +1000710}
711
Gavin Shanaa0c0332013-04-25 19:20:57 +0000712/* Fixup wrong class code in p7ioc and p8 root complex */
Greg Kroah-Hartmancad5cef2012-12-21 14:04:10 -0800713static void pnv_p7ioc_rc_quirk(struct pci_dev *dev)
Benjamin Herrenschmidtca45cfe2011-11-06 18:56:00 +0000714{
715 dev->class = PCI_CLASS_BRIDGE_PCI << 8;
716}
717DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_IBM, 0x3b9, pnv_p7ioc_rc_quirk);
718
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000719void __init pnv_pci_init(void)
720{
721 struct device_node *np;
Michael Ellerman646b54f2015-03-12 17:27:11 +1100722 bool found_ioda = false;
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000723
Bjorn Helgaas673c9752012-02-23 20:18:58 -0700724 pci_add_flags(PCI_CAN_SKIP_ISA_ALIGN);
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000725
Michael Ellerman646b54f2015-03-12 17:27:11 +1100726 /* If we don't have OPAL, eg. in sim, just skip PCI probe */
727 if (!firmware_has_feature(FW_FEATURE_OPAL))
728 return;
729
730 /* Look for IODA IO-Hubs. We don't support mixing IODA
731 * and p5ioc2 due to the need to change some global
732 * probing flags
733 */
734 for_each_compatible_node(np, NULL, "ibm,ioda-hub") {
735 pnv_pci_init_ioda_hub(np);
736 found_ioda = true;
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000737 }
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000738
Michael Ellerman646b54f2015-03-12 17:27:11 +1100739 /* Look for p5ioc2 IO-Hubs */
740 if (!found_ioda)
741 for_each_compatible_node(np, NULL, "ibm,p5ioc2")
742 pnv_pci_init_p5ioc2_hub(np);
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000743
Michael Ellerman646b54f2015-03-12 17:27:11 +1100744 /* Look for ioda2 built-in PHB3's */
745 for_each_compatible_node(np, NULL, "ibm,ioda2-phb")
746 pnv_pci_init_ioda2_phb(np);
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000747
748 /* Setup the linkage between OF nodes and PHBs */
749 pci_devs_phb_init();
750
751 /* Configure IOMMU DMA hooks */
Alexey Kardashevskiy8e0a1612013-08-28 18:37:43 +1000752 ppc_md.tce_build = pnv_tce_build_vm;
753 ppc_md.tce_free = pnv_tce_free_vm;
754 ppc_md.tce_build_rm = pnv_tce_build_rm;
755 ppc_md.tce_free_rm = pnv_tce_free_rm;
Alexey Kardashevskiy11f63d32012-09-04 15:19:35 +0000756 ppc_md.tce_get = pnv_tce_get;
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000757 set_pci_dma_ops(&dma_iommu_ops);
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000758}
Alexey Kardashevskiyd905c5d2013-11-21 17:43:14 +1100759
Michael Ellermanb14726c2014-07-15 22:22:24 +1000760machine_subsys_initcall_sync(powernv, tce_iommu_bus_notifier_init);