liodn.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. /*
  2. * Copyright 2008-2011 Freescale Semiconductor, Inc.
  3. *
  4. * See file CREDITS for list of people who contributed to this
  5. * project.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. */
  22. #include <common.h>
  23. #include <libfdt.h>
  24. #include <fdt_support.h>
  25. #include <asm/immap_85xx.h>
  26. #include <asm/io.h>
  27. #include <asm/processor.h>
  28. #include <asm/fsl_portals.h>
  29. #include <asm/fsl_liodn.h>
  30. int get_dpaa_liodn(enum fsl_dpaa_dev dpaa_dev, u32 *liodns, int liodn_offset)
  31. {
  32. liodns[0] = liodn_bases[dpaa_dev].id[0] + liodn_offset;
  33. if (liodn_bases[dpaa_dev].num_ids == 2)
  34. liodns[1] = liodn_bases[dpaa_dev].id[1] + liodn_offset;
  35. return liodn_bases[dpaa_dev].num_ids;
  36. }
  37. #ifdef CONFIG_SYS_SRIO
  38. static void set_srio_liodn(struct srio_liodn_id_table *tbl, int size)
  39. {
  40. int i;
  41. for (i = 0; i < size; i++) {
  42. unsigned long reg_off = tbl[i].reg_offset[0];
  43. out_be32((u32 *)reg_off, tbl[i].id[0]);
  44. if (tbl[i].num_ids == 2) {
  45. reg_off = tbl[i].reg_offset[1];
  46. out_be32((u32 *)reg_off, tbl[i].id[1]);
  47. }
  48. }
  49. }
  50. #endif
  51. static void set_liodn(struct liodn_id_table *tbl, int size)
  52. {
  53. int i;
  54. for (i = 0; i < size; i++) {
  55. u32 liodn;
  56. if (tbl[i].num_ids == 2) {
  57. liodn = (tbl[i].id[0] << 16) | tbl[i].id[1];
  58. } else {
  59. liodn = tbl[i].id[0];
  60. }
  61. out_be32((volatile u32 *)(tbl[i].reg_offset), liodn);
  62. }
  63. }
  64. static void setup_sec_liodn_base(void)
  65. {
  66. ccsr_sec_t *sec = (void *)CONFIG_SYS_FSL_SEC_ADDR;
  67. u32 base;
  68. if (!IS_E_PROCESSOR(get_svr()))
  69. return;
  70. /* QILCR[QSLOM] */
  71. out_be32(&sec->qilcr_ms, 0x3ff<<16);
  72. base = (liodn_bases[FSL_HW_PORTAL_SEC].id[0] << 16) |
  73. liodn_bases[FSL_HW_PORTAL_SEC].id[1];
  74. out_be32(&sec->qilcr_ls, base);
  75. }
  76. #ifdef CONFIG_SYS_DPAA_FMAN
  77. static void setup_fman_liodn_base(enum fsl_dpaa_dev dev,
  78. struct liodn_id_table *tbl, int size)
  79. {
  80. int i;
  81. ccsr_fman_t *fm;
  82. u32 base;
  83. switch(dev) {
  84. case FSL_HW_PORTAL_FMAN1:
  85. fm = (void *)CONFIG_SYS_FSL_FM1_ADDR;
  86. break;
  87. #if (CONFIG_SYS_NUM_FMAN == 2)
  88. case FSL_HW_PORTAL_FMAN2:
  89. fm = (void *)CONFIG_SYS_FSL_FM2_ADDR;
  90. break;
  91. #endif
  92. default:
  93. printf("Error: Invalid device type to %s\n", __FUNCTION__);
  94. return ;
  95. }
  96. base = (liodn_bases[dev].id[0] << 16) | liodn_bases[dev].id[0];
  97. /* setup all bases the same */
  98. for (i = 0; i < 32; i++) {
  99. out_be32(&fm->fm_dma.fmdmplr[i], base);
  100. }
  101. /* update tbl to ... */
  102. for (i = 0; i < size; i++)
  103. tbl[i].id[0] += liodn_bases[dev].id[0];
  104. }
  105. #endif
  106. static void setup_pme_liodn_base(void)
  107. {
  108. #ifdef CONFIG_SYS_DPAA_PME
  109. ccsr_pme_t *pme = (void *)CONFIG_SYS_FSL_CORENET_PME_ADDR;
  110. u32 base = (liodn_bases[FSL_HW_PORTAL_PME].id[0] << 16) |
  111. liodn_bases[FSL_HW_PORTAL_PME].id[1];
  112. out_be32(&pme->liodnbr, base);
  113. #endif
  114. }
  115. #ifdef CONFIG_SYS_FSL_RAID_ENGINE
  116. static void setup_raide_liodn_base(void)
  117. {
  118. struct ccsr_raide *raide = (void *)CONFIG_SYS_FSL_RAID_ENGINE_ADDR;
  119. /* setup raid engine liodn base for data/desc ; both set to 47 */
  120. u32 base = (liodn_bases[FSL_HW_PORTAL_RAID_ENGINE].id[0] << 16) |
  121. liodn_bases[FSL_HW_PORTAL_RAID_ENGINE].id[0];
  122. out_be32(&raide->liodnbr, base);
  123. }
  124. #endif
  125. #ifdef CONFIG_SYS_DPAA_RMAN
  126. static void set_rman_liodn(struct liodn_id_table *tbl, int size)
  127. {
  128. int i;
  129. struct ccsr_rman *rman = (void *)CONFIG_SYS_FSL_CORENET_RMAN_ADDR;
  130. for (i = 0; i < size; i++) {
  131. /* write the RMan block number */
  132. out_be32(&rman->mmitar, i);
  133. /* write the liodn offset corresponding to the block */
  134. out_be32((u32 *)(tbl[i].reg_offset), tbl[i].id[0]);
  135. }
  136. }
  137. static void setup_rman_liodn_base(struct liodn_id_table *tbl, int size)
  138. {
  139. int i;
  140. struct ccsr_rman *rman = (void *)CONFIG_SYS_FSL_CORENET_RMAN_ADDR;
  141. u32 base = liodn_bases[FSL_HW_PORTAL_RMAN].id[0];
  142. out_be32(&rman->mmliodnbr, base);
  143. /* update liodn offset */
  144. for (i = 0; i < size; i++)
  145. tbl[i].id[0] += base;
  146. }
  147. #endif
  148. void set_liodns(void)
  149. {
  150. /* setup general liodn offsets */
  151. set_liodn(liodn_tbl, liodn_tbl_sz);
  152. #ifdef CONFIG_SYS_SRIO
  153. /* setup SRIO port liodns */
  154. set_srio_liodn(srio_liodn_tbl, srio_liodn_tbl_sz);
  155. #endif
  156. /* setup SEC block liodn bases & offsets if we have one */
  157. if (IS_E_PROCESSOR(get_svr())) {
  158. set_liodn(sec_liodn_tbl, sec_liodn_tbl_sz);
  159. setup_sec_liodn_base();
  160. }
  161. /* setup FMAN block(s) liodn bases & offsets if we have one */
  162. #ifdef CONFIG_SYS_DPAA_FMAN
  163. set_liodn(fman1_liodn_tbl, fman1_liodn_tbl_sz);
  164. setup_fman_liodn_base(FSL_HW_PORTAL_FMAN1, fman1_liodn_tbl,
  165. fman1_liodn_tbl_sz);
  166. #if (CONFIG_SYS_NUM_FMAN == 2)
  167. set_liodn(fman2_liodn_tbl, fman2_liodn_tbl_sz);
  168. setup_fman_liodn_base(FSL_HW_PORTAL_FMAN2, fman2_liodn_tbl,
  169. fman2_liodn_tbl_sz);
  170. #endif
  171. #endif
  172. /* setup PME liodn base */
  173. setup_pme_liodn_base();
  174. #ifdef CONFIG_SYS_FSL_RAID_ENGINE
  175. /* raid engine ccr addr code for liodn */
  176. set_liodn(raide_liodn_tbl, raide_liodn_tbl_sz);
  177. setup_raide_liodn_base();
  178. #endif
  179. #ifdef CONFIG_SYS_DPAA_RMAN
  180. /* setup RMan liodn offsets */
  181. set_rman_liodn(rman_liodn_tbl, rman_liodn_tbl_sz);
  182. /* setup RMan liodn base */
  183. setup_rman_liodn_base(rman_liodn_tbl, rman_liodn_tbl_sz);
  184. #endif
  185. }
  186. #ifdef CONFIG_SYS_SRIO
  187. static void fdt_fixup_srio_liodn(void *blob, struct srio_liodn_id_table *tbl)
  188. {
  189. int i, srio_off;
  190. /* search for srio node, if doesn't exist just return - nothing todo */
  191. srio_off = fdt_node_offset_by_compatible(blob, -1, "fsl,srio");
  192. if (srio_off < 0)
  193. return ;
  194. for (i = 0; i < srio_liodn_tbl_sz; i++) {
  195. int off, portid = tbl[i].portid;
  196. off = fdt_node_offset_by_prop_value(blob, srio_off,
  197. "cell-index", &portid, 4);
  198. if (off >= 0) {
  199. off = fdt_setprop(blob, off, "fsl,liodn",
  200. &tbl[i].id[0],
  201. sizeof(u32) * tbl[i].num_ids);
  202. if (off > 0)
  203. printf("WARNING unable to set fsl,liodn for "
  204. "fsl,srio port %d: %s\n",
  205. portid, fdt_strerror(off));
  206. } else {
  207. debug("WARNING: couldn't set fsl,liodn for srio: %s.\n",
  208. fdt_strerror(off));
  209. }
  210. }
  211. }
  212. #endif
  213. static void fdt_fixup_liodn_tbl(void *blob, struct liodn_id_table *tbl, int sz)
  214. {
  215. int i;
  216. for (i = 0; i < sz; i++) {
  217. int off;
  218. if (tbl[i].compat == NULL)
  219. continue;
  220. off = fdt_node_offset_by_compat_reg(blob,
  221. tbl[i].compat, tbl[i].compat_offset);
  222. if (off >= 0) {
  223. off = fdt_setprop(blob, off, "fsl,liodn",
  224. &tbl[i].id[0],
  225. sizeof(u32) * tbl[i].num_ids);
  226. if (off > 0)
  227. printf("WARNING unable to set fsl,liodn for "
  228. "%s: %s\n",
  229. tbl[i].compat, fdt_strerror(off));
  230. } else {
  231. debug("WARNING: could not set fsl,liodn for %s: %s.\n",
  232. tbl[i].compat, fdt_strerror(off));
  233. }
  234. }
  235. }
  236. void fdt_fixup_liodn(void *blob)
  237. {
  238. #ifdef CONFIG_SYS_SRIO
  239. fdt_fixup_srio_liodn(blob, srio_liodn_tbl);
  240. #endif
  241. fdt_fixup_liodn_tbl(blob, liodn_tbl, liodn_tbl_sz);
  242. #ifdef CONFIG_SYS_DPAA_FMAN
  243. fdt_fixup_liodn_tbl(blob, fman1_liodn_tbl, fman1_liodn_tbl_sz);
  244. #if (CONFIG_SYS_NUM_FMAN == 2)
  245. fdt_fixup_liodn_tbl(blob, fman2_liodn_tbl, fman2_liodn_tbl_sz);
  246. #endif
  247. #endif
  248. fdt_fixup_liodn_tbl(blob, sec_liodn_tbl, sec_liodn_tbl_sz);
  249. #ifdef CONFIG_SYS_FSL_RAID_ENGINE
  250. fdt_fixup_liodn_tbl(blob, raide_liodn_tbl, raide_liodn_tbl_sz);
  251. #endif
  252. #ifdef CONFIG_SYS_DPAA_RMAN
  253. fdt_fixup_liodn_tbl(blob, rman_liodn_tbl, rman_liodn_tbl_sz);
  254. #endif
  255. }