Commit | Line | Data |
---|---|---|
b2deadd5 BM |
1 | /****************************************************************************** |
2 | * | |
3 | * Module Name: nsrepair - Repair for objects returned by predefined methods | |
4 | * | |
5 | *****************************************************************************/ | |
6 | ||
7 | /* | |
25f044e6 | 8 | * Copyright (C) 2000 - 2013, Intel Corp. |
b2deadd5 BM |
9 | * All rights reserved. |
10 | * | |
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. | |
25 | * | |
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. | |
29 | * | |
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. | |
42 | */ | |
43 | ||
44 | #include <acpi/acpi.h> | |
45 | #include "accommon.h" | |
46 | #include "acnamesp.h" | |
0240d7b4 | 47 | #include "acinterp.h" |
091f4d71 | 48 | #include "acpredef.h" |
d5a36100 | 49 | #include "amlresrc.h" |
b2deadd5 BM |
50 | |
51 | #define _COMPONENT ACPI_NAMESPACE | |
52 | ACPI_MODULE_NAME("nsrepair") | |
53 | ||
47e11d54 BM |
54 | /******************************************************************************* |
55 | * | |
56 | * This module attempts to repair or convert objects returned by the | |
57 | * predefined methods to an object type that is expected, as per the ACPI | |
58 | * specification. The need for this code is dictated by the many machines that | |
59 | * return incorrect types for the standard predefined methods. Performing these | |
60 | * conversions here, in one place, eliminates the need for individual ACPI | |
61 | * device drivers to do the same. Note: Most of these conversions are different | |
62 | * than the internal object conversion routines used for implicit object | |
63 | * conversion. | |
64 | * | |
65 | * The following conversions can be performed as necessary: | |
66 | * | |
67 | * Integer -> String | |
68 | * Integer -> Buffer | |
69 | * String -> Integer | |
70 | * String -> Buffer | |
71 | * Buffer -> Integer | |
72 | * Buffer -> String | |
73 | * Buffer -> Package of Integers | |
74 | * Package -> Package of one Package | |
d5a36100 BM |
75 | * |
76 | * Additional conversions that are available: | |
77 | * Convert a null return or zero return value to an end_tag descriptor | |
78 | * Convert an ASCII string to a Unicode buffer | |
79 | * | |
6a99b1c9 | 80 | * An incorrect standalone object is wrapped with required outer package |
47e11d54 | 81 | * |
091f4d71 | 82 | * Additional possible repairs: |
091f4d71 | 83 | * Required package elements that are NULL replaced by Integer/String/Buffer |
091f4d71 | 84 | * |
47e11d54 BM |
85 | ******************************************************************************/ |
86 | /* Local prototypes */ | |
d5a36100 BM |
87 | static const struct acpi_simple_repair_info *acpi_ns_match_simple_repair(struct |
88 | acpi_namespace_node | |
89 | *node, | |
90 | u32 | |
91 | return_btype, | |
92 | u32 | |
93 | package_index); | |
94 | ||
95 | /* | |
96 | * Special but simple repairs for some names. | |
97 | * | |
98 | * 2nd argument: Unexpected types that can be repaired | |
99 | */ | |
100 | static const struct acpi_simple_repair_info acpi_object_repair_info[] = { | |
88fd0ac8 LZ |
101 | /* Resource descriptor conversions */ |
102 | ||
103 | {"_CRS", | |
104 | ACPI_RTYPE_INTEGER | ACPI_RTYPE_STRING | ACPI_RTYPE_BUFFER | | |
105 | ACPI_RTYPE_NONE, | |
106 | ACPI_NOT_PACKAGE_ELEMENT, | |
107 | acpi_ns_convert_to_resource}, | |
108 | {"_DMA", | |
109 | ACPI_RTYPE_INTEGER | ACPI_RTYPE_STRING | ACPI_RTYPE_BUFFER | | |
110 | ACPI_RTYPE_NONE, | |
111 | ACPI_NOT_PACKAGE_ELEMENT, | |
112 | acpi_ns_convert_to_resource}, | |
113 | {"_PRS", | |
114 | ACPI_RTYPE_INTEGER | ACPI_RTYPE_STRING | ACPI_RTYPE_BUFFER | | |
115 | ACPI_RTYPE_NONE, | |
116 | ACPI_NOT_PACKAGE_ELEMENT, | |
117 | acpi_ns_convert_to_resource}, | |
118 | ||
96b44cc6 LZ |
119 | /* Unicode conversions */ |
120 | ||
121 | {"_MLS", ACPI_RTYPE_STRING, 1, | |
122 | acpi_ns_convert_to_unicode}, | |
123 | {"_STR", ACPI_RTYPE_STRING | ACPI_RTYPE_BUFFER, | |
124 | ACPI_NOT_PACKAGE_ELEMENT, | |
125 | acpi_ns_convert_to_unicode}, | |
d5a36100 BM |
126 | {{0, 0, 0, 0}, 0, 0, NULL} /* Table terminator */ |
127 | }; | |
128 | ||
b2deadd5 BM |
129 | /******************************************************************************* |
130 | * | |
d5a36100 | 131 | * FUNCTION: acpi_ns_simple_repair |
b2deadd5 | 132 | * |
29a241cc | 133 | * PARAMETERS: info - Method execution information block |
b2deadd5 BM |
134 | * expected_btypes - Object types expected |
135 | * package_index - Index of object within parent package (if | |
136 | * applicable - ACPI_NOT_PACKAGE_ELEMENT | |
137 | * otherwise) | |
138 | * return_object_ptr - Pointer to the object returned from the | |
139 | * evaluation of a method or object | |
140 | * | |
141 | * RETURN: Status. AE_OK if repair was successful. | |
142 | * | |
143 | * DESCRIPTION: Attempt to repair/convert a return object of a type that was | |
144 | * not expected. | |
145 | * | |
146 | ******************************************************************************/ | |
47e11d54 | 147 | |
b2deadd5 | 148 | acpi_status |
29a241cc | 149 | acpi_ns_simple_repair(struct acpi_evaluate_info *info, |
b2deadd5 BM |
150 | u32 expected_btypes, |
151 | u32 package_index, | |
152 | union acpi_operand_object **return_object_ptr) | |
153 | { | |
154 | union acpi_operand_object *return_object = *return_object_ptr; | |
d5a36100 | 155 | union acpi_operand_object *new_object = NULL; |
0240d7b4 | 156 | acpi_status status; |
d5a36100 | 157 | const struct acpi_simple_repair_info *predefined; |
b2deadd5 | 158 | |
d5a36100 BM |
159 | ACPI_FUNCTION_NAME(ns_simple_repair); |
160 | ||
161 | /* | |
162 | * Special repairs for certain names that are in the repair table. | |
163 | * Check if this name is in the list of repairable names. | |
164 | */ | |
29a241cc BM |
165 | predefined = acpi_ns_match_simple_repair(info->node, |
166 | info->return_btype, | |
d5a36100 BM |
167 | package_index); |
168 | if (predefined) { | |
169 | if (!return_object) { | |
29a241cc | 170 | ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname, |
d5a36100 BM |
171 | ACPI_WARN_ALWAYS, |
172 | "Missing expected return value")); | |
173 | } | |
174 | ||
175 | status = | |
176 | predefined->object_converter(return_object, &new_object); | |
177 | if (ACPI_FAILURE(status)) { | |
178 | ||
179 | /* A fatal error occurred during a conversion */ | |
180 | ||
181 | ACPI_EXCEPTION((AE_INFO, status, | |
182 | "During return object analysis")); | |
183 | return (status); | |
184 | } | |
185 | if (new_object) { | |
186 | goto object_repaired; | |
187 | } | |
188 | } | |
189 | ||
190 | /* | |
191 | * Do not perform simple object repair unless the return type is not | |
192 | * expected. | |
193 | */ | |
29a241cc | 194 | if (info->return_btype & expected_btypes) { |
d5a36100 BM |
195 | return (AE_OK); |
196 | } | |
3a58176e | 197 | |
27526993 BM |
198 | /* |
199 | * At this point, we know that the type of the returned object was not | |
200 | * one of the expected types for this predefined name. Attempt to | |
47e11d54 BM |
201 | * repair the object by converting it to one of the expected object |
202 | * types for this predefined name. | |
203 | */ | |
d5a36100 BM |
204 | |
205 | /* | |
206 | * If there is no return value, check if we require a return value for | |
207 | * this predefined name. Either one return value is expected, or none, | |
208 | * for both methods and other objects. | |
209 | * | |
210 | * Exit now if there is no return object. Warning if one was expected. | |
211 | */ | |
212 | if (!return_object) { | |
213 | if (expected_btypes && (!(expected_btypes & ACPI_RTYPE_NONE))) { | |
29a241cc | 214 | ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname, |
d5a36100 BM |
215 | ACPI_WARN_ALWAYS, |
216 | "Missing expected return value")); | |
217 | ||
218 | return (AE_AML_NO_RETURN_VALUE); | |
219 | } | |
220 | } | |
221 | ||
47e11d54 BM |
222 | if (expected_btypes & ACPI_RTYPE_INTEGER) { |
223 | status = acpi_ns_convert_to_integer(return_object, &new_object); | |
224 | if (ACPI_SUCCESS(status)) { | |
225 | goto object_repaired; | |
226 | } | |
227 | } | |
228 | if (expected_btypes & ACPI_RTYPE_STRING) { | |
229 | status = acpi_ns_convert_to_string(return_object, &new_object); | |
230 | if (ACPI_SUCCESS(status)) { | |
231 | goto object_repaired; | |
232 | } | |
233 | } | |
234 | if (expected_btypes & ACPI_RTYPE_BUFFER) { | |
235 | status = acpi_ns_convert_to_buffer(return_object, &new_object); | |
236 | if (ACPI_SUCCESS(status)) { | |
237 | goto object_repaired; | |
238 | } | |
239 | } | |
240 | if (expected_btypes & ACPI_RTYPE_PACKAGE) { | |
6a99b1c9 BM |
241 | /* |
242 | * A package is expected. We will wrap the existing object with a | |
243 | * new package object. It is often the case that if a variable-length | |
244 | * package is required, but there is only a single object needed, the | |
245 | * BIOS will return that object instead of wrapping it with a Package | |
246 | * object. Note: after the wrapping, the package will be validated | |
247 | * for correct contents (expected object type or types). | |
248 | */ | |
249 | status = | |
29a241cc | 250 | acpi_ns_wrap_with_package(info, return_object, &new_object); |
47e11d54 | 251 | if (ACPI_SUCCESS(status)) { |
6a99b1c9 BM |
252 | /* |
253 | * The original object just had its reference count | |
254 | * incremented for being inserted into the new package. | |
255 | */ | |
256 | *return_object_ptr = new_object; /* New Package object */ | |
29a241cc | 257 | info->return_flags |= ACPI_OBJECT_REPAIRED; |
6a99b1c9 | 258 | return (AE_OK); |
47e11d54 BM |
259 | } |
260 | } | |
261 | ||
262 | /* We cannot repair this object */ | |
263 | ||
264 | return (AE_AML_OPERAND_TYPE); | |
265 | ||
266 | object_repaired: | |
267 | ||
268 | /* Object was successfully repaired */ | |
269 | ||
47e11d54 | 270 | if (package_index != ACPI_NOT_PACKAGE_ELEMENT) { |
6a99b1c9 BM |
271 | /* |
272 | * The original object is a package element. We need to | |
273 | * decrement the reference count of the original object, | |
274 | * for removing it from the package. | |
275 | * | |
276 | * However, if the original object was just wrapped with a | |
277 | * package object as part of the repair, we don't need to | |
278 | * change the reference count. | |
279 | */ | |
29a241cc | 280 | if (!(info->return_flags & ACPI_OBJECT_WRAPPED)) { |
6a99b1c9 BM |
281 | new_object->common.reference_count = |
282 | return_object->common.reference_count; | |
47e11d54 | 283 | |
6a99b1c9 BM |
284 | if (return_object->common.reference_count > 1) { |
285 | return_object->common.reference_count--; | |
286 | } | |
47e11d54 BM |
287 | } |
288 | ||
3a58176e | 289 | ACPI_DEBUG_PRINT((ACPI_DB_REPAIR, |
6a99b1c9 | 290 | "%s: Converted %s to expected %s at Package index %u\n", |
29a241cc | 291 | info->full_pathname, |
3a58176e BM |
292 | acpi_ut_get_object_type_name(return_object), |
293 | acpi_ut_get_object_type_name(new_object), | |
294 | package_index)); | |
47e11d54 | 295 | } else { |
3a58176e BM |
296 | ACPI_DEBUG_PRINT((ACPI_DB_REPAIR, |
297 | "%s: Converted %s to expected %s\n", | |
29a241cc | 298 | info->full_pathname, |
3a58176e BM |
299 | acpi_ut_get_object_type_name(return_object), |
300 | acpi_ut_get_object_type_name(new_object))); | |
47e11d54 BM |
301 | } |
302 | ||
303 | /* Delete old object, install the new return object */ | |
304 | ||
305 | acpi_ut_remove_reference(return_object); | |
306 | *return_object_ptr = new_object; | |
29a241cc | 307 | info->return_flags |= ACPI_OBJECT_REPAIRED; |
47e11d54 BM |
308 | return (AE_OK); |
309 | } | |
310 | ||
d5a36100 BM |
311 | /****************************************************************************** |
312 | * | |
313 | * FUNCTION: acpi_ns_match_simple_repair | |
314 | * | |
315 | * PARAMETERS: node - Namespace node for the method/object | |
316 | * return_btype - Object type that was returned | |
317 | * package_index - Index of object within parent package (if | |
318 | * applicable - ACPI_NOT_PACKAGE_ELEMENT | |
319 | * otherwise) | |
320 | * | |
321 | * RETURN: Pointer to entry in repair table. NULL indicates not found. | |
322 | * | |
323 | * DESCRIPTION: Check an object name against the repairable object list. | |
324 | * | |
325 | *****************************************************************************/ | |
326 | ||
327 | static const struct acpi_simple_repair_info *acpi_ns_match_simple_repair(struct | |
328 | acpi_namespace_node | |
329 | *node, | |
330 | u32 | |
331 | return_btype, | |
332 | u32 | |
333 | package_index) | |
334 | { | |
335 | const struct acpi_simple_repair_info *this_name; | |
336 | ||
337 | /* Search info table for a repairable predefined method/object name */ | |
338 | ||
339 | this_name = acpi_object_repair_info; | |
340 | while (this_name->object_converter) { | |
341 | if (ACPI_COMPARE_NAME(node->name.ascii, this_name->name)) { | |
342 | ||
343 | /* Check if we can actually repair this name/type combination */ | |
344 | ||
345 | if ((return_btype & this_name->unexpected_btypes) && | |
346 | (package_index == this_name->package_index)) { | |
347 | return (this_name); | |
348 | } | |
349 | ||
350 | return (NULL); | |
351 | } | |
352 | this_name++; | |
353 | } | |
354 | ||
355 | return (NULL); /* Name was not found in the repair table */ | |
356 | } | |
357 | ||
091f4d71 BM |
358 | /******************************************************************************* |
359 | * | |
360 | * FUNCTION: acpi_ns_repair_null_element | |
361 | * | |
29a241cc | 362 | * PARAMETERS: info - Method execution information block |
091f4d71 BM |
363 | * expected_btypes - Object types expected |
364 | * package_index - Index of object within parent package (if | |
365 | * applicable - ACPI_NOT_PACKAGE_ELEMENT | |
366 | * otherwise) | |
367 | * return_object_ptr - Pointer to the object returned from the | |
368 | * evaluation of a method or object | |
369 | * | |
370 | * RETURN: Status. AE_OK if repair was successful. | |
371 | * | |
372 | * DESCRIPTION: Attempt to repair a NULL element of a returned Package object. | |
373 | * | |
374 | ******************************************************************************/ | |
375 | ||
376 | acpi_status | |
29a241cc | 377 | acpi_ns_repair_null_element(struct acpi_evaluate_info * info, |
091f4d71 BM |
378 | u32 expected_btypes, |
379 | u32 package_index, | |
380 | union acpi_operand_object **return_object_ptr) | |
381 | { | |
382 | union acpi_operand_object *return_object = *return_object_ptr; | |
383 | union acpi_operand_object *new_object; | |
384 | ||
385 | ACPI_FUNCTION_NAME(ns_repair_null_element); | |
386 | ||
387 | /* No repair needed if return object is non-NULL */ | |
388 | ||
389 | if (return_object) { | |
390 | return (AE_OK); | |
391 | } | |
392 | ||
393 | /* | |
394 | * Attempt to repair a NULL element of a Package object. This applies to | |
395 | * predefined names that return a fixed-length package and each element | |
396 | * is required. It does not apply to variable-length packages where NULL | |
397 | * elements are allowed, especially at the end of the package. | |
398 | */ | |
399 | if (expected_btypes & ACPI_RTYPE_INTEGER) { | |
400 | ||
ba494bee | 401 | /* Need an integer - create a zero-value integer */ |
091f4d71 | 402 | |
150dba38 | 403 | new_object = acpi_ut_create_integer_object((u64)0); |
091f4d71 BM |
404 | } else if (expected_btypes & ACPI_RTYPE_STRING) { |
405 | ||
ba494bee | 406 | /* Need a string - create a NULL string */ |
091f4d71 BM |
407 | |
408 | new_object = acpi_ut_create_string_object(0); | |
409 | } else if (expected_btypes & ACPI_RTYPE_BUFFER) { | |
410 | ||
ba494bee | 411 | /* Need a buffer - create a zero-length buffer */ |
091f4d71 BM |
412 | |
413 | new_object = acpi_ut_create_buffer_object(0); | |
414 | } else { | |
415 | /* Error for all other expected types */ | |
416 | ||
417 | return (AE_AML_OPERAND_TYPE); | |
418 | } | |
419 | ||
420 | if (!new_object) { | |
421 | return (AE_NO_MEMORY); | |
422 | } | |
423 | ||
424 | /* Set the reference count according to the parent Package object */ | |
425 | ||
426 | new_object->common.reference_count = | |
29a241cc | 427 | info->parent_package->common.reference_count; |
091f4d71 BM |
428 | |
429 | ACPI_DEBUG_PRINT((ACPI_DB_REPAIR, | |
430 | "%s: Converted NULL package element to expected %s at index %u\n", | |
29a241cc | 431 | info->full_pathname, |
091f4d71 BM |
432 | acpi_ut_get_object_type_name(new_object), |
433 | package_index)); | |
434 | ||
435 | *return_object_ptr = new_object; | |
29a241cc | 436 | info->return_flags |= ACPI_OBJECT_REPAIRED; |
091f4d71 BM |
437 | return (AE_OK); |
438 | } | |
439 | ||
440 | /****************************************************************************** | |
441 | * | |
442 | * FUNCTION: acpi_ns_remove_null_elements | |
443 | * | |
29a241cc | 444 | * PARAMETERS: info - Method execution information block |
091f4d71 BM |
445 | * package_type - An acpi_return_package_types value |
446 | * obj_desc - A Package object | |
447 | * | |
448 | * RETURN: None. | |
449 | * | |
450 | * DESCRIPTION: Remove all NULL package elements from packages that contain | |
451 | * a variable number of sub-packages. For these types of | |
452 | * packages, NULL elements can be safely removed. | |
453 | * | |
454 | *****************************************************************************/ | |
455 | ||
456 | void | |
29a241cc | 457 | acpi_ns_remove_null_elements(struct acpi_evaluate_info *info, |
091f4d71 BM |
458 | u8 package_type, |
459 | union acpi_operand_object *obj_desc) | |
460 | { | |
461 | union acpi_operand_object **source; | |
462 | union acpi_operand_object **dest; | |
463 | u32 count; | |
464 | u32 new_count; | |
465 | u32 i; | |
466 | ||
467 | ACPI_FUNCTION_NAME(ns_remove_null_elements); | |
468 | ||
469 | /* | |
945488b9 BM |
470 | * We can safely remove all NULL elements from these package types: |
471 | * PTYPE1_VAR packages contain a variable number of simple data types. | |
472 | * PTYPE2 packages contain a variable number of sub-packages. | |
091f4d71 BM |
473 | */ |
474 | switch (package_type) { | |
091f4d71 | 475 | case ACPI_PTYPE1_VAR: |
091f4d71 BM |
476 | case ACPI_PTYPE2: |
477 | case ACPI_PTYPE2_COUNT: | |
478 | case ACPI_PTYPE2_PKG_COUNT: | |
479 | case ACPI_PTYPE2_FIXED: | |
480 | case ACPI_PTYPE2_MIN: | |
481 | case ACPI_PTYPE2_REV_FIXED: | |
7fce7a4b | 482 | case ACPI_PTYPE2_FIX_VAR: |
1d1ea1b7 | 483 | |
091f4d71 BM |
484 | break; |
485 | ||
486 | default: | |
945488b9 BM |
487 | case ACPI_PTYPE1_FIXED: |
488 | case ACPI_PTYPE1_OPTION: | |
091f4d71 BM |
489 | return; |
490 | } | |
491 | ||
492 | count = obj_desc->package.count; | |
493 | new_count = count; | |
494 | ||
495 | source = obj_desc->package.elements; | |
496 | dest = source; | |
497 | ||
498 | /* Examine all elements of the package object, remove nulls */ | |
499 | ||
500 | for (i = 0; i < count; i++) { | |
501 | if (!*source) { | |
502 | new_count--; | |
503 | } else { | |
504 | *dest = *source; | |
505 | dest++; | |
506 | } | |
507 | source++; | |
508 | } | |
509 | ||
510 | /* Update parent package if any null elements were removed */ | |
511 | ||
512 | if (new_count < count) { | |
513 | ACPI_DEBUG_PRINT((ACPI_DB_REPAIR, | |
514 | "%s: Found and removed %u NULL elements\n", | |
29a241cc | 515 | info->full_pathname, (count - new_count))); |
091f4d71 BM |
516 | |
517 | /* NULL terminate list and update the package count */ | |
518 | ||
519 | *dest = NULL; | |
520 | obj_desc->package.count = new_count; | |
521 | } | |
522 | } | |
523 | ||
e5f69d6e BM |
524 | /******************************************************************************* |
525 | * | |
6a99b1c9 | 526 | * FUNCTION: acpi_ns_wrap_with_package |
e5f69d6e | 527 | * |
29a241cc | 528 | * PARAMETERS: info - Method execution information block |
6a99b1c9 BM |
529 | * original_object - Pointer to the object to repair. |
530 | * obj_desc_ptr - The new package object is returned here | |
e5f69d6e BM |
531 | * |
532 | * RETURN: Status, new object in *obj_desc_ptr | |
533 | * | |
6a99b1c9 BM |
534 | * DESCRIPTION: Repair a common problem with objects that are defined to |
535 | * return a variable-length Package of sub-objects. If there is | |
536 | * only one sub-object, some BIOS code mistakenly simply declares | |
537 | * the single object instead of a Package with one sub-object. | |
538 | * This function attempts to repair this error by wrapping a | |
539 | * Package object around the original object, creating the | |
540 | * correct and expected Package with one sub-object. | |
e5f69d6e BM |
541 | * |
542 | * Names that can be repaired in this manner include: | |
6a99b1c9 BM |
543 | * _ALR, _CSD, _HPX, _MLS, _PLD, _PRT, _PSS, _TRT, _TSS, |
544 | * _BCL, _DOD, _FIX, _Sx | |
e5f69d6e BM |
545 | * |
546 | ******************************************************************************/ | |
547 | ||
548 | acpi_status | |
29a241cc | 549 | acpi_ns_wrap_with_package(struct acpi_evaluate_info *info, |
6a99b1c9 BM |
550 | union acpi_operand_object *original_object, |
551 | union acpi_operand_object **obj_desc_ptr) | |
e5f69d6e BM |
552 | { |
553 | union acpi_operand_object *pkg_obj_desc; | |
554 | ||
6a99b1c9 | 555 | ACPI_FUNCTION_NAME(ns_wrap_with_package); |
3a58176e | 556 | |
e5f69d6e BM |
557 | /* |
558 | * Create the new outer package and populate it. The new package will | |
6a99b1c9 | 559 | * have a single element, the lone sub-object. |
e5f69d6e BM |
560 | */ |
561 | pkg_obj_desc = acpi_ut_create_package_object(1); | |
562 | if (!pkg_obj_desc) { | |
563 | return (AE_NO_MEMORY); | |
564 | } | |
565 | ||
6a99b1c9 BM |
566 | pkg_obj_desc->package.elements[0] = original_object; |
567 | ||
568 | ACPI_DEBUG_PRINT((ACPI_DB_REPAIR, | |
569 | "%s: Wrapped %s with expected Package object\n", | |
29a241cc | 570 | info->full_pathname, |
6a99b1c9 | 571 | acpi_ut_get_object_type_name(original_object))); |
e5f69d6e BM |
572 | |
573 | /* Return the new object in the object pointer */ | |
574 | ||
575 | *obj_desc_ptr = pkg_obj_desc; | |
29a241cc | 576 | info->return_flags |= ACPI_OBJECT_REPAIRED | ACPI_OBJECT_WRAPPED; |
e5f69d6e BM |
577 | return (AE_OK); |
578 | } |