1433d6423SLionel Sambuc /*******************************************************************************
2433d6423SLionel Sambuc *
3433d6423SLionel Sambuc * Module Name: utstate - state object support procedures
4433d6423SLionel Sambuc *
5433d6423SLionel Sambuc ******************************************************************************/
6433d6423SLionel Sambuc
7*29492bb7SDavid van Moolenbroek /*
8*29492bb7SDavid van Moolenbroek * Copyright (C) 2000 - 2014, Intel Corp.
9433d6423SLionel Sambuc * All rights reserved.
10433d6423SLionel Sambuc *
11*29492bb7SDavid van Moolenbroek * Redistribution and use in source and binary forms, with or without
12*29492bb7SDavid van Moolenbroek * modification, are permitted provided that the following conditions
13*29492bb7SDavid van Moolenbroek * are met:
14*29492bb7SDavid van Moolenbroek * 1. Redistributions of source code must retain the above copyright
15*29492bb7SDavid van Moolenbroek * notice, this list of conditions, and the following disclaimer,
16*29492bb7SDavid van Moolenbroek * without modification.
17*29492bb7SDavid van Moolenbroek * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18*29492bb7SDavid van Moolenbroek * substantially similar to the "NO WARRANTY" disclaimer below
19*29492bb7SDavid van Moolenbroek * ("Disclaimer") and any redistribution must be conditioned upon
20*29492bb7SDavid van Moolenbroek * including a substantially similar Disclaimer requirement for further
21*29492bb7SDavid van Moolenbroek * binary redistribution.
22*29492bb7SDavid van Moolenbroek * 3. Neither the names of the above-listed copyright holders nor the names
23*29492bb7SDavid van Moolenbroek * of any contributors may be used to endorse or promote products derived
24*29492bb7SDavid van Moolenbroek * from this software without specific prior written permission.
25433d6423SLionel Sambuc *
26*29492bb7SDavid van Moolenbroek * Alternatively, this software may be distributed under the terms of the
27*29492bb7SDavid van Moolenbroek * GNU General Public License ("GPL") version 2 as published by the Free
28*29492bb7SDavid van Moolenbroek * Software Foundation.
29433d6423SLionel Sambuc *
30*29492bb7SDavid van Moolenbroek * NO WARRANTY
31*29492bb7SDavid van Moolenbroek * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32*29492bb7SDavid van Moolenbroek * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33*29492bb7SDavid van Moolenbroek * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34*29492bb7SDavid van Moolenbroek * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35*29492bb7SDavid van Moolenbroek * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36*29492bb7SDavid van Moolenbroek * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37*29492bb7SDavid van Moolenbroek * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38*29492bb7SDavid van Moolenbroek * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39*29492bb7SDavid van Moolenbroek * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40*29492bb7SDavid van Moolenbroek * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41*29492bb7SDavid van Moolenbroek * POSSIBILITY OF SUCH DAMAGES.
42*29492bb7SDavid van Moolenbroek */
43433d6423SLionel Sambuc
44433d6423SLionel Sambuc #include "acpi.h"
45433d6423SLionel Sambuc #include "accommon.h"
46433d6423SLionel Sambuc
47433d6423SLionel Sambuc #define _COMPONENT ACPI_UTILITIES
48433d6423SLionel Sambuc ACPI_MODULE_NAME ("utstate")
49433d6423SLionel Sambuc
50433d6423SLionel Sambuc
51433d6423SLionel Sambuc /*******************************************************************************
52433d6423SLionel Sambuc *
53433d6423SLionel Sambuc * FUNCTION: AcpiUtCreatePkgStateAndPush
54433d6423SLionel Sambuc *
55433d6423SLionel Sambuc * PARAMETERS: Object - Object to be added to the new state
56433d6423SLionel Sambuc * Action - Increment/Decrement
57433d6423SLionel Sambuc * StateList - List the state will be added to
58433d6423SLionel Sambuc *
59433d6423SLionel Sambuc * RETURN: Status
60433d6423SLionel Sambuc *
61433d6423SLionel Sambuc * DESCRIPTION: Create a new state and push it
62433d6423SLionel Sambuc *
63433d6423SLionel Sambuc ******************************************************************************/
64433d6423SLionel Sambuc
65433d6423SLionel Sambuc ACPI_STATUS
AcpiUtCreatePkgStateAndPush(void * InternalObject,void * ExternalObject,UINT16 Index,ACPI_GENERIC_STATE ** StateList)66433d6423SLionel Sambuc AcpiUtCreatePkgStateAndPush (
67433d6423SLionel Sambuc void *InternalObject,
68433d6423SLionel Sambuc void *ExternalObject,
69433d6423SLionel Sambuc UINT16 Index,
70433d6423SLionel Sambuc ACPI_GENERIC_STATE **StateList)
71433d6423SLionel Sambuc {
72433d6423SLionel Sambuc ACPI_GENERIC_STATE *State;
73433d6423SLionel Sambuc
74433d6423SLionel Sambuc
75433d6423SLionel Sambuc ACPI_FUNCTION_ENTRY ();
76433d6423SLionel Sambuc
77433d6423SLionel Sambuc
78433d6423SLionel Sambuc State = AcpiUtCreatePkgState (InternalObject, ExternalObject, Index);
79433d6423SLionel Sambuc if (!State)
80433d6423SLionel Sambuc {
81433d6423SLionel Sambuc return (AE_NO_MEMORY);
82433d6423SLionel Sambuc }
83433d6423SLionel Sambuc
84433d6423SLionel Sambuc AcpiUtPushGenericState (StateList, State);
85433d6423SLionel Sambuc return (AE_OK);
86433d6423SLionel Sambuc }
87433d6423SLionel Sambuc
88433d6423SLionel Sambuc
89433d6423SLionel Sambuc /*******************************************************************************
90433d6423SLionel Sambuc *
91433d6423SLionel Sambuc * FUNCTION: AcpiUtPushGenericState
92433d6423SLionel Sambuc *
93433d6423SLionel Sambuc * PARAMETERS: ListHead - Head of the state stack
94433d6423SLionel Sambuc * State - State object to push
95433d6423SLionel Sambuc *
96433d6423SLionel Sambuc * RETURN: None
97433d6423SLionel Sambuc *
98433d6423SLionel Sambuc * DESCRIPTION: Push a state object onto a state stack
99433d6423SLionel Sambuc *
100433d6423SLionel Sambuc ******************************************************************************/
101433d6423SLionel Sambuc
102433d6423SLionel Sambuc void
AcpiUtPushGenericState(ACPI_GENERIC_STATE ** ListHead,ACPI_GENERIC_STATE * State)103433d6423SLionel Sambuc AcpiUtPushGenericState (
104433d6423SLionel Sambuc ACPI_GENERIC_STATE **ListHead,
105433d6423SLionel Sambuc ACPI_GENERIC_STATE *State)
106433d6423SLionel Sambuc {
107*29492bb7SDavid van Moolenbroek ACPI_FUNCTION_ENTRY ();
108433d6423SLionel Sambuc
109433d6423SLionel Sambuc
110433d6423SLionel Sambuc /* Push the state object onto the front of the list (stack) */
111433d6423SLionel Sambuc
112433d6423SLionel Sambuc State->Common.Next = *ListHead;
113433d6423SLionel Sambuc *ListHead = State;
114*29492bb7SDavid van Moolenbroek return;
115433d6423SLionel Sambuc }
116433d6423SLionel Sambuc
117433d6423SLionel Sambuc
118433d6423SLionel Sambuc /*******************************************************************************
119433d6423SLionel Sambuc *
120433d6423SLionel Sambuc * FUNCTION: AcpiUtPopGenericState
121433d6423SLionel Sambuc *
122433d6423SLionel Sambuc * PARAMETERS: ListHead - Head of the state stack
123433d6423SLionel Sambuc *
124433d6423SLionel Sambuc * RETURN: The popped state object
125433d6423SLionel Sambuc *
126433d6423SLionel Sambuc * DESCRIPTION: Pop a state object from a state stack
127433d6423SLionel Sambuc *
128433d6423SLionel Sambuc ******************************************************************************/
129433d6423SLionel Sambuc
130433d6423SLionel Sambuc ACPI_GENERIC_STATE *
AcpiUtPopGenericState(ACPI_GENERIC_STATE ** ListHead)131433d6423SLionel Sambuc AcpiUtPopGenericState (
132433d6423SLionel Sambuc ACPI_GENERIC_STATE **ListHead)
133433d6423SLionel Sambuc {
134433d6423SLionel Sambuc ACPI_GENERIC_STATE *State;
135433d6423SLionel Sambuc
136433d6423SLionel Sambuc
137*29492bb7SDavid van Moolenbroek ACPI_FUNCTION_ENTRY ();
138433d6423SLionel Sambuc
139433d6423SLionel Sambuc
140433d6423SLionel Sambuc /* Remove the state object at the head of the list (stack) */
141433d6423SLionel Sambuc
142433d6423SLionel Sambuc State = *ListHead;
143433d6423SLionel Sambuc if (State)
144433d6423SLionel Sambuc {
145433d6423SLionel Sambuc /* Update the list head */
146433d6423SLionel Sambuc
147433d6423SLionel Sambuc *ListHead = State->Common.Next;
148433d6423SLionel Sambuc }
149433d6423SLionel Sambuc
150*29492bb7SDavid van Moolenbroek return (State);
151433d6423SLionel Sambuc }
152433d6423SLionel Sambuc
153433d6423SLionel Sambuc
154433d6423SLionel Sambuc /*******************************************************************************
155433d6423SLionel Sambuc *
156433d6423SLionel Sambuc * FUNCTION: AcpiUtCreateGenericState
157433d6423SLionel Sambuc *
158433d6423SLionel Sambuc * PARAMETERS: None
159433d6423SLionel Sambuc *
160433d6423SLionel Sambuc * RETURN: The new state object. NULL on failure.
161433d6423SLionel Sambuc *
162433d6423SLionel Sambuc * DESCRIPTION: Create a generic state object. Attempt to obtain one from
163433d6423SLionel Sambuc * the global state cache; If none available, create a new one.
164433d6423SLionel Sambuc *
165433d6423SLionel Sambuc ******************************************************************************/
166433d6423SLionel Sambuc
167433d6423SLionel Sambuc ACPI_GENERIC_STATE *
AcpiUtCreateGenericState(void)168433d6423SLionel Sambuc AcpiUtCreateGenericState (
169433d6423SLionel Sambuc void)
170433d6423SLionel Sambuc {
171433d6423SLionel Sambuc ACPI_GENERIC_STATE *State;
172433d6423SLionel Sambuc
173433d6423SLionel Sambuc
174433d6423SLionel Sambuc ACPI_FUNCTION_ENTRY ();
175433d6423SLionel Sambuc
176433d6423SLionel Sambuc
177433d6423SLionel Sambuc State = AcpiOsAcquireObject (AcpiGbl_StateCache);
178433d6423SLionel Sambuc if (State)
179433d6423SLionel Sambuc {
180433d6423SLionel Sambuc /* Initialize */
181433d6423SLionel Sambuc State->Common.DescriptorType = ACPI_DESC_TYPE_STATE;
182433d6423SLionel Sambuc }
183433d6423SLionel Sambuc
184433d6423SLionel Sambuc return (State);
185433d6423SLionel Sambuc }
186433d6423SLionel Sambuc
187433d6423SLionel Sambuc
188433d6423SLionel Sambuc /*******************************************************************************
189433d6423SLionel Sambuc *
190433d6423SLionel Sambuc * FUNCTION: AcpiUtCreateThreadState
191433d6423SLionel Sambuc *
192433d6423SLionel Sambuc * PARAMETERS: None
193433d6423SLionel Sambuc *
194433d6423SLionel Sambuc * RETURN: New Thread State. NULL on failure
195433d6423SLionel Sambuc *
196433d6423SLionel Sambuc * DESCRIPTION: Create a "Thread State" - a flavor of the generic state used
197433d6423SLionel Sambuc * to track per-thread info during method execution
198433d6423SLionel Sambuc *
199433d6423SLionel Sambuc ******************************************************************************/
200433d6423SLionel Sambuc
201433d6423SLionel Sambuc ACPI_THREAD_STATE *
AcpiUtCreateThreadState(void)202433d6423SLionel Sambuc AcpiUtCreateThreadState (
203433d6423SLionel Sambuc void)
204433d6423SLionel Sambuc {
205433d6423SLionel Sambuc ACPI_GENERIC_STATE *State;
206433d6423SLionel Sambuc
207433d6423SLionel Sambuc
208*29492bb7SDavid van Moolenbroek ACPI_FUNCTION_ENTRY ();
209433d6423SLionel Sambuc
210433d6423SLionel Sambuc
211433d6423SLionel Sambuc /* Create the generic state object */
212433d6423SLionel Sambuc
213433d6423SLionel Sambuc State = AcpiUtCreateGenericState ();
214433d6423SLionel Sambuc if (!State)
215433d6423SLionel Sambuc {
216*29492bb7SDavid van Moolenbroek return (NULL);
217433d6423SLionel Sambuc }
218433d6423SLionel Sambuc
219433d6423SLionel Sambuc /* Init fields specific to the update struct */
220433d6423SLionel Sambuc
221433d6423SLionel Sambuc State->Common.DescriptorType = ACPI_DESC_TYPE_STATE_THREAD;
222433d6423SLionel Sambuc State->Thread.ThreadId = AcpiOsGetThreadId ();
223433d6423SLionel Sambuc
224433d6423SLionel Sambuc /* Check for invalid thread ID - zero is very bad, it will break things */
225433d6423SLionel Sambuc
226433d6423SLionel Sambuc if (!State->Thread.ThreadId)
227433d6423SLionel Sambuc {
228433d6423SLionel Sambuc ACPI_ERROR ((AE_INFO, "Invalid zero ID from AcpiOsGetThreadId"));
229433d6423SLionel Sambuc State->Thread.ThreadId = (ACPI_THREAD_ID) 1;
230433d6423SLionel Sambuc }
231433d6423SLionel Sambuc
232*29492bb7SDavid van Moolenbroek return ((ACPI_THREAD_STATE *) State);
233433d6423SLionel Sambuc }
234433d6423SLionel Sambuc
235433d6423SLionel Sambuc
236433d6423SLionel Sambuc /*******************************************************************************
237433d6423SLionel Sambuc *
238433d6423SLionel Sambuc * FUNCTION: AcpiUtCreateUpdateState
239433d6423SLionel Sambuc *
240433d6423SLionel Sambuc * PARAMETERS: Object - Initial Object to be installed in the state
241433d6423SLionel Sambuc * Action - Update action to be performed
242433d6423SLionel Sambuc *
243433d6423SLionel Sambuc * RETURN: New state object, null on failure
244433d6423SLionel Sambuc *
245433d6423SLionel Sambuc * DESCRIPTION: Create an "Update State" - a flavor of the generic state used
246433d6423SLionel Sambuc * to update reference counts and delete complex objects such
247433d6423SLionel Sambuc * as packages.
248433d6423SLionel Sambuc *
249433d6423SLionel Sambuc ******************************************************************************/
250433d6423SLionel Sambuc
251433d6423SLionel Sambuc ACPI_GENERIC_STATE *
AcpiUtCreateUpdateState(ACPI_OPERAND_OBJECT * Object,UINT16 Action)252433d6423SLionel Sambuc AcpiUtCreateUpdateState (
253433d6423SLionel Sambuc ACPI_OPERAND_OBJECT *Object,
254433d6423SLionel Sambuc UINT16 Action)
255433d6423SLionel Sambuc {
256433d6423SLionel Sambuc ACPI_GENERIC_STATE *State;
257433d6423SLionel Sambuc
258433d6423SLionel Sambuc
259*29492bb7SDavid van Moolenbroek ACPI_FUNCTION_ENTRY ();
260433d6423SLionel Sambuc
261433d6423SLionel Sambuc
262433d6423SLionel Sambuc /* Create the generic state object */
263433d6423SLionel Sambuc
264433d6423SLionel Sambuc State = AcpiUtCreateGenericState ();
265433d6423SLionel Sambuc if (!State)
266433d6423SLionel Sambuc {
267*29492bb7SDavid van Moolenbroek return (NULL);
268433d6423SLionel Sambuc }
269433d6423SLionel Sambuc
270433d6423SLionel Sambuc /* Init fields specific to the update struct */
271433d6423SLionel Sambuc
272433d6423SLionel Sambuc State->Common.DescriptorType = ACPI_DESC_TYPE_STATE_UPDATE;
273433d6423SLionel Sambuc State->Update.Object = Object;
274433d6423SLionel Sambuc State->Update.Value = Action;
275*29492bb7SDavid van Moolenbroek return (State);
276433d6423SLionel Sambuc }
277433d6423SLionel Sambuc
278433d6423SLionel Sambuc
279433d6423SLionel Sambuc /*******************************************************************************
280433d6423SLionel Sambuc *
281433d6423SLionel Sambuc * FUNCTION: AcpiUtCreatePkgState
282433d6423SLionel Sambuc *
283433d6423SLionel Sambuc * PARAMETERS: Object - Initial Object to be installed in the state
284433d6423SLionel Sambuc * Action - Update action to be performed
285433d6423SLionel Sambuc *
286433d6423SLionel Sambuc * RETURN: New state object, null on failure
287433d6423SLionel Sambuc *
288433d6423SLionel Sambuc * DESCRIPTION: Create a "Package State"
289433d6423SLionel Sambuc *
290433d6423SLionel Sambuc ******************************************************************************/
291433d6423SLionel Sambuc
292433d6423SLionel Sambuc ACPI_GENERIC_STATE *
AcpiUtCreatePkgState(void * InternalObject,void * ExternalObject,UINT16 Index)293433d6423SLionel Sambuc AcpiUtCreatePkgState (
294433d6423SLionel Sambuc void *InternalObject,
295433d6423SLionel Sambuc void *ExternalObject,
296433d6423SLionel Sambuc UINT16 Index)
297433d6423SLionel Sambuc {
298433d6423SLionel Sambuc ACPI_GENERIC_STATE *State;
299433d6423SLionel Sambuc
300433d6423SLionel Sambuc
301*29492bb7SDavid van Moolenbroek ACPI_FUNCTION_ENTRY ();
302433d6423SLionel Sambuc
303433d6423SLionel Sambuc
304433d6423SLionel Sambuc /* Create the generic state object */
305433d6423SLionel Sambuc
306433d6423SLionel Sambuc State = AcpiUtCreateGenericState ();
307433d6423SLionel Sambuc if (!State)
308433d6423SLionel Sambuc {
309*29492bb7SDavid van Moolenbroek return (NULL);
310433d6423SLionel Sambuc }
311433d6423SLionel Sambuc
312433d6423SLionel Sambuc /* Init fields specific to the update struct */
313433d6423SLionel Sambuc
314433d6423SLionel Sambuc State->Common.DescriptorType = ACPI_DESC_TYPE_STATE_PACKAGE;
315433d6423SLionel Sambuc State->Pkg.SourceObject = (ACPI_OPERAND_OBJECT *) InternalObject;
316433d6423SLionel Sambuc State->Pkg.DestObject = ExternalObject;
317433d6423SLionel Sambuc State->Pkg.Index= Index;
318433d6423SLionel Sambuc State->Pkg.NumPackages = 1;
319*29492bb7SDavid van Moolenbroek return (State);
320433d6423SLionel Sambuc }
321433d6423SLionel Sambuc
322433d6423SLionel Sambuc
323433d6423SLionel Sambuc /*******************************************************************************
324433d6423SLionel Sambuc *
325433d6423SLionel Sambuc * FUNCTION: AcpiUtCreateControlState
326433d6423SLionel Sambuc *
327433d6423SLionel Sambuc * PARAMETERS: None
328433d6423SLionel Sambuc *
329433d6423SLionel Sambuc * RETURN: New state object, null on failure
330433d6423SLionel Sambuc *
331433d6423SLionel Sambuc * DESCRIPTION: Create a "Control State" - a flavor of the generic state used
332433d6423SLionel Sambuc * to support nested IF/WHILE constructs in the AML.
333433d6423SLionel Sambuc *
334433d6423SLionel Sambuc ******************************************************************************/
335433d6423SLionel Sambuc
336433d6423SLionel Sambuc ACPI_GENERIC_STATE *
AcpiUtCreateControlState(void)337433d6423SLionel Sambuc AcpiUtCreateControlState (
338433d6423SLionel Sambuc void)
339433d6423SLionel Sambuc {
340433d6423SLionel Sambuc ACPI_GENERIC_STATE *State;
341433d6423SLionel Sambuc
342433d6423SLionel Sambuc
343*29492bb7SDavid van Moolenbroek ACPI_FUNCTION_ENTRY ();
344433d6423SLionel Sambuc
345433d6423SLionel Sambuc
346433d6423SLionel Sambuc /* Create the generic state object */
347433d6423SLionel Sambuc
348433d6423SLionel Sambuc State = AcpiUtCreateGenericState ();
349433d6423SLionel Sambuc if (!State)
350433d6423SLionel Sambuc {
351*29492bb7SDavid van Moolenbroek return (NULL);
352433d6423SLionel Sambuc }
353433d6423SLionel Sambuc
354433d6423SLionel Sambuc /* Init fields specific to the control struct */
355433d6423SLionel Sambuc
356433d6423SLionel Sambuc State->Common.DescriptorType = ACPI_DESC_TYPE_STATE_CONTROL;
357433d6423SLionel Sambuc State->Common.State = ACPI_CONTROL_CONDITIONAL_EXECUTING;
358*29492bb7SDavid van Moolenbroek return (State);
359433d6423SLionel Sambuc }
360433d6423SLionel Sambuc
361433d6423SLionel Sambuc
362433d6423SLionel Sambuc /*******************************************************************************
363433d6423SLionel Sambuc *
364433d6423SLionel Sambuc * FUNCTION: AcpiUtDeleteGenericState
365433d6423SLionel Sambuc *
366433d6423SLionel Sambuc * PARAMETERS: State - The state object to be deleted
367433d6423SLionel Sambuc *
368433d6423SLionel Sambuc * RETURN: None
369433d6423SLionel Sambuc *
370433d6423SLionel Sambuc * DESCRIPTION: Release a state object to the state cache. NULL state objects
371433d6423SLionel Sambuc * are ignored.
372433d6423SLionel Sambuc *
373433d6423SLionel Sambuc ******************************************************************************/
374433d6423SLionel Sambuc
375433d6423SLionel Sambuc void
AcpiUtDeleteGenericState(ACPI_GENERIC_STATE * State)376433d6423SLionel Sambuc AcpiUtDeleteGenericState (
377433d6423SLionel Sambuc ACPI_GENERIC_STATE *State)
378433d6423SLionel Sambuc {
379*29492bb7SDavid van Moolenbroek ACPI_FUNCTION_ENTRY ();
380433d6423SLionel Sambuc
381433d6423SLionel Sambuc
382433d6423SLionel Sambuc /* Ignore null state */
383433d6423SLionel Sambuc
384433d6423SLionel Sambuc if (State)
385433d6423SLionel Sambuc {
386433d6423SLionel Sambuc (void) AcpiOsReleaseObject (AcpiGbl_StateCache, State);
387433d6423SLionel Sambuc }
388*29492bb7SDavid van Moolenbroek return;
389433d6423SLionel Sambuc }
390