linux/drivers/acpi/acpica/acmacros.h

/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
/******************************************************************************
 *
 * Name: acmacros.h - C macros for the entire subsystem.
 *
 * Copyright (C) 2000 - 2023, Intel Corp.
 *
 *****************************************************************************/

#ifndef __ACMACROS_H__
#define __ACMACROS_H__

/*
 * Extract data using a pointer. Any more than a byte and we
 * get into potential alignment issues -- see the STORE macros below.
 * Use with care.
 */
#define ACPI_CAST8(ptr)
#define ACPI_CAST16(ptr)
#define ACPI_CAST32(ptr)
#define ACPI_CAST64(ptr)
#define ACPI_GET8(ptr)
#define ACPI_GET16(ptr)
#define ACPI_GET32(ptr)
#define ACPI_GET64(ptr)
#define ACPI_SET8(ptr, val)
#define ACPI_SET16(ptr, val)
#define ACPI_SET32(ptr, val)
#define ACPI_SET64(ptr, val)

/*
 * printf() format helper. This macro is a workaround for the difficulties
 * with emitting 64-bit integers and 64-bit pointers with the same code
 * for both 32-bit and 64-bit hosts.
 */
#define ACPI_FORMAT_UINT64(i)

/*
 * Macros for moving data around to/from buffers that are possibly unaligned.
 * If the hardware supports the transfer of unaligned data, just do the store.
 * Otherwise, we have to move one byte at a time.
 */
#ifdef ACPI_BIG_ENDIAN
/*
 * Macros for big-endian machines
 */

/* These macros reverse the bytes during the move, converting little-endian to big endian */

	 /* Big Endian      <==        Little Endian */
	 /*  Hi...Lo                     Lo...Hi     */
/* 16-bit source, 16/32/64 destination */

#define ACPI_MOVE_16_TO_16

#define ACPI_MOVE_16_TO_32

#define ACPI_MOVE_16_TO_64

/* 32-bit source, 16/32/64 destination */

#define ACPI_MOVE_32_TO_16

#define ACPI_MOVE_32_TO_32

#define ACPI_MOVE_32_TO_64

/* 64-bit source, 16/32/64 destination */

#define ACPI_MOVE_64_TO_16

#define ACPI_MOVE_64_TO_32

#define ACPI_MOVE_64_TO_64
#else
/*
 * Macros for little-endian machines
 */

#ifndef ACPI_MISALIGNMENT_NOT_SUPPORTED

/* The hardware supports unaligned transfers, just do the little-endian move */

/* 16-bit source, 16/32/64 destination */

#define ACPI_MOVE_16_TO_16(d, s)
#define ACPI_MOVE_16_TO_32(d, s)
#define ACPI_MOVE_16_TO_64(d, s)

/* 32-bit source, 16/32/64 destination */

#define ACPI_MOVE_32_TO_16(d, s)
#define ACPI_MOVE_32_TO_32(d, s)
#define ACPI_MOVE_32_TO_64(d, s)

/* 64-bit source, 16/32/64 destination */

#define ACPI_MOVE_64_TO_16(d, s)
#define ACPI_MOVE_64_TO_32(d, s)
#define ACPI_MOVE_64_TO_64(d, s)

#else
/*
 * The hardware does not support unaligned transfers. We must move the
 * data one byte at a time. These macros work whether the source or
 * the destination (or both) is/are unaligned. (Little-endian move)
 */

/* 16-bit source, 16/32/64 destination */

#define ACPI_MOVE_16_TO_16

#define ACPI_MOVE_16_TO_32
#define ACPI_MOVE_16_TO_64

/* 32-bit source, 16/32/64 destination */

#define ACPI_MOVE_32_TO_16

#define ACPI_MOVE_32_TO_32

#define ACPI_MOVE_32_TO_64

/* 64-bit source, 16/32/64 destination */

#define ACPI_MOVE_64_TO_16
#define ACPI_MOVE_64_TO_32
#define ACPI_MOVE_64_TO_64
#endif
#endif

/*
 * Fast power-of-two math macros for non-optimized compilers
 */
#define _ACPI_DIV(value, power_of2)
#define _ACPI_MUL(value, power_of2)
#define _ACPI_MOD(value, divisor)

#define ACPI_DIV_2(a)
#define ACPI_MUL_2(a)
#define ACPI_MOD_2(a)

#define ACPI_DIV_4(a)
#define ACPI_MUL_4(a)
#define ACPI_MOD_4(a)

#define ACPI_DIV_8(a)
#define ACPI_MUL_8(a)
#define ACPI_MOD_8(a)

#define ACPI_DIV_16(a)
#define ACPI_MUL_16(a)
#define ACPI_MOD_16(a)

#define ACPI_DIV_32(a)
#define ACPI_MUL_32(a)
#define ACPI_MOD_32(a)

/* Test for ASCII character */

#define ACPI_IS_ASCII(c)

/* Signed integers */

#define ACPI_SIGN_POSITIVE
#define ACPI_SIGN_NEGATIVE

/*
 * Rounding macros (Power of two boundaries only)
 */
#define ACPI_ROUND_DOWN(value, boundary)

#define ACPI_ROUND_UP(value, boundary)

/* Note: sizeof(acpi_size) evaluates to either 4 or 8 (32- vs 64-bit mode) */

#define ACPI_ROUND_DOWN_TO_32BIT(a)
#define ACPI_ROUND_DOWN_TO_64BIT(a)
#define ACPI_ROUND_DOWN_TO_NATIVE_WORD(a)

#define ACPI_ROUND_UP_TO_32BIT(a)
#define ACPI_ROUND_UP_TO_64BIT(a)
#define ACPI_ROUND_UP_TO_NATIVE_WORD(a)

#define ACPI_ROUND_BITS_UP_TO_BYTES(a)
#define ACPI_ROUND_BITS_DOWN_TO_BYTES(a)

#define ACPI_ROUND_UP_TO_1K(a)

/* Generic (non-power-of-two) rounding */

#define ACPI_ROUND_UP_TO(value, boundary)

#define ACPI_IS_MISALIGNED(value)

/* Generic bit manipulation */

#ifndef ACPI_USE_NATIVE_BIT_FINDER

#define __ACPI_FIND_LAST_BIT_2(a, r)
#define __ACPI_FIND_LAST_BIT_4(a, r)
#define __ACPI_FIND_LAST_BIT_8(a, r)
#define __ACPI_FIND_LAST_BIT_16(a, r)
#define __ACPI_FIND_LAST_BIT_32(a, r)
#define __ACPI_FIND_LAST_BIT_64(a, r)

#define ACPI_FIND_LAST_BIT_8(a)
#define ACPI_FIND_LAST_BIT_16(a)
#define ACPI_FIND_LAST_BIT_32(a)
#define ACPI_FIND_LAST_BIT_64(a)

#define __ACPI_FIND_FIRST_BIT_2(a, r)
#define __ACPI_FIND_FIRST_BIT_4(a, r)
#define __ACPI_FIND_FIRST_BIT_8(a, r)
#define __ACPI_FIND_FIRST_BIT_16(a, r)
#define __ACPI_FIND_FIRST_BIT_32(a, r)
#define __ACPI_FIND_FIRST_BIT_64(a, r)

#define ACPI_FIND_FIRST_BIT_8(a)
#define ACPI_FIND_FIRST_BIT_16(a)
#define ACPI_FIND_FIRST_BIT_32(a)
#define ACPI_FIND_FIRST_BIT_64(a)

#endif				/* ACPI_USE_NATIVE_BIT_FINDER */

/* Generic (power-of-two) rounding */

#define ACPI_ROUND_UP_POWER_OF_TWO_8(a)
#define ACPI_ROUND_DOWN_POWER_OF_TWO_8(a)
#define ACPI_ROUND_UP_POWER_OF_TWO_16(a)
#define ACPI_ROUND_DOWN_POWER_OF_TWO_16(a)
#define ACPI_ROUND_UP_POWER_OF_TWO_32(a)
#define ACPI_ROUND_DOWN_POWER_OF_TWO_32(a)
#define ACPI_IS_ALIGNED(a, s)
#define ACPI_IS_POWER_OF_TWO(a)

/*
 * Bitmask creation
 * Bit positions start at zero.
 * MASK_BITS_ABOVE creates a mask starting AT the position and above
 * MASK_BITS_BELOW creates a mask starting one bit BELOW the position
 * MASK_BITS_ABOVE/BELOW accepts a bit offset to create a mask
 * MASK_BITS_ABOVE/BELOW_32/64 accepts a bit width to create a mask
 * Note: The ACPI_INTEGER_BIT_SIZE check is used to bypass compiler
 * differences with the shift operator
 */
#define ACPI_MASK_BITS_ABOVE(position)
#define ACPI_MASK_BITS_BELOW(position)
#define ACPI_MASK_BITS_ABOVE_32(width)
#define ACPI_MASK_BITS_BELOW_32(width)
#define ACPI_MASK_BITS_ABOVE_64(width)
#define ACPI_MASK_BITS_BELOW_64(width)

/* Bitfields within ACPI registers */

#define ACPI_REGISTER_PREPARE_BITS(val, pos, mask)

#define ACPI_REGISTER_INSERT_VALUE(reg, pos, mask, val)

#define ACPI_INSERT_BITS(target, mask, source)

/* Generic bitfield macros and masks */

#define ACPI_GET_BITS(source_ptr, position, mask)

#define ACPI_SET_BITS(target_ptr, position, mask, value)

#define ACPI_1BIT_MASK
#define ACPI_2BIT_MASK
#define ACPI_3BIT_MASK
#define ACPI_4BIT_MASK
#define ACPI_5BIT_MASK
#define ACPI_6BIT_MASK
#define ACPI_7BIT_MASK
#define ACPI_8BIT_MASK
#define ACPI_16BIT_MASK
#define ACPI_24BIT_MASK

/* Macros to extract flag bits from position zero */

#define ACPI_GET_1BIT_FLAG(value)
#define ACPI_GET_2BIT_FLAG(value)
#define ACPI_GET_3BIT_FLAG(value)
#define ACPI_GET_4BIT_FLAG(value)

/* Macros to extract flag bits from position one and above */

#define ACPI_EXTRACT_1BIT_FLAG(field, position)
#define ACPI_EXTRACT_2BIT_FLAG(field, position)
#define ACPI_EXTRACT_3BIT_FLAG(field, position)
#define ACPI_EXTRACT_4BIT_FLAG(field, position)

/* ACPI Pathname helpers */

#define ACPI_IS_ROOT_PREFIX(c)
#define ACPI_IS_PARENT_PREFIX(c)
#define ACPI_IS_PATH_SEPARATOR(c)

/*
 * An object of type struct acpi_namespace_node can appear in some contexts
 * where a pointer to an object of type union acpi_operand_object can also
 * appear. This macro is used to distinguish them.
 *
 * The "DescriptorType" field is the second field in both structures.
 */
#define ACPI_GET_DESCRIPTOR_PTR(d)
#define ACPI_SET_DESCRIPTOR_PTR(d, p)
#define ACPI_GET_DESCRIPTOR_TYPE(d)
#define ACPI_SET_DESCRIPTOR_TYPE(d, t)

/*
 * Macros for the master AML opcode table
 */
#if defined (ACPI_DISASSEMBLER) || defined (ACPI_DEBUG_OUTPUT)
#define ACPI_OP(name, Pargs, Iargs, obj_type, class, type, flags)
#else
#define ACPI_OP
#endif

#define ARG_TYPE_WIDTH
#define ARG_1(x)
#define ARG_2(x)
#define ARG_3(x)
#define ARG_4(x)
#define ARG_5(x)
#define ARG_6(x)

#define ARGI_LIST1(a)
#define ARGI_LIST2(a, b)
#define ARGI_LIST3(a, b, c)
#define ARGI_LIST4(a, b, c, d)
#define ARGI_LIST5(a, b, c, d, e)
#define ARGI_LIST6(a, b, c, d, e, f)

#define ARGP_LIST1(a)
#define ARGP_LIST2(a, b)
#define ARGP_LIST3(a, b, c)
#define ARGP_LIST4(a, b, c, d)
#define ARGP_LIST5(a, b, c, d, e)
#define ARGP_LIST6(a, b, c, d, e, f)

#define GET_CURRENT_ARG_TYPE(list)
#define INCREMENT_ARG_LIST(list)

/*
 * Ascii error messages can be configured out
 */
#ifndef ACPI_NO_ERROR_MESSAGES
/*
 * Error reporting. The callers module and line number are inserted by AE_INFO,
 * the plist contains a set of parens to allow variable-length lists.
 * These macros are used for both the debug and non-debug versions of the code.
 */
#define ACPI_ERROR_NAMESPACE(s, p, e)
#define ACPI_ERROR_METHOD(s, n, p, e)
#define ACPI_WARN_PREDEFINED(plist)
#define ACPI_INFO_PREDEFINED(plist)
#define ACPI_BIOS_ERROR_PREDEFINED(plist)
#define ACPI_ERROR_ONLY(s)

#else

/* No error messages */

#define ACPI_ERROR_NAMESPACE
#define ACPI_ERROR_METHOD
#define ACPI_WARN_PREDEFINED
#define ACPI_INFO_PREDEFINED
#define ACPI_BIOS_ERROR_PREDEFINED
#define ACPI_ERROR_ONLY

#endif				/* ACPI_NO_ERROR_MESSAGES */

#if (!ACPI_REDUCED_HARDWARE)
#define ACPI_HW_OPTIONAL_FUNCTION
#else
#define ACPI_HW_OPTIONAL_FUNCTION(addr)
#endif

/*
 * Macros used for ACPICA utilities only
 */

/* Generate a UUID */

#define ACPI_INIT_UUID(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7)

#define ACPI_IS_OCTAL_DIGIT(d)

/*
 * Macros used for the ASL-/ASL+ converter utility
 */
#ifdef ACPI_ASL_COMPILER

#define ASL_CV_LABEL_FILENODE
#define ASL_CV_CAPTURE_COMMENTS_ONLY
#define ASL_CV_CAPTURE_COMMENTS
#define ASL_CV_TRANSFER_COMMENTS
#define ASL_CV_CLOSE_PAREN
#define ASL_CV_CLOSE_BRACE
#define ASL_CV_SWITCH_FILES
#define ASL_CV_CLEAR_OP_COMMENTS
#define ASL_CV_PRINT_ONE_COMMENT
#define ASL_CV_PRINT_ONE_COMMENT_LIST
#define ASL_CV_FILE_HAS_SWITCHED
#define ASL_CV_INIT_FILETREE

#else

#define ASL_CV_LABEL_FILENODE(a)
#define ASL_CV_CAPTURE_COMMENTS_ONLY(a)
#define ASL_CV_CAPTURE_COMMENTS(a)
#define ASL_CV_TRANSFER_COMMENTS(a)
#define ASL_CV_CLOSE_PAREN(a,b)
#define ASL_CV_CLOSE_BRACE(a,b)
#define ASL_CV_SWITCH_FILES(a,b)
#define ASL_CV_CLEAR_OP_COMMENTS(a)
#define ASL_CV_PRINT_ONE_COMMENT(a,b,c,d)
#define ASL_CV_PRINT_ONE_COMMENT_LIST(a,b)
#define ASL_CV_FILE_HAS_SWITCHED(a)
#define ASL_CV_INIT_FILETREE(a,b)

#endif

#endif				/* ACMACROS_H */