1 /*******************************************************************************
3 * Module Name: utstate - state object support procedures
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2014, 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.
49 #define _COMPONENT ACPI_UTILITIES
50 ACPI_MODULE_NAME ("utstate")
53 /*******************************************************************************
55 * FUNCTION: AcpiUtCreatePkgStateAndPush
57 * PARAMETERS: Object - Object to be added to the new state
58 * Action - Increment/Decrement
59 * StateList - List the state will be added to
63 * DESCRIPTION: Create a new state and push it
65 ******************************************************************************/
68 AcpiUtCreatePkgStateAndPush (
72 ACPI_GENERIC_STATE **StateList)
74 ACPI_GENERIC_STATE *State;
77 ACPI_FUNCTION_ENTRY ();
80 State = AcpiUtCreatePkgState (InternalObject, ExternalObject, Index);
83 return (AE_NO_MEMORY);
86 AcpiUtPushGenericState (StateList, State);
91 /*******************************************************************************
93 * FUNCTION: AcpiUtPushGenericState
95 * PARAMETERS: ListHead - Head of the state stack
96 * State - State object to push
100 * DESCRIPTION: Push a state object onto a state stack
102 ******************************************************************************/
105 AcpiUtPushGenericState (
106 ACPI_GENERIC_STATE **ListHead,
107 ACPI_GENERIC_STATE *State)
109 ACPI_FUNCTION_ENTRY ();
112 /* Push the state object onto the front of the list (stack) */
114 State->Common.Next = *ListHead;
120 /*******************************************************************************
122 * FUNCTION: AcpiUtPopGenericState
124 * PARAMETERS: ListHead - Head of the state stack
126 * RETURN: The popped state object
128 * DESCRIPTION: Pop a state object from a state stack
130 ******************************************************************************/
133 AcpiUtPopGenericState (
134 ACPI_GENERIC_STATE **ListHead)
136 ACPI_GENERIC_STATE *State;
139 ACPI_FUNCTION_ENTRY ();
142 /* Remove the state object at the head of the list (stack) */
147 /* Update the list head */
149 *ListHead = State->Common.Next;
156 /*******************************************************************************
158 * FUNCTION: AcpiUtCreateGenericState
162 * RETURN: The new state object. NULL on failure.
164 * DESCRIPTION: Create a generic state object. Attempt to obtain one from
165 * the global state cache; If none available, create a new one.
167 ******************************************************************************/
170 AcpiUtCreateGenericState (
173 ACPI_GENERIC_STATE *State;
176 ACPI_FUNCTION_ENTRY ();
179 State = AcpiOsAcquireObject (AcpiGbl_StateCache);
183 State->Common.DescriptorType = ACPI_DESC_TYPE_STATE;
190 /*******************************************************************************
192 * FUNCTION: AcpiUtCreateThreadState
196 * RETURN: New Thread State. NULL on failure
198 * DESCRIPTION: Create a "Thread State" - a flavor of the generic state used
199 * to track per-thread info during method execution
201 ******************************************************************************/
204 AcpiUtCreateThreadState (
207 ACPI_GENERIC_STATE *State;
210 ACPI_FUNCTION_ENTRY ();
213 /* Create the generic state object */
215 State = AcpiUtCreateGenericState ();
221 /* Init fields specific to the update struct */
223 State->Common.DescriptorType = ACPI_DESC_TYPE_STATE_THREAD;
224 State->Thread.ThreadId = AcpiOsGetThreadId ();
226 /* Check for invalid thread ID - zero is very bad, it will break things */
228 if (!State->Thread.ThreadId)
230 ACPI_ERROR ((AE_INFO, "Invalid zero ID from AcpiOsGetThreadId"));
231 State->Thread.ThreadId = (ACPI_THREAD_ID) 1;
234 return ((ACPI_THREAD_STATE *) State);
238 /*******************************************************************************
240 * FUNCTION: AcpiUtCreateUpdateState
242 * PARAMETERS: Object - Initial Object to be installed in the state
243 * Action - Update action to be performed
245 * RETURN: New state object, null on failure
247 * DESCRIPTION: Create an "Update State" - a flavor of the generic state used
248 * to update reference counts and delete complex objects such
251 ******************************************************************************/
254 AcpiUtCreateUpdateState (
255 ACPI_OPERAND_OBJECT *Object,
258 ACPI_GENERIC_STATE *State;
261 ACPI_FUNCTION_ENTRY ();
264 /* Create the generic state object */
266 State = AcpiUtCreateGenericState ();
272 /* Init fields specific to the update struct */
274 State->Common.DescriptorType = ACPI_DESC_TYPE_STATE_UPDATE;
275 State->Update.Object = Object;
276 State->Update.Value = Action;
281 /*******************************************************************************
283 * FUNCTION: AcpiUtCreatePkgState
285 * PARAMETERS: Object - Initial Object to be installed in the state
286 * Action - Update action to be performed
288 * RETURN: New state object, null on failure
290 * DESCRIPTION: Create a "Package State"
292 ******************************************************************************/
295 AcpiUtCreatePkgState (
296 void *InternalObject,
297 void *ExternalObject,
300 ACPI_GENERIC_STATE *State;
303 ACPI_FUNCTION_ENTRY ();
306 /* Create the generic state object */
308 State = AcpiUtCreateGenericState ();
314 /* Init fields specific to the update struct */
316 State->Common.DescriptorType = ACPI_DESC_TYPE_STATE_PACKAGE;
317 State->Pkg.SourceObject = (ACPI_OPERAND_OBJECT *) InternalObject;
318 State->Pkg.DestObject = ExternalObject;
319 State->Pkg.Index= Index;
320 State->Pkg.NumPackages = 1;
325 /*******************************************************************************
327 * FUNCTION: AcpiUtCreateControlState
331 * RETURN: New state object, null on failure
333 * DESCRIPTION: Create a "Control State" - a flavor of the generic state used
334 * to support nested IF/WHILE constructs in the AML.
336 ******************************************************************************/
339 AcpiUtCreateControlState (
342 ACPI_GENERIC_STATE *State;
345 ACPI_FUNCTION_ENTRY ();
348 /* Create the generic state object */
350 State = AcpiUtCreateGenericState ();
356 /* Init fields specific to the control struct */
358 State->Common.DescriptorType = ACPI_DESC_TYPE_STATE_CONTROL;
359 State->Common.State = ACPI_CONTROL_CONDITIONAL_EXECUTING;
364 /*******************************************************************************
366 * FUNCTION: AcpiUtDeleteGenericState
368 * PARAMETERS: State - The state object to be deleted
372 * DESCRIPTION: Release a state object to the state cache. NULL state objects
375 ******************************************************************************/
378 AcpiUtDeleteGenericState (
379 ACPI_GENERIC_STATE *State)
381 ACPI_FUNCTION_ENTRY ();
384 /* Ignore null state */
388 (void) AcpiOsReleaseObject (AcpiGbl_StateCache, State);