xref: /illumos-gate/usr/src/uts/intel/sys/acpi/platform/acefi.h (revision 8c69cc8fbe729fa7b091e901c4b50508ccc6bb33)
1 /******************************************************************************
2  *
3  * Name: acefi.h - OS specific defines, etc.
4  *
5  *****************************************************************************/
6 
7 /*
8  * Copyright (C) 2000 - 2016, 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 #include <stdarg.h>
48 #if defined(_GNU_EFI)
49 #include <stdint.h>
50 #include <unistd.h>
51 #endif
52 
53 #if defined(__x86_64__)
54 #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7))
55 #define USE_MS_ABI 1
56 #endif
57 #endif
58 
59 #ifdef _MSC_EXTENSIONS
60 #define EFIAPI __cdecl
61 #elif USE_MS_ABI
62 #define EFIAPI __attribute__((ms_abi))
63 #else
64 #define EFIAPI
65 #endif
66 
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;
76 
77 #define VOID        void
78 
79 #if defined(__ia64__) || defined(__x86_64__)
80 
81 #define ACPI_MACHINE_WIDTH          64
82 
83 #if defined(__x86_64__)
84 
85 /* for x86_64, EFI_FUNCTION_WRAPPER must be defined */
86 
87 #ifndef USE_MS_ABI
88 #define USE_EFI_FUNCTION_WRAPPER
89 #endif
90 
91 #ifdef _MSC_EXTENSIONS
92 #pragma warning ( disable : 4731 )  /* Suppress warnings about modification of EBP */
93 #endif
94 
95 #endif
96 
97 typedef uint64_t    UINTN;
98 typedef int64_t     INTN;
99 
100 #define EFIERR(a)           (0x8000000000000000 | a)
101 
102 #else
103 
104 #define ACPI_MACHINE_WIDTH          32
105 #define ACPI_USE_NATIVE_DIVIDE
106 
107 typedef uint32_t UINTN;
108 typedef int32_t INTN;
109 
110 #define EFIERR(a)           (0x80000000 | a)
111 
112 #endif
113 
114 
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
122 #define __RSEQ_N()                              \
123   10, 9,  8,  7,  6,  5,  4,  3,  2,  1,  0
124 
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)       \
130   prefix ## nargs
131 
132 /* Prototypes of EFI cdecl -> stdcall trampolines */
133 
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,
139                  UINT64 arg4);
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,
148                  UINT64 arg8);
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);
155 
156 /* Front-ends to efi_callX to avoid compiler warnings */
157 
158 #define _cast64_efi_call0(f) \
159   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), \
170             (UINT64)(a5))
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), \
183             (UINT64)(a9))
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))
188 
189 /* main wrapper (va_num ignored) */
190 
191 #define uefi_call_wrapper(func,va_num,...)                        \
192   __VA_ARG_NSUFFIX__(_cast64_efi_call, __VA_ARGS__) (func , ##__VA_ARGS__)
193 
194 #else
195 
196 #define uefi_call_wrapper(func, va_num, ...) func(__VA_ARGS__)
197 
198 #endif
199 
200 /* AED EFI definitions */
201 
202 #if defined(_AED_EFI)
203 
204 /* _int64 works for both IA32 and IA64 */
205 
206 #define COMPILER_DEPENDENT_INT64   __int64
207 #define COMPILER_DEPENDENT_UINT64  unsigned __int64
208 
209 /*
210  * Calling conventions:
211  *
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
216  */
217 #define ACPI_SYSTEM_XFACE
218 #define ACPI_EXTERNAL_XFACE
219 #define ACPI_INTERNAL_XFACE
220 #define ACPI_INTERNAL_VAR_XFACE
221 
222 /* warn C4142: redefinition of type */
223 
224 #pragma warning(disable:4142)
225 
226 #endif
227 
228 
229 /* GNU EFI definitions */
230 
231 #if defined(_GNU_EFI)
232 
233 /* Using GCC for GNU EFI */
234 
235 #include "acgcc.h"
236 
237 #undef ACPI_USE_SYSTEM_CLIBRARY
238 #undef ACPI_USE_STANDARD_HEADERS
239 #undef ACPI_USE_NATIVE_DIVIDE
240 #define ACPI_USE_SYSTEM_INTTYPES
241 
242 /*
243  * Math helpers
244  */
245 #define ACPI_DIV_64_BY_32(n_hi, n_lo, d32, q32, r32) \
246     do {                                             \
247         UINT64 __n = ((UINT64) n_hi) << 32 | (n_lo); \
248         (q32) = DivU64x32 ((__n), (d32), &(r32));    \
249     } while (0)
250 
251 #define ACPI_SHIFT_RIGHT_64(n_hi, n_lo) \
252     do {                                \
253         (n_lo) >>= 1;                   \
254         (n_lo) |= (((n_hi) & 1) << 31); \
255         (n_hi) >>= 1;                   \
256     } while (0)
257 
258 
259 #endif
260 
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;
267 
268 extern struct _EFI_SYSTEM_TABLE         *ST;
269 extern struct _EFI_BOOT_SERVICES        *BS;
270 
271 #define ACPI_FILE           struct _SIMPLE_TEXT_OUTPUT_INTERFACE *
272 #define ACPI_FILE_OUT       ST->ConOut
273 #define ACPI_FILE_ERR       ST->ConOut
274 
275 #endif /* __ACEFI_H__ */
276