aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/acpica/nsrepair.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/acpi/acpica/nsrepair.c')
-rw-r--r--drivers/acpi/acpica/nsrepair.c447
1 files changed, 373 insertions, 74 deletions
diff --git a/drivers/acpi/acpica/nsrepair.c b/drivers/acpi/acpica/nsrepair.c
index d563f1a564a7..4fd1bdb056b2 100644
--- a/drivers/acpi/acpica/nsrepair.c
+++ b/drivers/acpi/acpica/nsrepair.c
@@ -45,13 +45,52 @@
45#include "accommon.h" 45#include "accommon.h"
46#include "acnamesp.h" 46#include "acnamesp.h"
47#include "acinterp.h" 47#include "acinterp.h"
48#include "acpredef.h"
49 48
50#define _COMPONENT ACPI_NAMESPACE 49#define _COMPONENT ACPI_NAMESPACE
51ACPI_MODULE_NAME("nsrepair") 50ACPI_MODULE_NAME("nsrepair")
52 51
53/******************************************************************************* 52/*******************************************************************************
54 * 53 *
54 * This module attempts to repair or convert objects returned by the
55 * predefined methods to an object type that is expected, as per the ACPI
56 * specification. The need for this code is dictated by the many machines that
57 * return incorrect types for the standard predefined methods. Performing these
58 * conversions here, in one place, eliminates the need for individual ACPI
59 * device drivers to do the same. Note: Most of these conversions are different
60 * than the internal object conversion routines used for implicit object
61 * conversion.
62 *
63 * The following conversions can be performed as necessary:
64 *
65 * Integer -> String
66 * Integer -> Buffer
67 * String -> Integer
68 * String -> Buffer
69 * Buffer -> Integer
70 * Buffer -> String
71 * Buffer -> Package of Integers
72 * Package -> Package of one Package
73 *
74 ******************************************************************************/
75/* Local prototypes */
76static acpi_status
77acpi_ns_convert_to_integer(union acpi_operand_object *original_object,
78 union acpi_operand_object **return_object);
79
80static acpi_status
81acpi_ns_convert_to_string(union acpi_operand_object *original_object,
82 union acpi_operand_object **return_object);
83
84static acpi_status
85acpi_ns_convert_to_buffer(union acpi_operand_object *original_object,
86 union acpi_operand_object **return_object);
87
88static acpi_status
89acpi_ns_convert_to_package(union acpi_operand_object *original_object,
90 union acpi_operand_object **return_object);
91
92/*******************************************************************************
93 *
55 * FUNCTION: acpi_ns_repair_object 94 * FUNCTION: acpi_ns_repair_object
56 * 95 *
57 * PARAMETERS: Data - Pointer to validation data structure 96 * PARAMETERS: Data - Pointer to validation data structure
@@ -68,6 +107,7 @@ ACPI_MODULE_NAME("nsrepair")
68 * not expected. 107 * not expected.
69 * 108 *
70 ******************************************************************************/ 109 ******************************************************************************/
110
71acpi_status 111acpi_status
72acpi_ns_repair_object(struct acpi_predefined_data *data, 112acpi_ns_repair_object(struct acpi_predefined_data *data,
73 u32 expected_btypes, 113 u32 expected_btypes,
@@ -76,32 +116,206 @@ acpi_ns_repair_object(struct acpi_predefined_data *data,
76{ 116{
77 union acpi_operand_object *return_object = *return_object_ptr; 117 union acpi_operand_object *return_object = *return_object_ptr;
78 union acpi_operand_object *new_object; 118 union acpi_operand_object *new_object;
79 acpi_size length;
80 acpi_status status; 119 acpi_status status;
81 120
121 ACPI_FUNCTION_NAME(ns_repair_object);
122
82 /* 123 /*
83 * At this point, we know that the type of the returned object was not 124 * 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 125 * one of the expected types for this predefined name. Attempt to
85 * repair the object. Only a limited number of repairs are possible. 126 * repair the object by converting it to one of the expected object
127 * types for this predefined name.
86 */ 128 */
87 switch (return_object->common.type) { 129 if (expected_btypes & ACPI_RTYPE_INTEGER) {
130 status = acpi_ns_convert_to_integer(return_object, &new_object);
131 if (ACPI_SUCCESS(status)) {
132 goto object_repaired;
133 }
134 }
135 if (expected_btypes & ACPI_RTYPE_STRING) {
136 status = acpi_ns_convert_to_string(return_object, &new_object);
137 if (ACPI_SUCCESS(status)) {
138 goto object_repaired;
139 }
140 }
141 if (expected_btypes & ACPI_RTYPE_BUFFER) {
142 status = acpi_ns_convert_to_buffer(return_object, &new_object);
143 if (ACPI_SUCCESS(status)) {
144 goto object_repaired;
145 }
146 }
147 if (expected_btypes & ACPI_RTYPE_PACKAGE) {
148 status = acpi_ns_convert_to_package(return_object, &new_object);
149 if (ACPI_SUCCESS(status)) {
150 goto object_repaired;
151 }
152 }
153
154 /* We cannot repair this object */
155
156 return (AE_AML_OPERAND_TYPE);
157
158 object_repaired:
159
160 /* Object was successfully repaired */
161
162 /*
163 * If the original object is a package element, we need to:
164 * 1. Set the reference count of the new object to match the
165 * reference count of the old object.
166 * 2. Decrement the reference count of the original object.
167 */
168 if (package_index != ACPI_NOT_PACKAGE_ELEMENT) {
169 new_object->common.reference_count =
170 return_object->common.reference_count;
171
172 if (return_object->common.reference_count > 1) {
173 return_object->common.reference_count--;
174 }
175
176 ACPI_DEBUG_PRINT((ACPI_DB_REPAIR,
177 "%s: Converted %s to expected %s at index %u\n",
178 data->pathname,
179 acpi_ut_get_object_type_name(return_object),
180 acpi_ut_get_object_type_name(new_object),
181 package_index));
182 } else {
183 ACPI_DEBUG_PRINT((ACPI_DB_REPAIR,
184 "%s: Converted %s to expected %s\n",
185 data->pathname,
186 acpi_ut_get_object_type_name(return_object),
187 acpi_ut_get_object_type_name(new_object)));
188 }
189
190 /* Delete old object, install the new return object */
191
192 acpi_ut_remove_reference(return_object);
193 *return_object_ptr = new_object;
194 data->flags |= ACPI_OBJECT_REPAIRED;
195 return (AE_OK);
196}
197
198/*******************************************************************************
199 *
200 * FUNCTION: acpi_ns_convert_to_integer
201 *
202 * PARAMETERS: original_object - Object to be converted
203 * return_object - Where the new converted object is returned
204 *
205 * RETURN: Status. AE_OK if conversion was successful.
206 *
207 * DESCRIPTION: Attempt to convert a String/Buffer object to an Integer.
208 *
209 ******************************************************************************/
210
211static acpi_status
212acpi_ns_convert_to_integer(union acpi_operand_object *original_object,
213 union acpi_operand_object **return_object)
214{
215 union acpi_operand_object *new_object;
216 acpi_status status;
217 u64 value = 0;
218 u32 i;
219
220 switch (original_object->common.type) {
221 case ACPI_TYPE_STRING:
222
223 /* String-to-Integer conversion */
224
225 status = acpi_ut_strtoul64(original_object->string.pointer,
226 ACPI_ANY_BASE, &value);
227 if (ACPI_FAILURE(status)) {
228 return (status);
229 }
230 break;
231
88 case ACPI_TYPE_BUFFER: 232 case ACPI_TYPE_BUFFER:
89 233
90 /* Does the method/object legally return a string? */ 234 /* Buffer-to-Integer conversion. Max buffer size is 64 bits. */
91 235
92 if (!(expected_btypes & ACPI_RTYPE_STRING)) { 236 if (original_object->buffer.length > 8) {
93 return (AE_AML_OPERAND_TYPE); 237 return (AE_AML_OPERAND_TYPE);
94 } 238 }
95 239
240 /* Extract each buffer byte to create the integer */
241
242 for (i = 0; i < original_object->buffer.length; i++) {
243 value |=
244 ((u64) original_object->buffer.
245 pointer[i] << (i * 8));
246 }
247 break;
248
249 default:
250 return (AE_AML_OPERAND_TYPE);
251 }
252
253 new_object = acpi_ut_create_integer_object(value);
254 if (!new_object) {
255 return (AE_NO_MEMORY);
256 }
257
258 *return_object = new_object;
259 return (AE_OK);
260}
261
262/*******************************************************************************
263 *
264 * FUNCTION: acpi_ns_convert_to_string
265 *
266 * PARAMETERS: original_object - Object to be converted
267 * return_object - Where the new converted object is returned
268 *
269 * RETURN: Status. AE_OK if conversion was successful.
270 *
271 * DESCRIPTION: Attempt to convert a Integer/Buffer object to a String.
272 *
273 ******************************************************************************/
274
275static acpi_status
276acpi_ns_convert_to_string(union acpi_operand_object *original_object,
277 union acpi_operand_object **return_object)
278{
279 union acpi_operand_object *new_object;
280 acpi_size length;
281 acpi_status status;
282
283 switch (original_object->common.type) {
284 case ACPI_TYPE_INTEGER:
285 /*
286 * Integer-to-String conversion. Commonly, convert
287 * an integer of value 0 to a NULL string. The last element of
288 * _BIF and _BIX packages occasionally need this fix.
289 */
290 if (original_object->integer.value == 0) {
291
292 /* Allocate a new NULL string object */
293
294 new_object = acpi_ut_create_string_object(0);
295 if (!new_object) {
296 return (AE_NO_MEMORY);
297 }
298 } else {
299 status =
300 acpi_ex_convert_to_string(original_object,
301 &new_object,
302 ACPI_IMPLICIT_CONVERT_HEX);
303 if (ACPI_FAILURE(status)) {
304 return (status);
305 }
306 }
307 break;
308
309 case ACPI_TYPE_BUFFER:
96 /* 310 /*
97 * Have a Buffer, expected a String, convert. Use a to_string 311 * Buffer-to-String conversion. Use a to_string
98 * conversion, no transform performed on the buffer data. The best 312 * conversion, no transform performed on the buffer data. The best
99 * example of this is the _BIF method, where the string data from 313 * example of this is the _BIF method, where the string data from
100 * the battery is often (incorrectly) returned as buffer object(s). 314 * the battery is often (incorrectly) returned as buffer object(s).
101 */ 315 */
102 length = 0; 316 length = 0;
103 while ((length < return_object->buffer.length) && 317 while ((length < original_object->buffer.length) &&
104 (return_object->buffer.pointer[length])) { 318 (original_object->buffer.pointer[length])) {
105 length++; 319 length++;
106 } 320 }
107 321
@@ -117,94 +331,176 @@ acpi_ns_repair_object(struct acpi_predefined_data *data,
117 * terminated at Length+1. 331 * terminated at Length+1.
118 */ 332 */
119 ACPI_MEMCPY(new_object->string.pointer, 333 ACPI_MEMCPY(new_object->string.pointer,
120 return_object->buffer.pointer, length); 334 original_object->buffer.pointer, length);
121 break; 335 break;
122 336
337 default:
338 return (AE_AML_OPERAND_TYPE);
339 }
340
341 *return_object = new_object;
342 return (AE_OK);
343}
344
345/*******************************************************************************
346 *
347 * FUNCTION: acpi_ns_convert_to_buffer
348 *
349 * PARAMETERS: original_object - Object to be converted
350 * return_object - Where the new converted object is returned
351 *
352 * RETURN: Status. AE_OK if conversion was successful.
353 *
354 * DESCRIPTION: Attempt to convert a Integer/String/Package object to a Buffer.
355 *
356 ******************************************************************************/
357
358static acpi_status
359acpi_ns_convert_to_buffer(union acpi_operand_object *original_object,
360 union acpi_operand_object **return_object)
361{
362 union acpi_operand_object *new_object;
363 acpi_status status;
364 union acpi_operand_object **elements;
365 u32 *dword_buffer;
366 u32 count;
367 u32 i;
368
369 switch (original_object->common.type) {
123 case ACPI_TYPE_INTEGER: 370 case ACPI_TYPE_INTEGER:
371 /*
372 * Integer-to-Buffer conversion.
373 * Convert the Integer to a packed-byte buffer. _MAT and other
374 * objects need this sometimes, if a read has been performed on a
375 * Field object that is less than or equal to the global integer
376 * size (32 or 64 bits).
377 */
378 status =
379 acpi_ex_convert_to_buffer(original_object, &new_object);
380 if (ACPI_FAILURE(status)) {
381 return (status);
382 }
383 break;
124 384
125 /* 1) Does the method/object legally return a buffer? */ 385 case ACPI_TYPE_STRING:
126 386
127 if (expected_btypes & ACPI_RTYPE_BUFFER) { 387 /* String-to-Buffer conversion. Simple data copy */
128 /* 388
129 * Convert the Integer to a packed-byte buffer. _MAT needs 389 new_object =
130 * this sometimes, if a read has been performed on a Field 390 acpi_ut_create_buffer_object(original_object->string.
131 * object that is less than or equal to the global integer 391 length);
132 * size (32 or 64 bits). 392 if (!new_object) {
133 */ 393 return (AE_NO_MEMORY);
134 status =
135 acpi_ex_convert_to_buffer(return_object,
136 &new_object);
137 if (ACPI_FAILURE(status)) {
138 return (status);
139 }
140 } 394 }
141 395
142 /* 2) Does the method/object legally return a string? */ 396 ACPI_MEMCPY(new_object->buffer.pointer,
397 original_object->string.pointer,
398 original_object->string.length);
399 break;
400
401 case ACPI_TYPE_PACKAGE:
402 /*
403 * This case is often seen for predefined names that must return a
404 * Buffer object with multiple DWORD integers within. For example,
405 * _FDE and _GTM. The Package can be converted to a Buffer.
406 */
407
408 /* All elements of the Package must be integers */
143 409
144 else if (expected_btypes & ACPI_RTYPE_STRING) { 410 elements = original_object->package.elements;
145 /* 411 count = original_object->package.count;
146 * The only supported Integer-to-String conversion is to convert 412
147 * an integer of value 0 to a NULL string. The last element of 413 for (i = 0; i < count; i++) {
148 * _BIF and _BIX packages occasionally need this fix. 414 if ((!*elements) ||
149 */ 415 ((*elements)->common.type != ACPI_TYPE_INTEGER)) {
150 if (return_object->integer.value != 0) {
151 return (AE_AML_OPERAND_TYPE); 416 return (AE_AML_OPERAND_TYPE);
152 } 417 }
418 elements++;
419 }
153 420
154 /* Allocate a new NULL string object */ 421 /* Create the new buffer object to replace the Package */
155 422
156 new_object = acpi_ut_create_string_object(0); 423 new_object = acpi_ut_create_buffer_object(ACPI_MUL_4(count));
157 if (!new_object) { 424 if (!new_object) {
158 return (AE_NO_MEMORY); 425 return (AE_NO_MEMORY);
159 }
160 } else {
161 return (AE_AML_OPERAND_TYPE);
162 } 426 }
163 break;
164 427
165 default: 428 /* Copy the package elements (integers) to the buffer as DWORDs */
166 429
167 /* We cannot repair this object */ 430 elements = original_object->package.elements;
431 dword_buffer = ACPI_CAST_PTR(u32, new_object->buffer.pointer);
432
433 for (i = 0; i < count; i++) {
434 *dword_buffer = (u32) (*elements)->integer.value;
435 dword_buffer++;
436 elements++;
437 }
438 break;
168 439
440 default:
169 return (AE_AML_OPERAND_TYPE); 441 return (AE_AML_OPERAND_TYPE);
170 } 442 }
171 443
172 /* Object was successfully repaired */ 444 *return_object = new_object;
445 return (AE_OK);
446}
173 447
174 /* 448/*******************************************************************************
175 * If the original object is a package element, we need to: 449 *
176 * 1. Set the reference count of the new object to match the 450 * FUNCTION: acpi_ns_convert_to_package
177 * reference count of the old object. 451 *
178 * 2. Decrement the reference count of the original object. 452 * PARAMETERS: original_object - Object to be converted
179 */ 453 * return_object - Where the new converted object is returned
180 if (package_index != ACPI_NOT_PACKAGE_ELEMENT) { 454 *
181 new_object->common.reference_count = 455 * RETURN: Status. AE_OK if conversion was successful.
182 return_object->common.reference_count; 456 *
457 * DESCRIPTION: Attempt to convert a Buffer object to a Package. Each byte of
458 * the buffer is converted to a single integer package element.
459 *
460 ******************************************************************************/
183 461
184 if (return_object->common.reference_count > 1) { 462static acpi_status
185 return_object->common.reference_count--; 463acpi_ns_convert_to_package(union acpi_operand_object *original_object,
464 union acpi_operand_object **return_object)
465{
466 union acpi_operand_object *new_object;
467 union acpi_operand_object **elements;
468 u32 length;
469 u8 *buffer;
470
471 switch (original_object->common.type) {
472 case ACPI_TYPE_BUFFER:
473
474 /* Buffer-to-Package conversion */
475
476 length = original_object->buffer.length;
477 new_object = acpi_ut_create_package_object(length);
478 if (!new_object) {
479 return (AE_NO_MEMORY);
186 } 480 }
187 481
188 ACPI_INFO_PREDEFINED((AE_INFO, data->pathname, data->node_flags, 482 /* Convert each buffer byte to an integer package element */
189 "Converted %s to expected %s at index %u",
190 acpi_ut_get_object_type_name
191 (return_object),
192 acpi_ut_get_object_type_name(new_object),
193 package_index));
194 } else {
195 ACPI_INFO_PREDEFINED((AE_INFO, data->pathname, data->node_flags,
196 "Converted %s to expected %s",
197 acpi_ut_get_object_type_name
198 (return_object),
199 acpi_ut_get_object_type_name
200 (new_object)));
201 }
202 483
203 /* Delete old object, install the new return object */ 484 elements = new_object->package.elements;
485 buffer = original_object->buffer.pointer;
204 486
205 acpi_ut_remove_reference(return_object); 487 while (length--) {
206 *return_object_ptr = new_object; 488 *elements =
207 data->flags |= ACPI_OBJECT_REPAIRED; 489 acpi_ut_create_integer_object((u64) *buffer);
490 if (!*elements) {
491 acpi_ut_remove_reference(new_object);
492 return (AE_NO_MEMORY);
493 }
494 elements++;
495 buffer++;
496 }
497 break;
498
499 default:
500 return (AE_AML_OPERAND_TYPE);
501 }
502
503 *return_object = new_object;
208 return (AE_OK); 504 return (AE_OK);
209} 505}
210 506
@@ -238,6 +534,8 @@ acpi_ns_repair_package_list(struct acpi_predefined_data *data,
238{ 534{
239 union acpi_operand_object *pkg_obj_desc; 535 union acpi_operand_object *pkg_obj_desc;
240 536
537 ACPI_FUNCTION_NAME(ns_repair_package_list);
538
241 /* 539 /*
242 * Create the new outer package and populate it. The new package will 540 * Create the new outer package and populate it. The new package will
243 * have a single element, the lone subpackage. 541 * have a single element, the lone subpackage.
@@ -254,8 +552,9 @@ acpi_ns_repair_package_list(struct acpi_predefined_data *data,
254 *obj_desc_ptr = pkg_obj_desc; 552 *obj_desc_ptr = pkg_obj_desc;
255 data->flags |= ACPI_OBJECT_REPAIRED; 553 data->flags |= ACPI_OBJECT_REPAIRED;
256 554
257 ACPI_INFO_PREDEFINED((AE_INFO, data->pathname, data->node_flags, 555 ACPI_DEBUG_PRINT((ACPI_DB_REPAIR,
258 "Repaired Incorrectly formed Package")); 556 "%s: Repaired incorrectly formed Package\n",
557 data->pathname));
259 558
260 return (AE_OK); 559 return (AE_OK);
261} 560}