xref: /onnv-gate/usr/src/uts/intel/io/acpica/utilities/utstate.c (revision 9980:13d7f3eec672)
13446Smrj /*******************************************************************************
23446Smrj  *
33446Smrj  * Module Name: utstate - state object support procedures
43446Smrj  *
53446Smrj  ******************************************************************************/
63446Smrj 
73446Smrj /******************************************************************************
83446Smrj  *
93446Smrj  * 1. Copyright Notice
103446Smrj  *
11*9980SDana.Myers@Sun.COM  * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
123446Smrj  * All rights reserved.
133446Smrj  *
143446Smrj  * 2. License
153446Smrj  *
163446Smrj  * 2.1. This is your license from Intel Corp. under its intellectual property
173446Smrj  * rights.  You may have additional license terms from the party that provided
183446Smrj  * you this software, covering your right to use that party's intellectual
193446Smrj  * property rights.
203446Smrj  *
213446Smrj  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
223446Smrj  * copy of the source code appearing in this file ("Covered Code") an
233446Smrj  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
243446Smrj  * base code distributed originally by Intel ("Original Intel Code") to copy,
253446Smrj  * make derivatives, distribute, use and display any portion of the Covered
263446Smrj  * Code in any form, with the right to sublicense such rights; and
273446Smrj  *
283446Smrj  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
293446Smrj  * license (with the right to sublicense), under only those claims of Intel
303446Smrj  * patents that are infringed by the Original Intel Code, to make, use, sell,
313446Smrj  * offer to sell, and import the Covered Code and derivative works thereof
323446Smrj  * solely to the minimum extent necessary to exercise the above copyright
333446Smrj  * license, and in no event shall the patent license extend to any additions
343446Smrj  * to or modifications of the Original Intel Code.  No other license or right
353446Smrj  * is granted directly or by implication, estoppel or otherwise;
363446Smrj  *
373446Smrj  * The above copyright and patent license is granted only if the following
383446Smrj  * conditions are met:
393446Smrj  *
403446Smrj  * 3. Conditions
413446Smrj  *
423446Smrj  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
433446Smrj  * Redistribution of source code of any substantial portion of the Covered
443446Smrj  * Code or modification with rights to further distribute source must include
453446Smrj  * the above Copyright Notice, the above License, this list of Conditions,
463446Smrj  * and the following Disclaimer and Export Compliance provision.  In addition,
473446Smrj  * Licensee must cause all Covered Code to which Licensee contributes to
483446Smrj  * contain a file documenting the changes Licensee made to create that Covered
493446Smrj  * Code and the date of any change.  Licensee must include in that file the
503446Smrj  * documentation of any changes made by any predecessor Licensee.  Licensee
513446Smrj  * must include a prominent statement that the modification is derived,
523446Smrj  * directly or indirectly, from Original Intel Code.
533446Smrj  *
543446Smrj  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
553446Smrj  * Redistribution of source code of any substantial portion of the Covered
563446Smrj  * Code or modification without rights to further distribute source must
573446Smrj  * include the following Disclaimer and Export Compliance provision in the
583446Smrj  * documentation and/or other materials provided with distribution.  In
593446Smrj  * addition, Licensee may not authorize further sublicense of source of any
603446Smrj  * portion of the Covered Code, and must include terms to the effect that the
613446Smrj  * license from Licensee to its licensee is limited to the intellectual
623446Smrj  * property embodied in the software Licensee provides to its licensee, and
633446Smrj  * not to intellectual property embodied in modifications its licensee may
643446Smrj  * make.
653446Smrj  *
663446Smrj  * 3.3. Redistribution of Executable. Redistribution in executable form of any
673446Smrj  * substantial portion of the Covered Code or modification must reproduce the
683446Smrj  * above Copyright Notice, and the following Disclaimer and Export Compliance
693446Smrj  * provision in the documentation and/or other materials provided with the
703446Smrj  * distribution.
713446Smrj  *
723446Smrj  * 3.4. Intel retains all right, title, and interest in and to the Original
733446Smrj  * Intel Code.
743446Smrj  *
753446Smrj  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
763446Smrj  * Intel shall be used in advertising or otherwise to promote the sale, use or
773446Smrj  * other dealings in products derived from or relating to the Covered Code
783446Smrj  * without prior written authorization from Intel.
793446Smrj  *
803446Smrj  * 4. Disclaimer and Export Compliance
813446Smrj  *
823446Smrj  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
833446Smrj  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
843446Smrj  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
853446Smrj  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
863446Smrj  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
873446Smrj  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
883446Smrj  * PARTICULAR PURPOSE.
893446Smrj  *
903446Smrj  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
913446Smrj  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
923446Smrj  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
933446Smrj  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
943446Smrj  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
953446Smrj  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
963446Smrj  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
973446Smrj  * LIMITED REMEDY.
983446Smrj  *
993446Smrj  * 4.3. Licensee shall not export, either directly or indirectly, any of this
1003446Smrj  * software or system incorporating such software without first obtaining any
1013446Smrj  * required license or other approval from the U. S. Department of Commerce or
1023446Smrj  * any other agency or department of the United States Government.  In the
1033446Smrj  * event Licensee exports any such software from the United States or
1043446Smrj  * re-exports any such software from a foreign destination, Licensee shall
1053446Smrj  * ensure that the distribution and export/re-export of the software is in
1063446Smrj  * compliance with all laws, regulations, orders, or other restrictions of the
1073446Smrj  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
1083446Smrj  * any of its subsidiaries will export/re-export any technical data, process,
1093446Smrj  * software, or service, directly or indirectly, to any country for which the
1103446Smrj  * United States government or any agency thereof requires an export license,
1113446Smrj  * other governmental approval, or letter of assurance, without first obtaining
1123446Smrj  * such license, approval or letter.
1133446Smrj  *
1143446Smrj  *****************************************************************************/
1153446Smrj 
1163446Smrj 
1173446Smrj #define __UTSTATE_C__
1183446Smrj 
1193446Smrj #include "acpi.h"
120*9980SDana.Myers@Sun.COM #include "accommon.h"
1213446Smrj 
1223446Smrj #define _COMPONENT          ACPI_UTILITIES
1233446Smrj         ACPI_MODULE_NAME    ("utstate")
1243446Smrj 
1253446Smrj 
1263446Smrj /*******************************************************************************
1273446Smrj  *
1283446Smrj  * FUNCTION:    AcpiUtCreatePkgStateAndPush
1293446Smrj  *
1303446Smrj  * PARAMETERS:  Object          - Object to be added to the new state
1313446Smrj  *              Action          - Increment/Decrement
1323446Smrj  *              StateList       - List the state will be added to
1333446Smrj  *
1343446Smrj  * RETURN:      Status
1353446Smrj  *
1363446Smrj  * DESCRIPTION: Create a new state and push it
1373446Smrj  *
1383446Smrj  ******************************************************************************/
1393446Smrj 
1403446Smrj ACPI_STATUS
AcpiUtCreatePkgStateAndPush(void * InternalObject,void * ExternalObject,UINT16 Index,ACPI_GENERIC_STATE ** StateList)1413446Smrj AcpiUtCreatePkgStateAndPush (
1423446Smrj     void                    *InternalObject,
1433446Smrj     void                    *ExternalObject,
1443446Smrj     UINT16                  Index,
1453446Smrj     ACPI_GENERIC_STATE      **StateList)
1463446Smrj {
1473446Smrj     ACPI_GENERIC_STATE       *State;
1483446Smrj 
1493446Smrj 
1503446Smrj     ACPI_FUNCTION_ENTRY ();
1513446Smrj 
1523446Smrj 
1533446Smrj     State = AcpiUtCreatePkgState (InternalObject, ExternalObject, Index);
1543446Smrj     if (!State)
1553446Smrj     {
1563446Smrj         return (AE_NO_MEMORY);
1573446Smrj     }
1583446Smrj 
1593446Smrj     AcpiUtPushGenericState (StateList, State);
1603446Smrj     return (AE_OK);
1613446Smrj }
1623446Smrj 
1633446Smrj 
1643446Smrj /*******************************************************************************
1653446Smrj  *
1663446Smrj  * FUNCTION:    AcpiUtPushGenericState
1673446Smrj  *
1683446Smrj  * PARAMETERS:  ListHead            - Head of the state stack
1693446Smrj  *              State               - State object to push
1703446Smrj  *
1713446Smrj  * RETURN:      None
1723446Smrj  *
1733446Smrj  * DESCRIPTION: Push a state object onto a state stack
1743446Smrj  *
1753446Smrj  ******************************************************************************/
1763446Smrj 
1773446Smrj void
AcpiUtPushGenericState(ACPI_GENERIC_STATE ** ListHead,ACPI_GENERIC_STATE * State)1783446Smrj AcpiUtPushGenericState (
1793446Smrj     ACPI_GENERIC_STATE      **ListHead,
1803446Smrj     ACPI_GENERIC_STATE      *State)
1813446Smrj {
1823446Smrj     ACPI_FUNCTION_TRACE (UtPushGenericState);
1833446Smrj 
1843446Smrj 
1853446Smrj     /* Push the state object onto the front of the list (stack) */
1863446Smrj 
1873446Smrj     State->Common.Next = *ListHead;
1883446Smrj     *ListHead = State;
1893446Smrj 
1903446Smrj     return_VOID;
1913446Smrj }
1923446Smrj 
1933446Smrj 
1943446Smrj /*******************************************************************************
1953446Smrj  *
1963446Smrj  * FUNCTION:    AcpiUtPopGenericState
1973446Smrj  *
1983446Smrj  * PARAMETERS:  ListHead            - Head of the state stack
1993446Smrj  *
2003446Smrj  * RETURN:      The popped state object
2013446Smrj  *
2023446Smrj  * DESCRIPTION: Pop a state object from a state stack
2033446Smrj  *
2043446Smrj  ******************************************************************************/
2053446Smrj 
2063446Smrj ACPI_GENERIC_STATE *
AcpiUtPopGenericState(ACPI_GENERIC_STATE ** ListHead)2073446Smrj AcpiUtPopGenericState (
2083446Smrj     ACPI_GENERIC_STATE      **ListHead)
2093446Smrj {
2103446Smrj     ACPI_GENERIC_STATE      *State;
2113446Smrj 
2123446Smrj 
2133446Smrj     ACPI_FUNCTION_TRACE (UtPopGenericState);
2143446Smrj 
2153446Smrj 
2163446Smrj     /* Remove the state object at the head of the list (stack) */
2173446Smrj 
2183446Smrj     State = *ListHead;
2193446Smrj     if (State)
2203446Smrj     {
2213446Smrj         /* Update the list head */
2223446Smrj 
2233446Smrj         *ListHead = State->Common.Next;
2243446Smrj     }
2253446Smrj 
2263446Smrj     return_PTR (State);
2273446Smrj }
2283446Smrj 
2293446Smrj 
2303446Smrj /*******************************************************************************
2313446Smrj  *
2323446Smrj  * FUNCTION:    AcpiUtCreateGenericState
2333446Smrj  *
2343446Smrj  * PARAMETERS:  None
2353446Smrj  *
2363446Smrj  * RETURN:      The new state object. NULL on failure.
2373446Smrj  *
2383446Smrj  * DESCRIPTION: Create a generic state object.  Attempt to obtain one from
2393446Smrj  *              the global state cache;  If none available, create a new one.
2403446Smrj  *
2413446Smrj  ******************************************************************************/
2423446Smrj 
2433446Smrj ACPI_GENERIC_STATE *
AcpiUtCreateGenericState(void)2443446Smrj AcpiUtCreateGenericState (
2453446Smrj     void)
2463446Smrj {
2473446Smrj     ACPI_GENERIC_STATE      *State;
2483446Smrj 
2493446Smrj 
2503446Smrj     ACPI_FUNCTION_ENTRY ();
2513446Smrj 
2523446Smrj 
2533446Smrj     State = AcpiOsAcquireObject (AcpiGbl_StateCache);
2543446Smrj     if (State)
2553446Smrj     {
2563446Smrj         /* Initialize */
2573446Smrj         State->Common.DescriptorType = ACPI_DESC_TYPE_STATE;
2583446Smrj     }
2593446Smrj 
2603446Smrj     return (State);
2613446Smrj }
2623446Smrj 
2633446Smrj 
2643446Smrj /*******************************************************************************
2653446Smrj  *
2663446Smrj  * FUNCTION:    AcpiUtCreateThreadState
2673446Smrj  *
2683446Smrj  * PARAMETERS:  None
2693446Smrj  *
2703446Smrj  * RETURN:      New Thread State. NULL on failure
2713446Smrj  *
2723446Smrj  * DESCRIPTION: Create a "Thread State" - a flavor of the generic state used
2733446Smrj  *              to track per-thread info during method execution
2743446Smrj  *
2753446Smrj  ******************************************************************************/
2763446Smrj 
2773446Smrj ACPI_THREAD_STATE *
AcpiUtCreateThreadState(void)2783446Smrj AcpiUtCreateThreadState (
2793446Smrj     void)
2803446Smrj {
2813446Smrj     ACPI_GENERIC_STATE      *State;
2823446Smrj 
2833446Smrj 
2843446Smrj     ACPI_FUNCTION_TRACE (UtCreateThreadState);
2853446Smrj 
2863446Smrj 
2873446Smrj     /* Create the generic state object */
2883446Smrj 
2893446Smrj     State = AcpiUtCreateGenericState ();
2903446Smrj     if (!State)
2913446Smrj     {
2923446Smrj         return_PTR (NULL);
2933446Smrj     }
2943446Smrj 
2953446Smrj     /* Init fields specific to the update struct */
2963446Smrj 
2973446Smrj     State->Common.DescriptorType = ACPI_DESC_TYPE_STATE_THREAD;
2983446Smrj     State->Thread.ThreadId = AcpiOsGetThreadId ();
2993446Smrj 
3003446Smrj     /* Check for invalid thread ID - zero is very bad, it will break things */
3013446Smrj 
3023446Smrj     if (!State->Thread.ThreadId)
3033446Smrj     {
3043446Smrj         ACPI_ERROR ((AE_INFO, "Invalid zero ID from AcpiOsGetThreadId"));
305*9980SDana.Myers@Sun.COM         State->Thread.ThreadId = (ACPI_THREAD_ID) 1;
3063446Smrj     }
3073446Smrj 
3083446Smrj     return_PTR ((ACPI_THREAD_STATE *) State);
3093446Smrj }
3103446Smrj 
3113446Smrj 
3123446Smrj /*******************************************************************************
3133446Smrj  *
3143446Smrj  * FUNCTION:    AcpiUtCreateUpdateState
3153446Smrj  *
3163446Smrj  * PARAMETERS:  Object          - Initial Object to be installed in the state
3173446Smrj  *              Action          - Update action to be performed
3183446Smrj  *
3193446Smrj  * RETURN:      New state object, null on failure
3203446Smrj  *
3213446Smrj  * DESCRIPTION: Create an "Update State" - a flavor of the generic state used
3223446Smrj  *              to update reference counts and delete complex objects such
3233446Smrj  *              as packages.
3243446Smrj  *
3253446Smrj  ******************************************************************************/
3263446Smrj 
3273446Smrj ACPI_GENERIC_STATE *
AcpiUtCreateUpdateState(ACPI_OPERAND_OBJECT * Object,UINT16 Action)3283446Smrj AcpiUtCreateUpdateState (
3293446Smrj     ACPI_OPERAND_OBJECT     *Object,
3303446Smrj     UINT16                  Action)
3313446Smrj {
3323446Smrj     ACPI_GENERIC_STATE      *State;
3333446Smrj 
3343446Smrj 
3353446Smrj     ACPI_FUNCTION_TRACE_PTR (UtCreateUpdateState, Object);
3363446Smrj 
3373446Smrj 
3383446Smrj     /* Create the generic state object */
3393446Smrj 
3403446Smrj     State = AcpiUtCreateGenericState ();
3413446Smrj     if (!State)
3423446Smrj     {
3433446Smrj         return_PTR (NULL);
3443446Smrj     }
3453446Smrj 
3463446Smrj     /* Init fields specific to the update struct */
3473446Smrj 
3483446Smrj     State->Common.DescriptorType = ACPI_DESC_TYPE_STATE_UPDATE;
3493446Smrj     State->Update.Object = Object;
3503446Smrj     State->Update.Value = Action;
3513446Smrj 
3523446Smrj     return_PTR (State);
3533446Smrj }
3543446Smrj 
3553446Smrj 
3563446Smrj /*******************************************************************************
3573446Smrj  *
3583446Smrj  * FUNCTION:    AcpiUtCreatePkgState
3593446Smrj  *
3603446Smrj  * PARAMETERS:  Object          - Initial Object to be installed in the state
3613446Smrj  *              Action          - Update action to be performed
3623446Smrj  *
3633446Smrj  * RETURN:      New state object, null on failure
3643446Smrj  *
3653446Smrj  * DESCRIPTION: Create a "Package State"
3663446Smrj  *
3673446Smrj  ******************************************************************************/
3683446Smrj 
3693446Smrj ACPI_GENERIC_STATE *
AcpiUtCreatePkgState(void * InternalObject,void * ExternalObject,UINT16 Index)3703446Smrj AcpiUtCreatePkgState (
3713446Smrj     void                    *InternalObject,
3723446Smrj     void                    *ExternalObject,
3733446Smrj     UINT16                  Index)
3743446Smrj {
3753446Smrj     ACPI_GENERIC_STATE      *State;
3763446Smrj 
3773446Smrj 
3783446Smrj     ACPI_FUNCTION_TRACE_PTR (UtCreatePkgState, InternalObject);
3793446Smrj 
3803446Smrj 
3813446Smrj     /* Create the generic state object */
3823446Smrj 
3833446Smrj     State = AcpiUtCreateGenericState ();
3843446Smrj     if (!State)
3853446Smrj     {
3863446Smrj         return_PTR (NULL);
3873446Smrj     }
3883446Smrj 
3893446Smrj     /* Init fields specific to the update struct */
3903446Smrj 
3913446Smrj     State->Common.DescriptorType = ACPI_DESC_TYPE_STATE_PACKAGE;
3923446Smrj     State->Pkg.SourceObject = (ACPI_OPERAND_OBJECT *) InternalObject;
3933446Smrj     State->Pkg.DestObject = ExternalObject;
3943446Smrj     State->Pkg.Index= Index;
3953446Smrj     State->Pkg.NumPackages = 1;
3963446Smrj 
3973446Smrj     return_PTR (State);
3983446Smrj }
3993446Smrj 
4003446Smrj 
4013446Smrj /*******************************************************************************
4023446Smrj  *
4033446Smrj  * FUNCTION:    AcpiUtCreateControlState
4043446Smrj  *
4053446Smrj  * PARAMETERS:  None
4063446Smrj  *
4073446Smrj  * RETURN:      New state object, null on failure
4083446Smrj  *
4093446Smrj  * DESCRIPTION: Create a "Control State" - a flavor of the generic state used
4103446Smrj  *              to support nested IF/WHILE constructs in the AML.
4113446Smrj  *
4123446Smrj  ******************************************************************************/
4133446Smrj 
4143446Smrj ACPI_GENERIC_STATE *
AcpiUtCreateControlState(void)4153446Smrj AcpiUtCreateControlState (
4163446Smrj     void)
4173446Smrj {
4183446Smrj     ACPI_GENERIC_STATE      *State;
4193446Smrj 
4203446Smrj 
4213446Smrj     ACPI_FUNCTION_TRACE (UtCreateControlState);
4223446Smrj 
4233446Smrj 
4243446Smrj     /* Create the generic state object */
4253446Smrj 
4263446Smrj     State = AcpiUtCreateGenericState ();
4273446Smrj     if (!State)
4283446Smrj     {
4293446Smrj         return_PTR (NULL);
4303446Smrj     }
4313446Smrj 
4323446Smrj     /* Init fields specific to the control struct */
4333446Smrj 
4343446Smrj     State->Common.DescriptorType = ACPI_DESC_TYPE_STATE_CONTROL;
4353446Smrj     State->Common.State = ACPI_CONTROL_CONDITIONAL_EXECUTING;
4363446Smrj 
4373446Smrj     return_PTR (State);
4383446Smrj }
4393446Smrj 
4403446Smrj 
4413446Smrj /*******************************************************************************
4423446Smrj  *
4433446Smrj  * FUNCTION:    AcpiUtDeleteGenericState
4443446Smrj  *
4453446Smrj  * PARAMETERS:  State               - The state object to be deleted
4463446Smrj  *
4473446Smrj  * RETURN:      None
4483446Smrj  *
4493446Smrj  * DESCRIPTION: Release a state object to the state cache. NULL state objects
4503446Smrj  *              are ignored.
4513446Smrj  *
4523446Smrj  ******************************************************************************/
4533446Smrj 
4543446Smrj void
AcpiUtDeleteGenericState(ACPI_GENERIC_STATE * State)4553446Smrj AcpiUtDeleteGenericState (
4563446Smrj     ACPI_GENERIC_STATE      *State)
4573446Smrj {
4583446Smrj     ACPI_FUNCTION_TRACE (UtDeleteGenericState);
4593446Smrj 
4603446Smrj 
4613446Smrj     /* Ignore null state */
4623446Smrj 
4633446Smrj     if (State)
4643446Smrj     {
4653446Smrj         (void) AcpiOsReleaseObject (AcpiGbl_StateCache, State);
4663446Smrj     }
4673446Smrj     return_VOID;
4683446Smrj }
4693446Smrj 
4703446Smrj 
471