aboutsummaryrefslogtreecommitdiffstats
path: root/arch/mips/sibyte/cfe
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /arch/mips/sibyte/cfe
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'arch/mips/sibyte/cfe')
-rw-r--r--arch/mips/sibyte/cfe/Makefile3
-rw-r--r--arch/mips/sibyte/cfe/cfe_api.c502
-rw-r--r--arch/mips/sibyte/cfe/cfe_api.h185
-rw-r--r--arch/mips/sibyte/cfe/cfe_api_int.h152
-rw-r--r--arch/mips/sibyte/cfe/cfe_error.h85
-rw-r--r--arch/mips/sibyte/cfe/console.c80
-rw-r--r--arch/mips/sibyte/cfe/setup.c358
-rw-r--r--arch/mips/sibyte/cfe/smp.c92
8 files changed, 1457 insertions, 0 deletions
diff --git a/arch/mips/sibyte/cfe/Makefile b/arch/mips/sibyte/cfe/Makefile
new file mode 100644
index 000000000000..059d84a1d8a8
--- /dev/null
+++ b/arch/mips/sibyte/cfe/Makefile
@@ -0,0 +1,3 @@
1lib-y = cfe_api.o setup.o
2lib-$(CONFIG_SMP) += smp.o
3lib-$(CONFIG_SIBYTE_CFE_CONSOLE) += console.o
diff --git a/arch/mips/sibyte/cfe/cfe_api.c b/arch/mips/sibyte/cfe/cfe_api.c
new file mode 100644
index 000000000000..c0213605e18a
--- /dev/null
+++ b/arch/mips/sibyte/cfe/cfe_api.c
@@ -0,0 +1,502 @@
1/*
2 * Copyright (C) 2000, 2001, 2002 Broadcom Corporation
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19/* *********************************************************************
20 *
21 * Broadcom Common Firmware Environment (CFE)
22 *
23 * Device Function stubs File: cfe_api.c
24 *
25 * This module contains device function stubs (small routines to
26 * call the standard "iocb" interface entry point to CFE).
27 * There should be one routine here per iocb function call.
28 *
29 * Authors: Mitch Lichtenberg, Chris Demetriou
30 *
31 ********************************************************************* */
32
33#include "cfe_api.h"
34#include "cfe_api_int.h"
35
36/* Cast from a native pointer to a cfe_xptr_t and back. */
37#define XPTR_FROM_NATIVE(n) ((cfe_xptr_t) (intptr_t) (n))
38#define NATIVE_FROM_XPTR(x) ((void *) (intptr_t) (x))
39
40#ifdef CFE_API_IMPL_NAMESPACE
41#define cfe_iocb_dispatch(a) __cfe_iocb_dispatch(a)
42#endif
43int cfe_iocb_dispatch(cfe_xiocb_t * xiocb);
44
45#if defined(CFE_API_common) || defined(CFE_API_ALL)
46/*
47 * Declare the dispatch function with args of "intptr_t".
48 * This makes sure whatever model we're compiling in
49 * puts the pointers in a single register. For example,
50 * combining -mlong64 and -mips1 or -mips2 would lead to
51 * trouble, since the handle and IOCB pointer will be
52 * passed in two registers each, and CFE expects one.
53 */
54
55static int (*cfe_dispfunc) (intptr_t handle, intptr_t xiocb) = 0;
56static cfe_xuint_t cfe_handle = 0;
57
58int cfe_init(cfe_xuint_t handle, cfe_xuint_t ept)
59{
60 cfe_dispfunc = NATIVE_FROM_XPTR(ept);
61 cfe_handle = handle;
62 return 0;
63}
64
65int cfe_iocb_dispatch(cfe_xiocb_t * xiocb)
66{
67 if (!cfe_dispfunc)
68 return -1;
69 return (*cfe_dispfunc) ((intptr_t) cfe_handle, (intptr_t) xiocb);
70}
71#endif /* CFE_API_common || CFE_API_ALL */
72
73#if defined(CFE_API_close) || defined(CFE_API_ALL)
74int cfe_close(int handle)
75{
76 cfe_xiocb_t xiocb;
77
78 xiocb.xiocb_fcode = CFE_CMD_DEV_CLOSE;
79 xiocb.xiocb_status = 0;
80 xiocb.xiocb_handle = handle;
81 xiocb.xiocb_flags = 0;
82 xiocb.xiocb_psize = 0;
83
84 cfe_iocb_dispatch(&xiocb);
85
86 return xiocb.xiocb_status;
87
88}
89#endif /* CFE_API_close || CFE_API_ALL */
90
91#if defined(CFE_API_cpu_start) || defined(CFE_API_ALL)
92int cfe_cpu_start(int cpu, void (*fn) (void), long sp, long gp, long a1)
93{
94 cfe_xiocb_t xiocb;
95
96 xiocb.xiocb_fcode = CFE_CMD_FW_CPUCTL;
97 xiocb.xiocb_status = 0;
98 xiocb.xiocb_handle = 0;
99 xiocb.xiocb_flags = 0;
100 xiocb.xiocb_psize = sizeof(xiocb_cpuctl_t);
101 xiocb.plist.xiocb_cpuctl.cpu_number = cpu;
102 xiocb.plist.xiocb_cpuctl.cpu_command = CFE_CPU_CMD_START;
103 xiocb.plist.xiocb_cpuctl.gp_val = gp;
104 xiocb.plist.xiocb_cpuctl.sp_val = sp;
105 xiocb.plist.xiocb_cpuctl.a1_val = a1;
106 xiocb.plist.xiocb_cpuctl.start_addr = (long) fn;
107
108 cfe_iocb_dispatch(&xiocb);
109
110 return xiocb.xiocb_status;
111}
112#endif /* CFE_API_cpu_start || CFE_API_ALL */
113
114#if defined(CFE_API_cpu_stop) || defined(CFE_API_ALL)
115int cfe_cpu_stop(int cpu)
116{
117 cfe_xiocb_t xiocb;
118
119 xiocb.xiocb_fcode = CFE_CMD_FW_CPUCTL;
120 xiocb.xiocb_status = 0;
121 xiocb.xiocb_handle = 0;
122 xiocb.xiocb_flags = 0;
123 xiocb.xiocb_psize = sizeof(xiocb_cpuctl_t);
124 xiocb.plist.xiocb_cpuctl.cpu_number = cpu;
125 xiocb.plist.xiocb_cpuctl.cpu_command = CFE_CPU_CMD_STOP;
126
127 cfe_iocb_dispatch(&xiocb);
128
129 return xiocb.xiocb_status;
130}
131#endif /* CFE_API_cpu_stop || CFE_API_ALL */
132
133#if defined(CFE_API_enumenv) || defined(CFE_API_ALL)
134int cfe_enumenv(int idx, char *name, int namelen, char *val, int vallen)
135{
136 cfe_xiocb_t xiocb;
137
138 xiocb.xiocb_fcode = CFE_CMD_ENV_SET;
139 xiocb.xiocb_status = 0;
140 xiocb.xiocb_handle = 0;
141 xiocb.xiocb_flags = 0;
142 xiocb.xiocb_psize = sizeof(xiocb_envbuf_t);
143 xiocb.plist.xiocb_envbuf.enum_idx = idx;
144 xiocb.plist.xiocb_envbuf.name_ptr = XPTR_FROM_NATIVE(name);
145 xiocb.plist.xiocb_envbuf.name_length = namelen;
146 xiocb.plist.xiocb_envbuf.val_ptr = XPTR_FROM_NATIVE(val);
147 xiocb.plist.xiocb_envbuf.val_length = vallen;
148
149 cfe_iocb_dispatch(&xiocb);
150
151 return xiocb.xiocb_status;
152}
153#endif /* CFE_API_enumenv || CFE_API_ALL */
154
155#if defined(CFE_API_enummem) || defined(CFE_API_ALL)
156int
157cfe_enummem(int idx, int flags, cfe_xuint_t * start, cfe_xuint_t * length,
158 cfe_xuint_t * type)
159{
160 cfe_xiocb_t xiocb;
161
162 xiocb.xiocb_fcode = CFE_CMD_FW_MEMENUM;
163 xiocb.xiocb_status = 0;
164 xiocb.xiocb_handle = 0;
165 xiocb.xiocb_flags = flags;
166 xiocb.xiocb_psize = sizeof(xiocb_meminfo_t);
167 xiocb.plist.xiocb_meminfo.mi_idx = idx;
168
169 cfe_iocb_dispatch(&xiocb);
170
171 if (xiocb.xiocb_status < 0)
172 return xiocb.xiocb_status;
173
174 *start = xiocb.plist.xiocb_meminfo.mi_addr;
175 *length = xiocb.plist.xiocb_meminfo.mi_size;
176 *type = xiocb.plist.xiocb_meminfo.mi_type;
177
178 return 0;
179}
180#endif /* CFE_API_enummem || CFE_API_ALL */
181
182#if defined(CFE_API_exit) || defined(CFE_API_ALL)
183int cfe_exit(int warm, int status)
184{
185 cfe_xiocb_t xiocb;
186
187 xiocb.xiocb_fcode = CFE_CMD_FW_RESTART;
188 xiocb.xiocb_status = 0;
189 xiocb.xiocb_handle = 0;
190 xiocb.xiocb_flags = warm ? CFE_FLG_WARMSTART : 0;
191 xiocb.xiocb_psize = sizeof(xiocb_exitstat_t);
192 xiocb.plist.xiocb_exitstat.status = status;
193
194 cfe_iocb_dispatch(&xiocb);
195
196 return xiocb.xiocb_status;
197}
198#endif /* CFE_API_exit || CFE_API_ALL */
199
200#if defined(CFE_API_flushcache) || defined(CFE_API_ALL)
201int cfe_flushcache(int flg)
202{
203 cfe_xiocb_t xiocb;
204
205 xiocb.xiocb_fcode = CFE_CMD_FW_FLUSHCACHE;
206 xiocb.xiocb_status = 0;
207 xiocb.xiocb_handle = 0;
208 xiocb.xiocb_flags = flg;
209 xiocb.xiocb_psize = 0;
210
211 cfe_iocb_dispatch(&xiocb);
212
213 return xiocb.xiocb_status;
214}
215#endif /* CFE_API_flushcache || CFE_API_ALL */
216
217#if defined(CFE_API_getdevinfo) || defined(CFE_API_ALL)
218int cfe_getdevinfo(char *name)
219{
220 cfe_xiocb_t xiocb;
221
222 xiocb.xiocb_fcode = CFE_CMD_DEV_GETINFO;
223 xiocb.xiocb_status = 0;
224 xiocb.xiocb_handle = 0;
225 xiocb.xiocb_flags = 0;
226 xiocb.xiocb_psize = sizeof(xiocb_buffer_t);
227 xiocb.plist.xiocb_buffer.buf_offset = 0;
228 xiocb.plist.xiocb_buffer.buf_ptr = XPTR_FROM_NATIVE(name);
229 xiocb.plist.xiocb_buffer.buf_length = cfe_strlen(name);
230
231 cfe_iocb_dispatch(&xiocb);
232
233 if (xiocb.xiocb_status < 0)
234 return xiocb.xiocb_status;
235 return xiocb.plist.xiocb_buffer.buf_devflags;
236}
237#endif /* CFE_API_getdevinfo || CFE_API_ALL */
238
239#if defined(CFE_API_getenv) || defined(CFE_API_ALL)
240int cfe_getenv(char *name, char *dest, int destlen)
241{
242 cfe_xiocb_t xiocb;
243
244 *dest = 0;
245
246 xiocb.xiocb_fcode = CFE_CMD_ENV_GET;
247 xiocb.xiocb_status = 0;
248 xiocb.xiocb_handle = 0;
249 xiocb.xiocb_flags = 0;
250 xiocb.xiocb_psize = sizeof(xiocb_envbuf_t);
251 xiocb.plist.xiocb_envbuf.enum_idx = 0;
252 xiocb.plist.xiocb_envbuf.name_ptr = XPTR_FROM_NATIVE(name);
253 xiocb.plist.xiocb_envbuf.name_length = cfe_strlen(name);
254 xiocb.plist.xiocb_envbuf.val_ptr = XPTR_FROM_NATIVE(dest);
255 xiocb.plist.xiocb_envbuf.val_length = destlen;
256
257 cfe_iocb_dispatch(&xiocb);
258
259 return xiocb.xiocb_status;
260}
261#endif /* CFE_API_getenv || CFE_API_ALL */
262
263#if defined(CFE_API_getfwinfo) || defined(CFE_API_ALL)
264int cfe_getfwinfo(cfe_fwinfo_t * info)
265{
266 cfe_xiocb_t xiocb;
267
268 xiocb.xiocb_fcode = CFE_CMD_FW_GETINFO;
269 xiocb.xiocb_status = 0;
270 xiocb.xiocb_handle = 0;
271 xiocb.xiocb_flags = 0;
272 xiocb.xiocb_psize = sizeof(xiocb_fwinfo_t);
273
274 cfe_iocb_dispatch(&xiocb);
275
276 if (xiocb.xiocb_status < 0)
277 return xiocb.xiocb_status;
278
279 info->fwi_version = xiocb.plist.xiocb_fwinfo.fwi_version;
280 info->fwi_totalmem = xiocb.plist.xiocb_fwinfo.fwi_totalmem;
281 info->fwi_flags = xiocb.plist.xiocb_fwinfo.fwi_flags;
282 info->fwi_boardid = xiocb.plist.xiocb_fwinfo.fwi_boardid;
283 info->fwi_bootarea_va = xiocb.plist.xiocb_fwinfo.fwi_bootarea_va;
284 info->fwi_bootarea_pa = xiocb.plist.xiocb_fwinfo.fwi_bootarea_pa;
285 info->fwi_bootarea_size =
286 xiocb.plist.xiocb_fwinfo.fwi_bootarea_size;
287#if 0
288 info->fwi_reserved1 = xiocb.plist.xiocb_fwinfo.fwi_reserved1;
289 info->fwi_reserved2 = xiocb.plist.xiocb_fwinfo.fwi_reserved2;
290 info->fwi_reserved3 = xiocb.plist.xiocb_fwinfo.fwi_reserved3;
291#endif
292
293 return 0;
294}
295#endif /* CFE_API_getfwinfo || CFE_API_ALL */
296
297#if defined(CFE_API_getstdhandle) || defined(CFE_API_ALL)
298int cfe_getstdhandle(int flg)
299{
300 cfe_xiocb_t xiocb;
301
302 xiocb.xiocb_fcode = CFE_CMD_DEV_GETHANDLE;
303 xiocb.xiocb_status = 0;
304 xiocb.xiocb_handle = 0;
305 xiocb.xiocb_flags = flg;
306 xiocb.xiocb_psize = 0;
307
308 cfe_iocb_dispatch(&xiocb);
309
310 if (xiocb.xiocb_status < 0)
311 return xiocb.xiocb_status;
312 return xiocb.xiocb_handle;
313}
314#endif /* CFE_API_getstdhandle || CFE_API_ALL */
315
316#if defined(CFE_API_getticks) || defined(CFE_API_ALL)
317int64_t
318#ifdef CFE_API_IMPL_NAMESPACE
319__cfe_getticks(void)
320#else
321cfe_getticks(void)
322#endif
323{
324 cfe_xiocb_t xiocb;
325
326 xiocb.xiocb_fcode = CFE_CMD_FW_GETTIME;
327 xiocb.xiocb_status = 0;
328 xiocb.xiocb_handle = 0;
329 xiocb.xiocb_flags = 0;
330 xiocb.xiocb_psize = sizeof(xiocb_time_t);
331 xiocb.plist.xiocb_time.ticks = 0;
332
333 cfe_iocb_dispatch(&xiocb);
334
335 return xiocb.plist.xiocb_time.ticks;
336
337}
338#endif /* CFE_API_getticks || CFE_API_ALL */
339
340#if defined(CFE_API_inpstat) || defined(CFE_API_ALL)
341int cfe_inpstat(int handle)
342{
343 cfe_xiocb_t xiocb;
344
345 xiocb.xiocb_fcode = CFE_CMD_DEV_INPSTAT;
346 xiocb.xiocb_status = 0;
347 xiocb.xiocb_handle = handle;
348 xiocb.xiocb_flags = 0;
349 xiocb.xiocb_psize = sizeof(xiocb_inpstat_t);
350 xiocb.plist.xiocb_inpstat.inp_status = 0;
351
352 cfe_iocb_dispatch(&xiocb);
353
354 if (xiocb.xiocb_status < 0)
355 return xiocb.xiocb_status;
356 return xiocb.plist.xiocb_inpstat.inp_status;
357}
358#endif /* CFE_API_inpstat || CFE_API_ALL */
359
360#if defined(CFE_API_ioctl) || defined(CFE_API_ALL)
361int
362cfe_ioctl(int handle, unsigned int ioctlnum, unsigned char *buffer,
363 int length, int *retlen, cfe_xuint_t offset)
364{
365 cfe_xiocb_t xiocb;
366
367 xiocb.xiocb_fcode = CFE_CMD_DEV_IOCTL;
368 xiocb.xiocb_status = 0;
369 xiocb.xiocb_handle = handle;
370 xiocb.xiocb_flags = 0;
371 xiocb.xiocb_psize = sizeof(xiocb_buffer_t);
372 xiocb.plist.xiocb_buffer.buf_offset = offset;
373 xiocb.plist.xiocb_buffer.buf_ioctlcmd = ioctlnum;
374 xiocb.plist.xiocb_buffer.buf_ptr = XPTR_FROM_NATIVE(buffer);
375 xiocb.plist.xiocb_buffer.buf_length = length;
376
377 cfe_iocb_dispatch(&xiocb);
378
379 if (retlen)
380 *retlen = xiocb.plist.xiocb_buffer.buf_retlen;
381 return xiocb.xiocb_status;
382}
383#endif /* CFE_API_ioctl || CFE_API_ALL */
384
385#if defined(CFE_API_open) || defined(CFE_API_ALL)
386int cfe_open(char *name)
387{
388 cfe_xiocb_t xiocb;
389
390 xiocb.xiocb_fcode = CFE_CMD_DEV_OPEN;
391 xiocb.xiocb_status = 0;
392 xiocb.xiocb_handle = 0;
393 xiocb.xiocb_flags = 0;
394 xiocb.xiocb_psize = sizeof(xiocb_buffer_t);
395 xiocb.plist.xiocb_buffer.buf_offset = 0;
396 xiocb.plist.xiocb_buffer.buf_ptr = XPTR_FROM_NATIVE(name);
397 xiocb.plist.xiocb_buffer.buf_length = cfe_strlen(name);
398
399 cfe_iocb_dispatch(&xiocb);
400
401 if (xiocb.xiocb_status < 0)
402 return xiocb.xiocb_status;
403 return xiocb.xiocb_handle;
404}
405#endif /* CFE_API_open || CFE_API_ALL */
406
407#if defined(CFE_API_read) || defined(CFE_API_ALL)
408int cfe_read(int handle, unsigned char *buffer, int length)
409{
410 return cfe_readblk(handle, 0, buffer, length);
411}
412#endif /* CFE_API_read || CFE_API_ALL */
413
414#if defined(CFE_API_readblk) || defined(CFE_API_ALL)
415int
416cfe_readblk(int handle, cfe_xint_t offset, unsigned char *buffer,
417 int length)
418{
419 cfe_xiocb_t xiocb;
420
421 xiocb.xiocb_fcode = CFE_CMD_DEV_READ;
422 xiocb.xiocb_status = 0;
423 xiocb.xiocb_handle = handle;
424 xiocb.xiocb_flags = 0;
425 xiocb.xiocb_psize = sizeof(xiocb_buffer_t);
426 xiocb.plist.xiocb_buffer.buf_offset = offset;
427 xiocb.plist.xiocb_buffer.buf_ptr = XPTR_FROM_NATIVE(buffer);
428 xiocb.plist.xiocb_buffer.buf_length = length;
429
430 cfe_iocb_dispatch(&xiocb);
431
432 if (xiocb.xiocb_status < 0)
433 return xiocb.xiocb_status;
434 return xiocb.plist.xiocb_buffer.buf_retlen;
435}
436#endif /* CFE_API_readblk || CFE_API_ALL */
437
438#if defined(CFE_API_setenv) || defined(CFE_API_ALL)
439int cfe_setenv(char *name, char *val)
440{
441 cfe_xiocb_t xiocb;
442
443 xiocb.xiocb_fcode = CFE_CMD_ENV_SET;
444 xiocb.xiocb_status = 0;
445 xiocb.xiocb_handle = 0;
446 xiocb.xiocb_flags = 0;
447 xiocb.xiocb_psize = sizeof(xiocb_envbuf_t);
448 xiocb.plist.xiocb_envbuf.enum_idx = 0;
449 xiocb.plist.xiocb_envbuf.name_ptr = XPTR_FROM_NATIVE(name);
450 xiocb.plist.xiocb_envbuf.name_length = cfe_strlen(name);
451 xiocb.plist.xiocb_envbuf.val_ptr = XPTR_FROM_NATIVE(val);
452 xiocb.plist.xiocb_envbuf.val_length = cfe_strlen(val);
453
454 cfe_iocb_dispatch(&xiocb);
455
456 return xiocb.xiocb_status;
457}
458#endif /* CFE_API_setenv || CFE_API_ALL */
459
460#if (defined(CFE_API_strlen) || defined(CFE_API_ALL)) \
461 && !defined(CFE_API_STRLEN_CUSTOM)
462int cfe_strlen(char *name)
463{
464 int count = 0;
465
466 while (*name++)
467 count++;
468
469 return count;
470}
471#endif /* CFE_API_strlen || CFE_API_ALL */
472
473#if defined(CFE_API_write) || defined(CFE_API_ALL)
474int cfe_write(int handle, unsigned char *buffer, int length)
475{
476 return cfe_writeblk(handle, 0, buffer, length);
477}
478#endif /* CFE_API_write || CFE_API_ALL */
479
480#if defined(CFE_API_writeblk) || defined(CFE_API_ALL)
481int
482cfe_writeblk(int handle, cfe_xint_t offset, unsigned char *buffer,
483 int length)
484{
485 cfe_xiocb_t xiocb;
486
487 xiocb.xiocb_fcode = CFE_CMD_DEV_WRITE;
488 xiocb.xiocb_status = 0;
489 xiocb.xiocb_handle = handle;
490 xiocb.xiocb_flags = 0;
491 xiocb.xiocb_psize = sizeof(xiocb_buffer_t);
492 xiocb.plist.xiocb_buffer.buf_offset = offset;
493 xiocb.plist.xiocb_buffer.buf_ptr = XPTR_FROM_NATIVE(buffer);
494 xiocb.plist.xiocb_buffer.buf_length = length;
495
496 cfe_iocb_dispatch(&xiocb);
497
498 if (xiocb.xiocb_status < 0)
499 return xiocb.xiocb_status;
500 return xiocb.plist.xiocb_buffer.buf_retlen;
501}
502#endif /* CFE_API_writeblk || CFE_API_ALL */
diff --git a/arch/mips/sibyte/cfe/cfe_api.h b/arch/mips/sibyte/cfe/cfe_api.h
new file mode 100644
index 000000000000..d8230cc53b81
--- /dev/null
+++ b/arch/mips/sibyte/cfe/cfe_api.h
@@ -0,0 +1,185 @@
1/*
2 * Copyright (C) 2000, 2001, 2002 Broadcom Corporation
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19/* *********************************************************************
20 *
21 * Broadcom Common Firmware Environment (CFE)
22 *
23 * Device function prototypes File: cfe_api.h
24 *
25 * This file contains declarations for doing callbacks to
26 * cfe from an application. It should be the only header
27 * needed by the application to use this library
28 *
29 * Authors: Mitch Lichtenberg, Chris Demetriou
30 *
31 ********************************************************************* */
32
33#ifndef CFE_API_H
34#define CFE_API_H
35
36/*
37 * Apply customizations here for different OSes. These need to:
38 * * typedef uint64_t, int64_t, intptr_t, uintptr_t.
39 * * define cfe_strlen() if use of an existing function is desired.
40 * * define CFE_API_IMPL_NAMESPACE if API functions are to use
41 * names in the implementation namespace.
42 * Also, optionally, if the build environment does not do so automatically,
43 * CFE_API_* can be defined here as desired.
44 */
45/* Begin customization. */
46#include <linux/types.h>
47#include <linux/string.h>
48
49typedef long intptr_t;
50
51#define cfe_strlen strlen
52
53#define CFE_API_ALL
54#define CFE_API_STRLEN_CUSTOM
55/* End customization. */
56
57
58/* *********************************************************************
59 * Constants
60 ********************************************************************* */
61
62/* Seal indicating CFE's presence, passed to user program. */
63#define CFE_EPTSEAL 0x43464531
64
65#define CFE_MI_RESERVED 0 /* memory is reserved, do not use */
66#define CFE_MI_AVAILABLE 1 /* memory is available */
67
68#define CFE_FLG_WARMSTART 0x00000001
69#define CFE_FLG_FULL_ARENA 0x00000001
70#define CFE_FLG_ENV_PERMANENT 0x00000001
71
72#define CFE_CPU_CMD_START 1
73#define CFE_CPU_CMD_STOP 0
74
75#define CFE_STDHANDLE_CONSOLE 0
76
77#define CFE_DEV_NETWORK 1
78#define CFE_DEV_DISK 2
79#define CFE_DEV_FLASH 3
80#define CFE_DEV_SERIAL 4
81#define CFE_DEV_CPU 5
82#define CFE_DEV_NVRAM 6
83#define CFE_DEV_CLOCK 7
84#define CFE_DEV_OTHER 8
85#define CFE_DEV_MASK 0x0F
86
87#define CFE_CACHE_FLUSH_D 1
88#define CFE_CACHE_INVAL_I 2
89#define CFE_CACHE_INVAL_D 4
90#define CFE_CACHE_INVAL_L2 8
91
92#define CFE_FWI_64BIT 0x00000001
93#define CFE_FWI_32BIT 0x00000002
94#define CFE_FWI_RELOC 0x00000004
95#define CFE_FWI_UNCACHED 0x00000008
96#define CFE_FWI_MULTICPU 0x00000010
97#define CFE_FWI_FUNCSIM 0x00000020
98#define CFE_FWI_RTLSIM 0x00000040
99
100typedef struct {
101 int64_t fwi_version; /* major, minor, eco version */
102 int64_t fwi_totalmem; /* total installed mem */
103 int64_t fwi_flags; /* various flags */
104 int64_t fwi_boardid; /* board ID */
105 int64_t fwi_bootarea_va; /* VA of boot area */
106 int64_t fwi_bootarea_pa; /* PA of boot area */
107 int64_t fwi_bootarea_size; /* size of boot area */
108} cfe_fwinfo_t;
109
110
111/*
112 * cfe_strlen is handled specially: If already defined, it has been
113 * overridden in this environment with a standard strlen-like function.
114 */
115#ifdef cfe_strlen
116# define CFE_API_STRLEN_CUSTOM
117#else
118# ifdef CFE_API_IMPL_NAMESPACE
119# define cfe_strlen(a) __cfe_strlen(a)
120# endif
121int cfe_strlen(char *name);
122#endif
123
124/*
125 * Defines and prototypes for functions which take no arguments.
126 */
127#ifdef CFE_API_IMPL_NAMESPACE
128int64_t __cfe_getticks(void);
129#define cfe_getticks() __cfe_getticks()
130#else
131int64_t cfe_getticks(void);
132#endif
133
134/*
135 * Defines and prototypes for the rest of the functions.
136 */
137#ifdef CFE_API_IMPL_NAMESPACE
138#define cfe_close(a) __cfe_close(a)
139#define cfe_cpu_start(a,b,c,d,e) __cfe_cpu_start(a,b,c,d,e)
140#define cfe_cpu_stop(a) __cfe_cpu_stop(a)
141#define cfe_enumenv(a,b,d,e,f) __cfe_enumenv(a,b,d,e,f)
142#define cfe_enummem(a,b,c,d,e) __cfe_enummem(a,b,c,d,e)
143#define cfe_exit(a,b) __cfe_exit(a,b)
144#define cfe_flushcache(a) __cfe_cacheflush(a)
145#define cfe_getdevinfo(a) __cfe_getdevinfo(a)
146#define cfe_getenv(a,b,c) __cfe_getenv(a,b,c)
147#define cfe_getfwinfo(a) __cfe_getfwinfo(a)
148#define cfe_getstdhandle(a) __cfe_getstdhandle(a)
149#define cfe_init(a,b) __cfe_init(a,b)
150#define cfe_inpstat(a) __cfe_inpstat(a)
151#define cfe_ioctl(a,b,c,d,e,f) __cfe_ioctl(a,b,c,d,e,f)
152#define cfe_open(a) __cfe_open(a)
153#define cfe_read(a,b,c) __cfe_read(a,b,c)
154#define cfe_readblk(a,b,c,d) __cfe_readblk(a,b,c,d)
155#define cfe_setenv(a,b) __cfe_setenv(a,b)
156#define cfe_write(a,b,c) __cfe_write(a,b,c)
157#define cfe_writeblk(a,b,c,d) __cfe_writeblk(a,b,c,d)
158#endif /* CFE_API_IMPL_NAMESPACE */
159
160int cfe_close(int handle);
161int cfe_cpu_start(int cpu, void (*fn) (void), long sp, long gp, long a1);
162int cfe_cpu_stop(int cpu);
163int cfe_enumenv(int idx, char *name, int namelen, char *val, int vallen);
164int cfe_enummem(int idx, int flags, uint64_t * start, uint64_t * length,
165 uint64_t * type);
166int cfe_exit(int warm, int status);
167int cfe_flushcache(int flg);
168int cfe_getdevinfo(char *name);
169int cfe_getenv(char *name, char *dest, int destlen);
170int cfe_getfwinfo(cfe_fwinfo_t * info);
171int cfe_getstdhandle(int flg);
172int cfe_init(uint64_t handle, uint64_t ept);
173int cfe_inpstat(int handle);
174int cfe_ioctl(int handle, unsigned int ioctlnum, unsigned char *buffer,
175 int length, int *retlen, uint64_t offset);
176int cfe_open(char *name);
177int cfe_read(int handle, unsigned char *buffer, int length);
178int cfe_readblk(int handle, int64_t offset, unsigned char *buffer,
179 int length);
180int cfe_setenv(char *name, char *val);
181int cfe_write(int handle, unsigned char *buffer, int length);
182int cfe_writeblk(int handle, int64_t offset, unsigned char *buffer,
183 int length);
184
185#endif /* CFE_API_H */
diff --git a/arch/mips/sibyte/cfe/cfe_api_int.h b/arch/mips/sibyte/cfe/cfe_api_int.h
new file mode 100644
index 000000000000..f7e5a64b55f3
--- /dev/null
+++ b/arch/mips/sibyte/cfe/cfe_api_int.h
@@ -0,0 +1,152 @@
1/*
2 * Copyright (C) 2000, 2001, 2002 Broadcom Corporation
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19/* *********************************************************************
20 *
21 * Broadcom Common Firmware Environment (CFE)
22 *
23 * Device function prototypes File: cfe_api_int.h
24 *
25 * This header defines all internal types and macros for the
26 * library. This is stuff that's not exported to an app
27 * using the library.
28 *
29 * Authors: Mitch Lichtenberg, Chris Demetriou
30 *
31 ********************************************************************* */
32
33#ifndef CFE_API_INT_H
34#define CFE_API_INT_H
35
36/* *********************************************************************
37 * Constants
38 ********************************************************************* */
39
40#define CFE_CMD_FW_GETINFO 0
41#define CFE_CMD_FW_RESTART 1
42#define CFE_CMD_FW_BOOT 2
43#define CFE_CMD_FW_CPUCTL 3
44#define CFE_CMD_FW_GETTIME 4
45#define CFE_CMD_FW_MEMENUM 5
46#define CFE_CMD_FW_FLUSHCACHE 6
47
48#define CFE_CMD_DEV_GETHANDLE 9
49#define CFE_CMD_DEV_ENUM 10
50#define CFE_CMD_DEV_OPEN 11
51#define CFE_CMD_DEV_INPSTAT 12
52#define CFE_CMD_DEV_READ 13
53#define CFE_CMD_DEV_WRITE 14
54#define CFE_CMD_DEV_IOCTL 15
55#define CFE_CMD_DEV_CLOSE 16
56#define CFE_CMD_DEV_GETINFO 17
57
58#define CFE_CMD_ENV_ENUM 20
59#define CFE_CMD_ENV_GET 22
60#define CFE_CMD_ENV_SET 23
61#define CFE_CMD_ENV_DEL 24
62
63#define CFE_CMD_MAX 32
64
65#define CFE_CMD_VENDOR_USE 0x8000 /* codes above this are for customer use */
66
67/* *********************************************************************
68 * Structures
69 ********************************************************************* */
70
71typedef uint64_t cfe_xuint_t;
72typedef int64_t cfe_xint_t;
73typedef int64_t cfe_xptr_t;
74
75typedef struct xiocb_buffer_s {
76 cfe_xuint_t buf_offset; /* offset on device (bytes) */
77 cfe_xptr_t buf_ptr; /* pointer to a buffer */
78 cfe_xuint_t buf_length; /* length of this buffer */
79 cfe_xuint_t buf_retlen; /* returned length (for read ops) */
80 cfe_xuint_t buf_ioctlcmd; /* IOCTL command (used only for IOCTLs) */
81} xiocb_buffer_t;
82
83#define buf_devflags buf_ioctlcmd /* returned device info flags */
84
85typedef struct xiocb_inpstat_s {
86 cfe_xuint_t inp_status; /* 1 means input available */
87} xiocb_inpstat_t;
88
89typedef struct xiocb_envbuf_s {
90 cfe_xint_t enum_idx; /* 0-based enumeration index */
91 cfe_xptr_t name_ptr; /* name string buffer */
92 cfe_xint_t name_length; /* size of name buffer */
93 cfe_xptr_t val_ptr; /* value string buffer */
94 cfe_xint_t val_length; /* size of value string buffer */
95} xiocb_envbuf_t;
96
97typedef struct xiocb_cpuctl_s {
98 cfe_xuint_t cpu_number; /* cpu number to control */
99 cfe_xuint_t cpu_command; /* command to issue to CPU */
100 cfe_xuint_t start_addr; /* CPU start address */
101 cfe_xuint_t gp_val; /* starting GP value */
102 cfe_xuint_t sp_val; /* starting SP value */
103 cfe_xuint_t a1_val; /* starting A1 value */
104} xiocb_cpuctl_t;
105
106typedef struct xiocb_time_s {
107 cfe_xint_t ticks; /* current time in ticks */
108} xiocb_time_t;
109
110typedef struct xiocb_exitstat_s {
111 cfe_xint_t status;
112} xiocb_exitstat_t;
113
114typedef struct xiocb_meminfo_s {
115 cfe_xint_t mi_idx; /* 0-based enumeration index */
116 cfe_xint_t mi_type; /* type of memory block */
117 cfe_xuint_t mi_addr; /* physical start address */
118 cfe_xuint_t mi_size; /* block size */
119} xiocb_meminfo_t;
120
121typedef struct xiocb_fwinfo_s {
122 cfe_xint_t fwi_version; /* major, minor, eco version */
123 cfe_xint_t fwi_totalmem; /* total installed mem */
124 cfe_xint_t fwi_flags; /* various flags */
125 cfe_xint_t fwi_boardid; /* board ID */
126 cfe_xint_t fwi_bootarea_va; /* VA of boot area */
127 cfe_xint_t fwi_bootarea_pa; /* PA of boot area */
128 cfe_xint_t fwi_bootarea_size; /* size of boot area */
129 cfe_xint_t fwi_reserved1;
130 cfe_xint_t fwi_reserved2;
131 cfe_xint_t fwi_reserved3;
132} xiocb_fwinfo_t;
133
134typedef struct cfe_xiocb_s {
135 cfe_xuint_t xiocb_fcode; /* IOCB function code */
136 cfe_xint_t xiocb_status; /* return status */
137 cfe_xint_t xiocb_handle; /* file/device handle */
138 cfe_xuint_t xiocb_flags; /* flags for this IOCB */
139 cfe_xuint_t xiocb_psize; /* size of parameter list */
140 union {
141 xiocb_buffer_t xiocb_buffer; /* buffer parameters */
142 xiocb_inpstat_t xiocb_inpstat; /* input status parameters */
143 xiocb_envbuf_t xiocb_envbuf; /* environment function parameters */
144 xiocb_cpuctl_t xiocb_cpuctl; /* CPU control parameters */
145 xiocb_time_t xiocb_time; /* timer parameters */
146 xiocb_meminfo_t xiocb_meminfo; /* memory arena info parameters */
147 xiocb_fwinfo_t xiocb_fwinfo; /* firmware information */
148 xiocb_exitstat_t xiocb_exitstat; /* Exit Status */
149 } plist;
150} cfe_xiocb_t;
151
152#endif /* CFE_API_INT_H */
diff --git a/arch/mips/sibyte/cfe/cfe_error.h b/arch/mips/sibyte/cfe/cfe_error.h
new file mode 100644
index 000000000000..77eb4935bfb4
--- /dev/null
+++ b/arch/mips/sibyte/cfe/cfe_error.h
@@ -0,0 +1,85 @@
1/*
2 * Copyright (C) 2000, 2001, 2002 Broadcom Corporation
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19/* *********************************************************************
20 *
21 * Broadcom Common Firmware Environment (CFE)
22 *
23 * Error codes File: cfe_error.h
24 *
25 * CFE's global error code list is here.
26 *
27 * Author: Mitch Lichtenberg
28 *
29 ********************************************************************* */
30
31
32#define CFE_OK 0
33#define CFE_ERR -1 /* generic error */
34#define CFE_ERR_INV_COMMAND -2
35#define CFE_ERR_EOF -3
36#define CFE_ERR_IOERR -4
37#define CFE_ERR_NOMEM -5
38#define CFE_ERR_DEVNOTFOUND -6
39#define CFE_ERR_DEVOPEN -7
40#define CFE_ERR_INV_PARAM -8
41#define CFE_ERR_ENVNOTFOUND -9
42#define CFE_ERR_ENVREADONLY -10
43
44#define CFE_ERR_NOTELF -11
45#define CFE_ERR_NOT32BIT -12
46#define CFE_ERR_WRONGENDIAN -13
47#define CFE_ERR_BADELFVERS -14
48#define CFE_ERR_NOTMIPS -15
49#define CFE_ERR_BADELFFMT -16
50#define CFE_ERR_BADADDR -17
51
52#define CFE_ERR_FILENOTFOUND -18
53#define CFE_ERR_UNSUPPORTED -19
54
55#define CFE_ERR_HOSTUNKNOWN -20
56
57#define CFE_ERR_TIMEOUT -21
58
59#define CFE_ERR_PROTOCOLERR -22
60
61#define CFE_ERR_NETDOWN -23
62#define CFE_ERR_NONAMESERVER -24
63
64#define CFE_ERR_NOHANDLES -25
65#define CFE_ERR_ALREADYBOUND -26
66
67#define CFE_ERR_CANNOTSET -27
68#define CFE_ERR_NOMORE -28
69#define CFE_ERR_BADFILESYS -29
70#define CFE_ERR_FSNOTAVAIL -30
71
72#define CFE_ERR_INVBOOTBLOCK -31
73#define CFE_ERR_WRONGDEVTYPE -32
74#define CFE_ERR_BBCHECKSUM -33
75#define CFE_ERR_BOOTPROGCHKSUM -34
76
77#define CFE_ERR_LDRNOTAVAIL -35
78
79#define CFE_ERR_NOTREADY -36
80
81#define CFE_ERR_GETMEM -37
82#define CFE_ERR_SETMEM -38
83
84#define CFE_ERR_NOTCONN -39
85#define CFE_ERR_ADDRINUSE -40
diff --git a/arch/mips/sibyte/cfe/console.c b/arch/mips/sibyte/cfe/console.c
new file mode 100644
index 000000000000..53a5c1eb5611
--- /dev/null
+++ b/arch/mips/sibyte/cfe/console.c
@@ -0,0 +1,80 @@
1#include <linux/config.h>
2#include <linux/init.h>
3#include <linux/errno.h>
4#include <linux/console.h>
5
6#include <asm/sibyte/board.h>
7
8#include "cfe_api.h"
9#include "cfe_error.h"
10
11extern int cfe_cons_handle;
12
13static void cfe_console_write(struct console *cons, const char *str,
14 unsigned int count)
15{
16 int i, last, written;
17
18 for (i=0,last=0; i<count; i++) {
19 if (!str[i])
20 /* XXXKW can/should this ever happen? */
21 return;
22 if (str[i] == '\n') {
23 do {
24 written = cfe_write(cfe_cons_handle, &str[last], i-last);
25 if (written < 0)
26 ;
27 last += written;
28 } while (last < i);
29 while (cfe_write(cfe_cons_handle, "\r", 1) <= 0)
30 ;
31 }
32 }
33 if (last != count) {
34 do {
35 written = cfe_write(cfe_cons_handle, &str[last], count-last);
36 if (written < 0)
37 ;
38 last += written;
39 } while (last < count);
40 }
41
42}
43
44static int cfe_console_setup(struct console *cons, char *str)
45{
46 char consdev[32];
47 /* XXXKW think about interaction with 'console=' cmdline arg */
48 /* If none of the console options are configured, the build will break. */
49 if (cfe_getenv("BOOT_CONSOLE", consdev, 32) >= 0) {
50#ifdef CONFIG_SIBYTE_SB1250_DUART
51 if (!strcmp(consdev, "uart0")) {
52 setleds("u0cn");
53 } else if (!strcmp(consdev, "uart1")) {
54 setleds("u1cn");
55#endif
56#ifdef CONFIG_VGA_CONSOLE
57 } else if (!strcmp(consdev, "pcconsole0")) {
58 setleds("pccn");
59#endif
60 } else
61 return -ENODEV;
62 }
63 return 0;
64}
65
66static struct console sb1250_cfe_cons = {
67 .name = "cfe",
68 .write = cfe_console_write,
69 .setup = cfe_console_setup,
70 .flags = CON_PRINTBUFFER,
71 .index = -1,
72};
73
74static int __init sb1250_cfe_console_init(void)
75{
76 register_console(&sb1250_cfe_cons);
77 return 0;
78}
79
80console_initcall(sb1250_cfe_console_init);
diff --git a/arch/mips/sibyte/cfe/setup.c b/arch/mips/sibyte/cfe/setup.c
new file mode 100644
index 000000000000..d6d0364fa760
--- /dev/null
+++ b/arch/mips/sibyte/cfe/setup.c
@@ -0,0 +1,358 @@
1/*
2 * Copyright (C) 2000, 2001, 2002, 2003 Broadcom Corporation
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19#include <linux/config.h>
20#include <linux/init.h>
21#include <linux/kernel.h>
22#include <linux/linkage.h>
23#include <linux/mm.h>
24#include <linux/blkdev.h>
25#include <linux/bootmem.h>
26#include <linux/smp.h>
27
28#include <asm/bootinfo.h>
29#include <asm/reboot.h>
30#include <asm/sibyte/board.h>
31
32#include "cfe_api.h"
33#include "cfe_error.h"
34
35/* Max ram addressable in 32-bit segments */
36#ifdef CONFIG_MIPS64
37#define MAX_RAM_SIZE (~0ULL)
38#else
39#ifdef CONFIG_HIGHMEM
40#ifdef CONFIG_64BIT_PHYS_ADDR
41#define MAX_RAM_SIZE (~0ULL)
42#else
43#define MAX_RAM_SIZE (0xffffffffULL)
44#endif
45#else
46#define MAX_RAM_SIZE (0x1fffffffULL)
47#endif
48#endif
49
50#define SIBYTE_MAX_MEM_REGIONS 8
51phys_t board_mem_region_addrs[SIBYTE_MAX_MEM_REGIONS];
52phys_t board_mem_region_sizes[SIBYTE_MAX_MEM_REGIONS];
53unsigned int board_mem_region_count;
54
55int cfe_cons_handle;
56
57#ifdef CONFIG_BLK_DEV_INITRD
58extern unsigned long initrd_start, initrd_end;
59#endif
60
61#ifdef CONFIG_KGDB
62extern int kgdb_port;
63#endif
64
65static void ATTRIB_NORET cfe_linux_exit(void *arg)
66{
67 int warm = *(int *)arg;
68
69 if (smp_processor_id()) {
70 static int reboot_smp;
71
72 /* Don't repeat the process from another CPU */
73 if (!reboot_smp) {
74 /* Get CPU 0 to do the cfe_exit */
75 reboot_smp = 1;
76 smp_call_function(cfe_linux_exit, arg, 1, 0);
77 }
78 } else {
79 printk("Passing control back to CFE...\n");
80 cfe_exit(warm, 0);
81 printk("cfe_exit returned??\n");
82 }
83 while (1);
84}
85
86static void ATTRIB_NORET cfe_linux_restart(char *command)
87{
88 static const int zero;
89
90 cfe_linux_exit((void *)&zero);
91}
92
93static void ATTRIB_NORET cfe_linux_halt(void)
94{
95 static const int one = 1;
96
97 cfe_linux_exit((void *)&one);
98}
99
100static __init void prom_meminit(void)
101{
102 u64 addr, size, type; /* regardless of 64BIT_PHYS_ADDR */
103 int mem_flags = 0;
104 unsigned int idx;
105 int rd_flag;
106#ifdef CONFIG_BLK_DEV_INITRD
107 unsigned long initrd_pstart;
108 unsigned long initrd_pend;
109
110 initrd_pstart = CPHYSADDR(initrd_start);
111 initrd_pend = CPHYSADDR(initrd_end);
112 if (initrd_start &&
113 ((initrd_pstart > MAX_RAM_SIZE)
114 || (initrd_pend > MAX_RAM_SIZE))) {
115 panic("initrd out of addressable memory");
116 }
117
118#endif /* INITRD */
119
120 for (idx = 0; cfe_enummem(idx, mem_flags, &addr, &size, &type) != CFE_ERR_NOMORE;
121 idx++) {
122 rd_flag = 0;
123 if (type == CFE_MI_AVAILABLE) {
124 /*
125 * See if this block contains (any portion of) the
126 * ramdisk
127 */
128#ifdef CONFIG_BLK_DEV_INITRD
129 if (initrd_start) {
130 if ((initrd_pstart > addr) &&
131 (initrd_pstart < (addr + size))) {
132 add_memory_region(addr,
133 initrd_pstart - addr,
134 BOOT_MEM_RAM);
135 rd_flag = 1;
136 }
137 if ((initrd_pend > addr) &&
138 (initrd_pend < (addr + size))) {
139 add_memory_region(initrd_pend,
140 (addr + size) - initrd_pend,
141 BOOT_MEM_RAM);
142 rd_flag = 1;
143 }
144 }
145#endif
146 if (!rd_flag) {
147 if (addr > MAX_RAM_SIZE)
148 continue;
149 if (addr+size > MAX_RAM_SIZE)
150 size = MAX_RAM_SIZE - (addr+size) + 1;
151 /*
152 * memcpy/__copy_user prefetch, which
153 * will cause a bus error for
154 * KSEG/KUSEG addrs not backed by RAM.
155 * Hence, reserve some padding for the
156 * prefetch distance.
157 */
158 if (size > 512)
159 size -= 512;
160 add_memory_region(addr, size, BOOT_MEM_RAM);
161 }
162 board_mem_region_addrs[board_mem_region_count] = addr;
163 board_mem_region_sizes[board_mem_region_count] = size;
164 board_mem_region_count++;
165 if (board_mem_region_count ==
166 SIBYTE_MAX_MEM_REGIONS) {
167 /*
168 * Too many regions. Need to configure more
169 */
170 while(1);
171 }
172 }
173 }
174#ifdef CONFIG_BLK_DEV_INITRD
175 if (initrd_start) {
176 add_memory_region(initrd_pstart, initrd_pend - initrd_pstart,
177 BOOT_MEM_RESERVED);
178 }
179#endif
180}
181
182#ifdef CONFIG_BLK_DEV_INITRD
183static int __init initrd_setup(char *str)
184{
185 char rdarg[64];
186 int idx;
187 char *tmp, *endptr;
188 unsigned long initrd_size;
189
190 /* Make a copy of the initrd argument so we can smash it up here */
191 for (idx = 0; idx < sizeof(rdarg)-1; idx++) {
192 if (!str[idx] || (str[idx] == ' ')) break;
193 rdarg[idx] = str[idx];
194 }
195
196 rdarg[idx] = 0;
197 str = rdarg;
198
199 /*
200 *Initrd location comes in the form "<hex size of ramdisk in bytes>@<location in memory>"
201 * e.g. initrd=3abfd@80010000. This is set up by the loader.
202 */
203 for (tmp = str; *tmp != '@'; tmp++) {
204 if (!*tmp) {
205 goto fail;
206 }
207 }
208 *tmp = 0;
209 tmp++;
210 if (!*tmp) {
211 goto fail;
212 }
213 initrd_size = simple_strtoul(str, &endptr, 16);
214 if (*endptr) {
215 *(tmp-1) = '@';
216 goto fail;
217 }
218 *(tmp-1) = '@';
219 initrd_start = simple_strtoul(tmp, &endptr, 16);
220 if (*endptr) {
221 goto fail;
222 }
223 initrd_end = initrd_start + initrd_size;
224 prom_printf("Found initrd of %lx@%lx\n", initrd_size, initrd_start);
225 return 1;
226 fail:
227 prom_printf("Bad initrd argument. Disabling initrd\n");
228 initrd_start = 0;
229 initrd_end = 0;
230 return 1;
231}
232
233#endif
234
235/*
236 * prom_init is called just after the cpu type is determined, from setup_arch()
237 */
238void __init prom_init(void)
239{
240 uint64_t cfe_ept, cfe_handle;
241 unsigned int cfe_eptseal;
242 int argc = fw_arg0;
243 char **envp = (char **) fw_arg2;
244 int *prom_vec = (int *) fw_arg3;
245#ifdef CONFIG_KGDB
246 char *arg;
247#endif
248
249 _machine_restart = cfe_linux_restart;
250 _machine_halt = cfe_linux_halt;
251 _machine_power_off = cfe_linux_halt;
252
253 /*
254 * Check if a loader was used; if NOT, the 4 arguments are
255 * what CFE gives us (handle, 0, EPT and EPTSEAL)
256 */
257 if (argc < 0) {
258 cfe_handle = (uint64_t)(long)argc;
259 cfe_ept = (long)envp;
260 cfe_eptseal = (uint32_t)(unsigned long)prom_vec;
261 } else {
262 if ((int32_t)(long)prom_vec < 0) {
263 /*
264 * Old loader; all it gives us is the handle,
265 * so use the "known" entrypoint and assume
266 * the seal.
267 */
268 cfe_handle = (uint64_t)(long)prom_vec;
269 cfe_ept = (uint64_t)((int32_t)0x9fc00500);
270 cfe_eptseal = CFE_EPTSEAL;
271 } else {
272 /*
273 * Newer loaders bundle the handle/ept/eptseal
274 * Note: prom_vec is in the loader's useg
275 * which is still alive in the TLB.
276 */
277 cfe_handle = (uint64_t)((int32_t *)prom_vec)[0];
278 cfe_ept = (uint64_t)((int32_t *)prom_vec)[2];
279 cfe_eptseal = (unsigned int)((uint32_t *)prom_vec)[3];
280 }
281 }
282 if (cfe_eptseal != CFE_EPTSEAL) {
283 /* too early for panic to do any good */
284 prom_printf("CFE's entrypoint seal doesn't match. Spinning.");
285 while (1) ;
286 }
287 cfe_init(cfe_handle, cfe_ept);
288 /*
289 * Get the handle for (at least) prom_putchar, possibly for
290 * boot console
291 */
292 cfe_cons_handle = cfe_getstdhandle(CFE_STDHANDLE_CONSOLE);
293 if (cfe_getenv("LINUX_CMDLINE", arcs_cmdline, CL_SIZE) < 0) {
294 if (argc < 0) {
295 /*
296 * It's OK for direct boot to not provide a
297 * command line
298 */
299 strcpy(arcs_cmdline, "root=/dev/ram0 ");
300#ifdef CONFIG_SIBYTE_PTSWARM
301 strcat(arcs_cmdline, "console=ttyS0,115200 ");
302#endif
303 } else {
304 /* The loader should have set the command line */
305 /* too early for panic to do any good */
306 prom_printf("LINUX_CMDLINE not defined in cfe.");
307 while (1) ;
308 }
309 }
310
311#ifdef CONFIG_KGDB
312 if ((arg = strstr(arcs_cmdline,"kgdb=duart")) != NULL)
313 kgdb_port = (arg[10] == '0') ? 0 : 1;
314 else
315 kgdb_port = 1;
316#endif
317
318#ifdef CONFIG_BLK_DEV_INITRD
319 {
320 char *ptr;
321 /* Need to find out early whether we've got an initrd. So scan
322 the list looking now */
323 for (ptr = arcs_cmdline; *ptr; ptr++) {
324 while (*ptr == ' ') {
325 ptr++;
326 }
327 if (!strncmp(ptr, "initrd=", 7)) {
328 initrd_setup(ptr+7);
329 break;
330 } else {
331 while (*ptr && (*ptr != ' ')) {
332 ptr++;
333 }
334 }
335 }
336 }
337#endif /* CONFIG_BLK_DEV_INITRD */
338
339 /* Not sure this is needed, but it's the safe way. */
340 arcs_cmdline[CL_SIZE-1] = 0;
341
342 mips_machgroup = MACH_GROUP_SIBYTE;
343 prom_meminit();
344}
345
346unsigned long __init prom_free_prom_memory(void)
347{
348 /* Not sure what I'm supposed to do here. Nothing, I think */
349 return 0;
350}
351
352void prom_putchar(char c)
353{
354 int ret;
355
356 while ((ret = cfe_write(cfe_cons_handle, &c, 1)) == 0)
357 ;
358}
diff --git a/arch/mips/sibyte/cfe/smp.c b/arch/mips/sibyte/cfe/smp.c
new file mode 100644
index 000000000000..73392190d2b1
--- /dev/null
+++ b/arch/mips/sibyte/cfe/smp.c
@@ -0,0 +1,92 @@
1/*
2 * Copyright (C) 2000, 2001, 2002, 2003 Broadcom Corporation
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19#include <linux/init.h>
20#include <linux/sched.h>
21#include <linux/smp.h>
22#include <asm/processor.h>
23
24#include "cfe_api.h"
25#include "cfe_error.h"
26
27/*
28 * Use CFE to find out how many CPUs are available, setting up
29 * phys_cpu_present_map and the logical/physical mappings.
30 * XXXKW will the boot CPU ever not be physical 0?
31 *
32 * Common setup before any secondaries are started
33 */
34void __init prom_prepare_cpus(unsigned int max_cpus)
35{
36 int i, num;
37
38 cpus_clear(phys_cpu_present_map);
39 cpu_set(0, phys_cpu_present_map);
40 __cpu_number_map[0] = 0;
41 __cpu_logical_map[0] = 0;
42
43 for (i=1, num=0; i<NR_CPUS; i++) {
44 if (cfe_cpu_stop(i) == 0) {
45 cpu_set(i, phys_cpu_present_map);
46 __cpu_number_map[i] = ++num;
47 __cpu_logical_map[num] = i;
48 }
49 }
50 printk("Detected %i available secondary CPU(s)\n", num);
51}
52
53/*
54 * Setup the PC, SP, and GP of a secondary processor and start it
55 * running!
56 */
57void prom_boot_secondary(int cpu, struct task_struct *idle)
58{
59 int retval;
60
61 retval = cfe_cpu_start(cpu_logical_map(cpu), &smp_bootstrap,
62 __KSTK_TOS(idle),
63 (unsigned long)idle->thread_info, 0);
64 if (retval != 0)
65 printk("cfe_start_cpu(%i) returned %i\n" , cpu, retval);
66}
67
68/*
69 * Code to run on secondary just after probing the CPU
70 */
71void prom_init_secondary(void)
72{
73 extern void sb1250_smp_init(void);
74 sb1250_smp_init();
75}
76
77/*
78 * Do any tidying up before marking online and running the idle
79 * loop
80 */
81void prom_smp_finish(void)
82{
83 extern void sb1250_smp_finish(void);
84 sb1250_smp_finish();
85}
86
87/*
88 * Final cleanup after all secondaries booted
89 */
90void prom_cpus_done(void)
91{
92}