2 * Copyright 2008-2011 Freescale Semiconductor, Inc.
5 * SPDX-License-Identifier: GPL-2.0+
9 #include <linux/libfdt.h>
10 #include <fdt_support.h>
12 #include <asm/processor.h>
15 #include <asm/fsl_portals.h>
16 #include <asm/fsl_liodn.h>
18 #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)
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;
29 struct ccsr_qman *qman = (void *)CONFIG_SYS_FSL_QMAN_ADDR;
31 /* Set the Qman initiator BAR to match the LAW (for DQRR stashing) */
32 #ifdef CONFIG_PHYS_64BIT
33 out_be32(&qman->qcsp_bare, (u32)(CONFIG_SYS_QMAN_MEM_PHYS >> 32));
35 out_be32(&qman->qcsp_bar, (u32)CONFIG_SYS_QMAN_MEM_PHYS);
37 #ifdef CONFIG_FSL_CORENET
40 for (i = 0; i < CONFIG_SYS_QMAN_NUM_PORTALS; i++) {
41 u8 sdest = qp_info[i].sdest;
42 u16 fliodn = qp_info[i].fliodn;
43 u16 dliodn = qp_info[i].dliodn;
44 u16 liodn_off = qp_info[i].liodn_offset;
46 out_be32(&qman->qcsp[i].qcsp_lio_cfg, (liodn_off << 16) |
49 out_be32(&qman->qcsp[i].qcsp_io_cfg, (sdest << 16) | fliodn);
53 /* Change default state of BMan ISDR portals to all 1s */
54 inhibit_portals(bpaddr, CONFIG_SYS_BMAN_NUM_PORTALS, MAX_BPORTALS,
55 CONFIG_SYS_BMAN_SP_CINH_SIZE);
56 inhibit_portals(qpaddr, CONFIG_SYS_QMAN_NUM_PORTALS, MAX_QPORTALS,
57 CONFIG_SYS_QMAN_SP_CINH_SIZE);
60 void inhibit_portals(void __iomem *addr, int max_portals,
61 int arch_max_portals, int portal_cinh_size)
66 /* arch_max_portals is the maximum based on memory size. This includes
67 * the reserved memory in the SoC. max_portals the number of physical
70 if (max_portals > arch_max_portals) {
71 printf("ERROR: portal config error\n");
72 max_portals = arch_max_portals;
75 for (i = 0; i < max_portals; i++) {
79 printf("ERROR: Stopped after %d portals\n", i);
82 addr += portal_cinh_size;
84 debug("Cleared %d portals\n", i);
88 static int fdt_qportal(void *blob, int off, int id, char *name,
89 enum fsl_dpaa_dev dev, int create)
91 int childoff, dev_off, ret = 0;
93 #ifdef CONFIG_FSL_CORENET
98 childoff = fdt_subnode_offset(blob, off, name);
102 strncpy(handle, name, sizeof(handle));
103 p = strchr(handle, '@');
104 if (!strncmp(name, "fman", 4)) {
110 dev_off = fdt_path_offset(blob, handle);
111 /* skip this node if alias is not found */
112 if (dev_off == -FDT_ERR_BADPATH)
118 childoff = fdt_add_subnode(blob, off, name);
120 /* need to update the dev_off after adding a subnode */
121 dev_off = fdt_path_offset(blob, handle);
126 dev_handle = fdt_get_phandle(blob, dev_off);
127 if (dev_handle <= 0) {
128 dev_handle = fdt_alloc_phandle(blob);
129 ret = fdt_set_phandle(blob, dev_off,
135 ret = fdt_setprop(blob, childoff, "dev-handle",
136 &dev_handle, sizeof(dev_handle));
140 #ifdef CONFIG_FSL_CORENET
141 num = get_dpaa_liodn(dev, &liodns[0], id);
142 ret = fdt_setprop(blob, childoff, "fsl,liodn",
143 &liodns[0], sizeof(u32) * num);
144 if (!strncmp(name, "pme", 3)) {
145 u32 pme_rev1, pme_rev2;
146 ccsr_pme_t *pme_regs =
147 (void *)CONFIG_SYS_FSL_CORENET_PME_ADDR;
149 pme_rev1 = in_be32(&pme_regs->pm_ip_rev_1);
150 pme_rev2 = in_be32(&pme_regs->pm_ip_rev_2);
151 ret = fdt_setprop(blob, childoff,
152 "fsl,pme-rev1", &pme_rev1,
156 ret = fdt_setprop(blob, childoff,
157 "fsl,pme-rev2", &pme_rev2,
166 ret = fdt_del_node(blob, childoff);
171 #endif /* CONFIG_PPC */
173 void fdt_fixup_qportals(void *blob)
176 unsigned int maj, min;
178 struct ccsr_qman *qman = (void *)CONFIG_SYS_FSL_QMAN_ADDR;
179 u32 rev_1 = in_be32(&qman->ip_rev_1);
180 u32 rev_2 = in_be32(&qman->ip_rev_2);
184 maj = (rev_1 >> 8) & 0xff;
186 ip_cfg = rev_2 & 0xff;
188 compat_len = sprintf(compat, "fsl,qman-portal-%u.%u.%u",
189 maj, min, ip_cfg) + 1;
190 compat_len += sprintf(compat + compat_len, "fsl,qman-portal") + 1;
192 off = fdt_node_offset_by_compatible(blob, -1, "fsl,qman-portal");
193 while (off != -FDT_ERR_NOTFOUND) {
195 #ifdef CONFIG_FSL_CORENET
198 const int *ci = fdt_getprop(blob, off, "cell-index", &err);
205 #ifdef CONFIG_SYS_DPAA_FMAN
209 #endif /* CONFIG_PPC */
210 err = fdt_setprop(blob, off, "compatible", compat, compat_len);
214 #ifdef CONFIG_FSL_CORENET
215 liodns[0] = qp_info[i].dliodn;
216 liodns[1] = qp_info[i].fliodn;
217 err = fdt_setprop(blob, off, "fsl,liodn",
218 &liodns, sizeof(u32) * 2);
225 err = fdt_qportal(blob, off, i, "crypto@0", FSL_HW_PORTAL_SEC,
226 IS_E_PROCESSOR(get_svr()));
230 #ifdef CONFIG_FSL_CORENET
231 #ifdef CONFIG_SYS_DPAA_PME
232 err = fdt_qportal(blob, off, i, "pme@0", FSL_HW_PORTAL_PME, 1);
236 fdt_qportal(blob, off, i, "pme@0", FSL_HW_PORTAL_PME, 0);
240 #ifdef CONFIG_SYS_DPAA_FMAN
241 for (j = 0; j < CONFIG_SYS_NUM_FMAN; j++) {
242 char name[] = "fman@0";
244 name[sizeof(name) - 2] = '0' + j;
245 err = fdt_qportal(blob, off, i, name,
246 FSL_HW_PORTAL_FMAN1 + j, 1);
251 #ifdef CONFIG_SYS_DPAA_RMAN
252 err = fdt_qportal(blob, off, i, "rman@0",
253 FSL_HW_PORTAL_RMAN, 1);
257 #endif /* CONFIG_PPC */
261 printf("ERROR: unable to create props for %s: %s\n",
262 fdt_get_name(blob, off, NULL),
267 off = fdt_node_offset_by_compatible(blob, off,
272 void fdt_fixup_bportals(void *blob)
275 unsigned int maj, min;
277 struct ccsr_bman *bman = (void *)CONFIG_SYS_FSL_BMAN_ADDR;
278 u32 rev_1 = in_be32(&bman->ip_rev_1);
279 u32 rev_2 = in_be32(&bman->ip_rev_2);
283 maj = (rev_1 >> 8) & 0xff;
286 ip_cfg = rev_2 & 0xff;
288 compat_len = sprintf(compat, "fsl,bman-portal-%u.%u.%u",
289 maj, min, ip_cfg) + 1;
290 compat_len += sprintf(compat + compat_len, "fsl,bman-portal") + 1;
292 off = fdt_node_offset_by_compatible(blob, -1, "fsl,bman-portal");
293 while (off != -FDT_ERR_NOTFOUND) {
294 err = fdt_setprop(blob, off, "compatible", compat, compat_len);
296 printf("ERROR: unable to create props for %s: %s\n",
297 fdt_get_name(blob, off, NULL),
302 off = fdt_node_offset_by_compatible(blob, off,