1 /******************************************************************************
3 * Module Name: nspredef - Validation of ACPI predefined methods and objects
6 *****************************************************************************/
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
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.
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 <acpi/acnamesp.h>
47 #include <acpi/acpredef.h>
49 #define _COMPONENT ACPI_NAMESPACE
50 ACPI_MODULE_NAME("nspredef")
52 /*******************************************************************************
54 * This module validates predefined ACPI objects that appear in the namespace,
55 * at the time they are evaluated (via acpi_evaluate_object). The purpose of this
56 * validation is to detect problems with BIOS-exposed predefined ACPI objects
57 * before the results are returned to the ACPI-related drivers.
59 * There are several areas that are validated:
61 * 1) The number of input arguments as defined by the method/object in the
62 * ASL is validated against the ACPI specification.
63 * 2) The type of the return object (if any) is validated against the ACPI
65 * 3) For returned package objects, the count of package elements is
66 * validated, as well as the type of each package element. Nested
67 * packages are supported.
69 * For any problems found, a warning message is issued.
71 ******************************************************************************/
72 /* Local prototypes */
74 acpi_ns_check_package(char *pathname
,
75 union acpi_operand_object
*return_object
,
76 const union acpi_predefined_info
*predefined
);
79 acpi_ns_check_package_elements(char *pathname
,
80 union acpi_operand_object
**elements
,
81 u8 type1
, u32 count1
, u8 type2
, u32 count2
);
84 acpi_ns_check_object_type(char *pathname
,
85 union acpi_operand_object
*return_object
,
86 u32 expected_btypes
, u32 package_index
);
89 acpi_ns_check_reference(char *pathname
,
90 union acpi_operand_object
*return_object
);
93 * Names for the types that can be returned by the predefined objects.
94 * Used for warning messages. Must be in the same order as the ACPI_RTYPEs
96 static const char *acpi_rtype_names
[] = {
104 #define ACPI_NOT_PACKAGE ACPI_UINT32_MAX
106 /*******************************************************************************
108 * FUNCTION: acpi_ns_check_predefined_names
110 * PARAMETERS: Node - Namespace node for the method/object
111 * return_object - Object returned from the evaluation of this
116 * DESCRIPTION: Check an ACPI name for a match in the predefined name list.
118 ******************************************************************************/
121 acpi_ns_check_predefined_names(struct acpi_namespace_node
*node
,
122 union acpi_operand_object
*return_object
)
124 acpi_status status
= AE_OK
;
125 const union acpi_predefined_info
*predefined
;
128 /* Match the name for this method/object against the predefined list */
130 predefined
= acpi_ns_check_for_predefined_name(node
);
133 /* Name was not one of the predefined names */
138 /* Get the full pathname to the object, for use in error messages */
140 pathname
= acpi_ns_get_external_pathname(node
);
142 pathname
= ACPI_CAST_PTR(char, predefined
->info
.name
);
146 * Check that the parameter count for this method is in accordance
147 * with the ACPI specification.
149 acpi_ns_check_parameter_count(pathname
, node
, predefined
);
152 * If there is no return value, check if we require a return value for
153 * this predefined name. Either one return value is expected, or none,
154 * for both methods and other objects.
156 * Exit now if there is no return object. Warning if one was expected.
158 if (!return_object
) {
159 if ((predefined
->info
.expected_btypes
) &&
160 (!(predefined
->info
.expected_btypes
& ACPI_RTYPE_NONE
))) {
162 "%s: Missing expected return value",
165 status
= AE_AML_NO_RETURN_VALUE
;
171 * We have a return value, but if one wasn't expected, just exit, this is
174 * For example, if "Implicit return value" is enabled, methods will
175 * always return a value
177 if (!predefined
->info
.expected_btypes
) {
182 * Check that the type of the return object is what is expected for
183 * this predefined name
185 status
= acpi_ns_check_object_type(pathname
, return_object
,
186 predefined
->info
.expected_btypes
,
188 if (ACPI_FAILURE(status
)) {
192 /* For returned Package objects, check the type of all sub-objects */
194 if (ACPI_GET_OBJECT_TYPE(return_object
) == ACPI_TYPE_PACKAGE
) {
196 acpi_ns_check_package(pathname
, return_object
, predefined
);
207 /*******************************************************************************
209 * FUNCTION: acpi_ns_check_parameter_count
211 * PARAMETERS: Pathname - Full pathname to the node (for error msgs)
212 * Node - Namespace node for the method/object
213 * Predefined - Pointer to entry in predefined name table
217 * DESCRIPTION: Check that the declared (in ASL/AML) parameter count for a
218 * predefined name is what is expected (i.e., what is defined in
219 * the ACPI specification for this predefined name.)
221 ******************************************************************************/
224 acpi_ns_check_parameter_count(char *pathname
,
225 struct acpi_namespace_node
*node
,
226 const union acpi_predefined_info
*predefined
)
229 u32 required_params_current
;
230 u32 required_params_old
;
233 * Check that the ASL-defined parameter count is what is expected for
234 * this predefined name.
236 * Methods have 0-7 parameters. All other types have zero.
239 if (node
->type
== ACPI_TYPE_METHOD
) {
240 param_count
= node
->object
->method
.param_count
;
243 /* Validate parameter count - allow two different legal counts (_SCP) */
245 required_params_current
= predefined
->info
.param_count
& 0x0F;
246 required_params_old
= predefined
->info
.param_count
>> 4;
248 if ((param_count
!= required_params_current
) &&
249 (param_count
!= required_params_old
)) {
250 ACPI_WARNING((AE_INFO
,
251 "%s: Parameter count mismatch - ASL declared %d, expected %d",
252 pathname
, param_count
, required_params_current
));
256 /*******************************************************************************
258 * FUNCTION: acpi_ns_check_for_predefined_name
260 * PARAMETERS: Node - Namespace node for the method/object
262 * RETURN: Pointer to entry in predefined table. NULL indicates not found.
264 * DESCRIPTION: Check an object name against the predefined object list.
266 ******************************************************************************/
268 const union acpi_predefined_info
*acpi_ns_check_for_predefined_name(struct
272 const union acpi_predefined_info
*this_name
;
274 /* Quick check for a predefined name, first character must be underscore */
276 if (node
->name
.ascii
[0] != '_') {
280 /* Search info table for a predefined method/object name */
282 this_name
= predefined_names
;
283 while (this_name
->info
.name
[0]) {
284 if (ACPI_COMPARE_NAME(node
->name
.ascii
, this_name
->info
.name
)) {
286 /* Return pointer to this table entry */
292 * Skip next entry in the table if this name returns a Package
293 * (next entry contains the package info)
295 if (this_name
->info
.expected_btypes
& ACPI_RTYPE_PACKAGE
) {
305 /*******************************************************************************
307 * FUNCTION: acpi_ns_check_package
309 * PARAMETERS: Pathname - Full pathname to the node (for error msgs)
310 * return_object - Object returned from the evaluation of a
312 * Predefined - Pointer to entry in predefined name table
316 * DESCRIPTION: Check a returned package object for the correct count and
317 * correct type of all sub-objects.
319 ******************************************************************************/
322 acpi_ns_check_package(char *pathname
,
323 union acpi_operand_object
*return_object
,
324 const union acpi_predefined_info
*predefined
)
326 const union acpi_predefined_info
*package
;
327 union acpi_operand_object
*sub_package
;
328 union acpi_operand_object
**elements
;
329 union acpi_operand_object
**sub_elements
;
336 ACPI_FUNCTION_NAME(ns_check_package
);
338 /* The package info for this name is in the next table entry */
340 package
= predefined
+ 1;
342 ACPI_DEBUG_PRINT((ACPI_DB_NAMES
,
343 "%s Validating return Package of Type %X, Count %X\n",
344 pathname
, package
->ret_info
.type
,
345 return_object
->package
.count
));
347 /* Extract package count and elements array */
349 elements
= return_object
->package
.elements
;
350 count
= return_object
->package
.count
;
352 /* The package must have at least one element, else invalid */
355 ACPI_WARNING((AE_INFO
,
356 "%s: Return Package has no elements (empty)",
359 return (AE_AML_OPERAND_VALUE
);
363 * Decode the type of the expected package contents
365 * PTYPE1 packages contain no subpackages
366 * PTYPE2 packages contain sub-packages
368 switch (package
->ret_info
.type
) {
369 case ACPI_PTYPE1_FIXED
:
372 * The package count is fixed and there are no sub-packages
374 * If package is too small, exit.
375 * If package is larger than expected, issue warning but continue
378 package
->ret_info
.count1
+ package
->ret_info
.count2
;
379 if (count
< expected_count
) {
380 goto package_too_small
;
381 } else if (count
> expected_count
) {
382 ACPI_WARNING((AE_INFO
,
383 "%s: Return Package is larger than needed - "
384 "found %u, expected %u", pathname
, count
,
388 /* Validate all elements of the returned package */
390 status
= acpi_ns_check_package_elements(pathname
, elements
,
399 if (ACPI_FAILURE(status
)) {
404 case ACPI_PTYPE1_VAR
:
407 * The package count is variable, there are no sub-packages, and all
408 * elements must be of the same type
410 for (i
= 0; i
< count
; i
++) {
411 status
= acpi_ns_check_object_type(pathname
, *elements
,
414 if (ACPI_FAILURE(status
)) {
421 case ACPI_PTYPE1_OPTION
:
424 * The package count is variable, there are no sub-packages. There are
425 * a fixed number of required elements, and a variable number of
428 * Check if package is at least as large as the minimum required
430 expected_count
= package
->ret_info3
.count
;
431 if (count
< expected_count
) {
432 goto package_too_small
;
435 /* Variable number of sub-objects */
437 for (i
= 0; i
< count
; i
++) {
438 if (i
< package
->ret_info3
.count
) {
440 /* These are the required package elements (0, 1, or 2) */
443 acpi_ns_check_object_type(pathname
,
449 if (ACPI_FAILURE(status
)) {
453 /* These are the optional package elements */
456 acpi_ns_check_object_type(pathname
,
462 if (ACPI_FAILURE(status
)) {
470 case ACPI_PTYPE2_PKG_COUNT
:
472 /* First element is the (Integer) count of sub-packages to follow */
474 status
= acpi_ns_check_object_type(pathname
, *elements
,
475 ACPI_RTYPE_INTEGER
, 0);
476 if (ACPI_FAILURE(status
)) {
481 * Count cannot be larger than the parent package length, but allow it
482 * to be smaller. The >= accounts for the Integer above.
484 expected_count
= (u32
) (*elements
)->integer
.value
;
485 if (expected_count
>= count
) {
486 goto package_too_small
;
489 count
= expected_count
;
492 /* Now we can walk the sub-packages */
494 /*lint -fallthrough */
497 case ACPI_PTYPE2_FIXED
:
498 case ACPI_PTYPE2_MIN
:
499 case ACPI_PTYPE2_COUNT
:
502 * These types all return a single package that consists of a variable
503 * number of sub-packages
505 for (i
= 0; i
< count
; i
++) {
506 sub_package
= *elements
;
507 sub_elements
= sub_package
->package
.elements
;
509 /* Each sub-object must be of type Package */
512 acpi_ns_check_object_type(pathname
, sub_package
,
513 ACPI_RTYPE_PACKAGE
, i
);
514 if (ACPI_FAILURE(status
)) {
518 /* Examine the different types of sub-packages */
520 switch (package
->ret_info
.type
) {
522 case ACPI_PTYPE2_PKG_COUNT
:
524 /* Each subpackage has a fixed number of elements */
527 package
->ret_info
.count1
+
528 package
->ret_info
.count2
;
529 if (sub_package
->package
.count
!=
531 count
= sub_package
->package
.count
;
532 goto package_too_small
;
536 acpi_ns_check_package_elements(pathname
,
550 if (ACPI_FAILURE(status
)) {
555 case ACPI_PTYPE2_FIXED
:
557 /* Each sub-package has a fixed length */
559 expected_count
= package
->ret_info2
.count
;
560 if (sub_package
->package
.count
< expected_count
) {
561 count
= sub_package
->package
.count
;
562 goto package_too_small
;
565 /* Check the type of each sub-package element */
567 for (j
= 0; j
< expected_count
; j
++) {
569 acpi_ns_check_object_type(pathname
,
576 if (ACPI_FAILURE(status
)) {
582 case ACPI_PTYPE2_MIN
:
584 /* Each sub-package has a variable but minimum length */
586 expected_count
= package
->ret_info
.count1
;
587 if (sub_package
->package
.count
< expected_count
) {
588 count
= sub_package
->package
.count
;
589 goto package_too_small
;
592 /* Check the type of each sub-package element */
595 acpi_ns_check_package_elements(pathname
,
603 if (ACPI_FAILURE(status
)) {
608 case ACPI_PTYPE2_COUNT
:
610 /* First element is the (Integer) count of elements to follow */
613 acpi_ns_check_object_type(pathname
,
617 if (ACPI_FAILURE(status
)) {
621 /* Make sure package is large enough for the Count */
624 (u32
) (*sub_elements
)->integer
.value
;
625 if (sub_package
->package
.count
< expected_count
) {
626 count
= sub_package
->package
.count
;
627 goto package_too_small
;
630 /* Check the type of each sub-package element */
633 acpi_ns_check_package_elements(pathname
,
641 if (ACPI_FAILURE(status
)) {
656 /* Should not get here if predefined info table is correct */
658 ACPI_WARNING((AE_INFO
,
659 "%s: Invalid internal return type in table entry: %X",
660 pathname
, package
->ret_info
.type
));
662 return (AE_AML_INTERNAL
);
669 /* Error exit for the case with an incorrect package count */
671 ACPI_WARNING((AE_INFO
, "%s: Return Package is too small - "
672 "found %u, expected %u", pathname
, count
,
675 return (AE_AML_OPERAND_VALUE
);
678 /*******************************************************************************
680 * FUNCTION: acpi_ns_check_package_elements
682 * PARAMETERS: Pathname - Full pathname to the node (for error msgs)
683 * Elements - Pointer to the package elements array
684 * Type1 - Object type for first group
685 * Count1 - Count for first group
686 * Type2 - Object type for second group
687 * Count2 - Count for second group
691 * DESCRIPTION: Check that all elements of a package are of the correct object
692 * type. Supports up to two groups of different object types.
694 ******************************************************************************/
697 acpi_ns_check_package_elements(char *pathname
,
698 union acpi_operand_object
**elements
,
699 u8 type1
, u32 count1
, u8 type2
, u32 count2
)
701 union acpi_operand_object
**this_element
= elements
;
706 * Up to two groups of package elements are supported by the data
707 * structure. All elements in each group must be of the same type.
708 * The second group can have a count of zero.
710 for (i
= 0; i
< count1
; i
++) {
711 status
= acpi_ns_check_object_type(pathname
, *this_element
,
713 if (ACPI_FAILURE(status
)) {
719 for (i
= 0; i
< count2
; i
++) {
720 status
= acpi_ns_check_object_type(pathname
, *this_element
,
721 type2
, (i
+ count1
));
722 if (ACPI_FAILURE(status
)) {
731 /*******************************************************************************
733 * FUNCTION: acpi_ns_check_object_type
735 * PARAMETERS: Pathname - Full pathname to the node (for error msgs)
736 * return_object - Object return from the execution of this
738 * expected_btypes - Bitmap of expected return type(s)
739 * package_index - Index of object within parent package (if
740 * applicable - ACPI_NOT_PACKAGE otherwise)
744 * DESCRIPTION: Check the type of the return object against the expected object
745 * type(s). Use of Btype allows multiple expected object types.
747 ******************************************************************************/
750 acpi_ns_check_object_type(char *pathname
,
751 union acpi_operand_object
*return_object
,
752 u32 expected_btypes
, u32 package_index
)
754 acpi_status status
= AE_OK
;
756 char type_buffer
[48]; /* Room for 5 types */
762 * If we get a NULL return_object here, it is a NULL package element,
763 * and this is always an error.
765 if (!return_object
) {
766 goto type_error_exit
;
769 /* A Namespace node should not get here, but make sure */
771 if (ACPI_GET_DESCRIPTOR_TYPE(return_object
) == ACPI_DESC_TYPE_NAMED
) {
772 ACPI_WARNING((AE_INFO
,
773 "%s: Invalid return type - Found a Namespace node [%4.4s] type %s",
774 pathname
, return_object
->node
.name
.ascii
,
775 acpi_ut_get_type_name(return_object
->node
.type
)));
776 return (AE_AML_OPERAND_TYPE
);
780 * Convert the object type (ACPI_TYPE_xxx) to a bitmapped object type.
781 * The bitmapped type allows multiple possible return types.
783 * Note, the cases below must handle all of the possible types returned
784 * from all of the predefined names (including elements of returned
787 switch (ACPI_GET_OBJECT_TYPE(return_object
)) {
788 case ACPI_TYPE_INTEGER
:
789 return_btype
= ACPI_RTYPE_INTEGER
;
792 case ACPI_TYPE_BUFFER
:
793 return_btype
= ACPI_RTYPE_BUFFER
;
796 case ACPI_TYPE_STRING
:
797 return_btype
= ACPI_RTYPE_STRING
;
800 case ACPI_TYPE_PACKAGE
:
801 return_btype
= ACPI_RTYPE_PACKAGE
;
804 case ACPI_TYPE_LOCAL_REFERENCE
:
805 return_btype
= ACPI_RTYPE_REFERENCE
;
809 /* Not one of the supported objects, must be incorrect */
811 goto type_error_exit
;
814 /* Is the object one of the expected types? */
816 if (!(return_btype
& expected_btypes
)) {
817 goto type_error_exit
;
820 /* For reference objects, check that the reference type is correct */
822 if (ACPI_GET_OBJECT_TYPE(return_object
) == ACPI_TYPE_LOCAL_REFERENCE
) {
823 status
= acpi_ns_check_reference(pathname
, return_object
);
830 /* Create a string with all expected types for this predefined object */
834 this_rtype
= ACPI_RTYPE_INTEGER
;
836 for (i
= 0; i
< ACPI_NUM_RTYPES
; i
++) {
838 /* If one of the expected types, concatenate the name of this type */
840 if (expected_btypes
& this_rtype
) {
841 ACPI_STRCAT(type_buffer
, &acpi_rtype_names
[i
][j
]);
842 j
= 0; /* Use name separator from now on */
844 this_rtype
<<= 1; /* Next Rtype */
847 if (package_index
== ACPI_NOT_PACKAGE
) {
848 ACPI_WARNING((AE_INFO
,
849 "%s: Return type mismatch - found %s, expected %s",
851 acpi_ut_get_object_type_name(return_object
),
854 ACPI_WARNING((AE_INFO
,
855 "%s: Return Package type mismatch at index %u - "
856 "found %s, expected %s", pathname
, package_index
,
857 acpi_ut_get_object_type_name(return_object
),
861 return (AE_AML_OPERAND_TYPE
);
864 /*******************************************************************************
866 * FUNCTION: acpi_ns_check_reference
868 * PARAMETERS: Pathname - Full pathname to the node (for error msgs)
869 * return_object - Object returned from the evaluation of a
874 * DESCRIPTION: Check a returned reference object for the correct reference
875 * type. The only reference type that can be returned from a
876 * predefined method is a named reference. All others are invalid.
878 ******************************************************************************/
881 acpi_ns_check_reference(char *pathname
,
882 union acpi_operand_object
*return_object
)
886 * Check the reference object for the correct reference type (opcode).
887 * The only type of reference that can be converted to an union acpi_object is
888 * a reference to a named object (reference class: NAME)
890 if (return_object
->reference
.class == ACPI_REFCLASS_NAME
) {
894 ACPI_WARNING((AE_INFO
,
895 "%s: Return type mismatch - unexpected reference object type [%s] %2.2X",
896 pathname
, acpi_ut_get_reference_name(return_object
),
897 return_object
->reference
.class));
899 return (AE_AML_OPERAND_TYPE
);