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>
49 #define _COMPONENT ACPI_NAMESPACE
50 ACPI_MODULE_NAME("nsrepair")
52 /*******************************************************************************
54 * FUNCTION: acpi_ns_repair_object
56 * PARAMETERS: Data - Pointer to validation data structure
57 * expected_btypes - Object types expected
58 * package_index - Index of object within parent package (if
59 * applicable - ACPI_NOT_PACKAGE_ELEMENT
61 * return_object_ptr - Pointer to the object returned from the
62 * evaluation of a method or object
64 * RETURN: Status. AE_OK if repair was successful.
66 * DESCRIPTION: Attempt to repair/convert a return object of a type that was
69 ******************************************************************************/
71 acpi_ns_repair_object(struct acpi_predefined_data *data,
74 union acpi_operand_object **return_object_ptr)
76 union acpi_operand_object *return_object = *return_object_ptr;
77 union acpi_operand_object *new_object;
81 * At this point, we know that the type of the returned object was not
82 * one of the expected types for this predefined name. Attempt to
83 * repair the object. Only a limited number of repairs are possible.
85 switch (return_object->common.type) {
86 case ACPI_TYPE_BUFFER:
88 /* Does the method/object legally return a string? */
90 if (!(expected_btypes & ACPI_RTYPE_STRING)) {
91 return (AE_AML_OPERAND_TYPE);
95 * Have a Buffer, expected a String, convert. Use a to_string
96 * conversion, no transform performed on the buffer data. The best
97 * example of this is the _BIF method, where the string data from
98 * the battery is often (incorrectly) returned as buffer object(s).
101 while ((length < return_object->buffer.length) &&
102 (return_object->buffer.pointer[length])) {
106 /* Allocate a new string object */
108 new_object = acpi_ut_create_string_object(length);
110 return (AE_NO_MEMORY);
114 * Copy the raw buffer data with no transform. String is already NULL
115 * terminated at Length+1.
117 ACPI_MEMCPY(new_object->string.pointer,
118 return_object->buffer.pointer, length);
121 case ACPI_TYPE_INTEGER:
123 /* Does the method/object legally return a string? */
125 if (expected_btypes & ACPI_RTYPE_STRING) {
127 * The only supported Integer-to-String conversion is to convert
128 * an integer of value 0 to a NULL string. The last element of
129 * _BIF and _BIX packages occasionally need this fix.
131 if (return_object->integer.value != 0) {
132 return (AE_AML_OPERAND_TYPE);
135 /* Allocate a new NULL string object */
137 new_object = acpi_ut_create_string_object(0);
139 return (AE_NO_MEMORY);
142 return (AE_AML_OPERAND_TYPE);
148 /* We cannot repair this object */
150 return (AE_AML_OPERAND_TYPE);
153 /* Object was successfully repaired */
156 * If the original object is a package element, we need to:
157 * 1. Set the reference count of the new object to match the
158 * reference count of the old object.
159 * 2. Decrement the reference count of the original object.
161 if (package_index != ACPI_NOT_PACKAGE_ELEMENT) {
162 new_object->common.reference_count =
163 return_object->common.reference_count;
165 if (return_object->common.reference_count > 1) {
166 return_object->common.reference_count--;
169 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags,
170 "Converted %s to expected %s at index %u",
171 acpi_ut_get_object_type_name
173 acpi_ut_get_object_type_name(new_object),
176 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags,
177 "Converted %s to expected %s",
178 acpi_ut_get_object_type_name
180 acpi_ut_get_object_type_name
184 /* Delete old object, install the new return object */
186 acpi_ut_remove_reference(return_object);
187 *return_object_ptr = new_object;
188 data->flags |= ACPI_OBJECT_REPAIRED;
192 /*******************************************************************************
194 * FUNCTION: acpi_ns_repair_package_list
196 * PARAMETERS: Data - Pointer to validation data structure
197 * obj_desc_ptr - Pointer to the object to repair. The new
198 * package object is returned here,
199 * overwriting the old object.
201 * RETURN: Status, new object in *obj_desc_ptr
203 * DESCRIPTION: Repair a common problem with objects that are defined to return
204 * a variable-length Package of Packages. If the variable-length
205 * is one, some BIOS code mistakenly simply declares a single
206 * Package instead of a Package with one sub-Package. This
207 * function attempts to repair this error by wrapping a Package
208 * object around the original Package, creating the correct
209 * Package with one sub-Package.
211 * Names that can be repaired in this manner include:
212 * _ALR, _CSD, _HPX, _MLS, _PRT, _PSS, _TRT, TSS
214 ******************************************************************************/
217 acpi_ns_repair_package_list(struct acpi_predefined_data *data,
218 union acpi_operand_object **obj_desc_ptr)
220 union acpi_operand_object *pkg_obj_desc;
223 * Create the new outer package and populate it. The new package will
224 * have a single element, the lone subpackage.
226 pkg_obj_desc = acpi_ut_create_package_object(1);
228 return (AE_NO_MEMORY);
231 pkg_obj_desc->package.elements[0] = *obj_desc_ptr;
233 /* Return the new object in the object pointer */
235 *obj_desc_ptr = pkg_obj_desc;
236 data->flags |= ACPI_OBJECT_REPAIRED;
238 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags,
239 "Incorrectly formed Package, attempting repair"));