fsl_pci_init.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /*
  2. * Copyright 2007 Freescale Semiconductor, Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * Version 2 as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  16. * MA 02111-1307 USA
  17. */
  18. #include <common.h>
  19. /*
  20. * PCI/PCIE Controller initialization for mpc85xx/mpc86xx soc's
  21. *
  22. * Initialize controller and call the common driver/pci pci_hose_scan to
  23. * scan for bridges and devices.
  24. *
  25. * Hose fields which need to be pre-initialized by board specific code:
  26. * regions[]
  27. * first_busno
  28. *
  29. * Fields updated:
  30. * last_busno
  31. */
  32. #include <pci.h>
  33. #include <asm/immap_fsl_pci.h>
  34. void pciauto_prescan_setup_bridge(struct pci_controller *hose,
  35. pci_dev_t dev, int sub_bus);
  36. void pciauto_postscan_setup_bridge(struct pci_controller *hose,
  37. pci_dev_t dev, int sub_bus);
  38. void pciauto_config_init(struct pci_controller *hose);
  39. void fsl_pci_init(struct pci_controller *hose)
  40. {
  41. u16 temp16;
  42. u32 temp32;
  43. int busno = hose->first_busno;
  44. int enabled;
  45. u16 ltssm;
  46. u8 temp8;
  47. int r;
  48. int bridge;
  49. int inbound = 0;
  50. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) hose->cfg_addr;
  51. pci_dev_t dev = PCI_BDF(busno,0,0);
  52. /* Initialize ATMU registers based on hose regions and flags */
  53. volatile pot_t *po = &pci->pot[1]; /* skip 0 */
  54. volatile pit_t *pi = &pci->pit[0]; /* ranges from: 3 to 1 */
  55. #ifdef DEBUG
  56. int neg_link_w;
  57. #endif
  58. for (r=0; r<hose->region_count; r++) {
  59. u32 sz = (__ilog2_u64((u64)hose->regions[r].size) - 1);
  60. if (hose->regions[r].flags & PCI_REGION_MEMORY) { /* inbound */
  61. u32 flag = PIWAR_EN | PIWAR_LOCAL | \
  62. PIWAR_READ_SNOOP | PIWAR_WRITE_SNOOP;
  63. pi->pitar = (hose->regions[r].phys_start >> 12);
  64. pi->piwbar = (hose->regions[r].bus_start >> 12);
  65. #ifdef CONFIG_SYS_PCI_64BIT
  66. pi->piwbear = (hose->regions[r].bus_start >> 44);
  67. #else
  68. pi->piwbear = 0;
  69. #endif
  70. if (hose->regions[r].flags & PCI_REGION_PREFETCH)
  71. flag |= PIWAR_PF;
  72. pi->piwar = flag | sz;
  73. pi++;
  74. inbound = hose->regions[r].size > 0;
  75. } else { /* Outbound */
  76. po->powbar = (hose->regions[r].phys_start >> 12);
  77. po->potar = (hose->regions[r].bus_start >> 12);
  78. #ifdef CONFIG_SYS_PCI_64BIT
  79. po->potear = (hose->regions[r].bus_start >> 44);
  80. #else
  81. po->potear = 0;
  82. #endif
  83. if (hose->regions[r].flags & PCI_REGION_IO)
  84. po->powar = POWAR_EN | sz | \
  85. POWAR_IO_READ | POWAR_IO_WRITE;
  86. else
  87. po->powar = POWAR_EN | sz | \
  88. POWAR_MEM_READ | POWAR_MEM_WRITE;
  89. po++;
  90. }
  91. }
  92. pci_register_hose(hose);
  93. pciauto_config_init(hose); /* grab pci_{mem,prefetch,io} */
  94. hose->current_busno = hose->first_busno;
  95. pci->pedr = 0xffffffff; /* Clear any errors */
  96. pci->peer = ~0x20140; /* Enable All Error Interupts except
  97. * - Master abort (pci)
  98. * - Master PERR (pci)
  99. * - ICCA (PCIe)
  100. */
  101. pci_hose_read_config_dword (hose, dev, PCI_DCR, &temp32);
  102. temp32 |= 0xf000e; /* set URR, FER, NFER (but not CER) */
  103. pci_hose_write_config_dword(hose, dev, PCI_DCR, temp32);
  104. pci_hose_read_config_byte (hose, dev, PCI_HEADER_TYPE, &temp8);
  105. bridge = temp8 & PCI_HEADER_TYPE_BRIDGE; /* Bridge, such as pcie */
  106. if ( bridge ) {
  107. pci_hose_read_config_word(hose, dev, PCI_LTSSM, &ltssm);
  108. enabled = ltssm >= PCI_LTSSM_L0;
  109. #ifdef CONFIG_FSL_PCIE_RESET
  110. if (ltssm == 1) {
  111. int i;
  112. debug("....PCIe link error. "
  113. "LTSSM=0x%02x.", ltssm);
  114. pci->pdb_stat |= 0x08000000; /* assert PCIe reset */
  115. temp32 = pci->pdb_stat;
  116. udelay(100);
  117. debug(" Asserting PCIe reset @%x = %x\n",
  118. &pci->pdb_stat, pci->pdb_stat);
  119. pci->pdb_stat &= ~0x08000000; /* clear reset */
  120. asm("sync;isync");
  121. for (i=0; i<100 && ltssm < PCI_LTSSM_L0; i++) {
  122. pci_hose_read_config_word(hose, dev, PCI_LTSSM,
  123. &ltssm);
  124. udelay(1000);
  125. debug("....PCIe link error. "
  126. "LTSSM=0x%02x.\n", ltssm);
  127. }
  128. enabled = ltssm >= PCI_LTSSM_L0;
  129. }
  130. #endif
  131. if (!enabled) {
  132. debug("....PCIE link error. Skipping scan."
  133. "LTSSM=0x%02x\n", ltssm);
  134. hose->last_busno = hose->first_busno;
  135. return;
  136. }
  137. pci->pme_msg_det = 0xffffffff;
  138. pci->pme_msg_int_en = 0xffffffff;
  139. #ifdef DEBUG
  140. pci_hose_read_config_word(hose, dev, PCI_LSR, &temp16);
  141. neg_link_w = (temp16 & 0x3f0 ) >> 4;
  142. printf("...PCIE LTSSM=0x%x, Negotiated link width=%d\n",
  143. ltssm, neg_link_w);
  144. #endif
  145. hose->current_busno++; /* Start scan with secondary */
  146. pciauto_prescan_setup_bridge(hose, dev, hose->current_busno);
  147. }
  148. /* Use generic setup_device to initialize standard pci regs,
  149. * but do not allocate any windows since any BAR found (such
  150. * as PCSRBAR) is not in this cpu's memory space.
  151. */
  152. pciauto_setup_device(hose, dev, 0, hose->pci_mem,
  153. hose->pci_prefetch, hose->pci_io);
  154. if (inbound) {
  155. pci_hose_read_config_word(hose, dev, PCI_COMMAND, &temp16);
  156. pci_hose_write_config_word(hose, dev, PCI_COMMAND,
  157. temp16 | PCI_COMMAND_MEMORY);
  158. }
  159. #ifndef CONFIG_PCI_NOSCAN
  160. pci_hose_read_config_byte(hose, dev, PCI_CLASS_PROG, &temp8);
  161. /* Programming Interface (PCI_CLASS_PROG)
  162. * 0 == pci host or pcie root-complex,
  163. * 1 == pci agent or pcie end-point
  164. */
  165. if (!temp8) {
  166. printf(" Scanning PCI bus %02x\n",
  167. hose->current_busno);
  168. hose->last_busno = pci_hose_scan_bus(hose, hose->current_busno);
  169. } else {
  170. debug(" Not scanning PCI bus %02x. PI=%x\n",
  171. hose->current_busno, temp8);
  172. hose->last_busno = hose->current_busno;
  173. }
  174. if ( bridge ) { /* update limit regs and subordinate busno */
  175. pciauto_postscan_setup_bridge(hose, dev, hose->last_busno);
  176. }
  177. #else
  178. hose->last_busno = hose->current_busno;
  179. #endif
  180. /* Clear all error indications */
  181. if (bridge)
  182. pci->pme_msg_det = 0xffffffff;
  183. pci->pedr = 0xffffffff;
  184. pci_hose_read_config_word (hose, dev, PCI_DSR, &temp16);
  185. if (temp16) {
  186. pci_hose_write_config_word(hose, dev,
  187. PCI_DSR, 0xffff);
  188. }
  189. pci_hose_read_config_word (hose, dev, PCI_SEC_STATUS, &temp16);
  190. if (temp16) {
  191. pci_hose_write_config_word(hose, dev, PCI_SEC_STATUS, 0xffff);
  192. }
  193. }