fsl_85xx_pci.c 9.4 KB

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