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