]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/powerpc/cpu/mpc85xx/portals.c
Merge branch 'master' of /home/wd/git/u-boot/master
[karo-tx-uboot.git] / arch / powerpc / cpu / mpc85xx / portals.c
1 /*
2  * Copyright 2008-2010 Freescale Semiconductor, Inc.
3  *
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
33 static ccsr_qman_t *qman = (void *)CONFIG_SYS_FSL_CORENET_QMAN_ADDR;
34
35 void setup_portals(void)
36 {
37         int i;
38
39         /* Set the Qman initiator BAR to match the LAW (for DQRR stashing) */
40 #ifdef CONFIG_PHYS_64BIT
41         out_be32(&qman->qcsp_bare, (u32)(CONFIG_SYS_QMAN_MEM_PHYS >> 32));
42 #endif
43         out_be32(&qman->qcsp_bar, (u32)CONFIG_SYS_QMAN_MEM_PHYS);
44
45         for (i = 0; i < CONFIG_SYS_QMAN_NUM_PORTALS; i++) {
46                 u8 sdest = qp_info[i].sdest;
47                 u16 fliodn = qp_info[i].fliodn;
48                 u16 dliodn = qp_info[i].dliodn;
49                 u16 liodn_off = qp_info[i].liodn_offset;
50
51                 out_be32(&qman->qcsp[i].qcsp_lio_cfg, (liodn_off << 16) |
52                                         dliodn);
53                 /* set frame liodn */
54                 out_be32(&qman->qcsp[i].qcsp_io_cfg, (sdest << 16) | fliodn);
55         }
56 }
57
58 /* Update portal containter to match LAW setup of portal in phy map */
59 void fdt_portal(void *blob, const char *compat, const char *container,
60                         u64 addr, u32 size)
61 {
62         int off;
63
64         off = fdt_node_offset_by_compatible(blob, -1, compat);
65         if (off < 0)
66                 return ;
67
68         off = fdt_parent_offset(blob, off);
69         /* if non-zero assume we have a container */
70         if (off > 0) {
71                 char buf[60];
72                 const char *p, *name;
73                 u32 *range;
74                 int len;
75
76                 /* fixup ranges */
77                 range = fdt_getprop_w(blob, off, "ranges", &len);
78                 if (range == NULL) {
79                         printf("ERROR: container for %s has no ranges", compat);
80                         return ;
81                 }
82
83                 range[0] = 0;
84                 if (len == 16) {
85                         range[1] = addr >> 32;
86                         range[2] = addr & 0xffffffff;
87                         range[3] = size;
88                 } else {
89                         range[1] = addr & 0xffffffff;
90                         range[2] = size;
91                 }
92                 fdt_setprop_inplace(blob, off, "ranges", range, len);
93
94                 /* fixup the name */
95                 name = fdt_get_name(blob, off, &len);
96                 p = memchr(name, '@', len);
97
98                 if (p)
99                         len = p - name;
100
101                 /* if we are given a container name check it
102                  * against what we found, if it doesnt match exit out */
103                 if (container && (memcmp(container, name, len))) {
104                         printf("WARNING: container names didn't match %s %s\n",
105                                 container, name);
106                         return ;
107                 }
108
109                 memcpy(&buf, name, len);
110                 len += sprintf(&buf[len], "@%llx", addr);
111                 fdt_set_name(blob, off, buf);
112                 return ;
113         }
114
115         printf("ERROR: %s isn't in a container.  Not supported\n", compat);
116 }
117
118 static int fdt_qportal(void *blob, int off, int id, char *name,
119                        enum fsl_dpaa_dev dev, int create)
120 {
121         int childoff, dev_off, num, ret = 0;
122         uint32_t dev_handle;
123         u32 liodns[2];
124
125         childoff = fdt_subnode_offset(blob, off, name);
126         if (create) {
127                 if (childoff <= 0)
128                         childoff = fdt_add_subnode(blob, off, name);
129
130                 if (childoff > 0) {
131                         char handle[64], *p;
132
133                         strncpy(handle, name, sizeof(handle));
134                         p = strchr(handle, '@');
135                         if (!strncmp(name, "fman", 4)) {
136                                 *p = *(p + 1);
137                                 p++;
138                         }
139                         *p = '\0';
140
141                         dev_off = fdt_path_offset(blob, handle);
142                         if (dev_off < 0)
143                                 return dev_off;
144
145                         dev_handle = fdt_get_phandle(blob, dev_off);
146                         if (dev_handle <= 0) {
147                                 dev_handle = fdt_alloc_phandle(blob);
148                                 fdt_setprop_cell(blob, dev_off,
149                                         "linux,phandle", dev_handle);
150                         }
151
152                         ret = fdt_setprop(blob, childoff, "dev-handle",
153                                           &dev_handle, sizeof(dev_handle));
154                         if (ret < 0)
155                                 return ret;
156
157                         num = get_dpaa_liodn(dev, &liodns[0], id);
158                         ret = fdt_setprop(blob, childoff, "fsl,liodn",
159                                           &liodns[0], sizeof(u32) * num);
160                 } else {
161                         return childoff;
162                 }
163         } else {
164                 if (childoff > 0)
165                         ret = fdt_del_node(blob, childoff);
166         }
167
168         return ret;
169 }
170
171 void fdt_fixup_qportals(void *blob)
172 {
173         int off, err;
174         unsigned int maj, min;
175         u32 rev_1 = in_be32(&qman->ip_rev_1);
176         char compat[64];
177         int compat_len;
178
179         maj = (rev_1 >> 8) & 0xff;
180         min = rev_1 & 0xff;
181
182         compat_len = sprintf(compat, "fsl,qman-portal-%u.%u", maj, min) + 1;
183         compat_len += sprintf(compat + compat_len, "fsl,qman-portal") + 1;
184
185         off = fdt_node_offset_by_compatible(blob, -1, "fsl,qman-portal");
186         while (off != -FDT_ERR_NOTFOUND) {
187                 u32 liodns[2];
188                 const int *ci = fdt_getprop(blob, off, "cell-index", NULL);
189                 int j, i = *ci;
190
191                 err = fdt_setprop(blob, off, "compatible", compat, compat_len);
192                 if (err < 0)
193                         goto err;
194
195                 liodns[0] = qp_info[i].dliodn;
196                 liodns[1] = qp_info[i].fliodn;
197
198                 err = fdt_setprop(blob, off, "fsl,liodn",
199                                   &liodns, sizeof(u32) * 2);
200                 if (err < 0)
201                         goto err;
202
203                 i++;
204
205                 err = fdt_qportal(blob, off, i, "crypto@0", FSL_HW_PORTAL_SEC,
206                                   IS_E_PROCESSOR(get_svr()));
207                 if (err < 0)
208                         goto err;
209
210 #ifdef CONFIG_SYS_DPAA_PME
211                 err = fdt_qportal(blob, off, i, "pme@0", FSL_HW_PORTAL_PME, 1);
212                 if (err < 0)
213                         goto err;
214 #else
215                 fdt_qportal(blob, off, i, "pme@0", FSL_HW_PORTAL_PME, 0);
216 #endif
217 #ifdef CONFIG_SYS_DPAA_FMAN
218                 for (j = 0; j < CONFIG_SYS_NUM_FMAN; j++) {
219                         char name[] = "fman@0";
220
221                         name[sizeof(name) - 2] = '0' + j;
222                         err = fdt_qportal(blob, off, i, name,
223                                           FSL_HW_PORTAL_FMAN1 + j, 1);
224                         if (err < 0)
225                                 goto err;
226                 }
227 #endif
228
229 err:
230                 if (err < 0) {
231                         printf("ERROR: unable to create props for %s: %s\n",
232                                 fdt_get_name(blob, off, NULL), fdt_strerror(err));
233                         return;
234                 }
235
236                 off = fdt_node_offset_by_compatible(blob, off, "fsl,qman-portal");
237         }
238 }