Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Module Name: nspredef - Validation of ACPI predefined methods and objects |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 4 | * |
| 5 | *****************************************************************************/ |
| 6 | |
| 7 | /* |
Bob Moore | 7784813 | 2012-01-12 13:27:23 +0800 | [diff] [blame] | 8 | * Copyright (C) 2000 - 2012, Intel Corp. |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 9 | * All rights reserved. |
| 10 | * |
| 11 | * Redistribution and use in source and binary forms, with or without |
| 12 | * modification, are permitted provided that the following conditions |
| 13 | * are met: |
| 14 | * 1. Redistributions of source code must retain the above copyright |
| 15 | * notice, this list of conditions, and the following disclaimer, |
| 16 | * without modification. |
| 17 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer |
| 18 | * substantially similar to the "NO WARRANTY" disclaimer below |
| 19 | * ("Disclaimer") and any redistribution must be conditioned upon |
| 20 | * including a substantially similar Disclaimer requirement for further |
| 21 | * binary redistribution. |
| 22 | * 3. Neither the names of the above-listed copyright holders nor the names |
| 23 | * of any contributors may be used to endorse or promote products derived |
| 24 | * from this software without specific prior written permission. |
| 25 | * |
| 26 | * Alternatively, this software may be distributed under the terms of the |
| 27 | * GNU General Public License ("GPL") version 2 as published by the Free |
| 28 | * Software Foundation. |
| 29 | * |
| 30 | * NO WARRANTY |
| 31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 32 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 33 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR |
| 34 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 35 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 36 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 37 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 38 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 39 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 40 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 41 | * POSSIBILITY OF SUCH DAMAGES. |
| 42 | */ |
| 43 | |
Bob Moore | 999e08f | 2009-08-13 14:30:16 +0800 | [diff] [blame] | 44 | #define ACPI_CREATE_PREDEFINED_TABLE |
| 45 | |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 46 | #include <acpi/acpi.h> |
Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 47 | #include "accommon.h" |
| 48 | #include "acnamesp.h" |
| 49 | #include "acpredef.h" |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 50 | |
| 51 | #define _COMPONENT ACPI_NAMESPACE |
| 52 | ACPI_MODULE_NAME("nspredef") |
| 53 | |
| 54 | /******************************************************************************* |
| 55 | * |
| 56 | * This module validates predefined ACPI objects that appear in the namespace, |
| 57 | * at the time they are evaluated (via acpi_evaluate_object). The purpose of this |
| 58 | * validation is to detect problems with BIOS-exposed predefined ACPI objects |
| 59 | * before the results are returned to the ACPI-related drivers. |
| 60 | * |
| 61 | * There are several areas that are validated: |
| 62 | * |
| 63 | * 1) The number of input arguments as defined by the method/object in the |
| 64 | * ASL is validated against the ACPI specification. |
| 65 | * 2) The type of the return object (if any) is validated against the ACPI |
| 66 | * specification. |
| 67 | * 3) For returned package objects, the count of package elements is |
| 68 | * validated, as well as the type of each package element. Nested |
| 69 | * packages are supported. |
| 70 | * |
| 71 | * For any problems found, a warning message is issued. |
| 72 | * |
| 73 | ******************************************************************************/ |
| 74 | /* Local prototypes */ |
| 75 | static acpi_status |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 76 | acpi_ns_check_reference(struct acpi_predefined_data *data, |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 77 | union acpi_operand_object *return_object); |
| 78 | |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 79 | static void acpi_ns_get_expected_types(char *buffer, u32 expected_btypes); |
| 80 | |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 81 | /* |
| 82 | * Names for the types that can be returned by the predefined objects. |
| 83 | * Used for warning messages. Must be in the same order as the ACPI_RTYPEs |
| 84 | */ |
| 85 | static const char *acpi_rtype_names[] = { |
| 86 | "/Integer", |
| 87 | "/String", |
| 88 | "/Buffer", |
| 89 | "/Package", |
| 90 | "/Reference", |
| 91 | }; |
| 92 | |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 93 | /******************************************************************************* |
| 94 | * |
| 95 | * FUNCTION: acpi_ns_check_predefined_names |
| 96 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 97 | * PARAMETERS: node - Namespace node for the method/object |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 98 | * user_param_count - Number of parameters actually passed |
| 99 | * return_status - Status from the object evaluation |
Bob Moore | a647b5c | 2008-11-14 08:44:39 +0800 | [diff] [blame] | 100 | * return_object_ptr - Pointer to the object returned from the |
| 101 | * evaluation of a method or object |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 102 | * |
| 103 | * RETURN: Status |
| 104 | * |
| 105 | * DESCRIPTION: Check an ACPI name for a match in the predefined name list. |
| 106 | * |
| 107 | ******************************************************************************/ |
| 108 | |
| 109 | acpi_status |
| 110 | acpi_ns_check_predefined_names(struct acpi_namespace_node *node, |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 111 | u32 user_param_count, |
| 112 | acpi_status return_status, |
Bob Moore | a647b5c | 2008-11-14 08:44:39 +0800 | [diff] [blame] | 113 | union acpi_operand_object **return_object_ptr) |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 114 | { |
Bob Moore | a647b5c | 2008-11-14 08:44:39 +0800 | [diff] [blame] | 115 | union acpi_operand_object *return_object = *return_object_ptr; |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 116 | acpi_status status = AE_OK; |
| 117 | const union acpi_predefined_info *predefined; |
| 118 | char *pathname; |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 119 | struct acpi_predefined_data *data; |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 120 | |
| 121 | /* Match the name for this method/object against the predefined list */ |
| 122 | |
| 123 | predefined = acpi_ns_check_for_predefined_name(node); |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 124 | |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 125 | /* Get the full pathname to the object, for use in warning messages */ |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 126 | |
| 127 | pathname = acpi_ns_get_external_pathname(node); |
| 128 | if (!pathname) { |
Lv Zheng | 9c0d793 | 2012-12-19 05:37:21 +0000 | [diff] [blame] | 129 | return (AE_OK); /* Could not get pathname, ignore */ |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | /* |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 133 | * Check that the parameter count for this method matches the ASL |
| 134 | * definition. For predefined names, ensure that both the caller and |
| 135 | * the method itself are in accordance with the ACPI specification. |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 136 | */ |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 137 | acpi_ns_check_parameter_count(pathname, node, user_param_count, |
| 138 | predefined); |
| 139 | |
| 140 | /* If not a predefined name, we cannot validate the return object */ |
| 141 | |
| 142 | if (!predefined) { |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 143 | goto cleanup; |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | /* |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 147 | * If the method failed or did not actually return an object, we cannot |
| 148 | * validate the return object |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 149 | */ |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 150 | if ((return_status != AE_OK) && (return_status != AE_CTRL_RETURN_VALUE)) { |
| 151 | goto cleanup; |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 152 | } |
| 153 | |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 154 | /* |
| 155 | * If there is no return value, check if we require a return value for |
| 156 | * this predefined name. Either one return value is expected, or none, |
| 157 | * for both methods and other objects. |
| 158 | * |
| 159 | * Exit now if there is no return object. Warning if one was expected. |
| 160 | */ |
| 161 | if (!return_object) { |
| 162 | if ((predefined->info.expected_btypes) && |
| 163 | (!(predefined->info.expected_btypes & ACPI_RTYPE_NONE))) { |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 164 | ACPI_WARN_PREDEFINED((AE_INFO, pathname, |
| 165 | ACPI_WARN_ALWAYS, |
| 166 | "Missing expected return value")); |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 167 | |
| 168 | status = AE_AML_NO_RETURN_VALUE; |
| 169 | } |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 170 | goto cleanup; |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | /* |
Bob Moore | d57b23a | 2011-07-04 08:24:03 +0000 | [diff] [blame] | 174 | * Return value validation and possible repair. |
Bob Moore | 307a042 | 2009-09-03 09:55:40 +0800 | [diff] [blame] | 175 | * |
Bob Moore | d57b23a | 2011-07-04 08:24:03 +0000 | [diff] [blame] | 176 | * 1) Don't perform return value validation/repair if this feature |
| 177 | * has been disabled via a global option. |
| 178 | * |
| 179 | * 2) We have a return value, but if one wasn't expected, just exit, |
| 180 | * this is not a problem. For example, if the "Implicit Return" |
| 181 | * feature is enabled, methods will always return a value. |
| 182 | * |
| 183 | * 3) If the return value can be of any type, then we cannot perform |
| 184 | * any validation, just exit. |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 185 | */ |
Bob Moore | d57b23a | 2011-07-04 08:24:03 +0000 | [diff] [blame] | 186 | if (acpi_gbl_disable_auto_repair || |
| 187 | (!predefined->info.expected_btypes) || |
Bob Moore | 307a042 | 2009-09-03 09:55:40 +0800 | [diff] [blame] | 188 | (predefined->info.expected_btypes == ACPI_RTYPE_ALL)) { |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 189 | goto cleanup; |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 190 | } |
| 191 | |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 192 | /* Create the parameter data block for object validation */ |
| 193 | |
| 194 | data = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_predefined_data)); |
| 195 | if (!data) { |
| 196 | goto cleanup; |
| 197 | } |
| 198 | data->predefined = predefined; |
Fenghua Yu | 8f9c912 | 2011-07-04 08:36:16 +0000 | [diff] [blame] | 199 | data->node = node; |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 200 | data->node_flags = node->flags; |
| 201 | data->pathname = pathname; |
| 202 | |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 203 | /* |
Bob Moore | 465da9e | 2009-12-11 15:26:13 +0800 | [diff] [blame] | 204 | * Check that the type of the main return object is what is expected |
| 205 | * for this predefined name |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 206 | */ |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 207 | status = acpi_ns_check_object_type(data, return_object_ptr, |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 208 | predefined->info.expected_btypes, |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 209 | ACPI_NOT_PACKAGE_ELEMENT); |
Bob Moore | 465da9e | 2009-12-11 15:26:13 +0800 | [diff] [blame] | 210 | if (ACPI_FAILURE(status)) { |
| 211 | goto exit; |
| 212 | } |
| 213 | |
| 214 | /* |
| 215 | * For returned Package objects, check the type of all sub-objects. |
| 216 | * Note: Package may have been newly created by call above. |
| 217 | */ |
| 218 | if ((*return_object_ptr)->common.type == ACPI_TYPE_PACKAGE) { |
Bob Moore | 091f4d7 | 2010-01-21 09:28:32 +0800 | [diff] [blame] | 219 | data->parent_package = *return_object_ptr; |
Bob Moore | 465da9e | 2009-12-11 15:26:13 +0800 | [diff] [blame] | 220 | status = acpi_ns_check_package(data, return_object_ptr); |
| 221 | if (ACPI_FAILURE(status)) { |
| 222 | goto exit; |
Bob Moore | 34c39c7 | 2009-12-11 14:53:11 +0800 | [diff] [blame] | 223 | } |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 224 | } |
| 225 | |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 226 | /* |
Bob Moore | 465da9e | 2009-12-11 15:26:13 +0800 | [diff] [blame] | 227 | * The return object was OK, or it was successfully repaired above. |
| 228 | * Now make some additional checks such as verifying that package |
| 229 | * objects are sorted correctly (if required) or buffer objects have |
| 230 | * the correct data width (bytes vs. dwords). These repairs are |
| 231 | * performed on a per-name basis, i.e., the code is specific to |
| 232 | * particular predefined names. |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 233 | */ |
| 234 | status = acpi_ns_complex_repairs(data, node, status, return_object_ptr); |
| 235 | |
Bob Moore | 465da9e | 2009-12-11 15:26:13 +0800 | [diff] [blame] | 236 | exit: |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 237 | /* |
| 238 | * If the object validation failed or if we successfully repaired one |
| 239 | * or more objects, mark the parent node to suppress further warning |
| 240 | * messages during the next evaluation of the same method/object. |
| 241 | */ |
| 242 | if (ACPI_FAILURE(status) || (data->flags & ACPI_OBJECT_REPAIRED)) { |
| 243 | node->flags |= ANOBJ_EVALUATED; |
| 244 | } |
| 245 | ACPI_FREE(data); |
| 246 | |
| 247 | cleanup: |
Bob Moore | 6525909 | 2009-04-22 12:57:40 +0800 | [diff] [blame] | 248 | ACPI_FREE(pathname); |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 249 | return (status); |
| 250 | } |
| 251 | |
| 252 | /******************************************************************************* |
| 253 | * |
| 254 | * FUNCTION: acpi_ns_check_parameter_count |
| 255 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 256 | * PARAMETERS: pathname - Full pathname to the node (for error msgs) |
| 257 | * node - Namespace node for the method/object |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 258 | * user_param_count - Number of args passed in by the caller |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 259 | * predefined - Pointer to entry in predefined name table |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 260 | * |
| 261 | * RETURN: None |
| 262 | * |
| 263 | * DESCRIPTION: Check that the declared (in ASL/AML) parameter count for a |
| 264 | * predefined name is what is expected (i.e., what is defined in |
| 265 | * the ACPI specification for this predefined name.) |
| 266 | * |
| 267 | ******************************************************************************/ |
| 268 | |
| 269 | void |
| 270 | acpi_ns_check_parameter_count(char *pathname, |
| 271 | struct acpi_namespace_node *node, |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 272 | u32 user_param_count, |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 273 | const union acpi_predefined_info *predefined) |
| 274 | { |
| 275 | u32 param_count; |
| 276 | u32 required_params_current; |
| 277 | u32 required_params_old; |
| 278 | |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 279 | /* Methods have 0-7 parameters. All other types have zero. */ |
| 280 | |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 281 | param_count = 0; |
| 282 | if (node->type == ACPI_TYPE_METHOD) { |
| 283 | param_count = node->object->method.param_count; |
| 284 | } |
| 285 | |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 286 | if (!predefined) { |
| 287 | /* |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 288 | * Check the parameter count for non-predefined methods/objects. |
| 289 | * |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 290 | * Warning if too few or too many arguments have been passed by the |
| 291 | * caller. An incorrect number of arguments may not cause the method |
| 292 | * to fail. However, the method will fail if there are too few |
| 293 | * arguments and the method attempts to use one of the missing ones. |
| 294 | */ |
| 295 | if (user_param_count < param_count) { |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 296 | ACPI_WARN_PREDEFINED((AE_INFO, pathname, |
| 297 | ACPI_WARN_ALWAYS, |
| 298 | "Insufficient arguments - needs %u, found %u", |
| 299 | param_count, user_param_count)); |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 300 | } else if (user_param_count > param_count) { |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 301 | ACPI_WARN_PREDEFINED((AE_INFO, pathname, |
| 302 | ACPI_WARN_ALWAYS, |
| 303 | "Excess arguments - needs %u, found %u", |
| 304 | param_count, user_param_count)); |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 305 | } |
| 306 | return; |
| 307 | } |
| 308 | |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 309 | /* |
| 310 | * Validate the user-supplied parameter count. |
| 311 | * Allow two different legal argument counts (_SCP, etc.) |
| 312 | */ |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 313 | required_params_current = predefined->info.param_count & 0x0F; |
| 314 | required_params_old = predefined->info.param_count >> 4; |
| 315 | |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 316 | if (user_param_count != ACPI_UINT32_MAX) { |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 317 | if ((user_param_count != required_params_current) && |
| 318 | (user_param_count != required_params_old)) { |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 319 | ACPI_WARN_PREDEFINED((AE_INFO, pathname, |
| 320 | ACPI_WARN_ALWAYS, |
| 321 | "Parameter count mismatch - " |
| 322 | "caller passed %u, ACPI requires %u", |
| 323 | user_param_count, |
| 324 | required_params_current)); |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 325 | } |
| 326 | } |
| 327 | |
| 328 | /* |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 329 | * Check that the ASL-defined parameter count is what is expected for |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 330 | * this predefined name (parameter count as defined by the ACPI |
| 331 | * specification) |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 332 | */ |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 333 | if ((param_count != required_params_current) && |
| 334 | (param_count != required_params_old)) { |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 335 | ACPI_WARN_PREDEFINED((AE_INFO, pathname, node->flags, |
| 336 | "Parameter count mismatch - ASL declared %u, ACPI requires %u", |
| 337 | param_count, required_params_current)); |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 338 | } |
| 339 | } |
| 340 | |
| 341 | /******************************************************************************* |
| 342 | * |
| 343 | * FUNCTION: acpi_ns_check_for_predefined_name |
| 344 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 345 | * PARAMETERS: node - Namespace node for the method/object |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 346 | * |
| 347 | * RETURN: Pointer to entry in predefined table. NULL indicates not found. |
| 348 | * |
| 349 | * DESCRIPTION: Check an object name against the predefined object list. |
| 350 | * |
| 351 | ******************************************************************************/ |
| 352 | |
| 353 | const union acpi_predefined_info *acpi_ns_check_for_predefined_name(struct |
| 354 | acpi_namespace_node |
| 355 | *node) |
| 356 | { |
| 357 | const union acpi_predefined_info *this_name; |
| 358 | |
| 359 | /* Quick check for a predefined name, first character must be underscore */ |
| 360 | |
| 361 | if (node->name.ascii[0] != '_') { |
| 362 | return (NULL); |
| 363 | } |
| 364 | |
| 365 | /* Search info table for a predefined method/object name */ |
| 366 | |
| 367 | this_name = predefined_names; |
| 368 | while (this_name->info.name[0]) { |
| 369 | if (ACPI_COMPARE_NAME(node->name.ascii, this_name->info.name)) { |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 370 | return (this_name); |
| 371 | } |
| 372 | |
| 373 | /* |
| 374 | * Skip next entry in the table if this name returns a Package |
| 375 | * (next entry contains the package info) |
| 376 | */ |
| 377 | if (this_name->info.expected_btypes & ACPI_RTYPE_PACKAGE) { |
| 378 | this_name++; |
| 379 | } |
| 380 | |
| 381 | this_name++; |
| 382 | } |
| 383 | |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 384 | return (NULL); /* Not found */ |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | /******************************************************************************* |
| 388 | * |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 389 | * FUNCTION: acpi_ns_check_object_type |
| 390 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 391 | * PARAMETERS: data - Pointer to validation data structure |
Bob Moore | a647b5c | 2008-11-14 08:44:39 +0800 | [diff] [blame] | 392 | * return_object_ptr - Pointer to the object returned from the |
| 393 | * evaluation of a method or object |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 394 | * expected_btypes - Bitmap of expected return type(s) |
| 395 | * package_index - Index of object within parent package (if |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 396 | * applicable - ACPI_NOT_PACKAGE_ELEMENT |
| 397 | * otherwise) |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 398 | * |
| 399 | * RETURN: Status |
| 400 | * |
| 401 | * DESCRIPTION: Check the type of the return object against the expected object |
| 402 | * type(s). Use of Btype allows multiple expected object types. |
| 403 | * |
| 404 | ******************************************************************************/ |
| 405 | |
Bob Moore | 42f8fb7 | 2013-01-11 13:08:51 +0100 | [diff] [blame^] | 406 | acpi_status |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 407 | acpi_ns_check_object_type(struct acpi_predefined_data *data, |
Bob Moore | a647b5c | 2008-11-14 08:44:39 +0800 | [diff] [blame] | 408 | union acpi_operand_object **return_object_ptr, |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 409 | u32 expected_btypes, u32 package_index) |
| 410 | { |
Bob Moore | a647b5c | 2008-11-14 08:44:39 +0800 | [diff] [blame] | 411 | union acpi_operand_object *return_object = *return_object_ptr; |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 412 | acpi_status status = AE_OK; |
| 413 | u32 return_btype; |
| 414 | char type_buffer[48]; /* Room for 5 types */ |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 415 | |
| 416 | /* |
Bob Moore | 091f4d7 | 2010-01-21 09:28:32 +0800 | [diff] [blame] | 417 | * If we get a NULL return_object here, it is a NULL package element. |
| 418 | * Since all extraneous NULL package elements were removed earlier by a |
| 419 | * call to acpi_ns_remove_null_elements, this is an unexpected NULL element. |
| 420 | * We will attempt to repair it. |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 421 | */ |
| 422 | if (!return_object) { |
Bob Moore | 091f4d7 | 2010-01-21 09:28:32 +0800 | [diff] [blame] | 423 | status = acpi_ns_repair_null_element(data, expected_btypes, |
| 424 | package_index, |
| 425 | return_object_ptr); |
| 426 | if (ACPI_SUCCESS(status)) { |
| 427 | return (AE_OK); /* Repair was successful */ |
| 428 | } |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 429 | goto type_error_exit; |
| 430 | } |
| 431 | |
| 432 | /* A Namespace node should not get here, but make sure */ |
| 433 | |
| 434 | if (ACPI_GET_DESCRIPTOR_TYPE(return_object) == ACPI_DESC_TYPE_NAMED) { |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 435 | ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags, |
| 436 | "Invalid return type - Found a Namespace node [%4.4s] type %s", |
| 437 | return_object->node.name.ascii, |
| 438 | acpi_ut_get_type_name(return_object->node. |
| 439 | type))); |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 440 | return (AE_AML_OPERAND_TYPE); |
| 441 | } |
| 442 | |
| 443 | /* |
| 444 | * Convert the object type (ACPI_TYPE_xxx) to a bitmapped object type. |
| 445 | * The bitmapped type allows multiple possible return types. |
| 446 | * |
| 447 | * Note, the cases below must handle all of the possible types returned |
| 448 | * from all of the predefined names (including elements of returned |
| 449 | * packages) |
| 450 | */ |
Bob Moore | 3371c19 | 2009-02-18 14:44:03 +0800 | [diff] [blame] | 451 | switch (return_object->common.type) { |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 452 | case ACPI_TYPE_INTEGER: |
| 453 | return_btype = ACPI_RTYPE_INTEGER; |
| 454 | break; |
| 455 | |
| 456 | case ACPI_TYPE_BUFFER: |
| 457 | return_btype = ACPI_RTYPE_BUFFER; |
| 458 | break; |
| 459 | |
| 460 | case ACPI_TYPE_STRING: |
| 461 | return_btype = ACPI_RTYPE_STRING; |
| 462 | break; |
| 463 | |
| 464 | case ACPI_TYPE_PACKAGE: |
| 465 | return_btype = ACPI_RTYPE_PACKAGE; |
| 466 | break; |
| 467 | |
| 468 | case ACPI_TYPE_LOCAL_REFERENCE: |
| 469 | return_btype = ACPI_RTYPE_REFERENCE; |
| 470 | break; |
| 471 | |
| 472 | default: |
| 473 | /* Not one of the supported objects, must be incorrect */ |
| 474 | |
| 475 | goto type_error_exit; |
| 476 | } |
| 477 | |
| 478 | /* Is the object one of the expected types? */ |
| 479 | |
Bob Moore | 2147d3f | 2010-01-21 09:08:31 +0800 | [diff] [blame] | 480 | if (return_btype & expected_btypes) { |
Bob Moore | a647b5c | 2008-11-14 08:44:39 +0800 | [diff] [blame] | 481 | |
Bob Moore | 2147d3f | 2010-01-21 09:08:31 +0800 | [diff] [blame] | 482 | /* For reference objects, check that the reference type is correct */ |
Bob Moore | a647b5c | 2008-11-14 08:44:39 +0800 | [diff] [blame] | 483 | |
Bob Moore | 2147d3f | 2010-01-21 09:08:31 +0800 | [diff] [blame] | 484 | if (return_object->common.type == ACPI_TYPE_LOCAL_REFERENCE) { |
| 485 | status = acpi_ns_check_reference(data, return_object); |
Bob Moore | a647b5c | 2008-11-14 08:44:39 +0800 | [diff] [blame] | 486 | } |
Bob Moore | 2147d3f | 2010-01-21 09:08:31 +0800 | [diff] [blame] | 487 | |
| 488 | return (status); |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 489 | } |
| 490 | |
Bob Moore | 2147d3f | 2010-01-21 09:08:31 +0800 | [diff] [blame] | 491 | /* Type mismatch -- attempt repair of the returned object */ |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 492 | |
Bob Moore | 2147d3f | 2010-01-21 09:08:31 +0800 | [diff] [blame] | 493 | status = acpi_ns_repair_object(data, expected_btypes, |
| 494 | package_index, return_object_ptr); |
| 495 | if (ACPI_SUCCESS(status)) { |
| 496 | return (AE_OK); /* Repair was successful */ |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 497 | } |
| 498 | |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 499 | type_error_exit: |
| 500 | |
| 501 | /* Create a string with all expected types for this predefined object */ |
| 502 | |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 503 | acpi_ns_get_expected_types(type_buffer, expected_btypes); |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 504 | |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 505 | if (package_index == ACPI_NOT_PACKAGE_ELEMENT) { |
| 506 | ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags, |
| 507 | "Return type mismatch - found %s, expected %s", |
| 508 | acpi_ut_get_object_type_name |
| 509 | (return_object), type_buffer)); |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 510 | } else { |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 511 | ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags, |
| 512 | "Return Package type mismatch at index %u - " |
| 513 | "found %s, expected %s", package_index, |
| 514 | acpi_ut_get_object_type_name |
| 515 | (return_object), type_buffer)); |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | return (AE_AML_OPERAND_TYPE); |
| 519 | } |
| 520 | |
| 521 | /******************************************************************************* |
| 522 | * |
| 523 | * FUNCTION: acpi_ns_check_reference |
| 524 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 525 | * PARAMETERS: data - Pointer to validation data structure |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 526 | * return_object - Object returned from the evaluation of a |
| 527 | * method or object |
| 528 | * |
| 529 | * RETURN: Status |
| 530 | * |
| 531 | * DESCRIPTION: Check a returned reference object for the correct reference |
| 532 | * type. The only reference type that can be returned from a |
| 533 | * predefined method is a named reference. All others are invalid. |
| 534 | * |
| 535 | ******************************************************************************/ |
| 536 | |
| 537 | static acpi_status |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 538 | acpi_ns_check_reference(struct acpi_predefined_data *data, |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 539 | union acpi_operand_object *return_object) |
| 540 | { |
| 541 | |
| 542 | /* |
| 543 | * Check the reference object for the correct reference type (opcode). |
| 544 | * The only type of reference that can be converted to an union acpi_object is |
| 545 | * a reference to a named object (reference class: NAME) |
| 546 | */ |
| 547 | if (return_object->reference.class == ACPI_REFCLASS_NAME) { |
| 548 | return (AE_OK); |
| 549 | } |
| 550 | |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 551 | ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags, |
| 552 | "Return type mismatch - unexpected reference object type [%s] %2.2X", |
| 553 | acpi_ut_get_reference_name(return_object), |
| 554 | return_object->reference.class)); |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 555 | |
| 556 | return (AE_AML_OPERAND_TYPE); |
| 557 | } |
Bob Moore | a647b5c | 2008-11-14 08:44:39 +0800 | [diff] [blame] | 558 | |
| 559 | /******************************************************************************* |
| 560 | * |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 561 | * FUNCTION: acpi_ns_get_expected_types |
| 562 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 563 | * PARAMETERS: buffer - Pointer to where the string is returned |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 564 | * expected_btypes - Bitmap of expected return type(s) |
| 565 | * |
| 566 | * RETURN: Buffer is populated with type names. |
| 567 | * |
| 568 | * DESCRIPTION: Translate the expected types bitmap into a string of ascii |
| 569 | * names of expected types, for use in warning messages. |
| 570 | * |
| 571 | ******************************************************************************/ |
| 572 | |
| 573 | static void acpi_ns_get_expected_types(char *buffer, u32 expected_btypes) |
| 574 | { |
| 575 | u32 this_rtype; |
| 576 | u32 i; |
| 577 | u32 j; |
| 578 | |
| 579 | j = 1; |
| 580 | buffer[0] = 0; |
| 581 | this_rtype = ACPI_RTYPE_INTEGER; |
| 582 | |
| 583 | for (i = 0; i < ACPI_NUM_RTYPES; i++) { |
| 584 | |
| 585 | /* If one of the expected types, concatenate the name of this type */ |
| 586 | |
| 587 | if (expected_btypes & this_rtype) { |
| 588 | ACPI_STRCAT(buffer, &acpi_rtype_names[i][j]); |
| 589 | j = 0; /* Use name separator from now on */ |
| 590 | } |
| 591 | this_rtype <<= 1; /* Next Rtype */ |
| 592 | } |
| 593 | } |