![]() |
|
|||
0001 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 0002 /****************************************************************************** 0003 * 0004 * Module Name: nspredef - Validation of ACPI predefined methods and objects 0005 * 0006 * Copyright (C) 2000 - 2022, Intel Corp. 0007 * 0008 *****************************************************************************/ 0009 0010 #define ACPI_CREATE_PREDEFINED_TABLE 0011 0012 #include <acpi/acpi.h> 0013 #include "accommon.h" 0014 #include "acnamesp.h" 0015 #include "acpredef.h" 0016 0017 #define _COMPONENT ACPI_NAMESPACE 0018 ACPI_MODULE_NAME("nspredef") 0019 0020 /******************************************************************************* 0021 * 0022 * This module validates predefined ACPI objects that appear in the namespace, 0023 * at the time they are evaluated (via acpi_evaluate_object). The purpose of this 0024 * validation is to detect problems with BIOS-exposed predefined ACPI objects 0025 * before the results are returned to the ACPI-related drivers. 0026 * 0027 * There are several areas that are validated: 0028 * 0029 * 1) The number of input arguments as defined by the method/object in the 0030 * ASL is validated against the ACPI specification. 0031 * 2) The type of the return object (if any) is validated against the ACPI 0032 * specification. 0033 * 3) For returned package objects, the count of package elements is 0034 * validated, as well as the type of each package element. Nested 0035 * packages are supported. 0036 * 0037 * For any problems found, a warning message is issued. 0038 * 0039 ******************************************************************************/ 0040 /* Local prototypes */ 0041 static acpi_status 0042 acpi_ns_check_reference(struct acpi_evaluate_info *info, 0043 union acpi_operand_object *return_object); 0044 0045 static u32 acpi_ns_get_bitmapped_type(union acpi_operand_object *return_object); 0046 0047 /******************************************************************************* 0048 * 0049 * FUNCTION: acpi_ns_check_return_value 0050 * 0051 * PARAMETERS: node - Namespace node for the method/object 0052 * info - Method execution information block 0053 * user_param_count - Number of parameters actually passed 0054 * return_status - Status from the object evaluation 0055 * return_object_ptr - Pointer to the object returned from the 0056 * evaluation of a method or object 0057 * 0058 * RETURN: Status 0059 * 0060 * DESCRIPTION: Check the value returned from a predefined name. 0061 * 0062 ******************************************************************************/ 0063 0064 acpi_status 0065 acpi_ns_check_return_value(struct acpi_namespace_node *node, 0066 struct acpi_evaluate_info *info, 0067 u32 user_param_count, 0068 acpi_status return_status, 0069 union acpi_operand_object **return_object_ptr) 0070 { 0071 acpi_status status; 0072 const union acpi_predefined_info *predefined; 0073 0074 ACPI_FUNCTION_TRACE(ns_check_return_value); 0075 0076 /* If not a predefined name, we cannot validate the return object */ 0077 0078 predefined = info->predefined; 0079 if (!predefined) { 0080 return_ACPI_STATUS(AE_OK); 0081 } 0082 0083 /* 0084 * If the method failed or did not actually return an object, we cannot 0085 * validate the return object 0086 */ 0087 if ((return_status != AE_OK) && (return_status != AE_CTRL_RETURN_VALUE)) { 0088 return_ACPI_STATUS(AE_OK); 0089 } 0090 0091 /* 0092 * Return value validation and possible repair. 0093 * 0094 * 1) Don't perform return value validation/repair if this feature 0095 * has been disabled via a global option. 0096 * 0097 * 2) We have a return value, but if one wasn't expected, just exit, 0098 * this is not a problem. For example, if the "Implicit Return" 0099 * feature is enabled, methods will always return a value. 0100 * 0101 * 3) If the return value can be of any type, then we cannot perform 0102 * any validation, just exit. 0103 */ 0104 if (acpi_gbl_disable_auto_repair || 0105 (!predefined->info.expected_btypes) || 0106 (predefined->info.expected_btypes == ACPI_RTYPE_ALL)) { 0107 return_ACPI_STATUS(AE_OK); 0108 } 0109 0110 /* 0111 * Check that the type of the main return object is what is expected 0112 * for this predefined name 0113 */ 0114 status = acpi_ns_check_object_type(info, return_object_ptr, 0115 predefined->info.expected_btypes, 0116 ACPI_NOT_PACKAGE_ELEMENT); 0117 if (ACPI_FAILURE(status)) { 0118 goto exit; 0119 } 0120 0121 /* 0122 * 0123 * 4) If there is no return value and it is optional, just return 0124 * AE_OK (_WAK). 0125 */ 0126 if (!(*return_object_ptr)) { 0127 goto exit; 0128 } 0129 0130 /* 0131 * For returned Package objects, check the type of all sub-objects. 0132 * Note: Package may have been newly created by call above. 0133 */ 0134 if ((*return_object_ptr)->common.type == ACPI_TYPE_PACKAGE) { 0135 info->parent_package = *return_object_ptr; 0136 status = acpi_ns_check_package(info, return_object_ptr); 0137 if (ACPI_FAILURE(status)) { 0138 0139 /* We might be able to fix some errors */ 0140 0141 if ((status != AE_AML_OPERAND_TYPE) && 0142 (status != AE_AML_OPERAND_VALUE)) { 0143 goto exit; 0144 } 0145 } 0146 } 0147 0148 /* 0149 * The return object was OK, or it was successfully repaired above. 0150 * Now make some additional checks such as verifying that package 0151 * objects are sorted correctly (if required) or buffer objects have 0152 * the correct data width (bytes vs. dwords). These repairs are 0153 * performed on a per-name basis, i.e., the code is specific to 0154 * particular predefined names. 0155 */ 0156 status = acpi_ns_complex_repairs(info, node, status, return_object_ptr); 0157 0158 exit: 0159 /* 0160 * If the object validation failed or if we successfully repaired one 0161 * or more objects, mark the parent node to suppress further warning 0162 * messages during the next evaluation of the same method/object. 0163 */ 0164 if (ACPI_FAILURE(status) || (info->return_flags & ACPI_OBJECT_REPAIRED)) { 0165 node->flags |= ANOBJ_EVALUATED; 0166 } 0167 0168 return_ACPI_STATUS(status); 0169 } 0170 0171 /******************************************************************************* 0172 * 0173 * FUNCTION: acpi_ns_check_object_type 0174 * 0175 * PARAMETERS: info - Method execution information block 0176 * return_object_ptr - Pointer to the object returned from the 0177 * evaluation of a method or object 0178 * expected_btypes - Bitmap of expected return type(s) 0179 * package_index - Index of object within parent package (if 0180 * applicable - ACPI_NOT_PACKAGE_ELEMENT 0181 * otherwise) 0182 * 0183 * RETURN: Status 0184 * 0185 * DESCRIPTION: Check the type of the return object against the expected object 0186 * type(s). Use of Btype allows multiple expected object types. 0187 * 0188 ******************************************************************************/ 0189 0190 acpi_status 0191 acpi_ns_check_object_type(struct acpi_evaluate_info *info, 0192 union acpi_operand_object **return_object_ptr, 0193 u32 expected_btypes, u32 package_index) 0194 { 0195 union acpi_operand_object *return_object = *return_object_ptr; 0196 acpi_status status = AE_OK; 0197 char type_buffer[96]; /* Room for 10 types */ 0198 0199 /* A Namespace node should not get here, but make sure */ 0200 0201 if (return_object && 0202 ACPI_GET_DESCRIPTOR_TYPE(return_object) == ACPI_DESC_TYPE_NAMED) { 0203 ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname, 0204 info->node_flags, 0205 "Invalid return type - Found a Namespace node [%4.4s] type %s", 0206 return_object->node.name.ascii, 0207 acpi_ut_get_type_name(return_object->node. 0208 type))); 0209 return (AE_AML_OPERAND_TYPE); 0210 } 0211 0212 /* 0213 * Convert the object type (ACPI_TYPE_xxx) to a bitmapped object type. 0214 * The bitmapped type allows multiple possible return types. 0215 * 0216 * Note, the cases below must handle all of the possible types returned 0217 * from all of the predefined names (including elements of returned 0218 * packages) 0219 */ 0220 info->return_btype = acpi_ns_get_bitmapped_type(return_object); 0221 if (info->return_btype == ACPI_RTYPE_ANY) { 0222 0223 /* Not one of the supported objects, must be incorrect */ 0224 goto type_error_exit; 0225 } 0226 0227 /* For reference objects, check that the reference type is correct */ 0228 0229 if ((info->return_btype & expected_btypes) == ACPI_RTYPE_REFERENCE) { 0230 status = acpi_ns_check_reference(info, return_object); 0231 return (status); 0232 } 0233 0234 /* Attempt simple repair of the returned object if necessary */ 0235 0236 status = acpi_ns_simple_repair(info, expected_btypes, 0237 package_index, return_object_ptr); 0238 if (ACPI_SUCCESS(status)) { 0239 return (AE_OK); /* Successful repair */ 0240 } 0241 0242 type_error_exit: 0243 0244 /* Create a string with all expected types for this predefined object */ 0245 0246 acpi_ut_get_expected_return_types(type_buffer, expected_btypes); 0247 0248 if (!return_object) { 0249 ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname, 0250 info->node_flags, 0251 "Expected return object of type %s", 0252 type_buffer)); 0253 } else if (package_index == ACPI_NOT_PACKAGE_ELEMENT) { 0254 ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname, 0255 info->node_flags, 0256 "Return type mismatch - found %s, expected %s", 0257 acpi_ut_get_object_type_name 0258 (return_object), type_buffer)); 0259 } else { 0260 ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname, 0261 info->node_flags, 0262 "Return Package type mismatch at index %u - " 0263 "found %s, expected %s", package_index, 0264 acpi_ut_get_object_type_name 0265 (return_object), type_buffer)); 0266 } 0267 0268 return (AE_AML_OPERAND_TYPE); 0269 } 0270 0271 /******************************************************************************* 0272 * 0273 * FUNCTION: acpi_ns_check_reference 0274 * 0275 * PARAMETERS: info - Method execution information block 0276 * return_object - Object returned from the evaluation of a 0277 * method or object 0278 * 0279 * RETURN: Status 0280 * 0281 * DESCRIPTION: Check a returned reference object for the correct reference 0282 * type. The only reference type that can be returned from a 0283 * predefined method is a named reference. All others are invalid. 0284 * 0285 ******************************************************************************/ 0286 0287 static acpi_status 0288 acpi_ns_check_reference(struct acpi_evaluate_info *info, 0289 union acpi_operand_object *return_object) 0290 { 0291 0292 /* 0293 * Check the reference object for the correct reference type (opcode). 0294 * The only type of reference that can be converted to a union acpi_object is 0295 * a reference to a named object (reference class: NAME) 0296 */ 0297 if (return_object->reference.class == ACPI_REFCLASS_NAME) { 0298 return (AE_OK); 0299 } 0300 0301 ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname, info->node_flags, 0302 "Return type mismatch - unexpected reference object type [%s] %2.2X", 0303 acpi_ut_get_reference_name(return_object), 0304 return_object->reference.class)); 0305 0306 return (AE_AML_OPERAND_TYPE); 0307 } 0308 0309 /******************************************************************************* 0310 * 0311 * FUNCTION: acpi_ns_get_bitmapped_type 0312 * 0313 * PARAMETERS: return_object - Object returned from method/obj evaluation 0314 * 0315 * RETURN: Object return type. ACPI_RTYPE_ANY indicates that the object 0316 * type is not supported. ACPI_RTYPE_NONE indicates that no 0317 * object was returned (return_object is NULL). 0318 * 0319 * DESCRIPTION: Convert object type into a bitmapped object return type. 0320 * 0321 ******************************************************************************/ 0322 0323 static u32 acpi_ns_get_bitmapped_type(union acpi_operand_object *return_object) 0324 { 0325 u32 return_btype; 0326 0327 if (!return_object) { 0328 return (ACPI_RTYPE_NONE); 0329 } 0330 0331 /* Map acpi_object_type to internal bitmapped type */ 0332 0333 switch (return_object->common.type) { 0334 case ACPI_TYPE_INTEGER: 0335 0336 return_btype = ACPI_RTYPE_INTEGER; 0337 break; 0338 0339 case ACPI_TYPE_BUFFER: 0340 0341 return_btype = ACPI_RTYPE_BUFFER; 0342 break; 0343 0344 case ACPI_TYPE_STRING: 0345 0346 return_btype = ACPI_RTYPE_STRING; 0347 break; 0348 0349 case ACPI_TYPE_PACKAGE: 0350 0351 return_btype = ACPI_RTYPE_PACKAGE; 0352 break; 0353 0354 case ACPI_TYPE_LOCAL_REFERENCE: 0355 0356 return_btype = ACPI_RTYPE_REFERENCE; 0357 break; 0358 0359 default: 0360 0361 /* Not one of the supported objects, must be incorrect */ 0362 0363 return_btype = ACPI_RTYPE_ANY; 0364 break; 0365 } 0366 0367 return (return_btype); 0368 }
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |