1 /*******************************************************************************
3 * Module Name: utstate - state object support procedures
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2016, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
47 #define _COMPONENT ACPI_UTILITIES
48 ACPI_MODULE_NAME ("utstate")
51 /*******************************************************************************
53 * FUNCTION: AcpiUtPushGenericState
55 * PARAMETERS: ListHead - Head of the state stack
56 * State - State object to push
60 * DESCRIPTION: Push a state object onto a state stack
62 ******************************************************************************/
65 AcpiUtPushGenericState (
66 ACPI_GENERIC_STATE
**ListHead
,
67 ACPI_GENERIC_STATE
*State
)
69 ACPI_FUNCTION_ENTRY ();
72 /* Push the state object onto the front of the list (stack) */
74 State
->Common
.Next
= *ListHead
;
80 /*******************************************************************************
82 * FUNCTION: AcpiUtPopGenericState
84 * PARAMETERS: ListHead - Head of the state stack
86 * RETURN: The popped state object
88 * DESCRIPTION: Pop a state object from a state stack
90 ******************************************************************************/
93 AcpiUtPopGenericState (
94 ACPI_GENERIC_STATE
**ListHead
)
96 ACPI_GENERIC_STATE
*State
;
99 ACPI_FUNCTION_ENTRY ();
102 /* Remove the state object at the head of the list (stack) */
107 /* Update the list head */
109 *ListHead
= State
->Common
.Next
;
116 /*******************************************************************************
118 * FUNCTION: AcpiUtCreateGenericState
122 * RETURN: The new state object. NULL on failure.
124 * DESCRIPTION: Create a generic state object. Attempt to obtain one from
125 * the global state cache; If none available, create a new one.
127 ******************************************************************************/
130 AcpiUtCreateGenericState (
133 ACPI_GENERIC_STATE
*State
;
136 ACPI_FUNCTION_ENTRY ();
139 State
= AcpiOsAcquireObject (AcpiGbl_StateCache
);
143 State
->Common
.DescriptorType
= ACPI_DESC_TYPE_STATE
;
150 /*******************************************************************************
152 * FUNCTION: AcpiUtCreateThreadState
156 * RETURN: New Thread State. NULL on failure
158 * DESCRIPTION: Create a "Thread State" - a flavor of the generic state used
159 * to track per-thread info during method execution
161 ******************************************************************************/
164 AcpiUtCreateThreadState (
167 ACPI_GENERIC_STATE
*State
;
170 ACPI_FUNCTION_ENTRY ();
173 /* Create the generic state object */
175 State
= AcpiUtCreateGenericState ();
181 /* Init fields specific to the update struct */
183 State
->Common
.DescriptorType
= ACPI_DESC_TYPE_STATE_THREAD
;
184 State
->Thread
.ThreadId
= AcpiOsGetThreadId ();
186 /* Check for invalid thread ID - zero is very bad, it will break things */
188 if (!State
->Thread
.ThreadId
)
190 ACPI_ERROR ((AE_INFO
, "Invalid zero ID from AcpiOsGetThreadId"));
191 State
->Thread
.ThreadId
= (ACPI_THREAD_ID
) 1;
194 return ((ACPI_THREAD_STATE
*) State
);
198 /*******************************************************************************
200 * FUNCTION: AcpiUtCreateUpdateState
202 * PARAMETERS: Object - Initial Object to be installed in the state
203 * Action - Update action to be performed
205 * RETURN: New state object, null on failure
207 * DESCRIPTION: Create an "Update State" - a flavor of the generic state used
208 * to update reference counts and delete complex objects such
211 ******************************************************************************/
214 AcpiUtCreateUpdateState (
215 ACPI_OPERAND_OBJECT
*Object
,
218 ACPI_GENERIC_STATE
*State
;
221 ACPI_FUNCTION_ENTRY ();
224 /* Create the generic state object */
226 State
= AcpiUtCreateGenericState ();
232 /* Init fields specific to the update struct */
234 State
->Common
.DescriptorType
= ACPI_DESC_TYPE_STATE_UPDATE
;
235 State
->Update
.Object
= Object
;
236 State
->Update
.Value
= Action
;
241 /*******************************************************************************
243 * FUNCTION: AcpiUtCreatePkgState
245 * PARAMETERS: Object - Initial Object to be installed in the state
246 * Action - Update action to be performed
248 * RETURN: New state object, null on failure
250 * DESCRIPTION: Create a "Package State"
252 ******************************************************************************/
255 AcpiUtCreatePkgState (
256 void *InternalObject
,
257 void *ExternalObject
,
260 ACPI_GENERIC_STATE
*State
;
263 ACPI_FUNCTION_ENTRY ();
266 /* Create the generic state object */
268 State
= AcpiUtCreateGenericState ();
274 /* Init fields specific to the update struct */
276 State
->Common
.DescriptorType
= ACPI_DESC_TYPE_STATE_PACKAGE
;
277 State
->Pkg
.SourceObject
= (ACPI_OPERAND_OBJECT
*) InternalObject
;
278 State
->Pkg
.DestObject
= ExternalObject
;
279 State
->Pkg
.Index
= Index
;
280 State
->Pkg
.NumPackages
= 1;
286 /*******************************************************************************
288 * FUNCTION: AcpiUtCreateControlState
292 * RETURN: New state object, null on failure
294 * DESCRIPTION: Create a "Control State" - a flavor of the generic state used
295 * to support nested IF/WHILE constructs in the AML.
297 ******************************************************************************/
300 AcpiUtCreateControlState (
303 ACPI_GENERIC_STATE
*State
;
306 ACPI_FUNCTION_ENTRY ();
309 /* Create the generic state object */
311 State
= AcpiUtCreateGenericState ();
317 /* Init fields specific to the control struct */
319 State
->Common
.DescriptorType
= ACPI_DESC_TYPE_STATE_CONTROL
;
320 State
->Common
.State
= ACPI_CONTROL_CONDITIONAL_EXECUTING
;
326 /*******************************************************************************
328 * FUNCTION: AcpiUtDeleteGenericState
330 * PARAMETERS: State - The state object to be deleted
334 * DESCRIPTION: Release a state object to the state cache. NULL state objects
337 ******************************************************************************/
340 AcpiUtDeleteGenericState (
341 ACPI_GENERIC_STATE
*State
)
343 ACPI_FUNCTION_ENTRY ();
346 /* Ignore null state */
350 (void) AcpiOsReleaseObject (AcpiGbl_StateCache
, State
);