portals.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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. char handle[64], *p;
  113. strncpy(handle, name, sizeof(handle));
  114. p = strchr(handle, '@');
  115. if (!strncmp(name, "fman", 4)) {
  116. *p = *(p + 1);
  117. p++;
  118. }
  119. *p = '\0';
  120. dev_off = fdt_path_offset(blob, handle);
  121. /* skip this node if alias is not found */
  122. if (dev_off == -FDT_ERR_BADPATH)
  123. return 0;
  124. if (dev_off < 0)
  125. return dev_off;
  126. if (childoff <= 0)
  127. childoff = fdt_add_subnode(blob, off, name);
  128. /* need to update the dev_off after adding a subnode */
  129. dev_off = fdt_path_offset(blob, handle);
  130. if (dev_off < 0)
  131. return dev_off;
  132. if (childoff > 0) {
  133. dev_handle = fdt_get_phandle(blob, dev_off);
  134. if (dev_handle <= 0) {
  135. dev_handle = fdt_alloc_phandle(blob);
  136. ret = fdt_set_phandle(blob, dev_off,
  137. dev_handle);
  138. if (ret < 0)
  139. return ret;
  140. }
  141. ret = fdt_setprop(blob, childoff, "dev-handle",
  142. &dev_handle, sizeof(dev_handle));
  143. if (ret < 0)
  144. return ret;
  145. #ifdef CONFIG_FSL_CORENET
  146. num = get_dpaa_liodn(dev, &liodns[0], id);
  147. ret = fdt_setprop(blob, childoff, "fsl,liodn",
  148. &liodns[0], sizeof(u32) * num);
  149. if (!strncmp(name, "pme", 3)) {
  150. u32 pme_rev1, pme_rev2;
  151. ccsr_pme_t *pme_regs =
  152. (void *)CONFIG_SYS_FSL_CORENET_PME_ADDR;
  153. pme_rev1 = in_be32(&pme_regs->pm_ip_rev_1);
  154. pme_rev2 = in_be32(&pme_regs->pm_ip_rev_2);
  155. ret = fdt_setprop(blob, childoff,
  156. "fsl,pme-rev1", &pme_rev1, sizeof(u32));
  157. if (ret < 0)
  158. return ret;
  159. ret = fdt_setprop(blob, childoff,
  160. "fsl,pme-rev2", &pme_rev2, sizeof(u32));
  161. }
  162. #endif
  163. } else {
  164. return childoff;
  165. }
  166. } else {
  167. if (childoff > 0)
  168. ret = fdt_del_node(blob, childoff);
  169. }
  170. return ret;
  171. }
  172. void fdt_fixup_qportals(void *blob)
  173. {
  174. int off, err;
  175. unsigned int maj, min;
  176. unsigned int ip_cfg;
  177. ccsr_qman_t *qman = (void *)CONFIG_SYS_FSL_QMAN_ADDR;
  178. u32 rev_1 = in_be32(&qman->ip_rev_1);
  179. u32 rev_2 = in_be32(&qman->ip_rev_2);
  180. char compat[64];
  181. int compat_len;
  182. maj = (rev_1 >> 8) & 0xff;
  183. min = rev_1 & 0xff;
  184. ip_cfg = rev_2 & 0xff;
  185. compat_len = sprintf(compat, "fsl,qman-portal-%u.%u.%u",
  186. maj, min, ip_cfg) + 1;
  187. compat_len += sprintf(compat + compat_len, "fsl,qman-portal") + 1;
  188. off = fdt_node_offset_by_compatible(blob, -1, "fsl,qman-portal");
  189. while (off != -FDT_ERR_NOTFOUND) {
  190. #ifdef CONFIG_FSL_CORENET
  191. u32 liodns[2];
  192. #endif
  193. const int *ci = fdt_getprop(blob, off, "cell-index", NULL);
  194. int i = *ci;
  195. #ifdef CONFIG_SYS_DPAA_FMAN
  196. int j;
  197. #endif
  198. err = fdt_setprop(blob, off, "compatible", compat, compat_len);
  199. if (err < 0)
  200. goto err;
  201. #ifdef CONFIG_FSL_CORENET
  202. liodns[0] = qp_info[i].dliodn;
  203. liodns[1] = qp_info[i].fliodn;
  204. err = fdt_setprop(blob, off, "fsl,liodn",
  205. &liodns, sizeof(u32) * 2);
  206. if (err < 0)
  207. goto err;
  208. #endif
  209. i++;
  210. err = fdt_qportal(blob, off, i, "crypto@0", FSL_HW_PORTAL_SEC,
  211. IS_E_PROCESSOR(get_svr()));
  212. if (err < 0)
  213. goto err;
  214. #ifdef CONFIG_FSL_CORENET
  215. #ifdef CONFIG_SYS_DPAA_PME
  216. err = fdt_qportal(blob, off, i, "pme@0", FSL_HW_PORTAL_PME, 1);
  217. if (err < 0)
  218. goto err;
  219. #else
  220. fdt_qportal(blob, off, i, "pme@0", FSL_HW_PORTAL_PME, 0);
  221. #endif
  222. #endif
  223. #ifdef CONFIG_SYS_DPAA_FMAN
  224. for (j = 0; j < CONFIG_SYS_NUM_FMAN; j++) {
  225. char name[] = "fman@0";
  226. name[sizeof(name) - 2] = '0' + j;
  227. err = fdt_qportal(blob, off, i, name,
  228. FSL_HW_PORTAL_FMAN1 + j, 1);
  229. if (err < 0)
  230. goto err;
  231. }
  232. #endif
  233. #ifdef CONFIG_SYS_DPAA_RMAN
  234. err = fdt_qportal(blob, off, i, "rman@0",
  235. FSL_HW_PORTAL_RMAN, 1);
  236. if (err < 0)
  237. goto err;
  238. #endif
  239. err:
  240. if (err < 0) {
  241. printf("ERROR: unable to create props for %s: %s\n",
  242. fdt_get_name(blob, off, NULL), fdt_strerror(err));
  243. return;
  244. }
  245. off = fdt_node_offset_by_compatible(blob, off, "fsl,qman-portal");
  246. }
  247. }
  248. void fdt_fixup_bportals(void *blob)
  249. {
  250. int off, err;
  251. unsigned int maj, min;
  252. unsigned int ip_cfg;
  253. ccsr_bman_t *bman = (void *)CONFIG_SYS_FSL_BMAN_ADDR;
  254. u32 rev_1 = in_be32(&bman->ip_rev_1);
  255. u32 rev_2 = in_be32(&bman->ip_rev_2);
  256. char compat[64];
  257. int compat_len;
  258. maj = (rev_1 >> 8) & 0xff;
  259. min = rev_1 & 0xff;
  260. ip_cfg = rev_2 & 0xff;
  261. compat_len = sprintf(compat, "fsl,bman-portal-%u.%u.%u",
  262. maj, min, ip_cfg) + 1;
  263. compat_len += sprintf(compat + compat_len, "fsl,bman-portal") + 1;
  264. off = fdt_node_offset_by_compatible(blob, -1, "fsl,bman-portal");
  265. while (off != -FDT_ERR_NOTFOUND) {
  266. err = fdt_setprop(blob, off, "compatible", compat, compat_len);
  267. if (err < 0) {
  268. printf("ERROR: unable to create props for %s: %s\n",
  269. fdt_get_name(blob, off, NULL),
  270. fdt_strerror(err));
  271. return;
  272. }
  273. off = fdt_node_offset_by_compatible(blob, off, "fsl,bman-portal");
  274. }
  275. }