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