fsl_85xx_pci.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  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/fsl_pci.h>
  27. #include <libfdt.h>
  28. #include <fdt_support.h>
  29. int first_free_busno = 0;
  30. #ifdef CONFIG_PCI1
  31. static struct pci_controller pci1_hose;
  32. #endif
  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. #ifdef CONFIG_MPC8572
  43. /* Correlate host/agent POR bits to usable info. Table 4-14 */
  44. struct host_agent_cfg_t {
  45. uchar pcie_root[3];
  46. uchar rio_host;
  47. } host_agent_cfg[8] = {
  48. {{0, 0, 0}, 0},
  49. {{0, 1, 1}, 1},
  50. {{1, 0, 1}, 0},
  51. {{1, 1, 0}, 1},
  52. {{0, 0, 1}, 0},
  53. {{0, 1, 0}, 1},
  54. {{1, 0, 0}, 0},
  55. {{1, 1, 1}, 1}
  56. };
  57. /* Correlate port width POR bits to usable info. Table 4-15 */
  58. struct io_port_cfg_t {
  59. uchar pcie_width[3];
  60. uchar rio_width;
  61. } io_port_cfg[16] = {
  62. {{0, 0, 0}, 0},
  63. {{0, 0, 0}, 0},
  64. {{4, 0, 0}, 0},
  65. {{4, 4, 0}, 0},
  66. {{0, 0, 0}, 0},
  67. {{0, 0, 0}, 0},
  68. {{0, 0, 0}, 4},
  69. {{4, 2, 2}, 0},
  70. {{0, 0, 0}, 0},
  71. {{0, 0, 0}, 0},
  72. {{0, 0, 0}, 0},
  73. {{4, 0, 0}, 4},
  74. {{4, 0, 0}, 4},
  75. {{0, 0, 0}, 4},
  76. {{0, 0, 0}, 4},
  77. {{8, 0, 0}, 0},
  78. };
  79. #elif defined CONFIG_MPC8548
  80. /* Correlate host/agent POR bits to usable info. Table 4-12 */
  81. struct host_agent_cfg_t {
  82. uchar pci_host[2];
  83. uchar pcie_root[1];
  84. uchar rio_host;
  85. } host_agent_cfg[8] = {
  86. {{1, 1}, {0}, 0},
  87. {{1, 1}, {1}, 0},
  88. {{1, 1}, {0}, 1},
  89. {{0, 0}, {0}, 0}, /* reserved */
  90. {{0, 1}, {1}, 0},
  91. {{1, 1}, {1}, 0},
  92. {{0, 1}, {1}, 1},
  93. {{1, 1}, {1}, 1}
  94. };
  95. /* Correlate port width POR bits to usable info. Table 4-13 */
  96. struct io_port_cfg_t {
  97. uchar pcie_width[1];
  98. uchar rio_width;
  99. } io_port_cfg[8] = {
  100. {{0}, 0},
  101. {{0}, 0},
  102. {{0}, 0},
  103. {{4}, 4},
  104. {{4}, 4},
  105. {{0}, 4},
  106. {{0}, 4},
  107. {{8}, 0},
  108. };
  109. #endif
  110. void pci_init_board(void)
  111. {
  112. struct pci_controller *hose;
  113. volatile ccsr_fsl_pci_t *pci;
  114. int width;
  115. int host;
  116. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  117. uint devdisr = gur->devdisr;
  118. uint io_sel = (gur->pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> 19;
  119. uint host_agent = (gur->porbmsr & MPC85xx_PORBMSR_HA) >> 16;
  120. struct pci_region *r;
  121. #ifdef CONFIG_PCI1
  122. uint pci_spd_norm = (gur->pordevsr & MPC85xx_PORDEVSR_PCI1_SPD);
  123. uint pci_32 = gur->pordevsr & MPC85xx_PORDEVSR_PCI1_PCI32;
  124. uint pci_arb = gur->pordevsr & MPC85xx_PORDEVSR_PCI1_ARB;
  125. uint pcix = gur->pordevsr & MPC85xx_PORDEVSR_PCI1;
  126. uint freq = CONFIG_SYS_CLK_FREQ / 1000 / 1000;
  127. width = 0; /* Silence compiler warning... */
  128. io_sel &= 0xf; /* Silence compiler warning... */
  129. pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCI1_ADDR;
  130. hose = &pci1_hose;
  131. host = host_agent_cfg[host_agent].pci_host[0];
  132. r = hose->regions;
  133. if (!(devdisr & MPC85xx_DEVDISR_PCI1)) {
  134. printf("\n PCI1: %d bit %s, %s %d MHz, %s, %s\n",
  135. pci_32 ? 32 : 64,
  136. pcix ? "PCIX" : "PCI",
  137. pci_spd_norm ? ">=" : "<=",
  138. pcix ? freq * 2 : freq,
  139. host ? "host" : "agent",
  140. pci_arb ? "arbiter" : "external-arbiter");
  141. /* inbound */
  142. r += fsl_pci_setup_inbound_windows(r);
  143. /* outbound memory */
  144. pci_set_region(r++,
  145. CONFIG_SYS_PCI1_MEM_BASE,
  146. CONFIG_SYS_PCI1_MEM_PHYS,
  147. CONFIG_SYS_PCI1_MEM_SIZE,
  148. PCI_REGION_MEM);
  149. /* outbound io */
  150. pci_set_region(r++,
  151. CONFIG_SYS_PCI1_IO_BASE,
  152. CONFIG_SYS_PCI1_IO_PHYS,
  153. CONFIG_SYS_PCI1_IO_SIZE,
  154. PCI_REGION_IO);
  155. hose->region_count = r - hose->regions;
  156. hose->first_busno = first_free_busno;
  157. pci_setup_indirect(hose, (int)&pci->cfg_addr,
  158. (int)&pci->cfg_data);
  159. fsl_pci_init(hose);
  160. /* Unlock inbound PCI configuration cycles */
  161. if (!host)
  162. fsl_pci_config_unlock(hose);
  163. first_free_busno = hose->last_busno + 1;
  164. printf(" PCI1 on bus %02x - %02x\n",
  165. hose->first_busno, hose->last_busno);
  166. } else {
  167. printf(" PCI1: disabled\n");
  168. }
  169. #elif defined CONFIG_MPC8548
  170. /* PCI1 not present on MPC8572 */
  171. gur->devdisr |= MPC85xx_DEVDISR_PCI1; /* disable */
  172. #endif
  173. #ifdef CONFIG_PCIE1
  174. pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE1_ADDR;
  175. hose = &pcie1_hose;
  176. host = host_agent_cfg[host_agent].pcie_root[0];
  177. width = io_port_cfg[io_sel].pcie_width[0];
  178. r = hose->regions;
  179. if (width && !(devdisr & MPC85xx_DEVDISR_PCIE)) {
  180. printf("\n PCIE1 connected as %s (x%d)",
  181. host ? "Root Complex" : "End Point", width);
  182. if (pci->pme_msg_det) {
  183. pci->pme_msg_det = 0xffffffff;
  184. debug(" with errors. Clearing. Now 0x%08x",
  185. pci->pme_msg_det);
  186. }
  187. printf("\n");
  188. /* inbound */
  189. r += fsl_pci_setup_inbound_windows(r);
  190. /* outbound memory */
  191. pci_set_region(r++,
  192. CONFIG_SYS_PCIE1_MEM_BASE,
  193. CONFIG_SYS_PCIE1_MEM_PHYS,
  194. CONFIG_SYS_PCIE1_MEM_SIZE,
  195. PCI_REGION_MEM);
  196. /* outbound io */
  197. pci_set_region(r++,
  198. CONFIG_SYS_PCIE1_IO_BASE,
  199. CONFIG_SYS_PCIE1_IO_PHYS,
  200. CONFIG_SYS_PCIE1_IO_SIZE,
  201. PCI_REGION_IO);
  202. hose->region_count = r - hose->regions;
  203. hose->first_busno = first_free_busno;
  204. pci_setup_indirect(hose, (int)&pci->cfg_addr,
  205. (int) &pci->cfg_data);
  206. fsl_pci_init(hose);
  207. /* Unlock inbound PCI configuration cycles */
  208. if (!host)
  209. fsl_pci_config_unlock(hose);
  210. first_free_busno = hose->last_busno + 1;
  211. printf(" PCIE1 on bus %02x - %02x\n",
  212. hose->first_busno, hose->last_busno);
  213. }
  214. #else
  215. gur->devdisr |= MPC85xx_DEVDISR_PCIE; /* disable */
  216. #endif /* CONFIG_PCIE1 */
  217. #ifdef CONFIG_PCIE2
  218. pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE2_ADDR;
  219. hose = &pcie2_hose;
  220. host = host_agent_cfg[host_agent].pcie_root[1];
  221. width = io_port_cfg[io_sel].pcie_width[1];
  222. r = hose->regions;
  223. if (width && !(devdisr & MPC85xx_DEVDISR_PCIE2)) {
  224. printf("\n PCIE2 connected as %s (x%d)",
  225. host ? "Root Complex" : "End Point", width);
  226. if (pci->pme_msg_det) {
  227. pci->pme_msg_det = 0xffffffff;
  228. debug(" with errors. Clearing. Now 0x%08x",
  229. pci->pme_msg_det);
  230. }
  231. printf("\n");
  232. /* inbound */
  233. r += fsl_pci_setup_inbound_windows(r);
  234. /* outbound memory */
  235. pci_set_region(r++,
  236. CONFIG_SYS_PCIE2_MEM_BASE,
  237. CONFIG_SYS_PCIE2_MEM_PHYS,
  238. CONFIG_SYS_PCIE2_MEM_SIZE,
  239. PCI_REGION_MEM);
  240. /* outbound io */
  241. pci_set_region(r++,
  242. CONFIG_SYS_PCIE2_IO_BASE,
  243. CONFIG_SYS_PCIE2_IO_PHYS,
  244. CONFIG_SYS_PCIE2_IO_SIZE,
  245. PCI_REGION_IO);
  246. hose->region_count = r - hose->regions;
  247. hose->first_busno = first_free_busno;
  248. pci_setup_indirect(hose, (int)&pci->cfg_addr,
  249. (int)&pci->cfg_data);
  250. fsl_pci_init(hose);
  251. /* Unlock inbound PCI configuration cycles */
  252. if (!host)
  253. fsl_pci_config_unlock(hose);
  254. first_free_busno = hose->last_busno + 1;
  255. printf(" PCIE2 on bus %02x - %02x\n",
  256. hose->first_busno, hose->last_busno);
  257. }
  258. #else
  259. gur->devdisr |= MPC85xx_DEVDISR_PCIE2; /* disable */
  260. #endif /* CONFIG_PCIE2 */
  261. #ifdef CONFIG_PCIE3
  262. pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE3_ADDR;
  263. hose = &pcie3_hose;
  264. host = host_agent_cfg[host_agent].pcie_root[2];
  265. width = io_port_cfg[io_sel].pcie_width[2];
  266. r = hose->regions;
  267. if (width && !(devdisr & MPC85xx_DEVDISR_PCIE3)) {
  268. printf("\n PCIE3 connected as %s (x%d)",
  269. host ? "Root Complex" : "End Point", width);
  270. if (pci->pme_msg_det) {
  271. pci->pme_msg_det = 0xffffffff;
  272. debug(" with errors. Clearing. Now 0x%08x",
  273. pci->pme_msg_det);
  274. }
  275. printf("\n");
  276. /* inbound */
  277. r += fsl_pci_setup_inbound_windows(r);
  278. /* outbound memory */
  279. pci_set_region(r++,
  280. CONFIG_SYS_PCIE3_MEM_BASE,
  281. CONFIG_SYS_PCIE3_MEM_PHYS,
  282. CONFIG_SYS_PCIE3_MEM_SIZE,
  283. PCI_REGION_MEM);
  284. /* outbound io */
  285. pci_set_region(r++,
  286. CONFIG_SYS_PCIE3_IO_BASE,
  287. CONFIG_SYS_PCIE3_IO_PHYS,
  288. CONFIG_SYS_PCIE3_IO_SIZE,
  289. PCI_REGION_IO);
  290. hose->region_count = r - hose->regions;
  291. hose->first_busno = first_free_busno;
  292. pci_setup_indirect(hose, (int)&pci->cfg_addr,
  293. (int)&pci->cfg_data);
  294. fsl_pci_init(hose);
  295. /* Unlock inbound PCI configuration cycles */
  296. if (!host)
  297. fsl_pci_config_unlock(hose);
  298. first_free_busno = hose->last_busno + 1;
  299. printf(" PCIE3 on bus %02x - %02x\n",
  300. hose->first_busno, hose->last_busno);
  301. }
  302. #else
  303. gur->devdisr |= MPC85xx_DEVDISR_PCIE3; /* disable */
  304. #endif /* CONFIG_PCIE3 */
  305. }
  306. #if defined(CONFIG_OF_BOARD_SETUP)
  307. void ft_board_pci_setup(void *blob, bd_t *bd)
  308. {
  309. /* TODO - make node name (eg pci0) dynamic */
  310. #ifdef CONFIG_PCI1
  311. ft_fsl_pci_setup(blob, "pci0", &pci1_hose);
  312. #endif
  313. #ifdef CONFIG_PCIE1
  314. ft_fsl_pci_setup(blob, "pci2", &pcie1_hose);
  315. #endif
  316. #ifdef CONFIG_PCIE2
  317. ft_fsl_pci_setup(blob, "pci1", &pcie2_hose);
  318. #endif
  319. #ifdef CONFIG_PCIE3
  320. ft_fsl_pci_setup(blob, "pci0", &pcie3_hose);
  321. #endif
  322. }
  323. #endif /* CONFIG_OF_BOARD_SETUP */