1 /* $Id: cfe_api.c 241205 2011-02-17 21:57:41Z $ */
4 * Copyright 2000, 2001, 2002
5 * Broadcom Corporation. All rights reserved.
7 * This software is furnished under license and may be used and copied only
8 * in accordance with the following terms and conditions. Subject to these
9 * conditions, you may download, copy, install, use, modify and distribute
10 * modified or unmodified copies of this software in source and/or binary
11 * form. No title or ownership is transferred hereby.
13 * 1) Any source code used, modified or distributed must reproduce and
14 * retain this copyright notice and list of conditions as they appear in
17 * 2) No right is granted to use any trade name, trademark, or logo of
18 * Broadcom Corporation. The "Broadcom Corporation" name may not be
19 * used to endorse or promote products derived from this software
20 * without the prior written permission of Broadcom Corporation.
22 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR IMPLIED
23 * WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OF
24 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
25 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM BE LIABLE
26 * FOR ANY DAMAGES WHATSOEVER, AND IN PARTICULAR, BROADCOM SHALL NOT BE
27 * LIABLE FOR DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
30 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
32 * OR OTHERWISE), EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 /* *********************************************************************
37 * Broadcom Common Firmware Environment (CFE)
39 * Device Function stubs File: cfe_api.c
41 * This module contains device function stubs (small routines to
42 * call the standard "iocb" interface entry point to CFE).
43 * There should be one routine here per iocb function call.
45 * Authors: Mitch Lichtenberg, Chris Demetriou
47 ********************************************************************* */
50 #include "cfe_api_int.h"
52 /* Cast from a native pointer to a cfe_xptr_t and back. */
53 #define XPTR_FROM_NATIVE(n) ((cfe_xptr_t) (intptr_t) (n))
54 #define NATIVE_FROM_XPTR(x) ((void *) (intptr_t) (x))
56 #ifdef CFE_API_IMPL_NAMESPACE
57 #define cfe_iocb_dispatch(a) __cfe_iocb_dispatch(a)
59 int cfe_iocb_dispatch(cfe_xiocb_t
*xiocb
);
61 #if defined(CFE_API_common) || defined(CFE_API_ALL)
63 * Declare the dispatch function with args of "intptr_t".
64 * This makes sure whatever model we're compiling in
65 * puts the pointers in a single register. For example,
66 * combining -mlong64 and -mips1 or -mips2 would lead to
67 * trouble, since the handle and IOCB pointer will be
68 * passed in two registers each, and CFE expects one.
71 static int (*cfe_dispfunc
)(intptr_t handle
, intptr_t xiocb
) = 0;
72 static cfe_xuint_t cfe_handle
= 0;
75 cfe_init(cfe_xuint_t handle
, cfe_xuint_t ept
)
77 cfe_dispfunc
= NATIVE_FROM_XPTR(ept
);
83 cfe_iocb_dispatch(cfe_xiocb_t
*xiocb
)
85 if (!cfe_dispfunc
) return -1;
86 return (*cfe_dispfunc
)((intptr_t)cfe_handle
, (intptr_t)xiocb
);
88 #endif /* CFE_API_common || CFE_API_ALL */
90 #if defined(CFE_API_close) || defined(CFE_API_ALL)
96 xiocb
.xiocb_fcode
= CFE_CMD_DEV_CLOSE
;
97 xiocb
.xiocb_status
= 0;
98 xiocb
.xiocb_handle
= handle
;
99 xiocb
.xiocb_flags
= 0;
100 xiocb
.xiocb_psize
= 0;
102 cfe_iocb_dispatch(&xiocb
);
104 return xiocb
.xiocb_status
;
107 #endif /* CFE_API_close || CFE_API_ALL */
109 #if defined(CFE_API_cpu_start) || defined(CFE_API_ALL)
111 cfe_cpu_start(int cpu
, void (*fn
)(void), long sp
, long gp
, long a1
)
115 xiocb
.xiocb_fcode
= CFE_CMD_FW_CPUCTL
;
116 xiocb
.xiocb_status
= 0;
117 xiocb
.xiocb_handle
= 0;
118 xiocb
.xiocb_flags
= 0;
119 xiocb
.xiocb_psize
= sizeof(xiocb_cpuctl_t
);
120 xiocb
.plist
.xiocb_cpuctl
.cpu_number
= cpu
;
121 xiocb
.plist
.xiocb_cpuctl
.cpu_command
= CFE_CPU_CMD_START
;
122 xiocb
.plist
.xiocb_cpuctl
.gp_val
= gp
;
123 xiocb
.plist
.xiocb_cpuctl
.sp_val
= sp
;
124 xiocb
.plist
.xiocb_cpuctl
.a1_val
= a1
;
125 xiocb
.plist
.xiocb_cpuctl
.start_addr
= (long)fn
;
127 cfe_iocb_dispatch(&xiocb
);
129 return xiocb
.xiocb_status
;
131 #endif /* CFE_API_cpu_start || CFE_API_ALL */
133 #if defined(CFE_API_cpu_stop) || defined(CFE_API_ALL)
135 cfe_cpu_stop(int cpu
)
139 xiocb
.xiocb_fcode
= CFE_CMD_FW_CPUCTL
;
140 xiocb
.xiocb_status
= 0;
141 xiocb
.xiocb_handle
= 0;
142 xiocb
.xiocb_flags
= 0;
143 xiocb
.xiocb_psize
= sizeof(xiocb_cpuctl_t
);
144 xiocb
.plist
.xiocb_cpuctl
.cpu_number
= cpu
;
145 xiocb
.plist
.xiocb_cpuctl
.cpu_command
= CFE_CPU_CMD_STOP
;
147 cfe_iocb_dispatch(&xiocb
);
149 return xiocb
.xiocb_status
;
151 #endif /* CFE_API_cpu_stop || CFE_API_ALL */
153 #if defined(CFE_API_enumenv) || defined(CFE_API_ALL)
155 cfe_enumenv(int idx
, char *name
, int namelen
, char *val
, int vallen
)
159 xiocb
.xiocb_fcode
= CFE_CMD_ENV_SET
;
160 xiocb
.xiocb_status
= 0;
161 xiocb
.xiocb_handle
= 0;
162 xiocb
.xiocb_flags
= 0;
163 xiocb
.xiocb_psize
= sizeof(xiocb_envbuf_t
);
164 xiocb
.plist
.xiocb_envbuf
.enum_idx
= idx
;
165 xiocb
.plist
.xiocb_envbuf
.name_ptr
= XPTR_FROM_NATIVE(name
);
166 xiocb
.plist
.xiocb_envbuf
.name_length
= namelen
;
167 xiocb
.plist
.xiocb_envbuf
.val_ptr
= XPTR_FROM_NATIVE(val
);
168 xiocb
.plist
.xiocb_envbuf
.val_length
= vallen
;
170 cfe_iocb_dispatch(&xiocb
);
172 return xiocb
.xiocb_status
;
174 #endif /* CFE_API_enumenv || CFE_API_ALL */
176 #if defined(CFE_API_enummem) || defined(CFE_API_ALL)
178 cfe_enummem(int idx
, int flags
, cfe_xuint_t
*start
, cfe_xuint_t
*length
,
183 xiocb
.xiocb_fcode
= CFE_CMD_FW_MEMENUM
;
184 xiocb
.xiocb_status
= 0;
185 xiocb
.xiocb_handle
= 0;
186 xiocb
.xiocb_flags
= flags
;
187 xiocb
.xiocb_psize
= sizeof(xiocb_meminfo_t
);
188 xiocb
.plist
.xiocb_meminfo
.mi_idx
= idx
;
190 cfe_iocb_dispatch(&xiocb
);
192 if (xiocb
.xiocb_status
< 0)
193 return xiocb
.xiocb_status
;
195 *start
= xiocb
.plist
.xiocb_meminfo
.mi_addr
;
196 *length
= xiocb
.plist
.xiocb_meminfo
.mi_size
;
197 *type
= xiocb
.plist
.xiocb_meminfo
.mi_type
;
201 #endif /* CFE_API_enummem || CFE_API_ALL */
203 #if defined(CFE_API_exit) || defined(CFE_API_ALL)
205 cfe_exit(int warm
, int status
)
209 xiocb
.xiocb_fcode
= CFE_CMD_FW_RESTART
;
210 xiocb
.xiocb_status
= 0;
211 xiocb
.xiocb_handle
= 0;
212 xiocb
.xiocb_flags
= warm
? CFE_FLG_WARMSTART
: 0;
213 xiocb
.xiocb_psize
= sizeof(xiocb_exitstat_t
);
214 xiocb
.plist
.xiocb_exitstat
.status
= status
;
216 cfe_iocb_dispatch(&xiocb
);
218 return xiocb
.xiocb_status
;
220 #endif /* CFE_API_exit || CFE_API_ALL */
222 #if defined(CFE_API_flushcache) || defined(CFE_API_ALL)
224 cfe_flushcache(int flg
)
228 xiocb
.xiocb_fcode
= CFE_CMD_FW_FLUSHCACHE
;
229 xiocb
.xiocb_status
= 0;
230 xiocb
.xiocb_handle
= 0;
231 xiocb
.xiocb_flags
= flg
;
232 xiocb
.xiocb_psize
= 0;
234 cfe_iocb_dispatch(&xiocb
);
236 return xiocb
.xiocb_status
;
238 #endif /* CFE_API_flushcache || CFE_API_ALL */
240 #if defined(CFE_API_getdevinfo) || defined(CFE_API_ALL)
242 cfe_getdevinfo(char *name
)
246 xiocb
.xiocb_fcode
= CFE_CMD_DEV_GETINFO
;
247 xiocb
.xiocb_status
= 0;
248 xiocb
.xiocb_handle
= 0;
249 xiocb
.xiocb_flags
= 0;
250 xiocb
.xiocb_psize
= sizeof(xiocb_buffer_t
);
251 xiocb
.plist
.xiocb_buffer
.buf_offset
= 0;
252 xiocb
.plist
.xiocb_buffer
.buf_ptr
= XPTR_FROM_NATIVE(name
);
253 xiocb
.plist
.xiocb_buffer
.buf_length
= cfe_strlen(name
);
255 cfe_iocb_dispatch(&xiocb
);
257 if (xiocb
.xiocb_status
< 0)
258 return xiocb
.xiocb_status
;
259 return xiocb
.plist
.xiocb_buffer
.buf_devflags
;
261 #endif /* CFE_API_getdevinfo || CFE_API_ALL */
263 #if defined(CFE_API_getenv) || defined(CFE_API_ALL)
265 cfe_getenv(char *name
, char *dest
, int destlen
)
271 xiocb
.xiocb_fcode
= CFE_CMD_ENV_GET
;
272 xiocb
.xiocb_status
= 0;
273 xiocb
.xiocb_handle
= 0;
274 xiocb
.xiocb_flags
= 0;
275 xiocb
.xiocb_psize
= sizeof(xiocb_envbuf_t
);
276 xiocb
.plist
.xiocb_envbuf
.enum_idx
= 0;
277 xiocb
.plist
.xiocb_envbuf
.name_ptr
= XPTR_FROM_NATIVE(name
);
278 xiocb
.plist
.xiocb_envbuf
.name_length
= cfe_strlen(name
);
279 xiocb
.plist
.xiocb_envbuf
.val_ptr
= XPTR_FROM_NATIVE(dest
);
280 xiocb
.plist
.xiocb_envbuf
.val_length
= destlen
;
282 cfe_iocb_dispatch(&xiocb
);
284 return xiocb
.xiocb_status
;
286 #endif /* CFE_API_getenv || CFE_API_ALL */
288 #if defined(CFE_API_getfwinfo) || defined(CFE_API_ALL)
290 cfe_getfwinfo(cfe_fwinfo_t
*info
)
294 xiocb
.xiocb_fcode
= CFE_CMD_FW_GETINFO
;
295 xiocb
.xiocb_status
= 0;
296 xiocb
.xiocb_handle
= 0;
297 xiocb
.xiocb_flags
= 0;
298 xiocb
.xiocb_psize
= sizeof(xiocb_fwinfo_t
);
300 cfe_iocb_dispatch(&xiocb
);
302 if (xiocb
.xiocb_status
< 0)
303 return xiocb
.xiocb_status
;
305 info
->fwi_version
= xiocb
.plist
.xiocb_fwinfo
.fwi_version
;
306 info
->fwi_totalmem
= xiocb
.plist
.xiocb_fwinfo
.fwi_totalmem
;
307 info
->fwi_flags
= xiocb
.plist
.xiocb_fwinfo
.fwi_flags
;
308 info
->fwi_boardid
= xiocb
.plist
.xiocb_fwinfo
.fwi_boardid
;
309 info
->fwi_bootarea_va
= xiocb
.plist
.xiocb_fwinfo
.fwi_bootarea_va
;
310 info
->fwi_bootarea_pa
= xiocb
.plist
.xiocb_fwinfo
.fwi_bootarea_pa
;
311 info
->fwi_bootarea_size
= xiocb
.plist
.xiocb_fwinfo
.fwi_bootarea_size
;
315 #endif /* CFE_API_getfwinfo || CFE_API_ALL */
317 #if defined(CFE_API_getstdhandle) || defined(CFE_API_ALL)
319 cfe_getstdhandle(int flg
)
323 xiocb
.xiocb_fcode
= CFE_CMD_DEV_GETHANDLE
;
324 xiocb
.xiocb_status
= 0;
325 xiocb
.xiocb_handle
= 0;
326 xiocb
.xiocb_flags
= flg
;
327 xiocb
.xiocb_psize
= 0;
329 cfe_iocb_dispatch(&xiocb
);
331 if (xiocb
.xiocb_status
< 0)
332 return xiocb
.xiocb_status
;
333 return xiocb
.xiocb_handle
;
336 #endif /* CFE_API_getstdhandle || CFE_API_ALL */
338 #if defined(CFE_API_getticks) || defined(CFE_API_ALL)
340 #ifdef CFE_API_IMPL_NAMESPACE
348 xiocb
.xiocb_fcode
= CFE_CMD_FW_GETTIME
;
349 xiocb
.xiocb_status
= 0;
350 xiocb
.xiocb_handle
= 0;
351 xiocb
.xiocb_flags
= 0;
352 xiocb
.xiocb_psize
= sizeof(xiocb_time_t
);
353 xiocb
.plist
.xiocb_time
.ticks
= 0;
355 cfe_iocb_dispatch(&xiocb
);
357 return xiocb
.plist
.xiocb_time
.ticks
;
360 #endif /* CFE_API_getticks || CFE_API_ALL */
362 #if defined(CFE_API_inpstat) || defined(CFE_API_ALL)
364 cfe_inpstat(int handle
)
368 xiocb
.xiocb_fcode
= CFE_CMD_DEV_INPSTAT
;
369 xiocb
.xiocb_status
= 0;
370 xiocb
.xiocb_handle
= handle
;
371 xiocb
.xiocb_flags
= 0;
372 xiocb
.xiocb_psize
= sizeof(xiocb_inpstat_t
);
373 xiocb
.plist
.xiocb_inpstat
.inp_status
= 0;
375 cfe_iocb_dispatch(&xiocb
);
377 if (xiocb
.xiocb_status
< 0)
378 return xiocb
.xiocb_status
;
379 return xiocb
.plist
.xiocb_inpstat
.inp_status
;
382 #endif /* CFE_API_inpstat || CFE_API_ALL */
384 #if defined(CFE_API_ioctl) || defined(CFE_API_ALL)
386 cfe_ioctl(int handle
, unsigned int ioctlnum
, unsigned char *buffer
, int length
,
387 int *retlen
, cfe_xuint_t offset
)
391 xiocb
.xiocb_fcode
= CFE_CMD_DEV_IOCTL
;
392 xiocb
.xiocb_status
= 0;
393 xiocb
.xiocb_handle
= handle
;
394 xiocb
.xiocb_flags
= 0;
395 xiocb
.xiocb_psize
= sizeof(xiocb_buffer_t
);
396 xiocb
.plist
.xiocb_buffer
.buf_offset
= offset
;
397 xiocb
.plist
.xiocb_buffer
.buf_ioctlcmd
= ioctlnum
;
398 xiocb
.plist
.xiocb_buffer
.buf_ptr
= XPTR_FROM_NATIVE(buffer
);
399 xiocb
.plist
.xiocb_buffer
.buf_length
= length
;
401 cfe_iocb_dispatch(&xiocb
);
404 *retlen
= xiocb
.plist
.xiocb_buffer
.buf_retlen
;
405 return xiocb
.xiocb_status
;
407 #endif /* CFE_API_ioctl || CFE_API_ALL */
409 #if defined(CFE_API_open) || defined(CFE_API_ALL)
415 xiocb
.xiocb_fcode
= CFE_CMD_DEV_OPEN
;
416 xiocb
.xiocb_status
= 0;
417 xiocb
.xiocb_handle
= 0;
418 xiocb
.xiocb_flags
= 0;
419 xiocb
.xiocb_psize
= sizeof(xiocb_buffer_t
);
420 xiocb
.plist
.xiocb_buffer
.buf_offset
= 0;
421 xiocb
.plist
.xiocb_buffer
.buf_ptr
= XPTR_FROM_NATIVE(name
);
422 xiocb
.plist
.xiocb_buffer
.buf_length
= cfe_strlen(name
);
424 cfe_iocb_dispatch(&xiocb
);
426 if (xiocb
.xiocb_status
< 0)
427 return xiocb
.xiocb_status
;
428 return xiocb
.xiocb_handle
;
430 #endif /* CFE_API_open || CFE_API_ALL */
432 #if defined(CFE_API_read) || defined(CFE_API_ALL)
434 cfe_read(int handle
, unsigned char *buffer
, int length
)
436 return cfe_readblk(handle
, 0, buffer
, length
);
438 #endif /* CFE_API_read || CFE_API_ALL */
440 #if defined(CFE_API_readblk) || defined(CFE_API_ALL)
442 cfe_readblk(int handle
, cfe_xint_t offset
, unsigned char *buffer
, int length
)
446 xiocb
.xiocb_fcode
= CFE_CMD_DEV_READ
;
447 xiocb
.xiocb_status
= 0;
448 xiocb
.xiocb_handle
= handle
;
449 xiocb
.xiocb_flags
= 0;
450 xiocb
.xiocb_psize
= sizeof(xiocb_buffer_t
);
451 xiocb
.plist
.xiocb_buffer
.buf_offset
= offset
;
452 xiocb
.plist
.xiocb_buffer
.buf_ptr
= XPTR_FROM_NATIVE(buffer
);
453 xiocb
.plist
.xiocb_buffer
.buf_length
= length
;
455 cfe_iocb_dispatch(&xiocb
);
457 if (xiocb
.xiocb_status
< 0)
458 return xiocb
.xiocb_status
;
459 return xiocb
.plist
.xiocb_buffer
.buf_retlen
;
461 #endif /* CFE_API_readblk || CFE_API_ALL */
463 #if defined(CFE_API_setenv) || defined(CFE_API_ALL)
465 cfe_setenv(char *name
, char *val
)
469 xiocb
.xiocb_fcode
= CFE_CMD_ENV_SET
;
470 xiocb
.xiocb_status
= 0;
471 xiocb
.xiocb_handle
= 0;
472 xiocb
.xiocb_flags
= 0;
473 xiocb
.xiocb_psize
= sizeof(xiocb_envbuf_t
);
474 xiocb
.plist
.xiocb_envbuf
.enum_idx
= 0;
475 xiocb
.plist
.xiocb_envbuf
.name_ptr
= XPTR_FROM_NATIVE(name
);
476 xiocb
.plist
.xiocb_envbuf
.name_length
= cfe_strlen(name
);
477 xiocb
.plist
.xiocb_envbuf
.val_ptr
= XPTR_FROM_NATIVE(val
);
478 xiocb
.plist
.xiocb_envbuf
.val_length
= cfe_strlen(val
);
480 cfe_iocb_dispatch(&xiocb
);
482 return xiocb
.xiocb_status
;
484 #endif /* CFE_API_setenv || CFE_API_ALL */
486 #if (defined(CFE_API_strlen) || defined(CFE_API_ALL)) && \
487 !defined(CFE_API_STRLEN_CUSTOM)
489 cfe_strlen(char *name
)
498 #endif /* CFE_API_strlen || CFE_API_ALL */
500 #if defined(CFE_API_write) || defined(CFE_API_ALL)
502 cfe_write(int handle
, unsigned char *buffer
, int length
)
504 return cfe_writeblk(handle
, 0, buffer
, length
);
506 #endif /* CFE_API_write || CFE_API_ALL */
508 #if defined(CFE_API_writeblk) || defined(CFE_API_ALL)
510 cfe_writeblk(int handle
, cfe_xint_t offset
, unsigned char *buffer
, int length
)
514 xiocb
.xiocb_fcode
= CFE_CMD_DEV_WRITE
;
515 xiocb
.xiocb_status
= 0;
516 xiocb
.xiocb_handle
= handle
;
517 xiocb
.xiocb_flags
= 0;
518 xiocb
.xiocb_psize
= sizeof(xiocb_buffer_t
);
519 xiocb
.plist
.xiocb_buffer
.buf_offset
= offset
;
520 xiocb
.plist
.xiocb_buffer
.buf_ptr
= XPTR_FROM_NATIVE(buffer
);
521 xiocb
.plist
.xiocb_buffer
.buf_length
= length
;
523 cfe_iocb_dispatch(&xiocb
);
525 if (xiocb
.xiocb_status
< 0)
526 return xiocb
.xiocb_status
;
527 return xiocb
.plist
.xiocb_buffer
.buf_retlen
;
529 #endif /* CFE_API_writeblk || CFE_API_ALL */