source: trunk/libs/newlib/src/libgloss/mips/cfe_api.c @ 479

Last change on this file since 479 was 444, checked in by satin@…, 7 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 15.0 KB
Line 
1/* From: CFE Id: cfe_api.c,v 1.16 2002/07/09 23:29:11 cgd Exp $ */
2
3/*
4 * Copyright 2000, 2001, 2002
5 * Broadcom Corporation. All rights reserved.
6 *
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.
12 *
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
15 *    the source file.
16 *
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.
21 *
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.
33 */
34
35/*  *********************************************************************
36    *
37    *  Broadcom Common Firmware Environment (CFE)
38    *
39    *  Device Function stubs                    File: cfe_api.c
40    *
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.
44    *
45    *  Authors:  Mitch Lichtenberg, Chris Demetriou
46    *
47    ********************************************************************* */
48
49#include "cfe_api.h"
50#include "cfe_api_int.h"
51
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))
55
56#ifdef CFE_API_IMPL_NAMESPACE
57#define cfe_iocb_dispatch(a)            __cfe_iocb_dispatch(a)
58#endif
59int cfe_iocb_dispatch(cfe_xiocb_t *xiocb);
60
61#if defined(CFE_API_common) || defined(CFE_API_ALL)
62/*
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.
69 */
70
71static int (*cfe_dispfunc)(intptr_t handle, intptr_t xiocb) = 0;
72static cfe_xuint_t cfe_handle = 0;
73
74int
75cfe_init(cfe_xuint_t handle, cfe_xuint_t ept)
76{
77    cfe_dispfunc = NATIVE_FROM_XPTR(ept);
78    cfe_handle = handle;
79    return 0;
80}
81
82int
83cfe_iocb_dispatch(cfe_xiocb_t *xiocb)
84{
85    if (!cfe_dispfunc) return -1;
86    return (*cfe_dispfunc)((intptr_t)cfe_handle, (intptr_t)xiocb);
87}
88#endif /* CFE_API_common || CFE_API_ALL */
89
90#if defined(CFE_API_close) || defined(CFE_API_ALL)
91int
92cfe_close(int handle)
93{
94    cfe_xiocb_t xiocb;
95
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;
101
102    cfe_iocb_dispatch(&xiocb);
103
104    return xiocb.xiocb_status;
105
106}
107#endif /* CFE_API_close || CFE_API_ALL */
108
109#if defined(CFE_API_cpu_start) || defined(CFE_API_ALL)
110int
111cfe_cpu_start(int cpu, void (*fn)(void), long sp, long gp, long a1)
112{
113    cfe_xiocb_t xiocb;
114
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;
126
127    cfe_iocb_dispatch(&xiocb);
128
129    return xiocb.xiocb_status;
130}
131#endif /* CFE_API_cpu_start || CFE_API_ALL */
132
133#if defined(CFE_API_cpu_stop) || defined(CFE_API_ALL)
134int
135cfe_cpu_stop(int cpu)
136{
137    cfe_xiocb_t xiocb;
138
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;
146
147    cfe_iocb_dispatch(&xiocb);
148
149    return xiocb.xiocb_status;
150}
151#endif /* CFE_API_cpu_stop || CFE_API_ALL */
152
153#if defined(CFE_API_enumenv) || defined(CFE_API_ALL)
154int
155cfe_enumenv(int idx, char *name, int namelen, char *val, int vallen)
156{
157    cfe_xiocb_t xiocb;
158
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;
169
170    cfe_iocb_dispatch(&xiocb);
171
172    return xiocb.xiocb_status;
173}
174#endif /* CFE_API_enumenv || CFE_API_ALL */
175
176#if defined(CFE_API_enummem) || defined(CFE_API_ALL)
177int
178cfe_enummem(int idx, int flags, cfe_xuint_t *start, cfe_xuint_t *length,
179            cfe_xuint_t *type)
180{
181    cfe_xiocb_t xiocb;
182
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;
189
190    cfe_iocb_dispatch(&xiocb);
191
192    if (xiocb.xiocb_status < 0)
193        return xiocb.xiocb_status;
194
195    *start = xiocb.plist.xiocb_meminfo.mi_addr;
196    *length = xiocb.plist.xiocb_meminfo.mi_size;
197    *type = xiocb.plist.xiocb_meminfo.mi_type;
198
199    return 0;
200}
201#endif /* CFE_API_enummem || CFE_API_ALL */
202
203#if defined(CFE_API_exit) || defined(CFE_API_ALL)
204int
205cfe_exit(int warm, int status)
206{
207    cfe_xiocb_t xiocb;
208
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;
215
216    cfe_iocb_dispatch(&xiocb);
217
218    return xiocb.xiocb_status;
219}
220#endif /* CFE_API_exit || CFE_API_ALL */
221
222#if defined(CFE_API_flushcache) || defined(CFE_API_ALL)
223int
224cfe_flushcache(int flg)
225{
226    cfe_xiocb_t xiocb;
227
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;
233
234    cfe_iocb_dispatch(&xiocb);
235
236    return xiocb.xiocb_status;
237}
238#endif /* CFE_API_flushcache || CFE_API_ALL */
239
240#if defined(CFE_API_getdevinfo) || defined(CFE_API_ALL)
241int
242cfe_getdevinfo(char *name)
243{
244    cfe_xiocb_t xiocb;
245
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);
254
255    cfe_iocb_dispatch(&xiocb);
256
257    if (xiocb.xiocb_status < 0)
258        return xiocb.xiocb_status;
259    return xiocb.plist.xiocb_buffer.buf_devflags;
260}
261#endif /* CFE_API_getdevinfo || CFE_API_ALL */
262
263#if defined(CFE_API_getenv) || defined(CFE_API_ALL)
264int
265cfe_getenv(char *name, char *dest, int destlen)
266{
267    cfe_xiocb_t xiocb;
268
269    *dest = 0;
270
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;
281
282    cfe_iocb_dispatch(&xiocb);
283
284    return xiocb.xiocb_status;
285}
286#endif /* CFE_API_getenv || CFE_API_ALL */
287
288#if defined(CFE_API_getfwinfo) || defined(CFE_API_ALL)
289int
290cfe_getfwinfo(cfe_fwinfo_t *info)
291{
292    cfe_xiocb_t xiocb;
293
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);
299
300    cfe_iocb_dispatch(&xiocb);
301
302    if (xiocb.xiocb_status < 0)
303        return xiocb.xiocb_status;
304
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;
312#if 0
313    info->fwi_reserved1 = xiocb.plist.xiocb_fwinfo.fwi_reserved1;
314    info->fwi_reserved2 = xiocb.plist.xiocb_fwinfo.fwi_reserved2;
315    info->fwi_reserved3 = xiocb.plist.xiocb_fwinfo.fwi_reserved3;
316#endif
317
318    return 0;
319}
320#endif /* CFE_API_getfwinfo || CFE_API_ALL */
321
322#if defined(CFE_API_getstdhandle) || defined(CFE_API_ALL)
323int
324cfe_getstdhandle(int flg)
325{
326    cfe_xiocb_t xiocb;
327
328    xiocb.xiocb_fcode = CFE_CMD_DEV_GETHANDLE;
329    xiocb.xiocb_status = 0;
330    xiocb.xiocb_handle = 0;
331    xiocb.xiocb_flags = flg;
332    xiocb.xiocb_psize = 0;
333
334    cfe_iocb_dispatch(&xiocb);
335
336    if (xiocb.xiocb_status < 0)
337        return xiocb.xiocb_status;
338    return xiocb.xiocb_handle;
339
340}
341#endif /* CFE_API_getstdhandle || CFE_API_ALL */
342
343#if defined(CFE_API_getticks) || defined(CFE_API_ALL)
344int64_t
345#ifdef CFE_API_IMPL_NAMESPACE
346__cfe_getticks(void)
347#else
348cfe_getticks(void)
349#endif
350{
351    cfe_xiocb_t xiocb;
352
353    xiocb.xiocb_fcode = CFE_CMD_FW_GETTIME;
354    xiocb.xiocb_status = 0;
355    xiocb.xiocb_handle = 0;
356    xiocb.xiocb_flags = 0;
357    xiocb.xiocb_psize = sizeof(xiocb_time_t);
358    xiocb.plist.xiocb_time.ticks = 0;
359
360    cfe_iocb_dispatch(&xiocb);
361
362    return xiocb.plist.xiocb_time.ticks;
363
364}
365#endif /* CFE_API_getticks || CFE_API_ALL */
366
367#if defined(CFE_API_inpstat) || defined(CFE_API_ALL)
368int
369cfe_inpstat(int handle)
370{
371    cfe_xiocb_t xiocb;
372
373    xiocb.xiocb_fcode = CFE_CMD_DEV_INPSTAT;
374    xiocb.xiocb_status = 0;
375    xiocb.xiocb_handle = handle;
376    xiocb.xiocb_flags = 0;
377    xiocb.xiocb_psize = sizeof(xiocb_inpstat_t);
378    xiocb.plist.xiocb_inpstat.inp_status = 0;
379
380    cfe_iocb_dispatch(&xiocb);
381
382    if (xiocb.xiocb_status < 0)
383        return xiocb.xiocb_status;
384    return xiocb.plist.xiocb_inpstat.inp_status;
385
386}
387#endif /* CFE_API_inpstat || CFE_API_ALL */
388
389#if defined(CFE_API_ioctl) || defined(CFE_API_ALL)
390int
391cfe_ioctl(int handle, unsigned int ioctlnum, unsigned char *buffer, int length,
392          int *retlen, cfe_xuint_t offset)
393{
394    cfe_xiocb_t xiocb;
395
396    xiocb.xiocb_fcode = CFE_CMD_DEV_IOCTL;
397    xiocb.xiocb_status = 0;
398    xiocb.xiocb_handle = handle;
399    xiocb.xiocb_flags = 0;
400    xiocb.xiocb_psize = sizeof(xiocb_buffer_t);
401    xiocb.plist.xiocb_buffer.buf_offset = offset;
402    xiocb.plist.xiocb_buffer.buf_ioctlcmd = ioctlnum;
403    xiocb.plist.xiocb_buffer.buf_ptr = XPTR_FROM_NATIVE(buffer);
404    xiocb.plist.xiocb_buffer.buf_length = length;
405
406    cfe_iocb_dispatch(&xiocb);
407
408    if (retlen)
409        *retlen = xiocb.plist.xiocb_buffer.buf_retlen;
410    return xiocb.xiocb_status;
411}
412#endif /* CFE_API_ioctl || CFE_API_ALL */
413
414#if defined(CFE_API_open) || defined(CFE_API_ALL)
415int
416cfe_open(char *name)
417{
418    cfe_xiocb_t xiocb;
419
420    xiocb.xiocb_fcode = CFE_CMD_DEV_OPEN;
421    xiocb.xiocb_status = 0;
422    xiocb.xiocb_handle = 0;
423    xiocb.xiocb_flags = 0;
424    xiocb.xiocb_psize = sizeof(xiocb_buffer_t);
425    xiocb.plist.xiocb_buffer.buf_offset = 0;
426    xiocb.plist.xiocb_buffer.buf_ptr = XPTR_FROM_NATIVE(name);
427    xiocb.plist.xiocb_buffer.buf_length = cfe_strlen(name);
428
429    cfe_iocb_dispatch(&xiocb);
430
431    if (xiocb.xiocb_status < 0)
432        return xiocb.xiocb_status;
433    return xiocb.xiocb_handle;
434}
435#endif /* CFE_API_open || CFE_API_ALL */
436
437#if defined(CFE_API_read) || defined(CFE_API_ALL)
438int
439cfe_read(int handle, unsigned char *buffer, int length)
440{
441    return cfe_readblk(handle, 0, buffer, length);
442}
443#endif /* CFE_API_read || CFE_API_ALL */
444
445#if defined(CFE_API_readblk) || defined(CFE_API_ALL)
446int
447cfe_readblk(int handle, cfe_xint_t offset, unsigned char *buffer, int length)
448{
449    cfe_xiocb_t xiocb;
450
451    xiocb.xiocb_fcode = CFE_CMD_DEV_READ;
452    xiocb.xiocb_status = 0;
453    xiocb.xiocb_handle = handle;
454    xiocb.xiocb_flags = 0;
455    xiocb.xiocb_psize = sizeof(xiocb_buffer_t);
456    xiocb.plist.xiocb_buffer.buf_offset = offset;
457    xiocb.plist.xiocb_buffer.buf_ptr = XPTR_FROM_NATIVE(buffer);
458    xiocb.plist.xiocb_buffer.buf_length = length;
459
460    cfe_iocb_dispatch(&xiocb);
461
462    if (xiocb.xiocb_status < 0)
463        return xiocb.xiocb_status;
464    return xiocb.plist.xiocb_buffer.buf_retlen;
465}
466#endif /* CFE_API_readblk || CFE_API_ALL */
467
468#if defined(CFE_API_setenv) || defined(CFE_API_ALL)
469int
470cfe_setenv(char *name, char *val)
471{
472    cfe_xiocb_t xiocb;
473
474    xiocb.xiocb_fcode = CFE_CMD_ENV_SET;
475    xiocb.xiocb_status = 0;
476    xiocb.xiocb_handle = 0;
477    xiocb.xiocb_flags = 0;
478    xiocb.xiocb_psize = sizeof(xiocb_envbuf_t);
479    xiocb.plist.xiocb_envbuf.enum_idx = 0;
480    xiocb.plist.xiocb_envbuf.name_ptr = XPTR_FROM_NATIVE(name);
481    xiocb.plist.xiocb_envbuf.name_length = cfe_strlen(name);
482    xiocb.plist.xiocb_envbuf.val_ptr = XPTR_FROM_NATIVE(val);
483    xiocb.plist.xiocb_envbuf.val_length = cfe_strlen(val);
484
485    cfe_iocb_dispatch(&xiocb);
486
487    return xiocb.xiocb_status;
488}
489#endif /* CFE_API_setenv || CFE_API_ALL */
490
491#if (defined(CFE_API_strlen) || defined(CFE_API_ALL)) \
492    && !defined(CFE_API_STRLEN_CUSTOM)
493int
494cfe_strlen(char *name)
495{
496    int count = 0;
497
498    while (*name++)
499        count++;
500
501    return count;
502}
503#endif /* CFE_API_strlen || CFE_API_ALL */
504
505#if defined(CFE_API_write) || defined(CFE_API_ALL)
506int
507cfe_write(int handle, unsigned char *buffer, int length)
508{
509    return cfe_writeblk(handle, 0, buffer, length);
510}
511#endif /* CFE_API_write || CFE_API_ALL */
512
513#if defined(CFE_API_writeblk) || defined(CFE_API_ALL)
514int
515cfe_writeblk(int handle, cfe_xint_t offset, unsigned char *buffer, int length)
516{
517    cfe_xiocb_t xiocb;
518
519    xiocb.xiocb_fcode = CFE_CMD_DEV_WRITE;
520    xiocb.xiocb_status = 0;
521    xiocb.xiocb_handle = handle;
522    xiocb.xiocb_flags = 0;
523    xiocb.xiocb_psize = sizeof(xiocb_buffer_t);
524    xiocb.plist.xiocb_buffer.buf_offset = offset;
525    xiocb.plist.xiocb_buffer.buf_ptr = XPTR_FROM_NATIVE(buffer);
526    xiocb.plist.xiocb_buffer.buf_length = length;
527
528    cfe_iocb_dispatch(&xiocb);
529
530    if (xiocb.xiocb_status < 0)
531        return xiocb.xiocb_status;
532    return xiocb.plist.xiocb_buffer.buf_retlen;
533}
534#endif /* CFE_API_writeblk || CFE_API_ALL */
Note: See TracBrowser for help on using the repository browser.