ACPICA: Formatting update - no functional changes
[linux-2.6/linux-2.6-openrd.git] / drivers / acpi / acpica / nspredef.c
blob0d0b4ee1358e78c3f75cc3238b38a6027b07f760
1 /******************************************************************************
3 * Module Name: nspredef - Validation of ACPI predefined methods and objects
4 * $Revision: 1.1 $
6 *****************************************************************************/
8 /*
9 * Copyright (C) 2000 - 2008, 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 #include <acpi/acpi.h>
46 #include "accommon.h"
47 #include "acnamesp.h"
48 #include "acpredef.h"
50 #define _COMPONENT ACPI_NAMESPACE
51 ACPI_MODULE_NAME("nspredef")
53 /*******************************************************************************
55 * This module validates predefined ACPI objects that appear in the namespace,
56 * at the time they are evaluated (via acpi_evaluate_object). The purpose of this
57 * validation is to detect problems with BIOS-exposed predefined ACPI objects
58 * before the results are returned to the ACPI-related drivers.
60 * There are several areas that are validated:
62 * 1) The number of input arguments as defined by the method/object in the
63 * ASL is validated against the ACPI specification.
64 * 2) The type of the return object (if any) is validated against the ACPI
65 * specification.
66 * 3) For returned package objects, the count of package elements is
67 * validated, as well as the type of each package element. Nested
68 * packages are supported.
70 * For any problems found, a warning message is issued.
72 ******************************************************************************/
73 /* Local prototypes */
74 static acpi_status
75 acpi_ns_check_package(char *pathname,
76 union acpi_operand_object **return_object_ptr,
77 const union acpi_predefined_info *predefined);
79 static acpi_status
80 acpi_ns_check_package_elements(char *pathname,
81 union acpi_operand_object **elements,
82 u8 type1, u32 count1, u8 type2, u32 count2);
84 static acpi_status
85 acpi_ns_check_object_type(char *pathname,
86 union acpi_operand_object **return_object_ptr,
87 u32 expected_btypes, u32 package_index);
89 static acpi_status
90 acpi_ns_check_reference(char *pathname,
91 union acpi_operand_object *return_object);
93 static acpi_status
94 acpi_ns_repair_object(u32 expected_btypes,
95 u32 package_index,
96 union acpi_operand_object **return_object_ptr);
99 * Names for the types that can be returned by the predefined objects.
100 * Used for warning messages. Must be in the same order as the ACPI_RTYPEs
102 static const char *acpi_rtype_names[] = {
103 "/Integer",
104 "/String",
105 "/Buffer",
106 "/Package",
107 "/Reference",
110 #define ACPI_NOT_PACKAGE ACPI_UINT32_MAX
112 /*******************************************************************************
114 * FUNCTION: acpi_ns_check_predefined_names
116 * PARAMETERS: Node - Namespace node for the method/object
117 * return_object_ptr - Pointer to the object returned from the
118 * evaluation of a method or object
120 * RETURN: Status
122 * DESCRIPTION: Check an ACPI name for a match in the predefined name list.
124 ******************************************************************************/
126 acpi_status
127 acpi_ns_check_predefined_names(struct acpi_namespace_node *node,
128 u32 user_param_count,
129 acpi_status return_status,
130 union acpi_operand_object **return_object_ptr)
132 union acpi_operand_object *return_object = *return_object_ptr;
133 acpi_status status = AE_OK;
134 const union acpi_predefined_info *predefined;
135 char *pathname;
137 /* Match the name for this method/object against the predefined list */
139 predefined = acpi_ns_check_for_predefined_name(node);
141 /* Get the full pathname to the object, for use in error messages */
143 pathname = acpi_ns_get_external_pathname(node);
144 if (!pathname) {
145 pathname = ACPI_CAST_PTR(char, predefined->info.name);
149 * Check that the parameter count for this method matches the ASL
150 * definition. For predefined names, ensure that both the caller and
151 * the method itself are in accordance with the ACPI specification.
153 acpi_ns_check_parameter_count(pathname, node, user_param_count,
154 predefined);
156 /* If not a predefined name, we cannot validate the return object */
158 if (!predefined) {
159 goto exit;
162 /* If the method failed, we cannot validate the return object */
164 if ((return_status != AE_OK) && (return_status != AE_CTRL_RETURN_VALUE)) {
165 goto exit;
169 * Only validate the return value on the first successful evaluation of
170 * the method. This ensures that any warnings will only be emitted during
171 * the very first evaluation of the method/object.
173 if (node->flags & ANOBJ_EVALUATED) {
174 goto exit;
177 /* Mark the node as having been successfully evaluated */
179 node->flags |= ANOBJ_EVALUATED;
182 * If there is no return value, check if we require a return value for
183 * this predefined name. Either one return value is expected, or none,
184 * for both methods and other objects.
186 * Exit now if there is no return object. Warning if one was expected.
188 if (!return_object) {
189 if ((predefined->info.expected_btypes) &&
190 (!(predefined->info.expected_btypes & ACPI_RTYPE_NONE))) {
191 ACPI_ERROR((AE_INFO,
192 "%s: Missing expected return value",
193 pathname));
195 status = AE_AML_NO_RETURN_VALUE;
197 goto exit;
201 * We have a return value, but if one wasn't expected, just exit, this is
202 * not a problem
204 * For example, if the "Implicit Return" feature is enabled, methods will
205 * always return a value
207 if (!predefined->info.expected_btypes) {
208 goto exit;
212 * Check that the type of the return object is what is expected for
213 * this predefined name
215 status = acpi_ns_check_object_type(pathname, return_object_ptr,
216 predefined->info.expected_btypes,
217 ACPI_NOT_PACKAGE);
218 if (ACPI_FAILURE(status)) {
219 goto exit;
222 /* For returned Package objects, check the type of all sub-objects */
224 if (return_object->common.type == ACPI_TYPE_PACKAGE) {
225 status =
226 acpi_ns_check_package(pathname, return_object_ptr,
227 predefined);
230 exit:
231 if (pathname != predefined->info.name) {
232 ACPI_FREE(pathname);
235 return (status);
238 /*******************************************************************************
240 * FUNCTION: acpi_ns_check_parameter_count
242 * PARAMETERS: Pathname - Full pathname to the node (for error msgs)
243 * Node - Namespace node for the method/object
244 * user_param_count - Number of args passed in by the caller
245 * Predefined - Pointer to entry in predefined name table
247 * RETURN: None
249 * DESCRIPTION: Check that the declared (in ASL/AML) parameter count for a
250 * predefined name is what is expected (i.e., what is defined in
251 * the ACPI specification for this predefined name.)
253 ******************************************************************************/
255 void
256 acpi_ns_check_parameter_count(char *pathname,
257 struct acpi_namespace_node *node,
258 u32 user_param_count,
259 const union acpi_predefined_info *predefined)
261 u32 param_count;
262 u32 required_params_current;
263 u32 required_params_old;
265 /* Methods have 0-7 parameters. All other types have zero. */
267 param_count = 0;
268 if (node->type == ACPI_TYPE_METHOD) {
269 param_count = node->object->method.param_count;
272 /* Argument count check for non-predefined methods/objects */
274 if (!predefined) {
276 * Warning if too few or too many arguments have been passed by the
277 * caller. An incorrect number of arguments may not cause the method
278 * to fail. However, the method will fail if there are too few
279 * arguments and the method attempts to use one of the missing ones.
281 if (user_param_count < param_count) {
282 ACPI_WARNING((AE_INFO,
283 "%s: Insufficient arguments - needs %d, found %d",
284 pathname, param_count, user_param_count));
285 } else if (user_param_count > param_count) {
286 ACPI_WARNING((AE_INFO,
287 "%s: Excess arguments - needs %d, found %d",
288 pathname, param_count, user_param_count));
290 return;
293 /* Allow two different legal argument counts (_SCP, etc.) */
295 required_params_current = predefined->info.param_count & 0x0F;
296 required_params_old = predefined->info.param_count >> 4;
298 if (user_param_count != ACPI_UINT32_MAX) {
300 /* Validate the user-supplied parameter count */
302 if ((user_param_count != required_params_current) &&
303 (user_param_count != required_params_old)) {
304 ACPI_WARNING((AE_INFO,
305 "%s: Parameter count mismatch - "
306 "caller passed %d, ACPI requires %d",
307 pathname, user_param_count,
308 required_params_current));
313 * Only validate the argument count on the first successful evaluation of
314 * the method. This ensures that any warnings will only be emitted during
315 * the very first evaluation of the method/object.
317 if (node->flags & ANOBJ_EVALUATED) {
318 return;
322 * Check that the ASL-defined parameter count is what is expected for
323 * this predefined name.
325 if ((param_count != required_params_current) &&
326 (param_count != required_params_old)) {
327 ACPI_WARNING((AE_INFO,
328 "%s: Parameter count mismatch - ASL declared %d, ACPI requires %d",
329 pathname, param_count, required_params_current));
333 /*******************************************************************************
335 * FUNCTION: acpi_ns_check_for_predefined_name
337 * PARAMETERS: Node - Namespace node for the method/object
339 * RETURN: Pointer to entry in predefined table. NULL indicates not found.
341 * DESCRIPTION: Check an object name against the predefined object list.
343 ******************************************************************************/
345 const union acpi_predefined_info *acpi_ns_check_for_predefined_name(struct
346 acpi_namespace_node
347 *node)
349 const union acpi_predefined_info *this_name;
351 /* Quick check for a predefined name, first character must be underscore */
353 if (node->name.ascii[0] != '_') {
354 return (NULL);
357 /* Search info table for a predefined method/object name */
359 this_name = predefined_names;
360 while (this_name->info.name[0]) {
361 if (ACPI_COMPARE_NAME(node->name.ascii, this_name->info.name)) {
363 /* Return pointer to this table entry */
365 return (this_name);
369 * Skip next entry in the table if this name returns a Package
370 * (next entry contains the package info)
372 if (this_name->info.expected_btypes & ACPI_RTYPE_PACKAGE) {
373 this_name++;
376 this_name++;
379 return (NULL);
382 /*******************************************************************************
384 * FUNCTION: acpi_ns_check_package
386 * PARAMETERS: Pathname - Full pathname to the node (for error msgs)
387 * return_object_ptr - Pointer to the object returned from the
388 * evaluation of a method or object
389 * Predefined - Pointer to entry in predefined name table
391 * RETURN: Status
393 * DESCRIPTION: Check a returned package object for the correct count and
394 * correct type of all sub-objects.
396 ******************************************************************************/
398 static acpi_status
399 acpi_ns_check_package(char *pathname,
400 union acpi_operand_object **return_object_ptr,
401 const union acpi_predefined_info *predefined)
403 union acpi_operand_object *return_object = *return_object_ptr;
404 const union acpi_predefined_info *package;
405 union acpi_operand_object *sub_package;
406 union acpi_operand_object **elements;
407 union acpi_operand_object **sub_elements;
408 acpi_status status;
409 u32 expected_count;
410 u32 count;
411 u32 i;
412 u32 j;
414 ACPI_FUNCTION_NAME(ns_check_package);
416 /* The package info for this name is in the next table entry */
418 package = predefined + 1;
420 ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
421 "%s Validating return Package of Type %X, Count %X\n",
422 pathname, package->ret_info.type,
423 return_object->package.count));
425 /* Extract package count and elements array */
427 elements = return_object->package.elements;
428 count = return_object->package.count;
430 /* The package must have at least one element, else invalid */
432 if (!count) {
433 ACPI_WARNING((AE_INFO,
434 "%s: Return Package has no elements (empty)",
435 pathname));
437 return (AE_AML_OPERAND_VALUE);
441 * Decode the type of the expected package contents
443 * PTYPE1 packages contain no subpackages
444 * PTYPE2 packages contain sub-packages
446 switch (package->ret_info.type) {
447 case ACPI_PTYPE1_FIXED:
450 * The package count is fixed and there are no sub-packages
452 * If package is too small, exit.
453 * If package is larger than expected, issue warning but continue
455 expected_count =
456 package->ret_info.count1 + package->ret_info.count2;
457 if (count < expected_count) {
458 goto package_too_small;
459 } else if (count > expected_count) {
460 ACPI_WARNING((AE_INFO,
461 "%s: Return Package is larger than needed - "
462 "found %u, expected %u", pathname, count,
463 expected_count));
466 /* Validate all elements of the returned package */
468 status = acpi_ns_check_package_elements(pathname, elements,
469 package->ret_info.
470 object_type1,
471 package->ret_info.
472 count1,
473 package->ret_info.
474 object_type2,
475 package->ret_info.
476 count2);
477 if (ACPI_FAILURE(status)) {
478 return (status);
480 break;
482 case ACPI_PTYPE1_VAR:
485 * The package count is variable, there are no sub-packages, and all
486 * elements must be of the same type
488 for (i = 0; i < count; i++) {
489 status = acpi_ns_check_object_type(pathname, elements,
490 package->ret_info.
491 object_type1, i);
492 if (ACPI_FAILURE(status)) {
493 return (status);
495 elements++;
497 break;
499 case ACPI_PTYPE1_OPTION:
502 * The package count is variable, there are no sub-packages. There are
503 * a fixed number of required elements, and a variable number of
504 * optional elements.
506 * Check if package is at least as large as the minimum required
508 expected_count = package->ret_info3.count;
509 if (count < expected_count) {
510 goto package_too_small;
513 /* Variable number of sub-objects */
515 for (i = 0; i < count; i++) {
516 if (i < package->ret_info3.count) {
518 /* These are the required package elements (0, 1, or 2) */
520 status =
521 acpi_ns_check_object_type(pathname,
522 elements,
523 package->
524 ret_info3.
525 object_type[i],
527 if (ACPI_FAILURE(status)) {
528 return (status);
530 } else {
531 /* These are the optional package elements */
533 status =
534 acpi_ns_check_object_type(pathname,
535 elements,
536 package->
537 ret_info3.
538 tail_object_type,
540 if (ACPI_FAILURE(status)) {
541 return (status);
544 elements++;
546 break;
548 case ACPI_PTYPE2_PKG_COUNT:
550 /* First element is the (Integer) count of sub-packages to follow */
552 status = acpi_ns_check_object_type(pathname, elements,
553 ACPI_RTYPE_INTEGER, 0);
554 if (ACPI_FAILURE(status)) {
555 return (status);
559 * Count cannot be larger than the parent package length, but allow it
560 * to be smaller. The >= accounts for the Integer above.
562 expected_count = (u32) (*elements)->integer.value;
563 if (expected_count >= count) {
564 goto package_too_small;
567 count = expected_count;
568 elements++;
570 /* Now we can walk the sub-packages */
572 /*lint -fallthrough */
574 case ACPI_PTYPE2:
575 case ACPI_PTYPE2_FIXED:
576 case ACPI_PTYPE2_MIN:
577 case ACPI_PTYPE2_COUNT:
580 * These types all return a single package that consists of a variable
581 * number of sub-packages
583 for (i = 0; i < count; i++) {
584 sub_package = *elements;
585 sub_elements = sub_package->package.elements;
587 /* Each sub-object must be of type Package */
589 status =
590 acpi_ns_check_object_type(pathname, &sub_package,
591 ACPI_RTYPE_PACKAGE, i);
592 if (ACPI_FAILURE(status)) {
593 return (status);
596 /* Examine the different types of sub-packages */
598 switch (package->ret_info.type) {
599 case ACPI_PTYPE2:
600 case ACPI_PTYPE2_PKG_COUNT:
602 /* Each subpackage has a fixed number of elements */
604 expected_count =
605 package->ret_info.count1 +
606 package->ret_info.count2;
607 if (sub_package->package.count !=
608 expected_count) {
609 count = sub_package->package.count;
610 goto package_too_small;
613 status =
614 acpi_ns_check_package_elements(pathname,
615 sub_elements,
616 package->
617 ret_info.
618 object_type1,
619 package->
620 ret_info.
621 count1,
622 package->
623 ret_info.
624 object_type2,
625 package->
626 ret_info.
627 count2);
628 if (ACPI_FAILURE(status)) {
629 return (status);
631 break;
633 case ACPI_PTYPE2_FIXED:
635 /* Each sub-package has a fixed length */
637 expected_count = package->ret_info2.count;
638 if (sub_package->package.count < expected_count) {
639 count = sub_package->package.count;
640 goto package_too_small;
643 /* Check the type of each sub-package element */
645 for (j = 0; j < expected_count; j++) {
646 status =
647 acpi_ns_check_object_type(pathname,
648 &sub_elements[j],
649 package->ret_info2.object_type[j], j);
650 if (ACPI_FAILURE(status)) {
651 return (status);
654 break;
656 case ACPI_PTYPE2_MIN:
658 /* Each sub-package has a variable but minimum length */
660 expected_count = package->ret_info.count1;
661 if (sub_package->package.count < expected_count) {
662 count = sub_package->package.count;
663 goto package_too_small;
666 /* Check the type of each sub-package element */
668 status =
669 acpi_ns_check_package_elements(pathname,
670 sub_elements,
671 package->
672 ret_info.
673 object_type1,
674 sub_package->
675 package.
676 count, 0, 0);
677 if (ACPI_FAILURE(status)) {
678 return (status);
680 break;
682 case ACPI_PTYPE2_COUNT:
684 /* First element is the (Integer) count of elements to follow */
686 status =
687 acpi_ns_check_object_type(pathname,
688 sub_elements,
689 ACPI_RTYPE_INTEGER,
691 if (ACPI_FAILURE(status)) {
692 return (status);
695 /* Make sure package is large enough for the Count */
697 expected_count =
698 (u32) (*sub_elements)->integer.value;
699 if (sub_package->package.count < expected_count) {
700 count = sub_package->package.count;
701 goto package_too_small;
704 /* Check the type of each sub-package element */
706 status =
707 acpi_ns_check_package_elements(pathname,
708 (sub_elements
709 + 1),
710 package->
711 ret_info.
712 object_type1,
713 (expected_count
714 - 1), 0, 0);
715 if (ACPI_FAILURE(status)) {
716 return (status);
718 break;
720 default:
721 break;
724 elements++;
726 break;
728 default:
730 /* Should not get here if predefined info table is correct */
732 ACPI_WARNING((AE_INFO,
733 "%s: Invalid internal return type in table entry: %X",
734 pathname, package->ret_info.type));
736 return (AE_AML_INTERNAL);
739 return (AE_OK);
741 package_too_small:
743 /* Error exit for the case with an incorrect package count */
745 ACPI_WARNING((AE_INFO, "%s: Return Package is too small - "
746 "found %u, expected %u", pathname, count,
747 expected_count));
749 return (AE_AML_OPERAND_VALUE);
752 /*******************************************************************************
754 * FUNCTION: acpi_ns_check_package_elements
756 * PARAMETERS: Pathname - Full pathname to the node (for error msgs)
757 * Elements - Pointer to the package elements array
758 * Type1 - Object type for first group
759 * Count1 - Count for first group
760 * Type2 - Object type for second group
761 * Count2 - Count for second group
763 * RETURN: Status
765 * DESCRIPTION: Check that all elements of a package are of the correct object
766 * type. Supports up to two groups of different object types.
768 ******************************************************************************/
770 static acpi_status
771 acpi_ns_check_package_elements(char *pathname,
772 union acpi_operand_object **elements,
773 u8 type1, u32 count1, u8 type2, u32 count2)
775 union acpi_operand_object **this_element = elements;
776 acpi_status status;
777 u32 i;
780 * Up to two groups of package elements are supported by the data
781 * structure. All elements in each group must be of the same type.
782 * The second group can have a count of zero.
784 for (i = 0; i < count1; i++) {
785 status = acpi_ns_check_object_type(pathname, this_element,
786 type1, i);
787 if (ACPI_FAILURE(status)) {
788 return (status);
790 this_element++;
793 for (i = 0; i < count2; i++) {
794 status = acpi_ns_check_object_type(pathname, this_element,
795 type2, (i + count1));
796 if (ACPI_FAILURE(status)) {
797 return (status);
799 this_element++;
802 return (AE_OK);
805 /*******************************************************************************
807 * FUNCTION: acpi_ns_check_object_type
809 * PARAMETERS: Pathname - Full pathname to the node (for error msgs)
810 * return_object_ptr - Pointer to the object returned from the
811 * evaluation of a method or object
812 * expected_btypes - Bitmap of expected return type(s)
813 * package_index - Index of object within parent package (if
814 * applicable - ACPI_NOT_PACKAGE otherwise)
816 * RETURN: Status
818 * DESCRIPTION: Check the type of the return object against the expected object
819 * type(s). Use of Btype allows multiple expected object types.
821 ******************************************************************************/
823 static acpi_status
824 acpi_ns_check_object_type(char *pathname,
825 union acpi_operand_object **return_object_ptr,
826 u32 expected_btypes, u32 package_index)
828 union acpi_operand_object *return_object = *return_object_ptr;
829 acpi_status status = AE_OK;
830 u32 return_btype;
831 char type_buffer[48]; /* Room for 5 types */
832 u32 this_rtype;
833 u32 i;
834 u32 j;
837 * If we get a NULL return_object here, it is a NULL package element,
838 * and this is always an error.
840 if (!return_object) {
841 goto type_error_exit;
844 /* A Namespace node should not get here, but make sure */
846 if (ACPI_GET_DESCRIPTOR_TYPE(return_object) == ACPI_DESC_TYPE_NAMED) {
847 ACPI_WARNING((AE_INFO,
848 "%s: Invalid return type - Found a Namespace node [%4.4s] type %s",
849 pathname, return_object->node.name.ascii,
850 acpi_ut_get_type_name(return_object->node.type)));
851 return (AE_AML_OPERAND_TYPE);
855 * Convert the object type (ACPI_TYPE_xxx) to a bitmapped object type.
856 * The bitmapped type allows multiple possible return types.
858 * Note, the cases below must handle all of the possible types returned
859 * from all of the predefined names (including elements of returned
860 * packages)
862 switch (return_object->common.type) {
863 case ACPI_TYPE_INTEGER:
864 return_btype = ACPI_RTYPE_INTEGER;
865 break;
867 case ACPI_TYPE_BUFFER:
868 return_btype = ACPI_RTYPE_BUFFER;
869 break;
871 case ACPI_TYPE_STRING:
872 return_btype = ACPI_RTYPE_STRING;
873 break;
875 case ACPI_TYPE_PACKAGE:
876 return_btype = ACPI_RTYPE_PACKAGE;
877 break;
879 case ACPI_TYPE_LOCAL_REFERENCE:
880 return_btype = ACPI_RTYPE_REFERENCE;
881 break;
883 default:
884 /* Not one of the supported objects, must be incorrect */
886 goto type_error_exit;
889 /* Is the object one of the expected types? */
891 if (!(return_btype & expected_btypes)) {
893 /* Type mismatch -- attempt repair of the returned object */
895 status = acpi_ns_repair_object(expected_btypes, package_index,
896 return_object_ptr);
897 if (ACPI_SUCCESS(status)) {
898 return (status);
900 goto type_error_exit;
903 /* For reference objects, check that the reference type is correct */
905 if (return_object->common.type == ACPI_TYPE_LOCAL_REFERENCE) {
906 status = acpi_ns_check_reference(pathname, return_object);
909 return (status);
911 type_error_exit:
913 /* Create a string with all expected types for this predefined object */
915 j = 1;
916 type_buffer[0] = 0;
917 this_rtype = ACPI_RTYPE_INTEGER;
919 for (i = 0; i < ACPI_NUM_RTYPES; i++) {
921 /* If one of the expected types, concatenate the name of this type */
923 if (expected_btypes & this_rtype) {
924 ACPI_STRCAT(type_buffer, &acpi_rtype_names[i][j]);
925 j = 0; /* Use name separator from now on */
927 this_rtype <<= 1; /* Next Rtype */
930 if (package_index == ACPI_NOT_PACKAGE) {
931 ACPI_WARNING((AE_INFO,
932 "%s: Return type mismatch - found %s, expected %s",
933 pathname,
934 acpi_ut_get_object_type_name(return_object),
935 type_buffer));
936 } else {
937 ACPI_WARNING((AE_INFO,
938 "%s: Return Package type mismatch at index %u - "
939 "found %s, expected %s", pathname, package_index,
940 acpi_ut_get_object_type_name(return_object),
941 type_buffer));
944 return (AE_AML_OPERAND_TYPE);
947 /*******************************************************************************
949 * FUNCTION: acpi_ns_check_reference
951 * PARAMETERS: Pathname - Full pathname to the node (for error msgs)
952 * return_object - Object returned from the evaluation of a
953 * method or object
955 * RETURN: Status
957 * DESCRIPTION: Check a returned reference object for the correct reference
958 * type. The only reference type that can be returned from a
959 * predefined method is a named reference. All others are invalid.
961 ******************************************************************************/
963 static acpi_status
964 acpi_ns_check_reference(char *pathname,
965 union acpi_operand_object *return_object)
969 * Check the reference object for the correct reference type (opcode).
970 * The only type of reference that can be converted to an union acpi_object is
971 * a reference to a named object (reference class: NAME)
973 if (return_object->reference.class == ACPI_REFCLASS_NAME) {
974 return (AE_OK);
977 ACPI_WARNING((AE_INFO,
978 "%s: Return type mismatch - "
979 "unexpected reference object type [%s] %2.2X",
980 pathname, acpi_ut_get_reference_name(return_object),
981 return_object->reference.class));
983 return (AE_AML_OPERAND_TYPE);
986 /*******************************************************************************
988 * FUNCTION: acpi_ns_repair_object
990 * PARAMETERS: Pathname - Full pathname to the node (for error msgs)
991 * package_index - Used to determine if target is in a package
992 * return_object_ptr - Pointer to the object returned from the
993 * evaluation of a method or object
995 * RETURN: Status. AE_OK if repair was successful.
997 * DESCRIPTION: Attempt to repair/convert a return object of a type that was
998 * not expected.
1000 ******************************************************************************/
1002 static acpi_status
1003 acpi_ns_repair_object(u32 expected_btypes,
1004 u32 package_index,
1005 union acpi_operand_object **return_object_ptr)
1007 union acpi_operand_object *return_object = *return_object_ptr;
1008 union acpi_operand_object *new_object;
1009 acpi_size length;
1011 switch (return_object->common.type) {
1012 case ACPI_TYPE_BUFFER:
1014 if (!(expected_btypes & ACPI_RTYPE_STRING)) {
1015 return (AE_AML_OPERAND_TYPE);
1019 * Have a Buffer, expected a String, convert. Use a to_string
1020 * conversion, no transform performed on the buffer data. The best
1021 * example of this is the _BIF method, where the string data from
1022 * the battery is often (incorrectly) returned as buffer object(s).
1024 length = 0;
1025 while ((length < return_object->buffer.length) &&
1026 (return_object->buffer.pointer[length])) {
1027 length++;
1030 /* Allocate a new string object */
1032 new_object = acpi_ut_create_string_object(length);
1033 if (!new_object) {
1034 return (AE_NO_MEMORY);
1038 * Copy the raw buffer data with no transform. String is already NULL
1039 * terminated at Length+1.
1041 ACPI_MEMCPY(new_object->string.pointer,
1042 return_object->buffer.pointer, length);
1044 /* Install the new return object */
1046 acpi_ut_remove_reference(return_object);
1047 *return_object_ptr = new_object;
1050 * If the object is a package element, we need to:
1051 * 1. Decrement the reference count of the orignal object, it was
1052 * incremented when building the package
1053 * 2. Increment the reference count of the new object, it will be
1054 * decremented when releasing the package
1056 if (package_index != ACPI_NOT_PACKAGE) {
1057 acpi_ut_remove_reference(return_object);
1058 acpi_ut_add_reference(new_object);
1060 return (AE_OK);
1062 default:
1063 break;
1066 return (AE_AML_OPERAND_TYPE);