/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
/******************************************************************************
*
* Name: actypes.h - Common data types for the entire ACPI subsystem
*
* Copyright (C) 2000 - 2019, Intel Corp.
*
*****************************************************************************/
#ifndef __ACTYPES_H__
#define __ACTYPES_H__
/* acpisrc:struct_defs -- for acpisrc conversion */
/*
* ACPI_MACHINE_WIDTH must be specified in an OS- or compiler-dependent
* header and must be either 32 or 64. 16-bit ACPICA is no longer
* supported, as of 12/2006.
*/
#ifndef ACPI_MACHINE_WIDTH
#error ACPI_MACHINE_WIDTH not defined
#endif
/*
* Data type ranges
* Note: These macros are designed to be compiler independent as well as
* working around problems that some 32-bit compilers have with 64-bit
* constants.
*/
#define ACPI_UINT8_MAX (u8) (~((u8) 0)) /* 0xFF */
#define ACPI_UINT16_MAX (u16)(~((u16) 0)) /* 0xFFFF */
#define ACPI_UINT32_MAX (u32)(~((u32) 0)) /* 0xFFFFFFFF */
#define ACPI_UINT64_MAX (u64)(~((u64) 0)) /* 0xFFFFFFFFFFFFFFFF */
#define ACPI_ASCII_MAX 0x7F
/*
* Architecture-specific ACPICA Subsystem Data Types
*
* The goal of these types is to provide source code portability across
* 16-bit, 32-bit, and 64-bit targets.
*
* 1) The following types are of fixed size for all targets (16/32/64):
*
* u8 Logical boolean
*
* u8 8-bit (1 byte) unsigned value
* u16 16-bit (2 byte) unsigned value
* u32 32-bit (4 byte) unsigned value
* u64 64-bit (8 byte) unsigned value
*
* s16 16-bit (2 byte) signed value
* s32 32-bit (4 byte) signed value
* s64 64-bit (8 byte) signed value
*
* COMPILER_DEPENDENT_UINT64/s64 - These types are defined in the
* compiler-dependent header(s) and were introduced because there is no
* common 64-bit integer type across the various compilation models, as
* shown in the table below.
*
* Datatype LP64 ILP64 LLP64 ILP32 LP32 16bit
* char 8 8 8 8 8 8
* short 16 16 16 16 16 16
* _int32 32
* int 32 64 32 32 16 16
* long 64 64 32 32 32 32
* long long 64 64
* pointer 64 64 64 32 32 32
*
* Note: ILP64 and LP32 are currently not supported.
*
*
* 2) These types represent the native word size of the target mode of the
* processor, and may be 16-bit, 32-bit, or 64-bit as required. They are
* usually used for memory allocation, efficient loop counters, and array
* indexes. The types are similar to the size_t type in the C library and
* are required because there is no C type that consistently represents the
* native data width. acpi_size is needed because there is no guarantee
* that a kernel-level C library is present.
*
* acpi_size 16/32/64-bit unsigned value
* acpi_native_int 16/32/64-bit signed value
*/
/*******************************************************************************
*
* Common types for all compilers, all targets
*
******************************************************************************/
#ifndef ACPI_USE_SYSTEM_INTTYPES
typedef unsigned char u8;
typedef unsigned short u16;
typedef short s16;
typedef COMPILER_DEPENDENT_UINT64 u64;
typedef COMPILER_DEPENDENT_INT64 s64;
#endif /* ACPI_USE_SYSTEM_INTTYPES */
/*
* Value returned by acpi_os_get_thread_id. There is no standard "thread_id"
* across operating systems or even the various UNIX systems. Since ACPICA
* only needs the thread ID as a unique thread identifier, we use a u64
* as the only common data type - it will accommodate any type of pointer or
* any type of integer. It is up to the host-dependent OSL to cast the
* native thread ID type to a u64 (in acpi_os_get_thread_id).
*/
#define acpi_thread_id u64
/*******************************************************************************
*
* Types specific to 64-bit targets
*
******************************************************************************/
#if ACPI_MACHINE_WIDTH == 64
#ifndef ACPI_USE_SYSTEM_INTTYPES
typedef unsigned int u32;
typedef int s32;
#endif /* ACPI_USE_SYSTEM_INTTYPES */
typedef s64 acpi_native_int;
typedef u64 acpi_size;
typedef u64 acpi_io_address;
typedef u64 acpi_physical_address;
#define ACPI_MAX_PTR ACPI_UINT64_MAX
#define ACPI_SIZE_MAX ACPI_UINT64_MAX
#define ACPI_USE_NATIVE_DIVIDE /* Has native 64-bit integer support */
#define ACPI_USE_NATIVE_MATH64 /* Has native 64-bit integer support */
/*
* In the case of the Itanium Processor Family (IPF), the hardware does not
* support misaligned memory transfers. Set the MISALIGNMENT_NOT_SUPPORTED
* flag to indicate that special precautions must be taken to avoid alignment
* faults. (IA64 or ia64 is currently used by existing compilers to indicate
* IPF.)
*
* Note: EM64T and other X86-64 processors support misaligned transfers,
* so there is no need to define this flag.
*/
#if defined (__IA64__) || defined (__ia64__)
#define ACPI_MISALIGNMENT_NOT_SUPPORTED
#endif
/*******************************************************************************
*
* Types specific to 32-bit targets
*
******************************************************************************/
#elif ACPI_MACHINE_WIDTH == 32
#ifndef ACPI_USE_SYSTEM_INTTYPES
typedef unsigned int u32;
typedef int s32;
#endif /* ACPI_USE_SYSTEM_INTTYPES */
typedef s32 acpi_native_int;
typedef u32 acpi_size;
#ifdef ACPI_32BIT_PHYSICAL_ADDRESS
/*
* OSPMs can define this to shrink the size of the structures for 32-bit
* none PAE environment. ASL compiler may always define this to generate
* 32-bit OSPM compliant tables.
*/
typedef u32 acpi_io_address;
typedef u32 acpi_physical_address;
#else /* ACPI_32BIT_PHYSICAL_ADDRESS */
/*
* It is reported that, after some calculations, the physical addresses can
* wrap over the 32-bit boundary on 32-bit PAE environment.
* https://bugzilla.kernel.org/show_bug.cgi?id=87971
*/
typedef u64 acpi_io_address;
typedef u64 acpi_physical_address;
#endif /* ACPI_32BIT_PHYSICAL_ADDRESS */
#define ACPI_MAX_PTR ACPI_UINT32_MAX
#define ACPI_SIZE_MAX ACPI_UINT32_MAX
#else
/* ACPI_MACHINE_WIDTH must be either 64 or 32 */
#error unknown ACPI_MACHINE_WIDTH
#endif
/*******************************************************************************
*
* OS-dependent types
*
* If the defau