xref: /haiku/src/add-ons/kernel/bus_managers/acpi/acpica/components/executer/exutils.c (revision 6dde014f768e0ee49bae871ed857cf433837b9ff)
10174267aSFredrik Holmqvist /******************************************************************************
20174267aSFredrik Holmqvist  *
30174267aSFredrik Holmqvist  * Module Name: exutils - interpreter/scanner utilities
40174267aSFredrik Holmqvist  *
50174267aSFredrik Holmqvist  *****************************************************************************/
60174267aSFredrik Holmqvist 
70174267aSFredrik Holmqvist /******************************************************************************
80174267aSFredrik Holmqvist  *
90174267aSFredrik Holmqvist  * 1. Copyright Notice
100174267aSFredrik Holmqvist  *
11*6dde014fSPulkoMandy  * Some or all of this work - Copyright (c) 1999 - 2024, Intel Corp.
120174267aSFredrik Holmqvist  * All rights reserved.
130174267aSFredrik Holmqvist  *
140174267aSFredrik Holmqvist  * 2. License
150174267aSFredrik Holmqvist  *
160174267aSFredrik Holmqvist  * 2.1. This is your license from Intel Corp. under its intellectual property
170174267aSFredrik Holmqvist  * rights. You may have additional license terms from the party that provided
180174267aSFredrik Holmqvist  * you this software, covering your right to use that party's intellectual
190174267aSFredrik Holmqvist  * property rights.
200174267aSFredrik Holmqvist  *
210174267aSFredrik Holmqvist  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
220174267aSFredrik Holmqvist  * copy of the source code appearing in this file ("Covered Code") an
230174267aSFredrik Holmqvist  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
240174267aSFredrik Holmqvist  * base code distributed originally by Intel ("Original Intel Code") to copy,
250174267aSFredrik Holmqvist  * make derivatives, distribute, use and display any portion of the Covered
260174267aSFredrik Holmqvist  * Code in any form, with the right to sublicense such rights; and
270174267aSFredrik Holmqvist  *
280174267aSFredrik Holmqvist  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
290174267aSFredrik Holmqvist  * license (with the right to sublicense), under only those claims of Intel
300174267aSFredrik Holmqvist  * patents that are infringed by the Original Intel Code, to make, use, sell,
310174267aSFredrik Holmqvist  * offer to sell, and import the Covered Code and derivative works thereof
320174267aSFredrik Holmqvist  * solely to the minimum extent necessary to exercise the above copyright
330174267aSFredrik Holmqvist  * license, and in no event shall the patent license extend to any additions
340174267aSFredrik Holmqvist  * to or modifications of the Original Intel Code. No other license or right
350174267aSFredrik Holmqvist  * is granted directly or by implication, estoppel or otherwise;
360174267aSFredrik Holmqvist  *
370174267aSFredrik Holmqvist  * The above copyright and patent license is granted only if the following
380174267aSFredrik Holmqvist  * conditions are met:
390174267aSFredrik Holmqvist  *
400174267aSFredrik Holmqvist  * 3. Conditions
410174267aSFredrik Holmqvist  *
420174267aSFredrik Holmqvist  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
430174267aSFredrik Holmqvist  * Redistribution of source code of any substantial portion of the Covered
440174267aSFredrik Holmqvist  * Code or modification with rights to further distribute source must include
450174267aSFredrik Holmqvist  * the above Copyright Notice, the above License, this list of Conditions,
460174267aSFredrik Holmqvist  * and the following Disclaimer and Export Compliance provision. In addition,
470174267aSFredrik Holmqvist  * Licensee must cause all Covered Code to which Licensee contributes to
480174267aSFredrik Holmqvist  * contain a file documenting the changes Licensee made to create that Covered
490174267aSFredrik Holmqvist  * Code and the date of any change. Licensee must include in that file the
500174267aSFredrik Holmqvist  * documentation of any changes made by any predecessor Licensee. Licensee
510174267aSFredrik Holmqvist  * must include a prominent statement that the modification is derived,
520174267aSFredrik Holmqvist  * directly or indirectly, from Original Intel Code.
530174267aSFredrik Holmqvist  *
540174267aSFredrik Holmqvist  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
550174267aSFredrik Holmqvist  * Redistribution of source code of any substantial portion of the Covered
560174267aSFredrik Holmqvist  * Code or modification without rights to further distribute source must
570174267aSFredrik Holmqvist  * include the following Disclaimer and Export Compliance provision in the
580174267aSFredrik Holmqvist  * documentation and/or other materials provided with distribution. In
590174267aSFredrik Holmqvist  * addition, Licensee may not authorize further sublicense of source of any
600174267aSFredrik Holmqvist  * portion of the Covered Code, and must include terms to the effect that the
610174267aSFredrik Holmqvist  * license from Licensee to its licensee is limited to the intellectual
620174267aSFredrik Holmqvist  * property embodied in the software Licensee provides to its licensee, and
630174267aSFredrik Holmqvist  * not to intellectual property embodied in modifications its licensee may
640174267aSFredrik Holmqvist  * make.
650174267aSFredrik Holmqvist  *
660174267aSFredrik Holmqvist  * 3.3. Redistribution of Executable. Redistribution in executable form of any
670174267aSFredrik Holmqvist  * substantial portion of the Covered Code or modification must reproduce the
680174267aSFredrik Holmqvist  * above Copyright Notice, and the following Disclaimer and Export Compliance
690174267aSFredrik Holmqvist  * provision in the documentation and/or other materials provided with the
700174267aSFredrik Holmqvist  * distribution.
710174267aSFredrik Holmqvist  *
720174267aSFredrik Holmqvist  * 3.4. Intel retains all right, title, and interest in and to the Original
730174267aSFredrik Holmqvist  * Intel Code.
740174267aSFredrik Holmqvist  *
750174267aSFredrik Holmqvist  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
760174267aSFredrik Holmqvist  * Intel shall be used in advertising or otherwise to promote the sale, use or
770174267aSFredrik Holmqvist  * other dealings in products derived from or relating to the Covered Code
780174267aSFredrik Holmqvist  * without prior written authorization from Intel.
790174267aSFredrik Holmqvist  *
800174267aSFredrik Holmqvist  * 4. Disclaimer and Export Compliance
810174267aSFredrik Holmqvist  *
820174267aSFredrik Holmqvist  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
830174267aSFredrik Holmqvist  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
840174267aSFredrik Holmqvist  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
850174267aSFredrik Holmqvist  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
860174267aSFredrik Holmqvist  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
870174267aSFredrik Holmqvist  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
880174267aSFredrik Holmqvist  * PARTICULAR PURPOSE.
890174267aSFredrik Holmqvist  *
900174267aSFredrik Holmqvist  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
910174267aSFredrik Holmqvist  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
920174267aSFredrik Holmqvist  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
930174267aSFredrik Holmqvist  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
940174267aSFredrik Holmqvist  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
950174267aSFredrik Holmqvist  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
960174267aSFredrik Holmqvist  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
970174267aSFredrik Holmqvist  * LIMITED REMEDY.
980174267aSFredrik Holmqvist  *
990174267aSFredrik Holmqvist  * 4.3. Licensee shall not export, either directly or indirectly, any of this
1000174267aSFredrik Holmqvist  * software or system incorporating such software without first obtaining any
1010174267aSFredrik Holmqvist  * required license or other approval from the U. S. Department of Commerce or
1020174267aSFredrik Holmqvist  * any other agency or department of the United States Government. In the
1030174267aSFredrik Holmqvist  * event Licensee exports any such software from the United States or
1040174267aSFredrik Holmqvist  * re-exports any such software from a foreign destination, Licensee shall
1050174267aSFredrik Holmqvist  * ensure that the distribution and export/re-export of the software is in
1060174267aSFredrik Holmqvist  * compliance with all laws, regulations, orders, or other restrictions of the
1070174267aSFredrik Holmqvist  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
1080174267aSFredrik Holmqvist  * any of its subsidiaries will export/re-export any technical data, process,
1090174267aSFredrik Holmqvist  * software, or service, directly or indirectly, to any country for which the
1100174267aSFredrik Holmqvist  * United States government or any agency thereof requires an export license,
1110174267aSFredrik Holmqvist  * other governmental approval, or letter of assurance, without first obtaining
1120174267aSFredrik Holmqvist  * such license, approval or letter.
1130174267aSFredrik Holmqvist  *
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  *
1500174267aSFredrik Holmqvist  *****************************************************************************/
1510174267aSFredrik Holmqvist 
1520174267aSFredrik Holmqvist /*
1530174267aSFredrik Holmqvist  * DEFINE_AML_GLOBALS is tested in amlcode.h
1540174267aSFredrik Holmqvist  * to determine whether certain global names should be "defined" or only
1550174267aSFredrik Holmqvist  * "declared" in the current compilation. This enhances maintainability
1560174267aSFredrik Holmqvist  * by enabling a single header file to embody all knowledge of the names
1570174267aSFredrik Holmqvist  * in question.
1580174267aSFredrik Holmqvist  *
1590174267aSFredrik Holmqvist  * Exactly one module of any executable should #define DEFINE_GLOBALS
1600174267aSFredrik Holmqvist  * before #including the header files which use this convention. The
1610174267aSFredrik Holmqvist  * names in question will be defined and initialized in that module,
1620174267aSFredrik Holmqvist  * and declared as extern in all other modules which #include those
1630174267aSFredrik Holmqvist  * header files.
1640174267aSFredrik Holmqvist  */
1650174267aSFredrik Holmqvist 
1660174267aSFredrik Holmqvist #define DEFINE_AML_GLOBALS
1670174267aSFredrik Holmqvist 
1680174267aSFredrik Holmqvist #include "acpi.h"
1690174267aSFredrik Holmqvist #include "accommon.h"
1700174267aSFredrik Holmqvist #include "acinterp.h"
1710174267aSFredrik Holmqvist #include "amlcode.h"
1720174267aSFredrik Holmqvist 
1730174267aSFredrik Holmqvist #define _COMPONENT          ACPI_EXECUTER
1740174267aSFredrik Holmqvist         ACPI_MODULE_NAME    ("exutils")
1750174267aSFredrik Holmqvist 
1760174267aSFredrik Holmqvist /* Local prototypes */
1770174267aSFredrik Holmqvist 
1780174267aSFredrik Holmqvist static UINT32
1790174267aSFredrik Holmqvist AcpiExDigitsNeeded (
1800174267aSFredrik Holmqvist     UINT64                  Value,
1810174267aSFredrik Holmqvist     UINT32                  Base);
1820174267aSFredrik Holmqvist 
1830174267aSFredrik Holmqvist 
1840174267aSFredrik Holmqvist /*******************************************************************************
1850174267aSFredrik Holmqvist  *
1860174267aSFredrik Holmqvist  * FUNCTION:    AcpiExEnterInterpreter
1870174267aSFredrik Holmqvist  *
1880174267aSFredrik Holmqvist  * PARAMETERS:  None
1890174267aSFredrik Holmqvist  *
1900174267aSFredrik Holmqvist  * RETURN:      None
1910174267aSFredrik Holmqvist  *
1920174267aSFredrik Holmqvist  * DESCRIPTION: Enter the interpreter execution region. Failure to enter
1930174267aSFredrik Holmqvist  *              the interpreter region is a fatal system error. Used in
1940174267aSFredrik Holmqvist  *              conjunction with ExitInterpreter.
1950174267aSFredrik Holmqvist  *
1960174267aSFredrik Holmqvist  ******************************************************************************/
1970174267aSFredrik Holmqvist 
1980174267aSFredrik Holmqvist void
AcpiExEnterInterpreter(void)1990174267aSFredrik Holmqvist AcpiExEnterInterpreter (
2000174267aSFredrik Holmqvist     void)
2010174267aSFredrik Holmqvist {
2020174267aSFredrik Holmqvist     ACPI_STATUS             Status;
2030174267aSFredrik Holmqvist 
2040174267aSFredrik Holmqvist 
2050174267aSFredrik Holmqvist     ACPI_FUNCTION_TRACE (ExEnterInterpreter);
2060174267aSFredrik Holmqvist 
2070174267aSFredrik Holmqvist 
2080174267aSFredrik Holmqvist     Status = AcpiUtAcquireMutex (ACPI_MTX_INTERPRETER);
2090174267aSFredrik Holmqvist     if (ACPI_FAILURE (Status))
2100174267aSFredrik Holmqvist     {
2110174267aSFredrik Holmqvist         ACPI_ERROR ((AE_INFO, "Could not acquire AML Interpreter mutex"));
2120174267aSFredrik Holmqvist     }
213ff2e2f81SFredrik Holmqvist     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
214ff2e2f81SFredrik Holmqvist     if (ACPI_FAILURE (Status))
215ff2e2f81SFredrik Holmqvist     {
216ff2e2f81SFredrik Holmqvist         ACPI_ERROR ((AE_INFO, "Could not acquire AML Namespace mutex"));
217ff2e2f81SFredrik Holmqvist     }
2180174267aSFredrik Holmqvist 
2190174267aSFredrik Holmqvist     return_VOID;
2200174267aSFredrik Holmqvist }
2210174267aSFredrik Holmqvist 
2220174267aSFredrik Holmqvist 
2230174267aSFredrik Holmqvist /*******************************************************************************
2240174267aSFredrik Holmqvist  *
2250174267aSFredrik Holmqvist  * FUNCTION:    AcpiExExitInterpreter
2260174267aSFredrik Holmqvist  *
2270174267aSFredrik Holmqvist  * PARAMETERS:  None
2280174267aSFredrik Holmqvist  *
2290174267aSFredrik Holmqvist  * RETURN:      None
2300174267aSFredrik Holmqvist  *
2310174267aSFredrik Holmqvist  * DESCRIPTION: Exit the interpreter execution region. This is the top level
2320174267aSFredrik Holmqvist  *              routine used to exit the interpreter when all processing has
233ad5bbfb8SFredrik Holmqvist  *              been completed, or when the method blocks.
234ad5bbfb8SFredrik Holmqvist  *
235ad5bbfb8SFredrik Holmqvist  * Cases where the interpreter is unlocked internally:
236ad5bbfb8SFredrik Holmqvist  *      1) Method will be blocked on a Sleep() AML opcode
237ad5bbfb8SFredrik Holmqvist  *      2) Method will be blocked on an Acquire() AML opcode
238ad5bbfb8SFredrik Holmqvist  *      3) Method will be blocked on a Wait() AML opcode
239ad5bbfb8SFredrik Holmqvist  *      4) Method will be blocked to acquire the global lock
240ad5bbfb8SFredrik Holmqvist  *      5) Method will be blocked waiting to execute a serialized control
241ad5bbfb8SFredrik Holmqvist  *          method that is currently executing
242ad5bbfb8SFredrik Holmqvist  *      6) About to invoke a user-installed opregion handler
2430174267aSFredrik Holmqvist  *
2440174267aSFredrik Holmqvist  ******************************************************************************/
2450174267aSFredrik Holmqvist 
2460174267aSFredrik Holmqvist void
AcpiExExitInterpreter(void)2470174267aSFredrik Holmqvist AcpiExExitInterpreter (
2480174267aSFredrik Holmqvist     void)
2490174267aSFredrik Holmqvist {
2500174267aSFredrik Holmqvist     ACPI_STATUS             Status;
2510174267aSFredrik Holmqvist 
2520174267aSFredrik Holmqvist 
2530174267aSFredrik Holmqvist     ACPI_FUNCTION_TRACE (ExExitInterpreter);
2540174267aSFredrik Holmqvist 
2550174267aSFredrik Holmqvist 
256ff2e2f81SFredrik Holmqvist     Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
257ff2e2f81SFredrik Holmqvist     if (ACPI_FAILURE (Status))
258ff2e2f81SFredrik Holmqvist     {
259ff2e2f81SFredrik Holmqvist         ACPI_ERROR ((AE_INFO, "Could not release AML Namespace mutex"));
260ff2e2f81SFredrik Holmqvist     }
2610174267aSFredrik Holmqvist     Status = AcpiUtReleaseMutex (ACPI_MTX_INTERPRETER);
2620174267aSFredrik Holmqvist     if (ACPI_FAILURE (Status))
2630174267aSFredrik Holmqvist     {
2640174267aSFredrik Holmqvist         ACPI_ERROR ((AE_INFO, "Could not release AML Interpreter mutex"));
2650174267aSFredrik Holmqvist     }
2660174267aSFredrik Holmqvist 
2670174267aSFredrik Holmqvist     return_VOID;
2680174267aSFredrik Holmqvist }
2690174267aSFredrik Holmqvist 
2700174267aSFredrik Holmqvist 
2710174267aSFredrik Holmqvist /*******************************************************************************
2720174267aSFredrik Holmqvist  *
2730174267aSFredrik Holmqvist  * FUNCTION:    AcpiExTruncateFor32bitTable
2740174267aSFredrik Holmqvist  *
2750174267aSFredrik Holmqvist  * PARAMETERS:  ObjDesc         - Object to be truncated
2760174267aSFredrik Holmqvist  *
277c70258b7SJérôme Duval  * RETURN:      TRUE if a truncation was performed, FALSE otherwise.
2780174267aSFredrik Holmqvist  *
2790174267aSFredrik Holmqvist  * DESCRIPTION: Truncate an ACPI Integer to 32 bits if the execution mode is
2800174267aSFredrik Holmqvist  *              32-bit, as determined by the revision of the DSDT.
2810174267aSFredrik Holmqvist  *
2820174267aSFredrik Holmqvist  ******************************************************************************/
2830174267aSFredrik Holmqvist 
284c70258b7SJérôme Duval BOOLEAN
AcpiExTruncateFor32bitTable(ACPI_OPERAND_OBJECT * ObjDesc)2850174267aSFredrik Holmqvist AcpiExTruncateFor32bitTable (
2860174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     *ObjDesc)
2870174267aSFredrik Holmqvist {
2880174267aSFredrik Holmqvist 
2890174267aSFredrik Holmqvist     ACPI_FUNCTION_ENTRY ();
2900174267aSFredrik Holmqvist 
2910174267aSFredrik Holmqvist 
2920174267aSFredrik Holmqvist     /*
2930174267aSFredrik Holmqvist      * Object must be a valid number and we must be executing
294c70258b7SJérôme Duval      * a control method. Object could be NS node for AML_INT_NAMEPATH_OP.
2950174267aSFredrik Holmqvist      */
2960174267aSFredrik Holmqvist     if ((!ObjDesc) ||
2970174267aSFredrik Holmqvist         (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) != ACPI_DESC_TYPE_OPERAND) ||
2980174267aSFredrik Holmqvist         (ObjDesc->Common.Type != ACPI_TYPE_INTEGER))
2990174267aSFredrik Holmqvist     {
300c70258b7SJérôme Duval         return (FALSE);
3010174267aSFredrik Holmqvist     }
3020174267aSFredrik Holmqvist 
303c70258b7SJérôme Duval     if ((AcpiGbl_IntegerByteWidth == 4) &&
304c70258b7SJérôme Duval         (ObjDesc->Integer.Value > (UINT64) ACPI_UINT32_MAX))
3050174267aSFredrik Holmqvist     {
3060174267aSFredrik Holmqvist         /*
307b64e8511SFredrik Holmqvist          * We are executing in a 32-bit ACPI table. Truncate
308b64e8511SFredrik Holmqvist          * the value to 32 bits by zeroing out the upper 32-bit field
3090174267aSFredrik Holmqvist          */
3100174267aSFredrik Holmqvist         ObjDesc->Integer.Value &= (UINT64) ACPI_UINT32_MAX;
311c70258b7SJérôme Duval         return (TRUE);
3120174267aSFredrik Holmqvist     }
313c70258b7SJérôme Duval 
314c70258b7SJérôme Duval     return (FALSE);
3150174267aSFredrik Holmqvist }
3160174267aSFredrik Holmqvist 
3170174267aSFredrik Holmqvist 
3180174267aSFredrik Holmqvist /*******************************************************************************
3190174267aSFredrik Holmqvist  *
3200174267aSFredrik Holmqvist  * FUNCTION:    AcpiExAcquireGlobalLock
3210174267aSFredrik Holmqvist  *
3220174267aSFredrik Holmqvist  * PARAMETERS:  FieldFlags            - Flags with Lock rule:
3230174267aSFredrik Holmqvist  *                                      AlwaysLock or NeverLock
3240174267aSFredrik Holmqvist  *
3250174267aSFredrik Holmqvist  * RETURN:      None
3260174267aSFredrik Holmqvist  *
3270174267aSFredrik Holmqvist  * DESCRIPTION: Obtain the ACPI hardware Global Lock, only if the field
3280ffed378SFredrik Holmqvist  *              flags specify that it is to be obtained before field access.
3290174267aSFredrik Holmqvist  *
3300174267aSFredrik Holmqvist  ******************************************************************************/
3310174267aSFredrik Holmqvist 
3320174267aSFredrik Holmqvist void
AcpiExAcquireGlobalLock(UINT32 FieldFlags)3330174267aSFredrik Holmqvist AcpiExAcquireGlobalLock (
3340174267aSFredrik Holmqvist     UINT32                  FieldFlags)
3350174267aSFredrik Holmqvist {
3360174267aSFredrik Holmqvist     ACPI_STATUS             Status;
3370174267aSFredrik Holmqvist 
3380174267aSFredrik Holmqvist 
3390174267aSFredrik Holmqvist     ACPI_FUNCTION_TRACE (ExAcquireGlobalLock);
3400174267aSFredrik Holmqvist 
3410174267aSFredrik Holmqvist 
3420174267aSFredrik Holmqvist     /* Only use the lock if the AlwaysLock bit is set */
3430174267aSFredrik Holmqvist 
3440174267aSFredrik Holmqvist     if (!(FieldFlags & AML_FIELD_LOCK_RULE_MASK))
3450174267aSFredrik Holmqvist     {
3460174267aSFredrik Holmqvist         return_VOID;
3470174267aSFredrik Holmqvist     }
3480174267aSFredrik Holmqvist 
3490174267aSFredrik Holmqvist     /* Attempt to get the global lock, wait forever */
3500174267aSFredrik Holmqvist 
3510174267aSFredrik Holmqvist     Status = AcpiExAcquireMutexObject (ACPI_WAIT_FOREVER,
3520174267aSFredrik Holmqvist         AcpiGbl_GlobalLockMutex, AcpiOsGetThreadId ());
3530174267aSFredrik Holmqvist 
3540174267aSFredrik Holmqvist     if (ACPI_FAILURE (Status))
3550174267aSFredrik Holmqvist     {
3560174267aSFredrik Holmqvist         ACPI_EXCEPTION ((AE_INFO, Status,
3570174267aSFredrik Holmqvist             "Could not acquire Global Lock"));
3580174267aSFredrik Holmqvist     }
3590174267aSFredrik Holmqvist 
3600174267aSFredrik Holmqvist     return_VOID;
3610174267aSFredrik Holmqvist }
3620174267aSFredrik Holmqvist 
3630174267aSFredrik Holmqvist 
3640174267aSFredrik Holmqvist /*******************************************************************************
3650174267aSFredrik Holmqvist  *
3660174267aSFredrik Holmqvist  * FUNCTION:    AcpiExReleaseGlobalLock
3670174267aSFredrik Holmqvist  *
3680174267aSFredrik Holmqvist  * PARAMETERS:  FieldFlags            - Flags with Lock rule:
3690174267aSFredrik Holmqvist  *                                      AlwaysLock or NeverLock
3700174267aSFredrik Holmqvist  *
3710174267aSFredrik Holmqvist  * RETURN:      None
3720174267aSFredrik Holmqvist  *
3730174267aSFredrik Holmqvist  * DESCRIPTION: Release the ACPI hardware Global Lock
3740174267aSFredrik Holmqvist  *
3750174267aSFredrik Holmqvist  ******************************************************************************/
3760174267aSFredrik Holmqvist 
3770174267aSFredrik Holmqvist void
AcpiExReleaseGlobalLock(UINT32 FieldFlags)3780174267aSFredrik Holmqvist AcpiExReleaseGlobalLock (
3790174267aSFredrik Holmqvist     UINT32                  FieldFlags)
3800174267aSFredrik Holmqvist {
3810174267aSFredrik Holmqvist     ACPI_STATUS             Status;
3820174267aSFredrik Holmqvist 
3830174267aSFredrik Holmqvist 
3840174267aSFredrik Holmqvist     ACPI_FUNCTION_TRACE (ExReleaseGlobalLock);
3850174267aSFredrik Holmqvist 
3860174267aSFredrik Holmqvist 
3870174267aSFredrik Holmqvist     /* Only use the lock if the AlwaysLock bit is set */
3880174267aSFredrik Holmqvist 
3890174267aSFredrik Holmqvist     if (!(FieldFlags & AML_FIELD_LOCK_RULE_MASK))
3900174267aSFredrik Holmqvist     {
3910174267aSFredrik Holmqvist         return_VOID;
3920174267aSFredrik Holmqvist     }
3930174267aSFredrik Holmqvist 
3940174267aSFredrik Holmqvist     /* Release the global lock */
3950174267aSFredrik Holmqvist 
3960174267aSFredrik Holmqvist     Status = AcpiExReleaseMutexObject (AcpiGbl_GlobalLockMutex);
3970174267aSFredrik Holmqvist     if (ACPI_FAILURE (Status))
3980174267aSFredrik Holmqvist     {
3990174267aSFredrik Holmqvist         /* Report the error, but there isn't much else we can do */
4000174267aSFredrik Holmqvist 
4010174267aSFredrik Holmqvist         ACPI_EXCEPTION ((AE_INFO, Status,
4020174267aSFredrik Holmqvist             "Could not release Global Lock"));
4030174267aSFredrik Holmqvist     }
4040174267aSFredrik Holmqvist 
4050174267aSFredrik Holmqvist     return_VOID;
4060174267aSFredrik Holmqvist }
4070174267aSFredrik Holmqvist 
4080174267aSFredrik Holmqvist 
4090174267aSFredrik Holmqvist /*******************************************************************************
4100174267aSFredrik Holmqvist  *
4110174267aSFredrik Holmqvist  * FUNCTION:    AcpiExDigitsNeeded
4120174267aSFredrik Holmqvist  *
4130174267aSFredrik Holmqvist  * PARAMETERS:  Value           - Value to be represented
4140174267aSFredrik Holmqvist  *              Base            - Base of representation
4150174267aSFredrik Holmqvist  *
4160174267aSFredrik Holmqvist  * RETURN:      The number of digits.
4170174267aSFredrik Holmqvist  *
4180174267aSFredrik Holmqvist  * DESCRIPTION: Calculate the number of digits needed to represent the Value
4190174267aSFredrik Holmqvist  *              in the given Base (Radix)
4200174267aSFredrik Holmqvist  *
4210174267aSFredrik Holmqvist  ******************************************************************************/
4220174267aSFredrik Holmqvist 
4230174267aSFredrik Holmqvist static UINT32
AcpiExDigitsNeeded(UINT64 Value,UINT32 Base)4240174267aSFredrik Holmqvist AcpiExDigitsNeeded (
4250174267aSFredrik Holmqvist     UINT64                  Value,
4260174267aSFredrik Holmqvist     UINT32                  Base)
4270174267aSFredrik Holmqvist {
4280174267aSFredrik Holmqvist     UINT32                  NumDigits;
4290174267aSFredrik Holmqvist     UINT64                  CurrentValue;
4300174267aSFredrik Holmqvist 
4310174267aSFredrik Holmqvist 
4320174267aSFredrik Holmqvist     ACPI_FUNCTION_TRACE (ExDigitsNeeded);
4330174267aSFredrik Holmqvist 
4340174267aSFredrik Holmqvist 
4350174267aSFredrik Holmqvist     /* UINT64 is unsigned, so we don't worry about a '-' prefix */
4360174267aSFredrik Holmqvist 
4370174267aSFredrik Holmqvist     if (Value == 0)
4380174267aSFredrik Holmqvist     {
4390174267aSFredrik Holmqvist         return_UINT32 (1);
4400174267aSFredrik Holmqvist     }
4410174267aSFredrik Holmqvist 
4420174267aSFredrik Holmqvist     CurrentValue = Value;
4430174267aSFredrik Holmqvist     NumDigits = 0;
4440174267aSFredrik Holmqvist 
4450174267aSFredrik Holmqvist     /* Count the digits in the requested base */
4460174267aSFredrik Holmqvist 
4470174267aSFredrik Holmqvist     while (CurrentValue)
4480174267aSFredrik Holmqvist     {
4490174267aSFredrik Holmqvist         (void) AcpiUtShortDivide (CurrentValue, Base, &CurrentValue, NULL);
4500174267aSFredrik Holmqvist         NumDigits++;
4510174267aSFredrik Holmqvist     }
4520174267aSFredrik Holmqvist 
4530174267aSFredrik Holmqvist     return_UINT32 (NumDigits);
4540174267aSFredrik Holmqvist }
4550174267aSFredrik Holmqvist 
4560174267aSFredrik Holmqvist 
4570174267aSFredrik Holmqvist /*******************************************************************************
4580174267aSFredrik Holmqvist  *
4590174267aSFredrik Holmqvist  * FUNCTION:    AcpiExEisaIdToString
4600174267aSFredrik Holmqvist  *
46174ffd18dSFredrik Holmqvist  * PARAMETERS:  OutString       - Where to put the converted string (8 bytes)
46274ffd18dSFredrik Holmqvist  *              CompressedId    - EISAID to be converted
4630174267aSFredrik Holmqvist  *
4640174267aSFredrik Holmqvist  * RETURN:      None
4650174267aSFredrik Holmqvist  *
4660174267aSFredrik Holmqvist  * DESCRIPTION: Convert a numeric EISAID to string representation. Return
4670174267aSFredrik Holmqvist  *              buffer must be large enough to hold the string. The string
4680174267aSFredrik Holmqvist  *              returned is always exactly of length ACPI_EISAID_STRING_SIZE
4690174267aSFredrik Holmqvist  *              (includes null terminator). The EISAID is always 32 bits.
4700174267aSFredrik Holmqvist  *
4710174267aSFredrik Holmqvist  ******************************************************************************/
4720174267aSFredrik Holmqvist 
4730174267aSFredrik Holmqvist void
AcpiExEisaIdToString(char * OutString,UINT64 CompressedId)4740174267aSFredrik Holmqvist AcpiExEisaIdToString (
4750174267aSFredrik Holmqvist     char                    *OutString,
4760174267aSFredrik Holmqvist     UINT64                  CompressedId)
4770174267aSFredrik Holmqvist {
4780174267aSFredrik Holmqvist     UINT32                  SwappedId;
4790174267aSFredrik Holmqvist 
4800174267aSFredrik Holmqvist 
4810174267aSFredrik Holmqvist     ACPI_FUNCTION_ENTRY ();
4820174267aSFredrik Holmqvist 
4830174267aSFredrik Holmqvist 
4840174267aSFredrik Holmqvist     /* The EISAID should be a 32-bit integer */
4850174267aSFredrik Holmqvist 
4860174267aSFredrik Holmqvist     if (CompressedId > ACPI_UINT32_MAX)
4870174267aSFredrik Holmqvist     {
4880174267aSFredrik Holmqvist         ACPI_WARNING ((AE_INFO,
489b64e8511SFredrik Holmqvist             "Expected EISAID is larger than 32 bits: "
490b64e8511SFredrik Holmqvist             "0x%8.8X%8.8X, truncating",
4910174267aSFredrik Holmqvist             ACPI_FORMAT_UINT64 (CompressedId)));
4920174267aSFredrik Holmqvist     }
4930174267aSFredrik Holmqvist 
4940174267aSFredrik Holmqvist     /* Swap ID to big-endian to get contiguous bits */
4950174267aSFredrik Holmqvist 
4960174267aSFredrik Holmqvist     SwappedId = AcpiUtDwordByteSwap ((UINT32) CompressedId);
4970174267aSFredrik Holmqvist 
4980174267aSFredrik Holmqvist     /* First 3 bytes are uppercase letters. Next 4 bytes are hexadecimal */
4990174267aSFredrik Holmqvist 
5000174267aSFredrik Holmqvist     OutString[0] = (char) (0x40 + (((unsigned long) SwappedId >> 26) & 0x1F));
5010174267aSFredrik Holmqvist     OutString[1] = (char) (0x40 + ((SwappedId >> 21) & 0x1F));
5020174267aSFredrik Holmqvist     OutString[2] = (char) (0x40 + ((SwappedId >> 16) & 0x1F));
5030174267aSFredrik Holmqvist     OutString[3] = AcpiUtHexToAsciiChar ((UINT64) SwappedId, 12);
5040174267aSFredrik Holmqvist     OutString[4] = AcpiUtHexToAsciiChar ((UINT64) SwappedId, 8);
5050174267aSFredrik Holmqvist     OutString[5] = AcpiUtHexToAsciiChar ((UINT64) SwappedId, 4);
5060174267aSFredrik Holmqvist     OutString[6] = AcpiUtHexToAsciiChar ((UINT64) SwappedId, 0);
5070174267aSFredrik Holmqvist     OutString[7] = 0;
5080174267aSFredrik Holmqvist }
5090174267aSFredrik Holmqvist 
5100174267aSFredrik Holmqvist 
5110174267aSFredrik Holmqvist /*******************************************************************************
5120174267aSFredrik Holmqvist  *
5130174267aSFredrik Holmqvist  * FUNCTION:    AcpiExIntegerToString
5140174267aSFredrik Holmqvist  *
5150174267aSFredrik Holmqvist  * PARAMETERS:  OutString       - Where to put the converted string. At least
5160174267aSFredrik Holmqvist  *                                21 bytes are needed to hold the largest
5170174267aSFredrik Holmqvist  *                                possible 64-bit integer.
5180174267aSFredrik Holmqvist  *              Value           - Value to be converted
5190174267aSFredrik Holmqvist  *
52074ffd18dSFredrik Holmqvist  * RETURN:      Converted string in OutString
5210174267aSFredrik Holmqvist  *
5220174267aSFredrik Holmqvist  * DESCRIPTION: Convert a 64-bit integer to decimal string representation.
5230174267aSFredrik Holmqvist  *              Assumes string buffer is large enough to hold the string. The
5240174267aSFredrik Holmqvist  *              largest string is (ACPI_MAX64_DECIMAL_DIGITS + 1).
5250174267aSFredrik Holmqvist  *
5260174267aSFredrik Holmqvist  ******************************************************************************/
5270174267aSFredrik Holmqvist 
5280174267aSFredrik Holmqvist void
AcpiExIntegerToString(char * OutString,UINT64 Value)5290174267aSFredrik Holmqvist AcpiExIntegerToString (
5300174267aSFredrik Holmqvist     char                    *OutString,
5310174267aSFredrik Holmqvist     UINT64                  Value)
5320174267aSFredrik Holmqvist {
5330174267aSFredrik Holmqvist     UINT32                  Count;
5340174267aSFredrik Holmqvist     UINT32                  DigitsNeeded;
5350174267aSFredrik Holmqvist     UINT32                  Remainder;
5360174267aSFredrik Holmqvist 
5370174267aSFredrik Holmqvist 
5380174267aSFredrik Holmqvist     ACPI_FUNCTION_ENTRY ();
5390174267aSFredrik Holmqvist 
5400174267aSFredrik Holmqvist 
5410174267aSFredrik Holmqvist     DigitsNeeded = AcpiExDigitsNeeded (Value, 10);
5420174267aSFredrik Holmqvist     OutString[DigitsNeeded] = 0;
5430174267aSFredrik Holmqvist 
5440174267aSFredrik Holmqvist     for (Count = DigitsNeeded; Count > 0; Count--)
5450174267aSFredrik Holmqvist     {
5460174267aSFredrik Holmqvist         (void) AcpiUtShortDivide (Value, 10, &Value, &Remainder);
5470174267aSFredrik Holmqvist         OutString[Count-1] = (char) ('0' + Remainder);\
5480174267aSFredrik Holmqvist     }
5490174267aSFredrik Holmqvist }
5500174267aSFredrik Holmqvist 
5516822cda0SFredrik Holmqvist 
5526822cda0SFredrik Holmqvist /*******************************************************************************
5536822cda0SFredrik Holmqvist  *
554e226d1d0SFredrik Holmqvist  * FUNCTION:    AcpiExPciClsToString
555e226d1d0SFredrik Holmqvist  *
556e226d1d0SFredrik Holmqvist  * PARAMETERS:  OutString       - Where to put the converted string (7 bytes)
55774ffd18dSFredrik Holmqvist  *              ClassCode       - PCI class code to be converted (3 bytes)
558e226d1d0SFredrik Holmqvist  *
55974ffd18dSFredrik Holmqvist  * RETURN:      Converted string in OutString
560e226d1d0SFredrik Holmqvist  *
561e226d1d0SFredrik Holmqvist  * DESCRIPTION: Convert 3-bytes PCI class code to string representation.
562e226d1d0SFredrik Holmqvist  *              Return buffer must be large enough to hold the string. The
563e226d1d0SFredrik Holmqvist  *              string returned is always exactly of length
564e226d1d0SFredrik Holmqvist  *              ACPI_PCICLS_STRING_SIZE (includes null terminator).
565e226d1d0SFredrik Holmqvist  *
566e226d1d0SFredrik Holmqvist  ******************************************************************************/
567e226d1d0SFredrik Holmqvist 
568e226d1d0SFredrik Holmqvist void
AcpiExPciClsToString(char * OutString,UINT8 ClassCode[3])569e226d1d0SFredrik Holmqvist AcpiExPciClsToString (
570e226d1d0SFredrik Holmqvist     char                    *OutString,
571e226d1d0SFredrik Holmqvist     UINT8                   ClassCode[3])
572e226d1d0SFredrik Holmqvist {
573e226d1d0SFredrik Holmqvist 
574e226d1d0SFredrik Holmqvist     ACPI_FUNCTION_ENTRY ();
575e226d1d0SFredrik Holmqvist 
576e226d1d0SFredrik Holmqvist 
577e226d1d0SFredrik Holmqvist     /* All 3 bytes are hexadecimal */
578e226d1d0SFredrik Holmqvist 
579e226d1d0SFredrik Holmqvist     OutString[0] = AcpiUtHexToAsciiChar ((UINT64) ClassCode[0], 4);
580e226d1d0SFredrik Holmqvist     OutString[1] = AcpiUtHexToAsciiChar ((UINT64) ClassCode[0], 0);
581e226d1d0SFredrik Holmqvist     OutString[2] = AcpiUtHexToAsciiChar ((UINT64) ClassCode[1], 4);
582e226d1d0SFredrik Holmqvist     OutString[3] = AcpiUtHexToAsciiChar ((UINT64) ClassCode[1], 0);
583e226d1d0SFredrik Holmqvist     OutString[4] = AcpiUtHexToAsciiChar ((UINT64) ClassCode[2], 4);
584e226d1d0SFredrik Holmqvist     OutString[5] = AcpiUtHexToAsciiChar ((UINT64) ClassCode[2], 0);
585e226d1d0SFredrik Holmqvist     OutString[6] = 0;
586e226d1d0SFredrik Holmqvist }
587e226d1d0SFredrik Holmqvist 
588e226d1d0SFredrik Holmqvist 
589e226d1d0SFredrik Holmqvist /*******************************************************************************
590e226d1d0SFredrik Holmqvist  *
5916822cda0SFredrik Holmqvist  * FUNCTION:    AcpiIsValidSpaceId
5926822cda0SFredrik Holmqvist  *
5936822cda0SFredrik Holmqvist  * PARAMETERS:  SpaceId             - ID to be validated
5946822cda0SFredrik Holmqvist  *
59574ffd18dSFredrik Holmqvist  * RETURN:      TRUE if SpaceId is a valid/supported ID.
5966822cda0SFredrik Holmqvist  *
5976822cda0SFredrik Holmqvist  * DESCRIPTION: Validate an operation region SpaceID.
5986822cda0SFredrik Holmqvist  *
5996822cda0SFredrik Holmqvist  ******************************************************************************/
6006822cda0SFredrik Holmqvist 
6016822cda0SFredrik Holmqvist BOOLEAN
AcpiIsValidSpaceId(UINT8 SpaceId)6026822cda0SFredrik Holmqvist AcpiIsValidSpaceId (
6036822cda0SFredrik Holmqvist     UINT8                   SpaceId)
6046822cda0SFredrik Holmqvist {
6056822cda0SFredrik Holmqvist 
6066822cda0SFredrik Holmqvist     if ((SpaceId >= ACPI_NUM_PREDEFINED_REGIONS) &&
6076822cda0SFredrik Holmqvist         (SpaceId < ACPI_USER_REGION_BEGIN) &&
6086822cda0SFredrik Holmqvist         (SpaceId != ACPI_ADR_SPACE_DATA_TABLE) &&
6096822cda0SFredrik Holmqvist         (SpaceId != ACPI_ADR_SPACE_FIXED_HARDWARE))
6106822cda0SFredrik Holmqvist     {
6116822cda0SFredrik Holmqvist         return (FALSE);
6126822cda0SFredrik Holmqvist     }
6136822cda0SFredrik Holmqvist 
6146822cda0SFredrik Holmqvist     return (TRUE);
6156822cda0SFredrik Holmqvist }
616