blob: aca9bdf74e1f5918d7dc63e2486784e86d04fe39 [file] [log] [blame]
Bob Mooread5babe2009-11-12 09:44:06 +08001/******************************************************************************
2 *
3 * Module Name: nsrepair2 - Repair for objects returned by specific
4 * predefined methods
5 *
6 *****************************************************************************/
7
8/*
Bob Moore25f044e2013-01-25 05:38:56 +00009 * Copyright (C) 2000 - 2013, Intel Corp.
Bob Mooread5babe2009-11-12 09:44:06 +080010 * 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
50ACPI_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 */
56typedef
Bob Moore29a241c2013-05-30 10:00:01 +080057acpi_status(*acpi_repair_function) (struct acpi_evaluate_info * info,
Lv Zheng3e8214e2012-12-19 05:37:15 +000058 union acpi_operand_object
59 **return_object_ptr);
Bob Mooread5babe2009-11-12 09:44:06 +080060
61typedef 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 Moored5a36102013-03-08 09:23:03 +000069static const struct acpi_repair_info *acpi_ns_match_complex_repair(struct
70 acpi_namespace_node
71 *node);
Bob Mooread5babe2009-11-12 09:44:06 +080072
73static acpi_status
Bob Moore29a241c2013-05-30 10:00:01 +080074acpi_ns_repair_ALR(struct acpi_evaluate_info *info,
Bob Mooread5babe2009-11-12 09:44:06 +080075 union acpi_operand_object **return_object_ptr);
76
77static acpi_status
Bob Moore29a241c2013-05-30 10:00:01 +080078acpi_ns_repair_CID(struct acpi_evaluate_info *info,
Bob Moore77b23f7122010-09-15 14:11:02 +080079 union acpi_operand_object **return_object_ptr);
80
81static acpi_status
Bob Moore29a241c2013-05-30 10:00:01 +080082acpi_ns_repair_FDE(struct acpi_evaluate_info *info,
Bob Moore34c39c72009-12-11 14:53:11 +080083 union acpi_operand_object **return_object_ptr);
84
85static acpi_status
Bob Moore29a241c2013-05-30 10:00:01 +080086acpi_ns_repair_HID(struct acpi_evaluate_info *info,
Bob Moore77b23f7122010-09-15 14:11:02 +080087 union acpi_operand_object **return_object_ptr);
88
89static acpi_status
Lv Zhengaa6329c2013-06-08 09:01:01 +080090acpi_ns_repair_PRT(struct acpi_evaluate_info *info,
91 union acpi_operand_object **return_object_ptr);
92
93static acpi_status
Bob Moore29a241c2013-05-30 10:00:01 +080094acpi_ns_repair_PSS(struct acpi_evaluate_info *info,
Bob Mooread5babe2009-11-12 09:44:06 +080095 union acpi_operand_object **return_object_ptr);
96
97static acpi_status
Bob Moore29a241c2013-05-30 10:00:01 +080098acpi_ns_repair_TSS(struct acpi_evaluate_info *info,
Bob Mooread5babe2009-11-12 09:44:06 +080099 union acpi_operand_object **return_object_ptr);
100
101static acpi_status
Bob Moore29a241c2013-05-30 10:00:01 +0800102acpi_ns_check_sorted_list(struct acpi_evaluate_info *info,
Bob Mooread5babe2009-11-12 09:44:06 +0800103 union acpi_operand_object *return_object,
104 u32 expected_count,
105 u32 sort_index,
106 u8 sort_direction, char *sort_key_name);
107
Bob Moore2147d3f2010-01-21 09:08:31 +0800108static void
Bob Mooread5babe2009-11-12 09:44:06 +0800109acpi_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 Moore34c39c72009-12-11 14:53:11 +0800121 * As necessary:
122 *
123 * _ALR: Sort the list ascending by ambient_illuminance
Bob Moore77b23f7122010-09-15 14:11:02 +0800124 * _CID: Strings: uppercase all, remove any leading asterisk
Bob Moore43420bb2009-12-11 15:24:27 +0800125 * _FDE: Convert Buffer of BYTEs to a Buffer of DWORDs
126 * _GTM: Convert Buffer of BYTEs to a Buffer of DWORDs
Bob Moore77b23f7122010-09-15 14:11:02 +0800127 * _HID: Strings: uppercase all, remove any leading asterisk
Lv Zhengaa6329c2013-06-08 09:01:01 +0800128 * _PRT: Fix reversed source_name and source_index
Bob Moore34c39c72009-12-11 14:53:11 +0800129 * _PSS: Sort the list descending by Power
130 * _TSS: Sort the list descending by Power
Bob Mooreaa9d3602010-05-26 11:03:56 +0800131 *
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 Mooread5babe2009-11-12 09:44:06 +0800138 */
139static const struct acpi_repair_info acpi_ns_repairable_names[] = {
140 {"_ALR", acpi_ns_repair_ALR},
Bob Moore77b23f7122010-09-15 14:11:02 +0800141 {"_CID", acpi_ns_repair_CID},
Bob Moore34c39c72009-12-11 14:53:11 +0800142 {"_FDE", acpi_ns_repair_FDE},
143 {"_GTM", acpi_ns_repair_FDE}, /* _GTM has same repair as _FDE */
Bob Moore77b23f7122010-09-15 14:11:02 +0800144 {"_HID", acpi_ns_repair_HID},
Lv Zhengaa6329c2013-06-08 09:01:01 +0800145 {"_PRT", acpi_ns_repair_PRT},
Bob Mooread5babe2009-11-12 09:44:06 +0800146 {"_PSS", acpi_ns_repair_PSS},
147 {"_TSS", acpi_ns_repair_TSS},
148 {{0, 0, 0, 0}, NULL} /* Table terminator */
149};
150
Bob Moore34c39c72009-12-11 14:53:11 +0800151#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 Mooread5babe2009-11-12 09:44:06 +0800155/******************************************************************************
156 *
157 * FUNCTION: acpi_ns_complex_repairs
158 *
Bob Moore29a241c2013-05-30 10:00:01 +0800159 * PARAMETERS: info - Method execution information block
Bob Mooreba494be2012-07-12 09:40:10 +0800160 * node - Namespace node for the method/object
Bob Mooread5babe2009-11-12 09:44:06 +0800161 * 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
173acpi_status
Bob Moore29a241c2013-05-30 10:00:01 +0800174acpi_ns_complex_repairs(struct acpi_evaluate_info *info,
Bob Mooread5babe2009-11-12 09:44:06 +0800175 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 Moored5a36102013-03-08 09:23:03 +0000184 predefined = acpi_ns_match_complex_repair(node);
Bob Mooread5babe2009-11-12 09:44:06 +0800185 if (!predefined) {
186 return (validate_status);
187 }
188
Bob Moore29a241c2013-05-30 10:00:01 +0800189 status = predefined->repair_function(info, return_object_ptr);
Bob Mooread5babe2009-11-12 09:44:06 +0800190 return (status);
191}
192
193/******************************************************************************
194 *
Bob Moored5a36102013-03-08 09:23:03 +0000195 * FUNCTION: acpi_ns_match_complex_repair
Bob Mooread5babe2009-11-12 09:44:06 +0800196 *
Bob Mooreba494be2012-07-12 09:40:10 +0800197 * PARAMETERS: node - Namespace node for the method/object
Bob Mooread5babe2009-11-12 09:44:06 +0800198 *
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 Moored5a36102013-03-08 09:23:03 +0000205static const struct acpi_repair_info *acpi_ns_match_complex_repair(struct
206 acpi_namespace_node
207 *node)
Bob Mooread5babe2009-11-12 09:44:06 +0800208{
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 Moore29a241c2013-05-30 10:00:01 +0800228 * PARAMETERS: info - Method execution information block
Bob Mooread5babe2009-11-12 09:44:06 +0800229 * 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
239static acpi_status
Bob Moore29a241c2013-05-30 10:00:01 +0800240acpi_ns_repair_ALR(struct acpi_evaluate_info *info,
Bob Mooread5babe2009-11-12 09:44:06 +0800241 union acpi_operand_object **return_object_ptr)
242{
243 union acpi_operand_object *return_object = *return_object_ptr;
244 acpi_status status;
245
Bob Moore29a241c2013-05-30 10:00:01 +0800246 status = acpi_ns_check_sorted_list(info, return_object, 2, 1,
Bob Mooread5babe2009-11-12 09:44:06 +0800247 ACPI_SORT_ASCENDING,
248 "AmbientIlluminance");
249
250 return (status);
251}
252
253/******************************************************************************
254 *
Bob Moore34c39c72009-12-11 14:53:11 +0800255 * FUNCTION: acpi_ns_repair_FDE
256 *
Bob Moore29a241c2013-05-30 10:00:01 +0800257 * PARAMETERS: info - Method execution information block
Bob Moore34c39c72009-12-11 14:53:11 +0800258 * 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 Moore43420bb2009-12-11 15:24:27 +0800264 * 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 Moore34c39c72009-12-11 14:53:11 +0800267 *
268 *****************************************************************************/
269
270static acpi_status
Bob Moore29a241c2013-05-30 10:00:01 +0800271acpi_ns_repair_FDE(struct acpi_evaluate_info *info,
Bob Moore34c39c72009-12-11 14:53:11 +0800272 union acpi_operand_object **return_object_ptr)
273{
274 union acpi_operand_object *return_object = *return_object_ptr;
Bob Moore34c39c72009-12-11 14:53:11 +0800275 union acpi_operand_object *buffer_object;
276 u8 *byte_buffer;
277 u32 *dword_buffer;
Bob Moore34c39c72009-12-11 14:53:11 +0800278 u32 i;
279
Bob Moore3a581762009-12-11 15:23:22 +0800280 ACPI_FUNCTION_NAME(ns_repair_FDE);
281
Bob Moore34c39c72009-12-11 14:53:11 +0800282 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 Moore29a241c2013-05-30 10:00:01 +0800294 ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
295 info->node_flags,
Bob Moore34c39c72009-12-11 14:53:11 +0800296 "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 Moore3a581762009-12-11 15:23:22 +0800323 ACPI_DEBUG_PRINT((ACPI_DB_REPAIR,
324 "%s Expanded Byte Buffer to expected DWord Buffer\n",
Bob Moore29a241c2013-05-30 10:00:01 +0800325 info->full_pathname));
Bob Moore34c39c72009-12-11 14:53:11 +0800326 break;
327
Bob Moore34c39c72009-12-11 14:53:11 +0800328 default:
Chao Guan1d1ea1b2013-06-08 00:58:14 +0000329
Bob Moore34c39c72009-12-11 14:53:11 +0800330 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 Moore29a241c2013-05-30 10:00:01 +0800338 info->return_flags |= ACPI_OBJECT_REPAIRED;
Bob Moore34c39c72009-12-11 14:53:11 +0800339 return (AE_OK);
340}
341
342/******************************************************************************
343 *
Bob Moore77b23f7122010-09-15 14:11:02 +0800344 * FUNCTION: acpi_ns_repair_CID
345 *
Bob Moore29a241c2013-05-30 10:00:01 +0800346 * PARAMETERS: info - Method execution information block
Bob Moore77b23f7122010-09-15 14:11:02 +0800347 * 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
358static acpi_status
Bob Moore29a241c2013-05-30 10:00:01 +0800359acpi_ns_repair_CID(struct acpi_evaluate_info *info,
Bob Moore77b23f7122010-09-15 14:11:02 +0800360 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 Moore29a241c2013-05-30 10:00:01 +0800372 status = acpi_ns_repair_HID(info, return_object_ptr);
Bob Moore77b23f7122010-09-15 14:11:02 +0800373 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 Moore29a241c2013-05-30 10:00:01 +0800389 status = acpi_ns_repair_HID(info, element_ptr);
Bob Moore77b23f7122010-09-15 14:11:02 +0800390 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 Moore29a241c2013-05-30 10:00:01 +0800416 * PARAMETERS: info - Method execution information block
Bob Moore77b23f7122010-09-15 14:11:02 +0800417 * 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
427static acpi_status
Bob Moore29a241c2013-05-30 10:00:01 +0800428acpi_ns_repair_HID(struct acpi_evaluate_info *info,
Bob Moore77b23f7122010-09-15 14:11:02 +0800429 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 Moore29a241c2013-05-30 10:00:01 +0800445 ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
446 info->node_flags,
Bob Moore77b23f7122010-09-15 14:11:02 +0800447 "Invalid zero-length _HID or _CID string"));
448
449 /* Return AE_OK anyway, let driver handle it */
450
Bob Moore29a241c2013-05-30 10:00:01 +0800451 info->return_flags |= ACPI_OBJECT_REPAIRED;
Bob Moore77b23f7122010-09-15 14:11:02 +0800452 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 Moore29a241c2013-05-30 10:00:01 +0800475 info->full_pathname));
Bob Moore77b23f7122010-09-15 14:11:02 +0800476 }
477
478 /*
Bob Moore7fce7a42011-11-16 14:59:17 +0800479 * Copy and uppercase the string. From the ACPI 5.0 specification:
Bob Moore77b23f7122010-09-15 14:11:02 +0800480 *
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 Moore7fce7a42011-11-16 14:59:17 +0800483 * "NNNN####" where N is an uppercase letter or decimal digit, and
484 * # is a hex digit.
Bob Moore77b23f7122010-09-15 14:11:02 +0800485 */
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 Zhengaa6329c2013-06-08 09:01:01 +0800497 * FUNCTION: acpi_ns_repair_PRT
Bob Mooread5babe2009-11-12 09:44:06 +0800498 *
Bob Moore29a241c2013-05-30 10:00:01 +0800499 * PARAMETERS: info - Method execution information block
Bob Mooread5babe2009-11-12 09:44:06 +0800500 * 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 Zhengaa6329c2013-06-08 09:01:01 +0800505 * DESCRIPTION: Repair for the _PRT object. If necessary, fix reversed
506 * source_name and source_index field, a common BIOS bug.
Bob Mooread5babe2009-11-12 09:44:06 +0800507 *
508 *****************************************************************************/
509
510static acpi_status
Lv Zhengaa6329c2013-06-08 09:01:01 +0800511acpi_ns_repair_PRT(struct acpi_evaluate_info *info,
Bob Mooread5babe2009-11-12 09:44:06 +0800512 union acpi_operand_object **return_object_ptr)
513{
Lv Zhengaa6329c2013-06-08 09:01:01 +0800514 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 Yu8f9c9122011-07-04 08:36:16 +0000520
Lv Zhengaa6329c2013-06-08 09:01:01 +0800521 /* 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 Yu8f9c9122011-07-04 08:36:16 +0000550 }
Bob Mooread5babe2009-11-12 09:44:06 +0800551
Lv Zhengaa6329c2013-06-08 09:01:01 +0800552 return (AE_OK);
Bob Mooread5babe2009-11-12 09:44:06 +0800553}
554
555/******************************************************************************
556 *
557 * FUNCTION: acpi_ns_repair_PSS
558 *
Bob Moore29a241c2013-05-30 10:00:01 +0800559 * PARAMETERS: info - Method execution information block
Bob Mooread5babe2009-11-12 09:44:06 +0800560 * 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
572static acpi_status
Bob Moore29a241c2013-05-30 10:00:01 +0800573acpi_ns_repair_PSS(struct acpi_evaluate_info *info,
Bob Mooread5babe2009-11-12 09:44:06 +0800574 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 Moore29a241c2013-05-30 10:00:01 +0800591 status = acpi_ns_check_sorted_list(info, return_object, 6, 0,
Bob Mooread5babe2009-11-12 09:44:06 +0800592 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 Moore29a241c2013-05-30 10:00:01 +0800611 ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
612 info->node_flags,
Bob Mooread5babe2009-11-12 09:44:06 +0800613 "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 Zhengaa6329c2013-06-08 09:01:01 +0800626 * 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
639static acpi_status
640acpi_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 Mooread5babe2009-11-12 09:44:06 +0800670 * FUNCTION: acpi_ns_check_sorted_list
671 *
Bob Moore29a241c2013-05-30 10:00:01 +0800672 * PARAMETERS: info - Method execution information block
Bob Mooread5babe2009-11-12 09:44:06 +0800673 * 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
687static acpi_status
Bob Moore29a241c2013-05-30 10:00:01 +0800688acpi_ns_check_sorted_list(struct acpi_evaluate_info *info,
Bob Mooread5babe2009-11-12 09:44:06 +0800689 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 Mooread5babe2009-11-12 09:44:06 +0800700
Bob Moore3a581762009-12-11 15:23:22 +0800701 ACPI_FUNCTION_NAME(ns_check_sorted_list);
702
Bob Mooread5babe2009-11-12 09:44:06 +0800703 /* 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 Moored4085a32009-12-11 15:29:44 +0800710 * 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 Mooread5babe2009-11-12 09:44:06 +0800713 */
Bob Mooread5babe2009-11-12 09:44:06 +0800714 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 Moore2147d3f2010-01-21 09:08:31 +0800750 * discrepancy, sort the entire list.
Bob Mooread5babe2009-11-12 09:44:06 +0800751 */
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 Moore2147d3f2010-01-21 09:08:31 +0800756 acpi_ns_sort_list(return_object->package.elements,
757 outer_element_count, sort_index,
758 sort_direction);
Bob Mooread5babe2009-11-12 09:44:06 +0800759
Bob Moore29a241c2013-05-30 10:00:01 +0800760 info->return_flags |= ACPI_OBJECT_REPAIRED;
Bob Mooread5babe2009-11-12 09:44:06 +0800761
Bob Moore3a581762009-12-11 15:23:22 +0800762 ACPI_DEBUG_PRINT((ACPI_DB_REPAIR,
763 "%s: Repaired unsorted list - now sorted by %s\n",
Bob Moore29a241c2013-05-30 10:00:01 +0800764 info->full_pathname, sort_key_name));
Bob Mooread5babe2009-11-12 09:44:06 +0800765 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 Mooread5babe2009-11-12 09:44:06 +0800777 * FUNCTION: acpi_ns_sort_list
778 *
Bob Mooreba494be2012-07-12 09:40:10 +0800779 * PARAMETERS: elements - Package object element list
780 * count - Element count for above
781 * index - Sort by which package element
Bob Mooread5babe2009-11-12 09:44:06 +0800782 * sort_direction - Ascending or Descending sort
783 *
Bob Moore2147d3f2010-01-21 09:08:31 +0800784 * RETURN: None
Bob Mooread5babe2009-11-12 09:44:06 +0800785 *
786 * DESCRIPTION: Sort the objects that are in a package element list.
787 *
Bob Moore2147d3f2010-01-21 09:08:31 +0800788 * 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 Mooread5babe2009-11-12 09:44:06 +0800790 *
791 *****************************************************************************/
792
Bob Moore2147d3f2010-01-21 09:08:31 +0800793static void
Bob Mooread5babe2009-11-12 09:44:06 +0800794acpi_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 Mooread5babe2009-11-12 09:44:06 +0800822}