128c506b8Sjruoho /****************************************************************************** 228c506b8Sjruoho * 328c506b8Sjruoho * Name: aclinux.h - OS specific defines, etc. for Linux 428c506b8Sjruoho * 528c506b8Sjruoho *****************************************************************************/ 628c506b8Sjruoho 7124f4c82Sjruoho /* 8*046a2985Schristos * Copyright (C) 2000 - 2023, Intel Corp. 928c506b8Sjruoho * All rights reserved. 1028c506b8Sjruoho * 11124f4c82Sjruoho * Redistribution and use in source and binary forms, with or without 12124f4c82Sjruoho * modification, are permitted provided that the following conditions 13124f4c82Sjruoho * are met: 14124f4c82Sjruoho * 1. Redistributions of source code must retain the above copyright 15124f4c82Sjruoho * notice, this list of conditions, and the following disclaimer, 16124f4c82Sjruoho * without modification. 17124f4c82Sjruoho * 2. Redistributions in binary form must reproduce at minimum a disclaimer 18124f4c82Sjruoho * substantially similar to the "NO WARRANTY" disclaimer below 19124f4c82Sjruoho * ("Disclaimer") and any redistribution must be conditioned upon 20124f4c82Sjruoho * including a substantially similar Disclaimer requirement for further 21124f4c82Sjruoho * binary redistribution. 22124f4c82Sjruoho * 3. Neither the names of the above-listed copyright holders nor the names 23124f4c82Sjruoho * of any contributors may be used to endorse or promote products derived 24124f4c82Sjruoho * from this software without specific prior written permission. 2528c506b8Sjruoho * 26124f4c82Sjruoho * Alternatively, this software may be distributed under the terms of the 27124f4c82Sjruoho * GNU General Public License ("GPL") version 2 as published by the Free 28124f4c82Sjruoho * Software Foundation. 2928c506b8Sjruoho * 30124f4c82Sjruoho * NO WARRANTY 31124f4c82Sjruoho * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32124f4c82Sjruoho * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 3346a330b4Schristos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 34124f4c82Sjruoho * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35124f4c82Sjruoho * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36124f4c82Sjruoho * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37124f4c82Sjruoho * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38124f4c82Sjruoho * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 39124f4c82Sjruoho * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 40124f4c82Sjruoho * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 41124f4c82Sjruoho * POSSIBILITY OF SUCH DAMAGES. 42124f4c82Sjruoho */ 4328c506b8Sjruoho 4428c506b8Sjruoho #ifndef __ACLINUX_H__ 4528c506b8Sjruoho #define __ACLINUX_H__ 4628c506b8Sjruoho 47460301d4Schristos #ifdef __KERNEL__ 48460301d4Schristos 49460301d4Schristos /* ACPICA external files should not include ACPICA headers directly. */ 50460301d4Schristos 51460301d4Schristos #if !defined(BUILDING_ACPICA) && !defined(_LINUX_ACPI_H) 52460301d4Schristos #error "Please don't include <acpi/acpi.h> directly, include <linux/acpi.h> instead." 53460301d4Schristos #endif 54460301d4Schristos 55460301d4Schristos #endif 56460301d4Schristos 5728c506b8Sjruoho /* Common (in-kernel/user-space) ACPICA configuration */ 5828c506b8Sjruoho 5928c506b8Sjruoho #define ACPI_USE_SYSTEM_CLIBRARY 6028c506b8Sjruoho #define ACPI_USE_DO_WHILE_0 61062782b3Schristos #define ACPI_IGNORE_PACKAGE_RESOLUTION_ERRORS 6228c506b8Sjruoho 6328c506b8Sjruoho 6428c506b8Sjruoho #ifdef __KERNEL__ 6528c506b8Sjruoho 66460301d4Schristos #define ACPI_USE_SYSTEM_INTTYPES 67062782b3Schristos #define ACPI_USE_GPE_POLLING 68460301d4Schristos 6971e38f1dSchristos /* Kernel specific ACPICA configuration */ 70460301d4Schristos 71460301d4Schristos #ifdef CONFIG_ACPI_REDUCED_HARDWARE_ONLY 72460301d4Schristos #define ACPI_REDUCED_HARDWARE 1 73460301d4Schristos #endif 74460301d4Schristos 7571e38f1dSchristos #ifdef CONFIG_ACPI_DEBUGGER 7671e38f1dSchristos #define ACPI_DEBUGGER 7771e38f1dSchristos #endif 7871e38f1dSchristos 790b89cdedSchristos #ifdef CONFIG_ACPI_DEBUG 800b89cdedSchristos #define ACPI_MUTEX_DEBUG 810b89cdedSchristos #endif 820b89cdedSchristos 8328c506b8Sjruoho #include <linux/string.h> 8428c506b8Sjruoho #include <linux/kernel.h> 8528c506b8Sjruoho #include <linux/ctype.h> 8628c506b8Sjruoho #include <linux/sched.h> 87ff4a156dSchristos #include <linux/atomic.h> 88ff4a156dSchristos #include <linux/math64.h> 8928c506b8Sjruoho #include <linux/slab.h> 9028c506b8Sjruoho #include <linux/spinlock_types.h> 91ff4a156dSchristos #ifdef EXPORT_ACPI_INTERFACES 92ff4a156dSchristos #include <linux/export.h> 93ff4a156dSchristos #endif 94460301d4Schristos #ifdef CONFIG_ACPI 95460301d4Schristos #include <asm/acenv.h> 96460301d4Schristos #endif 97460301d4Schristos 98d0e1da26Schristos #define ACPI_INIT_FUNCTION __init 99d0e1da26Schristos 100783af925Schristos /* Use a specific bugging default separate from ACPICA */ 101783af925Schristos 102783af925Schristos #undef ACPI_DEBUG_DEFAULT 103783af925Schristos #define ACPI_DEBUG_DEFAULT (ACPI_LV_INFO | ACPI_LV_REPAIR) 104783af925Schristos 105460301d4Schristos #ifndef CONFIG_ACPI 106460301d4Schristos 107460301d4Schristos /* External globals for __KERNEL__, stubs is needed */ 108460301d4Schristos 109460301d4Schristos #define ACPI_GLOBAL(t,a) 110460301d4Schristos #define ACPI_INIT_GLOBAL(t,a,b) 111460301d4Schristos 112460301d4Schristos /* Generating stubs for configurable ACPICA macros */ 113460301d4Schristos 114460301d4Schristos #define ACPI_NO_MEM_ALLOCATIONS 115460301d4Schristos 116460301d4Schristos /* Generating stubs for configurable ACPICA functions */ 117460301d4Schristos 118460301d4Schristos #define ACPI_NO_ERROR_MESSAGES 119460301d4Schristos #undef ACPI_DEBUG_OUTPUT 120460301d4Schristos 121460301d4Schristos /* External interface for __KERNEL__, stub is needed */ 122460301d4Schristos 123460301d4Schristos #define ACPI_EXTERNAL_RETURN_STATUS(Prototype) \ 124460301d4Schristos static ACPI_INLINE Prototype {return(AE_NOT_CONFIGURED);} 125460301d4Schristos #define ACPI_EXTERNAL_RETURN_OK(Prototype) \ 126460301d4Schristos static ACPI_INLINE Prototype {return(AE_OK);} 127460301d4Schristos #define ACPI_EXTERNAL_RETURN_VOID(Prototype) \ 128460301d4Schristos static ACPI_INLINE Prototype {return;} 129460301d4Schristos #define ACPI_EXTERNAL_RETURN_UINT32(Prototype) \ 130460301d4Schristos static ACPI_INLINE Prototype {return(0);} 131460301d4Schristos #define ACPI_EXTERNAL_RETURN_PTR(Prototype) \ 132460301d4Schristos static ACPI_INLINE Prototype {return(NULL);} 133460301d4Schristos 134460301d4Schristos #endif /* CONFIG_ACPI */ 13528c506b8Sjruoho 13628c506b8Sjruoho /* Host-dependent types and defines for in-kernel ACPICA */ 13728c506b8Sjruoho 13828c506b8Sjruoho #define ACPI_MACHINE_WIDTH BITS_PER_LONG 13989b8eb6cSchristos #define ACPI_USE_NATIVE_MATH64 14028c506b8Sjruoho #define ACPI_EXPORT_SYMBOL(symbol) EXPORT_SYMBOL(symbol); 14128c506b8Sjruoho #define strtoul simple_strtoul 14228c506b8Sjruoho 14328c506b8Sjruoho #define ACPI_CACHE_T struct kmem_cache 14428c506b8Sjruoho #define ACPI_SPINLOCK spinlock_t * 14528c506b8Sjruoho #define ACPI_CPU_FLAGS unsigned long 14628c506b8Sjruoho 1475b139df6Schristos #define ACPI_UINTPTR_T uintptr_t 1485b139df6Schristos 1495b139df6Schristos #define ACPI_TO_INTEGER(p) ((uintptr_t)(p)) 1505b139df6Schristos #define ACPI_OFFSET(d, f) offsetof(d, f) 1515b139df6Schristos 152460301d4Schristos /* Use native linux version of AcpiOsAllocateZeroed */ 15328c506b8Sjruoho 154460301d4Schristos #define USE_NATIVE_ALLOCATE_ZEROED 155ff4a156dSchristos 15628c506b8Sjruoho /* 15728c506b8Sjruoho * Overrides for in-kernel ACPICA 15828c506b8Sjruoho */ 159ff4a156dSchristos #define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsInitialize 160ff4a156dSchristos #define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsTerminate 161ff4a156dSchristos #define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsAllocate 162ff4a156dSchristos #define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsAllocateZeroed 163ff4a156dSchristos #define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsFree 164ff4a156dSchristos #define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsAcquireObject 165ff4a156dSchristos #define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsGetThreadId 166ff4a156dSchristos #define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsCreateLock 167ff4a156dSchristos 168ff4a156dSchristos /* 169ff4a156dSchristos * OSL interfaces used by debugger/disassembler 170ff4a156dSchristos */ 171ff4a156dSchristos #define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsReadable 172ff4a156dSchristos #define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsWritable 1730b89cdedSchristos #define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsInitializeDebugger 1740b89cdedSchristos #define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsTerminateDebugger 175ff4a156dSchristos 176ff4a156dSchristos /* 177ff4a156dSchristos * OSL interfaces used by utilities 178ff4a156dSchristos */ 179ff4a156dSchristos #define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsRedirectOutput 180ff4a156dSchristos #define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsGetTableByName 181ff4a156dSchristos #define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsGetTableByIndex 182ff4a156dSchristos #define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsGetTableByAddress 183ff4a156dSchristos #define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsOpenDirectory 184ff4a156dSchristos #define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsGetNextFilename 185ff4a156dSchristos #define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsCloseDirectory 186ff4a156dSchristos 187ae01e9dcSchristos #define ACPI_MSG_ERROR KERN_ERR "ACPI Error: " 188ae01e9dcSchristos #define ACPI_MSG_EXCEPTION KERN_ERR "ACPI Exception: " 189ae01e9dcSchristos #define ACPI_MSG_WARNING KERN_WARNING "ACPI Warning: " 190ae01e9dcSchristos #define ACPI_MSG_INFO KERN_INFO "ACPI: " 191ae01e9dcSchristos 192ae01e9dcSchristos #define ACPI_MSG_BIOS_ERROR KERN_ERR "ACPI BIOS Error (bug): " 193ae01e9dcSchristos #define ACPI_MSG_BIOS_WARNING KERN_WARNING "ACPI BIOS Warning (bug): " 194ae01e9dcSchristos 19589b8eb6cSchristos /* 19689b8eb6cSchristos * Linux wants to use designated initializers for function pointer structs. 19789b8eb6cSchristos */ 19889b8eb6cSchristos #define ACPI_STRUCT_INIT(field, value) .field = value 19989b8eb6cSchristos 200460301d4Schristos #else /* !__KERNEL__ */ 201ff4a156dSchristos 202d0e1da26Schristos #define ACPI_USE_STANDARD_HEADERS 203d0e1da26Schristos 204d0e1da26Schristos #ifdef ACPI_USE_STANDARD_HEADERS 205*046a2985Schristos #include <stddef.h> 206460301d4Schristos #include <unistd.h> 207*046a2985Schristos #include <stdint.h> 208*046a2985Schristos 209*046a2985Schristos #define ACPI_OFFSET(d, f) offsetof(d, f) 210d0e1da26Schristos #endif 211460301d4Schristos 212460301d4Schristos /* Define/disable kernel-specific declarators */ 213460301d4Schristos 214460301d4Schristos #ifndef __init 215460301d4Schristos #define __init 216460301d4Schristos #endif 2170b89cdedSchristos #ifndef __iomem 2180b89cdedSchristos #define __iomem 2190b89cdedSchristos #endif 220460301d4Schristos 221460301d4Schristos /* Host-dependent types and defines for user-space ACPICA */ 222460301d4Schristos 223460301d4Schristos #define ACPI_FLUSH_CPU_CACHE() 224460301d4Schristos #define ACPI_CAST_PTHREAD_T(Pthread) ((ACPI_THREAD_ID) (Pthread)) 225460301d4Schristos 226062782b3Schristos #if defined(__ia64__) || (defined(__x86_64__) && !defined(__ILP32__)) ||\ 2270b89cdedSchristos defined(__aarch64__) || defined(__PPC64__) ||\ 228*046a2985Schristos defined(__s390x__) || defined(__loongarch__) ||\ 229360a9019Schristos (defined(__riscv) && (defined(__LP64__) || defined(_LP64))) 230460301d4Schristos #define ACPI_MACHINE_WIDTH 64 231460301d4Schristos #define COMPILER_DEPENDENT_INT64 long 232460301d4Schristos #define COMPILER_DEPENDENT_UINT64 unsigned long 233460301d4Schristos #else 234460301d4Schristos #define ACPI_MACHINE_WIDTH 32 235460301d4Schristos #define COMPILER_DEPENDENT_INT64 long long 236460301d4Schristos #define COMPILER_DEPENDENT_UINT64 unsigned long long 237460301d4Schristos #define ACPI_USE_NATIVE_DIVIDE 23889b8eb6cSchristos #define ACPI_USE_NATIVE_MATH64 239460301d4Schristos #endif 240460301d4Schristos 241460301d4Schristos #ifndef __cdecl 242460301d4Schristos #define __cdecl 243460301d4Schristos #endif 244ff4a156dSchristos 24528c506b8Sjruoho #endif /* __KERNEL__ */ 24628c506b8Sjruoho 24728c506b8Sjruoho #endif /* __ACLINUX_H__ */ 248