2 /* from: SiByte Id: cfe_api.c,v 1.16 2002/07/09 23:29:11 cgd Exp $ */
5 * Copyright 2000, 2001, 2002
6 * Broadcom Corporation. All rights reserved.
8 * This software is furnished under license and may be used and copied only
9 * in accordance with the following terms and conditions. Subject to these
10 * conditions, you may download, copy, install, use, modify and distribute
11 * modified or unmodified copies of this software in source and/or binary
12 * form. No title or ownership is transferred hereby.
14 * 1) Any source code used, modified or distributed must reproduce and
15 * retain this copyright notice and list of conditions as they appear in
18 * 2) No right is granted to use any trade name, trademark, or logo of
19 * Broadcom Corporation. The "Broadcom Corporation" name may not be
20 * used to endorse or promote products derived from this software
21 * without the prior written permission of Broadcom Corporation.
23 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR IMPLIED
24 * WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
26 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM BE LIABLE
27 * FOR ANY DAMAGES WHATSOEVER, AND IN PARTICULAR, BROADCOM SHALL NOT BE
28 * LIABLE FOR DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
31 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
33 * OR OTHERWISE), EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 /* *********************************************************************
38 * Broadcom Common Firmware Environment (CFE)
40 * Device Function stubs File: cfe_api.c
42 * This module contains device function stubs (small routines to
43 * call the standard "iocb" interface entry point to CFE).
44 * There should be one routine here per iocb function call.
46 * Authors: Mitch Lichtenberg, Chris Demetriou
48 ********************************************************************* */
51 #include "cfe_api_int.h"
53 /* Cast from a native pointer to a cfe_xptr_t and back. */
54 #define XPTR_FROM_NATIVE(n) ((cfe_xptr_t) (intptr_t) (n))
55 #define NATIVE_FROM_XPTR(x) ((void *) (intptr_t) (x))
57 #ifdef CFE_API_IMPL_NAMESPACE
58 #define cfe_iocb_dispatch(a) __cfe_iocb_dispatch(a)
60 int cfe_iocb_dispatch(cfe_xiocb_t
*xiocb
);
62 #if defined(CFE_API_common) || defined(CFE_API_ALL)
64 * Declare the dispatch function with args of "intptr_t".
65 * This makes sure whatever model we're compiling in
66 * puts the pointers in a single register. For example,
67 * combining -mlong64 and -mips1 or -mips2 would lead to
68 * trouble, since the handle and IOCB pointer will be
69 * passed in two registers each, and CFE expects one.
72 static int (*cfe_dispfunc
)(intptr_t handle
, intptr_t xiocb
) = 0;
73 static cfe_xuint_t cfe_handle
= 0;
76 cfe_init(cfe_xuint_t handle
, cfe_xuint_t ept
)
78 cfe_dispfunc
= NATIVE_FROM_XPTR(ept
);
84 cfe_iocb_dispatch(cfe_xiocb_t
*xiocb
)
86 if (!cfe_dispfunc
) return -1;
87 return (*cfe_dispfunc
)((intptr_t)cfe_handle
, (intptr_t)xiocb
);
89 #endif /* CFE_API_common || CFE_API_ALL */
91 #if defined(CFE_API_close) || defined(CFE_API_ALL)
97 xiocb
.xiocb_fcode
= CFE_CMD_DEV_CLOSE
;
98 xiocb
.xiocb_status
= 0;
99 xiocb
.xiocb_handle
= handle
;
100 xiocb
.xiocb_flags
= 0;
101 xiocb
.xiocb_psize
= 0;
103 cfe_iocb_dispatch(&xiocb
);
105 return xiocb
.xiocb_status
;
108 #endif /* CFE_API_close || CFE_API_ALL */
110 #if defined(CFE_API_cpu_start) || defined(CFE_API_ALL)
112 cfe_cpu_start(int cpu
, void (*fn
)(void), long sp
, long gp
, long a1
)
116 xiocb
.xiocb_fcode
= CFE_CMD_FW_CPUCTL
;
117 xiocb
.xiocb_status
= 0;
118 xiocb
.xiocb_handle
= 0;
119 xiocb
.xiocb_flags
= 0;
120 xiocb
.xiocb_psize
= sizeof(xiocb_cpuctl_t
);
121 xiocb
.plist
.xiocb_cpuctl
.cpu_number
= cpu
;
122 xiocb
.plist
.xiocb_cpuctl
.cpu_command
= CFE_CPU_CMD_START
;
123 xiocb
.plist
.xiocb_cpuctl
.gp_val
= gp
;
124 xiocb
.plist
.xiocb_cpuctl
.sp_val
= sp
;
125 xiocb
.plist
.xiocb_cpuctl
.a1_val
= a1
;
126 xiocb
.plist
.xiocb_cpuctl
.start_addr
= (long)fn
;
128 cfe_iocb_dispatch(&xiocb
);
130 return xiocb
.xiocb_status
;
132 #endif /* CFE_API_cpu_start || CFE_API_ALL */
134 #if defined(CFE_API_cpu_stop) || defined(CFE_API_ALL)
136 cfe_cpu_stop(int cpu
)
140 xiocb
.xiocb_fcode
= CFE_CMD_FW_CPUCTL
;
141 xiocb
.xiocb_status
= 0;
142 xiocb
.xiocb_handle
= 0;
143 xiocb
.xiocb_flags
= 0;
144 xiocb
.xiocb_psize
= sizeof(xiocb_cpuctl_t
);
145 xiocb
.plist
.xiocb_cpuctl
.cpu_number
= cpu
;
146 xiocb
.plist
.xiocb_cpuctl
.cpu_command
= CFE_CPU_CMD_STOP
;
148 cfe_iocb_dispatch(&xiocb
);
150 return xiocb
.xiocb_status
;
152 #endif /* CFE_API_cpu_stop || CFE_API_ALL */
154 #if defined(CFE_API_enumenv) || defined(CFE_API_ALL)
156 cfe_enumenv(int idx
, char *name
, int namelen
, char *val
, int vallen
)
160 xiocb
.xiocb_fcode
= CFE_CMD_ENV_SET
;
161 xiocb
.xiocb_status
= 0;
162 xiocb
.xiocb_handle
= 0;
163 xiocb
.xiocb_flags
= 0;
164 xiocb
.xiocb_psize
= sizeof(xiocb_envbuf_t
);
165 xiocb
.plist
.xiocb_envbuf
.enum_idx
= idx
;
166 xiocb
.plist
.xiocb_envbuf
.name_ptr
= XPTR_FROM_NATIVE(name
);
167 xiocb
.plist
.xiocb_envbuf
.name_length
= namelen
;
168 xiocb
.plist
.xiocb_envbuf
.val_ptr
= XPTR_FROM_NATIVE(val
);
169 xiocb
.plist
.xiocb_envbuf
.val_length
= vallen
;
171 cfe_iocb_dispatch(&xiocb
);
173 return xiocb
.xiocb_status
;
175 #endif /* CFE_API_enumenv || CFE_API_ALL */
177 #if defined(CFE_API_enummem) || defined(CFE_API_ALL)
179 cfe_enummem(int idx
, int flags
, cfe_xuint_t
*start
, cfe_xuint_t
*length
,
184 xiocb
.xiocb_fcode
= CFE_CMD_FW_MEMENUM
;
185 xiocb
.xiocb_status
= 0;
186 xiocb
.xiocb_handle
= 0;
187 xiocb
.xiocb_flags
= flags
;
188 xiocb
.xiocb_psize
= sizeof(xiocb_meminfo_t
);
189 xiocb
.plist
.xiocb_meminfo
.mi_idx
= idx
;
191 cfe_iocb_dispatch(&xiocb
);
193 if (xiocb
.xiocb_status
< 0)
194 return xiocb
.xiocb_status
;
196 *start
= xiocb
.plist
.xiocb_meminfo
.mi_addr
;
197 *length
= xiocb
.plist
.xiocb_meminfo
.mi_size
;
198 *type
= xiocb
.plist
.xiocb_meminfo
.mi_type
;
202 #endif /* CFE_API_enummem || CFE_API_ALL */
204 #if defined(CFE_API_exit) || defined(CFE_API_ALL)
206 cfe_exit(int warm
, int status
)
210 xiocb
.xiocb_fcode
= CFE_CMD_FW_RESTART
;
211 xiocb
.xiocb_status
= 0;
212 xiocb
.xiocb_handle
= 0;
213 xiocb
.xiocb_flags
= warm
? CFE_FLG_WARMSTART
: 0;
214 xiocb
.xiocb_psize
= sizeof(xiocb_exitstat_t
);
215 xiocb
.plist
.xiocb_exitstat
.status
= status
;
217 cfe_iocb_dispatch(&xiocb
);
219 return xiocb
.xiocb_status
;
221 #endif /* CFE_API_exit || CFE_API_ALL */
223 #if defined(CFE_API_flushcache) || defined(CFE_API_ALL)
225 cfe_flushcache(int flg
)
229 xiocb
.xiocb_fcode
= CFE_CMD_FW_FLUSHCACHE
;
230 xiocb
.xiocb_status
= 0;
231 xiocb
.xiocb_handle
= 0;
232 xiocb
.xiocb_flags
= flg
;
233 xiocb
.xiocb_psize
= 0;
235 cfe_iocb_dispatch(&xiocb
);
237 return xiocb
.xiocb_status
;
239 #endif /* CFE_API_flushcache || CFE_API_ALL */
241 #if defined(CFE_API_getdevinfo) || defined(CFE_API_ALL)
243 cfe_getdevinfo(char *name
)
247 xiocb
.xiocb_fcode
= CFE_CMD_DEV_GETINFO
;
248 xiocb
.xiocb_status
= 0;
249 xiocb
.xiocb_handle
= 0;
250 xiocb
.xiocb_flags
= 0;
251 xiocb
.xiocb_psize
= sizeof(xiocb_buffer_t
);
252 xiocb
.plist
.xiocb_buffer
.buf_offset
= 0;
253 xiocb
.plist
.xiocb_buffer
.buf_ptr
= XPTR_FROM_NATIVE(name
);
254 xiocb
.plist
.xiocb_buffer
.buf_length
= cfe_strlen(name
);
256 cfe_iocb_dispatch(&xiocb
);
258 if (xiocb
.xiocb_status
< 0)
259 return xiocb
.xiocb_status
;
260 return xiocb
.plist
.xiocb_buffer
.buf_devflags
;
262 #endif /* CFE_API_getdevinfo || CFE_API_ALL */
264 #if defined(CFE_API_getenv) || defined(CFE_API_ALL)
266 cfe_getenv(char *name
, char *dest
, int destlen
)
272 xiocb
.xiocb_fcode
= CFE_CMD_ENV_GET
;
273 xiocb
.xiocb_status
= 0;
274 xiocb
.xiocb_handle
= 0;
275 xiocb
.xiocb_flags
= 0;
276 xiocb
.xiocb_psize
= sizeof(xiocb_envbuf_t
);
277 xiocb
.plist
.xiocb_envbuf
.enum_idx
= 0;
278 xiocb
.plist
.xiocb_envbuf
.name_ptr
= XPTR_FROM_NATIVE(name
);
279 xiocb
.plist
.xiocb_envbuf
.name_length
= cfe_strlen(name
);
280 xiocb
.plist
.xiocb_envbuf
.val_ptr
= XPTR_FROM_NATIVE(dest
);
281 xiocb
.plist
.xiocb_envbuf
.val_length
= destlen
;
283 cfe_iocb_dispatch(&xiocb
);
285 return xiocb
.xiocb_status
;
287 #endif /* CFE_API_getenv || CFE_API_ALL */
289 #if defined(CFE_API_getfwinfo) || defined(CFE_API_ALL)
291 cfe_getfwinfo(cfe_fwinfo_t
*info
)
295 xiocb
.xiocb_fcode
= CFE_CMD_FW_GETINFO
;
296 xiocb
.xiocb_status
= 0;
297 xiocb
.xiocb_handle
= 0;
298 xiocb
.xiocb_flags
= 0;
299 xiocb
.xiocb_psize
= sizeof(xiocb_fwinfo_t
);
301 cfe_iocb_dispatch(&xiocb
);
303 if (xiocb
.xiocb_status
< 0)
304 return xiocb
.xiocb_status
;
306 info
->fwi_version
= xiocb
.plist
.xiocb_fwinfo
.fwi_version
;
307 info
->fwi_totalmem
= xiocb
.plist
.xiocb_fwinfo
.fwi_totalmem
;
308 info
->fwi_flags
= xiocb
.plist
.xiocb_fwinfo
.fwi_flags
;
309 info
->fwi_boardid
= xiocb
.plist
.xiocb_fwinfo
.fwi_boardid
;
310 info
->fwi_bootarea_va
= xiocb
.plist
.xiocb_fwinfo
.fwi_bootarea_va
;
311 info
->fwi_bootarea_pa
= xiocb
.plist
.xiocb_fwinfo
.fwi_bootarea_pa
;
312 info
->fwi_bootarea_size
= xiocb
.plist
.xiocb_fwinfo
.fwi_bootarea_size
;
314 info
->fwi_reserved1
= xiocb
.plist
.xiocb_fwinfo
.fwi_reserved1
;
315 info
->fwi_reserved2
= xiocb
.plist
.xiocb_fwinfo
.fwi_reserved2
;
316 info
->fwi_reserved3
= xiocb
.plist
.xiocb_fwinfo
.fwi_reserved3
;
321 #endif /* CFE_API_getfwinfo || CFE_API_ALL */
323 #if defined(CFE_API_getstdhandle) || defined(CFE_API_ALL)
325 cfe_getstdhandle(int flg
)
329 xiocb
.xiocb_fcode
= CFE_CMD_DEV_GETHANDLE
;
330 xiocb
.xiocb_status
= 0;
331 xiocb
.xiocb_handle
= 0;
332 xiocb
.xiocb_flags
= flg
;
333 xiocb
.xiocb_psize
= 0;
335 cfe_iocb_dispatch(&xiocb
);
337 if (xiocb
.xiocb_status
< 0)
338 return xiocb
.xiocb_status
;
339 return xiocb
.xiocb_handle
;
342 #endif /* CFE_API_getstdhandle || CFE_API_ALL */
344 #if defined(CFE_API_getticks) || defined(CFE_API_ALL)
346 #ifdef CFE_API_IMPL_NAMESPACE
354 xiocb
.xiocb_fcode
= CFE_CMD_FW_GETTIME
;
355 xiocb
.xiocb_status
= 0;
356 xiocb
.xiocb_handle
= 0;
357 xiocb
.xiocb_flags
= 0;
358 xiocb
.xiocb_psize
= sizeof(xiocb_time_t
);
359 xiocb
.plist
.xiocb_time
.ticks
= 0;
361 cfe_iocb_dispatch(&xiocb
);
363 return xiocb
.plist
.xiocb_time
.ticks
;
366 #endif /* CFE_API_getticks || CFE_API_ALL */
368 #if defined(CFE_API_inpstat) || defined(CFE_API_ALL)
370 cfe_inpstat(int handle
)
374 xiocb
.xiocb_fcode
= CFE_CMD_DEV_INPSTAT
;
375 xiocb
.xiocb_status
= 0;
376 xiocb
.xiocb_handle
= handle
;
377 xiocb
.xiocb_flags
= 0;
378 xiocb
.xiocb_psize
= sizeof(xiocb_inpstat_t
);
379 xiocb
.plist
.xiocb_inpstat
.inp_status
= 0;
381 cfe_iocb_dispatch(&xiocb
);
383 if (xiocb
.xiocb_status
< 0)
384 return xiocb
.xiocb_status
;
385 return xiocb
.plist
.xiocb_inpstat
.inp_status
;
388 #endif /* CFE_API_inpstat || CFE_API_ALL */
390 #if defined(CFE_API_ioctl) || defined(CFE_API_ALL)
392 cfe_ioctl(int handle
, unsigned int ioctlnum
, unsigned char *buffer
, int length
,
393 int *retlen
, cfe_xuint_t offset
)
397 xiocb
.xiocb_fcode
= CFE_CMD_DEV_IOCTL
;
398 xiocb
.xiocb_status
= 0;
399 xiocb
.xiocb_handle
= handle
;
400 xiocb
.xiocb_flags
= 0;
401 xiocb
.xiocb_psize
= sizeof(xiocb_buffer_t
);
402 xiocb
.plist
.xiocb_buffer
.buf_offset
= offset
;
403 xiocb
.plist
.xiocb_buffer
.buf_ioctlcmd
= ioctlnum
;
404 xiocb
.plist
.xiocb_buffer
.buf_ptr
= XPTR_FROM_NATIVE(buffer
);
405 xiocb
.plist
.xiocb_buffer
.buf_length
= length
;
407 cfe_iocb_dispatch(&xiocb
);
410 *retlen
= xiocb
.plist
.xiocb_buffer
.buf_retlen
;
411 return xiocb
.xiocb_status
;
413 #endif /* CFE_API_ioctl || CFE_API_ALL */
415 #if defined(CFE_API_open) || defined(CFE_API_ALL)
421 xiocb
.xiocb_fcode
= CFE_CMD_DEV_OPEN
;
422 xiocb
.xiocb_status
= 0;
423 xiocb
.xiocb_handle
= 0;
424 xiocb
.xiocb_flags
= 0;
425 xiocb
.xiocb_psize
= sizeof(xiocb_buffer_t
);
426 xiocb
.plist
.xiocb_buffer
.buf_offset
= 0;
427 xiocb
.plist
.xiocb_buffer
.buf_ptr
= XPTR_FROM_NATIVE(name
);
428 xiocb
.plist
.xiocb_buffer
.buf_length
= cfe_strlen(name
);
430 cfe_iocb_dispatch(&xiocb
);
432 if (xiocb
.xiocb_status
< 0)
433 return xiocb
.xiocb_status
;
434 return xiocb
.xiocb_handle
;
436 #endif /* CFE_API_open || CFE_API_ALL */
438 #if defined(CFE_API_read) || defined(CFE_API_ALL)
440 cfe_read(int handle
, unsigned char *buffer
, int length
)
442 return cfe_readblk(handle
, 0, buffer
, length
);
444 #endif /* CFE_API_read || CFE_API_ALL */
446 #if defined(CFE_API_readblk) || defined(CFE_API_ALL)
448 cfe_readblk(int handle
, cfe_xint_t offset
, unsigned char *buffer
, int length
)
452 xiocb
.xiocb_fcode
= CFE_CMD_DEV_READ
;
453 xiocb
.xiocb_status
= 0;
454 xiocb
.xiocb_handle
= handle
;
455 xiocb
.xiocb_flags
= 0;
456 xiocb
.xiocb_psize
= sizeof(xiocb_buffer_t
);
457 xiocb
.plist
.xiocb_buffer
.buf_offset
= offset
;
458 xiocb
.plist
.xiocb_buffer
.buf_ptr
= XPTR_FROM_NATIVE(buffer
);
459 xiocb
.plist
.xiocb_buffer
.buf_length
= length
;
461 cfe_iocb_dispatch(&xiocb
);
463 if (xiocb
.xiocb_status
< 0)
464 return xiocb
.xiocb_status
;
465 return xiocb
.plist
.xiocb_buffer
.buf_retlen
;
467 #endif /* CFE_API_readblk || CFE_API_ALL */
469 #if defined(CFE_API_setenv) || defined(CFE_API_ALL)
471 cfe_setenv(char *name
, char *val
)
475 xiocb
.xiocb_fcode
= CFE_CMD_ENV_SET
;
476 xiocb
.xiocb_status
= 0;
477 xiocb
.xiocb_handle
= 0;
478 xiocb
.xiocb_flags
= 0;
479 xiocb
.xiocb_psize
= sizeof(xiocb_envbuf_t
);
480 xiocb
.plist
.xiocb_envbuf
.enum_idx
= 0;
481 xiocb
.plist
.xiocb_envbuf
.name_ptr
= XPTR_FROM_NATIVE(name
);
482 xiocb
.plist
.xiocb_envbuf
.name_length
= cfe_strlen(name
);
483 xiocb
.plist
.xiocb_envbuf
.val_ptr
= XPTR_FROM_NATIVE(val
);
484 xiocb
.plist
.xiocb_envbuf
.val_length
= cfe_strlen(val
);
486 cfe_iocb_dispatch(&xiocb
);
488 return xiocb
.xiocb_status
;
490 #endif /* CFE_API_setenv || CFE_API_ALL */
492 #if (defined(CFE_API_strlen) || defined(CFE_API_ALL)) \
493 && !defined(CFE_API_STRLEN_CUSTOM)
495 cfe_strlen(char *name
)
504 #endif /* CFE_API_strlen || CFE_API_ALL */
506 #if defined(CFE_API_write) || defined(CFE_API_ALL)
508 cfe_write(int handle
, unsigned char *buffer
, int length
)
510 return cfe_writeblk(handle
, 0, buffer
, length
);
512 #endif /* CFE_API_write || CFE_API_ALL */
514 #if defined(CFE_API_writeblk) || defined(CFE_API_ALL)
516 cfe_writeblk(int handle
, cfe_xint_t offset
, unsigned char *buffer
, int length
)
520 xiocb
.xiocb_fcode
= CFE_CMD_DEV_WRITE
;
521 xiocb
.xiocb_status
= 0;
522 xiocb
.xiocb_handle
= handle
;
523 xiocb
.xiocb_flags
= 0;
524 xiocb
.xiocb_psize
= sizeof(xiocb_buffer_t
);
525 xiocb
.plist
.xiocb_buffer
.buf_offset
= offset
;
526 xiocb
.plist
.xiocb_buffer
.buf_ptr
= XPTR_FROM_NATIVE(buffer
);
527 xiocb
.plist
.xiocb_buffer
.buf_length
= length
;
529 cfe_iocb_dispatch(&xiocb
);
531 if (xiocb
.xiocb_status
< 0)
532 return xiocb
.xiocb_status
;
533 return xiocb
.plist
.xiocb_buffer
.buf_retlen
;
535 #endif /* CFE_API_writeblk || CFE_API_ALL */