Staging: strip: delete the driver
[linux/fpc-iii.git] / drivers / acpi / acpica / nsrepair2.c
blob61bd0f6755d222ac32dc6703e3f4c9dd8a66a372
1 /******************************************************************************
3 * Module Name: nsrepair2 - Repair for objects returned by specific
4 * predefined methods
6 *****************************************************************************/
8 /*
9 * Copyright (C) 2000 - 2010, Intel Corp.
10 * All rights reserved.
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.
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.
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.
45 #include <acpi/acpi.h>
46 #include "accommon.h"
47 #include "acnamesp.h"
49 #define _COMPONENT ACPI_NAMESPACE
50 ACPI_MODULE_NAME("nsrepair2")
53 * Information structure and handler for ACPI predefined names that can
54 * be repaired on a per-name basis.
56 typedef
57 acpi_status(*acpi_repair_function) (struct acpi_predefined_data *data,
58 union acpi_operand_object **return_object_ptr);
60 typedef struct acpi_repair_info {
61 char name[ACPI_NAME_SIZE];
62 acpi_repair_function repair_function;
64 } acpi_repair_info;
66 /* Local prototypes */
68 static const struct acpi_repair_info *acpi_ns_match_repairable_name(struct
69 acpi_namespace_node
70 *node);
72 static acpi_status
73 acpi_ns_repair_ALR(struct acpi_predefined_data *data,
74 union acpi_operand_object **return_object_ptr);
76 static acpi_status
77 acpi_ns_repair_FDE(struct acpi_predefined_data *data,
78 union acpi_operand_object **return_object_ptr);
80 static acpi_status
81 acpi_ns_repair_PSS(struct acpi_predefined_data *data,
82 union acpi_operand_object **return_object_ptr);
84 static acpi_status
85 acpi_ns_repair_TSS(struct acpi_predefined_data *data,
86 union acpi_operand_object **return_object_ptr);
88 static acpi_status
89 acpi_ns_check_sorted_list(struct acpi_predefined_data *data,
90 union acpi_operand_object *return_object,
91 u32 expected_count,
92 u32 sort_index,
93 u8 sort_direction, char *sort_key_name);
95 static void
96 acpi_ns_sort_list(union acpi_operand_object **elements,
97 u32 count, u32 index, u8 sort_direction);
99 /* Values for sort_direction above */
101 #define ACPI_SORT_ASCENDING 0
102 #define ACPI_SORT_DESCENDING 1
105 * This table contains the names of the predefined methods for which we can
106 * perform more complex repairs.
108 * As necessary:
110 * _ALR: Sort the list ascending by ambient_illuminance
111 * _FDE: Convert Buffer of BYTEs to a Buffer of DWORDs
112 * _GTM: Convert Buffer of BYTEs to a Buffer of DWORDs
113 * _PSS: Sort the list descending by Power
114 * _TSS: Sort the list descending by Power
116 static const struct acpi_repair_info acpi_ns_repairable_names[] = {
117 {"_ALR", acpi_ns_repair_ALR},
118 {"_FDE", acpi_ns_repair_FDE},
119 {"_GTM", acpi_ns_repair_FDE}, /* _GTM has same repair as _FDE */
120 {"_PSS", acpi_ns_repair_PSS},
121 {"_TSS", acpi_ns_repair_TSS},
122 {{0, 0, 0, 0}, NULL} /* Table terminator */
125 #define ACPI_FDE_FIELD_COUNT 5
126 #define ACPI_FDE_BYTE_BUFFER_SIZE 5
127 #define ACPI_FDE_DWORD_BUFFER_SIZE (ACPI_FDE_FIELD_COUNT * sizeof (u32))
129 /******************************************************************************
131 * FUNCTION: acpi_ns_complex_repairs
133 * PARAMETERS: Data - Pointer to validation data structure
134 * Node - Namespace node for the method/object
135 * validate_status - Original status of earlier validation
136 * return_object_ptr - Pointer to the object returned from the
137 * evaluation of a method or object
139 * RETURN: Status. AE_OK if repair was successful. If name is not
140 * matched, validate_status is returned.
142 * DESCRIPTION: Attempt to repair/convert a return object of a type that was
143 * not expected.
145 *****************************************************************************/
147 acpi_status
148 acpi_ns_complex_repairs(struct acpi_predefined_data *data,
149 struct acpi_namespace_node *node,
150 acpi_status validate_status,
151 union acpi_operand_object **return_object_ptr)
153 const struct acpi_repair_info *predefined;
154 acpi_status status;
156 /* Check if this name is in the list of repairable names */
158 predefined = acpi_ns_match_repairable_name(node);
159 if (!predefined) {
160 return (validate_status);
163 status = predefined->repair_function(data, return_object_ptr);
164 return (status);
167 /******************************************************************************
169 * FUNCTION: acpi_ns_match_repairable_name
171 * PARAMETERS: Node - Namespace node for the method/object
173 * RETURN: Pointer to entry in repair table. NULL indicates not found.
175 * DESCRIPTION: Check an object name against the repairable object list.
177 *****************************************************************************/
179 static const struct acpi_repair_info *acpi_ns_match_repairable_name(struct
180 acpi_namespace_node
181 *node)
183 const struct acpi_repair_info *this_name;
185 /* Search info table for a repairable predefined method/object name */
187 this_name = acpi_ns_repairable_names;
188 while (this_name->repair_function) {
189 if (ACPI_COMPARE_NAME(node->name.ascii, this_name->name)) {
190 return (this_name);
192 this_name++;
195 return (NULL); /* Not found */
198 /******************************************************************************
200 * FUNCTION: acpi_ns_repair_ALR
202 * PARAMETERS: Data - Pointer to validation data structure
203 * return_object_ptr - Pointer to the object returned from the
204 * evaluation of a method or object
206 * RETURN: Status. AE_OK if object is OK or was repaired successfully
208 * DESCRIPTION: Repair for the _ALR object. If necessary, sort the object list
209 * ascending by the ambient illuminance values.
211 *****************************************************************************/
213 static acpi_status
214 acpi_ns_repair_ALR(struct acpi_predefined_data *data,
215 union acpi_operand_object **return_object_ptr)
217 union acpi_operand_object *return_object = *return_object_ptr;
218 acpi_status status;
220 status = acpi_ns_check_sorted_list(data, return_object, 2, 1,
221 ACPI_SORT_ASCENDING,
222 "AmbientIlluminance");
224 return (status);
227 /******************************************************************************
229 * FUNCTION: acpi_ns_repair_FDE
231 * PARAMETERS: Data - Pointer to validation data structure
232 * return_object_ptr - Pointer to the object returned from the
233 * evaluation of a method or object
235 * RETURN: Status. AE_OK if object is OK or was repaired successfully
237 * DESCRIPTION: Repair for the _FDE and _GTM objects. The expected return
238 * value is a Buffer of 5 DWORDs. This function repairs a common
239 * problem where the return value is a Buffer of BYTEs, not
240 * DWORDs.
242 *****************************************************************************/
244 static acpi_status
245 acpi_ns_repair_FDE(struct acpi_predefined_data *data,
246 union acpi_operand_object **return_object_ptr)
248 union acpi_operand_object *return_object = *return_object_ptr;
249 union acpi_operand_object *buffer_object;
250 u8 *byte_buffer;
251 u32 *dword_buffer;
252 u32 i;
254 ACPI_FUNCTION_NAME(ns_repair_FDE);
256 switch (return_object->common.type) {
257 case ACPI_TYPE_BUFFER:
259 /* This is the expected type. Length should be (at least) 5 DWORDs */
261 if (return_object->buffer.length >= ACPI_FDE_DWORD_BUFFER_SIZE) {
262 return (AE_OK);
265 /* We can only repair if we have exactly 5 BYTEs */
267 if (return_object->buffer.length != ACPI_FDE_BYTE_BUFFER_SIZE) {
268 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname,
269 data->node_flags,
270 "Incorrect return buffer length %u, expected %u",
271 return_object->buffer.length,
272 ACPI_FDE_DWORD_BUFFER_SIZE));
274 return (AE_AML_OPERAND_TYPE);
277 /* Create the new (larger) buffer object */
279 buffer_object =
280 acpi_ut_create_buffer_object(ACPI_FDE_DWORD_BUFFER_SIZE);
281 if (!buffer_object) {
282 return (AE_NO_MEMORY);
285 /* Expand each byte to a DWORD */
287 byte_buffer = return_object->buffer.pointer;
288 dword_buffer =
289 ACPI_CAST_PTR(u32, buffer_object->buffer.pointer);
291 for (i = 0; i < ACPI_FDE_FIELD_COUNT; i++) {
292 *dword_buffer = (u32) *byte_buffer;
293 dword_buffer++;
294 byte_buffer++;
297 ACPI_DEBUG_PRINT((ACPI_DB_REPAIR,
298 "%s Expanded Byte Buffer to expected DWord Buffer\n",
299 data->pathname));
300 break;
302 default:
303 return (AE_AML_OPERAND_TYPE);
306 /* Delete the original return object, return the new buffer object */
308 acpi_ut_remove_reference(return_object);
309 *return_object_ptr = buffer_object;
311 data->flags |= ACPI_OBJECT_REPAIRED;
312 return (AE_OK);
315 /******************************************************************************
317 * FUNCTION: acpi_ns_repair_TSS
319 * PARAMETERS: Data - Pointer to validation data structure
320 * return_object_ptr - Pointer to the object returned from the
321 * evaluation of a method or object
323 * RETURN: Status. AE_OK if object is OK or was repaired successfully
325 * DESCRIPTION: Repair for the _TSS object. If necessary, sort the object list
326 * descending by the power dissipation values.
328 *****************************************************************************/
330 static acpi_status
331 acpi_ns_repair_TSS(struct acpi_predefined_data *data,
332 union acpi_operand_object **return_object_ptr)
334 union acpi_operand_object *return_object = *return_object_ptr;
335 acpi_status status;
337 status = acpi_ns_check_sorted_list(data, return_object, 5, 1,
338 ACPI_SORT_DESCENDING,
339 "PowerDissipation");
341 return (status);
344 /******************************************************************************
346 * FUNCTION: acpi_ns_repair_PSS
348 * PARAMETERS: Data - Pointer to validation data structure
349 * return_object_ptr - Pointer to the object returned from the
350 * evaluation of a method or object
352 * RETURN: Status. AE_OK if object is OK or was repaired successfully
354 * DESCRIPTION: Repair for the _PSS object. If necessary, sort the object list
355 * by the CPU frequencies. Check that the power dissipation values
356 * are all proportional to CPU frequency (i.e., sorting by
357 * frequency should be the same as sorting by power.)
359 *****************************************************************************/
361 static acpi_status
362 acpi_ns_repair_PSS(struct acpi_predefined_data *data,
363 union acpi_operand_object **return_object_ptr)
365 union acpi_operand_object *return_object = *return_object_ptr;
366 union acpi_operand_object **outer_elements;
367 u32 outer_element_count;
368 union acpi_operand_object **elements;
369 union acpi_operand_object *obj_desc;
370 u32 previous_value;
371 acpi_status status;
372 u32 i;
375 * Entries (sub-packages) in the _PSS Package must be sorted by power
376 * dissipation, in descending order. If it appears that the list is
377 * incorrectly sorted, sort it. We sort by cpu_frequency, since this
378 * should be proportional to the power.
380 status = acpi_ns_check_sorted_list(data, return_object, 6, 0,
381 ACPI_SORT_DESCENDING,
382 "CpuFrequency");
383 if (ACPI_FAILURE(status)) {
384 return (status);
388 * We now know the list is correctly sorted by CPU frequency. Check if
389 * the power dissipation values are proportional.
391 previous_value = ACPI_UINT32_MAX;
392 outer_elements = return_object->package.elements;
393 outer_element_count = return_object->package.count;
395 for (i = 0; i < outer_element_count; i++) {
396 elements = (*outer_elements)->package.elements;
397 obj_desc = elements[1]; /* Index1 = power_dissipation */
399 if ((u32) obj_desc->integer.value > previous_value) {
400 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname,
401 data->node_flags,
402 "SubPackage[%u,%u] - suspicious power dissipation values",
403 i - 1, i));
406 previous_value = (u32) obj_desc->integer.value;
407 outer_elements++;
410 return (AE_OK);
413 /******************************************************************************
415 * FUNCTION: acpi_ns_check_sorted_list
417 * PARAMETERS: Data - Pointer to validation data structure
418 * return_object - Pointer to the top-level returned object
419 * expected_count - Minimum length of each sub-package
420 * sort_index - Sub-package entry to sort on
421 * sort_direction - Ascending or descending
422 * sort_key_name - Name of the sort_index field
424 * RETURN: Status. AE_OK if the list is valid and is sorted correctly or
425 * has been repaired by sorting the list.
427 * DESCRIPTION: Check if the package list is valid and sorted correctly by the
428 * sort_index. If not, then sort the list.
430 *****************************************************************************/
432 static acpi_status
433 acpi_ns_check_sorted_list(struct acpi_predefined_data *data,
434 union acpi_operand_object *return_object,
435 u32 expected_count,
436 u32 sort_index,
437 u8 sort_direction, char *sort_key_name)
439 u32 outer_element_count;
440 union acpi_operand_object **outer_elements;
441 union acpi_operand_object **elements;
442 union acpi_operand_object *obj_desc;
443 u32 i;
444 u32 previous_value;
446 ACPI_FUNCTION_NAME(ns_check_sorted_list);
448 /* The top-level object must be a package */
450 if (return_object->common.type != ACPI_TYPE_PACKAGE) {
451 return (AE_AML_OPERAND_TYPE);
455 * NOTE: assumes list of sub-packages contains no NULL elements.
456 * Any NULL elements should have been removed by earlier call
457 * to acpi_ns_remove_null_elements.
459 outer_elements = return_object->package.elements;
460 outer_element_count = return_object->package.count;
461 if (!outer_element_count) {
462 return (AE_AML_PACKAGE_LIMIT);
465 previous_value = 0;
466 if (sort_direction == ACPI_SORT_DESCENDING) {
467 previous_value = ACPI_UINT32_MAX;
470 /* Examine each subpackage */
472 for (i = 0; i < outer_element_count; i++) {
474 /* Each element of the top-level package must also be a package */
476 if ((*outer_elements)->common.type != ACPI_TYPE_PACKAGE) {
477 return (AE_AML_OPERAND_TYPE);
480 /* Each sub-package must have the minimum length */
482 if ((*outer_elements)->package.count < expected_count) {
483 return (AE_AML_PACKAGE_LIMIT);
486 elements = (*outer_elements)->package.elements;
487 obj_desc = elements[sort_index];
489 if (obj_desc->common.type != ACPI_TYPE_INTEGER) {
490 return (AE_AML_OPERAND_TYPE);
494 * The list must be sorted in the specified order. If we detect a
495 * discrepancy, sort the entire list.
497 if (((sort_direction == ACPI_SORT_ASCENDING) &&
498 (obj_desc->integer.value < previous_value)) ||
499 ((sort_direction == ACPI_SORT_DESCENDING) &&
500 (obj_desc->integer.value > previous_value))) {
501 acpi_ns_sort_list(return_object->package.elements,
502 outer_element_count, sort_index,
503 sort_direction);
505 data->flags |= ACPI_OBJECT_REPAIRED;
507 ACPI_DEBUG_PRINT((ACPI_DB_REPAIR,
508 "%s: Repaired unsorted list - now sorted by %s\n",
509 data->pathname, sort_key_name));
510 return (AE_OK);
513 previous_value = (u32) obj_desc->integer.value;
514 outer_elements++;
517 return (AE_OK);
520 /******************************************************************************
522 * FUNCTION: acpi_ns_sort_list
524 * PARAMETERS: Elements - Package object element list
525 * Count - Element count for above
526 * Index - Sort by which package element
527 * sort_direction - Ascending or Descending sort
529 * RETURN: None
531 * DESCRIPTION: Sort the objects that are in a package element list.
533 * NOTE: Assumes that all NULL elements have been removed from the package,
534 * and that all elements have been verified to be of type Integer.
536 *****************************************************************************/
538 static void
539 acpi_ns_sort_list(union acpi_operand_object **elements,
540 u32 count, u32 index, u8 sort_direction)
542 union acpi_operand_object *obj_desc1;
543 union acpi_operand_object *obj_desc2;
544 union acpi_operand_object *temp_obj;
545 u32 i;
546 u32 j;
548 /* Simple bubble sort */
550 for (i = 1; i < count; i++) {
551 for (j = (count - 1); j >= i; j--) {
552 obj_desc1 = elements[j - 1]->package.elements[index];
553 obj_desc2 = elements[j]->package.elements[index];
555 if (((sort_direction == ACPI_SORT_ASCENDING) &&
556 (obj_desc1->integer.value >
557 obj_desc2->integer.value))
558 || ((sort_direction == ACPI_SORT_DESCENDING)
559 && (obj_desc1->integer.value <
560 obj_desc2->integer.value))) {
561 temp_obj = elements[j - 1];
562 elements[j - 1] = elements[j];
563 elements[j] = temp_obj;