portals.c 5.8 KB

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