liodn.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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. void set_liodns(void)
  124. {
  125. /* setup general liodn offsets */
  126. set_liodn(liodn_tbl, liodn_tbl_sz);
  127. /* setup SRIO port liodns */
  128. set_srio_liodn(srio_liodn_tbl, srio_liodn_tbl_sz);
  129. /* setup SEC block liodn bases & offsets if we have one */
  130. if (IS_E_PROCESSOR(get_svr())) {
  131. set_liodn(sec_liodn_tbl, sec_liodn_tbl_sz);
  132. setup_sec_liodn_base();
  133. }
  134. /* setup FMAN block(s) liodn bases & offsets if we have one */
  135. #ifdef CONFIG_SYS_DPAA_FMAN
  136. set_liodn(fman1_liodn_tbl, fman1_liodn_tbl_sz);
  137. setup_fman_liodn_base(FSL_HW_PORTAL_FMAN1, fman1_liodn_tbl,
  138. fman1_liodn_tbl_sz);
  139. #if (CONFIG_SYS_NUM_FMAN == 2)
  140. set_liodn(fman2_liodn_tbl, fman2_liodn_tbl_sz);
  141. setup_fman_liodn_base(FSL_HW_PORTAL_FMAN2, fman2_liodn_tbl,
  142. fman2_liodn_tbl_sz);
  143. #endif
  144. #endif
  145. /* setup PME liodn base */
  146. setup_pme_liodn_base();
  147. #ifdef CONFIG_SYS_FSL_RAID_ENGINE
  148. /* raid engine ccr addr code for liodn */
  149. set_liodn(raide_liodn_tbl, raide_liodn_tbl_sz);
  150. setup_raide_liodn_base();
  151. #endif
  152. }
  153. static void fdt_fixup_srio_liodn(void *blob, struct srio_liodn_id_table *tbl)
  154. {
  155. int i, srio_off;
  156. /* search for srio node, if doesn't exist just return - nothing todo */
  157. srio_off = fdt_node_offset_by_compatible(blob, -1, "fsl,srio");
  158. if (srio_off < 0)
  159. return ;
  160. for (i = 0; i < srio_liodn_tbl_sz; i++) {
  161. int off, portid = tbl[i].portid;
  162. off = fdt_node_offset_by_prop_value(blob, srio_off,
  163. "cell-index", &portid, 4);
  164. if (off >= 0) {
  165. off = fdt_setprop(blob, off, "fsl,liodn",
  166. &tbl[i].id[0],
  167. sizeof(u32) * tbl[i].num_ids);
  168. if (off > 0)
  169. printf("WARNING unable to set fsl,liodn for "
  170. "fsl,srio port %d: %s\n",
  171. portid, fdt_strerror(off));
  172. } else {
  173. debug("WARNING: couldn't set fsl,liodn for srio: %s.\n",
  174. fdt_strerror(off));
  175. }
  176. }
  177. }
  178. static void fdt_fixup_liodn_tbl(void *blob, struct liodn_id_table *tbl, int sz)
  179. {
  180. int i;
  181. for (i = 0; i < sz; i++) {
  182. int off;
  183. if (tbl[i].compat == NULL)
  184. continue;
  185. off = fdt_node_offset_by_compat_reg(blob,
  186. tbl[i].compat, tbl[i].compat_offset);
  187. if (off >= 0) {
  188. off = fdt_setprop(blob, off, "fsl,liodn",
  189. &tbl[i].id[0],
  190. sizeof(u32) * tbl[i].num_ids);
  191. if (off > 0)
  192. printf("WARNING unable to set fsl,liodn for "
  193. "%s: %s\n",
  194. tbl[i].compat, fdt_strerror(off));
  195. } else {
  196. debug("WARNING: could not set fsl,liodn for %s: %s.\n",
  197. tbl[i].compat, fdt_strerror(off));
  198. }
  199. }
  200. }
  201. void fdt_fixup_liodn(void *blob)
  202. {
  203. fdt_fixup_srio_liodn(blob, srio_liodn_tbl);
  204. fdt_fixup_liodn_tbl(blob, liodn_tbl, liodn_tbl_sz);
  205. #ifdef CONFIG_SYS_DPAA_FMAN
  206. fdt_fixup_liodn_tbl(blob, fman1_liodn_tbl, fman1_liodn_tbl_sz);
  207. #if (CONFIG_SYS_NUM_FMAN == 2)
  208. fdt_fixup_liodn_tbl(blob, fman2_liodn_tbl, fman2_liodn_tbl_sz);
  209. #endif
  210. #endif
  211. fdt_fixup_liodn_tbl(blob, sec_liodn_tbl, sec_liodn_tbl_sz);
  212. #ifdef CONFIG_SYS_FSL_RAID_ENGINE
  213. fdt_fixup_liodn_tbl(blob, raide_liodn_tbl, raide_liodn_tbl_sz);
  214. #endif
  215. }