17c478bd9Sstevel@tonic-gate /******************************************************************************
27c478bd9Sstevel@tonic-gate  *
37c478bd9Sstevel@tonic-gate  * Name: acwin.h - OS specific defines, etc.
47c478bd9Sstevel@tonic-gate  *
57c478bd9Sstevel@tonic-gate  *****************************************************************************/
67c478bd9Sstevel@tonic-gate 
7*26f3cdf0SGordon Ross /*
8*26f3cdf0SGordon Ross  * Copyright (C) 2000 - 2011, Intel Corp.
97c478bd9Sstevel@tonic-gate  * All rights reserved.
107c478bd9Sstevel@tonic-gate  *
11*26f3cdf0SGordon Ross  * Redistribution and use in source and binary forms, with or without
12*26f3cdf0SGordon Ross  * modification, are permitted provided that the following conditions
13*26f3cdf0SGordon Ross  * are met:
14*26f3cdf0SGordon Ross  * 1. Redistributions of source code must retain the above copyright
15*26f3cdf0SGordon Ross  *    notice, this list of conditions, and the following disclaimer,
16*26f3cdf0SGordon Ross  *    without modification.
17*26f3cdf0SGordon Ross  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18*26f3cdf0SGordon Ross  *    substantially similar to the "NO WARRANTY" disclaimer below
19*26f3cdf0SGordon Ross  *    ("Disclaimer") and any redistribution must be conditioned upon
20*26f3cdf0SGordon Ross  *    including a substantially similar Disclaimer requirement for further
21*26f3cdf0SGordon Ross  *    binary redistribution.
22*26f3cdf0SGordon Ross  * 3. Neither the names of the above-listed copyright holders nor the names
23*26f3cdf0SGordon Ross  *    of any contributors may be used to endorse or promote products derived
24*26f3cdf0SGordon Ross  *    from this software without specific prior written permission.
25*26f3cdf0SGordon Ross  *
26*26f3cdf0SGordon Ross  * Alternatively, this software may be distributed under the terms of the
27*26f3cdf0SGordon Ross  * GNU General Public License ("GPL") version 2 as published by the Free
28*26f3cdf0SGordon Ross  * Software Foundation.
29*26f3cdf0SGordon Ross  *
30*26f3cdf0SGordon Ross  * NO WARRANTY
31*26f3cdf0SGordon Ross  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32*26f3cdf0SGordon Ross  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33*26f3cdf0SGordon Ross  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34*26f3cdf0SGordon Ross  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35*26f3cdf0SGordon Ross  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36*26f3cdf0SGordon Ross  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37*26f3cdf0SGordon Ross  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38*26f3cdf0SGordon Ross  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39*26f3cdf0SGordon Ross  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40*26f3cdf0SGordon Ross  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41*26f3cdf0SGordon Ross  * POSSIBILITY OF SUCH DAMAGES.
42*26f3cdf0SGordon Ross  */
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate #ifndef __ACWIN_H__
457c478bd9Sstevel@tonic-gate #define __ACWIN_H__
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate /*! [Begin] no source code translation (Keep the include) */
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate /* Windows uses VC */
507c478bd9Sstevel@tonic-gate #ifdef _MSC_VER
517c478bd9Sstevel@tonic-gate #include "acmsvc.h"
527c478bd9Sstevel@tonic-gate #endif
537c478bd9Sstevel@tonic-gate /*! [End] no source code translation !*/
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate #define ACPI_MACHINE_WIDTH      32
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate #define ACPI_USE_STANDARD_HEADERS
587c478bd9Sstevel@tonic-gate 
5930082d0cSmyers #ifdef ACPI_DEFINE_ALTERNATE_TYPES
6030082d0cSmyers /*
6130082d0cSmyers  * Types used only in (Linux) translated source, defined here to enable
6230082d0cSmyers  * cross-platform compilation (i.e., generate the Linux code on Windows,
6330082d0cSmyers  * for test purposes only)
6430082d0cSmyers  */
6530082d0cSmyers typedef int                             s32;
6630082d0cSmyers typedef unsigned char                   u8;
6730082d0cSmyers typedef unsigned short                  u16;
6830082d0cSmyers typedef unsigned int                    u32;
6930082d0cSmyers typedef COMPILER_DEPENDENT_UINT64       u64;
7030082d0cSmyers #endif
7130082d0cSmyers 
7230082d0cSmyers 
737c478bd9Sstevel@tonic-gate /*
747c478bd9Sstevel@tonic-gate  * Handle platform- and compiler-specific assembly language differences.
757c478bd9Sstevel@tonic-gate  *
767c478bd9Sstevel@tonic-gate  * Notes:
777c478bd9Sstevel@tonic-gate  * 1) Interrupt 3 is used to break into a debugger
787c478bd9Sstevel@tonic-gate  * 2) Interrupts are turned off during ACPI register setup
797c478bd9Sstevel@tonic-gate  */
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate /*! [Begin] no source code translation  */
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate #ifdef ACPI_APPLICATION
847c478bd9Sstevel@tonic-gate #define ACPI_FLUSH_CPU_CACHE()
857c478bd9Sstevel@tonic-gate #else
867c478bd9Sstevel@tonic-gate #define ACPI_FLUSH_CPU_CACHE()  __asm {WBINVD}
877c478bd9Sstevel@tonic-gate #endif
887c478bd9Sstevel@tonic-gate 
89186507a7Smyers #ifdef _DEBUG
90186507a7Smyers #define ACPI_SIMPLE_RETURN_MACROS
91186507a7Smyers #endif
927c478bd9Sstevel@tonic-gate 
93db2bae30SDana Myers /*! [End] no source code translation !*/
94db2bae30SDana Myers 
957c478bd9Sstevel@tonic-gate /*
96db2bae30SDana Myers  * Global Lock acquire/release code
97db2bae30SDana Myers  *
98db2bae30SDana Myers  * Note: Handles case where the FACS pointer is null
997c478bd9Sstevel@tonic-gate  */
100db2bae30SDana Myers #define ACPI_ACQUIRE_GLOBAL_LOCK(FacsPtr, Acq)  __asm \
101db2bae30SDana Myers {                                                   \
102db2bae30SDana Myers         __asm mov           eax, 0xFF               \
103db2bae30SDana Myers         __asm mov           ecx, FacsPtr            \
104db2bae30SDana Myers         __asm or            ecx, ecx                \
105db2bae30SDana Myers         __asm jz            exit_acq                \
106db2bae30SDana Myers         __asm lea           ecx, [ecx].GlobalLock   \
107db2bae30SDana Myers                                                     \
1087c478bd9Sstevel@tonic-gate         __asm acq10:                                \
1097c478bd9Sstevel@tonic-gate         __asm mov           eax, [ecx]              \
1107c478bd9Sstevel@tonic-gate         __asm mov           edx, eax                \
1117c478bd9Sstevel@tonic-gate         __asm and           edx, 0xFFFFFFFE         \
1127c478bd9Sstevel@tonic-gate         __asm bts           edx, 1                  \
1137c478bd9Sstevel@tonic-gate         __asm adc           edx, 0                  \
1147c478bd9Sstevel@tonic-gate         __asm lock cmpxchg  dword ptr [ecx], edx    \
1157c478bd9Sstevel@tonic-gate         __asm jnz           acq10                   \
1167c478bd9Sstevel@tonic-gate                                                     \
1177c478bd9Sstevel@tonic-gate         __asm cmp           dl, 3                   \
1187c478bd9Sstevel@tonic-gate         __asm sbb           eax, eax                \
119db2bae30SDana Myers                                                     \
120db2bae30SDana Myers         __asm exit_acq:                             \
1217c478bd9Sstevel@tonic-gate         __asm mov           Acq, al                 \
1227c478bd9Sstevel@tonic-gate }
1237c478bd9Sstevel@tonic-gate 
124db2bae30SDana Myers #define ACPI_RELEASE_GLOBAL_LOCK(FacsPtr, Pnd) __asm \
125db2bae30SDana Myers {                                                   \
126db2bae30SDana Myers         __asm xor           eax, eax                \
127db2bae30SDana Myers         __asm mov           ecx, FacsPtr            \
128db2bae30SDana Myers         __asm or            ecx, ecx                \
129db2bae30SDana Myers         __asm jz            exit_rel                \
130db2bae30SDana Myers         __asm lea           ecx, [ecx].GlobalLock   \
131db2bae30SDana Myers                                                     \
1327c478bd9Sstevel@tonic-gate         __asm Rel10:                                \
1337c478bd9Sstevel@tonic-gate         __asm mov           eax, [ecx]              \
1347c478bd9Sstevel@tonic-gate         __asm mov           edx, eax                \
1357c478bd9Sstevel@tonic-gate         __asm and           edx, 0xFFFFFFFC         \
1367c478bd9Sstevel@tonic-gate         __asm lock cmpxchg  dword ptr [ecx], edx    \
1377c478bd9Sstevel@tonic-gate         __asm jnz           Rel10                   \
1387c478bd9Sstevel@tonic-gate                                                     \
1397c478bd9Sstevel@tonic-gate         __asm cmp           dl, 3                   \
1407c478bd9Sstevel@tonic-gate         __asm and           eax, 1                  \
141db2bae30SDana Myers                                                     \
142db2bae30SDana Myers         __asm exit_rel:                             \
1437c478bd9Sstevel@tonic-gate         __asm mov           Pnd, al                 \
1447c478bd9Sstevel@tonic-gate }
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate #endif /* __ACWIN_H__ */
147