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 |
| 4 | * $Revision: 1.1 $ |
| 5 | * |
| 6 | *****************************************************************************/ |
| 7 | |
| 8 | /* |
| 9 | * Copyright (C) 2000 - 2008, Intel Corp. |
| 10 | * All rights reserved. |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or without |
| 13 | * modification, are permitted provided that the following conditions |
| 14 | * are met: |
| 15 | * 1. Redistributions of source code must retain the above copyright |
| 16 | * notice, this list of conditions, and the following disclaimer, |
| 17 | * without modification. |
| 18 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer |
| 19 | * substantially similar to the "NO WARRANTY" disclaimer below |
| 20 | * ("Disclaimer") and any redistribution must be conditioned upon |
| 21 | * including a substantially similar Disclaimer requirement for further |
| 22 | * binary redistribution. |
| 23 | * 3. Neither the names of the above-listed copyright holders nor the names |
| 24 | * of any contributors may be used to endorse or promote products derived |
| 25 | * from this software without specific prior written permission. |
| 26 | * |
| 27 | * Alternatively, this software may be distributed under the terms of the |
| 28 | * GNU General Public License ("GPL") version 2 as published by the Free |
| 29 | * Software Foundation. |
| 30 | * |
| 31 | * NO WARRANTY |
| 32 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 33 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 34 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR |
| 35 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 36 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 37 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 38 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 39 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 40 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 41 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 42 | * POSSIBILITY OF SUCH DAMAGES. |
| 43 | */ |
| 44 | |
| 45 | #include <acpi/acpi.h> |
Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 46 | #include "accommon.h" |
| 47 | #include "acnamesp.h" |
| 48 | #include "acpredef.h" |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 49 | |
| 50 | #define _COMPONENT ACPI_NAMESPACE |
| 51 | ACPI_MODULE_NAME("nspredef") |
| 52 | |
| 53 | /******************************************************************************* |
| 54 | * |
| 55 | * This module validates predefined ACPI objects that appear in the namespace, |
| 56 | * at the time they are evaluated (via acpi_evaluate_object). The purpose of this |
| 57 | * validation is to detect problems with BIOS-exposed predefined ACPI objects |
| 58 | * before the results are returned to the ACPI-related drivers. |
| 59 | * |
| 60 | * There are several areas that are validated: |
| 61 | * |
| 62 | * 1) The number of input arguments as defined by the method/object in the |
| 63 | * ASL is validated against the ACPI specification. |
| 64 | * 2) The type of the return object (if any) is validated against the ACPI |
| 65 | * specification. |
| 66 | * 3) For returned package objects, the count of package elements is |
| 67 | * validated, as well as the type of each package element. Nested |
| 68 | * packages are supported. |
| 69 | * |
| 70 | * For any problems found, a warning message is issued. |
| 71 | * |
| 72 | ******************************************************************************/ |
| 73 | /* Local prototypes */ |
| 74 | static acpi_status |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 75 | acpi_ns_check_package(struct acpi_predefined_data *data, |
| 76 | union acpi_operand_object **return_object_ptr); |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 77 | |
| 78 | static acpi_status |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 79 | acpi_ns_check_package_elements(struct acpi_predefined_data *data, |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 80 | union acpi_operand_object **elements, |
Bob Moore | 03ef132 | 2009-03-19 10:14:45 +0800 | [diff] [blame] | 81 | u8 type1, |
| 82 | u32 count1, |
| 83 | u8 type2, u32 count2, u32 start_index); |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 84 | |
| 85 | static acpi_status |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 86 | acpi_ns_check_object_type(struct acpi_predefined_data *data, |
Bob Moore | a647b5c | 2008-11-14 08:44:39 +0800 | [diff] [blame] | 87 | union acpi_operand_object **return_object_ptr, |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 88 | u32 expected_btypes, u32 package_index); |
| 89 | |
| 90 | static acpi_status |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 91 | acpi_ns_check_reference(struct acpi_predefined_data *data, |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 92 | union acpi_operand_object *return_object); |
| 93 | |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 94 | static void acpi_ns_get_expected_types(char *buffer, u32 expected_btypes); |
| 95 | |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 96 | /* |
| 97 | * Names for the types that can be returned by the predefined objects. |
| 98 | * Used for warning messages. Must be in the same order as the ACPI_RTYPEs |
| 99 | */ |
| 100 | static const char *acpi_rtype_names[] = { |
| 101 | "/Integer", |
| 102 | "/String", |
| 103 | "/Buffer", |
| 104 | "/Package", |
| 105 | "/Reference", |
| 106 | }; |
| 107 | |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 108 | /******************************************************************************* |
| 109 | * |
| 110 | * FUNCTION: acpi_ns_check_predefined_names |
| 111 | * |
| 112 | * PARAMETERS: Node - Namespace node for the method/object |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 113 | * user_param_count - Number of parameters actually passed |
| 114 | * return_status - Status from the object evaluation |
Bob Moore | a647b5c | 2008-11-14 08:44:39 +0800 | [diff] [blame] | 115 | * return_object_ptr - Pointer to the object returned from the |
| 116 | * evaluation of a method or object |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 117 | * |
| 118 | * RETURN: Status |
| 119 | * |
| 120 | * DESCRIPTION: Check an ACPI name for a match in the predefined name list. |
| 121 | * |
| 122 | ******************************************************************************/ |
| 123 | |
| 124 | acpi_status |
| 125 | acpi_ns_check_predefined_names(struct acpi_namespace_node *node, |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 126 | u32 user_param_count, |
| 127 | acpi_status return_status, |
Bob Moore | a647b5c | 2008-11-14 08:44:39 +0800 | [diff] [blame] | 128 | union acpi_operand_object **return_object_ptr) |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 129 | { |
Bob Moore | a647b5c | 2008-11-14 08:44:39 +0800 | [diff] [blame] | 130 | union acpi_operand_object *return_object = *return_object_ptr; |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 131 | acpi_status status = AE_OK; |
| 132 | const union acpi_predefined_info *predefined; |
| 133 | char *pathname; |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 134 | struct acpi_predefined_data *data; |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 135 | |
| 136 | /* Match the name for this method/object against the predefined list */ |
| 137 | |
| 138 | predefined = acpi_ns_check_for_predefined_name(node); |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 139 | |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 140 | /* Get the full pathname to the object, for use in warning messages */ |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 141 | |
| 142 | pathname = acpi_ns_get_external_pathname(node); |
| 143 | if (!pathname) { |
Bob Moore | 6525909 | 2009-04-22 12:57:40 +0800 | [diff] [blame] | 144 | return AE_OK; /* Could not get pathname, ignore */ |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | /* |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 148 | * Check that the parameter count for this method matches the ASL |
| 149 | * definition. For predefined names, ensure that both the caller and |
| 150 | * the method itself are in accordance with the ACPI specification. |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 151 | */ |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 152 | acpi_ns_check_parameter_count(pathname, node, user_param_count, |
| 153 | predefined); |
| 154 | |
| 155 | /* If not a predefined name, we cannot validate the return object */ |
| 156 | |
| 157 | if (!predefined) { |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 158 | goto cleanup; |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | /* |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 162 | * If the method failed or did not actually return an object, we cannot |
| 163 | * validate the return object |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 164 | */ |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 165 | if ((return_status != AE_OK) && (return_status != AE_CTRL_RETURN_VALUE)) { |
| 166 | goto cleanup; |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 167 | } |
| 168 | |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 169 | /* |
| 170 | * If there is no return value, check if we require a return value for |
| 171 | * this predefined name. Either one return value is expected, or none, |
| 172 | * for both methods and other objects. |
| 173 | * |
| 174 | * Exit now if there is no return object. Warning if one was expected. |
| 175 | */ |
| 176 | if (!return_object) { |
| 177 | if ((predefined->info.expected_btypes) && |
| 178 | (!(predefined->info.expected_btypes & ACPI_RTYPE_NONE))) { |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 179 | ACPI_WARN_PREDEFINED((AE_INFO, pathname, |
| 180 | ACPI_WARN_ALWAYS, |
| 181 | "Missing expected return value")); |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 182 | |
| 183 | status = AE_AML_NO_RETURN_VALUE; |
| 184 | } |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 185 | goto cleanup; |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | /* |
| 189 | * We have a return value, but if one wasn't expected, just exit, this is |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 190 | * not a problem. For example, if the "Implicit Return" feature is |
| 191 | * enabled, methods will always return a value. |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 192 | */ |
| 193 | if (!predefined->info.expected_btypes) { |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 194 | goto cleanup; |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 195 | } |
| 196 | |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 197 | /* Create the parameter data block for object validation */ |
| 198 | |
| 199 | data = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_predefined_data)); |
| 200 | if (!data) { |
| 201 | goto cleanup; |
| 202 | } |
| 203 | data->predefined = predefined; |
| 204 | data->node_flags = node->flags; |
| 205 | data->pathname = pathname; |
| 206 | |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 207 | /* |
| 208 | * Check that the type of the return object is what is expected for |
| 209 | * this predefined name |
| 210 | */ |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 211 | status = acpi_ns_check_object_type(data, return_object_ptr, |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 212 | predefined->info.expected_btypes, |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 213 | ACPI_NOT_PACKAGE_ELEMENT); |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 214 | if (ACPI_FAILURE(status)) { |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 215 | goto check_validation_status; |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | /* For returned Package objects, check the type of all sub-objects */ |
| 219 | |
Bob Moore | 3371c19 | 2009-02-18 14:44:03 +0800 | [diff] [blame] | 220 | if (return_object->common.type == ACPI_TYPE_PACKAGE) { |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 221 | status = acpi_ns_check_package(data, return_object_ptr); |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 222 | } |
| 223 | |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 224 | check_validation_status: |
| 225 | /* |
| 226 | * If the object validation failed or if we successfully repaired one |
| 227 | * or more objects, mark the parent node to suppress further warning |
| 228 | * messages during the next evaluation of the same method/object. |
| 229 | */ |
| 230 | if (ACPI_FAILURE(status) || (data->flags & ACPI_OBJECT_REPAIRED)) { |
| 231 | node->flags |= ANOBJ_EVALUATED; |
| 232 | } |
| 233 | ACPI_FREE(data); |
| 234 | |
| 235 | cleanup: |
Bob Moore | 6525909 | 2009-04-22 12:57:40 +0800 | [diff] [blame] | 236 | ACPI_FREE(pathname); |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 237 | return (status); |
| 238 | } |
| 239 | |
| 240 | /******************************************************************************* |
| 241 | * |
| 242 | * FUNCTION: acpi_ns_check_parameter_count |
| 243 | * |
| 244 | * PARAMETERS: Pathname - Full pathname to the node (for error msgs) |
| 245 | * Node - Namespace node for the method/object |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 246 | * user_param_count - Number of args passed in by the caller |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 247 | * Predefined - Pointer to entry in predefined name table |
| 248 | * |
| 249 | * RETURN: None |
| 250 | * |
| 251 | * DESCRIPTION: Check that the declared (in ASL/AML) parameter count for a |
| 252 | * predefined name is what is expected (i.e., what is defined in |
| 253 | * the ACPI specification for this predefined name.) |
| 254 | * |
| 255 | ******************************************************************************/ |
| 256 | |
| 257 | void |
| 258 | acpi_ns_check_parameter_count(char *pathname, |
| 259 | struct acpi_namespace_node *node, |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 260 | u32 user_param_count, |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 261 | const union acpi_predefined_info *predefined) |
| 262 | { |
| 263 | u32 param_count; |
| 264 | u32 required_params_current; |
| 265 | u32 required_params_old; |
| 266 | |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 267 | /* Methods have 0-7 parameters. All other types have zero. */ |
| 268 | |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 269 | param_count = 0; |
| 270 | if (node->type == ACPI_TYPE_METHOD) { |
| 271 | param_count = node->object->method.param_count; |
| 272 | } |
| 273 | |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 274 | if (!predefined) { |
| 275 | /* |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 276 | * Check the parameter count for non-predefined methods/objects. |
| 277 | * |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 278 | * Warning if too few or too many arguments have been passed by the |
| 279 | * caller. An incorrect number of arguments may not cause the method |
| 280 | * to fail. However, the method will fail if there are too few |
| 281 | * arguments and the method attempts to use one of the missing ones. |
| 282 | */ |
| 283 | if (user_param_count < param_count) { |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 284 | ACPI_WARN_PREDEFINED((AE_INFO, pathname, |
| 285 | ACPI_WARN_ALWAYS, |
| 286 | "Insufficient arguments - needs %u, found %u", |
| 287 | param_count, user_param_count)); |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 288 | } else if (user_param_count > param_count) { |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 289 | ACPI_WARN_PREDEFINED((AE_INFO, pathname, |
| 290 | ACPI_WARN_ALWAYS, |
| 291 | "Excess arguments - needs %u, found %u", |
| 292 | param_count, user_param_count)); |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 293 | } |
| 294 | return; |
| 295 | } |
| 296 | |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 297 | /* |
| 298 | * Validate the user-supplied parameter count. |
| 299 | * Allow two different legal argument counts (_SCP, etc.) |
| 300 | */ |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 301 | required_params_current = predefined->info.param_count & 0x0F; |
| 302 | required_params_old = predefined->info.param_count >> 4; |
| 303 | |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 304 | if (user_param_count != ACPI_UINT32_MAX) { |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 305 | if ((user_param_count != required_params_current) && |
| 306 | (user_param_count != required_params_old)) { |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 307 | ACPI_WARN_PREDEFINED((AE_INFO, pathname, |
| 308 | ACPI_WARN_ALWAYS, |
| 309 | "Parameter count mismatch - " |
| 310 | "caller passed %u, ACPI requires %u", |
| 311 | user_param_count, |
| 312 | required_params_current)); |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 313 | } |
| 314 | } |
| 315 | |
| 316 | /* |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 317 | * Check that the ASL-defined parameter count is what is expected for |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 318 | * this predefined name (parameter count as defined by the ACPI |
| 319 | * specification) |
Bob Moore | eeb4437 | 2008-11-13 11:19:24 +0800 | [diff] [blame] | 320 | */ |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 321 | if ((param_count != required_params_current) && |
| 322 | (param_count != required_params_old)) { |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 323 | ACPI_WARN_PREDEFINED((AE_INFO, pathname, node->flags, |
| 324 | "Parameter count mismatch - ASL declared %u, ACPI requires %u", |
| 325 | param_count, required_params_current)); |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 326 | } |
| 327 | } |
| 328 | |
| 329 | /******************************************************************************* |
| 330 | * |
| 331 | * FUNCTION: acpi_ns_check_for_predefined_name |
| 332 | * |
| 333 | * PARAMETERS: Node - Namespace node for the method/object |
| 334 | * |
| 335 | * RETURN: Pointer to entry in predefined table. NULL indicates not found. |
| 336 | * |
| 337 | * DESCRIPTION: Check an object name against the predefined object list. |
| 338 | * |
| 339 | ******************************************************************************/ |
| 340 | |
| 341 | const union acpi_predefined_info *acpi_ns_check_for_predefined_name(struct |
| 342 | acpi_namespace_node |
| 343 | *node) |
| 344 | { |
| 345 | const union acpi_predefined_info *this_name; |
| 346 | |
| 347 | /* Quick check for a predefined name, first character must be underscore */ |
| 348 | |
| 349 | if (node->name.ascii[0] != '_') { |
| 350 | return (NULL); |
| 351 | } |
| 352 | |
| 353 | /* Search info table for a predefined method/object name */ |
| 354 | |
| 355 | this_name = predefined_names; |
| 356 | while (this_name->info.name[0]) { |
| 357 | if (ACPI_COMPARE_NAME(node->name.ascii, this_name->info.name)) { |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 358 | return (this_name); |
| 359 | } |
| 360 | |
| 361 | /* |
| 362 | * Skip next entry in the table if this name returns a Package |
| 363 | * (next entry contains the package info) |
| 364 | */ |
| 365 | if (this_name->info.expected_btypes & ACPI_RTYPE_PACKAGE) { |
| 366 | this_name++; |
| 367 | } |
| 368 | |
| 369 | this_name++; |
| 370 | } |
| 371 | |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 372 | return (NULL); /* Not found */ |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | /******************************************************************************* |
| 376 | * |
| 377 | * FUNCTION: acpi_ns_check_package |
| 378 | * |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 379 | * PARAMETERS: Data - Pointer to validation data structure |
Bob Moore | a647b5c | 2008-11-14 08:44:39 +0800 | [diff] [blame] | 380 | * return_object_ptr - Pointer to the object returned from the |
| 381 | * evaluation of a method or object |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 382 | * |
| 383 | * RETURN: Status |
| 384 | * |
| 385 | * DESCRIPTION: Check a returned package object for the correct count and |
| 386 | * correct type of all sub-objects. |
| 387 | * |
| 388 | ******************************************************************************/ |
| 389 | |
| 390 | static acpi_status |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 391 | acpi_ns_check_package(struct acpi_predefined_data *data, |
| 392 | union acpi_operand_object **return_object_ptr) |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 393 | { |
Bob Moore | a647b5c | 2008-11-14 08:44:39 +0800 | [diff] [blame] | 394 | union acpi_operand_object *return_object = *return_object_ptr; |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 395 | const union acpi_predefined_info *package; |
| 396 | union acpi_operand_object *sub_package; |
| 397 | union acpi_operand_object **elements; |
| 398 | union acpi_operand_object **sub_elements; |
| 399 | acpi_status status; |
| 400 | u32 expected_count; |
| 401 | u32 count; |
| 402 | u32 i; |
| 403 | u32 j; |
| 404 | |
| 405 | ACPI_FUNCTION_NAME(ns_check_package); |
| 406 | |
| 407 | /* The package info for this name is in the next table entry */ |
| 408 | |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 409 | package = data->predefined + 1; |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 410 | |
| 411 | ACPI_DEBUG_PRINT((ACPI_DB_NAMES, |
| 412 | "%s Validating return Package of Type %X, Count %X\n", |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 413 | data->pathname, package->ret_info.type, |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 414 | return_object->package.count)); |
| 415 | |
| 416 | /* Extract package count and elements array */ |
| 417 | |
| 418 | elements = return_object->package.elements; |
| 419 | count = return_object->package.count; |
| 420 | |
| 421 | /* The package must have at least one element, else invalid */ |
| 422 | |
| 423 | if (!count) { |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 424 | ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags, |
| 425 | "Return Package has no elements (empty)")); |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 426 | |
| 427 | return (AE_AML_OPERAND_VALUE); |
| 428 | } |
| 429 | |
| 430 | /* |
| 431 | * Decode the type of the expected package contents |
| 432 | * |
| 433 | * PTYPE1 packages contain no subpackages |
| 434 | * PTYPE2 packages contain sub-packages |
| 435 | */ |
| 436 | switch (package->ret_info.type) { |
| 437 | case ACPI_PTYPE1_FIXED: |
| 438 | |
| 439 | /* |
| 440 | * The package count is fixed and there are no sub-packages |
| 441 | * |
| 442 | * If package is too small, exit. |
| 443 | * If package is larger than expected, issue warning but continue |
| 444 | */ |
| 445 | expected_count = |
| 446 | package->ret_info.count1 + package->ret_info.count2; |
| 447 | if (count < expected_count) { |
| 448 | goto package_too_small; |
| 449 | } else if (count > expected_count) { |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 450 | ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, |
| 451 | data->node_flags, |
| 452 | "Return Package is larger than needed - " |
| 453 | "found %u, expected %u", count, |
| 454 | expected_count)); |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | /* Validate all elements of the returned package */ |
| 458 | |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 459 | status = acpi_ns_check_package_elements(data, elements, |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 460 | package->ret_info. |
| 461 | object_type1, |
| 462 | package->ret_info. |
| 463 | count1, |
| 464 | package->ret_info. |
| 465 | object_type2, |
| 466 | package->ret_info. |
Bob Moore | 03ef132 | 2009-03-19 10:14:45 +0800 | [diff] [blame] | 467 | count2, 0); |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 468 | if (ACPI_FAILURE(status)) { |
| 469 | return (status); |
| 470 | } |
| 471 | break; |
| 472 | |
| 473 | case ACPI_PTYPE1_VAR: |
| 474 | |
| 475 | /* |
| 476 | * The package count is variable, there are no sub-packages, and all |
| 477 | * elements must be of the same type |
| 478 | */ |
| 479 | for (i = 0; i < count; i++) { |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 480 | status = acpi_ns_check_object_type(data, elements, |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 481 | package->ret_info. |
| 482 | object_type1, i); |
| 483 | if (ACPI_FAILURE(status)) { |
| 484 | return (status); |
| 485 | } |
| 486 | elements++; |
| 487 | } |
| 488 | break; |
| 489 | |
| 490 | case ACPI_PTYPE1_OPTION: |
| 491 | |
| 492 | /* |
| 493 | * The package count is variable, there are no sub-packages. There are |
| 494 | * a fixed number of required elements, and a variable number of |
| 495 | * optional elements. |
| 496 | * |
| 497 | * Check if package is at least as large as the minimum required |
| 498 | */ |
| 499 | expected_count = package->ret_info3.count; |
| 500 | if (count < expected_count) { |
| 501 | goto package_too_small; |
| 502 | } |
| 503 | |
| 504 | /* Variable number of sub-objects */ |
| 505 | |
| 506 | for (i = 0; i < count; i++) { |
| 507 | if (i < package->ret_info3.count) { |
| 508 | |
| 509 | /* These are the required package elements (0, 1, or 2) */ |
| 510 | |
| 511 | status = |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 512 | acpi_ns_check_object_type(data, elements, |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 513 | package-> |
| 514 | ret_info3. |
| 515 | object_type[i], |
| 516 | i); |
| 517 | if (ACPI_FAILURE(status)) { |
| 518 | return (status); |
| 519 | } |
| 520 | } else { |
| 521 | /* These are the optional package elements */ |
| 522 | |
| 523 | status = |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 524 | acpi_ns_check_object_type(data, elements, |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 525 | package-> |
| 526 | ret_info3. |
| 527 | tail_object_type, |
| 528 | i); |
| 529 | if (ACPI_FAILURE(status)) { |
| 530 | return (status); |
| 531 | } |
| 532 | } |
| 533 | elements++; |
| 534 | } |
| 535 | break; |
| 536 | |
| 537 | case ACPI_PTYPE2_PKG_COUNT: |
| 538 | |
| 539 | /* First element is the (Integer) count of sub-packages to follow */ |
| 540 | |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 541 | status = acpi_ns_check_object_type(data, elements, |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 542 | ACPI_RTYPE_INTEGER, 0); |
| 543 | if (ACPI_FAILURE(status)) { |
| 544 | return (status); |
| 545 | } |
| 546 | |
| 547 | /* |
| 548 | * Count cannot be larger than the parent package length, but allow it |
| 549 | * to be smaller. The >= accounts for the Integer above. |
| 550 | */ |
| 551 | expected_count = (u32) (*elements)->integer.value; |
| 552 | if (expected_count >= count) { |
| 553 | goto package_too_small; |
| 554 | } |
| 555 | |
| 556 | count = expected_count; |
| 557 | elements++; |
| 558 | |
| 559 | /* Now we can walk the sub-packages */ |
| 560 | |
| 561 | /*lint -fallthrough */ |
| 562 | |
| 563 | case ACPI_PTYPE2: |
| 564 | case ACPI_PTYPE2_FIXED: |
| 565 | case ACPI_PTYPE2_MIN: |
| 566 | case ACPI_PTYPE2_COUNT: |
| 567 | |
| 568 | /* |
Bob Moore | e5f69d6 | 2009-07-24 11:03:09 +0800 | [diff] [blame^] | 569 | * These types all return a single Package that consists of a |
| 570 | * variable number of sub-Packages. |
| 571 | * |
| 572 | * First, ensure that the first element is a sub-Package. If not, |
| 573 | * the BIOS may have incorrectly returned the object as a single |
| 574 | * package instead of a Package of Packages (a common error if |
| 575 | * there is only one entry). We may be able to repair this by |
| 576 | * wrapping the returned Package with a new outer Package. |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 577 | */ |
Bob Moore | e5f69d6 | 2009-07-24 11:03:09 +0800 | [diff] [blame^] | 578 | if ((*elements)->common.type != ACPI_TYPE_PACKAGE) { |
| 579 | |
| 580 | /* Create the new outer package and populate it */ |
| 581 | |
| 582 | status = |
| 583 | acpi_ns_repair_package_list(data, |
| 584 | return_object_ptr); |
| 585 | if (ACPI_FAILURE(status)) { |
| 586 | return (status); |
| 587 | } |
| 588 | |
| 589 | /* Update locals to point to the new package (of 1 element) */ |
| 590 | |
| 591 | return_object = *return_object_ptr; |
| 592 | elements = return_object->package.elements; |
| 593 | count = 1; |
| 594 | } |
| 595 | |
| 596 | /* Validate each sub-Package in the parent Package */ |
| 597 | |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 598 | for (i = 0; i < count; i++) { |
| 599 | sub_package = *elements; |
| 600 | sub_elements = sub_package->package.elements; |
| 601 | |
| 602 | /* Each sub-object must be of type Package */ |
| 603 | |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 604 | status = acpi_ns_check_object_type(data, &sub_package, |
| 605 | ACPI_RTYPE_PACKAGE, |
| 606 | i); |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 607 | if (ACPI_FAILURE(status)) { |
| 608 | return (status); |
| 609 | } |
| 610 | |
| 611 | /* Examine the different types of sub-packages */ |
| 612 | |
| 613 | switch (package->ret_info.type) { |
| 614 | case ACPI_PTYPE2: |
| 615 | case ACPI_PTYPE2_PKG_COUNT: |
| 616 | |
| 617 | /* Each subpackage has a fixed number of elements */ |
| 618 | |
| 619 | expected_count = |
| 620 | package->ret_info.count1 + |
| 621 | package->ret_info.count2; |
| 622 | if (sub_package->package.count != |
| 623 | expected_count) { |
| 624 | count = sub_package->package.count; |
| 625 | goto package_too_small; |
| 626 | } |
| 627 | |
| 628 | status = |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 629 | acpi_ns_check_package_elements(data, |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 630 | sub_elements, |
| 631 | package-> |
| 632 | ret_info. |
| 633 | object_type1, |
| 634 | package-> |
| 635 | ret_info. |
| 636 | count1, |
| 637 | package-> |
| 638 | ret_info. |
| 639 | object_type2, |
| 640 | package-> |
| 641 | ret_info. |
Bob Moore | 03ef132 | 2009-03-19 10:14:45 +0800 | [diff] [blame] | 642 | count2, 0); |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 643 | if (ACPI_FAILURE(status)) { |
| 644 | return (status); |
| 645 | } |
| 646 | break; |
| 647 | |
| 648 | case ACPI_PTYPE2_FIXED: |
| 649 | |
| 650 | /* Each sub-package has a fixed length */ |
| 651 | |
| 652 | expected_count = package->ret_info2.count; |
| 653 | if (sub_package->package.count < expected_count) { |
| 654 | count = sub_package->package.count; |
| 655 | goto package_too_small; |
| 656 | } |
| 657 | |
| 658 | /* Check the type of each sub-package element */ |
| 659 | |
| 660 | for (j = 0; j < expected_count; j++) { |
| 661 | status = |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 662 | acpi_ns_check_object_type(data, |
Bob Moore | a647b5c | 2008-11-14 08:44:39 +0800 | [diff] [blame] | 663 | &sub_elements[j], |
| 664 | package->ret_info2.object_type[j], j); |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 665 | if (ACPI_FAILURE(status)) { |
| 666 | return (status); |
| 667 | } |
| 668 | } |
| 669 | break; |
| 670 | |
| 671 | case ACPI_PTYPE2_MIN: |
| 672 | |
| 673 | /* Each sub-package has a variable but minimum length */ |
| 674 | |
| 675 | expected_count = package->ret_info.count1; |
| 676 | if (sub_package->package.count < expected_count) { |
| 677 | count = sub_package->package.count; |
| 678 | goto package_too_small; |
| 679 | } |
| 680 | |
| 681 | /* Check the type of each sub-package element */ |
| 682 | |
| 683 | status = |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 684 | acpi_ns_check_package_elements(data, |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 685 | sub_elements, |
| 686 | package-> |
| 687 | ret_info. |
| 688 | object_type1, |
| 689 | sub_package-> |
| 690 | package. |
Bob Moore | 03ef132 | 2009-03-19 10:14:45 +0800 | [diff] [blame] | 691 | count, 0, 0, |
| 692 | 0); |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 693 | if (ACPI_FAILURE(status)) { |
| 694 | return (status); |
| 695 | } |
| 696 | break; |
| 697 | |
| 698 | case ACPI_PTYPE2_COUNT: |
| 699 | |
| 700 | /* First element is the (Integer) count of elements to follow */ |
| 701 | |
| 702 | status = |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 703 | acpi_ns_check_object_type(data, |
Bob Moore | a647b5c | 2008-11-14 08:44:39 +0800 | [diff] [blame] | 704 | sub_elements, |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 705 | ACPI_RTYPE_INTEGER, |
| 706 | 0); |
| 707 | if (ACPI_FAILURE(status)) { |
| 708 | return (status); |
| 709 | } |
| 710 | |
| 711 | /* Make sure package is large enough for the Count */ |
| 712 | |
| 713 | expected_count = |
| 714 | (u32) (*sub_elements)->integer.value; |
| 715 | if (sub_package->package.count < expected_count) { |
| 716 | count = sub_package->package.count; |
| 717 | goto package_too_small; |
| 718 | } |
| 719 | |
| 720 | /* Check the type of each sub-package element */ |
| 721 | |
| 722 | status = |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 723 | acpi_ns_check_package_elements(data, |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 724 | (sub_elements |
| 725 | + 1), |
| 726 | package-> |
| 727 | ret_info. |
| 728 | object_type1, |
| 729 | (expected_count |
Bob Moore | 03ef132 | 2009-03-19 10:14:45 +0800 | [diff] [blame] | 730 | - 1), 0, 0, |
| 731 | 1); |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 732 | if (ACPI_FAILURE(status)) { |
| 733 | return (status); |
| 734 | } |
| 735 | break; |
| 736 | |
| 737 | default: |
| 738 | break; |
| 739 | } |
| 740 | |
| 741 | elements++; |
| 742 | } |
| 743 | break; |
| 744 | |
| 745 | default: |
| 746 | |
| 747 | /* Should not get here if predefined info table is correct */ |
| 748 | |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 749 | ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags, |
| 750 | "Invalid internal return type in table entry: %X", |
| 751 | package->ret_info.type)); |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 752 | |
| 753 | return (AE_AML_INTERNAL); |
| 754 | } |
| 755 | |
| 756 | return (AE_OK); |
| 757 | |
| 758 | package_too_small: |
| 759 | |
| 760 | /* Error exit for the case with an incorrect package count */ |
| 761 | |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 762 | ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags, |
| 763 | "Return Package is too small - found %u, expected %u", |
| 764 | count, expected_count)); |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 765 | |
| 766 | return (AE_AML_OPERAND_VALUE); |
| 767 | } |
| 768 | |
| 769 | /******************************************************************************* |
| 770 | * |
| 771 | * FUNCTION: acpi_ns_check_package_elements |
| 772 | * |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 773 | * PARAMETERS: Data - Pointer to validation data structure |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 774 | * Elements - Pointer to the package elements array |
| 775 | * Type1 - Object type for first group |
| 776 | * Count1 - Count for first group |
| 777 | * Type2 - Object type for second group |
| 778 | * Count2 - Count for second group |
Bob Moore | 03ef132 | 2009-03-19 10:14:45 +0800 | [diff] [blame] | 779 | * start_index - Start of the first group of elements |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 780 | * |
| 781 | * RETURN: Status |
| 782 | * |
| 783 | * DESCRIPTION: Check that all elements of a package are of the correct object |
| 784 | * type. Supports up to two groups of different object types. |
| 785 | * |
| 786 | ******************************************************************************/ |
| 787 | |
| 788 | static acpi_status |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 789 | acpi_ns_check_package_elements(struct acpi_predefined_data *data, |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 790 | union acpi_operand_object **elements, |
Bob Moore | 03ef132 | 2009-03-19 10:14:45 +0800 | [diff] [blame] | 791 | u8 type1, |
| 792 | u32 count1, |
| 793 | u8 type2, u32 count2, u32 start_index) |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 794 | { |
| 795 | union acpi_operand_object **this_element = elements; |
| 796 | acpi_status status; |
| 797 | u32 i; |
| 798 | |
| 799 | /* |
| 800 | * Up to two groups of package elements are supported by the data |
| 801 | * structure. All elements in each group must be of the same type. |
| 802 | * The second group can have a count of zero. |
| 803 | */ |
| 804 | for (i = 0; i < count1; i++) { |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 805 | status = acpi_ns_check_object_type(data, this_element, |
Bob Moore | 03ef132 | 2009-03-19 10:14:45 +0800 | [diff] [blame] | 806 | type1, i + start_index); |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 807 | if (ACPI_FAILURE(status)) { |
| 808 | return (status); |
| 809 | } |
| 810 | this_element++; |
| 811 | } |
| 812 | |
| 813 | for (i = 0; i < count2; i++) { |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 814 | status = acpi_ns_check_object_type(data, this_element, |
Bob Moore | 03ef132 | 2009-03-19 10:14:45 +0800 | [diff] [blame] | 815 | type2, |
| 816 | (i + count1 + start_index)); |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 817 | if (ACPI_FAILURE(status)) { |
| 818 | return (status); |
| 819 | } |
| 820 | this_element++; |
| 821 | } |
| 822 | |
| 823 | return (AE_OK); |
| 824 | } |
| 825 | |
| 826 | /******************************************************************************* |
| 827 | * |
| 828 | * FUNCTION: acpi_ns_check_object_type |
| 829 | * |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 830 | * PARAMETERS: Data - Pointer to validation data structure |
Bob Moore | a647b5c | 2008-11-14 08:44:39 +0800 | [diff] [blame] | 831 | * return_object_ptr - Pointer to the object returned from the |
| 832 | * evaluation of a method or object |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 833 | * expected_btypes - Bitmap of expected return type(s) |
| 834 | * package_index - Index of object within parent package (if |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 835 | * applicable - ACPI_NOT_PACKAGE_ELEMENT |
| 836 | * otherwise) |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 837 | * |
| 838 | * RETURN: Status |
| 839 | * |
| 840 | * DESCRIPTION: Check the type of the return object against the expected object |
| 841 | * type(s). Use of Btype allows multiple expected object types. |
| 842 | * |
| 843 | ******************************************************************************/ |
| 844 | |
| 845 | static acpi_status |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 846 | acpi_ns_check_object_type(struct acpi_predefined_data *data, |
Bob Moore | a647b5c | 2008-11-14 08:44:39 +0800 | [diff] [blame] | 847 | union acpi_operand_object **return_object_ptr, |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 848 | u32 expected_btypes, u32 package_index) |
| 849 | { |
Bob Moore | a647b5c | 2008-11-14 08:44:39 +0800 | [diff] [blame] | 850 | union acpi_operand_object *return_object = *return_object_ptr; |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 851 | acpi_status status = AE_OK; |
| 852 | u32 return_btype; |
| 853 | char type_buffer[48]; /* Room for 5 types */ |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 854 | |
| 855 | /* |
| 856 | * If we get a NULL return_object here, it is a NULL package element, |
| 857 | * and this is always an error. |
| 858 | */ |
| 859 | if (!return_object) { |
| 860 | goto type_error_exit; |
| 861 | } |
| 862 | |
| 863 | /* A Namespace node should not get here, but make sure */ |
| 864 | |
| 865 | if (ACPI_GET_DESCRIPTOR_TYPE(return_object) == ACPI_DESC_TYPE_NAMED) { |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 866 | ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags, |
| 867 | "Invalid return type - Found a Namespace node [%4.4s] type %s", |
| 868 | return_object->node.name.ascii, |
| 869 | acpi_ut_get_type_name(return_object->node. |
| 870 | type))); |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 871 | return (AE_AML_OPERAND_TYPE); |
| 872 | } |
| 873 | |
| 874 | /* |
| 875 | * Convert the object type (ACPI_TYPE_xxx) to a bitmapped object type. |
| 876 | * The bitmapped type allows multiple possible return types. |
| 877 | * |
| 878 | * Note, the cases below must handle all of the possible types returned |
| 879 | * from all of the predefined names (including elements of returned |
| 880 | * packages) |
| 881 | */ |
Bob Moore | 3371c19 | 2009-02-18 14:44:03 +0800 | [diff] [blame] | 882 | switch (return_object->common.type) { |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 883 | case ACPI_TYPE_INTEGER: |
| 884 | return_btype = ACPI_RTYPE_INTEGER; |
| 885 | break; |
| 886 | |
| 887 | case ACPI_TYPE_BUFFER: |
| 888 | return_btype = ACPI_RTYPE_BUFFER; |
| 889 | break; |
| 890 | |
| 891 | case ACPI_TYPE_STRING: |
| 892 | return_btype = ACPI_RTYPE_STRING; |
| 893 | break; |
| 894 | |
| 895 | case ACPI_TYPE_PACKAGE: |
| 896 | return_btype = ACPI_RTYPE_PACKAGE; |
| 897 | break; |
| 898 | |
| 899 | case ACPI_TYPE_LOCAL_REFERENCE: |
| 900 | return_btype = ACPI_RTYPE_REFERENCE; |
| 901 | break; |
| 902 | |
| 903 | default: |
| 904 | /* Not one of the supported objects, must be incorrect */ |
| 905 | |
| 906 | goto type_error_exit; |
| 907 | } |
| 908 | |
| 909 | /* Is the object one of the expected types? */ |
| 910 | |
| 911 | if (!(return_btype & expected_btypes)) { |
Bob Moore | a647b5c | 2008-11-14 08:44:39 +0800 | [diff] [blame] | 912 | |
| 913 | /* Type mismatch -- attempt repair of the returned object */ |
| 914 | |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 915 | status = acpi_ns_repair_object(data, expected_btypes, |
| 916 | package_index, |
Bob Moore | a647b5c | 2008-11-14 08:44:39 +0800 | [diff] [blame] | 917 | return_object_ptr); |
| 918 | if (ACPI_SUCCESS(status)) { |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 919 | return (AE_OK); /* Repair was successful */ |
Bob Moore | a647b5c | 2008-11-14 08:44:39 +0800 | [diff] [blame] | 920 | } |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 921 | goto type_error_exit; |
| 922 | } |
| 923 | |
| 924 | /* For reference objects, check that the reference type is correct */ |
| 925 | |
Bob Moore | 3371c19 | 2009-02-18 14:44:03 +0800 | [diff] [blame] | 926 | if (return_object->common.type == ACPI_TYPE_LOCAL_REFERENCE) { |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 927 | status = acpi_ns_check_reference(data, return_object); |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 928 | } |
| 929 | |
| 930 | return (status); |
| 931 | |
| 932 | type_error_exit: |
| 933 | |
| 934 | /* Create a string with all expected types for this predefined object */ |
| 935 | |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 936 | acpi_ns_get_expected_types(type_buffer, expected_btypes); |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 937 | |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 938 | if (package_index == ACPI_NOT_PACKAGE_ELEMENT) { |
| 939 | ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags, |
| 940 | "Return type mismatch - found %s, expected %s", |
| 941 | acpi_ut_get_object_type_name |
| 942 | (return_object), type_buffer)); |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 943 | } else { |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 944 | ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags, |
| 945 | "Return Package type mismatch at index %u - " |
| 946 | "found %s, expected %s", package_index, |
| 947 | acpi_ut_get_object_type_name |
| 948 | (return_object), type_buffer)); |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 949 | } |
| 950 | |
| 951 | return (AE_AML_OPERAND_TYPE); |
| 952 | } |
| 953 | |
| 954 | /******************************************************************************* |
| 955 | * |
| 956 | * FUNCTION: acpi_ns_check_reference |
| 957 | * |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 958 | * PARAMETERS: Data - Pointer to validation data structure |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 959 | * return_object - Object returned from the evaluation of a |
| 960 | * method or object |
| 961 | * |
| 962 | * RETURN: Status |
| 963 | * |
| 964 | * DESCRIPTION: Check a returned reference object for the correct reference |
| 965 | * type. The only reference type that can be returned from a |
| 966 | * predefined method is a named reference. All others are invalid. |
| 967 | * |
| 968 | ******************************************************************************/ |
| 969 | |
| 970 | static acpi_status |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 971 | acpi_ns_check_reference(struct acpi_predefined_data *data, |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 972 | union acpi_operand_object *return_object) |
| 973 | { |
| 974 | |
| 975 | /* |
| 976 | * Check the reference object for the correct reference type (opcode). |
| 977 | * The only type of reference that can be converted to an union acpi_object is |
| 978 | * a reference to a named object (reference class: NAME) |
| 979 | */ |
| 980 | if (return_object->reference.class == ACPI_REFCLASS_NAME) { |
| 981 | return (AE_OK); |
| 982 | } |
| 983 | |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 984 | ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags, |
| 985 | "Return type mismatch - unexpected reference object type [%s] %2.2X", |
| 986 | acpi_ut_get_reference_name(return_object), |
| 987 | return_object->reference.class)); |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 988 | |
| 989 | return (AE_AML_OPERAND_TYPE); |
| 990 | } |
Bob Moore | a647b5c | 2008-11-14 08:44:39 +0800 | [diff] [blame] | 991 | |
| 992 | /******************************************************************************* |
| 993 | * |
Bob Moore | 0444e8f | 2009-06-24 13:38:02 +0800 | [diff] [blame] | 994 | * FUNCTION: acpi_ns_get_expected_types |
| 995 | * |
| 996 | * PARAMETERS: Buffer - Pointer to where the string is returned |
| 997 | * expected_btypes - Bitmap of expected return type(s) |
| 998 | * |
| 999 | * RETURN: Buffer is populated with type names. |
| 1000 | * |
| 1001 | * DESCRIPTION: Translate the expected types bitmap into a string of ascii |
| 1002 | * names of expected types, for use in warning messages. |
| 1003 | * |
| 1004 | ******************************************************************************/ |
| 1005 | |
| 1006 | static void acpi_ns_get_expected_types(char *buffer, u32 expected_btypes) |
| 1007 | { |
| 1008 | u32 this_rtype; |
| 1009 | u32 i; |
| 1010 | u32 j; |
| 1011 | |
| 1012 | j = 1; |
| 1013 | buffer[0] = 0; |
| 1014 | this_rtype = ACPI_RTYPE_INTEGER; |
| 1015 | |
| 1016 | for (i = 0; i < ACPI_NUM_RTYPES; i++) { |
| 1017 | |
| 1018 | /* If one of the expected types, concatenate the name of this type */ |
| 1019 | |
| 1020 | if (expected_btypes & this_rtype) { |
| 1021 | ACPI_STRCAT(buffer, &acpi_rtype_names[i][j]); |
| 1022 | j = 0; /* Use name separator from now on */ |
| 1023 | } |
| 1024 | this_rtype <<= 1; /* Next Rtype */ |
| 1025 | } |
| 1026 | } |