blob: e8d53bb2fd0b94a2aaae4a0d0592e351be11c51c [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;
Kumar Gala38449a42009-09-10 03:02:13 -050034
35void setup_portals(void)
36{
Haiying Wang325a12f2011-01-20 22:26:31 +000037#ifdef CONFIG_FSL_CORENET
Kumar Gala38449a42009-09-10 03:02:13 -050038 int i;
39
Kumar Gala38449a42009-09-10 03:02:13 -050040 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;
45
46 out_be32(&qman->qcsp[i].qcsp_lio_cfg, (liodn_off << 16) |
47 dliodn);
48 /* set frame liodn */
49 out_be32(&qman->qcsp[i].qcsp_io_cfg, (sdest << 16) | fliodn);
50 }
Haiying Wang325a12f2011-01-20 22:26:31 +000051#endif
52
53 /* Set the Qman initiator BAR to match the LAW (for DQRR stashing) */
54#ifdef CONFIG_PHYS_64BIT
55 out_be32(&qman->qcsp_bare, (u32)(CONFIG_SYS_QMAN_MEM_PHYS >> 32));
56#endif
57 out_be32(&qman->qcsp_bar, (u32)CONFIG_SYS_QMAN_MEM_PHYS);
Kumar Gala38449a42009-09-10 03:02:13 -050058}
59
60/* Update portal containter to match LAW setup of portal in phy map */
61void fdt_portal(void *blob, const char *compat, const char *container,
62 u64 addr, u32 size)
63{
64 int off;
65
66 off = fdt_node_offset_by_compatible(blob, -1, compat);
67 if (off < 0)
68 return ;
69
70 off = fdt_parent_offset(blob, off);
71 /* if non-zero assume we have a container */
72 if (off > 0) {
73 char buf[60];
74 const char *p, *name;
75 u32 *range;
76 int len;
77
78 /* fixup ranges */
79 range = fdt_getprop_w(blob, off, "ranges", &len);
80 if (range == NULL) {
81 printf("ERROR: container for %s has no ranges", compat);
82 return ;
83 }
84
85 range[0] = 0;
86 if (len == 16) {
87 range[1] = addr >> 32;
88 range[2] = addr & 0xffffffff;
89 range[3] = size;
90 } else {
91 range[1] = addr & 0xffffffff;
92 range[2] = size;
93 }
94 fdt_setprop_inplace(blob, off, "ranges", range, len);
95
96 /* fixup the name */
97 name = fdt_get_name(blob, off, &len);
98 p = memchr(name, '@', len);
99
100 if (p)
101 len = p - name;
102
103 /* if we are given a container name check it
104 * against what we found, if it doesnt match exit out */
105 if (container && (memcmp(container, name, len))) {
106 printf("WARNING: container names didn't match %s %s\n",
107 container, name);
108 return ;
109 }
110
111 memcpy(&buf, name, len);
112 len += sprintf(&buf[len], "@%llx", addr);
113 fdt_set_name(blob, off, buf);
114 return ;
115 }
116
117 printf("ERROR: %s isn't in a container. Not supported\n", compat);
118}
119
120static int fdt_qportal(void *blob, int off, int id, char *name,
121 enum fsl_dpaa_dev dev, int create)
122{
Haiying Wang325a12f2011-01-20 22:26:31 +0000123 int childoff, dev_off, ret = 0;
Kumar Gala38449a42009-09-10 03:02:13 -0500124 uint32_t dev_handle;
Haiying Wang325a12f2011-01-20 22:26:31 +0000125#ifdef CONFIG_FSL_CORENET
126 int num;
Kumar Gala38449a42009-09-10 03:02:13 -0500127 u32 liodns[2];
Haiying Wang325a12f2011-01-20 22:26:31 +0000128#endif
Kumar Gala38449a42009-09-10 03:02:13 -0500129
130 childoff = fdt_subnode_offset(blob, off, name);
131 if (create) {
132 if (childoff <= 0)
133 childoff = fdt_add_subnode(blob, off, name);
134
135 if (childoff > 0) {
136 char handle[64], *p;
137
138 strncpy(handle, name, sizeof(handle));
139 p = strchr(handle, '@');
140 if (!strncmp(name, "fman", 4)) {
141 *p = *(p + 1);
142 p++;
143 }
144 *p = '\0';
145
146 dev_off = fdt_path_offset(blob, handle);
147 if (dev_off < 0)
148 return dev_off;
149
150 dev_handle = fdt_get_phandle(blob, dev_off);
151 if (dev_handle <= 0) {
152 dev_handle = fdt_alloc_phandle(blob);
153 fdt_setprop_cell(blob, dev_off,
154 "linux,phandle", dev_handle);
155 }
156
157 ret = fdt_setprop(blob, childoff, "dev-handle",
158 &dev_handle, sizeof(dev_handle));
159 if (ret < 0)
160 return ret;
161
Haiying Wang325a12f2011-01-20 22:26:31 +0000162#ifdef CONFIG_FSL_CORENET
Kumar Gala38449a42009-09-10 03:02:13 -0500163 num = get_dpaa_liodn(dev, &liodns[0], id);
164 ret = fdt_setprop(blob, childoff, "fsl,liodn",
165 &liodns[0], sizeof(u32) * num);
Haiying Wang325a12f2011-01-20 22:26:31 +0000166#endif
Kumar Gala38449a42009-09-10 03:02:13 -0500167 } else {
168 return childoff;
169 }
170 } else {
171 if (childoff > 0)
172 ret = fdt_del_node(blob, childoff);
173 }
174
175 return ret;
176}
177
178void fdt_fixup_qportals(void *blob)
179{
180 int off, err;
181 unsigned int maj, min;
182 u32 rev_1 = in_be32(&qman->ip_rev_1);
183 char compat[64];
184 int compat_len;
185
186 maj = (rev_1 >> 8) & 0xff;
187 min = rev_1 & 0xff;
188
189 compat_len = sprintf(compat, "fsl,qman-portal-%u.%u", maj, min) + 1;
190 compat_len += sprintf(compat + compat_len, "fsl,qman-portal") + 1;
191
192 off = fdt_node_offset_by_compatible(blob, -1, "fsl,qman-portal");
193 while (off != -FDT_ERR_NOTFOUND) {
Haiying Wang325a12f2011-01-20 22:26:31 +0000194#ifdef CONFIG_FSL_CORENET
Kumar Gala38449a42009-09-10 03:02:13 -0500195 u32 liodns[2];
Haiying Wang325a12f2011-01-20 22:26:31 +0000196#endif
Kumar Gala38449a42009-09-10 03:02:13 -0500197 const int *ci = fdt_getprop(blob, off, "cell-index", NULL);
198 int j, i = *ci;
199
200 err = fdt_setprop(blob, off, "compatible", compat, compat_len);
201 if (err < 0)
202 goto err;
203
Haiying Wang325a12f2011-01-20 22:26:31 +0000204#ifdef CONFIG_FSL_CORENET
Kumar Gala38449a42009-09-10 03:02:13 -0500205 liodns[0] = qp_info[i].dliodn;
206 liodns[1] = qp_info[i].fliodn;
207
208 err = fdt_setprop(blob, off, "fsl,liodn",
209 &liodns, sizeof(u32) * 2);
210 if (err < 0)
211 goto err;
Haiying Wang325a12f2011-01-20 22:26:31 +0000212#endif
Kumar Gala38449a42009-09-10 03:02:13 -0500213
214 i++;
215
216 err = fdt_qportal(blob, off, i, "crypto@0", FSL_HW_PORTAL_SEC,
217 IS_E_PROCESSOR(get_svr()));
218 if (err < 0)
219 goto err;
220
Haiying Wang325a12f2011-01-20 22:26:31 +0000221#ifdef CONFIG_FSL_CORENET
Kumar Gala38449a42009-09-10 03:02:13 -0500222#ifdef CONFIG_SYS_DPAA_PME
223 err = fdt_qportal(blob, off, i, "pme@0", FSL_HW_PORTAL_PME, 1);
224 if (err < 0)
225 goto err;
226#else
227 fdt_qportal(blob, off, i, "pme@0", FSL_HW_PORTAL_PME, 0);
228#endif
Haiying Wang325a12f2011-01-20 22:26:31 +0000229#endif
230
Kumar Gala38449a42009-09-10 03:02:13 -0500231#ifdef CONFIG_SYS_DPAA_FMAN
232 for (j = 0; j < CONFIG_SYS_NUM_FMAN; j++) {
233 char name[] = "fman@0";
234
235 name[sizeof(name) - 2] = '0' + j;
236 err = fdt_qportal(blob, off, i, name,
237 FSL_HW_PORTAL_FMAN1 + j, 1);
238 if (err < 0)
239 goto err;
240 }
241#endif
242
243err:
244 if (err < 0) {
245 printf("ERROR: unable to create props for %s: %s\n",
246 fdt_get_name(blob, off, NULL), fdt_strerror(err));
247 return;
248 }
249
250 off = fdt_node_offset_by_compatible(blob, off, "fsl,qman-portal");
251 }
252}