sch_gred: should not use GFP_KERNEL while holding a spinlock
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / acpi / acpica / nspredef.c
blobdc005827b9dac04e70613956bec3885fac0f76a4
1 /******************************************************************************
3 * Module Name: nspredef - Validation of ACPI predefined methods and objects
4 * $Revision: 1.1 $
6 *****************************************************************************/
8 /*
9 * Copyright (C) 2000 - 2011, Intel Corp.
10 * All rights reserved.
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.
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.
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.
45 #define ACPI_CREATE_PREDEFINED_TABLE
47 #include <acpi/acpi.h>
48 #include "accommon.h"
49 #include "acnamesp.h"
50 #include "acpredef.h"
52 #define _COMPONENT ACPI_NAMESPACE
53 ACPI_MODULE_NAME("nspredef")
55 /*******************************************************************************
57 * This module validates predefined ACPI objects that appear in the namespace,
58 * at the time they are evaluated (via acpi_evaluate_object). The purpose of this
59 * validation is to detect problems with BIOS-exposed predefined ACPI objects
60 * before the results are returned to the ACPI-related drivers.
62 * There are several areas that are validated:
64 * 1) The number of input arguments as defined by the method/object in the
65 * ASL is validated against the ACPI specification.
66 * 2) The type of the return object (if any) is validated against the ACPI
67 * specification.
68 * 3) For returned package objects, the count of package elements is
69 * validated, as well as the type of each package element. Nested
70 * packages are supported.
72 * For any problems found, a warning message is issued.
74 ******************************************************************************/
75 /* Local prototypes */
76 static acpi_status
77 acpi_ns_check_package(struct acpi_predefined_data *data,
78 union acpi_operand_object **return_object_ptr);
80 static acpi_status
81 acpi_ns_check_package_list(struct acpi_predefined_data *data,
82 const union acpi_predefined_info *package,
83 union acpi_operand_object **elements, u32 count);
85 static acpi_status
86 acpi_ns_check_package_elements(struct acpi_predefined_data *data,
87 union acpi_operand_object **elements,
88 u8 type1,
89 u32 count1,
90 u8 type2, u32 count2, u32 start_index);
92 static acpi_status
93 acpi_ns_check_object_type(struct acpi_predefined_data *data,
94 union acpi_operand_object **return_object_ptr,
95 u32 expected_btypes, u32 package_index);
97 static acpi_status
98 acpi_ns_check_reference(struct acpi_predefined_data *data,
99 union acpi_operand_object *return_object);
101 static void acpi_ns_get_expected_types(char *buffer, u32 expected_btypes);
104 * Names for the types that can be returned by the predefined objects.
105 * Used for warning messages. Must be in the same order as the ACPI_RTYPEs
107 static const char *acpi_rtype_names[] = {
108 "/Integer",
109 "/String",
110 "/Buffer",
111 "/Package",
112 "/Reference",
115 /*******************************************************************************
117 * FUNCTION: acpi_ns_check_predefined_names
119 * PARAMETERS: Node - Namespace node for the method/object
120 * user_param_count - Number of parameters actually passed
121 * return_status - Status from the object evaluation
122 * return_object_ptr - Pointer to the object returned from the
123 * evaluation of a method or object
125 * RETURN: Status
127 * DESCRIPTION: Check an ACPI name for a match in the predefined name list.
129 ******************************************************************************/
131 acpi_status
132 acpi_ns_check_predefined_names(struct acpi_namespace_node *node,
133 u32 user_param_count,
134 acpi_status return_status,
135 union acpi_operand_object **return_object_ptr)
137 union acpi_operand_object *return_object = *return_object_ptr;
138 acpi_status status = AE_OK;
139 const union acpi_predefined_info *predefined;
140 char *pathname;
141 struct acpi_predefined_data *data;
143 /* Match the name for this method/object against the predefined list */
145 predefined = acpi_ns_check_for_predefined_name(node);
147 /* Get the full pathname to the object, for use in warning messages */
149 pathname = acpi_ns_get_external_pathname(node);
150 if (!pathname) {
151 return AE_OK; /* Could not get pathname, ignore */
155 * Check that the parameter count for this method matches the ASL
156 * definition. For predefined names, ensure that both the caller and
157 * the method itself are in accordance with the ACPI specification.
159 acpi_ns_check_parameter_count(pathname, node, user_param_count,
160 predefined);
162 /* If not a predefined name, we cannot validate the return object */
164 if (!predefined) {
165 goto cleanup;
169 * If the method failed or did not actually return an object, we cannot
170 * validate the return object
172 if ((return_status != AE_OK) && (return_status != AE_CTRL_RETURN_VALUE)) {
173 goto cleanup;
177 * If there is no return value, check if we require a return value for
178 * this predefined name. Either one return value is expected, or none,
179 * for both methods and other objects.
181 * Exit now if there is no return object. Warning if one was expected.
183 if (!return_object) {
184 if ((predefined->info.expected_btypes) &&
185 (!(predefined->info.expected_btypes & ACPI_RTYPE_NONE))) {
186 ACPI_WARN_PREDEFINED((AE_INFO, pathname,
187 ACPI_WARN_ALWAYS,
188 "Missing expected return value"));
190 status = AE_AML_NO_RETURN_VALUE;
192 goto cleanup;
196 * 1) We have a return value, but if one wasn't expected, just exit, this is
197 * not a problem. For example, if the "Implicit Return" feature is
198 * enabled, methods will always return a value.
200 * 2) If the return value can be of any type, then we cannot perform any
201 * validation, exit.
203 if ((!predefined->info.expected_btypes) ||
204 (predefined->info.expected_btypes == ACPI_RTYPE_ALL)) {
205 goto cleanup;
208 /* Create the parameter data block for object validation */
210 data = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_predefined_data));
211 if (!data) {
212 goto cleanup;
214 data->predefined = predefined;
215 data->node = node;
216 data->node_flags = node->flags;
217 data->pathname = pathname;
220 * Check that the type of the main return object is what is expected
221 * for this predefined name
223 status = acpi_ns_check_object_type(data, return_object_ptr,
224 predefined->info.expected_btypes,
225 ACPI_NOT_PACKAGE_ELEMENT);
226 if (ACPI_FAILURE(status)) {
227 goto exit;
231 * For returned Package objects, check the type of all sub-objects.
232 * Note: Package may have been newly created by call above.
234 if ((*return_object_ptr)->common.type == ACPI_TYPE_PACKAGE) {
235 data->parent_package = *return_object_ptr;
236 status = acpi_ns_check_package(data, return_object_ptr);
237 if (ACPI_FAILURE(status)) {
238 goto exit;
243 * The return object was OK, or it was successfully repaired above.
244 * Now make some additional checks such as verifying that package
245 * objects are sorted correctly (if required) or buffer objects have
246 * the correct data width (bytes vs. dwords). These repairs are
247 * performed on a per-name basis, i.e., the code is specific to
248 * particular predefined names.
250 status = acpi_ns_complex_repairs(data, node, status, return_object_ptr);
252 exit:
254 * If the object validation failed or if we successfully repaired one
255 * or more objects, mark the parent node to suppress further warning
256 * messages during the next evaluation of the same method/object.
258 if (ACPI_FAILURE(status) || (data->flags & ACPI_OBJECT_REPAIRED)) {
259 node->flags |= ANOBJ_EVALUATED;
261 ACPI_FREE(data);
263 cleanup:
264 ACPI_FREE(pathname);
265 return (status);
268 /*******************************************************************************
270 * FUNCTION: acpi_ns_check_parameter_count
272 * PARAMETERS: Pathname - Full pathname to the node (for error msgs)
273 * Node - Namespace node for the method/object
274 * user_param_count - Number of args passed in by the caller
275 * Predefined - Pointer to entry in predefined name table
277 * RETURN: None
279 * DESCRIPTION: Check that the declared (in ASL/AML) parameter count for a
280 * predefined name is what is expected (i.e., what is defined in
281 * the ACPI specification for this predefined name.)
283 ******************************************************************************/
285 void
286 acpi_ns_check_parameter_count(char *pathname,
287 struct acpi_namespace_node *node,
288 u32 user_param_count,
289 const union acpi_predefined_info *predefined)
291 u32 param_count;
292 u32 required_params_current;
293 u32 required_params_old;
295 /* Methods have 0-7 parameters. All other types have zero. */
297 param_count = 0;
298 if (node->type == ACPI_TYPE_METHOD) {
299 param_count = node->object->method.param_count;
302 if (!predefined) {
304 * Check the parameter count for non-predefined methods/objects.
306 * Warning if too few or too many arguments have been passed by the
307 * caller. An incorrect number of arguments may not cause the method
308 * to fail. However, the method will fail if there are too few
309 * arguments and the method attempts to use one of the missing ones.
311 if (user_param_count < param_count) {
312 ACPI_WARN_PREDEFINED((AE_INFO, pathname,
313 ACPI_WARN_ALWAYS,
314 "Insufficient arguments - needs %u, found %u",
315 param_count, user_param_count));
316 } else if (user_param_count > param_count) {
317 ACPI_WARN_PREDEFINED((AE_INFO, pathname,
318 ACPI_WARN_ALWAYS,
319 "Excess arguments - needs %u, found %u",
320 param_count, user_param_count));
322 return;
326 * Validate the user-supplied parameter count.
327 * Allow two different legal argument counts (_SCP, etc.)
329 required_params_current = predefined->info.param_count & 0x0F;
330 required_params_old = predefined->info.param_count >> 4;
332 if (user_param_count != ACPI_UINT32_MAX) {
333 if ((user_param_count != required_params_current) &&
334 (user_param_count != required_params_old)) {
335 ACPI_WARN_PREDEFINED((AE_INFO, pathname,
336 ACPI_WARN_ALWAYS,
337 "Parameter count mismatch - "
338 "caller passed %u, ACPI requires %u",
339 user_param_count,
340 required_params_current));
345 * Check that the ASL-defined parameter count is what is expected for
346 * this predefined name (parameter count as defined by the ACPI
347 * specification)
349 if ((param_count != required_params_current) &&
350 (param_count != required_params_old)) {
351 ACPI_WARN_PREDEFINED((AE_INFO, pathname, node->flags,
352 "Parameter count mismatch - ASL declared %u, ACPI requires %u",
353 param_count, required_params_current));
357 /*******************************************************************************
359 * FUNCTION: acpi_ns_check_for_predefined_name
361 * PARAMETERS: Node - Namespace node for the method/object
363 * RETURN: Pointer to entry in predefined table. NULL indicates not found.
365 * DESCRIPTION: Check an object name against the predefined object list.
367 ******************************************************************************/
369 const union acpi_predefined_info *acpi_ns_check_for_predefined_name(struct
370 acpi_namespace_node
371 *node)
373 const union acpi_predefined_info *this_name;
375 /* Quick check for a predefined name, first character must be underscore */
377 if (node->name.ascii[0] != '_') {
378 return (NULL);
381 /* Search info table for a predefined method/object name */
383 this_name = predefined_names;
384 while (this_name->info.name[0]) {
385 if (ACPI_COMPARE_NAME(node->name.ascii, this_name->info.name)) {
386 return (this_name);
390 * Skip next entry in the table if this name returns a Package
391 * (next entry contains the package info)
393 if (this_name->info.expected_btypes & ACPI_RTYPE_PACKAGE) {
394 this_name++;
397 this_name++;
400 return (NULL); /* Not found */
403 /*******************************************************************************
405 * FUNCTION: acpi_ns_check_package
407 * PARAMETERS: Data - Pointer to validation data structure
408 * return_object_ptr - Pointer to the object returned from the
409 * evaluation of a method or object
411 * RETURN: Status
413 * DESCRIPTION: Check a returned package object for the correct count and
414 * correct type of all sub-objects.
416 ******************************************************************************/
418 static acpi_status
419 acpi_ns_check_package(struct acpi_predefined_data *data,
420 union acpi_operand_object **return_object_ptr)
422 union acpi_operand_object *return_object = *return_object_ptr;
423 const union acpi_predefined_info *package;
424 union acpi_operand_object **elements;
425 acpi_status status = AE_OK;
426 u32 expected_count;
427 u32 count;
428 u32 i;
430 ACPI_FUNCTION_NAME(ns_check_package);
432 /* The package info for this name is in the next table entry */
434 package = data->predefined + 1;
436 ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
437 "%s Validating return Package of Type %X, Count %X\n",
438 data->pathname, package->ret_info.type,
439 return_object->package.count));
442 * For variable-length Packages, we can safely remove all embedded
443 * and trailing NULL package elements
445 acpi_ns_remove_null_elements(data, package->ret_info.type,
446 return_object);
448 /* Extract package count and elements array */
450 elements = return_object->package.elements;
451 count = return_object->package.count;
453 /* The package must have at least one element, else invalid */
455 if (!count) {
456 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags,
457 "Return Package has no elements (empty)"));
459 return (AE_AML_OPERAND_VALUE);
463 * Decode the type of the expected package contents
465 * PTYPE1 packages contain no subpackages
466 * PTYPE2 packages contain sub-packages
468 switch (package->ret_info.type) {
469 case ACPI_PTYPE1_FIXED:
472 * The package count is fixed and there are no sub-packages
474 * If package is too small, exit.
475 * If package is larger than expected, issue warning but continue
477 expected_count =
478 package->ret_info.count1 + package->ret_info.count2;
479 if (count < expected_count) {
480 goto package_too_small;
481 } else if (count > expected_count) {
482 ACPI_DEBUG_PRINT((ACPI_DB_REPAIR,
483 "%s: Return Package is larger than needed - "
484 "found %u, expected %u\n",
485 data->pathname, count,
486 expected_count));
489 /* Validate all elements of the returned package */
491 status = acpi_ns_check_package_elements(data, elements,
492 package->ret_info.
493 object_type1,
494 package->ret_info.
495 count1,
496 package->ret_info.
497 object_type2,
498 package->ret_info.
499 count2, 0);
500 break;
502 case ACPI_PTYPE1_VAR:
505 * The package count is variable, there are no sub-packages, and all
506 * elements must be of the same type
508 for (i = 0; i < count; i++) {
509 status = acpi_ns_check_object_type(data, elements,
510 package->ret_info.
511 object_type1, i);
512 if (ACPI_FAILURE(status)) {
513 return (status);
515 elements++;
517 break;
519 case ACPI_PTYPE1_OPTION:
522 * The package count is variable, there are no sub-packages. There are
523 * a fixed number of required elements, and a variable number of
524 * optional elements.
526 * Check if package is at least as large as the minimum required
528 expected_count = package->ret_info3.count;
529 if (count < expected_count) {
530 goto package_too_small;
533 /* Variable number of sub-objects */
535 for (i = 0; i < count; i++) {
536 if (i < package->ret_info3.count) {
538 /* These are the required package elements (0, 1, or 2) */
540 status =
541 acpi_ns_check_object_type(data, elements,
542 package->
543 ret_info3.
544 object_type[i],
546 if (ACPI_FAILURE(status)) {
547 return (status);
549 } else {
550 /* These are the optional package elements */
552 status =
553 acpi_ns_check_object_type(data, elements,
554 package->
555 ret_info3.
556 tail_object_type,
558 if (ACPI_FAILURE(status)) {
559 return (status);
562 elements++;
564 break;
566 case ACPI_PTYPE2_REV_FIXED:
568 /* First element is the (Integer) revision */
570 status = acpi_ns_check_object_type(data, elements,
571 ACPI_RTYPE_INTEGER, 0);
572 if (ACPI_FAILURE(status)) {
573 return (status);
576 elements++;
577 count--;
579 /* Examine the sub-packages */
581 status =
582 acpi_ns_check_package_list(data, package, elements, count);
583 break;
585 case ACPI_PTYPE2_PKG_COUNT:
587 /* First element is the (Integer) count of sub-packages to follow */
589 status = acpi_ns_check_object_type(data, elements,
590 ACPI_RTYPE_INTEGER, 0);
591 if (ACPI_FAILURE(status)) {
592 return (status);
596 * Count cannot be larger than the parent package length, but allow it
597 * to be smaller. The >= accounts for the Integer above.
599 expected_count = (u32) (*elements)->integer.value;
600 if (expected_count >= count) {
601 goto package_too_small;
604 count = expected_count;
605 elements++;
607 /* Examine the sub-packages */
609 status =
610 acpi_ns_check_package_list(data, package, elements, count);
611 break;
613 case ACPI_PTYPE2:
614 case ACPI_PTYPE2_FIXED:
615 case ACPI_PTYPE2_MIN:
616 case ACPI_PTYPE2_COUNT:
619 * These types all return a single Package that consists of a
620 * variable number of sub-Packages.
622 * First, ensure that the first element is a sub-Package. If not,
623 * the BIOS may have incorrectly returned the object as a single
624 * package instead of a Package of Packages (a common error if
625 * there is only one entry). We may be able to repair this by
626 * wrapping the returned Package with a new outer Package.
628 if (*elements
629 && ((*elements)->common.type != ACPI_TYPE_PACKAGE)) {
631 /* Create the new outer package and populate it */
633 status =
634 acpi_ns_repair_package_list(data,
635 return_object_ptr);
636 if (ACPI_FAILURE(status)) {
637 return (status);
640 /* Update locals to point to the new package (of 1 element) */
642 return_object = *return_object_ptr;
643 elements = return_object->package.elements;
644 count = 1;
647 /* Examine the sub-packages */
649 status =
650 acpi_ns_check_package_list(data, package, elements, count);
651 break;
653 default:
655 /* Should not get here if predefined info table is correct */
657 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags,
658 "Invalid internal return type in table entry: %X",
659 package->ret_info.type));
661 return (AE_AML_INTERNAL);
664 return (status);
666 package_too_small:
668 /* Error exit for the case with an incorrect package count */
670 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags,
671 "Return Package is too small - found %u elements, expected %u",
672 count, expected_count));
674 return (AE_AML_OPERAND_VALUE);
677 /*******************************************************************************
679 * FUNCTION: acpi_ns_check_package_list
681 * PARAMETERS: Data - Pointer to validation data structure
682 * Package - Pointer to package-specific info for method
683 * Elements - Element list of parent package. All elements
684 * of this list should be of type Package.
685 * Count - Count of subpackages
687 * RETURN: Status
689 * DESCRIPTION: Examine a list of subpackages
691 ******************************************************************************/
693 static acpi_status
694 acpi_ns_check_package_list(struct acpi_predefined_data *data,
695 const union acpi_predefined_info *package,
696 union acpi_operand_object **elements, u32 count)
698 union acpi_operand_object *sub_package;
699 union acpi_operand_object **sub_elements;
700 acpi_status status;
701 u32 expected_count;
702 u32 i;
703 u32 j;
706 * Validate each sub-Package in the parent Package
708 * NOTE: assumes list of sub-packages contains no NULL elements.
709 * Any NULL elements should have been removed by earlier call
710 * to acpi_ns_remove_null_elements.
712 for (i = 0; i < count; i++) {
713 sub_package = *elements;
714 sub_elements = sub_package->package.elements;
715 data->parent_package = sub_package;
717 /* Each sub-object must be of type Package */
719 status = acpi_ns_check_object_type(data, &sub_package,
720 ACPI_RTYPE_PACKAGE, i);
721 if (ACPI_FAILURE(status)) {
722 return (status);
725 /* Examine the different types of expected sub-packages */
727 data->parent_package = sub_package;
728 switch (package->ret_info.type) {
729 case ACPI_PTYPE2:
730 case ACPI_PTYPE2_PKG_COUNT:
731 case ACPI_PTYPE2_REV_FIXED:
733 /* Each subpackage has a fixed number of elements */
735 expected_count =
736 package->ret_info.count1 + package->ret_info.count2;
737 if (sub_package->package.count < expected_count) {
738 goto package_too_small;
741 status =
742 acpi_ns_check_package_elements(data, sub_elements,
743 package->ret_info.
744 object_type1,
745 package->ret_info.
746 count1,
747 package->ret_info.
748 object_type2,
749 package->ret_info.
750 count2, 0);
751 if (ACPI_FAILURE(status)) {
752 return (status);
754 break;
756 case ACPI_PTYPE2_FIXED:
758 /* Each sub-package has a fixed length */
760 expected_count = package->ret_info2.count;
761 if (sub_package->package.count < expected_count) {
762 goto package_too_small;
765 /* Check the type of each sub-package element */
767 for (j = 0; j < expected_count; j++) {
768 status =
769 acpi_ns_check_object_type(data,
770 &sub_elements[j],
771 package->
772 ret_info2.
773 object_type[j],
775 if (ACPI_FAILURE(status)) {
776 return (status);
779 break;
781 case ACPI_PTYPE2_MIN:
783 /* Each sub-package has a variable but minimum length */
785 expected_count = package->ret_info.count1;
786 if (sub_package->package.count < expected_count) {
787 goto package_too_small;
790 /* Check the type of each sub-package element */
792 status =
793 acpi_ns_check_package_elements(data, sub_elements,
794 package->ret_info.
795 object_type1,
796 sub_package->package.
797 count, 0, 0, 0);
798 if (ACPI_FAILURE(status)) {
799 return (status);
801 break;
803 case ACPI_PTYPE2_COUNT:
806 * First element is the (Integer) count of elements, including
807 * the count field (the ACPI name is num_elements)
809 status = acpi_ns_check_object_type(data, sub_elements,
810 ACPI_RTYPE_INTEGER,
812 if (ACPI_FAILURE(status)) {
813 return (status);
817 * Make sure package is large enough for the Count and is
818 * is as large as the minimum size
820 expected_count = (u32)(*sub_elements)->integer.value;
821 if (sub_package->package.count < expected_count) {
822 goto package_too_small;
824 if (sub_package->package.count <
825 package->ret_info.count1) {
826 expected_count = package->ret_info.count1;
827 goto package_too_small;
829 if (expected_count == 0) {
831 * Either the num_entries element was originally zero or it was
832 * a NULL element and repaired to an Integer of value zero.
833 * In either case, repair it by setting num_entries to be the
834 * actual size of the subpackage.
836 expected_count = sub_package->package.count;
837 (*sub_elements)->integer.value = expected_count;
840 /* Check the type of each sub-package element */
842 status =
843 acpi_ns_check_package_elements(data,
844 (sub_elements + 1),
845 package->ret_info.
846 object_type1,
847 (expected_count - 1),
848 0, 0, 1);
849 if (ACPI_FAILURE(status)) {
850 return (status);
852 break;
854 default: /* Should not get here, type was validated by caller */
856 return (AE_AML_INTERNAL);
859 elements++;
862 return (AE_OK);
864 package_too_small:
866 /* The sub-package count was smaller than required */
868 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags,
869 "Return Sub-Package[%u] is too small - found %u elements, expected %u",
870 i, sub_package->package.count, expected_count));
872 return (AE_AML_OPERAND_VALUE);
875 /*******************************************************************************
877 * FUNCTION: acpi_ns_check_package_elements
879 * PARAMETERS: Data - Pointer to validation data structure
880 * Elements - Pointer to the package elements array
881 * Type1 - Object type for first group
882 * Count1 - Count for first group
883 * Type2 - Object type for second group
884 * Count2 - Count for second group
885 * start_index - Start of the first group of elements
887 * RETURN: Status
889 * DESCRIPTION: Check that all elements of a package are of the correct object
890 * type. Supports up to two groups of different object types.
892 ******************************************************************************/
894 static acpi_status
895 acpi_ns_check_package_elements(struct acpi_predefined_data *data,
896 union acpi_operand_object **elements,
897 u8 type1,
898 u32 count1,
899 u8 type2, u32 count2, u32 start_index)
901 union acpi_operand_object **this_element = elements;
902 acpi_status status;
903 u32 i;
906 * Up to two groups of package elements are supported by the data
907 * structure. All elements in each group must be of the same type.
908 * The second group can have a count of zero.
910 for (i = 0; i < count1; i++) {
911 status = acpi_ns_check_object_type(data, this_element,
912 type1, i + start_index);
913 if (ACPI_FAILURE(status)) {
914 return (status);
916 this_element++;
919 for (i = 0; i < count2; i++) {
920 status = acpi_ns_check_object_type(data, this_element,
921 type2,
922 (i + count1 + start_index));
923 if (ACPI_FAILURE(status)) {
924 return (status);
926 this_element++;
929 return (AE_OK);
932 /*******************************************************************************
934 * FUNCTION: acpi_ns_check_object_type
936 * PARAMETERS: Data - Pointer to validation data structure
937 * return_object_ptr - Pointer to the object returned from the
938 * evaluation of a method or object
939 * expected_btypes - Bitmap of expected return type(s)
940 * package_index - Index of object within parent package (if
941 * applicable - ACPI_NOT_PACKAGE_ELEMENT
942 * otherwise)
944 * RETURN: Status
946 * DESCRIPTION: Check the type of the return object against the expected object
947 * type(s). Use of Btype allows multiple expected object types.
949 ******************************************************************************/
951 static acpi_status
952 acpi_ns_check_object_type(struct acpi_predefined_data *data,
953 union acpi_operand_object **return_object_ptr,
954 u32 expected_btypes, u32 package_index)
956 union acpi_operand_object *return_object = *return_object_ptr;
957 acpi_status status = AE_OK;
958 u32 return_btype;
959 char type_buffer[48]; /* Room for 5 types */
962 * If we get a NULL return_object here, it is a NULL package element.
963 * Since all extraneous NULL package elements were removed earlier by a
964 * call to acpi_ns_remove_null_elements, this is an unexpected NULL element.
965 * We will attempt to repair it.
967 if (!return_object) {
968 status = acpi_ns_repair_null_element(data, expected_btypes,
969 package_index,
970 return_object_ptr);
971 if (ACPI_SUCCESS(status)) {
972 return (AE_OK); /* Repair was successful */
974 goto type_error_exit;
977 /* A Namespace node should not get here, but make sure */
979 if (ACPI_GET_DESCRIPTOR_TYPE(return_object) == ACPI_DESC_TYPE_NAMED) {
980 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags,
981 "Invalid return type - Found a Namespace node [%4.4s] type %s",
982 return_object->node.name.ascii,
983 acpi_ut_get_type_name(return_object->node.
984 type)));
985 return (AE_AML_OPERAND_TYPE);
989 * Convert the object type (ACPI_TYPE_xxx) to a bitmapped object type.
990 * The bitmapped type allows multiple possible return types.
992 * Note, the cases below must handle all of the possible types returned
993 * from all of the predefined names (including elements of returned
994 * packages)
996 switch (return_object->common.type) {
997 case ACPI_TYPE_INTEGER:
998 return_btype = ACPI_RTYPE_INTEGER;
999 break;
1001 case ACPI_TYPE_BUFFER:
1002 return_btype = ACPI_RTYPE_BUFFER;
1003 break;
1005 case ACPI_TYPE_STRING:
1006 return_btype = ACPI_RTYPE_STRING;
1007 break;
1009 case ACPI_TYPE_PACKAGE:
1010 return_btype = ACPI_RTYPE_PACKAGE;
1011 break;
1013 case ACPI_TYPE_LOCAL_REFERENCE:
1014 return_btype = ACPI_RTYPE_REFERENCE;
1015 break;
1017 default:
1018 /* Not one of the supported objects, must be incorrect */
1020 goto type_error_exit;
1023 /* Is the object one of the expected types? */
1025 if (return_btype & expected_btypes) {
1027 /* For reference objects, check that the reference type is correct */
1029 if (return_object->common.type == ACPI_TYPE_LOCAL_REFERENCE) {
1030 status = acpi_ns_check_reference(data, return_object);
1033 return (status);
1036 /* Type mismatch -- attempt repair of the returned object */
1038 status = acpi_ns_repair_object(data, expected_btypes,
1039 package_index, return_object_ptr);
1040 if (ACPI_SUCCESS(status)) {
1041 return (AE_OK); /* Repair was successful */
1044 type_error_exit:
1046 /* Create a string with all expected types for this predefined object */
1048 acpi_ns_get_expected_types(type_buffer, expected_btypes);
1050 if (package_index == ACPI_NOT_PACKAGE_ELEMENT) {
1051 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags,
1052 "Return type mismatch - found %s, expected %s",
1053 acpi_ut_get_object_type_name
1054 (return_object), type_buffer));
1055 } else {
1056 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags,
1057 "Return Package type mismatch at index %u - "
1058 "found %s, expected %s", package_index,
1059 acpi_ut_get_object_type_name
1060 (return_object), type_buffer));
1063 return (AE_AML_OPERAND_TYPE);
1066 /*******************************************************************************
1068 * FUNCTION: acpi_ns_check_reference
1070 * PARAMETERS: Data - Pointer to validation data structure
1071 * return_object - Object returned from the evaluation of a
1072 * method or object
1074 * RETURN: Status
1076 * DESCRIPTION: Check a returned reference object for the correct reference
1077 * type. The only reference type that can be returned from a
1078 * predefined method is a named reference. All others are invalid.
1080 ******************************************************************************/
1082 static acpi_status
1083 acpi_ns_check_reference(struct acpi_predefined_data *data,
1084 union acpi_operand_object *return_object)
1088 * Check the reference object for the correct reference type (opcode).
1089 * The only type of reference that can be converted to an union acpi_object is
1090 * a reference to a named object (reference class: NAME)
1092 if (return_object->reference.class == ACPI_REFCLASS_NAME) {
1093 return (AE_OK);
1096 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags,
1097 "Return type mismatch - unexpected reference object type [%s] %2.2X",
1098 acpi_ut_get_reference_name(return_object),
1099 return_object->reference.class));
1101 return (AE_AML_OPERAND_TYPE);
1104 /*******************************************************************************
1106 * FUNCTION: acpi_ns_get_expected_types
1108 * PARAMETERS: Buffer - Pointer to where the string is returned
1109 * expected_btypes - Bitmap of expected return type(s)
1111 * RETURN: Buffer is populated with type names.
1113 * DESCRIPTION: Translate the expected types bitmap into a string of ascii
1114 * names of expected types, for use in warning messages.
1116 ******************************************************************************/
1118 static void acpi_ns_get_expected_types(char *buffer, u32 expected_btypes)
1120 u32 this_rtype;
1121 u32 i;
1122 u32 j;
1124 j = 1;
1125 buffer[0] = 0;
1126 this_rtype = ACPI_RTYPE_INTEGER;
1128 for (i = 0; i < ACPI_NUM_RTYPES; i++) {
1130 /* If one of the expected types, concatenate the name of this type */
1132 if (expected_btypes & this_rtype) {
1133 ACPI_STRCAT(buffer, &acpi_rtype_names[i][j]);
1134 j = 0; /* Use name separator from now on */
1136 this_rtype <<= 1; /* Next Rtype */