xref: /haiku/src/add-ons/kernel/bus_managers/acpi/acpica/components/dispatcher/dswstate.c (revision 6dde014f768e0ee49bae871ed857cf433837b9ff)
10174267aSFredrik Holmqvist /******************************************************************************
20174267aSFredrik Holmqvist  *
30174267aSFredrik Holmqvist  * Module Name: dswstate - Dispatcher parse tree walk management routines
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 #include "acpi.h"
1530174267aSFredrik Holmqvist #include "accommon.h"
1540174267aSFredrik Holmqvist #include "acparser.h"
1550174267aSFredrik Holmqvist #include "acdispat.h"
1560174267aSFredrik Holmqvist #include "acnamesp.h"
1570174267aSFredrik Holmqvist 
1580174267aSFredrik Holmqvist #define _COMPONENT          ACPI_DISPATCHER
1590174267aSFredrik Holmqvist         ACPI_MODULE_NAME    ("dswstate")
1600174267aSFredrik Holmqvist 
1610174267aSFredrik Holmqvist /* Local prototypes */
1620174267aSFredrik Holmqvist 
1630174267aSFredrik Holmqvist static ACPI_STATUS
1640174267aSFredrik Holmqvist AcpiDsResultStackPush (
1650174267aSFredrik Holmqvist     ACPI_WALK_STATE         *WalkState);
1660174267aSFredrik Holmqvist 
1670174267aSFredrik Holmqvist static ACPI_STATUS
1680174267aSFredrik Holmqvist AcpiDsResultStackPop (
1690174267aSFredrik Holmqvist     ACPI_WALK_STATE         *WalkState);
1700174267aSFredrik Holmqvist 
1710174267aSFredrik Holmqvist 
1720174267aSFredrik Holmqvist /*******************************************************************************
1730174267aSFredrik Holmqvist  *
1740174267aSFredrik Holmqvist  * FUNCTION:    AcpiDsResultPop
1750174267aSFredrik Holmqvist  *
1760174267aSFredrik Holmqvist  * PARAMETERS:  Object              - Where to return the popped object
1770174267aSFredrik Holmqvist  *              WalkState           - Current Walk state
1780174267aSFredrik Holmqvist  *
1790174267aSFredrik Holmqvist  * RETURN:      Status
1800174267aSFredrik Holmqvist  *
1810174267aSFredrik Holmqvist  * DESCRIPTION: Pop an object off the top of this walk's result stack
1820174267aSFredrik Holmqvist  *
1830174267aSFredrik Holmqvist  ******************************************************************************/
1840174267aSFredrik Holmqvist 
1850174267aSFredrik Holmqvist ACPI_STATUS
AcpiDsResultPop(ACPI_OPERAND_OBJECT ** Object,ACPI_WALK_STATE * WalkState)1860174267aSFredrik Holmqvist AcpiDsResultPop (
1870174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     **Object,
1880174267aSFredrik Holmqvist     ACPI_WALK_STATE         *WalkState)
1890174267aSFredrik Holmqvist {
1900174267aSFredrik Holmqvist     UINT32                  Index;
1910174267aSFredrik Holmqvist     ACPI_GENERIC_STATE      *State;
1920174267aSFredrik Holmqvist     ACPI_STATUS             Status;
1930174267aSFredrik Holmqvist 
1940174267aSFredrik Holmqvist 
1950174267aSFredrik Holmqvist     ACPI_FUNCTION_NAME (DsResultPop);
1960174267aSFredrik Holmqvist 
1970174267aSFredrik Holmqvist 
1980174267aSFredrik Holmqvist     State = WalkState->Results;
1990174267aSFredrik Holmqvist 
2000174267aSFredrik Holmqvist     /* Incorrect state of result stack */
2010174267aSFredrik Holmqvist 
2020174267aSFredrik Holmqvist     if (State && !WalkState->ResultCount)
2030174267aSFredrik Holmqvist     {
2040174267aSFredrik Holmqvist         ACPI_ERROR ((AE_INFO, "No results on result stack"));
2050174267aSFredrik Holmqvist         return (AE_AML_INTERNAL);
2060174267aSFredrik Holmqvist     }
2070174267aSFredrik Holmqvist 
2080174267aSFredrik Holmqvist     if (!State && WalkState->ResultCount)
2090174267aSFredrik Holmqvist     {
2100174267aSFredrik Holmqvist         ACPI_ERROR ((AE_INFO, "No result state for result stack"));
2110174267aSFredrik Holmqvist         return (AE_AML_INTERNAL);
2120174267aSFredrik Holmqvist     }
2130174267aSFredrik Holmqvist 
2140174267aSFredrik Holmqvist     /* Empty result stack */
2150174267aSFredrik Holmqvist 
2160174267aSFredrik Holmqvist     if (!State)
2170174267aSFredrik Holmqvist     {
2180174267aSFredrik Holmqvist         ACPI_ERROR ((AE_INFO, "Result stack is empty! State=%p", WalkState));
2190174267aSFredrik Holmqvist         return (AE_AML_NO_RETURN_VALUE);
2200174267aSFredrik Holmqvist     }
2210174267aSFredrik Holmqvist 
2220174267aSFredrik Holmqvist     /* Return object of the top element and clean that top element result stack */
2230174267aSFredrik Holmqvist 
2240174267aSFredrik Holmqvist     WalkState->ResultCount--;
2250174267aSFredrik Holmqvist     Index = (UINT32) WalkState->ResultCount % ACPI_RESULTS_FRAME_OBJ_NUM;
2260174267aSFredrik Holmqvist 
2270174267aSFredrik Holmqvist     *Object = State->Results.ObjDesc [Index];
2280174267aSFredrik Holmqvist     if (!*Object)
2290174267aSFredrik Holmqvist     {
2300174267aSFredrik Holmqvist         ACPI_ERROR ((AE_INFO, "No result objects on result stack, State=%p",
2310174267aSFredrik Holmqvist             WalkState));
2320174267aSFredrik Holmqvist         return (AE_AML_NO_RETURN_VALUE);
2330174267aSFredrik Holmqvist     }
2340174267aSFredrik Holmqvist 
2350174267aSFredrik Holmqvist     State->Results.ObjDesc [Index] = NULL;
2360174267aSFredrik Holmqvist     if (Index == 0)
2370174267aSFredrik Holmqvist     {
2380174267aSFredrik Holmqvist         Status = AcpiDsResultStackPop (WalkState);
2390174267aSFredrik Holmqvist         if (ACPI_FAILURE (Status))
2400174267aSFredrik Holmqvist         {
2410174267aSFredrik Holmqvist             return (Status);
2420174267aSFredrik Holmqvist         }
2430174267aSFredrik Holmqvist     }
2440174267aSFredrik Holmqvist 
2450174267aSFredrik Holmqvist     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
2460174267aSFredrik Holmqvist         "Obj=%p [%s] Index=%X State=%p Num=%X\n", *Object,
2470174267aSFredrik Holmqvist         AcpiUtGetObjectTypeName (*Object),
2480174267aSFredrik Holmqvist         Index, WalkState, WalkState->ResultCount));
2490174267aSFredrik Holmqvist 
2500174267aSFredrik Holmqvist     return (AE_OK);
2510174267aSFredrik Holmqvist }
2520174267aSFredrik Holmqvist 
2530174267aSFredrik Holmqvist 
2540174267aSFredrik Holmqvist /*******************************************************************************
2550174267aSFredrik Holmqvist  *
2560174267aSFredrik Holmqvist  * FUNCTION:    AcpiDsResultPush
2570174267aSFredrik Holmqvist  *
2580174267aSFredrik Holmqvist  * PARAMETERS:  Object              - Where to return the popped object
2590174267aSFredrik Holmqvist  *              WalkState           - Current Walk state
2600174267aSFredrik Holmqvist  *
2610174267aSFredrik Holmqvist  * RETURN:      Status
2620174267aSFredrik Holmqvist  *
2630174267aSFredrik Holmqvist  * DESCRIPTION: Push an object onto the current result stack
2640174267aSFredrik Holmqvist  *
2650174267aSFredrik Holmqvist  ******************************************************************************/
2660174267aSFredrik Holmqvist 
2670174267aSFredrik Holmqvist ACPI_STATUS
AcpiDsResultPush(ACPI_OPERAND_OBJECT * Object,ACPI_WALK_STATE * WalkState)2680174267aSFredrik Holmqvist AcpiDsResultPush (
2690174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     *Object,
2700174267aSFredrik Holmqvist     ACPI_WALK_STATE         *WalkState)
2710174267aSFredrik Holmqvist {
2720174267aSFredrik Holmqvist     ACPI_GENERIC_STATE      *State;
2730174267aSFredrik Holmqvist     ACPI_STATUS             Status;
2740174267aSFredrik Holmqvist     UINT32                  Index;
2750174267aSFredrik Holmqvist 
2760174267aSFredrik Holmqvist 
2770174267aSFredrik Holmqvist     ACPI_FUNCTION_NAME (DsResultPush);
2780174267aSFredrik Holmqvist 
2790174267aSFredrik Holmqvist 
2800174267aSFredrik Holmqvist     if (WalkState->ResultCount > WalkState->ResultSize)
2810174267aSFredrik Holmqvist     {
2820174267aSFredrik Holmqvist         ACPI_ERROR ((AE_INFO, "Result stack is full"));
2830174267aSFredrik Holmqvist         return (AE_AML_INTERNAL);
2840174267aSFredrik Holmqvist     }
2850174267aSFredrik Holmqvist     else if (WalkState->ResultCount == WalkState->ResultSize)
2860174267aSFredrik Holmqvist     {
2870174267aSFredrik Holmqvist         /* Extend the result stack */
2880174267aSFredrik Holmqvist 
2890174267aSFredrik Holmqvist         Status = AcpiDsResultStackPush (WalkState);
2900174267aSFredrik Holmqvist         if (ACPI_FAILURE (Status))
2910174267aSFredrik Holmqvist         {
2920174267aSFredrik Holmqvist             ACPI_ERROR ((AE_INFO, "Failed to extend the result stack"));
2930174267aSFredrik Holmqvist             return (Status);
2940174267aSFredrik Holmqvist         }
2950174267aSFredrik Holmqvist     }
2960174267aSFredrik Holmqvist 
2970174267aSFredrik Holmqvist     if (!(WalkState->ResultCount < WalkState->ResultSize))
2980174267aSFredrik Holmqvist     {
2990174267aSFredrik Holmqvist         ACPI_ERROR ((AE_INFO, "No free elements in result stack"));
3000174267aSFredrik Holmqvist         return (AE_AML_INTERNAL);
3010174267aSFredrik Holmqvist     }
3020174267aSFredrik Holmqvist 
3030174267aSFredrik Holmqvist     State = WalkState->Results;
3040174267aSFredrik Holmqvist     if (!State)
3050174267aSFredrik Holmqvist     {
3060174267aSFredrik Holmqvist         ACPI_ERROR ((AE_INFO, "No result stack frame during push"));
3070174267aSFredrik Holmqvist         return (AE_AML_INTERNAL);
3080174267aSFredrik Holmqvist     }
3090174267aSFredrik Holmqvist 
3100174267aSFredrik Holmqvist     if (!Object)
3110174267aSFredrik Holmqvist     {
3120174267aSFredrik Holmqvist         ACPI_ERROR ((AE_INFO,
31315338de9SPulkoMandy             "Null Object! State=%p Num=%u",
31415338de9SPulkoMandy             WalkState, WalkState->ResultCount));
3150174267aSFredrik Holmqvist         return (AE_BAD_PARAMETER);
3160174267aSFredrik Holmqvist     }
3170174267aSFredrik Holmqvist 
3180174267aSFredrik Holmqvist     /* Assign the address of object to the top free element of result stack */
3190174267aSFredrik Holmqvist 
3200174267aSFredrik Holmqvist     Index = (UINT32) WalkState->ResultCount % ACPI_RESULTS_FRAME_OBJ_NUM;
3210174267aSFredrik Holmqvist     State->Results.ObjDesc [Index] = Object;
3220174267aSFredrik Holmqvist     WalkState->ResultCount++;
3230174267aSFredrik Holmqvist 
3240174267aSFredrik Holmqvist     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p [%s] State=%p Num=%X Cur=%X\n",
3250174267aSFredrik Holmqvist         Object, AcpiUtGetObjectTypeName ((ACPI_OPERAND_OBJECT *) Object),
3260174267aSFredrik Holmqvist         WalkState, WalkState->ResultCount, WalkState->CurrentResult));
3270174267aSFredrik Holmqvist 
3280174267aSFredrik Holmqvist     return (AE_OK);
3290174267aSFredrik Holmqvist }
3300174267aSFredrik Holmqvist 
3310174267aSFredrik Holmqvist 
3320174267aSFredrik Holmqvist /*******************************************************************************
3330174267aSFredrik Holmqvist  *
3340174267aSFredrik Holmqvist  * FUNCTION:    AcpiDsResultStackPush
3350174267aSFredrik Holmqvist  *
3360174267aSFredrik Holmqvist  * PARAMETERS:  WalkState           - Current Walk state
3370174267aSFredrik Holmqvist  *
3380174267aSFredrik Holmqvist  * RETURN:      Status
3390174267aSFredrik Holmqvist  *
3400174267aSFredrik Holmqvist  * DESCRIPTION: Push an object onto the WalkState result stack
3410174267aSFredrik Holmqvist  *
3420174267aSFredrik Holmqvist  ******************************************************************************/
3430174267aSFredrik Holmqvist 
3440174267aSFredrik Holmqvist static ACPI_STATUS
AcpiDsResultStackPush(ACPI_WALK_STATE * WalkState)3450174267aSFredrik Holmqvist AcpiDsResultStackPush (
3460174267aSFredrik Holmqvist     ACPI_WALK_STATE         *WalkState)
3470174267aSFredrik Holmqvist {
3480174267aSFredrik Holmqvist     ACPI_GENERIC_STATE      *State;
3490174267aSFredrik Holmqvist 
3500174267aSFredrik Holmqvist 
3510174267aSFredrik Holmqvist     ACPI_FUNCTION_NAME (DsResultStackPush);
3520174267aSFredrik Holmqvist 
3530174267aSFredrik Holmqvist 
3540174267aSFredrik Holmqvist     /* Check for stack overflow */
3550174267aSFredrik Holmqvist 
3560174267aSFredrik Holmqvist     if (((UINT32) WalkState->ResultSize + ACPI_RESULTS_FRAME_OBJ_NUM) >
3570174267aSFredrik Holmqvist         ACPI_RESULTS_OBJ_NUM_MAX)
3580174267aSFredrik Holmqvist     {
3590174267aSFredrik Holmqvist         ACPI_ERROR ((AE_INFO, "Result stack overflow: State=%p Num=%u",
3600174267aSFredrik Holmqvist             WalkState, WalkState->ResultSize));
3610174267aSFredrik Holmqvist         return (AE_STACK_OVERFLOW);
3620174267aSFredrik Holmqvist     }
3630174267aSFredrik Holmqvist 
3640174267aSFredrik Holmqvist     State = AcpiUtCreateGenericState ();
3650174267aSFredrik Holmqvist     if (!State)
3660174267aSFredrik Holmqvist     {
3670174267aSFredrik Holmqvist         return (AE_NO_MEMORY);
3680174267aSFredrik Holmqvist     }
3690174267aSFredrik Holmqvist 
3700174267aSFredrik Holmqvist     State->Common.DescriptorType = ACPI_DESC_TYPE_STATE_RESULT;
3710174267aSFredrik Holmqvist     AcpiUtPushGenericState (&WalkState->Results, State);
3720174267aSFredrik Holmqvist 
3730174267aSFredrik Holmqvist     /* Increase the length of the result stack by the length of frame */
3740174267aSFredrik Holmqvist 
3750174267aSFredrik Holmqvist     WalkState->ResultSize += ACPI_RESULTS_FRAME_OBJ_NUM;
3760174267aSFredrik Holmqvist 
3770174267aSFredrik Holmqvist     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Results=%p State=%p\n",
3780174267aSFredrik Holmqvist         State, WalkState));
3790174267aSFredrik Holmqvist 
3800174267aSFredrik Holmqvist     return (AE_OK);
3810174267aSFredrik Holmqvist }
3820174267aSFredrik Holmqvist 
3830174267aSFredrik Holmqvist 
3840174267aSFredrik Holmqvist /*******************************************************************************
3850174267aSFredrik Holmqvist  *
3860174267aSFredrik Holmqvist  * FUNCTION:    AcpiDsResultStackPop
3870174267aSFredrik Holmqvist  *
3880174267aSFredrik Holmqvist  * PARAMETERS:  WalkState           - Current Walk state
3890174267aSFredrik Holmqvist  *
3900174267aSFredrik Holmqvist  * RETURN:      Status
3910174267aSFredrik Holmqvist  *
3920174267aSFredrik Holmqvist  * DESCRIPTION: Pop an object off of the WalkState result stack
3930174267aSFredrik Holmqvist  *
3940174267aSFredrik Holmqvist  ******************************************************************************/
3950174267aSFredrik Holmqvist 
3960174267aSFredrik Holmqvist static ACPI_STATUS
AcpiDsResultStackPop(ACPI_WALK_STATE * WalkState)3970174267aSFredrik Holmqvist AcpiDsResultStackPop (
3980174267aSFredrik Holmqvist     ACPI_WALK_STATE         *WalkState)
3990174267aSFredrik Holmqvist {
4000174267aSFredrik Holmqvist     ACPI_GENERIC_STATE      *State;
4010174267aSFredrik Holmqvist 
4020174267aSFredrik Holmqvist 
4030174267aSFredrik Holmqvist     ACPI_FUNCTION_NAME (DsResultStackPop);
4040174267aSFredrik Holmqvist 
4050174267aSFredrik Holmqvist 
4060174267aSFredrik Holmqvist     /* Check for stack underflow */
4070174267aSFredrik Holmqvist 
4080174267aSFredrik Holmqvist     if (WalkState->Results == NULL)
4090174267aSFredrik Holmqvist     {
410b64e8511SFredrik Holmqvist         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
411b64e8511SFredrik Holmqvist             "Result stack underflow - State=%p\n", WalkState));
4120174267aSFredrik Holmqvist         return (AE_AML_NO_OPERAND);
4130174267aSFredrik Holmqvist     }
4140174267aSFredrik Holmqvist 
4150174267aSFredrik Holmqvist     if (WalkState->ResultSize < ACPI_RESULTS_FRAME_OBJ_NUM)
4160174267aSFredrik Holmqvist     {
4170174267aSFredrik Holmqvist         ACPI_ERROR ((AE_INFO, "Insufficient result stack size"));
4180174267aSFredrik Holmqvist         return (AE_AML_INTERNAL);
4190174267aSFredrik Holmqvist     }
4200174267aSFredrik Holmqvist 
4210174267aSFredrik Holmqvist     State = AcpiUtPopGenericState (&WalkState->Results);
4220174267aSFredrik Holmqvist     AcpiUtDeleteGenericState (State);
4230174267aSFredrik Holmqvist 
4240174267aSFredrik Holmqvist     /* Decrease the length of result stack by the length of frame */
4250174267aSFredrik Holmqvist 
4260174267aSFredrik Holmqvist     WalkState->ResultSize -= ACPI_RESULTS_FRAME_OBJ_NUM;
4270174267aSFredrik Holmqvist 
4280174267aSFredrik Holmqvist     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
4290174267aSFredrik Holmqvist         "Result=%p RemainingResults=%X State=%p\n",
4300174267aSFredrik Holmqvist         State, WalkState->ResultCount, WalkState));
4310174267aSFredrik Holmqvist 
4320174267aSFredrik Holmqvist     return (AE_OK);
4330174267aSFredrik Holmqvist }
4340174267aSFredrik Holmqvist 
4350174267aSFredrik Holmqvist 
4360174267aSFredrik Holmqvist /*******************************************************************************
4370174267aSFredrik Holmqvist  *
4380174267aSFredrik Holmqvist  * FUNCTION:    AcpiDsObjStackPush
4390174267aSFredrik Holmqvist  *
4400174267aSFredrik Holmqvist  * PARAMETERS:  Object              - Object to push
4410174267aSFredrik Holmqvist  *              WalkState           - Current Walk state
4420174267aSFredrik Holmqvist  *
4430174267aSFredrik Holmqvist  * RETURN:      Status
4440174267aSFredrik Holmqvist  *
4450174267aSFredrik Holmqvist  * DESCRIPTION: Push an object onto this walk's object/operand stack
4460174267aSFredrik Holmqvist  *
4470174267aSFredrik Holmqvist  ******************************************************************************/
4480174267aSFredrik Holmqvist 
4490174267aSFredrik Holmqvist ACPI_STATUS
AcpiDsObjStackPush(void * Object,ACPI_WALK_STATE * WalkState)4500174267aSFredrik Holmqvist AcpiDsObjStackPush (
4510174267aSFredrik Holmqvist     void                    *Object,
4520174267aSFredrik Holmqvist     ACPI_WALK_STATE         *WalkState)
4530174267aSFredrik Holmqvist {
4540174267aSFredrik Holmqvist     ACPI_FUNCTION_NAME (DsObjStackPush);
4550174267aSFredrik Holmqvist 
4560174267aSFredrik Holmqvist 
4570174267aSFredrik Holmqvist     /* Check for stack overflow */
4580174267aSFredrik Holmqvist 
4590174267aSFredrik Holmqvist     if (WalkState->NumOperands >= ACPI_OBJ_NUM_OPERANDS)
4600174267aSFredrik Holmqvist     {
4610174267aSFredrik Holmqvist         ACPI_ERROR ((AE_INFO,
4620174267aSFredrik Holmqvist             "Object stack overflow! Obj=%p State=%p #Ops=%u",
4630174267aSFredrik Holmqvist             Object, WalkState, WalkState->NumOperands));
4640174267aSFredrik Holmqvist         return (AE_STACK_OVERFLOW);
4650174267aSFredrik Holmqvist     }
4660174267aSFredrik Holmqvist 
4670174267aSFredrik Holmqvist     /* Put the object onto the stack */
4680174267aSFredrik Holmqvist 
4690174267aSFredrik Holmqvist     WalkState->Operands [WalkState->OperandIndex] = Object;
4700174267aSFredrik Holmqvist     WalkState->NumOperands++;
4710174267aSFredrik Holmqvist 
4720174267aSFredrik Holmqvist     /* For the usual order of filling the operand stack */
4730174267aSFredrik Holmqvist 
4740174267aSFredrik Holmqvist     WalkState->OperandIndex++;
4750174267aSFredrik Holmqvist 
4760174267aSFredrik Holmqvist     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p [%s] State=%p #Ops=%X\n",
4770174267aSFredrik Holmqvist         Object, AcpiUtGetObjectTypeName ((ACPI_OPERAND_OBJECT *) Object),
4780174267aSFredrik Holmqvist         WalkState, WalkState->NumOperands));
4790174267aSFredrik Holmqvist 
4800174267aSFredrik Holmqvist     return (AE_OK);
4810174267aSFredrik Holmqvist }
4820174267aSFredrik Holmqvist 
4830174267aSFredrik Holmqvist 
4840174267aSFredrik Holmqvist /*******************************************************************************
4850174267aSFredrik Holmqvist  *
4860174267aSFredrik Holmqvist  * FUNCTION:    AcpiDsObjStackPop
4870174267aSFredrik Holmqvist  *
4880174267aSFredrik Holmqvist  * PARAMETERS:  PopCount            - Number of objects/entries to pop
4890174267aSFredrik Holmqvist  *              WalkState           - Current Walk state
4900174267aSFredrik Holmqvist  *
4910174267aSFredrik Holmqvist  * RETURN:      Status
4920174267aSFredrik Holmqvist  *
4930174267aSFredrik Holmqvist  * DESCRIPTION: Pop this walk's object stack. Objects on the stack are NOT
4940174267aSFredrik Holmqvist  *              deleted by this routine.
4950174267aSFredrik Holmqvist  *
4960174267aSFredrik Holmqvist  ******************************************************************************/
4970174267aSFredrik Holmqvist 
4980174267aSFredrik Holmqvist ACPI_STATUS
AcpiDsObjStackPop(UINT32 PopCount,ACPI_WALK_STATE * WalkState)4990174267aSFredrik Holmqvist AcpiDsObjStackPop (
5000174267aSFredrik Holmqvist     UINT32                  PopCount,
5010174267aSFredrik Holmqvist     ACPI_WALK_STATE         *WalkState)
5020174267aSFredrik Holmqvist {
5030174267aSFredrik Holmqvist     UINT32                  i;
5040174267aSFredrik Holmqvist 
5050174267aSFredrik Holmqvist 
5060174267aSFredrik Holmqvist     ACPI_FUNCTION_NAME (DsObjStackPop);
5070174267aSFredrik Holmqvist 
5080174267aSFredrik Holmqvist 
5090174267aSFredrik Holmqvist     for (i = 0; i < PopCount; i++)
5100174267aSFredrik Holmqvist     {
5110174267aSFredrik Holmqvist         /* Check for stack underflow */
5120174267aSFredrik Holmqvist 
5130174267aSFredrik Holmqvist         if (WalkState->NumOperands == 0)
5140174267aSFredrik Holmqvist         {
5150174267aSFredrik Holmqvist             ACPI_ERROR ((AE_INFO,
5160174267aSFredrik Holmqvist                 "Object stack underflow! Count=%X State=%p #Ops=%u",
5170174267aSFredrik Holmqvist                 PopCount, WalkState, WalkState->NumOperands));
5180174267aSFredrik Holmqvist             return (AE_STACK_UNDERFLOW);
5190174267aSFredrik Holmqvist         }
5200174267aSFredrik Holmqvist 
5210174267aSFredrik Holmqvist         /* Just set the stack entry to null */
5220174267aSFredrik Holmqvist 
5230174267aSFredrik Holmqvist         WalkState->NumOperands--;
5240174267aSFredrik Holmqvist         WalkState->Operands [WalkState->NumOperands] = NULL;
5250174267aSFredrik Holmqvist     }
5260174267aSFredrik Holmqvist 
5270174267aSFredrik Holmqvist     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%u\n",
5280174267aSFredrik Holmqvist         PopCount, WalkState, WalkState->NumOperands));
5290174267aSFredrik Holmqvist 
5300174267aSFredrik Holmqvist     return (AE_OK);
5310174267aSFredrik Holmqvist }
5320174267aSFredrik Holmqvist 
5330174267aSFredrik Holmqvist 
5340174267aSFredrik Holmqvist /*******************************************************************************
5350174267aSFredrik Holmqvist  *
5360174267aSFredrik Holmqvist  * FUNCTION:    AcpiDsObjStackPopAndDelete
5370174267aSFredrik Holmqvist  *
5380174267aSFredrik Holmqvist  * PARAMETERS:  PopCount            - Number of objects/entries to pop
5390174267aSFredrik Holmqvist  *              WalkState           - Current Walk state
5400174267aSFredrik Holmqvist  *
5410174267aSFredrik Holmqvist  * RETURN:      Status
5420174267aSFredrik Holmqvist  *
5430174267aSFredrik Holmqvist  * DESCRIPTION: Pop this walk's object stack and delete each object that is
5440174267aSFredrik Holmqvist  *              popped off.
5450174267aSFredrik Holmqvist  *
5460174267aSFredrik Holmqvist  ******************************************************************************/
5470174267aSFredrik Holmqvist 
5480174267aSFredrik Holmqvist void
AcpiDsObjStackPopAndDelete(UINT32 PopCount,ACPI_WALK_STATE * WalkState)5490174267aSFredrik Holmqvist AcpiDsObjStackPopAndDelete (
5500174267aSFredrik Holmqvist     UINT32                  PopCount,
5510174267aSFredrik Holmqvist     ACPI_WALK_STATE         *WalkState)
5520174267aSFredrik Holmqvist {
5530174267aSFredrik Holmqvist     INT32                   i;
5540174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     *ObjDesc;
5550174267aSFredrik Holmqvist 
5560174267aSFredrik Holmqvist 
5570174267aSFredrik Holmqvist     ACPI_FUNCTION_NAME (DsObjStackPopAndDelete);
5580174267aSFredrik Holmqvist 
5590174267aSFredrik Holmqvist 
5600174267aSFredrik Holmqvist     if (PopCount == 0)
5610174267aSFredrik Holmqvist     {
5620174267aSFredrik Holmqvist         return;
5630174267aSFredrik Holmqvist     }
5640174267aSFredrik Holmqvist 
5650174267aSFredrik Holmqvist     for (i = (INT32) PopCount - 1; i >= 0; i--)
5660174267aSFredrik Holmqvist     {
5670174267aSFredrik Holmqvist         if (WalkState->NumOperands == 0)
5680174267aSFredrik Holmqvist         {
5690174267aSFredrik Holmqvist             return;
5700174267aSFredrik Holmqvist         }
5710174267aSFredrik Holmqvist 
5720174267aSFredrik Holmqvist         /* Pop the stack and delete an object if present in this stack entry */
5730174267aSFredrik Holmqvist 
5740174267aSFredrik Holmqvist         WalkState->NumOperands--;
5750174267aSFredrik Holmqvist         ObjDesc = WalkState->Operands [i];
5760174267aSFredrik Holmqvist         if (ObjDesc)
5770174267aSFredrik Holmqvist         {
5780174267aSFredrik Holmqvist             AcpiUtRemoveReference (WalkState->Operands [i]);
5790174267aSFredrik Holmqvist             WalkState->Operands [i] = NULL;
5800174267aSFredrik Holmqvist         }
5810174267aSFredrik Holmqvist     }
5820174267aSFredrik Holmqvist 
5830174267aSFredrik Holmqvist     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%X\n",
5840174267aSFredrik Holmqvist         PopCount, WalkState, WalkState->NumOperands));
5850174267aSFredrik Holmqvist }
5860174267aSFredrik Holmqvist 
5870174267aSFredrik Holmqvist 
5880174267aSFredrik Holmqvist /*******************************************************************************
5890174267aSFredrik Holmqvist  *
5900174267aSFredrik Holmqvist  * FUNCTION:    AcpiDsGetCurrentWalkState
5910174267aSFredrik Holmqvist  *
5920174267aSFredrik Holmqvist  * PARAMETERS:  Thread          - Get current active state for this Thread
5930174267aSFredrik Holmqvist  *
5940174267aSFredrik Holmqvist  * RETURN:      Pointer to the current walk state
5950174267aSFredrik Holmqvist  *
5960174267aSFredrik Holmqvist  * DESCRIPTION: Get the walk state that is at the head of the list (the "current"
5970174267aSFredrik Holmqvist  *              walk state.)
5980174267aSFredrik Holmqvist  *
5990174267aSFredrik Holmqvist  ******************************************************************************/
6000174267aSFredrik Holmqvist 
6010174267aSFredrik Holmqvist ACPI_WALK_STATE *
AcpiDsGetCurrentWalkState(ACPI_THREAD_STATE * Thread)6020174267aSFredrik Holmqvist AcpiDsGetCurrentWalkState (
6030174267aSFredrik Holmqvist     ACPI_THREAD_STATE       *Thread)
6040174267aSFredrik Holmqvist {
6050174267aSFredrik Holmqvist     ACPI_FUNCTION_NAME (DsGetCurrentWalkState);
6060174267aSFredrik Holmqvist 
6070174267aSFredrik Holmqvist 
6080174267aSFredrik Holmqvist     if (!Thread)
6090174267aSFredrik Holmqvist     {
6100174267aSFredrik Holmqvist         return (NULL);
6110174267aSFredrik Holmqvist     }
6120174267aSFredrik Holmqvist 
6130174267aSFredrik Holmqvist     ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Current WalkState %p\n",
6140174267aSFredrik Holmqvist         Thread->WalkStateList));
6150174267aSFredrik Holmqvist 
6160174267aSFredrik Holmqvist     return (Thread->WalkStateList);
6170174267aSFredrik Holmqvist }
6180174267aSFredrik Holmqvist 
6190174267aSFredrik Holmqvist 
6200174267aSFredrik Holmqvist /*******************************************************************************
6210174267aSFredrik Holmqvist  *
6220174267aSFredrik Holmqvist  * FUNCTION:    AcpiDsPushWalkState
6230174267aSFredrik Holmqvist  *
6240174267aSFredrik Holmqvist  * PARAMETERS:  WalkState       - State to push
6250174267aSFredrik Holmqvist  *              Thread          - Thread state object
6260174267aSFredrik Holmqvist  *
6270174267aSFredrik Holmqvist  * RETURN:      None
6280174267aSFredrik Holmqvist  *
6290174267aSFredrik Holmqvist  * DESCRIPTION: Place the Thread state at the head of the state list
6300174267aSFredrik Holmqvist  *
6310174267aSFredrik Holmqvist  ******************************************************************************/
6320174267aSFredrik Holmqvist 
6330174267aSFredrik Holmqvist void
AcpiDsPushWalkState(ACPI_WALK_STATE * WalkState,ACPI_THREAD_STATE * Thread)6340174267aSFredrik Holmqvist AcpiDsPushWalkState (
6350174267aSFredrik Holmqvist     ACPI_WALK_STATE         *WalkState,
6360174267aSFredrik Holmqvist     ACPI_THREAD_STATE       *Thread)
6370174267aSFredrik Holmqvist {
6380174267aSFredrik Holmqvist     ACPI_FUNCTION_TRACE (DsPushWalkState);
6390174267aSFredrik Holmqvist 
6400174267aSFredrik Holmqvist 
6410174267aSFredrik Holmqvist     WalkState->Next = Thread->WalkStateList;
6420174267aSFredrik Holmqvist     Thread->WalkStateList = WalkState;
6430174267aSFredrik Holmqvist 
6440174267aSFredrik Holmqvist     return_VOID;
6450174267aSFredrik Holmqvist }
6460174267aSFredrik Holmqvist 
6470174267aSFredrik Holmqvist 
6480174267aSFredrik Holmqvist /*******************************************************************************
6490174267aSFredrik Holmqvist  *
6500174267aSFredrik Holmqvist  * FUNCTION:    AcpiDsPopWalkState
6510174267aSFredrik Holmqvist  *
6520174267aSFredrik Holmqvist  * PARAMETERS:  Thread      - Current thread state
6530174267aSFredrik Holmqvist  *
6540174267aSFredrik Holmqvist  * RETURN:      A WalkState object popped from the thread's stack
6550174267aSFredrik Holmqvist  *
6560174267aSFredrik Holmqvist  * DESCRIPTION: Remove and return the walkstate object that is at the head of
6570174267aSFredrik Holmqvist  *              the walk stack for the given walk list. NULL indicates that
6580174267aSFredrik Holmqvist  *              the list is empty.
6590174267aSFredrik Holmqvist  *
6600174267aSFredrik Holmqvist  ******************************************************************************/
6610174267aSFredrik Holmqvist 
6620174267aSFredrik Holmqvist ACPI_WALK_STATE *
AcpiDsPopWalkState(ACPI_THREAD_STATE * Thread)6630174267aSFredrik Holmqvist AcpiDsPopWalkState (
6640174267aSFredrik Holmqvist     ACPI_THREAD_STATE       *Thread)
6650174267aSFredrik Holmqvist {
6660174267aSFredrik Holmqvist     ACPI_WALK_STATE         *WalkState;
6670174267aSFredrik Holmqvist 
6680174267aSFredrik Holmqvist 
6690174267aSFredrik Holmqvist     ACPI_FUNCTION_TRACE (DsPopWalkState);
6700174267aSFredrik Holmqvist 
6710174267aSFredrik Holmqvist 
6720174267aSFredrik Holmqvist     WalkState = Thread->WalkStateList;
6730174267aSFredrik Holmqvist 
6740174267aSFredrik Holmqvist     if (WalkState)
6750174267aSFredrik Holmqvist     {
6760174267aSFredrik Holmqvist         /* Next walk state becomes the current walk state */
6770174267aSFredrik Holmqvist 
6780174267aSFredrik Holmqvist         Thread->WalkStateList = WalkState->Next;
6790174267aSFredrik Holmqvist 
6800174267aSFredrik Holmqvist         /*
6810174267aSFredrik Holmqvist          * Don't clear the NEXT field, this serves as an indicator
6820174267aSFredrik Holmqvist          * that there is a parent WALK STATE
6830174267aSFredrik Holmqvist          * Do Not: WalkState->Next = NULL;
6840174267aSFredrik Holmqvist          */
6850174267aSFredrik Holmqvist     }
6860174267aSFredrik Holmqvist 
6870174267aSFredrik Holmqvist     return_PTR (WalkState);
6880174267aSFredrik Holmqvist }
6890174267aSFredrik Holmqvist 
6900174267aSFredrik Holmqvist 
6910174267aSFredrik Holmqvist /*******************************************************************************
6920174267aSFredrik Holmqvist  *
6930174267aSFredrik Holmqvist  * FUNCTION:    AcpiDsCreateWalkState
6940174267aSFredrik Holmqvist  *
6950174267aSFredrik Holmqvist  * PARAMETERS:  OwnerId         - ID for object creation
6960174267aSFredrik Holmqvist  *              Origin          - Starting point for this walk
6970174267aSFredrik Holmqvist  *              MethodDesc      - Method object
6980174267aSFredrik Holmqvist  *              Thread          - Current thread state
6990174267aSFredrik Holmqvist  *
7000174267aSFredrik Holmqvist  * RETURN:      Pointer to the new walk state.
7010174267aSFredrik Holmqvist  *
7020174267aSFredrik Holmqvist  * DESCRIPTION: Allocate and initialize a new walk state. The current walk
7030174267aSFredrik Holmqvist  *              state is set to this new state.
7040174267aSFredrik Holmqvist  *
7050174267aSFredrik Holmqvist  ******************************************************************************/
7060174267aSFredrik Holmqvist 
7070174267aSFredrik Holmqvist ACPI_WALK_STATE *
AcpiDsCreateWalkState(ACPI_OWNER_ID OwnerId,ACPI_PARSE_OBJECT * Origin,ACPI_OPERAND_OBJECT * MethodDesc,ACPI_THREAD_STATE * Thread)7080174267aSFredrik Holmqvist AcpiDsCreateWalkState (
7090174267aSFredrik Holmqvist     ACPI_OWNER_ID           OwnerId,
7100174267aSFredrik Holmqvist     ACPI_PARSE_OBJECT       *Origin,
7110174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     *MethodDesc,
7120174267aSFredrik Holmqvist     ACPI_THREAD_STATE       *Thread)
7130174267aSFredrik Holmqvist {
7140174267aSFredrik Holmqvist     ACPI_WALK_STATE         *WalkState;
7150174267aSFredrik Holmqvist 
7160174267aSFredrik Holmqvist 
7170174267aSFredrik Holmqvist     ACPI_FUNCTION_TRACE (DsCreateWalkState);
7180174267aSFredrik Holmqvist 
7190174267aSFredrik Holmqvist 
7200174267aSFredrik Holmqvist     WalkState = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_WALK_STATE));
7210174267aSFredrik Holmqvist     if (!WalkState)
7220174267aSFredrik Holmqvist     {
7230174267aSFredrik Holmqvist         return_PTR (NULL);
7240174267aSFredrik Holmqvist     }
7250174267aSFredrik Holmqvist 
7260174267aSFredrik Holmqvist     WalkState->DescriptorType = ACPI_DESC_TYPE_WALK;
7270174267aSFredrik Holmqvist     WalkState->MethodDesc = MethodDesc;
7280174267aSFredrik Holmqvist     WalkState->OwnerId = OwnerId;
7290174267aSFredrik Holmqvist     WalkState->Origin = Origin;
7300174267aSFredrik Holmqvist     WalkState->Thread = Thread;
7310174267aSFredrik Holmqvist 
7320174267aSFredrik Holmqvist     WalkState->ParserState.StartOp = Origin;
7330174267aSFredrik Holmqvist 
7340174267aSFredrik Holmqvist     /* Init the method args/local */
7350174267aSFredrik Holmqvist 
73608c9948cSFredrik Holmqvist #ifndef ACPI_CONSTANT_EVAL_ONLY
7370174267aSFredrik Holmqvist     AcpiDsMethodDataInit (WalkState);
7380174267aSFredrik Holmqvist #endif
7390174267aSFredrik Holmqvist 
7400174267aSFredrik Holmqvist     /* Put the new state at the head of the walk list */
7410174267aSFredrik Holmqvist 
7420174267aSFredrik Holmqvist     if (Thread)
7430174267aSFredrik Holmqvist     {
7440174267aSFredrik Holmqvist         AcpiDsPushWalkState (WalkState, Thread);
7450174267aSFredrik Holmqvist     }
7460174267aSFredrik Holmqvist 
7470174267aSFredrik Holmqvist     return_PTR (WalkState);
7480174267aSFredrik Holmqvist }
7490174267aSFredrik Holmqvist 
7500174267aSFredrik Holmqvist 
7510174267aSFredrik Holmqvist /*******************************************************************************
7520174267aSFredrik Holmqvist  *
7530174267aSFredrik Holmqvist  * FUNCTION:    AcpiDsInitAmlWalk
7540174267aSFredrik Holmqvist  *
7550174267aSFredrik Holmqvist  * PARAMETERS:  WalkState       - New state to be initialized
7560174267aSFredrik Holmqvist  *              Op              - Current parse op
7570174267aSFredrik Holmqvist  *              MethodNode      - Control method NS node, if any
7580174267aSFredrik Holmqvist  *              AmlStart        - Start of AML
7590174267aSFredrik Holmqvist  *              AmlLength       - Length of AML
7600174267aSFredrik Holmqvist  *              Info            - Method info block (params, etc.)
7610174267aSFredrik Holmqvist  *              PassNumber      - 1, 2, or 3
7620174267aSFredrik Holmqvist  *
7630174267aSFredrik Holmqvist  * RETURN:      Status
7640174267aSFredrik Holmqvist  *
7650174267aSFredrik Holmqvist  * DESCRIPTION: Initialize a walk state for a pass 1 or 2 parse tree walk
7660174267aSFredrik Holmqvist  *
7670174267aSFredrik Holmqvist  ******************************************************************************/
7680174267aSFredrik Holmqvist 
7690174267aSFredrik Holmqvist ACPI_STATUS
AcpiDsInitAmlWalk(ACPI_WALK_STATE * WalkState,ACPI_PARSE_OBJECT * Op,ACPI_NAMESPACE_NODE * MethodNode,UINT8 * AmlStart,UINT32 AmlLength,ACPI_EVALUATE_INFO * Info,UINT8 PassNumber)7700174267aSFredrik Holmqvist AcpiDsInitAmlWalk (
7710174267aSFredrik Holmqvist     ACPI_WALK_STATE         *WalkState,
7720174267aSFredrik Holmqvist     ACPI_PARSE_OBJECT       *Op,
7730174267aSFredrik Holmqvist     ACPI_NAMESPACE_NODE     *MethodNode,
7740174267aSFredrik Holmqvist     UINT8                   *AmlStart,
7750174267aSFredrik Holmqvist     UINT32                  AmlLength,
7760174267aSFredrik Holmqvist     ACPI_EVALUATE_INFO      *Info,
7770174267aSFredrik Holmqvist     UINT8                   PassNumber)
7780174267aSFredrik Holmqvist {
7790174267aSFredrik Holmqvist     ACPI_STATUS             Status;
7800174267aSFredrik Holmqvist     ACPI_PARSE_STATE        *ParserState = &WalkState->ParserState;
7810174267aSFredrik Holmqvist     ACPI_PARSE_OBJECT       *ExtraOp;
7820174267aSFredrik Holmqvist 
7830174267aSFredrik Holmqvist 
7840174267aSFredrik Holmqvist     ACPI_FUNCTION_TRACE (DsInitAmlWalk);
7850174267aSFredrik Holmqvist 
7860174267aSFredrik Holmqvist 
7870174267aSFredrik Holmqvist     WalkState->ParserState.Aml =
78815338de9SPulkoMandy     WalkState->ParserState.AmlStart =
7890174267aSFredrik Holmqvist     WalkState->ParserState.AmlEnd =
79015338de9SPulkoMandy     WalkState->ParserState.PkgEnd = AmlStart;
79115338de9SPulkoMandy     /* Avoid undefined behavior: applying zero offset to null pointer */
79215338de9SPulkoMandy     if (AmlLength != 0) {
79315338de9SPulkoMandy       WalkState->ParserState.AmlEnd += AmlLength;
79415338de9SPulkoMandy       WalkState->ParserState.PkgEnd += AmlLength;
79515338de9SPulkoMandy     }
7960174267aSFredrik Holmqvist 
7970174267aSFredrik Holmqvist     /* The NextOp of the NextWalk will be the beginning of the method */
7980174267aSFredrik Holmqvist 
7990174267aSFredrik Holmqvist     WalkState->NextOp = NULL;
8000174267aSFredrik Holmqvist     WalkState->PassNumber = PassNumber;
8010174267aSFredrik Holmqvist 
8020174267aSFredrik Holmqvist     if (Info)
8030174267aSFredrik Holmqvist     {
8040174267aSFredrik Holmqvist         WalkState->Params = Info->Parameters;
8050174267aSFredrik Holmqvist         WalkState->CallerReturnDesc = &Info->ReturnObject;
8060174267aSFredrik Holmqvist     }
8070174267aSFredrik Holmqvist 
8080174267aSFredrik Holmqvist     Status = AcpiPsInitScope (&WalkState->ParserState, Op);
8090174267aSFredrik Holmqvist     if (ACPI_FAILURE (Status))
8100174267aSFredrik Holmqvist     {
8110174267aSFredrik Holmqvist         return_ACPI_STATUS (Status);
8120174267aSFredrik Holmqvist     }
8130174267aSFredrik Holmqvist 
8140174267aSFredrik Holmqvist     if (MethodNode)
8150174267aSFredrik Holmqvist     {
8160174267aSFredrik Holmqvist         WalkState->ParserState.StartNode = MethodNode;
8170174267aSFredrik Holmqvist         WalkState->WalkType = ACPI_WALK_METHOD;
8180174267aSFredrik Holmqvist         WalkState->MethodNode = MethodNode;
8190174267aSFredrik Holmqvist         WalkState->MethodDesc = AcpiNsGetAttachedObject (MethodNode);
8200174267aSFredrik Holmqvist 
8210174267aSFredrik Holmqvist         /* Push start scope on scope stack and make it current  */
8220174267aSFredrik Holmqvist 
823b64e8511SFredrik Holmqvist         Status = AcpiDsScopeStackPush (
824b64e8511SFredrik Holmqvist             MethodNode, ACPI_TYPE_METHOD, WalkState);
8250174267aSFredrik Holmqvist         if (ACPI_FAILURE (Status))
8260174267aSFredrik Holmqvist         {
8270174267aSFredrik Holmqvist             return_ACPI_STATUS (Status);
8280174267aSFredrik Holmqvist         }
8290174267aSFredrik Holmqvist 
8300174267aSFredrik Holmqvist         /* Init the method arguments */
8310174267aSFredrik Holmqvist 
8320174267aSFredrik Holmqvist         Status = AcpiDsMethodDataInitArgs (WalkState->Params,
8330174267aSFredrik Holmqvist                     ACPI_METHOD_NUM_ARGS, WalkState);
8340174267aSFredrik Holmqvist         if (ACPI_FAILURE (Status))
8350174267aSFredrik Holmqvist         {
8360174267aSFredrik Holmqvist             return_ACPI_STATUS (Status);
8370174267aSFredrik Holmqvist         }
8380174267aSFredrik Holmqvist     }
8390174267aSFredrik Holmqvist     else
8400174267aSFredrik Holmqvist     {
8410174267aSFredrik Holmqvist         /*
8420174267aSFredrik Holmqvist          * Setup the current scope.
8430174267aSFredrik Holmqvist          * Find a Named Op that has a namespace node associated with it.
8440174267aSFredrik Holmqvist          * search upwards from this Op. Current scope is the first
8450174267aSFredrik Holmqvist          * Op with a namespace node.
8460174267aSFredrik Holmqvist          */
8470174267aSFredrik Holmqvist         ExtraOp = ParserState->StartOp;
8480174267aSFredrik Holmqvist         while (ExtraOp && !ExtraOp->Common.Node)
8490174267aSFredrik Holmqvist         {
8500174267aSFredrik Holmqvist             ExtraOp = ExtraOp->Common.Parent;
8510174267aSFredrik Holmqvist         }
8520174267aSFredrik Holmqvist 
8530174267aSFredrik Holmqvist         if (!ExtraOp)
8540174267aSFredrik Holmqvist         {
8550174267aSFredrik Holmqvist             ParserState->StartNode = NULL;
8560174267aSFredrik Holmqvist         }
8570174267aSFredrik Holmqvist         else
8580174267aSFredrik Holmqvist         {
8590174267aSFredrik Holmqvist             ParserState->StartNode = ExtraOp->Common.Node;
8600174267aSFredrik Holmqvist         }
8610174267aSFredrik Holmqvist 
8620174267aSFredrik Holmqvist         if (ParserState->StartNode)
8630174267aSFredrik Holmqvist         {
8640174267aSFredrik Holmqvist             /* Push start scope on scope stack and make it current  */
8650174267aSFredrik Holmqvist 
8660174267aSFredrik Holmqvist             Status = AcpiDsScopeStackPush (ParserState->StartNode,
8670174267aSFredrik Holmqvist                 ParserState->StartNode->Type, WalkState);
8680174267aSFredrik Holmqvist             if (ACPI_FAILURE (Status))
8690174267aSFredrik Holmqvist             {
8700174267aSFredrik Holmqvist                 return_ACPI_STATUS (Status);
8710174267aSFredrik Holmqvist             }
8720174267aSFredrik Holmqvist         }
8730174267aSFredrik Holmqvist     }
8740174267aSFredrik Holmqvist 
8750174267aSFredrik Holmqvist     Status = AcpiDsInitCallbacks (WalkState, PassNumber);
8760174267aSFredrik Holmqvist     return_ACPI_STATUS (Status);
8770174267aSFredrik Holmqvist }
8780174267aSFredrik Holmqvist 
8790174267aSFredrik Holmqvist 
8800174267aSFredrik Holmqvist /*******************************************************************************
8810174267aSFredrik Holmqvist  *
8820174267aSFredrik Holmqvist  * FUNCTION:    AcpiDsDeleteWalkState
8830174267aSFredrik Holmqvist  *
8840174267aSFredrik Holmqvist  * PARAMETERS:  WalkState       - State to delete
8850174267aSFredrik Holmqvist  *
8860174267aSFredrik Holmqvist  * RETURN:      Status
8870174267aSFredrik Holmqvist  *
8880174267aSFredrik Holmqvist  * DESCRIPTION: Delete a walk state including all internal data structures
8890174267aSFredrik Holmqvist  *
8900174267aSFredrik Holmqvist  ******************************************************************************/
8910174267aSFredrik Holmqvist 
8920174267aSFredrik Holmqvist void
AcpiDsDeleteWalkState(ACPI_WALK_STATE * WalkState)8930174267aSFredrik Holmqvist AcpiDsDeleteWalkState (
8940174267aSFredrik Holmqvist     ACPI_WALK_STATE         *WalkState)
8950174267aSFredrik Holmqvist {
8960174267aSFredrik Holmqvist     ACPI_GENERIC_STATE      *State;
8970174267aSFredrik Holmqvist 
8980174267aSFredrik Holmqvist 
8990174267aSFredrik Holmqvist     ACPI_FUNCTION_TRACE_PTR (DsDeleteWalkState, WalkState);
9000174267aSFredrik Holmqvist 
9010174267aSFredrik Holmqvist 
9020174267aSFredrik Holmqvist     if (!WalkState)
9030174267aSFredrik Holmqvist     {
9049b0d045cSFredrik Holmqvist         return_VOID;
9050174267aSFredrik Holmqvist     }
9060174267aSFredrik Holmqvist 
9070174267aSFredrik Holmqvist     if (WalkState->DescriptorType != ACPI_DESC_TYPE_WALK)
9080174267aSFredrik Holmqvist     {
9090174267aSFredrik Holmqvist         ACPI_ERROR ((AE_INFO, "%p is not a valid walk state",
9100174267aSFredrik Holmqvist             WalkState));
9119b0d045cSFredrik Holmqvist         return_VOID;
9120174267aSFredrik Holmqvist     }
9130174267aSFredrik Holmqvist 
9140174267aSFredrik Holmqvist     /* There should not be any open scopes */
9150174267aSFredrik Holmqvist 
9160174267aSFredrik Holmqvist     if (WalkState->ParserState.Scope)
9170174267aSFredrik Holmqvist     {
9180174267aSFredrik Holmqvist         ACPI_ERROR ((AE_INFO, "%p walk still has a scope list",
9190174267aSFredrik Holmqvist             WalkState));
9200174267aSFredrik Holmqvist         AcpiPsCleanupScope (&WalkState->ParserState);
9210174267aSFredrik Holmqvist     }
9220174267aSFredrik Holmqvist 
9230174267aSFredrik Holmqvist     /* Always must free any linked control states */
9240174267aSFredrik Holmqvist 
9250174267aSFredrik Holmqvist     while (WalkState->ControlState)
9260174267aSFredrik Holmqvist     {
9270174267aSFredrik Holmqvist         State = WalkState->ControlState;
9280174267aSFredrik Holmqvist         WalkState->ControlState = State->Common.Next;
9290174267aSFredrik Holmqvist 
9300174267aSFredrik Holmqvist         AcpiUtDeleteGenericState (State);
9310174267aSFredrik Holmqvist     }
9320174267aSFredrik Holmqvist 
9330174267aSFredrik Holmqvist     /* Always must free any linked parse states */
9340174267aSFredrik Holmqvist 
9350174267aSFredrik Holmqvist     while (WalkState->ScopeInfo)
9360174267aSFredrik Holmqvist     {
9370174267aSFredrik Holmqvist         State = WalkState->ScopeInfo;
9380174267aSFredrik Holmqvist         WalkState->ScopeInfo = State->Common.Next;
9390174267aSFredrik Holmqvist 
9400174267aSFredrik Holmqvist         AcpiUtDeleteGenericState (State);
9410174267aSFredrik Holmqvist     }
9420174267aSFredrik Holmqvist 
9430174267aSFredrik Holmqvist     /* Always must free any stacked result states */
9440174267aSFredrik Holmqvist 
9450174267aSFredrik Holmqvist     while (WalkState->Results)
9460174267aSFredrik Holmqvist     {
9470174267aSFredrik Holmqvist         State = WalkState->Results;
9480174267aSFredrik Holmqvist         WalkState->Results = State->Common.Next;
9490174267aSFredrik Holmqvist 
9500174267aSFredrik Holmqvist         AcpiUtDeleteGenericState (State);
9510174267aSFredrik Holmqvist     }
9520174267aSFredrik Holmqvist 
9530174267aSFredrik Holmqvist     ACPI_FREE (WalkState);
9540174267aSFredrik Holmqvist     return_VOID;
9550174267aSFredrik Holmqvist }
956