pci.c 17 KB

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