c6f8c8b5f1398fb0306f8257a5e85fdea0e0175a
[reactos.git] / reactos / drivers / bus / acpi / acpica / include / platform / acefi.h
1 /******************************************************************************
2 *
3 * Name: acefi.h - OS specific defines, etc.
4 *
5 *****************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2017, 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 __ACEFI_H__
45 #define __ACEFI_H__
46
47 /* EDK2 EFI environemnt */
48
49 #if defined(_EDK2_EFI)
50
51 #define _GNU_EFI
52
53 #endif
54
55 #if defined(__x86_64__)
56 #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7))
57 #define USE_MS_ABI 1
58 #endif
59 #endif
60
61 #ifdef _MSC_EXTENSIONS
62 #define ACPI_EFI_API __cdecl
63 #elif USE_MS_ABI
64 #define ACPI_EFI_API __attribute__((ms_abi))
65 #else
66 #define ACPI_EFI_API
67 #endif
68
69 #define VOID void
70
71 #if defined(__ia64__) || defined(__x86_64__)
72
73 #define ACPI_MACHINE_WIDTH 64
74
75 #if defined(__x86_64__)
76
77 /* for x86_64, EFI_FUNCTION_WRAPPER must be defined */
78
79 #ifndef USE_MS_ABI
80 #define USE_EFI_FUNCTION_WRAPPER
81 #endif
82
83 #ifdef _MSC_EXTENSIONS
84 #pragma warning ( disable : 4731 ) /* Suppress warnings about modification of EBP */
85 #endif
86
87 #endif
88
89 #define UINTN uint64_t
90 #define INTN int64_t
91
92 #define ACPI_EFI_ERR(a) (0x8000000000000000 | a)
93
94 #else
95
96 #define ACPI_MACHINE_WIDTH 32
97
98 #define UINTN uint32_t
99 #define INTN int32_t
100
101 #define ACPI_EFI_ERR(a) (0x80000000 | a)
102
103 #endif
104
105 #define CHAR16 uint16_t
106
107 #ifdef USE_EFI_FUNCTION_WRAPPER
108 #define __VA_NARG__(...) \
109 __VA_NARG_(_0, ## __VA_ARGS__, __RSEQ_N())
110 #define __VA_NARG_(...) \
111 __VA_ARG_N(__VA_ARGS__)
112 #define __VA_ARG_N( \
113 _0,_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,N,...) N
114 #define __RSEQ_N() \
115 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
116
117 #define __VA_ARG_NSUFFIX__(prefix,...) \
118 __VA_ARG_NSUFFIX_N(prefix, __VA_NARG__(__VA_ARGS__))
119 #define __VA_ARG_NSUFFIX_N(prefix,nargs) \
120 __VA_ARG_NSUFFIX_N_(prefix, nargs)
121 #define __VA_ARG_NSUFFIX_N_(prefix,nargs) \
122 prefix ## nargs
123
124 /* Prototypes of EFI cdecl -> stdcall trampolines */
125
126 UINT64 efi_call0(void *func);
127 UINT64 efi_call1(void *func, UINT64 arg1);
128 UINT64 efi_call2(void *func, UINT64 arg1, UINT64 arg2);
129 UINT64 efi_call3(void *func, UINT64 arg1, UINT64 arg2, UINT64 arg3);
130 UINT64 efi_call4(void *func, UINT64 arg1, UINT64 arg2, UINT64 arg3,
131 UINT64 arg4);
132 UINT64 efi_call5(void *func, UINT64 arg1, UINT64 arg2, UINT64 arg3,
133 UINT64 arg4, UINT64 arg5);
134 UINT64 efi_call6(void *func, UINT64 arg1, UINT64 arg2, UINT64 arg3,
135 UINT64 arg4, UINT64 arg5, UINT64 arg6);
136 UINT64 efi_call7(void *func, UINT64 arg1, UINT64 arg2, UINT64 arg3,
137 UINT64 arg4, UINT64 arg5, UINT64 arg6, UINT64 arg7);
138 UINT64 efi_call8(void *func, UINT64 arg1, UINT64 arg2, UINT64 arg3,
139 UINT64 arg4, UINT64 arg5, UINT64 arg6, UINT64 arg7,
140 UINT64 arg8);
141 UINT64 efi_call9(void *func, UINT64 arg1, UINT64 arg2, UINT64 arg3,
142 UINT64 arg4, UINT64 arg5, UINT64 arg6, UINT64 arg7,
143 UINT64 arg8, UINT64 arg9);
144 UINT64 efi_call10(void *func, UINT64 arg1, UINT64 arg2, UINT64 arg3,
145 UINT64 arg4, UINT64 arg5, UINT64 arg6, UINT64 arg7,
146 UINT64 arg8, UINT64 arg9, UINT64 arg10);
147
148 /* Front-ends to efi_callX to avoid compiler warnings */
149
150 #define _cast64_efi_call0(f) \
151 efi_call0(f)
152 #define _cast64_efi_call1(f,a1) \
153 efi_call1(f, (UINT64)(a1))
154 #define _cast64_efi_call2(f,a1,a2) \
155 efi_call2(f, (UINT64)(a1), (UINT64)(a2))
156 #define _cast64_efi_call3(f,a1,a2,a3) \
157 efi_call3(f, (UINT64)(a1), (UINT64)(a2), (UINT64)(a3))
158 #define _cast64_efi_call4(f,a1,a2,a3,a4) \
159 efi_call4(f, (UINT64)(a1), (UINT64)(a2), (UINT64)(a3), (UINT64)(a4))
160 #define _cast64_efi_call5(f,a1,a2,a3,a4,a5) \
161 efi_call5(f, (UINT64)(a1), (UINT64)(a2), (UINT64)(a3), (UINT64)(a4), \
162 (UINT64)(a5))
163 #define _cast64_efi_call6(f,a1,a2,a3,a4,a5,a6) \
164 efi_call6(f, (UINT64)(a1), (UINT64)(a2), (UINT64)(a3), (UINT64)(a4), \
165 (UINT64)(a5), (UINT64)(a6))
166 #define _cast64_efi_call7(f,a1,a2,a3,a4,a5,a6,a7) \
167 efi_call7(f, (UINT64)(a1), (UINT64)(a2), (UINT64)(a3), (UINT64)(a4), \
168 (UINT64)(a5), (UINT64)(a6), (UINT64)(a7))
169 #define _cast64_efi_call8(f,a1,a2,a3,a4,a5,a6,a7,a8) \
170 efi_call8(f, (UINT64)(a1), (UINT64)(a2), (UINT64)(a3), (UINT64)(a4), \
171 (UINT64)(a5), (UINT64)(a6), (UINT64)(a7), (UINT64)(a8))
172 #define _cast64_efi_call9(f,a1,a2,a3,a4,a5,a6,a7,a8,a9) \
173 efi_call9(f, (UINT64)(a1), (UINT64)(a2), (UINT64)(a3), (UINT64)(a4), \
174 (UINT64)(a5), (UINT64)(a6), (UINT64)(a7), (UINT64)(a8), \
175 (UINT64)(a9))
176 #define _cast64_efi_call10(f,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10) \
177 efi_call10(f, (UINT64)(a1), (UINT64)(a2), (UINT64)(a3), (UINT64)(a4), \
178 (UINT64)(a5), (UINT64)(a6), (UINT64)(a7), (UINT64)(a8), \
179 (UINT64)(a9), (UINT64)(a10))
180
181 /* main wrapper (va_num ignored) */
182
183 #define uefi_call_wrapper(func,va_num,...) \
184 __VA_ARG_NSUFFIX__(_cast64_efi_call, __VA_ARGS__) (func , ##__VA_ARGS__)
185
186 #else
187
188 #define uefi_call_wrapper(func, va_num, ...) func(__VA_ARGS__)
189
190 #endif
191
192 /* AED EFI definitions */
193
194 #if defined(_AED_EFI)
195
196 /* _int64 works for both IA32 and IA64 */
197
198 #define COMPILER_DEPENDENT_INT64 __int64
199 #define COMPILER_DEPENDENT_UINT64 unsigned __int64
200
201 /*
202 * Calling conventions:
203 *
204 * ACPI_SYSTEM_XFACE - Interfaces to host OS (handlers, threads)
205 * ACPI_EXTERNAL_XFACE - External ACPI interfaces
206 * ACPI_INTERNAL_XFACE - Internal ACPI interfaces
207 * ACPI_INTERNAL_VAR_XFACE - Internal variable-parameter list interfaces
208 */
209 #define ACPI_SYSTEM_XFACE
210 #define ACPI_EXTERNAL_XFACE
211 #define ACPI_INTERNAL_XFACE
212 #define ACPI_INTERNAL_VAR_XFACE
213
214 /* warn C4142: redefinition of type */
215
216 #pragma warning(disable:4142)
217
218 #endif
219
220
221 /* GNU EFI definitions */
222
223 #if defined(_GNU_EFI)
224
225 /*
226 * Math helpers
227 */
228 #define ACPI_DIV_64_BY_32(n_hi, n_lo, d32, q32, r32) \
229 do { \
230 UINT64 __n = ((UINT64) n_hi) << 32 | (n_lo); \
231 (q32) = DivU64x32 ((__n), (d32), &(r32)); \
232 } while (0)
233
234 #define ACPI_SHIFT_RIGHT_64(n_hi, n_lo) \
235 do { \
236 (n_lo) >>= 1; \
237 (n_lo) |= (((n_hi) & 1) << 31); \
238 (n_hi) >>= 1; \
239 } while (0)
240
241 #endif
242
243 struct _ACPI_SIMPLE_TEXT_OUTPUT_INTERFACE;
244 struct _ACPI_SIMPLE_INPUT_INTERFACE;
245 struct _ACPI_EFI_FILE_IO_INTERFACE;
246 struct _ACPI_EFI_FILE_HANDLE;
247 struct _ACPI_EFI_BOOT_SERVICES;
248 struct _ACPI_EFI_SYSTEM_TABLE;
249 struct _ACPI_EFI_PCI_IO;
250
251 extern struct _ACPI_EFI_SYSTEM_TABLE *ST;
252 extern struct _ACPI_EFI_BOOT_SERVICES *BS;
253
254 typedef union acpi_efi_file ACPI_EFI_FILE;
255 #define FILE ACPI_EFI_FILE
256
257 extern FILE *stdin;
258 extern FILE *stdout;
259 extern FILE *stderr;
260
261 #endif /* __ACEFI_H__ */