Bob Moore | b2deadd | 2009-07-24 10:56:43 +0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Module Name: nsrepair - Repair for objects returned by predefined methods |
| 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 | b2deadd | 2009-07-24 10:56:43 +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 | |
| 44 | #include <acpi/acpi.h> |
| 45 | #include "accommon.h" |
| 46 | #include "acnamesp.h" |
Lin Ming | 0240d7b | 2009-10-13 10:23:20 +0800 | [diff] [blame] | 47 | #include "acinterp.h" |
Bob Moore | 091f4d7 | 2010-01-21 09:28:32 +0800 | [diff] [blame] | 48 | #include "acpredef.h" |
Bob Moore | d5a3610 | 2013-03-08 09:23:03 +0000 | [diff] [blame^] | 49 | #include "amlresrc.h" |
Bob Moore | b2deadd | 2009-07-24 10:56:43 +0800 | [diff] [blame] | 50 | |
| 51 | #define _COMPONENT ACPI_NAMESPACE |
| 52 | ACPI_MODULE_NAME("nsrepair") |
| 53 | |
| 54 | /******************************************************************************* |
| 55 | * |
Bob Moore | 47e11d5 | 2009-12-11 15:01:12 +0800 | [diff] [blame] | 56 | * This module attempts to repair or convert objects returned by the |
| 57 | * predefined methods to an object type that is expected, as per the ACPI |
| 58 | * specification. The need for this code is dictated by the many machines that |
| 59 | * return incorrect types for the standard predefined methods. Performing these |
| 60 | * conversions here, in one place, eliminates the need for individual ACPI |
| 61 | * device drivers to do the same. Note: Most of these conversions are different |
| 62 | * than the internal object conversion routines used for implicit object |
| 63 | * conversion. |
| 64 | * |
| 65 | * The following conversions can be performed as necessary: |
| 66 | * |
| 67 | * Integer -> String |
| 68 | * Integer -> Buffer |
| 69 | * String -> Integer |
| 70 | * String -> Buffer |
| 71 | * Buffer -> Integer |
| 72 | * Buffer -> String |
| 73 | * Buffer -> Package of Integers |
| 74 | * Package -> Package of one Package |
Bob Moore | d5a3610 | 2013-03-08 09:23:03 +0000 | [diff] [blame^] | 75 | * |
| 76 | * Additional conversions that are available: |
| 77 | * Convert a null return or zero return value to an end_tag descriptor |
| 78 | * Convert an ASCII string to a Unicode buffer |
| 79 | * |
Bob Moore | 6a99b1c | 2012-03-21 09:51:39 +0800 | [diff] [blame] | 80 | * An incorrect standalone object is wrapped with required outer package |
Bob Moore | 47e11d5 | 2009-12-11 15:01:12 +0800 | [diff] [blame] | 81 | * |
Bob Moore | 091f4d7 | 2010-01-21 09:28:32 +0800 | [diff] [blame] | 82 | * Additional possible repairs: |
Bob Moore | 091f4d7 | 2010-01-21 09:28:32 +0800 | [diff] [blame] | 83 | * Required package elements that are NULL replaced by Integer/String/Buffer |
Bob Moore | 091f4d7 | 2010-01-21 09:28:32 +0800 | [diff] [blame] | 84 | * |
Bob Moore | 47e11d5 | 2009-12-11 15:01:12 +0800 | [diff] [blame] | 85 | ******************************************************************************/ |
| 86 | /* Local prototypes */ |
| 87 | static acpi_status |
| 88 | acpi_ns_convert_to_integer(union acpi_operand_object *original_object, |
| 89 | union acpi_operand_object **return_object); |
| 90 | |
| 91 | static acpi_status |
| 92 | acpi_ns_convert_to_string(union acpi_operand_object *original_object, |
| 93 | union acpi_operand_object **return_object); |
| 94 | |
| 95 | static acpi_status |
| 96 | acpi_ns_convert_to_buffer(union acpi_operand_object *original_object, |
| 97 | union acpi_operand_object **return_object); |
| 98 | |
Bob Moore | d5a3610 | 2013-03-08 09:23:03 +0000 | [diff] [blame^] | 99 | static const struct acpi_simple_repair_info *acpi_ns_match_simple_repair(struct |
| 100 | acpi_namespace_node |
| 101 | *node, |
| 102 | u32 |
| 103 | return_btype, |
| 104 | u32 |
| 105 | package_index); |
| 106 | |
| 107 | /* |
| 108 | * Special but simple repairs for some names. |
| 109 | * |
| 110 | * 2nd argument: Unexpected types that can be repaired |
| 111 | */ |
| 112 | static const struct acpi_simple_repair_info acpi_object_repair_info[] = { |
| 113 | {{0, 0, 0, 0}, 0, 0, NULL} /* Table terminator */ |
| 114 | }; |
| 115 | |
Bob Moore | 47e11d5 | 2009-12-11 15:01:12 +0800 | [diff] [blame] | 116 | /******************************************************************************* |
| 117 | * |
Bob Moore | d5a3610 | 2013-03-08 09:23:03 +0000 | [diff] [blame^] | 118 | * FUNCTION: acpi_ns_simple_repair |
Bob Moore | b2deadd | 2009-07-24 10:56:43 +0800 | [diff] [blame] | 119 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 120 | * PARAMETERS: data - Pointer to validation data structure |
Bob Moore | b2deadd | 2009-07-24 10:56:43 +0800 | [diff] [blame] | 121 | * expected_btypes - Object types expected |
| 122 | * package_index - Index of object within parent package (if |
| 123 | * applicable - ACPI_NOT_PACKAGE_ELEMENT |
| 124 | * otherwise) |
| 125 | * return_object_ptr - Pointer to the object returned from the |
| 126 | * evaluation of a method or object |
| 127 | * |
| 128 | * RETURN: Status. AE_OK if repair was successful. |
| 129 | * |
| 130 | * DESCRIPTION: Attempt to repair/convert a return object of a type that was |
| 131 | * not expected. |
| 132 | * |
| 133 | ******************************************************************************/ |
Bob Moore | 47e11d5 | 2009-12-11 15:01:12 +0800 | [diff] [blame] | 134 | |
Bob Moore | b2deadd | 2009-07-24 10:56:43 +0800 | [diff] [blame] | 135 | acpi_status |
Bob Moore | d5a3610 | 2013-03-08 09:23:03 +0000 | [diff] [blame^] | 136 | acpi_ns_simple_repair(struct acpi_predefined_data *data, |
Bob Moore | b2deadd | 2009-07-24 10:56:43 +0800 | [diff] [blame] | 137 | u32 expected_btypes, |
| 138 | u32 package_index, |
| 139 | union acpi_operand_object **return_object_ptr) |
| 140 | { |
| 141 | union acpi_operand_object *return_object = *return_object_ptr; |
Bob Moore | d5a3610 | 2013-03-08 09:23:03 +0000 | [diff] [blame^] | 142 | union acpi_operand_object *new_object = NULL; |
Lin Ming | 0240d7b | 2009-10-13 10:23:20 +0800 | [diff] [blame] | 143 | acpi_status status; |
Bob Moore | d5a3610 | 2013-03-08 09:23:03 +0000 | [diff] [blame^] | 144 | const struct acpi_simple_repair_info *predefined; |
Bob Moore | b2deadd | 2009-07-24 10:56:43 +0800 | [diff] [blame] | 145 | |
Bob Moore | d5a3610 | 2013-03-08 09:23:03 +0000 | [diff] [blame^] | 146 | ACPI_FUNCTION_NAME(ns_simple_repair); |
| 147 | |
| 148 | /* |
| 149 | * Special repairs for certain names that are in the repair table. |
| 150 | * Check if this name is in the list of repairable names. |
| 151 | */ |
| 152 | predefined = acpi_ns_match_simple_repair(data->node, |
| 153 | data->return_btype, |
| 154 | package_index); |
| 155 | if (predefined) { |
| 156 | if (!return_object) { |
| 157 | ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, |
| 158 | ACPI_WARN_ALWAYS, |
| 159 | "Missing expected return value")); |
| 160 | } |
| 161 | |
| 162 | status = |
| 163 | predefined->object_converter(return_object, &new_object); |
| 164 | if (ACPI_FAILURE(status)) { |
| 165 | |
| 166 | /* A fatal error occurred during a conversion */ |
| 167 | |
| 168 | ACPI_EXCEPTION((AE_INFO, status, |
| 169 | "During return object analysis")); |
| 170 | return (status); |
| 171 | } |
| 172 | if (new_object) { |
| 173 | goto object_repaired; |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | /* |
| 178 | * Do not perform simple object repair unless the return type is not |
| 179 | * expected. |
| 180 | */ |
| 181 | if (data->return_btype & expected_btypes) { |
| 182 | return (AE_OK); |
| 183 | } |
Bob Moore | 3a58176 | 2009-12-11 15:23:22 +0800 | [diff] [blame] | 184 | |
Bob Moore | 2752699 | 2009-10-13 10:20:33 +0800 | [diff] [blame] | 185 | /* |
| 186 | * At this point, we know that the type of the returned object was not |
| 187 | * one of the expected types for this predefined name. Attempt to |
Bob Moore | 47e11d5 | 2009-12-11 15:01:12 +0800 | [diff] [blame] | 188 | * repair the object by converting it to one of the expected object |
| 189 | * types for this predefined name. |
Bob Moore | 2752699 | 2009-10-13 10:20:33 +0800 | [diff] [blame] | 190 | */ |
Bob Moore | d5a3610 | 2013-03-08 09:23:03 +0000 | [diff] [blame^] | 191 | |
| 192 | /* |
| 193 | * If there is no return value, check if we require a return value for |
| 194 | * this predefined name. Either one return value is expected, or none, |
| 195 | * for both methods and other objects. |
| 196 | * |
| 197 | * Exit now if there is no return object. Warning if one was expected. |
| 198 | */ |
| 199 | if (!return_object) { |
| 200 | if (expected_btypes && (!(expected_btypes & ACPI_RTYPE_NONE))) { |
| 201 | ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, |
| 202 | ACPI_WARN_ALWAYS, |
| 203 | "Missing expected return value")); |
| 204 | |
| 205 | return (AE_AML_NO_RETURN_VALUE); |
| 206 | } |
| 207 | } |
| 208 | |
Bob Moore | 47e11d5 | 2009-12-11 15:01:12 +0800 | [diff] [blame] | 209 | if (expected_btypes & ACPI_RTYPE_INTEGER) { |
| 210 | status = acpi_ns_convert_to_integer(return_object, &new_object); |
| 211 | if (ACPI_SUCCESS(status)) { |
| 212 | goto object_repaired; |
Bob Moore | b2deadd | 2009-07-24 10:56:43 +0800 | [diff] [blame] | 213 | } |
Bob Moore | b2deadd | 2009-07-24 10:56:43 +0800 | [diff] [blame] | 214 | } |
Bob Moore | 47e11d5 | 2009-12-11 15:01:12 +0800 | [diff] [blame] | 215 | if (expected_btypes & ACPI_RTYPE_STRING) { |
| 216 | status = acpi_ns_convert_to_string(return_object, &new_object); |
| 217 | if (ACPI_SUCCESS(status)) { |
| 218 | goto object_repaired; |
| 219 | } |
| 220 | } |
| 221 | if (expected_btypes & ACPI_RTYPE_BUFFER) { |
| 222 | status = acpi_ns_convert_to_buffer(return_object, &new_object); |
| 223 | if (ACPI_SUCCESS(status)) { |
| 224 | goto object_repaired; |
| 225 | } |
| 226 | } |
| 227 | if (expected_btypes & ACPI_RTYPE_PACKAGE) { |
Bob Moore | 6a99b1c | 2012-03-21 09:51:39 +0800 | [diff] [blame] | 228 | /* |
| 229 | * A package is expected. We will wrap the existing object with a |
| 230 | * new package object. It is often the case that if a variable-length |
| 231 | * package is required, but there is only a single object needed, the |
| 232 | * BIOS will return that object instead of wrapping it with a Package |
| 233 | * object. Note: after the wrapping, the package will be validated |
| 234 | * for correct contents (expected object type or types). |
| 235 | */ |
| 236 | status = |
| 237 | acpi_ns_wrap_with_package(data, return_object, &new_object); |
Bob Moore | 47e11d5 | 2009-12-11 15:01:12 +0800 | [diff] [blame] | 238 | if (ACPI_SUCCESS(status)) { |
Bob Moore | 6a99b1c | 2012-03-21 09:51:39 +0800 | [diff] [blame] | 239 | /* |
| 240 | * The original object just had its reference count |
| 241 | * incremented for being inserted into the new package. |
| 242 | */ |
| 243 | *return_object_ptr = new_object; /* New Package object */ |
| 244 | data->flags |= ACPI_OBJECT_REPAIRED; |
| 245 | return (AE_OK); |
Bob Moore | 47e11d5 | 2009-12-11 15:01:12 +0800 | [diff] [blame] | 246 | } |
| 247 | } |
| 248 | |
| 249 | /* We cannot repair this object */ |
| 250 | |
| 251 | return (AE_AML_OPERAND_TYPE); |
| 252 | |
| 253 | object_repaired: |
Bob Moore | b2deadd | 2009-07-24 10:56:43 +0800 | [diff] [blame] | 254 | |
Bob Moore | 2752699 | 2009-10-13 10:20:33 +0800 | [diff] [blame] | 255 | /* Object was successfully repaired */ |
| 256 | |
Bob Moore | 2752699 | 2009-10-13 10:20:33 +0800 | [diff] [blame] | 257 | if (package_index != ACPI_NOT_PACKAGE_ELEMENT) { |
Bob Moore | 6a99b1c | 2012-03-21 09:51:39 +0800 | [diff] [blame] | 258 | /* |
| 259 | * The original object is a package element. We need to |
| 260 | * decrement the reference count of the original object, |
| 261 | * for removing it from the package. |
| 262 | * |
| 263 | * However, if the original object was just wrapped with a |
| 264 | * package object as part of the repair, we don't need to |
| 265 | * change the reference count. |
| 266 | */ |
| 267 | if (!(data->flags & ACPI_OBJECT_WRAPPED)) { |
| 268 | new_object->common.reference_count = |
| 269 | return_object->common.reference_count; |
Bob Moore | 2752699 | 2009-10-13 10:20:33 +0800 | [diff] [blame] | 270 | |
Bob Moore | 6a99b1c | 2012-03-21 09:51:39 +0800 | [diff] [blame] | 271 | if (return_object->common.reference_count > 1) { |
| 272 | return_object->common.reference_count--; |
| 273 | } |
Bob Moore | 2752699 | 2009-10-13 10:20:33 +0800 | [diff] [blame] | 274 | } |
| 275 | |
Bob Moore | 3a58176 | 2009-12-11 15:23:22 +0800 | [diff] [blame] | 276 | ACPI_DEBUG_PRINT((ACPI_DB_REPAIR, |
Bob Moore | 6a99b1c | 2012-03-21 09:51:39 +0800 | [diff] [blame] | 277 | "%s: Converted %s to expected %s at Package index %u\n", |
Bob Moore | 3a58176 | 2009-12-11 15:23:22 +0800 | [diff] [blame] | 278 | data->pathname, |
| 279 | acpi_ut_get_object_type_name(return_object), |
| 280 | acpi_ut_get_object_type_name(new_object), |
| 281 | package_index)); |
Bob Moore | 2752699 | 2009-10-13 10:20:33 +0800 | [diff] [blame] | 282 | } else { |
Bob Moore | 3a58176 | 2009-12-11 15:23:22 +0800 | [diff] [blame] | 283 | ACPI_DEBUG_PRINT((ACPI_DB_REPAIR, |
| 284 | "%s: Converted %s to expected %s\n", |
| 285 | data->pathname, |
| 286 | acpi_ut_get_object_type_name(return_object), |
| 287 | acpi_ut_get_object_type_name(new_object))); |
Bob Moore | 2752699 | 2009-10-13 10:20:33 +0800 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | /* Delete old object, install the new return object */ |
| 291 | |
| 292 | acpi_ut_remove_reference(return_object); |
| 293 | *return_object_ptr = new_object; |
| 294 | data->flags |= ACPI_OBJECT_REPAIRED; |
| 295 | return (AE_OK); |
Bob Moore | b2deadd | 2009-07-24 10:56:43 +0800 | [diff] [blame] | 296 | } |
Bob Moore | e5f69d6 | 2009-07-24 11:03:09 +0800 | [diff] [blame] | 297 | |
Bob Moore | d5a3610 | 2013-03-08 09:23:03 +0000 | [diff] [blame^] | 298 | /****************************************************************************** |
| 299 | * |
| 300 | * FUNCTION: acpi_ns_match_simple_repair |
| 301 | * |
| 302 | * PARAMETERS: node - Namespace node for the method/object |
| 303 | * return_btype - Object type that was returned |
| 304 | * package_index - Index of object within parent package (if |
| 305 | * applicable - ACPI_NOT_PACKAGE_ELEMENT |
| 306 | * otherwise) |
| 307 | * |
| 308 | * RETURN: Pointer to entry in repair table. NULL indicates not found. |
| 309 | * |
| 310 | * DESCRIPTION: Check an object name against the repairable object list. |
| 311 | * |
| 312 | *****************************************************************************/ |
| 313 | |
| 314 | static const struct acpi_simple_repair_info *acpi_ns_match_simple_repair(struct |
| 315 | acpi_namespace_node |
| 316 | *node, |
| 317 | u32 |
| 318 | return_btype, |
| 319 | u32 |
| 320 | package_index) |
| 321 | { |
| 322 | const struct acpi_simple_repair_info *this_name; |
| 323 | |
| 324 | /* Search info table for a repairable predefined method/object name */ |
| 325 | |
| 326 | this_name = acpi_object_repair_info; |
| 327 | while (this_name->object_converter) { |
| 328 | if (ACPI_COMPARE_NAME(node->name.ascii, this_name->name)) { |
| 329 | |
| 330 | /* Check if we can actually repair this name/type combination */ |
| 331 | |
| 332 | if ((return_btype & this_name->unexpected_btypes) && |
| 333 | (package_index == this_name->package_index)) { |
| 334 | return (this_name); |
| 335 | } |
| 336 | |
| 337 | return (NULL); |
| 338 | } |
| 339 | this_name++; |
| 340 | } |
| 341 | |
| 342 | return (NULL); /* Name was not found in the repair table */ |
| 343 | } |
| 344 | |
Bob Moore | e5f69d6 | 2009-07-24 11:03:09 +0800 | [diff] [blame] | 345 | /******************************************************************************* |
| 346 | * |
Bob Moore | 47e11d5 | 2009-12-11 15:01:12 +0800 | [diff] [blame] | 347 | * FUNCTION: acpi_ns_convert_to_integer |
| 348 | * |
| 349 | * PARAMETERS: original_object - Object to be converted |
| 350 | * return_object - Where the new converted object is returned |
| 351 | * |
| 352 | * RETURN: Status. AE_OK if conversion was successful. |
| 353 | * |
| 354 | * DESCRIPTION: Attempt to convert a String/Buffer object to an Integer. |
| 355 | * |
| 356 | ******************************************************************************/ |
| 357 | |
| 358 | static acpi_status |
| 359 | acpi_ns_convert_to_integer(union acpi_operand_object *original_object, |
| 360 | union acpi_operand_object **return_object) |
| 361 | { |
| 362 | union acpi_operand_object *new_object; |
| 363 | acpi_status status; |
| 364 | u64 value = 0; |
| 365 | u32 i; |
| 366 | |
| 367 | switch (original_object->common.type) { |
| 368 | case ACPI_TYPE_STRING: |
| 369 | |
| 370 | /* String-to-Integer conversion */ |
| 371 | |
| 372 | status = acpi_ut_strtoul64(original_object->string.pointer, |
| 373 | ACPI_ANY_BASE, &value); |
| 374 | if (ACPI_FAILURE(status)) { |
| 375 | return (status); |
| 376 | } |
| 377 | break; |
| 378 | |
| 379 | case ACPI_TYPE_BUFFER: |
| 380 | |
| 381 | /* Buffer-to-Integer conversion. Max buffer size is 64 bits. */ |
| 382 | |
| 383 | if (original_object->buffer.length > 8) { |
| 384 | return (AE_AML_OPERAND_TYPE); |
| 385 | } |
| 386 | |
| 387 | /* Extract each buffer byte to create the integer */ |
| 388 | |
| 389 | for (i = 0; i < original_object->buffer.length; i++) { |
| 390 | value |= |
| 391 | ((u64) original_object->buffer. |
| 392 | pointer[i] << (i * 8)); |
| 393 | } |
| 394 | break; |
| 395 | |
| 396 | default: |
| 397 | return (AE_AML_OPERAND_TYPE); |
| 398 | } |
| 399 | |
| 400 | new_object = acpi_ut_create_integer_object(value); |
| 401 | if (!new_object) { |
| 402 | return (AE_NO_MEMORY); |
| 403 | } |
| 404 | |
| 405 | *return_object = new_object; |
| 406 | return (AE_OK); |
| 407 | } |
| 408 | |
| 409 | /******************************************************************************* |
| 410 | * |
| 411 | * FUNCTION: acpi_ns_convert_to_string |
| 412 | * |
| 413 | * PARAMETERS: original_object - Object to be converted |
| 414 | * return_object - Where the new converted object is returned |
| 415 | * |
| 416 | * RETURN: Status. AE_OK if conversion was successful. |
| 417 | * |
| 418 | * DESCRIPTION: Attempt to convert a Integer/Buffer object to a String. |
| 419 | * |
| 420 | ******************************************************************************/ |
| 421 | |
| 422 | static acpi_status |
| 423 | acpi_ns_convert_to_string(union acpi_operand_object *original_object, |
| 424 | union acpi_operand_object **return_object) |
| 425 | { |
| 426 | union acpi_operand_object *new_object; |
| 427 | acpi_size length; |
| 428 | acpi_status status; |
| 429 | |
| 430 | switch (original_object->common.type) { |
| 431 | case ACPI_TYPE_INTEGER: |
| 432 | /* |
| 433 | * Integer-to-String conversion. Commonly, convert |
| 434 | * an integer of value 0 to a NULL string. The last element of |
| 435 | * _BIF and _BIX packages occasionally need this fix. |
| 436 | */ |
| 437 | if (original_object->integer.value == 0) { |
| 438 | |
| 439 | /* Allocate a new NULL string object */ |
| 440 | |
| 441 | new_object = acpi_ut_create_string_object(0); |
| 442 | if (!new_object) { |
| 443 | return (AE_NO_MEMORY); |
| 444 | } |
| 445 | } else { |
| 446 | status = |
| 447 | acpi_ex_convert_to_string(original_object, |
| 448 | &new_object, |
| 449 | ACPI_IMPLICIT_CONVERT_HEX); |
| 450 | if (ACPI_FAILURE(status)) { |
| 451 | return (status); |
| 452 | } |
| 453 | } |
| 454 | break; |
| 455 | |
| 456 | case ACPI_TYPE_BUFFER: |
| 457 | /* |
| 458 | * Buffer-to-String conversion. Use a to_string |
| 459 | * conversion, no transform performed on the buffer data. The best |
| 460 | * example of this is the _BIF method, where the string data from |
| 461 | * the battery is often (incorrectly) returned as buffer object(s). |
| 462 | */ |
| 463 | length = 0; |
| 464 | while ((length < original_object->buffer.length) && |
| 465 | (original_object->buffer.pointer[length])) { |
| 466 | length++; |
| 467 | } |
| 468 | |
| 469 | /* Allocate a new string object */ |
| 470 | |
| 471 | new_object = acpi_ut_create_string_object(length); |
| 472 | if (!new_object) { |
| 473 | return (AE_NO_MEMORY); |
| 474 | } |
| 475 | |
| 476 | /* |
| 477 | * Copy the raw buffer data with no transform. String is already NULL |
| 478 | * terminated at Length+1. |
| 479 | */ |
| 480 | ACPI_MEMCPY(new_object->string.pointer, |
| 481 | original_object->buffer.pointer, length); |
| 482 | break; |
| 483 | |
| 484 | default: |
| 485 | return (AE_AML_OPERAND_TYPE); |
| 486 | } |
| 487 | |
| 488 | *return_object = new_object; |
| 489 | return (AE_OK); |
| 490 | } |
| 491 | |
| 492 | /******************************************************************************* |
| 493 | * |
| 494 | * FUNCTION: acpi_ns_convert_to_buffer |
| 495 | * |
| 496 | * PARAMETERS: original_object - Object to be converted |
| 497 | * return_object - Where the new converted object is returned |
| 498 | * |
| 499 | * RETURN: Status. AE_OK if conversion was successful. |
| 500 | * |
Bob Moore | ea7c5ec | 2009-12-11 15:18:52 +0800 | [diff] [blame] | 501 | * DESCRIPTION: Attempt to convert a Integer/String/Package object to a Buffer. |
Bob Moore | 47e11d5 | 2009-12-11 15:01:12 +0800 | [diff] [blame] | 502 | * |
| 503 | ******************************************************************************/ |
| 504 | |
| 505 | static acpi_status |
| 506 | acpi_ns_convert_to_buffer(union acpi_operand_object *original_object, |
| 507 | union acpi_operand_object **return_object) |
| 508 | { |
| 509 | union acpi_operand_object *new_object; |
| 510 | acpi_status status; |
Bob Moore | ea7c5ec | 2009-12-11 15:18:52 +0800 | [diff] [blame] | 511 | union acpi_operand_object **elements; |
| 512 | u32 *dword_buffer; |
| 513 | u32 count; |
| 514 | u32 i; |
Bob Moore | 47e11d5 | 2009-12-11 15:01:12 +0800 | [diff] [blame] | 515 | |
| 516 | switch (original_object->common.type) { |
| 517 | case ACPI_TYPE_INTEGER: |
| 518 | /* |
| 519 | * Integer-to-Buffer conversion. |
| 520 | * Convert the Integer to a packed-byte buffer. _MAT and other |
| 521 | * objects need this sometimes, if a read has been performed on a |
| 522 | * Field object that is less than or equal to the global integer |
| 523 | * size (32 or 64 bits). |
| 524 | */ |
| 525 | status = |
| 526 | acpi_ex_convert_to_buffer(original_object, &new_object); |
| 527 | if (ACPI_FAILURE(status)) { |
| 528 | return (status); |
| 529 | } |
| 530 | break; |
| 531 | |
| 532 | case ACPI_TYPE_STRING: |
| 533 | |
| 534 | /* String-to-Buffer conversion. Simple data copy */ |
| 535 | |
| 536 | new_object = |
| 537 | acpi_ut_create_buffer_object(original_object->string. |
| 538 | length); |
| 539 | if (!new_object) { |
| 540 | return (AE_NO_MEMORY); |
| 541 | } |
| 542 | |
| 543 | ACPI_MEMCPY(new_object->buffer.pointer, |
| 544 | original_object->string.pointer, |
| 545 | original_object->string.length); |
| 546 | break; |
| 547 | |
Bob Moore | ea7c5ec | 2009-12-11 15:18:52 +0800 | [diff] [blame] | 548 | case ACPI_TYPE_PACKAGE: |
Bob Moore | 43420bb | 2009-12-11 15:24:27 +0800 | [diff] [blame] | 549 | /* |
| 550 | * This case is often seen for predefined names that must return a |
| 551 | * Buffer object with multiple DWORD integers within. For example, |
| 552 | * _FDE and _GTM. The Package can be converted to a Buffer. |
| 553 | */ |
Bob Moore | ea7c5ec | 2009-12-11 15:18:52 +0800 | [diff] [blame] | 554 | |
| 555 | /* All elements of the Package must be integers */ |
| 556 | |
| 557 | elements = original_object->package.elements; |
| 558 | count = original_object->package.count; |
| 559 | |
| 560 | for (i = 0; i < count; i++) { |
| 561 | if ((!*elements) || |
| 562 | ((*elements)->common.type != ACPI_TYPE_INTEGER)) { |
| 563 | return (AE_AML_OPERAND_TYPE); |
| 564 | } |
| 565 | elements++; |
| 566 | } |
| 567 | |
| 568 | /* Create the new buffer object to replace the Package */ |
| 569 | |
| 570 | new_object = acpi_ut_create_buffer_object(ACPI_MUL_4(count)); |
| 571 | if (!new_object) { |
| 572 | return (AE_NO_MEMORY); |
| 573 | } |
| 574 | |
| 575 | /* Copy the package elements (integers) to the buffer as DWORDs */ |
| 576 | |
| 577 | elements = original_object->package.elements; |
| 578 | dword_buffer = ACPI_CAST_PTR(u32, new_object->buffer.pointer); |
| 579 | |
| 580 | for (i = 0; i < count; i++) { |
| 581 | *dword_buffer = (u32) (*elements)->integer.value; |
| 582 | dword_buffer++; |
| 583 | elements++; |
| 584 | } |
| 585 | break; |
| 586 | |
Bob Moore | 47e11d5 | 2009-12-11 15:01:12 +0800 | [diff] [blame] | 587 | default: |
| 588 | return (AE_AML_OPERAND_TYPE); |
| 589 | } |
| 590 | |
| 591 | *return_object = new_object; |
| 592 | return (AE_OK); |
| 593 | } |
| 594 | |
| 595 | /******************************************************************************* |
| 596 | * |
Bob Moore | 091f4d7 | 2010-01-21 09:28:32 +0800 | [diff] [blame] | 597 | * FUNCTION: acpi_ns_repair_null_element |
| 598 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 599 | * PARAMETERS: data - Pointer to validation data structure |
Bob Moore | 091f4d7 | 2010-01-21 09:28:32 +0800 | [diff] [blame] | 600 | * expected_btypes - Object types expected |
| 601 | * package_index - Index of object within parent package (if |
| 602 | * applicable - ACPI_NOT_PACKAGE_ELEMENT |
| 603 | * otherwise) |
| 604 | * return_object_ptr - Pointer to the object returned from the |
| 605 | * evaluation of a method or object |
| 606 | * |
| 607 | * RETURN: Status. AE_OK if repair was successful. |
| 608 | * |
| 609 | * DESCRIPTION: Attempt to repair a NULL element of a returned Package object. |
| 610 | * |
| 611 | ******************************************************************************/ |
| 612 | |
| 613 | acpi_status |
| 614 | acpi_ns_repair_null_element(struct acpi_predefined_data *data, |
| 615 | u32 expected_btypes, |
| 616 | u32 package_index, |
| 617 | union acpi_operand_object **return_object_ptr) |
| 618 | { |
| 619 | union acpi_operand_object *return_object = *return_object_ptr; |
| 620 | union acpi_operand_object *new_object; |
| 621 | |
| 622 | ACPI_FUNCTION_NAME(ns_repair_null_element); |
| 623 | |
| 624 | /* No repair needed if return object is non-NULL */ |
| 625 | |
| 626 | if (return_object) { |
| 627 | return (AE_OK); |
| 628 | } |
| 629 | |
| 630 | /* |
| 631 | * Attempt to repair a NULL element of a Package object. This applies to |
| 632 | * predefined names that return a fixed-length package and each element |
| 633 | * is required. It does not apply to variable-length packages where NULL |
| 634 | * elements are allowed, especially at the end of the package. |
| 635 | */ |
| 636 | if (expected_btypes & ACPI_RTYPE_INTEGER) { |
| 637 | |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 638 | /* Need an integer - create a zero-value integer */ |
Bob Moore | 091f4d7 | 2010-01-21 09:28:32 +0800 | [diff] [blame] | 639 | |
Bob Moore | 150dba3 | 2010-07-06 10:35:55 +0800 | [diff] [blame] | 640 | new_object = acpi_ut_create_integer_object((u64)0); |
Bob Moore | 091f4d7 | 2010-01-21 09:28:32 +0800 | [diff] [blame] | 641 | } else if (expected_btypes & ACPI_RTYPE_STRING) { |
| 642 | |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 643 | /* Need a string - create a NULL string */ |
Bob Moore | 091f4d7 | 2010-01-21 09:28:32 +0800 | [diff] [blame] | 644 | |
| 645 | new_object = acpi_ut_create_string_object(0); |
| 646 | } else if (expected_btypes & ACPI_RTYPE_BUFFER) { |
| 647 | |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 648 | /* Need a buffer - create a zero-length buffer */ |
Bob Moore | 091f4d7 | 2010-01-21 09:28:32 +0800 | [diff] [blame] | 649 | |
| 650 | new_object = acpi_ut_create_buffer_object(0); |
| 651 | } else { |
| 652 | /* Error for all other expected types */ |
| 653 | |
| 654 | return (AE_AML_OPERAND_TYPE); |
| 655 | } |
| 656 | |
| 657 | if (!new_object) { |
| 658 | return (AE_NO_MEMORY); |
| 659 | } |
| 660 | |
| 661 | /* Set the reference count according to the parent Package object */ |
| 662 | |
| 663 | new_object->common.reference_count = |
| 664 | data->parent_package->common.reference_count; |
| 665 | |
| 666 | ACPI_DEBUG_PRINT((ACPI_DB_REPAIR, |
| 667 | "%s: Converted NULL package element to expected %s at index %u\n", |
| 668 | data->pathname, |
| 669 | acpi_ut_get_object_type_name(new_object), |
| 670 | package_index)); |
| 671 | |
| 672 | *return_object_ptr = new_object; |
| 673 | data->flags |= ACPI_OBJECT_REPAIRED; |
| 674 | return (AE_OK); |
| 675 | } |
| 676 | |
| 677 | /****************************************************************************** |
| 678 | * |
| 679 | * FUNCTION: acpi_ns_remove_null_elements |
| 680 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 681 | * PARAMETERS: data - Pointer to validation data structure |
Bob Moore | 091f4d7 | 2010-01-21 09:28:32 +0800 | [diff] [blame] | 682 | * package_type - An acpi_return_package_types value |
| 683 | * obj_desc - A Package object |
| 684 | * |
| 685 | * RETURN: None. |
| 686 | * |
| 687 | * DESCRIPTION: Remove all NULL package elements from packages that contain |
| 688 | * a variable number of sub-packages. For these types of |
| 689 | * packages, NULL elements can be safely removed. |
| 690 | * |
| 691 | *****************************************************************************/ |
| 692 | |
| 693 | void |
| 694 | acpi_ns_remove_null_elements(struct acpi_predefined_data *data, |
| 695 | u8 package_type, |
| 696 | union acpi_operand_object *obj_desc) |
| 697 | { |
| 698 | union acpi_operand_object **source; |
| 699 | union acpi_operand_object **dest; |
| 700 | u32 count; |
| 701 | u32 new_count; |
| 702 | u32 i; |
| 703 | |
| 704 | ACPI_FUNCTION_NAME(ns_remove_null_elements); |
| 705 | |
| 706 | /* |
Bob Moore | 945488b | 2011-04-13 13:15:58 +0800 | [diff] [blame] | 707 | * We can safely remove all NULL elements from these package types: |
| 708 | * PTYPE1_VAR packages contain a variable number of simple data types. |
| 709 | * PTYPE2 packages contain a variable number of sub-packages. |
Bob Moore | 091f4d7 | 2010-01-21 09:28:32 +0800 | [diff] [blame] | 710 | */ |
| 711 | switch (package_type) { |
Bob Moore | 091f4d7 | 2010-01-21 09:28:32 +0800 | [diff] [blame] | 712 | case ACPI_PTYPE1_VAR: |
Bob Moore | 091f4d7 | 2010-01-21 09:28:32 +0800 | [diff] [blame] | 713 | case ACPI_PTYPE2: |
| 714 | case ACPI_PTYPE2_COUNT: |
| 715 | case ACPI_PTYPE2_PKG_COUNT: |
| 716 | case ACPI_PTYPE2_FIXED: |
| 717 | case ACPI_PTYPE2_MIN: |
| 718 | case ACPI_PTYPE2_REV_FIXED: |
Bob Moore | 7fce7a4 | 2011-11-16 14:59:17 +0800 | [diff] [blame] | 719 | case ACPI_PTYPE2_FIX_VAR: |
Bob Moore | 091f4d7 | 2010-01-21 09:28:32 +0800 | [diff] [blame] | 720 | break; |
| 721 | |
| 722 | default: |
Bob Moore | 945488b | 2011-04-13 13:15:58 +0800 | [diff] [blame] | 723 | case ACPI_PTYPE1_FIXED: |
| 724 | case ACPI_PTYPE1_OPTION: |
Bob Moore | 091f4d7 | 2010-01-21 09:28:32 +0800 | [diff] [blame] | 725 | return; |
| 726 | } |
| 727 | |
| 728 | count = obj_desc->package.count; |
| 729 | new_count = count; |
| 730 | |
| 731 | source = obj_desc->package.elements; |
| 732 | dest = source; |
| 733 | |
| 734 | /* Examine all elements of the package object, remove nulls */ |
| 735 | |
| 736 | for (i = 0; i < count; i++) { |
| 737 | if (!*source) { |
| 738 | new_count--; |
| 739 | } else { |
| 740 | *dest = *source; |
| 741 | dest++; |
| 742 | } |
| 743 | source++; |
| 744 | } |
| 745 | |
| 746 | /* Update parent package if any null elements were removed */ |
| 747 | |
| 748 | if (new_count < count) { |
| 749 | ACPI_DEBUG_PRINT((ACPI_DB_REPAIR, |
| 750 | "%s: Found and removed %u NULL elements\n", |
| 751 | data->pathname, (count - new_count))); |
| 752 | |
| 753 | /* NULL terminate list and update the package count */ |
| 754 | |
| 755 | *dest = NULL; |
| 756 | obj_desc->package.count = new_count; |
| 757 | } |
| 758 | } |
| 759 | |
| 760 | /******************************************************************************* |
| 761 | * |
Bob Moore | 6a99b1c | 2012-03-21 09:51:39 +0800 | [diff] [blame] | 762 | * FUNCTION: acpi_ns_wrap_with_package |
Bob Moore | e5f69d6 | 2009-07-24 11:03:09 +0800 | [diff] [blame] | 763 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 764 | * PARAMETERS: data - Pointer to validation data structure |
Bob Moore | 6a99b1c | 2012-03-21 09:51:39 +0800 | [diff] [blame] | 765 | * original_object - Pointer to the object to repair. |
| 766 | * obj_desc_ptr - The new package object is returned here |
Bob Moore | e5f69d6 | 2009-07-24 11:03:09 +0800 | [diff] [blame] | 767 | * |
| 768 | * RETURN: Status, new object in *obj_desc_ptr |
| 769 | * |
Bob Moore | 6a99b1c | 2012-03-21 09:51:39 +0800 | [diff] [blame] | 770 | * DESCRIPTION: Repair a common problem with objects that are defined to |
| 771 | * return a variable-length Package of sub-objects. If there is |
| 772 | * only one sub-object, some BIOS code mistakenly simply declares |
| 773 | * the single object instead of a Package with one sub-object. |
| 774 | * This function attempts to repair this error by wrapping a |
| 775 | * Package object around the original object, creating the |
| 776 | * correct and expected Package with one sub-object. |
Bob Moore | e5f69d6 | 2009-07-24 11:03:09 +0800 | [diff] [blame] | 777 | * |
| 778 | * Names that can be repaired in this manner include: |
Bob Moore | 6a99b1c | 2012-03-21 09:51:39 +0800 | [diff] [blame] | 779 | * _ALR, _CSD, _HPX, _MLS, _PLD, _PRT, _PSS, _TRT, _TSS, |
| 780 | * _BCL, _DOD, _FIX, _Sx |
Bob Moore | e5f69d6 | 2009-07-24 11:03:09 +0800 | [diff] [blame] | 781 | * |
| 782 | ******************************************************************************/ |
| 783 | |
| 784 | acpi_status |
Bob Moore | 6a99b1c | 2012-03-21 09:51:39 +0800 | [diff] [blame] | 785 | acpi_ns_wrap_with_package(struct acpi_predefined_data *data, |
| 786 | union acpi_operand_object *original_object, |
| 787 | union acpi_operand_object **obj_desc_ptr) |
Bob Moore | e5f69d6 | 2009-07-24 11:03:09 +0800 | [diff] [blame] | 788 | { |
| 789 | union acpi_operand_object *pkg_obj_desc; |
| 790 | |
Bob Moore | 6a99b1c | 2012-03-21 09:51:39 +0800 | [diff] [blame] | 791 | ACPI_FUNCTION_NAME(ns_wrap_with_package); |
Bob Moore | 3a58176 | 2009-12-11 15:23:22 +0800 | [diff] [blame] | 792 | |
Bob Moore | e5f69d6 | 2009-07-24 11:03:09 +0800 | [diff] [blame] | 793 | /* |
| 794 | * Create the new outer package and populate it. The new package will |
Bob Moore | 6a99b1c | 2012-03-21 09:51:39 +0800 | [diff] [blame] | 795 | * have a single element, the lone sub-object. |
Bob Moore | e5f69d6 | 2009-07-24 11:03:09 +0800 | [diff] [blame] | 796 | */ |
| 797 | pkg_obj_desc = acpi_ut_create_package_object(1); |
| 798 | if (!pkg_obj_desc) { |
| 799 | return (AE_NO_MEMORY); |
| 800 | } |
| 801 | |
Bob Moore | 6a99b1c | 2012-03-21 09:51:39 +0800 | [diff] [blame] | 802 | pkg_obj_desc->package.elements[0] = original_object; |
| 803 | |
| 804 | ACPI_DEBUG_PRINT((ACPI_DB_REPAIR, |
| 805 | "%s: Wrapped %s with expected Package object\n", |
| 806 | data->pathname, |
| 807 | acpi_ut_get_object_type_name(original_object))); |
Bob Moore | e5f69d6 | 2009-07-24 11:03:09 +0800 | [diff] [blame] | 808 | |
| 809 | /* Return the new object in the object pointer */ |
| 810 | |
| 811 | *obj_desc_ptr = pkg_obj_desc; |
Bob Moore | 6a99b1c | 2012-03-21 09:51:39 +0800 | [diff] [blame] | 812 | data->flags |= ACPI_OBJECT_REPAIRED | ACPI_OBJECT_WRAPPED; |
Bob Moore | e5f69d6 | 2009-07-24 11:03:09 +0800 | [diff] [blame] | 813 | return (AE_OK); |
| 814 | } |