1 /* $NetBSD: cfe_api.c,v 1.3.2.3 2004/09/21 13:18:38 skrll Exp $ */
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 ********************************************************************* */
50 #include <sys/cdefs.h>
51 __KERNEL_RCSID(0, "$NetBSD: cfe_api.c,v 1.3.2.3 2004/09/21 13:18:38 skrll Exp $");
54 #include "cfe_api_int.h"
56 /* Cast from a native pointer to a cfe_xptr_t and back. */
57 #define XPTR_FROM_NATIVE(n) ((cfe_xptr_t) (intptr_t) (n))
58 #define NATIVE_FROM_XPTR(x) ((void *) (intptr_t) (x))
60 #ifdef CFE_API_IMPL_NAMESPACE
61 #define cfe_iocb_dispatch(a) __cfe_iocb_dispatch(a)
63 int cfe_iocb_dispatch(cfe_xiocb_t
*xiocb
);
65 #if defined(CFE_API_common) || defined(CFE_API_ALL)
67 * Declare the dispatch function with args of "intptr_t".
68 * This makes sure whatever model we're compiling in
69 * puts the pointers in a single register. For example,
70 * combining -mlong64 and -mips1 or -mips2 would lead to
71 * trouble, since the handle and IOCB pointer will be
72 * passed in two registers each, and CFE expects one.
75 static int (*cfe_dispfunc
)(intptr_t handle
, intptr_t xiocb
) = 0;
76 static cfe_xuint_t cfe_handle
= 0;
79 cfe_init(cfe_xuint_t handle
, cfe_xuint_t ept
)
81 cfe_dispfunc
= NATIVE_FROM_XPTR(ept
);
87 cfe_iocb_dispatch(cfe_xiocb_t
*xiocb
)
89 if (!cfe_dispfunc
) return -1;
90 return (*cfe_dispfunc
)((intptr_t)cfe_handle
, (intptr_t)xiocb
);
92 #endif /* CFE_API_common || CFE_API_ALL */
94 #if defined(CFE_API_close) || defined(CFE_API_ALL)
100 xiocb
.xiocb_fcode
= CFE_CMD_DEV_CLOSE
;
101 xiocb
.xiocb_status
= 0;
102 xiocb
.xiocb_handle
= handle
;
103 xiocb
.xiocb_flags
= 0;
104 xiocb
.xiocb_psize
= 0;
106 cfe_iocb_dispatch(&xiocb
);
108 return xiocb
.xiocb_status
;
111 #endif /* CFE_API_close || CFE_API_ALL */
113 #if defined(CFE_API_cpu_start) || defined(CFE_API_ALL)
115 cfe_cpu_start(int cpu
, void (*fn
)(void), long sp
, long gp
, long a1
)
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_START
;
126 xiocb
.plist
.xiocb_cpuctl
.gp_val
= gp
;
127 xiocb
.plist
.xiocb_cpuctl
.sp_val
= sp
;
128 xiocb
.plist
.xiocb_cpuctl
.a1_val
= a1
;
129 xiocb
.plist
.xiocb_cpuctl
.start_addr
= (long)fn
;
131 cfe_iocb_dispatch(&xiocb
);
133 return xiocb
.xiocb_status
;
135 #endif /* CFE_API_cpu_start || CFE_API_ALL */
137 #if defined(CFE_API_cpu_stop) || defined(CFE_API_ALL)
139 cfe_cpu_stop(int cpu
)
143 xiocb
.xiocb_fcode
= CFE_CMD_FW_CPUCTL
;
144 xiocb
.xiocb_status
= 0;
145 xiocb
.xiocb_handle
= 0;
146 xiocb
.xiocb_flags
= 0;
147 xiocb
.xiocb_psize
= sizeof(xiocb_cpuctl_t
);
148 xiocb
.plist
.xiocb_cpuctl
.cpu_number
= cpu
;
149 xiocb
.plist
.xiocb_cpuctl
.cpu_command
= CFE_CPU_CMD_STOP
;
151 cfe_iocb_dispatch(&xiocb
);
153 return xiocb
.xiocb_status
;
155 #endif /* CFE_API_cpu_stop || CFE_API_ALL */
157 #if defined(CFE_API_enumenv) || defined(CFE_API_ALL)
159 cfe_enumenv(int idx
, char *name
, int namelen
, char *val
, int vallen
)
163 xiocb
.xiocb_fcode
= CFE_CMD_ENV_SET
;
164 xiocb
.xiocb_status
= 0;
165 xiocb
.xiocb_handle
= 0;
166 xiocb
.xiocb_flags
= 0;
167 xiocb
.xiocb_psize
= sizeof(xiocb_envbuf_t
);
168 xiocb
.plist
.xiocb_envbuf
.enum_idx
= idx
;
169 xiocb
.plist
.xiocb_envbuf
.name_ptr
= XPTR_FROM_NATIVE(name
);
170 xiocb
.plist
.xiocb_envbuf
.name_length
= namelen
;
171 xiocb
.plist
.xiocb_envbuf
.val_ptr
= XPTR_FROM_NATIVE(val
);
172 xiocb
.plist
.xiocb_envbuf
.val_length
= vallen
;
174 cfe_iocb_dispatch(&xiocb
);
176 return xiocb
.xiocb_status
;
178 #endif /* CFE_API_enumenv || CFE_API_ALL */
180 #if defined(CFE_API_enummem) || defined(CFE_API_ALL)
182 cfe_enummem(int idx
, int flags
, cfe_xuint_t
*start
, cfe_xuint_t
*length
,
187 xiocb
.xiocb_fcode
= CFE_CMD_FW_MEMENUM
;
188 xiocb
.xiocb_status
= 0;
189 xiocb
.xiocb_handle
= 0;
190 xiocb
.xiocb_flags
= flags
;
191 xiocb
.xiocb_psize
= sizeof(xiocb_meminfo_t
);
192 xiocb
.plist
.xiocb_meminfo
.mi_idx
= idx
;
194 cfe_iocb_dispatch(&xiocb
);
196 if (xiocb
.xiocb_status
< 0)
197 return xiocb
.xiocb_status
;
199 *start
= xiocb
.plist
.xiocb_meminfo
.mi_addr
;
200 *length
= xiocb
.plist
.xiocb_meminfo
.mi_size
;
201 *type
= xiocb
.plist
.xiocb_meminfo
.mi_type
;
205 #endif /* CFE_API_enummem || CFE_API_ALL */
207 #if defined(CFE_API_exit) || defined(CFE_API_ALL)
209 cfe_exit(int warm
, int status
)
213 xiocb
.xiocb_fcode
= CFE_CMD_FW_RESTART
;
214 xiocb
.xiocb_status
= 0;
215 xiocb
.xiocb_handle
= 0;
216 xiocb
.xiocb_flags
= warm
? CFE_FLG_WARMSTART
: 0;
217 xiocb
.xiocb_psize
= sizeof(xiocb_exitstat_t
);
218 xiocb
.plist
.xiocb_exitstat
.status
= status
;
220 cfe_iocb_dispatch(&xiocb
);
222 return xiocb
.xiocb_status
;
224 #endif /* CFE_API_exit || CFE_API_ALL */
226 #if defined(CFE_API_flushcache) || defined(CFE_API_ALL)
228 cfe_flushcache(int flg
)
232 xiocb
.xiocb_fcode
= CFE_CMD_FW_FLUSHCACHE
;
233 xiocb
.xiocb_status
= 0;
234 xiocb
.xiocb_handle
= 0;
235 xiocb
.xiocb_flags
= flg
;
236 xiocb
.xiocb_psize
= 0;
238 cfe_iocb_dispatch(&xiocb
);
240 return xiocb
.xiocb_status
;
242 #endif /* CFE_API_flushcache || CFE_API_ALL */
244 #if defined(CFE_API_getdevinfo) || defined(CFE_API_ALL)
246 cfe_getdevinfo(char *name
)
250 xiocb
.xiocb_fcode
= CFE_CMD_DEV_GETINFO
;
251 xiocb
.xiocb_status
= 0;
252 xiocb
.xiocb_handle
= 0;
253 xiocb
.xiocb_flags
= 0;
254 xiocb
.xiocb_psize
= sizeof(xiocb_buffer_t
);
255 xiocb
.plist
.xiocb_buffer
.buf_offset
= 0;
256 xiocb
.plist
.xiocb_buffer
.buf_ptr
= XPTR_FROM_NATIVE(name
);
257 xiocb
.plist
.xiocb_buffer
.buf_length
= cfe_strlen(name
);
259 cfe_iocb_dispatch(&xiocb
);
261 if (xiocb
.xiocb_status
< 0)
262 return xiocb
.xiocb_status
;
263 return xiocb
.plist
.xiocb_buffer
.buf_devflags
;
265 #endif /* CFE_API_getdevinfo || CFE_API_ALL */
267 #if defined(CFE_API_getenv) || defined(CFE_API_ALL)
269 cfe_getenv(char *name
, char *dest
, int destlen
)
275 xiocb
.xiocb_fcode
= CFE_CMD_ENV_GET
;
276 xiocb
.xiocb_status
= 0;
277 xiocb
.xiocb_handle
= 0;
278 xiocb
.xiocb_flags
= 0;
279 xiocb
.xiocb_psize
= sizeof(xiocb_envbuf_t
);
280 xiocb
.plist
.xiocb_envbuf
.enum_idx
= 0;
281 xiocb
.plist
.xiocb_envbuf
.name_ptr
= XPTR_FROM_NATIVE(name
);
282 xiocb
.plist
.xiocb_envbuf
.name_length
= cfe_strlen(name
);
283 xiocb
.plist
.xiocb_envbuf
.val_ptr
= XPTR_FROM_NATIVE(dest
);
284 xiocb
.plist
.xiocb_envbuf
.val_length
= destlen
;
286 cfe_iocb_dispatch(&xiocb
);
288 return xiocb
.xiocb_status
;
290 #endif /* CFE_API_getenv || CFE_API_ALL */
292 #if defined(CFE_API_getfwinfo) || defined(CFE_API_ALL)
294 cfe_getfwinfo(cfe_fwinfo_t
*info
)
298 xiocb
.xiocb_fcode
= CFE_CMD_FW_GETINFO
;
299 xiocb
.xiocb_status
= 0;
300 xiocb
.xiocb_handle
= 0;
301 xiocb
.xiocb_flags
= 0;
302 xiocb
.xiocb_psize
= sizeof(xiocb_fwinfo_t
);
304 cfe_iocb_dispatch(&xiocb
);
306 if (xiocb
.xiocb_status
< 0)
307 return xiocb
.xiocb_status
;
309 info
->fwi_version
= xiocb
.plist
.xiocb_fwinfo
.fwi_version
;
310 info
->fwi_totalmem
= xiocb
.plist
.xiocb_fwinfo
.fwi_totalmem
;
311 info
->fwi_flags
= xiocb
.plist
.xiocb_fwinfo
.fwi_flags
;
312 info
->fwi_boardid
= xiocb
.plist
.xiocb_fwinfo
.fwi_boardid
;
313 info
->fwi_bootarea_va
= xiocb
.plist
.xiocb_fwinfo
.fwi_bootarea_va
;
314 info
->fwi_bootarea_pa
= xiocb
.plist
.xiocb_fwinfo
.fwi_bootarea_pa
;
315 info
->fwi_bootarea_size
= xiocb
.plist
.xiocb_fwinfo
.fwi_bootarea_size
;
317 info
->fwi_reserved1
= xiocb
.plist
.xiocb_fwinfo
.fwi_reserved1
;
318 info
->fwi_reserved2
= xiocb
.plist
.xiocb_fwinfo
.fwi_reserved2
;
319 info
->fwi_reserved3
= xiocb
.plist
.xiocb_fwinfo
.fwi_reserved3
;
324 #endif /* CFE_API_getfwinfo || CFE_API_ALL */
326 #if defined(CFE_API_getstdhandle) || defined(CFE_API_ALL)
328 cfe_getstdhandle(int flg
)
332 xiocb
.xiocb_fcode
= CFE_CMD_DEV_GETHANDLE
;
333 xiocb
.xiocb_status
= 0;
334 xiocb
.xiocb_handle
= 0;
335 xiocb
.xiocb_flags
= flg
;
336 xiocb
.xiocb_psize
= 0;
338 cfe_iocb_dispatch(&xiocb
);
340 if (xiocb
.xiocb_status
< 0)
341 return xiocb
.xiocb_status
;
342 return xiocb
.xiocb_handle
;
345 #endif /* CFE_API_getstdhandle || CFE_API_ALL */
347 #if defined(CFE_API_getticks) || defined(CFE_API_ALL)
349 #ifdef CFE_API_IMPL_NAMESPACE
357 xiocb
.xiocb_fcode
= CFE_CMD_FW_GETTIME
;
358 xiocb
.xiocb_status
= 0;
359 xiocb
.xiocb_handle
= 0;
360 xiocb
.xiocb_flags
= 0;
361 xiocb
.xiocb_psize
= sizeof(xiocb_time_t
);
362 xiocb
.plist
.xiocb_time
.ticks
= 0;
364 cfe_iocb_dispatch(&xiocb
);
366 return xiocb
.plist
.xiocb_time
.ticks
;
369 #endif /* CFE_API_getticks || CFE_API_ALL */
371 #if defined(CFE_API_inpstat) || defined(CFE_API_ALL)
373 cfe_inpstat(int handle
)
377 xiocb
.xiocb_fcode
= CFE_CMD_DEV_INPSTAT
;
378 xiocb
.xiocb_status
= 0;
379 xiocb
.xiocb_handle
= handle
;
380 xiocb
.xiocb_flags
= 0;
381 xiocb
.xiocb_psize
= sizeof(xiocb_inpstat_t
);
382 xiocb
.plist
.xiocb_inpstat
.inp_status
= 0;
384 cfe_iocb_dispatch(&xiocb
);
386 if (xiocb
.xiocb_status
< 0)
387 return xiocb
.xiocb_status
;
388 return xiocb
.plist
.xiocb_inpstat
.inp_status
;
391 #endif /* CFE_API_inpstat || CFE_API_ALL */
393 #if defined(CFE_API_ioctl) || defined(CFE_API_ALL)
395 cfe_ioctl(int handle
, unsigned int ioctlnum
, unsigned char *buffer
, int length
,
396 int *retlen
, cfe_xuint_t offset
)
400 xiocb
.xiocb_fcode
= CFE_CMD_DEV_IOCTL
;
401 xiocb
.xiocb_status
= 0;
402 xiocb
.xiocb_handle
= handle
;
403 xiocb
.xiocb_flags
= 0;
404 xiocb
.xiocb_psize
= sizeof(xiocb_buffer_t
);
405 xiocb
.plist
.xiocb_buffer
.buf_offset
= offset
;
406 xiocb
.plist
.xiocb_buffer
.buf_ioctlcmd
= ioctlnum
;
407 xiocb
.plist
.xiocb_buffer
.buf_ptr
= XPTR_FROM_NATIVE(buffer
);
408 xiocb
.plist
.xiocb_buffer
.buf_length
= length
;
410 cfe_iocb_dispatch(&xiocb
);
413 *retlen
= xiocb
.plist
.xiocb_buffer
.buf_retlen
;
414 return xiocb
.xiocb_status
;
416 #endif /* CFE_API_ioctl || CFE_API_ALL */
418 #if defined(CFE_API_open) || defined(CFE_API_ALL)
424 xiocb
.xiocb_fcode
= CFE_CMD_DEV_OPEN
;
425 xiocb
.xiocb_status
= 0;
426 xiocb
.xiocb_handle
= 0;
427 xiocb
.xiocb_flags
= 0;
428 xiocb
.xiocb_psize
= sizeof(xiocb_buffer_t
);
429 xiocb
.plist
.xiocb_buffer
.buf_offset
= 0;
430 xiocb
.plist
.xiocb_buffer
.buf_ptr
= XPTR_FROM_NATIVE(name
);
431 xiocb
.plist
.xiocb_buffer
.buf_length
= cfe_strlen(name
);
433 cfe_iocb_dispatch(&xiocb
);
435 if (xiocb
.xiocb_status
< 0)
436 return xiocb
.xiocb_status
;
437 return xiocb
.xiocb_handle
;
439 #endif /* CFE_API_open || CFE_API_ALL */
441 #if defined(CFE_API_read) || defined(CFE_API_ALL)
443 cfe_read(int handle
, unsigned char *buffer
, int length
)
445 return cfe_readblk(handle
, 0, buffer
, length
);
447 #endif /* CFE_API_read || CFE_API_ALL */
449 #if defined(CFE_API_readblk) || defined(CFE_API_ALL)
451 cfe_readblk(int handle
, cfe_xint_t offset
, unsigned char *buffer
, int length
)
455 xiocb
.xiocb_fcode
= CFE_CMD_DEV_READ
;
456 xiocb
.xiocb_status
= 0;
457 xiocb
.xiocb_handle
= handle
;
458 xiocb
.xiocb_flags
= 0;
459 xiocb
.xiocb_psize
= sizeof(xiocb_buffer_t
);
460 xiocb
.plist
.xiocb_buffer
.buf_offset
= offset
;
461 xiocb
.plist
.xiocb_buffer
.buf_ptr
= XPTR_FROM_NATIVE(buffer
);
462 xiocb
.plist
.xiocb_buffer
.buf_length
= length
;
464 cfe_iocb_dispatch(&xiocb
);
466 if (xiocb
.xiocb_status
< 0)
467 return xiocb
.xiocb_status
;
468 return xiocb
.plist
.xiocb_buffer
.buf_retlen
;
470 #endif /* CFE_API_readblk || CFE_API_ALL */
472 #if defined(CFE_API_setenv) || defined(CFE_API_ALL)
474 cfe_setenv(char *name
, char *val
)
478 xiocb
.xiocb_fcode
= CFE_CMD_ENV_SET
;
479 xiocb
.xiocb_status
= 0;
480 xiocb
.xiocb_handle
= 0;
481 xiocb
.xiocb_flags
= 0;
482 xiocb
.xiocb_psize
= sizeof(xiocb_envbuf_t
);
483 xiocb
.plist
.xiocb_envbuf
.enum_idx
= 0;
484 xiocb
.plist
.xiocb_envbuf
.name_ptr
= XPTR_FROM_NATIVE(name
);
485 xiocb
.plist
.xiocb_envbuf
.name_length
= cfe_strlen(name
);
486 xiocb
.plist
.xiocb_envbuf
.val_ptr
= XPTR_FROM_NATIVE(val
);
487 xiocb
.plist
.xiocb_envbuf
.val_length
= cfe_strlen(val
);
489 cfe_iocb_dispatch(&xiocb
);
491 return xiocb
.xiocb_status
;
493 #endif /* CFE_API_setenv || CFE_API_ALL */
495 #if (defined(CFE_API_strlen) || defined(CFE_API_ALL)) \
496 && !defined(CFE_API_STRLEN_CUSTOM)
498 cfe_strlen(char *name
)
507 #endif /* CFE_API_strlen || CFE_API_ALL */
509 #if defined(CFE_API_write) || defined(CFE_API_ALL)
511 cfe_write(int handle
, unsigned char *buffer
, int length
)
513 return cfe_writeblk(handle
, 0, buffer
, length
);
515 #endif /* CFE_API_write || CFE_API_ALL */
517 #if defined(CFE_API_writeblk) || defined(CFE_API_ALL)
519 cfe_writeblk(int handle
, cfe_xint_t offset
, unsigned char *buffer
, int length
)
523 xiocb
.xiocb_fcode
= CFE_CMD_DEV_WRITE
;
524 xiocb
.xiocb_status
= 0;
525 xiocb
.xiocb_handle
= handle
;
526 xiocb
.xiocb_flags
= 0;
527 xiocb
.xiocb_psize
= sizeof(xiocb_buffer_t
);
528 xiocb
.plist
.xiocb_buffer
.buf_offset
= offset
;
529 xiocb
.plist
.xiocb_buffer
.buf_ptr
= XPTR_FROM_NATIVE(buffer
);
530 xiocb
.plist
.xiocb_buffer
.buf_length
= length
;
532 cfe_iocb_dispatch(&xiocb
);
534 if (xiocb
.xiocb_status
< 0)
535 return xiocb
.xiocb_status
;
536 return xiocb
.plist
.xiocb_buffer
.buf_retlen
;
538 #endif /* CFE_API_writeblk || CFE_API_ALL */