[ARM] pxa: update defconfig for Verdex Pro
[linux-2.6/verdex.git] / drivers / acpi / acpica / nsrepair.c
blobdb2b2a99c3a8130ba31dab24fd31a58116f5ec71
1 /******************************************************************************
3 * Module Name: nsrepair - Repair for objects returned by predefined methods
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2009, Intel Corp.
9 * All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
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.
30 * NO WARRANTY
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>
45 #include "accommon.h"
46 #include "acnamesp.h"
47 #include "acpredef.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
60 * otherwise)
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
67 * not expected.
69 ******************************************************************************/
70 acpi_status
71 acpi_ns_repair_object(struct acpi_predefined_data *data,
72 u32 expected_btypes,
73 u32 package_index,
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;
78 acpi_size length;
80 switch (return_object->common.type) {
81 case ACPI_TYPE_BUFFER:
83 /* Does the method/object legally return a string? */
85 if (!(expected_btypes & ACPI_RTYPE_STRING)) {
86 return (AE_AML_OPERAND_TYPE);
90 * Have a Buffer, expected a String, convert. Use a to_string
91 * conversion, no transform performed on the buffer data. The best
92 * example of this is the _BIF method, where the string data from
93 * the battery is often (incorrectly) returned as buffer object(s).
95 length = 0;
96 while ((length < return_object->buffer.length) &&
97 (return_object->buffer.pointer[length])) {
98 length++;
101 /* Allocate a new string object */
103 new_object = acpi_ut_create_string_object(length);
104 if (!new_object) {
105 return (AE_NO_MEMORY);
109 * Copy the raw buffer data with no transform. String is already NULL
110 * terminated at Length+1.
112 ACPI_MEMCPY(new_object->string.pointer,
113 return_object->buffer.pointer, length);
116 * If the original object is a package element, we need to:
117 * 1. Set the reference count of the new object to match the
118 * reference count of the old object.
119 * 2. Decrement the reference count of the original object.
121 if (package_index != ACPI_NOT_PACKAGE_ELEMENT) {
122 new_object->common.reference_count =
123 return_object->common.reference_count;
125 if (return_object->common.reference_count > 1) {
126 return_object->common.reference_count--;
129 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname,
130 data->node_flags,
131 "Converted Buffer to expected String at index %u",
132 package_index));
133 } else {
134 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname,
135 data->node_flags,
136 "Converted Buffer to expected String"));
139 /* Delete old object, install the new return object */
141 acpi_ut_remove_reference(return_object);
142 *return_object_ptr = new_object;
143 data->flags |= ACPI_OBJECT_REPAIRED;
144 return (AE_OK);
146 default:
147 break;
150 return (AE_AML_OPERAND_TYPE);
153 /*******************************************************************************
155 * FUNCTION: acpi_ns_repair_package_list
157 * PARAMETERS: Data - Pointer to validation data structure
158 * obj_desc_ptr - Pointer to the object to repair. The new
159 * package object is returned here,
160 * overwriting the old object.
162 * RETURN: Status, new object in *obj_desc_ptr
164 * DESCRIPTION: Repair a common problem with objects that are defined to return
165 * a variable-length Package of Packages. If the variable-length
166 * is one, some BIOS code mistakenly simply declares a single
167 * Package instead of a Package with one sub-Package. This
168 * function attempts to repair this error by wrapping a Package
169 * object around the original Package, creating the correct
170 * Package with one sub-Package.
172 * Names that can be repaired in this manner include:
173 * _ALR, _CSD, _HPX, _MLS, _PRT, _PSS, _TRT, TSS
175 ******************************************************************************/
177 acpi_status
178 acpi_ns_repair_package_list(struct acpi_predefined_data *data,
179 union acpi_operand_object **obj_desc_ptr)
181 union acpi_operand_object *pkg_obj_desc;
184 * Create the new outer package and populate it. The new package will
185 * have a single element, the lone subpackage.
187 pkg_obj_desc = acpi_ut_create_package_object(1);
188 if (!pkg_obj_desc) {
189 return (AE_NO_MEMORY);
192 pkg_obj_desc->package.elements[0] = *obj_desc_ptr;
194 /* Return the new object in the object pointer */
196 *obj_desc_ptr = pkg_obj_desc;
197 data->flags |= ACPI_OBJECT_REPAIRED;
199 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags,
200 "Incorrectly formed Package, attempting repair"));
202 return (AE_OK);