fsl_85xx_pci.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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_config_unlock(struct pci_controller *hose);
  31. extern void fsl_pci_init(struct pci_controller *hose);
  32. int first_free_busno = 0;
  33. #ifdef CONFIG_PCIE1
  34. static struct pci_controller pcie1_hose;
  35. #endif
  36. #ifdef CONFIG_PCIE2
  37. static struct pci_controller pcie2_hose;
  38. #endif
  39. #ifdef CONFIG_PCIE3
  40. static struct pci_controller pcie3_hose;
  41. #endif
  42. /* Correlate host/agent POR bits to usable info. Table 4-14 */
  43. struct host_agent_cfg_t {
  44. uchar pcie_root[3];
  45. uchar rio_host;
  46. } host_agent_cfg[8] = {
  47. {{0, 0, 0}, 0},
  48. {{0, 1, 1}, 1},
  49. {{1, 0, 1}, 0},
  50. {{1, 1, 0}, 1},
  51. {{0, 0, 1}, 0},
  52. {{0, 1, 0}, 1},
  53. {{1, 0, 0}, 0},
  54. {{1, 1, 1}, 1}
  55. };
  56. /* Correlate port width POR bits to usable info. Table 4-15 */
  57. struct io_port_cfg_t {
  58. uchar pcie_width[3];
  59. uchar rio_width;
  60. } io_port_cfg[16] = {
  61. {{0, 0, 0}, 0},
  62. {{0, 0, 0}, 0},
  63. {{4, 0, 0}, 0},
  64. {{4, 4, 0}, 0},
  65. {{0, 0, 0}, 0},
  66. {{0, 0, 0}, 0},
  67. {{0, 0, 0}, 4},
  68. {{4, 2, 2}, 0},
  69. {{0, 0, 0}, 0},
  70. {{0, 0, 0}, 0},
  71. {{0, 0, 0}, 0},
  72. {{4, 0, 0}, 4},
  73. {{4, 0, 0}, 4},
  74. {{0, 0, 0}, 4},
  75. {{0, 0, 0}, 4},
  76. {{8, 0, 0}, 0},
  77. };
  78. void pci_init_board(void)
  79. {
  80. struct pci_controller *hose;
  81. volatile ccsr_fsl_pci_t *pci;
  82. int width;
  83. int host;
  84. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  85. uint devdisr = gur->devdisr;
  86. uint io_sel = (gur->pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> 19;
  87. uint host_agent = (gur->porbmsr & MPC85xx_PORBMSR_HA) >> 16;
  88. struct pci_region *r;
  89. debug(" pci_init_board: devdisr=%x, io_sel=%x, host_agent=%x\n",
  90. devdisr, io_sel, host_agent);
  91. #ifdef CONFIG_PCIE1
  92. pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE1_ADDR;
  93. hose = &pcie1_hose;
  94. host = host_agent_cfg[host_agent].pcie_root[0];
  95. width = io_port_cfg[io_sel].pcie_width[0];
  96. r = hose->regions;
  97. if (width && !(devdisr & MPC85xx_DEVDISR_PCIE)) {
  98. printf("\n PCIE1 connected as %s (x%d)",
  99. host ? "Root Complex" : "End Point", width);
  100. if (pci->pme_msg_det) {
  101. pci->pme_msg_det = 0xffffffff;
  102. debug(" with errors. Clearing. Now 0x%08x",
  103. pci->pme_msg_det);
  104. }
  105. printf("\n");
  106. /* inbound */
  107. r += fsl_pci_setup_inbound_windows(r);
  108. /* outbound memory */
  109. pci_set_region(r++,
  110. CONFIG_SYS_PCIE1_MEM_BASE,
  111. CONFIG_SYS_PCIE1_MEM_PHYS,
  112. CONFIG_SYS_PCIE1_MEM_SIZE,
  113. PCI_REGION_MEM);
  114. /* outbound io */
  115. pci_set_region(r++,
  116. CONFIG_SYS_PCIE1_IO_BASE,
  117. CONFIG_SYS_PCIE1_IO_PHYS,
  118. CONFIG_SYS_PCIE1_IO_SIZE,
  119. PCI_REGION_IO);
  120. hose->region_count = r - hose->regions;
  121. hose->first_busno = first_free_busno;
  122. pci_setup_indirect(hose, (int)&pci->cfg_addr,
  123. (int) &pci->cfg_data);
  124. fsl_pci_init(hose);
  125. /* Unlock inbound PCI configuration cycles */
  126. if (!host)
  127. fsl_pci_config_unlock(hose);
  128. first_free_busno = hose->last_busno+1;
  129. printf(" PCIE1 on bus %02x - %02x\n",
  130. hose->first_busno, hose->last_busno);
  131. }
  132. #else
  133. gur->devdisr |= MPC85xx_DEVDISR_PCIE; /* disable */
  134. #endif /* CONFIG_PCIE1 */
  135. #ifdef CONFIG_PCIE2
  136. pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE2_ADDR;
  137. hose = &pcie2_hose;
  138. host = host_agent_cfg[host_agent].pcie_root[1];
  139. width = io_port_cfg[io_sel].pcie_width[1];
  140. r = hose->regions;
  141. if (width && !(devdisr & MPC85xx_DEVDISR_PCIE2)) {
  142. printf("\n PCIE2 connected as %s (x%d)",
  143. host ? "Root Complex" : "End Point", width);
  144. if (pci->pme_msg_det) {
  145. pci->pme_msg_det = 0xffffffff;
  146. debug(" with errors. Clearing. Now 0x%08x",
  147. pci->pme_msg_det);
  148. }
  149. printf("\n");
  150. /* inbound */
  151. r += fsl_pci_setup_inbound_windows(r);
  152. /* outbound memory */
  153. pci_set_region(r++,
  154. CONFIG_SYS_PCIE2_MEM_BASE,
  155. CONFIG_SYS_PCIE2_MEM_PHYS,
  156. CONFIG_SYS_PCIE2_MEM_SIZE,
  157. PCI_REGION_MEM);
  158. /* outbound io */
  159. pci_set_region(r++,
  160. CONFIG_SYS_PCIE2_IO_BASE,
  161. CONFIG_SYS_PCIE2_IO_PHYS,
  162. CONFIG_SYS_PCIE2_IO_SIZE,
  163. PCI_REGION_IO);
  164. hose->region_count = r - hose->regions;
  165. hose->first_busno = first_free_busno;
  166. pci_setup_indirect(hose, (int)&pci->cfg_addr,
  167. (int)&pci->cfg_data);
  168. fsl_pci_init(hose);
  169. /* Unlock inbound PCI configuration cycles */
  170. if (!host)
  171. fsl_pci_config_unlock(hose);
  172. first_free_busno = hose->last_busno+1;
  173. printf(" PCIE2 on bus %02x - %02x\n",
  174. hose->first_busno, hose->last_busno);
  175. }
  176. #else
  177. gur->devdisr |= MPC85xx_DEVDISR_PCIE2; /* disable */
  178. #endif /* CONFIG_PCIE2 */
  179. #ifdef CONFIG_PCIE3
  180. pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE3_ADDR;
  181. hose = &pcie3_hose;
  182. host = host_agent_cfg[host_agent].pcie_root[2];
  183. width = io_port_cfg[io_sel].pcie_width[2];
  184. r = hose->regions;
  185. if (width && !(devdisr & MPC85xx_DEVDISR_PCIE3)) {
  186. printf("\n PCIE3 connected as %s (x%d)",
  187. host ? "Root Complex" : "End Point", width);
  188. if (pci->pme_msg_det) {
  189. pci->pme_msg_det = 0xffffffff;
  190. debug(" with errors. Clearing. Now 0x%08x",
  191. pci->pme_msg_det);
  192. }
  193. printf("\n");
  194. /* inbound */
  195. r += fsl_pci_setup_inbound_windows(r);
  196. /* outbound memory */
  197. pci_set_region(r++,
  198. CONFIG_SYS_PCIE3_MEM_BASE,
  199. CONFIG_SYS_PCIE3_MEM_PHYS,
  200. CONFIG_SYS_PCIE3_MEM_SIZE,
  201. PCI_REGION_MEM);
  202. /* outbound io */
  203. pci_set_region(r++,
  204. CONFIG_SYS_PCIE3_IO_BASE,
  205. CONFIG_SYS_PCIE3_IO_PHYS,
  206. CONFIG_SYS_PCIE3_IO_SIZE,
  207. PCI_REGION_IO);
  208. hose->region_count = r - hose->regions;
  209. hose->first_busno = first_free_busno;
  210. pci_setup_indirect(hose, (int)&pci->cfg_addr,
  211. (int)&pci->cfg_data);
  212. fsl_pci_init(hose);
  213. /* Unlock inbound PCI configuration cycles */
  214. if (!host)
  215. fsl_pci_config_unlock(hose);
  216. first_free_busno = hose->last_busno+1;
  217. printf(" PCIE3 on bus %02x - %02x\n",
  218. hose->first_busno, hose->last_busno);
  219. }
  220. #else
  221. gur->devdisr |= MPC85xx_DEVDISR_PCIE3; /* disable */
  222. #endif /* CONFIG_PCIE3 */
  223. }
  224. #if defined(CONFIG_OF_BOARD_SETUP)
  225. extern void ft_fsl_pci_setup(void *blob, const char *pci_alias,
  226. struct pci_controller *hose);
  227. void ft_board_pci_setup(void *blob, bd_t *bd)
  228. {
  229. #ifdef CONFIG_PCIE1
  230. ft_fsl_pci_setup(blob, "pci2", &pcie1_hose);
  231. #endif
  232. #ifdef CONFIG_PCIE2
  233. ft_fsl_pci_setup(blob, "pci1", &pcie2_hose);
  234. #endif
  235. #ifdef CONFIG_PCIE3
  236. ft_fsl_pci_setup(blob, "pci0", &pcie3_hose);
  237. #endif
  238. }
  239. #endif /* CONFIG_OF_BOARD_SETUP */