blob: c84603ee83ae084312f3936324a1bfb524b64f08 [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
Lv Zheng5a9792f2013-06-08 09:01:07 +080082acpi_ns_repair_CST(struct acpi_evaluate_info *info,
83 union acpi_operand_object **return_object_ptr);
84
85static acpi_status
Bob Moore29a241c2013-05-30 10:00:01 +080086acpi_ns_repair_FDE(struct acpi_evaluate_info *info,
Bob Moore34c39c72009-12-11 14:53:11 +080087 union acpi_operand_object **return_object_ptr);
88
89static acpi_status
Bob Moore29a241c2013-05-30 10:00:01 +080090acpi_ns_repair_HID(struct acpi_evaluate_info *info,
Bob Moore77b23f7122010-09-15 14:11:02 +080091 union acpi_operand_object **return_object_ptr);
92
93static acpi_status
Lv Zhengaa6329c2013-06-08 09:01:01 +080094acpi_ns_repair_PRT(struct acpi_evaluate_info *info,
95 union acpi_operand_object **return_object_ptr);
96
97static acpi_status
Bob Moore29a241c2013-05-30 10:00:01 +080098acpi_ns_repair_PSS(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_repair_TSS(struct acpi_evaluate_info *info,
Bob Mooread5babe2009-11-12 09:44:06 +0800103 union acpi_operand_object **return_object_ptr);
104
105static acpi_status
Bob Moore29a241c2013-05-30 10:00:01 +0800106acpi_ns_check_sorted_list(struct acpi_evaluate_info *info,
Bob Mooread5babe2009-11-12 09:44:06 +0800107 union acpi_operand_object *return_object,
Lv Zheng5a9792f2013-06-08 09:01:07 +0800108 u32 start_index,
Bob Mooread5babe2009-11-12 09:44:06 +0800109 u32 expected_count,
110 u32 sort_index,
111 u8 sort_direction, char *sort_key_name);
112
Bob Mooread5babe2009-11-12 09:44:06 +0800113/* Values for sort_direction above */
114
115#define ACPI_SORT_ASCENDING 0
116#define ACPI_SORT_DESCENDING 1
117
Lv Zheng5a9792f2013-06-08 09:01:07 +0800118static void
119acpi_ns_remove_element(union acpi_operand_object *obj_desc, u32 index);
120
121static void
122acpi_ns_sort_list(union acpi_operand_object **elements,
123 u32 count, u32 index, u8 sort_direction);
124
Bob Mooread5babe2009-11-12 09:44:06 +0800125/*
126 * This table contains the names of the predefined methods for which we can
127 * perform more complex repairs.
128 *
Bob Moore34c39c72009-12-11 14:53:11 +0800129 * As necessary:
130 *
131 * _ALR: Sort the list ascending by ambient_illuminance
Bob Moore77b23f7122010-09-15 14:11:02 +0800132 * _CID: Strings: uppercase all, remove any leading asterisk
Lv Zheng5a9792f2013-06-08 09:01:07 +0800133 * _CST: Sort the list ascending by C state type
Bob Moore43420bb2009-12-11 15:24:27 +0800134 * _FDE: Convert Buffer of BYTEs to a Buffer of DWORDs
135 * _GTM: Convert Buffer of BYTEs to a Buffer of DWORDs
Bob Moore77b23f7122010-09-15 14:11:02 +0800136 * _HID: Strings: uppercase all, remove any leading asterisk
Lv Zhengaa6329c2013-06-08 09:01:01 +0800137 * _PRT: Fix reversed source_name and source_index
Bob Moore34c39c72009-12-11 14:53:11 +0800138 * _PSS: Sort the list descending by Power
139 * _TSS: Sort the list descending by Power
Bob Mooreaa9d3602010-05-26 11:03:56 +0800140 *
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 Mooread5babe2009-11-12 09:44:06 +0800147 */
148static const struct acpi_repair_info acpi_ns_repairable_names[] = {
149 {"_ALR", acpi_ns_repair_ALR},
Bob Moore77b23f7122010-09-15 14:11:02 +0800150 {"_CID", acpi_ns_repair_CID},
Lv Zheng5a9792f2013-06-08 09:01:07 +0800151 {"_CST", acpi_ns_repair_CST},
Bob Moore34c39c72009-12-11 14:53:11 +0800152 {"_FDE", acpi_ns_repair_FDE},
153 {"_GTM", acpi_ns_repair_FDE}, /* _GTM has same repair as _FDE */
Bob Moore77b23f7122010-09-15 14:11:02 +0800154 {"_HID", acpi_ns_repair_HID},
Lv Zhengaa6329c2013-06-08 09:01:01 +0800155 {"_PRT", acpi_ns_repair_PRT},
Bob Mooread5babe2009-11-12 09:44:06 +0800156 {"_PSS", acpi_ns_repair_PSS},
157 {"_TSS", acpi_ns_repair_TSS},
158 {{0, 0, 0, 0}, NULL} /* Table terminator */
159};
160
Bob Moore34c39c72009-12-11 14:53:11 +0800161#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 Mooread5babe2009-11-12 09:44:06 +0800165/******************************************************************************
166 *
167 * FUNCTION: acpi_ns_complex_repairs
168 *
Bob Moore29a241c2013-05-30 10:00:01 +0800169 * PARAMETERS: info - Method execution information block
Bob Mooreba494be2012-07-12 09:40:10 +0800170 * node - Namespace node for the method/object
Bob Mooread5babe2009-11-12 09:44:06 +0800171 * 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
183acpi_status
Bob Moore29a241c2013-05-30 10:00:01 +0800184acpi_ns_complex_repairs(struct acpi_evaluate_info *info,
Bob Mooread5babe2009-11-12 09:44:06 +0800185 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 Moored5a36102013-03-08 09:23:03 +0000194 predefined = acpi_ns_match_complex_repair(node);
Bob Mooread5babe2009-11-12 09:44:06 +0800195 if (!predefined) {
196 return (validate_status);
197 }
198
Bob Moore29a241c2013-05-30 10:00:01 +0800199 status = predefined->repair_function(info, return_object_ptr);
Bob Mooread5babe2009-11-12 09:44:06 +0800200 return (status);
201}
202
203/******************************************************************************
204 *
Bob Moored5a36102013-03-08 09:23:03 +0000205 * FUNCTION: acpi_ns_match_complex_repair
Bob Mooread5babe2009-11-12 09:44:06 +0800206 *
Bob Mooreba494be2012-07-12 09:40:10 +0800207 * PARAMETERS: node - Namespace node for the method/object
Bob Mooread5babe2009-11-12 09:44:06 +0800208 *
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 Moored5a36102013-03-08 09:23:03 +0000215static const struct acpi_repair_info *acpi_ns_match_complex_repair(struct
216 acpi_namespace_node
217 *node)
Bob Mooread5babe2009-11-12 09:44:06 +0800218{
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 }
228 this_name++;
229 }
230
231 return (NULL); /* Not found */
232}
233
234/******************************************************************************
235 *
236 * FUNCTION: acpi_ns_repair_ALR
237 *
Bob Moore29a241c2013-05-30 10:00:01 +0800238 * PARAMETERS: info - Method execution information block
Bob Mooread5babe2009-11-12 09:44:06 +0800239 * return_object_ptr - Pointer to the object returned from the
240 * evaluation of a method or object
241 *
242 * RETURN: Status. AE_OK if object is OK or was repaired successfully
243 *
244 * DESCRIPTION: Repair for the _ALR object. If necessary, sort the object list
245 * ascending by the ambient illuminance values.
246 *
247 *****************************************************************************/
248
249static acpi_status
Bob Moore29a241c2013-05-30 10:00:01 +0800250acpi_ns_repair_ALR(struct acpi_evaluate_info *info,
Bob Mooread5babe2009-11-12 09:44:06 +0800251 union acpi_operand_object **return_object_ptr)
252{
253 union acpi_operand_object *return_object = *return_object_ptr;
254 acpi_status status;
255
Lv Zheng5a9792f2013-06-08 09:01:07 +0800256 status = acpi_ns_check_sorted_list(info, return_object, 0, 2, 1,
Bob Mooread5babe2009-11-12 09:44:06 +0800257 ACPI_SORT_ASCENDING,
258 "AmbientIlluminance");
259
260 return (status);
261}
262
263/******************************************************************************
264 *
Bob Moore34c39c72009-12-11 14:53:11 +0800265 * FUNCTION: acpi_ns_repair_FDE
266 *
Bob Moore29a241c2013-05-30 10:00:01 +0800267 * PARAMETERS: info - Method execution information block
Bob Moore34c39c72009-12-11 14:53:11 +0800268 * return_object_ptr - Pointer to the object returned from the
269 * evaluation of a method or object
270 *
271 * RETURN: Status. AE_OK if object is OK or was repaired successfully
272 *
273 * DESCRIPTION: Repair for the _FDE and _GTM objects. The expected return
Bob Moore43420bb2009-12-11 15:24:27 +0800274 * value is a Buffer of 5 DWORDs. This function repairs a common
275 * problem where the return value is a Buffer of BYTEs, not
276 * DWORDs.
Bob Moore34c39c72009-12-11 14:53:11 +0800277 *
278 *****************************************************************************/
279
280static acpi_status
Bob Moore29a241c2013-05-30 10:00:01 +0800281acpi_ns_repair_FDE(struct acpi_evaluate_info *info,
Bob Moore34c39c72009-12-11 14:53:11 +0800282 union acpi_operand_object **return_object_ptr)
283{
284 union acpi_operand_object *return_object = *return_object_ptr;
Bob Moore34c39c72009-12-11 14:53:11 +0800285 union acpi_operand_object *buffer_object;
286 u8 *byte_buffer;
287 u32 *dword_buffer;
Bob Moore34c39c72009-12-11 14:53:11 +0800288 u32 i;
289
Bob Moore3a581762009-12-11 15:23:22 +0800290 ACPI_FUNCTION_NAME(ns_repair_FDE);
291
Bob Moore34c39c72009-12-11 14:53:11 +0800292 switch (return_object->common.type) {
293 case ACPI_TYPE_BUFFER:
294
295 /* This is the expected type. Length should be (at least) 5 DWORDs */
296
297 if (return_object->buffer.length >= ACPI_FDE_DWORD_BUFFER_SIZE) {
298 return (AE_OK);
299 }
300
301 /* We can only repair if we have exactly 5 BYTEs */
302
303 if (return_object->buffer.length != ACPI_FDE_BYTE_BUFFER_SIZE) {
Bob Moore29a241c2013-05-30 10:00:01 +0800304 ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
305 info->node_flags,
Bob Moore34c39c72009-12-11 14:53:11 +0800306 "Incorrect return buffer length %u, expected %u",
307 return_object->buffer.length,
308 ACPI_FDE_DWORD_BUFFER_SIZE));
309
310 return (AE_AML_OPERAND_TYPE);
311 }
312
313 /* Create the new (larger) buffer object */
314
315 buffer_object =
316 acpi_ut_create_buffer_object(ACPI_FDE_DWORD_BUFFER_SIZE);
317 if (!buffer_object) {
318 return (AE_NO_MEMORY);
319 }
320
321 /* Expand each byte to a DWORD */
322
323 byte_buffer = return_object->buffer.pointer;
324 dword_buffer =
325 ACPI_CAST_PTR(u32, buffer_object->buffer.pointer);
326
327 for (i = 0; i < ACPI_FDE_FIELD_COUNT; i++) {
328 *dword_buffer = (u32) *byte_buffer;
329 dword_buffer++;
330 byte_buffer++;
331 }
332
Bob Moore3a581762009-12-11 15:23:22 +0800333 ACPI_DEBUG_PRINT((ACPI_DB_REPAIR,
334 "%s Expanded Byte Buffer to expected DWord Buffer\n",
Bob Moore29a241c2013-05-30 10:00:01 +0800335 info->full_pathname));
Bob Moore34c39c72009-12-11 14:53:11 +0800336 break;
337
Bob Moore34c39c72009-12-11 14:53:11 +0800338 default:
Chao Guan1d1ea1b2013-06-08 00:58:14 +0000339
Bob Moore34c39c72009-12-11 14:53:11 +0800340 return (AE_AML_OPERAND_TYPE);
341 }
342
343 /* Delete the original return object, return the new buffer object */
344
345 acpi_ut_remove_reference(return_object);
346 *return_object_ptr = buffer_object;
347
Bob Moore29a241c2013-05-30 10:00:01 +0800348 info->return_flags |= ACPI_OBJECT_REPAIRED;
Bob Moore34c39c72009-12-11 14:53:11 +0800349 return (AE_OK);
350}
351
352/******************************************************************************
353 *
Bob Moore77b23f7122010-09-15 14:11:02 +0800354 * FUNCTION: acpi_ns_repair_CID
355 *
Bob Moore29a241c2013-05-30 10:00:01 +0800356 * PARAMETERS: info - Method execution information block
Bob Moore77b23f7122010-09-15 14:11:02 +0800357 * return_object_ptr - Pointer to the object returned from the
358 * evaluation of a method or object
359 *
360 * RETURN: Status. AE_OK if object is OK or was repaired successfully
361 *
362 * DESCRIPTION: Repair for the _CID object. If a string, ensure that all
363 * letters are uppercase and that there is no leading asterisk.
364 * If a Package, ensure same for all string elements.
365 *
366 *****************************************************************************/
367
368static acpi_status
Bob Moore29a241c2013-05-30 10:00:01 +0800369acpi_ns_repair_CID(struct acpi_evaluate_info *info,
Bob Moore77b23f7122010-09-15 14:11:02 +0800370 union acpi_operand_object **return_object_ptr)
371{
372 acpi_status status;
373 union acpi_operand_object *return_object = *return_object_ptr;
374 union acpi_operand_object **element_ptr;
375 union acpi_operand_object *original_element;
376 u16 original_ref_count;
377 u32 i;
378
379 /* Check for _CID as a simple string */
380
381 if (return_object->common.type == ACPI_TYPE_STRING) {
Bob Moore29a241c2013-05-30 10:00:01 +0800382 status = acpi_ns_repair_HID(info, return_object_ptr);
Bob Moore77b23f7122010-09-15 14:11:02 +0800383 return (status);
384 }
385
386 /* Exit if not a Package */
387
388 if (return_object->common.type != ACPI_TYPE_PACKAGE) {
389 return (AE_OK);
390 }
391
392 /* Examine each element of the _CID package */
393
394 element_ptr = return_object->package.elements;
395 for (i = 0; i < return_object->package.count; i++) {
396 original_element = *element_ptr;
397 original_ref_count = original_element->common.reference_count;
398
Bob Moore29a241c2013-05-30 10:00:01 +0800399 status = acpi_ns_repair_HID(info, element_ptr);
Bob Moore77b23f7122010-09-15 14:11:02 +0800400 if (ACPI_FAILURE(status)) {
401 return (status);
402 }
403
404 /* Take care with reference counts */
405
406 if (original_element != *element_ptr) {
407
408 /* Element was replaced */
409
410 (*element_ptr)->common.reference_count =
411 original_ref_count;
412
413 acpi_ut_remove_reference(original_element);
414 }
415
416 element_ptr++;
417 }
418
419 return (AE_OK);
420}
421
422/******************************************************************************
423 *
Lv Zheng5a9792f2013-06-08 09:01:07 +0800424 * FUNCTION: acpi_ns_repair_CST
425 *
426 * PARAMETERS: info - Method execution information block
427 * return_object_ptr - Pointer to the object returned from the
428 * evaluation of a method or object
429 *
430 * RETURN: Status. AE_OK if object is OK or was repaired successfully
431 *
432 * DESCRIPTION: Repair for the _CST object:
433 * 1. Sort the list ascending by C state type
434 * 2. Ensure type cannot be zero
435 * 3. A sub-package count of zero means _CST is meaningless
436 * 4. Count must match the number of C state sub-packages
437 *
438 *****************************************************************************/
439
440static acpi_status
441acpi_ns_repair_CST(struct acpi_evaluate_info *info,
442 union acpi_operand_object **return_object_ptr)
443{
444 union acpi_operand_object *return_object = *return_object_ptr;
445 union acpi_operand_object **outer_elements;
446 u32 outer_element_count;
447 union acpi_operand_object *obj_desc;
448 acpi_status status;
449 u8 removing;
450 u32 i;
451
452 ACPI_FUNCTION_NAME(ns_repair_CST);
453
454 /*
Lv Zheng341e7ba2013-06-08 09:01:19 +0800455 * Check if the C-state type values are proportional.
Lv Zheng5a9792f2013-06-08 09:01:07 +0800456 */
457 outer_element_count = return_object->package.count - 1;
458 i = 0;
459 while (i < outer_element_count) {
460 outer_elements = &return_object->package.elements[i + 1];
461 removing = FALSE;
462
463 if ((*outer_elements)->package.count == 0) {
464 ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
465 info->node_flags,
466 "SubPackage[%u] - removing entry due to zero count",
467 i));
468 removing = TRUE;
469 goto remove_element;
470 }
471
472 obj_desc = (*outer_elements)->package.elements[1]; /* Index1 = Type */
473 if ((u32)obj_desc->integer.value == 0) {
474 ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
475 info->node_flags,
476 "SubPackage[%u] - removing entry due to invalid Type(0)",
477 i));
478 removing = TRUE;
479 }
480
481 remove_element:
482 if (removing) {
483 acpi_ns_remove_element(return_object, i + 1);
484 outer_element_count--;
485 } else {
486 i++;
487 }
488 }
489
490 /* Update top-level package count, Type "Integer" checked elsewhere */
491
492 obj_desc = return_object->package.elements[0];
493 obj_desc->integer.value = outer_element_count;
Lv Zheng341e7ba2013-06-08 09:01:19 +0800494
495 /*
496 * Entries (subpackages) in the _CST Package must be sorted by the
497 * C-state type, in ascending order.
498 */
499 status = acpi_ns_check_sorted_list(info, return_object, 1, 4, 1,
500 ACPI_SORT_ASCENDING, "C-State Type");
501 if (ACPI_FAILURE(status)) {
502 return (status);
503 }
504
Lv Zheng5a9792f2013-06-08 09:01:07 +0800505 return (AE_OK);
506}
507
508/******************************************************************************
509 *
Bob Moore77b23f7122010-09-15 14:11:02 +0800510 * FUNCTION: acpi_ns_repair_HID
511 *
Bob Moore29a241c2013-05-30 10:00:01 +0800512 * PARAMETERS: info - Method execution information block
Bob Moore77b23f7122010-09-15 14:11:02 +0800513 * return_object_ptr - Pointer to the object returned from the
514 * evaluation of a method or object
515 *
516 * RETURN: Status. AE_OK if object is OK or was repaired successfully
517 *
518 * DESCRIPTION: Repair for the _HID object. If a string, ensure that all
519 * letters are uppercase and that there is no leading asterisk.
520 *
521 *****************************************************************************/
522
523static acpi_status
Bob Moore29a241c2013-05-30 10:00:01 +0800524acpi_ns_repair_HID(struct acpi_evaluate_info *info,
Bob Moore77b23f7122010-09-15 14:11:02 +0800525 union acpi_operand_object **return_object_ptr)
526{
527 union acpi_operand_object *return_object = *return_object_ptr;
528 union acpi_operand_object *new_string;
529 char *source;
530 char *dest;
531
532 ACPI_FUNCTION_NAME(ns_repair_HID);
533
534 /* We only care about string _HID objects (not integers) */
535
536 if (return_object->common.type != ACPI_TYPE_STRING) {
537 return (AE_OK);
538 }
539
540 if (return_object->string.length == 0) {
Bob Moore29a241c2013-05-30 10:00:01 +0800541 ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
542 info->node_flags,
Bob Moore77b23f7122010-09-15 14:11:02 +0800543 "Invalid zero-length _HID or _CID string"));
544
545 /* Return AE_OK anyway, let driver handle it */
546
Bob Moore29a241c2013-05-30 10:00:01 +0800547 info->return_flags |= ACPI_OBJECT_REPAIRED;
Bob Moore77b23f7122010-09-15 14:11:02 +0800548 return (AE_OK);
549 }
550
551 /* It is simplest to always create a new string object */
552
553 new_string = acpi_ut_create_string_object(return_object->string.length);
554 if (!new_string) {
555 return (AE_NO_MEMORY);
556 }
557
558 /*
559 * Remove a leading asterisk if present. For some unknown reason, there
560 * are many machines in the field that contains IDs like this.
561 *
562 * Examples: "*PNP0C03", "*ACPI0003"
563 */
564 source = return_object->string.pointer;
565 if (*source == '*') {
566 source++;
567 new_string->string.length--;
568
569 ACPI_DEBUG_PRINT((ACPI_DB_REPAIR,
570 "%s: Removed invalid leading asterisk\n",
Bob Moore29a241c2013-05-30 10:00:01 +0800571 info->full_pathname));
Bob Moore77b23f7122010-09-15 14:11:02 +0800572 }
573
574 /*
Bob Moore7fce7a42011-11-16 14:59:17 +0800575 * Copy and uppercase the string. From the ACPI 5.0 specification:
Bob Moore77b23f7122010-09-15 14:11:02 +0800576 *
577 * A valid PNP ID must be of the form "AAA####" where A is an uppercase
578 * letter and # is a hex digit. A valid ACPI ID must be of the form
Bob Moore7fce7a42011-11-16 14:59:17 +0800579 * "NNNN####" where N is an uppercase letter or decimal digit, and
580 * # is a hex digit.
Bob Moore77b23f7122010-09-15 14:11:02 +0800581 */
582 for (dest = new_string->string.pointer; *source; dest++, source++) {
583 *dest = (char)ACPI_TOUPPER(*source);
584 }
585
586 acpi_ut_remove_reference(return_object);
587 *return_object_ptr = new_string;
588 return (AE_OK);
589}
590
591/******************************************************************************
592 *
Lv Zhengaa6329c2013-06-08 09:01:01 +0800593 * FUNCTION: acpi_ns_repair_PRT
Bob Mooread5babe2009-11-12 09:44:06 +0800594 *
Bob Moore29a241c2013-05-30 10:00:01 +0800595 * PARAMETERS: info - Method execution information block
Bob Mooread5babe2009-11-12 09:44:06 +0800596 * return_object_ptr - Pointer to the object returned from the
597 * evaluation of a method or object
598 *
599 * RETURN: Status. AE_OK if object is OK or was repaired successfully
600 *
Lv Zhengaa6329c2013-06-08 09:01:01 +0800601 * DESCRIPTION: Repair for the _PRT object. If necessary, fix reversed
602 * source_name and source_index field, a common BIOS bug.
Bob Mooread5babe2009-11-12 09:44:06 +0800603 *
604 *****************************************************************************/
605
606static acpi_status
Lv Zhengaa6329c2013-06-08 09:01:01 +0800607acpi_ns_repair_PRT(struct acpi_evaluate_info *info,
Bob Mooread5babe2009-11-12 09:44:06 +0800608 union acpi_operand_object **return_object_ptr)
609{
Lv Zhengaa6329c2013-06-08 09:01:01 +0800610 union acpi_operand_object *package_object = *return_object_ptr;
611 union acpi_operand_object **top_object_list;
612 union acpi_operand_object **sub_object_list;
613 union acpi_operand_object *obj_desc;
614 u32 element_count;
615 u32 index;
Fenghua Yu8f9c9122011-07-04 08:36:16 +0000616
Lv Zhengaa6329c2013-06-08 09:01:01 +0800617 /* Each element in the _PRT package is a subpackage */
618
619 top_object_list = package_object->package.elements;
620 element_count = package_object->package.count;
621
622 for (index = 0; index < element_count; index++) {
623 sub_object_list = (*top_object_list)->package.elements;
624
625 /*
626 * If the BIOS has erroneously reversed the _PRT source_name (index 2)
627 * and the source_index (index 3), fix it. _PRT is important enough to
628 * workaround this BIOS error. This also provides compatibility with
629 * other ACPI implementations.
630 */
631 obj_desc = sub_object_list[3];
632 if (!obj_desc || (obj_desc->common.type != ACPI_TYPE_INTEGER)) {
633 sub_object_list[3] = sub_object_list[2];
634 sub_object_list[2] = obj_desc;
635 info->return_flags |= ACPI_OBJECT_REPAIRED;
636
637 ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
638 info->node_flags,
639 "PRT[%X]: Fixed reversed SourceName and SourceIndex",
640 index));
641 }
642
643 /* Point to the next union acpi_operand_object in the top level package */
644
645 top_object_list++;
Fenghua Yu8f9c9122011-07-04 08:36:16 +0000646 }
Bob Mooread5babe2009-11-12 09:44:06 +0800647
Lv Zhengaa6329c2013-06-08 09:01:01 +0800648 return (AE_OK);
Bob Mooread5babe2009-11-12 09:44:06 +0800649}
650
651/******************************************************************************
652 *
653 * FUNCTION: acpi_ns_repair_PSS
654 *
Bob Moore29a241c2013-05-30 10:00:01 +0800655 * PARAMETERS: info - Method execution information block
Bob Mooread5babe2009-11-12 09:44:06 +0800656 * return_object_ptr - Pointer to the object returned from the
657 * evaluation of a method or object
658 *
659 * RETURN: Status. AE_OK if object is OK or was repaired successfully
660 *
661 * DESCRIPTION: Repair for the _PSS object. If necessary, sort the object list
662 * by the CPU frequencies. Check that the power dissipation values
663 * are all proportional to CPU frequency (i.e., sorting by
664 * frequency should be the same as sorting by power.)
665 *
666 *****************************************************************************/
667
668static acpi_status
Bob Moore29a241c2013-05-30 10:00:01 +0800669acpi_ns_repair_PSS(struct acpi_evaluate_info *info,
Bob Mooread5babe2009-11-12 09:44:06 +0800670 union acpi_operand_object **return_object_ptr)
671{
672 union acpi_operand_object *return_object = *return_object_ptr;
673 union acpi_operand_object **outer_elements;
674 u32 outer_element_count;
675 union acpi_operand_object **elements;
676 union acpi_operand_object *obj_desc;
677 u32 previous_value;
678 acpi_status status;
679 u32 i;
680
681 /*
682 * Entries (sub-packages) in the _PSS Package must be sorted by power
683 * dissipation, in descending order. If it appears that the list is
684 * incorrectly sorted, sort it. We sort by cpu_frequency, since this
685 * should be proportional to the power.
686 */
Lv Zheng5a9792f2013-06-08 09:01:07 +0800687 status = acpi_ns_check_sorted_list(info, return_object, 0, 6, 0,
Bob Mooread5babe2009-11-12 09:44:06 +0800688 ACPI_SORT_DESCENDING,
689 "CpuFrequency");
690 if (ACPI_FAILURE(status)) {
691 return (status);
692 }
693
694 /*
695 * We now know the list is correctly sorted by CPU frequency. Check if
696 * the power dissipation values are proportional.
697 */
698 previous_value = ACPI_UINT32_MAX;
699 outer_elements = return_object->package.elements;
700 outer_element_count = return_object->package.count;
701
702 for (i = 0; i < outer_element_count; i++) {
703 elements = (*outer_elements)->package.elements;
704 obj_desc = elements[1]; /* Index1 = power_dissipation */
705
706 if ((u32) obj_desc->integer.value > previous_value) {
Bob Moore29a241c2013-05-30 10:00:01 +0800707 ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
708 info->node_flags,
Bob Mooread5babe2009-11-12 09:44:06 +0800709 "SubPackage[%u,%u] - suspicious power dissipation values",
710 i - 1, i));
711 }
712
713 previous_value = (u32) obj_desc->integer.value;
714 outer_elements++;
715 }
716
717 return (AE_OK);
718}
719
720/******************************************************************************
721 *
Lv Zhengaa6329c2013-06-08 09:01:01 +0800722 * FUNCTION: acpi_ns_repair_TSS
723 *
724 * PARAMETERS: info - Method execution information block
725 * return_object_ptr - Pointer to the object returned from the
726 * evaluation of a method or object
727 *
728 * RETURN: Status. AE_OK if object is OK or was repaired successfully
729 *
730 * DESCRIPTION: Repair for the _TSS object. If necessary, sort the object list
731 * descending by the power dissipation values.
732 *
733 *****************************************************************************/
734
735static acpi_status
736acpi_ns_repair_TSS(struct acpi_evaluate_info *info,
737 union acpi_operand_object **return_object_ptr)
738{
739 union acpi_operand_object *return_object = *return_object_ptr;
740 acpi_status status;
741 struct acpi_namespace_node *node;
742
743 /*
744 * We can only sort the _TSS return package if there is no _PSS in the
745 * same scope. This is because if _PSS is present, the ACPI specification
746 * dictates that the _TSS Power Dissipation field is to be ignored, and
747 * therefore some BIOSs leave garbage values in the _TSS Power field(s).
748 * In this case, it is best to just return the _TSS package as-is.
749 * (May, 2011)
750 */
751 status = acpi_ns_get_node(info->node, "^_PSS",
752 ACPI_NS_NO_UPSEARCH, &node);
753 if (ACPI_SUCCESS(status)) {
754 return (AE_OK);
755 }
756
Lv Zheng5a9792f2013-06-08 09:01:07 +0800757 status = acpi_ns_check_sorted_list(info, return_object, 0, 5, 1,
Lv Zhengaa6329c2013-06-08 09:01:01 +0800758 ACPI_SORT_DESCENDING,
759 "PowerDissipation");
760
761 return (status);
762}
763
764/******************************************************************************
765 *
Bob Mooread5babe2009-11-12 09:44:06 +0800766 * FUNCTION: acpi_ns_check_sorted_list
767 *
Bob Moore29a241c2013-05-30 10:00:01 +0800768 * PARAMETERS: info - Method execution information block
Bob Mooread5babe2009-11-12 09:44:06 +0800769 * return_object - Pointer to the top-level returned object
Lv Zheng5a9792f2013-06-08 09:01:07 +0800770 * start_index - Index of the first sub-package
Bob Mooread5babe2009-11-12 09:44:06 +0800771 * expected_count - Minimum length of each sub-package
772 * sort_index - Sub-package entry to sort on
773 * sort_direction - Ascending or descending
774 * sort_key_name - Name of the sort_index field
775 *
776 * RETURN: Status. AE_OK if the list is valid and is sorted correctly or
777 * has been repaired by sorting the list.
778 *
779 * DESCRIPTION: Check if the package list is valid and sorted correctly by the
780 * sort_index. If not, then sort the list.
781 *
782 *****************************************************************************/
783
784static acpi_status
Bob Moore29a241c2013-05-30 10:00:01 +0800785acpi_ns_check_sorted_list(struct acpi_evaluate_info *info,
Bob Mooread5babe2009-11-12 09:44:06 +0800786 union acpi_operand_object *return_object,
Lv Zheng5a9792f2013-06-08 09:01:07 +0800787 u32 start_index,
Bob Mooread5babe2009-11-12 09:44:06 +0800788 u32 expected_count,
789 u32 sort_index,
790 u8 sort_direction, char *sort_key_name)
791{
792 u32 outer_element_count;
793 union acpi_operand_object **outer_elements;
794 union acpi_operand_object **elements;
795 union acpi_operand_object *obj_desc;
796 u32 i;
797 u32 previous_value;
Bob Mooread5babe2009-11-12 09:44:06 +0800798
Bob Moore3a581762009-12-11 15:23:22 +0800799 ACPI_FUNCTION_NAME(ns_check_sorted_list);
800
Bob Mooread5babe2009-11-12 09:44:06 +0800801 /* The top-level object must be a package */
802
803 if (return_object->common.type != ACPI_TYPE_PACKAGE) {
804 return (AE_AML_OPERAND_TYPE);
805 }
806
807 /*
Bob Moored4085a3f2009-12-11 15:29:44 +0800808 * NOTE: assumes list of sub-packages contains no NULL elements.
809 * Any NULL elements should have been removed by earlier call
810 * to acpi_ns_remove_null_elements.
Bob Mooread5babe2009-11-12 09:44:06 +0800811 */
Bob Mooread5babe2009-11-12 09:44:06 +0800812 outer_element_count = return_object->package.count;
Lv Zheng5a9792f2013-06-08 09:01:07 +0800813 if (!outer_element_count || start_index >= outer_element_count) {
Bob Mooread5babe2009-11-12 09:44:06 +0800814 return (AE_AML_PACKAGE_LIMIT);
815 }
816
Lv Zheng5a9792f2013-06-08 09:01:07 +0800817 outer_elements = &return_object->package.elements[start_index];
818 outer_element_count -= start_index;
819
Bob Mooread5babe2009-11-12 09:44:06 +0800820 previous_value = 0;
821 if (sort_direction == ACPI_SORT_DESCENDING) {
822 previous_value = ACPI_UINT32_MAX;
823 }
824
825 /* Examine each subpackage */
826
827 for (i = 0; i < outer_element_count; i++) {
828
829 /* Each element of the top-level package must also be a package */
830
831 if ((*outer_elements)->common.type != ACPI_TYPE_PACKAGE) {
832 return (AE_AML_OPERAND_TYPE);
833 }
834
835 /* Each sub-package must have the minimum length */
836
837 if ((*outer_elements)->package.count < expected_count) {
838 return (AE_AML_PACKAGE_LIMIT);
839 }
840
841 elements = (*outer_elements)->package.elements;
842 obj_desc = elements[sort_index];
843
844 if (obj_desc->common.type != ACPI_TYPE_INTEGER) {
845 return (AE_AML_OPERAND_TYPE);
846 }
847
848 /*
849 * The list must be sorted in the specified order. If we detect a
Bob Moore2147d3f2010-01-21 09:08:31 +0800850 * discrepancy, sort the entire list.
Bob Mooread5babe2009-11-12 09:44:06 +0800851 */
852 if (((sort_direction == ACPI_SORT_ASCENDING) &&
853 (obj_desc->integer.value < previous_value)) ||
854 ((sort_direction == ACPI_SORT_DESCENDING) &&
855 (obj_desc->integer.value > previous_value))) {
Lv Zheng5a9792f2013-06-08 09:01:07 +0800856 acpi_ns_sort_list(&return_object->package.
857 elements[start_index],
Bob Moore2147d3f2010-01-21 09:08:31 +0800858 outer_element_count, sort_index,
859 sort_direction);
Bob Mooread5babe2009-11-12 09:44:06 +0800860
Bob Moore29a241c2013-05-30 10:00:01 +0800861 info->return_flags |= ACPI_OBJECT_REPAIRED;
Bob Mooread5babe2009-11-12 09:44:06 +0800862
Bob Moore3a581762009-12-11 15:23:22 +0800863 ACPI_DEBUG_PRINT((ACPI_DB_REPAIR,
864 "%s: Repaired unsorted list - now sorted by %s\n",
Bob Moore29a241c2013-05-30 10:00:01 +0800865 info->full_pathname, sort_key_name));
Bob Mooread5babe2009-11-12 09:44:06 +0800866 return (AE_OK);
867 }
868
869 previous_value = (u32) obj_desc->integer.value;
870 outer_elements++;
871 }
872
873 return (AE_OK);
874}
875
876/******************************************************************************
877 *
Bob Mooread5babe2009-11-12 09:44:06 +0800878 * FUNCTION: acpi_ns_sort_list
879 *
Bob Mooreba494be2012-07-12 09:40:10 +0800880 * PARAMETERS: elements - Package object element list
881 * count - Element count for above
882 * index - Sort by which package element
Bob Mooread5babe2009-11-12 09:44:06 +0800883 * sort_direction - Ascending or Descending sort
884 *
Bob Moore2147d3f2010-01-21 09:08:31 +0800885 * RETURN: None
Bob Mooread5babe2009-11-12 09:44:06 +0800886 *
887 * DESCRIPTION: Sort the objects that are in a package element list.
888 *
Bob Moore2147d3f2010-01-21 09:08:31 +0800889 * NOTE: Assumes that all NULL elements have been removed from the package,
890 * and that all elements have been verified to be of type Integer.
Bob Mooread5babe2009-11-12 09:44:06 +0800891 *
892 *****************************************************************************/
893
Bob Moore2147d3f2010-01-21 09:08:31 +0800894static void
Bob Mooread5babe2009-11-12 09:44:06 +0800895acpi_ns_sort_list(union acpi_operand_object **elements,
896 u32 count, u32 index, u8 sort_direction)
897{
898 union acpi_operand_object *obj_desc1;
899 union acpi_operand_object *obj_desc2;
900 union acpi_operand_object *temp_obj;
901 u32 i;
902 u32 j;
903
904 /* Simple bubble sort */
905
906 for (i = 1; i < count; i++) {
907 for (j = (count - 1); j >= i; j--) {
908 obj_desc1 = elements[j - 1]->package.elements[index];
909 obj_desc2 = elements[j]->package.elements[index];
910
911 if (((sort_direction == ACPI_SORT_ASCENDING) &&
912 (obj_desc1->integer.value >
913 obj_desc2->integer.value))
914 || ((sort_direction == ACPI_SORT_DESCENDING)
915 && (obj_desc1->integer.value <
916 obj_desc2->integer.value))) {
917 temp_obj = elements[j - 1];
918 elements[j - 1] = elements[j];
919 elements[j] = temp_obj;
920 }
921 }
922 }
Bob Mooread5babe2009-11-12 09:44:06 +0800923}
Lv Zheng5a9792f2013-06-08 09:01:07 +0800924
925/******************************************************************************
926 *
927 * FUNCTION: acpi_ns_remove_element
928 *
929 * PARAMETERS: obj_desc - Package object element list
930 * index - Index of element to remove
931 *
932 * RETURN: None
933 *
934 * DESCRIPTION: Remove the requested element of a package and delete it.
935 *
936 *****************************************************************************/
937
938static void
939acpi_ns_remove_element(union acpi_operand_object *obj_desc, u32 index)
940{
941 union acpi_operand_object **source;
942 union acpi_operand_object **dest;
943 u32 count;
944 u32 new_count;
945 u32 i;
946
947 ACPI_FUNCTION_NAME(ns_remove_element);
948
949 count = obj_desc->package.count;
950 new_count = count - 1;
951
952 source = obj_desc->package.elements;
953 dest = source;
954
955 /* Examine all elements of the package object, remove matched index */
956
957 for (i = 0; i < count; i++) {
958 if (i == index) {
959 acpi_ut_remove_reference(*source); /* Remove one ref for being in pkg */
960 acpi_ut_remove_reference(*source);
961 } else {
962 *dest = *source;
963 dest++;
964 }
965 source++;
966 }
967
968 /* NULL terminate list and update the package count */
969
970 *dest = NULL;
971 obj_desc->package.count = new_count;
972}