1 /******************************************************************************
3 * Module Name: nsrepair2 - Repair for objects returned by specific
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2009, 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
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.
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>
50 #define _COMPONENT ACPI_NAMESPACE
51 ACPI_MODULE_NAME("nsrepair2")
54 * Information structure and handler for ACPI predefined names that can
55 * be repaired on a per-name basis.
58 acpi_status(*acpi_repair_function
) (struct acpi_predefined_data
*data
,
59 union acpi_operand_object
**return_object_ptr
);
61 typedef struct acpi_repair_info
{
62 char name
[ACPI_NAME_SIZE
];
63 acpi_repair_function repair_function
;
67 /* Local prototypes */
69 static const struct acpi_repair_info
*acpi_ns_match_repairable_name(struct
74 acpi_ns_repair_ALR(struct acpi_predefined_data
*data
,
75 union acpi_operand_object
**return_object_ptr
);
78 acpi_ns_repair_FDE(struct acpi_predefined_data
*data
,
79 union acpi_operand_object
**return_object_ptr
);
82 acpi_ns_repair_PSS(struct acpi_predefined_data
*data
,
83 union acpi_operand_object
**return_object_ptr
);
86 acpi_ns_repair_TSS(struct acpi_predefined_data
*data
,
87 union acpi_operand_object
**return_object_ptr
);
90 acpi_ns_check_sorted_list(struct acpi_predefined_data
*data
,
91 union acpi_operand_object
*return_object
,
94 u8 sort_direction
, char *sort_key_name
);
97 acpi_ns_sort_list(union acpi_operand_object
**elements
,
98 u32 count
, u32 index
, u8 sort_direction
);
100 /* Values for sort_direction above */
102 #define ACPI_SORT_ASCENDING 0
103 #define ACPI_SORT_DESCENDING 1
106 * This table contains the names of the predefined methods for which we can
107 * perform more complex repairs.
111 * _ALR: Sort the list ascending by ambient_illuminance
112 * _FDE: Convert Buffer of BYTEs to a Buffer of DWORDs
113 * _GTM: Convert Buffer of BYTEs to a Buffer of DWORDs
114 * _PSS: Sort the list descending by Power
115 * _TSS: Sort the list descending by Power
117 static const struct acpi_repair_info acpi_ns_repairable_names
[] = {
118 {"_ALR", acpi_ns_repair_ALR
},
119 {"_FDE", acpi_ns_repair_FDE
},
120 {"_GTM", acpi_ns_repair_FDE
}, /* _GTM has same repair as _FDE */
121 {"_PSS", acpi_ns_repair_PSS
},
122 {"_TSS", acpi_ns_repair_TSS
},
123 {{0, 0, 0, 0}, NULL
} /* Table terminator */
126 #define ACPI_FDE_FIELD_COUNT 5
127 #define ACPI_FDE_BYTE_BUFFER_SIZE 5
128 #define ACPI_FDE_DWORD_BUFFER_SIZE (ACPI_FDE_FIELD_COUNT * sizeof (u32))
130 /******************************************************************************
132 * FUNCTION: acpi_ns_complex_repairs
134 * PARAMETERS: Data - Pointer to validation data structure
135 * Node - Namespace node for the method/object
136 * validate_status - Original status of earlier validation
137 * return_object_ptr - Pointer to the object returned from the
138 * evaluation of a method or object
140 * RETURN: Status. AE_OK if repair was successful. If name is not
141 * matched, validate_status is returned.
143 * DESCRIPTION: Attempt to repair/convert a return object of a type that was
146 *****************************************************************************/
149 acpi_ns_complex_repairs(struct acpi_predefined_data
*data
,
150 struct acpi_namespace_node
*node
,
151 acpi_status validate_status
,
152 union acpi_operand_object
**return_object_ptr
)
154 const struct acpi_repair_info
*predefined
;
157 /* Check if this name is in the list of repairable names */
159 predefined
= acpi_ns_match_repairable_name(node
);
161 return (validate_status
);
164 status
= predefined
->repair_function(data
, return_object_ptr
);
168 /******************************************************************************
170 * FUNCTION: acpi_ns_match_repairable_name
172 * PARAMETERS: Node - Namespace node for the method/object
174 * RETURN: Pointer to entry in repair table. NULL indicates not found.
176 * DESCRIPTION: Check an object name against the repairable object list.
178 *****************************************************************************/
180 static const struct acpi_repair_info
*acpi_ns_match_repairable_name(struct
184 const struct acpi_repair_info
*this_name
;
186 /* Search info table for a repairable predefined method/object name */
188 this_name
= acpi_ns_repairable_names
;
189 while (this_name
->repair_function
) {
190 if (ACPI_COMPARE_NAME(node
->name
.ascii
, this_name
->name
)) {
196 return (NULL
); /* Not found */
199 /******************************************************************************
201 * FUNCTION: acpi_ns_repair_ALR
203 * PARAMETERS: Data - Pointer to validation data structure
204 * return_object_ptr - Pointer to the object returned from the
205 * evaluation of a method or object
207 * RETURN: Status. AE_OK if object is OK or was repaired successfully
209 * DESCRIPTION: Repair for the _ALR object. If necessary, sort the object list
210 * ascending by the ambient illuminance values.
212 *****************************************************************************/
215 acpi_ns_repair_ALR(struct acpi_predefined_data
*data
,
216 union acpi_operand_object
**return_object_ptr
)
218 union acpi_operand_object
*return_object
= *return_object_ptr
;
221 status
= acpi_ns_check_sorted_list(data
, return_object
, 2, 1,
223 "AmbientIlluminance");
228 /******************************************************************************
230 * FUNCTION: acpi_ns_repair_FDE
232 * PARAMETERS: Data - Pointer to validation data structure
233 * return_object_ptr - Pointer to the object returned from the
234 * evaluation of a method or object
236 * RETURN: Status. AE_OK if object is OK or was repaired successfully
238 * DESCRIPTION: Repair for the _FDE and _GTM objects. The expected return
239 * value is a Buffer of 5 DWORDs. This function repairs a common
240 * problem where the return value is a Buffer of BYTEs, not
243 *****************************************************************************/
246 acpi_ns_repair_FDE(struct acpi_predefined_data
*data
,
247 union acpi_operand_object
**return_object_ptr
)
249 union acpi_operand_object
*return_object
= *return_object_ptr
;
250 union acpi_operand_object
*buffer_object
;
255 ACPI_FUNCTION_NAME(ns_repair_FDE
);
257 switch (return_object
->common
.type
) {
258 case ACPI_TYPE_BUFFER
:
260 /* This is the expected type. Length should be (at least) 5 DWORDs */
262 if (return_object
->buffer
.length
>= ACPI_FDE_DWORD_BUFFER_SIZE
) {
266 /* We can only repair if we have exactly 5 BYTEs */
268 if (return_object
->buffer
.length
!= ACPI_FDE_BYTE_BUFFER_SIZE
) {
269 ACPI_WARN_PREDEFINED((AE_INFO
, data
->pathname
,
271 "Incorrect return buffer length %u, expected %u",
272 return_object
->buffer
.length
,
273 ACPI_FDE_DWORD_BUFFER_SIZE
));
275 return (AE_AML_OPERAND_TYPE
);
278 /* Create the new (larger) buffer object */
281 acpi_ut_create_buffer_object(ACPI_FDE_DWORD_BUFFER_SIZE
);
282 if (!buffer_object
) {
283 return (AE_NO_MEMORY
);
286 /* Expand each byte to a DWORD */
288 byte_buffer
= return_object
->buffer
.pointer
;
290 ACPI_CAST_PTR(u32
, buffer_object
->buffer
.pointer
);
292 for (i
= 0; i
< ACPI_FDE_FIELD_COUNT
; i
++) {
293 *dword_buffer
= (u32
) *byte_buffer
;
298 ACPI_DEBUG_PRINT((ACPI_DB_REPAIR
,
299 "%s Expanded Byte Buffer to expected DWord Buffer\n",
304 return (AE_AML_OPERAND_TYPE
);
307 /* Delete the original return object, return the new buffer object */
309 acpi_ut_remove_reference(return_object
);
310 *return_object_ptr
= buffer_object
;
312 data
->flags
|= ACPI_OBJECT_REPAIRED
;
316 /******************************************************************************
318 * FUNCTION: acpi_ns_repair_TSS
320 * PARAMETERS: Data - Pointer to validation data structure
321 * return_object_ptr - Pointer to the object returned from the
322 * evaluation of a method or object
324 * RETURN: Status. AE_OK if object is OK or was repaired successfully
326 * DESCRIPTION: Repair for the _TSS object. If necessary, sort the object list
327 * descending by the power dissipation values.
329 *****************************************************************************/
332 acpi_ns_repair_TSS(struct acpi_predefined_data
*data
,
333 union acpi_operand_object
**return_object_ptr
)
335 union acpi_operand_object
*return_object
= *return_object_ptr
;
338 status
= acpi_ns_check_sorted_list(data
, return_object
, 5, 1,
339 ACPI_SORT_DESCENDING
,
345 /******************************************************************************
347 * FUNCTION: acpi_ns_repair_PSS
349 * PARAMETERS: Data - Pointer to validation data structure
350 * return_object_ptr - Pointer to the object returned from the
351 * evaluation of a method or object
353 * RETURN: Status. AE_OK if object is OK or was repaired successfully
355 * DESCRIPTION: Repair for the _PSS object. If necessary, sort the object list
356 * by the CPU frequencies. Check that the power dissipation values
357 * are all proportional to CPU frequency (i.e., sorting by
358 * frequency should be the same as sorting by power.)
360 *****************************************************************************/
363 acpi_ns_repair_PSS(struct acpi_predefined_data
*data
,
364 union acpi_operand_object
**return_object_ptr
)
366 union acpi_operand_object
*return_object
= *return_object_ptr
;
367 union acpi_operand_object
**outer_elements
;
368 u32 outer_element_count
;
369 union acpi_operand_object
**elements
;
370 union acpi_operand_object
*obj_desc
;
376 * Entries (sub-packages) in the _PSS Package must be sorted by power
377 * dissipation, in descending order. If it appears that the list is
378 * incorrectly sorted, sort it. We sort by cpu_frequency, since this
379 * should be proportional to the power.
381 status
= acpi_ns_check_sorted_list(data
, return_object
, 6, 0,
382 ACPI_SORT_DESCENDING
,
384 if (ACPI_FAILURE(status
)) {
389 * We now know the list is correctly sorted by CPU frequency. Check if
390 * the power dissipation values are proportional.
392 previous_value
= ACPI_UINT32_MAX
;
393 outer_elements
= return_object
->package
.elements
;
394 outer_element_count
= return_object
->package
.count
;
396 for (i
= 0; i
< outer_element_count
; i
++) {
397 elements
= (*outer_elements
)->package
.elements
;
398 obj_desc
= elements
[1]; /* Index1 = power_dissipation */
400 if ((u32
) obj_desc
->integer
.value
> previous_value
) {
401 ACPI_WARN_PREDEFINED((AE_INFO
, data
->pathname
,
403 "SubPackage[%u,%u] - suspicious power dissipation values",
407 previous_value
= (u32
) obj_desc
->integer
.value
;
414 /******************************************************************************
416 * FUNCTION: acpi_ns_check_sorted_list
418 * PARAMETERS: Data - Pointer to validation data structure
419 * return_object - Pointer to the top-level returned object
420 * expected_count - Minimum length of each sub-package
421 * sort_index - Sub-package entry to sort on
422 * sort_direction - Ascending or descending
423 * sort_key_name - Name of the sort_index field
425 * RETURN: Status. AE_OK if the list is valid and is sorted correctly or
426 * has been repaired by sorting the list.
428 * DESCRIPTION: Check if the package list is valid and sorted correctly by the
429 * sort_index. If not, then sort the list.
431 *****************************************************************************/
434 acpi_ns_check_sorted_list(struct acpi_predefined_data
*data
,
435 union acpi_operand_object
*return_object
,
438 u8 sort_direction
, char *sort_key_name
)
440 u32 outer_element_count
;
441 union acpi_operand_object
**outer_elements
;
442 union acpi_operand_object
**elements
;
443 union acpi_operand_object
*obj_desc
;
448 ACPI_FUNCTION_NAME(ns_check_sorted_list
);
450 /* The top-level object must be a package */
452 if (return_object
->common
.type
!= ACPI_TYPE_PACKAGE
) {
453 return (AE_AML_OPERAND_TYPE
);
457 * NOTE: assumes list of sub-packages contains no NULL elements.
458 * Any NULL elements should have been removed by earlier call
459 * to acpi_ns_remove_null_elements.
461 outer_elements
= return_object
->package
.elements
;
462 outer_element_count
= return_object
->package
.count
;
463 if (!outer_element_count
) {
464 return (AE_AML_PACKAGE_LIMIT
);
468 if (sort_direction
== ACPI_SORT_DESCENDING
) {
469 previous_value
= ACPI_UINT32_MAX
;
472 /* Examine each subpackage */
474 for (i
= 0; i
< outer_element_count
; i
++) {
476 /* Each element of the top-level package must also be a package */
478 if ((*outer_elements
)->common
.type
!= ACPI_TYPE_PACKAGE
) {
479 return (AE_AML_OPERAND_TYPE
);
482 /* Each sub-package must have the minimum length */
484 if ((*outer_elements
)->package
.count
< expected_count
) {
485 return (AE_AML_PACKAGE_LIMIT
);
488 elements
= (*outer_elements
)->package
.elements
;
489 obj_desc
= elements
[sort_index
];
491 if (obj_desc
->common
.type
!= ACPI_TYPE_INTEGER
) {
492 return (AE_AML_OPERAND_TYPE
);
496 * The list must be sorted in the specified order. If we detect a
497 * discrepancy, issue a warning and sort the entire list
499 if (((sort_direction
== ACPI_SORT_ASCENDING
) &&
500 (obj_desc
->integer
.value
< previous_value
)) ||
501 ((sort_direction
== ACPI_SORT_DESCENDING
) &&
502 (obj_desc
->integer
.value
> previous_value
))) {
504 acpi_ns_sort_list(return_object
->package
.elements
,
505 outer_element_count
, sort_index
,
507 if (ACPI_FAILURE(status
)) {
511 data
->flags
|= ACPI_OBJECT_REPAIRED
;
513 ACPI_DEBUG_PRINT((ACPI_DB_REPAIR
,
514 "%s: Repaired unsorted list - now sorted by %s\n",
515 data
->pathname
, sort_key_name
));
519 previous_value
= (u32
) obj_desc
->integer
.value
;
526 /******************************************************************************
528 * FUNCTION: acpi_ns_remove_null_elements
530 * PARAMETERS: Data - Pointer to validation data structure
531 * package_type - An acpi_return_package_types value
532 * obj_desc - A Package object
536 * DESCRIPTION: Remove all NULL package elements from packages that contain
537 * a variable number of sub-packages.
539 *****************************************************************************/
542 acpi_ns_remove_null_elements(struct acpi_predefined_data
*data
,
544 union acpi_operand_object
*obj_desc
)
546 union acpi_operand_object
**source
;
547 union acpi_operand_object
**dest
;
552 ACPI_FUNCTION_NAME(ns_remove_null_elements
);
555 * PTYPE1 packages contain no subpackages.
556 * PTYPE2 packages contain a variable number of sub-packages. We can
557 * safely remove all NULL elements from the PTYPE2 packages.
559 switch (package_type
) {
560 case ACPI_PTYPE1_FIXED
:
561 case ACPI_PTYPE1_VAR
:
562 case ACPI_PTYPE1_OPTION
:
566 case ACPI_PTYPE2_COUNT
:
567 case ACPI_PTYPE2_PKG_COUNT
:
568 case ACPI_PTYPE2_FIXED
:
569 case ACPI_PTYPE2_MIN
:
570 case ACPI_PTYPE2_REV_FIXED
:
577 count
= obj_desc
->package
.count
;
580 source
= obj_desc
->package
.elements
;
583 /* Examine all elements of the package object, remove nulls */
585 for (i
= 0; i
< count
; i
++) {
595 /* Update parent package if any null elements were removed */
597 if (new_count
< count
) {
598 ACPI_DEBUG_PRINT((ACPI_DB_REPAIR
,
599 "%s: Found and removed %u NULL elements\n",
600 data
->pathname
, (count
- new_count
)));
602 /* NULL terminate list and update the package count */
605 obj_desc
->package
.count
= new_count
;
609 /******************************************************************************
611 * FUNCTION: acpi_ns_sort_list
613 * PARAMETERS: Elements - Package object element list
614 * Count - Element count for above
615 * Index - Sort by which package element
616 * sort_direction - Ascending or Descending sort
620 * DESCRIPTION: Sort the objects that are in a package element list.
622 * NOTE: Assumes that all NULL elements have been removed from the package.
624 *****************************************************************************/
627 acpi_ns_sort_list(union acpi_operand_object
**elements
,
628 u32 count
, u32 index
, u8 sort_direction
)
630 union acpi_operand_object
*obj_desc1
;
631 union acpi_operand_object
*obj_desc2
;
632 union acpi_operand_object
*temp_obj
;
636 /* Simple bubble sort */
638 for (i
= 1; i
< count
; i
++) {
639 for (j
= (count
- 1); j
>= i
; j
--) {
640 obj_desc1
= elements
[j
- 1]->package
.elements
[index
];
641 obj_desc2
= elements
[j
]->package
.elements
[index
];
643 if (((sort_direction
== ACPI_SORT_ASCENDING
) &&
644 (obj_desc1
->integer
.value
>
645 obj_desc2
->integer
.value
))
646 || ((sort_direction
== ACPI_SORT_DESCENDING
)
647 && (obj_desc1
->integer
.value
<
648 obj_desc2
->integer
.value
))) {
649 temp_obj
= elements
[j
- 1];
650 elements
[j
- 1] = elements
[j
];
651 elements
[j
] = temp_obj
;