srio.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /*
  2. * Copyright 2011 Freescale Semiconductor, Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License as published by the Free
  6. * Software Foundation; either version 2 of the License, or (at your option)
  7. * any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  17. * MA 02111-1307 USA
  18. */
  19. #include <common.h>
  20. #include <config.h>
  21. #include <asm/fsl_law.h>
  22. #include <asm/fsl_serdes.h>
  23. #include <asm/fsl_srio.h>
  24. #define SRIO_PORT_ACCEPT_ALL 0x10000001
  25. #define SRIO_IB_ATMU_AR 0x80f55000
  26. #define SRIO_OB_ATMU_AR_MAINT 0x80077000
  27. #define SRIO_OB_ATMU_AR_RW 0x80045000
  28. #define SRIO_LCSBA1CSR_OFFSET 0x5c
  29. #define SRIO_MAINT_WIN_SIZE 0x1000000 /* 16M */
  30. #define SRIO_RW_WIN_SIZE 0x100000 /* 1M */
  31. #define SRIO_LCSBA1CSR 0x60000000
  32. #if defined(CONFIG_FSL_CORENET)
  33. #define _DEVDISR_SRIO1 FSL_CORENET_DEVDISR_SRIO1
  34. #define _DEVDISR_SRIO2 FSL_CORENET_DEVDISR_SRIO2
  35. #define _DEVDISR_RMU FSL_CORENET_DEVDISR_RMU
  36. #define CONFIG_SYS_MPC8xxx_GUTS_ADDR CONFIG_SYS_MPC85xx_GUTS_ADDR
  37. #elif defined(CONFIG_MPC85xx)
  38. #define _DEVDISR_SRIO1 MPC85xx_DEVDISR_SRIO
  39. #define _DEVDISR_SRIO2 MPC85xx_DEVDISR_SRIO
  40. #define _DEVDISR_RMU MPC85xx_DEVDISR_RMSG
  41. #define CONFIG_SYS_MPC8xxx_GUTS_ADDR CONFIG_SYS_MPC85xx_GUTS_ADDR
  42. #elif defined(CONFIG_MPC86xx)
  43. #define _DEVDISR_SRIO1 MPC86xx_DEVDISR_SRIO
  44. #define _DEVDISR_SRIO2 MPC86xx_DEVDISR_SRIO
  45. #define _DEVDISR_RMU MPC86xx_DEVDISR_RMSG
  46. #define CONFIG_SYS_MPC8xxx_GUTS_ADDR \
  47. (&((immap_t *)CONFIG_SYS_IMMR)->im_gur)
  48. #else
  49. #error "No defines for DEVDISR_SRIO"
  50. #endif
  51. void srio_init(void)
  52. {
  53. ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC8xxx_GUTS_ADDR;
  54. int srio1_used = 0, srio2_used = 0;
  55. if (is_serdes_configured(SRIO1)) {
  56. set_next_law(CONFIG_SYS_SRIO1_MEM_PHYS,
  57. law_size_bits(CONFIG_SYS_SRIO1_MEM_SIZE),
  58. LAW_TRGT_IF_RIO_1);
  59. srio1_used = 1;
  60. printf("SRIO1: enabled\n");
  61. } else {
  62. printf("SRIO1: disabled\n");
  63. }
  64. #ifdef CONFIG_SRIO2
  65. if (is_serdes_configured(SRIO2)) {
  66. set_next_law(CONFIG_SYS_SRIO2_MEM_PHYS,
  67. law_size_bits(CONFIG_SYS_SRIO2_MEM_SIZE),
  68. LAW_TRGT_IF_RIO_2);
  69. srio2_used = 1;
  70. printf("SRIO2: enabled\n");
  71. } else {
  72. printf("SRIO2: disabled\n");
  73. }
  74. #endif
  75. #ifdef CONFIG_FSL_CORENET
  76. /* On FSL_CORENET devices we can disable individual ports */
  77. if (!srio1_used)
  78. setbits_be32(&gur->devdisr, FSL_CORENET_DEVDISR_SRIO1);
  79. if (!srio2_used)
  80. setbits_be32(&gur->devdisr, FSL_CORENET_DEVDISR_SRIO2);
  81. #endif
  82. /* neither port is used - disable everything */
  83. if (!srio1_used && !srio2_used) {
  84. setbits_be32(&gur->devdisr, _DEVDISR_SRIO1);
  85. setbits_be32(&gur->devdisr, _DEVDISR_SRIO2);
  86. setbits_be32(&gur->devdisr, _DEVDISR_RMU);
  87. }
  88. }
  89. #ifdef CONFIG_FSL_CORENET
  90. void srio_boot_master(int port)
  91. {
  92. struct ccsr_rio *srio = (void *)CONFIG_SYS_FSL_SRIO_ADDR;
  93. /* set port accept-all */
  94. out_be32((void *)&srio->impl.port[port - 1].ptaacr,
  95. SRIO_PORT_ACCEPT_ALL);
  96. debug("SRIOBOOT - MASTER: Master port [ %d ] for srio boot.\n", port);
  97. /* configure inbound window for slave's u-boot image */
  98. debug("SRIOBOOT - MASTER: Inbound window for slave's image; "
  99. "Local = 0x%llx, Srio = 0x%llx, Size = 0x%x\n",
  100. (u64)CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_PHYS,
  101. (u64)CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_BUS1,
  102. CONFIG_SRIO_PCIE_BOOT_IMAGE_SIZE);
  103. out_be32((void *)&srio->atmu.port[port - 1].inbw[0].riwtar,
  104. CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_PHYS >> 12);
  105. out_be32((void *)&srio->atmu.port[port - 1].inbw[0].riwbar,
  106. CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_BUS1 >> 12);
  107. out_be32((void *)&srio->atmu.port[port - 1].inbw[0].riwar,
  108. SRIO_IB_ATMU_AR
  109. | atmu_size_mask(CONFIG_SRIO_PCIE_BOOT_IMAGE_SIZE));
  110. /* configure inbound window for slave's u-boot image */
  111. debug("SRIOBOOT - MASTER: Inbound window for slave's image; "
  112. "Local = 0x%llx, Srio = 0x%llx, Size = 0x%x\n",
  113. (u64)CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_PHYS,
  114. (u64)CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_BUS2,
  115. CONFIG_SRIO_PCIE_BOOT_IMAGE_SIZE);
  116. out_be32((void *)&srio->atmu.port[port - 1].inbw[1].riwtar,
  117. CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_PHYS >> 12);
  118. out_be32((void *)&srio->atmu.port[port - 1].inbw[1].riwbar,
  119. CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_BUS2 >> 12);
  120. out_be32((void *)&srio->atmu.port[port - 1].inbw[1].riwar,
  121. SRIO_IB_ATMU_AR
  122. | atmu_size_mask(CONFIG_SRIO_PCIE_BOOT_IMAGE_SIZE));
  123. /* configure inbound window for slave's ucode and ENV */
  124. debug("SRIOBOOT - MASTER: Inbound window for slave's ucode and ENV; "
  125. "Local = 0x%llx, Srio = 0x%llx, Size = 0x%x\n",
  126. (u64)CONFIG_SRIO_PCIE_BOOT_UCODE_ENV_MEM_PHYS,
  127. (u64)CONFIG_SRIO_PCIE_BOOT_UCODE_ENV_MEM_BUS,
  128. CONFIG_SRIO_PCIE_BOOT_UCODE_ENV_SIZE);
  129. out_be32((void *)&srio->atmu.port[port - 1].inbw[2].riwtar,
  130. CONFIG_SRIO_PCIE_BOOT_UCODE_ENV_MEM_PHYS >> 12);
  131. out_be32((void *)&srio->atmu.port[port - 1].inbw[2].riwbar,
  132. CONFIG_SRIO_PCIE_BOOT_UCODE_ENV_MEM_BUS >> 12);
  133. out_be32((void *)&srio->atmu.port[port - 1].inbw[2].riwar,
  134. SRIO_IB_ATMU_AR
  135. | atmu_size_mask(CONFIG_SRIO_PCIE_BOOT_UCODE_ENV_SIZE));
  136. }
  137. void srio_boot_master_release_slave(int port)
  138. {
  139. struct ccsr_rio *srio = (void *)CONFIG_SYS_FSL_SRIO_ADDR;
  140. u32 escsr;
  141. debug("SRIOBOOT - MASTER: "
  142. "Check the port status and release slave core ...\n");
  143. escsr = in_be32((void *)&srio->lp_serial.port[port - 1].pescsr);
  144. if (escsr & 0x2) {
  145. if (escsr & 0x10100) {
  146. debug("SRIOBOOT - MASTER: Port [ %d ] is error.\n",
  147. port);
  148. } else {
  149. debug("SRIOBOOT - MASTER: "
  150. "Port [ %d ] is ready, now release slave's core ...\n",
  151. port);
  152. /*
  153. * configure outbound window
  154. * with maintenance attribute to set slave's LCSBA1CSR
  155. */
  156. out_be32((void *)&srio->atmu.port[port - 1]
  157. .outbw[1].rowtar, 0);
  158. out_be32((void *)&srio->atmu.port[port - 1]
  159. .outbw[1].rowtear, 0);
  160. if (port - 1)
  161. out_be32((void *)&srio->atmu.port[port - 1]
  162. .outbw[1].rowbar,
  163. CONFIG_SYS_SRIO2_MEM_PHYS >> 12);
  164. else
  165. out_be32((void *)&srio->atmu.port[port - 1]
  166. .outbw[1].rowbar,
  167. CONFIG_SYS_SRIO1_MEM_PHYS >> 12);
  168. out_be32((void *)&srio->atmu.port[port - 1]
  169. .outbw[1].rowar,
  170. SRIO_OB_ATMU_AR_MAINT
  171. | atmu_size_mask(SRIO_MAINT_WIN_SIZE));
  172. /*
  173. * configure outbound window
  174. * with R/W attribute to set slave's BRR
  175. */
  176. out_be32((void *)&srio->atmu.port[port - 1]
  177. .outbw[2].rowtar,
  178. SRIO_LCSBA1CSR >> 9);
  179. out_be32((void *)&srio->atmu.port[port - 1]
  180. .outbw[2].rowtear, 0);
  181. if (port - 1)
  182. out_be32((void *)&srio->atmu.port[port - 1]
  183. .outbw[2].rowbar,
  184. (CONFIG_SYS_SRIO2_MEM_PHYS
  185. + SRIO_MAINT_WIN_SIZE) >> 12);
  186. else
  187. out_be32((void *)&srio->atmu.port[port - 1]
  188. .outbw[2].rowbar,
  189. (CONFIG_SYS_SRIO1_MEM_PHYS
  190. + SRIO_MAINT_WIN_SIZE) >> 12);
  191. out_be32((void *)&srio->atmu.port[port - 1]
  192. .outbw[2].rowar,
  193. SRIO_OB_ATMU_AR_RW
  194. | atmu_size_mask(SRIO_RW_WIN_SIZE));
  195. /*
  196. * Set the LCSBA1CSR register in slave
  197. * by the maint-outbound window
  198. */
  199. if (port - 1) {
  200. out_be32((void *)CONFIG_SYS_SRIO2_MEM_VIRT
  201. + SRIO_LCSBA1CSR_OFFSET,
  202. SRIO_LCSBA1CSR);
  203. while (in_be32((void *)CONFIG_SYS_SRIO2_MEM_VIRT
  204. + SRIO_LCSBA1CSR_OFFSET)
  205. != SRIO_LCSBA1CSR)
  206. ;
  207. /*
  208. * And then set the BRR register
  209. * to release slave core
  210. */
  211. out_be32((void *)CONFIG_SYS_SRIO2_MEM_VIRT
  212. + SRIO_MAINT_WIN_SIZE
  213. + CONFIG_SRIO_PCIE_BOOT_BRR_OFFSET,
  214. CONFIG_SRIO_PCIE_BOOT_RELEASE_MASK);
  215. } else {
  216. out_be32((void *)CONFIG_SYS_SRIO1_MEM_VIRT
  217. + SRIO_LCSBA1CSR_OFFSET,
  218. SRIO_LCSBA1CSR);
  219. while (in_be32((void *)CONFIG_SYS_SRIO1_MEM_VIRT
  220. + SRIO_LCSBA1CSR_OFFSET)
  221. != SRIO_LCSBA1CSR)
  222. ;
  223. /*
  224. * And then set the BRR register
  225. * to release slave core
  226. */
  227. out_be32((void *)CONFIG_SYS_SRIO1_MEM_VIRT
  228. + SRIO_MAINT_WIN_SIZE
  229. + CONFIG_SRIO_PCIE_BOOT_BRR_OFFSET,
  230. CONFIG_SRIO_PCIE_BOOT_RELEASE_MASK);
  231. }
  232. debug("SRIOBOOT - MASTER: "
  233. "Release slave successfully! Now the slave should start up!\n");
  234. }
  235. } else
  236. debug("SRIOBOOT - MASTER: Port [ %d ] is not ready.\n", port);
  237. }
  238. #endif