portals.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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/processor.h>
  26. #include <asm/io.h>
  27. #include <asm/fsl_portals.h>
  28. #include <asm/fsl_liodn.h>
  29. static ccsr_qman_t *qman = (void *)CONFIG_SYS_FSL_QMAN_ADDR;
  30. static ccsr_bman_t *bman = (void *)CONFIG_SYS_FSL_BMAN_ADDR;
  31. void setup_portals(void)
  32. {
  33. #ifdef CONFIG_FSL_CORENET
  34. int i;
  35. for (i = 0; i < CONFIG_SYS_QMAN_NUM_PORTALS; i++) {
  36. u8 sdest = qp_info[i].sdest;
  37. u16 fliodn = qp_info[i].fliodn;
  38. u16 dliodn = qp_info[i].dliodn;
  39. u16 liodn_off = qp_info[i].liodn_offset;
  40. out_be32(&qman->qcsp[i].qcsp_lio_cfg, (liodn_off << 16) |
  41. dliodn);
  42. /* set frame liodn */
  43. out_be32(&qman->qcsp[i].qcsp_io_cfg, (sdest << 16) | fliodn);
  44. }
  45. #endif
  46. /* Set the Qman initiator BAR to match the LAW (for DQRR stashing) */
  47. #ifdef CONFIG_PHYS_64BIT
  48. out_be32(&qman->qcsp_bare, (u32)(CONFIG_SYS_QMAN_MEM_PHYS >> 32));
  49. #endif
  50. out_be32(&qman->qcsp_bar, (u32)CONFIG_SYS_QMAN_MEM_PHYS);
  51. }
  52. /* Update portal containter to match LAW setup of portal in phy map */
  53. void fdt_portal(void *blob, const char *compat, const char *container,
  54. u64 addr, u32 size)
  55. {
  56. int off;
  57. off = fdt_node_offset_by_compatible(blob, -1, compat);
  58. if (off < 0)
  59. return ;
  60. off = fdt_parent_offset(blob, off);
  61. /* if non-zero assume we have a container */
  62. if (off > 0) {
  63. char buf[60];
  64. const char *p, *name;
  65. u32 *range;
  66. int len;
  67. /* fixup ranges */
  68. range = fdt_getprop_w(blob, off, "ranges", &len);
  69. if (range == NULL) {
  70. printf("ERROR: container for %s has no ranges", compat);
  71. return ;
  72. }
  73. range[0] = 0;
  74. if (len == 16) {
  75. range[1] = addr >> 32;
  76. range[2] = addr & 0xffffffff;
  77. range[3] = size;
  78. } else {
  79. range[1] = addr & 0xffffffff;
  80. range[2] = size;
  81. }
  82. fdt_setprop_inplace(blob, off, "ranges", range, len);
  83. /* fixup the name */
  84. name = fdt_get_name(blob, off, &len);
  85. p = memchr(name, '@', len);
  86. if (p)
  87. len = p - name;
  88. /* if we are given a container name check it
  89. * against what we found, if it doesnt match exit out */
  90. if (container && (memcmp(container, name, len))) {
  91. printf("WARNING: container names didn't match %s %s\n",
  92. container, name);
  93. return ;
  94. }
  95. memcpy(&buf, name, len);
  96. len += sprintf(&buf[len], "@%llx", addr);
  97. fdt_set_name(blob, off, buf);
  98. return ;
  99. }
  100. printf("ERROR: %s isn't in a container. Not supported\n", compat);
  101. }
  102. static int fdt_qportal(void *blob, int off, int id, char *name,
  103. enum fsl_dpaa_dev dev, int create)
  104. {
  105. int childoff, dev_off, ret = 0;
  106. uint32_t dev_handle;
  107. #ifdef CONFIG_FSL_CORENET
  108. int num;
  109. u32 liodns[2];
  110. #endif
  111. childoff = fdt_subnode_offset(blob, off, name);
  112. if (create) {
  113. if (childoff <= 0)
  114. childoff = fdt_add_subnode(blob, off, name);
  115. if (childoff > 0) {
  116. char handle[64], *p;
  117. strncpy(handle, name, sizeof(handle));
  118. p = strchr(handle, '@');
  119. if (!strncmp(name, "fman", 4)) {
  120. *p = *(p + 1);
  121. p++;
  122. }
  123. *p = '\0';
  124. dev_off = fdt_path_offset(blob, handle);
  125. if (dev_off < 0)
  126. return dev_off;
  127. dev_handle = fdt_get_phandle(blob, dev_off);
  128. if (dev_handle <= 0) {
  129. dev_handle = fdt_alloc_phandle(blob);
  130. ret = fdt_set_phandle(blob, dev_off,
  131. dev_handle);
  132. if (ret < 0)
  133. return ret;
  134. }
  135. ret = fdt_setprop(blob, childoff, "dev-handle",
  136. &dev_handle, sizeof(dev_handle));
  137. if (ret < 0)
  138. return ret;
  139. #ifdef CONFIG_FSL_CORENET
  140. num = get_dpaa_liodn(dev, &liodns[0], id);
  141. ret = fdt_setprop(blob, childoff, "fsl,liodn",
  142. &liodns[0], sizeof(u32) * num);
  143. #endif
  144. } else {
  145. return childoff;
  146. }
  147. } else {
  148. if (childoff > 0)
  149. ret = fdt_del_node(blob, childoff);
  150. }
  151. return ret;
  152. }
  153. void fdt_fixup_qportals(void *blob)
  154. {
  155. int off, err;
  156. unsigned int maj, min;
  157. u32 rev_1 = in_be32(&qman->ip_rev_1);
  158. char compat[64];
  159. int compat_len;
  160. maj = (rev_1 >> 8) & 0xff;
  161. min = rev_1 & 0xff;
  162. compat_len = sprintf(compat, "fsl,qman-portal-%u.%u", maj, min) + 1;
  163. compat_len += sprintf(compat + compat_len, "fsl,qman-portal") + 1;
  164. off = fdt_node_offset_by_compatible(blob, -1, "fsl,qman-portal");
  165. while (off != -FDT_ERR_NOTFOUND) {
  166. #ifdef CONFIG_FSL_CORENET
  167. u32 liodns[2];
  168. #endif
  169. const int *ci = fdt_getprop(blob, off, "cell-index", NULL);
  170. int i = *ci;
  171. #ifdef CONFIG_SYS_DPAA_FMAN
  172. int j;
  173. #endif
  174. err = fdt_setprop(blob, off, "compatible", compat, compat_len);
  175. if (err < 0)
  176. goto err;
  177. #ifdef CONFIG_FSL_CORENET
  178. liodns[0] = qp_info[i].dliodn;
  179. liodns[1] = qp_info[i].fliodn;
  180. err = fdt_setprop(blob, off, "fsl,liodn",
  181. &liodns, sizeof(u32) * 2);
  182. if (err < 0)
  183. goto err;
  184. #endif
  185. i++;
  186. err = fdt_qportal(blob, off, i, "crypto@0", FSL_HW_PORTAL_SEC,
  187. IS_E_PROCESSOR(get_svr()));
  188. if (err < 0)
  189. goto err;
  190. #ifdef CONFIG_FSL_CORENET
  191. #ifdef CONFIG_SYS_DPAA_PME
  192. err = fdt_qportal(blob, off, i, "pme@0", FSL_HW_PORTAL_PME, 1);
  193. if (err < 0)
  194. goto err;
  195. #else
  196. fdt_qportal(blob, off, i, "pme@0", FSL_HW_PORTAL_PME, 0);
  197. #endif
  198. #endif
  199. #ifdef CONFIG_SYS_DPAA_FMAN
  200. for (j = 0; j < CONFIG_SYS_NUM_FMAN; j++) {
  201. char name[] = "fman@0";
  202. name[sizeof(name) - 2] = '0' + j;
  203. err = fdt_qportal(blob, off, i, name,
  204. FSL_HW_PORTAL_FMAN1 + j, 1);
  205. if (err < 0)
  206. goto err;
  207. }
  208. #endif
  209. #ifdef CONFIG_SYS_DPAA_RMAN
  210. err = fdt_qportal(blob, off, i, "rman@0",
  211. FSL_HW_PORTAL_RMAN, 1);
  212. if (err < 0)
  213. goto err;
  214. #endif
  215. err:
  216. if (err < 0) {
  217. printf("ERROR: unable to create props for %s: %s\n",
  218. fdt_get_name(blob, off, NULL), fdt_strerror(err));
  219. return;
  220. }
  221. off = fdt_node_offset_by_compatible(blob, off, "fsl,qman-portal");
  222. }
  223. }
  224. void fdt_fixup_bportals(void *blob)
  225. {
  226. int off, err;
  227. unsigned int maj, min;
  228. u32 rev_1 = in_be32(&bman->ip_rev_1);
  229. char compat[64];
  230. int compat_len;
  231. maj = (rev_1 >> 8) & 0xff;
  232. min = rev_1 & 0xff;
  233. compat_len = sprintf(compat, "fsl,bman-portal-%u.%u", maj, min) + 1;
  234. compat_len += sprintf(compat + compat_len, "fsl,bman-portal") + 1;
  235. off = fdt_node_offset_by_compatible(blob, -1, "fsl,bman-portal");
  236. while (off != -FDT_ERR_NOTFOUND) {
  237. err = fdt_setprop(blob, off, "compatible", compat, compat_len);
  238. if (err < 0) {
  239. printf("ERROR: unable to create props for %s: %s\n",
  240. fdt_get_name(blob, off, NULL),
  241. fdt_strerror(err));
  242. return;
  243. }
  244. off = fdt_node_offset_by_compatible(blob, off, "fsl,bman-portal");
  245. }
  246. }