Fixed compatibility of output.
[AROS.git] / arch / all-pc / acpica / source / components / utilities / utstate.c
blobb2e4c1c6848698b7de794dcf37b3909eda7ff319
1 /*******************************************************************************
3 * Module Name: utstate - state object support procedures
5 ******************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2013, Intel Corp.
9 * All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
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.
30 * NO WARRANTY
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.
45 #define __UTSTATE_C__
47 #include "acpi.h"
48 #include "accommon.h"
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
62 * RETURN: Status
64 * DESCRIPTION: Create a new state and push it
66 ******************************************************************************/
68 ACPI_STATUS
69 AcpiUtCreatePkgStateAndPush (
70 void *InternalObject,
71 void *ExternalObject,
72 UINT16 Index,
73 ACPI_GENERIC_STATE **StateList)
75 ACPI_GENERIC_STATE *State;
78 ACPI_FUNCTION_ENTRY ();
81 State = AcpiUtCreatePkgState (InternalObject, ExternalObject, Index);
82 if (!State)
84 return (AE_NO_MEMORY);
87 AcpiUtPushGenericState (StateList, State);
88 return (AE_OK);
92 /*******************************************************************************
94 * FUNCTION: AcpiUtPushGenericState
96 * PARAMETERS: ListHead - Head of the state stack
97 * State - State object to push
99 * RETURN: None
101 * DESCRIPTION: Push a state object onto a state stack
103 ******************************************************************************/
105 void
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;
116 *ListHead = State;
117 return;
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 ******************************************************************************/
133 ACPI_GENERIC_STATE *
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) */
145 State = *ListHead;
146 if (State)
148 /* Update the list head */
150 *ListHead = State->Common.Next;
153 return (State);
157 /*******************************************************************************
159 * FUNCTION: AcpiUtCreateGenericState
161 * PARAMETERS: None
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 ******************************************************************************/
170 ACPI_GENERIC_STATE *
171 AcpiUtCreateGenericState (
172 void)
174 ACPI_GENERIC_STATE *State;
177 ACPI_FUNCTION_ENTRY ();
180 State = AcpiOsAcquireObject (AcpiGbl_StateCache);
181 if (State)
183 /* Initialize */
184 State->Common.DescriptorType = ACPI_DESC_TYPE_STATE;
187 return (State);
191 /*******************************************************************************
193 * FUNCTION: AcpiUtCreateThreadState
195 * PARAMETERS: None
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 ******************************************************************************/
204 ACPI_THREAD_STATE *
205 AcpiUtCreateThreadState (
206 void)
208 ACPI_GENERIC_STATE *State;
211 ACPI_FUNCTION_ENTRY ();
214 /* Create the generic state object */
216 State = AcpiUtCreateGenericState ();
217 if (!State)
219 return (NULL);
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
250 * as packages.
252 ******************************************************************************/
254 ACPI_GENERIC_STATE *
255 AcpiUtCreateUpdateState (
256 ACPI_OPERAND_OBJECT *Object,
257 UINT16 Action)
259 ACPI_GENERIC_STATE *State;
262 ACPI_FUNCTION_ENTRY ();
265 /* Create the generic state object */
267 State = AcpiUtCreateGenericState ();
268 if (!State)
270 return (NULL);
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;
278 return (State);
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 ******************************************************************************/
295 ACPI_GENERIC_STATE *
296 AcpiUtCreatePkgState (
297 void *InternalObject,
298 void *ExternalObject,
299 UINT16 Index)
301 ACPI_GENERIC_STATE *State;
304 ACPI_FUNCTION_ENTRY ();
307 /* Create the generic state object */
309 State = AcpiUtCreateGenericState ();
310 if (!State)
312 return (NULL);
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;
322 return (State);
326 /*******************************************************************************
328 * FUNCTION: AcpiUtCreateControlState
330 * PARAMETERS: None
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 ******************************************************************************/
339 ACPI_GENERIC_STATE *
340 AcpiUtCreateControlState (
341 void)
343 ACPI_GENERIC_STATE *State;
346 ACPI_FUNCTION_ENTRY ();
349 /* Create the generic state object */
351 State = AcpiUtCreateGenericState ();
352 if (!State)
354 return (NULL);
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;
361 return (State);
365 /*******************************************************************************
367 * FUNCTION: AcpiUtDeleteGenericState
369 * PARAMETERS: State - The state object to be deleted
371 * RETURN: None
373 * DESCRIPTION: Release a state object to the state cache. NULL state objects
374 * are ignored.
376 ******************************************************************************/
378 void
379 AcpiUtDeleteGenericState (
380 ACPI_GENERIC_STATE *State)
382 ACPI_FUNCTION_ENTRY ();
385 /* Ignore null state */
387 if (State)
389 (void) AcpiOsReleaseObject (AcpiGbl_StateCache, State);
391 return;