acmacros.h
来自「是关于linux2.5.1的完全源码」· C头文件 代码 · 共 565 行 · 第 1/2 页
H
565 行
/****************************************************************************** * * Name: acmacros.h - C macros for the entire subsystem. * $Revision: 115 $ * *****************************************************************************//* * Copyright (C) 2000 - 2002, R. Byron Moore * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */#ifndef __ACMACROS_H__#define __ACMACROS_H__/* * Data manipulation macros */#define ACPI_LOWORD(l) ((u16)(NATIVE_UINT)(l))#define ACPI_HIWORD(l) ((u16)((((NATIVE_UINT)(l)) >> 16) & 0xFFFF))#define ACPI_LOBYTE(l) ((u8)(u16)(l))#define ACPI_HIBYTE(l) ((u8)((((u16)(l)) >> 8) & 0xFF))#ifdef _IA16/* * For 16-bit addresses, we have to assume that the upper 32 bits * are zero. */#define ACPI_LODWORD(l) (l)#define ACPI_HIDWORD(l) (0)#define ACPI_GET_ADDRESS(a) ((a).lo)#define ACPI_STORE_ADDRESS(a,b) {(a).hi=0;(a).lo=(b);}#define ACPI_VALID_ADDRESS(a) ((a).hi | (a).lo)#else#ifdef ACPI_NO_INTEGER64_SUPPORT/* * acpi_integer is 32-bits, no 64-bit support on this platform */#define ACPI_LODWORD(l) ((u32)(l))#define ACPI_HIDWORD(l) (0)#define ACPI_GET_ADDRESS(a) (a)#define ACPI_STORE_ADDRESS(a,b) ((a)=(b))#define ACPI_VALID_ADDRESS(a) (a)#else/* * Full 64-bit address/integer on both 32-bit and 64-bit platforms */#define ACPI_LODWORD(l) ((u32)(u64)(l))#define ACPI_HIDWORD(l) ((u32)(((*(uint64_struct *)(&l))).hi))#define ACPI_GET_ADDRESS(a) (a)#define ACPI_STORE_ADDRESS(a,b) ((a)=(b))#define ACPI_VALID_ADDRESS(a) (a)#endif#endif /* * Extract a byte of data using a pointer. Any more than a byte and we * get into potential aligment issues -- see the STORE macros below */#define ACPI_GET8(addr) (*(u8*)(addr))/* Pointer arithmetic */#define ACPI_PTR_ADD(t,a,b) (t *) ((char *)(a) + (b))#define ACPI_PTR_DIFF(a,b) (NATIVE_UINT) ((char *)(a) - (char *)(b))/* Pointer/Integer type conversions */#define ACPI_TO_POINTER(i) ACPI_PTR_ADD (void,NULL,(NATIVE_UINT)i)#define ACPI_TO_INTEGER(p) ACPI_PTR_DIFF (p,NULL)#define ACPI_OFFSET(d,o) ((ACPI_SIZE) ACPI_TO_INTEGER (&(((d *)0)->o)))#define ACPI_FADT_OFFSET(o) ACPI_OFFSET (FADT_DESCRIPTOR, o)#ifdef _IA16#define ACPI_PHYSADDR_TO_PTR(i) (void *)(i)#define ACPI_PTR_TO_PHYSADDR(i) (char *)(i)#else#define ACPI_PHYSADDR_TO_PTR(i) ACPI_TO_POINTER(i)#define ACPI_PTR_TO_PHYSADDR(i) ACPI_TO_INTEGER(i)#endif/* * 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 _HW_ALIGNMENT_SUPPORT/* The hardware supports unaligned transfers, just do the move */#define ACPI_MOVE_UNALIGNED16_TO_16(d,s) *(u16 *)(d) = *(u16 *)(s)#define ACPI_MOVE_UNALIGNED32_TO_32(d,s) *(u32 *)(d) = *(u32 *)(s)#define ACPI_MOVE_UNALIGNED16_TO_32(d,s) *(u32 *)(d) = *(u16 *)(s)#define ACPI_MOVE_UNALIGNED64_TO_64(d,s) *(u64 *)(d) = *(u64 *)(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. */#define ACPI_MOVE_UNALIGNED16_TO_16(d,s) {((u8 *)(d))[0] = ((u8 *)(s))[0];\ ((u8 *)(d))[1] = ((u8 *)(s))[1];}#define ACPI_MOVE_UNALIGNED32_TO_32(d,s) {((u8 *)(d))[0] = ((u8 *)(s))[0];\ ((u8 *)(d))[1] = ((u8 *)(s))[1];\ ((u8 *)(d))[2] = ((u8 *)(s))[2];\ ((u8 *)(d))[3] = ((u8 *)(s))[3];}#define ACPI_MOVE_UNALIGNED16_TO_32(d,s) {(*(u32*)(d)) = 0; ACPI_MOVE_UNALIGNED16_TO_16(d,s);}#define ACPI_MOVE_UNALIGNED64_TO_64(d,s) {((u8 *)(d))[0] = ((u8 *)(s))[0];\ ((u8 *)(d))[1] = ((u8 *)(s))[1];\ ((u8 *)(d))[2] = ((u8 *)(s))[2];\ ((u8 *)(d))[3] = ((u8 *)(s))[3];\ ((u8 *)(d))[4] = ((u8 *)(s))[4];\ ((u8 *)(d))[5] = ((u8 *)(s))[5];\ ((u8 *)(d))[6] = ((u8 *)(s))[6];\ ((u8 *)(d))[7] = ((u8 *)(s))[7];}#endif/* * Fast power-of-two math macros for non-optimized compilers */#define _ACPI_DIV(value,power_of2) ((u32) ((value) >> (power_of2)))#define _ACPI_MUL(value,power_of2) ((u32) ((value) << (power_of2)))#define _ACPI_MOD(value,divisor) ((u32) ((value) & ((divisor) -1)))#define ACPI_DIV_2(a) _ACPI_DIV(a,1)#define ACPI_MUL_2(a) _ACPI_MUL(a,1)#define ACPI_MOD_2(a) _ACPI_MOD(a,2)#define ACPI_DIV_4(a) _ACPI_DIV(a,2)#define ACPI_MUL_4(a) _ACPI_MUL(a,2)#define ACPI_MOD_4(a) _ACPI_MOD(a,4)#define ACPI_DIV_8(a) _ACPI_DIV(a,3)#define ACPI_MUL_8(a) _ACPI_MUL(a,3)#define ACPI_MOD_8(a) _ACPI_MOD(a,8)#define ACPI_DIV_16(a) _ACPI_DIV(a,4)#define ACPI_MUL_16(a) _ACPI_MUL(a,4)#define ACPI_MOD_16(a) _ACPI_MOD(a,16)/* * Rounding macros (Power of two boundaries only) */#define ACPI_ROUND_DOWN(value,boundary) (((NATIVE_UINT)(value)) & (~((boundary)-1)))#define ACPI_ROUND_UP(value,boundary) ((((NATIVE_UINT)(value)) + ((boundary)-1)) & (~((boundary)-1)))#define ACPI_ROUND_DOWN_TO_32_BITS(a) ACPI_ROUND_DOWN(a,4)#define ACPI_ROUND_DOWN_TO_64_BITS(a) ACPI_ROUND_DOWN(a,8)#define ACPI_ROUND_DOWN_TO_NATIVE_WORD(a) ACPI_ROUND_DOWN(a,ALIGNED_ADDRESS_BOUNDARY)#define ACPI_ROUND_UP_TO_32_bITS(a) ACPI_ROUND_UP(a,4)#define ACPI_ROUND_UP_TO_64_bITS(a) ACPI_ROUND_UP(a,8)#define ACPI_ROUND_UP_TO_NATIVE_WORD(a) ACPI_ROUND_UP(a,ALIGNED_ADDRESS_BOUNDARY)#define ACPI_ROUND_BITS_UP_TO_BYTES(a) ACPI_DIV_8((a) + 7)#define ACPI_ROUND_BITS_DOWN_TO_BYTES(a) ACPI_DIV_8((a))#define ACPI_ROUND_UP_TO_1K(a) (((a) + 1023) >> 10)/* Generic (non-power-of-two) rounding */#define ACPI_ROUND_UP_TO(value,boundary) (((value) + ((boundary)-1)) / (boundary))/* * 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 */#define ACPI_MASK_BITS_ABOVE(position) (~(((acpi_integer)(-1)) << ((u32) (position))))#define ACPI_MASK_BITS_BELOW(position) (((acpi_integer)(-1)) << ((u32) (position)))#define ACPI_IS_OCTAL_DIGIT(d) (((char)(d) >= '0') && ((char)(d) <= '7'))/* Macros for GAS addressing */#ifndef _IA16#define ACPI_PCI_DEVICE_MASK (u64) 0x0000FFFF00000000#define ACPI_PCI_FUNCTION_MASK (u64) 0x00000000FFFF0000#define ACPI_PCI_REGISTER_MASK (u64) 0x000000000000FFFF#define ACPI_PCI_FUNCTION(a) (u16) ((((a) & ACPI_PCI_FUNCTION_MASK) >> 16))#define ACPI_PCI_DEVICE(a) (u16) ((((a) & ACPI_PCI_DEVICE_MASK) >> 32))#define ACPI_PCI_REGISTER(a) (u16) (((a) & ACPI_PCI_REGISTER_MASK))#else/* No support for GAS and PCI IDs in 16-bit mode */#define ACPI_PCI_FUNCTION(a) (u16) ((a) & 0xFFFF0000)#define ACPI_PCI_DEVICE(a) (u16) ((a) & 0x0000FFFF)#define ACPI_PCI_REGISTER(a) (u16) ((a) & 0x0000FFFF)#endif/* Bitfields within ACPI registers */#define ACPI_REGISTER_PREPARE_BITS(val, pos, mask) ((val << pos) & mask)#define ACPI_REGISTER_INSERT_VALUE(reg, pos, mask, val) reg = (reg & (~(mask))) | ACPI_REGISTER_PREPARE_BITS(val, pos, mask)/* * An acpi_namespace_node * can appear in some contexts, * where a pointer to an acpi_operand_object can also * appear. This macro is used to distinguish them. * * The "Descriptor" field is the first field in both structures. */#define ACPI_GET_DESCRIPTOR_TYPE(d) (((acpi_namespace_node *)d)->descriptor)#define ACPI_SET_DESCRIPTOR_TYPE(d,t) (((acpi_namespace_node *)d)->descriptor = t)/* Macro to test the object type */#define ACPI_GET_OBJECT_TYPE(d) (((acpi_operand_object *)d)->common.type)/* Macro to check the table flags for SINGLE or MULTIPLE tables are allowed */#define ACPI_IS_SINGLE_TABLE(x) (((x) & 0x01) == ACPI_TABLE_SINGLE ? 1 : 0)/* * Macro to check if a pointer is within an ACPI table. * Parameter (a) is the pointer to check. Parameter (b) must be defined * as a pointer to an acpi_table_header. (b+1) then points past the header, * and ((u8 *)b+b->Length) points one byte past the end of the table. */#ifndef _IA16#define ACPI_IS_IN_ACPI_TABLE(a,b) (((u8 *)(a) >= (u8 *)(b + 1)) &&\ ((u8 *)(a) < ((u8 *)b + b->length)))#else#define ACPI_IS_IN_ACPI_TABLE(a,b) (_segment)(a) == (_segment)(b) &&\ (((u8 *)(a) >= (u8 *)(b + 1)) &&\ ((u8 *)(a) < ((u8 *)b + b->length)))#endif/* * Macros for the master AML opcode table */#ifdef ACPI_DEBUG#define ACPI_OP(name,Pargs,Iargs,obj_type,class,type,flags) {name,Pargs,Iargs,flags,obj_type,class,type}#else#define ACPI_OP(name,Pargs,Iargs,obj_type,class,type,flags) {Pargs,Iargs,flags,obj_type,class,type}#endif#define ARG_TYPE_WIDTH 5#define ARG_1(x) ((u32)(x))#define ARG_2(x) ((u32)(x) << (1 * ARG_TYPE_WIDTH))
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?