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 <asm/arch-fsl-layerscape/fsl_portals.h>
18 #include <asm/arch-fsl-layerscape/fsl_icid.h>
20 #include <fsl_qbman.h>
22 #define MAX_BPORTALS (CONFIG_SYS_BMAN_CINH_SIZE / CONFIG_SYS_BMAN_SP_CINH_SIZE)
23 #define MAX_QPORTALS (CONFIG_SYS_QMAN_CINH_SIZE / CONFIG_SYS_QMAN_SP_CINH_SIZE)
24 void setup_qbman_portals(void)
26 void __iomem *bpaddr = (void *)CONFIG_SYS_BMAN_CINH_BASE +
27 CONFIG_SYS_BMAN_SWP_ISDR_REG;
28 void __iomem *qpaddr = (void *)CONFIG_SYS_QMAN_CINH_BASE +
29 CONFIG_SYS_QMAN_SWP_ISDR_REG;
30 struct ccsr_qman *qman = (void *)CONFIG_SYS_FSL_QMAN_ADDR;
32 /* Set the Qman initiator BAR to match the LAW (for DQRR stashing) */
33 #ifdef CONFIG_PHYS_64BIT
34 out_be32(&qman->qcsp_bare, (u32)(CONFIG_SYS_QMAN_MEM_PHYS >> 32));
36 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);
52 #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
55 for (i = 0; i < CONFIG_SYS_QMAN_NUM_PORTALS; i++) {
56 u8 sdest = qp_info[i].sdest;
57 u16 ficid = qp_info[i].ficid;
58 u16 dicid = qp_info[i].dicid;
59 u16 icid = qp_info[i].icid;
61 out_be32(&qman->qcsp[i].qcsp_lio_cfg, (icid << 16) |
64 out_be32(&qman->qcsp[i].qcsp_io_cfg, (sdest << 16) | ficid);
69 /* Change default state of BMan ISDR portals to all 1s */
70 inhibit_portals(bpaddr, CONFIG_SYS_BMAN_NUM_PORTALS, MAX_BPORTALS,
71 CONFIG_SYS_BMAN_SP_CINH_SIZE);
72 inhibit_portals(qpaddr, CONFIG_SYS_QMAN_NUM_PORTALS, MAX_QPORTALS,
73 CONFIG_SYS_QMAN_SP_CINH_SIZE);
76 void inhibit_portals(void __iomem *addr, int max_portals,
77 int arch_max_portals, int portal_cinh_size)
82 /* arch_max_portals is the maximum based on memory size. This includes
83 * the reserved memory in the SoC. max_portals the number of physical
86 if (max_portals > arch_max_portals) {
87 printf("ERROR: portal config error\n");
88 max_portals = arch_max_portals;
91 for (i = 0; i < max_portals; i++) {
95 printf("ERROR: Stopped after %d portals\n", i);
98 addr += portal_cinh_size;
100 debug("Cleared %d portals\n", i);
104 static int fdt_qportal(void *blob, int off, int id, char *name,
105 enum fsl_dpaa_dev dev, int create)
107 int childoff, dev_off, ret = 0;
109 #ifdef CONFIG_FSL_CORENET
114 childoff = fdt_subnode_offset(blob, off, name);
118 strncpy(handle, name, sizeof(handle));
119 p = strchr(handle, '@');
120 if (!strncmp(name, "fman", 4)) {
126 dev_off = fdt_path_offset(blob, handle);
127 /* skip this node if alias is not found */
128 if (dev_off == -FDT_ERR_BADPATH)
134 childoff = fdt_add_subnode(blob, off, name);
136 /* need to update the dev_off after adding a subnode */
137 dev_off = fdt_path_offset(blob, handle);
142 dev_handle = fdt_get_phandle(blob, dev_off);
143 if (dev_handle <= 0) {
144 dev_handle = fdt_alloc_phandle(blob);
145 ret = fdt_set_phandle(blob, dev_off,
151 ret = fdt_setprop(blob, childoff, "dev-handle",
152 &dev_handle, sizeof(dev_handle));
156 #ifdef CONFIG_FSL_CORENET
157 num = get_dpaa_liodn(dev, &liodns[0], id);
158 ret = fdt_setprop(blob, childoff, "fsl,liodn",
159 &liodns[0], sizeof(u32) * num);
160 if (!strncmp(name, "pme", 3)) {
161 u32 pme_rev1, pme_rev2;
162 ccsr_pme_t *pme_regs =
163 (void *)CONFIG_SYS_FSL_CORENET_PME_ADDR;
165 pme_rev1 = in_be32(&pme_regs->pm_ip_rev_1);
166 pme_rev2 = in_be32(&pme_regs->pm_ip_rev_2);
167 ret = fdt_setprop(blob, childoff,
168 "fsl,pme-rev1", &pme_rev1,
172 ret = fdt_setprop(blob, childoff,
173 "fsl,pme-rev2", &pme_rev2,
182 ret = fdt_del_node(blob, childoff);
187 #endif /* CONFIG_PPC */
189 void fdt_fixup_qportals(void *blob)
192 unsigned int maj, min;
194 struct ccsr_qman *qman = (void *)CONFIG_SYS_FSL_QMAN_ADDR;
195 u32 rev_1 = in_be32(&qman->ip_rev_1);
196 u32 rev_2 = in_be32(&qman->ip_rev_2);
200 #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
201 int smmu_ph = fdt_get_smmu_phandle(blob);
204 maj = (rev_1 >> 8) & 0xff;
206 ip_cfg = rev_2 & 0xff;
208 compat_len = sprintf(compat, "fsl,qman-portal-%u.%u.%u",
209 maj, min, ip_cfg) + 1;
210 compat_len += sprintf(compat + compat_len, "fsl,qman-portal") + 1;
212 off = fdt_node_offset_by_compatible(blob, -1, "fsl,qman-portal");
213 while (off != -FDT_ERR_NOTFOUND) {
214 #if defined(CONFIG_PPC) || defined(CONFIG_ARCH_LS1043A) || \
215 defined(CONFIG_ARCH_LS1046A)
216 #ifdef CONFIG_FSL_CORENET
219 const int *ci = fdt_getprop(blob, off, "cell-index", &err);
225 i = fdt32_to_cpu(*ci);
226 #if defined(CONFIG_SYS_DPAA_FMAN) && defined(CONFIG_PPC)
230 #endif /* CONFIG_PPC || CONFIG_ARCH_LS1043A || CONFIG_ARCH_LS1046A */
231 err = fdt_setprop(blob, off, "compatible", compat, compat_len);
235 #ifdef CONFIG_FSL_CORENET
236 liodns[0] = qp_info[i].dliodn;
237 liodns[1] = qp_info[i].fliodn;
238 err = fdt_setprop(blob, off, "fsl,liodn",
239 &liodns, sizeof(u32) * 2);
246 err = fdt_qportal(blob, off, i, "crypto@0", FSL_HW_PORTAL_SEC,
247 IS_E_PROCESSOR(get_svr()));
251 #ifdef CONFIG_FSL_CORENET
252 #ifdef CONFIG_SYS_DPAA_PME
253 err = fdt_qportal(blob, off, i, "pme@0", FSL_HW_PORTAL_PME, 1);
257 fdt_qportal(blob, off, i, "pme@0", FSL_HW_PORTAL_PME, 0);
261 #ifdef CONFIG_SYS_DPAA_FMAN
262 for (j = 0; j < CONFIG_SYS_NUM_FMAN; j++) {
263 char name[] = "fman@0";
265 name[sizeof(name) - 2] = '0' + j;
266 err = fdt_qportal(blob, off, i, name,
267 FSL_HW_PORTAL_FMAN1 + j, 1);
272 #ifdef CONFIG_SYS_DPAA_RMAN
273 err = fdt_qportal(blob, off, i, "rman@0",
274 FSL_HW_PORTAL_RMAN, 1);
279 #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
283 icids[0] = qp_info[i].icid;
284 icids[1] = qp_info[i].dicid;
285 icids[2] = qp_info[i].ficid;
287 fdt_set_iommu_prop(blob, off, smmu_ph, icids, 3);
290 #endif /* CONFIG_PPC */
294 printf("ERROR: unable to create props for %s: %s\n",
295 fdt_get_name(blob, off, NULL),
300 off = fdt_node_offset_by_compatible(blob, off,
305 void fdt_fixup_bportals(void *blob)
308 unsigned int maj, min;
310 struct ccsr_bman *bman = (void *)CONFIG_SYS_FSL_BMAN_ADDR;
311 u32 rev_1 = in_be32(&bman->ip_rev_1);
312 u32 rev_2 = in_be32(&bman->ip_rev_2);
316 maj = (rev_1 >> 8) & 0xff;
319 ip_cfg = rev_2 & 0xff;
321 compat_len = sprintf(compat, "fsl,bman-portal-%u.%u.%u",
322 maj, min, ip_cfg) + 1;
323 compat_len += sprintf(compat + compat_len, "fsl,bman-portal") + 1;
325 off = fdt_node_offset_by_compatible(blob, -1, "fsl,bman-portal");
326 while (off != -FDT_ERR_NOTFOUND) {
327 err = fdt_setprop(blob, off, "compatible", compat, compat_len);
329 printf("ERROR: unable to create props for %s: %s\n",
330 fdt_get_name(blob, off, NULL),
335 off = fdt_node_offset_by_compatible(blob, off,