1ddbd7b91SNathan Whitehorn/******************************************************************************
2ddbd7b91SNathan Whitehorn *
3ddbd7b91SNathan Whitehorn * Name: acmacros.h - C macros for the entire subsystem.
4ddbd7b91SNathan Whitehorn *
5ddbd7b91SNathan Whitehorn *****************************************************************************/
6ddbd7b91SNathan Whitehorn
7ddbd7b91SNathan Whitehorn/******************************************************************************
8ddbd7b91SNathan Whitehorn *
9ddbd7b91SNathan Whitehorn * 1. Copyright Notice
10ddbd7b91SNathan Whitehorn *
11ff2e2f81SFredrik Holmqvist * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
12ddbd7b91SNathan Whitehorn * All rights reserved.
13ddbd7b91SNathan Whitehorn *
14ddbd7b91SNathan Whitehorn * 2. License
15ddbd7b91SNathan Whitehorn *
16ddbd7b91SNathan Whitehorn * 2.1. This is your license from Intel Corp. under its intellectual property
179b0d045cSFredrik Holmqvist * rights. You may have additional license terms from the party that provided
18ddbd7b91SNathan Whitehorn * you this software, covering your right to use that party's intellectual
19ddbd7b91SNathan Whitehorn * property rights.
20ddbd7b91SNathan Whitehorn *
21ddbd7b91SNathan Whitehorn * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22ddbd7b91SNathan Whitehorn * copy of the source code appearing in this file ("Covered Code") an
23ddbd7b91SNathan Whitehorn * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24ddbd7b91SNathan Whitehorn * base code distributed originally by Intel ("Original Intel Code") to copy,
25ddbd7b91SNathan Whitehorn * make derivatives, distribute, use and display any portion of the Covered
26ddbd7b91SNathan Whitehorn * Code in any form, with the right to sublicense such rights; and
27ddbd7b91SNathan Whitehorn *
28ddbd7b91SNathan Whitehorn * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29ddbd7b91SNathan Whitehorn * license (with the right to sublicense), under only those claims of Intel
30ddbd7b91SNathan Whitehorn * patents that are infringed by the Original Intel Code, to make, use, sell,
31ddbd7b91SNathan Whitehorn * offer to sell, and import the Covered Code and derivative works thereof
32ddbd7b91SNathan Whitehorn * solely to the minimum extent necessary to exercise the above copyright
33ddbd7b91SNathan Whitehorn * license, and in no event shall the patent license extend to any additions
349b0d045cSFredrik Holmqvist * to or modifications of the Original Intel Code. No other license or right
35ddbd7b91SNathan Whitehorn * is granted directly or by implication, estoppel or otherwise;
36ddbd7b91SNathan Whitehorn *
37ddbd7b91SNathan Whitehorn * The above copyright and patent license is granted only if the following
38ddbd7b91SNathan Whitehorn * conditions are met:
39ddbd7b91SNathan Whitehorn *
40ddbd7b91SNathan Whitehorn * 3. Conditions
41ddbd7b91SNathan Whitehorn *
42ddbd7b91SNathan Whitehorn * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43ddbd7b91SNathan Whitehorn * Redistribution of source code of any substantial portion of the Covered
44ddbd7b91SNathan Whitehorn * Code or modification with rights to further distribute source must include
45ddbd7b91SNathan Whitehorn * the above Copyright Notice, the above License, this list of Conditions,
469b0d045cSFredrik Holmqvist * and the following Disclaimer and Export Compliance provision. In addition,
47ddbd7b91SNathan Whitehorn * Licensee must cause all Covered Code to which Licensee contributes to
48ddbd7b91SNathan Whitehorn * contain a file documenting the changes Licensee made to create that Covered
499b0d045cSFredrik Holmqvist * Code and the date of any change. Licensee must include in that file the
509b0d045cSFredrik Holmqvist * documentation of any changes made by any predecessor Licensee. Licensee
51ddbd7b91SNathan Whitehorn * must include a prominent statement that the modification is derived,
52ddbd7b91SNathan Whitehorn * directly or indirectly, from Original Intel Code.
53ddbd7b91SNathan Whitehorn *
54ddbd7b91SNathan Whitehorn * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55ddbd7b91SNathan Whitehorn * Redistribution of source code of any substantial portion of the Covered
56ddbd7b91SNathan Whitehorn * Code or modification without rights to further distribute source must
57ddbd7b91SNathan Whitehorn * include the following Disclaimer and Export Compliance provision in the
589b0d045cSFredrik Holmqvist * documentation and/or other materials provided with distribution. In
59ddbd7b91SNathan Whitehorn * addition, Licensee may not authorize further sublicense of source of any
60ddbd7b91SNathan Whitehorn * portion of the Covered Code, and must include terms to the effect that the
61ddbd7b91SNathan Whitehorn * license from Licensee to its licensee is limited to the intellectual
62ddbd7b91SNathan Whitehorn * property embodied in the software Licensee provides to its licensee, and
63ddbd7b91SNathan Whitehorn * not to intellectual property embodied in modifications its licensee may
64ddbd7b91SNathan Whitehorn * make.
65ddbd7b91SNathan Whitehorn *
66ddbd7b91SNathan Whitehorn * 3.3. Redistribution of Executable. Redistribution in executable form of any
67ddbd7b91SNathan Whitehorn * substantial portion of the Covered Code or modification must reproduce the
68ddbd7b91SNathan Whitehorn * above Copyright Notice, and the following Disclaimer and Export Compliance
69ddbd7b91SNathan Whitehorn * provision in the documentation and/or other materials provided with the
70ddbd7b91SNathan Whitehorn * distribution.
71ddbd7b91SNathan Whitehorn *
72ddbd7b91SNathan Whitehorn * 3.4. Intel retains all right, title, and interest in and to the Original
73ddbd7b91SNathan Whitehorn * Intel Code.
74ddbd7b91SNathan Whitehorn *
75ddbd7b91SNathan Whitehorn * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76ddbd7b91SNathan Whitehorn * Intel shall be used in advertising or otherwise to promote the sale, use or
77ddbd7b91SNathan Whitehorn * other dealings in products derived from or relating to the Covered Code
78ddbd7b91SNathan Whitehorn * without prior written authorization from Intel.
79ddbd7b91SNathan Whitehorn *
80ddbd7b91SNathan Whitehorn * 4. Disclaimer and Export Compliance
81ddbd7b91SNathan Whitehorn *
82ddbd7b91SNathan Whitehorn * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
839b0d045cSFredrik Holmqvist * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
849b0d045cSFredrik Holmqvist * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
859b0d045cSFredrik Holmqvist * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
869b0d045cSFredrik Holmqvist * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87ddbd7b91SNathan Whitehorn * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88ddbd7b91SNathan Whitehorn * PARTICULAR PURPOSE.
89ddbd7b91SNathan Whitehorn *
90ddbd7b91SNathan Whitehorn * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91ddbd7b91SNathan Whitehorn * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92ddbd7b91SNathan Whitehorn * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93ddbd7b91SNathan Whitehorn * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94ddbd7b91SNathan Whitehorn * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
959b0d045cSFredrik Holmqvist * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96ddbd7b91SNathan Whitehorn * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97ddbd7b91SNathan Whitehorn * LIMITED REMEDY.
98ddbd7b91SNathan Whitehorn *
99ddbd7b91SNathan Whitehorn * 4.3. Licensee shall not export, either directly or indirectly, any of this
100ddbd7b91SNathan Whitehorn * software or system incorporating such software without first obtaining any
101ddbd7b91SNathan Whitehorn * required license or other approval from the U. S. Department of Commerce or
1029b0d045cSFredrik Holmqvist * any other agency or department of the United States Government. In the
103ddbd7b91SNathan Whitehorn * event Licensee exports any such software from the United States or
104ddbd7b91SNathan Whitehorn * re-exports any such software from a foreign destination, Licensee shall
105ddbd7b91SNathan Whitehorn * ensure that the distribution and export/re-export of the software is in
106ddbd7b91SNathan Whitehorn * compliance with all laws, regulations, orders, or other restrictions of the
107ddbd7b91SNathan Whitehorn * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108ddbd7b91SNathan Whitehorn * any of its subsidiaries will export/re-export any technical data, process,
109ddbd7b91SNathan Whitehorn * software, or service, directly or indirectly, to any country for which the
110ddbd7b91SNathan Whitehorn * United States government or any agency thereof requires an export license,
111ddbd7b91SNathan Whitehorn * other governmental approval, or letter of assurance, without first obtaining
112ddbd7b91SNathan Whitehorn * such license, approval or letter.
113ddbd7b91SNathan Whitehorn *
114ff2e2f81SFredrik Holmqvist *****************************************************************************
115ff2e2f81SFredrik Holmqvist *
116ff2e2f81SFredrik Holmqvist * Alternatively, you may choose to be licensed under the terms of the
117ff2e2f81SFredrik Holmqvist * following license:
118ff2e2f81SFredrik Holmqvist *
119ff2e2f81SFredrik Holmqvist * Redistribution and use in source and binary forms, with or without
120ff2e2f81SFredrik Holmqvist * modification, are permitted provided that the following conditions
121ff2e2f81SFredrik Holmqvist * are met:
122ff2e2f81SFredrik Holmqvist * 1. Redistributions of source code must retain the above copyright
123ff2e2f81SFredrik Holmqvist *    notice, this list of conditions, and the following disclaimer,
124ff2e2f81SFredrik Holmqvist *    without modification.
125ff2e2f81SFredrik Holmqvist * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126ff2e2f81SFredrik Holmqvist *    substantially similar to the "NO WARRANTY" disclaimer below
127ff2e2f81SFredrik Holmqvist *    ("Disclaimer") and any redistribution must be conditioned upon
128ff2e2f81SFredrik Holmqvist *    including a substantially similar Disclaimer requirement for further
129ff2e2f81SFredrik Holmqvist *    binary redistribution.
130ff2e2f81SFredrik Holmqvist * 3. Neither the names of the above-listed copyright holders nor the names
131ff2e2f81SFredrik Holmqvist *    of any contributors may be used to endorse or promote products derived
132ff2e2f81SFredrik Holmqvist *    from this software without specific prior written permission.
133ff2e2f81SFredrik Holmqvist *
134ff2e2f81SFredrik Holmqvist * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135ff2e2f81SFredrik Holmqvist * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136ff2e2f81SFredrik Holmqvist * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137ff2e2f81SFredrik Holmqvist * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138ff2e2f81SFredrik Holmqvist * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139ff2e2f81SFredrik Holmqvist * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140ff2e2f81SFredrik Holmqvist * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141ff2e2f81SFredrik Holmqvist * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142ff2e2f81SFredrik Holmqvist * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143ff2e2f81SFredrik Holmqvist * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144ff2e2f81SFredrik Holmqvist * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145ff2e2f81SFredrik Holmqvist *
146ff2e2f81SFredrik Holmqvist * Alternatively, you may choose to be licensed under the terms of the
147ff2e2f81SFredrik Holmqvist * GNU General Public License ("GPL") version 2 as published by the Free
148ff2e2f81SFredrik Holmqvist * Software Foundation.
149ff2e2f81SFredrik Holmqvist *
150ddbd7b91SNathan Whitehorn *****************************************************************************/
151ddbd7b91SNathan Whitehorn
152ddbd7b91SNathan Whitehorn#ifndef __ACMACROS_H__
153ddbd7b91SNathan Whitehorn#define __ACMACROS_H__
154ddbd7b91SNathan Whitehorn
155ddbd7b91SNathan Whitehorn
156ddbd7b91SNathan Whitehorn/*
157cfd62a38SJérôme Duval * Extract data using a pointer. Any more than a byte and we
158ff2e2f81SFredrik Holmqvist * get into potential alignment issues -- see the STORE macros below.
15943547dbeSJérôme Duval * Use with care.
160ddbd7b91SNathan Whitehorn */
161c70258b7SJérôme Duval#define ACPI_CAST8(ptr)                 ACPI_CAST_PTR (UINT8, (ptr))
162c70258b7SJérôme Duval#define ACPI_CAST16(ptr)                ACPI_CAST_PTR (UINT16, (ptr))
163c70258b7SJérôme Duval#define ACPI_CAST32(ptr)                ACPI_CAST_PTR (UINT32, (ptr))
164c70258b7SJérôme Duval#define ACPI_CAST64(ptr)                ACPI_CAST_PTR (UINT64, (ptr))
165c70258b7SJérôme Duval#define ACPI_GET8(ptr)                  (*ACPI_CAST8 (ptr))
166c70258b7SJérôme Duval#define ACPI_GET16(ptr)                 (*ACPI_CAST16 (ptr))
167c70258b7SJérôme Duval#define ACPI_GET32(ptr)                 (*ACPI_CAST32 (ptr))
168c70258b7SJérôme Duval#define ACPI_GET64(ptr)                 (*ACPI_CAST64 (ptr))
169c70258b7SJérôme Duval#define ACPI_SET8(ptr, val)             (*ACPI_CAST8 (ptr) = (UINT8) (val))
170c70258b7SJérôme Duval#define ACPI_SET16(ptr, val)            (*ACPI_CAST16 (ptr) = (UINT16) (val))
171c70258b7SJérôme Duval#define ACPI_SET32(ptr, val)            (*ACPI_CAST32 (ptr) = (UINT32) (val))
172c70258b7SJérôme Duval#define ACPI_SET64(ptr, val)            (*ACPI_CAST64 (ptr) = (UINT64) (val))
173ddbd7b91SNathan Whitehorn
1742608583eSJérôme Duval/*
175ff2e2f81SFredrik Holmqvist * printf() format helper. This macro is a workaround for the difficulties
176ad5bbfb8SFredrik Holmqvist * with emitting 64-bit integers and 64-bit pointers with the same code
177ad5bbfb8SFredrik Holmqvist * for both 32-bit and 64-bit hosts.
1782608583eSJérôme Duval */
179cfd62a38SJérôme Duval#define ACPI_FORMAT_UINT64(i)           ACPI_HIDWORD(i), ACPI_LODWORD(i)
1802608583eSJérôme Duval
1812608583eSJérôme Duval
182ddbd7b91SNathan Whitehorn/*
183ddbd7b91SNathan Whitehorn * Macros for moving data around to/from buffers that are possibly unaligned.
184ddbd7b91SNathan Whitehorn * If the hardware supports the transfer of unaligned data, just do the store.
185ddbd7b91SNathan Whitehorn * Otherwise, we have to move one byte at a time.
186ddbd7b91SNathan Whitehorn */
187ddbd7b91SNathan Whitehorn#ifdef ACPI_BIG_ENDIAN
188ddbd7b91SNathan Whitehorn/*
189ddbd7b91SNathan Whitehorn * Macros for big-endian machines
190ddbd7b91SNathan Whitehorn */
191ddbd7b91SNathan Whitehorn
192ddbd7b91SNathan Whitehorn/* These macros reverse the bytes during the move, converting little-endian to big endian */
193ddbd7b91SNathan Whitehorn
194ddbd7b91SNathan Whitehorn                                                     /* Big Endian      <==        Little Endian */
195ddbd7b91SNathan Whitehorn                                                     /*  Hi...Lo                     Lo...Hi     */
196ddbd7b91SNathan Whitehorn/* 16-bit source, 16/32/64 destination */
197ddbd7b91SNathan Whitehorn
198cfd62a38SJérôme Duval#define ACPI_MOVE_16_TO_16(d, s)        {((  UINT8 *)(void *)(d))[0] = ((UINT8 *)(void *)(s))[1];\
199ddbd7b91SNathan Whitehorn                                         ((  UINT8 *)(void *)(d))[1] = ((UINT8 *)(void *)(s))[0];}
200ddbd7b91SNathan Whitehorn
201cfd62a38SJérôme Duval#define ACPI_MOVE_16_TO_32(d, s)        {(*(UINT32 *)(void *)(d))=0;\
202ddbd7b91SNathan Whitehorn                                           ((UINT8 *)(void *)(d))[2] = ((UINT8 *)(void *)(s))[1];\
203ddbd7b91SNathan Whitehorn                                           ((UINT8 *)(void *)(d))[3] = ((UINT8 *)(void *)(s))[0];}
204ddbd7b91SNathan Whitehorn
205cfd62a38SJérôme Duval#define ACPI_MOVE_16_TO_64(d, s)        {(*(UINT64 *)(void *)(d))=0;\
206ddbd7b91SNathan Whitehorn                                           ((UINT8 *)(void *)(d))[6] = ((UINT8 *)(void *)(s))[1];\
207ddbd7b91SNathan Whitehorn                                           ((UINT8 *)(void *)(d))[7] = ((UINT8 *)(void *)(s))[0];}
208ddbd7b91SNathan Whitehorn
209ddbd7b91SNathan Whitehorn/* 32-bit source, 16/32/64 destination */
210ddbd7b91SNathan Whitehorn
211cfd62a38SJérôme Duval#define ACPI_MOVE_32_TO_16(d, s)        ACPI_MOVE_16_TO_16(d, s)    /* Truncate to 16 */
212ddbd7b91SNathan Whitehorn
213cfd62a38SJérôme Duval#define ACPI_MOVE_32_TO_32(d, s)        {((  UINT8 *)(void *)(d))[0] = ((UINT8 *)(void *)(s))[3];\
214ddbd7b91SNathan Whitehorn                                         ((  UINT8 *)(void *)(d))[1] = ((UINT8 *)(void *)(s))[2];\
215ddbd7b91SNathan Whitehorn                                         ((  UINT8 *)(void *)(d))[2] = ((UINT8 *)(void *)(s))[1];\
216ddbd7b91SNathan Whitehorn                                         ((  UINT8 *)(void *)(d))[3] = ((UINT8 *)(void *)(s))[0];}
217ddbd7b91SNathan Whitehorn
218cfd62a38SJérôme Duval#define ACPI_MOVE_32_TO_64(d, s)        {(*(UINT64 *)(void *)(d))=0;\
219ddbd7b91SNathan Whitehorn                                           ((UINT8 *)(void *)(d))[4] = ((UINT8 *)(void *)(s))[3];\
220ddbd7b91SNathan Whitehorn                                           ((UINT8 *)(void *)(d))[5] = ((UINT8 *)(void *)(s))[2];\
221ddbd7b91SNathan Whitehorn                                           ((UINT8 *)(void *)(d))[6] = ((UINT8 *)(void *)(s))[1];\
222ddbd7b91SNathan Whitehorn                                           ((UINT8 *)(void *)(d))[7] = ((UINT8 *)(void *)(s))[0];}
223ddbd7b91SNathan Whitehorn
224ddbd7b91SNathan Whitehorn/* 64-bit source, 16/32/64 destination */
225ddbd7b91SNathan Whitehorn
226cfd62a38SJérôme Duval#define ACPI_MOVE_64_TO_16(d, s)        ACPI_MOVE_16_TO_16(d, s)    /* Truncate to 16 */
227ddbd7b91SNathan Whitehorn
228cfd62a38SJérôme Duval#define ACPI_MOVE_64_TO_32(d, s)        ACPI_MOVE_32_TO_32(d, s)    /* Truncate to 32 */
229ddbd7b91SNathan Whitehorn
230cfd62a38SJérôme Duval#define ACPI_MOVE_64_TO_64(d, s)        {((  UINT8 *)(void *)(d))[0] = ((UINT8 *)(void *)(s))[7];\
231ddbd7b91SNathan Whitehorn                                         ((  UINT8 *)(void *)(d))[1] = ((UINT8 *)(void *)(s))[6];\
232ddbd7b91SNathan Whitehorn                                         ((  UINT8 *)(void *)(d))[2] = ((UINT8 *)(void *)(s))[5];\
233ddbd7b91SNathan Whitehorn                                         ((  UINT8 *)(void *)(d))[3] = ((UINT8 *)(void *)(s))[4];\
234ddbd7b91SNathan Whitehorn                                         ((  UINT8 *)(void *)(d))[4] = ((UINT8 *)(void *)(s))[3];\
235ddbd7b91SNathan Whitehorn                                         ((  UINT8 *)(void *)(d))[5] = ((UINT8 *)(void *)(s))[2];\
236ddbd7b91SNathan Whitehorn                                         ((  UINT8 *)(void *)(d))[6] = ((UINT8 *)(void *)(s))[1];\
237ddbd7b91SNathan Whitehorn                                         ((  UINT8 *)(void *)(d))[7] = ((UINT8 *)(void *)(s))[0];}
238ddbd7b91SNathan Whitehorn#else
239ddbd7b91SNathan Whitehorn/*
240ddbd7b91SNathan Whitehorn * Macros for little-endian machines
241ddbd7b91SNathan Whitehorn */
242ddbd7b91SNathan Whitehorn
24343547dbeSJérôme Duval#ifndef ACPI_MISALIGNMENT_NOT_SUPPORTED
244ddbd7b91SNathan Whitehorn
245ddbd7b91SNathan Whitehorn/* The hardware supports unaligned transfers, just do the little-endian move */
246ddbd7b91SNathan Whitehorn
247ddbd7b91SNathan Whitehorn/* 16-bit source, 16/32/64 destination */
248ddbd7b91SNathan Whitehorn
249cfd62a38SJérôme Duval#define ACPI_MOVE_16_TO_16(d, s)        *(UINT16 *)(void *)(d) = *(UINT16 *)(void *)(s)
250cfd62a38SJérôme Duval#define ACPI_MOVE_16_TO_32(d, s)        *(UINT32 *)(void *)(d) = *(UINT16 *)(void *)(s)
251cfd62a38SJérôme Duval#define ACPI_MOVE_16_TO_64(d, s)        *(UINT64 *)(void *)(d) = *(UINT16 *)(void *)(s)
252ddbd7b91SNathan Whitehorn
253ddbd7b91SNathan Whitehorn/* 32-bit source, 16/32/64 destination */
254ddbd7b91SNathan Whitehorn
255cfd62a38SJérôme Duval#define ACPI_MOVE_32_TO_16(d, s)        ACPI_MOVE_16_TO_16(d, s)    /* Truncate to 16 */
256cfd62a38SJérôme Duval#define ACPI_MOVE_32_TO_32(d, s)        *(UINT32 *)(void *)(d) = *(UINT32 *)(void *)(s)
257cfd62a38SJérôme Duval#define ACPI_MOVE_32_TO_64(d, s)        *(UINT64 *)(void *)(d) = *(UINT32 *)(void *)(s)
258ddbd7b91SNathan Whitehorn
259ddbd7b91SNathan Whitehorn/* 64-bit source, 16/32/64 destination */
260ddbd7b91SNathan Whitehorn
261cfd62a38SJérôme Duval#define ACPI_MOVE_64_TO_16(d, s)        ACPI_MOVE_16_TO_16(d, s)    /* Truncate to 16 */
262cfd62a38SJérôme Duval#define ACPI_MOVE_64_TO_32(d, s)        ACPI_MOVE_32_TO_32(d, s)    /* Truncate to 32 */
263cfd62a38SJérôme Duval#define ACPI_MOVE_64_TO_64(d, s)        *(UINT64 *)(void *)(d) = *(UINT64 *)(void *)(s)
264ddbd7b91SNathan Whitehorn
265ddbd7b91SNathan Whitehorn#else
266ddbd7b91SNathan Whitehorn/*
267cfd62a38SJérôme Duval * The hardware does not support unaligned transfers. We must move the
268cfd62a38SJérôme Duval * data one byte at a time. These macros work whether the source or
26980377d9aSJérôme Duval * the destination (or both) is/are unaligned. (Little-endian move)
270ddbd7b91SNathan Whitehorn */
271ddbd7b91SNathan Whitehorn
272ddbd7b91SNathan Whitehorn/* 16-bit source, 16/32/64 destination */
273ddbd7b91SNathan Whitehorn
274cfd62a38SJérôme Duval#define ACPI_MOVE_16_TO_16(d, s)        {((  UINT8 *)(void *)(d))[0] = ((UINT8 *)(void *)(s))[0];\
275ddbd7b91SNathan Whitehorn                                         ((  UINT8 *)(void *)(d))[1] = ((UINT8 *)(void *)(s))[1];}
276ddbd7b91SNathan Whitehorn
277cfd62a38SJérôme Duval#define ACPI_MOVE_16_TO_32(d, s)        {(*(UINT32 *)(void *)(d)) = 0; ACPI_MOVE_16_TO_16(d, s);}
278cfd62a38SJérôme Duval#define ACPI_MOVE_16_TO_64(d, s)        {(*(UINT64 *)(void *)(d)) = 0; ACPI_MOVE_16_TO_16(d, s);}
279ddbd7b91SNathan Whitehorn
280ddbd7b91SNathan Whitehorn/* 32-bit source, 16/32/64 destination */
281ddbd7b91SNathan Whitehorn
282cfd62a38SJérôme Duval#define ACPI_MOVE_32_TO_16(d, s)        ACPI_MOVE_16_TO_16(d, s)    /* Truncate to 16 */
283ddbd7b91SNathan Whitehorn
284cfd62a38SJérôme Duval#define ACPI_MOVE_32_TO_32(d, s)        {((  UINT8 *)(void *)(d))[0] = ((UINT8 *)(void *)(s))[0];\
285ddbd7b91SNathan Whitehorn                                         ((  UINT8 *)(void *)(d))[1] = ((UINT8 *)(void *)(s))[1];\
286ddbd7b91SNathan Whitehorn                                         ((  UINT8 *)(void *)(d))[2] = ((UINT8 *)(void *)(s))[2];\
287ddbd7b91SNathan Whitehorn                                         ((  UINT8 *)(void *)(d))[3] = ((UINT8 *)(void *)(s))[3];}
288ddbd7b91SNathan Whitehorn
289cfd62a38SJérôme Duval#define ACPI_MOVE_32_TO_64(d, s)        {(*(UINT64 *)(void *)(d)) = 0; ACPI_MOVE_32_TO_32(d, s);}
290ddbd7b91SNathan Whitehorn
291ddbd7b91SNathan Whitehorn/* 64-bit source, 16/32/64 destination */
292ddbd7b91SNathan Whitehorn
293cfd62a38SJérôme Duval#define ACPI_MOVE_64_TO_16(d, s)        ACPI_MOVE_16_TO_16(d, s)    /* Truncate to 16 */
294cfd62a38SJérôme Duval#define ACPI_MOVE_64_TO_32(d, s)        ACPI_MOVE_32_TO_32(d, s)    /* Truncate to 32 */
295cfd62a38SJérôme Duval#define ACPI_MOVE_64_TO_64(d, s)        {((  UINT8 *)(void *)(d))[0] = ((UINT8 *)(void *)(s))[0];\
296ddbd7b91SNathan Whitehorn                                         ((  UINT8 *)(void *)(d))[1] = ((UINT8 *)(void *)(s))[1];\
297ddbd7b91SNathan Whitehorn                                         ((  UINT8 *)(void *)(d))[2] = ((UINT8 *)(void *)(s))[2];\
298ddbd7b91SNathan Whitehorn                                         ((  UINT8 *)(void *)(d))[3] = ((UINT8 *)(void *)(s))[3];\
299ddbd7b91SNathan Whitehorn                                         ((  UINT8 *)(void *)(d))[4] = ((UINT8 *)(void *)(s))[4];\
300ddbd7b91SNathan Whitehorn                                         ((  UINT8 *)(void *)(d))[5] = ((UINT8 *)(void *)(s))[5];\
301ddbd7b91SNathan Whitehorn                                         ((  UINT8 *)(void *)(d))[6] = ((UINT8 *)(void *)(s))[6];\
302ddbd7b91SNathan Whitehorn                                         ((  UINT8 *)(void *)(d))[7] = ((UINT8 *)(void *)(s))[7];}
303ddbd7b91SNathan Whitehorn#endif
304ddbd7b91SNathan Whitehorn#endif
305ddbd7b91SNathan Whitehorn
306ddbd7b91SNathan Whitehorn
307ddbd7b91SNathan Whitehorn/*
308ddbd7b91SNathan Whitehorn * Fast power-of-two math macros for non-optimized compilers
309ddbd7b91SNathan Whitehorn */
310cfd62a38SJérôme Duval#define _ACPI_DIV(value, PowerOf2)      ((UINT32) ((value) >> (PowerOf2)))
311cfd62a38SJérôme Duval#define _ACPI_MUL(value, PowerOf2)      ((UINT32) ((value) << (PowerOf2)))
312cfd62a38SJérôme Duval#define _ACPI_MOD(value, Divisor)       ((UINT32) ((value) & ((Divisor) -1)))
313ddbd7b91SNathan Whitehorn
314cfd62a38SJérôme Duval#define ACPI_DIV_2(a)                   _ACPI_DIV(a, 1)
315cfd62a38SJérôme Duval#define ACPI_MUL_2(a)                   _ACPI_MUL(a, 1)
316cfd62a38SJérôme Duval#define ACPI_MOD_2(a)                   _ACPI_MOD(a, 2)
317ddbd7b91SNathan Whitehorn
318cfd62a38SJérôme Duval#define ACPI_DIV_4(a)                   _ACPI_DIV(a, 2)
319cfd62a38SJérôme Duval#define ACPI_MUL_4(a)                   _ACPI_MUL(a, 2)
320cfd62a38SJérôme Duval#define ACPI_MOD_4(a)                   _ACPI_MOD(a, 4)
321ddbd7b91SNathan Whitehorn
322cfd62a38SJérôme Duval#define ACPI_DIV_8(a)                   _ACPI_DIV(a, 3)
323cfd62a38SJérôme Duval#define ACPI_MUL_8(a)                   _ACPI_MUL(a, 3)
324cfd62a38SJérôme Duval#define ACPI_MOD_8(a)                   _ACPI_MOD(a, 8)
325ddbd7b91SNathan Whitehorn
326cfd62a38SJérôme Duval#define ACPI_DIV_16(a)                  _ACPI_DIV(a, 4)
327cfd62a38SJérôme Duval#define ACPI_MUL_16(a)                  _ACPI_MUL(a, 4)
328cfd62a38SJérôme Duval#define ACPI_MOD_16(a)                  _ACPI_MOD(a, 16)
329ddbd7b91SNathan Whitehorn
330cfd62a38SJérôme Duval#define ACPI_DIV_32(a)                  _ACPI_DIV(a, 5)
331cfd62a38SJérôme Duval#define ACPI_MUL_32(a)                  _ACPI_MUL(a, 5)
332cfd62a38SJérôme Duval#define ACPI_MOD_32(a)                  _ACPI_MOD(a, 32)
333ddbd7b91SNathan Whitehorn
334e226d1d0SFredrik Holmqvist/* Test for ASCII character */
335e226d1d0SFredrik Holmqvist
336e226d1d0SFredrik Holmqvist#define ACPI_IS_ASCII(c)                ((c) < 0x80)
337e226d1d0SFredrik Holmqvist
338e226d1d0SFredrik Holmqvist/* Signed integers */
339e226d1d0SFredrik Holmqvist
340e226d1d0SFredrik Holmqvist#define ACPI_SIGN_POSITIVE              0
341e226d1d0SFredrik Holmqvist#define ACPI_SIGN_NEGATIVE              1
342e226d1d0SFredrik Holmqvist
343e226d1d0SFredrik Holmqvist
344ddbd7b91SNathan Whitehorn/*
345ddbd7b91SNathan Whitehorn * Rounding macros (Power of two boundaries only)
346ddbd7b91SNathan Whitehorn */
347cfd62a38SJérôme Duval#define ACPI_ROUND_DOWN(value, boundary)    (((ACPI_SIZE)(value)) & \
34845e9de08SJérôme Duval                                                (~(((ACPI_SIZE) boundary)-1)))
349ddbd7b91SNathan Whitehorn
350cfd62a38SJérôme Duval#define ACPI_ROUND_UP(value, boundary)      ((((ACPI_SIZE)(value)) + \
35145e9de08SJérôme Duval                                                (((ACPI_SIZE) boundary)-1)) & \
35245e9de08SJérôme Duval                                                (~(((ACPI_SIZE) boundary)-1)))
353ddbd7b91SNathan Whitehorn
35445e9de08SJérôme Duval/* Note: sizeof(ACPI_SIZE) evaluates to either 4 or 8 (32- vs 64-bit mode) */
355ddbd7b91SNathan Whitehorn
356cfd62a38SJérôme Duval#define ACPI_ROUND_DOWN_TO_32BIT(a)         ACPI_ROUND_DOWN(a, 4)
357cfd62a38SJérôme Duval#define ACPI_ROUND_DOWN_TO_64BIT(a)         ACPI_ROUND_DOWN(a, 8)
358cfd62a38SJérôme Duval#define ACPI_ROUND_DOWN_TO_NATIVE_WORD(a)   ACPI_ROUND_DOWN(a, sizeof(ACPI_SIZE))
359ddbd7b91SNathan Whitehorn
360cfd62a38SJérôme Duval#define ACPI_ROUND_UP_TO_32BIT(a)           ACPI_ROUND_UP(a, 4)
361cfd62a38SJérôme Duval#define ACPI_ROUND_UP_TO_64BIT(a)           ACPI_ROUND_UP(a, 8)
362cfd62a38SJérôme Duval#define ACPI_ROUND_UP_TO_NATIVE_WORD(a)     ACPI_ROUND_UP(a, sizeof(ACPI_SIZE))
363ddbd7b91SNathan Whitehorn
36443547dbeSJérôme Duval#define ACPI_ROUND_BITS_UP_TO_BYTES(a)      ACPI_DIV_8((a) + 7)
36543547dbeSJérôme Duval#define ACPI_ROUND_BITS_DOWN_TO_BYTES(a)    ACPI_DIV_8((a))
36643547dbeSJérôme Duval
36743547dbeSJérôme Duval#define ACPI_ROUND_UP_TO_1K(a)              (((a) + 1023) >> 10)
368ddbd7b91SNathan Whitehorn
369ddbd7b91SNathan Whitehorn/* Generic (non-power-of-two) rounding */
370ddbd7b91SNathan Whitehorn
371cfd62a38SJérôme Duval#define ACPI_ROUND_UP_TO(value, boundary)   (((value) + ((boundary)-1)) / (boundary))
37243547dbeSJérôme Duval
373cfd62a38SJérôme Duval#define ACPI_IS_MISALIGNED(value)           (((ACPI_SIZE) value) & (sizeof(ACPI_SIZE)-1))
374ddbd7b91SNathan Whitehorn
375ff2e2f81SFredrik Holmqvist/* Generic bit manipulation */
376ff2e2f81SFredrik Holmqvist
377ff2e2f81SFredrik Holmqvist#ifndef ACPI_USE_NATIVE_BIT_FINDER
378ff2e2f81SFredrik Holmqvist
379ff2e2f81SFredrik Holmqvist#define __ACPI_FIND_LAST_BIT_2(a, r)        ((((UINT8)  (a)) & 0x02) ? (r)+1 : (r))
380ff2e2f81SFredrik Holmqvist#define __ACPI_FIND_LAST_BIT_4(a, r)        ((((UINT8)  (a)) & 0x0C) ? \
381ff2e2f81SFredrik Holmqvist                                             __ACPI_FIND_LAST_BIT_2  ((a)>>2,  (r)+2) : \
382ff2e2f81SFredrik Holmqvist                                             __ACPI_FIND_LAST_BIT_2  ((a), (r)))
383ff2e2f81SFredrik Holmqvist#define __ACPI_FIND_LAST_BIT_8(a, r)        ((((UINT8)  (a)) & 0xF0) ? \
384ff2e2f81SFredrik Holmqvist                                             __ACPI_FIND_LAST_BIT_4  ((a)>>4,  (r)+4) : \
385ff2e2f81SFredrik Holmqvist                                             __ACPI_FIND_LAST_BIT_4  ((a), (r)))
386ff2e2f81SFredrik Holmqvist#define __ACPI_FIND_LAST_BIT_16(a, r)       ((((UINT16) (a)) & 0xFF00) ? \
387ff2e2f81SFredrik Holmqvist                                             __ACPI_FIND_LAST_BIT_8  ((a)>>8,  (r)+8) : \
388ff2e2f81SFredrik Holmqvist                                             __ACPI_FIND_LAST_BIT_8  ((a), (r)))
389ff2e2f81SFredrik Holmqvist#define __ACPI_FIND_LAST_BIT_32(a, r)       ((((UINT32) (a)) & 0xFFFF0000) ? \
390ff2e2f81SFredrik Holmqvist                                             __ACPI_FIND_LAST_BIT_16 ((a)>>16, (r)+16) : \
391ff2e2f81SFredrik Holmqvist                                             __ACPI_FIND_LAST_BIT_16 ((a), (r)))
392ff2e2f81SFredrik Holmqvist#define __ACPI_FIND_LAST_BIT_64(a, r)       ((((UINT64) (a)) & 0xFFFFFFFF00000000) ? \
393ff2e2f81SFredrik Holmqvist                                             __ACPI_FIND_LAST_BIT_32 ((a)>>32, (r)+32) : \
394ff2e2f81SFredrik Holmqvist                                             __ACPI_FIND_LAST_BIT_32 ((a), (r)))
395ff2e2f81SFredrik Holmqvist
396ff2e2f81SFredrik Holmqvist#define ACPI_FIND_LAST_BIT_8(a)             ((a) ? __ACPI_FIND_LAST_BIT_8 (a, 1) : 0)
397ff2e2f81SFredrik Holmqvist#define ACPI_FIND_LAST_BIT_16(a)            ((a) ? __ACPI_FIND_LAST_BIT_16 (a, 1) : 0)
398ff2e2f81SFredrik Holmqvist#define ACPI_FIND_LAST_BIT_32(a)            ((a) ? __ACPI_FIND_LAST_BIT_32 (a, 1) : 0)
399ff2e2f81SFredrik Holmqvist#define ACPI_FIND_LAST_BIT_64(a)            ((a) ? __ACPI_FIND_LAST_BIT_64 (a, 1) : 0)
400ff2e2f81SFredrik Holmqvist
401ff2e2f81SFredrik Holmqvist#define __ACPI_FIND_FIRST_BIT_2(a, r)       ((((UINT8) (a)) & 0x01) ? (r) : (r)+1)
402ff2e2f81SFredrik Holmqvist#define __ACPI_FIND_FIRST_BIT_4(a, r)       ((((UINT8) (a)) & 0x03) ? \
403ff2e2f81SFredrik Holmqvist                                             __ACPI_FIND_FIRST_BIT_2  ((a), (r)) : \
404ff2e2f81SFredrik Holmqvist                                             __ACPI_FIND_FIRST_BIT_2  ((a)>>2, (r)+2))
405ff2e2f81SFredrik Holmqvist#define __ACPI_FIND_FIRST_BIT_8(a, r)       ((((UINT8) (a)) & 0x0F) ? \
406ff2e2f81SFredrik Holmqvist                                             __ACPI_FIND_FIRST_BIT_4  ((a), (r)) : \
407ff2e2f81SFredrik Holmqvist                                             __ACPI_FIND_FIRST_BIT_4  ((a)>>4, (r)+4))
408ff2e2f81SFredrik Holmqvist#define __ACPI_FIND_FIRST_BIT_16(a, r)      ((((UINT16) (a)) & 0x00FF) ? \
409ff2e2f81SFredrik Holmqvist                                             __ACPI_FIND_FIRST_BIT_8  ((a), (r)) : \
410ff2e2f81SFredrik Holmqvist                                             __ACPI_FIND_FIRST_BIT_8  ((a)>>8, (r)+8))
411ff2e2f81SFredrik Holmqvist#define __ACPI_FIND_FIRST_BIT_32(a, r)      ((((UINT32) (a)) & 0x0000FFFF) ? \
412ff2e2f81SFredrik Holmqvist                                             __ACPI_FIND_FIRST_BIT_16 ((a), (r)) : \
413ff2e2f81SFredrik Holmqvist                                             __ACPI_FIND_FIRST_BIT_16 ((a)>>16, (r)+16))
414ff2e2f81SFredrik Holmqvist#define __ACPI_FIND_FIRST_BIT_64(a, r)      ((((UINT64) (a)) & 0x00000000FFFFFFFF) ? \
415ff2e2f81SFredrik Holmqvist                                             __ACPI_FIND_FIRST_BIT_32 ((a), (r)) : \
416ff2e2f81SFredrik Holmqvist                                             __ACPI_FIND_FIRST_BIT_32 ((a)>>32, (r)+32))
417ff2e2f81SFredrik Holmqvist
418ff2e2f81SFredrik Holmqvist#define ACPI_FIND_FIRST_BIT_8(a)            ((a) ? __ACPI_FIND_FIRST_BIT_8 (a, 1) : 0)
419ff2e2f81SFredrik Holmqvist#define ACPI_FIND_FIRST_BIT_16(a)           ((a) ? __ACPI_FIND_FIRST_BIT_16 (a, 1) : 0)
420ff2e2f81SFredrik Holmqvist#define ACPI_FIND_FIRST_BIT_32(a)           ((a) ? __ACPI_FIND_FIRST_BIT_32 (a, 1) : 0)
421ff2e2f81SFredrik Holmqvist#define ACPI_FIND_FIRST_BIT_64(a)           ((a) ? __ACPI_FIND_FIRST_BIT_64 (a, 1) : 0)
422ff2e2f81SFredrik Holmqvist
423ff2e2f81SFredrik Holmqvist#endif /* ACPI_USE_NATIVE_BIT_FINDER */
424ff2e2f81SFredrik Holmqvist
425ff2e2f81SFredrik Holmqvist/* Generic (power-of-two) rounding */
426ff2e2f81SFredrik Holmqvist
427ff2e2f81SFredrik Holmqvist#define ACPI_ROUND_UP_POWER_OF_TWO_8(a)     ((UINT8) \
428ff2e2f81SFredrik Holmqvist                                            (((UINT16) 1) <<  ACPI_FIND_LAST_BIT_8  ((a)  - 1)))
429ff2e2f81SFredrik Holmqvist#define ACPI_ROUND_DOWN_POWER_OF_TWO_8(a)   ((UINT8) \
430ff2e2f81SFredrik Holmqvist                                            (((UINT16) 1) << (ACPI_FIND_LAST_BIT_8  ((a)) - 1)))
431ff2e2f81SFredrik Holmqvist#define ACPI_ROUND_UP_POWER_OF_TWO_16(a)    ((UINT16) \
432ff2e2f81SFredrik Holmqvist                                            (((UINT32) 1) <<  ACPI_FIND_LAST_BIT_16 ((a)  - 1)))
433ff2e2f81SFredrik Holmqvist#define ACPI_ROUND_DOWN_POWER_OF_TWO_16(a)  ((UINT16) \
434ff2e2f81SFredrik Holmqvist                                            (((UINT32) 1) << (ACPI_FIND_LAST_BIT_16 ((a)) - 1)))
435ff2e2f81SFredrik Holmqvist#define ACPI_ROUND_UP_POWER_OF_TWO_32(a)    ((UINT32) \
436ff2e2f81SFredrik Holmqvist                                            (((UINT64) 1) <<  ACPI_FIND_LAST_BIT_32 ((a)  - 1)))
437ff2e2f81SFredrik Holmqvist#define ACPI_ROUND_DOWN_POWER_OF_TWO_32(a)  ((UINT32) \
438ff2e2f81SFredrik Holmqvist                                            (((UINT64) 1) << (ACPI_FIND_LAST_BIT_32 ((a)) - 1)))
439ff2e2f81SFredrik Holmqvist#define ACPI_IS_ALIGNED(a, s)               (((a) & ((s) - 1)) == 0)
440ff2e2f81SFredrik Holmqvist#define ACPI_IS_POWER_OF_TWO(a)             ACPI_IS_ALIGNED(a, a)
441ff2e2f81SFredrik Holmqvist
442ddbd7b91SNathan Whitehorn/*
443ddbd7b91SNathan Whitehorn * Bitmask creation
444ddbd7b91SNathan Whitehorn * Bit positions start at zero.
445ddbd7b91SNathan Whitehorn * MASK_BITS_ABOVE creates a mask starting AT the position and above
446ddbd7b91SNathan Whitehorn * MASK_BITS_BELOW creates a mask starting one bit BELOW the position
447ff2e2f81SFredrik Holmqvist * MASK_BITS_ABOVE/BELOW accepts a bit offset to create a mask
448ff2e2f81SFredrik Holmqvist * MASK_BITS_ABOVE/BELOW_32/64 accepts a bit width to create a mask
449ff2e2f81SFredrik Holmqvist * Note: The ACPI_INTEGER_BIT_SIZE check is used to bypass compiler
450ff2e2f81SFredrik Holmqvist * differences with the shift operator
451ddbd7b91SNathan Whitehorn */
45257c418cdSFredrik Holmqvist#define ACPI_MASK_BITS_ABOVE(position)      (~((ACPI_UINT64_MAX) << ((UINT32) (position))))
45357c418cdSFredrik Holmqvist#define ACPI_MASK_BITS_BELOW(position)      ((ACPI_UINT64_MAX) << ((UINT32) (position)))
454ff2e2f81SFredrik Holmqvist#define ACPI_MASK_BITS_ABOVE_32(width)      ((UINT32) ACPI_MASK_BITS_ABOVE(width))
455ff2e2f81SFredrik Holmqvist#define ACPI_MASK_BITS_BELOW_32(width)      ((UINT32) ACPI_MASK_BITS_BELOW(width))
456ff2e2f81SFredrik Holmqvist#define ACPI_MASK_BITS_ABOVE_64(width)      ((width) == ACPI_INTEGER_BIT_SIZE ? \
457ff2e2f81SFredrik Holmqvist                                                ACPI_UINT64_MAX : \
458ff2e2f81SFredrik Holmqvist                                                ACPI_MASK_BITS_ABOVE(width))
459ff2e2f81SFredrik Holmqvist#define ACPI_MASK_BITS_BELOW_64(width)      ((width) == ACPI_INTEGER_BIT_SIZE ? \
460ff2e2f81SFredrik Holmqvist                                                (UINT64) 0 : \
461ff2e2f81SFredrik Holmqvist                                                ACPI_MASK_BITS_BELOW(width))
462ddbd7b91SNathan Whitehorn
463ddbd7b91SNathan Whitehorn/* Bitfields within ACPI registers */
464ddbd7b91SNathan Whitehorn
4659b0d045cSFredrik Holmqvist#define ACPI_REGISTER_PREPARE_BITS(Val, Pos, Mask) \
4669b0d045cSFredrik Holmqvist    ((Val << Pos) & Mask)
467ddbd7b91SNathan Whitehorn
4689b0d045cSFredrik Holmqvist#define ACPI_REGISTER_INSERT_VALUE(Reg, Pos, Mask, Val) \
4699b0d045cSFredrik Holmqvist    Reg = (Reg & (~(Mask))) | ACPI_REGISTER_PREPARE_BITS(Val, Pos, Mask)
4709b0d045cSFredrik Holmqvist
4719b0d045cSFredrik Holmqvist#define ACPI_INSERT_BITS(Target, Mask, Source) \
4729b0d045cSFredrik Holmqvist    Target = ((Target & (~(Mask))) | (Source & Mask))
4739b0d045cSFredrik Holmqvist
4749b0d045cSFredrik Holmqvist/* Generic bitfield macros and masks */
4759b0d045cSFredrik Holmqvist
4769b0d045cSFredrik Holmqvist#define ACPI_GET_BITS(SourcePtr, Position, Mask) \
47774ffd18dSFredrik Holmqvist    ((*(SourcePtr) >> (Position)) & (Mask))
4789b0d045cSFredrik Holmqvist
4799b0d045cSFredrik Holmqvist#define ACPI_SET_BITS(TargetPtr, Position, Mask, Value) \
48074ffd18dSFredrik Holmqvist    (*(TargetPtr) |= (((Value) & (Mask)) << (Position)))
4819b0d045cSFredrik Holmqvist
4829b0d045cSFredrik Holmqvist#define ACPI_1BIT_MASK      0x00000001
4839b0d045cSFredrik Holmqvist#define ACPI_2BIT_MASK      0x00000003
4849b0d045cSFredrik Holmqvist#define ACPI_3BIT_MASK      0x00000007
4859b0d045cSFredrik Holmqvist#define ACPI_4BIT_MASK      0x0000000F
4869b0d045cSFredrik Holmqvist#define ACPI_5BIT_MASK      0x0000001F
4879b0d045cSFredrik Holmqvist#define ACPI_6BIT_MASK      0x0000003F
4889b0d045cSFredrik Holmqvist#define ACPI_7BIT_MASK      0x0000007F
4899b0d045cSFredrik Holmqvist#define ACPI_8BIT_MASK      0x000000FF
4909b0d045cSFredrik Holmqvist#define ACPI_16BIT_MASK     0x0000FFFF
4919b0d045cSFredrik Holmqvist#define ACPI_24BIT_MASK     0x00FFFFFF
49239d02f89SJérôme Duval
493c70258b7SJérôme Duval/* Macros to extract flag bits from position zero */
494c70258b7SJérôme Duval
495c70258b7SJérôme Duval#define ACPI_GET_1BIT_FLAG(Value)                   ((Value) & ACPI_1BIT_MASK)
496c70258b7SJérôme Duval#define ACPI_GET_2BIT_FLAG(Value)                   ((Value) & ACPI_2BIT_MASK)
497c70258b7SJérôme Duval#define ACPI_GET_3BIT_FLAG(Value)                   ((Value) & ACPI_3BIT_MASK)
498c70258b7SJérôme Duval#define ACPI_GET_4BIT_FLAG(Value)                   ((Value) & ACPI_4BIT_MASK)
499c70258b7SJérôme Duval
500c70258b7SJérôme Duval/* Macros to extract flag bits from position one and above */
501c70258b7SJérôme Duval
502c70258b7SJérôme Duval#define ACPI_EXTRACT_1BIT_FLAG(Field, Position)     (ACPI_GET_1BIT_FLAG ((Field) >> Position))
503c70258b7SJérôme Duval#define ACPI_EXTRACT_2BIT_FLAG(Field, Position)     (ACPI_GET_2BIT_FLAG ((Field) >> Position))
504c70258b7SJérôme Duval#define ACPI_EXTRACT_3BIT_FLAG(Field, Position)     (ACPI_GET_3BIT_FLAG ((Field) >> Position))
505c70258b7SJérôme Duval#define ACPI_EXTRACT_4BIT_FLAG(Field, Position)     (ACPI_GET_4BIT_FLAG ((Field) >> Position))
506c70258b7SJérôme Duval
507c70258b7SJérôme Duval/* ACPI Pathname helpers */
508c70258b7SJérôme Duval
509c70258b7SJérôme Duval#define ACPI_IS_ROOT_PREFIX(c)      ((c) == (UINT8) 0x5C) /* Backslash */
510c70258b7SJérôme Duval#define ACPI_IS_PARENT_PREFIX(c)    ((c) == (UINT8) 0x5E) /* Carat */
511c70258b7SJérôme Duval#define ACPI_IS_PATH_SEPARATOR(c)   ((c) == (UINT8) 0x2E) /* Period (dot) */
512c70258b7SJérôme Duval
513ddbd7b91SNathan Whitehorn/*
5146822cda0SFredrik Holmqvist * An object of type ACPI_NAMESPACE_NODE can appear in some contexts
5156822cda0SFredrik Holmqvist * where a pointer to an object of type ACPI_OPERAND_OBJECT can also
516cfd62a38SJérôme Duval * appear. This macro is used to distinguish them.
517ddbd7b91SNathan Whitehorn *
518c70258b7SJérôme Duval * The "DescriptorType" field is the second field in both structures.
519ddbd7b91SNathan Whitehorn */
520c70258b7SJérôme Duval#define ACPI_GET_DESCRIPTOR_PTR(d)      (((ACPI_DESCRIPTOR *)(void *)(d))->Common.CommonPointer)
521c70258b7SJérôme Duval#define ACPI_SET_DESCRIPTOR_PTR(d, p)   (((ACPI_DESCRIPTOR *)(void *)(d))->Common.CommonPointer = (p))
52243547dbeSJérôme Duval#define ACPI_GET_DESCRIPTOR_TYPE(d)     (((ACPI_DESCRIPTOR *)(void *)(d))->Common.DescriptorType)
523c70258b7SJérôme Duval#define ACPI_SET_DESCRIPTOR_TYPE(d, t)  (((ACPI_DESCRIPTOR *)(void *)(d))->Common.DescriptorType = (t))
524ddbd7b91SNathan Whitehorn
525ddbd7b91SNathan Whitehorn/*
526ddbd7b91SNathan Whitehorn * Macros for the master AML opcode table
527ddbd7b91SNathan Whitehorn */
528cfd62a38SJérôme Duval#if defined (ACPI_DISASSEMBLER) || defined (ACPI_DEBUG_OUTPUT)
529cfd62a38SJérôme Duval#define ACPI_OP(Name, PArgs, IArgs, ObjType, Class, Type, Flags) \
530cfd62a38SJérôme Duval    {Name, (UINT32)(PArgs), (UINT32)(IArgs), (UINT32)(Flags), ObjType, Class, Type}
531ddbd7b91SNathan Whitehorn#else
532cfd62a38SJérôme Duval#define ACPI_OP(Name, PArgs, IArgs, ObjType, Class, Type, Flags) \
533cfd62a38SJérôme Duval    {(UINT32)(PArgs), (UINT32)(IArgs), (UINT32)(Flags), ObjType, Class, Type}
534ddbd7b91SNathan Whitehorn#endif
535ddbd7b91SNathan Whitehorn
536ddbd7b91SNathan Whitehorn#define ARG_TYPE_WIDTH                  5
537ddbd7b91SNathan Whitehorn#define ARG_1(x)                        ((UINT32)(x))
538ddbd7b91SNathan Whitehorn#define ARG_2(x)                        ((UINT32)(x) << (1 * ARG_TYPE_WIDTH))
539ddbd7b91SNathan Whitehorn#define ARG_3(x)                        ((UINT32)(x) << (2 * ARG_TYPE_WIDTH))
540ddbd7b91SNathan Whitehorn#define ARG_4(x)                        ((UINT32)(x) << (3 * ARG_TYPE_WIDTH))
541ddbd7b91SNathan Whitehorn#define ARG_5(x)                        ((UINT32)(x) << (4 * ARG_TYPE_WIDTH))
542ddbd7b91SNathan Whitehorn#define ARG_6(x)                        ((UINT32)(x) << (5 * ARG_TYPE_WIDTH))
543ddbd7b91SNathan Whitehorn
544ddbd7b91SNathan Whitehorn#define ARGI_LIST1(a)                   (ARG_1(a))
545cfd62a38SJérôme Duval#define ARGI_LIST2(a, b)                (ARG_1(b)|ARG_2(a))
546cfd62a38SJérôme Duval#define ARGI_LIST3(a, b, c)             (ARG_1(c)|ARG_2(b)|ARG_3(a))
547cfd62a38SJérôme Duval#define ARGI_LIST4(a, b, c, d)          (ARG_1(d)|ARG_2(c)|ARG_3(b)|ARG_4(a))
548cfd62a38SJérôme Duval#define ARGI_LIST5(a, b, c, d, e)       (ARG_1(e)|ARG_2(d)|ARG_3(c)|ARG_4(b)|ARG_5(a))
549cfd62a38SJérôme Duval#define ARGI_LIST6(a, b, c, d, e, f)    (ARG_1(f)|ARG_2(e)|ARG_3(d)|ARG_4(c)|ARG_5(b)|ARG_6(a))
550ddbd7b91SNathan Whitehorn
551ddbd7b91SNathan Whitehorn#define ARGP_LIST1(a)                   (ARG_1(a))
552cfd62a38SJérôme Duval#define ARGP_LIST2(a, b)                (ARG_1(a)|ARG_2(b))
553cfd62a38SJérôme Duval#define ARGP_LIST3(a, b, c)             (ARG_1(a)|ARG_2(b)|ARG_3(c))
554cfd62a38SJérôme Duval#define ARGP_LIST4(a, b, c, d)          (ARG_1(a)|ARG_2(b)|ARG_3(c)|ARG_4(d))
555cfd62a38SJérôme Duval#define ARGP_LIST5(a, b, c, d, e)       (ARG_1(a)|ARG_2(b)|ARG_3(c)|ARG_4(d)|ARG_5(e))
556cfd62a38SJérôme Duval#define ARGP_LIST6(a, b, c, d, e, f)    (ARG_1(a)|ARG_2(b)|ARG_3(c)|ARG_4(d)|ARG_5(e)|ARG_6(f))
557ddbd7b91SNathan Whitehorn
558ddbd7b91SNathan Whitehorn#define GET_CURRENT_ARG_TYPE(List)      (List & ((UINT32) 0x1F))
559ddbd7b91SNathan Whitehorn#define INCREMENT_ARG_LIST(List)        (List >>= ((UINT32) ARG_TYPE_WIDTH))
560ddbd7b91SNathan Whitehorn
561ddbd7b91SNathan Whitehorn/*
56243547dbeSJérôme Duval * Ascii error messages can be configured out
563ddbd7b91SNathan Whitehorn */
56443547dbeSJérôme Duval#ifndef ACPI_NO_ERROR_MESSAGES
56543547dbeSJérôme Duval/*
566ff2e2f81SFredrik Holmqvist * Error reporting. The callers module and line number are inserted by AE_INFO,
56743547dbeSJérôme Duval * the plist contains a set of parens to allow variable-length lists.
56843547dbeSJérôme Duval * These macros are used for both the debug and non-debug versions of the code.
56943547dbeSJérôme Duval */
570ff2e2f81SFredrik Holmqvist#define ACPI_ERROR_NAMESPACE(s, p, e)       AcpiUtPrefixedNamespaceError (AE_INFO, s, p, e);
571c70258b7SJérôme Duval#define ACPI_ERROR_METHOD(s, n, p, e)       AcpiUtMethodError (AE_INFO, s, n, p, e);
572c70258b7SJérôme Duval#define ACPI_WARN_PREDEFINED(plist)         AcpiUtPredefinedWarning plist
573c70258b7SJérôme Duval#define ACPI_INFO_PREDEFINED(plist)         AcpiUtPredefinedInfo plist
574c70258b7SJérôme Duval#define ACPI_BIOS_ERROR_PREDEFINED(plist)   AcpiUtPredefinedBiosError plist
57508c9948cSFredrik Holmqvist#define ACPI_ERROR_ONLY(s)                  s
576ddbd7b91SNathan Whitehorn
577ddbd7b91SNathan Whitehorn#else
578ddbd7b91SNathan Whitehorn
57943547dbeSJérôme Duval/* No error messages */
580ddbd7b91SNathan Whitehorn
58108c9948cSFredrik Holmqvist#define ACPI_ERROR_NAMESPACE(s, p, e)
582cfd62a38SJérôme Duval#define ACPI_ERROR_METHOD(s, n, p, e)
58380377d9aSJérôme Duval#define ACPI_WARN_PREDEFINED(plist)
58457c418cdSFredrik Holmqvist#define ACPI_INFO_PREDEFINED(plist)
585c70258b7SJérôme Duval#define ACPI_BIOS_ERROR_PREDEFINED(plist)
58608c9948cSFredrik Holmqvist#define ACPI_ERROR_ONLY(s)
58780377d9aSJérôme Duval
58880377d9aSJérôme Duval#endif /* ACPI_NO_ERROR_MESSAGES */
589ddbd7b91SNathan Whitehorn
5906822cda0SFredrik Holmqvist#if (!ACPI_REDUCED_HARDWARE)
5916822cda0SFredrik Holmqvist#define ACPI_HW_OPTIONAL_FUNCTION(addr)     addr
5926822cda0SFredrik Holmqvist#else
5936822cda0SFredrik Holmqvist#define ACPI_HW_OPTIONAL_FUNCTION(addr)     NULL
5946822cda0SFredrik Holmqvist#endif
5956822cda0SFredrik Holmqvist
5966822cda0SFredrik Holmqvist
597cfd62a38SJérôme Duval/*
598cfd62a38SJérôme Duval * Macros used for ACPICA utilities only
599cfd62a38SJérôme Duval */
600cfd62a38SJérôme Duval
601cfd62a38SJérôme Duval/* Generate a UUID */
602cfd62a38SJérôme Duval
603cfd62a38SJérôme Duval#define ACPI_INIT_UUID(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \
604cfd62a38SJérôme Duval    (a) & 0xFF, ((a) >> 8) & 0xFF, ((a) >> 16) & 0xFF, ((a) >> 24) & 0xFF, \
605cfd62a38SJérôme Duval    (b) & 0xFF, ((b) >> 8) & 0xFF, \
606cfd62a38SJérôme Duval    (c) & 0xFF, ((c) >> 8) & 0xFF, \
607cfd62a38SJérôme Duval    (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7)
608cfd62a38SJérôme Duval
609cfd62a38SJérôme Duval#define ACPI_IS_OCTAL_DIGIT(d)              (((char)(d) >= '0') && ((char)(d) <= '7'))
610cfd62a38SJérôme Duval
611cfd62a38SJérôme Duval
612ff2e2f81SFredrik Holmqvist/*
613ff2e2f81SFredrik Holmqvist * Macors used for the ASL-/ASL+ converter utility
614ff2e2f81SFredrik Holmqvist */
615ff2e2f81SFredrik Holmqvist#ifdef ACPI_ASL_COMPILER
616ff2e2f81SFredrik Holmqvist
617ff2e2f81SFredrik Holmqvist#define ASL_CV_LABEL_FILENODE(a)         CvLabelFileNode(a);
618ff2e2f81SFredrik Holmqvist#define ASL_CV_CAPTURE_COMMENTS_ONLY(a)   CvCaptureCommentsOnly (a);
619ff2e2f81SFredrik Holmqvist#define ASL_CV_CAPTURE_COMMENTS(a)       CvCaptureComments (a);
620ff2e2f81SFredrik Holmqvist#define ASL_CV_TRANSFER_COMMENTS(a)      CvTransferComments (a);
621ff2e2f81SFredrik Holmqvist#define ASL_CV_CLOSE_PAREN(a,b)          CvCloseParenWriteComment(a,b);
622ff2e2f81SFredrik Holmqvist#define ASL_CV_CLOSE_BRACE(a,b)          CvCloseBraceWriteComment(a,b);
623ff2e2f81SFredrik Holmqvist#define ASL_CV_SWITCH_FILES(a,b)         CvSwitchFiles(a,b);
624ff2e2f81SFredrik Holmqvist#define ASL_CV_CLEAR_OP_COMMENTS(a)       CvClearOpComments(a);
625ff2e2f81SFredrik Holmqvist#define ASL_CV_PRINT_ONE_COMMENT(a,b,c,d) CvPrintOneCommentType (a,b,c,d);
626ff2e2f81SFredrik Holmqvist#define ASL_CV_PRINT_ONE_COMMENT_LIST(a,b) CvPrintOneCommentList (a,b);
627ff2e2f81SFredrik Holmqvist#define ASL_CV_FILE_HAS_SWITCHED(a)       CvFileHasSwitched(a)
628ff2e2f81SFredrik Holmqvist#define ASL_CV_INIT_FILETREE(a,b,c)      CvInitFileTree(a,b,c);
629ff2e2f81SFredrik Holmqvist
630ff2e2f81SFredrik Holmqvist#else
631ff2e2f81SFredrik Holmqvist
632ff2e2f81SFredrik Holmqvist#define ASL_CV_LABEL_FILENODE(a)
633ff2e2f81SFredrik Holmqvist#define ASL_CV_CAPTURE_COMMENTS_ONLY(a)
634ff2e2f81SFredrik Holmqvist#define ASL_CV_CAPTURE_COMMENTS(a)
635ff2e2f81SFredrik Holmqvist#define ASL_CV_TRANSFER_COMMENTS(a)
636ff2e2f81SFredrik Holmqvist#define ASL_CV_CLOSE_PAREN(a,b)          AcpiOsPrintf (")");
637ff2e2f81SFredrik Holmqvist#define ASL_CV_CLOSE_BRACE(a,b)          AcpiOsPrintf ("}");
638ff2e2f81SFredrik Holmqvist#define ASL_CV_SWITCH_FILES(a,b)
639ff2e2f81SFredrik Holmqvist#define ASL_CV_CLEAR_OP_COMMENTS(a)
640ff2e2f81SFredrik Holmqvist#define ASL_CV_PRINT_ONE_COMMENT(a,b,c,d)
641ff2e2f81SFredrik Holmqvist#define ASL_CV_PRINT_ONE_COMMENT_LIST(a,b)
642ff2e2f81SFredrik Holmqvist#define ASL_CV_FILE_HAS_SWITCHED(a)       0
643ff2e2f81SFredrik Holmqvist#define ASL_CV_INIT_FILETREE(a,b,c)
644ff2e2f81SFredrik Holmqvist
645ff2e2f81SFredrik Holmqvist#endif
646ff2e2f81SFredrik Holmqvist
647ddbd7b91SNathan Whitehorn#endif /* ACMACROS_H */
648