blob: 22faf16751eb202ea806bc1d3f30dda4366fa5d9 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Ahmed Mansour44262322017-12-15 16:01:00 -05002/*
3 * Copyright 2008-2011 Freescale Semiconductor, Inc.
4 * Copyright 2017 NXP
Ahmed Mansour44262322017-12-15 16:01:00 -05005 */
6
7#include <common.h>
Masahiro Yamadab08c8c42018-03-05 01:20:11 +09008#include <linux/libfdt.h>
Ahmed Mansour44262322017-12-15 16:01:00 -05009#include <fdt_support.h>
10
11#include <asm/processor.h>
12#include <asm/io.h>
13#ifdef CONFIG_PPC
14#include <asm/fsl_portals.h>
15#include <asm/fsl_liodn.h>
16#endif
17#include <fsl_qbman.h>
18
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)
21void setup_qbman_portals(void)
22{
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;
Ahmed Mansour44262322017-12-15 16:01:00 -050027 struct ccsr_qman *qman = (void *)CONFIG_SYS_FSL_QMAN_ADDR;
28
29 /* Set the Qman initiator BAR to match the LAW (for DQRR stashing) */
30#ifdef CONFIG_PHYS_64BIT
31 out_be32(&qman->qcsp_bare, (u32)(CONFIG_SYS_QMAN_MEM_PHYS >> 32));
32#endif
33 out_be32(&qman->qcsp_bar, (u32)CONFIG_SYS_QMAN_MEM_PHYS);
Ahmed Mansour44262322017-12-15 16:01:00 -050034#ifdef CONFIG_FSL_CORENET
35 int i;
36
37 for (i = 0; i < CONFIG_SYS_QMAN_NUM_PORTALS; i++) {
38 u8 sdest = qp_info[i].sdest;
39 u16 fliodn = qp_info[i].fliodn;
40 u16 dliodn = qp_info[i].dliodn;
41 u16 liodn_off = qp_info[i].liodn_offset;
42
43 out_be32(&qman->qcsp[i].qcsp_lio_cfg, (liodn_off << 16) |
44 dliodn);
45 /* set frame liodn */
46 out_be32(&qman->qcsp[i].qcsp_io_cfg, (sdest << 16) | fliodn);
47 }
48#endif
49
50 /* Change default state of BMan ISDR portals to all 1s */
51 inhibit_portals(bpaddr, CONFIG_SYS_BMAN_NUM_PORTALS, MAX_BPORTALS,
52 CONFIG_SYS_BMAN_SP_CINH_SIZE);
53 inhibit_portals(qpaddr, CONFIG_SYS_QMAN_NUM_PORTALS, MAX_QPORTALS,
54 CONFIG_SYS_QMAN_SP_CINH_SIZE);
55}
56
57void inhibit_portals(void __iomem *addr, int max_portals,
58 int arch_max_portals, int portal_cinh_size)
59{
60 u32 val;
61 int i;
62
63 /* arch_max_portals is the maximum based on memory size. This includes
64 * the reserved memory in the SoC. max_portals the number of physical
65 * portals in the SoC
66 */
67 if (max_portals > arch_max_portals) {
68 printf("ERROR: portal config error\n");
69 max_portals = arch_max_portals;
70 }
71
72 for (i = 0; i < max_portals; i++) {
73 out_be32(addr, -1);
74 val = in_be32(addr);
75 if (!val) {
76 printf("ERROR: Stopped after %d portals\n", i);
77 return;
78 }
79 addr += portal_cinh_size;
80 }
81 debug("Cleared %d portals\n", i);
82}
83
84#ifdef CONFIG_PPC
85static int fdt_qportal(void *blob, int off, int id, char *name,
86 enum fsl_dpaa_dev dev, int create)
87{
88 int childoff, dev_off, ret = 0;
89 u32 dev_handle;
90#ifdef CONFIG_FSL_CORENET
91 int num;
92 u32 liodns[2];
93#endif
94
95 childoff = fdt_subnode_offset(blob, off, name);
96 if (create) {
97 char handle[64], *p;
98
99 strncpy(handle, name, sizeof(handle));
100 p = strchr(handle, '@');
101 if (!strncmp(name, "fman", 4)) {
102 *p = *(p + 1);
103 p++;
104 }
105 *p = '\0';
106
107 dev_off = fdt_path_offset(blob, handle);
108 /* skip this node if alias is not found */
109 if (dev_off == -FDT_ERR_BADPATH)
110 return 0;
111 if (dev_off < 0)
112 return dev_off;
113
114 if (childoff <= 0)
115 childoff = fdt_add_subnode(blob, off, name);
116
117 /* need to update the dev_off after adding a subnode */
118 dev_off = fdt_path_offset(blob, handle);
119 if (dev_off < 0)
120 return dev_off;
121
122 if (childoff > 0) {
123 dev_handle = fdt_get_phandle(blob, dev_off);
124 if (dev_handle <= 0) {
125 dev_handle = fdt_alloc_phandle(blob);
126 ret = fdt_set_phandle(blob, dev_off,
127 dev_handle);
128 if (ret < 0)
129 return ret;
130 }
131
132 ret = fdt_setprop(blob, childoff, "dev-handle",
133 &dev_handle, sizeof(dev_handle));
134 if (ret < 0)
135 return ret;
136
137#ifdef CONFIG_FSL_CORENET
138 num = get_dpaa_liodn(dev, &liodns[0], id);
139 ret = fdt_setprop(blob, childoff, "fsl,liodn",
140 &liodns[0], sizeof(u32) * num);
141 if (!strncmp(name, "pme", 3)) {
142 u32 pme_rev1, pme_rev2;
143 ccsr_pme_t *pme_regs =
144 (void *)CONFIG_SYS_FSL_CORENET_PME_ADDR;
145
146 pme_rev1 = in_be32(&pme_regs->pm_ip_rev_1);
147 pme_rev2 = in_be32(&pme_regs->pm_ip_rev_2);
148 ret = fdt_setprop(blob, childoff,
149 "fsl,pme-rev1", &pme_rev1,
150 sizeof(u32));
151 if (ret < 0)
152 return ret;
153 ret = fdt_setprop(blob, childoff,
154 "fsl,pme-rev2", &pme_rev2,
155 sizeof(u32));
156 }
157#endif
158 } else {
159 return childoff;
160 }
161 } else {
162 if (childoff > 0)
163 ret = fdt_del_node(blob, childoff);
164 }
165
166 return ret;
167}
168#endif /* CONFIG_PPC */
169
170void fdt_fixup_qportals(void *blob)
171{
172 int off, err;
173 unsigned int maj, min;
174 unsigned int ip_cfg;
175 struct ccsr_qman *qman = (void *)CONFIG_SYS_FSL_QMAN_ADDR;
176 u32 rev_1 = in_be32(&qman->ip_rev_1);
177 u32 rev_2 = in_be32(&qman->ip_rev_2);
178 char compat[64];
179 int compat_len;
180
181 maj = (rev_1 >> 8) & 0xff;
182 min = rev_1 & 0xff;
183 ip_cfg = rev_2 & 0xff;
184
185 compat_len = sprintf(compat, "fsl,qman-portal-%u.%u.%u",
186 maj, min, ip_cfg) + 1;
187 compat_len += sprintf(compat + compat_len, "fsl,qman-portal") + 1;
188
189 off = fdt_node_offset_by_compatible(blob, -1, "fsl,qman-portal");
190 while (off != -FDT_ERR_NOTFOUND) {
191#ifdef CONFIG_PPC
192#ifdef CONFIG_FSL_CORENET
193 u32 liodns[2];
194#endif
195 const int *ci = fdt_getprop(blob, off, "cell-index", &err);
196 int i;
197
198 if (!ci)
199 goto err;
200
201 i = *ci;
202#ifdef CONFIG_SYS_DPAA_FMAN
203 int j;
204#endif
205
206#endif /* CONFIG_PPC */
207 err = fdt_setprop(blob, off, "compatible", compat, compat_len);
208 if (err < 0)
209 goto err;
210#ifdef CONFIG_PPC
211#ifdef CONFIG_FSL_CORENET
212 liodns[0] = qp_info[i].dliodn;
213 liodns[1] = qp_info[i].fliodn;
214 err = fdt_setprop(blob, off, "fsl,liodn",
215 &liodns, sizeof(u32) * 2);
216 if (err < 0)
217 goto err;
218#endif
219
220 i++;
221
222 err = fdt_qportal(blob, off, i, "crypto@0", FSL_HW_PORTAL_SEC,
223 IS_E_PROCESSOR(get_svr()));
224 if (err < 0)
225 goto err;
226
227#ifdef CONFIG_FSL_CORENET
228#ifdef CONFIG_SYS_DPAA_PME
229 err = fdt_qportal(blob, off, i, "pme@0", FSL_HW_PORTAL_PME, 1);
230 if (err < 0)
231 goto err;
232#else
233 fdt_qportal(blob, off, i, "pme@0", FSL_HW_PORTAL_PME, 0);
234#endif
235#endif
236
237#ifdef CONFIG_SYS_DPAA_FMAN
238 for (j = 0; j < CONFIG_SYS_NUM_FMAN; j++) {
239 char name[] = "fman@0";
240
241 name[sizeof(name) - 2] = '0' + j;
242 err = fdt_qportal(blob, off, i, name,
243 FSL_HW_PORTAL_FMAN1 + j, 1);
244 if (err < 0)
245 goto err;
246 }
247#endif
248#ifdef CONFIG_SYS_DPAA_RMAN
249 err = fdt_qportal(blob, off, i, "rman@0",
250 FSL_HW_PORTAL_RMAN, 1);
251 if (err < 0)
252 goto err;
253#endif
254#endif /* CONFIG_PPC */
255
256err:
257 if (err < 0) {
258 printf("ERROR: unable to create props for %s: %s\n",
259 fdt_get_name(blob, off, NULL),
260 fdt_strerror(err));
261 return;
262 }
263
264 off = fdt_node_offset_by_compatible(blob, off,
265 "fsl,qman-portal");
266 }
267}
268
269void fdt_fixup_bportals(void *blob)
270{
271 int off, err;
272 unsigned int maj, min;
273 unsigned int ip_cfg;
274 struct ccsr_bman *bman = (void *)CONFIG_SYS_FSL_BMAN_ADDR;
275 u32 rev_1 = in_be32(&bman->ip_rev_1);
276 u32 rev_2 = in_be32(&bman->ip_rev_2);
277 char compat[64];
278 int compat_len;
279
280 maj = (rev_1 >> 8) & 0xff;
281 min = rev_1 & 0xff;
282
283 ip_cfg = rev_2 & 0xff;
284
285 compat_len = sprintf(compat, "fsl,bman-portal-%u.%u.%u",
286 maj, min, ip_cfg) + 1;
287 compat_len += sprintf(compat + compat_len, "fsl,bman-portal") + 1;
288
289 off = fdt_node_offset_by_compatible(blob, -1, "fsl,bman-portal");
290 while (off != -FDT_ERR_NOTFOUND) {
291 err = fdt_setprop(blob, off, "compatible", compat, compat_len);
292 if (err < 0) {
293 printf("ERROR: unable to create props for %s: %s\n",
294 fdt_get_name(blob, off, NULL),
295 fdt_strerror(err));
296 return;
297 }
298
299 off = fdt_node_offset_by_compatible(blob, off,
300 "fsl,bman-portal");
301 }
302}