pci.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. /*
  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. #include <linux/kernel.h>
  14. #include <linux/pci.h>
  15. #include <linux/delay.h>
  16. #include <linux/string.h>
  17. #include <linux/init.h>
  18. #include <linux/bootmem.h>
  19. #include <linux/irq.h>
  20. #include <linux/io.h>
  21. #include <linux/msi.h>
  22. #include <asm/sections.h>
  23. #include <asm/io.h>
  24. #include <asm/prom.h>
  25. #include <asm/pci-bridge.h>
  26. #include <asm/machdep.h>
  27. #include <asm/ppc-pci.h>
  28. #include <asm/opal.h>
  29. #include <asm/iommu.h>
  30. #include <asm/tce.h>
  31. #include <asm/abs_addr.h>
  32. #include "powernv.h"
  33. #include "pci.h"
  34. /* Delay in usec */
  35. #define PCI_RESET_DELAY_US 3000000
  36. #define cfg_dbg(fmt...) do { } while(0)
  37. //#define cfg_dbg(fmt...) printk(fmt)
  38. #ifdef CONFIG_PCI_MSI
  39. static int pnv_msi_check_device(struct pci_dev* pdev, int nvec, int type)
  40. {
  41. struct pci_controller *hose = pci_bus_to_host(pdev->bus);
  42. struct pnv_phb *phb = hose->private_data;
  43. return (phb && phb->msi_map) ? 0 : -ENODEV;
  44. }
  45. static unsigned int pnv_get_one_msi(struct pnv_phb *phb)
  46. {
  47. unsigned int id;
  48. spin_lock(&phb->lock);
  49. id = find_next_zero_bit(phb->msi_map, phb->msi_count, phb->msi_next);
  50. if (id >= phb->msi_count && phb->msi_next)
  51. id = find_next_zero_bit(phb->msi_map, phb->msi_count, 0);
  52. if (id >= phb->msi_count) {
  53. spin_unlock(&phb->lock);
  54. return 0;
  55. }
  56. __set_bit(id, phb->msi_map);
  57. spin_unlock(&phb->lock);
  58. return id + phb->msi_base;
  59. }
  60. static void pnv_put_msi(struct pnv_phb *phb, unsigned int hwirq)
  61. {
  62. unsigned int id;
  63. if (WARN_ON(hwirq < phb->msi_base ||
  64. hwirq >= (phb->msi_base + phb->msi_count)))
  65. return;
  66. id = hwirq - phb->msi_base;
  67. spin_lock(&phb->lock);
  68. __clear_bit(id, phb->msi_map);
  69. spin_unlock(&phb->lock);
  70. }
  71. static int pnv_setup_msi_irqs(struct pci_dev *pdev, int nvec, int type)
  72. {
  73. struct pci_controller *hose = pci_bus_to_host(pdev->bus);
  74. struct pnv_phb *phb = hose->private_data;
  75. struct msi_desc *entry;
  76. struct msi_msg msg;
  77. unsigned int hwirq, virq;
  78. int rc;
  79. if (WARN_ON(!phb))
  80. return -ENODEV;
  81. list_for_each_entry(entry, &pdev->msi_list, list) {
  82. if (!entry->msi_attrib.is_64 && !phb->msi32_support) {
  83. pr_warn("%s: Supports only 64-bit MSIs\n",
  84. pci_name(pdev));
  85. return -ENXIO;
  86. }
  87. hwirq = pnv_get_one_msi(phb);
  88. if (!hwirq) {
  89. pr_warn("%s: Failed to find a free MSI\n",
  90. pci_name(pdev));
  91. return -ENOSPC;
  92. }
  93. virq = irq_create_mapping(NULL, hwirq);
  94. if (virq == NO_IRQ) {
  95. pr_warn("%s: Failed to map MSI to linux irq\n",
  96. pci_name(pdev));
  97. pnv_put_msi(phb, hwirq);
  98. return -ENOMEM;
  99. }
  100. rc = phb->msi_setup(phb, pdev, hwirq, entry->msi_attrib.is_64,
  101. &msg);
  102. if (rc) {
  103. pr_warn("%s: Failed to setup MSI\n", pci_name(pdev));
  104. irq_dispose_mapping(virq);
  105. pnv_put_msi(phb, hwirq);
  106. return rc;
  107. }
  108. irq_set_msi_desc(virq, entry);
  109. write_msi_msg(virq, &msg);
  110. }
  111. return 0;
  112. }
  113. static void pnv_teardown_msi_irqs(struct pci_dev *pdev)
  114. {
  115. struct pci_controller *hose = pci_bus_to_host(pdev->bus);
  116. struct pnv_phb *phb = hose->private_data;
  117. struct msi_desc *entry;
  118. if (WARN_ON(!phb))
  119. return;
  120. list_for_each_entry(entry, &pdev->msi_list, list) {
  121. if (entry->irq == NO_IRQ)
  122. continue;
  123. irq_set_msi_desc(entry->irq, NULL);
  124. pnv_put_msi(phb, virq_to_hw(entry->irq));
  125. irq_dispose_mapping(entry->irq);
  126. }
  127. }
  128. #endif /* CONFIG_PCI_MSI */
  129. static void pnv_pci_dump_p7ioc_diag_data(struct pnv_phb *phb)
  130. {
  131. struct OpalIoP7IOCPhbErrorData *data = &phb->diag.p7ioc;
  132. int i;
  133. pr_info("PHB %d diagnostic data:\n", phb->hose->global_number);
  134. pr_info(" brdgCtl = 0x%08x\n", data->brdgCtl);
  135. pr_info(" portStatusReg = 0x%08x\n", data->portStatusReg);
  136. pr_info(" rootCmplxStatus = 0x%08x\n", data->rootCmplxStatus);
  137. pr_info(" busAgentStatus = 0x%08x\n", data->busAgentStatus);
  138. pr_info(" deviceStatus = 0x%08x\n", data->deviceStatus);
  139. pr_info(" slotStatus = 0x%08x\n", data->slotStatus);
  140. pr_info(" linkStatus = 0x%08x\n", data->linkStatus);
  141. pr_info(" devCmdStatus = 0x%08x\n", data->devCmdStatus);
  142. pr_info(" devSecStatus = 0x%08x\n", data->devSecStatus);
  143. pr_info(" rootErrorStatus = 0x%08x\n", data->rootErrorStatus);
  144. pr_info(" uncorrErrorStatus = 0x%08x\n", data->uncorrErrorStatus);
  145. pr_info(" corrErrorStatus = 0x%08x\n", data->corrErrorStatus);
  146. pr_info(" tlpHdr1 = 0x%08x\n", data->tlpHdr1);
  147. pr_info(" tlpHdr2 = 0x%08x\n", data->tlpHdr2);
  148. pr_info(" tlpHdr3 = 0x%08x\n", data->tlpHdr3);
  149. pr_info(" tlpHdr4 = 0x%08x\n", data->tlpHdr4);
  150. pr_info(" sourceId = 0x%08x\n", data->sourceId);
  151. pr_info(" errorClass = 0x%016llx\n", data->errorClass);
  152. pr_info(" correlator = 0x%016llx\n", data->correlator);
  153. pr_info(" p7iocPlssr = 0x%016llx\n", data->p7iocPlssr);
  154. pr_info(" p7iocCsr = 0x%016llx\n", data->p7iocCsr);
  155. pr_info(" lemFir = 0x%016llx\n", data->lemFir);
  156. pr_info(" lemErrorMask = 0x%016llx\n", data->lemErrorMask);
  157. pr_info(" lemWOF = 0x%016llx\n", data->lemWOF);
  158. pr_info(" phbErrorStatus = 0x%016llx\n", data->phbErrorStatus);
  159. pr_info(" phbFirstErrorStatus = 0x%016llx\n", data->phbFirstErrorStatus);
  160. pr_info(" phbErrorLog0 = 0x%016llx\n", data->phbErrorLog0);
  161. pr_info(" phbErrorLog1 = 0x%016llx\n", data->phbErrorLog1);
  162. pr_info(" mmioErrorStatus = 0x%016llx\n", data->mmioErrorStatus);
  163. pr_info(" mmioFirstErrorStatus = 0x%016llx\n", data->mmioFirstErrorStatus);
  164. pr_info(" mmioErrorLog0 = 0x%016llx\n", data->mmioErrorLog0);
  165. pr_info(" mmioErrorLog1 = 0x%016llx\n", data->mmioErrorLog1);
  166. pr_info(" dma0ErrorStatus = 0x%016llx\n", data->dma0ErrorStatus);
  167. pr_info(" dma0FirstErrorStatus = 0x%016llx\n", data->dma0FirstErrorStatus);
  168. pr_info(" dma0ErrorLog0 = 0x%016llx\n", data->dma0ErrorLog0);
  169. pr_info(" dma0ErrorLog1 = 0x%016llx\n", data->dma0ErrorLog1);
  170. pr_info(" dma1ErrorStatus = 0x%016llx\n", data->dma1ErrorStatus);
  171. pr_info(" dma1FirstErrorStatus = 0x%016llx\n", data->dma1FirstErrorStatus);
  172. pr_info(" dma1ErrorLog0 = 0x%016llx\n", data->dma1ErrorLog0);
  173. pr_info(" dma1ErrorLog1 = 0x%016llx\n", data->dma1ErrorLog1);
  174. for (i = 0; i < OPAL_P7IOC_NUM_PEST_REGS; i++) {
  175. if ((data->pestA[i] >> 63) == 0 &&
  176. (data->pestB[i] >> 63) == 0)
  177. continue;
  178. pr_info(" PE[%3d] PESTA = 0x%016llx\n", i, data->pestA[i]);
  179. pr_info(" PESTB = 0x%016llx\n", data->pestB[i]);
  180. }
  181. }
  182. static void pnv_pci_dump_phb_diag_data(struct pnv_phb *phb)
  183. {
  184. switch(phb->model) {
  185. case PNV_PHB_MODEL_P7IOC:
  186. pnv_pci_dump_p7ioc_diag_data(phb);
  187. break;
  188. default:
  189. pr_warning("PCI %d: Can't decode this PHB diag data\n",
  190. phb->hose->global_number);
  191. }
  192. }
  193. static void pnv_pci_handle_eeh_config(struct pnv_phb *phb, u32 pe_no)
  194. {
  195. unsigned long flags, rc;
  196. int has_diag;
  197. spin_lock_irqsave(&phb->lock, flags);
  198. rc = opal_pci_get_phb_diag_data(phb->opal_id, phb->diag.blob, PNV_PCI_DIAG_BUF_SIZE);
  199. has_diag = (rc == OPAL_SUCCESS);
  200. rc = opal_pci_eeh_freeze_clear(phb->opal_id, pe_no,
  201. OPAL_EEH_ACTION_CLEAR_FREEZE_ALL);
  202. if (rc) {
  203. pr_warning("PCI %d: Failed to clear EEH freeze state"
  204. " for PE#%d, err %ld\n",
  205. phb->hose->global_number, pe_no, rc);
  206. /* For now, let's only display the diag buffer when we fail to clear
  207. * the EEH status. We'll do more sensible things later when we have
  208. * proper EEH support. We need to make sure we don't pollute ourselves
  209. * with the normal errors generated when probing empty slots
  210. */
  211. if (has_diag)
  212. pnv_pci_dump_phb_diag_data(phb);
  213. else
  214. pr_warning("PCI %d: No diag data available\n",
  215. phb->hose->global_number);
  216. }
  217. spin_unlock_irqrestore(&phb->lock, flags);
  218. }
  219. static void pnv_pci_config_check_eeh(struct pnv_phb *phb, struct pci_bus *bus,
  220. u32 bdfn)
  221. {
  222. s64 rc;
  223. u8 fstate;
  224. u16 pcierr;
  225. u32 pe_no;
  226. /* Get PE# if we support IODA */
  227. pe_no = phb->bdfn_to_pe ? phb->bdfn_to_pe(phb, bus, bdfn & 0xff) : 0;
  228. /* Read freeze status */
  229. rc = opal_pci_eeh_freeze_status(phb->opal_id, pe_no, &fstate, &pcierr,
  230. NULL);
  231. if (rc) {
  232. pr_warning("PCI %d: Failed to read EEH status for PE#%d,"
  233. " err %lld\n", phb->hose->global_number, pe_no, rc);
  234. return;
  235. }
  236. cfg_dbg(" -> EEH check, bdfn=%04x PE%d fstate=%x\n",
  237. bdfn, pe_no, fstate);
  238. if (fstate != 0)
  239. pnv_pci_handle_eeh_config(phb, pe_no);
  240. }
  241. static int pnv_pci_read_config(struct pci_bus *bus,
  242. unsigned int devfn,
  243. int where, int size, u32 *val)
  244. {
  245. struct pci_controller *hose = pci_bus_to_host(bus);
  246. struct pnv_phb *phb = hose->private_data;
  247. u32 bdfn = (((uint64_t)bus->number) << 8) | devfn;
  248. s64 rc;
  249. if (hose == NULL)
  250. return PCIBIOS_DEVICE_NOT_FOUND;
  251. switch (size) {
  252. case 1: {
  253. u8 v8;
  254. rc = opal_pci_config_read_byte(phb->opal_id, bdfn, where, &v8);
  255. *val = (rc == OPAL_SUCCESS) ? v8 : 0xff;
  256. break;
  257. }
  258. case 2: {
  259. u16 v16;
  260. rc = opal_pci_config_read_half_word(phb->opal_id, bdfn, where,
  261. &v16);
  262. *val = (rc == OPAL_SUCCESS) ? v16 : 0xffff;
  263. break;
  264. }
  265. case 4: {
  266. u32 v32;
  267. rc = opal_pci_config_read_word(phb->opal_id, bdfn, where, &v32);
  268. *val = (rc == OPAL_SUCCESS) ? v32 : 0xffffffff;
  269. break;
  270. }
  271. default:
  272. return PCIBIOS_FUNC_NOT_SUPPORTED;
  273. }
  274. cfg_dbg("pnv_pci_read_config bus: %x devfn: %x +%x/%x -> %08x\n",
  275. bus->number, devfn, where, size, *val);
  276. /* Check if the PHB got frozen due to an error (no response) */
  277. pnv_pci_config_check_eeh(phb, bus, bdfn);
  278. return PCIBIOS_SUCCESSFUL;
  279. }
  280. static int pnv_pci_write_config(struct pci_bus *bus,
  281. unsigned int devfn,
  282. int where, int size, u32 val)
  283. {
  284. struct pci_controller *hose = pci_bus_to_host(bus);
  285. struct pnv_phb *phb = hose->private_data;
  286. u32 bdfn = (((uint64_t)bus->number) << 8) | devfn;
  287. if (hose == NULL)
  288. return PCIBIOS_DEVICE_NOT_FOUND;
  289. cfg_dbg("pnv_pci_write_config bus: %x devfn: %x +%x/%x -> %08x\n",
  290. bus->number, devfn, where, size, val);
  291. switch (size) {
  292. case 1:
  293. opal_pci_config_write_byte(phb->opal_id, bdfn, where, val);
  294. break;
  295. case 2:
  296. opal_pci_config_write_half_word(phb->opal_id, bdfn, where, val);
  297. break;
  298. case 4:
  299. opal_pci_config_write_word(phb->opal_id, bdfn, where, val);
  300. break;
  301. default:
  302. return PCIBIOS_FUNC_NOT_SUPPORTED;
  303. }
  304. /* Check if the PHB got frozen due to an error (no response) */
  305. pnv_pci_config_check_eeh(phb, bus, bdfn);
  306. return PCIBIOS_SUCCESSFUL;
  307. }
  308. struct pci_ops pnv_pci_ops = {
  309. .read = pnv_pci_read_config,
  310. .write = pnv_pci_write_config,
  311. };
  312. static void pnv_tce_invalidate(struct iommu_table *tbl,
  313. u64 *startp, u64 *endp)
  314. {
  315. u64 __iomem *invalidate = (u64 __iomem *)tbl->it_index;
  316. unsigned long start, end, inc;
  317. start = __pa(startp);
  318. end = __pa(endp);
  319. /* BML uses this case for p6/p7/galaxy2: Shift addr and put in node */
  320. if (tbl->it_busno) {
  321. start <<= 12;
  322. end <<= 12;
  323. inc = 128 << 12;
  324. start |= tbl->it_busno;
  325. end |= tbl->it_busno;
  326. }
  327. /* p7ioc-style invalidation, 2 TCEs per write */
  328. else if (tbl->it_type & TCE_PCI_SWINV_PAIR) {
  329. start |= (1ull << 63);
  330. end |= (1ull << 63);
  331. inc = 16;
  332. }
  333. /* Default (older HW) */
  334. else
  335. inc = 128;
  336. end |= inc - 1; /* round up end to be different than start */
  337. mb(); /* Ensure above stores are visible */
  338. while (start <= end) {
  339. __raw_writeq(start, invalidate);
  340. start += inc;
  341. }
  342. /* The iommu layer will do another mb() for us on build() and
  343. * we don't care on free()
  344. */
  345. }
  346. static int pnv_tce_build(struct iommu_table *tbl, long index, long npages,
  347. unsigned long uaddr, enum dma_data_direction direction,
  348. struct dma_attrs *attrs)
  349. {
  350. u64 proto_tce;
  351. u64 *tcep, *tces;
  352. u64 rpn;
  353. proto_tce = TCE_PCI_READ; // Read allowed
  354. if (direction != DMA_TO_DEVICE)
  355. proto_tce |= TCE_PCI_WRITE;
  356. tces = tcep = ((u64 *)tbl->it_base) + index - tbl->it_offset;
  357. rpn = __pa(uaddr) >> TCE_SHIFT;
  358. while (npages--)
  359. *(tcep++) = proto_tce | (rpn++ << TCE_RPN_SHIFT);
  360. /* Some implementations won't cache invalid TCEs and thus may not
  361. * need that flush. We'll probably turn it_type into a bit mask
  362. * of flags if that becomes the case
  363. */
  364. if (tbl->it_type & TCE_PCI_SWINV_CREATE)
  365. pnv_tce_invalidate(tbl, tces, tcep - 1);
  366. return 0;
  367. }
  368. static void pnv_tce_free(struct iommu_table *tbl, long index, long npages)
  369. {
  370. u64 *tcep, *tces;
  371. tces = tcep = ((u64 *)tbl->it_base) + index - tbl->it_offset;
  372. while (npages--)
  373. *(tcep++) = 0;
  374. if (tbl->it_type & TCE_PCI_SWINV_FREE)
  375. pnv_tce_invalidate(tbl, tces, tcep - 1);
  376. }
  377. void pnv_pci_setup_iommu_table(struct iommu_table *tbl,
  378. void *tce_mem, u64 tce_size,
  379. u64 dma_offset)
  380. {
  381. tbl->it_blocksize = 16;
  382. tbl->it_base = (unsigned long)tce_mem;
  383. tbl->it_offset = dma_offset >> IOMMU_PAGE_SHIFT;
  384. tbl->it_index = 0;
  385. tbl->it_size = tce_size >> 3;
  386. tbl->it_busno = 0;
  387. tbl->it_type = TCE_PCI;
  388. }
  389. static struct iommu_table * __devinit
  390. pnv_pci_setup_bml_iommu(struct pci_controller *hose)
  391. {
  392. struct iommu_table *tbl;
  393. const __be64 *basep, *swinvp;
  394. const __be32 *sizep;
  395. basep = of_get_property(hose->dn, "linux,tce-base", NULL);
  396. sizep = of_get_property(hose->dn, "linux,tce-size", NULL);
  397. if (basep == NULL || sizep == NULL) {
  398. pr_err("PCI: %s has missing tce entries !\n",
  399. hose->dn->full_name);
  400. return NULL;
  401. }
  402. tbl = kzalloc_node(sizeof(struct iommu_table), GFP_KERNEL, hose->node);
  403. if (WARN_ON(!tbl))
  404. return NULL;
  405. pnv_pci_setup_iommu_table(tbl, __va(be64_to_cpup(basep)),
  406. be32_to_cpup(sizep), 0);
  407. iommu_init_table(tbl, hose->node);
  408. /* Deal with SW invalidated TCEs when needed (BML way) */
  409. swinvp = of_get_property(hose->dn, "linux,tce-sw-invalidate-info",
  410. NULL);
  411. if (swinvp) {
  412. tbl->it_busno = swinvp[1];
  413. tbl->it_index = (unsigned long)ioremap(swinvp[0], 8);
  414. tbl->it_type = TCE_PCI_SWINV_CREATE | TCE_PCI_SWINV_FREE;
  415. }
  416. return tbl;
  417. }
  418. static void __devinit pnv_pci_dma_fallback_setup(struct pci_controller *hose,
  419. struct pci_dev *pdev)
  420. {
  421. struct device_node *np = pci_bus_to_OF_node(hose->bus);
  422. struct pci_dn *pdn;
  423. if (np == NULL)
  424. return;
  425. pdn = PCI_DN(np);
  426. if (!pdn->iommu_table)
  427. pdn->iommu_table = pnv_pci_setup_bml_iommu(hose);
  428. if (!pdn->iommu_table)
  429. return;
  430. set_iommu_table_base(&pdev->dev, pdn->iommu_table);
  431. }
  432. static void __devinit pnv_pci_dma_dev_setup(struct pci_dev *pdev)
  433. {
  434. struct pci_controller *hose = pci_bus_to_host(pdev->bus);
  435. struct pnv_phb *phb = hose->private_data;
  436. /* If we have no phb structure, try to setup a fallback based on
  437. * the device-tree (RTAS PCI for example)
  438. */
  439. if (phb && phb->dma_dev_setup)
  440. phb->dma_dev_setup(phb, pdev);
  441. else
  442. pnv_pci_dma_fallback_setup(hose, pdev);
  443. }
  444. /* Fixup wrong class code in p7ioc root complex */
  445. static void __devinit pnv_p7ioc_rc_quirk(struct pci_dev *dev)
  446. {
  447. dev->class = PCI_CLASS_BRIDGE_PCI << 8;
  448. }
  449. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_IBM, 0x3b9, pnv_p7ioc_rc_quirk);
  450. static int pnv_pci_probe_mode(struct pci_bus *bus)
  451. {
  452. struct pci_controller *hose = pci_bus_to_host(bus);
  453. const __be64 *tstamp;
  454. u64 now, target;
  455. /* We hijack this as a way to ensure we have waited long
  456. * enough since the reset was lifted on the PCI bus
  457. */
  458. if (bus != hose->bus)
  459. return PCI_PROBE_NORMAL;
  460. tstamp = of_get_property(hose->dn, "reset-clear-timestamp", NULL);
  461. if (!tstamp || !*tstamp)
  462. return PCI_PROBE_NORMAL;
  463. now = mftb() / tb_ticks_per_usec;
  464. target = (be64_to_cpup(tstamp) / tb_ticks_per_usec)
  465. + PCI_RESET_DELAY_US;
  466. pr_devel("pci %04d: Reset target: 0x%llx now: 0x%llx\n",
  467. hose->global_number, target, now);
  468. if (now < target)
  469. msleep((target - now + 999) / 1000);
  470. return PCI_PROBE_NORMAL;
  471. }
  472. void __init pnv_pci_init(void)
  473. {
  474. struct device_node *np;
  475. pci_set_flags(PCI_CAN_SKIP_ISA_ALIGN);
  476. /* We do not want to just probe */
  477. pci_probe_only = 0;
  478. /* OPAL absent, try POPAL first then RTAS detection of PHBs */
  479. if (!firmware_has_feature(FW_FEATURE_OPAL)) {
  480. #ifdef CONFIG_PPC_POWERNV_RTAS
  481. init_pci_config_tokens();
  482. find_and_init_phbs();
  483. #endif /* CONFIG_PPC_POWERNV_RTAS */
  484. }
  485. /* OPAL is here, do our normal stuff */
  486. else {
  487. int found_ioda = 0;
  488. /* Look for IODA IO-Hubs. We don't support mixing IODA
  489. * and p5ioc2 due to the need to change some global
  490. * probing flags
  491. */
  492. for_each_compatible_node(np, NULL, "ibm,ioda-hub") {
  493. pnv_pci_init_ioda_hub(np);
  494. found_ioda = 1;
  495. }
  496. /* Look for p5ioc2 IO-Hubs */
  497. if (!found_ioda)
  498. for_each_compatible_node(np, NULL, "ibm,p5ioc2")
  499. pnv_pci_init_p5ioc2_hub(np);
  500. }
  501. /* Setup the linkage between OF nodes and PHBs */
  502. pci_devs_phb_init();
  503. /* Configure IOMMU DMA hooks */
  504. ppc_md.pci_dma_dev_setup = pnv_pci_dma_dev_setup;
  505. ppc_md.tce_build = pnv_tce_build;
  506. ppc_md.tce_free = pnv_tce_free;
  507. ppc_md.pci_probe_mode = pnv_pci_probe_mode;
  508. set_pci_dma_ops(&dma_iommu_ops);
  509. /* Configure MSIs */
  510. #ifdef CONFIG_PCI_MSI
  511. ppc_md.msi_check_device = pnv_msi_check_device;
  512. ppc_md.setup_msi_irqs = pnv_setup_msi_irqs;
  513. ppc_md.teardown_msi_irqs = pnv_teardown_msi_irqs;
  514. #endif
  515. }