portals.c 7.6 KB

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