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 void setup_portals(void)
19 ccsr_qman_t
*qman
= (void *)CONFIG_SYS_FSL_QMAN_ADDR
;
20 #ifdef CONFIG_FSL_CORENET
23 for (i
= 0; i
< CONFIG_SYS_QMAN_NUM_PORTALS
; i
++) {
24 u8 sdest
= qp_info
[i
].sdest
;
25 u16 fliodn
= qp_info
[i
].fliodn
;
26 u16 dliodn
= qp_info
[i
].dliodn
;
27 u16 liodn_off
= qp_info
[i
].liodn_offset
;
29 out_be32(&qman
->qcsp
[i
].qcsp_lio_cfg
, (liodn_off
<< 16) |
32 out_be32(&qman
->qcsp
[i
].qcsp_io_cfg
, (sdest
<< 16) | fliodn
);
36 /* Set the Qman initiator BAR to match the LAW (for DQRR stashing) */
37 #ifdef CONFIG_PHYS_64BIT
38 out_be32(&qman
->qcsp_bare
, (u32
)(CONFIG_SYS_QMAN_MEM_PHYS
>> 32));
40 out_be32(&qman
->qcsp_bar
, (u32
)CONFIG_SYS_QMAN_MEM_PHYS
);
43 /* Update portal containter to match LAW setup of portal in phy map */
44 void fdt_portal(void *blob
, const char *compat
, const char *container
,
49 off
= fdt_node_offset_by_compatible(blob
, -1, compat
);
53 off
= fdt_parent_offset(blob
, off
);
54 /* if non-zero assume we have a container */
62 range
= fdt_getprop_w(blob
, off
, "ranges", &len
);
64 printf("ERROR: container for %s has no ranges", compat
);
70 range
[1] = addr
>> 32;
71 range
[2] = addr
& 0xffffffff;
74 range
[1] = addr
& 0xffffffff;
77 fdt_setprop_inplace(blob
, off
, "ranges", range
, len
);
80 name
= fdt_get_name(blob
, off
, &len
);
81 p
= memchr(name
, '@', len
);
86 /* if we are given a container name check it
87 * against what we found, if it doesnt match exit out */
88 if (container
&& (memcmp(container
, name
, len
))) {
89 printf("WARNING: container names didn't match %s %s\n",
94 memcpy(&buf
, name
, len
);
95 len
+= sprintf(&buf
[len
], "@%llx", addr
);
96 fdt_set_name(blob
, off
, buf
);
100 printf("ERROR: %s isn't in a container. Not supported\n", compat
);
103 static int fdt_qportal(void *blob
, int off
, int id
, char *name
,
104 enum fsl_dpaa_dev dev
, int create
)
106 int childoff
, dev_off
, ret
= 0;
108 #ifdef CONFIG_FSL_CORENET
113 childoff
= fdt_subnode_offset(blob
, off
, name
);
117 strncpy(handle
, name
, sizeof(handle
));
118 p
= strchr(handle
, '@');
119 if (!strncmp(name
, "fman", 4)) {
125 dev_off
= fdt_path_offset(blob
, handle
);
126 /* skip this node if alias is not found */
127 if (dev_off
== -FDT_ERR_BADPATH
)
133 childoff
= fdt_add_subnode(blob
, off
, name
);
135 /* need to update the dev_off after adding a subnode */
136 dev_off
= fdt_path_offset(blob
, handle
);
141 dev_handle
= fdt_get_phandle(blob
, dev_off
);
142 if (dev_handle
<= 0) {
143 dev_handle
= fdt_alloc_phandle(blob
);
144 ret
= fdt_set_phandle(blob
, dev_off
,
150 ret
= fdt_setprop(blob
, childoff
, "dev-handle",
151 &dev_handle
, sizeof(dev_handle
));
155 #ifdef CONFIG_FSL_CORENET
156 num
= get_dpaa_liodn(dev
, &liodns
[0], id
);
157 ret
= fdt_setprop(blob
, childoff
, "fsl,liodn",
158 &liodns
[0], sizeof(u32
) * num
);
159 if (!strncmp(name
, "pme", 3)) {
160 u32 pme_rev1
, pme_rev2
;
161 ccsr_pme_t
*pme_regs
=
162 (void *)CONFIG_SYS_FSL_CORENET_PME_ADDR
;
164 pme_rev1
= in_be32(&pme_regs
->pm_ip_rev_1
);
165 pme_rev2
= in_be32(&pme_regs
->pm_ip_rev_2
);
166 ret
= fdt_setprop(blob
, childoff
,
167 "fsl,pme-rev1", &pme_rev1
, sizeof(u32
));
170 ret
= fdt_setprop(blob
, childoff
,
171 "fsl,pme-rev2", &pme_rev2
, sizeof(u32
));
179 ret
= fdt_del_node(blob
, childoff
);
185 void fdt_fixup_qportals(void *blob
)
188 unsigned int maj
, min
;
190 ccsr_qman_t
*qman
= (void *)CONFIG_SYS_FSL_QMAN_ADDR
;
191 u32 rev_1
= in_be32(&qman
->ip_rev_1
);
192 u32 rev_2
= in_be32(&qman
->ip_rev_2
);
196 maj
= (rev_1
>> 8) & 0xff;
198 ip_cfg
= rev_2
& 0xff;
200 compat_len
= sprintf(compat
, "fsl,qman-portal-%u.%u.%u",
201 maj
, min
, ip_cfg
) + 1;
202 compat_len
+= sprintf(compat
+ compat_len
, "fsl,qman-portal") + 1;
204 off
= fdt_node_offset_by_compatible(blob
, -1, "fsl,qman-portal");
205 while (off
!= -FDT_ERR_NOTFOUND
) {
206 #ifdef CONFIG_FSL_CORENET
209 const int *ci
= fdt_getprop(blob
, off
, "cell-index", NULL
);
211 #ifdef CONFIG_SYS_DPAA_FMAN
215 err
= fdt_setprop(blob
, off
, "compatible", compat
, compat_len
);
219 #ifdef CONFIG_FSL_CORENET
220 liodns
[0] = qp_info
[i
].dliodn
;
221 liodns
[1] = qp_info
[i
].fliodn
;
223 err
= fdt_setprop(blob
, off
, "fsl,liodn",
224 &liodns
, sizeof(u32
) * 2);
231 err
= fdt_qportal(blob
, off
, i
, "crypto@0", FSL_HW_PORTAL_SEC
,
232 IS_E_PROCESSOR(get_svr()));
236 #ifdef CONFIG_FSL_CORENET
237 #ifdef CONFIG_SYS_DPAA_PME
238 err
= fdt_qportal(blob
, off
, i
, "pme@0", FSL_HW_PORTAL_PME
, 1);
242 fdt_qportal(blob
, off
, i
, "pme@0", FSL_HW_PORTAL_PME
, 0);
246 #ifdef CONFIG_SYS_DPAA_FMAN
247 for (j
= 0; j
< CONFIG_SYS_NUM_FMAN
; j
++) {
248 char name
[] = "fman@0";
250 name
[sizeof(name
) - 2] = '0' + j
;
251 err
= fdt_qportal(blob
, off
, i
, name
,
252 FSL_HW_PORTAL_FMAN1
+ j
, 1);
257 #ifdef CONFIG_SYS_DPAA_RMAN
258 err
= fdt_qportal(blob
, off
, i
, "rman@0",
259 FSL_HW_PORTAL_RMAN
, 1);
266 printf("ERROR: unable to create props for %s: %s\n",
267 fdt_get_name(blob
, off
, NULL
), fdt_strerror(err
));
271 off
= fdt_node_offset_by_compatible(blob
, off
, "fsl,qman-portal");
275 void fdt_fixup_bportals(void *blob
)
278 unsigned int maj
, min
;
280 ccsr_bman_t
*bman
= (void *)CONFIG_SYS_FSL_BMAN_ADDR
;
281 u32 rev_1
= in_be32(&bman
->ip_rev_1
);
282 u32 rev_2
= in_be32(&bman
->ip_rev_2
);
286 maj
= (rev_1
>> 8) & 0xff;
289 ip_cfg
= rev_2
& 0xff;
291 compat_len
= sprintf(compat
, "fsl,bman-portal-%u.%u.%u",
292 maj
, min
, ip_cfg
) + 1;
293 compat_len
+= sprintf(compat
+ compat_len
, "fsl,bman-portal") + 1;
295 off
= fdt_node_offset_by_compatible(blob
, -1, "fsl,bman-portal");
296 while (off
!= -FDT_ERR_NOTFOUND
) {
297 err
= fdt_setprop(blob
, off
, "compatible", compat
, compat_len
);
299 printf("ERROR: unable to create props for %s: %s\n",
300 fdt_get_name(blob
, off
, NULL
),
305 off
= fdt_node_offset_by_compatible(blob
, off
, "fsl,bman-portal");