1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2008-2011 Freescale Semiconductor, Inc.
8 #include <linux/libfdt.h>
9 #include <fdt_support.h>
11 #include <asm/processor.h>
14 #include <asm/fsl_portals.h>
15 #include <asm/fsl_liodn.h>
17 #include <fsl_qbman.h>
19 #define MAX_BPORTALS (CONFIG_SYS_BMAN_CINH_SIZE / CONFIG_SYS_BMAN_SP_CINH_SIZE)
20 #define MAX_QPORTALS (CONFIG_SYS_QMAN_CINH_SIZE / CONFIG_SYS_QMAN_SP_CINH_SIZE)
21 void setup_qbman_portals(void)
23 void __iomem *bpaddr = (void *)CONFIG_SYS_BMAN_CINH_BASE +
24 CONFIG_SYS_BMAN_SWP_ISDR_REG;
25 void __iomem *qpaddr = (void *)CONFIG_SYS_QMAN_CINH_BASE +
26 CONFIG_SYS_QMAN_SWP_ISDR_REG;
28 struct ccsr_qman *qman = (void *)CONFIG_SYS_FSL_QMAN_ADDR;
30 /* Set the Qman initiator BAR to match the LAW (for DQRR stashing) */
31 #ifdef CONFIG_PHYS_64BIT
32 out_be32(&qman->qcsp_bare, (u32)(CONFIG_SYS_QMAN_MEM_PHYS >> 32));
34 out_be32(&qman->qcsp_bar, (u32)CONFIG_SYS_QMAN_MEM_PHYS);
36 #ifdef CONFIG_FSL_CORENET
39 for (i = 0; i < CONFIG_SYS_QMAN_NUM_PORTALS; i++) {
40 u8 sdest = qp_info[i].sdest;
41 u16 fliodn = qp_info[i].fliodn;
42 u16 dliodn = qp_info[i].dliodn;
43 u16 liodn_off = qp_info[i].liodn_offset;
45 out_be32(&qman->qcsp[i].qcsp_lio_cfg, (liodn_off << 16) |
48 out_be32(&qman->qcsp[i].qcsp_io_cfg, (sdest << 16) | fliodn);
52 /* Change default state of BMan ISDR portals to all 1s */
53 inhibit_portals(bpaddr, CONFIG_SYS_BMAN_NUM_PORTALS, MAX_BPORTALS,
54 CONFIG_SYS_BMAN_SP_CINH_SIZE);
55 inhibit_portals(qpaddr, CONFIG_SYS_QMAN_NUM_PORTALS, MAX_QPORTALS,
56 CONFIG_SYS_QMAN_SP_CINH_SIZE);
59 void inhibit_portals(void __iomem *addr, int max_portals,
60 int arch_max_portals, int portal_cinh_size)
65 /* arch_max_portals is the maximum based on memory size. This includes
66 * the reserved memory in the SoC. max_portals the number of physical
69 if (max_portals > arch_max_portals) {
70 printf("ERROR: portal config error\n");
71 max_portals = arch_max_portals;
74 for (i = 0; i < max_portals; i++) {
78 printf("ERROR: Stopped after %d portals\n", i);
81 addr += portal_cinh_size;
83 debug("Cleared %d portals\n", i);
87 static int fdt_qportal(void *blob, int off, int id, char *name,
88 enum fsl_dpaa_dev dev, int create)
90 int childoff, dev_off, ret = 0;
92 #ifdef CONFIG_FSL_CORENET
97 childoff = fdt_subnode_offset(blob, off, name);
101 strncpy(handle, name, sizeof(handle));
102 p = strchr(handle, '@');
103 if (!strncmp(name, "fman", 4)) {
109 dev_off = fdt_path_offset(blob, handle);
110 /* skip this node if alias is not found */
111 if (dev_off == -FDT_ERR_BADPATH)
117 childoff = fdt_add_subnode(blob, off, name);
119 /* need to update the dev_off after adding a subnode */
120 dev_off = fdt_path_offset(blob, handle);
125 dev_handle = fdt_get_phandle(blob, dev_off);
126 if (dev_handle <= 0) {
127 dev_handle = fdt_alloc_phandle(blob);
128 ret = fdt_set_phandle(blob, dev_off,
134 ret = fdt_setprop(blob, childoff, "dev-handle",
135 &dev_handle, sizeof(dev_handle));
139 #ifdef CONFIG_FSL_CORENET
140 num = get_dpaa_liodn(dev, &liodns[0], id);
141 ret = fdt_setprop(blob, childoff, "fsl,liodn",
142 &liodns[0], sizeof(u32) * num);
143 if (!strncmp(name, "pme", 3)) {
144 u32 pme_rev1, pme_rev2;
145 ccsr_pme_t *pme_regs =
146 (void *)CONFIG_SYS_FSL_CORENET_PME_ADDR;
148 pme_rev1 = in_be32(&pme_regs->pm_ip_rev_1);
149 pme_rev2 = in_be32(&pme_regs->pm_ip_rev_2);
150 ret = fdt_setprop(blob, childoff,
151 "fsl,pme-rev1", &pme_rev1,
155 ret = fdt_setprop(blob, childoff,
156 "fsl,pme-rev2", &pme_rev2,
165 ret = fdt_del_node(blob, childoff);
170 #endif /* CONFIG_PPC */
172 void fdt_fixup_qportals(void *blob)
175 unsigned int maj, min;
177 struct ccsr_qman *qman = (void *)CONFIG_SYS_FSL_QMAN_ADDR;
178 u32 rev_1 = in_be32(&qman->ip_rev_1);
179 u32 rev_2 = in_be32(&qman->ip_rev_2);
183 maj = (rev_1 >> 8) & 0xff;
185 ip_cfg = rev_2 & 0xff;
187 compat_len = sprintf(compat, "fsl,qman-portal-%u.%u.%u",
188 maj, min, ip_cfg) + 1;
189 compat_len += sprintf(compat + compat_len, "fsl,qman-portal") + 1;
191 off = fdt_node_offset_by_compatible(blob, -1, "fsl,qman-portal");
192 while (off != -FDT_ERR_NOTFOUND) {
194 #ifdef CONFIG_FSL_CORENET
197 const int *ci = fdt_getprop(blob, off, "cell-index", &err);
204 #ifdef CONFIG_SYS_DPAA_FMAN
208 #endif /* CONFIG_PPC */
209 err = fdt_setprop(blob, off, "compatible", compat, compat_len);
213 #ifdef CONFIG_FSL_CORENET
214 liodns[0] = qp_info[i].dliodn;
215 liodns[1] = qp_info[i].fliodn;
216 err = fdt_setprop(blob, off, "fsl,liodn",
217 &liodns, sizeof(u32) * 2);
224 err = fdt_qportal(blob, off, i, "crypto@0", FSL_HW_PORTAL_SEC,
225 IS_E_PROCESSOR(get_svr()));
229 #ifdef CONFIG_FSL_CORENET
230 #ifdef CONFIG_SYS_DPAA_PME
231 err = fdt_qportal(blob, off, i, "pme@0", FSL_HW_PORTAL_PME, 1);
235 fdt_qportal(blob, off, i, "pme@0", FSL_HW_PORTAL_PME, 0);
239 #ifdef CONFIG_SYS_DPAA_FMAN
240 for (j = 0; j < CONFIG_SYS_NUM_FMAN; j++) {
241 char name[] = "fman@0";
243 name[sizeof(name) - 2] = '0' + j;
244 err = fdt_qportal(blob, off, i, name,
245 FSL_HW_PORTAL_FMAN1 + j, 1);
250 #ifdef CONFIG_SYS_DPAA_RMAN
251 err = fdt_qportal(blob, off, i, "rman@0",
252 FSL_HW_PORTAL_RMAN, 1);
256 #endif /* CONFIG_PPC */
260 printf("ERROR: unable to create props for %s: %s\n",
261 fdt_get_name(blob, off, NULL),
266 off = fdt_node_offset_by_compatible(blob, off,
271 void fdt_fixup_bportals(void *blob)
274 unsigned int maj, min;
276 struct ccsr_bman *bman = (void *)CONFIG_SYS_FSL_BMAN_ADDR;
277 u32 rev_1 = in_be32(&bman->ip_rev_1);
278 u32 rev_2 = in_be32(&bman->ip_rev_2);
282 maj = (rev_1 >> 8) & 0xff;
285 ip_cfg = rev_2 & 0xff;
287 compat_len = sprintf(compat, "fsl,bman-portal-%u.%u.%u",
288 maj, min, ip_cfg) + 1;
289 compat_len += sprintf(compat + compat_len, "fsl,bman-portal") + 1;
291 off = fdt_node_offset_by_compatible(blob, -1, "fsl,bman-portal");
292 while (off != -FDT_ERR_NOTFOUND) {
293 err = fdt_setprop(blob, off, "compatible", compat, compat_len);
295 printf("ERROR: unable to create props for %s: %s\n",
296 fdt_get_name(blob, off, NULL),
301 off = fdt_node_offset_by_compatible(blob, off,