blob: 3777c6faa166142685e0364e4e23c82d010b3346 [file] [log] [blame]
Kumar Gala38449a42009-09-10 03:02:13 -05001/*
Haiying Wang325a12f2011-01-20 22:26:31 +00002 * Copyright 2008-2011 Freescale Semiconductor, Inc.
Kumar Gala38449a42009-09-10 03:02:13 -05003 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02004 * SPDX-License-Identifier: GPL-2.0+
Kumar Gala38449a42009-09-10 03:02:13 -05005 */
6
7#include <common.h>
8#include <libfdt.h>
9#include <fdt_support.h>
10
11#include <asm/processor.h>
12#include <asm/io.h>
13
14#include <asm/fsl_portals.h>
15#include <asm/fsl_liodn.h>
16
Jeffrey Ladouceurff2c6462014-12-08 14:54:01 -050017#define MAX_BPORTALS (CONFIG_SYS_BMAN_CINH_SIZE / CONFIG_SYS_BMAN_SP_CINH_SIZE)
18#define MAX_QPORTALS (CONFIG_SYS_QMAN_CINH_SIZE / CONFIG_SYS_QMAN_SP_CINH_SIZE)
19static void inhibit_portals(void __iomem *addr, int max_portals,
20 int arch_max_portals, int portal_cinh_size)
21{
22 uint32_t val;
23 int i;
24
25 /* arch_max_portals is the maximum based on memory size. This includes
26 * the reserved memory in the SoC. max_portals the number of physical
27 * portals in the SoC */
28 if (max_portals > arch_max_portals) {
29 printf("ERROR: portal config error\n");
30 max_portals = arch_max_portals;
31 }
32
33 for (i = 0; i < max_portals; i++) {
34 out_be32(addr, -1);
35 val = in_be32(addr);
36 if (!val) {
37 printf("ERROR: Stopped after %d portals\n", i);
38 goto done;
39 }
40 addr += portal_cinh_size;
41 }
42#ifdef DEBUG
43 printf("Cleared %d portals\n", i);
44#endif
45done:
46
47 return;
48}
49
Kumar Gala38449a42009-09-10 03:02:13 -050050void setup_portals(void)
51{
Jeffrey Ladouceur13452202013-01-25 10:38:53 +000052 ccsr_qman_t *qman = (void *)CONFIG_SYS_FSL_QMAN_ADDR;
Jeffrey Ladouceurff2c6462014-12-08 14:54:01 -050053 void __iomem *bpaddr = (void *)CONFIG_SYS_BMAN_CINH_BASE +
54 CONFIG_SYS_BMAN_SWP_ISDR_REG;
55 void __iomem *qpaddr = (void *)CONFIG_SYS_QMAN_CINH_BASE +
56 CONFIG_SYS_QMAN_SWP_ISDR_REG;
Haiying Wang325a12f2011-01-20 22:26:31 +000057#ifdef CONFIG_FSL_CORENET
Kumar Gala38449a42009-09-10 03:02:13 -050058 int i;
59
Kumar Gala38449a42009-09-10 03:02:13 -050060 for (i = 0; i < CONFIG_SYS_QMAN_NUM_PORTALS; i++) {
61 u8 sdest = qp_info[i].sdest;
62 u16 fliodn = qp_info[i].fliodn;
63 u16 dliodn = qp_info[i].dliodn;
64 u16 liodn_off = qp_info[i].liodn_offset;
65
66 out_be32(&qman->qcsp[i].qcsp_lio_cfg, (liodn_off << 16) |
67 dliodn);
68 /* set frame liodn */
69 out_be32(&qman->qcsp[i].qcsp_io_cfg, (sdest << 16) | fliodn);
70 }
Haiying Wang325a12f2011-01-20 22:26:31 +000071#endif
72
73 /* Set the Qman initiator BAR to match the LAW (for DQRR stashing) */
74#ifdef CONFIG_PHYS_64BIT
75 out_be32(&qman->qcsp_bare, (u32)(CONFIG_SYS_QMAN_MEM_PHYS >> 32));
76#endif
77 out_be32(&qman->qcsp_bar, (u32)CONFIG_SYS_QMAN_MEM_PHYS);
Jeffrey Ladouceurff2c6462014-12-08 14:54:01 -050078
79 /* Change default state of BMan ISDR portals to all 1s */
80 inhibit_portals(bpaddr, CONFIG_SYS_BMAN_NUM_PORTALS, MAX_BPORTALS,
81 CONFIG_SYS_BMAN_SP_CINH_SIZE);
82 inhibit_portals(qpaddr, CONFIG_SYS_QMAN_NUM_PORTALS, MAX_QPORTALS,
83 CONFIG_SYS_QMAN_SP_CINH_SIZE);
Kumar Gala38449a42009-09-10 03:02:13 -050084}
85
86/* Update portal containter to match LAW setup of portal in phy map */
87void fdt_portal(void *blob, const char *compat, const char *container,
88 u64 addr, u32 size)
89{
90 int off;
91
92 off = fdt_node_offset_by_compatible(blob, -1, compat);
93 if (off < 0)
94 return ;
95
96 off = fdt_parent_offset(blob, off);
97 /* if non-zero assume we have a container */
98 if (off > 0) {
99 char buf[60];
100 const char *p, *name;
101 u32 *range;
102 int len;
103
104 /* fixup ranges */
105 range = fdt_getprop_w(blob, off, "ranges", &len);
106 if (range == NULL) {
107 printf("ERROR: container for %s has no ranges", compat);
108 return ;
109 }
110
111 range[0] = 0;
112 if (len == 16) {
113 range[1] = addr >> 32;
114 range[2] = addr & 0xffffffff;
115 range[3] = size;
116 } else {
117 range[1] = addr & 0xffffffff;
118 range[2] = size;
119 }
120 fdt_setprop_inplace(blob, off, "ranges", range, len);
121
122 /* fixup the name */
123 name = fdt_get_name(blob, off, &len);
124 p = memchr(name, '@', len);
125
126 if (p)
127 len = p - name;
128
129 /* if we are given a container name check it
130 * against what we found, if it doesnt match exit out */
131 if (container && (memcmp(container, name, len))) {
132 printf("WARNING: container names didn't match %s %s\n",
133 container, name);
134 return ;
135 }
136
137 memcpy(&buf, name, len);
138 len += sprintf(&buf[len], "@%llx", addr);
139 fdt_set_name(blob, off, buf);
140 return ;
141 }
142
143 printf("ERROR: %s isn't in a container. Not supported\n", compat);
144}
145
146static int fdt_qportal(void *blob, int off, int id, char *name,
147 enum fsl_dpaa_dev dev, int create)
148{
Haiying Wang325a12f2011-01-20 22:26:31 +0000149 int childoff, dev_off, ret = 0;
Kumar Gala38449a42009-09-10 03:02:13 -0500150 uint32_t dev_handle;
Haiying Wang325a12f2011-01-20 22:26:31 +0000151#ifdef CONFIG_FSL_CORENET
152 int num;
Kumar Gala38449a42009-09-10 03:02:13 -0500153 u32 liodns[2];
Haiying Wang325a12f2011-01-20 22:26:31 +0000154#endif
Kumar Gala38449a42009-09-10 03:02:13 -0500155
156 childoff = fdt_subnode_offset(blob, off, name);
157 if (create) {
York Sune2f35732013-03-25 07:33:21 +0000158 char handle[64], *p;
Kumar Gala38449a42009-09-10 03:02:13 -0500159
York Sune2f35732013-03-25 07:33:21 +0000160 strncpy(handle, name, sizeof(handle));
161 p = strchr(handle, '@');
162 if (!strncmp(name, "fman", 4)) {
163 *p = *(p + 1);
164 p++;
165 }
166 *p = '\0';
Kumar Gala38449a42009-09-10 03:02:13 -0500167
York Sune2f35732013-03-25 07:33:21 +0000168 dev_off = fdt_path_offset(blob, handle);
169 /* skip this node if alias is not found */
170 if (dev_off == -FDT_ERR_BADPATH)
171 return 0;
172 if (dev_off < 0)
173 return dev_off;
Kumar Gala38449a42009-09-10 03:02:13 -0500174
York Sune2f35732013-03-25 07:33:21 +0000175 if (childoff <= 0)
176 childoff = fdt_add_subnode(blob, off, name);
177
178 /* need to update the dev_off after adding a subnode */
179 dev_off = fdt_path_offset(blob, handle);
180 if (dev_off < 0)
181 return dev_off;
Kumar Gala38449a42009-09-10 03:02:13 -0500182
York Sune2f35732013-03-25 07:33:21 +0000183 if (childoff > 0) {
Kumar Gala38449a42009-09-10 03:02:13 -0500184 dev_handle = fdt_get_phandle(blob, dev_off);
185 if (dev_handle <= 0) {
186 dev_handle = fdt_alloc_phandle(blob);
Kumar Galaf2f1c5a2011-08-01 00:23:23 -0500187 ret = fdt_set_phandle(blob, dev_off,
Timur Tabiecd9c692011-05-10 15:28:14 -0500188 dev_handle);
189 if (ret < 0)
190 return ret;
Kumar Gala38449a42009-09-10 03:02:13 -0500191 }
192
193 ret = fdt_setprop(blob, childoff, "dev-handle",
194 &dev_handle, sizeof(dev_handle));
195 if (ret < 0)
196 return ret;
197
Haiying Wang325a12f2011-01-20 22:26:31 +0000198#ifdef CONFIG_FSL_CORENET
Kumar Gala38449a42009-09-10 03:02:13 -0500199 num = get_dpaa_liodn(dev, &liodns[0], id);
200 ret = fdt_setprop(blob, childoff, "fsl,liodn",
201 &liodns[0], sizeof(u32) * num);
Jeffrey Ladouceur13452202013-01-25 10:38:53 +0000202 if (!strncmp(name, "pme", 3)) {
203 u32 pme_rev1, pme_rev2;
204 ccsr_pme_t *pme_regs =
205 (void *)CONFIG_SYS_FSL_CORENET_PME_ADDR;
206
207 pme_rev1 = in_be32(&pme_regs->pm_ip_rev_1);
208 pme_rev2 = in_be32(&pme_regs->pm_ip_rev_2);
209 ret = fdt_setprop(blob, childoff,
210 "fsl,pme-rev1", &pme_rev1, sizeof(u32));
211 if (ret < 0)
212 return ret;
213 ret = fdt_setprop(blob, childoff,
214 "fsl,pme-rev2", &pme_rev2, sizeof(u32));
215 }
Haiying Wang325a12f2011-01-20 22:26:31 +0000216#endif
Kumar Gala38449a42009-09-10 03:02:13 -0500217 } else {
218 return childoff;
219 }
220 } else {
221 if (childoff > 0)
222 ret = fdt_del_node(blob, childoff);
223 }
224
225 return ret;
226}
227
228void fdt_fixup_qportals(void *blob)
229{
230 int off, err;
231 unsigned int maj, min;
Haiying Wange67bdfc2012-10-11 07:13:38 +0000232 unsigned int ip_cfg;
Jeffrey Ladouceur13452202013-01-25 10:38:53 +0000233 ccsr_qman_t *qman = (void *)CONFIG_SYS_FSL_QMAN_ADDR;
Kumar Gala38449a42009-09-10 03:02:13 -0500234 u32 rev_1 = in_be32(&qman->ip_rev_1);
Haiying Wange67bdfc2012-10-11 07:13:38 +0000235 u32 rev_2 = in_be32(&qman->ip_rev_2);
Kumar Gala38449a42009-09-10 03:02:13 -0500236 char compat[64];
237 int compat_len;
238
239 maj = (rev_1 >> 8) & 0xff;
240 min = rev_1 & 0xff;
Haiying Wange67bdfc2012-10-11 07:13:38 +0000241 ip_cfg = rev_2 & 0xff;
Kumar Gala38449a42009-09-10 03:02:13 -0500242
Haiying Wange67bdfc2012-10-11 07:13:38 +0000243 compat_len = sprintf(compat, "fsl,qman-portal-%u.%u.%u",
244 maj, min, ip_cfg) + 1;
Kumar Gala38449a42009-09-10 03:02:13 -0500245 compat_len += sprintf(compat + compat_len, "fsl,qman-portal") + 1;
246
247 off = fdt_node_offset_by_compatible(blob, -1, "fsl,qman-portal");
248 while (off != -FDT_ERR_NOTFOUND) {
Haiying Wang325a12f2011-01-20 22:26:31 +0000249#ifdef CONFIG_FSL_CORENET
Kumar Gala38449a42009-09-10 03:02:13 -0500250 u32 liodns[2];
Haiying Wang325a12f2011-01-20 22:26:31 +0000251#endif
Scott Wood4ffeb5d2015-04-17 18:10:06 -0500252 const int *ci = fdt_getprop(blob, off, "cell-index", &err);
253 int i;
254
255 if (!ci)
256 goto err;
257
258 i = *ci;
Kumar Gala302a65c2011-07-31 12:55:39 -0500259#ifdef CONFIG_SYS_DPAA_FMAN
260 int j;
261#endif
Kumar Gala38449a42009-09-10 03:02:13 -0500262
263 err = fdt_setprop(blob, off, "compatible", compat, compat_len);
264 if (err < 0)
265 goto err;
266
Haiying Wang325a12f2011-01-20 22:26:31 +0000267#ifdef CONFIG_FSL_CORENET
Kumar Gala38449a42009-09-10 03:02:13 -0500268 liodns[0] = qp_info[i].dliodn;
269 liodns[1] = qp_info[i].fliodn;
270
271 err = fdt_setprop(blob, off, "fsl,liodn",
272 &liodns, sizeof(u32) * 2);
273 if (err < 0)
274 goto err;
Haiying Wang325a12f2011-01-20 22:26:31 +0000275#endif
Kumar Gala38449a42009-09-10 03:02:13 -0500276
277 i++;
278
279 err = fdt_qportal(blob, off, i, "crypto@0", FSL_HW_PORTAL_SEC,
280 IS_E_PROCESSOR(get_svr()));
281 if (err < 0)
282 goto err;
283
Haiying Wang325a12f2011-01-20 22:26:31 +0000284#ifdef CONFIG_FSL_CORENET
Kumar Gala38449a42009-09-10 03:02:13 -0500285#ifdef CONFIG_SYS_DPAA_PME
286 err = fdt_qportal(blob, off, i, "pme@0", FSL_HW_PORTAL_PME, 1);
287 if (err < 0)
288 goto err;
289#else
290 fdt_qportal(blob, off, i, "pme@0", FSL_HW_PORTAL_PME, 0);
291#endif
Haiying Wang325a12f2011-01-20 22:26:31 +0000292#endif
293
Kumar Gala38449a42009-09-10 03:02:13 -0500294#ifdef CONFIG_SYS_DPAA_FMAN
295 for (j = 0; j < CONFIG_SYS_NUM_FMAN; j++) {
296 char name[] = "fman@0";
297
298 name[sizeof(name) - 2] = '0' + j;
299 err = fdt_qportal(blob, off, i, name,
300 FSL_HW_PORTAL_FMAN1 + j, 1);
301 if (err < 0)
302 goto err;
303 }
304#endif
Kumar Gala4eb3c372011-10-14 13:28:52 -0500305#ifdef CONFIG_SYS_DPAA_RMAN
306 err = fdt_qportal(blob, off, i, "rman@0",
307 FSL_HW_PORTAL_RMAN, 1);
308 if (err < 0)
309 goto err;
310#endif
Kumar Gala38449a42009-09-10 03:02:13 -0500311
312err:
313 if (err < 0) {
314 printf("ERROR: unable to create props for %s: %s\n",
315 fdt_get_name(blob, off, NULL), fdt_strerror(err));
316 return;
317 }
318
319 off = fdt_node_offset_by_compatible(blob, off, "fsl,qman-portal");
320 }
321}
Haiying Wangd38d4b22011-03-01 09:30:07 -0500322
323void fdt_fixup_bportals(void *blob)
324{
325 int off, err;
326 unsigned int maj, min;
Haiying Wange67bdfc2012-10-11 07:13:38 +0000327 unsigned int ip_cfg;
Jeffrey Ladouceur13452202013-01-25 10:38:53 +0000328 ccsr_bman_t *bman = (void *)CONFIG_SYS_FSL_BMAN_ADDR;
Haiying Wangd38d4b22011-03-01 09:30:07 -0500329 u32 rev_1 = in_be32(&bman->ip_rev_1);
Haiying Wange67bdfc2012-10-11 07:13:38 +0000330 u32 rev_2 = in_be32(&bman->ip_rev_2);
Haiying Wangd38d4b22011-03-01 09:30:07 -0500331 char compat[64];
332 int compat_len;
333
334 maj = (rev_1 >> 8) & 0xff;
335 min = rev_1 & 0xff;
336
Haiying Wange67bdfc2012-10-11 07:13:38 +0000337 ip_cfg = rev_2 & 0xff;
338
339 compat_len = sprintf(compat, "fsl,bman-portal-%u.%u.%u",
340 maj, min, ip_cfg) + 1;
Haiying Wangd38d4b22011-03-01 09:30:07 -0500341 compat_len += sprintf(compat + compat_len, "fsl,bman-portal") + 1;
342
343 off = fdt_node_offset_by_compatible(blob, -1, "fsl,bman-portal");
344 while (off != -FDT_ERR_NOTFOUND) {
345 err = fdt_setprop(blob, off, "compatible", compat, compat_len);
346 if (err < 0) {
347 printf("ERROR: unable to create props for %s: %s\n",
348 fdt_get_name(blob, off, NULL),
349 fdt_strerror(err));
350 return;
351 }
352
353 off = fdt_node_offset_by_compatible(blob, off, "fsl,bman-portal");
354 }
355
356}