blob: 7d6dcc6d5fa9a6551c2465285cc1886242cc0125 [file] [log] [blame]
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +00001/*
2 * Support PCI/PCIe on PowerNV platforms
3 *
4 * Copyright 2011 Benjamin Herrenschmidt, IBM Corp.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11
Benjamin Herrenschmidtcee72d52011-11-29 18:22:53 +000012#undef DEBUG
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +000013
14#include <linux/kernel.h>
15#include <linux/pci.h>
Gavin Shan37c367f2013-06-20 18:13:25 +080016#include <linux/debugfs.h>
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +000017#include <linux/delay.h>
18#include <linux/string.h>
19#include <linux/init.h>
20#include <linux/bootmem.h>
21#include <linux/irq.h>
22#include <linux/io.h>
23#include <linux/msi.h>
24
25#include <asm/sections.h>
26#include <asm/io.h>
27#include <asm/prom.h>
28#include <asm/pci-bridge.h>
29#include <asm/machdep.h>
Gavin Shanfb1b55d2013-03-05 21:12:37 +000030#include <asm/msi_bitmap.h>
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +000031#include <asm/ppc-pci.h>
32#include <asm/opal.h>
33#include <asm/iommu.h>
34#include <asm/tce.h>
Gavin Shan137436c2013-04-25 19:20:59 +000035#include <asm/xics.h>
Gavin Shan37c367f2013-06-20 18:13:25 +080036#include <asm/debug.h>
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +000037
38#include "powernv.h"
39#include "pci.h"
40
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +000041#define define_pe_printk_level(func, kern_level) \
42static int func(const struct pnv_ioda_pe *pe, const char *fmt, ...) \
43{ \
44 struct va_format vaf; \
45 va_list args; \
Gavin Shan490e0782012-10-17 19:53:30 +000046 char pfix[32]; \
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +000047 int r; \
48 \
49 va_start(args, fmt); \
50 \
51 vaf.fmt = fmt; \
52 vaf.va = &args; \
53 \
Gavin Shan490e0782012-10-17 19:53:30 +000054 if (pe->pdev) \
55 strlcpy(pfix, dev_name(&pe->pdev->dev), \
56 sizeof(pfix)); \
57 else \
58 sprintf(pfix, "%04x:%02x ", \
59 pci_domain_nr(pe->pbus), \
60 pe->pbus->number); \
61 r = printk(kern_level "pci %s: [PE# %.3d] %pV", \
62 pfix, pe->pe_number, &vaf); \
63 \
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +000064 va_end(args); \
65 \
66 return r; \
67} \
68
69define_pe_printk_level(pe_err, KERN_ERR);
70define_pe_printk_level(pe_warn, KERN_WARNING);
71define_pe_printk_level(pe_info, KERN_INFO);
72
Alexey Kardashevskiy8e0a1612013-08-28 18:37:43 +100073/*
74 * stdcix is only supposed to be used in hypervisor real mode as per
75 * the architecture spec
76 */
77static inline void __raw_rm_writeq(u64 val, volatile void __iomem *paddr)
78{
79 __asm__ __volatile__("stdcix %0,0,%1"
80 : : "r" (val), "r" (paddr) : "memory");
81}
82
Greg Kroah-Hartmancad5cef2012-12-21 14:04:10 -080083static int pnv_ioda_alloc_pe(struct pnv_phb *phb)
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +000084{
85 unsigned long pe;
86
87 do {
88 pe = find_next_zero_bit(phb->ioda.pe_alloc,
89 phb->ioda.total_pe, 0);
90 if (pe >= phb->ioda.total_pe)
91 return IODA_INVALID_PE;
92 } while(test_and_set_bit(pe, phb->ioda.pe_alloc));
93
Gavin Shan4cce9552013-04-25 19:21:00 +000094 phb->ioda.pe_array[pe].phb = phb;
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +000095 phb->ioda.pe_array[pe].pe_number = pe;
96 return pe;
97}
98
Greg Kroah-Hartmancad5cef2012-12-21 14:04:10 -080099static void pnv_ioda_free_pe(struct pnv_phb *phb, int pe)
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000100{
101 WARN_ON(phb->ioda.pe_array[pe].pdev);
102
103 memset(&phb->ioda.pe_array[pe], 0, sizeof(struct pnv_ioda_pe));
104 clear_bit(pe, phb->ioda.pe_alloc);
105}
106
107/* Currently those 2 are only used when MSIs are enabled, this will change
108 * but in the meantime, we need to protect them to avoid warnings
109 */
110#ifdef CONFIG_PCI_MSI
Greg Kroah-Hartmancad5cef2012-12-21 14:04:10 -0800111static struct pnv_ioda_pe *pnv_ioda_get_pe(struct pci_dev *dev)
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000112{
113 struct pci_controller *hose = pci_bus_to_host(dev->bus);
114 struct pnv_phb *phb = hose->private_data;
Benjamin Herrenschmidtb72c1f62013-05-21 22:58:21 +0000115 struct pci_dn *pdn = pci_get_pdn(dev);
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000116
117 if (!pdn)
118 return NULL;
119 if (pdn->pe_number == IODA_INVALID_PE)
120 return NULL;
121 return &phb->ioda.pe_array[pdn->pe_number];
122}
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000123#endif /* CONFIG_PCI_MSI */
124
Greg Kroah-Hartmancad5cef2012-12-21 14:04:10 -0800125static int pnv_ioda_configure_pe(struct pnv_phb *phb, struct pnv_ioda_pe *pe)
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000126{
127 struct pci_dev *parent;
128 uint8_t bcomp, dcomp, fcomp;
129 long rc, rid_end, rid;
130
131 /* Bus validation ? */
132 if (pe->pbus) {
133 int count;
134
135 dcomp = OPAL_IGNORE_RID_DEVICE_NUMBER;
136 fcomp = OPAL_IGNORE_RID_FUNCTION_NUMBER;
137 parent = pe->pbus->self;
Gavin Shanfb446ad2012-08-20 03:49:14 +0000138 if (pe->flags & PNV_IODA_PE_BUS_ALL)
139 count = pe->pbus->busn_res.end - pe->pbus->busn_res.start + 1;
140 else
141 count = 1;
142
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000143 switch(count) {
144 case 1: bcomp = OpalPciBusAll; break;
145 case 2: bcomp = OpalPciBus7Bits; break;
146 case 4: bcomp = OpalPciBus6Bits; break;
147 case 8: bcomp = OpalPciBus5Bits; break;
148 case 16: bcomp = OpalPciBus4Bits; break;
149 case 32: bcomp = OpalPciBus3Bits; break;
150 default:
151 pr_err("%s: Number of subordinate busses %d"
152 " unsupported\n",
153 pci_name(pe->pbus->self), count);
154 /* Do an exact match only */
155 bcomp = OpalPciBusAll;
156 }
157 rid_end = pe->rid + (count << 8);
158 } else {
159 parent = pe->pdev->bus->self;
160 bcomp = OpalPciBusAll;
161 dcomp = OPAL_COMPARE_RID_DEVICE_NUMBER;
162 fcomp = OPAL_COMPARE_RID_FUNCTION_NUMBER;
163 rid_end = pe->rid + 1;
164 }
165
Gavin Shan631ad692013-11-04 16:32:46 +0800166 /*
167 * Associate PE in PELT. We need add the PE into the
168 * corresponding PELT-V as well. Otherwise, the error
169 * originated from the PE might contribute to other
170 * PEs.
171 */
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000172 rc = opal_pci_set_pe(phb->opal_id, pe->pe_number, pe->rid,
173 bcomp, dcomp, fcomp, OPAL_MAP_PE);
174 if (rc) {
175 pe_err(pe, "OPAL error %ld trying to setup PELT table\n", rc);
176 return -ENXIO;
177 }
Gavin Shan631ad692013-11-04 16:32:46 +0800178
179 rc = opal_pci_set_peltv(phb->opal_id, pe->pe_number,
180 pe->pe_number, OPAL_ADD_PE_TO_DOMAIN);
181 if (rc)
182 pe_warn(pe, "OPAL error %d adding self to PELTV\n", rc);
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000183 opal_pci_eeh_freeze_clear(phb->opal_id, pe->pe_number,
184 OPAL_EEH_ACTION_CLEAR_FREEZE_ALL);
185
186 /* Add to all parents PELT-V */
187 while (parent) {
Benjamin Herrenschmidtb72c1f62013-05-21 22:58:21 +0000188 struct pci_dn *pdn = pci_get_pdn(parent);
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000189 if (pdn && pdn->pe_number != IODA_INVALID_PE) {
190 rc = opal_pci_set_peltv(phb->opal_id, pdn->pe_number,
Benjamin Herrenschmidtcee72d52011-11-29 18:22:53 +0000191 pe->pe_number, OPAL_ADD_PE_TO_DOMAIN);
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000192 /* XXX What to do in case of error ? */
193 }
194 parent = parent->bus->self;
195 }
196 /* Setup reverse map */
197 for (rid = pe->rid; rid < rid_end; rid++)
198 phb->ioda.pe_rmap[rid] = pe->pe_number;
199
200 /* Setup one MVTs on IODA1 */
201 if (phb->type == PNV_PHB_IODA1) {
202 pe->mve_number = pe->pe_number;
203 rc = opal_pci_set_mve(phb->opal_id, pe->mve_number,
204 pe->pe_number);
205 if (rc) {
206 pe_err(pe, "OPAL error %ld setting up MVE %d\n",
207 rc, pe->mve_number);
208 pe->mve_number = -1;
209 } else {
210 rc = opal_pci_set_mve_enable(phb->opal_id,
Benjamin Herrenschmidtcee72d52011-11-29 18:22:53 +0000211 pe->mve_number, OPAL_ENABLE_MVE);
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000212 if (rc) {
213 pe_err(pe, "OPAL error %ld enabling MVE %d\n",
214 rc, pe->mve_number);
215 pe->mve_number = -1;
216 }
217 }
218 } else if (phb->type == PNV_PHB_IODA2)
219 pe->mve_number = 0;
220
221 return 0;
222}
223
Greg Kroah-Hartmancad5cef2012-12-21 14:04:10 -0800224static void pnv_ioda_link_pe_by_weight(struct pnv_phb *phb,
225 struct pnv_ioda_pe *pe)
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000226{
227 struct pnv_ioda_pe *lpe;
228
Gavin Shan7ebdf952012-08-20 03:49:15 +0000229 list_for_each_entry(lpe, &phb->ioda.pe_dma_list, dma_link) {
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000230 if (lpe->dma_weight < pe->dma_weight) {
Gavin Shan7ebdf952012-08-20 03:49:15 +0000231 list_add_tail(&pe->dma_link, &lpe->dma_link);
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000232 return;
233 }
234 }
Gavin Shan7ebdf952012-08-20 03:49:15 +0000235 list_add_tail(&pe->dma_link, &phb->ioda.pe_dma_list);
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000236}
237
238static unsigned int pnv_ioda_dma_weight(struct pci_dev *dev)
239{
240 /* This is quite simplistic. The "base" weight of a device
241 * is 10. 0 means no DMA is to be accounted for it.
242 */
243
244 /* If it's a bridge, no DMA */
245 if (dev->hdr_type != PCI_HEADER_TYPE_NORMAL)
246 return 0;
247
248 /* Reduce the weight of slow USB controllers */
249 if (dev->class == PCI_CLASS_SERIAL_USB_UHCI ||
250 dev->class == PCI_CLASS_SERIAL_USB_OHCI ||
251 dev->class == PCI_CLASS_SERIAL_USB_EHCI)
252 return 3;
253
254 /* Increase the weight of RAID (includes Obsidian) */
255 if ((dev->class >> 8) == PCI_CLASS_STORAGE_RAID)
256 return 15;
257
258 /* Default */
259 return 10;
260}
261
Gavin Shanfb446ad2012-08-20 03:49:14 +0000262#if 0
Greg Kroah-Hartmancad5cef2012-12-21 14:04:10 -0800263static struct pnv_ioda_pe *pnv_ioda_setup_dev_PE(struct pci_dev *dev)
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000264{
265 struct pci_controller *hose = pci_bus_to_host(dev->bus);
266 struct pnv_phb *phb = hose->private_data;
Benjamin Herrenschmidtb72c1f62013-05-21 22:58:21 +0000267 struct pci_dn *pdn = pci_get_pdn(dev);
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000268 struct pnv_ioda_pe *pe;
269 int pe_num;
270
271 if (!pdn) {
272 pr_err("%s: Device tree node not associated properly\n",
273 pci_name(dev));
274 return NULL;
275 }
276 if (pdn->pe_number != IODA_INVALID_PE)
277 return NULL;
278
279 /* PE#0 has been pre-set */
280 if (dev->bus->number == 0)
281 pe_num = 0;
282 else
283 pe_num = pnv_ioda_alloc_pe(phb);
284 if (pe_num == IODA_INVALID_PE) {
285 pr_warning("%s: Not enough PE# available, disabling device\n",
286 pci_name(dev));
287 return NULL;
288 }
289
290 /* NOTE: We get only one ref to the pci_dev for the pdn, not for the
291 * pointer in the PE data structure, both should be destroyed at the
292 * same time. However, this needs to be looked at more closely again
293 * once we actually start removing things (Hotplug, SR-IOV, ...)
294 *
295 * At some point we want to remove the PDN completely anyways
296 */
297 pe = &phb->ioda.pe_array[pe_num];
298 pci_dev_get(dev);
299 pdn->pcidev = dev;
300 pdn->pe_number = pe_num;
301 pe->pdev = dev;
302 pe->pbus = NULL;
303 pe->tce32_seg = -1;
304 pe->mve_number = -1;
305 pe->rid = dev->bus->number << 8 | pdn->devfn;
306
307 pe_info(pe, "Associated device to PE\n");
308
309 if (pnv_ioda_configure_pe(phb, pe)) {
310 /* XXX What do we do here ? */
311 if (pe_num)
312 pnv_ioda_free_pe(phb, pe_num);
313 pdn->pe_number = IODA_INVALID_PE;
314 pe->pdev = NULL;
315 pci_dev_put(dev);
316 return NULL;
317 }
318
319 /* Assign a DMA weight to the device */
320 pe->dma_weight = pnv_ioda_dma_weight(dev);
321 if (pe->dma_weight != 0) {
322 phb->ioda.dma_weight += pe->dma_weight;
323 phb->ioda.dma_pe_count++;
324 }
325
326 /* Link the PE */
327 pnv_ioda_link_pe_by_weight(phb, pe);
328
329 return pe;
330}
Gavin Shanfb446ad2012-08-20 03:49:14 +0000331#endif /* Useful for SRIOV case */
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000332
333static void pnv_ioda_setup_same_PE(struct pci_bus *bus, struct pnv_ioda_pe *pe)
334{
335 struct pci_dev *dev;
336
337 list_for_each_entry(dev, &bus->devices, bus_list) {
Benjamin Herrenschmidtb72c1f62013-05-21 22:58:21 +0000338 struct pci_dn *pdn = pci_get_pdn(dev);
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000339
340 if (pdn == NULL) {
341 pr_warn("%s: No device node associated with device !\n",
342 pci_name(dev));
343 continue;
344 }
345 pci_dev_get(dev);
346 pdn->pcidev = dev;
347 pdn->pe_number = pe->pe_number;
348 pe->dma_weight += pnv_ioda_dma_weight(dev);
Gavin Shanfb446ad2012-08-20 03:49:14 +0000349 if ((pe->flags & PNV_IODA_PE_BUS_ALL) && dev->subordinate)
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000350 pnv_ioda_setup_same_PE(dev->subordinate, pe);
351 }
352}
353
Gavin Shanfb446ad2012-08-20 03:49:14 +0000354/*
355 * There're 2 types of PCI bus sensitive PEs: One that is compromised of
356 * single PCI bus. Another one that contains the primary PCI bus and its
357 * subordinate PCI devices and buses. The second type of PE is normally
358 * orgiriated by PCIe-to-PCI bridge or PLX switch downstream ports.
359 */
Greg Kroah-Hartmancad5cef2012-12-21 14:04:10 -0800360static void pnv_ioda_setup_bus_PE(struct pci_bus *bus, int all)
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000361{
Gavin Shanfb446ad2012-08-20 03:49:14 +0000362 struct pci_controller *hose = pci_bus_to_host(bus);
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000363 struct pnv_phb *phb = hose->private_data;
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000364 struct pnv_ioda_pe *pe;
365 int pe_num;
366
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000367 pe_num = pnv_ioda_alloc_pe(phb);
368 if (pe_num == IODA_INVALID_PE) {
Gavin Shanfb446ad2012-08-20 03:49:14 +0000369 pr_warning("%s: Not enough PE# available for PCI bus %04x:%02x\n",
370 __func__, pci_domain_nr(bus), bus->number);
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000371 return;
372 }
373
374 pe = &phb->ioda.pe_array[pe_num];
Gavin Shanfb446ad2012-08-20 03:49:14 +0000375 pe->flags = (all ? PNV_IODA_PE_BUS_ALL : PNV_IODA_PE_BUS);
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000376 pe->pbus = bus;
377 pe->pdev = NULL;
378 pe->tce32_seg = -1;
379 pe->mve_number = -1;
Yinghai Lub918c622012-05-17 18:51:11 -0700380 pe->rid = bus->busn_res.start << 8;
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000381 pe->dma_weight = 0;
382
Gavin Shanfb446ad2012-08-20 03:49:14 +0000383 if (all)
384 pe_info(pe, "Secondary bus %d..%d associated with PE#%d\n",
385 bus->busn_res.start, bus->busn_res.end, pe_num);
386 else
387 pe_info(pe, "Secondary bus %d associated with PE#%d\n",
388 bus->busn_res.start, pe_num);
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000389
390 if (pnv_ioda_configure_pe(phb, pe)) {
391 /* XXX What do we do here ? */
392 if (pe_num)
393 pnv_ioda_free_pe(phb, pe_num);
394 pe->pbus = NULL;
395 return;
396 }
397
398 /* Associate it with all child devices */
399 pnv_ioda_setup_same_PE(bus, pe);
400
Gavin Shan7ebdf952012-08-20 03:49:15 +0000401 /* Put PE to the list */
402 list_add_tail(&pe->list, &phb->ioda.pe_list);
403
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000404 /* Account for one DMA PE if at least one DMA capable device exist
405 * below the bridge
406 */
407 if (pe->dma_weight != 0) {
408 phb->ioda.dma_weight += pe->dma_weight;
409 phb->ioda.dma_pe_count++;
410 }
411
412 /* Link the PE */
413 pnv_ioda_link_pe_by_weight(phb, pe);
414}
415
Greg Kroah-Hartmancad5cef2012-12-21 14:04:10 -0800416static void pnv_ioda_setup_PEs(struct pci_bus *bus)
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000417{
418 struct pci_dev *dev;
Gavin Shanfb446ad2012-08-20 03:49:14 +0000419
420 pnv_ioda_setup_bus_PE(bus, 0);
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000421
422 list_for_each_entry(dev, &bus->devices, bus_list) {
Gavin Shanfb446ad2012-08-20 03:49:14 +0000423 if (dev->subordinate) {
424 if (pci_pcie_type(dev) == PCI_EXP_TYPE_PCI_BRIDGE)
425 pnv_ioda_setup_bus_PE(dev->subordinate, 1);
426 else
427 pnv_ioda_setup_PEs(dev->subordinate);
428 }
429 }
430}
431
432/*
433 * Configure PEs so that the downstream PCI buses and devices
434 * could have their associated PE#. Unfortunately, we didn't
435 * figure out the way to identify the PLX bridge yet. So we
436 * simply put the PCI bus and the subordinate behind the root
437 * port to PE# here. The game rule here is expected to be changed
438 * as soon as we can detected PLX bridge correctly.
439 */
Greg Kroah-Hartmancad5cef2012-12-21 14:04:10 -0800440static void pnv_pci_ioda_setup_PEs(void)
Gavin Shanfb446ad2012-08-20 03:49:14 +0000441{
442 struct pci_controller *hose, *tmp;
443
444 list_for_each_entry_safe(hose, tmp, &hose_list, list_node) {
445 pnv_ioda_setup_PEs(hose->bus);
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000446 }
447}
448
Gavin Shan959c9bd2013-04-25 19:21:02 +0000449static void pnv_pci_ioda_dma_dev_setup(struct pnv_phb *phb, struct pci_dev *pdev)
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000450{
Benjamin Herrenschmidtb72c1f62013-05-21 22:58:21 +0000451 struct pci_dn *pdn = pci_get_pdn(pdev);
Gavin Shan959c9bd2013-04-25 19:21:02 +0000452 struct pnv_ioda_pe *pe;
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000453
Gavin Shan959c9bd2013-04-25 19:21:02 +0000454 /*
455 * The function can be called while the PE#
456 * hasn't been assigned. Do nothing for the
457 * case.
458 */
459 if (!pdn || pdn->pe_number == IODA_INVALID_PE)
460 return;
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000461
Gavin Shan959c9bd2013-04-25 19:21:02 +0000462 pe = &phb->ioda.pe_array[pdn->pe_number];
Alexey Kardashevskiyd905c5d2013-11-21 17:43:14 +1100463 set_iommu_table_base_and_group(&pdev->dev, &pe->tce32_table);
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000464}
465
Benjamin Herrenschmidt74251fe2013-07-01 17:54:09 +1000466static void pnv_ioda_setup_bus_dma(struct pnv_ioda_pe *pe, struct pci_bus *bus)
467{
468 struct pci_dev *dev;
469
470 list_for_each_entry(dev, &bus->devices, bus_list) {
Alexey Kardashevskiyd905c5d2013-11-21 17:43:14 +1100471 set_iommu_table_base_and_group(&dev->dev, &pe->tce32_table);
Benjamin Herrenschmidt74251fe2013-07-01 17:54:09 +1000472 if (dev->subordinate)
473 pnv_ioda_setup_bus_dma(pe, dev->subordinate);
474 }
475}
476
Alexey Kardashevskiy8e0a1612013-08-28 18:37:43 +1000477static void pnv_pci_ioda1_tce_invalidate(struct pnv_ioda_pe *pe,
478 struct iommu_table *tbl,
Benjamin Herrenschmidt3ad26e52013-10-11 18:23:53 +1100479 __be64 *startp, __be64 *endp, bool rm)
Gavin Shan4cce9552013-04-25 19:21:00 +0000480{
Benjamin Herrenschmidt3ad26e52013-10-11 18:23:53 +1100481 __be64 __iomem *invalidate = rm ?
482 (__be64 __iomem *)pe->tce_inval_reg_phys :
483 (__be64 __iomem *)tbl->it_index;
Gavin Shan4cce9552013-04-25 19:21:00 +0000484 unsigned long start, end, inc;
485
486 start = __pa(startp);
487 end = __pa(endp);
488
489 /* BML uses this case for p6/p7/galaxy2: Shift addr and put in node */
490 if (tbl->it_busno) {
491 start <<= 12;
492 end <<= 12;
493 inc = 128 << 12;
494 start |= tbl->it_busno;
495 end |= tbl->it_busno;
496 } else if (tbl->it_type & TCE_PCI_SWINV_PAIR) {
497 /* p7ioc-style invalidation, 2 TCEs per write */
498 start |= (1ull << 63);
499 end |= (1ull << 63);
500 inc = 16;
501 } else {
502 /* Default (older HW) */
503 inc = 128;
504 }
505
506 end |= inc - 1; /* round up end to be different than start */
507
508 mb(); /* Ensure above stores are visible */
509 while (start <= end) {
Alexey Kardashevskiy8e0a1612013-08-28 18:37:43 +1000510 if (rm)
Benjamin Herrenschmidt3ad26e52013-10-11 18:23:53 +1100511 __raw_rm_writeq(cpu_to_be64(start), invalidate);
Alexey Kardashevskiy8e0a1612013-08-28 18:37:43 +1000512 else
Benjamin Herrenschmidt3ad26e52013-10-11 18:23:53 +1100513 __raw_writeq(cpu_to_be64(start), invalidate);
Gavin Shan4cce9552013-04-25 19:21:00 +0000514 start += inc;
515 }
516
517 /*
518 * The iommu layer will do another mb() for us on build()
519 * and we don't care on free()
520 */
521}
522
523static void pnv_pci_ioda2_tce_invalidate(struct pnv_ioda_pe *pe,
524 struct iommu_table *tbl,
Benjamin Herrenschmidt3ad26e52013-10-11 18:23:53 +1100525 __be64 *startp, __be64 *endp, bool rm)
Gavin Shan4cce9552013-04-25 19:21:00 +0000526{
527 unsigned long start, end, inc;
Benjamin Herrenschmidt3ad26e52013-10-11 18:23:53 +1100528 __be64 __iomem *invalidate = rm ?
529 (__be64 __iomem *)pe->tce_inval_reg_phys :
530 (__be64 __iomem *)tbl->it_index;
Gavin Shan4cce9552013-04-25 19:21:00 +0000531
532 /* We'll invalidate DMA address in PE scope */
533 start = 0x2ul << 60;
534 start |= (pe->pe_number & 0xFF);
535 end = start;
536
537 /* Figure out the start, end and step */
538 inc = tbl->it_offset + (((u64)startp - tbl->it_base) / sizeof(u64));
539 start |= (inc << 12);
540 inc = tbl->it_offset + (((u64)endp - tbl->it_base) / sizeof(u64));
541 end |= (inc << 12);
542 inc = (0x1ul << 12);
543 mb();
544
545 while (start <= end) {
Alexey Kardashevskiy8e0a1612013-08-28 18:37:43 +1000546 if (rm)
Benjamin Herrenschmidt3ad26e52013-10-11 18:23:53 +1100547 __raw_rm_writeq(cpu_to_be64(start), invalidate);
Alexey Kardashevskiy8e0a1612013-08-28 18:37:43 +1000548 else
Benjamin Herrenschmidt3ad26e52013-10-11 18:23:53 +1100549 __raw_writeq(cpu_to_be64(start), invalidate);
Gavin Shan4cce9552013-04-25 19:21:00 +0000550 start += inc;
551 }
552}
553
554void pnv_pci_ioda_tce_invalidate(struct iommu_table *tbl,
Benjamin Herrenschmidt3ad26e52013-10-11 18:23:53 +1100555 __be64 *startp, __be64 *endp, bool rm)
Gavin Shan4cce9552013-04-25 19:21:00 +0000556{
557 struct pnv_ioda_pe *pe = container_of(tbl, struct pnv_ioda_pe,
558 tce32_table);
559 struct pnv_phb *phb = pe->phb;
560
561 if (phb->type == PNV_PHB_IODA1)
Alexey Kardashevskiy8e0a1612013-08-28 18:37:43 +1000562 pnv_pci_ioda1_tce_invalidate(pe, tbl, startp, endp, rm);
Gavin Shan4cce9552013-04-25 19:21:00 +0000563 else
Alexey Kardashevskiy8e0a1612013-08-28 18:37:43 +1000564 pnv_pci_ioda2_tce_invalidate(pe, tbl, startp, endp, rm);
Gavin Shan4cce9552013-04-25 19:21:00 +0000565}
566
Greg Kroah-Hartmancad5cef2012-12-21 14:04:10 -0800567static void pnv_pci_ioda_setup_dma_pe(struct pnv_phb *phb,
568 struct pnv_ioda_pe *pe, unsigned int base,
569 unsigned int segs)
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000570{
571
572 struct page *tce_mem = NULL;
573 const __be64 *swinvp;
574 struct iommu_table *tbl;
575 unsigned int i;
576 int64_t rc;
577 void *addr;
578
579 /* 256M DMA window, 4K TCE pages, 8 bytes TCE */
580#define TCE32_TABLE_SIZE ((0x10000000 / 0x1000) * 8)
581
582 /* XXX FIXME: Handle 64-bit only DMA devices */
583 /* XXX FIXME: Provide 64-bit DMA facilities & non-4K TCE tables etc.. */
584 /* XXX FIXME: Allocate multi-level tables on PHB3 */
585
586 /* We shouldn't already have a 32-bit DMA associated */
587 if (WARN_ON(pe->tce32_seg >= 0))
588 return;
589
590 /* Grab a 32-bit TCE table */
591 pe->tce32_seg = base;
592 pe_info(pe, " Setting up 32-bit TCE table at %08x..%08x\n",
593 (base << 28), ((base + segs) << 28) - 1);
594
595 /* XXX Currently, we allocate one big contiguous table for the
596 * TCEs. We only really need one chunk per 256M of TCE space
597 * (ie per segment) but that's an optimization for later, it
598 * requires some added smarts with our get/put_tce implementation
599 */
600 tce_mem = alloc_pages_node(phb->hose->node, GFP_KERNEL,
601 get_order(TCE32_TABLE_SIZE * segs));
602 if (!tce_mem) {
603 pe_err(pe, " Failed to allocate a 32-bit TCE memory\n");
604 goto fail;
605 }
606 addr = page_address(tce_mem);
607 memset(addr, 0, TCE32_TABLE_SIZE * segs);
608
609 /* Configure HW */
610 for (i = 0; i < segs; i++) {
611 rc = opal_pci_map_pe_dma_window(phb->opal_id,
612 pe->pe_number,
613 base + i, 1,
614 __pa(addr) + TCE32_TABLE_SIZE * i,
615 TCE32_TABLE_SIZE, 0x1000);
616 if (rc) {
617 pe_err(pe, " Failed to configure 32-bit TCE table,"
618 " err %ld\n", rc);
619 goto fail;
620 }
621 }
622
623 /* Setup linux iommu table */
624 tbl = &pe->tce32_table;
625 pnv_pci_setup_iommu_table(tbl, addr, TCE32_TABLE_SIZE * segs,
626 base << 28);
627
628 /* OPAL variant of P7IOC SW invalidated TCEs */
629 swinvp = of_get_property(phb->hose->dn, "ibm,opal-tce-kill", NULL);
630 if (swinvp) {
631 /* We need a couple more fields -- an address and a data
632 * to or. Since the bus is only printed out on table free
633 * errors, and on the first pass the data will be a relative
634 * bus number, print that out instead.
635 */
636 tbl->it_busno = 0;
Alexey Kardashevskiy8e0a1612013-08-28 18:37:43 +1000637 pe->tce_inval_reg_phys = be64_to_cpup(swinvp);
638 tbl->it_index = (unsigned long)ioremap(pe->tce_inval_reg_phys,
639 8);
Gavin Shan373f5652013-04-25 19:21:01 +0000640 tbl->it_type = TCE_PCI_SWINV_CREATE | TCE_PCI_SWINV_FREE |
641 TCE_PCI_SWINV_PAIR;
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000642 }
643 iommu_init_table(tbl, phb->hose->node);
Alexey Kardashevskiy4e13c1a2013-05-21 13:33:09 +1000644 iommu_register_group(tbl, pci_domain_nr(pe->pbus), pe->pe_number);
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000645
Benjamin Herrenschmidt74251fe2013-07-01 17:54:09 +1000646 if (pe->pdev)
Alexey Kardashevskiyd905c5d2013-11-21 17:43:14 +1100647 set_iommu_table_base_and_group(&pe->pdev->dev, tbl);
Benjamin Herrenschmidt74251fe2013-07-01 17:54:09 +1000648 else
649 pnv_ioda_setup_bus_dma(pe, pe->pbus);
650
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000651 return;
652 fail:
653 /* XXX Failure: Try to fallback to 64-bit only ? */
654 if (pe->tce32_seg >= 0)
655 pe->tce32_seg = -1;
656 if (tce_mem)
657 __free_pages(tce_mem, get_order(TCE32_TABLE_SIZE * segs));
658}
659
Gavin Shan373f5652013-04-25 19:21:01 +0000660static void pnv_pci_ioda2_setup_dma_pe(struct pnv_phb *phb,
661 struct pnv_ioda_pe *pe)
662{
663 struct page *tce_mem = NULL;
664 void *addr;
665 const __be64 *swinvp;
666 struct iommu_table *tbl;
667 unsigned int tce_table_size, end;
668 int64_t rc;
669
670 /* We shouldn't already have a 32-bit DMA associated */
671 if (WARN_ON(pe->tce32_seg >= 0))
672 return;
673
674 /* The PE will reserve all possible 32-bits space */
675 pe->tce32_seg = 0;
676 end = (1 << ilog2(phb->ioda.m32_pci_base));
677 tce_table_size = (end / 0x1000) * 8;
678 pe_info(pe, "Setting up 32-bit TCE table at 0..%08x\n",
679 end);
680
681 /* Allocate TCE table */
682 tce_mem = alloc_pages_node(phb->hose->node, GFP_KERNEL,
683 get_order(tce_table_size));
684 if (!tce_mem) {
685 pe_err(pe, "Failed to allocate a 32-bit TCE memory\n");
686 goto fail;
687 }
688 addr = page_address(tce_mem);
689 memset(addr, 0, tce_table_size);
690
691 /*
692 * Map TCE table through TVT. The TVE index is the PE number
693 * shifted by 1 bit for 32-bits DMA space.
694 */
695 rc = opal_pci_map_pe_dma_window(phb->opal_id, pe->pe_number,
696 pe->pe_number << 1, 1, __pa(addr),
697 tce_table_size, 0x1000);
698 if (rc) {
699 pe_err(pe, "Failed to configure 32-bit TCE table,"
700 " err %ld\n", rc);
701 goto fail;
702 }
703
704 /* Setup linux iommu table */
705 tbl = &pe->tce32_table;
706 pnv_pci_setup_iommu_table(tbl, addr, tce_table_size, 0);
707
708 /* OPAL variant of PHB3 invalidated TCEs */
709 swinvp = of_get_property(phb->hose->dn, "ibm,opal-tce-kill", NULL);
710 if (swinvp) {
711 /* We need a couple more fields -- an address and a data
712 * to or. Since the bus is only printed out on table free
713 * errors, and on the first pass the data will be a relative
714 * bus number, print that out instead.
715 */
716 tbl->it_busno = 0;
Alexey Kardashevskiy8e0a1612013-08-28 18:37:43 +1000717 pe->tce_inval_reg_phys = be64_to_cpup(swinvp);
718 tbl->it_index = (unsigned long)ioremap(pe->tce_inval_reg_phys,
719 8);
Gavin Shan373f5652013-04-25 19:21:01 +0000720 tbl->it_type = TCE_PCI_SWINV_CREATE | TCE_PCI_SWINV_FREE;
721 }
722 iommu_init_table(tbl, phb->hose->node);
Thadeu Lima de Souza Cascardo08607af2013-12-09 14:41:01 -0200723 iommu_register_group(tbl, pci_domain_nr(pe->pbus), pe->pe_number);
Gavin Shan373f5652013-04-25 19:21:01 +0000724
Benjamin Herrenschmidt74251fe2013-07-01 17:54:09 +1000725 if (pe->pdev)
Alexey Kardashevskiyd905c5d2013-11-21 17:43:14 +1100726 set_iommu_table_base_and_group(&pe->pdev->dev, tbl);
Benjamin Herrenschmidt74251fe2013-07-01 17:54:09 +1000727 else
728 pnv_ioda_setup_bus_dma(pe, pe->pbus);
729
Gavin Shan373f5652013-04-25 19:21:01 +0000730 return;
731fail:
732 if (pe->tce32_seg >= 0)
733 pe->tce32_seg = -1;
734 if (tce_mem)
735 __free_pages(tce_mem, get_order(tce_table_size));
736}
737
Greg Kroah-Hartmancad5cef2012-12-21 14:04:10 -0800738static void pnv_ioda_setup_dma(struct pnv_phb *phb)
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000739{
740 struct pci_controller *hose = phb->hose;
741 unsigned int residual, remaining, segs, tw, base;
742 struct pnv_ioda_pe *pe;
743
744 /* If we have more PE# than segments available, hand out one
745 * per PE until we run out and let the rest fail. If not,
746 * then we assign at least one segment per PE, plus more based
747 * on the amount of devices under that PE
748 */
749 if (phb->ioda.dma_pe_count > phb->ioda.tce32_count)
750 residual = 0;
751 else
752 residual = phb->ioda.tce32_count -
753 phb->ioda.dma_pe_count;
754
755 pr_info("PCI: Domain %04x has %ld available 32-bit DMA segments\n",
756 hose->global_number, phb->ioda.tce32_count);
757 pr_info("PCI: %d PE# for a total weight of %d\n",
758 phb->ioda.dma_pe_count, phb->ioda.dma_weight);
759
760 /* Walk our PE list and configure their DMA segments, hand them
761 * out one base segment plus any residual segments based on
762 * weight
763 */
764 remaining = phb->ioda.tce32_count;
765 tw = phb->ioda.dma_weight;
766 base = 0;
Gavin Shan7ebdf952012-08-20 03:49:15 +0000767 list_for_each_entry(pe, &phb->ioda.pe_dma_list, dma_link) {
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000768 if (!pe->dma_weight)
769 continue;
770 if (!remaining) {
771 pe_warn(pe, "No DMA32 resources available\n");
772 continue;
773 }
774 segs = 1;
775 if (residual) {
776 segs += ((pe->dma_weight * residual) + (tw / 2)) / tw;
777 if (segs > remaining)
778 segs = remaining;
779 }
Gavin Shan373f5652013-04-25 19:21:01 +0000780
781 /*
782 * For IODA2 compliant PHB3, we needn't care about the weight.
783 * The all available 32-bits DMA space will be assigned to
784 * the specific PE.
785 */
786 if (phb->type == PNV_PHB_IODA1) {
787 pe_info(pe, "DMA weight %d, assigned %d DMA32 segments\n",
788 pe->dma_weight, segs);
789 pnv_pci_ioda_setup_dma_pe(phb, pe, base, segs);
790 } else {
791 pe_info(pe, "Assign DMA32 space\n");
792 segs = 0;
793 pnv_pci_ioda2_setup_dma_pe(phb, pe);
794 }
795
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000796 remaining -= segs;
797 base += segs;
798 }
799}
800
801#ifdef CONFIG_PCI_MSI
Gavin Shan137436c2013-04-25 19:20:59 +0000802static void pnv_ioda2_msi_eoi(struct irq_data *d)
803{
804 unsigned int hw_irq = (unsigned int)irqd_to_hwirq(d);
805 struct irq_chip *chip = irq_data_get_irq_chip(d);
806 struct pnv_phb *phb = container_of(chip, struct pnv_phb,
807 ioda.irq_chip);
808 int64_t rc;
809
810 rc = opal_pci_msi_eoi(phb->opal_id, hw_irq);
811 WARN_ON_ONCE(rc);
812
813 icp_native_eoi(d);
814}
815
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000816static int pnv_pci_ioda_msi_setup(struct pnv_phb *phb, struct pci_dev *dev,
Gavin Shan137436c2013-04-25 19:20:59 +0000817 unsigned int hwirq, unsigned int virq,
818 unsigned int is_64, struct msi_msg *msg)
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000819{
820 struct pnv_ioda_pe *pe = pnv_ioda_get_pe(dev);
Benjamin Herrenschmidtb72c1f62013-05-21 22:58:21 +0000821 struct pci_dn *pdn = pci_get_pdn(dev);
Gavin Shan137436c2013-04-25 19:20:59 +0000822 struct irq_data *idata;
823 struct irq_chip *ichip;
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000824 unsigned int xive_num = hwirq - phb->msi_base;
Benjamin Herrenschmidt3a1a4662013-09-23 12:05:01 +1000825 __be32 data;
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000826 int rc;
827
828 /* No PE assigned ? bail out ... no MSI for you ! */
829 if (pe == NULL)
830 return -ENXIO;
831
832 /* Check if we have an MVE */
833 if (pe->mve_number < 0)
834 return -ENXIO;
835
Benjamin Herrenschmidtb72c1f62013-05-21 22:58:21 +0000836 /* Force 32-bit MSI on some broken devices */
837 if (pdn && pdn->force_32bit_msi)
838 is_64 = 0;
839
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000840 /* Assign XIVE to PE */
841 rc = opal_pci_set_xive_pe(phb->opal_id, pe->pe_number, xive_num);
842 if (rc) {
843 pr_warn("%s: OPAL error %d setting XIVE %d PE\n",
844 pci_name(dev), rc, xive_num);
845 return -EIO;
846 }
847
848 if (is_64) {
Benjamin Herrenschmidt3a1a4662013-09-23 12:05:01 +1000849 __be64 addr64;
850
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000851 rc = opal_get_msi_64(phb->opal_id, pe->mve_number, xive_num, 1,
852 &addr64, &data);
853 if (rc) {
854 pr_warn("%s: OPAL error %d getting 64-bit MSI data\n",
855 pci_name(dev), rc);
856 return -EIO;
857 }
Benjamin Herrenschmidt3a1a4662013-09-23 12:05:01 +1000858 msg->address_hi = be64_to_cpu(addr64) >> 32;
859 msg->address_lo = be64_to_cpu(addr64) & 0xfffffffful;
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000860 } else {
Benjamin Herrenschmidt3a1a4662013-09-23 12:05:01 +1000861 __be32 addr32;
862
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000863 rc = opal_get_msi_32(phb->opal_id, pe->mve_number, xive_num, 1,
864 &addr32, &data);
865 if (rc) {
866 pr_warn("%s: OPAL error %d getting 32-bit MSI data\n",
867 pci_name(dev), rc);
868 return -EIO;
869 }
870 msg->address_hi = 0;
Benjamin Herrenschmidt3a1a4662013-09-23 12:05:01 +1000871 msg->address_lo = be32_to_cpu(addr32);
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000872 }
Benjamin Herrenschmidt3a1a4662013-09-23 12:05:01 +1000873 msg->data = be32_to_cpu(data);
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000874
Gavin Shan137436c2013-04-25 19:20:59 +0000875 /*
876 * Change the IRQ chip for the MSI interrupts on PHB3.
877 * The corresponding IRQ chip should be populated for
878 * the first time.
879 */
880 if (phb->type == PNV_PHB_IODA2) {
881 if (!phb->ioda.irq_chip_init) {
882 idata = irq_get_irq_data(virq);
883 ichip = irq_data_get_irq_chip(idata);
884 phb->ioda.irq_chip_init = 1;
885 phb->ioda.irq_chip = *ichip;
886 phb->ioda.irq_chip.irq_eoi = pnv_ioda2_msi_eoi;
887 }
888
889 irq_set_chip(virq, &phb->ioda.irq_chip);
890 }
891
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000892 pr_devel("%s: %s-bit MSI on hwirq %x (xive #%d),"
893 " address=%x_%08x data=%x PE# %d\n",
894 pci_name(dev), is_64 ? "64" : "32", hwirq, xive_num,
895 msg->address_hi, msg->address_lo, data, pe->pe_number);
896
897 return 0;
898}
899
900static void pnv_pci_init_ioda_msis(struct pnv_phb *phb)
901{
Gavin Shanfb1b55d2013-03-05 21:12:37 +0000902 unsigned int count;
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000903 const __be32 *prop = of_get_property(phb->hose->dn,
904 "ibm,opal-msi-ranges", NULL);
905 if (!prop) {
906 /* BML Fallback */
907 prop = of_get_property(phb->hose->dn, "msi-ranges", NULL);
908 }
909 if (!prop)
910 return;
911
912 phb->msi_base = be32_to_cpup(prop);
Gavin Shanfb1b55d2013-03-05 21:12:37 +0000913 count = be32_to_cpup(prop + 1);
914 if (msi_bitmap_alloc(&phb->msi_bmp, count, phb->hose->dn)) {
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000915 pr_err("PCI %d: Failed to allocate MSI bitmap !\n",
916 phb->hose->global_number);
917 return;
918 }
Gavin Shanfb1b55d2013-03-05 21:12:37 +0000919
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000920 phb->msi_setup = pnv_pci_ioda_msi_setup;
921 phb->msi32_support = 1;
922 pr_info(" Allocated bitmap for %d MSIs (base IRQ 0x%x)\n",
Gavin Shanfb1b55d2013-03-05 21:12:37 +0000923 count, phb->msi_base);
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000924}
925#else
926static void pnv_pci_init_ioda_msis(struct pnv_phb *phb) { }
927#endif /* CONFIG_PCI_MSI */
928
Gavin Shan11685be2012-08-20 03:49:16 +0000929/*
930 * This function is supposed to be called on basis of PE from top
931 * to bottom style. So the the I/O or MMIO segment assigned to
932 * parent PE could be overrided by its child PEs if necessary.
933 */
Greg Kroah-Hartmancad5cef2012-12-21 14:04:10 -0800934static void pnv_ioda_setup_pe_seg(struct pci_controller *hose,
935 struct pnv_ioda_pe *pe)
Gavin Shan11685be2012-08-20 03:49:16 +0000936{
937 struct pnv_phb *phb = hose->private_data;
938 struct pci_bus_region region;
939 struct resource *res;
940 int i, index;
941 int rc;
942
943 /*
944 * NOTE: We only care PCI bus based PE for now. For PCI
945 * device based PE, for example SRIOV sensitive VF should
946 * be figured out later.
947 */
948 BUG_ON(!(pe->flags & (PNV_IODA_PE_BUS | PNV_IODA_PE_BUS_ALL)));
949
950 pci_bus_for_each_resource(pe->pbus, res, i) {
951 if (!res || !res->flags ||
952 res->start > res->end)
953 continue;
954
955 if (res->flags & IORESOURCE_IO) {
956 region.start = res->start - phb->ioda.io_pci_base;
957 region.end = res->end - phb->ioda.io_pci_base;
958 index = region.start / phb->ioda.io_segsize;
959
960 while (index < phb->ioda.total_pe &&
961 region.start <= region.end) {
962 phb->ioda.io_segmap[index] = pe->pe_number;
963 rc = opal_pci_map_pe_mmio_window(phb->opal_id,
964 pe->pe_number, OPAL_IO_WINDOW_TYPE, 0, index);
965 if (rc != OPAL_SUCCESS) {
966 pr_err("%s: OPAL error %d when mapping IO "
967 "segment #%d to PE#%d\n",
968 __func__, rc, index, pe->pe_number);
969 break;
970 }
971
972 region.start += phb->ioda.io_segsize;
973 index++;
974 }
975 } else if (res->flags & IORESOURCE_MEM) {
Benjamin Herrenschmidt3fd47f02013-05-06 13:40:40 +1000976 /* WARNING: Assumes M32 is mem region 0 in PHB. We need to
977 * harden that algorithm when we start supporting M64
978 */
Gavin Shan11685be2012-08-20 03:49:16 +0000979 region.start = res->start -
Benjamin Herrenschmidt3fd47f02013-05-06 13:40:40 +1000980 hose->mem_offset[0] -
Gavin Shan11685be2012-08-20 03:49:16 +0000981 phb->ioda.m32_pci_base;
982 region.end = res->end -
Benjamin Herrenschmidt3fd47f02013-05-06 13:40:40 +1000983 hose->mem_offset[0] -
Gavin Shan11685be2012-08-20 03:49:16 +0000984 phb->ioda.m32_pci_base;
985 index = region.start / phb->ioda.m32_segsize;
986
987 while (index < phb->ioda.total_pe &&
988 region.start <= region.end) {
989 phb->ioda.m32_segmap[index] = pe->pe_number;
990 rc = opal_pci_map_pe_mmio_window(phb->opal_id,
991 pe->pe_number, OPAL_M32_WINDOW_TYPE, 0, index);
992 if (rc != OPAL_SUCCESS) {
993 pr_err("%s: OPAL error %d when mapping M32 "
994 "segment#%d to PE#%d",
995 __func__, rc, index, pe->pe_number);
996 break;
997 }
998
999 region.start += phb->ioda.m32_segsize;
1000 index++;
1001 }
1002 }
1003 }
1004}
1005
Greg Kroah-Hartmancad5cef2012-12-21 14:04:10 -08001006static void pnv_pci_ioda_setup_seg(void)
Gavin Shan11685be2012-08-20 03:49:16 +00001007{
1008 struct pci_controller *tmp, *hose;
1009 struct pnv_phb *phb;
1010 struct pnv_ioda_pe *pe;
1011
1012 list_for_each_entry_safe(hose, tmp, &hose_list, list_node) {
1013 phb = hose->private_data;
1014 list_for_each_entry(pe, &phb->ioda.pe_list, list) {
1015 pnv_ioda_setup_pe_seg(hose, pe);
1016 }
1017 }
1018}
1019
Greg Kroah-Hartmancad5cef2012-12-21 14:04:10 -08001020static void pnv_pci_ioda_setup_DMA(void)
Gavin Shan13395c42012-08-20 03:49:17 +00001021{
1022 struct pci_controller *hose, *tmp;
Gavin Shandb1266c2012-08-20 03:49:18 +00001023 struct pnv_phb *phb;
Gavin Shan13395c42012-08-20 03:49:17 +00001024
1025 list_for_each_entry_safe(hose, tmp, &hose_list, list_node) {
1026 pnv_ioda_setup_dma(hose->private_data);
Gavin Shandb1266c2012-08-20 03:49:18 +00001027
1028 /* Mark the PHB initialization done */
1029 phb = hose->private_data;
1030 phb->initialized = 1;
Gavin Shan13395c42012-08-20 03:49:17 +00001031 }
1032}
1033
Gavin Shan37c367f2013-06-20 18:13:25 +08001034static void pnv_pci_ioda_create_dbgfs(void)
1035{
1036#ifdef CONFIG_DEBUG_FS
1037 struct pci_controller *hose, *tmp;
1038 struct pnv_phb *phb;
1039 char name[16];
1040
1041 list_for_each_entry_safe(hose, tmp, &hose_list, list_node) {
1042 phb = hose->private_data;
1043
1044 sprintf(name, "PCI%04x", hose->global_number);
1045 phb->dbgfs = debugfs_create_dir(name, powerpc_debugfs_root);
1046 if (!phb->dbgfs)
1047 pr_warning("%s: Error on creating debugfs on PHB#%x\n",
1048 __func__, hose->global_number);
1049 }
1050#endif /* CONFIG_DEBUG_FS */
1051}
1052
Greg Kroah-Hartmancad5cef2012-12-21 14:04:10 -08001053static void pnv_pci_ioda_fixup(void)
Gavin Shanfb446ad2012-08-20 03:49:14 +00001054{
1055 pnv_pci_ioda_setup_PEs();
Gavin Shan11685be2012-08-20 03:49:16 +00001056 pnv_pci_ioda_setup_seg();
Gavin Shan13395c42012-08-20 03:49:17 +00001057 pnv_pci_ioda_setup_DMA();
Gavin Shane9cc17d2013-06-20 13:21:14 +08001058
Gavin Shan37c367f2013-06-20 18:13:25 +08001059 pnv_pci_ioda_create_dbgfs();
1060
Gavin Shane9cc17d2013-06-20 13:21:14 +08001061#ifdef CONFIG_EEH
Gavin Shan88b6d142013-06-27 13:46:45 +08001062 eeh_probe_mode_set(EEH_PROBE_MODE_DEV);
Gavin Shane9cc17d2013-06-20 13:21:14 +08001063 eeh_addr_cache_build();
1064 eeh_init();
1065#endif
Gavin Shanfb446ad2012-08-20 03:49:14 +00001066}
1067
Gavin Shan271fd032012-09-11 16:59:47 -06001068/*
1069 * Returns the alignment for I/O or memory windows for P2P
1070 * bridges. That actually depends on how PEs are segmented.
1071 * For now, we return I/O or M32 segment size for PE sensitive
1072 * P2P bridges. Otherwise, the default values (4KiB for I/O,
1073 * 1MiB for memory) will be returned.
1074 *
1075 * The current PCI bus might be put into one PE, which was
1076 * create against the parent PCI bridge. For that case, we
1077 * needn't enlarge the alignment so that we can save some
1078 * resources.
1079 */
1080static resource_size_t pnv_pci_window_alignment(struct pci_bus *bus,
1081 unsigned long type)
1082{
1083 struct pci_dev *bridge;
1084 struct pci_controller *hose = pci_bus_to_host(bus);
1085 struct pnv_phb *phb = hose->private_data;
1086 int num_pci_bridges = 0;
1087
1088 bridge = bus->self;
1089 while (bridge) {
1090 if (pci_pcie_type(bridge) == PCI_EXP_TYPE_PCI_BRIDGE) {
1091 num_pci_bridges++;
1092 if (num_pci_bridges >= 2)
1093 return 1;
1094 }
1095
1096 bridge = bridge->bus->self;
1097 }
1098
1099 /* We need support prefetchable memory window later */
1100 if (type & IORESOURCE_MEM)
1101 return phb->ioda.m32_segsize;
1102
1103 return phb->ioda.io_segsize;
1104}
1105
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +00001106/* Prevent enabling devices for which we couldn't properly
1107 * assign a PE
1108 */
Greg Kroah-Hartmancad5cef2012-12-21 14:04:10 -08001109static int pnv_pci_enable_device_hook(struct pci_dev *dev)
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +00001110{
Gavin Shandb1266c2012-08-20 03:49:18 +00001111 struct pci_controller *hose = pci_bus_to_host(dev->bus);
1112 struct pnv_phb *phb = hose->private_data;
1113 struct pci_dn *pdn;
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +00001114
Gavin Shandb1266c2012-08-20 03:49:18 +00001115 /* The function is probably called while the PEs have
1116 * not be created yet. For example, resource reassignment
1117 * during PCI probe period. We just skip the check if
1118 * PEs isn't ready.
1119 */
1120 if (!phb->initialized)
1121 return 0;
1122
Benjamin Herrenschmidtb72c1f62013-05-21 22:58:21 +00001123 pdn = pci_get_pdn(dev);
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +00001124 if (!pdn || pdn->pe_number == IODA_INVALID_PE)
1125 return -EINVAL;
Gavin Shandb1266c2012-08-20 03:49:18 +00001126
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +00001127 return 0;
1128}
1129
1130static u32 pnv_ioda_bdfn_to_pe(struct pnv_phb *phb, struct pci_bus *bus,
1131 u32 devfn)
1132{
1133 return phb->ioda.pe_rmap[(bus->number << 8) | devfn];
1134}
1135
Benjamin Herrenschmidt73ed1482013-05-10 16:59:18 +10001136static void pnv_pci_ioda_shutdown(struct pnv_phb *phb)
1137{
1138 opal_pci_reset(phb->opal_id, OPAL_PCI_IODA_TABLE_RESET,
1139 OPAL_ASSERT_RESET);
1140}
1141
Gavin Shane9cc17d2013-06-20 13:21:14 +08001142void __init pnv_pci_init_ioda_phb(struct device_node *np,
1143 u64 hub_id, int ioda_type)
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +00001144{
1145 struct pci_controller *hose;
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +00001146 struct pnv_phb *phb;
Gavin Shan81846162013-12-26 09:29:40 +08001147 unsigned long size, m32map_off, pemap_off, iomap_off = 0;
Alistair Popplec681b932013-09-23 12:04:57 +10001148 const __be64 *prop64;
Benjamin Herrenschmidt3a1a4662013-09-23 12:05:01 +10001149 const __be32 *prop32;
Gavin Shanf1b7cc32013-07-31 16:47:01 +08001150 int len;
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +00001151 u64 phb_id;
1152 void *aux;
1153 long rc;
1154
Gavin Shan58d714e2013-07-31 16:47:00 +08001155 pr_info("Initializing IODA%d OPAL PHB %s\n", ioda_type, np->full_name);
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +00001156
1157 prop64 = of_get_property(np, "ibm,opal-phbid", NULL);
1158 if (!prop64) {
1159 pr_err(" Missing \"ibm,opal-phbid\" property !\n");
1160 return;
1161 }
1162 phb_id = be64_to_cpup(prop64);
1163 pr_debug(" PHB-ID : 0x%016llx\n", phb_id);
1164
1165 phb = alloc_bootmem(sizeof(struct pnv_phb));
Gavin Shan58d714e2013-07-31 16:47:00 +08001166 if (!phb) {
1167 pr_err(" Out of memory !\n");
1168 return;
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +00001169 }
Gavin Shan58d714e2013-07-31 16:47:00 +08001170
1171 /* Allocate PCI controller */
1172 memset(phb, 0, sizeof(struct pnv_phb));
1173 phb->hose = hose = pcibios_alloc_controller(np);
1174 if (!phb->hose) {
1175 pr_err(" Can't allocate PCI controller for %s\n",
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +00001176 np->full_name);
Gavin Shan58d714e2013-07-31 16:47:00 +08001177 free_bootmem((unsigned long)phb, sizeof(struct pnv_phb));
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +00001178 return;
1179 }
1180
1181 spin_lock_init(&phb->lock);
Gavin Shanf1b7cc32013-07-31 16:47:01 +08001182 prop32 = of_get_property(np, "bus-range", &len);
1183 if (prop32 && len == 8) {
Benjamin Herrenschmidt3a1a4662013-09-23 12:05:01 +10001184 hose->first_busno = be32_to_cpu(prop32[0]);
1185 hose->last_busno = be32_to_cpu(prop32[1]);
Gavin Shanf1b7cc32013-07-31 16:47:01 +08001186 } else {
1187 pr_warn(" Broken <bus-range> on %s\n", np->full_name);
1188 hose->first_busno = 0;
1189 hose->last_busno = 0xff;
1190 }
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +00001191 hose->private_data = phb;
Gavin Shane9cc17d2013-06-20 13:21:14 +08001192 phb->hub_id = hub_id;
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +00001193 phb->opal_id = phb_id;
Gavin Shanaa0c0332013-04-25 19:20:57 +00001194 phb->type = ioda_type;
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +00001195
Benjamin Herrenschmidtcee72d52011-11-29 18:22:53 +00001196 /* Detect specific models for error handling */
1197 if (of_device_is_compatible(np, "ibm,p7ioc-pciex"))
1198 phb->model = PNV_PHB_MODEL_P7IOC;
Benjamin Herrenschmidtf3d40c22013-05-04 14:24:32 +00001199 else if (of_device_is_compatible(np, "ibm,power8-pciex"))
Gavin Shanaa0c0332013-04-25 19:20:57 +00001200 phb->model = PNV_PHB_MODEL_PHB3;
Benjamin Herrenschmidtcee72d52011-11-29 18:22:53 +00001201 else
1202 phb->model = PNV_PHB_MODEL_UNKNOWN;
1203
Gavin Shanaa0c0332013-04-25 19:20:57 +00001204 /* Parse 32-bit and IO ranges (if any) */
Gavin Shan2f1ec022013-07-31 16:47:02 +08001205 pci_process_bridge_OF_ranges(hose, np, !hose->global_number);
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +00001206
Gavin Shanaa0c0332013-04-25 19:20:57 +00001207 /* Get registers */
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +00001208 phb->regs = of_iomap(np, 0);
1209 if (phb->regs == NULL)
1210 pr_err(" Failed to map registers !\n");
1211
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +00001212 /* Initialize more IODA stuff */
Gavin Shan36954dc2013-11-04 16:32:47 +08001213 phb->ioda.total_pe = 1;
Gavin Shanaa0c0332013-04-25 19:20:57 +00001214 prop32 = of_get_property(np, "ibm,opal-num-pes", NULL);
Gavin Shan36954dc2013-11-04 16:32:47 +08001215 if (prop32)
Benjamin Herrenschmidt3a1a4662013-09-23 12:05:01 +10001216 phb->ioda.total_pe = be32_to_cpup(prop32);
Gavin Shan36954dc2013-11-04 16:32:47 +08001217 prop32 = of_get_property(np, "ibm,opal-reserved-pe", NULL);
1218 if (prop32)
1219 phb->ioda.reserved_pe = be32_to_cpup(prop32);
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +00001220 phb->ioda.m32_size = resource_size(&hose->mem_resources[0]);
Gavin Shanaa0c0332013-04-25 19:20:57 +00001221 /* FW Has already off top 64k of M32 space (MSI space) */
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +00001222 phb->ioda.m32_size += 0x10000;
1223
1224 phb->ioda.m32_segsize = phb->ioda.m32_size / phb->ioda.total_pe;
Benjamin Herrenschmidt3fd47f02013-05-06 13:40:40 +10001225 phb->ioda.m32_pci_base = hose->mem_resources[0].start - hose->mem_offset[0];
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +00001226 phb->ioda.io_size = hose->pci_io_size;
1227 phb->ioda.io_segsize = phb->ioda.io_size / phb->ioda.total_pe;
1228 phb->ioda.io_pci_base = 0; /* XXX calculate this ? */
1229
Gavin Shanc35d2a82013-07-31 16:47:04 +08001230 /* Allocate aux data & arrays. We don't have IO ports on PHB3 */
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +00001231 size = _ALIGN_UP(phb->ioda.total_pe / 8, sizeof(unsigned long));
1232 m32map_off = size;
Gavin Shane47747f2012-08-20 03:49:19 +00001233 size += phb->ioda.total_pe * sizeof(phb->ioda.m32_segmap[0]);
Gavin Shanc35d2a82013-07-31 16:47:04 +08001234 if (phb->type == PNV_PHB_IODA1) {
1235 iomap_off = size;
1236 size += phb->ioda.total_pe * sizeof(phb->ioda.io_segmap[0]);
1237 }
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +00001238 pemap_off = size;
1239 size += phb->ioda.total_pe * sizeof(struct pnv_ioda_pe);
1240 aux = alloc_bootmem(size);
1241 memset(aux, 0, size);
1242 phb->ioda.pe_alloc = aux;
1243 phb->ioda.m32_segmap = aux + m32map_off;
Gavin Shanc35d2a82013-07-31 16:47:04 +08001244 if (phb->type == PNV_PHB_IODA1)
1245 phb->ioda.io_segmap = aux + iomap_off;
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +00001246 phb->ioda.pe_array = aux + pemap_off;
Gavin Shan36954dc2013-11-04 16:32:47 +08001247 set_bit(phb->ioda.reserved_pe, phb->ioda.pe_alloc);
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +00001248
Gavin Shan7ebdf952012-08-20 03:49:15 +00001249 INIT_LIST_HEAD(&phb->ioda.pe_dma_list);
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +00001250 INIT_LIST_HEAD(&phb->ioda.pe_list);
1251
1252 /* Calculate how many 32-bit TCE segments we have */
1253 phb->ioda.tce32_count = phb->ioda.m32_pci_base >> 28;
1254
1255 /* Clear unusable m64 */
1256 hose->mem_resources[1].flags = 0;
1257 hose->mem_resources[1].start = 0;
1258 hose->mem_resources[1].end = 0;
1259 hose->mem_resources[2].flags = 0;
1260 hose->mem_resources[2].start = 0;
1261 hose->mem_resources[2].end = 0;
1262
Gavin Shanaa0c0332013-04-25 19:20:57 +00001263#if 0 /* We should really do that ... */
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +00001264 rc = opal_pci_set_phb_mem_window(opal->phb_id,
1265 window_type,
1266 window_num,
1267 starting_real_address,
1268 starting_pci_address,
1269 segment_size);
1270#endif
1271
Gavin Shan36954dc2013-11-04 16:32:47 +08001272 pr_info(" %d (%d) PE's M32: 0x%x [segment=0x%x]"
1273 " IO: 0x%x [segment=0x%x]\n",
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +00001274 phb->ioda.total_pe,
Gavin Shan36954dc2013-11-04 16:32:47 +08001275 phb->ioda.reserved_pe,
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +00001276 phb->ioda.m32_size, phb->ioda.m32_segsize,
1277 phb->ioda.io_size, phb->ioda.io_segsize);
1278
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +00001279 phb->hose->ops = &pnv_pci_ops;
Gavin Shane9cc17d2013-06-20 13:21:14 +08001280#ifdef CONFIG_EEH
1281 phb->eeh_ops = &ioda_eeh_ops;
1282#endif
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +00001283
1284 /* Setup RID -> PE mapping function */
1285 phb->bdfn_to_pe = pnv_ioda_bdfn_to_pe;
1286
1287 /* Setup TCEs */
1288 phb->dma_dev_setup = pnv_pci_ioda_dma_dev_setup;
1289
Benjamin Herrenschmidt73ed1482013-05-10 16:59:18 +10001290 /* Setup shutdown function for kexec */
1291 phb->shutdown = pnv_pci_ioda_shutdown;
1292
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +00001293 /* Setup MSI support */
1294 pnv_pci_init_ioda_msis(phb);
1295
Gavin Shanc40a4212012-08-20 03:49:20 +00001296 /*
1297 * We pass the PCI probe flag PCI_REASSIGN_ALL_RSRC here
1298 * to let the PCI core do resource assignment. It's supposed
1299 * that the PCI core will do correct I/O and MMIO alignment
1300 * for the P2P bridge bars so that each PCI bus (excluding
1301 * the child P2P bridges) can form individual PE.
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +00001302 */
Gavin Shanfb446ad2012-08-20 03:49:14 +00001303 ppc_md.pcibios_fixup = pnv_pci_ioda_fixup;
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +00001304 ppc_md.pcibios_enable_device_hook = pnv_pci_enable_device_hook;
Gavin Shan271fd032012-09-11 16:59:47 -06001305 ppc_md.pcibios_window_alignment = pnv_pci_window_alignment;
Gavin Shanc40a4212012-08-20 03:49:20 +00001306 pci_add_flags(PCI_REASSIGN_ALL_RSRC);
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +00001307
1308 /* Reset IODA tables to a clean state */
Benjamin Herrenschmidtf11fe552011-11-29 18:22:50 +00001309 rc = opal_pci_reset(phb_id, OPAL_PCI_IODA_TABLE_RESET, OPAL_ASSERT_RESET);
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +00001310 if (rc)
Benjamin Herrenschmidtf11fe552011-11-29 18:22:50 +00001311 pr_warning(" OPAL Error %ld performing IODA table reset !\n", rc);
Gavin Shanaa0c0332013-04-25 19:20:57 +00001312}
1313
Bjorn Helgaas67975002013-07-02 12:20:03 -06001314void __init pnv_pci_init_ioda2_phb(struct device_node *np)
Gavin Shanaa0c0332013-04-25 19:20:57 +00001315{
Gavin Shane9cc17d2013-06-20 13:21:14 +08001316 pnv_pci_init_ioda_phb(np, 0, PNV_PHB_IODA2);
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +00001317}
1318
1319void __init pnv_pci_init_ioda_hub(struct device_node *np)
1320{
1321 struct device_node *phbn;
Alistair Popplec681b932013-09-23 12:04:57 +10001322 const __be64 *prop64;
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +00001323 u64 hub_id;
1324
1325 pr_info("Probing IODA IO-Hub %s\n", np->full_name);
1326
1327 prop64 = of_get_property(np, "ibm,opal-hubid", NULL);
1328 if (!prop64) {
1329 pr_err(" Missing \"ibm,opal-hubid\" property !\n");
1330 return;
1331 }
1332 hub_id = be64_to_cpup(prop64);
1333 pr_devel(" HUB-ID : 0x%016llx\n", hub_id);
1334
1335 /* Count child PHBs */
1336 for_each_child_of_node(np, phbn) {
1337 /* Look for IODA1 PHBs */
1338 if (of_device_is_compatible(phbn, "ibm,ioda-phb"))
Gavin Shane9cc17d2013-06-20 13:21:14 +08001339 pnv_pci_init_ioda_phb(phbn, hub_id, PNV_PHB_IODA1);
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +00001340 }
1341}