pci.c 17 KB

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