18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
28c2ecf20Sopenharmony_ci/******************************************************************************
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Name: aclinux.h - OS specific defines, etc. for Linux
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Copyright (C) 2000 - 2020, Intel Corp.
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci *****************************************************************************/
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#ifndef __ACLINUX_H__
118c2ecf20Sopenharmony_ci#define __ACLINUX_H__
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#ifdef __KERNEL__
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci/* ACPICA external files should not include ACPICA headers directly. */
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#if !defined(BUILDING_ACPICA) && !defined(_LINUX_ACPI_H)
188c2ecf20Sopenharmony_ci#error "Please don't include <acpi/acpi.h> directly, include <linux/acpi.h> instead."
198c2ecf20Sopenharmony_ci#endif
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#endif
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci/* Common (in-kernel/user-space) ACPICA configuration */
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci#define ACPI_USE_SYSTEM_CLIBRARY
268c2ecf20Sopenharmony_ci#define ACPI_USE_DO_WHILE_0
278c2ecf20Sopenharmony_ci#define ACPI_IGNORE_PACKAGE_RESOLUTION_ERRORS
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci#ifdef __KERNEL__
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci#define ACPI_USE_SYSTEM_INTTYPES
328c2ecf20Sopenharmony_ci#define ACPI_USE_GPE_POLLING
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci/* Kernel specific ACPICA configuration */
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci#ifdef CONFIG_PCI
378c2ecf20Sopenharmony_ci#define ACPI_PCI_CONFIGURED
388c2ecf20Sopenharmony_ci#endif
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci#ifdef CONFIG_ACPI_REDUCED_HARDWARE_ONLY
418c2ecf20Sopenharmony_ci#define ACPI_REDUCED_HARDWARE 1
428c2ecf20Sopenharmony_ci#endif
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci#ifdef CONFIG_ACPI_DEBUGGER
458c2ecf20Sopenharmony_ci#define ACPI_DEBUGGER
468c2ecf20Sopenharmony_ci#endif
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci#ifdef CONFIG_ACPI_DEBUG
498c2ecf20Sopenharmony_ci#define ACPI_MUTEX_DEBUG
508c2ecf20Sopenharmony_ci#endif
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci#include <linux/string.h>
538c2ecf20Sopenharmony_ci#include <linux/kernel.h>
548c2ecf20Sopenharmony_ci#include <linux/ctype.h>
558c2ecf20Sopenharmony_ci#include <linux/sched.h>
568c2ecf20Sopenharmony_ci#include <linux/atomic.h>
578c2ecf20Sopenharmony_ci#include <linux/math64.h>
588c2ecf20Sopenharmony_ci#include <linux/slab.h>
598c2ecf20Sopenharmony_ci#include <linux/spinlock_types.h>
608c2ecf20Sopenharmony_ci#ifdef EXPORT_ACPI_INTERFACES
618c2ecf20Sopenharmony_ci#include <linux/export.h>
628c2ecf20Sopenharmony_ci#endif
638c2ecf20Sopenharmony_ci#ifdef CONFIG_ACPI
648c2ecf20Sopenharmony_ci#include <asm/acenv.h>
658c2ecf20Sopenharmony_ci#endif
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci#define ACPI_INIT_FUNCTION __init
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci/* Use a specific bugging default separate from ACPICA */
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci#undef ACPI_DEBUG_DEFAULT
728c2ecf20Sopenharmony_ci#define ACPI_DEBUG_DEFAULT          (ACPI_LV_INFO | ACPI_LV_REPAIR)
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci#ifndef CONFIG_ACPI
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci/* External globals for __KERNEL__, stubs is needed */
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci#define ACPI_GLOBAL(t,a)
798c2ecf20Sopenharmony_ci#define ACPI_INIT_GLOBAL(t,a,b)
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci/* Generating stubs for configurable ACPICA macros */
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci#define ACPI_NO_MEM_ALLOCATIONS
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ci/* Generating stubs for configurable ACPICA functions */
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci#define ACPI_NO_ERROR_MESSAGES
888c2ecf20Sopenharmony_ci#undef ACPI_DEBUG_OUTPUT
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci/* External interface for __KERNEL__, stub is needed */
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci#define ACPI_EXTERNAL_RETURN_STATUS(prototype) \
938c2ecf20Sopenharmony_ci	static ACPI_INLINE prototype {return(AE_NOT_CONFIGURED);}
948c2ecf20Sopenharmony_ci#define ACPI_EXTERNAL_RETURN_OK(prototype) \
958c2ecf20Sopenharmony_ci	static ACPI_INLINE prototype {return(AE_OK);}
968c2ecf20Sopenharmony_ci#define ACPI_EXTERNAL_RETURN_VOID(prototype) \
978c2ecf20Sopenharmony_ci	static ACPI_INLINE prototype {return;}
988c2ecf20Sopenharmony_ci#define ACPI_EXTERNAL_RETURN_UINT32(prototype) \
998c2ecf20Sopenharmony_ci	static ACPI_INLINE prototype {return(0);}
1008c2ecf20Sopenharmony_ci#define ACPI_EXTERNAL_RETURN_PTR(prototype) \
1018c2ecf20Sopenharmony_ci	static ACPI_INLINE prototype {return(NULL);}
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci#endif				/* CONFIG_ACPI */
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci/* Host-dependent types and defines for in-kernel ACPICA */
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci#define ACPI_MACHINE_WIDTH          BITS_PER_LONG
1088c2ecf20Sopenharmony_ci#define ACPI_USE_NATIVE_MATH64
1098c2ecf20Sopenharmony_ci#define ACPI_EXPORT_SYMBOL(symbol)  EXPORT_SYMBOL(symbol);
1108c2ecf20Sopenharmony_ci#define strtoul                     simple_strtoul
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci#define acpi_cache_t                        struct kmem_cache
1138c2ecf20Sopenharmony_ci#define acpi_spinlock                       spinlock_t *
1148c2ecf20Sopenharmony_ci#define acpi_raw_spinlock                   raw_spinlock_t *
1158c2ecf20Sopenharmony_ci#define acpi_cpu_flags                      unsigned long
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci/* Use native linux version of acpi_os_allocate_zeroed */
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ci#define USE_NATIVE_ALLOCATE_ZEROED
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_ci/* Use logical addresses for accessing GPE registers in system memory */
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ci#define ACPI_GPE_USE_LOGICAL_ADDRESSES
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_ci/*
1268c2ecf20Sopenharmony_ci * Overrides for in-kernel ACPICA
1278c2ecf20Sopenharmony_ci */
1288c2ecf20Sopenharmony_ci#define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_initialize
1298c2ecf20Sopenharmony_ci#define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_terminate
1308c2ecf20Sopenharmony_ci#define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_allocate
1318c2ecf20Sopenharmony_ci#define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_allocate_zeroed
1328c2ecf20Sopenharmony_ci#define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_free
1338c2ecf20Sopenharmony_ci#define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_acquire_object
1348c2ecf20Sopenharmony_ci#define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_get_thread_id
1358c2ecf20Sopenharmony_ci#define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_create_lock
1368c2ecf20Sopenharmony_ci#define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_create_raw_lock
1378c2ecf20Sopenharmony_ci#define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_delete_raw_lock
1388c2ecf20Sopenharmony_ci#define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_acquire_raw_lock
1398c2ecf20Sopenharmony_ci#define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_release_raw_lock
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci/*
1428c2ecf20Sopenharmony_ci * OSL interfaces used by debugger/disassembler
1438c2ecf20Sopenharmony_ci */
1448c2ecf20Sopenharmony_ci#define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_readable
1458c2ecf20Sopenharmony_ci#define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_writable
1468c2ecf20Sopenharmony_ci#define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_initialize_debugger
1478c2ecf20Sopenharmony_ci#define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_terminate_debugger
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_ci/*
1508c2ecf20Sopenharmony_ci * OSL interfaces used by utilities
1518c2ecf20Sopenharmony_ci */
1528c2ecf20Sopenharmony_ci#define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_redirect_output
1538c2ecf20Sopenharmony_ci#define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_get_table_by_name
1548c2ecf20Sopenharmony_ci#define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_get_table_by_index
1558c2ecf20Sopenharmony_ci#define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_get_table_by_address
1568c2ecf20Sopenharmony_ci#define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_open_directory
1578c2ecf20Sopenharmony_ci#define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_get_next_filename
1588c2ecf20Sopenharmony_ci#define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_close_directory
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ci#define ACPI_MSG_ERROR          KERN_ERR "ACPI Error: "
1618c2ecf20Sopenharmony_ci#define ACPI_MSG_EXCEPTION      KERN_ERR "ACPI Exception: "
1628c2ecf20Sopenharmony_ci#define ACPI_MSG_WARNING        KERN_WARNING "ACPI Warning: "
1638c2ecf20Sopenharmony_ci#define ACPI_MSG_INFO           KERN_INFO "ACPI: "
1648c2ecf20Sopenharmony_ci
1658c2ecf20Sopenharmony_ci#define ACPI_MSG_BIOS_ERROR     KERN_ERR "ACPI BIOS Error (bug): "
1668c2ecf20Sopenharmony_ci#define ACPI_MSG_BIOS_WARNING   KERN_WARNING "ACPI BIOS Warning (bug): "
1678c2ecf20Sopenharmony_ci
1688c2ecf20Sopenharmony_ci/*
1698c2ecf20Sopenharmony_ci * Linux wants to use designated initializers for function pointer structs.
1708c2ecf20Sopenharmony_ci */
1718c2ecf20Sopenharmony_ci#define ACPI_STRUCT_INIT(field, value)	.field = value
1728c2ecf20Sopenharmony_ci
1738c2ecf20Sopenharmony_ci#else				/* !__KERNEL__ */
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_ci#define ACPI_USE_STANDARD_HEADERS
1768c2ecf20Sopenharmony_ci
1778c2ecf20Sopenharmony_ci#ifdef ACPI_USE_STANDARD_HEADERS
1788c2ecf20Sopenharmony_ci#include <unistd.h>
1798c2ecf20Sopenharmony_ci#endif
1808c2ecf20Sopenharmony_ci
1818c2ecf20Sopenharmony_ci/* Define/disable kernel-specific declarators */
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_ci#ifndef __init
1848c2ecf20Sopenharmony_ci#define __init
1858c2ecf20Sopenharmony_ci#endif
1868c2ecf20Sopenharmony_ci#ifndef __iomem
1878c2ecf20Sopenharmony_ci#define __iomem
1888c2ecf20Sopenharmony_ci#endif
1898c2ecf20Sopenharmony_ci
1908c2ecf20Sopenharmony_ci/* Host-dependent types and defines for user-space ACPICA */
1918c2ecf20Sopenharmony_ci
1928c2ecf20Sopenharmony_ci#define ACPI_FLUSH_CPU_CACHE()
1938c2ecf20Sopenharmony_ci#define ACPI_CAST_PTHREAD_T(pthread) ((acpi_thread_id) (pthread))
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_ci#if defined(__ia64__)    || (defined(__x86_64__) && !defined(__ILP32__)) ||\
1968c2ecf20Sopenharmony_ci	defined(__aarch64__) || defined(__PPC64__) ||\
1978c2ecf20Sopenharmony_ci	defined(__s390x__) || defined(__loongarch__) ||\
1988c2ecf20Sopenharmony_ci	(defined(__riscv) && (defined(__LP64__) || defined(_LP64)))
1998c2ecf20Sopenharmony_ci#define ACPI_MACHINE_WIDTH          64
2008c2ecf20Sopenharmony_ci#define COMPILER_DEPENDENT_INT64    long
2018c2ecf20Sopenharmony_ci#define COMPILER_DEPENDENT_UINT64   unsigned long
2028c2ecf20Sopenharmony_ci#else
2038c2ecf20Sopenharmony_ci#define ACPI_MACHINE_WIDTH          32
2048c2ecf20Sopenharmony_ci#define COMPILER_DEPENDENT_INT64    long long
2058c2ecf20Sopenharmony_ci#define COMPILER_DEPENDENT_UINT64   unsigned long long
2068c2ecf20Sopenharmony_ci#define ACPI_USE_NATIVE_DIVIDE
2078c2ecf20Sopenharmony_ci#define ACPI_USE_NATIVE_MATH64
2088c2ecf20Sopenharmony_ci#endif
2098c2ecf20Sopenharmony_ci
2108c2ecf20Sopenharmony_ci#ifndef __cdecl
2118c2ecf20Sopenharmony_ci#define __cdecl
2128c2ecf20Sopenharmony_ci#endif
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_ci#endif				/* __KERNEL__ */
2158c2ecf20Sopenharmony_ci
2168c2ecf20Sopenharmony_ci#endif				/* __ACLINUX_H__ */
217