162306a36Sopenharmony_ci/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ 262306a36Sopenharmony_ci/****************************************************************************** 362306a36Sopenharmony_ci * 462306a36Sopenharmony_ci * Name: aclinux.h - OS specific defines, etc. for Linux 562306a36Sopenharmony_ci * 662306a36Sopenharmony_ci * Copyright (C) 2000 - 2023, Intel Corp. 762306a36Sopenharmony_ci * 862306a36Sopenharmony_ci *****************************************************************************/ 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci#ifndef __ACLINUX_H__ 1162306a36Sopenharmony_ci#define __ACLINUX_H__ 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ci#ifdef __KERNEL__ 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ci/* ACPICA external files should not include ACPICA headers directly. */ 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_ci#if !defined(BUILDING_ACPICA) && !defined(_LINUX_ACPI_H) 1862306a36Sopenharmony_ci#error "Please don't include <acpi/acpi.h> directly, include <linux/acpi.h> instead." 1962306a36Sopenharmony_ci#endif 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ci#endif 2262306a36Sopenharmony_ci 2362306a36Sopenharmony_ci/* Common (in-kernel/user-space) ACPICA configuration */ 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_ci#define ACPI_USE_SYSTEM_CLIBRARY 2662306a36Sopenharmony_ci#define ACPI_USE_DO_WHILE_0 2762306a36Sopenharmony_ci#define ACPI_IGNORE_PACKAGE_RESOLUTION_ERRORS 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_ci#ifdef __KERNEL__ 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ci#define ACPI_USE_SYSTEM_INTTYPES 3262306a36Sopenharmony_ci#define ACPI_USE_GPE_POLLING 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_ci/* Kernel specific ACPICA configuration */ 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_ci#ifdef CONFIG_PCI 3762306a36Sopenharmony_ci#define ACPI_PCI_CONFIGURED 3862306a36Sopenharmony_ci#endif 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_ci#ifdef CONFIG_ACPI_REDUCED_HARDWARE_ONLY 4162306a36Sopenharmony_ci#define ACPI_REDUCED_HARDWARE 1 4262306a36Sopenharmony_ci#endif 4362306a36Sopenharmony_ci 4462306a36Sopenharmony_ci#ifdef CONFIG_ACPI_DEBUGGER 4562306a36Sopenharmony_ci#define ACPI_DEBUGGER 4662306a36Sopenharmony_ci#endif 4762306a36Sopenharmony_ci 4862306a36Sopenharmony_ci#ifdef CONFIG_ACPI_DEBUG 4962306a36Sopenharmony_ci#define ACPI_MUTEX_DEBUG 5062306a36Sopenharmony_ci#endif 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ci#include <linux/string.h> 5362306a36Sopenharmony_ci#include <linux/kernel.h> 5462306a36Sopenharmony_ci#include <linux/ctype.h> 5562306a36Sopenharmony_ci#include <linux/sched.h> 5662306a36Sopenharmony_ci#include <linux/atomic.h> 5762306a36Sopenharmony_ci#include <linux/math64.h> 5862306a36Sopenharmony_ci#include <linux/slab.h> 5962306a36Sopenharmony_ci#include <linux/spinlock_types.h> 6062306a36Sopenharmony_ci#ifdef EXPORT_ACPI_INTERFACES 6162306a36Sopenharmony_ci#include <linux/export.h> 6262306a36Sopenharmony_ci#endif 6362306a36Sopenharmony_ci#ifdef CONFIG_ACPI 6462306a36Sopenharmony_ci#include <asm/acenv.h> 6562306a36Sopenharmony_ci#endif 6662306a36Sopenharmony_ci 6762306a36Sopenharmony_ci#define ACPI_INIT_FUNCTION __init 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_ci/* Use a specific bugging default separate from ACPICA */ 7062306a36Sopenharmony_ci 7162306a36Sopenharmony_ci#undef ACPI_DEBUG_DEFAULT 7262306a36Sopenharmony_ci#define ACPI_DEBUG_DEFAULT (ACPI_LV_INFO | ACPI_LV_REPAIR) 7362306a36Sopenharmony_ci 7462306a36Sopenharmony_ci#ifndef CONFIG_ACPI 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_ci/* External globals for __KERNEL__, stubs is needed */ 7762306a36Sopenharmony_ci 7862306a36Sopenharmony_ci#define ACPI_GLOBAL(t,a) 7962306a36Sopenharmony_ci#define ACPI_INIT_GLOBAL(t,a,b) 8062306a36Sopenharmony_ci 8162306a36Sopenharmony_ci/* Generating stubs for configurable ACPICA macros */ 8262306a36Sopenharmony_ci 8362306a36Sopenharmony_ci#define ACPI_NO_MEM_ALLOCATIONS 8462306a36Sopenharmony_ci 8562306a36Sopenharmony_ci/* Generating stubs for configurable ACPICA functions */ 8662306a36Sopenharmony_ci 8762306a36Sopenharmony_ci#define ACPI_NO_ERROR_MESSAGES 8862306a36Sopenharmony_ci#undef ACPI_DEBUG_OUTPUT 8962306a36Sopenharmony_ci 9062306a36Sopenharmony_ci/* External interface for __KERNEL__, stub is needed */ 9162306a36Sopenharmony_ci 9262306a36Sopenharmony_ci#define ACPI_EXTERNAL_RETURN_STATUS(prototype) \ 9362306a36Sopenharmony_ci static ACPI_INLINE prototype {return(AE_NOT_CONFIGURED);} 9462306a36Sopenharmony_ci#define ACPI_EXTERNAL_RETURN_OK(prototype) \ 9562306a36Sopenharmony_ci static ACPI_INLINE prototype {return(AE_OK);} 9662306a36Sopenharmony_ci#define ACPI_EXTERNAL_RETURN_VOID(prototype) \ 9762306a36Sopenharmony_ci static ACPI_INLINE prototype {return;} 9862306a36Sopenharmony_ci#define ACPI_EXTERNAL_RETURN_UINT32(prototype) \ 9962306a36Sopenharmony_ci static ACPI_INLINE prototype {return(0);} 10062306a36Sopenharmony_ci#define ACPI_EXTERNAL_RETURN_PTR(prototype) \ 10162306a36Sopenharmony_ci static ACPI_INLINE prototype {return(NULL);} 10262306a36Sopenharmony_ci 10362306a36Sopenharmony_ci#endif /* CONFIG_ACPI */ 10462306a36Sopenharmony_ci 10562306a36Sopenharmony_ci/* Host-dependent types and defines for in-kernel ACPICA */ 10662306a36Sopenharmony_ci 10762306a36Sopenharmony_ci#define ACPI_MACHINE_WIDTH BITS_PER_LONG 10862306a36Sopenharmony_ci#define ACPI_USE_NATIVE_MATH64 10962306a36Sopenharmony_ci#define ACPI_EXPORT_SYMBOL(symbol) EXPORT_SYMBOL(symbol); 11062306a36Sopenharmony_ci#define strtoul simple_strtoul 11162306a36Sopenharmony_ci 11262306a36Sopenharmony_ci#define acpi_cache_t struct kmem_cache 11362306a36Sopenharmony_ci#define acpi_spinlock spinlock_t * 11462306a36Sopenharmony_ci#define acpi_raw_spinlock raw_spinlock_t * 11562306a36Sopenharmony_ci#define acpi_cpu_flags unsigned long 11662306a36Sopenharmony_ci 11762306a36Sopenharmony_ci#define acpi_uintptr_t uintptr_t 11862306a36Sopenharmony_ci 11962306a36Sopenharmony_ci#define ACPI_TO_INTEGER(p) ((uintptr_t)(p)) 12062306a36Sopenharmony_ci#define ACPI_OFFSET(d, f) offsetof(d, f) 12162306a36Sopenharmony_ci 12262306a36Sopenharmony_ci/* Use native linux version of acpi_os_allocate_zeroed */ 12362306a36Sopenharmony_ci 12462306a36Sopenharmony_ci#define USE_NATIVE_ALLOCATE_ZEROED 12562306a36Sopenharmony_ci 12662306a36Sopenharmony_ci/* Use logical addresses for accessing GPE registers in system memory */ 12762306a36Sopenharmony_ci 12862306a36Sopenharmony_ci#define ACPI_GPE_USE_LOGICAL_ADDRESSES 12962306a36Sopenharmony_ci 13062306a36Sopenharmony_ci/* 13162306a36Sopenharmony_ci * Overrides for in-kernel ACPICA 13262306a36Sopenharmony_ci */ 13362306a36Sopenharmony_ci#define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_initialize 13462306a36Sopenharmony_ci#define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_terminate 13562306a36Sopenharmony_ci#define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_allocate 13662306a36Sopenharmony_ci#define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_allocate_zeroed 13762306a36Sopenharmony_ci#define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_free 13862306a36Sopenharmony_ci#define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_acquire_object 13962306a36Sopenharmony_ci#define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_get_thread_id 14062306a36Sopenharmony_ci#define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_create_lock 14162306a36Sopenharmony_ci#define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_create_raw_lock 14262306a36Sopenharmony_ci#define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_delete_raw_lock 14362306a36Sopenharmony_ci#define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_acquire_raw_lock 14462306a36Sopenharmony_ci#define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_release_raw_lock 14562306a36Sopenharmony_ci 14662306a36Sopenharmony_ci/* 14762306a36Sopenharmony_ci * OSL interfaces used by debugger/disassembler 14862306a36Sopenharmony_ci */ 14962306a36Sopenharmony_ci#define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_readable 15062306a36Sopenharmony_ci#define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_writable 15162306a36Sopenharmony_ci#define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_initialize_debugger 15262306a36Sopenharmony_ci#define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_terminate_debugger 15362306a36Sopenharmony_ci 15462306a36Sopenharmony_ci/* 15562306a36Sopenharmony_ci * OSL interfaces used by utilities 15662306a36Sopenharmony_ci */ 15762306a36Sopenharmony_ci#define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_redirect_output 15862306a36Sopenharmony_ci#define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_get_table_by_name 15962306a36Sopenharmony_ci#define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_get_table_by_index 16062306a36Sopenharmony_ci#define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_get_table_by_address 16162306a36Sopenharmony_ci#define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_open_directory 16262306a36Sopenharmony_ci#define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_get_next_filename 16362306a36Sopenharmony_ci#define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_close_directory 16462306a36Sopenharmony_ci 16562306a36Sopenharmony_ci#define ACPI_MSG_ERROR KERN_ERR "ACPI Error: " 16662306a36Sopenharmony_ci#define ACPI_MSG_EXCEPTION KERN_ERR "ACPI Exception: " 16762306a36Sopenharmony_ci#define ACPI_MSG_WARNING KERN_WARNING "ACPI Warning: " 16862306a36Sopenharmony_ci#define ACPI_MSG_INFO KERN_INFO "ACPI: " 16962306a36Sopenharmony_ci 17062306a36Sopenharmony_ci#define ACPI_MSG_BIOS_ERROR KERN_ERR "ACPI BIOS Error (bug): " 17162306a36Sopenharmony_ci#define ACPI_MSG_BIOS_WARNING KERN_WARNING "ACPI BIOS Warning (bug): " 17262306a36Sopenharmony_ci 17362306a36Sopenharmony_ci/* 17462306a36Sopenharmony_ci * Linux wants to use designated initializers for function pointer structs. 17562306a36Sopenharmony_ci */ 17662306a36Sopenharmony_ci#define ACPI_STRUCT_INIT(field, value) .field = value 17762306a36Sopenharmony_ci 17862306a36Sopenharmony_ci#else /* !__KERNEL__ */ 17962306a36Sopenharmony_ci 18062306a36Sopenharmony_ci#define ACPI_USE_STANDARD_HEADERS 18162306a36Sopenharmony_ci 18262306a36Sopenharmony_ci#ifdef ACPI_USE_STANDARD_HEADERS 18362306a36Sopenharmony_ci#include <stddef.h> 18462306a36Sopenharmony_ci#include <unistd.h> 18562306a36Sopenharmony_ci#include <stdint.h> 18662306a36Sopenharmony_ci 18762306a36Sopenharmony_ci#define ACPI_OFFSET(d, f) offsetof(d, f) 18862306a36Sopenharmony_ci#endif 18962306a36Sopenharmony_ci 19062306a36Sopenharmony_ci/* Define/disable kernel-specific declarators */ 19162306a36Sopenharmony_ci 19262306a36Sopenharmony_ci#ifndef __init 19362306a36Sopenharmony_ci#define __init 19462306a36Sopenharmony_ci#endif 19562306a36Sopenharmony_ci#ifndef __iomem 19662306a36Sopenharmony_ci#define __iomem 19762306a36Sopenharmony_ci#endif 19862306a36Sopenharmony_ci 19962306a36Sopenharmony_ci/* Host-dependent types and defines for user-space ACPICA */ 20062306a36Sopenharmony_ci 20162306a36Sopenharmony_ci#define ACPI_FLUSH_CPU_CACHE() 20262306a36Sopenharmony_ci#define ACPI_CAST_PTHREAD_T(pthread) ((acpi_thread_id) (pthread)) 20362306a36Sopenharmony_ci 20462306a36Sopenharmony_ci#if defined(__ia64__) || (defined(__x86_64__) && !defined(__ILP32__)) ||\ 20562306a36Sopenharmony_ci defined(__aarch64__) || defined(__PPC64__) ||\ 20662306a36Sopenharmony_ci defined(__s390x__) || defined(__loongarch__) ||\ 20762306a36Sopenharmony_ci (defined(__riscv) && (defined(__LP64__) || defined(_LP64))) 20862306a36Sopenharmony_ci#define ACPI_MACHINE_WIDTH 64 20962306a36Sopenharmony_ci#define COMPILER_DEPENDENT_INT64 long 21062306a36Sopenharmony_ci#define COMPILER_DEPENDENT_UINT64 unsigned long 21162306a36Sopenharmony_ci#else 21262306a36Sopenharmony_ci#define ACPI_MACHINE_WIDTH 32 21362306a36Sopenharmony_ci#define COMPILER_DEPENDENT_INT64 long long 21462306a36Sopenharmony_ci#define COMPILER_DEPENDENT_UINT64 unsigned long long 21562306a36Sopenharmony_ci#define ACPI_USE_NATIVE_DIVIDE 21662306a36Sopenharmony_ci#define ACPI_USE_NATIVE_MATH64 21762306a36Sopenharmony_ci#endif 21862306a36Sopenharmony_ci 21962306a36Sopenharmony_ci#ifndef __cdecl 22062306a36Sopenharmony_ci#define __cdecl 22162306a36Sopenharmony_ci#endif 22262306a36Sopenharmony_ci 22362306a36Sopenharmony_ci#endif /* __KERNEL__ */ 22462306a36Sopenharmony_ci 22562306a36Sopenharmony_ci#endif /* __ACLINUX_H__ */ 226