Linux Audio

Check our new training course

Loading...
v3.1
  1
  2/******************************************************************************
  3 *
  4 * Module Name: exresnte - AML Interpreter object resolution
  5 *
 
 
  6 *****************************************************************************/
  7
  8/*
  9 * Copyright (C) 2000 - 2011, Intel Corp.
 10 * All rights reserved.
 11 *
 12 * Redistribution and use in source and binary forms, with or without
 13 * modification, are permitted provided that the following conditions
 14 * are met:
 15 * 1. Redistributions of source code must retain the above copyright
 16 *    notice, this list of conditions, and the following disclaimer,
 17 *    without modification.
 18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
 19 *    substantially similar to the "NO WARRANTY" disclaimer below
 20 *    ("Disclaimer") and any redistribution must be conditioned upon
 21 *    including a substantially similar Disclaimer requirement for further
 22 *    binary redistribution.
 23 * 3. Neither the names of the above-listed copyright holders nor the names
 24 *    of any contributors may be used to endorse or promote products derived
 25 *    from this software without specific prior written permission.
 26 *
 27 * Alternatively, this software may be distributed under the terms of the
 28 * GNU General Public License ("GPL") version 2 as published by the Free
 29 * Software Foundation.
 30 *
 31 * NO WARRANTY
 32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
 35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 42 * POSSIBILITY OF SUCH DAMAGES.
 43 */
 44
 45#include <acpi/acpi.h>
 46#include "accommon.h"
 47#include "acdispat.h"
 48#include "acinterp.h"
 49#include "acnamesp.h"
 50
 51#define _COMPONENT          ACPI_EXECUTER
 52ACPI_MODULE_NAME("exresnte")
 53
 54/*******************************************************************************
 55 *
 56 * FUNCTION:    acpi_ex_resolve_node_to_value
 57 *
 58 * PARAMETERS:  object_ptr      - Pointer to a location that contains
 59 *                                a pointer to a NS node, and will receive a
 60 *                                pointer to the resolved object.
 61 *              walk_state      - Current state.  Valid only if executing AML
 62 *                                code.  NULL if simply resolving an object
 63 *
 64 * RETURN:      Status
 65 *
 66 * DESCRIPTION: Resolve a Namespace node to a valued object
 67 *
 68 * Note: for some of the data types, the pointer attached to the Node
 69 * can be either a pointer to an actual internal object or a pointer into the
 70 * AML stream itself.  These types are currently:
 71 *
 72 *      ACPI_TYPE_INTEGER
 73 *      ACPI_TYPE_STRING
 74 *      ACPI_TYPE_BUFFER
 75 *      ACPI_TYPE_MUTEX
 76 *      ACPI_TYPE_PACKAGE
 77 *
 78 ******************************************************************************/
 79acpi_status
 80acpi_ex_resolve_node_to_value(struct acpi_namespace_node **object_ptr,
 81			      struct acpi_walk_state *walk_state)
 82{
 83	acpi_status status = AE_OK;
 84	union acpi_operand_object *source_desc;
 85	union acpi_operand_object *obj_desc = NULL;
 86	struct acpi_namespace_node *node;
 87	acpi_object_type entry_type;
 88
 89	ACPI_FUNCTION_TRACE(ex_resolve_node_to_value);
 90
 91	/*
 92	 * The stack pointer points to a struct acpi_namespace_node (Node).  Get the
 93	 * object that is attached to the Node.
 94	 */
 95	node = *object_ptr;
 96	source_desc = acpi_ns_get_attached_object(node);
 97	entry_type = acpi_ns_get_type((acpi_handle) node);
 98
 99	ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Entry=%p SourceDesc=%p [%s]\n",
100			  node, source_desc,
101			  acpi_ut_get_type_name(entry_type)));
102
103	if ((entry_type == ACPI_TYPE_LOCAL_ALIAS) ||
104	    (entry_type == ACPI_TYPE_LOCAL_METHOD_ALIAS)) {
105
106		/* There is always exactly one level of indirection */
107
108		node = ACPI_CAST_PTR(struct acpi_namespace_node, node->object);
109		source_desc = acpi_ns_get_attached_object(node);
110		entry_type = acpi_ns_get_type((acpi_handle) node);
111		*object_ptr = node;
112	}
113
114	/*
115	 * Several object types require no further processing:
116	 * 1) Device/Thermal objects don't have a "real" subobject, return the Node
117	 * 2) Method locals and arguments have a pseudo-Node
118	 * 3) 10/2007: Added method type to assist with Package construction.
119	 */
120	if ((entry_type == ACPI_TYPE_DEVICE) ||
121	    (entry_type == ACPI_TYPE_THERMAL) ||
122	    (entry_type == ACPI_TYPE_METHOD) ||
123	    (node->flags & (ANOBJ_METHOD_ARG | ANOBJ_METHOD_LOCAL))) {
124		return_ACPI_STATUS(AE_OK);
125	}
126
127	if (!source_desc) {
128		ACPI_ERROR((AE_INFO, "No object attached to node %p", node));
129		return_ACPI_STATUS(AE_AML_NO_OPERAND);
 
130	}
131
132	/*
133	 * Action is based on the type of the Node, which indicates the type
134	 * of the attached object or pointer
135	 */
136	switch (entry_type) {
137	case ACPI_TYPE_PACKAGE:
138
139		if (source_desc->common.type != ACPI_TYPE_PACKAGE) {
140			ACPI_ERROR((AE_INFO, "Object not a Package, type %s",
141				    acpi_ut_get_object_type_name(source_desc)));
142			return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
143		}
144
145		status = acpi_ds_get_package_arguments(source_desc);
146		if (ACPI_SUCCESS(status)) {
147
148			/* Return an additional reference to the object */
149
150			obj_desc = source_desc;
151			acpi_ut_add_reference(obj_desc);
152		}
153		break;
154
155	case ACPI_TYPE_BUFFER:
156
157		if (source_desc->common.type != ACPI_TYPE_BUFFER) {
158			ACPI_ERROR((AE_INFO, "Object not a Buffer, type %s",
159				    acpi_ut_get_object_type_name(source_desc)));
160			return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
161		}
162
163		status = acpi_ds_get_buffer_arguments(source_desc);
164		if (ACPI_SUCCESS(status)) {
165
166			/* Return an additional reference to the object */
167
168			obj_desc = source_desc;
169			acpi_ut_add_reference(obj_desc);
170		}
171		break;
172
173	case ACPI_TYPE_STRING:
174
175		if (source_desc->common.type != ACPI_TYPE_STRING) {
176			ACPI_ERROR((AE_INFO, "Object not a String, type %s",
177				    acpi_ut_get_object_type_name(source_desc)));
178			return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
179		}
180
181		/* Return an additional reference to the object */
182
183		obj_desc = source_desc;
184		acpi_ut_add_reference(obj_desc);
185		break;
186
187	case ACPI_TYPE_INTEGER:
188
189		if (source_desc->common.type != ACPI_TYPE_INTEGER) {
190			ACPI_ERROR((AE_INFO, "Object not a Integer, type %s",
191				    acpi_ut_get_object_type_name(source_desc)));
192			return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
193		}
194
195		/* Return an additional reference to the object */
196
197		obj_desc = source_desc;
198		acpi_ut_add_reference(obj_desc);
199		break;
200
201	case ACPI_TYPE_BUFFER_FIELD:
202	case ACPI_TYPE_LOCAL_REGION_FIELD:
203	case ACPI_TYPE_LOCAL_BANK_FIELD:
204	case ACPI_TYPE_LOCAL_INDEX_FIELD:
205
206		ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
207				  "FieldRead Node=%p SourceDesc=%p Type=%X\n",
208				  node, source_desc, entry_type));
209
210		status =
211		    acpi_ex_read_data_from_field(walk_state, source_desc,
212						 &obj_desc);
213		break;
214
215		/* For these objects, just return the object attached to the Node */
216
217	case ACPI_TYPE_MUTEX:
218	case ACPI_TYPE_POWER:
219	case ACPI_TYPE_PROCESSOR:
220	case ACPI_TYPE_EVENT:
221	case ACPI_TYPE_REGION:
222
223		/* Return an additional reference to the object */
224
225		obj_desc = source_desc;
226		acpi_ut_add_reference(obj_desc);
227		break;
228
229		/* TYPE_ANY is untyped, and thus there is no object associated with it */
230
231	case ACPI_TYPE_ANY:
232
233		ACPI_ERROR((AE_INFO,
234			    "Untyped entry %p, no attached object!", node));
235
236		return_ACPI_STATUS(AE_AML_OPERAND_TYPE);	/* Cannot be AE_TYPE */
237
238	case ACPI_TYPE_LOCAL_REFERENCE:
239
240		switch (source_desc->reference.class) {
241		case ACPI_REFCLASS_TABLE:	/* This is a ddb_handle */
242		case ACPI_REFCLASS_REFOF:
243		case ACPI_REFCLASS_INDEX:
244
245			/* Return an additional reference to the object */
246
247			obj_desc = source_desc;
248			acpi_ut_add_reference(obj_desc);
249			break;
250
251		default:
 
252			/* No named references are allowed here */
253
254			ACPI_ERROR((AE_INFO,
255				    "Unsupported Reference type 0x%X",
256				    source_desc->reference.class));
257
258			return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
259		}
260		break;
261
262	default:
263
264		/* Default case is for unknown types */
265
266		ACPI_ERROR((AE_INFO,
267			    "Node %p - Unknown object type 0x%X",
268			    node, entry_type));
269
270		return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
271
272	}			/* switch (entry_type) */
273
274	/* Return the object descriptor */
275
276	*object_ptr = (void *)obj_desc;
277	return_ACPI_STATUS(status);
278}
v6.8
  1// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
  2/******************************************************************************
  3 *
  4 * Module Name: exresnte - AML Interpreter object resolution
  5 *
  6 * Copyright (C) 2000 - 2023, Intel Corp.
  7 *
  8 *****************************************************************************/
  9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 10#include <acpi/acpi.h>
 11#include "accommon.h"
 12#include "acdispat.h"
 13#include "acinterp.h"
 14#include "acnamesp.h"
 15
 16#define _COMPONENT          ACPI_EXECUTER
 17ACPI_MODULE_NAME("exresnte")
 18
 19/*******************************************************************************
 20 *
 21 * FUNCTION:    acpi_ex_resolve_node_to_value
 22 *
 23 * PARAMETERS:  object_ptr      - Pointer to a location that contains
 24 *                                a pointer to a NS node, and will receive a
 25 *                                pointer to the resolved object.
 26 *              walk_state      - Current state. Valid only if executing AML
 27 *                                code. NULL if simply resolving an object
 28 *
 29 * RETURN:      Status
 30 *
 31 * DESCRIPTION: Resolve a Namespace node to a valued object
 32 *
 33 * Note: for some of the data types, the pointer attached to the Node
 34 * can be either a pointer to an actual internal object or a pointer into the
 35 * AML stream itself. These types are currently:
 36 *
 37 *      ACPI_TYPE_INTEGER
 38 *      ACPI_TYPE_STRING
 39 *      ACPI_TYPE_BUFFER
 40 *      ACPI_TYPE_MUTEX
 41 *      ACPI_TYPE_PACKAGE
 42 *
 43 ******************************************************************************/
 44acpi_status
 45acpi_ex_resolve_node_to_value(struct acpi_namespace_node **object_ptr,
 46			      struct acpi_walk_state *walk_state)
 47{
 48	acpi_status status = AE_OK;
 49	union acpi_operand_object *source_desc;
 50	union acpi_operand_object *obj_desc = NULL;
 51	struct acpi_namespace_node *node;
 52	acpi_object_type entry_type;
 53
 54	ACPI_FUNCTION_TRACE(ex_resolve_node_to_value);
 55
 56	/*
 57	 * The stack pointer points to a struct acpi_namespace_node (Node). Get the
 58	 * object that is attached to the Node.
 59	 */
 60	node = *object_ptr;
 61	source_desc = acpi_ns_get_attached_object(node);
 62	entry_type = acpi_ns_get_type((acpi_handle)node);
 63
 64	ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Entry=%p SourceDesc=%p [%s]\n",
 65			  node, source_desc,
 66			  acpi_ut_get_type_name(entry_type)));
 67
 68	if ((entry_type == ACPI_TYPE_LOCAL_ALIAS) ||
 69	    (entry_type == ACPI_TYPE_LOCAL_METHOD_ALIAS)) {
 70
 71		/* There is always exactly one level of indirection */
 72
 73		node = ACPI_CAST_PTR(struct acpi_namespace_node, node->object);
 74		source_desc = acpi_ns_get_attached_object(node);
 75		entry_type = acpi_ns_get_type((acpi_handle)node);
 76		*object_ptr = node;
 77	}
 78
 79	/*
 80	 * Several object types require no further processing:
 81	 * 1) Device/Thermal objects don't have a "real" subobject, return Node
 82	 * 2) Method locals and arguments have a pseudo-Node
 83	 * 3) 10/2007: Added method type to assist with Package construction.
 84	 */
 85	if ((entry_type == ACPI_TYPE_DEVICE) ||
 86	    (entry_type == ACPI_TYPE_THERMAL) ||
 87	    (entry_type == ACPI_TYPE_METHOD) ||
 88	    (node->flags & (ANOBJ_METHOD_ARG | ANOBJ_METHOD_LOCAL))) {
 89		return_ACPI_STATUS(AE_OK);
 90	}
 91
 92	if (!source_desc) {
 93		ACPI_ERROR((AE_INFO, "No object attached to node [%4.4s] %p",
 94			    node->name.ascii, node));
 95		return_ACPI_STATUS(AE_AML_UNINITIALIZED_NODE);
 96	}
 97
 98	/*
 99	 * Action is based on the type of the Node, which indicates the type
100	 * of the attached object or pointer
101	 */
102	switch (entry_type) {
103	case ACPI_TYPE_PACKAGE:
104
105		if (source_desc->common.type != ACPI_TYPE_PACKAGE) {
106			ACPI_ERROR((AE_INFO, "Object not a Package, type %s",
107				    acpi_ut_get_object_type_name(source_desc)));
108			return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
109		}
110
111		status = acpi_ds_get_package_arguments(source_desc);
112		if (ACPI_SUCCESS(status)) {
113
114			/* Return an additional reference to the object */
115
116			obj_desc = source_desc;
117			acpi_ut_add_reference(obj_desc);
118		}
119		break;
120
121	case ACPI_TYPE_BUFFER:
122
123		if (source_desc->common.type != ACPI_TYPE_BUFFER) {
124			ACPI_ERROR((AE_INFO, "Object not a Buffer, type %s",
125				    acpi_ut_get_object_type_name(source_desc)));
126			return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
127		}
128
129		status = acpi_ds_get_buffer_arguments(source_desc);
130		if (ACPI_SUCCESS(status)) {
131
132			/* Return an additional reference to the object */
133
134			obj_desc = source_desc;
135			acpi_ut_add_reference(obj_desc);
136		}
137		break;
138
139	case ACPI_TYPE_STRING:
140
141		if (source_desc->common.type != ACPI_TYPE_STRING) {
142			ACPI_ERROR((AE_INFO, "Object not a String, type %s",
143				    acpi_ut_get_object_type_name(source_desc)));
144			return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
145		}
146
147		/* Return an additional reference to the object */
148
149		obj_desc = source_desc;
150		acpi_ut_add_reference(obj_desc);
151		break;
152
153	case ACPI_TYPE_INTEGER:
154
155		if (source_desc->common.type != ACPI_TYPE_INTEGER) {
156			ACPI_ERROR((AE_INFO, "Object not a Integer, type %s",
157				    acpi_ut_get_object_type_name(source_desc)));
158			return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
159		}
160
161		/* Return an additional reference to the object */
162
163		obj_desc = source_desc;
164		acpi_ut_add_reference(obj_desc);
165		break;
166
167	case ACPI_TYPE_BUFFER_FIELD:
168	case ACPI_TYPE_LOCAL_REGION_FIELD:
169	case ACPI_TYPE_LOCAL_BANK_FIELD:
170	case ACPI_TYPE_LOCAL_INDEX_FIELD:
171
172		ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
173				  "FieldRead Node=%p SourceDesc=%p Type=%X\n",
174				  node, source_desc, entry_type));
175
176		status =
177		    acpi_ex_read_data_from_field(walk_state, source_desc,
178						 &obj_desc);
179		break;
180
181		/* For these objects, just return the object attached to the Node */
182
183	case ACPI_TYPE_MUTEX:
184	case ACPI_TYPE_POWER:
185	case ACPI_TYPE_PROCESSOR:
186	case ACPI_TYPE_EVENT:
187	case ACPI_TYPE_REGION:
188
189		/* Return an additional reference to the object */
190
191		obj_desc = source_desc;
192		acpi_ut_add_reference(obj_desc);
193		break;
194
195		/* TYPE_ANY is untyped, and thus there is no object associated with it */
196
197	case ACPI_TYPE_ANY:
198
199		ACPI_ERROR((AE_INFO,
200			    "Untyped entry %p, no attached object!", node));
201
202		return_ACPI_STATUS(AE_AML_OPERAND_TYPE);	/* Cannot be AE_TYPE */
203
204	case ACPI_TYPE_LOCAL_REFERENCE:
205
206		switch (source_desc->reference.class) {
207		case ACPI_REFCLASS_TABLE:	/* This is a ddb_handle */
208		case ACPI_REFCLASS_REFOF:
209		case ACPI_REFCLASS_INDEX:
210
211			/* Return an additional reference to the object */
212
213			obj_desc = source_desc;
214			acpi_ut_add_reference(obj_desc);
215			break;
216
217		default:
218
219			/* No named references are allowed here */
220
221			ACPI_ERROR((AE_INFO,
222				    "Unsupported Reference type 0x%X",
223				    source_desc->reference.class));
224
225			return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
226		}
227		break;
228
229	default:
230
231		/* Default case is for unknown types */
232
233		ACPI_ERROR((AE_INFO,
234			    "Node %p - Unknown object type 0x%X",
235			    node, entry_type));
236
237		return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
238
239	}			/* switch (entry_type) */
240
241	/* Return the object descriptor */
242
243	*object_ptr = (void *)obj_desc;
244	return_ACPI_STATUS(status);
245}