1 /*******************************************************************************
3 * Module Name: utstate - state object support procedures
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2013, 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.
50 #define _COMPONENT ACPI_UTILITIES
51 ACPI_MODULE_NAME ("utstate")
54 /*******************************************************************************
56 * FUNCTION: AcpiUtCreatePkgStateAndPush
58 * PARAMETERS: Object - Object to be added to the new state
59 * Action - Increment/Decrement
60 * StateList - List the state will be added to
64 * DESCRIPTION: Create a new state and push it
66 ******************************************************************************/
69 AcpiUtCreatePkgStateAndPush (
73 ACPI_GENERIC_STATE
**StateList
)
75 ACPI_GENERIC_STATE
*State
;
78 ACPI_FUNCTION_ENTRY ();
81 State
= AcpiUtCreatePkgState (InternalObject
, ExternalObject
, Index
);
84 return (AE_NO_MEMORY
);
87 AcpiUtPushGenericState (StateList
, State
);
92 /*******************************************************************************
94 * FUNCTION: AcpiUtPushGenericState
96 * PARAMETERS: ListHead - Head of the state stack
97 * State - State object to push
101 * DESCRIPTION: Push a state object onto a state stack
103 ******************************************************************************/
106 AcpiUtPushGenericState (
107 ACPI_GENERIC_STATE
**ListHead
,
108 ACPI_GENERIC_STATE
*State
)
110 ACPI_FUNCTION_ENTRY ();
113 /* Push the state object onto the front of the list (stack) */
115 State
->Common
.Next
= *ListHead
;
121 /*******************************************************************************
123 * FUNCTION: AcpiUtPopGenericState
125 * PARAMETERS: ListHead - Head of the state stack
127 * RETURN: The popped state object
129 * DESCRIPTION: Pop a state object from a state stack
131 ******************************************************************************/
134 AcpiUtPopGenericState (
135 ACPI_GENERIC_STATE
**ListHead
)
137 ACPI_GENERIC_STATE
*State
;
140 ACPI_FUNCTION_ENTRY ();
143 /* Remove the state object at the head of the list (stack) */
148 /* Update the list head */
150 *ListHead
= State
->Common
.Next
;
157 /*******************************************************************************
159 * FUNCTION: AcpiUtCreateGenericState
163 * RETURN: The new state object. NULL on failure.
165 * DESCRIPTION: Create a generic state object. Attempt to obtain one from
166 * the global state cache; If none available, create a new one.
168 ******************************************************************************/
171 AcpiUtCreateGenericState (
174 ACPI_GENERIC_STATE
*State
;
177 ACPI_FUNCTION_ENTRY ();
180 State
= AcpiOsAcquireObject (AcpiGbl_StateCache
);
184 State
->Common
.DescriptorType
= ACPI_DESC_TYPE_STATE
;
191 /*******************************************************************************
193 * FUNCTION: AcpiUtCreateThreadState
197 * RETURN: New Thread State. NULL on failure
199 * DESCRIPTION: Create a "Thread State" - a flavor of the generic state used
200 * to track per-thread info during method execution
202 ******************************************************************************/
205 AcpiUtCreateThreadState (
208 ACPI_GENERIC_STATE
*State
;
211 ACPI_FUNCTION_ENTRY ();
214 /* Create the generic state object */
216 State
= AcpiUtCreateGenericState ();
222 /* Init fields specific to the update struct */
224 State
->Common
.DescriptorType
= ACPI_DESC_TYPE_STATE_THREAD
;
225 State
->Thread
.ThreadId
= AcpiOsGetThreadId ();
227 /* Check for invalid thread ID - zero is very bad, it will break things */
229 if (!State
->Thread
.ThreadId
)
231 ACPI_ERROR ((AE_INFO
, "Invalid zero ID from AcpiOsGetThreadId"));
232 State
->Thread
.ThreadId
= (ACPI_THREAD_ID
) 1;
235 return ((ACPI_THREAD_STATE
*) State
);
239 /*******************************************************************************
241 * FUNCTION: AcpiUtCreateUpdateState
243 * PARAMETERS: Object - Initial Object to be installed in the state
244 * Action - Update action to be performed
246 * RETURN: New state object, null on failure
248 * DESCRIPTION: Create an "Update State" - a flavor of the generic state used
249 * to update reference counts and delete complex objects such
252 ******************************************************************************/
255 AcpiUtCreateUpdateState (
256 ACPI_OPERAND_OBJECT
*Object
,
259 ACPI_GENERIC_STATE
*State
;
262 ACPI_FUNCTION_ENTRY ();
265 /* Create the generic state object */
267 State
= AcpiUtCreateGenericState ();
273 /* Init fields specific to the update struct */
275 State
->Common
.DescriptorType
= ACPI_DESC_TYPE_STATE_UPDATE
;
276 State
->Update
.Object
= Object
;
277 State
->Update
.Value
= Action
;
282 /*******************************************************************************
284 * FUNCTION: AcpiUtCreatePkgState
286 * PARAMETERS: Object - Initial Object to be installed in the state
287 * Action - Update action to be performed
289 * RETURN: New state object, null on failure
291 * DESCRIPTION: Create a "Package State"
293 ******************************************************************************/
296 AcpiUtCreatePkgState (
297 void *InternalObject
,
298 void *ExternalObject
,
301 ACPI_GENERIC_STATE
*State
;
304 ACPI_FUNCTION_ENTRY ();
307 /* Create the generic state object */
309 State
= AcpiUtCreateGenericState ();
315 /* Init fields specific to the update struct */
317 State
->Common
.DescriptorType
= ACPI_DESC_TYPE_STATE_PACKAGE
;
318 State
->Pkg
.SourceObject
= (ACPI_OPERAND_OBJECT
*) InternalObject
;
319 State
->Pkg
.DestObject
= ExternalObject
;
320 State
->Pkg
.Index
= Index
;
321 State
->Pkg
.NumPackages
= 1;
326 /*******************************************************************************
328 * FUNCTION: AcpiUtCreateControlState
332 * RETURN: New state object, null on failure
334 * DESCRIPTION: Create a "Control State" - a flavor of the generic state used
335 * to support nested IF/WHILE constructs in the AML.
337 ******************************************************************************/
340 AcpiUtCreateControlState (
343 ACPI_GENERIC_STATE
*State
;
346 ACPI_FUNCTION_ENTRY ();
349 /* Create the generic state object */
351 State
= AcpiUtCreateGenericState ();
357 /* Init fields specific to the control struct */
359 State
->Common
.DescriptorType
= ACPI_DESC_TYPE_STATE_CONTROL
;
360 State
->Common
.State
= ACPI_CONTROL_CONDITIONAL_EXECUTING
;
365 /*******************************************************************************
367 * FUNCTION: AcpiUtDeleteGenericState
369 * PARAMETERS: State - The state object to be deleted
373 * DESCRIPTION: Release a state object to the state cache. NULL state objects
376 ******************************************************************************/
379 AcpiUtDeleteGenericState (
380 ACPI_GENERIC_STATE
*State
)
382 ACPI_FUNCTION_ENTRY ();
385 /* Ignore null state */
389 (void) AcpiOsReleaseObject (AcpiGbl_StateCache
, State
);