13cbea0b1SLandon J. Fuller /* from: Broadcom Id: cfe_api.c,v 1.18 2006/08/24 02:13:56 binh Exp $ */
2ae36cccdSWarner Losh
3ae36cccdSWarner Losh /*-
4*718cf2ccSPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause
5*718cf2ccSPedro F. Giffuni *
6ae36cccdSWarner Losh * Copyright 2000, 2001, 2002
7ae36cccdSWarner Losh * Broadcom Corporation. All rights reserved.
8ae36cccdSWarner Losh *
9ae36cccdSWarner Losh * This software is furnished under license and may be used and copied only
10ae36cccdSWarner Losh * in accordance with the following terms and conditions. Subject to these
11ae36cccdSWarner Losh * conditions, you may download, copy, install, use, modify and distribute
12ae36cccdSWarner Losh * modified or unmodified copies of this software in source and/or binary
13ae36cccdSWarner Losh * form. No title or ownership is transferred hereby.
14ae36cccdSWarner Losh *
15ae36cccdSWarner Losh * 1) Any source code used, modified or distributed must reproduce and
16ae36cccdSWarner Losh * retain this copyright notice and list of conditions as they appear in
17ae36cccdSWarner Losh * the source file.
18ae36cccdSWarner Losh *
19ae36cccdSWarner Losh * 2) No right is granted to use any trade name, trademark, or logo of
20ae36cccdSWarner Losh * Broadcom Corporation. The "Broadcom Corporation" name may not be
21ae36cccdSWarner Losh * used to endorse or promote products derived from this software
22ae36cccdSWarner Losh * without the prior written permission of Broadcom Corporation.
23ae36cccdSWarner Losh *
24ae36cccdSWarner Losh * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR IMPLIED
25ae36cccdSWarner Losh * WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OF
26ae36cccdSWarner Losh * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
27ae36cccdSWarner Losh * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM BE LIABLE
28ae36cccdSWarner Losh * FOR ANY DAMAGES WHATSOEVER, AND IN PARTICULAR, BROADCOM SHALL NOT BE
29ae36cccdSWarner Losh * LIABLE FOR DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30ae36cccdSWarner Losh * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31ae36cccdSWarner Losh * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32ae36cccdSWarner Losh * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
33ae36cccdSWarner Losh * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
34ae36cccdSWarner Losh * OR OTHERWISE), EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35ae36cccdSWarner Losh */
36ae36cccdSWarner Losh
37ae36cccdSWarner Losh /* *********************************************************************
38ae36cccdSWarner Losh *
39ae36cccdSWarner Losh * Broadcom Common Firmware Environment (CFE)
40ae36cccdSWarner Losh *
41ae36cccdSWarner Losh * Device Function stubs File: cfe_api.c
42ae36cccdSWarner Losh *
43ae36cccdSWarner Losh * This module contains device function stubs (small routines to
44ae36cccdSWarner Losh * call the standard "iocb" interface entry point to CFE).
45ae36cccdSWarner Losh * There should be one routine here per iocb function call.
46ae36cccdSWarner Losh *
47ae36cccdSWarner Losh * Authors: Mitch Lichtenberg, Chris Demetriou
48ae36cccdSWarner Losh *
49ae36cccdSWarner Losh ********************************************************************* */
50ae36cccdSWarner Losh
51ae36cccdSWarner Losh #include <sys/cdefs.h>
52ae36cccdSWarner Losh #include <dev/cfe/cfe_api.h>
53ae36cccdSWarner Losh #include <dev/cfe/cfe_api_int.h>
54ae36cccdSWarner Losh
55ae36cccdSWarner Losh /* Cast from a native pointer to a cfe_xptr_t and back. */
56ae36cccdSWarner Losh #define XPTR_FROM_NATIVE(n) ((cfe_xptr_t) (intptr_t) (n))
57ae36cccdSWarner Losh #define NATIVE_FROM_XPTR(x) ((void *) (intptr_t) (x))
58ae36cccdSWarner Losh
59ae36cccdSWarner Losh #ifdef CFE_API_IMPL_NAMESPACE
60ae36cccdSWarner Losh #define cfe_iocb_dispatch(a) __cfe_iocb_dispatch(a)
61ae36cccdSWarner Losh #endif
62ae36cccdSWarner Losh int cfe_iocb_dispatch(cfe_xiocb_t *xiocb);
63ae36cccdSWarner Losh
64ae36cccdSWarner Losh #if defined(CFE_API_common) || defined(CFE_API_ALL)
65ae36cccdSWarner Losh /*
66ae36cccdSWarner Losh * Declare the dispatch function with args of "intptr_t".
67ae36cccdSWarner Losh * This makes sure whatever model we're compiling in
68ae36cccdSWarner Losh * puts the pointers in a single register. For example,
69ae36cccdSWarner Losh * combining -mlong64 and -mips1 or -mips2 would lead to
70ae36cccdSWarner Losh * trouble, since the handle and IOCB pointer will be
71ae36cccdSWarner Losh * passed in two registers each, and CFE expects one.
72ae36cccdSWarner Losh */
73ae36cccdSWarner Losh
74ae36cccdSWarner Losh static int (*cfe_dispfunc)(intptr_t handle, intptr_t xiocb) = 0;
75ae36cccdSWarner Losh static cfe_xuint_t cfe_handle = 0;
76ae36cccdSWarner Losh
77ae36cccdSWarner Losh int
cfe_init(cfe_xuint_t handle,cfe_xuint_t ept)78ae36cccdSWarner Losh cfe_init(cfe_xuint_t handle, cfe_xuint_t ept)
79ae36cccdSWarner Losh {
80ae36cccdSWarner Losh cfe_dispfunc = NATIVE_FROM_XPTR(ept);
81ae36cccdSWarner Losh cfe_handle = handle;
82ae36cccdSWarner Losh return 0;
83ae36cccdSWarner Losh }
84ae36cccdSWarner Losh
85ae36cccdSWarner Losh int
cfe_iocb_dispatch(cfe_xiocb_t * xiocb)86ae36cccdSWarner Losh cfe_iocb_dispatch(cfe_xiocb_t *xiocb)
87ae36cccdSWarner Losh {
88ae36cccdSWarner Losh if (!cfe_dispfunc) return -1;
89ae36cccdSWarner Losh return (*cfe_dispfunc)((intptr_t)cfe_handle, (intptr_t)xiocb);
90ae36cccdSWarner Losh }
91ae36cccdSWarner Losh #endif /* CFE_API_common || CFE_API_ALL */
92ae36cccdSWarner Losh
93ae36cccdSWarner Losh #if defined(CFE_API_close) || defined(CFE_API_ALL)
94ae36cccdSWarner Losh int
cfe_close(int handle)95ae36cccdSWarner Losh cfe_close(int handle)
96ae36cccdSWarner Losh {
97ae36cccdSWarner Losh cfe_xiocb_t xiocb;
98ae36cccdSWarner Losh
99ae36cccdSWarner Losh xiocb.xiocb_fcode = CFE_CMD_DEV_CLOSE;
100ae36cccdSWarner Losh xiocb.xiocb_status = 0;
101ae36cccdSWarner Losh xiocb.xiocb_handle = handle;
102ae36cccdSWarner Losh xiocb.xiocb_flags = 0;
103ae36cccdSWarner Losh xiocb.xiocb_psize = 0;
104ae36cccdSWarner Losh
105ae36cccdSWarner Losh cfe_iocb_dispatch(&xiocb);
106ae36cccdSWarner Losh
107ae36cccdSWarner Losh return xiocb.xiocb_status;
108ae36cccdSWarner Losh
109ae36cccdSWarner Losh }
110ae36cccdSWarner Losh #endif /* CFE_API_close || CFE_API_ALL */
111ae36cccdSWarner Losh
112ae36cccdSWarner Losh #if defined(CFE_API_cpu_start) || defined(CFE_API_ALL)
113ae36cccdSWarner Losh int
cfe_cpu_start(int cpu,void (* fn)(void),long sp,long gp,long a1)114ae36cccdSWarner Losh cfe_cpu_start(int cpu, void (*fn)(void), long sp, long gp, long a1)
115ae36cccdSWarner Losh {
116ae36cccdSWarner Losh cfe_xiocb_t xiocb;
117ae36cccdSWarner Losh
118ae36cccdSWarner Losh xiocb.xiocb_fcode = CFE_CMD_FW_CPUCTL;
119ae36cccdSWarner Losh xiocb.xiocb_status = 0;
120ae36cccdSWarner Losh xiocb.xiocb_handle = 0;
121ae36cccdSWarner Losh xiocb.xiocb_flags = 0;
122ae36cccdSWarner Losh xiocb.xiocb_psize = sizeof(xiocb_cpuctl_t);
123ae36cccdSWarner Losh xiocb.plist.xiocb_cpuctl.cpu_number = cpu;
124ae36cccdSWarner Losh xiocb.plist.xiocb_cpuctl.cpu_command = CFE_CPU_CMD_START;
125ae36cccdSWarner Losh xiocb.plist.xiocb_cpuctl.gp_val = gp;
126ae36cccdSWarner Losh xiocb.plist.xiocb_cpuctl.sp_val = sp;
127ae36cccdSWarner Losh xiocb.plist.xiocb_cpuctl.a1_val = a1;
128ae36cccdSWarner Losh xiocb.plist.xiocb_cpuctl.start_addr = (long)fn;
129ae36cccdSWarner Losh
130ae36cccdSWarner Losh cfe_iocb_dispatch(&xiocb);
131ae36cccdSWarner Losh
132ae36cccdSWarner Losh return xiocb.xiocb_status;
133ae36cccdSWarner Losh }
134ae36cccdSWarner Losh #endif /* CFE_API_cpu_start || CFE_API_ALL */
135ae36cccdSWarner Losh
136ae36cccdSWarner Losh #if defined(CFE_API_cpu_stop) || defined(CFE_API_ALL)
137ae36cccdSWarner Losh int
cfe_cpu_stop(int cpu)138ae36cccdSWarner Losh cfe_cpu_stop(int cpu)
139ae36cccdSWarner Losh {
140ae36cccdSWarner Losh cfe_xiocb_t xiocb;
141ae36cccdSWarner Losh
142ae36cccdSWarner Losh xiocb.xiocb_fcode = CFE_CMD_FW_CPUCTL;
143ae36cccdSWarner Losh xiocb.xiocb_status = 0;
144ae36cccdSWarner Losh xiocb.xiocb_handle = 0;
145ae36cccdSWarner Losh xiocb.xiocb_flags = 0;
146ae36cccdSWarner Losh xiocb.xiocb_psize = sizeof(xiocb_cpuctl_t);
147ae36cccdSWarner Losh xiocb.plist.xiocb_cpuctl.cpu_number = cpu;
148ae36cccdSWarner Losh xiocb.plist.xiocb_cpuctl.cpu_command = CFE_CPU_CMD_STOP;
149ae36cccdSWarner Losh
150ae36cccdSWarner Losh cfe_iocb_dispatch(&xiocb);
151ae36cccdSWarner Losh
152ae36cccdSWarner Losh return xiocb.xiocb_status;
153ae36cccdSWarner Losh }
154ae36cccdSWarner Losh #endif /* CFE_API_cpu_stop || CFE_API_ALL */
155ae36cccdSWarner Losh
156ae36cccdSWarner Losh #if defined(CFE_API_enumenv) || defined(CFE_API_ALL)
157ae36cccdSWarner Losh int
cfe_enumenv(int idx,char * name,int namelen,char * val,int vallen)158ae36cccdSWarner Losh cfe_enumenv(int idx, char *name, int namelen, char *val, int vallen)
159ae36cccdSWarner Losh {
160ae36cccdSWarner Losh cfe_xiocb_t xiocb;
161ae36cccdSWarner Losh
1623274f529SWarner Losh xiocb.xiocb_fcode = CFE_CMD_ENV_ENUM;
163ae36cccdSWarner Losh xiocb.xiocb_status = 0;
164ae36cccdSWarner Losh xiocb.xiocb_handle = 0;
165ae36cccdSWarner Losh xiocb.xiocb_flags = 0;
166ae36cccdSWarner Losh xiocb.xiocb_psize = sizeof(xiocb_envbuf_t);
167ae36cccdSWarner Losh xiocb.plist.xiocb_envbuf.enum_idx = idx;
168ae36cccdSWarner Losh xiocb.plist.xiocb_envbuf.name_ptr = XPTR_FROM_NATIVE(name);
169ae36cccdSWarner Losh xiocb.plist.xiocb_envbuf.name_length = namelen;
170ae36cccdSWarner Losh xiocb.plist.xiocb_envbuf.val_ptr = XPTR_FROM_NATIVE(val);
171ae36cccdSWarner Losh xiocb.plist.xiocb_envbuf.val_length = vallen;
172ae36cccdSWarner Losh
173ae36cccdSWarner Losh cfe_iocb_dispatch(&xiocb);
174ae36cccdSWarner Losh
175ae36cccdSWarner Losh return xiocb.xiocb_status;
176ae36cccdSWarner Losh }
177ae36cccdSWarner Losh #endif /* CFE_API_enumenv || CFE_API_ALL */
178ae36cccdSWarner Losh
1793cbea0b1SLandon J. Fuller #if defined(CFE_API_enumdev) || defined(CFE_API_ALL)
1803cbea0b1SLandon J. Fuller int
cfe_enumdev(int idx,char * name,int namelen)1813cbea0b1SLandon J. Fuller cfe_enumdev(int idx, char *name, int namelen)
1823cbea0b1SLandon J. Fuller {
1833cbea0b1SLandon J. Fuller cfe_xiocb_t xiocb;
1843cbea0b1SLandon J. Fuller
1853cbea0b1SLandon J. Fuller xiocb.xiocb_fcode = CFE_CMD_DEV_ENUM;
1863cbea0b1SLandon J. Fuller xiocb.xiocb_status = 0;
1873cbea0b1SLandon J. Fuller xiocb.xiocb_handle = 0;
1883cbea0b1SLandon J. Fuller xiocb.xiocb_flags = 0;
1893cbea0b1SLandon J. Fuller xiocb.xiocb_psize = sizeof(xiocb_envbuf_t);
1903cbea0b1SLandon J. Fuller xiocb.plist.xiocb_envbuf.enum_idx = idx;
1913cbea0b1SLandon J. Fuller xiocb.plist.xiocb_envbuf.name_ptr = XPTR_FROM_NATIVE(name);
1923cbea0b1SLandon J. Fuller xiocb.plist.xiocb_envbuf.name_length = namelen;
1933cbea0b1SLandon J. Fuller
1943cbea0b1SLandon J. Fuller cfe_iocb_dispatch(&xiocb);
1953cbea0b1SLandon J. Fuller
1963cbea0b1SLandon J. Fuller return xiocb.xiocb_status;
1973cbea0b1SLandon J. Fuller }
1983cbea0b1SLandon J. Fuller #endif /* CFE_API_enumdev || CFE_API_ALL */
1993cbea0b1SLandon J. Fuller
200ae36cccdSWarner Losh #if defined(CFE_API_enummem) || defined(CFE_API_ALL)
201ae36cccdSWarner Losh int
cfe_enummem(int idx,int flags,cfe_xuint_t * start,cfe_xuint_t * length,cfe_xuint_t * type)202ae36cccdSWarner Losh cfe_enummem(int idx, int flags, cfe_xuint_t *start, cfe_xuint_t *length,
203ae36cccdSWarner Losh cfe_xuint_t *type)
204ae36cccdSWarner Losh {
205ae36cccdSWarner Losh cfe_xiocb_t xiocb;
206ae36cccdSWarner Losh
207ae36cccdSWarner Losh xiocb.xiocb_fcode = CFE_CMD_FW_MEMENUM;
208ae36cccdSWarner Losh xiocb.xiocb_status = 0;
209ae36cccdSWarner Losh xiocb.xiocb_handle = 0;
210ae36cccdSWarner Losh xiocb.xiocb_flags = flags;
211ae36cccdSWarner Losh xiocb.xiocb_psize = sizeof(xiocb_meminfo_t);
212ae36cccdSWarner Losh xiocb.plist.xiocb_meminfo.mi_idx = idx;
213ae36cccdSWarner Losh
214ae36cccdSWarner Losh cfe_iocb_dispatch(&xiocb);
215ae36cccdSWarner Losh
216ae36cccdSWarner Losh if (xiocb.xiocb_status < 0)
217ae36cccdSWarner Losh return xiocb.xiocb_status;
218ae36cccdSWarner Losh
219ae36cccdSWarner Losh *start = xiocb.plist.xiocb_meminfo.mi_addr;
220ae36cccdSWarner Losh *length = xiocb.plist.xiocb_meminfo.mi_size;
221ae36cccdSWarner Losh *type = xiocb.plist.xiocb_meminfo.mi_type;
222ae36cccdSWarner Losh
223ae36cccdSWarner Losh return 0;
224ae36cccdSWarner Losh }
225ae36cccdSWarner Losh #endif /* CFE_API_enummem || CFE_API_ALL */
226ae36cccdSWarner Losh
227ae36cccdSWarner Losh #if defined(CFE_API_exit) || defined(CFE_API_ALL)
228ae36cccdSWarner Losh int
cfe_exit(int warm,int status)229ae36cccdSWarner Losh cfe_exit(int warm, int status)
230ae36cccdSWarner Losh {
231ae36cccdSWarner Losh cfe_xiocb_t xiocb;
232ae36cccdSWarner Losh
233ae36cccdSWarner Losh xiocb.xiocb_fcode = CFE_CMD_FW_RESTART;
234ae36cccdSWarner Losh xiocb.xiocb_status = 0;
235ae36cccdSWarner Losh xiocb.xiocb_handle = 0;
236ae36cccdSWarner Losh xiocb.xiocb_flags = warm ? CFE_FLG_WARMSTART : 0;
237ae36cccdSWarner Losh xiocb.xiocb_psize = sizeof(xiocb_exitstat_t);
238ae36cccdSWarner Losh xiocb.plist.xiocb_exitstat.status = status;
239ae36cccdSWarner Losh
240ae36cccdSWarner Losh cfe_iocb_dispatch(&xiocb);
241ae36cccdSWarner Losh
242ae36cccdSWarner Losh return xiocb.xiocb_status;
243ae36cccdSWarner Losh }
244ae36cccdSWarner Losh #endif /* CFE_API_exit || CFE_API_ALL */
245ae36cccdSWarner Losh
246ae36cccdSWarner Losh #if defined(CFE_API_flushcache) || defined(CFE_API_ALL)
247ae36cccdSWarner Losh int
cfe_flushcache(int flg)248ae36cccdSWarner Losh cfe_flushcache(int flg)
249ae36cccdSWarner Losh {
250ae36cccdSWarner Losh cfe_xiocb_t xiocb;
251ae36cccdSWarner Losh
252ae36cccdSWarner Losh xiocb.xiocb_fcode = CFE_CMD_FW_FLUSHCACHE;
253ae36cccdSWarner Losh xiocb.xiocb_status = 0;
254ae36cccdSWarner Losh xiocb.xiocb_handle = 0;
255ae36cccdSWarner Losh xiocb.xiocb_flags = flg;
256ae36cccdSWarner Losh xiocb.xiocb_psize = 0;
257ae36cccdSWarner Losh
258ae36cccdSWarner Losh cfe_iocb_dispatch(&xiocb);
259ae36cccdSWarner Losh
260ae36cccdSWarner Losh return xiocb.xiocb_status;
261ae36cccdSWarner Losh }
262ae36cccdSWarner Losh #endif /* CFE_API_flushcache || CFE_API_ALL */
263ae36cccdSWarner Losh
264ae36cccdSWarner Losh #if defined(CFE_API_getdevinfo) || defined(CFE_API_ALL)
265ae36cccdSWarner Losh int
cfe_getdevinfo(char * name)266ae36cccdSWarner Losh cfe_getdevinfo(char *name)
267ae36cccdSWarner Losh {
268ae36cccdSWarner Losh cfe_xiocb_t xiocb;
269ae36cccdSWarner Losh
270ae36cccdSWarner Losh xiocb.xiocb_fcode = CFE_CMD_DEV_GETINFO;
271ae36cccdSWarner Losh xiocb.xiocb_status = 0;
272ae36cccdSWarner Losh xiocb.xiocb_handle = 0;
273ae36cccdSWarner Losh xiocb.xiocb_flags = 0;
274ae36cccdSWarner Losh xiocb.xiocb_psize = sizeof(xiocb_buffer_t);
275ae36cccdSWarner Losh xiocb.plist.xiocb_buffer.buf_offset = 0;
276ae36cccdSWarner Losh xiocb.plist.xiocb_buffer.buf_ptr = XPTR_FROM_NATIVE(name);
277ae36cccdSWarner Losh xiocb.plist.xiocb_buffer.buf_length = cfe_strlen(name);
278ae36cccdSWarner Losh
279ae36cccdSWarner Losh cfe_iocb_dispatch(&xiocb);
280ae36cccdSWarner Losh
281ae36cccdSWarner Losh if (xiocb.xiocb_status < 0)
282ae36cccdSWarner Losh return xiocb.xiocb_status;
283ae36cccdSWarner Losh return xiocb.plist.xiocb_buffer.buf_devflags;
284ae36cccdSWarner Losh }
285ae36cccdSWarner Losh #endif /* CFE_API_getdevinfo || CFE_API_ALL */
286ae36cccdSWarner Losh
287ae36cccdSWarner Losh #if defined(CFE_API_getenv) || defined(CFE_API_ALL)
288ae36cccdSWarner Losh int
cfe_getenv(char * name,char * dest,int destlen)289ae36cccdSWarner Losh cfe_getenv(char *name, char *dest, int destlen)
290ae36cccdSWarner Losh {
291ae36cccdSWarner Losh cfe_xiocb_t xiocb;
292ae36cccdSWarner Losh
293ae36cccdSWarner Losh *dest = 0;
294ae36cccdSWarner Losh
295ae36cccdSWarner Losh xiocb.xiocb_fcode = CFE_CMD_ENV_GET;
296ae36cccdSWarner Losh xiocb.xiocb_status = 0;
297ae36cccdSWarner Losh xiocb.xiocb_handle = 0;
298ae36cccdSWarner Losh xiocb.xiocb_flags = 0;
299ae36cccdSWarner Losh xiocb.xiocb_psize = sizeof(xiocb_envbuf_t);
300ae36cccdSWarner Losh xiocb.plist.xiocb_envbuf.enum_idx = 0;
301ae36cccdSWarner Losh xiocb.plist.xiocb_envbuf.name_ptr = XPTR_FROM_NATIVE(name);
302ae36cccdSWarner Losh xiocb.plist.xiocb_envbuf.name_length = cfe_strlen(name);
303ae36cccdSWarner Losh xiocb.plist.xiocb_envbuf.val_ptr = XPTR_FROM_NATIVE(dest);
304ae36cccdSWarner Losh xiocb.plist.xiocb_envbuf.val_length = destlen;
305ae36cccdSWarner Losh
306ae36cccdSWarner Losh cfe_iocb_dispatch(&xiocb);
307ae36cccdSWarner Losh
308ae36cccdSWarner Losh return xiocb.xiocb_status;
309ae36cccdSWarner Losh }
310ae36cccdSWarner Losh #endif /* CFE_API_getenv || CFE_API_ALL */
311ae36cccdSWarner Losh
312ae36cccdSWarner Losh #if defined(CFE_API_getfwinfo) || defined(CFE_API_ALL)
313ae36cccdSWarner Losh int
cfe_getfwinfo(cfe_fwinfo_t * info)314ae36cccdSWarner Losh cfe_getfwinfo(cfe_fwinfo_t *info)
315ae36cccdSWarner Losh {
316ae36cccdSWarner Losh cfe_xiocb_t xiocb;
317ae36cccdSWarner Losh
318ae36cccdSWarner Losh xiocb.xiocb_fcode = CFE_CMD_FW_GETINFO;
319ae36cccdSWarner Losh xiocb.xiocb_status = 0;
320ae36cccdSWarner Losh xiocb.xiocb_handle = 0;
321ae36cccdSWarner Losh xiocb.xiocb_flags = 0;
322ae36cccdSWarner Losh xiocb.xiocb_psize = sizeof(xiocb_fwinfo_t);
323ae36cccdSWarner Losh
324ae36cccdSWarner Losh cfe_iocb_dispatch(&xiocb);
325ae36cccdSWarner Losh
326ae36cccdSWarner Losh if (xiocb.xiocb_status < 0)
327ae36cccdSWarner Losh return xiocb.xiocb_status;
328ae36cccdSWarner Losh
329ae36cccdSWarner Losh info->fwi_version = xiocb.plist.xiocb_fwinfo.fwi_version;
330ae36cccdSWarner Losh info->fwi_totalmem = xiocb.plist.xiocb_fwinfo.fwi_totalmem;
331ae36cccdSWarner Losh info->fwi_flags = xiocb.plist.xiocb_fwinfo.fwi_flags;
332ae36cccdSWarner Losh info->fwi_boardid = xiocb.plist.xiocb_fwinfo.fwi_boardid;
333ae36cccdSWarner Losh info->fwi_bootarea_va = xiocb.plist.xiocb_fwinfo.fwi_bootarea_va;
334ae36cccdSWarner Losh info->fwi_bootarea_pa = xiocb.plist.xiocb_fwinfo.fwi_bootarea_pa;
335ae36cccdSWarner Losh info->fwi_bootarea_size = xiocb.plist.xiocb_fwinfo.fwi_bootarea_size;
336ae36cccdSWarner Losh #if 0
337ae36cccdSWarner Losh info->fwi_reserved1 = xiocb.plist.xiocb_fwinfo.fwi_reserved1;
338ae36cccdSWarner Losh info->fwi_reserved2 = xiocb.plist.xiocb_fwinfo.fwi_reserved2;
339ae36cccdSWarner Losh info->fwi_reserved3 = xiocb.plist.xiocb_fwinfo.fwi_reserved3;
340ae36cccdSWarner Losh #endif
341ae36cccdSWarner Losh
342ae36cccdSWarner Losh return 0;
343ae36cccdSWarner Losh }
344ae36cccdSWarner Losh #endif /* CFE_API_getfwinfo || CFE_API_ALL */
345ae36cccdSWarner Losh
346ae36cccdSWarner Losh #if defined(CFE_API_getstdhandle) || defined(CFE_API_ALL)
347ae36cccdSWarner Losh int
cfe_getstdhandle(int flg)348ae36cccdSWarner Losh cfe_getstdhandle(int flg)
349ae36cccdSWarner Losh {
350ae36cccdSWarner Losh cfe_xiocb_t xiocb;
351ae36cccdSWarner Losh
352ae36cccdSWarner Losh xiocb.xiocb_fcode = CFE_CMD_DEV_GETHANDLE;
353ae36cccdSWarner Losh xiocb.xiocb_status = 0;
354ae36cccdSWarner Losh xiocb.xiocb_handle = 0;
355ae36cccdSWarner Losh xiocb.xiocb_flags = flg;
356ae36cccdSWarner Losh xiocb.xiocb_psize = 0;
357ae36cccdSWarner Losh
358ae36cccdSWarner Losh cfe_iocb_dispatch(&xiocb);
359ae36cccdSWarner Losh
360ae36cccdSWarner Losh if (xiocb.xiocb_status < 0)
361ae36cccdSWarner Losh return xiocb.xiocb_status;
362ae36cccdSWarner Losh return xiocb.xiocb_handle;
363ae36cccdSWarner Losh
364ae36cccdSWarner Losh }
365ae36cccdSWarner Losh #endif /* CFE_API_getstdhandle || CFE_API_ALL */
366ae36cccdSWarner Losh
367ae36cccdSWarner Losh #if defined(CFE_API_getticks) || defined(CFE_API_ALL)
368ae36cccdSWarner Losh int64_t
369ae36cccdSWarner Losh #ifdef CFE_API_IMPL_NAMESPACE
__cfe_getticks(void)370ae36cccdSWarner Losh __cfe_getticks(void)
371ae36cccdSWarner Losh #else
372ae36cccdSWarner Losh cfe_getticks(void)
373ae36cccdSWarner Losh #endif
374ae36cccdSWarner Losh {
375ae36cccdSWarner Losh cfe_xiocb_t xiocb;
376ae36cccdSWarner Losh
377ae36cccdSWarner Losh xiocb.xiocb_fcode = CFE_CMD_FW_GETTIME;
378ae36cccdSWarner Losh xiocb.xiocb_status = 0;
379ae36cccdSWarner Losh xiocb.xiocb_handle = 0;
380ae36cccdSWarner Losh xiocb.xiocb_flags = 0;
381ae36cccdSWarner Losh xiocb.xiocb_psize = sizeof(xiocb_time_t);
382ae36cccdSWarner Losh xiocb.plist.xiocb_time.ticks = 0;
383ae36cccdSWarner Losh
384ae36cccdSWarner Losh cfe_iocb_dispatch(&xiocb);
385ae36cccdSWarner Losh
386ae36cccdSWarner Losh return xiocb.plist.xiocb_time.ticks;
387ae36cccdSWarner Losh
388ae36cccdSWarner Losh }
389ae36cccdSWarner Losh #endif /* CFE_API_getticks || CFE_API_ALL */
390ae36cccdSWarner Losh
391ae36cccdSWarner Losh #if defined(CFE_API_inpstat) || defined(CFE_API_ALL)
392ae36cccdSWarner Losh int
cfe_inpstat(int handle)393ae36cccdSWarner Losh cfe_inpstat(int handle)
394ae36cccdSWarner Losh {
395ae36cccdSWarner Losh cfe_xiocb_t xiocb;
396ae36cccdSWarner Losh
397ae36cccdSWarner Losh xiocb.xiocb_fcode = CFE_CMD_DEV_INPSTAT;
398ae36cccdSWarner Losh xiocb.xiocb_status = 0;
399ae36cccdSWarner Losh xiocb.xiocb_handle = handle;
400ae36cccdSWarner Losh xiocb.xiocb_flags = 0;
401ae36cccdSWarner Losh xiocb.xiocb_psize = sizeof(xiocb_inpstat_t);
402ae36cccdSWarner Losh xiocb.plist.xiocb_inpstat.inp_status = 0;
403ae36cccdSWarner Losh
404ae36cccdSWarner Losh cfe_iocb_dispatch(&xiocb);
405ae36cccdSWarner Losh
406ae36cccdSWarner Losh if (xiocb.xiocb_status < 0)
407ae36cccdSWarner Losh return xiocb.xiocb_status;
408ae36cccdSWarner Losh return xiocb.plist.xiocb_inpstat.inp_status;
409ae36cccdSWarner Losh
410ae36cccdSWarner Losh }
411ae36cccdSWarner Losh #endif /* CFE_API_inpstat || CFE_API_ALL */
412ae36cccdSWarner Losh
413ae36cccdSWarner Losh #if defined(CFE_API_ioctl) || defined(CFE_API_ALL)
414ae36cccdSWarner Losh int
cfe_ioctl(int handle,unsigned int ioctlnum,unsigned char * buffer,int length,int * retlen,cfe_xuint_t offset)415ae36cccdSWarner Losh cfe_ioctl(int handle, unsigned int ioctlnum, unsigned char *buffer, int length,
416ae36cccdSWarner Losh int *retlen, cfe_xuint_t offset)
417ae36cccdSWarner Losh {
418ae36cccdSWarner Losh cfe_xiocb_t xiocb;
419ae36cccdSWarner Losh
420ae36cccdSWarner Losh xiocb.xiocb_fcode = CFE_CMD_DEV_IOCTL;
421ae36cccdSWarner Losh xiocb.xiocb_status = 0;
422ae36cccdSWarner Losh xiocb.xiocb_handle = handle;
423ae36cccdSWarner Losh xiocb.xiocb_flags = 0;
424ae36cccdSWarner Losh xiocb.xiocb_psize = sizeof(xiocb_buffer_t);
425ae36cccdSWarner Losh xiocb.plist.xiocb_buffer.buf_offset = offset;
426ae36cccdSWarner Losh xiocb.plist.xiocb_buffer.buf_ioctlcmd = ioctlnum;
427ae36cccdSWarner Losh xiocb.plist.xiocb_buffer.buf_ptr = XPTR_FROM_NATIVE(buffer);
428ae36cccdSWarner Losh xiocb.plist.xiocb_buffer.buf_length = length;
429ae36cccdSWarner Losh
430ae36cccdSWarner Losh cfe_iocb_dispatch(&xiocb);
431ae36cccdSWarner Losh
432ae36cccdSWarner Losh if (retlen)
433ae36cccdSWarner Losh *retlen = xiocb.plist.xiocb_buffer.buf_retlen;
434ae36cccdSWarner Losh return xiocb.xiocb_status;
435ae36cccdSWarner Losh }
436ae36cccdSWarner Losh #endif /* CFE_API_ioctl || CFE_API_ALL */
437ae36cccdSWarner Losh
438ae36cccdSWarner Losh #if defined(CFE_API_open) || defined(CFE_API_ALL)
439ae36cccdSWarner Losh int
cfe_open(char * name)440ae36cccdSWarner Losh cfe_open(char *name)
441ae36cccdSWarner Losh {
442ae36cccdSWarner Losh cfe_xiocb_t xiocb;
443ae36cccdSWarner Losh
444ae36cccdSWarner Losh xiocb.xiocb_fcode = CFE_CMD_DEV_OPEN;
445ae36cccdSWarner Losh xiocb.xiocb_status = 0;
446ae36cccdSWarner Losh xiocb.xiocb_handle = 0;
447ae36cccdSWarner Losh xiocb.xiocb_flags = 0;
448ae36cccdSWarner Losh xiocb.xiocb_psize = sizeof(xiocb_buffer_t);
449ae36cccdSWarner Losh xiocb.plist.xiocb_buffer.buf_offset = 0;
450ae36cccdSWarner Losh xiocb.plist.xiocb_buffer.buf_ptr = XPTR_FROM_NATIVE(name);
451ae36cccdSWarner Losh xiocb.plist.xiocb_buffer.buf_length = cfe_strlen(name);
452ae36cccdSWarner Losh
453ae36cccdSWarner Losh cfe_iocb_dispatch(&xiocb);
454ae36cccdSWarner Losh
455ae36cccdSWarner Losh if (xiocb.xiocb_status < 0)
456ae36cccdSWarner Losh return xiocb.xiocb_status;
457ae36cccdSWarner Losh return xiocb.xiocb_handle;
458ae36cccdSWarner Losh }
459ae36cccdSWarner Losh #endif /* CFE_API_open || CFE_API_ALL */
460ae36cccdSWarner Losh
461ae36cccdSWarner Losh #if defined(CFE_API_read) || defined(CFE_API_ALL)
462ae36cccdSWarner Losh int
cfe_read(int handle,unsigned char * buffer,int length)463ae36cccdSWarner Losh cfe_read(int handle, unsigned char *buffer, int length)
464ae36cccdSWarner Losh {
465ae36cccdSWarner Losh return cfe_readblk(handle, 0, buffer, length);
466ae36cccdSWarner Losh }
467ae36cccdSWarner Losh #endif /* CFE_API_read || CFE_API_ALL */
468ae36cccdSWarner Losh
469ae36cccdSWarner Losh #if defined(CFE_API_readblk) || defined(CFE_API_ALL)
470ae36cccdSWarner Losh int
cfe_readblk(int handle,cfe_xint_t offset,unsigned char * buffer,int length)471ae36cccdSWarner Losh cfe_readblk(int handle, cfe_xint_t offset, unsigned char *buffer, int length)
472ae36cccdSWarner Losh {
473ae36cccdSWarner Losh cfe_xiocb_t xiocb;
474ae36cccdSWarner Losh
475ae36cccdSWarner Losh xiocb.xiocb_fcode = CFE_CMD_DEV_READ;
476ae36cccdSWarner Losh xiocb.xiocb_status = 0;
477ae36cccdSWarner Losh xiocb.xiocb_handle = handle;
478ae36cccdSWarner Losh xiocb.xiocb_flags = 0;
479ae36cccdSWarner Losh xiocb.xiocb_psize = sizeof(xiocb_buffer_t);
480ae36cccdSWarner Losh xiocb.plist.xiocb_buffer.buf_offset = offset;
481ae36cccdSWarner Losh xiocb.plist.xiocb_buffer.buf_ptr = XPTR_FROM_NATIVE(buffer);
482ae36cccdSWarner Losh xiocb.plist.xiocb_buffer.buf_length = length;
483ae36cccdSWarner Losh
484ae36cccdSWarner Losh cfe_iocb_dispatch(&xiocb);
485ae36cccdSWarner Losh
486ae36cccdSWarner Losh if (xiocb.xiocb_status < 0)
487ae36cccdSWarner Losh return xiocb.xiocb_status;
488ae36cccdSWarner Losh return xiocb.plist.xiocb_buffer.buf_retlen;
489ae36cccdSWarner Losh }
490ae36cccdSWarner Losh #endif /* CFE_API_readblk || CFE_API_ALL */
491ae36cccdSWarner Losh
492ae36cccdSWarner Losh #if defined(CFE_API_setenv) || defined(CFE_API_ALL)
493ae36cccdSWarner Losh int
cfe_setenv(char * name,char * val)494ae36cccdSWarner Losh cfe_setenv(char *name, char *val)
495ae36cccdSWarner Losh {
496ae36cccdSWarner Losh cfe_xiocb_t xiocb;
497ae36cccdSWarner Losh
498ae36cccdSWarner Losh xiocb.xiocb_fcode = CFE_CMD_ENV_SET;
499ae36cccdSWarner Losh xiocb.xiocb_status = 0;
500ae36cccdSWarner Losh xiocb.xiocb_handle = 0;
501ae36cccdSWarner Losh xiocb.xiocb_flags = 0;
502ae36cccdSWarner Losh xiocb.xiocb_psize = sizeof(xiocb_envbuf_t);
503ae36cccdSWarner Losh xiocb.plist.xiocb_envbuf.enum_idx = 0;
504ae36cccdSWarner Losh xiocb.plist.xiocb_envbuf.name_ptr = XPTR_FROM_NATIVE(name);
505ae36cccdSWarner Losh xiocb.plist.xiocb_envbuf.name_length = cfe_strlen(name);
506ae36cccdSWarner Losh xiocb.plist.xiocb_envbuf.val_ptr = XPTR_FROM_NATIVE(val);
507ae36cccdSWarner Losh xiocb.plist.xiocb_envbuf.val_length = cfe_strlen(val);
508ae36cccdSWarner Losh
509ae36cccdSWarner Losh cfe_iocb_dispatch(&xiocb);
510ae36cccdSWarner Losh
511ae36cccdSWarner Losh return xiocb.xiocb_status;
512ae36cccdSWarner Losh }
513ae36cccdSWarner Losh #endif /* CFE_API_setenv || CFE_API_ALL */
514ae36cccdSWarner Losh
515ae36cccdSWarner Losh #if (defined(CFE_API_strlen) || defined(CFE_API_ALL)) \
516ae36cccdSWarner Losh && !defined(CFE_API_STRLEN_CUSTOM)
517ae36cccdSWarner Losh int
cfe_strlen(char * name)518ae36cccdSWarner Losh cfe_strlen(char *name)
519ae36cccdSWarner Losh {
520ae36cccdSWarner Losh int count = 0;
521ae36cccdSWarner Losh
522ae36cccdSWarner Losh while (*name++)
523ae36cccdSWarner Losh count++;
524ae36cccdSWarner Losh
525ae36cccdSWarner Losh return count;
526ae36cccdSWarner Losh }
527ae36cccdSWarner Losh #endif /* CFE_API_strlen || CFE_API_ALL */
528ae36cccdSWarner Losh
529ae36cccdSWarner Losh #if defined(CFE_API_write) || defined(CFE_API_ALL)
530ae36cccdSWarner Losh int
cfe_write(int handle,unsigned char * buffer,int length)531ae36cccdSWarner Losh cfe_write(int handle, unsigned char *buffer, int length)
532ae36cccdSWarner Losh {
533ae36cccdSWarner Losh return cfe_writeblk(handle, 0, buffer, length);
534ae36cccdSWarner Losh }
535ae36cccdSWarner Losh #endif /* CFE_API_write || CFE_API_ALL */
536ae36cccdSWarner Losh
537ae36cccdSWarner Losh #if defined(CFE_API_writeblk) || defined(CFE_API_ALL)
538ae36cccdSWarner Losh int
cfe_writeblk(int handle,cfe_xint_t offset,unsigned char * buffer,int length)539ae36cccdSWarner Losh cfe_writeblk(int handle, cfe_xint_t offset, unsigned char *buffer, int length)
540ae36cccdSWarner Losh {
541ae36cccdSWarner Losh cfe_xiocb_t xiocb;
542ae36cccdSWarner Losh
543ae36cccdSWarner Losh xiocb.xiocb_fcode = CFE_CMD_DEV_WRITE;
544ae36cccdSWarner Losh xiocb.xiocb_status = 0;
545ae36cccdSWarner Losh xiocb.xiocb_handle = handle;
546ae36cccdSWarner Losh xiocb.xiocb_flags = 0;
547ae36cccdSWarner Losh xiocb.xiocb_psize = sizeof(xiocb_buffer_t);
548ae36cccdSWarner Losh xiocb.plist.xiocb_buffer.buf_offset = offset;
549ae36cccdSWarner Losh xiocb.plist.xiocb_buffer.buf_ptr = XPTR_FROM_NATIVE(buffer);
550ae36cccdSWarner Losh xiocb.plist.xiocb_buffer.buf_length = length;
551ae36cccdSWarner Losh
552ae36cccdSWarner Losh cfe_iocb_dispatch(&xiocb);
553ae36cccdSWarner Losh
554ae36cccdSWarner Losh if (xiocb.xiocb_status < 0)
555ae36cccdSWarner Losh return xiocb.xiocb_status;
556ae36cccdSWarner Losh return xiocb.plist.xiocb_buffer.buf_retlen;
557ae36cccdSWarner Losh }
558ae36cccdSWarner Losh #endif /* CFE_API_writeblk || CFE_API_ALL */
559