1 /*******************************************************************************
3 * Module Name: utstate - state object support procedures
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2012, 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_TRACE (UtPushGenericState);
113 /* Push the state object onto the front of the list (stack) */
115 State->Common.Next = *ListHead;
122 /*******************************************************************************
124 * FUNCTION: AcpiUtPopGenericState
126 * PARAMETERS: ListHead - Head of the state stack
128 * RETURN: The popped state object
130 * DESCRIPTION: Pop a state object from a state stack
132 ******************************************************************************/
135 AcpiUtPopGenericState (
136 ACPI_GENERIC_STATE **ListHead)
138 ACPI_GENERIC_STATE *State;
141 ACPI_FUNCTION_TRACE (UtPopGenericState);
144 /* Remove the state object at the head of the list (stack) */
149 /* Update the list head */
151 *ListHead = State->Common.Next;
158 /*******************************************************************************
160 * FUNCTION: AcpiUtCreateGenericState
164 * RETURN: The new state object. NULL on failure.
166 * DESCRIPTION: Create a generic state object. Attempt to obtain one from
167 * the global state cache; If none available, create a new one.
169 ******************************************************************************/
172 AcpiUtCreateGenericState (
175 ACPI_GENERIC_STATE *State;
178 ACPI_FUNCTION_ENTRY ();
181 State = AcpiOsAcquireObject (AcpiGbl_StateCache);
185 State->Common.DescriptorType = ACPI_DESC_TYPE_STATE;
192 /*******************************************************************************
194 * FUNCTION: AcpiUtCreateThreadState
198 * RETURN: New Thread State. NULL on failure
200 * DESCRIPTION: Create a "Thread State" - a flavor of the generic state used
201 * to track per-thread info during method execution
203 ******************************************************************************/
206 AcpiUtCreateThreadState (
209 ACPI_GENERIC_STATE *State;
212 ACPI_FUNCTION_TRACE (UtCreateThreadState);
215 /* Create the generic state object */
217 State = AcpiUtCreateGenericState ();
223 /* Init fields specific to the update struct */
225 State->Common.DescriptorType = ACPI_DESC_TYPE_STATE_THREAD;
226 State->Thread.ThreadId = AcpiOsGetThreadId ();
228 /* Check for invalid thread ID - zero is very bad, it will break things */
230 if (!State->Thread.ThreadId)
232 ACPI_ERROR ((AE_INFO, "Invalid zero ID from AcpiOsGetThreadId"));
233 State->Thread.ThreadId = (ACPI_THREAD_ID) 1;
236 return_PTR ((ACPI_THREAD_STATE *) State);
240 /*******************************************************************************
242 * FUNCTION: AcpiUtCreateUpdateState
244 * PARAMETERS: Object - Initial Object to be installed in the state
245 * Action - Update action to be performed
247 * RETURN: New state object, null on failure
249 * DESCRIPTION: Create an "Update State" - a flavor of the generic state used
250 * to update reference counts and delete complex objects such
253 ******************************************************************************/
256 AcpiUtCreateUpdateState (
257 ACPI_OPERAND_OBJECT *Object,
260 ACPI_GENERIC_STATE *State;
263 ACPI_FUNCTION_TRACE_PTR (UtCreateUpdateState, Object);
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_UPDATE;
277 State->Update.Object = Object;
278 State->Update.Value = Action;
284 /*******************************************************************************
286 * FUNCTION: AcpiUtCreatePkgState
288 * PARAMETERS: Object - Initial Object to be installed in the state
289 * Action - Update action to be performed
291 * RETURN: New state object, null on failure
293 * DESCRIPTION: Create a "Package State"
295 ******************************************************************************/
298 AcpiUtCreatePkgState (
299 void *InternalObject,
300 void *ExternalObject,
303 ACPI_GENERIC_STATE *State;
306 ACPI_FUNCTION_TRACE_PTR (UtCreatePkgState, InternalObject);
309 /* Create the generic state object */
311 State = AcpiUtCreateGenericState ();
317 /* Init fields specific to the update struct */
319 State->Common.DescriptorType = ACPI_DESC_TYPE_STATE_PACKAGE;
320 State->Pkg.SourceObject = (ACPI_OPERAND_OBJECT *) InternalObject;
321 State->Pkg.DestObject = ExternalObject;
322 State->Pkg.Index= Index;
323 State->Pkg.NumPackages = 1;
329 /*******************************************************************************
331 * FUNCTION: AcpiUtCreateControlState
335 * RETURN: New state object, null on failure
337 * DESCRIPTION: Create a "Control State" - a flavor of the generic state used
338 * to support nested IF/WHILE constructs in the AML.
340 ******************************************************************************/
343 AcpiUtCreateControlState (
346 ACPI_GENERIC_STATE *State;
349 ACPI_FUNCTION_TRACE (UtCreateControlState);
352 /* Create the generic state object */
354 State = AcpiUtCreateGenericState ();
360 /* Init fields specific to the control struct */
362 State->Common.DescriptorType = ACPI_DESC_TYPE_STATE_CONTROL;
363 State->Common.State = ACPI_CONTROL_CONDITIONAL_EXECUTING;
369 /*******************************************************************************
371 * FUNCTION: AcpiUtDeleteGenericState
373 * PARAMETERS: State - The state object to be deleted
377 * DESCRIPTION: Release a state object to the state cache. NULL state objects
380 ******************************************************************************/
383 AcpiUtDeleteGenericState (
384 ACPI_GENERIC_STATE *State)
386 ACPI_FUNCTION_TRACE (UtDeleteGenericState);
389 /* Ignore null state */
393 (void) AcpiOsReleaseObject (AcpiGbl_StateCache, State);