fsl_8xxx_pci.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  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/fsl_pci.h>
  26. #include <asm/io.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. #elif defined CONFIG_MPC86xx
  110. /* Correlate host/agent POR bits to usable info. Table 4-17 */
  111. struct host_agent_cfg_t {
  112. uchar pcie_root[2];
  113. uchar rio_host;
  114. } host_agent_cfg[8] = {
  115. {{0, 0}, 0},
  116. {{1, 0}, 1},
  117. {{0, 1}, 0},
  118. {{1, 1}, 1}
  119. };
  120. /* Correlate port width POR bits to usable info. Table 4-16 */
  121. struct io_port_cfg_t {
  122. uchar pcie_width[2];
  123. uchar rio_width;
  124. } io_port_cfg[16] = {
  125. {{0, 0}, 0},
  126. {{0, 0}, 0},
  127. {{8, 0}, 0},
  128. {{8, 8}, 0},
  129. {{0, 0}, 0},
  130. {{8, 0}, 4},
  131. {{8, 0}, 4},
  132. {{8, 0}, 4},
  133. {{0, 0}, 0},
  134. {{0, 0}, 4},
  135. {{0, 0}, 4},
  136. {{0, 0}, 4},
  137. {{0, 0}, 0},
  138. {{0, 0}, 0},
  139. {{0, 8}, 0},
  140. {{8, 8}, 0},
  141. };
  142. #endif
  143. /*
  144. * 85xx and 86xx share naming conventions, but different layout.
  145. * Correlate names to CPU-specific values to share common
  146. * PCI code.
  147. */
  148. #if defined(CONFIG_MPC85xx)
  149. #define MPC8xxx_DEVDISR_PCIE1 MPC85xx_DEVDISR_PCIE
  150. #define MPC8xxx_DEVDISR_PCIE2 MPC85xx_DEVDISR_PCIE2
  151. #define MPC8xxx_DEVDISR_PCIE3 MPC85xx_DEVDISR_PCIE3
  152. #define MPC8xxx_PORDEVSR_IO_SEL MPC85xx_PORDEVSR_IO_SEL
  153. #define MPC8xxx_PORDEVSR_IO_SEL_SHIFT MPC85xx_PORDEVSR_IO_SEL_SHIFT
  154. #define MPC8xxx_PORBMSR_HA MPC85xx_PORBMSR_HA
  155. #define MPC8xxx_PORBMSR_HA_SHIFT MPC85xx_PORBMSR_HA_SHIFT
  156. #elif defined(CONFIG_MPC86xx)
  157. #define MPC8xxx_DEVDISR_PCIE1 MPC86xx_DEVDISR_PCIEX1
  158. #define MPC8xxx_DEVDISR_PCIE2 MPC86xx_DEVDISR_PCIEX2
  159. #define MPC8xxx_DEVDISR_PCIE3 0 /* 8641 doesn't have PCIe3 */
  160. #define MPC8xxx_PORDEVSR_IO_SEL MPC8641_PORDEVSR_IO_SEL
  161. #define MPC8xxx_PORDEVSR_IO_SEL_SHIFT MPC8641_PORDEVSR_IO_SEL_SHIFT
  162. #define MPC8xxx_PORBMSR_HA MPC8641_PORBMSR_HA
  163. #define MPC8xxx_PORBMSR_HA_SHIFT MPC8641_PORBMSR_HA_SHIFT
  164. #endif
  165. void pci_init_board(void)
  166. {
  167. struct pci_controller *hose;
  168. volatile ccsr_fsl_pci_t *pci;
  169. int width;
  170. int host;
  171. #if defined(CONFIG_MPC85xx)
  172. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  173. #elif defined(CONFIG_MPC86xx)
  174. immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
  175. volatile ccsr_gur_t *gur = &immap->im_gur;
  176. #endif
  177. uint devdisr = in_be32(&gur->devdisr);
  178. uint io_sel = (in_be32(&gur->pordevsr) & MPC8xxx_PORDEVSR_IO_SEL) >>
  179. MPC8xxx_PORDEVSR_IO_SEL_SHIFT;
  180. uint host_agent = (in_be32(&gur->porbmsr) & MPC8xxx_PORBMSR_HA) >>
  181. MPC8xxx_PORBMSR_HA_SHIFT;
  182. struct pci_region *r;
  183. #ifdef CONFIG_PCI1
  184. uint pci_spd_norm = in_be32(&gur->pordevsr) & MPC85xx_PORDEVSR_PCI1_SPD;
  185. uint pci_32 = in_be32(&gur->pordevsr) & MPC85xx_PORDEVSR_PCI1_PCI32;
  186. uint pci_arb = in_be32(&gur->pordevsr) & MPC85xx_PORDEVSR_PCI1_ARB;
  187. uint pcix = in_be32(&gur->pordevsr) & MPC85xx_PORDEVSR_PCI1;
  188. uint freq = CONFIG_SYS_CLK_FREQ / 1000 / 1000;
  189. width = 0; /* Silence compiler warning... */
  190. io_sel &= 0xf; /* Silence compiler warning... */
  191. pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCI1_ADDR;
  192. hose = &pci1_hose;
  193. host = host_agent_cfg[host_agent].pci_host[0];
  194. r = hose->regions;
  195. if (!(devdisr & MPC85xx_DEVDISR_PCI1)) {
  196. printf("\n PCI1: %d bit %s, %s %d MHz, %s, %s\n",
  197. pci_32 ? 32 : 64,
  198. pcix ? "PCIX" : "PCI",
  199. pci_spd_norm ? ">=" : "<=",
  200. pcix ? freq * 2 : freq,
  201. host ? "host" : "agent",
  202. pci_arb ? "arbiter" : "external-arbiter");
  203. /* outbound memory */
  204. pci_set_region(r++,
  205. CONFIG_SYS_PCI1_MEM_BASE,
  206. CONFIG_SYS_PCI1_MEM_PHYS,
  207. CONFIG_SYS_PCI1_MEM_SIZE,
  208. PCI_REGION_MEM);
  209. /* outbound io */
  210. pci_set_region(r++,
  211. CONFIG_SYS_PCI1_IO_BASE,
  212. CONFIG_SYS_PCI1_IO_PHYS,
  213. CONFIG_SYS_PCI1_IO_SIZE,
  214. PCI_REGION_IO);
  215. hose->region_count = r - hose->regions;
  216. hose->first_busno = first_free_busno;
  217. fsl_pci_init(hose, (u32)&pci->cfg_addr, (u32)&pci->cfg_data);
  218. /* Unlock inbound PCI configuration cycles */
  219. if (!host)
  220. fsl_pci_config_unlock(hose);
  221. first_free_busno = hose->last_busno + 1;
  222. printf(" PCI1 on bus %02x - %02x\n",
  223. hose->first_busno, hose->last_busno);
  224. } else {
  225. printf(" PCI1: disabled\n");
  226. }
  227. #elif defined CONFIG_MPC8548
  228. /* PCI1 not present on MPC8572 */
  229. setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_PCI1);
  230. #endif
  231. #ifdef CONFIG_PCIE1
  232. pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE1_ADDR;
  233. hose = &pcie1_hose;
  234. host = host_agent_cfg[host_agent].pcie_root[0];
  235. width = io_port_cfg[io_sel].pcie_width[0];
  236. r = hose->regions;
  237. if (width && !(devdisr & MPC8xxx_DEVDISR_PCIE1)) {
  238. printf("\n PCIE1 connected as %s (x%d)",
  239. host ? "Root Complex" : "Endpoint", width);
  240. if (in_be32(&pci->pme_msg_det)) {
  241. out_be32(&pci->pme_msg_det, 0xffffffff);
  242. debug(" with errors. Clearing. Now 0x%08x",
  243. in_be32(&pci->pme_msg_det));
  244. }
  245. printf("\n");
  246. /* outbound memory */
  247. pci_set_region(r++,
  248. CONFIG_SYS_PCIE1_MEM_BASE,
  249. CONFIG_SYS_PCIE1_MEM_PHYS,
  250. CONFIG_SYS_PCIE1_MEM_SIZE,
  251. PCI_REGION_MEM);
  252. /* outbound io */
  253. pci_set_region(r++,
  254. CONFIG_SYS_PCIE1_IO_BASE,
  255. CONFIG_SYS_PCIE1_IO_PHYS,
  256. CONFIG_SYS_PCIE1_IO_SIZE,
  257. PCI_REGION_IO);
  258. hose->region_count = r - hose->regions;
  259. hose->first_busno = first_free_busno;
  260. fsl_pci_init(hose, (u32)&pci->cfg_addr, (u32)&pci->cfg_data);
  261. /* Unlock inbound PCI configuration cycles */
  262. if (!host)
  263. fsl_pci_config_unlock(hose);
  264. first_free_busno = hose->last_busno + 1;
  265. printf(" PCIE1 on bus %02x - %02x\n",
  266. hose->first_busno, hose->last_busno);
  267. }
  268. #else
  269. setbits_be32(&gur->devdisr, MPC8xxx_DEVDISR_PCIE1);
  270. #endif /* CONFIG_PCIE1 */
  271. #ifdef CONFIG_PCIE2
  272. pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE2_ADDR;
  273. hose = &pcie2_hose;
  274. host = host_agent_cfg[host_agent].pcie_root[1];
  275. width = io_port_cfg[io_sel].pcie_width[1];
  276. r = hose->regions;
  277. if (width && !(devdisr & MPC8xxx_DEVDISR_PCIE2)) {
  278. printf("\n PCIE2 connected as %s (x%d)",
  279. host ? "Root Complex" : "Endpoint", width);
  280. if (in_be32(&pci->pme_msg_det)) {
  281. out_be32(&pci->pme_msg_det, 0xffffffff);
  282. debug(" with errors. Clearing. Now 0x%08x",
  283. in_be32(&pci->pme_msg_det));
  284. }
  285. printf("\n");
  286. /* outbound memory */
  287. pci_set_region(r++,
  288. CONFIG_SYS_PCIE2_MEM_BASE,
  289. CONFIG_SYS_PCIE2_MEM_PHYS,
  290. CONFIG_SYS_PCIE2_MEM_SIZE,
  291. PCI_REGION_MEM);
  292. /* outbound io */
  293. pci_set_region(r++,
  294. CONFIG_SYS_PCIE2_IO_BASE,
  295. CONFIG_SYS_PCIE2_IO_PHYS,
  296. CONFIG_SYS_PCIE2_IO_SIZE,
  297. PCI_REGION_IO);
  298. hose->region_count = r - hose->regions;
  299. hose->first_busno = first_free_busno;
  300. fsl_pci_init(hose, (u32)&pci->cfg_addr, (u32)&pci->cfg_data);
  301. /* Unlock inbound PCI configuration cycles */
  302. if (!host)
  303. fsl_pci_config_unlock(hose);
  304. first_free_busno = hose->last_busno + 1;
  305. printf(" PCIE2 on bus %02x - %02x\n",
  306. hose->first_busno, hose->last_busno);
  307. }
  308. #else
  309. setbits_be32(&gur->devdisr, MPC8xxx_DEVDISR_PCIE2);
  310. #endif /* CONFIG_PCIE2 */
  311. #ifdef CONFIG_PCIE3
  312. pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE3_ADDR;
  313. hose = &pcie3_hose;
  314. host = host_agent_cfg[host_agent].pcie_root[2];
  315. width = io_port_cfg[io_sel].pcie_width[2];
  316. r = hose->regions;
  317. if (width && !(devdisr & MPC8xxx_DEVDISR_PCIE3)) {
  318. printf("\n PCIE3 connected as %s (x%d)",
  319. host ? "Root Complex" : "Endpoint", width);
  320. if (in_be32(&pci->pme_msg_det)) {
  321. out_be32(&pci->pme_msg_det, 0xffffffff);
  322. debug(" with errors. Clearing. Now 0x%08x",
  323. in_be32(&pci->pme_msg_det));
  324. }
  325. printf("\n");
  326. /* outbound memory */
  327. pci_set_region(r++,
  328. CONFIG_SYS_PCIE3_MEM_BASE,
  329. CONFIG_SYS_PCIE3_MEM_PHYS,
  330. CONFIG_SYS_PCIE3_MEM_SIZE,
  331. PCI_REGION_MEM);
  332. /* outbound io */
  333. pci_set_region(r++,
  334. CONFIG_SYS_PCIE3_IO_BASE,
  335. CONFIG_SYS_PCIE3_IO_PHYS,
  336. CONFIG_SYS_PCIE3_IO_SIZE,
  337. PCI_REGION_IO);
  338. hose->region_count = r - hose->regions;
  339. hose->first_busno = first_free_busno;
  340. fsl_pci_init(hose, (u32)&pci->cfg_addr, (u32)&pci->cfg_data);
  341. /* Unlock inbound PCI configuration cycles */
  342. if (!host)
  343. fsl_pci_config_unlock(hose);
  344. first_free_busno = hose->last_busno + 1;
  345. printf(" PCIE3 on bus %02x - %02x\n",
  346. hose->first_busno, hose->last_busno);
  347. }
  348. #else
  349. setbits_be32(&gur->devdisr, MPC8xxx_DEVDISR_PCIE3);
  350. #endif /* CONFIG_PCIE3 */
  351. }
  352. #if defined(CONFIG_OF_BOARD_SETUP)
  353. void ft_board_pci_setup(void *blob, bd_t *bd)
  354. {
  355. FT_FSL_PCI_SETUP;
  356. }
  357. #endif /* CONFIG_OF_BOARD_SETUP */