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