1 /* *********************************************************************
2 * Broadcom Common Firmware Environment (CFE)
4 * Device Function stubs File: cfe_devfuncs.c
6 * This module contains device function stubs (small routines to
7 * call the standard "iocb" interface entry point to CFE).
8 * There should be one routine here per iocb function call.
10 * Author: Mitch Lichtenberg (mpl@broadcom.com)
12 *********************************************************************
14 * Copyright 2000,2001,2002,2003
15 * Broadcom Corporation. All rights reserved.
17 * This software is furnished under license and may be used and
18 * copied only in accordance with the following terms and
19 * conditions. Subject to these conditions, you may download,
20 * copy, install, use, modify and distribute modified or unmodified
21 * copies of this software in source and/or binary form. No title
22 * or ownership is transferred hereby.
24 * 1) Any source code used, modified or distributed must reproduce
25 * and retain this copyright notice and list of conditions
26 * as they appear in the source file.
28 * 2) No right is granted to use any trade name, trademark, or
29 * logo of Broadcom Corporation. The "Broadcom Corporation"
30 * name may not be used to endorse or promote products derived
31 * from this software without the prior written permission of
32 * Broadcom Corporation.
34 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
35 * IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
36 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
37 * PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
38 * SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
39 * PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
40 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
41 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
42 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
43 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
44 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
45 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
46 * THE POSSIBILITY OF SUCH DAMAGE.
47 ********************************************************************* */
50 #include "lib_types.h"
51 #include "lib_string.h"
53 #include "cfe_devfuncs.h"
55 extern int cfe_iocb_dispatch(cfe_iocb_t
*iocb
);
57 static int cfe_strlen(char *name
)
69 int cfe_open(char *name
)
73 iocb
.iocb_fcode
= CFE_CMD_DEV_OPEN
;
77 iocb
.iocb_psize
= sizeof(iocb_buffer_t
);
78 iocb
.plist
.iocb_buffer
.buf_offset
= 0;
79 iocb
.plist
.iocb_buffer
.buf_ptr
= (cfe_ptr_t
)name
;
80 iocb
.plist
.iocb_buffer
.buf_length
= cfe_strlen(name
);
82 cfe_iocb_dispatch(&iocb
);
84 return (iocb
.iocb_status
< 0) ? iocb
.iocb_status
: iocb
.iocb_handle
;
87 int cfe_close(int handle
)
91 iocb
.iocb_fcode
= CFE_CMD_DEV_CLOSE
;
93 iocb
.iocb_handle
= handle
;
97 cfe_iocb_dispatch(&iocb
);
99 return (iocb
.iocb_status
);
103 int cfe_readblk(int handle
,cfe_offset_t offset
,unsigned char *buffer
,int length
)
107 iocb
.iocb_fcode
= CFE_CMD_DEV_READ
;
108 iocb
.iocb_status
= 0;
109 iocb
.iocb_handle
= handle
;
111 iocb
.iocb_psize
= sizeof(iocb_buffer_t
);
112 iocb
.plist
.iocb_buffer
.buf_offset
= offset
;
113 iocb
.plist
.iocb_buffer
.buf_ptr
= buffer
;
114 iocb
.plist
.iocb_buffer
.buf_length
= length
;
116 cfe_iocb_dispatch(&iocb
);
118 return (iocb
.iocb_status
< 0) ? iocb
.iocb_status
: iocb
.plist
.iocb_buffer
.buf_retlen
;
121 int cfe_read(int handle
,unsigned char *buffer
,int length
)
123 return cfe_readblk(handle
,0,buffer
,length
);
127 int cfe_writeblk(int handle
,cfe_offset_t offset
,unsigned char *buffer
,int length
)
131 iocb
.iocb_fcode
= CFE_CMD_DEV_WRITE
;
132 iocb
.iocb_status
= 0;
133 iocb
.iocb_handle
= handle
;
135 iocb
.iocb_psize
= sizeof(iocb_buffer_t
);
136 iocb
.plist
.iocb_buffer
.buf_offset
= offset
;
137 iocb
.plist
.iocb_buffer
.buf_ptr
= buffer
;
138 iocb
.plist
.iocb_buffer
.buf_length
= length
;
140 cfe_iocb_dispatch(&iocb
);
142 return (iocb
.iocb_status
< 0) ? iocb
.iocb_status
: iocb
.plist
.iocb_buffer
.buf_retlen
;
145 int cfe_write(int handle
,unsigned char *buffer
,int length
)
147 return cfe_writeblk(handle
,0,buffer
,length
);
151 int cfe_ioctl(int handle
,unsigned int ioctlnum
,
152 unsigned char *buffer
,int length
,int *retlen
,
157 iocb
.iocb_fcode
= CFE_CMD_DEV_IOCTL
;
158 iocb
.iocb_status
= 0;
159 iocb
.iocb_handle
= handle
;
161 iocb
.iocb_psize
= sizeof(iocb_buffer_t
);
162 iocb
.plist
.iocb_buffer
.buf_offset
= offset
;
163 iocb
.plist
.iocb_buffer
.buf_ioctlcmd
= (cfe_offset_t
) ioctlnum
;
164 iocb
.plist
.iocb_buffer
.buf_ptr
= buffer
;
165 iocb
.plist
.iocb_buffer
.buf_length
= length
;
167 cfe_iocb_dispatch(&iocb
);
169 if (retlen
) *retlen
= iocb
.plist
.iocb_buffer
.buf_retlen
;
170 return iocb
.iocb_status
;
173 int cfe_inpstat(int handle
)
177 iocb
.iocb_fcode
= CFE_CMD_DEV_INPSTAT
;
178 iocb
.iocb_status
= 0;
179 iocb
.iocb_handle
= handle
;
181 iocb
.iocb_psize
= sizeof(iocb_inpstat_t
);
182 iocb
.plist
.iocb_inpstat
.inp_status
= 0;
184 cfe_iocb_dispatch(&iocb
);
186 if (iocb
.iocb_status
< 0) return iocb
.iocb_status
;
188 return iocb
.plist
.iocb_inpstat
.inp_status
;
192 long long cfe_getticks(void)
196 iocb
.iocb_fcode
= CFE_CMD_FW_GETTIME
;
197 iocb
.iocb_status
= 0;
198 iocb
.iocb_handle
= 0;
200 iocb
.iocb_psize
= sizeof(iocb_time_t
);
201 iocb
.plist
.iocb_time
.ticks
= 0;
203 cfe_iocb_dispatch(&iocb
);
205 return iocb
.plist
.iocb_time
.ticks
;
209 int cfe_getenv(char *name
,char *dest
,int destlen
)
215 iocb
.iocb_fcode
= CFE_CMD_ENV_GET
;
216 iocb
.iocb_status
= 0;
217 iocb
.iocb_handle
= 0;
219 iocb
.iocb_psize
= sizeof(iocb_envbuf_t
);
220 iocb
.plist
.iocb_envbuf
.enum_idx
= 0;
221 iocb
.plist
.iocb_envbuf
.name_ptr
= (cfe_ptr_t
)name
;
222 iocb
.plist
.iocb_envbuf
.name_length
= strlen(name
)+1;
223 iocb
.plist
.iocb_envbuf
.val_ptr
= (cfe_ptr_t
)dest
;
224 iocb
.plist
.iocb_envbuf
.val_length
= destlen
;
226 cfe_iocb_dispatch(&iocb
);
228 return iocb
.iocb_status
;
231 int cfe_exit(int warm
,int code
)
235 iocb
.iocb_fcode
= CFE_CMD_FW_RESTART
;
236 iocb
.iocb_status
= 0;
237 iocb
.iocb_handle
= 0;
238 iocb
.iocb_flags
= warm
? CFE_FLG_WARMSTART
: 0;
239 iocb
.iocb_psize
= sizeof(iocb_exitstat_t
);
240 iocb
.plist
.iocb_exitstat
.status
= code
;
242 cfe_iocb_dispatch(&iocb
);
244 return (iocb
.iocb_status
);
248 int cfe_flushcache(int flg
)
252 iocb
.iocb_fcode
= CFE_CMD_FW_FLUSHCACHE
;
253 iocb
.iocb_status
= 0;
254 iocb
.iocb_handle
= 0;
255 iocb
.iocb_flags
= flg
;
258 cfe_iocb_dispatch(&iocb
);
260 return iocb
.iocb_status
;
263 int cfe_getdevinfo(char *name
)
267 iocb
.iocb_fcode
= CFE_CMD_DEV_GETINFO
;
268 iocb
.iocb_status
= 0;
269 iocb
.iocb_handle
= 0;
271 iocb
.iocb_psize
= sizeof(iocb_buffer_t
);
272 iocb
.plist
.iocb_buffer
.buf_offset
= 0;
273 iocb
.plist
.iocb_buffer
.buf_ptr
= (cfe_ptr_t
)name
;
274 iocb
.plist
.iocb_buffer
.buf_length
= cfe_strlen(name
);
276 cfe_iocb_dispatch(&iocb
);
278 return (iocb
.iocb_status
< 0) ? iocb
.iocb_status
: (int)iocb
.plist
.iocb_buffer
.buf_devflags
;