fsl_portals.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright 2008-2011 Freescale Semiconductor, Inc.
  4. * Copyright 2017 NXP
  5. */
  6. #include <common.h>
  7. #include <linux/libfdt.h>
  8. #include <fdt_support.h>
  9. #include <asm/processor.h>
  10. #include <asm/io.h>
  11. #ifdef CONFIG_PPC
  12. #include <asm/fsl_portals.h>
  13. #include <asm/fsl_liodn.h>
  14. #endif
  15. #include <fsl_qbman.h>
  16. #define MAX_BPORTALS (CONFIG_SYS_BMAN_CINH_SIZE / CONFIG_SYS_BMAN_SP_CINH_SIZE)
  17. #define MAX_QPORTALS (CONFIG_SYS_QMAN_CINH_SIZE / CONFIG_SYS_QMAN_SP_CINH_SIZE)
  18. void setup_qbman_portals(void)
  19. {
  20. void __iomem *bpaddr = (void *)CONFIG_SYS_BMAN_CINH_BASE +
  21. CONFIG_SYS_BMAN_SWP_ISDR_REG;
  22. void __iomem *qpaddr = (void *)CONFIG_SYS_QMAN_CINH_BASE +
  23. CONFIG_SYS_QMAN_SWP_ISDR_REG;
  24. #ifdef CONFIG_PPC
  25. struct ccsr_qman *qman = (void *)CONFIG_SYS_FSL_QMAN_ADDR;
  26. /* Set the Qman initiator BAR to match the LAW (for DQRR stashing) */
  27. #ifdef CONFIG_PHYS_64BIT
  28. out_be32(&qman->qcsp_bare, (u32)(CONFIG_SYS_QMAN_MEM_PHYS >> 32));
  29. #endif
  30. out_be32(&qman->qcsp_bar, (u32)CONFIG_SYS_QMAN_MEM_PHYS);
  31. #endif
  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. /* Change default state of BMan ISDR portals to all 1s */
  46. inhibit_portals(bpaddr, CONFIG_SYS_BMAN_NUM_PORTALS, MAX_BPORTALS,
  47. CONFIG_SYS_BMAN_SP_CINH_SIZE);
  48. inhibit_portals(qpaddr, CONFIG_SYS_QMAN_NUM_PORTALS, MAX_QPORTALS,
  49. CONFIG_SYS_QMAN_SP_CINH_SIZE);
  50. }
  51. void inhibit_portals(void __iomem *addr, int max_portals,
  52. int arch_max_portals, int portal_cinh_size)
  53. {
  54. u32 val;
  55. int i;
  56. /* arch_max_portals is the maximum based on memory size. This includes
  57. * the reserved memory in the SoC. max_portals the number of physical
  58. * portals in the SoC
  59. */
  60. if (max_portals > arch_max_portals) {
  61. printf("ERROR: portal config error\n");
  62. max_portals = arch_max_portals;
  63. }
  64. for (i = 0; i < max_portals; i++) {
  65. out_be32(addr, -1);
  66. val = in_be32(addr);
  67. if (!val) {
  68. printf("ERROR: Stopped after %d portals\n", i);
  69. return;
  70. }
  71. addr += portal_cinh_size;
  72. }
  73. debug("Cleared %d portals\n", i);
  74. }
  75. #ifdef CONFIG_PPC
  76. static int fdt_qportal(void *blob, int off, int id, char *name,
  77. enum fsl_dpaa_dev dev, int create)
  78. {
  79. int childoff, dev_off, ret = 0;
  80. u32 dev_handle;
  81. #ifdef CONFIG_FSL_CORENET
  82. int num;
  83. u32 liodns[2];
  84. #endif
  85. childoff = fdt_subnode_offset(blob, off, name);
  86. if (create) {
  87. char handle[64], *p;
  88. strncpy(handle, name, sizeof(handle));
  89. p = strchr(handle, '@');
  90. if (!strncmp(name, "fman", 4)) {
  91. *p = *(p + 1);
  92. p++;
  93. }
  94. *p = '\0';
  95. dev_off = fdt_path_offset(blob, handle);
  96. /* skip this node if alias is not found */
  97. if (dev_off == -FDT_ERR_BADPATH)
  98. return 0;
  99. if (dev_off < 0)
  100. return dev_off;
  101. if (childoff <= 0)
  102. childoff = fdt_add_subnode(blob, off, name);
  103. /* need to update the dev_off after adding a subnode */
  104. dev_off = fdt_path_offset(blob, handle);
  105. if (dev_off < 0)
  106. return dev_off;
  107. if (childoff > 0) {
  108. dev_handle = fdt_get_phandle(blob, dev_off);
  109. if (dev_handle <= 0) {
  110. dev_handle = fdt_alloc_phandle(blob);
  111. ret = fdt_set_phandle(blob, dev_off,
  112. dev_handle);
  113. if (ret < 0)
  114. return ret;
  115. }
  116. ret = fdt_setprop(blob, childoff, "dev-handle",
  117. &dev_handle, sizeof(dev_handle));
  118. if (ret < 0)
  119. return ret;
  120. #ifdef CONFIG_FSL_CORENET
  121. num = get_dpaa_liodn(dev, &liodns[0], id);
  122. ret = fdt_setprop(blob, childoff, "fsl,liodn",
  123. &liodns[0], sizeof(u32) * num);
  124. if (!strncmp(name, "pme", 3)) {
  125. u32 pme_rev1, pme_rev2;
  126. ccsr_pme_t *pme_regs =
  127. (void *)CONFIG_SYS_FSL_CORENET_PME_ADDR;
  128. pme_rev1 = in_be32(&pme_regs->pm_ip_rev_1);
  129. pme_rev2 = in_be32(&pme_regs->pm_ip_rev_2);
  130. ret = fdt_setprop(blob, childoff,
  131. "fsl,pme-rev1", &pme_rev1,
  132. sizeof(u32));
  133. if (ret < 0)
  134. return ret;
  135. ret = fdt_setprop(blob, childoff,
  136. "fsl,pme-rev2", &pme_rev2,
  137. sizeof(u32));
  138. }
  139. #endif
  140. } else {
  141. return childoff;
  142. }
  143. } else {
  144. if (childoff > 0)
  145. ret = fdt_del_node(blob, childoff);
  146. }
  147. return ret;
  148. }
  149. #endif /* CONFIG_PPC */
  150. void fdt_fixup_qportals(void *blob)
  151. {
  152. int off, err;
  153. unsigned int maj, min;
  154. unsigned int ip_cfg;
  155. struct ccsr_qman *qman = (void *)CONFIG_SYS_FSL_QMAN_ADDR;
  156. u32 rev_1 = in_be32(&qman->ip_rev_1);
  157. u32 rev_2 = in_be32(&qman->ip_rev_2);
  158. char compat[64];
  159. int compat_len;
  160. maj = (rev_1 >> 8) & 0xff;
  161. min = rev_1 & 0xff;
  162. ip_cfg = rev_2 & 0xff;
  163. compat_len = sprintf(compat, "fsl,qman-portal-%u.%u.%u",
  164. maj, min, ip_cfg) + 1;
  165. compat_len += sprintf(compat + compat_len, "fsl,qman-portal") + 1;
  166. off = fdt_node_offset_by_compatible(blob, -1, "fsl,qman-portal");
  167. while (off != -FDT_ERR_NOTFOUND) {
  168. #ifdef CONFIG_PPC
  169. #ifdef CONFIG_FSL_CORENET
  170. u32 liodns[2];
  171. #endif
  172. const int *ci = fdt_getprop(blob, off, "cell-index", &err);
  173. int i;
  174. if (!ci)
  175. goto err;
  176. i = *ci;
  177. #ifdef CONFIG_SYS_DPAA_FMAN
  178. int j;
  179. #endif
  180. #endif /* CONFIG_PPC */
  181. err = fdt_setprop(blob, off, "compatible", compat, compat_len);
  182. if (err < 0)
  183. goto err;
  184. #ifdef CONFIG_PPC
  185. #ifdef CONFIG_FSL_CORENET
  186. liodns[0] = qp_info[i].dliodn;
  187. liodns[1] = qp_info[i].fliodn;
  188. err = fdt_setprop(blob, off, "fsl,liodn",
  189. &liodns, sizeof(u32) * 2);
  190. if (err < 0)
  191. goto err;
  192. #endif
  193. i++;
  194. err = fdt_qportal(blob, off, i, "crypto@0", FSL_HW_PORTAL_SEC,
  195. IS_E_PROCESSOR(get_svr()));
  196. if (err < 0)
  197. goto err;
  198. #ifdef CONFIG_FSL_CORENET
  199. #ifdef CONFIG_SYS_DPAA_PME
  200. err = fdt_qportal(blob, off, i, "pme@0", FSL_HW_PORTAL_PME, 1);
  201. if (err < 0)
  202. goto err;
  203. #else
  204. fdt_qportal(blob, off, i, "pme@0", FSL_HW_PORTAL_PME, 0);
  205. #endif
  206. #endif
  207. #ifdef CONFIG_SYS_DPAA_FMAN
  208. for (j = 0; j < CONFIG_SYS_NUM_FMAN; j++) {
  209. char name[] = "fman@0";
  210. name[sizeof(name) - 2] = '0' + j;
  211. err = fdt_qportal(blob, off, i, name,
  212. FSL_HW_PORTAL_FMAN1 + j, 1);
  213. if (err < 0)
  214. goto err;
  215. }
  216. #endif
  217. #ifdef CONFIG_SYS_DPAA_RMAN
  218. err = fdt_qportal(blob, off, i, "rman@0",
  219. FSL_HW_PORTAL_RMAN, 1);
  220. if (err < 0)
  221. goto err;
  222. #endif
  223. #endif /* CONFIG_PPC */
  224. err:
  225. if (err < 0) {
  226. printf("ERROR: unable to create props for %s: %s\n",
  227. fdt_get_name(blob, off, NULL),
  228. fdt_strerror(err));
  229. return;
  230. }
  231. off = fdt_node_offset_by_compatible(blob, off,
  232. "fsl,qman-portal");
  233. }
  234. }
  235. void fdt_fixup_bportals(void *blob)
  236. {
  237. int off, err;
  238. unsigned int maj, min;
  239. unsigned int ip_cfg;
  240. struct ccsr_bman *bman = (void *)CONFIG_SYS_FSL_BMAN_ADDR;
  241. u32 rev_1 = in_be32(&bman->ip_rev_1);
  242. u32 rev_2 = in_be32(&bman->ip_rev_2);
  243. char compat[64];
  244. int compat_len;
  245. maj = (rev_1 >> 8) & 0xff;
  246. min = rev_1 & 0xff;
  247. ip_cfg = rev_2 & 0xff;
  248. compat_len = sprintf(compat, "fsl,bman-portal-%u.%u.%u",
  249. maj, min, ip_cfg) + 1;
  250. compat_len += sprintf(compat + compat_len, "fsl,bman-portal") + 1;
  251. off = fdt_node_offset_by_compatible(blob, -1, "fsl,bman-portal");
  252. while (off != -FDT_ERR_NOTFOUND) {
  253. err = fdt_setprop(blob, off, "compatible", compat, compat_len);
  254. if (err < 0) {
  255. printf("ERROR: unable to create props for %s: %s\n",
  256. fdt_get_name(blob, off, NULL),
  257. fdt_strerror(err));
  258. return;
  259. }
  260. off = fdt_node_offset_by_compatible(blob, off,
  261. "fsl,bman-portal");
  262. }
  263. }