fsl_portals.c 8.3 KB

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