fsl_85xx_pci.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. /*
  2. * Copyright 2008 Extreme Engineering Solutions, Inc.
  3. * Copyright 2007-2008 Freescale Semiconductor, Inc.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  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 as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <pci.h>
  25. #include <asm/immap_85xx.h>
  26. #include <asm/immap_fsl_pci.h>
  27. #include <libfdt.h>
  28. #include <fdt_support.h>
  29. extern int fsl_pci_setup_inbound_windows(struct pci_region *r);
  30. extern void fsl_pci_init(struct pci_controller *hose);
  31. int first_free_busno = 0;
  32. #ifdef CONFIG_PCIE1
  33. static struct pci_controller pcie1_hose;
  34. #endif
  35. #ifdef CONFIG_PCIE2
  36. static struct pci_controller pcie2_hose;
  37. #endif
  38. #ifdef CONFIG_PCIE3
  39. static struct pci_controller pcie3_hose;
  40. #endif
  41. /* Correlate host/agent POR bits to usable info. Table 4-14 */
  42. struct host_agent_cfg_t {
  43. uchar pcie_root[3];
  44. uchar rio_host;
  45. } host_agent_cfg[8] = {
  46. {{0, 0, 0}, 0},
  47. {{0, 1, 1}, 1},
  48. {{1, 0, 1}, 0},
  49. {{1, 1, 0}, 1},
  50. {{0, 0, 1}, 0},
  51. {{0, 1, 0}, 1},
  52. {{1, 0, 0}, 0},
  53. {{1, 1, 1}, 1}
  54. };
  55. /* Correlate port width POR bits to usable info. Table 4-15 */
  56. struct io_port_cfg_t {
  57. uchar pcie_width[3];
  58. uchar rio_width;
  59. } io_port_cfg[16] = {
  60. {{0, 0, 0}, 0},
  61. {{0, 0, 0}, 0},
  62. {{4, 0, 0}, 0},
  63. {{4, 4, 0}, 0},
  64. {{0, 0, 0}, 0},
  65. {{0, 0, 0}, 0},
  66. {{0, 0, 0}, 4},
  67. {{4, 2, 2}, 0},
  68. {{0, 0, 0}, 0},
  69. {{0, 0, 0}, 0},
  70. {{0, 0, 0}, 0},
  71. {{4, 0, 0}, 4},
  72. {{4, 0, 0}, 4},
  73. {{0, 0, 0}, 4},
  74. {{0, 0, 0}, 4},
  75. {{8, 0, 0}, 0},
  76. };
  77. void pci_init_board(void)
  78. {
  79. struct pci_controller *hose;
  80. volatile ccsr_fsl_pci_t *pci;
  81. int width;
  82. int host;
  83. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  84. uint devdisr = gur->devdisr;
  85. uint io_sel = (gur->pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> 19;
  86. uint host_agent = (gur->porbmsr & MPC85xx_PORBMSR_HA) >> 16;
  87. struct pci_region *r;
  88. debug(" pci_init_board: devdisr=%x, io_sel=%x, host_agent=%x\n",
  89. devdisr, io_sel, host_agent);
  90. #ifdef CONFIG_PCIE1
  91. pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE1_ADDR;
  92. hose = &pcie1_hose;
  93. host = host_agent_cfg[host_agent].pcie_root[0];
  94. width = io_port_cfg[io_sel].pcie_width[0];
  95. r = hose->regions;
  96. if (width && !(devdisr & MPC85xx_DEVDISR_PCIE)) {
  97. printf("\n PCIE1 connected as %s (x%d)",
  98. host ? "Root Complex" : "End Point", width);
  99. if (pci->pme_msg_det) {
  100. pci->pme_msg_det = 0xffffffff;
  101. debug(" with errors. Clearing. Now 0x%08x",
  102. pci->pme_msg_det);
  103. }
  104. printf("\n");
  105. /* inbound */
  106. r += fsl_pci_setup_inbound_windows(r);
  107. /* outbound memory */
  108. pci_set_region(r++,
  109. CONFIG_SYS_PCIE1_MEM_BASE,
  110. CONFIG_SYS_PCIE1_MEM_PHYS,
  111. CONFIG_SYS_PCIE1_MEM_SIZE,
  112. PCI_REGION_MEM);
  113. /* outbound io */
  114. pci_set_region(r++,
  115. CONFIG_SYS_PCIE1_IO_BASE,
  116. CONFIG_SYS_PCIE1_IO_PHYS,
  117. CONFIG_SYS_PCIE1_IO_SIZE,
  118. PCI_REGION_IO);
  119. hose->region_count = r - hose->regions;
  120. hose->first_busno = first_free_busno;
  121. pci_setup_indirect(hose, (int)&pci->cfg_addr,
  122. (int) &pci->cfg_data);
  123. fsl_pci_init(hose);
  124. first_free_busno = hose->last_busno+1;
  125. printf(" PCIE1 on bus %02x - %02x\n",
  126. hose->first_busno, hose->last_busno);
  127. }
  128. #else
  129. gur->devdisr |= MPC85xx_DEVDISR_PCIE; /* disable */
  130. #endif /* CONFIG_PCIE1 */
  131. #ifdef CONFIG_PCIE2
  132. pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE2_ADDR;
  133. hose = &pcie2_hose;
  134. host = host_agent_cfg[host_agent].pcie_root[1];
  135. width = io_port_cfg[io_sel].pcie_width[1];
  136. r = hose->regions;
  137. if (width && !(devdisr & MPC85xx_DEVDISR_PCIE2)) {
  138. printf("\n PCIE2 connected as %s (x%d)",
  139. host ? "Root Complex" : "End Point", width);
  140. if (pci->pme_msg_det) {
  141. pci->pme_msg_det = 0xffffffff;
  142. debug(" with errors. Clearing. Now 0x%08x",
  143. pci->pme_msg_det);
  144. }
  145. printf("\n");
  146. /* inbound */
  147. r += fsl_pci_setup_inbound_windows(r);
  148. /* outbound memory */
  149. pci_set_region(r++,
  150. CONFIG_SYS_PCIE2_MEM_BASE,
  151. CONFIG_SYS_PCIE2_MEM_PHYS,
  152. CONFIG_SYS_PCIE2_MEM_SIZE,
  153. PCI_REGION_MEM);
  154. /* outbound io */
  155. pci_set_region(r++,
  156. CONFIG_SYS_PCIE2_IO_BASE,
  157. CONFIG_SYS_PCIE2_IO_PHYS,
  158. CONFIG_SYS_PCIE2_IO_SIZE,
  159. PCI_REGION_IO);
  160. hose->region_count = r - hose->regions;
  161. hose->first_busno = first_free_busno;
  162. pci_setup_indirect(hose, (int)&pci->cfg_addr,
  163. (int)&pci->cfg_data);
  164. fsl_pci_init(hose);
  165. first_free_busno = hose->last_busno+1;
  166. printf(" PCIE2 on bus %02x - %02x\n",
  167. hose->first_busno, hose->last_busno);
  168. }
  169. #else
  170. gur->devdisr |= MPC85xx_DEVDISR_PCIE2; /* disable */
  171. #endif /* CONFIG_PCIE2 */
  172. #ifdef CONFIG_PCIE3
  173. pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE3_ADDR;
  174. hose = &pcie3_hose;
  175. host = host_agent_cfg[host_agent].pcie_root[2];
  176. width = io_port_cfg[io_sel].pcie_width[2];
  177. r = hose->regions;
  178. if (width && !(devdisr & MPC85xx_DEVDISR_PCIE3)) {
  179. printf("\n PCIE3 connected as %s (x%d)",
  180. host ? "Root Complex" : "End Point", width);
  181. if (pci->pme_msg_det) {
  182. pci->pme_msg_det = 0xffffffff;
  183. debug(" with errors. Clearing. Now 0x%08x",
  184. pci->pme_msg_det);
  185. }
  186. printf("\n");
  187. /* inbound */
  188. r += fsl_pci_setup_inbound_windows(r);
  189. /* outbound memory */
  190. pci_set_region(r++,
  191. CONFIG_SYS_PCIE3_MEM_BASE,
  192. CONFIG_SYS_PCIE3_MEM_PHYS,
  193. CONFIG_SYS_PCIE3_MEM_SIZE,
  194. PCI_REGION_MEM);
  195. /* outbound io */
  196. pci_set_region(r++,
  197. CONFIG_SYS_PCIE3_IO_BASE,
  198. CONFIG_SYS_PCIE3_IO_PHYS,
  199. CONFIG_SYS_PCIE3_IO_SIZE,
  200. PCI_REGION_IO);
  201. hose->region_count = r - hose->regions;
  202. hose->first_busno = first_free_busno;
  203. pci_setup_indirect(hose, (int)&pci->cfg_addr,
  204. (int)&pci->cfg_data);
  205. fsl_pci_init(hose);
  206. first_free_busno = hose->last_busno+1;
  207. printf(" PCIE3 on bus %02x - %02x\n",
  208. hose->first_busno, hose->last_busno);
  209. }
  210. #else
  211. gur->devdisr |= MPC85xx_DEVDISR_PCIE3; /* disable */
  212. #endif /* CONFIG_PCIE3 */
  213. }
  214. #if defined(CONFIG_OF_BOARD_SETUP)
  215. extern void ft_fsl_pci_setup(void *blob, const char *pci_alias,
  216. struct pci_controller *hose);
  217. void ft_board_pci_setup(void *blob, bd_t *bd)
  218. {
  219. #ifdef CONFIG_PCIE1
  220. ft_fsl_pci_setup(blob, "pci2", &pcie1_hose);
  221. #endif
  222. #ifdef CONFIG_PCIE2
  223. ft_fsl_pci_setup(blob, "pci1", &pcie2_hose);
  224. #endif
  225. #ifdef CONFIG_PCIE3
  226. ft_fsl_pci_setup(blob, "pci0", &pcie3_hose);
  227. #endif
  228. }
  229. #endif /* CONFIG_OF_BOARD_SETUP */