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 | 25f044e | 2013-01-25 05:38:56 +0000 | [diff] [blame] | 8 | * Copyright (C) 2000 - 2013, 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 | d5a3610 | 2013-03-08 09:23:03 +0000 | [diff] [blame] | 79 | static u32 acpi_ns_get_bitmapped_type(union acpi_operand_object *return_object); |
| 80 | |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 81 | /******************************************************************************* |
| 82 | * |
| 83 | * FUNCTION: acpi_ns_check_predefined_names |
| 84 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 85 | * PARAMETERS: node - Namespace node for the method/object |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 86 | * user_param_count - Number of parameters actually passed |
| 87 | * return_status - Status from the object evaluation |
Bob Moore | a647b5c | 2008-11-14 08:44:39 +0800 | [diff] [blame] | 88 | * return_object_ptr - Pointer to the object returned from the |
| 89 | * evaluation of a method or object |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 90 | * |
| 91 | * RETURN: Status |
| 92 | * |
| 93 | * DESCRIPTION: Check an ACPI name for a match in the predefined name list. |
| 94 | * |
| 95 | ******************************************************************************/ |
| 96 | |
| 97 | acpi_status |
| 98 | acpi_ns_check_predefined_names(struct acpi_namespace_node *node, |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 99 | u32 user_param_count, |
| 100 | acpi_status return_status, |
Bob Moore | a647b5c | 2008-11-14 08:44:39 +0800 | [diff] [blame] | 101 | union acpi_operand_object **return_object_ptr) |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 102 | { |
| 103 | acpi_status status = AE_OK; |
| 104 | const union acpi_predefined_info *predefined; |
| 105 | char *pathname; |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 106 | struct acpi_predefined_data *data; |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 107 | |
| 108 | /* Match the name for this method/object against the predefined list */ |
| 109 | |
Bob Moore | c34c82b | 2013-04-12 00:24:22 +0000 | [diff] [blame^] | 110 | predefined = acpi_ut_match_predefined_method(node->name.ascii); |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 111 | |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 112 | /* Get the full pathname to the object, for use in warning messages */ |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 113 | |
| 114 | pathname = acpi_ns_get_external_pathname(node); |
| 115 | if (!pathname) { |
Lv Zheng | 9c0d793 | 2012-12-19 05:37:21 +0000 | [diff] [blame] | 116 | return (AE_OK); /* Could not get pathname, ignore */ |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | /* |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 120 | * Check that the parameter count for this method matches the ASL |
| 121 | * definition. For predefined names, ensure that both the caller and |
| 122 | * the method itself are in accordance with the ACPI specification. |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 123 | */ |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 124 | acpi_ns_check_parameter_count(pathname, node, user_param_count, |
| 125 | predefined); |
| 126 | |
| 127 | /* If not a predefined name, we cannot validate the return object */ |
| 128 | |
| 129 | if (!predefined) { |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 130 | goto cleanup; |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | /* |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 134 | * If the method failed or did not actually return an object, we cannot |
| 135 | * validate the return object |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 136 | */ |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 137 | if ((return_status != AE_OK) && (return_status != AE_CTRL_RETURN_VALUE)) { |
| 138 | goto cleanup; |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 139 | } |
| 140 | |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 141 | /* |
Bob Moore | d57b23a | 2011-07-04 08:24:03 +0000 | [diff] [blame] | 142 | * Return value validation and possible repair. |
Bob Moore | 307a042 | 2009-09-03 09:55:40 +0800 | [diff] [blame] | 143 | * |
Bob Moore | d57b23a | 2011-07-04 08:24:03 +0000 | [diff] [blame] | 144 | * 1) Don't perform return value validation/repair if this feature |
| 145 | * has been disabled via a global option. |
| 146 | * |
| 147 | * 2) We have a return value, but if one wasn't expected, just exit, |
| 148 | * this is not a problem. For example, if the "Implicit Return" |
| 149 | * feature is enabled, methods will always return a value. |
| 150 | * |
| 151 | * 3) If the return value can be of any type, then we cannot perform |
| 152 | * any validation, just exit. |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 153 | */ |
Bob Moore | d57b23a | 2011-07-04 08:24:03 +0000 | [diff] [blame] | 154 | if (acpi_gbl_disable_auto_repair || |
| 155 | (!predefined->info.expected_btypes) || |
Bob Moore | 307a042 | 2009-09-03 09:55:40 +0800 | [diff] [blame] | 156 | (predefined->info.expected_btypes == ACPI_RTYPE_ALL)) { |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 157 | goto cleanup; |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 158 | } |
| 159 | |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 160 | /* Create the parameter data block for object validation */ |
| 161 | |
| 162 | data = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_predefined_data)); |
| 163 | if (!data) { |
| 164 | goto cleanup; |
| 165 | } |
| 166 | data->predefined = predefined; |
Fenghua Yu | 8f9c912 | 2011-07-04 08:36:16 +0000 | [diff] [blame] | 167 | data->node = node; |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 168 | data->node_flags = node->flags; |
| 169 | data->pathname = pathname; |
| 170 | |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 171 | /* |
Bob Moore | 465da9e | 2009-12-11 15:26:13 +0800 | [diff] [blame] | 172 | * Check that the type of the main return object is what is expected |
| 173 | * for this predefined name |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 174 | */ |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 175 | status = acpi_ns_check_object_type(data, return_object_ptr, |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 176 | predefined->info.expected_btypes, |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 177 | ACPI_NOT_PACKAGE_ELEMENT); |
Bob Moore | 465da9e | 2009-12-11 15:26:13 +0800 | [diff] [blame] | 178 | if (ACPI_FAILURE(status)) { |
| 179 | goto exit; |
| 180 | } |
| 181 | |
| 182 | /* |
| 183 | * For returned Package objects, check the type of all sub-objects. |
| 184 | * Note: Package may have been newly created by call above. |
| 185 | */ |
| 186 | if ((*return_object_ptr)->common.type == ACPI_TYPE_PACKAGE) { |
Bob Moore | 091f4d7 | 2010-01-21 09:28:32 +0800 | [diff] [blame] | 187 | data->parent_package = *return_object_ptr; |
Bob Moore | 465da9e | 2009-12-11 15:26:13 +0800 | [diff] [blame] | 188 | status = acpi_ns_check_package(data, return_object_ptr); |
| 189 | if (ACPI_FAILURE(status)) { |
| 190 | goto exit; |
Bob Moore | 34c39c7 | 2009-12-11 14:53:11 +0800 | [diff] [blame] | 191 | } |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 192 | } |
| 193 | |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 194 | /* |
Bob Moore | 465da9e | 2009-12-11 15:26:13 +0800 | [diff] [blame] | 195 | * The return object was OK, or it was successfully repaired above. |
| 196 | * Now make some additional checks such as verifying that package |
| 197 | * objects are sorted correctly (if required) or buffer objects have |
| 198 | * the correct data width (bytes vs. dwords). These repairs are |
| 199 | * performed on a per-name basis, i.e., the code is specific to |
| 200 | * particular predefined names. |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 201 | */ |
| 202 | status = acpi_ns_complex_repairs(data, node, status, return_object_ptr); |
| 203 | |
Bob Moore | 465da9e | 2009-12-11 15:26:13 +0800 | [diff] [blame] | 204 | exit: |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 205 | /* |
| 206 | * If the object validation failed or if we successfully repaired one |
| 207 | * or more objects, mark the parent node to suppress further warning |
| 208 | * messages during the next evaluation of the same method/object. |
| 209 | */ |
| 210 | if (ACPI_FAILURE(status) || (data->flags & ACPI_OBJECT_REPAIRED)) { |
| 211 | node->flags |= ANOBJ_EVALUATED; |
| 212 | } |
| 213 | ACPI_FREE(data); |
| 214 | |
| 215 | cleanup: |
Bob Moore | 6525909 | 2009-04-22 12:57:40 +0800 | [diff] [blame] | 216 | ACPI_FREE(pathname); |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 217 | return (status); |
| 218 | } |
| 219 | |
| 220 | /******************************************************************************* |
| 221 | * |
| 222 | * FUNCTION: acpi_ns_check_parameter_count |
| 223 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 224 | * PARAMETERS: pathname - Full pathname to the node (for error msgs) |
| 225 | * node - Namespace node for the method/object |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 226 | * user_param_count - Number of args passed in by the caller |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 227 | * predefined - Pointer to entry in predefined name table |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 228 | * |
| 229 | * RETURN: None |
| 230 | * |
| 231 | * DESCRIPTION: Check that the declared (in ASL/AML) parameter count for a |
| 232 | * predefined name is what is expected (i.e., what is defined in |
| 233 | * the ACPI specification for this predefined name.) |
| 234 | * |
| 235 | ******************************************************************************/ |
| 236 | |
| 237 | void |
| 238 | acpi_ns_check_parameter_count(char *pathname, |
| 239 | struct acpi_namespace_node *node, |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 240 | u32 user_param_count, |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 241 | const union acpi_predefined_info *predefined) |
| 242 | { |
| 243 | u32 param_count; |
| 244 | u32 required_params_current; |
| 245 | u32 required_params_old; |
| 246 | |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 247 | /* Methods have 0-7 parameters. All other types have zero. */ |
| 248 | |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 249 | param_count = 0; |
| 250 | if (node->type == ACPI_TYPE_METHOD) { |
| 251 | param_count = node->object->method.param_count; |
| 252 | } |
| 253 | |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 254 | if (!predefined) { |
| 255 | /* |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 256 | * Check the parameter count for non-predefined methods/objects. |
| 257 | * |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 258 | * Warning if too few or too many arguments have been passed by the |
| 259 | * caller. An incorrect number of arguments may not cause the method |
| 260 | * to fail. However, the method will fail if there are too few |
| 261 | * arguments and the method attempts to use one of the missing ones. |
| 262 | */ |
| 263 | if (user_param_count < param_count) { |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 264 | ACPI_WARN_PREDEFINED((AE_INFO, pathname, |
| 265 | ACPI_WARN_ALWAYS, |
| 266 | "Insufficient arguments - needs %u, found %u", |
| 267 | param_count, user_param_count)); |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 268 | } else if (user_param_count > param_count) { |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 269 | ACPI_WARN_PREDEFINED((AE_INFO, pathname, |
| 270 | ACPI_WARN_ALWAYS, |
| 271 | "Excess arguments - needs %u, found %u", |
| 272 | param_count, user_param_count)); |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 273 | } |
| 274 | return; |
| 275 | } |
| 276 | |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 277 | /* |
| 278 | * Validate the user-supplied parameter count. |
| 279 | * Allow two different legal argument counts (_SCP, etc.) |
| 280 | */ |
Bob Moore | c34c82b | 2013-04-12 00:24:22 +0000 | [diff] [blame^] | 281 | required_params_current = |
| 282 | predefined->info.argument_list & METHOD_ARG_MASK; |
| 283 | required_params_old = |
| 284 | predefined->info.argument_list >> METHOD_ARG_BIT_WIDTH; |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 285 | |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 286 | if (user_param_count != ACPI_UINT32_MAX) { |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 287 | if ((user_param_count != required_params_current) && |
| 288 | (user_param_count != required_params_old)) { |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 289 | ACPI_WARN_PREDEFINED((AE_INFO, pathname, |
| 290 | ACPI_WARN_ALWAYS, |
| 291 | "Parameter count mismatch - " |
| 292 | "caller passed %u, ACPI requires %u", |
| 293 | user_param_count, |
| 294 | required_params_current)); |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 295 | } |
| 296 | } |
| 297 | |
| 298 | /* |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 299 | * Check that the ASL-defined parameter count is what is expected for |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 300 | * this predefined name (parameter count as defined by the ACPI |
| 301 | * specification) |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 302 | */ |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 303 | if ((param_count != required_params_current) && |
| 304 | (param_count != required_params_old)) { |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 305 | ACPI_WARN_PREDEFINED((AE_INFO, pathname, node->flags, |
| 306 | "Parameter count mismatch - ASL declared %u, ACPI requires %u", |
| 307 | param_count, required_params_current)); |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 308 | } |
| 309 | } |
| 310 | |
| 311 | /******************************************************************************* |
| 312 | * |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 313 | * FUNCTION: acpi_ns_check_object_type |
| 314 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 315 | * PARAMETERS: data - Pointer to validation data structure |
Bob Moore | a647b5c | 2008-11-14 08:44:39 +0800 | [diff] [blame] | 316 | * return_object_ptr - Pointer to the object returned from the |
| 317 | * evaluation of a method or object |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 318 | * expected_btypes - Bitmap of expected return type(s) |
| 319 | * package_index - Index of object within parent package (if |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 320 | * applicable - ACPI_NOT_PACKAGE_ELEMENT |
| 321 | * otherwise) |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 322 | * |
| 323 | * RETURN: Status |
| 324 | * |
| 325 | * DESCRIPTION: Check the type of the return object against the expected object |
| 326 | * type(s). Use of Btype allows multiple expected object types. |
| 327 | * |
| 328 | ******************************************************************************/ |
| 329 | |
Bob Moore | 42f8fb7 | 2013-01-11 13:08:51 +0100 | [diff] [blame] | 330 | acpi_status |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 331 | acpi_ns_check_object_type(struct acpi_predefined_data *data, |
Bob Moore | a647b5c | 2008-11-14 08:44:39 +0800 | [diff] [blame] | 332 | union acpi_operand_object **return_object_ptr, |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 333 | u32 expected_btypes, u32 package_index) |
| 334 | { |
Bob Moore | a647b5c | 2008-11-14 08:44:39 +0800 | [diff] [blame] | 335 | union acpi_operand_object *return_object = *return_object_ptr; |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 336 | acpi_status status = AE_OK; |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 337 | char type_buffer[48]; /* Room for 5 types */ |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 338 | |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 339 | /* A Namespace node should not get here, but make sure */ |
| 340 | |
Bob Moore | d5a3610 | 2013-03-08 09:23:03 +0000 | [diff] [blame] | 341 | if (return_object && |
| 342 | ACPI_GET_DESCRIPTOR_TYPE(return_object) == ACPI_DESC_TYPE_NAMED) { |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 343 | ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags, |
| 344 | "Invalid return type - Found a Namespace node [%4.4s] type %s", |
| 345 | return_object->node.name.ascii, |
| 346 | acpi_ut_get_type_name(return_object->node. |
| 347 | type))); |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 348 | return (AE_AML_OPERAND_TYPE); |
| 349 | } |
| 350 | |
| 351 | /* |
| 352 | * Convert the object type (ACPI_TYPE_xxx) to a bitmapped object type. |
| 353 | * The bitmapped type allows multiple possible return types. |
| 354 | * |
| 355 | * Note, the cases below must handle all of the possible types returned |
| 356 | * from all of the predefined names (including elements of returned |
| 357 | * packages) |
| 358 | */ |
Bob Moore | d5a3610 | 2013-03-08 09:23:03 +0000 | [diff] [blame] | 359 | data->return_btype = acpi_ns_get_bitmapped_type(return_object); |
| 360 | if (data->return_btype == ACPI_RTYPE_ANY) { |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 361 | |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 362 | /* Not one of the supported objects, must be incorrect */ |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 363 | goto type_error_exit; |
| 364 | } |
| 365 | |
Bob Moore | d5a3610 | 2013-03-08 09:23:03 +0000 | [diff] [blame] | 366 | /* For reference objects, check that the reference type is correct */ |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 367 | |
Bob Moore | d5a3610 | 2013-03-08 09:23:03 +0000 | [diff] [blame] | 368 | if ((data->return_btype & expected_btypes) == ACPI_RTYPE_REFERENCE) { |
| 369 | status = acpi_ns_check_reference(data, return_object); |
Bob Moore | 2147d3f | 2010-01-21 09:08:31 +0800 | [diff] [blame] | 370 | return (status); |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 371 | } |
| 372 | |
Bob Moore | d5a3610 | 2013-03-08 09:23:03 +0000 | [diff] [blame] | 373 | /* Attempt simple repair of the returned object if necessary */ |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 374 | |
Bob Moore | d5a3610 | 2013-03-08 09:23:03 +0000 | [diff] [blame] | 375 | status = acpi_ns_simple_repair(data, expected_btypes, |
Bob Moore | 2147d3f | 2010-01-21 09:08:31 +0800 | [diff] [blame] | 376 | package_index, return_object_ptr); |
Bob Moore | d5a3610 | 2013-03-08 09:23:03 +0000 | [diff] [blame] | 377 | return (status); |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 378 | |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 379 | type_error_exit: |
| 380 | |
| 381 | /* Create a string with all expected types for this predefined object */ |
| 382 | |
Bob Moore | c34c82b | 2013-04-12 00:24:22 +0000 | [diff] [blame^] | 383 | acpi_ut_get_expected_return_types(type_buffer, expected_btypes); |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 384 | |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 385 | if (package_index == ACPI_NOT_PACKAGE_ELEMENT) { |
| 386 | ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags, |
| 387 | "Return type mismatch - found %s, expected %s", |
| 388 | acpi_ut_get_object_type_name |
| 389 | (return_object), type_buffer)); |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 390 | } else { |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 391 | ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags, |
| 392 | "Return Package type mismatch at index %u - " |
| 393 | "found %s, expected %s", package_index, |
| 394 | acpi_ut_get_object_type_name |
| 395 | (return_object), type_buffer)); |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | return (AE_AML_OPERAND_TYPE); |
| 399 | } |
| 400 | |
| 401 | /******************************************************************************* |
| 402 | * |
| 403 | * FUNCTION: acpi_ns_check_reference |
| 404 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 405 | * PARAMETERS: data - Pointer to validation data structure |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 406 | * return_object - Object returned from the evaluation of a |
| 407 | * method or object |
| 408 | * |
| 409 | * RETURN: Status |
| 410 | * |
| 411 | * DESCRIPTION: Check a returned reference object for the correct reference |
| 412 | * type. The only reference type that can be returned from a |
| 413 | * predefined method is a named reference. All others are invalid. |
| 414 | * |
| 415 | ******************************************************************************/ |
| 416 | |
| 417 | static acpi_status |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 418 | acpi_ns_check_reference(struct acpi_predefined_data *data, |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 419 | union acpi_operand_object *return_object) |
| 420 | { |
| 421 | |
| 422 | /* |
| 423 | * Check the reference object for the correct reference type (opcode). |
| 424 | * The only type of reference that can be converted to an union acpi_object is |
| 425 | * a reference to a named object (reference class: NAME) |
| 426 | */ |
| 427 | if (return_object->reference.class == ACPI_REFCLASS_NAME) { |
| 428 | return (AE_OK); |
| 429 | } |
| 430 | |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 431 | ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags, |
| 432 | "Return type mismatch - unexpected reference object type [%s] %2.2X", |
| 433 | acpi_ut_get_reference_name(return_object), |
| 434 | return_object->reference.class)); |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 435 | |
| 436 | return (AE_AML_OPERAND_TYPE); |
| 437 | } |
Bob Moore | a647b5c | 2008-11-14 08:44:39 +0800 | [diff] [blame] | 438 | |
| 439 | /******************************************************************************* |
| 440 | * |
Bob Moore | d5a3610 | 2013-03-08 09:23:03 +0000 | [diff] [blame] | 441 | * FUNCTION: acpi_ns_get_bitmapped_type |
| 442 | * |
| 443 | * PARAMETERS: return_object - Object returned from method/obj evaluation |
| 444 | * |
| 445 | * RETURN: Object return type. ACPI_RTYPE_ANY indicates that the object |
| 446 | * type is not supported. ACPI_RTYPE_NONE indicates that no |
| 447 | * object was returned (return_object is NULL). |
| 448 | * |
| 449 | * DESCRIPTION: Convert object type into a bitmapped object return type. |
| 450 | * |
| 451 | ******************************************************************************/ |
| 452 | |
| 453 | static u32 acpi_ns_get_bitmapped_type(union acpi_operand_object *return_object) |
| 454 | { |
| 455 | u32 return_btype; |
| 456 | |
| 457 | if (!return_object) { |
| 458 | return (ACPI_RTYPE_NONE); |
| 459 | } |
| 460 | |
| 461 | /* Map acpi_object_type to internal bitmapped type */ |
| 462 | |
| 463 | switch (return_object->common.type) { |
| 464 | case ACPI_TYPE_INTEGER: |
| 465 | return_btype = ACPI_RTYPE_INTEGER; |
| 466 | break; |
| 467 | |
| 468 | case ACPI_TYPE_BUFFER: |
| 469 | return_btype = ACPI_RTYPE_BUFFER; |
| 470 | break; |
| 471 | |
| 472 | case ACPI_TYPE_STRING: |
| 473 | return_btype = ACPI_RTYPE_STRING; |
| 474 | break; |
| 475 | |
| 476 | case ACPI_TYPE_PACKAGE: |
| 477 | return_btype = ACPI_RTYPE_PACKAGE; |
| 478 | break; |
| 479 | |
| 480 | case ACPI_TYPE_LOCAL_REFERENCE: |
| 481 | return_btype = ACPI_RTYPE_REFERENCE; |
| 482 | break; |
| 483 | |
| 484 | default: |
| 485 | /* Not one of the supported objects, must be incorrect */ |
| 486 | |
| 487 | return_btype = ACPI_RTYPE_ANY; |
| 488 | break; |
| 489 | } |
| 490 | |
| 491 | return (return_btype); |
| 492 | } |