blob: 98815f8e1e9fc9c92a7091f0066ebcdfdd4d464f [file] [log] [blame]
Kumar Galadb977ab2009-09-10 03:02:13 -05001/*
Haiying Wang24995d82011-01-20 22:26:31 +00002 * Copyright 2008-2011 Freescale Semiconductor, Inc.
Kumar Galadb977ab2009-09-10 03:02:13 -05003 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02004 * SPDX-License-Identifier: GPL-2.0+
Kumar Galadb977ab2009-09-10 03:02:13 -05005 */
6
7#include <common.h>
8#include <libfdt.h>
9#include <fdt_support.h>
10
11#include <asm/processor.h>
12#include <asm/io.h>
13
14#include <asm/fsl_portals.h>
15#include <asm/fsl_liodn.h>
16
Kumar Galadb977ab2009-09-10 03:02:13 -050017void setup_portals(void)
18{
Jeffrey Ladouceur3c1bfc02013-01-25 10:38:53 +000019 ccsr_qman_t *qman = (void *)CONFIG_SYS_FSL_QMAN_ADDR;
Haiying Wang24995d82011-01-20 22:26:31 +000020#ifdef CONFIG_FSL_CORENET
Kumar Galadb977ab2009-09-10 03:02:13 -050021 int i;
22
Kumar Galadb977ab2009-09-10 03:02:13 -050023 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;
28
29 out_be32(&qman->qcsp[i].qcsp_lio_cfg, (liodn_off << 16) |
30 dliodn);
31 /* set frame liodn */
32 out_be32(&qman->qcsp[i].qcsp_io_cfg, (sdest << 16) | fliodn);
33 }
Haiying Wang24995d82011-01-20 22:26:31 +000034#endif
35
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));
39#endif
40 out_be32(&qman->qcsp_bar, (u32)CONFIG_SYS_QMAN_MEM_PHYS);
Kumar Galadb977ab2009-09-10 03:02:13 -050041}
42
43/* Update portal containter to match LAW setup of portal in phy map */
44void fdt_portal(void *blob, const char *compat, const char *container,
45 u64 addr, u32 size)
46{
47 int off;
48
49 off = fdt_node_offset_by_compatible(blob, -1, compat);
50 if (off < 0)
51 return ;
52
53 off = fdt_parent_offset(blob, off);
54 /* if non-zero assume we have a container */
55 if (off > 0) {
56 char buf[60];
57 const char *p, *name;
58 u32 *range;
59 int len;
60
61 /* fixup ranges */
62 range = fdt_getprop_w(blob, off, "ranges", &len);
63 if (range == NULL) {
64 printf("ERROR: container for %s has no ranges", compat);
65 return ;
66 }
67
68 range[0] = 0;
69 if (len == 16) {
70 range[1] = addr >> 32;
71 range[2] = addr & 0xffffffff;
72 range[3] = size;
73 } else {
74 range[1] = addr & 0xffffffff;
75 range[2] = size;
76 }
77 fdt_setprop_inplace(blob, off, "ranges", range, len);
78
79 /* fixup the name */
80 name = fdt_get_name(blob, off, &len);
81 p = memchr(name, '@', len);
82
83 if (p)
84 len = p - name;
85
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",
90 container, name);
91 return ;
92 }
93
94 memcpy(&buf, name, len);
95 len += sprintf(&buf[len], "@%llx", addr);
96 fdt_set_name(blob, off, buf);
97 return ;
98 }
99
100 printf("ERROR: %s isn't in a container. Not supported\n", compat);
101}
102
103static int fdt_qportal(void *blob, int off, int id, char *name,
104 enum fsl_dpaa_dev dev, int create)
105{
Haiying Wang24995d82011-01-20 22:26:31 +0000106 int childoff, dev_off, ret = 0;
Kumar Galadb977ab2009-09-10 03:02:13 -0500107 uint32_t dev_handle;
Haiying Wang24995d82011-01-20 22:26:31 +0000108#ifdef CONFIG_FSL_CORENET
109 int num;
Kumar Galadb977ab2009-09-10 03:02:13 -0500110 u32 liodns[2];
Haiying Wang24995d82011-01-20 22:26:31 +0000111#endif
Kumar Galadb977ab2009-09-10 03:02:13 -0500112
113 childoff = fdt_subnode_offset(blob, off, name);
114 if (create) {
York Sune1d5a272013-03-25 07:33:21 +0000115 char handle[64], *p;
116
117 strncpy(handle, name, sizeof(handle));
118 p = strchr(handle, '@');
119 if (!strncmp(name, "fman", 4)) {
120 *p = *(p + 1);
121 p++;
122 }
123 *p = '\0';
124
125 dev_off = fdt_path_offset(blob, handle);
126 /* skip this node if alias is not found */
127 if (dev_off == -FDT_ERR_BADPATH)
128 return 0;
129 if (dev_off < 0)
130 return dev_off;
131
Kumar Galadb977ab2009-09-10 03:02:13 -0500132 if (childoff <= 0)
133 childoff = fdt_add_subnode(blob, off, name);
134
York Sune1d5a272013-03-25 07:33:21 +0000135 /* need to update the dev_off after adding a subnode */
136 dev_off = fdt_path_offset(blob, handle);
137 if (dev_off < 0)
138 return dev_off;
139
Kumar Galadb977ab2009-09-10 03:02:13 -0500140 if (childoff > 0) {
Kumar Galadb977ab2009-09-10 03:02:13 -0500141 dev_handle = fdt_get_phandle(blob, dev_off);
142 if (dev_handle <= 0) {
143 dev_handle = fdt_alloc_phandle(blob);
Kumar Galaf117c0f2011-08-01 00:23:23 -0500144 ret = fdt_set_phandle(blob, dev_off,
Timur Tabie4e7e422011-05-10 15:28:14 -0500145 dev_handle);
146 if (ret < 0)
147 return ret;
Kumar Galadb977ab2009-09-10 03:02:13 -0500148 }
149
150 ret = fdt_setprop(blob, childoff, "dev-handle",
151 &dev_handle, sizeof(dev_handle));
152 if (ret < 0)
153 return ret;
154
Haiying Wang24995d82011-01-20 22:26:31 +0000155#ifdef CONFIG_FSL_CORENET
Kumar Galadb977ab2009-09-10 03:02:13 -0500156 num = get_dpaa_liodn(dev, &liodns[0], id);
157 ret = fdt_setprop(blob, childoff, "fsl,liodn",
158 &liodns[0], sizeof(u32) * num);
Jeffrey Ladouceur3c1bfc02013-01-25 10:38:53 +0000159 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;
163
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));
168 if (ret < 0)
169 return ret;
170 ret = fdt_setprop(blob, childoff,
171 "fsl,pme-rev2", &pme_rev2, sizeof(u32));
172 }
Haiying Wang24995d82011-01-20 22:26:31 +0000173#endif
Kumar Galadb977ab2009-09-10 03:02:13 -0500174 } else {
175 return childoff;
176 }
177 } else {
178 if (childoff > 0)
179 ret = fdt_del_node(blob, childoff);
180 }
181
182 return ret;
183}
184
185void fdt_fixup_qportals(void *blob)
186{
187 int off, err;
188 unsigned int maj, min;
Haiying Wangb0e81152012-10-11 07:13:38 +0000189 unsigned int ip_cfg;
Jeffrey Ladouceur3c1bfc02013-01-25 10:38:53 +0000190 ccsr_qman_t *qman = (void *)CONFIG_SYS_FSL_QMAN_ADDR;
Kumar Galadb977ab2009-09-10 03:02:13 -0500191 u32 rev_1 = in_be32(&qman->ip_rev_1);
Haiying Wangb0e81152012-10-11 07:13:38 +0000192 u32 rev_2 = in_be32(&qman->ip_rev_2);
Kumar Galadb977ab2009-09-10 03:02:13 -0500193 char compat[64];
194 int compat_len;
195
196 maj = (rev_1 >> 8) & 0xff;
197 min = rev_1 & 0xff;
Haiying Wangb0e81152012-10-11 07:13:38 +0000198 ip_cfg = rev_2 & 0xff;
Kumar Galadb977ab2009-09-10 03:02:13 -0500199
Haiying Wangb0e81152012-10-11 07:13:38 +0000200 compat_len = sprintf(compat, "fsl,qman-portal-%u.%u.%u",
201 maj, min, ip_cfg) + 1;
Kumar Galadb977ab2009-09-10 03:02:13 -0500202 compat_len += sprintf(compat + compat_len, "fsl,qman-portal") + 1;
203
204 off = fdt_node_offset_by_compatible(blob, -1, "fsl,qman-portal");
205 while (off != -FDT_ERR_NOTFOUND) {
Haiying Wang24995d82011-01-20 22:26:31 +0000206#ifdef CONFIG_FSL_CORENET
Kumar Galadb977ab2009-09-10 03:02:13 -0500207 u32 liodns[2];
Haiying Wang24995d82011-01-20 22:26:31 +0000208#endif
Kumar Galadb977ab2009-09-10 03:02:13 -0500209 const int *ci = fdt_getprop(blob, off, "cell-index", NULL);
Kumar Galae2d0f252011-07-31 12:55:39 -0500210 int i = *ci;
211#ifdef CONFIG_SYS_DPAA_FMAN
212 int j;
213#endif
Kumar Galadb977ab2009-09-10 03:02:13 -0500214
215 err = fdt_setprop(blob, off, "compatible", compat, compat_len);
216 if (err < 0)
217 goto err;
218
Haiying Wang24995d82011-01-20 22:26:31 +0000219#ifdef CONFIG_FSL_CORENET
Kumar Galadb977ab2009-09-10 03:02:13 -0500220 liodns[0] = qp_info[i].dliodn;
221 liodns[1] = qp_info[i].fliodn;
222
223 err = fdt_setprop(blob, off, "fsl,liodn",
224 &liodns, sizeof(u32) * 2);
225 if (err < 0)
226 goto err;
Haiying Wang24995d82011-01-20 22:26:31 +0000227#endif
Kumar Galadb977ab2009-09-10 03:02:13 -0500228
229 i++;
230
231 err = fdt_qportal(blob, off, i, "crypto@0", FSL_HW_PORTAL_SEC,
232 IS_E_PROCESSOR(get_svr()));
233 if (err < 0)
234 goto err;
235
Haiying Wang24995d82011-01-20 22:26:31 +0000236#ifdef CONFIG_FSL_CORENET
Kumar Galadb977ab2009-09-10 03:02:13 -0500237#ifdef CONFIG_SYS_DPAA_PME
238 err = fdt_qportal(blob, off, i, "pme@0", FSL_HW_PORTAL_PME, 1);
239 if (err < 0)
240 goto err;
241#else
242 fdt_qportal(blob, off, i, "pme@0", FSL_HW_PORTAL_PME, 0);
243#endif
Haiying Wang24995d82011-01-20 22:26:31 +0000244#endif
245
Kumar Galadb977ab2009-09-10 03:02:13 -0500246#ifdef CONFIG_SYS_DPAA_FMAN
247 for (j = 0; j < CONFIG_SYS_NUM_FMAN; j++) {
248 char name[] = "fman@0";
249
250 name[sizeof(name) - 2] = '0' + j;
251 err = fdt_qportal(blob, off, i, name,
252 FSL_HW_PORTAL_FMAN1 + j, 1);
253 if (err < 0)
254 goto err;
255 }
256#endif
Kumar Gala4d28db82011-10-14 13:28:52 -0500257#ifdef CONFIG_SYS_DPAA_RMAN
258 err = fdt_qportal(blob, off, i, "rman@0",
259 FSL_HW_PORTAL_RMAN, 1);
260 if (err < 0)
261 goto err;
262#endif
Kumar Galadb977ab2009-09-10 03:02:13 -0500263
264err:
265 if (err < 0) {
266 printf("ERROR: unable to create props for %s: %s\n",
267 fdt_get_name(blob, off, NULL), fdt_strerror(err));
268 return;
269 }
270
271 off = fdt_node_offset_by_compatible(blob, off, "fsl,qman-portal");
272 }
273}
Haiying Wang2a0ffb82011-03-01 09:30:07 -0500274
275void fdt_fixup_bportals(void *blob)
276{
277 int off, err;
278 unsigned int maj, min;
Haiying Wangb0e81152012-10-11 07:13:38 +0000279 unsigned int ip_cfg;
Jeffrey Ladouceur3c1bfc02013-01-25 10:38:53 +0000280 ccsr_bman_t *bman = (void *)CONFIG_SYS_FSL_BMAN_ADDR;
Haiying Wang2a0ffb82011-03-01 09:30:07 -0500281 u32 rev_1 = in_be32(&bman->ip_rev_1);
Haiying Wangb0e81152012-10-11 07:13:38 +0000282 u32 rev_2 = in_be32(&bman->ip_rev_2);
Haiying Wang2a0ffb82011-03-01 09:30:07 -0500283 char compat[64];
284 int compat_len;
285
286 maj = (rev_1 >> 8) & 0xff;
287 min = rev_1 & 0xff;
288
Haiying Wangb0e81152012-10-11 07:13:38 +0000289 ip_cfg = rev_2 & 0xff;
290
291 compat_len = sprintf(compat, "fsl,bman-portal-%u.%u.%u",
292 maj, min, ip_cfg) + 1;
Haiying Wang2a0ffb82011-03-01 09:30:07 -0500293 compat_len += sprintf(compat + compat_len, "fsl,bman-portal") + 1;
294
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);
298 if (err < 0) {
299 printf("ERROR: unable to create props for %s: %s\n",
300 fdt_get_name(blob, off, NULL),
301 fdt_strerror(err));
302 return;
303 }
304
305 off = fdt_node_offset_by_compatible(blob, off, "fsl,bman-portal");
306 }
307
308}