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 | c8100dc | 2016-01-15 08:17:03 +0800 | [diff] [blame] | 9 | * Copyright (C) 2000 - 2016, 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 |
Lv Zheng | f5c1e1c | 2016-05-05 12:57:53 +0800 | [diff] [blame] | 57 | acpi_status (*acpi_repair_function) (struct acpi_evaluate_info * info, |
| 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 |
Lv Zheng | 5a9792f | 2013-06-08 09:01:07 +0800 | [diff] [blame] | 82 | acpi_ns_repair_CST(struct acpi_evaluate_info *info, |
| 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_FDE(struct acpi_evaluate_info *info, |
Bob Moore | 34c39c7 | 2009-12-11 14:53:11 +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_HID(struct acpi_evaluate_info *info, |
Bob Moore | 77b23f712 | 2010-09-15 14:11:02 +0800 | [diff] [blame] | 91 | union acpi_operand_object **return_object_ptr); |
| 92 | |
| 93 | static acpi_status |
Lv Zheng | aa6329c | 2013-06-08 09:01:01 +0800 | [diff] [blame] | 94 | acpi_ns_repair_PRT(struct acpi_evaluate_info *info, |
| 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_repair_PSS(struct acpi_evaluate_info *info, |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 99 | union acpi_operand_object **return_object_ptr); |
| 100 | |
| 101 | static acpi_status |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 102 | acpi_ns_repair_TSS(struct acpi_evaluate_info *info, |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 103 | union acpi_operand_object **return_object_ptr); |
| 104 | |
| 105 | static acpi_status |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 106 | acpi_ns_check_sorted_list(struct acpi_evaluate_info *info, |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 107 | union acpi_operand_object *return_object, |
Lv Zheng | 5a9792f | 2013-06-08 09:01:07 +0800 | [diff] [blame] | 108 | u32 start_index, |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 109 | u32 expected_count, |
| 110 | u32 sort_index, |
| 111 | u8 sort_direction, char *sort_key_name); |
| 112 | |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 113 | /* Values for sort_direction above */ |
| 114 | |
| 115 | #define ACPI_SORT_ASCENDING 0 |
| 116 | #define ACPI_SORT_DESCENDING 1 |
| 117 | |
Lv Zheng | 5a9792f | 2013-06-08 09:01:07 +0800 | [diff] [blame] | 118 | static void |
| 119 | acpi_ns_remove_element(union acpi_operand_object *obj_desc, u32 index); |
| 120 | |
| 121 | static void |
| 122 | acpi_ns_sort_list(union acpi_operand_object **elements, |
| 123 | u32 count, u32 index, u8 sort_direction); |
| 124 | |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 125 | /* |
| 126 | * This table contains the names of the predefined methods for which we can |
| 127 | * perform more complex repairs. |
| 128 | * |
Bob Moore | 34c39c7 | 2009-12-11 14:53:11 +0800 | [diff] [blame] | 129 | * As necessary: |
| 130 | * |
| 131 | * _ALR: Sort the list ascending by ambient_illuminance |
Bob Moore | 77b23f712 | 2010-09-15 14:11:02 +0800 | [diff] [blame] | 132 | * _CID: Strings: uppercase all, remove any leading asterisk |
Lv Zheng | 5a9792f | 2013-06-08 09:01:07 +0800 | [diff] [blame] | 133 | * _CST: Sort the list ascending by C state type |
Bob Moore | 43420bb | 2009-12-11 15:24:27 +0800 | [diff] [blame] | 134 | * _FDE: Convert Buffer of BYTEs to a Buffer of DWORDs |
| 135 | * _GTM: Convert Buffer of BYTEs to a Buffer of DWORDs |
Bob Moore | 77b23f712 | 2010-09-15 14:11:02 +0800 | [diff] [blame] | 136 | * _HID: Strings: uppercase all, remove any leading asterisk |
Lv Zheng | aa6329c | 2013-06-08 09:01:01 +0800 | [diff] [blame] | 137 | * _PRT: Fix reversed source_name and source_index |
Bob Moore | 34c39c7 | 2009-12-11 14:53:11 +0800 | [diff] [blame] | 138 | * _PSS: Sort the list descending by Power |
| 139 | * _TSS: Sort the list descending by Power |
Bob Moore | aa9d360 | 2010-05-26 11:03:56 +0800 | [diff] [blame] | 140 | * |
| 141 | * Names that must be packages, but cannot be sorted: |
| 142 | * |
| 143 | * _BCL: Values are tied to the Package index where they appear, and cannot |
| 144 | * be moved or sorted. These index values are used for _BQC and _BCM. |
| 145 | * However, we can fix the case where a buffer is returned, by converting |
| 146 | * it to a Package of integers. |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 147 | */ |
| 148 | static const struct acpi_repair_info acpi_ns_repairable_names[] = { |
| 149 | {"_ALR", acpi_ns_repair_ALR}, |
Bob Moore | 77b23f712 | 2010-09-15 14:11:02 +0800 | [diff] [blame] | 150 | {"_CID", acpi_ns_repair_CID}, |
Lv Zheng | 5a9792f | 2013-06-08 09:01:07 +0800 | [diff] [blame] | 151 | {"_CST", acpi_ns_repair_CST}, |
Bob Moore | 34c39c7 | 2009-12-11 14:53:11 +0800 | [diff] [blame] | 152 | {"_FDE", acpi_ns_repair_FDE}, |
| 153 | {"_GTM", acpi_ns_repair_FDE}, /* _GTM has same repair as _FDE */ |
Bob Moore | 77b23f712 | 2010-09-15 14:11:02 +0800 | [diff] [blame] | 154 | {"_HID", acpi_ns_repair_HID}, |
Lv Zheng | aa6329c | 2013-06-08 09:01:01 +0800 | [diff] [blame] | 155 | {"_PRT", acpi_ns_repair_PRT}, |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 156 | {"_PSS", acpi_ns_repair_PSS}, |
| 157 | {"_TSS", acpi_ns_repair_TSS}, |
| 158 | {{0, 0, 0, 0}, NULL} /* Table terminator */ |
| 159 | }; |
| 160 | |
Bob Moore | 34c39c7 | 2009-12-11 14:53:11 +0800 | [diff] [blame] | 161 | #define ACPI_FDE_FIELD_COUNT 5 |
| 162 | #define ACPI_FDE_BYTE_BUFFER_SIZE 5 |
| 163 | #define ACPI_FDE_DWORD_BUFFER_SIZE (ACPI_FDE_FIELD_COUNT * sizeof (u32)) |
| 164 | |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 165 | /****************************************************************************** |
| 166 | * |
| 167 | * FUNCTION: acpi_ns_complex_repairs |
| 168 | * |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 169 | * PARAMETERS: info - Method execution information block |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 170 | * node - Namespace node for the method/object |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 171 | * validate_status - Original status of earlier validation |
| 172 | * return_object_ptr - Pointer to the object returned from the |
| 173 | * evaluation of a method or object |
| 174 | * |
| 175 | * RETURN: Status. AE_OK if repair was successful. If name is not |
| 176 | * matched, validate_status is returned. |
| 177 | * |
| 178 | * DESCRIPTION: Attempt to repair/convert a return object of a type that was |
| 179 | * not expected. |
| 180 | * |
| 181 | *****************************************************************************/ |
| 182 | |
| 183 | acpi_status |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 184 | acpi_ns_complex_repairs(struct acpi_evaluate_info *info, |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 185 | struct acpi_namespace_node *node, |
| 186 | acpi_status validate_status, |
| 187 | union acpi_operand_object **return_object_ptr) |
| 188 | { |
| 189 | const struct acpi_repair_info *predefined; |
| 190 | acpi_status status; |
| 191 | |
| 192 | /* Check if this name is in the list of repairable names */ |
| 193 | |
Bob Moore | d5a3610 | 2013-03-08 09:23:03 +0000 | [diff] [blame] | 194 | predefined = acpi_ns_match_complex_repair(node); |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 195 | if (!predefined) { |
| 196 | return (validate_status); |
| 197 | } |
| 198 | |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 199 | status = predefined->repair_function(info, return_object_ptr); |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 200 | return (status); |
| 201 | } |
| 202 | |
| 203 | /****************************************************************************** |
| 204 | * |
Bob Moore | d5a3610 | 2013-03-08 09:23:03 +0000 | [diff] [blame] | 205 | * FUNCTION: acpi_ns_match_complex_repair |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 206 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 207 | * PARAMETERS: node - Namespace node for the method/object |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 208 | * |
| 209 | * RETURN: Pointer to entry in repair table. NULL indicates not found. |
| 210 | * |
| 211 | * DESCRIPTION: Check an object name against the repairable object list. |
| 212 | * |
| 213 | *****************************************************************************/ |
| 214 | |
Bob Moore | d5a3610 | 2013-03-08 09:23:03 +0000 | [diff] [blame] | 215 | static const struct acpi_repair_info *acpi_ns_match_complex_repair(struct |
| 216 | acpi_namespace_node |
| 217 | *node) |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 218 | { |
| 219 | const struct acpi_repair_info *this_name; |
| 220 | |
| 221 | /* Search info table for a repairable predefined method/object name */ |
| 222 | |
| 223 | this_name = acpi_ns_repairable_names; |
| 224 | while (this_name->repair_function) { |
| 225 | if (ACPI_COMPARE_NAME(node->name.ascii, this_name->name)) { |
| 226 | return (this_name); |
| 227 | } |
Bob Moore | 1fad873 | 2015-12-29 13:54:36 +0800 | [diff] [blame] | 228 | |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 229 | this_name++; |
| 230 | } |
| 231 | |
| 232 | return (NULL); /* Not found */ |
| 233 | } |
| 234 | |
| 235 | /****************************************************************************** |
| 236 | * |
| 237 | * FUNCTION: acpi_ns_repair_ALR |
| 238 | * |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 239 | * PARAMETERS: info - Method execution information block |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 240 | * return_object_ptr - Pointer to the object returned from the |
| 241 | * evaluation of a method or object |
| 242 | * |
| 243 | * RETURN: Status. AE_OK if object is OK or was repaired successfully |
| 244 | * |
| 245 | * DESCRIPTION: Repair for the _ALR object. If necessary, sort the object list |
| 246 | * ascending by the ambient illuminance values. |
| 247 | * |
| 248 | *****************************************************************************/ |
| 249 | |
| 250 | static acpi_status |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 251 | acpi_ns_repair_ALR(struct acpi_evaluate_info *info, |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 252 | union acpi_operand_object **return_object_ptr) |
| 253 | { |
| 254 | union acpi_operand_object *return_object = *return_object_ptr; |
| 255 | acpi_status status; |
| 256 | |
Lv Zheng | 5a9792f | 2013-06-08 09:01:07 +0800 | [diff] [blame] | 257 | status = acpi_ns_check_sorted_list(info, return_object, 0, 2, 1, |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 258 | ACPI_SORT_ASCENDING, |
| 259 | "AmbientIlluminance"); |
| 260 | |
| 261 | return (status); |
| 262 | } |
| 263 | |
| 264 | /****************************************************************************** |
| 265 | * |
Bob Moore | 34c39c7 | 2009-12-11 14:53:11 +0800 | [diff] [blame] | 266 | * FUNCTION: acpi_ns_repair_FDE |
| 267 | * |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 268 | * PARAMETERS: info - Method execution information block |
Bob Moore | 34c39c7 | 2009-12-11 14:53:11 +0800 | [diff] [blame] | 269 | * return_object_ptr - Pointer to the object returned from the |
| 270 | * evaluation of a method or object |
| 271 | * |
| 272 | * RETURN: Status. AE_OK if object is OK or was repaired successfully |
| 273 | * |
| 274 | * DESCRIPTION: Repair for the _FDE and _GTM objects. The expected return |
Bob Moore | 43420bb | 2009-12-11 15:24:27 +0800 | [diff] [blame] | 275 | * value is a Buffer of 5 DWORDs. This function repairs a common |
| 276 | * problem where the return value is a Buffer of BYTEs, not |
| 277 | * DWORDs. |
Bob Moore | 34c39c7 | 2009-12-11 14:53:11 +0800 | [diff] [blame] | 278 | * |
| 279 | *****************************************************************************/ |
| 280 | |
| 281 | static acpi_status |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 282 | acpi_ns_repair_FDE(struct acpi_evaluate_info *info, |
Bob Moore | 34c39c7 | 2009-12-11 14:53:11 +0800 | [diff] [blame] | 283 | union acpi_operand_object **return_object_ptr) |
| 284 | { |
| 285 | union acpi_operand_object *return_object = *return_object_ptr; |
Bob Moore | 34c39c7 | 2009-12-11 14:53:11 +0800 | [diff] [blame] | 286 | union acpi_operand_object *buffer_object; |
| 287 | u8 *byte_buffer; |
| 288 | u32 *dword_buffer; |
Bob Moore | 34c39c7 | 2009-12-11 14:53:11 +0800 | [diff] [blame] | 289 | u32 i; |
| 290 | |
Bob Moore | 3a58176 | 2009-12-11 15:23:22 +0800 | [diff] [blame] | 291 | ACPI_FUNCTION_NAME(ns_repair_FDE); |
| 292 | |
Bob Moore | 34c39c7 | 2009-12-11 14:53:11 +0800 | [diff] [blame] | 293 | switch (return_object->common.type) { |
| 294 | case ACPI_TYPE_BUFFER: |
| 295 | |
| 296 | /* This is the expected type. Length should be (at least) 5 DWORDs */ |
| 297 | |
| 298 | if (return_object->buffer.length >= ACPI_FDE_DWORD_BUFFER_SIZE) { |
| 299 | return (AE_OK); |
| 300 | } |
| 301 | |
| 302 | /* We can only repair if we have exactly 5 BYTEs */ |
| 303 | |
| 304 | if (return_object->buffer.length != ACPI_FDE_BYTE_BUFFER_SIZE) { |
Bob Moore | 1fad873 | 2015-12-29 13:54:36 +0800 | [diff] [blame] | 305 | ACPI_WARN_PREDEFINED((AE_INFO, |
| 306 | info->full_pathname, |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 307 | info->node_flags, |
Bob Moore | 34c39c7 | 2009-12-11 14:53:11 +0800 | [diff] [blame] | 308 | "Incorrect return buffer length %u, expected %u", |
| 309 | return_object->buffer.length, |
| 310 | ACPI_FDE_DWORD_BUFFER_SIZE)); |
| 311 | |
| 312 | return (AE_AML_OPERAND_TYPE); |
| 313 | } |
| 314 | |
| 315 | /* Create the new (larger) buffer object */ |
| 316 | |
| 317 | buffer_object = |
| 318 | acpi_ut_create_buffer_object(ACPI_FDE_DWORD_BUFFER_SIZE); |
| 319 | if (!buffer_object) { |
| 320 | return (AE_NO_MEMORY); |
| 321 | } |
| 322 | |
| 323 | /* Expand each byte to a DWORD */ |
| 324 | |
| 325 | byte_buffer = return_object->buffer.pointer; |
Bob Moore | 1fad873 | 2015-12-29 13:54:36 +0800 | [diff] [blame] | 326 | dword_buffer = ACPI_CAST_PTR(u32, |
| 327 | buffer_object->buffer.pointer); |
Bob Moore | 34c39c7 | 2009-12-11 14:53:11 +0800 | [diff] [blame] | 328 | |
| 329 | for (i = 0; i < ACPI_FDE_FIELD_COUNT; i++) { |
| 330 | *dword_buffer = (u32) *byte_buffer; |
| 331 | dword_buffer++; |
| 332 | byte_buffer++; |
| 333 | } |
| 334 | |
Bob Moore | 3a58176 | 2009-12-11 15:23:22 +0800 | [diff] [blame] | 335 | ACPI_DEBUG_PRINT((ACPI_DB_REPAIR, |
| 336 | "%s Expanded Byte Buffer to expected DWord Buffer\n", |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 337 | info->full_pathname)); |
Bob Moore | 34c39c7 | 2009-12-11 14:53:11 +0800 | [diff] [blame] | 338 | break; |
| 339 | |
Bob Moore | 34c39c7 | 2009-12-11 14:53:11 +0800 | [diff] [blame] | 340 | default: |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 341 | |
Bob Moore | 34c39c7 | 2009-12-11 14:53:11 +0800 | [diff] [blame] | 342 | return (AE_AML_OPERAND_TYPE); |
| 343 | } |
| 344 | |
| 345 | /* Delete the original return object, return the new buffer object */ |
| 346 | |
| 347 | acpi_ut_remove_reference(return_object); |
| 348 | *return_object_ptr = buffer_object; |
| 349 | |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 350 | info->return_flags |= ACPI_OBJECT_REPAIRED; |
Bob Moore | 34c39c7 | 2009-12-11 14:53:11 +0800 | [diff] [blame] | 351 | return (AE_OK); |
| 352 | } |
| 353 | |
| 354 | /****************************************************************************** |
| 355 | * |
Bob Moore | 77b23f712 | 2010-09-15 14:11:02 +0800 | [diff] [blame] | 356 | * FUNCTION: acpi_ns_repair_CID |
| 357 | * |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 358 | * PARAMETERS: info - Method execution information block |
Bob Moore | 77b23f712 | 2010-09-15 14:11:02 +0800 | [diff] [blame] | 359 | * return_object_ptr - Pointer to the object returned from the |
| 360 | * evaluation of a method or object |
| 361 | * |
| 362 | * RETURN: Status. AE_OK if object is OK or was repaired successfully |
| 363 | * |
| 364 | * DESCRIPTION: Repair for the _CID object. If a string, ensure that all |
| 365 | * letters are uppercase and that there is no leading asterisk. |
| 366 | * If a Package, ensure same for all string elements. |
| 367 | * |
| 368 | *****************************************************************************/ |
| 369 | |
| 370 | static acpi_status |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 371 | acpi_ns_repair_CID(struct acpi_evaluate_info *info, |
Bob Moore | 77b23f712 | 2010-09-15 14:11:02 +0800 | [diff] [blame] | 372 | union acpi_operand_object **return_object_ptr) |
| 373 | { |
| 374 | acpi_status status; |
| 375 | union acpi_operand_object *return_object = *return_object_ptr; |
| 376 | union acpi_operand_object **element_ptr; |
| 377 | union acpi_operand_object *original_element; |
| 378 | u16 original_ref_count; |
| 379 | u32 i; |
| 380 | |
| 381 | /* Check for _CID as a simple string */ |
| 382 | |
| 383 | if (return_object->common.type == ACPI_TYPE_STRING) { |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 384 | status = acpi_ns_repair_HID(info, return_object_ptr); |
Bob Moore | 77b23f712 | 2010-09-15 14:11:02 +0800 | [diff] [blame] | 385 | return (status); |
| 386 | } |
| 387 | |
| 388 | /* Exit if not a Package */ |
| 389 | |
| 390 | if (return_object->common.type != ACPI_TYPE_PACKAGE) { |
| 391 | return (AE_OK); |
| 392 | } |
| 393 | |
| 394 | /* Examine each element of the _CID package */ |
| 395 | |
| 396 | element_ptr = return_object->package.elements; |
| 397 | for (i = 0; i < return_object->package.count; i++) { |
| 398 | original_element = *element_ptr; |
| 399 | original_ref_count = original_element->common.reference_count; |
| 400 | |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 401 | status = acpi_ns_repair_HID(info, element_ptr); |
Bob Moore | 77b23f712 | 2010-09-15 14:11:02 +0800 | [diff] [blame] | 402 | if (ACPI_FAILURE(status)) { |
| 403 | return (status); |
| 404 | } |
| 405 | |
| 406 | /* Take care with reference counts */ |
| 407 | |
| 408 | if (original_element != *element_ptr) { |
| 409 | |
| 410 | /* Element was replaced */ |
| 411 | |
| 412 | (*element_ptr)->common.reference_count = |
| 413 | original_ref_count; |
| 414 | |
| 415 | acpi_ut_remove_reference(original_element); |
| 416 | } |
| 417 | |
| 418 | element_ptr++; |
| 419 | } |
| 420 | |
| 421 | return (AE_OK); |
| 422 | } |
| 423 | |
| 424 | /****************************************************************************** |
| 425 | * |
Lv Zheng | 5a9792f | 2013-06-08 09:01:07 +0800 | [diff] [blame] | 426 | * FUNCTION: acpi_ns_repair_CST |
| 427 | * |
| 428 | * PARAMETERS: info - Method execution information block |
| 429 | * return_object_ptr - Pointer to the object returned from the |
| 430 | * evaluation of a method or object |
| 431 | * |
| 432 | * RETURN: Status. AE_OK if object is OK or was repaired successfully |
| 433 | * |
| 434 | * DESCRIPTION: Repair for the _CST object: |
| 435 | * 1. Sort the list ascending by C state type |
| 436 | * 2. Ensure type cannot be zero |
Bob Moore | 0a16d12 | 2014-02-26 10:31:18 +0800 | [diff] [blame] | 437 | * 3. A subpackage count of zero means _CST is meaningless |
| 438 | * 4. Count must match the number of C state subpackages |
Lv Zheng | 5a9792f | 2013-06-08 09:01:07 +0800 | [diff] [blame] | 439 | * |
| 440 | *****************************************************************************/ |
| 441 | |
| 442 | static acpi_status |
| 443 | acpi_ns_repair_CST(struct acpi_evaluate_info *info, |
| 444 | union acpi_operand_object **return_object_ptr) |
| 445 | { |
| 446 | union acpi_operand_object *return_object = *return_object_ptr; |
| 447 | union acpi_operand_object **outer_elements; |
| 448 | u32 outer_element_count; |
| 449 | union acpi_operand_object *obj_desc; |
| 450 | acpi_status status; |
| 451 | u8 removing; |
| 452 | u32 i; |
| 453 | |
| 454 | ACPI_FUNCTION_NAME(ns_repair_CST); |
| 455 | |
| 456 | /* |
Lv Zheng | 341e7ba | 2013-06-08 09:01:19 +0800 | [diff] [blame] | 457 | * Check if the C-state type values are proportional. |
Lv Zheng | 5a9792f | 2013-06-08 09:01:07 +0800 | [diff] [blame] | 458 | */ |
| 459 | outer_element_count = return_object->package.count - 1; |
| 460 | i = 0; |
| 461 | while (i < outer_element_count) { |
| 462 | outer_elements = &return_object->package.elements[i + 1]; |
| 463 | removing = FALSE; |
| 464 | |
| 465 | if ((*outer_elements)->package.count == 0) { |
Bob Moore | 1fad873 | 2015-12-29 13:54:36 +0800 | [diff] [blame] | 466 | ACPI_WARN_PREDEFINED((AE_INFO, |
| 467 | info->full_pathname, |
Lv Zheng | 5a9792f | 2013-06-08 09:01:07 +0800 | [diff] [blame] | 468 | info->node_flags, |
| 469 | "SubPackage[%u] - removing entry due to zero count", |
| 470 | i)); |
| 471 | removing = TRUE; |
| 472 | goto remove_element; |
| 473 | } |
| 474 | |
| 475 | obj_desc = (*outer_elements)->package.elements[1]; /* Index1 = Type */ |
| 476 | if ((u32)obj_desc->integer.value == 0) { |
Bob Moore | 1fad873 | 2015-12-29 13:54:36 +0800 | [diff] [blame] | 477 | ACPI_WARN_PREDEFINED((AE_INFO, |
| 478 | info->full_pathname, |
Lv Zheng | 5a9792f | 2013-06-08 09:01:07 +0800 | [diff] [blame] | 479 | info->node_flags, |
| 480 | "SubPackage[%u] - removing entry due to invalid Type(0)", |
| 481 | i)); |
| 482 | removing = TRUE; |
| 483 | } |
| 484 | |
Lv Zheng | 10622bf | 2013-10-29 09:30:02 +0800 | [diff] [blame] | 485 | remove_element: |
Lv Zheng | 5a9792f | 2013-06-08 09:01:07 +0800 | [diff] [blame] | 486 | if (removing) { |
| 487 | acpi_ns_remove_element(return_object, i + 1); |
| 488 | outer_element_count--; |
| 489 | } else { |
| 490 | i++; |
| 491 | } |
| 492 | } |
| 493 | |
| 494 | /* Update top-level package count, Type "Integer" checked elsewhere */ |
| 495 | |
| 496 | obj_desc = return_object->package.elements[0]; |
| 497 | obj_desc->integer.value = outer_element_count; |
Lv Zheng | 341e7ba | 2013-06-08 09:01:19 +0800 | [diff] [blame] | 498 | |
| 499 | /* |
| 500 | * Entries (subpackages) in the _CST Package must be sorted by the |
| 501 | * C-state type, in ascending order. |
| 502 | */ |
| 503 | status = acpi_ns_check_sorted_list(info, return_object, 1, 4, 1, |
| 504 | ACPI_SORT_ASCENDING, "C-State Type"); |
| 505 | if (ACPI_FAILURE(status)) { |
| 506 | return (status); |
| 507 | } |
| 508 | |
Lv Zheng | 5a9792f | 2013-06-08 09:01:07 +0800 | [diff] [blame] | 509 | return (AE_OK); |
| 510 | } |
| 511 | |
| 512 | /****************************************************************************** |
| 513 | * |
Bob Moore | 77b23f712 | 2010-09-15 14:11:02 +0800 | [diff] [blame] | 514 | * FUNCTION: acpi_ns_repair_HID |
| 515 | * |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 516 | * PARAMETERS: info - Method execution information block |
Bob Moore | 77b23f712 | 2010-09-15 14:11:02 +0800 | [diff] [blame] | 517 | * return_object_ptr - Pointer to the object returned from the |
| 518 | * evaluation of a method or object |
| 519 | * |
| 520 | * RETURN: Status. AE_OK if object is OK or was repaired successfully |
| 521 | * |
| 522 | * DESCRIPTION: Repair for the _HID object. If a string, ensure that all |
| 523 | * letters are uppercase and that there is no leading asterisk. |
| 524 | * |
| 525 | *****************************************************************************/ |
| 526 | |
| 527 | static acpi_status |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 528 | acpi_ns_repair_HID(struct acpi_evaluate_info *info, |
Bob Moore | 77b23f712 | 2010-09-15 14:11:02 +0800 | [diff] [blame] | 529 | union acpi_operand_object **return_object_ptr) |
| 530 | { |
| 531 | union acpi_operand_object *return_object = *return_object_ptr; |
| 532 | union acpi_operand_object *new_string; |
| 533 | char *source; |
| 534 | char *dest; |
| 535 | |
| 536 | ACPI_FUNCTION_NAME(ns_repair_HID); |
| 537 | |
| 538 | /* We only care about string _HID objects (not integers) */ |
| 539 | |
| 540 | if (return_object->common.type != ACPI_TYPE_STRING) { |
| 541 | return (AE_OK); |
| 542 | } |
| 543 | |
| 544 | if (return_object->string.length == 0) { |
Bob Moore | 1fad873 | 2015-12-29 13:54:36 +0800 | [diff] [blame] | 545 | ACPI_WARN_PREDEFINED((AE_INFO, |
| 546 | info->full_pathname, info->node_flags, |
Bob Moore | 77b23f712 | 2010-09-15 14:11:02 +0800 | [diff] [blame] | 547 | "Invalid zero-length _HID or _CID string")); |
| 548 | |
| 549 | /* Return AE_OK anyway, let driver handle it */ |
| 550 | |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 551 | info->return_flags |= ACPI_OBJECT_REPAIRED; |
Bob Moore | 77b23f712 | 2010-09-15 14:11:02 +0800 | [diff] [blame] | 552 | return (AE_OK); |
| 553 | } |
| 554 | |
| 555 | /* It is simplest to always create a new string object */ |
| 556 | |
| 557 | new_string = acpi_ut_create_string_object(return_object->string.length); |
| 558 | if (!new_string) { |
| 559 | return (AE_NO_MEMORY); |
| 560 | } |
| 561 | |
| 562 | /* |
| 563 | * Remove a leading asterisk if present. For some unknown reason, there |
| 564 | * are many machines in the field that contains IDs like this. |
| 565 | * |
| 566 | * Examples: "*PNP0C03", "*ACPI0003" |
| 567 | */ |
| 568 | source = return_object->string.pointer; |
| 569 | if (*source == '*') { |
| 570 | source++; |
| 571 | new_string->string.length--; |
| 572 | |
| 573 | ACPI_DEBUG_PRINT((ACPI_DB_REPAIR, |
| 574 | "%s: Removed invalid leading asterisk\n", |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 575 | info->full_pathname)); |
Bob Moore | 77b23f712 | 2010-09-15 14:11:02 +0800 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | /* |
Bob Moore | 7fce7a4 | 2011-11-16 14:59:17 +0800 | [diff] [blame] | 579 | * Copy and uppercase the string. From the ACPI 5.0 specification: |
Bob Moore | 77b23f712 | 2010-09-15 14:11:02 +0800 | [diff] [blame] | 580 | * |
| 581 | * A valid PNP ID must be of the form "AAA####" where A is an uppercase |
| 582 | * 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] | 583 | * "NNNN####" where N is an uppercase letter or decimal digit, and |
| 584 | * # is a hex digit. |
Bob Moore | 77b23f712 | 2010-09-15 14:11:02 +0800 | [diff] [blame] | 585 | */ |
| 586 | for (dest = new_string->string.pointer; *source; dest++, source++) { |
Bob Moore | 4fa4616 | 2015-07-01 14:45:11 +0800 | [diff] [blame] | 587 | *dest = (char)toupper((int)*source); |
Bob Moore | 77b23f712 | 2010-09-15 14:11:02 +0800 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | acpi_ut_remove_reference(return_object); |
| 591 | *return_object_ptr = new_string; |
| 592 | return (AE_OK); |
| 593 | } |
| 594 | |
| 595 | /****************************************************************************** |
| 596 | * |
Lv Zheng | aa6329c | 2013-06-08 09:01:01 +0800 | [diff] [blame] | 597 | * FUNCTION: acpi_ns_repair_PRT |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 598 | * |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 599 | * PARAMETERS: info - Method execution information block |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 600 | * return_object_ptr - Pointer to the object returned from the |
| 601 | * evaluation of a method or object |
| 602 | * |
| 603 | * RETURN: Status. AE_OK if object is OK or was repaired successfully |
| 604 | * |
Lv Zheng | aa6329c | 2013-06-08 09:01:01 +0800 | [diff] [blame] | 605 | * DESCRIPTION: Repair for the _PRT object. If necessary, fix reversed |
| 606 | * source_name and source_index field, a common BIOS bug. |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 607 | * |
| 608 | *****************************************************************************/ |
| 609 | |
| 610 | static acpi_status |
Lv Zheng | aa6329c | 2013-06-08 09:01:01 +0800 | [diff] [blame] | 611 | acpi_ns_repair_PRT(struct acpi_evaluate_info *info, |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 612 | union acpi_operand_object **return_object_ptr) |
| 613 | { |
Lv Zheng | aa6329c | 2013-06-08 09:01:01 +0800 | [diff] [blame] | 614 | union acpi_operand_object *package_object = *return_object_ptr; |
| 615 | union acpi_operand_object **top_object_list; |
| 616 | union acpi_operand_object **sub_object_list; |
| 617 | union acpi_operand_object *obj_desc; |
Bob Moore | 1c3c2a5 | 2014-02-26 10:30:25 +0800 | [diff] [blame] | 618 | union acpi_operand_object *sub_package; |
Lv Zheng | aa6329c | 2013-06-08 09:01:01 +0800 | [diff] [blame] | 619 | u32 element_count; |
| 620 | u32 index; |
Fenghua Yu | 8f9c912 | 2011-07-04 08:36:16 +0000 | [diff] [blame] | 621 | |
Lv Zheng | aa6329c | 2013-06-08 09:01:01 +0800 | [diff] [blame] | 622 | /* Each element in the _PRT package is a subpackage */ |
| 623 | |
| 624 | top_object_list = package_object->package.elements; |
| 625 | element_count = package_object->package.count; |
| 626 | |
Bob Moore | 69e6bb6 | 2014-02-26 10:30:43 +0800 | [diff] [blame] | 627 | /* Examine each subpackage */ |
| 628 | |
| 629 | for (index = 0; index < element_count; index++, top_object_list++) { |
Bob Moore | 1c3c2a5 | 2014-02-26 10:30:25 +0800 | [diff] [blame] | 630 | sub_package = *top_object_list; |
| 631 | sub_object_list = sub_package->package.elements; |
| 632 | |
Bob Moore | 69e6bb6 | 2014-02-26 10:30:43 +0800 | [diff] [blame] | 633 | /* Check for minimum required element count */ |
| 634 | |
| 635 | if (sub_package->package.count < 4) { |
| 636 | continue; |
Bob Moore | 1c3c2a5 | 2014-02-26 10:30:25 +0800 | [diff] [blame] | 637 | } |
Lv Zheng | aa6329c | 2013-06-08 09:01:01 +0800 | [diff] [blame] | 638 | |
| 639 | /* |
| 640 | * If the BIOS has erroneously reversed the _PRT source_name (index 2) |
| 641 | * and the source_index (index 3), fix it. _PRT is important enough to |
| 642 | * workaround this BIOS error. This also provides compatibility with |
| 643 | * other ACPI implementations. |
| 644 | */ |
| 645 | obj_desc = sub_object_list[3]; |
| 646 | if (!obj_desc || (obj_desc->common.type != ACPI_TYPE_INTEGER)) { |
| 647 | sub_object_list[3] = sub_object_list[2]; |
| 648 | sub_object_list[2] = obj_desc; |
| 649 | info->return_flags |= ACPI_OBJECT_REPAIRED; |
| 650 | |
Bob Moore | 69e6bb6 | 2014-02-26 10:30:43 +0800 | [diff] [blame] | 651 | ACPI_WARN_PREDEFINED((AE_INFO, |
| 652 | info->full_pathname, |
Lv Zheng | aa6329c | 2013-06-08 09:01:01 +0800 | [diff] [blame] | 653 | info->node_flags, |
| 654 | "PRT[%X]: Fixed reversed SourceName and SourceIndex", |
| 655 | index)); |
| 656 | } |
Fenghua Yu | 8f9c912 | 2011-07-04 08:36:16 +0000 | [diff] [blame] | 657 | } |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 658 | |
Lv Zheng | aa6329c | 2013-06-08 09:01:01 +0800 | [diff] [blame] | 659 | return (AE_OK); |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | /****************************************************************************** |
| 663 | * |
| 664 | * FUNCTION: acpi_ns_repair_PSS |
| 665 | * |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 666 | * PARAMETERS: info - Method execution information block |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 667 | * return_object_ptr - Pointer to the object returned from the |
| 668 | * evaluation of a method or object |
| 669 | * |
| 670 | * RETURN: Status. AE_OK if object is OK or was repaired successfully |
| 671 | * |
| 672 | * DESCRIPTION: Repair for the _PSS object. If necessary, sort the object list |
| 673 | * by the CPU frequencies. Check that the power dissipation values |
| 674 | * are all proportional to CPU frequency (i.e., sorting by |
| 675 | * frequency should be the same as sorting by power.) |
| 676 | * |
| 677 | *****************************************************************************/ |
| 678 | |
| 679 | static acpi_status |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 680 | acpi_ns_repair_PSS(struct acpi_evaluate_info *info, |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 681 | union acpi_operand_object **return_object_ptr) |
| 682 | { |
| 683 | union acpi_operand_object *return_object = *return_object_ptr; |
| 684 | union acpi_operand_object **outer_elements; |
| 685 | u32 outer_element_count; |
| 686 | union acpi_operand_object **elements; |
| 687 | union acpi_operand_object *obj_desc; |
| 688 | u32 previous_value; |
| 689 | acpi_status status; |
| 690 | u32 i; |
| 691 | |
| 692 | /* |
Bob Moore | 0a16d12 | 2014-02-26 10:31:18 +0800 | [diff] [blame] | 693 | * Entries (subpackages) in the _PSS Package must be sorted by power |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 694 | * dissipation, in descending order. If it appears that the list is |
| 695 | * incorrectly sorted, sort it. We sort by cpu_frequency, since this |
| 696 | * should be proportional to the power. |
| 697 | */ |
Lv Zheng | 5a9792f | 2013-06-08 09:01:07 +0800 | [diff] [blame] | 698 | status = acpi_ns_check_sorted_list(info, return_object, 0, 6, 0, |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 699 | ACPI_SORT_DESCENDING, |
| 700 | "CpuFrequency"); |
| 701 | if (ACPI_FAILURE(status)) { |
| 702 | return (status); |
| 703 | } |
| 704 | |
| 705 | /* |
| 706 | * We now know the list is correctly sorted by CPU frequency. Check if |
| 707 | * the power dissipation values are proportional. |
| 708 | */ |
| 709 | previous_value = ACPI_UINT32_MAX; |
| 710 | outer_elements = return_object->package.elements; |
| 711 | outer_element_count = return_object->package.count; |
| 712 | |
| 713 | for (i = 0; i < outer_element_count; i++) { |
| 714 | elements = (*outer_elements)->package.elements; |
| 715 | obj_desc = elements[1]; /* Index1 = power_dissipation */ |
| 716 | |
Lv Zheng | 5431b65 | 2015-12-29 13:52:32 +0800 | [diff] [blame] | 717 | if ((u32)obj_desc->integer.value > previous_value) { |
Bob Moore | 1fad873 | 2015-12-29 13:54:36 +0800 | [diff] [blame] | 718 | ACPI_WARN_PREDEFINED((AE_INFO, |
| 719 | info->full_pathname, |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 720 | info->node_flags, |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 721 | "SubPackage[%u,%u] - suspicious power dissipation values", |
| 722 | i - 1, i)); |
| 723 | } |
| 724 | |
| 725 | previous_value = (u32) obj_desc->integer.value; |
| 726 | outer_elements++; |
| 727 | } |
| 728 | |
| 729 | return (AE_OK); |
| 730 | } |
| 731 | |
| 732 | /****************************************************************************** |
| 733 | * |
Lv Zheng | aa6329c | 2013-06-08 09:01:01 +0800 | [diff] [blame] | 734 | * FUNCTION: acpi_ns_repair_TSS |
| 735 | * |
| 736 | * PARAMETERS: info - Method execution information block |
| 737 | * return_object_ptr - Pointer to the object returned from the |
| 738 | * evaluation of a method or object |
| 739 | * |
| 740 | * RETURN: Status. AE_OK if object is OK or was repaired successfully |
| 741 | * |
| 742 | * DESCRIPTION: Repair for the _TSS object. If necessary, sort the object list |
| 743 | * descending by the power dissipation values. |
| 744 | * |
| 745 | *****************************************************************************/ |
| 746 | |
| 747 | static acpi_status |
| 748 | acpi_ns_repair_TSS(struct acpi_evaluate_info *info, |
| 749 | union acpi_operand_object **return_object_ptr) |
| 750 | { |
| 751 | union acpi_operand_object *return_object = *return_object_ptr; |
| 752 | acpi_status status; |
| 753 | struct acpi_namespace_node *node; |
| 754 | |
| 755 | /* |
| 756 | * We can only sort the _TSS return package if there is no _PSS in the |
| 757 | * same scope. This is because if _PSS is present, the ACPI specification |
| 758 | * dictates that the _TSS Power Dissipation field is to be ignored, and |
| 759 | * therefore some BIOSs leave garbage values in the _TSS Power field(s). |
| 760 | * In this case, it is best to just return the _TSS package as-is. |
| 761 | * (May, 2011) |
| 762 | */ |
| 763 | status = acpi_ns_get_node(info->node, "^_PSS", |
| 764 | ACPI_NS_NO_UPSEARCH, &node); |
| 765 | if (ACPI_SUCCESS(status)) { |
| 766 | return (AE_OK); |
| 767 | } |
| 768 | |
Lv Zheng | 5a9792f | 2013-06-08 09:01:07 +0800 | [diff] [blame] | 769 | status = acpi_ns_check_sorted_list(info, return_object, 0, 5, 1, |
Lv Zheng | aa6329c | 2013-06-08 09:01:01 +0800 | [diff] [blame] | 770 | ACPI_SORT_DESCENDING, |
| 771 | "PowerDissipation"); |
| 772 | |
| 773 | return (status); |
| 774 | } |
| 775 | |
| 776 | /****************************************************************************** |
| 777 | * |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 778 | * FUNCTION: acpi_ns_check_sorted_list |
| 779 | * |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 780 | * PARAMETERS: info - Method execution information block |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 781 | * return_object - Pointer to the top-level returned object |
Bob Moore | 0a16d12 | 2014-02-26 10:31:18 +0800 | [diff] [blame] | 782 | * start_index - Index of the first subpackage |
| 783 | * expected_count - Minimum length of each subpackage |
| 784 | * sort_index - Subpackage entry to sort on |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 785 | * sort_direction - Ascending or descending |
| 786 | * sort_key_name - Name of the sort_index field |
| 787 | * |
| 788 | * RETURN: Status. AE_OK if the list is valid and is sorted correctly or |
| 789 | * has been repaired by sorting the list. |
| 790 | * |
| 791 | * DESCRIPTION: Check if the package list is valid and sorted correctly by the |
| 792 | * sort_index. If not, then sort the list. |
| 793 | * |
| 794 | *****************************************************************************/ |
| 795 | |
| 796 | static acpi_status |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 797 | acpi_ns_check_sorted_list(struct acpi_evaluate_info *info, |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 798 | union acpi_operand_object *return_object, |
Lv Zheng | 5a9792f | 2013-06-08 09:01:07 +0800 | [diff] [blame] | 799 | u32 start_index, |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 800 | u32 expected_count, |
| 801 | u32 sort_index, |
| 802 | u8 sort_direction, char *sort_key_name) |
| 803 | { |
| 804 | u32 outer_element_count; |
| 805 | union acpi_operand_object **outer_elements; |
| 806 | union acpi_operand_object **elements; |
| 807 | union acpi_operand_object *obj_desc; |
| 808 | u32 i; |
| 809 | u32 previous_value; |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 810 | |
Bob Moore | 3a58176 | 2009-12-11 15:23:22 +0800 | [diff] [blame] | 811 | ACPI_FUNCTION_NAME(ns_check_sorted_list); |
| 812 | |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 813 | /* The top-level object must be a package */ |
| 814 | |
| 815 | if (return_object->common.type != ACPI_TYPE_PACKAGE) { |
| 816 | return (AE_AML_OPERAND_TYPE); |
| 817 | } |
| 818 | |
| 819 | /* |
Bob Moore | 0a16d12 | 2014-02-26 10:31:18 +0800 | [diff] [blame] | 820 | * NOTE: assumes list of subpackages contains no NULL elements. |
Bob Moore | d4085a3f | 2009-12-11 15:29:44 +0800 | [diff] [blame] | 821 | * Any NULL elements should have been removed by earlier call |
| 822 | * to acpi_ns_remove_null_elements. |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 823 | */ |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 824 | outer_element_count = return_object->package.count; |
Lv Zheng | 5a9792f | 2013-06-08 09:01:07 +0800 | [diff] [blame] | 825 | if (!outer_element_count || start_index >= outer_element_count) { |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 826 | return (AE_AML_PACKAGE_LIMIT); |
| 827 | } |
| 828 | |
Lv Zheng | 5a9792f | 2013-06-08 09:01:07 +0800 | [diff] [blame] | 829 | outer_elements = &return_object->package.elements[start_index]; |
| 830 | outer_element_count -= start_index; |
| 831 | |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 832 | previous_value = 0; |
| 833 | if (sort_direction == ACPI_SORT_DESCENDING) { |
| 834 | previous_value = ACPI_UINT32_MAX; |
| 835 | } |
| 836 | |
| 837 | /* Examine each subpackage */ |
| 838 | |
| 839 | for (i = 0; i < outer_element_count; i++) { |
| 840 | |
| 841 | /* Each element of the top-level package must also be a package */ |
| 842 | |
| 843 | if ((*outer_elements)->common.type != ACPI_TYPE_PACKAGE) { |
| 844 | return (AE_AML_OPERAND_TYPE); |
| 845 | } |
| 846 | |
Bob Moore | 0a16d12 | 2014-02-26 10:31:18 +0800 | [diff] [blame] | 847 | /* Each subpackage must have the minimum length */ |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 848 | |
| 849 | if ((*outer_elements)->package.count < expected_count) { |
| 850 | return (AE_AML_PACKAGE_LIMIT); |
| 851 | } |
| 852 | |
| 853 | elements = (*outer_elements)->package.elements; |
| 854 | obj_desc = elements[sort_index]; |
| 855 | |
| 856 | if (obj_desc->common.type != ACPI_TYPE_INTEGER) { |
| 857 | return (AE_AML_OPERAND_TYPE); |
| 858 | } |
| 859 | |
| 860 | /* |
| 861 | * 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] | 862 | * discrepancy, sort the entire list. |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 863 | */ |
| 864 | if (((sort_direction == ACPI_SORT_ASCENDING) && |
| 865 | (obj_desc->integer.value < previous_value)) || |
| 866 | ((sort_direction == ACPI_SORT_DESCENDING) && |
| 867 | (obj_desc->integer.value > previous_value))) { |
Lv Zheng | 5a9792f | 2013-06-08 09:01:07 +0800 | [diff] [blame] | 868 | acpi_ns_sort_list(&return_object->package. |
| 869 | elements[start_index], |
Bob Moore | 2147d3f | 2010-01-21 09:08:31 +0800 | [diff] [blame] | 870 | outer_element_count, sort_index, |
| 871 | sort_direction); |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 872 | |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 873 | info->return_flags |= ACPI_OBJECT_REPAIRED; |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 874 | |
Bob Moore | 3a58176 | 2009-12-11 15:23:22 +0800 | [diff] [blame] | 875 | ACPI_DEBUG_PRINT((ACPI_DB_REPAIR, |
| 876 | "%s: Repaired unsorted list - now sorted by %s\n", |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 877 | info->full_pathname, sort_key_name)); |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 878 | return (AE_OK); |
| 879 | } |
| 880 | |
| 881 | previous_value = (u32) obj_desc->integer.value; |
| 882 | outer_elements++; |
| 883 | } |
| 884 | |
| 885 | return (AE_OK); |
| 886 | } |
| 887 | |
| 888 | /****************************************************************************** |
| 889 | * |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 890 | * FUNCTION: acpi_ns_sort_list |
| 891 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 892 | * PARAMETERS: elements - Package object element list |
| 893 | * count - Element count for above |
| 894 | * index - Sort by which package element |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 895 | * sort_direction - Ascending or Descending sort |
| 896 | * |
Bob Moore | 2147d3f | 2010-01-21 09:08:31 +0800 | [diff] [blame] | 897 | * RETURN: None |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 898 | * |
| 899 | * DESCRIPTION: Sort the objects that are in a package element list. |
| 900 | * |
Bob Moore | 2147d3f | 2010-01-21 09:08:31 +0800 | [diff] [blame] | 901 | * NOTE: Assumes that all NULL elements have been removed from the package, |
| 902 | * and that all elements have been verified to be of type Integer. |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 903 | * |
| 904 | *****************************************************************************/ |
| 905 | |
Bob Moore | 2147d3f | 2010-01-21 09:08:31 +0800 | [diff] [blame] | 906 | static void |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 907 | acpi_ns_sort_list(union acpi_operand_object **elements, |
| 908 | u32 count, u32 index, u8 sort_direction) |
| 909 | { |
| 910 | union acpi_operand_object *obj_desc1; |
| 911 | union acpi_operand_object *obj_desc2; |
| 912 | union acpi_operand_object *temp_obj; |
| 913 | u32 i; |
| 914 | u32 j; |
| 915 | |
| 916 | /* Simple bubble sort */ |
| 917 | |
| 918 | for (i = 1; i < count; i++) { |
| 919 | for (j = (count - 1); j >= i; j--) { |
| 920 | obj_desc1 = elements[j - 1]->package.elements[index]; |
| 921 | obj_desc2 = elements[j]->package.elements[index]; |
| 922 | |
| 923 | if (((sort_direction == ACPI_SORT_ASCENDING) && |
| 924 | (obj_desc1->integer.value > |
| 925 | obj_desc2->integer.value)) |
| 926 | || ((sort_direction == ACPI_SORT_DESCENDING) |
| 927 | && (obj_desc1->integer.value < |
| 928 | obj_desc2->integer.value))) { |
| 929 | temp_obj = elements[j - 1]; |
| 930 | elements[j - 1] = elements[j]; |
| 931 | elements[j] = temp_obj; |
| 932 | } |
| 933 | } |
| 934 | } |
Bob Moore | ad5babe | 2009-11-12 09:44:06 +0800 | [diff] [blame] | 935 | } |
Lv Zheng | 5a9792f | 2013-06-08 09:01:07 +0800 | [diff] [blame] | 936 | |
| 937 | /****************************************************************************** |
| 938 | * |
| 939 | * FUNCTION: acpi_ns_remove_element |
| 940 | * |
| 941 | * PARAMETERS: obj_desc - Package object element list |
| 942 | * index - Index of element to remove |
| 943 | * |
| 944 | * RETURN: None |
| 945 | * |
| 946 | * DESCRIPTION: Remove the requested element of a package and delete it. |
| 947 | * |
| 948 | *****************************************************************************/ |
| 949 | |
| 950 | static void |
| 951 | acpi_ns_remove_element(union acpi_operand_object *obj_desc, u32 index) |
| 952 | { |
| 953 | union acpi_operand_object **source; |
| 954 | union acpi_operand_object **dest; |
| 955 | u32 count; |
| 956 | u32 new_count; |
| 957 | u32 i; |
| 958 | |
| 959 | ACPI_FUNCTION_NAME(ns_remove_element); |
| 960 | |
| 961 | count = obj_desc->package.count; |
| 962 | new_count = count - 1; |
| 963 | |
| 964 | source = obj_desc->package.elements; |
| 965 | dest = source; |
| 966 | |
| 967 | /* Examine all elements of the package object, remove matched index */ |
| 968 | |
| 969 | for (i = 0; i < count; i++) { |
| 970 | if (i == index) { |
| 971 | acpi_ut_remove_reference(*source); /* Remove one ref for being in pkg */ |
| 972 | acpi_ut_remove_reference(*source); |
| 973 | } else { |
| 974 | *dest = *source; |
| 975 | dest++; |
| 976 | } |
Bob Moore | 1fad873 | 2015-12-29 13:54:36 +0800 | [diff] [blame] | 977 | |
Lv Zheng | 5a9792f | 2013-06-08 09:01:07 +0800 | [diff] [blame] | 978 | source++; |
| 979 | } |
| 980 | |
| 981 | /* NULL terminate list and update the package count */ |
| 982 | |
| 983 | *dest = NULL; |
| 984 | obj_desc->package.count = new_count; |
| 985 | } |