fsl_8xxx_pci.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  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. /* outbound memory */
  203. pci_set_region(r++,
  204. CONFIG_SYS_PCI1_MEM_BASE,
  205. CONFIG_SYS_PCI1_MEM_PHYS,
  206. CONFIG_SYS_PCI1_MEM_SIZE,
  207. PCI_REGION_MEM);
  208. /* outbound io */
  209. pci_set_region(r++,
  210. CONFIG_SYS_PCI1_IO_BASE,
  211. CONFIG_SYS_PCI1_IO_PHYS,
  212. CONFIG_SYS_PCI1_IO_SIZE,
  213. PCI_REGION_IO);
  214. hose->region_count = r - hose->regions;
  215. hose->first_busno = first_free_busno;
  216. fsl_pci_init(hose, (u32)&pci->cfg_addr, (u32)&pci->cfg_data);
  217. /* Unlock inbound PCI configuration cycles */
  218. if (!host)
  219. fsl_pci_config_unlock(hose);
  220. first_free_busno = hose->last_busno + 1;
  221. printf(" PCI1 on bus %02x - %02x\n",
  222. hose->first_busno, hose->last_busno);
  223. } else {
  224. printf(" PCI1: disabled\n");
  225. }
  226. #elif defined CONFIG_MPC8548
  227. /* PCI1 not present on MPC8572 */
  228. gur->devdisr |= MPC85xx_DEVDISR_PCI1; /* disable */
  229. #endif
  230. #ifdef CONFIG_PCIE1
  231. pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE1_ADDR;
  232. hose = &pcie1_hose;
  233. host = host_agent_cfg[host_agent].pcie_root[0];
  234. width = io_port_cfg[io_sel].pcie_width[0];
  235. r = hose->regions;
  236. if (width && !(devdisr & MPC8xxx_DEVDISR_PCIE1)) {
  237. printf("\n PCIE1 connected as %s (x%d)",
  238. host ? "Root Complex" : "End Point", width);
  239. if (pci->pme_msg_det) {
  240. pci->pme_msg_det = 0xffffffff;
  241. debug(" with errors. Clearing. Now 0x%08x",
  242. pci->pme_msg_det);
  243. }
  244. printf("\n");
  245. /* outbound memory */
  246. pci_set_region(r++,
  247. CONFIG_SYS_PCIE1_MEM_BASE,
  248. CONFIG_SYS_PCIE1_MEM_PHYS,
  249. CONFIG_SYS_PCIE1_MEM_SIZE,
  250. PCI_REGION_MEM);
  251. /* outbound io */
  252. pci_set_region(r++,
  253. CONFIG_SYS_PCIE1_IO_BASE,
  254. CONFIG_SYS_PCIE1_IO_PHYS,
  255. CONFIG_SYS_PCIE1_IO_SIZE,
  256. PCI_REGION_IO);
  257. hose->region_count = r - hose->regions;
  258. hose->first_busno = first_free_busno;
  259. fsl_pci_init(hose, (u32)&pci->cfg_addr, (u32)&pci->cfg_data);
  260. /* Unlock inbound PCI configuration cycles */
  261. if (!host)
  262. fsl_pci_config_unlock(hose);
  263. first_free_busno = hose->last_busno + 1;
  264. printf(" PCIE1 on bus %02x - %02x\n",
  265. hose->first_busno, hose->last_busno);
  266. }
  267. #else
  268. gur->devdisr |= MPC8xxx_DEVDISR_PCIE1; /* disable */
  269. #endif /* CONFIG_PCIE1 */
  270. #ifdef CONFIG_PCIE2
  271. pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE2_ADDR;
  272. hose = &pcie2_hose;
  273. host = host_agent_cfg[host_agent].pcie_root[1];
  274. width = io_port_cfg[io_sel].pcie_width[1];
  275. r = hose->regions;
  276. if (width && !(devdisr & MPC8xxx_DEVDISR_PCIE2)) {
  277. printf("\n PCIE2 connected as %s (x%d)",
  278. host ? "Root Complex" : "End Point", width);
  279. if (pci->pme_msg_det) {
  280. pci->pme_msg_det = 0xffffffff;
  281. debug(" with errors. Clearing. Now 0x%08x",
  282. pci->pme_msg_det);
  283. }
  284. printf("\n");
  285. /* outbound memory */
  286. pci_set_region(r++,
  287. CONFIG_SYS_PCIE2_MEM_BASE,
  288. CONFIG_SYS_PCIE2_MEM_PHYS,
  289. CONFIG_SYS_PCIE2_MEM_SIZE,
  290. PCI_REGION_MEM);
  291. /* outbound io */
  292. pci_set_region(r++,
  293. CONFIG_SYS_PCIE2_IO_BASE,
  294. CONFIG_SYS_PCIE2_IO_PHYS,
  295. CONFIG_SYS_PCIE2_IO_SIZE,
  296. PCI_REGION_IO);
  297. hose->region_count = r - hose->regions;
  298. hose->first_busno = first_free_busno;
  299. fsl_pci_init(hose, (u32)&pci->cfg_addr, (u32)&pci->cfg_data);
  300. /* Unlock inbound PCI configuration cycles */
  301. if (!host)
  302. fsl_pci_config_unlock(hose);
  303. first_free_busno = hose->last_busno + 1;
  304. printf(" PCIE2 on bus %02x - %02x\n",
  305. hose->first_busno, hose->last_busno);
  306. }
  307. #else
  308. gur->devdisr |= MPC8xxx_DEVDISR_PCIE2; /* disable */
  309. #endif /* CONFIG_PCIE2 */
  310. #ifdef CONFIG_PCIE3
  311. pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE3_ADDR;
  312. hose = &pcie3_hose;
  313. host = host_agent_cfg[host_agent].pcie_root[2];
  314. width = io_port_cfg[io_sel].pcie_width[2];
  315. r = hose->regions;
  316. if (width && !(devdisr & MPC8xxx_DEVDISR_PCIE3)) {
  317. printf("\n PCIE3 connected as %s (x%d)",
  318. host ? "Root Complex" : "End Point", width);
  319. if (pci->pme_msg_det) {
  320. pci->pme_msg_det = 0xffffffff;
  321. debug(" with errors. Clearing. Now 0x%08x",
  322. pci->pme_msg_det);
  323. }
  324. printf("\n");
  325. /* outbound memory */
  326. pci_set_region(r++,
  327. CONFIG_SYS_PCIE3_MEM_BASE,
  328. CONFIG_SYS_PCIE3_MEM_PHYS,
  329. CONFIG_SYS_PCIE3_MEM_SIZE,
  330. PCI_REGION_MEM);
  331. /* outbound io */
  332. pci_set_region(r++,
  333. CONFIG_SYS_PCIE3_IO_BASE,
  334. CONFIG_SYS_PCIE3_IO_PHYS,
  335. CONFIG_SYS_PCIE3_IO_SIZE,
  336. PCI_REGION_IO);
  337. hose->region_count = r - hose->regions;
  338. hose->first_busno = first_free_busno;
  339. fsl_pci_init(hose, (u32)&pci->cfg_addr, (u32)&pci->cfg_data);
  340. /* Unlock inbound PCI configuration cycles */
  341. if (!host)
  342. fsl_pci_config_unlock(hose);
  343. first_free_busno = hose->last_busno + 1;
  344. printf(" PCIE3 on bus %02x - %02x\n",
  345. hose->first_busno, hose->last_busno);
  346. }
  347. #else
  348. gur->devdisr |= MPC8xxx_DEVDISR_PCIE3; /* disable */
  349. #endif /* CONFIG_PCIE3 */
  350. }
  351. #if defined(CONFIG_OF_BOARD_SETUP)
  352. void ft_board_pci_setup(void *blob, bd_t *bd)
  353. {
  354. /* TODO - make node name (eg pci0) dynamic */
  355. #ifdef CONFIG_PCI1
  356. ft_fsl_pci_setup(blob, "pci0", &pci1_hose);
  357. #endif
  358. #ifdef CONFIG_PCIE1
  359. ft_fsl_pci_setup(blob, "pci2", &pcie1_hose);
  360. #endif
  361. #ifdef CONFIG_PCIE2
  362. ft_fsl_pci_setup(blob, "pci1", &pcie2_hose);
  363. #endif
  364. #ifdef CONFIG_PCIE3
  365. ft_fsl_pci_setup(blob, "pci0", &pcie3_hose);
  366. #endif
  367. }
  368. #endif /* CONFIG_OF_BOARD_SETUP */