1 /******************************************************************************
3 * Module Name: nsrepair - Repair for objects returned by predefined methods
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2009, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
44 #include <acpi/acpi.h>
50 #define _COMPONENT ACPI_NAMESPACE
51 ACPI_MODULE_NAME("nsrepair")
53 /*******************************************************************************
55 * FUNCTION: acpi_ns_repair_object
57 * PARAMETERS: Data - Pointer to validation data structure
58 * expected_btypes - Object types expected
59 * package_index - Index of object within parent package (if
60 * applicable - ACPI_NOT_PACKAGE_ELEMENT
62 * return_object_ptr - Pointer to the object returned from the
63 * evaluation of a method or object
65 * RETURN: Status. AE_OK if repair was successful.
67 * DESCRIPTION: Attempt to repair/convert a return object of a type that was
70 ******************************************************************************/
72 acpi_ns_repair_object(struct acpi_predefined_data *data,
75 union acpi_operand_object **return_object_ptr)
77 union acpi_operand_object *return_object = *return_object_ptr;
78 union acpi_operand_object *new_object;
83 * At this point, we know that the type of the returned object was not
84 * one of the expected types for this predefined name. Attempt to
85 * repair the object. Only a limited number of repairs are possible.
87 switch (return_object->common.type) {
88 case ACPI_TYPE_BUFFER:
90 /* Does the method/object legally return a string? */
92 if (!(expected_btypes & ACPI_RTYPE_STRING)) {
93 return (AE_AML_OPERAND_TYPE);
97 * Have a Buffer, expected a String, convert. Use a to_string
98 * conversion, no transform performed on the buffer data. The best
99 * example of this is the _BIF method, where the string data from
100 * the battery is often (incorrectly) returned as buffer object(s).
103 while ((length < return_object->buffer.length) &&
104 (return_object->buffer.pointer[length])) {
108 /* Allocate a new string object */
110 new_object = acpi_ut_create_string_object(length);
112 return (AE_NO_MEMORY);
116 * Copy the raw buffer data with no transform. String is already NULL
117 * terminated at Length+1.
119 ACPI_MEMCPY(new_object->string.pointer,
120 return_object->buffer.pointer, length);
123 case ACPI_TYPE_INTEGER:
125 /* 1) Does the method/object legally return a buffer? */
127 if (expected_btypes & ACPI_RTYPE_BUFFER) {
129 * Convert the Integer to a packed-byte buffer. _MAT needs
130 * this sometimes, if a read has been performed on a Field
131 * object that is less than or equal to the global integer
132 * size (32 or 64 bits).
135 acpi_ex_convert_to_buffer(return_object,
137 if (ACPI_FAILURE(status)) {
142 /* 2) Does the method/object legally return a string? */
144 else if (expected_btypes & ACPI_RTYPE_STRING) {
146 * The only supported Integer-to-String conversion is to convert
147 * an integer of value 0 to a NULL string. The last element of
148 * _BIF and _BIX packages occasionally need this fix.
150 if (return_object->integer.value != 0) {
151 return (AE_AML_OPERAND_TYPE);
154 /* Allocate a new NULL string object */
156 new_object = acpi_ut_create_string_object(0);
158 return (AE_NO_MEMORY);
161 return (AE_AML_OPERAND_TYPE);
167 /* We cannot repair this object */
169 return (AE_AML_OPERAND_TYPE);
172 /* Object was successfully repaired */
175 * If the original object is a package element, we need to:
176 * 1. Set the reference count of the new object to match the
177 * reference count of the old object.
178 * 2. Decrement the reference count of the original object.
180 if (package_index != ACPI_NOT_PACKAGE_ELEMENT) {
181 new_object->common.reference_count =
182 return_object->common.reference_count;
184 if (return_object->common.reference_count > 1) {
185 return_object->common.reference_count--;
188 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags,
189 "Converted %s to expected %s at index %u",
190 acpi_ut_get_object_type_name
192 acpi_ut_get_object_type_name(new_object),
195 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags,
196 "Converted %s to expected %s",
197 acpi_ut_get_object_type_name
199 acpi_ut_get_object_type_name
203 /* Delete old object, install the new return object */
205 acpi_ut_remove_reference(return_object);
206 *return_object_ptr = new_object;
207 data->flags |= ACPI_OBJECT_REPAIRED;
211 /*******************************************************************************
213 * FUNCTION: acpi_ns_repair_package_list
215 * PARAMETERS: Data - Pointer to validation data structure
216 * obj_desc_ptr - Pointer to the object to repair. The new
217 * package object is returned here,
218 * overwriting the old object.
220 * RETURN: Status, new object in *obj_desc_ptr
222 * DESCRIPTION: Repair a common problem with objects that are defined to return
223 * a variable-length Package of Packages. If the variable-length
224 * is one, some BIOS code mistakenly simply declares a single
225 * Package instead of a Package with one sub-Package. This
226 * function attempts to repair this error by wrapping a Package
227 * object around the original Package, creating the correct
228 * Package with one sub-Package.
230 * Names that can be repaired in this manner include:
231 * _ALR, _CSD, _HPX, _MLS, _PRT, _PSS, _TRT, TSS
233 ******************************************************************************/
236 acpi_ns_repair_package_list(struct acpi_predefined_data *data,
237 union acpi_operand_object **obj_desc_ptr)
239 union acpi_operand_object *pkg_obj_desc;
242 * Create the new outer package and populate it. The new package will
243 * have a single element, the lone subpackage.
245 pkg_obj_desc = acpi_ut_create_package_object(1);
247 return (AE_NO_MEMORY);
250 pkg_obj_desc->package.elements[0] = *obj_desc_ptr;
252 /* Return the new object in the object pointer */
254 *obj_desc_ptr = pkg_obj_desc;
255 data->flags |= ACPI_OBJECT_REPAIRED;
257 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags,
258 "Incorrectly formed Package, attempting repair"));