RT-AC66 3.0.0.4.374.130 core
[tomato.git] / release / src-rt-6.x / cfe / cfe / main / cfe_devfuncs.c
blob39514a6deb0a7775d914315286935a93af953f0f
1 /* *********************************************************************
2 * Broadcom Common Firmware Environment (CFE)
3 *
4 * Device Function stubs File: cfe_devfuncs.c
5 *
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.
9 *
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"
52 #include "cfe_iocb.h"
53 #include "cfe_devfuncs.h"
55 extern int cfe_iocb_dispatch(cfe_iocb_t *iocb);
57 static int cfe_strlen(char *name)
59 int count = 0;
61 while (*name) {
62 count++;
63 name++;
66 return count;
69 int cfe_open(char *name)
71 cfe_iocb_t iocb;
73 iocb.iocb_fcode = CFE_CMD_DEV_OPEN;
74 iocb.iocb_status = 0;
75 iocb.iocb_handle = 0;
76 iocb.iocb_flags = 0;
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)
89 cfe_iocb_t iocb;
91 iocb.iocb_fcode = CFE_CMD_DEV_CLOSE;
92 iocb.iocb_status = 0;
93 iocb.iocb_handle = handle;
94 iocb.iocb_flags = 0;
95 iocb.iocb_psize = 0;
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)
105 cfe_iocb_t iocb;
107 iocb.iocb_fcode = CFE_CMD_DEV_READ;
108 iocb.iocb_status = 0;
109 iocb.iocb_handle = handle;
110 iocb.iocb_flags = 0;
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)
129 cfe_iocb_t iocb;
131 iocb.iocb_fcode = CFE_CMD_DEV_WRITE;
132 iocb.iocb_status = 0;
133 iocb.iocb_handle = handle;
134 iocb.iocb_flags = 0;
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,
153 cfe_offset_t offset)
155 cfe_iocb_t iocb;
157 iocb.iocb_fcode = CFE_CMD_DEV_IOCTL;
158 iocb.iocb_status = 0;
159 iocb.iocb_handle = handle;
160 iocb.iocb_flags = 0;
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)
175 cfe_iocb_t iocb;
177 iocb.iocb_fcode = CFE_CMD_DEV_INPSTAT;
178 iocb.iocb_status = 0;
179 iocb.iocb_handle = handle;
180 iocb.iocb_flags = 0;
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)
194 cfe_iocb_t iocb;
196 iocb.iocb_fcode = CFE_CMD_FW_GETTIME;
197 iocb.iocb_status = 0;
198 iocb.iocb_handle = 0;
199 iocb.iocb_flags = 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)
211 cfe_iocb_t iocb;
213 *dest = NULL;
215 iocb.iocb_fcode = CFE_CMD_ENV_GET;
216 iocb.iocb_status = 0;
217 iocb.iocb_handle = 0;
218 iocb.iocb_flags = 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)
233 cfe_iocb_t iocb;
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)
250 cfe_iocb_t iocb;
252 iocb.iocb_fcode = CFE_CMD_FW_FLUSHCACHE;
253 iocb.iocb_status = 0;
254 iocb.iocb_handle = 0;
255 iocb.iocb_flags = flg;
256 iocb.iocb_psize = 0;
258 cfe_iocb_dispatch(&iocb);
260 return iocb.iocb_status;
263 int cfe_getdevinfo(char *name)
265 cfe_iocb_t iocb;
267 iocb.iocb_fcode = CFE_CMD_DEV_GETINFO;
268 iocb.iocb_status = 0;
269 iocb.iocb_handle = 0;
270 iocb.iocb_flags = 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;