1/* $Id: cfe_api.h,v 1.31 2006/08/24 02:13:56 binh Exp $ */
2
3/*
4 * Copyright 2000, 2001, 2002
5 * Broadcom Corporation. All rights reserved.
6 *
7 * This software is furnished under license and may be used and copied only
8 * in accordance with the following terms and conditions.  Subject to these
9 * conditions, you may download, copy, install, use, modify and distribute
10 * modified or unmodified copies of this software in source and/or binary
11 * form. No title or ownership is transferred hereby.
12 *
13 * 1) Any source code used, modified or distributed must reproduce and
14 *    retain this copyright notice and list of conditions as they appear in
15 *    the source file.
16 *
17 * 2) No right is granted to use any trade name, trademark, or logo of
18 *    Broadcom Corporation.  The "Broadcom Corporation" name may not be
19 *    used to endorse or promote products derived from this software
20 *    without the prior written permission of Broadcom Corporation.
21 *
22 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR IMPLIED
23 *    WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OF
24 *    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
25 *    NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM BE LIABLE
26 *    FOR ANY DAMAGES WHATSOEVER, AND IN PARTICULAR, BROADCOM SHALL NOT BE
27 *    LIABLE FOR DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 *    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 *    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
30 *    BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31 *    WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
32 *    OR OTHERWISE), EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35/*  *********************************************************************
36    *
37    *  Broadcom Common Firmware Environment (CFE)
38    *
39    *  Device function prototypes		File: cfe_api.h
40    *
41    *  This file contains declarations for doing callbacks to
42    *  cfe from an application.  It should be the only header
43    *  needed by the application to use this library
44    *
45    *  Authors:  Mitch Lichtenberg, Chris Demetriou
46    *
47    ********************************************************************* */
48
49#ifndef CFE_API_H
50#define CFE_API_H
51
52/*
53 * Apply customizations here for different OSes.  These need to:
54 *	* typedef uint64_t, int64_t, intptr_t, uintptr_t.
55 *	* define cfe_strlen() if use of an existing function is desired.
56 *	* define CFE_API_IMPL_NAMESPACE if API functions are to use
57 *	  names in the implementation namespace.
58 * Also, optionally, if the build environment does not do so automatically,
59 * CFE_API_* can be defined here as desired.
60 */
61/* Begin customization. */
62#include "lib_types.h"
63/* End customization. */
64
65
66/*  *********************************************************************
67    *  Constants
68    ********************************************************************* */
69
70/* Seal indicating CFE's presence, passed to user program. */
71#define CFE_EPTSEAL 0x43464531
72
73#define CFE_MI_RESERVED	0		/* memory is reserved, do not use */
74#define CFE_MI_AVAILABLE 1		/* memory is available */
75
76#define CFE_FLG_WARMSTART     0x00000001
77#define CFE_FLG_FULL_ARENA    0x00000001
78#define CFE_FLG_ENV_PERMANENT 0x00000001
79
80#define CFE_CPU_CMD_START 1
81#define CFE_CPU_CMD_STOP 0
82
83#define CFE_STDHANDLE_CONSOLE	0
84
85#define CFE_DEV_NETWORK 	1
86#define CFE_DEV_DISK		2
87#define CFE_DEV_FLASH		3
88#define CFE_DEV_SERIAL		4
89#define CFE_DEV_CPU		5
90#define CFE_DEV_NVRAM		6
91#define CFE_DEV_CLOCK           7
92#define CFE_DEV_OTHER		8
93#define CFE_DEV_MASK		0x0F
94
95#define CFE_CACHE_FLUSH_D	1
96#define CFE_CACHE_INVAL_I	2
97#define CFE_CACHE_INVAL_D	4
98#define CFE_CACHE_INVAL_L2	8
99
100#define CFE_FWI_64BIT		0x00000001
101#define CFE_FWI_32BIT		0x00000002
102#define CFE_FWI_RELOC		0x00000004
103#define CFE_FWI_UNCACHED	0x00000008
104#define CFE_FWI_MULTICPU	0x00000010
105#define CFE_FWI_FUNCSIM		0x00000020
106#define CFE_FWI_RTLSIM		0x00000040
107
108typedef struct {
109    int64_t fwi_version;		/* major, minor, eco version */
110    int64_t fwi_totalmem;		/* total installed mem */
111    int64_t fwi_flags;		        /* various flags */
112    int64_t fwi_boardid;		/* board ID */
113    int64_t fwi_bootarea_va;		/* VA of boot area */
114    int64_t fwi_bootarea_pa;		/* PA of boot area */
115    int64_t fwi_bootarea_size;	        /* size of boot area */
116} cfe_fwinfo_t;
117
118
119/*
120 * cfe_strlen is handled specially: If already defined, it has been
121 * overridden in this environment with a standard strlen-like function.
122 */
123#ifdef cfe_strlen
124# define CFE_API_STRLEN_CUSTOM
125#else
126# ifdef CFE_API_IMPL_NAMESPACE
127#  define cfe_strlen(a)			__cfe_strlen(a)
128# endif
129int cfe_strlen(char *name);
130#endif
131
132/*
133 * Defines and prototypes for functions which take no arguments.
134 */
135#ifdef CFE_API_IMPL_NAMESPACE
136int64_t __cfe_getticks(void);
137#define cfe_getticks()			__cfe_getticks()
138#else
139int64_t cfe_getticks(void);
140#endif
141
142/*
143 * Defines and prototypes for the rest of the functions.
144 */
145#ifdef CFE_API_IMPL_NAMESPACE
146#define cfe_close(a)			__cfe_close(a)
147#define cfe_cpu_start(a,b,c,d,e)	__cfe_cpu_start(a,b,c,d,e)
148#define cfe_cpu_stop(a)			__cfe_cpu_stop(a)
149#define cfe_enumenv(a,b,d,e,f)		__cfe_enumenv(a,b,d,e,f)
150#define cfe_enumdev(a,b,c)		__cfe_enumdev(a,b,c)
151#define cfe_enummem(a,b,c,d,e)		__cfe_enummem(a,b,c,d,e)
152#define cfe_exit(a,b)			__cfe_exit(a,b)
153#define cfe_flushcache(a)		__cfe_cacheflush(a)
154#define cfe_getdevinfo(a)		__cfe_getdevinfo(a)
155#define cfe_getenv(a,b,c)		__cfe_getenv(a,b,c)
156#define cfe_getfwinfo(a)		__cfe_getfwinfo(a)
157#define cfe_getstdhandle(a)		__cfe_getstdhandle(a)
158#define cfe_init(a,b)			__cfe_init(a,b)
159#define cfe_inpstat(a)			__cfe_inpstat(a)
160#define cfe_ioctl(a,b,c,d,e,f)		__cfe_ioctl(a,b,c,d,e,f)
161#define cfe_open(a)			__cfe_open(a)
162#define cfe_read(a,b,c)			__cfe_read(a,b,c)
163#define cfe_readblk(a,b,c,d)		__cfe_readblk(a,b,c,d)
164#define cfe_setenv(a,b)			__cfe_setenv(a,b)
165#define cfe_write(a,b,c)		__cfe_write(a,b,c)
166#define cfe_writeblk(a,b,c,d)		__cfe_writeblk(a,b,c,d)
167#endif /* CFE_API_IMPL_NAMESPACE */
168
169int cfe_close(int handle);
170int cfe_cpu_start(int cpu, void (*fn)(void), long sp, long gp, long a1);
171int cfe_cpu_stop(int cpu);
172int cfe_enumenv(int idx, char *name, int namelen, char *val, int vallen);
173int cfe_enumdev(int idx, char *name, int namelen);
174int cfe_enummem(int idx, int flags, uint64_t *start, uint64_t *length,
175		uint64_t *type);
176int cfe_exit(int warm,int status);
177int cfe_flushcache(int flg);
178int cfe_getdevinfo(char *name);
179int cfe_getenv(char *name, char *dest, int destlen);
180int cfe_getfwinfo(cfe_fwinfo_t *info);
181int cfe_getstdhandle(int flg);
182int cfe_init(uint64_t handle,uint64_t ept);
183int cfe_inpstat(int handle);
184int cfe_ioctl(int handle, unsigned int ioctlnum, unsigned char *buffer,
185	      int length, int *retlen, uint64_t offset);
186int cfe_open(char *name);
187int cfe_read(int handle, unsigned char *buffer, int length);
188int cfe_readblk(int handle, int64_t offset, unsigned char *buffer, int length);
189int cfe_setenv(char *name, char *val);
190int cfe_write(int handle, unsigned char *buffer, int length);
191int cfe_writeblk(int handle, int64_t offset, unsigned char *buffer,
192		 int length);
193
194#endif /* CFE_API_H */
195