fsl_portals.c 8.4 KB

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