Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Module Name: nsrepair2 - Repair for objects returned by specific |
| 4 | * predefined methods |
| 5 | * |
| 6 | *****************************************************************************/ |
| 7 | |
| 8 | /* |
Bob Moore | 25f044e | 2013-01-25 05:38:56 +0000 | [diff] [blame] | 9 | * Copyright (C) 2000 - 2013, Intel Corp. |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 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> |
| 46 | #include "accommon.h" |
| 47 | #include "acnamesp.h" |
| 48 | |
| 49 | #define _COMPONENT ACPI_NAMESPACE |
| 50 | ACPI_MODULE_NAME("nsrepair2") |
| 51 | |
| 52 | /* |
| 53 | * Information structure and handler for ACPI predefined names that can |
| 54 | * be repaired on a per-name basis. |
| 55 | */ |
| 56 | typedef |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 57 | acpi_status(*acpi_repair_function) (struct acpi_evaluate_info * info, |
Lv Zheng | 3e8214e | 2012-12-19 05:37:15 +0000 | [diff] [blame] | 58 | union acpi_operand_object |
| 59 | **return_object_ptr); |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 60 | |
| 61 | typedef struct acpi_repair_info { |
| 62 | char name[ACPI_NAME_SIZE]; |
| 63 | acpi_repair_function repair_function; |
| 64 | |
| 65 | } acpi_repair_info; |
| 66 | |
| 67 | /* Local prototypes */ |
| 68 | |
Bob Moore | d5a3610 | 2013-03-08 09:23:03 +0000 | [diff] [blame] | 69 | static const struct acpi_repair_info *acpi_ns_match_complex_repair(struct |
| 70 | acpi_namespace_node |
| 71 | *node); |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 72 | |
| 73 | static acpi_status |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 74 | acpi_ns_repair_ALR(struct acpi_evaluate_info *info, |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 75 | union acpi_operand_object **return_object_ptr); |
| 76 | |
| 77 | static acpi_status |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 78 | acpi_ns_repair_CID(struct acpi_evaluate_info *info, |
Bob Moore | 77b23f712 | 2010-09-15 14:11:02 +0800 | [diff] [blame] | 79 | union acpi_operand_object **return_object_ptr); |
| 80 | |
| 81 | static acpi_status |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 82 | acpi_ns_repair_FDE(struct acpi_evaluate_info *info, |
Bob Moore | 34c39c7 | 2009-12-11 14:53:11 +0800 | [diff] [blame] | 83 | union acpi_operand_object **return_object_ptr); |
| 84 | |
| 85 | static acpi_status |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 86 | acpi_ns_repair_HID(struct acpi_evaluate_info *info, |
Bob Moore | 77b23f712 | 2010-09-15 14:11:02 +0800 | [diff] [blame] | 87 | union acpi_operand_object **return_object_ptr); |
| 88 | |
| 89 | static acpi_status |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 90 | acpi_ns_repair_PSS(struct acpi_evaluate_info *info, |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 91 | union acpi_operand_object **return_object_ptr); |
| 92 | |
| 93 | static acpi_status |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 94 | acpi_ns_repair_TSS(struct acpi_evaluate_info *info, |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 95 | union acpi_operand_object **return_object_ptr); |
| 96 | |
| 97 | static acpi_status |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 98 | acpi_ns_check_sorted_list(struct acpi_evaluate_info *info, |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 99 | union acpi_operand_object *return_object, |
| 100 | u32 expected_count, |
| 101 | u32 sort_index, |
| 102 | u8 sort_direction, char *sort_key_name); |
| 103 | |
Bob Moore | 2147d3f | 2010-01-21 09:08:31 +0800 | [diff] [blame] | 104 | static void |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 105 | acpi_ns_sort_list(union acpi_operand_object **elements, |
| 106 | u32 count, u32 index, u8 sort_direction); |
| 107 | |
| 108 | /* Values for sort_direction above */ |
| 109 | |
| 110 | #define ACPI_SORT_ASCENDING 0 |
| 111 | #define ACPI_SORT_DESCENDING 1 |
| 112 | |
| 113 | /* |
| 114 | * This table contains the names of the predefined methods for which we can |
| 115 | * perform more complex repairs. |
| 116 | * |
Bob Moore | 34c39c7 | 2009-12-11 14:53:11 +0800 | [diff] [blame] | 117 | * As necessary: |
| 118 | * |
| 119 | * _ALR: Sort the list ascending by ambient_illuminance |
Bob Moore | 77b23f712 | 2010-09-15 14:11:02 +0800 | [diff] [blame] | 120 | * _CID: Strings: uppercase all, remove any leading asterisk |
Bob Moore | 43420bb | 2009-12-11 15:24:27 +0800 | [diff] [blame] | 121 | * _FDE: Convert Buffer of BYTEs to a Buffer of DWORDs |
| 122 | * _GTM: Convert Buffer of BYTEs to a Buffer of DWORDs |
Bob Moore | 77b23f712 | 2010-09-15 14:11:02 +0800 | [diff] [blame] | 123 | * _HID: Strings: uppercase all, remove any leading asterisk |
Bob Moore | 34c39c7 | 2009-12-11 14:53:11 +0800 | [diff] [blame] | 124 | * _PSS: Sort the list descending by Power |
| 125 | * _TSS: Sort the list descending by Power |
Bob Moore | aa9d360 | 2010-05-26 11:03:56 +0800 | [diff] [blame] | 126 | * |
| 127 | * Names that must be packages, but cannot be sorted: |
| 128 | * |
| 129 | * _BCL: Values are tied to the Package index where they appear, and cannot |
| 130 | * be moved or sorted. These index values are used for _BQC and _BCM. |
| 131 | * However, we can fix the case where a buffer is returned, by converting |
| 132 | * it to a Package of integers. |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 133 | */ |
| 134 | static const struct acpi_repair_info acpi_ns_repairable_names[] = { |
| 135 | {"_ALR", acpi_ns_repair_ALR}, |
Bob Moore | 77b23f712 | 2010-09-15 14:11:02 +0800 | [diff] [blame] | 136 | {"_CID", acpi_ns_repair_CID}, |
Bob Moore | 34c39c7 | 2009-12-11 14:53:11 +0800 | [diff] [blame] | 137 | {"_FDE", acpi_ns_repair_FDE}, |
| 138 | {"_GTM", acpi_ns_repair_FDE}, /* _GTM has same repair as _FDE */ |
Bob Moore | 77b23f712 | 2010-09-15 14:11:02 +0800 | [diff] [blame] | 139 | {"_HID", acpi_ns_repair_HID}, |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 140 | {"_PSS", acpi_ns_repair_PSS}, |
| 141 | {"_TSS", acpi_ns_repair_TSS}, |
| 142 | {{0, 0, 0, 0}, NULL} /* Table terminator */ |
| 143 | }; |
| 144 | |
Bob Moore | 34c39c7 | 2009-12-11 14:53:11 +0800 | [diff] [blame] | 145 | #define ACPI_FDE_FIELD_COUNT 5 |
| 146 | #define ACPI_FDE_BYTE_BUFFER_SIZE 5 |
| 147 | #define ACPI_FDE_DWORD_BUFFER_SIZE (ACPI_FDE_FIELD_COUNT * sizeof (u32)) |
| 148 | |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 149 | /****************************************************************************** |
| 150 | * |
| 151 | * FUNCTION: acpi_ns_complex_repairs |
| 152 | * |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 153 | * PARAMETERS: info - Method execution information block |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 154 | * node - Namespace node for the method/object |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 155 | * validate_status - Original status of earlier validation |
| 156 | * return_object_ptr - Pointer to the object returned from the |
| 157 | * evaluation of a method or object |
| 158 | * |
| 159 | * RETURN: Status. AE_OK if repair was successful. If name is not |
| 160 | * matched, validate_status is returned. |
| 161 | * |
| 162 | * DESCRIPTION: Attempt to repair/convert a return object of a type that was |
| 163 | * not expected. |
| 164 | * |
| 165 | *****************************************************************************/ |
| 166 | |
| 167 | acpi_status |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 168 | acpi_ns_complex_repairs(struct acpi_evaluate_info *info, |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 169 | struct acpi_namespace_node *node, |
| 170 | acpi_status validate_status, |
| 171 | union acpi_operand_object **return_object_ptr) |
| 172 | { |
| 173 | const struct acpi_repair_info *predefined; |
| 174 | acpi_status status; |
| 175 | |
| 176 | /* Check if this name is in the list of repairable names */ |
| 177 | |
Bob Moore | d5a3610 | 2013-03-08 09:23:03 +0000 | [diff] [blame] | 178 | predefined = acpi_ns_match_complex_repair(node); |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 179 | if (!predefined) { |
| 180 | return (validate_status); |
| 181 | } |
| 182 | |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 183 | status = predefined->repair_function(info, return_object_ptr); |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 184 | return (status); |
| 185 | } |
| 186 | |
| 187 | /****************************************************************************** |
| 188 | * |
Bob Moore | d5a3610 | 2013-03-08 09:23:03 +0000 | [diff] [blame] | 189 | * FUNCTION: acpi_ns_match_complex_repair |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 190 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 191 | * PARAMETERS: node - Namespace node for the method/object |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 192 | * |
| 193 | * RETURN: Pointer to entry in repair table. NULL indicates not found. |
| 194 | * |
| 195 | * DESCRIPTION: Check an object name against the repairable object list. |
| 196 | * |
| 197 | *****************************************************************************/ |
| 198 | |
Bob Moore | d5a3610 | 2013-03-08 09:23:03 +0000 | [diff] [blame] | 199 | static const struct acpi_repair_info *acpi_ns_match_complex_repair(struct |
| 200 | acpi_namespace_node |
| 201 | *node) |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 202 | { |
| 203 | const struct acpi_repair_info *this_name; |
| 204 | |
| 205 | /* Search info table for a repairable predefined method/object name */ |
| 206 | |
| 207 | this_name = acpi_ns_repairable_names; |
| 208 | while (this_name->repair_function) { |
| 209 | if (ACPI_COMPARE_NAME(node->name.ascii, this_name->name)) { |
| 210 | return (this_name); |
| 211 | } |
| 212 | this_name++; |
| 213 | } |
| 214 | |
| 215 | return (NULL); /* Not found */ |
| 216 | } |
| 217 | |
| 218 | /****************************************************************************** |
| 219 | * |
| 220 | * FUNCTION: acpi_ns_repair_ALR |
| 221 | * |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 222 | * PARAMETERS: info - Method execution information block |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 223 | * return_object_ptr - Pointer to the object returned from the |
| 224 | * evaluation of a method or object |
| 225 | * |
| 226 | * RETURN: Status. AE_OK if object is OK or was repaired successfully |
| 227 | * |
| 228 | * DESCRIPTION: Repair for the _ALR object. If necessary, sort the object list |
| 229 | * ascending by the ambient illuminance values. |
| 230 | * |
| 231 | *****************************************************************************/ |
| 232 | |
| 233 | static acpi_status |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 234 | acpi_ns_repair_ALR(struct acpi_evaluate_info *info, |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 235 | union acpi_operand_object **return_object_ptr) |
| 236 | { |
| 237 | union acpi_operand_object *return_object = *return_object_ptr; |
| 238 | acpi_status status; |
| 239 | |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 240 | status = acpi_ns_check_sorted_list(info, return_object, 2, 1, |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 241 | ACPI_SORT_ASCENDING, |
| 242 | "AmbientIlluminance"); |
| 243 | |
| 244 | return (status); |
| 245 | } |
| 246 | |
| 247 | /****************************************************************************** |
| 248 | * |
Bob Moore | 34c39c7 | 2009-12-11 14:53:11 +0800 | [diff] [blame] | 249 | * FUNCTION: acpi_ns_repair_FDE |
| 250 | * |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 251 | * PARAMETERS: info - Method execution information block |
Bob Moore | 34c39c7 | 2009-12-11 14:53:11 +0800 | [diff] [blame] | 252 | * return_object_ptr - Pointer to the object returned from the |
| 253 | * evaluation of a method or object |
| 254 | * |
| 255 | * RETURN: Status. AE_OK if object is OK or was repaired successfully |
| 256 | * |
| 257 | * DESCRIPTION: Repair for the _FDE and _GTM objects. The expected return |
Bob Moore | 43420bb | 2009-12-11 15:24:27 +0800 | [diff] [blame] | 258 | * value is a Buffer of 5 DWORDs. This function repairs a common |
| 259 | * problem where the return value is a Buffer of BYTEs, not |
| 260 | * DWORDs. |
Bob Moore | 34c39c7 | 2009-12-11 14:53:11 +0800 | [diff] [blame] | 261 | * |
| 262 | *****************************************************************************/ |
| 263 | |
| 264 | static acpi_status |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 265 | acpi_ns_repair_FDE(struct acpi_evaluate_info *info, |
Bob Moore | 34c39c7 | 2009-12-11 14:53:11 +0800 | [diff] [blame] | 266 | union acpi_operand_object **return_object_ptr) |
| 267 | { |
| 268 | union acpi_operand_object *return_object = *return_object_ptr; |
Bob Moore | 34c39c7 | 2009-12-11 14:53:11 +0800 | [diff] [blame] | 269 | union acpi_operand_object *buffer_object; |
| 270 | u8 *byte_buffer; |
| 271 | u32 *dword_buffer; |
Bob Moore | 34c39c7 | 2009-12-11 14:53:11 +0800 | [diff] [blame] | 272 | u32 i; |
| 273 | |
Bob Moore | 3a58176 | 2009-12-11 15:23:22 +0800 | [diff] [blame] | 274 | ACPI_FUNCTION_NAME(ns_repair_FDE); |
| 275 | |
Bob Moore | 34c39c7 | 2009-12-11 14:53:11 +0800 | [diff] [blame] | 276 | switch (return_object->common.type) { |
| 277 | case ACPI_TYPE_BUFFER: |
| 278 | |
| 279 | /* This is the expected type. Length should be (at least) 5 DWORDs */ |
| 280 | |
| 281 | if (return_object->buffer.length >= ACPI_FDE_DWORD_BUFFER_SIZE) { |
| 282 | return (AE_OK); |
| 283 | } |
| 284 | |
| 285 | /* We can only repair if we have exactly 5 BYTEs */ |
| 286 | |
| 287 | if (return_object->buffer.length != ACPI_FDE_BYTE_BUFFER_SIZE) { |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 288 | ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname, |
| 289 | info->node_flags, |
Bob Moore | 34c39c7 | 2009-12-11 14:53:11 +0800 | [diff] [blame] | 290 | "Incorrect return buffer length %u, expected %u", |
| 291 | return_object->buffer.length, |
| 292 | ACPI_FDE_DWORD_BUFFER_SIZE)); |
| 293 | |
| 294 | return (AE_AML_OPERAND_TYPE); |
| 295 | } |
| 296 | |
| 297 | /* Create the new (larger) buffer object */ |
| 298 | |
| 299 | buffer_object = |
| 300 | acpi_ut_create_buffer_object(ACPI_FDE_DWORD_BUFFER_SIZE); |
| 301 | if (!buffer_object) { |
| 302 | return (AE_NO_MEMORY); |
| 303 | } |
| 304 | |
| 305 | /* Expand each byte to a DWORD */ |
| 306 | |
| 307 | byte_buffer = return_object->buffer.pointer; |
| 308 | dword_buffer = |
| 309 | ACPI_CAST_PTR(u32, buffer_object->buffer.pointer); |
| 310 | |
| 311 | for (i = 0; i < ACPI_FDE_FIELD_COUNT; i++) { |
| 312 | *dword_buffer = (u32) *byte_buffer; |
| 313 | dword_buffer++; |
| 314 | byte_buffer++; |
| 315 | } |
| 316 | |
Bob Moore | 3a58176 | 2009-12-11 15:23:22 +0800 | [diff] [blame] | 317 | ACPI_DEBUG_PRINT((ACPI_DB_REPAIR, |
| 318 | "%s Expanded Byte Buffer to expected DWord Buffer\n", |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 319 | info->full_pathname)); |
Bob Moore | 34c39c7 | 2009-12-11 14:53:11 +0800 | [diff] [blame] | 320 | break; |
| 321 | |
Bob Moore | 34c39c7 | 2009-12-11 14:53:11 +0800 | [diff] [blame] | 322 | default: |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame^] | 323 | |
Bob Moore | 34c39c7 | 2009-12-11 14:53:11 +0800 | [diff] [blame] | 324 | return (AE_AML_OPERAND_TYPE); |
| 325 | } |
| 326 | |
| 327 | /* Delete the original return object, return the new buffer object */ |
| 328 | |
| 329 | acpi_ut_remove_reference(return_object); |
| 330 | *return_object_ptr = buffer_object; |
| 331 | |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 332 | info->return_flags |= ACPI_OBJECT_REPAIRED; |
Bob Moore | 34c39c7 | 2009-12-11 14:53:11 +0800 | [diff] [blame] | 333 | return (AE_OK); |
| 334 | } |
| 335 | |
| 336 | /****************************************************************************** |
| 337 | * |
Bob Moore | 77b23f712 | 2010-09-15 14:11:02 +0800 | [diff] [blame] | 338 | * FUNCTION: acpi_ns_repair_CID |
| 339 | * |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 340 | * PARAMETERS: info - Method execution information block |
Bob Moore | 77b23f712 | 2010-09-15 14:11:02 +0800 | [diff] [blame] | 341 | * return_object_ptr - Pointer to the object returned from the |
| 342 | * evaluation of a method or object |
| 343 | * |
| 344 | * RETURN: Status. AE_OK if object is OK or was repaired successfully |
| 345 | * |
| 346 | * DESCRIPTION: Repair for the _CID object. If a string, ensure that all |
| 347 | * letters are uppercase and that there is no leading asterisk. |
| 348 | * If a Package, ensure same for all string elements. |
| 349 | * |
| 350 | *****************************************************************************/ |
| 351 | |
| 352 | static acpi_status |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 353 | acpi_ns_repair_CID(struct acpi_evaluate_info *info, |
Bob Moore | 77b23f712 | 2010-09-15 14:11:02 +0800 | [diff] [blame] | 354 | union acpi_operand_object **return_object_ptr) |
| 355 | { |
| 356 | acpi_status status; |
| 357 | union acpi_operand_object *return_object = *return_object_ptr; |
| 358 | union acpi_operand_object **element_ptr; |
| 359 | union acpi_operand_object *original_element; |
| 360 | u16 original_ref_count; |
| 361 | u32 i; |
| 362 | |
| 363 | /* Check for _CID as a simple string */ |
| 364 | |
| 365 | if (return_object->common.type == ACPI_TYPE_STRING) { |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 366 | status = acpi_ns_repair_HID(info, return_object_ptr); |
Bob Moore | 77b23f712 | 2010-09-15 14:11:02 +0800 | [diff] [blame] | 367 | return (status); |
| 368 | } |
| 369 | |
| 370 | /* Exit if not a Package */ |
| 371 | |
| 372 | if (return_object->common.type != ACPI_TYPE_PACKAGE) { |
| 373 | return (AE_OK); |
| 374 | } |
| 375 | |
| 376 | /* Examine each element of the _CID package */ |
| 377 | |
| 378 | element_ptr = return_object->package.elements; |
| 379 | for (i = 0; i < return_object->package.count; i++) { |
| 380 | original_element = *element_ptr; |
| 381 | original_ref_count = original_element->common.reference_count; |
| 382 | |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 383 | status = acpi_ns_repair_HID(info, element_ptr); |
Bob Moore | 77b23f712 | 2010-09-15 14:11:02 +0800 | [diff] [blame] | 384 | if (ACPI_FAILURE(status)) { |
| 385 | return (status); |
| 386 | } |
| 387 | |
| 388 | /* Take care with reference counts */ |
| 389 | |
| 390 | if (original_element != *element_ptr) { |
| 391 | |
| 392 | /* Element was replaced */ |
| 393 | |
| 394 | (*element_ptr)->common.reference_count = |
| 395 | original_ref_count; |
| 396 | |
| 397 | acpi_ut_remove_reference(original_element); |
| 398 | } |
| 399 | |
| 400 | element_ptr++; |
| 401 | } |
| 402 | |
| 403 | return (AE_OK); |
| 404 | } |
| 405 | |
| 406 | /****************************************************************************** |
| 407 | * |
| 408 | * FUNCTION: acpi_ns_repair_HID |
| 409 | * |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 410 | * PARAMETERS: info - Method execution information block |
Bob Moore | 77b23f712 | 2010-09-15 14:11:02 +0800 | [diff] [blame] | 411 | * return_object_ptr - Pointer to the object returned from the |
| 412 | * evaluation of a method or object |
| 413 | * |
| 414 | * RETURN: Status. AE_OK if object is OK or was repaired successfully |
| 415 | * |
| 416 | * DESCRIPTION: Repair for the _HID object. If a string, ensure that all |
| 417 | * letters are uppercase and that there is no leading asterisk. |
| 418 | * |
| 419 | *****************************************************************************/ |
| 420 | |
| 421 | static acpi_status |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 422 | acpi_ns_repair_HID(struct acpi_evaluate_info *info, |
Bob Moore | 77b23f712 | 2010-09-15 14:11:02 +0800 | [diff] [blame] | 423 | union acpi_operand_object **return_object_ptr) |
| 424 | { |
| 425 | union acpi_operand_object *return_object = *return_object_ptr; |
| 426 | union acpi_operand_object *new_string; |
| 427 | char *source; |
| 428 | char *dest; |
| 429 | |
| 430 | ACPI_FUNCTION_NAME(ns_repair_HID); |
| 431 | |
| 432 | /* We only care about string _HID objects (not integers) */ |
| 433 | |
| 434 | if (return_object->common.type != ACPI_TYPE_STRING) { |
| 435 | return (AE_OK); |
| 436 | } |
| 437 | |
| 438 | if (return_object->string.length == 0) { |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 439 | ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname, |
| 440 | info->node_flags, |
Bob Moore | 77b23f712 | 2010-09-15 14:11:02 +0800 | [diff] [blame] | 441 | "Invalid zero-length _HID or _CID string")); |
| 442 | |
| 443 | /* Return AE_OK anyway, let driver handle it */ |
| 444 | |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 445 | info->return_flags |= ACPI_OBJECT_REPAIRED; |
Bob Moore | 77b23f712 | 2010-09-15 14:11:02 +0800 | [diff] [blame] | 446 | return (AE_OK); |
| 447 | } |
| 448 | |
| 449 | /* It is simplest to always create a new string object */ |
| 450 | |
| 451 | new_string = acpi_ut_create_string_object(return_object->string.length); |
| 452 | if (!new_string) { |
| 453 | return (AE_NO_MEMORY); |
| 454 | } |
| 455 | |
| 456 | /* |
| 457 | * Remove a leading asterisk if present. For some unknown reason, there |
| 458 | * are many machines in the field that contains IDs like this. |
| 459 | * |
| 460 | * Examples: "*PNP0C03", "*ACPI0003" |
| 461 | */ |
| 462 | source = return_object->string.pointer; |
| 463 | if (*source == '*') { |
| 464 | source++; |
| 465 | new_string->string.length--; |
| 466 | |
| 467 | ACPI_DEBUG_PRINT((ACPI_DB_REPAIR, |
| 468 | "%s: Removed invalid leading asterisk\n", |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 469 | info->full_pathname)); |
Bob Moore | 77b23f712 | 2010-09-15 14:11:02 +0800 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | /* |
Bob Moore | 7fce7a4 | 2011-11-16 14:59:17 +0800 | [diff] [blame] | 473 | * Copy and uppercase the string. From the ACPI 5.0 specification: |
Bob Moore | 77b23f712 | 2010-09-15 14:11:02 +0800 | [diff] [blame] | 474 | * |
| 475 | * A valid PNP ID must be of the form "AAA####" where A is an uppercase |
| 476 | * letter and # is a hex digit. A valid ACPI ID must be of the form |
Bob Moore | 7fce7a4 | 2011-11-16 14:59:17 +0800 | [diff] [blame] | 477 | * "NNNN####" where N is an uppercase letter or decimal digit, and |
| 478 | * # is a hex digit. |
Bob Moore | 77b23f712 | 2010-09-15 14:11:02 +0800 | [diff] [blame] | 479 | */ |
| 480 | for (dest = new_string->string.pointer; *source; dest++, source++) { |
| 481 | *dest = (char)ACPI_TOUPPER(*source); |
| 482 | } |
| 483 | |
| 484 | acpi_ut_remove_reference(return_object); |
| 485 | *return_object_ptr = new_string; |
| 486 | return (AE_OK); |
| 487 | } |
| 488 | |
| 489 | /****************************************************************************** |
| 490 | * |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 491 | * FUNCTION: acpi_ns_repair_TSS |
| 492 | * |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 493 | * PARAMETERS: info - Method execution information block |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 494 | * return_object_ptr - Pointer to the object returned from the |
| 495 | * evaluation of a method or object |
| 496 | * |
| 497 | * RETURN: Status. AE_OK if object is OK or was repaired successfully |
| 498 | * |
| 499 | * DESCRIPTION: Repair for the _TSS object. If necessary, sort the object list |
| 500 | * descending by the power dissipation values. |
| 501 | * |
| 502 | *****************************************************************************/ |
| 503 | |
| 504 | static acpi_status |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 505 | acpi_ns_repair_TSS(struct acpi_evaluate_info *info, |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 506 | union acpi_operand_object **return_object_ptr) |
| 507 | { |
| 508 | union acpi_operand_object *return_object = *return_object_ptr; |
| 509 | acpi_status status; |
Fenghua Yu | 8f9c912 | 2011-07-04 08:36:16 +0000 | [diff] [blame] | 510 | struct acpi_namespace_node *node; |
| 511 | |
| 512 | /* |
| 513 | * We can only sort the _TSS return package if there is no _PSS in the |
| 514 | * same scope. This is because if _PSS is present, the ACPI specification |
| 515 | * dictates that the _TSS Power Dissipation field is to be ignored, and |
| 516 | * therefore some BIOSs leave garbage values in the _TSS Power field(s). |
| 517 | * In this case, it is best to just return the _TSS package as-is. |
| 518 | * (May, 2011) |
| 519 | */ |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 520 | status = acpi_ns_get_node(info->node, "^_PSS", |
| 521 | ACPI_NS_NO_UPSEARCH, &node); |
Fenghua Yu | 8f9c912 | 2011-07-04 08:36:16 +0000 | [diff] [blame] | 522 | if (ACPI_SUCCESS(status)) { |
| 523 | return (AE_OK); |
| 524 | } |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 525 | |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 526 | status = acpi_ns_check_sorted_list(info, return_object, 5, 1, |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 527 | ACPI_SORT_DESCENDING, |
| 528 | "PowerDissipation"); |
| 529 | |
| 530 | return (status); |
| 531 | } |
| 532 | |
| 533 | /****************************************************************************** |
| 534 | * |
| 535 | * FUNCTION: acpi_ns_repair_PSS |
| 536 | * |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 537 | * PARAMETERS: info - Method execution information block |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 538 | * return_object_ptr - Pointer to the object returned from the |
| 539 | * evaluation of a method or object |
| 540 | * |
| 541 | * RETURN: Status. AE_OK if object is OK or was repaired successfully |
| 542 | * |
| 543 | * DESCRIPTION: Repair for the _PSS object. If necessary, sort the object list |
| 544 | * by the CPU frequencies. Check that the power dissipation values |
| 545 | * are all proportional to CPU frequency (i.e., sorting by |
| 546 | * frequency should be the same as sorting by power.) |
| 547 | * |
| 548 | *****************************************************************************/ |
| 549 | |
| 550 | static acpi_status |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 551 | acpi_ns_repair_PSS(struct acpi_evaluate_info *info, |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 552 | union acpi_operand_object **return_object_ptr) |
| 553 | { |
| 554 | union acpi_operand_object *return_object = *return_object_ptr; |
| 555 | union acpi_operand_object **outer_elements; |
| 556 | u32 outer_element_count; |
| 557 | union acpi_operand_object **elements; |
| 558 | union acpi_operand_object *obj_desc; |
| 559 | u32 previous_value; |
| 560 | acpi_status status; |
| 561 | u32 i; |
| 562 | |
| 563 | /* |
| 564 | * Entries (sub-packages) in the _PSS Package must be sorted by power |
| 565 | * dissipation, in descending order. If it appears that the list is |
| 566 | * incorrectly sorted, sort it. We sort by cpu_frequency, since this |
| 567 | * should be proportional to the power. |
| 568 | */ |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 569 | status = acpi_ns_check_sorted_list(info, return_object, 6, 0, |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 570 | ACPI_SORT_DESCENDING, |
| 571 | "CpuFrequency"); |
| 572 | if (ACPI_FAILURE(status)) { |
| 573 | return (status); |
| 574 | } |
| 575 | |
| 576 | /* |
| 577 | * We now know the list is correctly sorted by CPU frequency. Check if |
| 578 | * the power dissipation values are proportional. |
| 579 | */ |
| 580 | previous_value = ACPI_UINT32_MAX; |
| 581 | outer_elements = return_object->package.elements; |
| 582 | outer_element_count = return_object->package.count; |
| 583 | |
| 584 | for (i = 0; i < outer_element_count; i++) { |
| 585 | elements = (*outer_elements)->package.elements; |
| 586 | obj_desc = elements[1]; /* Index1 = power_dissipation */ |
| 587 | |
| 588 | if ((u32) obj_desc->integer.value > previous_value) { |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 589 | ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname, |
| 590 | info->node_flags, |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 591 | "SubPackage[%u,%u] - suspicious power dissipation values", |
| 592 | i - 1, i)); |
| 593 | } |
| 594 | |
| 595 | previous_value = (u32) obj_desc->integer.value; |
| 596 | outer_elements++; |
| 597 | } |
| 598 | |
| 599 | return (AE_OK); |
| 600 | } |
| 601 | |
| 602 | /****************************************************************************** |
| 603 | * |
| 604 | * FUNCTION: acpi_ns_check_sorted_list |
| 605 | * |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 606 | * PARAMETERS: info - Method execution information block |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 607 | * return_object - Pointer to the top-level returned object |
| 608 | * expected_count - Minimum length of each sub-package |
| 609 | * sort_index - Sub-package entry to sort on |
| 610 | * sort_direction - Ascending or descending |
| 611 | * sort_key_name - Name of the sort_index field |
| 612 | * |
| 613 | * RETURN: Status. AE_OK if the list is valid and is sorted correctly or |
| 614 | * has been repaired by sorting the list. |
| 615 | * |
| 616 | * DESCRIPTION: Check if the package list is valid and sorted correctly by the |
| 617 | * sort_index. If not, then sort the list. |
| 618 | * |
| 619 | *****************************************************************************/ |
| 620 | |
| 621 | static acpi_status |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 622 | acpi_ns_check_sorted_list(struct acpi_evaluate_info *info, |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 623 | union acpi_operand_object *return_object, |
| 624 | u32 expected_count, |
| 625 | u32 sort_index, |
| 626 | u8 sort_direction, char *sort_key_name) |
| 627 | { |
| 628 | u32 outer_element_count; |
| 629 | union acpi_operand_object **outer_elements; |
| 630 | union acpi_operand_object **elements; |
| 631 | union acpi_operand_object *obj_desc; |
| 632 | u32 i; |
| 633 | u32 previous_value; |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 634 | |
Bob Moore | 3a58176 | 2009-12-11 15:23:22 +0800 | [diff] [blame] | 635 | ACPI_FUNCTION_NAME(ns_check_sorted_list); |
| 636 | |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 637 | /* The top-level object must be a package */ |
| 638 | |
| 639 | if (return_object->common.type != ACPI_TYPE_PACKAGE) { |
| 640 | return (AE_AML_OPERAND_TYPE); |
| 641 | } |
| 642 | |
| 643 | /* |
Bob Moore | d4085a3f | 2009-12-11 15:29:44 +0800 | [diff] [blame] | 644 | * NOTE: assumes list of sub-packages contains no NULL elements. |
| 645 | * Any NULL elements should have been removed by earlier call |
| 646 | * to acpi_ns_remove_null_elements. |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 647 | */ |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 648 | outer_elements = return_object->package.elements; |
| 649 | outer_element_count = return_object->package.count; |
| 650 | if (!outer_element_count) { |
| 651 | return (AE_AML_PACKAGE_LIMIT); |
| 652 | } |
| 653 | |
| 654 | previous_value = 0; |
| 655 | if (sort_direction == ACPI_SORT_DESCENDING) { |
| 656 | previous_value = ACPI_UINT32_MAX; |
| 657 | } |
| 658 | |
| 659 | /* Examine each subpackage */ |
| 660 | |
| 661 | for (i = 0; i < outer_element_count; i++) { |
| 662 | |
| 663 | /* Each element of the top-level package must also be a package */ |
| 664 | |
| 665 | if ((*outer_elements)->common.type != ACPI_TYPE_PACKAGE) { |
| 666 | return (AE_AML_OPERAND_TYPE); |
| 667 | } |
| 668 | |
| 669 | /* Each sub-package must have the minimum length */ |
| 670 | |
| 671 | if ((*outer_elements)->package.count < expected_count) { |
| 672 | return (AE_AML_PACKAGE_LIMIT); |
| 673 | } |
| 674 | |
| 675 | elements = (*outer_elements)->package.elements; |
| 676 | obj_desc = elements[sort_index]; |
| 677 | |
| 678 | if (obj_desc->common.type != ACPI_TYPE_INTEGER) { |
| 679 | return (AE_AML_OPERAND_TYPE); |
| 680 | } |
| 681 | |
| 682 | /* |
| 683 | * The list must be sorted in the specified order. If we detect a |
Bob Moore | 2147d3f | 2010-01-21 09:08:31 +0800 | [diff] [blame] | 684 | * discrepancy, sort the entire list. |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 685 | */ |
| 686 | if (((sort_direction == ACPI_SORT_ASCENDING) && |
| 687 | (obj_desc->integer.value < previous_value)) || |
| 688 | ((sort_direction == ACPI_SORT_DESCENDING) && |
| 689 | (obj_desc->integer.value > previous_value))) { |
Bob Moore | 2147d3f | 2010-01-21 09:08:31 +0800 | [diff] [blame] | 690 | acpi_ns_sort_list(return_object->package.elements, |
| 691 | outer_element_count, sort_index, |
| 692 | sort_direction); |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 693 | |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 694 | info->return_flags |= ACPI_OBJECT_REPAIRED; |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 695 | |
Bob Moore | 3a58176 | 2009-12-11 15:23:22 +0800 | [diff] [blame] | 696 | ACPI_DEBUG_PRINT((ACPI_DB_REPAIR, |
| 697 | "%s: Repaired unsorted list - now sorted by %s\n", |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 698 | info->full_pathname, sort_key_name)); |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 699 | return (AE_OK); |
| 700 | } |
| 701 | |
| 702 | previous_value = (u32) obj_desc->integer.value; |
| 703 | outer_elements++; |
| 704 | } |
| 705 | |
| 706 | return (AE_OK); |
| 707 | } |
| 708 | |
| 709 | /****************************************************************************** |
| 710 | * |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 711 | * FUNCTION: acpi_ns_sort_list |
| 712 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 713 | * PARAMETERS: elements - Package object element list |
| 714 | * count - Element count for above |
| 715 | * index - Sort by which package element |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 716 | * sort_direction - Ascending or Descending sort |
| 717 | * |
Bob Moore | 2147d3f | 2010-01-21 09:08:31 +0800 | [diff] [blame] | 718 | * RETURN: None |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 719 | * |
| 720 | * DESCRIPTION: Sort the objects that are in a package element list. |
| 721 | * |
Bob Moore | 2147d3f | 2010-01-21 09:08:31 +0800 | [diff] [blame] | 722 | * NOTE: Assumes that all NULL elements have been removed from the package, |
| 723 | * and that all elements have been verified to be of type Integer. |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 724 | * |
| 725 | *****************************************************************************/ |
| 726 | |
Bob Moore | 2147d3f | 2010-01-21 09:08:31 +0800 | [diff] [blame] | 727 | static void |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 728 | acpi_ns_sort_list(union acpi_operand_object **elements, |
| 729 | u32 count, u32 index, u8 sort_direction) |
| 730 | { |
| 731 | union acpi_operand_object *obj_desc1; |
| 732 | union acpi_operand_object *obj_desc2; |
| 733 | union acpi_operand_object *temp_obj; |
| 734 | u32 i; |
| 735 | u32 j; |
| 736 | |
| 737 | /* Simple bubble sort */ |
| 738 | |
| 739 | for (i = 1; i < count; i++) { |
| 740 | for (j = (count - 1); j >= i; j--) { |
| 741 | obj_desc1 = elements[j - 1]->package.elements[index]; |
| 742 | obj_desc2 = elements[j]->package.elements[index]; |
| 743 | |
| 744 | if (((sort_direction == ACPI_SORT_ASCENDING) && |
| 745 | (obj_desc1->integer.value > |
| 746 | obj_desc2->integer.value)) |
| 747 | || ((sort_direction == ACPI_SORT_DESCENDING) |
| 748 | && (obj_desc1->integer.value < |
| 749 | obj_desc2->integer.value))) { |
| 750 | temp_obj = elements[j - 1]; |
| 751 | elements[j - 1] = elements[j]; |
| 752 | elements[j] = temp_obj; |
| 753 | } |
| 754 | } |
| 755 | } |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 756 | } |