liodn.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. /*
  2. * Copyright 2008-2011 Freescale Semiconductor, Inc.
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <libfdt.h>
  8. #include <fdt_support.h>
  9. #include <asm/immap_85xx.h>
  10. #include <asm/io.h>
  11. #include <asm/processor.h>
  12. #include <asm/fsl_portals.h>
  13. #include <asm/fsl_liodn.h>
  14. int get_dpaa_liodn(enum fsl_dpaa_dev dpaa_dev, u32 *liodns, int liodn_offset)
  15. {
  16. liodns[0] = liodn_bases[dpaa_dev].id[0] + liodn_offset;
  17. if (liodn_bases[dpaa_dev].num_ids == 2)
  18. liodns[1] = liodn_bases[dpaa_dev].id[1] + liodn_offset;
  19. return liodn_bases[dpaa_dev].num_ids;
  20. }
  21. #ifdef CONFIG_SYS_SRIO
  22. static void set_srio_liodn(struct srio_liodn_id_table *tbl, int size)
  23. {
  24. int i;
  25. for (i = 0; i < size; i++) {
  26. unsigned long reg_off = tbl[i].reg_offset[0];
  27. out_be32((u32 *)reg_off, tbl[i].id[0]);
  28. if (tbl[i].num_ids == 2) {
  29. reg_off = tbl[i].reg_offset[1];
  30. out_be32((u32 *)reg_off, tbl[i].id[1]);
  31. }
  32. }
  33. }
  34. #endif
  35. static void set_liodn(struct liodn_id_table *tbl, int size)
  36. {
  37. int i;
  38. for (i = 0; i < size; i++) {
  39. u32 liodn;
  40. if (tbl[i].num_ids == 2) {
  41. liodn = (tbl[i].id[0] << 16) | tbl[i].id[1];
  42. } else {
  43. liodn = tbl[i].id[0];
  44. }
  45. out_be32((volatile u32 *)(tbl[i].reg_offset), liodn);
  46. }
  47. }
  48. static void setup_sec_liodn_base(void)
  49. {
  50. ccsr_sec_t *sec = (void *)CONFIG_SYS_FSL_SEC_ADDR;
  51. u32 base;
  52. if (!IS_E_PROCESSOR(get_svr()))
  53. return;
  54. /* QILCR[QSLOM] */
  55. out_be32(&sec->qilcr_ms, 0x3ff<<16);
  56. base = (liodn_bases[FSL_HW_PORTAL_SEC].id[0] << 16) |
  57. liodn_bases[FSL_HW_PORTAL_SEC].id[1];
  58. out_be32(&sec->qilcr_ls, base);
  59. }
  60. #ifdef CONFIG_SYS_DPAA_FMAN
  61. static void setup_fman_liodn_base(enum fsl_dpaa_dev dev,
  62. struct liodn_id_table *tbl, int size)
  63. {
  64. int i;
  65. ccsr_fman_t *fm;
  66. u32 base;
  67. switch(dev) {
  68. case FSL_HW_PORTAL_FMAN1:
  69. fm = (void *)CONFIG_SYS_FSL_FM1_ADDR;
  70. break;
  71. #if (CONFIG_SYS_NUM_FMAN == 2)
  72. case FSL_HW_PORTAL_FMAN2:
  73. fm = (void *)CONFIG_SYS_FSL_FM2_ADDR;
  74. break;
  75. #endif
  76. default:
  77. printf("Error: Invalid device type to %s\n", __FUNCTION__);
  78. return ;
  79. }
  80. base = (liodn_bases[dev].id[0] << 16) | liodn_bases[dev].id[0];
  81. /* setup all bases the same */
  82. for (i = 0; i < 32; i++) {
  83. out_be32(&fm->fm_dma.fmdmplr[i], base);
  84. }
  85. /* update tbl to ... */
  86. for (i = 0; i < size; i++)
  87. tbl[i].id[0] += liodn_bases[dev].id[0];
  88. }
  89. #endif
  90. static void setup_pme_liodn_base(void)
  91. {
  92. #ifdef CONFIG_SYS_DPAA_PME
  93. ccsr_pme_t *pme = (void *)CONFIG_SYS_FSL_CORENET_PME_ADDR;
  94. u32 base = (liodn_bases[FSL_HW_PORTAL_PME].id[0] << 16) |
  95. liodn_bases[FSL_HW_PORTAL_PME].id[1];
  96. out_be32(&pme->liodnbr, base);
  97. #endif
  98. }
  99. #ifdef CONFIG_SYS_FSL_RAID_ENGINE
  100. static void setup_raide_liodn_base(void)
  101. {
  102. struct ccsr_raide *raide = (void *)CONFIG_SYS_FSL_RAID_ENGINE_ADDR;
  103. /* setup raid engine liodn base for data/desc ; both set to 47 */
  104. u32 base = (liodn_bases[FSL_HW_PORTAL_RAID_ENGINE].id[0] << 16) |
  105. liodn_bases[FSL_HW_PORTAL_RAID_ENGINE].id[0];
  106. out_be32(&raide->liodnbr, base);
  107. }
  108. #endif
  109. #ifdef CONFIG_SYS_DPAA_RMAN
  110. static void set_rman_liodn(struct liodn_id_table *tbl, int size)
  111. {
  112. int i;
  113. struct ccsr_rman *rman = (void *)CONFIG_SYS_FSL_CORENET_RMAN_ADDR;
  114. for (i = 0; i < size; i++) {
  115. /* write the RMan block number */
  116. out_be32(&rman->mmitar, i);
  117. /* write the liodn offset corresponding to the block */
  118. out_be32((u32 *)(tbl[i].reg_offset), tbl[i].id[0]);
  119. }
  120. }
  121. static void setup_rman_liodn_base(struct liodn_id_table *tbl, int size)
  122. {
  123. int i;
  124. struct ccsr_rman *rman = (void *)CONFIG_SYS_FSL_CORENET_RMAN_ADDR;
  125. u32 base = liodn_bases[FSL_HW_PORTAL_RMAN].id[0];
  126. out_be32(&rman->mmliodnbr, base);
  127. /* update liodn offset */
  128. for (i = 0; i < size; i++)
  129. tbl[i].id[0] += base;
  130. }
  131. #endif
  132. void set_liodns(void)
  133. {
  134. /* setup general liodn offsets */
  135. set_liodn(liodn_tbl, liodn_tbl_sz);
  136. #ifdef CONFIG_SYS_SRIO
  137. /* setup SRIO port liodns */
  138. set_srio_liodn(srio_liodn_tbl, srio_liodn_tbl_sz);
  139. #endif
  140. /* setup SEC block liodn bases & offsets if we have one */
  141. if (IS_E_PROCESSOR(get_svr())) {
  142. set_liodn(sec_liodn_tbl, sec_liodn_tbl_sz);
  143. setup_sec_liodn_base();
  144. }
  145. /* setup FMAN block(s) liodn bases & offsets if we have one */
  146. #ifdef CONFIG_SYS_DPAA_FMAN
  147. set_liodn(fman1_liodn_tbl, fman1_liodn_tbl_sz);
  148. setup_fman_liodn_base(FSL_HW_PORTAL_FMAN1, fman1_liodn_tbl,
  149. fman1_liodn_tbl_sz);
  150. #if (CONFIG_SYS_NUM_FMAN == 2)
  151. set_liodn(fman2_liodn_tbl, fman2_liodn_tbl_sz);
  152. setup_fman_liodn_base(FSL_HW_PORTAL_FMAN2, fman2_liodn_tbl,
  153. fman2_liodn_tbl_sz);
  154. #endif
  155. #endif
  156. /* setup PME liodn base */
  157. setup_pme_liodn_base();
  158. #ifdef CONFIG_SYS_FSL_RAID_ENGINE
  159. /* raid engine ccr addr code for liodn */
  160. set_liodn(raide_liodn_tbl, raide_liodn_tbl_sz);
  161. setup_raide_liodn_base();
  162. #endif
  163. #ifdef CONFIG_SYS_DPAA_RMAN
  164. /* setup RMan liodn offsets */
  165. set_rman_liodn(rman_liodn_tbl, rman_liodn_tbl_sz);
  166. /* setup RMan liodn base */
  167. setup_rman_liodn_base(rman_liodn_tbl, rman_liodn_tbl_sz);
  168. #endif
  169. }
  170. #ifdef CONFIG_SYS_SRIO
  171. static void fdt_fixup_srio_liodn(void *blob, struct srio_liodn_id_table *tbl)
  172. {
  173. int i, srio_off;
  174. /* search for srio node, if doesn't exist just return - nothing todo */
  175. srio_off = fdt_node_offset_by_compatible(blob, -1, "fsl,srio");
  176. if (srio_off < 0)
  177. return ;
  178. for (i = 0; i < srio_liodn_tbl_sz; i++) {
  179. int off, portid = tbl[i].portid;
  180. off = fdt_node_offset_by_prop_value(blob, srio_off,
  181. "cell-index", &portid, 4);
  182. if (off >= 0) {
  183. off = fdt_setprop(blob, off, "fsl,liodn",
  184. &tbl[i].id[0],
  185. sizeof(u32) * tbl[i].num_ids);
  186. if (off > 0)
  187. printf("WARNING unable to set fsl,liodn for "
  188. "fsl,srio port %d: %s\n",
  189. portid, fdt_strerror(off));
  190. } else {
  191. debug("WARNING: couldn't set fsl,liodn for srio: %s.\n",
  192. fdt_strerror(off));
  193. }
  194. }
  195. }
  196. #endif
  197. #define CONFIG_SYS_MAX_PCI_EPS 8
  198. static void fdt_fixup_pci_liodn_offsets(void *fdt, const char *compat,
  199. int ep_liodn_start)
  200. {
  201. int off, pci_idx = 0, pci_cnt = 0, i, rc;
  202. const uint32_t *base_liodn;
  203. uint32_t liodn_offs[CONFIG_SYS_MAX_PCI_EPS + 1] = { 0 };
  204. /*
  205. * Count the number of pci nodes.
  206. * It's needed later when the interleaved liodn offsets are generated.
  207. */
  208. off = fdt_node_offset_by_compatible(fdt, -1, compat);
  209. while (off != -FDT_ERR_NOTFOUND) {
  210. pci_cnt++;
  211. off = fdt_node_offset_by_compatible(fdt, off, compat);
  212. }
  213. for (off = fdt_node_offset_by_compatible(fdt, -1, compat);
  214. off != -FDT_ERR_NOTFOUND;
  215. off = fdt_node_offset_by_compatible(fdt, off, compat)) {
  216. base_liodn = fdt_getprop(fdt, off, "fsl,liodn", &rc);
  217. if (!base_liodn) {
  218. char path[64];
  219. if (fdt_get_path(fdt, off, path, sizeof(path)) < 0)
  220. strcpy(path, "(unknown)");
  221. printf("WARNING Could not get liodn of node %s: %s\n",
  222. path, fdt_strerror(rc));
  223. continue;
  224. }
  225. for (i = 0; i < CONFIG_SYS_MAX_PCI_EPS; i++)
  226. liodn_offs[i + 1] = ep_liodn_start +
  227. i * pci_cnt + pci_idx - *base_liodn;
  228. rc = fdt_setprop(fdt, off, "fsl,liodn-offset-list",
  229. liodn_offs, sizeof(liodn_offs));
  230. if (rc) {
  231. char path[64];
  232. if (fdt_get_path(fdt, off, path, sizeof(path)) < 0)
  233. strcpy(path, "(unknown)");
  234. printf("WARNING Unable to set fsl,liodn-offset-list for "
  235. "node %s: %s\n", path, fdt_strerror(rc));
  236. continue;
  237. }
  238. pci_idx++;
  239. }
  240. }
  241. static void fdt_fixup_liodn_tbl(void *blob, struct liodn_id_table *tbl, int sz)
  242. {
  243. int i;
  244. for (i = 0; i < sz; i++) {
  245. int off;
  246. if (tbl[i].compat == NULL)
  247. continue;
  248. off = fdt_node_offset_by_compat_reg(blob,
  249. tbl[i].compat, tbl[i].compat_offset);
  250. if (off >= 0) {
  251. off = fdt_setprop(blob, off, "fsl,liodn",
  252. &tbl[i].id[0],
  253. sizeof(u32) * tbl[i].num_ids);
  254. if (off > 0)
  255. printf("WARNING unable to set fsl,liodn for "
  256. "%s: %s\n",
  257. tbl[i].compat, fdt_strerror(off));
  258. } else {
  259. debug("WARNING: could not set fsl,liodn for %s: %s.\n",
  260. tbl[i].compat, fdt_strerror(off));
  261. }
  262. }
  263. }
  264. void fdt_fixup_liodn(void *blob)
  265. {
  266. #ifdef CONFIG_SYS_SRIO
  267. fdt_fixup_srio_liodn(blob, srio_liodn_tbl);
  268. #endif
  269. fdt_fixup_liodn_tbl(blob, liodn_tbl, liodn_tbl_sz);
  270. #ifdef CONFIG_SYS_DPAA_FMAN
  271. fdt_fixup_liodn_tbl(blob, fman1_liodn_tbl, fman1_liodn_tbl_sz);
  272. #if (CONFIG_SYS_NUM_FMAN == 2)
  273. fdt_fixup_liodn_tbl(blob, fman2_liodn_tbl, fman2_liodn_tbl_sz);
  274. #endif
  275. #endif
  276. fdt_fixup_liodn_tbl(blob, sec_liodn_tbl, sec_liodn_tbl_sz);
  277. #ifdef CONFIG_SYS_FSL_RAID_ENGINE
  278. fdt_fixup_liodn_tbl(blob, raide_liodn_tbl, raide_liodn_tbl_sz);
  279. #endif
  280. #ifdef CONFIG_SYS_DPAA_RMAN
  281. fdt_fixup_liodn_tbl(blob, rman_liodn_tbl, rman_liodn_tbl_sz);
  282. #endif
  283. ccsr_pcix_t *pcix = (ccsr_pcix_t *)CONFIG_SYS_PCIE1_ADDR;
  284. int pci_ver = pcix->ipver1 & 0xffff, liodn_base = 0;
  285. if (pci_ver >= 0x0204) {
  286. if (pci_ver >= 0x0300)
  287. liodn_base = 1024;
  288. else
  289. liodn_base = 256;
  290. }
  291. if (liodn_base) {
  292. char compat[32];
  293. sprintf(compat, "fsl,qoriq-pcie-v%d.%d",
  294. (pci_ver & 0xff00) >> 8, pci_ver & 0xff);
  295. fdt_fixup_pci_liodn_offsets(blob, compat, liodn_base);
  296. fdt_fixup_pci_liodn_offsets(blob, "fsl,qoriq-pcie", liodn_base);
  297. }
  298. }