1 /******************************************************************************
3 * Name: acefi.h - OS specific defines, etc.
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2016, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
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.
53 #if defined(__x86_64__)
54 #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7))
59 #ifdef _MSC_EXTENSIONS
60 #define EFIAPI __cdecl
62 #define EFIAPI __attribute__((ms_abi))
67 typedef uint8_t UINT8
;
68 typedef uint16_t UINT16
;
69 typedef int16_t INT16
;
70 typedef uint32_t UINT32
;
71 typedef int32_t INT32
;
72 typedef uint64_t UINT64
;
73 typedef int64_t INT64
;
74 typedef uint8_t BOOLEAN
;
75 typedef uint16_t CHAR16
;
79 #if defined(__ia64__) || defined(__x86_64__)
81 #define ACPI_MACHINE_WIDTH 64
83 #if defined(__x86_64__)
85 /* for x86_64, EFI_FUNCTION_WRAPPER must be defined */
88 #define USE_EFI_FUNCTION_WRAPPER
91 #ifdef _MSC_EXTENSIONS
92 #pragma warning ( disable : 4731 ) /* Suppress warnings about modification of EBP */
97 typedef uint64_t UINTN
;
100 #define EFIERR(a) (0x8000000000000000 | a)
104 #define ACPI_MACHINE_WIDTH 32
105 #define ACPI_USE_NATIVE_DIVIDE
107 typedef uint32_t UINTN
;
108 typedef int32_t INTN
;
110 #define EFIERR(a) (0x80000000 | a)
115 #ifdef USE_EFI_FUNCTION_WRAPPER
116 #define __VA_NARG__(...) \
117 __VA_NARG_(_0, ## __VA_ARGS__, __RSEQ_N())
118 #define __VA_NARG_(...) \
119 __VA_ARG_N(__VA_ARGS__)
120 #define __VA_ARG_N( \
121 _0,_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,N,...) N
123 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
125 #define __VA_ARG_NSUFFIX__(prefix,...) \
126 __VA_ARG_NSUFFIX_N(prefix, __VA_NARG__(__VA_ARGS__))
127 #define __VA_ARG_NSUFFIX_N(prefix,nargs) \
128 __VA_ARG_NSUFFIX_N_(prefix, nargs)
129 #define __VA_ARG_NSUFFIX_N_(prefix,nargs) \
132 /* Prototypes of EFI cdecl -> stdcall trampolines */
134 UINT64
efi_call0(void *func
);
135 UINT64
efi_call1(void *func
, UINT64 arg1
);
136 UINT64
efi_call2(void *func
, UINT64 arg1
, UINT64 arg2
);
137 UINT64
efi_call3(void *func
, UINT64 arg1
, UINT64 arg2
, UINT64 arg3
);
138 UINT64
efi_call4(void *func
, UINT64 arg1
, UINT64 arg2
, UINT64 arg3
,
140 UINT64
efi_call5(void *func
, UINT64 arg1
, UINT64 arg2
, UINT64 arg3
,
141 UINT64 arg4
, UINT64 arg5
);
142 UINT64
efi_call6(void *func
, UINT64 arg1
, UINT64 arg2
, UINT64 arg3
,
143 UINT64 arg4
, UINT64 arg5
, UINT64 arg6
);
144 UINT64
efi_call7(void *func
, UINT64 arg1
, UINT64 arg2
, UINT64 arg3
,
145 UINT64 arg4
, UINT64 arg5
, UINT64 arg6
, UINT64 arg7
);
146 UINT64
efi_call8(void *func
, UINT64 arg1
, UINT64 arg2
, UINT64 arg3
,
147 UINT64 arg4
, UINT64 arg5
, UINT64 arg6
, UINT64 arg7
,
149 UINT64
efi_call9(void *func
, UINT64 arg1
, UINT64 arg2
, UINT64 arg3
,
150 UINT64 arg4
, UINT64 arg5
, UINT64 arg6
, UINT64 arg7
,
151 UINT64 arg8
, UINT64 arg9
);
152 UINT64
efi_call10(void *func
, UINT64 arg1
, UINT64 arg2
, UINT64 arg3
,
153 UINT64 arg4
, UINT64 arg5
, UINT64 arg6
, UINT64 arg7
,
154 UINT64 arg8
, UINT64 arg9
, UINT64 arg10
);
156 /* Front-ends to efi_callX to avoid compiler warnings */
158 #define _cast64_efi_call0(f) \
160 #define _cast64_efi_call1(f,a1) \
161 efi_call1(f, (UINT64)(a1))
162 #define _cast64_efi_call2(f,a1,a2) \
163 efi_call2(f, (UINT64)(a1), (UINT64)(a2))
164 #define _cast64_efi_call3(f,a1,a2,a3) \
165 efi_call3(f, (UINT64)(a1), (UINT64)(a2), (UINT64)(a3))
166 #define _cast64_efi_call4(f,a1,a2,a3,a4) \
167 efi_call4(f, (UINT64)(a1), (UINT64)(a2), (UINT64)(a3), (UINT64)(a4))
168 #define _cast64_efi_call5(f,a1,a2,a3,a4,a5) \
169 efi_call5(f, (UINT64)(a1), (UINT64)(a2), (UINT64)(a3), (UINT64)(a4), \
171 #define _cast64_efi_call6(f,a1,a2,a3,a4,a5,a6) \
172 efi_call6(f, (UINT64)(a1), (UINT64)(a2), (UINT64)(a3), (UINT64)(a4), \
173 (UINT64)(a5), (UINT64)(a6))
174 #define _cast64_efi_call7(f,a1,a2,a3,a4,a5,a6,a7) \
175 efi_call7(f, (UINT64)(a1), (UINT64)(a2), (UINT64)(a3), (UINT64)(a4), \
176 (UINT64)(a5), (UINT64)(a6), (UINT64)(a7))
177 #define _cast64_efi_call8(f,a1,a2,a3,a4,a5,a6,a7,a8) \
178 efi_call8(f, (UINT64)(a1), (UINT64)(a2), (UINT64)(a3), (UINT64)(a4), \
179 (UINT64)(a5), (UINT64)(a6), (UINT64)(a7), (UINT64)(a8))
180 #define _cast64_efi_call9(f,a1,a2,a3,a4,a5,a6,a7,a8,a9) \
181 efi_call9(f, (UINT64)(a1), (UINT64)(a2), (UINT64)(a3), (UINT64)(a4), \
182 (UINT64)(a5), (UINT64)(a6), (UINT64)(a7), (UINT64)(a8), \
184 #define _cast64_efi_call10(f,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10) \
185 efi_call10(f, (UINT64)(a1), (UINT64)(a2), (UINT64)(a3), (UINT64)(a4), \
186 (UINT64)(a5), (UINT64)(a6), (UINT64)(a7), (UINT64)(a8), \
187 (UINT64)(a9), (UINT64)(a10))
189 /* main wrapper (va_num ignored) */
191 #define uefi_call_wrapper(func,va_num,...) \
192 __VA_ARG_NSUFFIX__(_cast64_efi_call, __VA_ARGS__) (func , ##__VA_ARGS__)
196 #define uefi_call_wrapper(func, va_num, ...) func(__VA_ARGS__)
200 /* AED EFI definitions */
202 #if defined(_AED_EFI)
204 /* _int64 works for both IA32 and IA64 */
206 #define COMPILER_DEPENDENT_INT64 __int64
207 #define COMPILER_DEPENDENT_UINT64 unsigned __int64
210 * Calling conventions:
212 * ACPI_SYSTEM_XFACE - Interfaces to host OS (handlers, threads)
213 * ACPI_EXTERNAL_XFACE - External ACPI interfaces
214 * ACPI_INTERNAL_XFACE - Internal ACPI interfaces
215 * ACPI_INTERNAL_VAR_XFACE - Internal variable-parameter list interfaces
217 #define ACPI_SYSTEM_XFACE
218 #define ACPI_EXTERNAL_XFACE
219 #define ACPI_INTERNAL_XFACE
220 #define ACPI_INTERNAL_VAR_XFACE
222 /* warn C4142: redefinition of type */
224 #pragma warning(disable:4142)
229 /* GNU EFI definitions */
231 #if defined(_GNU_EFI)
233 /* Using GCC for GNU EFI */
237 #undef ACPI_USE_SYSTEM_CLIBRARY
238 #undef ACPI_USE_STANDARD_HEADERS
239 #undef ACPI_USE_NATIVE_DIVIDE
240 #define ACPI_USE_SYSTEM_INTTYPES
245 #define ACPI_DIV_64_BY_32(n_hi, n_lo, d32, q32, r32) \
247 UINT64 __n = ((UINT64) n_hi) << 32 | (n_lo); \
248 (q32) = DivU64x32 ((__n), (d32), &(r32)); \
251 #define ACPI_SHIFT_RIGHT_64(n_hi, n_lo) \
254 (n_lo) |= (((n_hi) & 1) << 31); \
261 struct _SIMPLE_TEXT_OUTPUT_INTERFACE
;
262 struct _SIMPLE_INPUT_INTERFACE
;
263 struct _EFI_FILE_IO_INTERFACE
;
264 struct _EFI_FILE_HANDLE
;
265 struct _EFI_BOOT_SERVICES
;
266 struct _EFI_SYSTEM_TABLE
;
268 extern struct _EFI_SYSTEM_TABLE
*ST
;
269 extern struct _EFI_BOOT_SERVICES
*BS
;
271 #define ACPI_FILE struct _SIMPLE_TEXT_OUTPUT_INTERFACE *
272 #define ACPI_FILE_OUT ST->ConOut
273 #define ACPI_FILE_ERR ST->ConOut
275 #endif /* __ACEFI_H__ */