Linux Audio

Check our new training course

Loading...
v3.5.6
 
  1/*******************************************************************************
  2 *
  3 * Module Name: utstate - state object support procedures
  4 *
  5 ******************************************************************************/
  6
  7/*
  8 * Copyright (C) 2000 - 2012, Intel Corp.
  9 * All rights reserved.
 10 *
 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.
 25 *
 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.
 29 *
 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.
 42 */
 43
 44#include <acpi/acpi.h>
 45#include "accommon.h"
 46
 47#define _COMPONENT          ACPI_UTILITIES
 48ACPI_MODULE_NAME("utstate")
 49
 50/*******************************************************************************
 51 *
 52 * FUNCTION:    acpi_ut_create_pkg_state_and_push
 53 *
 54 * PARAMETERS:  Object          - Object to be added to the new state
 55 *              Action          - Increment/Decrement
 56 *              state_list      - List the state will be added to
 57 *
 58 * RETURN:      Status
 59 *
 60 * DESCRIPTION: Create a new state and push it
 61 *
 62 ******************************************************************************/
 63acpi_status
 64acpi_ut_create_pkg_state_and_push(void *internal_object,
 65				  void *external_object,
 66				  u16 index,
 67				  union acpi_generic_state **state_list)
 68{
 69	union acpi_generic_state *state;
 70
 71	ACPI_FUNCTION_ENTRY();
 72
 73	state =
 74	    acpi_ut_create_pkg_state(internal_object, external_object, index);
 75	if (!state) {
 76		return (AE_NO_MEMORY);
 77	}
 78
 79	acpi_ut_push_generic_state(state_list, state);
 80	return (AE_OK);
 81}
 82
 83/*******************************************************************************
 84 *
 85 * FUNCTION:    acpi_ut_push_generic_state
 86 *
 87 * PARAMETERS:  list_head           - Head of the state stack
 88 *              State               - State object to push
 89 *
 90 * RETURN:      None
 91 *
 92 * DESCRIPTION: Push a state object onto a state stack
 93 *
 94 ******************************************************************************/
 95
 96void
 97acpi_ut_push_generic_state(union acpi_generic_state **list_head,
 98			   union acpi_generic_state *state)
 99{
100	ACPI_FUNCTION_TRACE(ut_push_generic_state);
101
102	/* Push the state object onto the front of the list (stack) */
103
104	state->common.next = *list_head;
105	*list_head = state;
106
107	return_VOID;
108}
109
110/*******************************************************************************
111 *
112 * FUNCTION:    acpi_ut_pop_generic_state
113 *
114 * PARAMETERS:  list_head           - Head of the state stack
115 *
116 * RETURN:      The popped state object
117 *
118 * DESCRIPTION: Pop a state object from a state stack
119 *
120 ******************************************************************************/
121
122union acpi_generic_state *acpi_ut_pop_generic_state(union acpi_generic_state
123						    **list_head)
124{
125	union acpi_generic_state *state;
126
127	ACPI_FUNCTION_TRACE(ut_pop_generic_state);
128
129	/* Remove the state object at the head of the list (stack) */
130
131	state = *list_head;
132	if (state) {
133
134		/* Update the list head */
135
136		*list_head = state->common.next;
137	}
138
139	return_PTR(state);
140}
141
142/*******************************************************************************
143 *
144 * FUNCTION:    acpi_ut_create_generic_state
145 *
146 * PARAMETERS:  None
147 *
148 * RETURN:      The new state object. NULL on failure.
149 *
150 * DESCRIPTION: Create a generic state object.  Attempt to obtain one from
151 *              the global state cache;  If none available, create a new one.
152 *
153 ******************************************************************************/
154
155union acpi_generic_state *acpi_ut_create_generic_state(void)
156{
157	union acpi_generic_state *state;
158
159	ACPI_FUNCTION_ENTRY();
160
161	state = acpi_os_acquire_object(acpi_gbl_state_cache);
162	if (state) {
163
164		/* Initialize */
165		memset(state, 0, sizeof(union acpi_generic_state));
166		state->common.descriptor_type = ACPI_DESC_TYPE_STATE;
167	}
168
169	return (state);
170}
171
172/*******************************************************************************
173 *
174 * FUNCTION:    acpi_ut_create_thread_state
175 *
176 * PARAMETERS:  None
177 *
178 * RETURN:      New Thread State. NULL on failure
179 *
180 * DESCRIPTION: Create a "Thread State" - a flavor of the generic state used
181 *              to track per-thread info during method execution
182 *
183 ******************************************************************************/
184
185struct acpi_thread_state *acpi_ut_create_thread_state(void)
186{
187	union acpi_generic_state *state;
188
189	ACPI_FUNCTION_TRACE(ut_create_thread_state);
190
191	/* Create the generic state object */
192
193	state = acpi_ut_create_generic_state();
194	if (!state) {
195		return_PTR(NULL);
196	}
197
198	/* Init fields specific to the update struct */
199
200	state->common.descriptor_type = ACPI_DESC_TYPE_STATE_THREAD;
201	state->thread.thread_id = acpi_os_get_thread_id();
202
203	/* Check for invalid thread ID - zero is very bad, it will break things */
204
205	if (!state->thread.thread_id) {
206		ACPI_ERROR((AE_INFO, "Invalid zero ID from AcpiOsGetThreadId"));
207		state->thread.thread_id = (acpi_thread_id) 1;
208	}
209
210	return_PTR((struct acpi_thread_state *)state);
211}
212
213/*******************************************************************************
214 *
215 * FUNCTION:    acpi_ut_create_update_state
216 *
217 * PARAMETERS:  Object          - Initial Object to be installed in the state
218 *              Action          - Update action to be performed
219 *
220 * RETURN:      New state object, null on failure
221 *
222 * DESCRIPTION: Create an "Update State" - a flavor of the generic state used
223 *              to update reference counts and delete complex objects such
224 *              as packages.
225 *
226 ******************************************************************************/
227
228union acpi_generic_state *acpi_ut_create_update_state(union acpi_operand_object
229						      *object, u16 action)
230{
231	union acpi_generic_state *state;
232
233	ACPI_FUNCTION_TRACE_PTR(ut_create_update_state, object);
234
235	/* Create the generic state object */
236
237	state = acpi_ut_create_generic_state();
238	if (!state) {
239		return_PTR(NULL);
240	}
241
242	/* Init fields specific to the update struct */
243
244	state->common.descriptor_type = ACPI_DESC_TYPE_STATE_UPDATE;
245	state->update.object = object;
246	state->update.value = action;
247
248	return_PTR(state);
249}
250
251/*******************************************************************************
252 *
253 * FUNCTION:    acpi_ut_create_pkg_state
254 *
255 * PARAMETERS:  Object          - Initial Object to be installed in the state
256 *              Action          - Update action to be performed
257 *
258 * RETURN:      New state object, null on failure
259 *
260 * DESCRIPTION: Create a "Package State"
261 *
262 ******************************************************************************/
263
264union acpi_generic_state *acpi_ut_create_pkg_state(void *internal_object,
265						   void *external_object,
266						   u16 index)
267{
268	union acpi_generic_state *state;
269
270	ACPI_FUNCTION_TRACE_PTR(ut_create_pkg_state, internal_object);
271
272	/* Create the generic state object */
273
274	state = acpi_ut_create_generic_state();
275	if (!state) {
276		return_PTR(NULL);
277	}
278
279	/* Init fields specific to the update struct */
280
281	state->common.descriptor_type = ACPI_DESC_TYPE_STATE_PACKAGE;
282	state->pkg.source_object = (union acpi_operand_object *)internal_object;
283	state->pkg.dest_object = external_object;
284	state->pkg.index = index;
285	state->pkg.num_packages = 1;
286
287	return_PTR(state);
288}
289
290/*******************************************************************************
291 *
292 * FUNCTION:    acpi_ut_create_control_state
293 *
294 * PARAMETERS:  None
295 *
296 * RETURN:      New state object, null on failure
297 *
298 * DESCRIPTION: Create a "Control State" - a flavor of the generic state used
299 *              to support nested IF/WHILE constructs in the AML.
300 *
301 ******************************************************************************/
302
303union acpi_generic_state *acpi_ut_create_control_state(void)
304{
305	union acpi_generic_state *state;
306
307	ACPI_FUNCTION_TRACE(ut_create_control_state);
308
309	/* Create the generic state object */
310
311	state = acpi_ut_create_generic_state();
312	if (!state) {
313		return_PTR(NULL);
314	}
315
316	/* Init fields specific to the control struct */
317
318	state->common.descriptor_type = ACPI_DESC_TYPE_STATE_CONTROL;
319	state->common.state = ACPI_CONTROL_CONDITIONAL_EXECUTING;
320
321	return_PTR(state);
322}
323
324/*******************************************************************************
325 *
326 * FUNCTION:    acpi_ut_delete_generic_state
327 *
328 * PARAMETERS:  State               - The state object to be deleted
329 *
330 * RETURN:      None
331 *
332 * DESCRIPTION: Release a state object to the state cache. NULL state objects
333 *              are ignored.
334 *
335 ******************************************************************************/
336
337void acpi_ut_delete_generic_state(union acpi_generic_state *state)
338{
339	ACPI_FUNCTION_TRACE(ut_delete_generic_state);
340
341	/* Ignore null state */
342
343	if (state) {
344		(void)acpi_os_release_object(acpi_gbl_state_cache, state);
345	}
346	return_VOID;
 
347}
v4.17
  1// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
  2/*******************************************************************************
  3 *
  4 * Module Name: utstate - state object support procedures
  5 *
  6 ******************************************************************************/
  7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  8#include <acpi/acpi.h>
  9#include "accommon.h"
 10
 11#define _COMPONENT          ACPI_UTILITIES
 12ACPI_MODULE_NAME("utstate")
 13
 14/*******************************************************************************
 15 *
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 16 * FUNCTION:    acpi_ut_push_generic_state
 17 *
 18 * PARAMETERS:  list_head           - Head of the state stack
 19 *              state               - State object to push
 20 *
 21 * RETURN:      None
 22 *
 23 * DESCRIPTION: Push a state object onto a state stack
 24 *
 25 ******************************************************************************/
 
 26void
 27acpi_ut_push_generic_state(union acpi_generic_state **list_head,
 28			   union acpi_generic_state *state)
 29{
 30	ACPI_FUNCTION_ENTRY();
 31
 32	/* Push the state object onto the front of the list (stack) */
 33
 34	state->common.next = *list_head;
 35	*list_head = state;
 36	return;
 
 37}
 38
 39/*******************************************************************************
 40 *
 41 * FUNCTION:    acpi_ut_pop_generic_state
 42 *
 43 * PARAMETERS:  list_head           - Head of the state stack
 44 *
 45 * RETURN:      The popped state object
 46 *
 47 * DESCRIPTION: Pop a state object from a state stack
 48 *
 49 ******************************************************************************/
 50
 51union acpi_generic_state *acpi_ut_pop_generic_state(union acpi_generic_state
 52						    **list_head)
 53{
 54	union acpi_generic_state *state;
 55
 56	ACPI_FUNCTION_ENTRY();
 57
 58	/* Remove the state object at the head of the list (stack) */
 59
 60	state = *list_head;
 61	if (state) {
 62
 63		/* Update the list head */
 64
 65		*list_head = state->common.next;
 66	}
 67
 68	return (state);
 69}
 70
 71/*******************************************************************************
 72 *
 73 * FUNCTION:    acpi_ut_create_generic_state
 74 *
 75 * PARAMETERS:  None
 76 *
 77 * RETURN:      The new state object. NULL on failure.
 78 *
 79 * DESCRIPTION: Create a generic state object. Attempt to obtain one from
 80 *              the global state cache;  If none available, create a new one.
 81 *
 82 ******************************************************************************/
 83
 84union acpi_generic_state *acpi_ut_create_generic_state(void)
 85{
 86	union acpi_generic_state *state;
 87
 88	ACPI_FUNCTION_ENTRY();
 89
 90	state = acpi_os_acquire_object(acpi_gbl_state_cache);
 91	if (state) {
 92
 93		/* Initialize */
 
 94		state->common.descriptor_type = ACPI_DESC_TYPE_STATE;
 95	}
 96
 97	return (state);
 98}
 99
100/*******************************************************************************
101 *
102 * FUNCTION:    acpi_ut_create_thread_state
103 *
104 * PARAMETERS:  None
105 *
106 * RETURN:      New Thread State. NULL on failure
107 *
108 * DESCRIPTION: Create a "Thread State" - a flavor of the generic state used
109 *              to track per-thread info during method execution
110 *
111 ******************************************************************************/
112
113struct acpi_thread_state *acpi_ut_create_thread_state(void)
114{
115	union acpi_generic_state *state;
116
117	ACPI_FUNCTION_ENTRY();
118
119	/* Create the generic state object */
120
121	state = acpi_ut_create_generic_state();
122	if (!state) {
123		return (NULL);
124	}
125
126	/* Init fields specific to the update struct */
127
128	state->common.descriptor_type = ACPI_DESC_TYPE_STATE_THREAD;
129	state->thread.thread_id = acpi_os_get_thread_id();
130
131	/* Check for invalid thread ID - zero is very bad, it will break things */
132
133	if (!state->thread.thread_id) {
134		ACPI_ERROR((AE_INFO, "Invalid zero ID from AcpiOsGetThreadId"));
135		state->thread.thread_id = (acpi_thread_id) 1;
136	}
137
138	return ((struct acpi_thread_state *)state);
139}
140
141/*******************************************************************************
142 *
143 * FUNCTION:    acpi_ut_create_update_state
144 *
145 * PARAMETERS:  object          - Initial Object to be installed in the state
146 *              action          - Update action to be performed
147 *
148 * RETURN:      New state object, null on failure
149 *
150 * DESCRIPTION: Create an "Update State" - a flavor of the generic state used
151 *              to update reference counts and delete complex objects such
152 *              as packages.
153 *
154 ******************************************************************************/
155
156union acpi_generic_state *acpi_ut_create_update_state(union acpi_operand_object
157						      *object, u16 action)
158{
159	union acpi_generic_state *state;
160
161	ACPI_FUNCTION_ENTRY();
162
163	/* Create the generic state object */
164
165	state = acpi_ut_create_generic_state();
166	if (!state) {
167		return (NULL);
168	}
169
170	/* Init fields specific to the update struct */
171
172	state->common.descriptor_type = ACPI_DESC_TYPE_STATE_UPDATE;
173	state->update.object = object;
174	state->update.value = action;
175	return (state);
 
176}
177
178/*******************************************************************************
179 *
180 * FUNCTION:    acpi_ut_create_pkg_state
181 *
182 * PARAMETERS:  object          - Initial Object to be installed in the state
183 *              action          - Update action to be performed
184 *
185 * RETURN:      New state object, null on failure
186 *
187 * DESCRIPTION: Create a "Package State"
188 *
189 ******************************************************************************/
190
191union acpi_generic_state *acpi_ut_create_pkg_state(void *internal_object,
192						   void *external_object,
193						   u32 index)
194{
195	union acpi_generic_state *state;
196
197	ACPI_FUNCTION_ENTRY();
198
199	/* Create the generic state object */
200
201	state = acpi_ut_create_generic_state();
202	if (!state) {
203		return (NULL);
204	}
205
206	/* Init fields specific to the update struct */
207
208	state->common.descriptor_type = ACPI_DESC_TYPE_STATE_PACKAGE;
209	state->pkg.source_object = (union acpi_operand_object *)internal_object;
210	state->pkg.dest_object = external_object;
211	state->pkg.index = index;
212	state->pkg.num_packages = 1;
213
214	return (state);
215}
216
217/*******************************************************************************
218 *
219 * FUNCTION:    acpi_ut_create_control_state
220 *
221 * PARAMETERS:  None
222 *
223 * RETURN:      New state object, null on failure
224 *
225 * DESCRIPTION: Create a "Control State" - a flavor of the generic state used
226 *              to support nested IF/WHILE constructs in the AML.
227 *
228 ******************************************************************************/
229
230union acpi_generic_state *acpi_ut_create_control_state(void)
231{
232	union acpi_generic_state *state;
233
234	ACPI_FUNCTION_ENTRY();
235
236	/* Create the generic state object */
237
238	state = acpi_ut_create_generic_state();
239	if (!state) {
240		return (NULL);
241	}
242
243	/* Init fields specific to the control struct */
244
245	state->common.descriptor_type = ACPI_DESC_TYPE_STATE_CONTROL;
246	state->common.state = ACPI_CONTROL_CONDITIONAL_EXECUTING;
247
248	return (state);
249}
250
251/*******************************************************************************
252 *
253 * FUNCTION:    acpi_ut_delete_generic_state
254 *
255 * PARAMETERS:  state               - The state object to be deleted
256 *
257 * RETURN:      None
258 *
259 * DESCRIPTION: Release a state object to the state cache. NULL state objects
260 *              are ignored.
261 *
262 ******************************************************************************/
263
264void acpi_ut_delete_generic_state(union acpi_generic_state *state)
265{
266	ACPI_FUNCTION_ENTRY();
267
268	/* Ignore null state */
269
270	if (state) {
271		(void)acpi_os_release_object(acpi_gbl_state_cache, state);
272	}
273
274	return;
275}