2 * Copyright 2008-2011 Freescale Semiconductor, Inc.
4 * SPDX-License-Identifier: GPL-2.0+
9 #include <fdt_support.h>
11 #include <asm/processor.h>
14 #include <asm/fsl_portals.h>
15 #include <asm/fsl_liodn.h>
17 #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)
19 static void inhibit_portals(void __iomem
*addr
, int max_portals
,
20 int arch_max_portals
, int portal_cinh_size
)
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
;
33 for (i
= 0; i
< max_portals
; i
++) {
37 printf("ERROR: Stopped after %d portals\n", i
);
40 addr
+= portal_cinh_size
;
43 printf("Cleared %d portals\n", i
);
50 void setup_portals(void)
52 ccsr_qman_t
*qman
= (void *)CONFIG_SYS_FSL_QMAN_ADDR
;
53 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
;
57 #ifdef CONFIG_FSL_CORENET
60 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
;
66 out_be32(&qman
->qcsp
[i
].qcsp_lio_cfg
, (liodn_off
<< 16) |
69 out_be32(&qman
->qcsp
[i
].qcsp_io_cfg
, (sdest
<< 16) | fliodn
);
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));
77 out_be32(&qman
->qcsp_bar
, (u32
)CONFIG_SYS_QMAN_MEM_PHYS
);
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
);
86 /* Update portal containter to match LAW setup of portal in phy map */
87 void fdt_portal(void *blob
, const char *compat
, const char *container
,
92 off
= fdt_node_offset_by_compatible(blob
, -1, compat
);
96 off
= fdt_parent_offset(blob
, off
);
97 /* if non-zero assume we have a container */
100 const char *p
, *name
;
105 range
= fdt_getprop_w(blob
, off
, "ranges", &len
);
107 printf("ERROR: container for %s has no ranges", compat
);
113 range
[1] = addr
>> 32;
114 range
[2] = addr
& 0xffffffff;
117 range
[1] = addr
& 0xffffffff;
120 fdt_setprop_inplace(blob
, off
, "ranges", range
, len
);
123 name
= fdt_get_name(blob
, off
, &len
);
124 p
= memchr(name
, '@', len
);
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",
137 memcpy(&buf
, name
, len
);
138 len
+= sprintf(&buf
[len
], "@%llx", addr
);
139 fdt_set_name(blob
, off
, buf
);
143 printf("ERROR: %s isn't in a container. Not supported\n", compat
);
146 static int fdt_qportal(void *blob
, int off
, int id
, char *name
,
147 enum fsl_dpaa_dev dev
, int create
)
149 int childoff
, dev_off
, ret
= 0;
151 #ifdef CONFIG_FSL_CORENET
156 childoff
= fdt_subnode_offset(blob
, off
, name
);
160 strncpy(handle
, name
, sizeof(handle
));
161 p
= strchr(handle
, '@');
162 if (!strncmp(name
, "fman", 4)) {
168 dev_off
= fdt_path_offset(blob
, handle
);
169 /* skip this node if alias is not found */
170 if (dev_off
== -FDT_ERR_BADPATH
)
176 childoff
= fdt_add_subnode(blob
, off
, name
);
178 /* need to update the dev_off after adding a subnode */
179 dev_off
= fdt_path_offset(blob
, handle
);
184 dev_handle
= fdt_get_phandle(blob
, dev_off
);
185 if (dev_handle
<= 0) {
186 dev_handle
= fdt_alloc_phandle(blob
);
187 ret
= fdt_set_phandle(blob
, dev_off
,
193 ret
= fdt_setprop(blob
, childoff
, "dev-handle",
194 &dev_handle
, sizeof(dev_handle
));
198 #ifdef CONFIG_FSL_CORENET
199 num
= get_dpaa_liodn(dev
, &liodns
[0], id
);
200 ret
= fdt_setprop(blob
, childoff
, "fsl,liodn",
201 &liodns
[0], sizeof(u32
) * num
);
202 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
;
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
));
213 ret
= fdt_setprop(blob
, childoff
,
214 "fsl,pme-rev2", &pme_rev2
, sizeof(u32
));
222 ret
= fdt_del_node(blob
, childoff
);
228 void fdt_fixup_qportals(void *blob
)
231 unsigned int maj
, min
;
233 ccsr_qman_t
*qman
= (void *)CONFIG_SYS_FSL_QMAN_ADDR
;
234 u32 rev_1
= in_be32(&qman
->ip_rev_1
);
235 u32 rev_2
= in_be32(&qman
->ip_rev_2
);
239 maj
= (rev_1
>> 8) & 0xff;
241 ip_cfg
= rev_2
& 0xff;
243 compat_len
= sprintf(compat
, "fsl,qman-portal-%u.%u.%u",
244 maj
, min
, ip_cfg
) + 1;
245 compat_len
+= sprintf(compat
+ compat_len
, "fsl,qman-portal") + 1;
247 off
= fdt_node_offset_by_compatible(blob
, -1, "fsl,qman-portal");
248 while (off
!= -FDT_ERR_NOTFOUND
) {
249 #ifdef CONFIG_FSL_CORENET
252 const int *ci
= fdt_getprop(blob
, off
, "cell-index", &err
);
259 #ifdef CONFIG_SYS_DPAA_FMAN
263 err
= fdt_setprop(blob
, off
, "compatible", compat
, compat_len
);
267 #ifdef CONFIG_FSL_CORENET
268 liodns
[0] = qp_info
[i
].dliodn
;
269 liodns
[1] = qp_info
[i
].fliodn
;
271 err
= fdt_setprop(blob
, off
, "fsl,liodn",
272 &liodns
, sizeof(u32
) * 2);
279 err
= fdt_qportal(blob
, off
, i
, "crypto@0", FSL_HW_PORTAL_SEC
,
280 IS_E_PROCESSOR(get_svr()));
284 #ifdef CONFIG_FSL_CORENET
285 #ifdef CONFIG_SYS_DPAA_PME
286 err
= fdt_qportal(blob
, off
, i
, "pme@0", FSL_HW_PORTAL_PME
, 1);
290 fdt_qportal(blob
, off
, i
, "pme@0", FSL_HW_PORTAL_PME
, 0);
294 #ifdef CONFIG_SYS_DPAA_FMAN
295 for (j
= 0; j
< CONFIG_SYS_NUM_FMAN
; j
++) {
296 char name
[] = "fman@0";
298 name
[sizeof(name
) - 2] = '0' + j
;
299 err
= fdt_qportal(blob
, off
, i
, name
,
300 FSL_HW_PORTAL_FMAN1
+ j
, 1);
305 #ifdef CONFIG_SYS_DPAA_RMAN
306 err
= fdt_qportal(blob
, off
, i
, "rman@0",
307 FSL_HW_PORTAL_RMAN
, 1);
314 printf("ERROR: unable to create props for %s: %s\n",
315 fdt_get_name(blob
, off
, NULL
), fdt_strerror(err
));
319 off
= fdt_node_offset_by_compatible(blob
, off
, "fsl,qman-portal");
323 void fdt_fixup_bportals(void *blob
)
326 unsigned int maj
, min
;
328 ccsr_bman_t
*bman
= (void *)CONFIG_SYS_FSL_BMAN_ADDR
;
329 u32 rev_1
= in_be32(&bman
->ip_rev_1
);
330 u32 rev_2
= in_be32(&bman
->ip_rev_2
);
334 maj
= (rev_1
>> 8) & 0xff;
337 ip_cfg
= rev_2
& 0xff;
339 compat_len
= sprintf(compat
, "fsl,bman-portal-%u.%u.%u",
340 maj
, min
, ip_cfg
) + 1;
341 compat_len
+= sprintf(compat
+ compat_len
, "fsl,bman-portal") + 1;
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
);
347 printf("ERROR: unable to create props for %s: %s\n",
348 fdt_get_name(blob
, off
, NULL
),
353 off
= fdt_node_offset_by_compatible(blob
, off
, "fsl,bman-portal");