17c478bd9Sstevel@tonic-gate /******************************************************************************
27c478bd9Sstevel@tonic-gate  *
3aa2aa9a6SDana Myers  * Name: aclinux.h - OS specific defines, etc. for Linux
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 __ACLINUX_H__
457c478bd9Sstevel@tonic-gate #define __ACLINUX_H__
467c478bd9Sstevel@tonic-gate 
47aa2aa9a6SDana Myers /* Common (in-kernel/user-space) ACPICA configuration */
48aa2aa9a6SDana Myers 
497c478bd9Sstevel@tonic-gate #define ACPI_USE_SYSTEM_CLIBRARY
507c478bd9Sstevel@tonic-gate #define ACPI_USE_DO_WHILE_0
51aa2aa9a6SDana Myers #define ACPI_MUTEX_TYPE             ACPI_BINARY_SEMAPHORE
52aa2aa9a6SDana Myers 
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate #ifdef __KERNEL__
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate #include <linux/string.h>
577c478bd9Sstevel@tonic-gate #include <linux/kernel.h>
58aa2aa9a6SDana Myers #include <linux/module.h>
597c478bd9Sstevel@tonic-gate #include <linux/ctype.h>
60aa2aa9a6SDana Myers #include <linux/sched.h>
617c478bd9Sstevel@tonic-gate #include <asm/system.h>
627c478bd9Sstevel@tonic-gate #include <asm/atomic.h>
637c478bd9Sstevel@tonic-gate #include <asm/div64.h>
647c478bd9Sstevel@tonic-gate #include <asm/acpi.h>
65aa2aa9a6SDana Myers #include <linux/slab.h>
66aa2aa9a6SDana Myers #include <linux/spinlock_types.h>
67aa2aa9a6SDana Myers #include <asm/current.h>
687c478bd9Sstevel@tonic-gate 
69aa2aa9a6SDana Myers /* Host-dependent types and defines for in-kernel ACPICA */
70450d6964Smyers 
7127f7c583Smyers #define ACPI_MACHINE_WIDTH          BITS_PER_LONG
72aa2aa9a6SDana Myers #define ACPI_EXPORT_SYMBOL(symbol)  EXPORT_SYMBOL(symbol);
7327f7c583Smyers #define strtoul                     simple_strtoul
74450d6964Smyers 
75aa2aa9a6SDana Myers #define ACPI_CACHE_T                struct kmem_cache
76aa2aa9a6SDana Myers #define ACPI_SPINLOCK               spinlock_t *
77aa2aa9a6SDana Myers #define ACPI_CPU_FLAGS              unsigned long
78aa2aa9a6SDana Myers 
797c478bd9Sstevel@tonic-gate #else /* !__KERNEL__ */
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate #include <stdarg.h>
827c478bd9Sstevel@tonic-gate #include <string.h>
837c478bd9Sstevel@tonic-gate #include <stdlib.h>
847c478bd9Sstevel@tonic-gate #include <ctype.h>
857c478bd9Sstevel@tonic-gate #include <unistd.h>
867c478bd9Sstevel@tonic-gate 
87aa2aa9a6SDana Myers /* Host-dependent types and defines for user-space ACPICA */
88aa2aa9a6SDana Myers 
89aa2aa9a6SDana Myers #define ACPI_FLUSH_CPU_CACHE()
90*26f3cdf0SGordon Ross #define ACPI_CAST_PTHREAD_T(pthread) ((ACPI_THREAD_ID) (pthread))
91aa2aa9a6SDana Myers 
927c478bd9Sstevel@tonic-gate #if defined(__ia64__) || defined(__x86_64__)
937c478bd9Sstevel@tonic-gate #define ACPI_MACHINE_WIDTH          64
947c478bd9Sstevel@tonic-gate #define COMPILER_DEPENDENT_INT64    long
957c478bd9Sstevel@tonic-gate #define COMPILER_DEPENDENT_UINT64   unsigned long
967c478bd9Sstevel@tonic-gate #else
977c478bd9Sstevel@tonic-gate #define ACPI_MACHINE_WIDTH          32
987c478bd9Sstevel@tonic-gate #define COMPILER_DEPENDENT_INT64    long long
997c478bd9Sstevel@tonic-gate #define COMPILER_DEPENDENT_UINT64   unsigned long long
1007c478bd9Sstevel@tonic-gate #define ACPI_USE_NATIVE_DIVIDE
1017c478bd9Sstevel@tonic-gate #endif
1027c478bd9Sstevel@tonic-gate 
103db2bae30SDana Myers #ifndef __cdecl
1047c478bd9Sstevel@tonic-gate #define __cdecl
105db2bae30SDana Myers #endif
106db2bae30SDana Myers 
1077c478bd9Sstevel@tonic-gate #endif /* __KERNEL__ */
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate /* Linux uses GCC */
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate #include "acgcc.h"
1127c478bd9Sstevel@tonic-gate 
113aa2aa9a6SDana Myers 
114aa2aa9a6SDana Myers #ifdef __KERNEL__
115aa2aa9a6SDana Myers /*
116aa2aa9a6SDana Myers  * Overrides for in-kernel ACPICA
117aa2aa9a6SDana Myers  */
118aa2aa9a6SDana Myers static inline acpi_thread_id acpi_os_get_thread_id(void)
119aa2aa9a6SDana Myers {
120aa2aa9a6SDana Myers     return current;
121aa2aa9a6SDana Myers }
122aa2aa9a6SDana Myers 
123aa2aa9a6SDana Myers /*
124aa2aa9a6SDana Myers  * The irqs_disabled() check is for resume from RAM.
125aa2aa9a6SDana Myers  * Interrupts are off during resume, just like they are for boot.
126aa2aa9a6SDana Myers  * However, boot has  (system_state != SYSTEM_RUNNING)
127aa2aa9a6SDana Myers  * to quiet __might_sleep() in kmalloc() and resume does not.
128aa2aa9a6SDana Myers  */
129aa2aa9a6SDana Myers #include <acpi/actypes.h>
130aa2aa9a6SDana Myers static inline void *acpi_os_allocate(acpi_size size)
131aa2aa9a6SDana Myers {
132aa2aa9a6SDana Myers     return kmalloc(size, irqs_disabled() ? GFP_ATOMIC : GFP_KERNEL);
133aa2aa9a6SDana Myers }
134aa2aa9a6SDana Myers 
135aa2aa9a6SDana Myers static inline void *acpi_os_allocate_zeroed(acpi_size size)
136aa2aa9a6SDana Myers {
137aa2aa9a6SDana Myers     return kzalloc(size, irqs_disabled() ? GFP_ATOMIC : GFP_KERNEL);
138aa2aa9a6SDana Myers }
139aa2aa9a6SDana Myers 
140aa2aa9a6SDana Myers static inline void *acpi_os_acquire_object(acpi_cache_t * cache)
141aa2aa9a6SDana Myers {
142aa2aa9a6SDana Myers     return kmem_cache_zalloc(cache,
143aa2aa9a6SDana Myers         irqs_disabled() ? GFP_ATOMIC : GFP_KERNEL);
144aa2aa9a6SDana Myers }
145aa2aa9a6SDana Myers 
146aa2aa9a6SDana Myers #define ACPI_ALLOCATE(a)        acpi_os_allocate(a)
147aa2aa9a6SDana Myers #define ACPI_ALLOCATE_ZEROED(a) acpi_os_allocate_zeroed(a)
148aa2aa9a6SDana Myers #define ACPI_FREE(a)            kfree(a)
149aa2aa9a6SDana Myers 
150aa2aa9a6SDana Myers /* Used within ACPICA to show where it is safe to preempt execution */
151aa2aa9a6SDana Myers 
152aa2aa9a6SDana Myers #define ACPI_PREEMPTION_POINT() \
153aa2aa9a6SDana Myers     do { \
154aa2aa9a6SDana Myers         if (!irqs_disabled()) \
155aa2aa9a6SDana Myers             cond_resched(); \
156aa2aa9a6SDana Myers     } while (0)
157aa2aa9a6SDana Myers 
158aa2aa9a6SDana Myers #endif /* __KERNEL__ */
159aa2aa9a6SDana Myers 
1607c478bd9Sstevel@tonic-gate #endif /* __ACLINUX_H__ */
161