fsl_8xxx_pci.c 11 KB

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