Merge with 2.4.0-test3-pre4.
[linux-2.6/linux-mips.git] / drivers / acpi / include / acenv.h
blobf2738537ff733e1318b80c73cc066fcb21dc81bd
2 /******************************************************************************
4 * Name: acenv.h - Generation environment specific items
6 *****************************************************************************/
8 /*
9 * Copyright (C) 2000 R. Byron Moore
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #ifndef __ACENV_H__
27 #define __ACENV_H__
31 * Environment configuration. The purpose of this file is to interface to the
32 * local generation environment.
34 * 1) ACPI_USE_SYSTEM_CLIBRARY - Define this if linking to an actual C library.
35 * Otherwise, local versions of string/memory functions will be used.
36 * 2) ACPI_USE_STANDARD_HEADERS - Define this if linking to a C library and
37 * the standard header files may be used.
39 * The ACPI subsystem only uses low level C library functions that do not call
40 * operating system services and may therefore be inlined in the code.
42 * It may be necessary to tailor these include files to the target
43 * generation environment.
46 * Functions and constants used from each header:
48 * string.h: memcpy
49 * memset
50 * strcat
51 * strcmp
52 * strcpy
53 * strlen
54 * strncmp
55 * strncat
56 * strncpy
58 * stdlib.h: strtoul
60 * stdarg.h: va_list
61 * va_arg
62 * va_start
63 * va_end
69 * Environment-specific configuration
72 #ifdef _LINUX
74 #include <linux/config.h>
75 #include <linux/string.h>
76 #include <linux/kernel.h>
77 #include <linux/ctype.h>
78 #include <asm/system.h>
80 /* Single threaded */
82 #define ACPI_APPLICATION
84 /* Use native Linux string library */
86 #define ACPI_USE_SYSTEM_CLIBRARY
88 /* Special functions */
90 #define strtoul simple_strtoul
92 #else
94 /* All other environments */
96 #define ACPI_USE_STANDARD_HEADERS
98 #endif
101 /******************************************************************************
103 * C library configuration
105 *****************************************************************************/
107 #ifdef ACPI_USE_SYSTEM_CLIBRARY
109 * Use the standard C library headers.
110 * We want to keep these to a minimum.
114 #ifdef ACPI_USE_STANDARD_HEADERS
116 * Use the standard headers from the standard locations
118 #include <stdarg.h>
119 #include <stdlib.h>
120 #include <string.h>
122 #endif /* ACPI_USE_STANDARD_HEADERS */
125 * We will be linking to the standard Clib functions
128 #define STRSTR(s1,s2) strstr((char *) (s1), (char *) (s2))
129 #define STRUPR(s) strupr((char *) (s))
130 #define STRLEN(s) strlen((char *) (s))
131 #define STRCPY(d,s) strcpy((char *) (d), (char *) (s))
132 #define STRNCPY(d,s,n) strncpy((char *) (d), (char *) (s), (n))
133 #define STRNCMP(d,s,n) strncmp((char *) (d), (char *) (s), (n))
134 #define STRCMP(d,s) strcmp((char *) (d), (char *) (s))
135 #define STRCAT(d,s) strcat((char *) (d), (char *) (s))
136 #define STRNCAT(d,s,n) strncat((char *) (d), (char *) (s), (n))
137 #define STRTOUL(d,s,n) strtoul((char *) (d), (char **) (s), (n))
138 #define MEMCPY(d,s,n) memcpy(d, s, (size_t) n)
139 #define MEMSET(d,s,n) memset(d, s, (size_t) n)
140 #define TOUPPER toupper
141 #define TOLOWER tolower
144 /******************************************************************************
146 * Not using native C library, use local implementations
148 *****************************************************************************/
149 #else
152 * Use local definitions of C library macros and functions
153 * NOTE: The function implementations may not be as efficient
154 * as an inline or assembly code implementation provided by a
155 * native C library.
158 #ifndef va_arg
160 #ifndef _VALIST
161 #define _VALIST
162 typedef char *va_list;
163 #endif /* _VALIST */
166 * Storage alignment properties
169 #define _AUPBND (sizeof(int) - 1)
170 #define _ADNBND (sizeof(int) - 1)
173 * Variable argument list macro definitions
176 #define _bnd(X, bnd) (((sizeof(X)) + (bnd)) & (~(bnd)))
177 #define va_arg(ap, T) (*(T *)(((ap) += ((_bnd(T, _AUPBND))) \
178 - (_bnd(T, _ADNBND)))))
179 #define va_end(ap) (void)0
180 #define va_start(ap, A) (void) ((ap) = (((char *)&(A)) \
181 + (_bnd(A, _AUPBND))))
183 #endif /* va_arg */
186 #define STRSTR(s1,s2) acpi_cm_strstr ((char *) (s1), (char *) (s2))
187 #define STRUPR(s) acpi_cm_strupr ((char *) (s))
188 #define STRLEN(s) acpi_cm_strlen ((char *) (s))
189 #define STRCPY(d,s) acpi_cm_strcpy ((char *) (d), (char *) (s))
190 #define STRNCPY(d,s,n) acpi_cm_strncpy ((char *) (d), (char *) (s), (n))
191 #define STRNCMP(d,s,n) acpi_cm_strncmp ((char *) (d), (char *) (s), (n))
192 #define STRCMP(d,s) acpi_cm_strcmp ((char *) (d), (char *) (s))
193 #define STRCAT(d,s) acpi_cm_strcat ((char *) (d), (char *) (s))
194 #define STRNCAT(d,s,n) acpi_cm_strncat ((char *) (d), (char *) (s), (n))
195 #define STRTOUL(d,s,n) acpi_cm_strtoul ((char *) (d), (char **) (s), (n))
196 #define MEMCPY(d,s,n) acpi_cm_memcpy ((void *) (d), (const void *) (s), (n))
197 #define MEMSET(d,v,n) acpi_cm_memset ((void *) (d), (v), (n))
198 #define TOUPPER acpi_cm_to_upper
199 #define TOLOWER acpi_cm_to_lower
201 #endif /* ACPI_USE_SYSTEM_CLIBRARY */
204 /******************************************************************************
206 * Assembly code macros
208 *****************************************************************************/
211 * Handle platform- and compiler-specific assembly language differences.
213 * Notes:
214 * 1) Interrupt 3 is used to break into a debugger
215 * 2) Interrupts are turned off during ACPI register setup
219 #ifdef __GNUC__
221 #ifdef __ia64__
222 #define _IA64
223 #endif
225 #define ACPI_ASM_MACROS
226 #define causeinterrupt(level)
227 #define BREAKPOINT3
228 #define disable() __cli()
229 #define enable() __sti()
230 #define halt() __asm__ __volatile__ ("sti; hlt":::"memory")
231 #define wbinvd()
234 /*! [Begin] no source code translation
236 * A brief explanation as GNU inline assembly is a bit hairy
237 * %0 is the output parameter in EAX ("=a")
238 * %1 and %2 are the input parameters in ECX ("c") and an immediate value ("i") respectively
239 * All actual register references are preceded with "%%" as in "%%edx"
240 * Immediate values in the assembly are preceded by "$" as in "$0x1"
241 * The final asm parameter is the non-output registers altered by the operation
243 #define ACPI_ACQUIRE_GLOBAL_LOCK(GLptr, Acq) \
244 do { \
245 int dummy; \
246 asm("1: movl (%1),%%eax;" \
247 "movl %%eax,%%edx;" \
248 "andl %2,%%edx;" \
249 "btsl $0x1,%%edx;" \
250 "adcl $0x0,%%edx;" \
251 "lock; cmpxchgl %%edx,(%1);" \
252 "jnz 1b;" \
253 "cmpb $0x3,%%dl;" \
254 "sbbl %%eax,%%eax" \
255 :"=a"(Acq),"=c"(dummy):"c"(GLptr),"i"(~1L):"dx"); \
256 } while(0)
258 #define ACPI_RELEASE_GLOBAL_LOCK(GLptr, Acq) \
259 do { \
260 int dummy; \
261 asm("1: movl (%1),%%eax;" \
262 "movl %%eax,%%edx;" \
263 "andl %2,%%edx;" \
264 "lock; cmpxchgl %%edx,(%1);" \
265 "jnz 1b;" \
266 "andl $0x1,%%eax" \
267 :"=a"(Acq),"=c"(dummy):"c"(GLptr),"i"(~3L):"dx"); \
268 } while(0)
269 /*! [End] no source code translation !*/
271 #endif /* __GNUC__ */
274 #ifndef ACPI_ASM_MACROS
276 /* Unrecognized compiler, use defaults */
278 #define ACPI_ASM_MACROS
279 #define causeinterrupt(level)
280 #define BREAKPOINT3
281 #define disable()
282 #define enable()
283 #define halt()
285 #define ACPI_ACQUIRE_GLOBAL_LOCK(Glptr, acq)
286 #define ACPI_RELEASE_GLOBAL_LOCK(Glptr, acq)
288 #endif /* ACPI_ASM_MACROS */
291 #ifdef ACPI_APPLICATION
293 /* Don't want software interrupts within a ring3 application */
295 #undef causeinterrupt
296 #undef BREAKPOINT3
297 #define causeinterrupt(level)
298 #define BREAKPOINT3
299 #endif
302 #endif /* __ACENV_H__ */