Linux Audio

Check our new training course

Loading...
v3.1
 
  1/******************************************************************************
  2 *
  3 * Module Name: dsobject - Dispatcher object management routines
  4 *
 
 
  5 *****************************************************************************/
  6
  7/*
  8 * Copyright (C) 2000 - 2011, 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#include "acparser.h"
 47#include "amlcode.h"
 48#include "acdispat.h"
 49#include "acnamesp.h"
 50#include "acinterp.h"
 51
 52#define _COMPONENT          ACPI_DISPATCHER
 53ACPI_MODULE_NAME("dsobject")
 54
 55/* Local prototypes */
 56static acpi_status
 57acpi_ds_build_internal_object(struct acpi_walk_state *walk_state,
 58			      union acpi_parse_object *op,
 59			      union acpi_operand_object **obj_desc_ptr);
 60
 61#ifndef ACPI_NO_METHOD_EXECUTION
 62/*******************************************************************************
 63 *
 64 * FUNCTION:    acpi_ds_build_internal_object
 65 *
 66 * PARAMETERS:  walk_state      - Current walk state
 67 *              Op              - Parser object to be translated
 68 *              obj_desc_ptr    - Where the ACPI internal object is returned
 69 *
 70 * RETURN:      Status
 71 *
 72 * DESCRIPTION: Translate a parser Op object to the equivalent namespace object
 73 *              Simple objects are any objects other than a package object!
 74 *
 75 ******************************************************************************/
 76
 77static acpi_status
 78acpi_ds_build_internal_object(struct acpi_walk_state *walk_state,
 79			      union acpi_parse_object *op,
 80			      union acpi_operand_object **obj_desc_ptr)
 81{
 82	union acpi_operand_object *obj_desc;
 83	acpi_status status;
 84	acpi_object_type type;
 85
 86	ACPI_FUNCTION_TRACE(ds_build_internal_object);
 87
 88	*obj_desc_ptr = NULL;
 89	if (op->common.aml_opcode == AML_INT_NAMEPATH_OP) {
 90		/*
 91		 * This is a named object reference. If this name was
 92		 * previously looked up in the namespace, it was stored in this op.
 93		 * Otherwise, go ahead and look it up now
 94		 */
 95		if (!op->common.node) {
 96			status = acpi_ns_lookup(walk_state->scope_info,
 97						op->common.value.string,
 98						ACPI_TYPE_ANY,
 99						ACPI_IMODE_EXECUTE,
100						ACPI_NS_SEARCH_PARENT |
101						ACPI_NS_DONT_OPEN_SCOPE, NULL,
102						ACPI_CAST_INDIRECT_PTR(struct
103								       acpi_namespace_node,
104								       &(op->
105									 common.
106									 node)));
107			if (ACPI_FAILURE(status)) {
108
109				/* Check if we are resolving a named reference within a package */
110
111				if ((status == AE_NOT_FOUND)
112				    && (acpi_gbl_enable_interpreter_slack)
113				    &&
114				    ((op->common.parent->common.aml_opcode ==
115				      AML_PACKAGE_OP)
116				     || (op->common.parent->common.aml_opcode ==
117					 AML_VAR_PACKAGE_OP))) {
118					/*
119					 * We didn't find the target and we are populating elements
120					 * of a package - ignore if slack enabled. Some ASL code
121					 * contains dangling invalid references in packages and
122					 * expects that no exception will be issued. Leave the
123					 * element as a null element. It cannot be used, but it
124					 * can be overwritten by subsequent ASL code - this is
125					 * typically the case.
126					 */
127					ACPI_DEBUG_PRINT((ACPI_DB_INFO,
128							  "Ignoring unresolved reference in package [%4.4s]\n",
129							  walk_state->
130							  scope_info->scope.
131							  node->name.ascii));
132
133					return_ACPI_STATUS(AE_OK);
134				} else {
135					ACPI_ERROR_NAMESPACE(op->common.value.
136							     string, status);
137				}
138
139				return_ACPI_STATUS(status);
140			}
141		}
142
143		/* Special object resolution for elements of a package */
144
145		if ((op->common.parent->common.aml_opcode == AML_PACKAGE_OP) ||
146		    (op->common.parent->common.aml_opcode ==
147		     AML_VAR_PACKAGE_OP)) {
148			/*
149			 * Attempt to resolve the node to a value before we insert it into
150			 * the package. If this is a reference to a common data type,
151			 * resolve it immediately. According to the ACPI spec, package
152			 * elements can only be "data objects" or method references.
153			 * Attempt to resolve to an Integer, Buffer, String or Package.
154			 * If cannot, return the named reference (for things like Devices,
155			 * Methods, etc.) Buffer Fields and Fields will resolve to simple
156			 * objects (int/buf/str/pkg).
157			 *
158			 * NOTE: References to things like Devices, Methods, Mutexes, etc.
159			 * will remain as named references. This behavior is not described
160			 * in the ACPI spec, but it appears to be an oversight.
161			 */
162			obj_desc =
163			    ACPI_CAST_PTR(union acpi_operand_object,
164					  op->common.node);
165
166			status =
167			    acpi_ex_resolve_node_to_value(ACPI_CAST_INDIRECT_PTR
168							  (struct
169							   acpi_namespace_node,
170							   &obj_desc),
171							  walk_state);
172			if (ACPI_FAILURE(status)) {
173				return_ACPI_STATUS(status);
174			}
175
176			/*
177			 * Special handling for Alias objects. We need to setup the type
178			 * and the Op->Common.Node to point to the Alias target. Note,
179			 * Alias has at most one level of indirection internally.
180			 */
181			type = op->common.node->type;
182			if (type == ACPI_TYPE_LOCAL_ALIAS) {
183				type = obj_desc->common.type;
184				op->common.node =
185				    ACPI_CAST_PTR(struct acpi_namespace_node,
186						  op->common.node->object);
187			}
188
189			switch (type) {
190				/*
191				 * For these types, we need the actual node, not the subobject.
192				 * However, the subobject did not get an extra reference count above.
193				 *
194				 * TBD: should ex_resolve_node_to_value be changed to fix this?
195				 */
196			case ACPI_TYPE_DEVICE:
197			case ACPI_TYPE_THERMAL:
198
199				acpi_ut_add_reference(op->common.node->object);
200
201				/*lint -fallthrough */
 
 
 
202				/*
203				 * For these types, we need the actual node, not the subobject.
204				 * The subobject got an extra reference count in ex_resolve_node_to_value.
 
 
205				 */
206			case ACPI_TYPE_MUTEX:
207			case ACPI_TYPE_METHOD:
208			case ACPI_TYPE_POWER:
209			case ACPI_TYPE_PROCESSOR:
210			case ACPI_TYPE_EVENT:
211			case ACPI_TYPE_REGION:
212
213				/* We will create a reference object for these types below */
214				break;
215
216			default:
217				/*
218				 * All other types - the node was resolved to an actual
219				 * object, we are done.
220				 */
221				goto exit;
 
 
 
 
222			}
223		}
224	}
225
 
 
226	/* Create and init a new internal ACPI object */
227
228	obj_desc = acpi_ut_create_internal_object((acpi_ps_get_opcode_info
229						   (op->common.aml_opcode))->
230						  object_type);
231	if (!obj_desc) {
232		return_ACPI_STATUS(AE_NO_MEMORY);
233	}
234
235	status =
236	    acpi_ds_init_object_from_op(walk_state, op, op->common.aml_opcode,
237					&obj_desc);
238	if (ACPI_FAILURE(status)) {
239		acpi_ut_remove_reference(obj_desc);
240		return_ACPI_STATUS(status);
241	}
242
243      exit:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
244	*obj_desc_ptr = obj_desc;
245	return_ACPI_STATUS(status);
246}
247
248/*******************************************************************************
249 *
250 * FUNCTION:    acpi_ds_build_internal_buffer_obj
251 *
252 * PARAMETERS:  walk_state      - Current walk state
253 *              Op              - Parser object to be translated
254 *              buffer_length   - Length of the buffer
255 *              obj_desc_ptr    - Where the ACPI internal object is returned
256 *
257 * RETURN:      Status
258 *
259 * DESCRIPTION: Translate a parser Op package object to the equivalent
260 *              namespace object
261 *
262 ******************************************************************************/
263
264acpi_status
265acpi_ds_build_internal_buffer_obj(struct acpi_walk_state *walk_state,
266				  union acpi_parse_object *op,
267				  u32 buffer_length,
268				  union acpi_operand_object **obj_desc_ptr)
269{
270	union acpi_parse_object *arg;
271	union acpi_operand_object *obj_desc;
272	union acpi_parse_object *byte_list;
273	u32 byte_list_length = 0;
274
275	ACPI_FUNCTION_TRACE(ds_build_internal_buffer_obj);
276
277	/*
278	 * If we are evaluating a Named buffer object "Name (xxxx, Buffer)".
279	 * The buffer object already exists (from the NS node), otherwise it must
280	 * be created.
281	 */
282	obj_desc = *obj_desc_ptr;
283	if (!obj_desc) {
284
285		/* Create a new buffer object */
286
287		obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_BUFFER);
288		*obj_desc_ptr = obj_desc;
289		if (!obj_desc) {
290			return_ACPI_STATUS(AE_NO_MEMORY);
291		}
292	}
293
294	/*
295	 * Second arg is the buffer data (optional) byte_list can be either
296	 * individual bytes or a string initializer.  In either case, a
297	 * byte_list appears in the AML.
298	 */
299	arg = op->common.value.arg;	/* skip first arg */
300
301	byte_list = arg->named.next;
302	if (byte_list) {
303		if (byte_list->common.aml_opcode != AML_INT_BYTELIST_OP) {
304			ACPI_ERROR((AE_INFO,
305				    "Expecting bytelist, found AML opcode 0x%X in op %p",
306				    byte_list->common.aml_opcode, byte_list));
307
308			acpi_ut_remove_reference(obj_desc);
309			return (AE_TYPE);
310		}
311
312		byte_list_length = (u32) byte_list->common.value.integer;
313	}
314
315	/*
316	 * The buffer length (number of bytes) will be the larger of:
317	 * 1) The specified buffer length and
318	 * 2) The length of the initializer byte list
319	 */
320	obj_desc->buffer.length = buffer_length;
321	if (byte_list_length > buffer_length) {
322		obj_desc->buffer.length = byte_list_length;
323	}
324
325	/* Allocate the buffer */
326
327	if (obj_desc->buffer.length == 0) {
328		obj_desc->buffer.pointer = NULL;
329		ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
330				  "Buffer defined with zero length in AML, creating\n"));
331	} else {
332		obj_desc->buffer.pointer =
333		    ACPI_ALLOCATE_ZEROED(obj_desc->buffer.length);
334		if (!obj_desc->buffer.pointer) {
335			acpi_ut_delete_object_desc(obj_desc);
336			return_ACPI_STATUS(AE_NO_MEMORY);
337		}
338
339		/* Initialize buffer from the byte_list (if present) */
340
341		if (byte_list) {
342			ACPI_MEMCPY(obj_desc->buffer.pointer,
343				    byte_list->named.data, byte_list_length);
344		}
345	}
346
347	obj_desc->buffer.flags |= AOPOBJ_DATA_VALID;
348	op->common.node = ACPI_CAST_PTR(struct acpi_namespace_node, obj_desc);
349	return_ACPI_STATUS(AE_OK);
350}
351
352/*******************************************************************************
353 *
354 * FUNCTION:    acpi_ds_build_internal_package_obj
355 *
356 * PARAMETERS:  walk_state      - Current walk state
357 *              Op              - Parser object to be translated
358 *              element_count   - Number of elements in the package - this is
359 *                                the num_elements argument to Package()
360 *              obj_desc_ptr    - Where the ACPI internal object is returned
361 *
362 * RETURN:      Status
363 *
364 * DESCRIPTION: Translate a parser Op package object to the equivalent
365 *              namespace object
366 *
367 * NOTE: The number of elements in the package will be always be the num_elements
368 * count, regardless of the number of elements in the package list. If
369 * num_elements is smaller, only that many package list elements are used.
370 * if num_elements is larger, the Package object is padded out with
371 * objects of type Uninitialized (as per ACPI spec.)
372 *
373 * Even though the ASL compilers do not allow num_elements to be smaller
374 * than the Package list length (for the fixed length package opcode), some
375 * BIOS code modifies the AML on the fly to adjust the num_elements, and
376 * this code compensates for that. This also provides compatibility with
377 * other AML interpreters.
378 *
379 ******************************************************************************/
380
381acpi_status
382acpi_ds_build_internal_package_obj(struct acpi_walk_state *walk_state,
383				   union acpi_parse_object *op,
384				   u32 element_count,
385				   union acpi_operand_object **obj_desc_ptr)
386{
387	union acpi_parse_object *arg;
388	union acpi_parse_object *parent;
389	union acpi_operand_object *obj_desc = NULL;
390	acpi_status status = AE_OK;
391	unsigned i;
392	u16 index;
393	u16 reference_count;
394
395	ACPI_FUNCTION_TRACE(ds_build_internal_package_obj);
396
397	/* Find the parent of a possibly nested package */
398
399	parent = op->common.parent;
400	while ((parent->common.aml_opcode == AML_PACKAGE_OP) ||
401	       (parent->common.aml_opcode == AML_VAR_PACKAGE_OP)) {
402		parent = parent->common.parent;
403	}
404
405	/*
406	 * If we are evaluating a Named package object "Name (xxxx, Package)",
407	 * the package object already exists, otherwise it must be created.
408	 */
409	obj_desc = *obj_desc_ptr;
410	if (!obj_desc) {
411		obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_PACKAGE);
412		*obj_desc_ptr = obj_desc;
413		if (!obj_desc) {
414			return_ACPI_STATUS(AE_NO_MEMORY);
415		}
416
417		obj_desc->package.node = parent->common.node;
418	}
419
420	/*
421	 * Allocate the element array (array of pointers to the individual
422	 * objects) based on the num_elements parameter. Add an extra pointer slot
423	 * so that the list is always null terminated.
424	 */
425	obj_desc->package.elements = ACPI_ALLOCATE_ZEROED(((acpi_size)
426							   element_count +
427							   1) * sizeof(void *));
428
429	if (!obj_desc->package.elements) {
430		acpi_ut_delete_object_desc(obj_desc);
431		return_ACPI_STATUS(AE_NO_MEMORY);
432	}
433
434	obj_desc->package.count = element_count;
435
436	/*
437	 * Initialize the elements of the package, up to the num_elements count.
438	 * Package is automatically padded with uninitialized (NULL) elements
439	 * if num_elements is greater than the package list length. Likewise,
440	 * Package is truncated if num_elements is less than the list length.
441	 */
442	arg = op->common.value.arg;
443	arg = arg->common.next;
444	for (i = 0; arg && (i < element_count); i++) {
445		if (arg->common.aml_opcode == AML_INT_RETURN_VALUE_OP) {
446			if (arg->common.node->type == ACPI_TYPE_METHOD) {
447				/*
448				 * A method reference "looks" to the parser to be a method
449				 * invocation, so we special case it here
450				 */
451				arg->common.aml_opcode = AML_INT_NAMEPATH_OP;
452				status =
453				    acpi_ds_build_internal_object(walk_state,
454								  arg,
455								  &obj_desc->
456								  package.
457								  elements[i]);
458			} else {
459				/* This package element is already built, just get it */
460
461				obj_desc->package.elements[i] =
462				    ACPI_CAST_PTR(union acpi_operand_object,
463						  arg->common.node);
464			}
465		} else {
466			status = acpi_ds_build_internal_object(walk_state, arg,
467							       &obj_desc->
468							       package.
469							       elements[i]);
470		}
471
472		if (*obj_desc_ptr) {
473
474			/* Existing package, get existing reference count */
475
476			reference_count =
477			    (*obj_desc_ptr)->common.reference_count;
478			if (reference_count > 1) {
479
480				/* Make new element ref count match original ref count */
481
482				for (index = 0; index < (reference_count - 1);
483				     index++) {
484					acpi_ut_add_reference((obj_desc->
485							       package.
486							       elements[i]));
487				}
488			}
489		}
490
491		arg = arg->common.next;
492	}
493
494	/* Check for match between num_elements and actual length of package_list */
495
496	if (arg) {
497		/*
498		 * num_elements was exhausted, but there are remaining elements in the
499		 * package_list. Truncate the package to num_elements.
500		 *
501		 * Note: technically, this is an error, from ACPI spec: "It is an error
502		 * for NumElements to be less than the number of elements in the
503		 * PackageList". However, we just print a message and
504		 * no exception is returned. This provides Windows compatibility. Some
505		 * BIOSs will alter the num_elements on the fly, creating this type
506		 * of ill-formed package object.
507		 */
508		while (arg) {
509			/*
510			 * We must delete any package elements that were created earlier
511			 * and are not going to be used because of the package truncation.
512			 */
513			if (arg->common.node) {
514				acpi_ut_remove_reference(ACPI_CAST_PTR
515							 (union
516							  acpi_operand_object,
517							  arg->common.node));
518				arg->common.node = NULL;
519			}
520
521			/* Find out how many elements there really are */
522
523			i++;
524			arg = arg->common.next;
525		}
526
527		ACPI_INFO((AE_INFO,
528			   "Actual Package length (%u) is larger than NumElements field (%u), truncated\n",
529			   i, element_count));
530	} else if (i < element_count) {
531		/*
532		 * Arg list (elements) was exhausted, but we did not reach num_elements count.
533		 * Note: this is not an error, the package is padded out with NULLs.
534		 */
535		ACPI_DEBUG_PRINT((ACPI_DB_INFO,
536				  "Package List length (%u) smaller than NumElements count (%u), padded with null elements\n",
537				  i, element_count));
538	}
539
540	obj_desc->package.flags |= AOPOBJ_DATA_VALID;
541	op->common.node = ACPI_CAST_PTR(struct acpi_namespace_node, obj_desc);
542	return_ACPI_STATUS(status);
543}
544
545/*******************************************************************************
546 *
547 * FUNCTION:    acpi_ds_create_node
548 *
549 * PARAMETERS:  walk_state      - Current walk state
550 *              Node            - NS Node to be initialized
551 *              Op              - Parser object to be translated
552 *
553 * RETURN:      Status
554 *
555 * DESCRIPTION: Create the object to be associated with a namespace node
556 *
557 ******************************************************************************/
558
559acpi_status
560acpi_ds_create_node(struct acpi_walk_state *walk_state,
561		    struct acpi_namespace_node *node,
562		    union acpi_parse_object *op)
563{
564	acpi_status status;
565	union acpi_operand_object *obj_desc;
566
567	ACPI_FUNCTION_TRACE_PTR(ds_create_node, op);
568
569	/*
570	 * Because of the execution pass through the non-control-method
571	 * parts of the table, we can arrive here twice.  Only init
572	 * the named object node the first time through
573	 */
574	if (acpi_ns_get_attached_object(node)) {
575		return_ACPI_STATUS(AE_OK);
576	}
577
578	if (!op->common.value.arg) {
579
580		/* No arguments, there is nothing to do */
581
582		return_ACPI_STATUS(AE_OK);
583	}
584
585	/* Build an internal object for the argument(s) */
586
587	status = acpi_ds_build_internal_object(walk_state, op->common.value.arg,
588					       &obj_desc);
 
589	if (ACPI_FAILURE(status)) {
590		return_ACPI_STATUS(status);
591	}
592
593	/* Re-type the object according to its argument */
594
595	node->type = obj_desc->common.type;
596
597	/* Attach obj to node */
598
599	status = acpi_ns_attach_object(node, obj_desc, node->type);
600
601	/* Remove local reference to the object */
602
603	acpi_ut_remove_reference(obj_desc);
604	return_ACPI_STATUS(status);
605}
606
607#endif				/* ACPI_NO_METHOD_EXECUTION */
608
609/*******************************************************************************
610 *
611 * FUNCTION:    acpi_ds_init_object_from_op
612 *
613 * PARAMETERS:  walk_state      - Current walk state
614 *              Op              - Parser op used to init the internal object
615 *              Opcode          - AML opcode associated with the object
616 *              ret_obj_desc    - Namespace object to be initialized
617 *
618 * RETURN:      Status
619 *
620 * DESCRIPTION: Initialize a namespace object from a parser Op and its
621 *              associated arguments.  The namespace object is a more compact
622 *              representation of the Op and its arguments.
623 *
624 ******************************************************************************/
625
626acpi_status
627acpi_ds_init_object_from_op(struct acpi_walk_state *walk_state,
628			    union acpi_parse_object *op,
629			    u16 opcode,
630			    union acpi_operand_object **ret_obj_desc)
631{
632	const struct acpi_opcode_info *op_info;
633	union acpi_operand_object *obj_desc;
634	acpi_status status = AE_OK;
635
636	ACPI_FUNCTION_TRACE(ds_init_object_from_op);
637
638	obj_desc = *ret_obj_desc;
639	op_info = acpi_ps_get_opcode_info(opcode);
640	if (op_info->class == AML_CLASS_UNKNOWN) {
641
642		/* Unknown opcode */
643
644		return_ACPI_STATUS(AE_TYPE);
645	}
646
647	/* Perform per-object initialization */
648
649	switch (obj_desc->common.type) {
650	case ACPI_TYPE_BUFFER:
651
652		/*
653		 * Defer evaluation of Buffer term_arg operand
654		 */
655		obj_desc->buffer.node =
656		    ACPI_CAST_PTR(struct acpi_namespace_node,
657				  walk_state->operands[0]);
658		obj_desc->buffer.aml_start = op->named.data;
659		obj_desc->buffer.aml_length = op->named.length;
660		break;
661
662	case ACPI_TYPE_PACKAGE:
663
664		/*
665		 * Defer evaluation of Package term_arg operand
 
 
 
 
666		 */
667		obj_desc->package.node =
668		    ACPI_CAST_PTR(struct acpi_namespace_node,
669				  walk_state->operands[0]);
 
 
 
 
 
670		obj_desc->package.aml_start = op->named.data;
671		obj_desc->package.aml_length = op->named.length;
672		break;
673
674	case ACPI_TYPE_INTEGER:
675
676		switch (op_info->type) {
677		case AML_TYPE_CONSTANT:
678			/*
679			 * Resolve AML Constants here - AND ONLY HERE!
680			 * All constants are integers.
681			 * We mark the integer with a flag that indicates that it started
682			 * life as a constant -- so that stores to constants will perform
683			 * as expected (noop). zero_op is used as a placeholder for optional
684			 * target operands.
685			 */
686			obj_desc->common.flags = AOPOBJ_AML_CONSTANT;
687
688			switch (opcode) {
689			case AML_ZERO_OP:
690
691				obj_desc->integer.value = 0;
692				break;
693
694			case AML_ONE_OP:
695
696				obj_desc->integer.value = 1;
697				break;
698
699			case AML_ONES_OP:
700
701				obj_desc->integer.value = ACPI_UINT64_MAX;
702
703				/* Truncate value if we are executing from a 32-bit ACPI table */
704
705#ifndef ACPI_NO_METHOD_EXECUTION
706				acpi_ex_truncate_for32bit_table(obj_desc);
707#endif
708				break;
709
710			case AML_REVISION_OP:
711
712				obj_desc->integer.value = ACPI_CA_VERSION;
713				break;
714
715			default:
716
717				ACPI_ERROR((AE_INFO,
718					    "Unknown constant opcode 0x%X",
719					    opcode));
720				status = AE_AML_OPERAND_TYPE;
721				break;
722			}
723			break;
724
725		case AML_TYPE_LITERAL:
726
727			obj_desc->integer.value = op->common.value.integer;
728#ifndef ACPI_NO_METHOD_EXECUTION
729			acpi_ex_truncate_for32bit_table(obj_desc);
730#endif
 
 
 
 
 
 
 
 
731			break;
732
733		default:
 
734			ACPI_ERROR((AE_INFO, "Unknown Integer type 0x%X",
735				    op_info->type));
736			status = AE_AML_OPERAND_TYPE;
737			break;
738		}
739		break;
740
741	case ACPI_TYPE_STRING:
742
743		obj_desc->string.pointer = op->common.value.string;
744		obj_desc->string.length =
745		    (u32) ACPI_STRLEN(op->common.value.string);
746
747		/*
748		 * The string is contained in the ACPI table, don't ever try
749		 * to delete it
750		 */
751		obj_desc->common.flags |= AOPOBJ_STATIC_POINTER;
752		break;
753
754	case ACPI_TYPE_METHOD:
755		break;
756
757	case ACPI_TYPE_LOCAL_REFERENCE:
758
759		switch (op_info->type) {
760		case AML_TYPE_LOCAL_VARIABLE:
761
762			/* Local ID (0-7) is (AML opcode - base AML_LOCAL_OP) */
763
764			obj_desc->reference.value =
765			    ((u32)opcode) - AML_LOCAL_OP;
766			obj_desc->reference.class = ACPI_REFCLASS_LOCAL;
767
768#ifndef ACPI_NO_METHOD_EXECUTION
769			status =
770			    acpi_ds_method_data_get_node(ACPI_REFCLASS_LOCAL,
771							 obj_desc->reference.
772							 value, walk_state,
773							 ACPI_CAST_INDIRECT_PTR
774							 (struct
775							  acpi_namespace_node,
776							  &obj_desc->reference.
777							  object));
778#endif
779			break;
780
781		case AML_TYPE_METHOD_ARGUMENT:
782
783			/* Arg ID (0-6) is (AML opcode - base AML_ARG_OP) */
784
785			obj_desc->reference.value = ((u32)opcode) - AML_ARG_OP;
 
786			obj_desc->reference.class = ACPI_REFCLASS_ARG;
787
788#ifndef ACPI_NO_METHOD_EXECUTION
789			status = acpi_ds_method_data_get_node(ACPI_REFCLASS_ARG,
790							      obj_desc->
791							      reference.value,
792							      walk_state,
793							      ACPI_CAST_INDIRECT_PTR
794							      (struct
795							       acpi_namespace_node,
796							       &obj_desc->
797							       reference.
798							       object));
799#endif
800			break;
801
802		default:	/* Object name or Debug object */
803
804			switch (op->common.aml_opcode) {
805			case AML_INT_NAMEPATH_OP:
806
807				/* Node was saved in Op */
808
809				obj_desc->reference.node = op->common.node;
810				obj_desc->reference.object =
811				    op->common.node->object;
812				obj_desc->reference.class = ACPI_REFCLASS_NAME;
 
 
 
 
813				break;
814
815			case AML_DEBUG_OP:
816
817				obj_desc->reference.class = ACPI_REFCLASS_DEBUG;
818				break;
819
820			default:
821
822				ACPI_ERROR((AE_INFO,
823					    "Unimplemented reference type for AML opcode: 0x%4.4X",
824					    opcode));
825				return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
826			}
827			break;
828		}
829		break;
830
831	default:
832
833		ACPI_ERROR((AE_INFO, "Unimplemented data type: 0x%X",
834			    obj_desc->common.type));
835
836		status = AE_AML_OPERAND_TYPE;
837		break;
838	}
839
840	return_ACPI_STATUS(status);
841}
v5.9
  1// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
  2/******************************************************************************
  3 *
  4 * Module Name: dsobject - Dispatcher object management routines
  5 *
  6 * Copyright (C) 2000 - 2020, Intel Corp.
  7 *
  8 *****************************************************************************/
  9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 10#include <acpi/acpi.h>
 11#include "accommon.h"
 12#include "acparser.h"
 13#include "amlcode.h"
 14#include "acdispat.h"
 15#include "acnamesp.h"
 16#include "acinterp.h"
 17
 18#define _COMPONENT          ACPI_DISPATCHER
 19ACPI_MODULE_NAME("dsobject")
 20
 
 
 
 
 
 
 
 21/*******************************************************************************
 22 *
 23 * FUNCTION:    acpi_ds_build_internal_object
 24 *
 25 * PARAMETERS:  walk_state      - Current walk state
 26 *              op              - Parser object to be translated
 27 *              obj_desc_ptr    - Where the ACPI internal object is returned
 28 *
 29 * RETURN:      Status
 30 *
 31 * DESCRIPTION: Translate a parser Op object to the equivalent namespace object
 32 *              Simple objects are any objects other than a package object!
 33 *
 34 ******************************************************************************/
 35acpi_status
 
 36acpi_ds_build_internal_object(struct acpi_walk_state *walk_state,
 37			      union acpi_parse_object *op,
 38			      union acpi_operand_object **obj_desc_ptr)
 39{
 40	union acpi_operand_object *obj_desc;
 41	acpi_status status;
 
 42
 43	ACPI_FUNCTION_TRACE(ds_build_internal_object);
 44
 45	*obj_desc_ptr = NULL;
 46	if (op->common.aml_opcode == AML_INT_NAMEPATH_OP) {
 47		/*
 48		 * This is a named object reference. If this name was
 49		 * previously looked up in the namespace, it was stored in
 50		 * this op. Otherwise, go ahead and look it up now
 51		 */
 52		if (!op->common.node) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 53
 54			/* Check if we are resolving a named reference within a package */
 55
 56			if ((op->common.parent->common.aml_opcode ==
 57			     AML_PACKAGE_OP)
 58			    || (op->common.parent->common.aml_opcode ==
 59				AML_VARIABLE_PACKAGE_OP)) {
 60				/*
 61				 * We won't resolve package elements here, we will do this
 62				 * after all ACPI tables are loaded into the namespace. This
 63				 * behavior supports both forward references to named objects
 64				 * and external references to objects in other tables.
 65				 */
 66				goto create_new_object;
 67			} else {
 68				status = acpi_ns_lookup(walk_state->scope_info,
 69							op->common.value.string,
 70							ACPI_TYPE_ANY,
 71							ACPI_IMODE_EXECUTE,
 72							ACPI_NS_SEARCH_PARENT |
 73							ACPI_NS_DONT_OPEN_SCOPE,
 74							NULL,
 75							ACPI_CAST_INDIRECT_PTR
 76							(struct
 77							 acpi_namespace_node,
 78							 &(op->common.node)));
 79				if (ACPI_FAILURE(status)) {
 80					ACPI_ERROR_NAMESPACE(walk_state->
 81							     scope_info,
 82							     op->common.value.
 83							     string, status);
 84					return_ACPI_STATUS(status);
 85				}
 86			}
 87		}
 88	}
 89
 90create_new_object:
 91
 92	/* Create and init a new internal ACPI object */
 93
 94	obj_desc = acpi_ut_create_internal_object((acpi_ps_get_opcode_info
 95						   (op->common.aml_opcode))->
 96						  object_type);
 97	if (!obj_desc) {
 98		return_ACPI_STATUS(AE_NO_MEMORY);
 99	}
100
101	status =
102	    acpi_ds_init_object_from_op(walk_state, op, op->common.aml_opcode,
103					&obj_desc);
104	if (ACPI_FAILURE(status)) {
105		acpi_ut_remove_reference(obj_desc);
106		return_ACPI_STATUS(status);
107	}
108
109	/*
110	 * Handling for unresolved package reference elements.
111	 * These are elements that are namepaths.
112	 */
113	if ((op->common.parent->common.aml_opcode == AML_PACKAGE_OP) ||
114	    (op->common.parent->common.aml_opcode == AML_VARIABLE_PACKAGE_OP)) {
115		obj_desc->reference.resolved = TRUE;
116
117		if ((op->common.aml_opcode == AML_INT_NAMEPATH_OP) &&
118		    !obj_desc->reference.node) {
119			/*
120			 * Name was unresolved above.
121			 * Get the prefix node for later lookup
122			 */
123			obj_desc->reference.node =
124			    walk_state->scope_info->scope.node;
125			obj_desc->reference.aml = op->common.aml;
126			obj_desc->reference.resolved = FALSE;
127		}
128	}
129
130	*obj_desc_ptr = obj_desc;
131	return_ACPI_STATUS(status);
132}
133
134/*******************************************************************************
135 *
136 * FUNCTION:    acpi_ds_build_internal_buffer_obj
137 *
138 * PARAMETERS:  walk_state      - Current walk state
139 *              op              - Parser object to be translated
140 *              buffer_length   - Length of the buffer
141 *              obj_desc_ptr    - Where the ACPI internal object is returned
142 *
143 * RETURN:      Status
144 *
145 * DESCRIPTION: Translate a parser Op package object to the equivalent
146 *              namespace object
147 *
148 ******************************************************************************/
149
150acpi_status
151acpi_ds_build_internal_buffer_obj(struct acpi_walk_state *walk_state,
152				  union acpi_parse_object *op,
153				  u32 buffer_length,
154				  union acpi_operand_object **obj_desc_ptr)
155{
156	union acpi_parse_object *arg;
157	union acpi_operand_object *obj_desc;
158	union acpi_parse_object *byte_list;
159	u32 byte_list_length = 0;
160
161	ACPI_FUNCTION_TRACE(ds_build_internal_buffer_obj);
162
163	/*
164	 * If we are evaluating a Named buffer object "Name (xxxx, Buffer)".
165	 * The buffer object already exists (from the NS node), otherwise it must
166	 * be created.
167	 */
168	obj_desc = *obj_desc_ptr;
169	if (!obj_desc) {
170
171		/* Create a new buffer object */
172
173		obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_BUFFER);
174		*obj_desc_ptr = obj_desc;
175		if (!obj_desc) {
176			return_ACPI_STATUS(AE_NO_MEMORY);
177		}
178	}
179
180	/*
181	 * Second arg is the buffer data (optional) byte_list can be either
182	 * individual bytes or a string initializer. In either case, a
183	 * byte_list appears in the AML.
184	 */
185	arg = op->common.value.arg;	/* skip first arg */
186
187	byte_list = arg->named.next;
188	if (byte_list) {
189		if (byte_list->common.aml_opcode != AML_INT_BYTELIST_OP) {
190			ACPI_ERROR((AE_INFO,
191				    "Expecting bytelist, found AML opcode 0x%X in op %p",
192				    byte_list->common.aml_opcode, byte_list));
193
194			acpi_ut_remove_reference(obj_desc);
195			return (AE_TYPE);
196		}
197
198		byte_list_length = (u32) byte_list->common.value.integer;
199	}
200
201	/*
202	 * The buffer length (number of bytes) will be the larger of:
203	 * 1) The specified buffer length and
204	 * 2) The length of the initializer byte list
205	 */
206	obj_desc->buffer.length = buffer_length;
207	if (byte_list_length > buffer_length) {
208		obj_desc->buffer.length = byte_list_length;
209	}
210
211	/* Allocate the buffer */
212
213	if (obj_desc->buffer.length == 0) {
214		obj_desc->buffer.pointer = NULL;
215		ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
216				  "Buffer defined with zero length in AML, creating\n"));
217	} else {
218		obj_desc->buffer.pointer =
219		    ACPI_ALLOCATE_ZEROED(obj_desc->buffer.length);
220		if (!obj_desc->buffer.pointer) {
221			acpi_ut_delete_object_desc(obj_desc);
222			return_ACPI_STATUS(AE_NO_MEMORY);
223		}
224
225		/* Initialize buffer from the byte_list (if present) */
226
227		if (byte_list) {
228			memcpy(obj_desc->buffer.pointer, byte_list->named.data,
229			       byte_list_length);
230		}
231	}
232
233	obj_desc->buffer.flags |= AOPOBJ_DATA_VALID;
234	op->common.node = ACPI_CAST_PTR(struct acpi_namespace_node, obj_desc);
235	return_ACPI_STATUS(AE_OK);
236}
237
238/*******************************************************************************
239 *
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
240 * FUNCTION:    acpi_ds_create_node
241 *
242 * PARAMETERS:  walk_state      - Current walk state
243 *              node            - NS Node to be initialized
244 *              op              - Parser object to be translated
245 *
246 * RETURN:      Status
247 *
248 * DESCRIPTION: Create the object to be associated with a namespace node
249 *
250 ******************************************************************************/
251
252acpi_status
253acpi_ds_create_node(struct acpi_walk_state *walk_state,
254		    struct acpi_namespace_node *node,
255		    union acpi_parse_object *op)
256{
257	acpi_status status;
258	union acpi_operand_object *obj_desc;
259
260	ACPI_FUNCTION_TRACE_PTR(ds_create_node, op);
261
262	/*
263	 * Because of the execution pass through the non-control-method
264	 * parts of the table, we can arrive here twice. Only init
265	 * the named object node the first time through
266	 */
267	if (acpi_ns_get_attached_object(node)) {
268		return_ACPI_STATUS(AE_OK);
269	}
270
271	if (!op->common.value.arg) {
272
273		/* No arguments, there is nothing to do */
274
275		return_ACPI_STATUS(AE_OK);
276	}
277
278	/* Build an internal object for the argument(s) */
279
280	status =
281	    acpi_ds_build_internal_object(walk_state, op->common.value.arg,
282					  &obj_desc);
283	if (ACPI_FAILURE(status)) {
284		return_ACPI_STATUS(status);
285	}
286
287	/* Re-type the object according to its argument */
288
289	node->type = obj_desc->common.type;
290
291	/* Attach obj to node */
292
293	status = acpi_ns_attach_object(node, obj_desc, node->type);
294
295	/* Remove local reference to the object */
296
297	acpi_ut_remove_reference(obj_desc);
298	return_ACPI_STATUS(status);
299}
300
 
 
301/*******************************************************************************
302 *
303 * FUNCTION:    acpi_ds_init_object_from_op
304 *
305 * PARAMETERS:  walk_state      - Current walk state
306 *              op              - Parser op used to init the internal object
307 *              opcode          - AML opcode associated with the object
308 *              ret_obj_desc    - Namespace object to be initialized
309 *
310 * RETURN:      Status
311 *
312 * DESCRIPTION: Initialize a namespace object from a parser Op and its
313 *              associated arguments. The namespace object is a more compact
314 *              representation of the Op and its arguments.
315 *
316 ******************************************************************************/
317
318acpi_status
319acpi_ds_init_object_from_op(struct acpi_walk_state *walk_state,
320			    union acpi_parse_object *op,
321			    u16 opcode,
322			    union acpi_operand_object **ret_obj_desc)
323{
324	const struct acpi_opcode_info *op_info;
325	union acpi_operand_object *obj_desc;
326	acpi_status status = AE_OK;
327
328	ACPI_FUNCTION_TRACE(ds_init_object_from_op);
329
330	obj_desc = *ret_obj_desc;
331	op_info = acpi_ps_get_opcode_info(opcode);
332	if (op_info->class == AML_CLASS_UNKNOWN) {
333
334		/* Unknown opcode */
335
336		return_ACPI_STATUS(AE_TYPE);
337	}
338
339	/* Perform per-object initialization */
340
341	switch (obj_desc->common.type) {
342	case ACPI_TYPE_BUFFER:
 
343		/*
344		 * Defer evaluation of Buffer term_arg operand
345		 */
346		obj_desc->buffer.node =
347		    ACPI_CAST_PTR(struct acpi_namespace_node,
348				  walk_state->operands[0]);
349		obj_desc->buffer.aml_start = op->named.data;
350		obj_desc->buffer.aml_length = op->named.length;
351		break;
352
353	case ACPI_TYPE_PACKAGE:
 
354		/*
355		 * Defer evaluation of Package term_arg operand and all
356		 * package elements. (01/2017): We defer the element
357		 * resolution to allow forward references from the package
358		 * in order to provide compatibility with other ACPI
359		 * implementations.
360		 */
361		obj_desc->package.node =
362		    ACPI_CAST_PTR(struct acpi_namespace_node,
363				  walk_state->operands[0]);
364
365		if (!op->named.data) {
366			return_ACPI_STATUS(AE_OK);
367		}
368
369		obj_desc->package.aml_start = op->named.data;
370		obj_desc->package.aml_length = op->named.length;
371		break;
372
373	case ACPI_TYPE_INTEGER:
374
375		switch (op_info->type) {
376		case AML_TYPE_CONSTANT:
377			/*
378			 * Resolve AML Constants here - AND ONLY HERE!
379			 * All constants are integers.
380			 * We mark the integer with a flag that indicates that it started
381			 * life as a constant -- so that stores to constants will perform
382			 * as expected (noop). zero_op is used as a placeholder for optional
383			 * target operands.
384			 */
385			obj_desc->common.flags = AOPOBJ_AML_CONSTANT;
386
387			switch (opcode) {
388			case AML_ZERO_OP:
389
390				obj_desc->integer.value = 0;
391				break;
392
393			case AML_ONE_OP:
394
395				obj_desc->integer.value = 1;
396				break;
397
398			case AML_ONES_OP:
399
400				obj_desc->integer.value = ACPI_UINT64_MAX;
401
402				/* Truncate value if we are executing from a 32-bit ACPI table */
403
404				(void)acpi_ex_truncate_for32bit_table(obj_desc);
 
 
405				break;
406
407			case AML_REVISION_OP:
408
409				obj_desc->integer.value = ACPI_CA_VERSION;
410				break;
411
412			default:
413
414				ACPI_ERROR((AE_INFO,
415					    "Unknown constant opcode 0x%X",
416					    opcode));
417				status = AE_AML_OPERAND_TYPE;
418				break;
419			}
420			break;
421
422		case AML_TYPE_LITERAL:
423
424			obj_desc->integer.value = op->common.value.integer;
425
426			if (acpi_ex_truncate_for32bit_table(obj_desc)) {
427
428				/* Warn if we found a 64-bit constant in a 32-bit table */
429
430				ACPI_WARNING((AE_INFO,
431					      "Truncated 64-bit constant found in 32-bit table: %8.8X%8.8X => %8.8X",
432					      ACPI_FORMAT_UINT64(op->common.
433								 value.integer),
434					      (u32)obj_desc->integer.value));
435			}
436			break;
437
438		default:
439
440			ACPI_ERROR((AE_INFO, "Unknown Integer type 0x%X",
441				    op_info->type));
442			status = AE_AML_OPERAND_TYPE;
443			break;
444		}
445		break;
446
447	case ACPI_TYPE_STRING:
448
449		obj_desc->string.pointer = op->common.value.string;
450		obj_desc->string.length = (u32)strlen(op->common.value.string);
 
451
452		/*
453		 * The string is contained in the ACPI table, don't ever try
454		 * to delete it
455		 */
456		obj_desc->common.flags |= AOPOBJ_STATIC_POINTER;
457		break;
458
459	case ACPI_TYPE_METHOD:
460		break;
461
462	case ACPI_TYPE_LOCAL_REFERENCE:
463
464		switch (op_info->type) {
465		case AML_TYPE_LOCAL_VARIABLE:
466
467			/* Local ID (0-7) is (AML opcode - base AML_FIRST_LOCAL_OP) */
468
469			obj_desc->reference.value =
470			    ((u32)opcode) - AML_FIRST_LOCAL_OP;
471			obj_desc->reference.class = ACPI_REFCLASS_LOCAL;
472
 
473			status =
474			    acpi_ds_method_data_get_node(ACPI_REFCLASS_LOCAL,
475							 obj_desc->reference.
476							 value, walk_state,
477							 ACPI_CAST_INDIRECT_PTR
478							 (struct
479							  acpi_namespace_node,
480							  &obj_desc->reference.
481							  object));
 
482			break;
483
484		case AML_TYPE_METHOD_ARGUMENT:
485
486			/* Arg ID (0-6) is (AML opcode - base AML_FIRST_ARG_OP) */
487
488			obj_desc->reference.value =
489			    ((u32)opcode) - AML_FIRST_ARG_OP;
490			obj_desc->reference.class = ACPI_REFCLASS_ARG;
491
 
492			status = acpi_ds_method_data_get_node(ACPI_REFCLASS_ARG,
493							      obj_desc->
494							      reference.value,
495							      walk_state,
496							      ACPI_CAST_INDIRECT_PTR
497							      (struct
498							       acpi_namespace_node,
499							       &obj_desc->
500							       reference.
501							       object));
 
502			break;
503
504		default:	/* Object name or Debug object */
505
506			switch (op->common.aml_opcode) {
507			case AML_INT_NAMEPATH_OP:
508
509				/* Node was saved in Op */
510
511				obj_desc->reference.node = op->common.node;
 
 
512				obj_desc->reference.class = ACPI_REFCLASS_NAME;
513				if (op->common.node) {
514					obj_desc->reference.object =
515					    op->common.node->object;
516				}
517				break;
518
519			case AML_DEBUG_OP:
520
521				obj_desc->reference.class = ACPI_REFCLASS_DEBUG;
522				break;
523
524			default:
525
526				ACPI_ERROR((AE_INFO,
527					    "Unimplemented reference type for AML opcode: 0x%4.4X",
528					    opcode));
529				return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
530			}
531			break;
532		}
533		break;
534
535	default:
536
537		ACPI_ERROR((AE_INFO, "Unimplemented data type: 0x%X",
538			    obj_desc->common.type));
539
540		status = AE_AML_OPERAND_TYPE;
541		break;
542	}
543
544	return_ACPI_STATUS(status);
545}