liodn.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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. static void set_srio_liodn(struct srio_liodn_id_table *tbl, int size)
  38. {
  39. int i;
  40. for (i = 0; i < size; i++) {
  41. unsigned long reg_off = tbl[i].reg_offset[0];
  42. out_be32((u32 *)reg_off, tbl[i].id[0]);
  43. if (tbl[i].num_ids == 2) {
  44. reg_off = tbl[i].reg_offset[1];
  45. out_be32((u32 *)reg_off, tbl[i].id[1]);
  46. }
  47. }
  48. }
  49. static void set_liodn(struct liodn_id_table *tbl, int size)
  50. {
  51. int i;
  52. for (i = 0; i < size; i++) {
  53. u32 liodn;
  54. if (tbl[i].num_ids == 2) {
  55. liodn = (tbl[i].id[0] << 16) | tbl[i].id[1];
  56. } else {
  57. liodn = tbl[i].id[0];
  58. }
  59. out_be32((volatile u32 *)(tbl[i].reg_offset), liodn);
  60. }
  61. }
  62. static void setup_sec_liodn_base(void)
  63. {
  64. ccsr_sec_t *sec = (void *)CONFIG_SYS_FSL_SEC_ADDR;
  65. u32 base;
  66. if (!IS_E_PROCESSOR(get_svr()))
  67. return;
  68. /* QILCR[QSLOM] */
  69. out_be32(&sec->qilcr_ms, 0x3ff<<16);
  70. base = (liodn_bases[FSL_HW_PORTAL_SEC].id[0] << 16) |
  71. liodn_bases[FSL_HW_PORTAL_SEC].id[1];
  72. out_be32(&sec->qilcr_ls, base);
  73. }
  74. #ifdef CONFIG_SYS_DPAA_FMAN
  75. static void setup_fman_liodn_base(enum fsl_dpaa_dev dev,
  76. struct liodn_id_table *tbl, int size)
  77. {
  78. int i;
  79. ccsr_fman_t *fm;
  80. u32 base;
  81. switch(dev) {
  82. case FSL_HW_PORTAL_FMAN1:
  83. fm = (void *)CONFIG_SYS_FSL_FM1_ADDR;
  84. break;
  85. #if (CONFIG_SYS_NUM_FMAN == 2)
  86. case FSL_HW_PORTAL_FMAN2:
  87. fm = (void *)CONFIG_SYS_FSL_FM2_ADDR;
  88. break;
  89. #endif
  90. default:
  91. printf("Error: Invalid device type to %s\n", __FUNCTION__);
  92. return ;
  93. }
  94. base = (liodn_bases[dev].id[0] << 16) | liodn_bases[dev].id[0];
  95. /* setup all bases the same */
  96. for (i = 0; i < 32; i++) {
  97. out_be32(&fm->fm_dma.fmdmplr[i], base);
  98. }
  99. /* update tbl to ... */
  100. for (i = 0; i < size; i++)
  101. tbl[i].id[0] += liodn_bases[dev].id[0];
  102. }
  103. #endif
  104. static void setup_pme_liodn_base(void)
  105. {
  106. #ifdef CONFIG_SYS_DPAA_PME
  107. ccsr_pme_t *pme = (void *)CONFIG_SYS_FSL_CORENET_PME_ADDR;
  108. u32 base = (liodn_bases[FSL_HW_PORTAL_PME].id[0] << 16) |
  109. liodn_bases[FSL_HW_PORTAL_PME].id[1];
  110. out_be32(&pme->liodnbr, base);
  111. #endif
  112. }
  113. #ifdef CONFIG_SYS_FSL_RAID_ENGINE
  114. static void setup_raide_liodn_base(void)
  115. {
  116. struct ccsr_raide *raide = (void *)CONFIG_SYS_FSL_RAID_ENGINE_ADDR;
  117. /* setup raid engine liodn base for data/desc ; both set to 47 */
  118. u32 base = (liodn_bases[FSL_HW_PORTAL_RAID_ENGINE].id[0] << 16) |
  119. liodn_bases[FSL_HW_PORTAL_RAID_ENGINE].id[0];
  120. out_be32(&raide->liodnbr, base);
  121. }
  122. #endif
  123. #ifdef CONFIG_SYS_DPAA_RMAN
  124. static void set_rman_liodn(struct liodn_id_table *tbl, int size)
  125. {
  126. int i;
  127. struct ccsr_rman *rman = (void *)CONFIG_SYS_FSL_CORENET_RMAN_ADDR;
  128. for (i = 0; i < size; i++) {
  129. /* write the RMan block number */
  130. out_be32(&rman->mmitar, i);
  131. /* write the liodn offset corresponding to the block */
  132. out_be32((u32 *)(tbl[i].reg_offset), tbl[i].id[0]);
  133. }
  134. }
  135. static void setup_rman_liodn_base(struct liodn_id_table *tbl, int size)
  136. {
  137. int i;
  138. struct ccsr_rman *rman = (void *)CONFIG_SYS_FSL_CORENET_RMAN_ADDR;
  139. u32 base = liodn_bases[FSL_HW_PORTAL_RMAN].id[0];
  140. out_be32(&rman->mmliodnbr, base);
  141. /* update liodn offset */
  142. for (i = 0; i < size; i++)
  143. tbl[i].id[0] += base;
  144. }
  145. #endif
  146. void set_liodns(void)
  147. {
  148. /* setup general liodn offsets */
  149. set_liodn(liodn_tbl, liodn_tbl_sz);
  150. /* setup SRIO port liodns */
  151. set_srio_liodn(srio_liodn_tbl, srio_liodn_tbl_sz);
  152. /* setup SEC block liodn bases & offsets if we have one */
  153. if (IS_E_PROCESSOR(get_svr())) {
  154. set_liodn(sec_liodn_tbl, sec_liodn_tbl_sz);
  155. setup_sec_liodn_base();
  156. }
  157. /* setup FMAN block(s) liodn bases & offsets if we have one */
  158. #ifdef CONFIG_SYS_DPAA_FMAN
  159. set_liodn(fman1_liodn_tbl, fman1_liodn_tbl_sz);
  160. setup_fman_liodn_base(FSL_HW_PORTAL_FMAN1, fman1_liodn_tbl,
  161. fman1_liodn_tbl_sz);
  162. #if (CONFIG_SYS_NUM_FMAN == 2)
  163. set_liodn(fman2_liodn_tbl, fman2_liodn_tbl_sz);
  164. setup_fman_liodn_base(FSL_HW_PORTAL_FMAN2, fman2_liodn_tbl,
  165. fman2_liodn_tbl_sz);
  166. #endif
  167. #endif
  168. /* setup PME liodn base */
  169. setup_pme_liodn_base();
  170. #ifdef CONFIG_SYS_FSL_RAID_ENGINE
  171. /* raid engine ccr addr code for liodn */
  172. set_liodn(raide_liodn_tbl, raide_liodn_tbl_sz);
  173. setup_raide_liodn_base();
  174. #endif
  175. #ifdef CONFIG_SYS_DPAA_RMAN
  176. /* setup RMan liodn offsets */
  177. set_rman_liodn(rman_liodn_tbl, rman_liodn_tbl_sz);
  178. /* setup RMan liodn base */
  179. setup_rman_liodn_base(rman_liodn_tbl, rman_liodn_tbl_sz);
  180. #endif
  181. }
  182. static void fdt_fixup_srio_liodn(void *blob, struct srio_liodn_id_table *tbl)
  183. {
  184. int i, srio_off;
  185. /* search for srio node, if doesn't exist just return - nothing todo */
  186. srio_off = fdt_node_offset_by_compatible(blob, -1, "fsl,srio");
  187. if (srio_off < 0)
  188. return ;
  189. for (i = 0; i < srio_liodn_tbl_sz; i++) {
  190. int off, portid = tbl[i].portid;
  191. off = fdt_node_offset_by_prop_value(blob, srio_off,
  192. "cell-index", &portid, 4);
  193. if (off >= 0) {
  194. off = fdt_setprop(blob, off, "fsl,liodn",
  195. &tbl[i].id[0],
  196. sizeof(u32) * tbl[i].num_ids);
  197. if (off > 0)
  198. printf("WARNING unable to set fsl,liodn for "
  199. "fsl,srio port %d: %s\n",
  200. portid, fdt_strerror(off));
  201. } else {
  202. debug("WARNING: couldn't set fsl,liodn for srio: %s.\n",
  203. fdt_strerror(off));
  204. }
  205. }
  206. }
  207. static void fdt_fixup_liodn_tbl(void *blob, struct liodn_id_table *tbl, int sz)
  208. {
  209. int i;
  210. for (i = 0; i < sz; i++) {
  211. int off;
  212. if (tbl[i].compat == NULL)
  213. continue;
  214. off = fdt_node_offset_by_compat_reg(blob,
  215. tbl[i].compat, tbl[i].compat_offset);
  216. if (off >= 0) {
  217. off = fdt_setprop(blob, off, "fsl,liodn",
  218. &tbl[i].id[0],
  219. sizeof(u32) * tbl[i].num_ids);
  220. if (off > 0)
  221. printf("WARNING unable to set fsl,liodn for "
  222. "%s: %s\n",
  223. tbl[i].compat, fdt_strerror(off));
  224. } else {
  225. debug("WARNING: could not set fsl,liodn for %s: %s.\n",
  226. tbl[i].compat, fdt_strerror(off));
  227. }
  228. }
  229. }
  230. void fdt_fixup_liodn(void *blob)
  231. {
  232. fdt_fixup_srio_liodn(blob, srio_liodn_tbl);
  233. fdt_fixup_liodn_tbl(blob, liodn_tbl, liodn_tbl_sz);
  234. #ifdef CONFIG_SYS_DPAA_FMAN
  235. fdt_fixup_liodn_tbl(blob, fman1_liodn_tbl, fman1_liodn_tbl_sz);
  236. #if (CONFIG_SYS_NUM_FMAN == 2)
  237. fdt_fixup_liodn_tbl(blob, fman2_liodn_tbl, fman2_liodn_tbl_sz);
  238. #endif
  239. #endif
  240. fdt_fixup_liodn_tbl(blob, sec_liodn_tbl, sec_liodn_tbl_sz);
  241. #ifdef CONFIG_SYS_FSL_RAID_ENGINE
  242. fdt_fixup_liodn_tbl(blob, raide_liodn_tbl, raide_liodn_tbl_sz);
  243. #endif
  244. #ifdef CONFIG_SYS_DPAA_RMAN
  245. fdt_fixup_liodn_tbl(blob, rman_liodn_tbl, rman_liodn_tbl_sz);
  246. #endif
  247. }