1 /******************************************************************************
3 * Name: aclinux.h - OS specific defines, etc. for Linux
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2014, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
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.
47 /* Common (in-kernel/user-space) ACPICA configuration */
49 #define ACPI_USE_SYSTEM_CLIBRARY
50 #define ACPI_USE_DO_WHILE_0
51 #define ACPI_MUTEX_TYPE ACPI_BINARY_SEMAPHORE
56 #define ACPI_USE_SYSTEM_INTTYPES
58 #include <linux/string.h>
59 #include <linux/kernel.h>
60 #include <linux/ctype.h>
61 #include <linux/sched.h>
62 #include <linux/atomic.h>
63 #include <linux/math64.h>
64 #include <linux/slab.h>
65 #include <linux/spinlock_types.h>
66 #ifdef EXPORT_ACPI_INTERFACES
67 #include <linux/export.h>
73 /* External globals for __KERNEL__, stubs is needed */
75 #define ACPI_GLOBAL(t,a)
76 #define ACPI_INIT_GLOBAL(t,a,b)
78 /* Generating stubs for configurable ACPICA macros */
80 #define ACPI_NO_MEM_ALLOCATIONS
82 /* Generating stubs for configurable ACPICA functions */
84 #define ACPI_NO_ERROR_MESSAGES
85 #undef ACPI_DEBUG_OUTPUT
87 /* External interface for __KERNEL__, stub is needed */
89 #define ACPI_EXTERNAL_RETURN_STATUS(Prototype) \
90 static ACPI_INLINE Prototype {return(AE_NOT_CONFIGURED);}
91 #define ACPI_EXTERNAL_RETURN_OK(Prototype) \
92 static ACPI_INLINE Prototype {return(AE_OK);}
93 #define ACPI_EXTERNAL_RETURN_VOID(Prototype) \
94 static ACPI_INLINE Prototype {return;}
95 #define ACPI_EXTERNAL_RETURN_UINT32(Prototype) \
96 static ACPI_INLINE Prototype {return(0);}
97 #define ACPI_EXTERNAL_RETURN_PTR(Prototype) \
98 static ACPI_INLINE Prototype {return(NULL);}
100 #endif /* CONFIG_ACPI */
102 /* Host-dependent types and defines for in-kernel ACPICA */
104 #define ACPI_MACHINE_WIDTH BITS_PER_LONG
105 #define ACPI_EXPORT_SYMBOL(symbol) EXPORT_SYMBOL(symbol);
106 #define strtoul simple_strtoul
108 #define ACPI_CACHE_T struct kmem_cache
109 #define ACPI_SPINLOCK spinlock_t *
110 #define ACPI_CPU_FLAGS unsigned long
112 #else /* !__KERNEL__ */
120 /* Define/disable kernel-specific declarators */
130 /* Host-dependent types and defines for user-space ACPICA */
132 #define ACPI_FLUSH_CPU_CACHE()
133 #define ACPI_CAST_PTHREAD_T(Pthread) ((ACPI_THREAD_ID) (Pthread))
135 #if defined(__ia64__) || defined(__x86_64__) ||\
136 defined(__aarch64__) || defined(__PPC64__)
137 #define ACPI_MACHINE_WIDTH 64
138 #define COMPILER_DEPENDENT_INT64 long
139 #define COMPILER_DEPENDENT_UINT64 unsigned long
141 #define ACPI_MACHINE_WIDTH 32
142 #define COMPILER_DEPENDENT_INT64 long long
143 #define COMPILER_DEPENDENT_UINT64 unsigned long long
144 #define ACPI_USE_NATIVE_DIVIDE
151 #endif /* __KERNEL__ */
161 * FIXME: Inclusion of actypes.h
162 * Linux kernel need this before defining inline OSL interfaces as
163 * actypes.h need to be included to find ACPICA type definitions.
164 * Since from ACPICA's perspective, the actypes.h should be included after
165 * acenv.h (aclinux.h), this leads to a inclusion mis-ordering issue.
167 #include <acpi/actypes.h>
170 * Overrides for in-kernel ACPICA
172 ACPI_STATUS __init AcpiOsInitialize (
174 #define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsInitialize
176 ACPI_STATUS AcpiOsTerminate (
178 #define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsTerminate
181 * Memory allocation/deallocation
185 * The irqs_disabled() check is for resume from RAM.
186 * Interrupts are off during resume, just like they are for boot.
187 * However, boot has (system_state != SYSTEM_RUNNING)
188 * to quiet __might_sleep() in kmalloc() and resume does not.
194 return kmalloc (Size, irqs_disabled () ? GFP_ATOMIC : GFP_KERNEL);
196 #define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsAllocate
198 /* Use native linux version of AcpiOsAllocateZeroed */
201 AcpiOsAllocateZeroed (
204 return kzalloc (Size, irqs_disabled () ? GFP_ATOMIC : GFP_KERNEL);
206 #define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsAllocateZeroed
207 #define USE_NATIVE_ALLOCATE_ZEROED
215 #define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsFree
218 AcpiOsAcquireObject (
221 return kmem_cache_zalloc (Cache,
222 irqs_disabled () ? GFP_ATOMIC : GFP_KERNEL);
224 #define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsAcquireObject
226 static inline ACPI_THREAD_ID
230 return (ACPI_THREAD_ID) (unsigned long) current;
232 #define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsGetThreadId
234 #ifndef CONFIG_PREEMPT
237 * Used within ACPICA to show where it is safe to preempt execution
238 * when CONFIG_PREEMPT=n
240 #define ACPI_PREEMPTION_POINT() \
242 if (!irqs_disabled()) \
249 * When lockdep is enabled, the spin_lock_init() macro stringifies it's
250 * argument and uses that as a name for the lock in debugging.
251 * By executing spin_lock_init() in a macro the key changes from "lock" for
252 * all locks to the name of the argument of acpi_os_create_lock(), which
253 * prevents lockdep from reporting false positives for ACPICA locks.
255 #define AcpiOsCreateLock(__Handle) \
257 spinlock_t *Lock = ACPI_ALLOCATE(sizeof(*Lock)); \
259 *(__Handle) = Lock; \
260 spin_lock_init(*(__Handle)); \
262 Lock ? AE_OK : AE_NO_MEMORY; \
264 #define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsCreateLock
268 ACPI_PHYSICAL_ADDRESS Where,
270 #define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsMapMemory
274 void __iomem *LogicalAddress,
276 #define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsUnmapMemory
279 * OSL interfaces used by debugger/disassembler
281 #define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsReadable
282 #define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsWritable
285 * OSL interfaces used by utilities
287 #define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsRedirectOutput
288 #define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsGetLine
289 #define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsGetTableByName
290 #define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsGetTableByIndex
291 #define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsGetTableByAddress
292 #define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsOpenDirectory
293 #define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsGetNextFilename
294 #define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsCloseDirectory
297 * OSL interfaces added by Linux
300 EarlyAcpiOsUnmapMemory (
304 #endif /* __KERNEL__ */
306 #endif /* __ACLINUX_H__ */