blob: b59ef69f1f6c5aa123aae4ae80191fd926047461 [file] [log] [blame]
Kumar Gala38449a42009-09-10 03:02:13 -05001/*
Haiying Wang325a12f2011-01-20 22:26:31 +00002 * Copyright 2008-2011 Freescale Semiconductor, Inc.
Kumar Gala38449a42009-09-10 03:02:13 -05003 *
4 * See file CREDITS for list of people who contributed to this
5 * project.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 * MA 02111-1307 USA
21 */
22
23#include <common.h>
24#include <libfdt.h>
25#include <fdt_support.h>
26
27#include <asm/processor.h>
28#include <asm/io.h>
29
30#include <asm/fsl_portals.h>
31#include <asm/fsl_liodn.h>
32
Haiying Wang325a12f2011-01-20 22:26:31 +000033static ccsr_qman_t *qman = (void *)CONFIG_SYS_FSL_QMAN_ADDR;
Haiying Wangd38d4b22011-03-01 09:30:07 -050034static ccsr_bman_t *bman = (void *)CONFIG_SYS_FSL_BMAN_ADDR;
Kumar Gala38449a42009-09-10 03:02:13 -050035
36void setup_portals(void)
37{
Haiying Wang325a12f2011-01-20 22:26:31 +000038#ifdef CONFIG_FSL_CORENET
Kumar Gala38449a42009-09-10 03:02:13 -050039 int i;
40
Kumar Gala38449a42009-09-10 03:02:13 -050041 for (i = 0; i < CONFIG_SYS_QMAN_NUM_PORTALS; i++) {
42 u8 sdest = qp_info[i].sdest;
43 u16 fliodn = qp_info[i].fliodn;
44 u16 dliodn = qp_info[i].dliodn;
45 u16 liodn_off = qp_info[i].liodn_offset;
46
47 out_be32(&qman->qcsp[i].qcsp_lio_cfg, (liodn_off << 16) |
48 dliodn);
49 /* set frame liodn */
50 out_be32(&qman->qcsp[i].qcsp_io_cfg, (sdest << 16) | fliodn);
51 }
Haiying Wang325a12f2011-01-20 22:26:31 +000052#endif
53
54 /* Set the Qman initiator BAR to match the LAW (for DQRR stashing) */
55#ifdef CONFIG_PHYS_64BIT
56 out_be32(&qman->qcsp_bare, (u32)(CONFIG_SYS_QMAN_MEM_PHYS >> 32));
57#endif
58 out_be32(&qman->qcsp_bar, (u32)CONFIG_SYS_QMAN_MEM_PHYS);
Kumar Gala38449a42009-09-10 03:02:13 -050059}
60
61/* Update portal containter to match LAW setup of portal in phy map */
62void fdt_portal(void *blob, const char *compat, const char *container,
63 u64 addr, u32 size)
64{
65 int off;
66
67 off = fdt_node_offset_by_compatible(blob, -1, compat);
68 if (off < 0)
69 return ;
70
71 off = fdt_parent_offset(blob, off);
72 /* if non-zero assume we have a container */
73 if (off > 0) {
74 char buf[60];
75 const char *p, *name;
76 u32 *range;
77 int len;
78
79 /* fixup ranges */
80 range = fdt_getprop_w(blob, off, "ranges", &len);
81 if (range == NULL) {
82 printf("ERROR: container for %s has no ranges", compat);
83 return ;
84 }
85
86 range[0] = 0;
87 if (len == 16) {
88 range[1] = addr >> 32;
89 range[2] = addr & 0xffffffff;
90 range[3] = size;
91 } else {
92 range[1] = addr & 0xffffffff;
93 range[2] = size;
94 }
95 fdt_setprop_inplace(blob, off, "ranges", range, len);
96
97 /* fixup the name */
98 name = fdt_get_name(blob, off, &len);
99 p = memchr(name, '@', len);
100
101 if (p)
102 len = p - name;
103
104 /* if we are given a container name check it
105 * against what we found, if it doesnt match exit out */
106 if (container && (memcmp(container, name, len))) {
107 printf("WARNING: container names didn't match %s %s\n",
108 container, name);
109 return ;
110 }
111
112 memcpy(&buf, name, len);
113 len += sprintf(&buf[len], "@%llx", addr);
114 fdt_set_name(blob, off, buf);
115 return ;
116 }
117
118 printf("ERROR: %s isn't in a container. Not supported\n", compat);
119}
120
121static int fdt_qportal(void *blob, int off, int id, char *name,
122 enum fsl_dpaa_dev dev, int create)
123{
Haiying Wang325a12f2011-01-20 22:26:31 +0000124 int childoff, dev_off, ret = 0;
Kumar Gala38449a42009-09-10 03:02:13 -0500125 uint32_t dev_handle;
Haiying Wang325a12f2011-01-20 22:26:31 +0000126#ifdef CONFIG_FSL_CORENET
127 int num;
Kumar Gala38449a42009-09-10 03:02:13 -0500128 u32 liodns[2];
Haiying Wang325a12f2011-01-20 22:26:31 +0000129#endif
Kumar Gala38449a42009-09-10 03:02:13 -0500130
131 childoff = fdt_subnode_offset(blob, off, name);
132 if (create) {
133 if (childoff <= 0)
134 childoff = fdt_add_subnode(blob, off, name);
135
136 if (childoff > 0) {
137 char handle[64], *p;
138
139 strncpy(handle, name, sizeof(handle));
140 p = strchr(handle, '@');
141 if (!strncmp(name, "fman", 4)) {
142 *p = *(p + 1);
143 p++;
144 }
145 *p = '\0';
146
147 dev_off = fdt_path_offset(blob, handle);
148 if (dev_off < 0)
149 return dev_off;
150
151 dev_handle = fdt_get_phandle(blob, dev_off);
152 if (dev_handle <= 0) {
153 dev_handle = fdt_alloc_phandle(blob);
Kumar Galaf2f1c5a2011-08-01 00:23:23 -0500154 ret = fdt_set_phandle(blob, dev_off,
Timur Tabiecd9c692011-05-10 15:28:14 -0500155 dev_handle);
156 if (ret < 0)
157 return ret;
Kumar Gala38449a42009-09-10 03:02:13 -0500158 }
159
160 ret = fdt_setprop(blob, childoff, "dev-handle",
161 &dev_handle, sizeof(dev_handle));
162 if (ret < 0)
163 return ret;
164
Haiying Wang325a12f2011-01-20 22:26:31 +0000165#ifdef CONFIG_FSL_CORENET
Kumar Gala38449a42009-09-10 03:02:13 -0500166 num = get_dpaa_liodn(dev, &liodns[0], id);
167 ret = fdt_setprop(blob, childoff, "fsl,liodn",
168 &liodns[0], sizeof(u32) * num);
Haiying Wang325a12f2011-01-20 22:26:31 +0000169#endif
Kumar Gala38449a42009-09-10 03:02:13 -0500170 } else {
171 return childoff;
172 }
173 } else {
174 if (childoff > 0)
175 ret = fdt_del_node(blob, childoff);
176 }
177
178 return ret;
179}
180
181void fdt_fixup_qportals(void *blob)
182{
183 int off, err;
184 unsigned int maj, min;
Haiying Wange67bdfc2012-10-11 07:13:38 +0000185 unsigned int ip_cfg;
Kumar Gala38449a42009-09-10 03:02:13 -0500186 u32 rev_1 = in_be32(&qman->ip_rev_1);
Haiying Wange67bdfc2012-10-11 07:13:38 +0000187 u32 rev_2 = in_be32(&qman->ip_rev_2);
Kumar Gala38449a42009-09-10 03:02:13 -0500188 char compat[64];
189 int compat_len;
190
191 maj = (rev_1 >> 8) & 0xff;
192 min = rev_1 & 0xff;
Haiying Wange67bdfc2012-10-11 07:13:38 +0000193 ip_cfg = rev_2 & 0xff;
Kumar Gala38449a42009-09-10 03:02:13 -0500194
Haiying Wange67bdfc2012-10-11 07:13:38 +0000195 compat_len = sprintf(compat, "fsl,qman-portal-%u.%u.%u",
196 maj, min, ip_cfg) + 1;
Kumar Gala38449a42009-09-10 03:02:13 -0500197 compat_len += sprintf(compat + compat_len, "fsl,qman-portal") + 1;
198
199 off = fdt_node_offset_by_compatible(blob, -1, "fsl,qman-portal");
200 while (off != -FDT_ERR_NOTFOUND) {
Haiying Wang325a12f2011-01-20 22:26:31 +0000201#ifdef CONFIG_FSL_CORENET
Kumar Gala38449a42009-09-10 03:02:13 -0500202 u32 liodns[2];
Haiying Wang325a12f2011-01-20 22:26:31 +0000203#endif
Kumar Gala38449a42009-09-10 03:02:13 -0500204 const int *ci = fdt_getprop(blob, off, "cell-index", NULL);
Kumar Gala302a65c2011-07-31 12:55:39 -0500205 int i = *ci;
206#ifdef CONFIG_SYS_DPAA_FMAN
207 int j;
208#endif
Kumar Gala38449a42009-09-10 03:02:13 -0500209
210 err = fdt_setprop(blob, off, "compatible", compat, compat_len);
211 if (err < 0)
212 goto err;
213
Haiying Wang325a12f2011-01-20 22:26:31 +0000214#ifdef CONFIG_FSL_CORENET
Kumar Gala38449a42009-09-10 03:02:13 -0500215 liodns[0] = qp_info[i].dliodn;
216 liodns[1] = qp_info[i].fliodn;
217
218 err = fdt_setprop(blob, off, "fsl,liodn",
219 &liodns, sizeof(u32) * 2);
220 if (err < 0)
221 goto err;
Haiying Wang325a12f2011-01-20 22:26:31 +0000222#endif
Kumar Gala38449a42009-09-10 03:02:13 -0500223
224 i++;
225
226 err = fdt_qportal(blob, off, i, "crypto@0", FSL_HW_PORTAL_SEC,
227 IS_E_PROCESSOR(get_svr()));
228 if (err < 0)
229 goto err;
230
Haiying Wang325a12f2011-01-20 22:26:31 +0000231#ifdef CONFIG_FSL_CORENET
Kumar Gala38449a42009-09-10 03:02:13 -0500232#ifdef CONFIG_SYS_DPAA_PME
233 err = fdt_qportal(blob, off, i, "pme@0", FSL_HW_PORTAL_PME, 1);
234 if (err < 0)
235 goto err;
236#else
237 fdt_qportal(blob, off, i, "pme@0", FSL_HW_PORTAL_PME, 0);
238#endif
Haiying Wang325a12f2011-01-20 22:26:31 +0000239#endif
240
Kumar Gala38449a42009-09-10 03:02:13 -0500241#ifdef CONFIG_SYS_DPAA_FMAN
242 for (j = 0; j < CONFIG_SYS_NUM_FMAN; j++) {
243 char name[] = "fman@0";
244
245 name[sizeof(name) - 2] = '0' + j;
246 err = fdt_qportal(blob, off, i, name,
247 FSL_HW_PORTAL_FMAN1 + j, 1);
248 if (err < 0)
249 goto err;
250 }
251#endif
Kumar Gala4eb3c372011-10-14 13:28:52 -0500252#ifdef CONFIG_SYS_DPAA_RMAN
253 err = fdt_qportal(blob, off, i, "rman@0",
254 FSL_HW_PORTAL_RMAN, 1);
255 if (err < 0)
256 goto err;
257#endif
Kumar Gala38449a42009-09-10 03:02:13 -0500258
259err:
260 if (err < 0) {
261 printf("ERROR: unable to create props for %s: %s\n",
262 fdt_get_name(blob, off, NULL), fdt_strerror(err));
263 return;
264 }
265
266 off = fdt_node_offset_by_compatible(blob, off, "fsl,qman-portal");
267 }
268}
Haiying Wangd38d4b22011-03-01 09:30:07 -0500269
270void fdt_fixup_bportals(void *blob)
271{
272 int off, err;
273 unsigned int maj, min;
Haiying Wange67bdfc2012-10-11 07:13:38 +0000274 unsigned int ip_cfg;
Haiying Wangd38d4b22011-03-01 09:30:07 -0500275 u32 rev_1 = in_be32(&bman->ip_rev_1);
Haiying Wange67bdfc2012-10-11 07:13:38 +0000276 u32 rev_2 = in_be32(&bman->ip_rev_2);
Haiying Wangd38d4b22011-03-01 09:30:07 -0500277 char compat[64];
278 int compat_len;
279
280 maj = (rev_1 >> 8) & 0xff;
281 min = rev_1 & 0xff;
282
Haiying Wange67bdfc2012-10-11 07:13:38 +0000283 ip_cfg = rev_2 & 0xff;
284
285 compat_len = sprintf(compat, "fsl,bman-portal-%u.%u.%u",
286 maj, min, ip_cfg) + 1;
Haiying Wangd38d4b22011-03-01 09:30:07 -0500287 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, "fsl,bman-portal");
300 }
301
302}