xref: /freebsd/sys/contrib/dev/acpica/include/platform/acenv.h (revision 9a14aa017b21c292740c00ee098195cd46642730)
1 /******************************************************************************
2  *
3  * Name: acenv.h - Host and compiler configuration
4  *
5  *****************************************************************************/
6 
7 /*
8  * Copyright (C) 2000 - 2012, Intel Corp.
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions, and the following disclaimer,
16  *    without modification.
17  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18  *    substantially similar to the "NO WARRANTY" disclaimer below
19  *    ("Disclaimer") and any redistribution must be conditioned upon
20  *    including a substantially similar Disclaimer requirement for further
21  *    binary redistribution.
22  * 3. Neither the names of the above-listed copyright holders nor the names
23  *    of any contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * Alternatively, this software may be distributed under the terms of the
27  * GNU General Public License ("GPL") version 2 as published by the Free
28  * Software Foundation.
29  *
30  * NO WARRANTY
31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41  * POSSIBILITY OF SUCH DAMAGES.
42  */
43 
44 #ifndef __ACENV_H__
45 #define __ACENV_H__
46 
47 /*
48  * Environment configuration. The purpose of this file is to interface ACPICA
49  * to the local environment. This includes compiler-specific, OS-specific,
50  * and machine-specific configuration.
51  */
52 
53 /* Types for ACPI_MUTEX_TYPE */
54 
55 #define ACPI_BINARY_SEMAPHORE       0
56 #define ACPI_OSL_MUTEX              1
57 
58 /* Types for DEBUGGER_THREADING */
59 
60 #define DEBUGGER_SINGLE_THREADED    0
61 #define DEBUGGER_MULTI_THREADED     1
62 
63 
64 /******************************************************************************
65  *
66  * Configuration for ACPI tools and utilities
67  *
68  *****************************************************************************/
69 
70 /* iASL configuration */
71 
72 #ifdef ACPI_ASL_COMPILER
73 #define ACPI_APPLICATION
74 #define ACPI_DISASSEMBLER
75 #define ACPI_DEBUG_OUTPUT
76 #define ACPI_CONSTANT_EVAL_ONLY
77 #define ACPI_LARGE_NAMESPACE_NODE
78 #define ACPI_DATA_TABLE_DISASSEMBLY
79 #define ACPI_SINGLE_THREADED
80 #endif
81 
82 /* AcpiExec configuration. Multithreaded with full AML debugger */
83 
84 #ifdef ACPI_EXEC_APP
85 #define ACPI_APPLICATION
86 #define ACPI_FULL_DEBUG
87 #define ACPI_MUTEX_DEBUG
88 #define ACPI_DBG_TRACK_ALLOCATIONS
89 #endif
90 
91 /* AcpiNames configuration. Single threaded with debugger output enabled. */
92 
93 #ifdef ACPI_NAMES_APP
94 #define ACPI_DEBUGGER
95 #define ACPI_APPLICATION
96 #define ACPI_SINGLE_THREADED
97 #endif
98 
99 /*
100  * AcpiBin/AcpiHelp/AcpiSrc configuration. All single threaded, with
101  * no debug output.
102  */
103 #if (defined ACPI_BIN_APP)   || \
104     (defined ACPI_SRC_APP)   || \
105     (defined ACPI_XTRACT_APP)
106 #define ACPI_APPLICATION
107 #define ACPI_SINGLE_THREADED
108 #endif
109 
110 #ifdef ACPI_HELP_APP
111 #define ACPI_DEBUG_OUTPUT
112 #define ACPI_APPLICATION
113 #define ACPI_SINGLE_THREADED
114 #endif
115 
116 /* Linkable ACPICA library */
117 
118 #ifdef ACPI_LIBRARY
119 #define ACPI_USE_LOCAL_CACHE
120 #endif
121 
122 /* Common for all ACPICA applications */
123 
124 #ifdef ACPI_APPLICATION
125 #define ACPI_USE_SYSTEM_CLIBRARY
126 #define ACPI_USE_LOCAL_CACHE
127 #endif
128 
129 /* Common debug support */
130 
131 #ifdef ACPI_FULL_DEBUG
132 #define ACPI_DEBUGGER
133 #define ACPI_DEBUG_OUTPUT
134 #define ACPI_DISASSEMBLER
135 #endif
136 
137 
138 /*! [Begin] no source code translation */
139 
140 /******************************************************************************
141  *
142  * Host configuration files. The compiler configuration files are included
143  * by the host files.
144  *
145  *****************************************************************************/
146 
147 #if defined(_LINUX) || defined(__linux__)
148 #include "aclinux.h"
149 
150 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
151 #include <contrib/dev/acpica/include/platform/acfreebsd.h>
152 
153 #elif defined(__NetBSD__)
154 #include "acnetbsd.h"
155 
156 #elif defined(__sun)
157 #include "acsolaris.h"
158 
159 #elif defined(MODESTO)
160 #include "acmodesto.h"
161 
162 #elif defined(NETWARE)
163 #include "acnetware.h"
164 
165 #elif defined(_CYGWIN)
166 #include "accygwin.h"
167 
168 #elif defined(WIN32)
169 #include "acwin.h"
170 
171 #elif defined(WIN64)
172 #include "acwin64.h"
173 
174 #elif defined(_WRS_LIB_BUILD)
175 #include "acvxworks.h"
176 
177 #elif defined(__OS2__)
178 #include "acos2.h"
179 
180 #elif defined(_AED_EFI)
181 #include "acefi.h"
182 
183 #else
184 
185 /* Unknown environment */
186 
187 #error Unknown target environment
188 #endif
189 
190 /*! [End] no source code translation !*/
191 
192 
193 /******************************************************************************
194  *
195  * Setup defaults for the required symbols that were not defined in one of
196  * the host/compiler files above.
197  *
198  *****************************************************************************/
199 
200 /* 64-bit data types */
201 
202 #ifndef COMPILER_DEPENDENT_INT64
203 #define COMPILER_DEPENDENT_INT64   long long
204 #endif
205 
206 #ifndef COMPILER_DEPENDENT_UINT64
207 #define COMPILER_DEPENDENT_UINT64  unsigned long long
208 #endif
209 
210 /* Type of mutex supported by host. Default is binary semaphores. */
211 
212 #ifndef ACPI_MUTEX_TYPE
213 #define ACPI_MUTEX_TYPE             ACPI_BINARY_SEMAPHORE
214 #endif
215 
216 /* Global Lock acquire/release */
217 
218 #ifndef ACPI_ACQUIRE_GLOBAL_LOCK
219 #define ACPI_ACQUIRE_GLOBAL_LOCK(GLptr, Acquired) Acquired = 1
220 #endif
221 
222 #ifndef ACPI_RELEASE_GLOBAL_LOCK
223 #define ACPI_RELEASE_GLOBAL_LOCK(GLptr, Pending) Pending = 0
224 #endif
225 
226 /* Flush CPU cache - used when going to sleep. Wbinvd or similar. */
227 
228 #ifndef ACPI_FLUSH_CPU_CACHE
229 #define ACPI_FLUSH_CPU_CACHE()
230 #endif
231 
232 /* "inline" keywords - configurable since inline is not standardized */
233 
234 #ifndef ACPI_INLINE
235 #define ACPI_INLINE
236 #endif
237 
238 /*
239  * Configurable calling conventions:
240  *
241  * ACPI_SYSTEM_XFACE        - Interfaces to host OS (handlers, threads)
242  * ACPI_EXTERNAL_XFACE      - External ACPI interfaces
243  * ACPI_INTERNAL_XFACE      - Internal ACPI interfaces
244  * ACPI_INTERNAL_VAR_XFACE  - Internal variable-parameter list interfaces
245  */
246 #ifndef ACPI_SYSTEM_XFACE
247 #define ACPI_SYSTEM_XFACE
248 #endif
249 
250 #ifndef ACPI_EXTERNAL_XFACE
251 #define ACPI_EXTERNAL_XFACE
252 #endif
253 
254 #ifndef ACPI_INTERNAL_XFACE
255 #define ACPI_INTERNAL_XFACE
256 #endif
257 
258 #ifndef ACPI_INTERNAL_VAR_XFACE
259 #define ACPI_INTERNAL_VAR_XFACE
260 #endif
261 
262 /*
263  * Debugger threading model
264  * Use single threaded if the entire subsystem is contained in an application
265  * Use multiple threaded when the subsystem is running in the kernel.
266  *
267  * By default the model is single threaded if ACPI_APPLICATION is set,
268  * multi-threaded if ACPI_APPLICATION is not set.
269  */
270 #ifndef DEBUGGER_THREADING
271 #ifdef ACPI_APPLICATION
272 #define DEBUGGER_THREADING          DEBUGGER_SINGLE_THREADED
273 
274 #else
275 #define DEBUGGER_THREADING          DEBUGGER_MULTI_THREADED
276 #endif
277 #endif /* !DEBUGGER_THREADING */
278 
279 
280 /******************************************************************************
281  *
282  * C library configuration
283  *
284  *****************************************************************************/
285 
286 /*
287  * ACPI_USE_SYSTEM_CLIBRARY - Define this if linking to an actual C library.
288  *      Otherwise, local versions of string/memory functions will be used.
289  * ACPI_USE_STANDARD_HEADERS - Define this if linking to a C library and
290  *      the standard header files may be used.
291  *
292  * The ACPICA subsystem only uses low level C library functions that do not call
293  * operating system services and may therefore be inlined in the code.
294  *
295  * It may be necessary to tailor these include files to the target
296  * generation environment.
297  */
298 #ifdef ACPI_USE_SYSTEM_CLIBRARY
299 
300 /* Use the standard C library headers. We want to keep these to a minimum */
301 
302 #ifdef ACPI_USE_STANDARD_HEADERS
303 
304 /* Use the standard headers from the standard locations */
305 
306 #include <stdarg.h>
307 #include <stdlib.h>
308 #include <string.h>
309 #include <ctype.h>
310 
311 #endif /* ACPI_USE_STANDARD_HEADERS */
312 
313 /* We will be linking to the standard Clib functions */
314 
315 #define ACPI_STRSTR(s1,s2)      strstr((s1), (s2))
316 #define ACPI_STRCHR(s1,c)       strchr((s1), (c))
317 #define ACPI_STRLEN(s)          (ACPI_SIZE) strlen((s))
318 #define ACPI_STRCPY(d,s)        (void) strcpy((d), (s))
319 #define ACPI_STRNCPY(d,s,n)     (void) strncpy((d), (s), (ACPI_SIZE)(n))
320 #define ACPI_STRNCMP(d,s,n)     strncmp((d), (s), (ACPI_SIZE)(n))
321 #define ACPI_STRCMP(d,s)        strcmp((d), (s))
322 #define ACPI_STRCAT(d,s)        (void) strcat((d), (s))
323 #define ACPI_STRNCAT(d,s,n)     strncat((d), (s), (ACPI_SIZE)(n))
324 #define ACPI_STRTOUL(d,s,n)     strtoul((d), (s), (ACPI_SIZE)(n))
325 #define ACPI_MEMCMP(s1,s2,n)    memcmp((const char *)(s1), (const char *)(s2), (ACPI_SIZE)(n))
326 #define ACPI_MEMCPY(d,s,n)      (void) memcpy((d), (s), (ACPI_SIZE)(n))
327 #define ACPI_MEMSET(d,s,n)      (void) memset((d), (s), (ACPI_SIZE)(n))
328 #define ACPI_TOUPPER(i)         toupper((int) (i))
329 #define ACPI_TOLOWER(i)         tolower((int) (i))
330 #define ACPI_IS_XDIGIT(i)       isxdigit((int) (i))
331 #define ACPI_IS_DIGIT(i)        isdigit((int) (i))
332 #define ACPI_IS_SPACE(i)        isspace((int) (i))
333 #define ACPI_IS_UPPER(i)        isupper((int) (i))
334 #define ACPI_IS_PRINT(i)        isprint((int) (i))
335 #define ACPI_IS_ALPHA(i)        isalpha((int) (i))
336 
337 #else
338 
339 /******************************************************************************
340  *
341  * Not using native C library, use local implementations
342  *
343  *****************************************************************************/
344 
345 /*
346  * Use local definitions of C library macros and functions. These function
347  * implementations may not be as efficient as an inline or assembly code
348  * implementation provided by a native C library, but they are functionally
349  * equivalent.
350  */
351 #ifndef va_arg
352 
353 #ifndef _VALIST
354 #define _VALIST
355 typedef char *va_list;
356 #endif /* _VALIST */
357 
358 /* Storage alignment properties */
359 
360 #define  _AUPBND                (sizeof (ACPI_NATIVE_INT) - 1)
361 #define  _ADNBND                (sizeof (ACPI_NATIVE_INT) - 1)
362 
363 /* Variable argument list macro definitions */
364 
365 #define _Bnd(X, bnd)            (((sizeof (X)) + (bnd)) & (~(bnd)))
366 #define va_arg(ap, T)           (*(T *)(((ap) += (_Bnd (T, _AUPBND))) - (_Bnd (T,_ADNBND))))
367 #define va_end(ap)              (void) 0
368 #define va_start(ap, A)         (void) ((ap) = (((char *) &(A)) + (_Bnd (A,_AUPBND))))
369 
370 #endif /* va_arg */
371 
372 /* Use the local (ACPICA) definitions of the clib functions */
373 
374 #define ACPI_STRSTR(s1,s2)      AcpiUtStrstr ((s1), (s2))
375 #define ACPI_STRCHR(s1,c)       AcpiUtStrchr ((s1), (c))
376 #define ACPI_STRLEN(s)          (ACPI_SIZE) AcpiUtStrlen ((s))
377 #define ACPI_STRCPY(d,s)        (void) AcpiUtStrcpy ((d), (s))
378 #define ACPI_STRNCPY(d,s,n)     (void) AcpiUtStrncpy ((d), (s), (ACPI_SIZE)(n))
379 #define ACPI_STRNCMP(d,s,n)     AcpiUtStrncmp ((d), (s), (ACPI_SIZE)(n))
380 #define ACPI_STRCMP(d,s)        AcpiUtStrcmp ((d), (s))
381 #define ACPI_STRCAT(d,s)        (void) AcpiUtStrcat ((d), (s))
382 #define ACPI_STRNCAT(d,s,n)     AcpiUtStrncat ((d), (s), (ACPI_SIZE)(n))
383 #define ACPI_STRTOUL(d,s,n)     AcpiUtStrtoul ((d), (s), (ACPI_SIZE)(n))
384 #define ACPI_MEMCMP(s1,s2,n)    AcpiUtMemcmp((const char *)(s1), (const char *)(s2), (ACPI_SIZE)(n))
385 #define ACPI_MEMCPY(d,s,n)      (void) AcpiUtMemcpy ((d), (s), (ACPI_SIZE)(n))
386 #define ACPI_MEMSET(d,v,n)      (void) AcpiUtMemset ((d), (v), (ACPI_SIZE)(n))
387 #define ACPI_TOUPPER(c)         AcpiUtToUpper ((int) (c))
388 #define ACPI_TOLOWER(c)         AcpiUtToLower ((int) (c))
389 
390 #endif /* ACPI_USE_SYSTEM_CLIBRARY */
391 
392 #endif /* __ACENV_H__ */
393