pci.c 17 KB

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