xref: /freebsd/sys/dev/cfe/cfe_api.c (revision 718cf2ccb9956613756ab15d7a0e28f2c8e91cab)
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 __FBSDID("$FreeBSD$");
53ae36cccdSWarner Losh 
54ae36cccdSWarner Losh #include <dev/cfe/cfe_api.h>
55ae36cccdSWarner Losh #include <dev/cfe/cfe_api_int.h>
56ae36cccdSWarner Losh 
57ae36cccdSWarner Losh /* Cast from a native pointer to a cfe_xptr_t and back.  */
58ae36cccdSWarner Losh #define XPTR_FROM_NATIVE(n)	((cfe_xptr_t) (intptr_t) (n))
59ae36cccdSWarner Losh #define NATIVE_FROM_XPTR(x)	((void *) (intptr_t) (x))
60ae36cccdSWarner Losh 
61ae36cccdSWarner Losh #ifdef CFE_API_IMPL_NAMESPACE
62ae36cccdSWarner Losh #define cfe_iocb_dispatch(a)		__cfe_iocb_dispatch(a)
63ae36cccdSWarner Losh #endif
64ae36cccdSWarner Losh int cfe_iocb_dispatch(cfe_xiocb_t *xiocb);
65ae36cccdSWarner Losh 
66ae36cccdSWarner Losh #if defined(CFE_API_common) || defined(CFE_API_ALL)
67ae36cccdSWarner Losh /*
68ae36cccdSWarner Losh  * Declare the dispatch function with args of "intptr_t".
69ae36cccdSWarner Losh  * This makes sure whatever model we're compiling in
70ae36cccdSWarner Losh  * puts the pointers in a single register.  For example,
71ae36cccdSWarner Losh  * combining -mlong64 and -mips1 or -mips2 would lead to
72ae36cccdSWarner Losh  * trouble, since the handle and IOCB pointer will be
73ae36cccdSWarner Losh  * passed in two registers each, and CFE expects one.
74ae36cccdSWarner Losh  */
75ae36cccdSWarner Losh 
76ae36cccdSWarner Losh static int (*cfe_dispfunc)(intptr_t handle, intptr_t xiocb) = 0;
77ae36cccdSWarner Losh static cfe_xuint_t cfe_handle = 0;
78ae36cccdSWarner Losh 
79ae36cccdSWarner Losh int
80ae36cccdSWarner Losh cfe_init(cfe_xuint_t handle, cfe_xuint_t ept)
81ae36cccdSWarner Losh {
82ae36cccdSWarner Losh     cfe_dispfunc = NATIVE_FROM_XPTR(ept);
83ae36cccdSWarner Losh     cfe_handle = handle;
84ae36cccdSWarner Losh     return 0;
85ae36cccdSWarner Losh }
86ae36cccdSWarner Losh 
87ae36cccdSWarner Losh int
88ae36cccdSWarner Losh cfe_iocb_dispatch(cfe_xiocb_t *xiocb)
89ae36cccdSWarner Losh {
90ae36cccdSWarner Losh     if (!cfe_dispfunc) return -1;
91ae36cccdSWarner Losh     return (*cfe_dispfunc)((intptr_t)cfe_handle, (intptr_t)xiocb);
92ae36cccdSWarner Losh }
93ae36cccdSWarner Losh #endif /* CFE_API_common || CFE_API_ALL */
94ae36cccdSWarner Losh 
95ae36cccdSWarner Losh #if defined(CFE_API_close) || defined(CFE_API_ALL)
96ae36cccdSWarner Losh int
97ae36cccdSWarner Losh cfe_close(int handle)
98ae36cccdSWarner Losh {
99ae36cccdSWarner Losh     cfe_xiocb_t xiocb;
100ae36cccdSWarner Losh 
101ae36cccdSWarner Losh     xiocb.xiocb_fcode = CFE_CMD_DEV_CLOSE;
102ae36cccdSWarner Losh     xiocb.xiocb_status = 0;
103ae36cccdSWarner Losh     xiocb.xiocb_handle = handle;
104ae36cccdSWarner Losh     xiocb.xiocb_flags = 0;
105ae36cccdSWarner Losh     xiocb.xiocb_psize = 0;
106ae36cccdSWarner Losh 
107ae36cccdSWarner Losh     cfe_iocb_dispatch(&xiocb);
108ae36cccdSWarner Losh 
109ae36cccdSWarner Losh     return xiocb.xiocb_status;
110ae36cccdSWarner Losh 
111ae36cccdSWarner Losh }
112ae36cccdSWarner Losh #endif /* CFE_API_close || CFE_API_ALL */
113ae36cccdSWarner Losh 
114ae36cccdSWarner Losh #if defined(CFE_API_cpu_start) || defined(CFE_API_ALL)
115ae36cccdSWarner Losh int
116ae36cccdSWarner Losh cfe_cpu_start(int cpu, void (*fn)(void), long sp, long gp, long a1)
117ae36cccdSWarner Losh {
118ae36cccdSWarner Losh     cfe_xiocb_t xiocb;
119ae36cccdSWarner Losh 
120ae36cccdSWarner Losh     xiocb.xiocb_fcode = CFE_CMD_FW_CPUCTL;
121ae36cccdSWarner Losh     xiocb.xiocb_status = 0;
122ae36cccdSWarner Losh     xiocb.xiocb_handle = 0;
123ae36cccdSWarner Losh     xiocb.xiocb_flags  = 0;
124ae36cccdSWarner Losh     xiocb.xiocb_psize = sizeof(xiocb_cpuctl_t);
125ae36cccdSWarner Losh     xiocb.plist.xiocb_cpuctl.cpu_number = cpu;
126ae36cccdSWarner Losh     xiocb.plist.xiocb_cpuctl.cpu_command = CFE_CPU_CMD_START;
127ae36cccdSWarner Losh     xiocb.plist.xiocb_cpuctl.gp_val = gp;
128ae36cccdSWarner Losh     xiocb.plist.xiocb_cpuctl.sp_val = sp;
129ae36cccdSWarner Losh     xiocb.plist.xiocb_cpuctl.a1_val = a1;
130ae36cccdSWarner Losh     xiocb.plist.xiocb_cpuctl.start_addr = (long)fn;
131ae36cccdSWarner Losh 
132ae36cccdSWarner Losh     cfe_iocb_dispatch(&xiocb);
133ae36cccdSWarner Losh 
134ae36cccdSWarner Losh     return xiocb.xiocb_status;
135ae36cccdSWarner Losh }
136ae36cccdSWarner Losh #endif /* CFE_API_cpu_start || CFE_API_ALL */
137ae36cccdSWarner Losh 
138ae36cccdSWarner Losh #if defined(CFE_API_cpu_stop) || defined(CFE_API_ALL)
139ae36cccdSWarner Losh int
140ae36cccdSWarner Losh cfe_cpu_stop(int cpu)
141ae36cccdSWarner Losh {
142ae36cccdSWarner Losh     cfe_xiocb_t xiocb;
143ae36cccdSWarner Losh 
144ae36cccdSWarner Losh     xiocb.xiocb_fcode = CFE_CMD_FW_CPUCTL;
145ae36cccdSWarner Losh     xiocb.xiocb_status = 0;
146ae36cccdSWarner Losh     xiocb.xiocb_handle = 0;
147ae36cccdSWarner Losh     xiocb.xiocb_flags  = 0;
148ae36cccdSWarner Losh     xiocb.xiocb_psize = sizeof(xiocb_cpuctl_t);
149ae36cccdSWarner Losh     xiocb.plist.xiocb_cpuctl.cpu_number = cpu;
150ae36cccdSWarner Losh     xiocb.plist.xiocb_cpuctl.cpu_command = CFE_CPU_CMD_STOP;
151ae36cccdSWarner Losh 
152ae36cccdSWarner Losh     cfe_iocb_dispatch(&xiocb);
153ae36cccdSWarner Losh 
154ae36cccdSWarner Losh     return xiocb.xiocb_status;
155ae36cccdSWarner Losh }
156ae36cccdSWarner Losh #endif /* CFE_API_cpu_stop || CFE_API_ALL */
157ae36cccdSWarner Losh 
158ae36cccdSWarner Losh #if defined(CFE_API_enumenv) || defined(CFE_API_ALL)
159ae36cccdSWarner Losh int
160ae36cccdSWarner Losh cfe_enumenv(int idx, char *name, int namelen, char *val, int vallen)
161ae36cccdSWarner Losh {
162ae36cccdSWarner Losh     cfe_xiocb_t xiocb;
163ae36cccdSWarner Losh 
1643274f529SWarner Losh     xiocb.xiocb_fcode = CFE_CMD_ENV_ENUM;
165ae36cccdSWarner Losh     xiocb.xiocb_status = 0;
166ae36cccdSWarner Losh     xiocb.xiocb_handle = 0;
167ae36cccdSWarner Losh     xiocb.xiocb_flags = 0;
168ae36cccdSWarner Losh     xiocb.xiocb_psize = sizeof(xiocb_envbuf_t);
169ae36cccdSWarner Losh     xiocb.plist.xiocb_envbuf.enum_idx = idx;
170ae36cccdSWarner Losh     xiocb.plist.xiocb_envbuf.name_ptr = XPTR_FROM_NATIVE(name);
171ae36cccdSWarner Losh     xiocb.plist.xiocb_envbuf.name_length = namelen;
172ae36cccdSWarner Losh     xiocb.plist.xiocb_envbuf.val_ptr = XPTR_FROM_NATIVE(val);
173ae36cccdSWarner Losh     xiocb.plist.xiocb_envbuf.val_length = vallen;
174ae36cccdSWarner Losh 
175ae36cccdSWarner Losh     cfe_iocb_dispatch(&xiocb);
176ae36cccdSWarner Losh 
177ae36cccdSWarner Losh     return xiocb.xiocb_status;
178ae36cccdSWarner Losh }
179ae36cccdSWarner Losh #endif /* CFE_API_enumenv || CFE_API_ALL */
180ae36cccdSWarner Losh 
1813cbea0b1SLandon J. Fuller #if defined(CFE_API_enumdev) || defined(CFE_API_ALL)
1823cbea0b1SLandon J. Fuller int
1833cbea0b1SLandon J. Fuller cfe_enumdev(int idx, char *name, int namelen)
1843cbea0b1SLandon J. Fuller {
1853cbea0b1SLandon J. Fuller     cfe_xiocb_t xiocb;
1863cbea0b1SLandon J. Fuller 
1873cbea0b1SLandon J. Fuller     xiocb.xiocb_fcode = CFE_CMD_DEV_ENUM;
1883cbea0b1SLandon J. Fuller     xiocb.xiocb_status = 0;
1893cbea0b1SLandon J. Fuller     xiocb.xiocb_handle = 0;
1903cbea0b1SLandon J. Fuller     xiocb.xiocb_flags = 0;
1913cbea0b1SLandon J. Fuller     xiocb.xiocb_psize = sizeof(xiocb_envbuf_t);
1923cbea0b1SLandon J. Fuller     xiocb.plist.xiocb_envbuf.enum_idx = idx;
1933cbea0b1SLandon J. Fuller     xiocb.plist.xiocb_envbuf.name_ptr = XPTR_FROM_NATIVE(name);
1943cbea0b1SLandon J. Fuller     xiocb.plist.xiocb_envbuf.name_length = namelen;
1953cbea0b1SLandon J. Fuller 
1963cbea0b1SLandon J. Fuller     cfe_iocb_dispatch(&xiocb);
1973cbea0b1SLandon J. Fuller 
1983cbea0b1SLandon J. Fuller     return xiocb.xiocb_status;
1993cbea0b1SLandon J. Fuller }
2003cbea0b1SLandon J. Fuller #endif /* CFE_API_enumdev || CFE_API_ALL */
2013cbea0b1SLandon J. Fuller 
202ae36cccdSWarner Losh #if defined(CFE_API_enummem) || defined(CFE_API_ALL)
203ae36cccdSWarner Losh int
204ae36cccdSWarner Losh cfe_enummem(int idx, int flags, cfe_xuint_t *start, cfe_xuint_t *length,
205ae36cccdSWarner Losh 	    cfe_xuint_t *type)
206ae36cccdSWarner Losh {
207ae36cccdSWarner Losh     cfe_xiocb_t xiocb;
208ae36cccdSWarner Losh 
209ae36cccdSWarner Losh     xiocb.xiocb_fcode = CFE_CMD_FW_MEMENUM;
210ae36cccdSWarner Losh     xiocb.xiocb_status = 0;
211ae36cccdSWarner Losh     xiocb.xiocb_handle = 0;
212ae36cccdSWarner Losh     xiocb.xiocb_flags = flags;
213ae36cccdSWarner Losh     xiocb.xiocb_psize = sizeof(xiocb_meminfo_t);
214ae36cccdSWarner Losh     xiocb.plist.xiocb_meminfo.mi_idx = idx;
215ae36cccdSWarner Losh 
216ae36cccdSWarner Losh     cfe_iocb_dispatch(&xiocb);
217ae36cccdSWarner Losh 
218ae36cccdSWarner Losh     if (xiocb.xiocb_status < 0)
219ae36cccdSWarner Losh 	return xiocb.xiocb_status;
220ae36cccdSWarner Losh 
221ae36cccdSWarner Losh     *start = xiocb.plist.xiocb_meminfo.mi_addr;
222ae36cccdSWarner Losh     *length = xiocb.plist.xiocb_meminfo.mi_size;
223ae36cccdSWarner Losh     *type = xiocb.plist.xiocb_meminfo.mi_type;
224ae36cccdSWarner Losh 
225ae36cccdSWarner Losh     return 0;
226ae36cccdSWarner Losh }
227ae36cccdSWarner Losh #endif /* CFE_API_enummem || CFE_API_ALL */
228ae36cccdSWarner Losh 
229ae36cccdSWarner Losh #if defined(CFE_API_exit) || defined(CFE_API_ALL)
230ae36cccdSWarner Losh int
231ae36cccdSWarner Losh cfe_exit(int warm, int status)
232ae36cccdSWarner Losh {
233ae36cccdSWarner Losh     cfe_xiocb_t xiocb;
234ae36cccdSWarner Losh 
235ae36cccdSWarner Losh     xiocb.xiocb_fcode = CFE_CMD_FW_RESTART;
236ae36cccdSWarner Losh     xiocb.xiocb_status = 0;
237ae36cccdSWarner Losh     xiocb.xiocb_handle = 0;
238ae36cccdSWarner Losh     xiocb.xiocb_flags = warm ? CFE_FLG_WARMSTART : 0;
239ae36cccdSWarner Losh     xiocb.xiocb_psize = sizeof(xiocb_exitstat_t);
240ae36cccdSWarner Losh     xiocb.plist.xiocb_exitstat.status = status;
241ae36cccdSWarner Losh 
242ae36cccdSWarner Losh     cfe_iocb_dispatch(&xiocb);
243ae36cccdSWarner Losh 
244ae36cccdSWarner Losh     return xiocb.xiocb_status;
245ae36cccdSWarner Losh }
246ae36cccdSWarner Losh #endif /* CFE_API_exit || CFE_API_ALL */
247ae36cccdSWarner Losh 
248ae36cccdSWarner Losh #if defined(CFE_API_flushcache) || defined(CFE_API_ALL)
249ae36cccdSWarner Losh int
250ae36cccdSWarner Losh cfe_flushcache(int flg)
251ae36cccdSWarner Losh {
252ae36cccdSWarner Losh     cfe_xiocb_t xiocb;
253ae36cccdSWarner Losh 
254ae36cccdSWarner Losh     xiocb.xiocb_fcode = CFE_CMD_FW_FLUSHCACHE;
255ae36cccdSWarner Losh     xiocb.xiocb_status = 0;
256ae36cccdSWarner Losh     xiocb.xiocb_handle = 0;
257ae36cccdSWarner Losh     xiocb.xiocb_flags = flg;
258ae36cccdSWarner Losh     xiocb.xiocb_psize = 0;
259ae36cccdSWarner Losh 
260ae36cccdSWarner Losh     cfe_iocb_dispatch(&xiocb);
261ae36cccdSWarner Losh 
262ae36cccdSWarner Losh     return xiocb.xiocb_status;
263ae36cccdSWarner Losh }
264ae36cccdSWarner Losh #endif /* CFE_API_flushcache || CFE_API_ALL */
265ae36cccdSWarner Losh 
266ae36cccdSWarner Losh #if defined(CFE_API_getdevinfo) || defined(CFE_API_ALL)
267ae36cccdSWarner Losh int
268ae36cccdSWarner Losh cfe_getdevinfo(char *name)
269ae36cccdSWarner Losh {
270ae36cccdSWarner Losh     cfe_xiocb_t xiocb;
271ae36cccdSWarner Losh 
272ae36cccdSWarner Losh     xiocb.xiocb_fcode = CFE_CMD_DEV_GETINFO;
273ae36cccdSWarner Losh     xiocb.xiocb_status = 0;
274ae36cccdSWarner Losh     xiocb.xiocb_handle = 0;
275ae36cccdSWarner Losh     xiocb.xiocb_flags = 0;
276ae36cccdSWarner Losh     xiocb.xiocb_psize = sizeof(xiocb_buffer_t);
277ae36cccdSWarner Losh     xiocb.plist.xiocb_buffer.buf_offset = 0;
278ae36cccdSWarner Losh     xiocb.plist.xiocb_buffer.buf_ptr = XPTR_FROM_NATIVE(name);
279ae36cccdSWarner Losh     xiocb.plist.xiocb_buffer.buf_length = cfe_strlen(name);
280ae36cccdSWarner Losh 
281ae36cccdSWarner Losh     cfe_iocb_dispatch(&xiocb);
282ae36cccdSWarner Losh 
283ae36cccdSWarner Losh     if (xiocb.xiocb_status < 0)
284ae36cccdSWarner Losh 	return xiocb.xiocb_status;
285ae36cccdSWarner Losh     return xiocb.plist.xiocb_buffer.buf_devflags;
286ae36cccdSWarner Losh }
287ae36cccdSWarner Losh #endif /* CFE_API_getdevinfo || CFE_API_ALL */
288ae36cccdSWarner Losh 
289ae36cccdSWarner Losh #if defined(CFE_API_getenv) || defined(CFE_API_ALL)
290ae36cccdSWarner Losh int
291ae36cccdSWarner Losh cfe_getenv(char *name, char *dest, int destlen)
292ae36cccdSWarner Losh {
293ae36cccdSWarner Losh     cfe_xiocb_t xiocb;
294ae36cccdSWarner Losh 
295ae36cccdSWarner Losh     *dest = 0;
296ae36cccdSWarner Losh 
297ae36cccdSWarner Losh     xiocb.xiocb_fcode = CFE_CMD_ENV_GET;
298ae36cccdSWarner Losh     xiocb.xiocb_status = 0;
299ae36cccdSWarner Losh     xiocb.xiocb_handle = 0;
300ae36cccdSWarner Losh     xiocb.xiocb_flags = 0;
301ae36cccdSWarner Losh     xiocb.xiocb_psize = sizeof(xiocb_envbuf_t);
302ae36cccdSWarner Losh     xiocb.plist.xiocb_envbuf.enum_idx = 0;
303ae36cccdSWarner Losh     xiocb.plist.xiocb_envbuf.name_ptr = XPTR_FROM_NATIVE(name);
304ae36cccdSWarner Losh     xiocb.plist.xiocb_envbuf.name_length = cfe_strlen(name);
305ae36cccdSWarner Losh     xiocb.plist.xiocb_envbuf.val_ptr = XPTR_FROM_NATIVE(dest);
306ae36cccdSWarner Losh     xiocb.plist.xiocb_envbuf.val_length = destlen;
307ae36cccdSWarner Losh 
308ae36cccdSWarner Losh     cfe_iocb_dispatch(&xiocb);
309ae36cccdSWarner Losh 
310ae36cccdSWarner Losh     return xiocb.xiocb_status;
311ae36cccdSWarner Losh }
312ae36cccdSWarner Losh #endif /* CFE_API_getenv || CFE_API_ALL */
313ae36cccdSWarner Losh 
314ae36cccdSWarner Losh #if defined(CFE_API_getfwinfo) || defined(CFE_API_ALL)
315ae36cccdSWarner Losh int
316ae36cccdSWarner Losh cfe_getfwinfo(cfe_fwinfo_t *info)
317ae36cccdSWarner Losh {
318ae36cccdSWarner Losh     cfe_xiocb_t xiocb;
319ae36cccdSWarner Losh 
320ae36cccdSWarner Losh     xiocb.xiocb_fcode = CFE_CMD_FW_GETINFO;
321ae36cccdSWarner Losh     xiocb.xiocb_status = 0;
322ae36cccdSWarner Losh     xiocb.xiocb_handle = 0;
323ae36cccdSWarner Losh     xiocb.xiocb_flags = 0;
324ae36cccdSWarner Losh     xiocb.xiocb_psize = sizeof(xiocb_fwinfo_t);
325ae36cccdSWarner Losh 
326ae36cccdSWarner Losh     cfe_iocb_dispatch(&xiocb);
327ae36cccdSWarner Losh 
328ae36cccdSWarner Losh     if (xiocb.xiocb_status < 0)
329ae36cccdSWarner Losh 	return xiocb.xiocb_status;
330ae36cccdSWarner Losh 
331ae36cccdSWarner Losh     info->fwi_version = xiocb.plist.xiocb_fwinfo.fwi_version;
332ae36cccdSWarner Losh     info->fwi_totalmem = xiocb.plist.xiocb_fwinfo.fwi_totalmem;
333ae36cccdSWarner Losh     info->fwi_flags = xiocb.plist.xiocb_fwinfo.fwi_flags;
334ae36cccdSWarner Losh     info->fwi_boardid = xiocb.plist.xiocb_fwinfo.fwi_boardid;
335ae36cccdSWarner Losh     info->fwi_bootarea_va = xiocb.plist.xiocb_fwinfo.fwi_bootarea_va;
336ae36cccdSWarner Losh     info->fwi_bootarea_pa = xiocb.plist.xiocb_fwinfo.fwi_bootarea_pa;
337ae36cccdSWarner Losh     info->fwi_bootarea_size = xiocb.plist.xiocb_fwinfo.fwi_bootarea_size;
338ae36cccdSWarner Losh #if 0
339ae36cccdSWarner Losh     info->fwi_reserved1 = xiocb.plist.xiocb_fwinfo.fwi_reserved1;
340ae36cccdSWarner Losh     info->fwi_reserved2 = xiocb.plist.xiocb_fwinfo.fwi_reserved2;
341ae36cccdSWarner Losh     info->fwi_reserved3 = xiocb.plist.xiocb_fwinfo.fwi_reserved3;
342ae36cccdSWarner Losh #endif
343ae36cccdSWarner Losh 
344ae36cccdSWarner Losh     return 0;
345ae36cccdSWarner Losh }
346ae36cccdSWarner Losh #endif /* CFE_API_getfwinfo || CFE_API_ALL */
347ae36cccdSWarner Losh 
348ae36cccdSWarner Losh #if defined(CFE_API_getstdhandle) || defined(CFE_API_ALL)
349ae36cccdSWarner Losh int
350ae36cccdSWarner Losh cfe_getstdhandle(int flg)
351ae36cccdSWarner Losh {
352ae36cccdSWarner Losh     cfe_xiocb_t xiocb;
353ae36cccdSWarner Losh 
354ae36cccdSWarner Losh     xiocb.xiocb_fcode = CFE_CMD_DEV_GETHANDLE;
355ae36cccdSWarner Losh     xiocb.xiocb_status = 0;
356ae36cccdSWarner Losh     xiocb.xiocb_handle = 0;
357ae36cccdSWarner Losh     xiocb.xiocb_flags = flg;
358ae36cccdSWarner Losh     xiocb.xiocb_psize = 0;
359ae36cccdSWarner Losh 
360ae36cccdSWarner Losh     cfe_iocb_dispatch(&xiocb);
361ae36cccdSWarner Losh 
362ae36cccdSWarner Losh     if (xiocb.xiocb_status < 0)
363ae36cccdSWarner Losh 	return xiocb.xiocb_status;
364ae36cccdSWarner Losh     return xiocb.xiocb_handle;
365ae36cccdSWarner Losh 
366ae36cccdSWarner Losh }
367ae36cccdSWarner Losh #endif /* CFE_API_getstdhandle || CFE_API_ALL */
368ae36cccdSWarner Losh 
369ae36cccdSWarner Losh #if defined(CFE_API_getticks) || defined(CFE_API_ALL)
370ae36cccdSWarner Losh int64_t
371ae36cccdSWarner Losh #ifdef CFE_API_IMPL_NAMESPACE
372ae36cccdSWarner Losh __cfe_getticks(void)
373ae36cccdSWarner Losh #else
374ae36cccdSWarner Losh cfe_getticks(void)
375ae36cccdSWarner Losh #endif
376ae36cccdSWarner Losh {
377ae36cccdSWarner Losh     cfe_xiocb_t xiocb;
378ae36cccdSWarner Losh 
379ae36cccdSWarner Losh     xiocb.xiocb_fcode = CFE_CMD_FW_GETTIME;
380ae36cccdSWarner Losh     xiocb.xiocb_status = 0;
381ae36cccdSWarner Losh     xiocb.xiocb_handle = 0;
382ae36cccdSWarner Losh     xiocb.xiocb_flags = 0;
383ae36cccdSWarner Losh     xiocb.xiocb_psize = sizeof(xiocb_time_t);
384ae36cccdSWarner Losh     xiocb.plist.xiocb_time.ticks = 0;
385ae36cccdSWarner Losh 
386ae36cccdSWarner Losh     cfe_iocb_dispatch(&xiocb);
387ae36cccdSWarner Losh 
388ae36cccdSWarner Losh     return xiocb.plist.xiocb_time.ticks;
389ae36cccdSWarner Losh 
390ae36cccdSWarner Losh }
391ae36cccdSWarner Losh #endif /* CFE_API_getticks || CFE_API_ALL */
392ae36cccdSWarner Losh 
393ae36cccdSWarner Losh #if defined(CFE_API_inpstat) || defined(CFE_API_ALL)
394ae36cccdSWarner Losh int
395ae36cccdSWarner Losh cfe_inpstat(int handle)
396ae36cccdSWarner Losh {
397ae36cccdSWarner Losh     cfe_xiocb_t xiocb;
398ae36cccdSWarner Losh 
399ae36cccdSWarner Losh     xiocb.xiocb_fcode = CFE_CMD_DEV_INPSTAT;
400ae36cccdSWarner Losh     xiocb.xiocb_status = 0;
401ae36cccdSWarner Losh     xiocb.xiocb_handle = handle;
402ae36cccdSWarner Losh     xiocb.xiocb_flags = 0;
403ae36cccdSWarner Losh     xiocb.xiocb_psize = sizeof(xiocb_inpstat_t);
404ae36cccdSWarner Losh     xiocb.plist.xiocb_inpstat.inp_status = 0;
405ae36cccdSWarner Losh 
406ae36cccdSWarner Losh     cfe_iocb_dispatch(&xiocb);
407ae36cccdSWarner Losh 
408ae36cccdSWarner Losh     if (xiocb.xiocb_status < 0)
409ae36cccdSWarner Losh 	return xiocb.xiocb_status;
410ae36cccdSWarner Losh     return xiocb.plist.xiocb_inpstat.inp_status;
411ae36cccdSWarner Losh 
412ae36cccdSWarner Losh }
413ae36cccdSWarner Losh #endif /* CFE_API_inpstat || CFE_API_ALL */
414ae36cccdSWarner Losh 
415ae36cccdSWarner Losh #if defined(CFE_API_ioctl) || defined(CFE_API_ALL)
416ae36cccdSWarner Losh int
417ae36cccdSWarner Losh cfe_ioctl(int handle, unsigned int ioctlnum, unsigned char *buffer, int length,
418ae36cccdSWarner Losh 	  int *retlen, cfe_xuint_t offset)
419ae36cccdSWarner Losh {
420ae36cccdSWarner Losh     cfe_xiocb_t xiocb;
421ae36cccdSWarner Losh 
422ae36cccdSWarner Losh     xiocb.xiocb_fcode = CFE_CMD_DEV_IOCTL;
423ae36cccdSWarner Losh     xiocb.xiocb_status = 0;
424ae36cccdSWarner Losh     xiocb.xiocb_handle = handle;
425ae36cccdSWarner Losh     xiocb.xiocb_flags = 0;
426ae36cccdSWarner Losh     xiocb.xiocb_psize = sizeof(xiocb_buffer_t);
427ae36cccdSWarner Losh     xiocb.plist.xiocb_buffer.buf_offset = offset;
428ae36cccdSWarner Losh     xiocb.plist.xiocb_buffer.buf_ioctlcmd = ioctlnum;
429ae36cccdSWarner Losh     xiocb.plist.xiocb_buffer.buf_ptr = XPTR_FROM_NATIVE(buffer);
430ae36cccdSWarner Losh     xiocb.plist.xiocb_buffer.buf_length = length;
431ae36cccdSWarner Losh 
432ae36cccdSWarner Losh     cfe_iocb_dispatch(&xiocb);
433ae36cccdSWarner Losh 
434ae36cccdSWarner Losh     if (retlen)
435ae36cccdSWarner Losh 	*retlen = xiocb.plist.xiocb_buffer.buf_retlen;
436ae36cccdSWarner Losh     return xiocb.xiocb_status;
437ae36cccdSWarner Losh }
438ae36cccdSWarner Losh #endif /* CFE_API_ioctl || CFE_API_ALL */
439ae36cccdSWarner Losh 
440ae36cccdSWarner Losh #if defined(CFE_API_open) || defined(CFE_API_ALL)
441ae36cccdSWarner Losh int
442ae36cccdSWarner Losh cfe_open(char *name)
443ae36cccdSWarner Losh {
444ae36cccdSWarner Losh     cfe_xiocb_t xiocb;
445ae36cccdSWarner Losh 
446ae36cccdSWarner Losh     xiocb.xiocb_fcode = CFE_CMD_DEV_OPEN;
447ae36cccdSWarner Losh     xiocb.xiocb_status = 0;
448ae36cccdSWarner Losh     xiocb.xiocb_handle = 0;
449ae36cccdSWarner Losh     xiocb.xiocb_flags = 0;
450ae36cccdSWarner Losh     xiocb.xiocb_psize = sizeof(xiocb_buffer_t);
451ae36cccdSWarner Losh     xiocb.plist.xiocb_buffer.buf_offset = 0;
452ae36cccdSWarner Losh     xiocb.plist.xiocb_buffer.buf_ptr = XPTR_FROM_NATIVE(name);
453ae36cccdSWarner Losh     xiocb.plist.xiocb_buffer.buf_length = cfe_strlen(name);
454ae36cccdSWarner Losh 
455ae36cccdSWarner Losh     cfe_iocb_dispatch(&xiocb);
456ae36cccdSWarner Losh 
457ae36cccdSWarner Losh     if (xiocb.xiocb_status < 0)
458ae36cccdSWarner Losh 	return xiocb.xiocb_status;
459ae36cccdSWarner Losh     return xiocb.xiocb_handle;
460ae36cccdSWarner Losh }
461ae36cccdSWarner Losh #endif /* CFE_API_open || CFE_API_ALL */
462ae36cccdSWarner Losh 
463ae36cccdSWarner Losh #if defined(CFE_API_read) || defined(CFE_API_ALL)
464ae36cccdSWarner Losh int
465ae36cccdSWarner Losh cfe_read(int handle, unsigned char *buffer, int length)
466ae36cccdSWarner Losh {
467ae36cccdSWarner Losh     return cfe_readblk(handle, 0, buffer, length);
468ae36cccdSWarner Losh }
469ae36cccdSWarner Losh #endif /* CFE_API_read || CFE_API_ALL */
470ae36cccdSWarner Losh 
471ae36cccdSWarner Losh #if defined(CFE_API_readblk) || defined(CFE_API_ALL)
472ae36cccdSWarner Losh int
473ae36cccdSWarner Losh cfe_readblk(int handle, cfe_xint_t offset, unsigned char *buffer, int length)
474ae36cccdSWarner Losh {
475ae36cccdSWarner Losh     cfe_xiocb_t xiocb;
476ae36cccdSWarner Losh 
477ae36cccdSWarner Losh     xiocb.xiocb_fcode = CFE_CMD_DEV_READ;
478ae36cccdSWarner Losh     xiocb.xiocb_status = 0;
479ae36cccdSWarner Losh     xiocb.xiocb_handle = handle;
480ae36cccdSWarner Losh     xiocb.xiocb_flags = 0;
481ae36cccdSWarner Losh     xiocb.xiocb_psize = sizeof(xiocb_buffer_t);
482ae36cccdSWarner Losh     xiocb.plist.xiocb_buffer.buf_offset = offset;
483ae36cccdSWarner Losh     xiocb.plist.xiocb_buffer.buf_ptr = XPTR_FROM_NATIVE(buffer);
484ae36cccdSWarner Losh     xiocb.plist.xiocb_buffer.buf_length = length;
485ae36cccdSWarner Losh 
486ae36cccdSWarner Losh     cfe_iocb_dispatch(&xiocb);
487ae36cccdSWarner Losh 
488ae36cccdSWarner Losh     if (xiocb.xiocb_status < 0)
489ae36cccdSWarner Losh 	return xiocb.xiocb_status;
490ae36cccdSWarner Losh     return xiocb.plist.xiocb_buffer.buf_retlen;
491ae36cccdSWarner Losh }
492ae36cccdSWarner Losh #endif /* CFE_API_readblk || CFE_API_ALL */
493ae36cccdSWarner Losh 
494ae36cccdSWarner Losh #if defined(CFE_API_setenv) || defined(CFE_API_ALL)
495ae36cccdSWarner Losh int
496ae36cccdSWarner Losh cfe_setenv(char *name, char *val)
497ae36cccdSWarner Losh {
498ae36cccdSWarner Losh     cfe_xiocb_t xiocb;
499ae36cccdSWarner Losh 
500ae36cccdSWarner Losh     xiocb.xiocb_fcode = CFE_CMD_ENV_SET;
501ae36cccdSWarner Losh     xiocb.xiocb_status = 0;
502ae36cccdSWarner Losh     xiocb.xiocb_handle = 0;
503ae36cccdSWarner Losh     xiocb.xiocb_flags = 0;
504ae36cccdSWarner Losh     xiocb.xiocb_psize = sizeof(xiocb_envbuf_t);
505ae36cccdSWarner Losh     xiocb.plist.xiocb_envbuf.enum_idx = 0;
506ae36cccdSWarner Losh     xiocb.plist.xiocb_envbuf.name_ptr = XPTR_FROM_NATIVE(name);
507ae36cccdSWarner Losh     xiocb.plist.xiocb_envbuf.name_length = cfe_strlen(name);
508ae36cccdSWarner Losh     xiocb.plist.xiocb_envbuf.val_ptr = XPTR_FROM_NATIVE(val);
509ae36cccdSWarner Losh     xiocb.plist.xiocb_envbuf.val_length = cfe_strlen(val);
510ae36cccdSWarner Losh 
511ae36cccdSWarner Losh     cfe_iocb_dispatch(&xiocb);
512ae36cccdSWarner Losh 
513ae36cccdSWarner Losh     return xiocb.xiocb_status;
514ae36cccdSWarner Losh }
515ae36cccdSWarner Losh #endif /* CFE_API_setenv || CFE_API_ALL */
516ae36cccdSWarner Losh 
517ae36cccdSWarner Losh #if (defined(CFE_API_strlen) || defined(CFE_API_ALL)) \
518ae36cccdSWarner Losh     && !defined(CFE_API_STRLEN_CUSTOM)
519ae36cccdSWarner Losh int
520ae36cccdSWarner Losh cfe_strlen(char *name)
521ae36cccdSWarner Losh {
522ae36cccdSWarner Losh     int count = 0;
523ae36cccdSWarner Losh 
524ae36cccdSWarner Losh     while (*name++)
525ae36cccdSWarner Losh 	count++;
526ae36cccdSWarner Losh 
527ae36cccdSWarner Losh     return count;
528ae36cccdSWarner Losh }
529ae36cccdSWarner Losh #endif /* CFE_API_strlen || CFE_API_ALL */
530ae36cccdSWarner Losh 
531ae36cccdSWarner Losh #if defined(CFE_API_write) || defined(CFE_API_ALL)
532ae36cccdSWarner Losh int
533ae36cccdSWarner Losh cfe_write(int handle, unsigned char *buffer, int length)
534ae36cccdSWarner Losh {
535ae36cccdSWarner Losh     return cfe_writeblk(handle, 0, buffer, length);
536ae36cccdSWarner Losh }
537ae36cccdSWarner Losh #endif /* CFE_API_write || CFE_API_ALL */
538ae36cccdSWarner Losh 
539ae36cccdSWarner Losh #if defined(CFE_API_writeblk) || defined(CFE_API_ALL)
540ae36cccdSWarner Losh int
541ae36cccdSWarner Losh cfe_writeblk(int handle, cfe_xint_t offset, unsigned char *buffer, int length)
542ae36cccdSWarner Losh {
543ae36cccdSWarner Losh     cfe_xiocb_t xiocb;
544ae36cccdSWarner Losh 
545ae36cccdSWarner Losh     xiocb.xiocb_fcode = CFE_CMD_DEV_WRITE;
546ae36cccdSWarner Losh     xiocb.xiocb_status = 0;
547ae36cccdSWarner Losh     xiocb.xiocb_handle = handle;
548ae36cccdSWarner Losh     xiocb.xiocb_flags = 0;
549ae36cccdSWarner Losh     xiocb.xiocb_psize = sizeof(xiocb_buffer_t);
550ae36cccdSWarner Losh     xiocb.plist.xiocb_buffer.buf_offset = offset;
551ae36cccdSWarner Losh     xiocb.plist.xiocb_buffer.buf_ptr = XPTR_FROM_NATIVE(buffer);
552ae36cccdSWarner Losh     xiocb.plist.xiocb_buffer.buf_length = length;
553ae36cccdSWarner Losh 
554ae36cccdSWarner Losh     cfe_iocb_dispatch(&xiocb);
555ae36cccdSWarner Losh 
556ae36cccdSWarner Losh     if (xiocb.xiocb_status < 0)
557ae36cccdSWarner Losh 	return xiocb.xiocb_status;
558ae36cccdSWarner Losh     return xiocb.plist.xiocb_buffer.buf_retlen;
559ae36cccdSWarner Losh }
560ae36cccdSWarner Losh #endif /* CFE_API_writeblk || CFE_API_ALL */
561