1 /****************************************************************************** 2 * 3 * Name: aclinux.h - OS specific defines, etc. for Linux 4 * 5 *****************************************************************************/ 6 7 /* 8 * Copyright (C) 2000 - 2014, 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 __ACLINUX_H__ 45 #define __ACLINUX_H__ 46 47 /* Common (in-kernel/user-space) ACPICA configuration */ 48 49 #define ACPI_USE_SYSTEM_CLIBRARY 50 #define ACPI_USE_DO_WHILE_0 51 #define ACPI_MUTEX_TYPE ACPI_BINARY_SEMAPHORE 52 53 54 #ifdef __KERNEL__ 55 56 #define ACPI_USE_SYSTEM_INTTYPES 57 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> 68 #endif 69 #include <asm/acpi.h> 70 71 #ifndef CONFIG_ACPI 72 73 /* External globals for __KERNEL__, stubs is needed */ 74 75 #define ACPI_GLOBAL(t,a) 76 #define ACPI_INIT_GLOBAL(t,a,b) 77 78 /* Generating stubs for configurable ACPICA macros */ 79 80 #define ACPI_NO_MEM_ALLOCATIONS 81 82 /* Generating stubs for configurable ACPICA functions */ 83 84 #define ACPI_NO_ERROR_MESSAGES 85 #undef ACPI_DEBUG_OUTPUT 86 87 /* External interface for __KERNEL__, stub is needed */ 88 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);} 99 100 #endif /* CONFIG_ACPI */ 101 102 /* Host-dependent types and defines for in-kernel ACPICA */ 103 104 #define ACPI_MACHINE_WIDTH BITS_PER_LONG 105 #define ACPI_EXPORT_SYMBOL(symbol) EXPORT_SYMBOL(symbol); 106 #define strtoul simple_strtoul 107 108 #define ACPI_CACHE_T struct kmem_cache 109 #define ACPI_SPINLOCK spinlock_t * 110 #define ACPI_CPU_FLAGS unsigned long 111 112 #else /* !__KERNEL__ */ 113 114 #include <stdarg.h> 115 #include <string.h> 116 #include <stdlib.h> 117 #include <ctype.h> 118 #include <unistd.h> 119 120 /* Define/disable kernel-specific declarators */ 121 122 #ifndef __init 123 #define __init 124 #endif 125 126 #ifndef __iomem 127 #define __iomem 128 #endif 129 130 /* Host-dependent types and defines for user-space ACPICA */ 131 132 #define ACPI_FLUSH_CPU_CACHE() 133 #define ACPI_CAST_PTHREAD_T(Pthread) ((ACPI_THREAD_ID) (Pthread)) 134 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 140 #else 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 145 #endif 146 147 #ifndef __cdecl 148 #define __cdecl 149 #endif 150 151 #endif /* __KERNEL__ */ 152 153 /* Linux uses GCC */ 154 155 #include "acgcc.h" 156 157 158 #ifdef __KERNEL__ 159 160 /* 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. 166 */ 167 #include <acpi/actypes.h> 168 169 /* 170 * Overrides for in-kernel ACPICA 171 */ 172 ACPI_STATUS __init AcpiOsInitialize ( 173 void); 174 #define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsInitialize 175 176 ACPI_STATUS AcpiOsTerminate ( 177 void); 178 #define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsTerminate 179 180 /* 181 * Memory allocation/deallocation 182 */ 183 184 /* 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. 189 */ 190 static inline void * 191 AcpiOsAllocate ( 192 ACPI_SIZE Size) 193 { 194 return kmalloc (Size, irqs_disabled () ? GFP_ATOMIC : GFP_KERNEL); 195 } 196 #define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsAllocate 197 198 /* Use native linux version of AcpiOsAllocateZeroed */ 199 200 static inline void * 201 AcpiOsAllocateZeroed ( 202 ACPI_SIZE Size) 203 { 204 return kzalloc (Size, irqs_disabled () ? GFP_ATOMIC : GFP_KERNEL); 205 } 206 #define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsAllocateZeroed 207 #define USE_NATIVE_ALLOCATE_ZEROED 208 209 static inline void 210 AcpiOsFree ( 211 void *Memory) 212 { 213 kfree (Memory); 214 } 215 #define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsFree 216 217 static inline void * 218 AcpiOsAcquireObject ( 219 ACPI_CACHE_T *Cache) 220 { 221 return kmem_cache_zalloc (Cache, 222 irqs_disabled () ? GFP_ATOMIC : GFP_KERNEL); 223 } 224 #define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsAcquireObject 225 226 static inline ACPI_THREAD_ID 227 AcpiOsGetThreadId ( 228 void) 229 { 230 return (ACPI_THREAD_ID) (unsigned long) current; 231 } 232 #define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsGetThreadId 233 234 #ifndef CONFIG_PREEMPT 235 236 /* 237 * Used within ACPICA to show where it is safe to preempt execution 238 * when CONFIG_PREEMPT=n 239 */ 240 #define ACPI_PREEMPTION_POINT() \ 241 do { \ 242 if (!irqs_disabled()) \ 243 cond_resched(); \ 244 } while (0) 245 246 #endif 247 248 /* 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. 254 */ 255 #define AcpiOsCreateLock(__Handle) \ 256 ({ \ 257 spinlock_t *Lock = ACPI_ALLOCATE(sizeof(*Lock)); \ 258 if (Lock) { \ 259 *(__Handle) = Lock; \ 260 spin_lock_init(*(__Handle)); \ 261 } \ 262 Lock ? AE_OK : AE_NO_MEMORY; \ 263 }) 264 #define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsCreateLock 265 266 void __iomem * 267 AcpiOsMapMemory ( 268 ACPI_PHYSICAL_ADDRESS Where, 269 ACPI_SIZE Length); 270 #define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsMapMemory 271 272 void 273 AcpiOsUnmapMemory ( 274 void __iomem *LogicalAddress, 275 ACPI_SIZE Size); 276 #define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsUnmapMemory 277 278 /* 279 * OSL interfaces used by debugger/disassembler 280 */ 281 #define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsReadable 282 #define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsWritable 283 284 /* 285 * OSL interfaces used by utilities 286 */ 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 295 296 /* 297 * OSL interfaces added by Linux 298 */ 299 void 300 EarlyAcpiOsUnmapMemory ( 301 void __iomem *Virt, 302 ACPI_SIZE Size); 303 304 #endif /* __KERNEL__ */ 305 306 #endif /* __ACLINUX_H__ */ 307