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