xref: /netbsd-src/sys/external/bsd/acpica/dist/include/platform/acwin.h (revision c7960b37466ae0fd417c32e6acbb4b956ac7a121)
1 /******************************************************************************
2  *
3  * Name: acwin.h - OS specific defines, etc.
4  *
5  *****************************************************************************/
6 
7 /*
8  * Copyright (C) 2000 - 2023, 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 MERCHANTABILITY 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 __ACWIN_H__
45 #define __ACWIN_H__
46 
47 #include <io.h>
48 
49 #define ACPI_USE_STANDARD_HEADERS
50 #define ACPI_USE_SYSTEM_CLIBRARY
51 
52  /* Note: do not include any C library headers here */
53 
54  /*
55  * Note: MSVC project files should define ACPI_DEBUGGER and ACPI_DISASSEMBLER
56  * as appropriate to enable editor functions like "Find all references".
57  * The editor isn't smart enough to dig through the include files to find
58  * out if these are actually defined.
59  */
60 
61  /* Eliminate warnings for "old" (non-secure) versions of clib functions */
62 
63 #ifndef _CRT_SECURE_NO_WARNINGS
64 #define _CRT_SECURE_NO_WARNINGS
65 #endif
66 
67  /* Eliminate warnings for POSIX clib function names (open, write, etc.) */
68 
69 #ifndef _CRT_NONSTDC_NO_DEPRECATE
70 #define _CRT_NONSTDC_NO_DEPRECATE
71 #endif
72 
73  /*  Disable these warnings under Windows and MSVC since C4201: nameless
74   *  structs/unions are needed as ACPI event-handling under Linux/GCC breaks
75   *  with named and nested structs/unions while C4068: unknown pragma
76   *  complains of GCC pragmas in use to disable dangling ptr warnings
77   */
78 
79 #pragma warning( disable: 4201)
80 #pragma warning( disable: 4068)
81 #pragma warning( push)
82 
83 #define ACPI_MACHINE_WIDTH      32
84 #define ACPI_USE_NATIVE_DIVIDE
85 #define ACPI_USE_NATIVE_MATH64
86 
87 #ifdef ACPI_DEFINE_ALTERNATE_TYPES
88 /*
89  * Types used only in (Linux) translated source, defined here to enable
90  * cross-platform compilation (i.e., generate the Linux code on Windows,
91  * for test purposes only)
92  */
93 typedef int                             s32;
94 typedef unsigned char                   u8;
95 typedef unsigned short                  u16;
96 typedef unsigned int                    u32;
97 typedef COMPILER_DEPENDENT_UINT64       u64;
98 #endif
99 
100 /*
101  * Map low I/O functions for MS. This allows us to disable MS language
102  * extensions for maximum portability.
103  */
104 #define open            _open
105 #define read            _read
106 #define write           _write
107 #define close           _close
108 #define stat            _stat
109 #define fstat           _fstat
110 #define mkdir           _mkdir
111 #define fileno          _fileno
112 #define isatty          _isatty
113 
114 #if _MSC_VER <= 1200 /* Versions below VC++ 6 */
115 #define vsnprintf       _vsnprintf
116 #endif
117 #define O_RDONLY        _O_RDONLY
118 #define O_BINARY        _O_BINARY
119 #define O_CREAT         _O_CREAT
120 #define O_WRONLY        _O_WRONLY
121 #define O_TRUNC         _O_TRUNC
122 #define S_IREAD         _S_IREAD
123 #define S_IWRITE        _S_IWRITE
124 #define S_IFDIR         _S_IFDIR
125 #if _MSC_VER < 1900
126 #define snprintf        _snprintf
127 #endif
128 
129 
130 /*
131  * Handle platform- and compiler-specific assembly language differences.
132  *
133  * Notes:
134  * 1) Interrupt 3 is used to break into a debugger
135  * 2) Interrupts are turned off during ACPI register setup
136  */
137 
138 /*! [Begin] no source code translation  */
139 
140 #ifdef ACPI_APPLICATION
141 #define ACPI_FLUSH_CPU_CACHE()
142 #else
143 #define ACPI_FLUSH_CPU_CACHE()  __asm {WBINVD}
144 #endif
145 
146 #ifdef _DEBUG
147 #define ACPI_SIMPLE_RETURN_MACROS
148 #endif
149 
150 /*! [End] no source code translation !*/
151 
152 /*
153  * Global Lock acquire/release code
154  *
155  * Note: Handles case where the FACS pointer is null
156  */
157 #define ACPI_ACQUIRE_GLOBAL_LOCK(FacsPtr, Acq)  __asm \
158 {                                                   \
159         __asm mov           eax, 0xFF               \
160         __asm mov           ecx, FacsPtr            \
161         __asm or            ecx, ecx                \
162         __asm jz            exit_acq                \
163         __asm lea           ecx, [ecx].GlobalLock   \
164                                                     \
165         __asm acq10:                                \
166         __asm mov           eax, [ecx]              \
167         __asm mov           edx, eax                \
168         __asm and           edx, 0xFFFFFFFE         \
169         __asm bts           edx, 1                  \
170         __asm adc           edx, 0                  \
171         __asm lock cmpxchg  dword ptr [ecx], edx    \
172         __asm jnz           acq10                   \
173                                                     \
174         __asm cmp           dl, 3                   \
175         __asm sbb           eax, eax                \
176                                                     \
177         __asm exit_acq:                             \
178         __asm mov           Acq, al                 \
179 }
180 
181 #define ACPI_RELEASE_GLOBAL_LOCK(FacsPtr, Pnd) __asm \
182 {                                                   \
183         __asm xor           eax, eax                \
184         __asm mov           ecx, FacsPtr            \
185         __asm or            ecx, ecx                \
186         __asm jz            exit_rel                \
187         __asm lea           ecx, [ecx].GlobalLock   \
188                                                     \
189         __asm Rel10:                                \
190         __asm mov           eax, [ecx]              \
191         __asm mov           edx, eax                \
192         __asm and           edx, 0xFFFFFFFC         \
193         __asm lock cmpxchg  dword ptr [ecx], edx    \
194         __asm jnz           Rel10                   \
195                                                     \
196         __asm cmp           dl, 3                   \
197         __asm and           eax, 1                  \
198                                                     \
199         __asm exit_rel:                             \
200         __asm mov           Pnd, al                 \
201 }
202 
203 #endif /* __ACWIN_H__ */
204