blob: be86fea8e4d48aa08bc0032f582749a1a40ba771 [file] [log] [blame]
Erik Schmauss95857632018-03-14 16:13:07 -07001// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
Bob Mooreb2deadd2009-07-24 10:56:43 +08002/******************************************************************************
3 *
4 * Module Name: nsrepair - Repair for objects returned by predefined methods
5 *
Bob Moore840c02c2019-01-14 09:55:25 -08006 * Copyright (C) 2000 - 2019, Intel Corp.
Bob Mooreb2deadd2009-07-24 10:56:43 +08007 *
Erik Schmauss95857632018-03-14 16:13:07 -07008 *****************************************************************************/
Bob Mooreb2deadd2009-07-24 10:56:43 +08009
10#include <acpi/acpi.h>
11#include "accommon.h"
12#include "acnamesp.h"
Lin Ming0240d7b2009-10-13 10:23:20 +080013#include "acinterp.h"
Bob Moore091f4d72010-01-21 09:28:32 +080014#include "acpredef.h"
Bob Moored5a36102013-03-08 09:23:03 +000015#include "amlresrc.h"
Bob Mooreb2deadd2009-07-24 10:56:43 +080016
17#define _COMPONENT ACPI_NAMESPACE
18ACPI_MODULE_NAME("nsrepair")
19
20/*******************************************************************************
21 *
Bob Moore47e11d52009-12-11 15:01:12 +080022 * This module attempts to repair or convert objects returned by the
23 * predefined methods to an object type that is expected, as per the ACPI
24 * specification. The need for this code is dictated by the many machines that
25 * return incorrect types for the standard predefined methods. Performing these
26 * conversions here, in one place, eliminates the need for individual ACPI
27 * device drivers to do the same. Note: Most of these conversions are different
28 * than the internal object conversion routines used for implicit object
29 * conversion.
30 *
31 * The following conversions can be performed as necessary:
32 *
33 * Integer -> String
34 * Integer -> Buffer
35 * String -> Integer
36 * String -> Buffer
37 * Buffer -> Integer
38 * Buffer -> String
39 * Buffer -> Package of Integers
40 * Package -> Package of one Package
Bob Moored5a36102013-03-08 09:23:03 +000041 *
42 * Additional conversions that are available:
43 * Convert a null return or zero return value to an end_tag descriptor
44 * Convert an ASCII string to a Unicode buffer
45 *
Bob Moore6a99b1c2012-03-21 09:51:39 +080046 * An incorrect standalone object is wrapped with required outer package
Bob Moore47e11d52009-12-11 15:01:12 +080047 *
Bob Moore091f4d72010-01-21 09:28:32 +080048 * Additional possible repairs:
Bob Moore091f4d72010-01-21 09:28:32 +080049 * Required package elements that are NULL replaced by Integer/String/Buffer
Bob Moore091f4d72010-01-21 09:28:32 +080050 *
Bob Moore47e11d52009-12-11 15:01:12 +080051 ******************************************************************************/
52/* Local prototypes */
Bob Moored5a36102013-03-08 09:23:03 +000053static const struct acpi_simple_repair_info *acpi_ns_match_simple_repair(struct
54 acpi_namespace_node
55 *node,
56 u32
57 return_btype,
58 u32
59 package_index);
60
61/*
62 * Special but simple repairs for some names.
63 *
64 * 2nd argument: Unexpected types that can be repaired
65 */
66static const struct acpi_simple_repair_info acpi_object_repair_info[] = {
Lv Zheng88fd0ac2013-03-08 09:23:32 +000067 /* Resource descriptor conversions */
68
69 {"_CRS",
70 ACPI_RTYPE_INTEGER | ACPI_RTYPE_STRING | ACPI_RTYPE_BUFFER |
71 ACPI_RTYPE_NONE,
72 ACPI_NOT_PACKAGE_ELEMENT,
73 acpi_ns_convert_to_resource},
74 {"_DMA",
75 ACPI_RTYPE_INTEGER | ACPI_RTYPE_STRING | ACPI_RTYPE_BUFFER |
76 ACPI_RTYPE_NONE,
77 ACPI_NOT_PACKAGE_ELEMENT,
78 acpi_ns_convert_to_resource},
79 {"_PRS",
80 ACPI_RTYPE_INTEGER | ACPI_RTYPE_STRING | ACPI_RTYPE_BUFFER |
81 ACPI_RTYPE_NONE,
82 ACPI_NOT_PACKAGE_ELEMENT,
83 acpi_ns_convert_to_resource},
84
Lv Zhengee387402015-12-29 13:58:02 +080085 /* Object reference conversions */
86
87 {"_DEP", ACPI_RTYPE_STRING, ACPI_ALL_PACKAGE_ELEMENTS,
88 acpi_ns_convert_to_reference},
89
Lv Zheng96b44cc2013-03-08 09:23:24 +000090 /* Unicode conversions */
91
92 {"_MLS", ACPI_RTYPE_STRING, 1,
93 acpi_ns_convert_to_unicode},
94 {"_STR", ACPI_RTYPE_STRING | ACPI_RTYPE_BUFFER,
95 ACPI_NOT_PACKAGE_ELEMENT,
96 acpi_ns_convert_to_unicode},
Bob Moored5a36102013-03-08 09:23:03 +000097 {{0, 0, 0, 0}, 0, 0, NULL} /* Table terminator */
98};
99
Bob Moore47e11d52009-12-11 15:01:12 +0800100/*******************************************************************************
101 *
Bob Moored5a36102013-03-08 09:23:03 +0000102 * FUNCTION: acpi_ns_simple_repair
Bob Mooreb2deadd2009-07-24 10:56:43 +0800103 *
Bob Moore29a241c2013-05-30 10:00:01 +0800104 * PARAMETERS: info - Method execution information block
Bob Mooreb2deadd2009-07-24 10:56:43 +0800105 * expected_btypes - Object types expected
106 * package_index - Index of object within parent package (if
107 * applicable - ACPI_NOT_PACKAGE_ELEMENT
108 * otherwise)
109 * return_object_ptr - Pointer to the object returned from the
110 * evaluation of a method or object
111 *
112 * RETURN: Status. AE_OK if repair was successful.
113 *
114 * DESCRIPTION: Attempt to repair/convert a return object of a type that was
115 * not expected.
116 *
117 ******************************************************************************/
Bob Moore47e11d52009-12-11 15:01:12 +0800118
Bob Mooreb2deadd2009-07-24 10:56:43 +0800119acpi_status
Bob Moore29a241c2013-05-30 10:00:01 +0800120acpi_ns_simple_repair(struct acpi_evaluate_info *info,
Bob Mooreb2deadd2009-07-24 10:56:43 +0800121 u32 expected_btypes,
122 u32 package_index,
123 union acpi_operand_object **return_object_ptr)
124{
125 union acpi_operand_object *return_object = *return_object_ptr;
Bob Moored5a36102013-03-08 09:23:03 +0000126 union acpi_operand_object *new_object = NULL;
Lin Ming0240d7b2009-10-13 10:23:20 +0800127 acpi_status status;
Bob Moored5a36102013-03-08 09:23:03 +0000128 const struct acpi_simple_repair_info *predefined;
Bob Mooreb2deadd2009-07-24 10:56:43 +0800129
Bob Moored5a36102013-03-08 09:23:03 +0000130 ACPI_FUNCTION_NAME(ns_simple_repair);
131
132 /*
133 * Special repairs for certain names that are in the repair table.
134 * Check if this name is in the list of repairable names.
135 */
Bob Moore29a241c2013-05-30 10:00:01 +0800136 predefined = acpi_ns_match_simple_repair(info->node,
137 info->return_btype,
Bob Moored5a36102013-03-08 09:23:03 +0000138 package_index);
139 if (predefined) {
140 if (!return_object) {
Bob Moore29a241c2013-05-30 10:00:01 +0800141 ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
Bob Moored5a36102013-03-08 09:23:03 +0000142 ACPI_WARN_ALWAYS,
143 "Missing expected return value"));
144 }
145
Lv Zheng4debda52015-12-29 13:57:38 +0800146 status = predefined->object_converter(info->node, return_object,
147 &new_object);
Bob Moored5a36102013-03-08 09:23:03 +0000148 if (ACPI_FAILURE(status)) {
149
150 /* A fatal error occurred during a conversion */
151
152 ACPI_EXCEPTION((AE_INFO, status,
153 "During return object analysis"));
154 return (status);
155 }
156 if (new_object) {
157 goto object_repaired;
158 }
159 }
160
161 /*
162 * Do not perform simple object repair unless the return type is not
163 * expected.
164 */
Bob Moore29a241c2013-05-30 10:00:01 +0800165 if (info->return_btype & expected_btypes) {
Bob Moored5a36102013-03-08 09:23:03 +0000166 return (AE_OK);
167 }
Bob Moore3a581762009-12-11 15:23:22 +0800168
Bob Moore27526992009-10-13 10:20:33 +0800169 /*
170 * At this point, we know that the type of the returned object was not
171 * one of the expected types for this predefined name. Attempt to
Bob Moore47e11d52009-12-11 15:01:12 +0800172 * repair the object by converting it to one of the expected object
173 * types for this predefined name.
Bob Moore27526992009-10-13 10:20:33 +0800174 */
Bob Moored5a36102013-03-08 09:23:03 +0000175
176 /*
177 * If there is no return value, check if we require a return value for
178 * this predefined name. Either one return value is expected, or none,
179 * for both methods and other objects.
180 *
Lv Zheng61db45c2014-02-26 10:29:40 +0800181 * Try to fix if there was no return object. Warning if failed to fix.
Bob Moored5a36102013-03-08 09:23:03 +0000182 */
183 if (!return_object) {
184 if (expected_btypes && (!(expected_btypes & ACPI_RTYPE_NONE))) {
Lv Zheng61db45c2014-02-26 10:29:40 +0800185 if (package_index != ACPI_NOT_PACKAGE_ELEMENT) {
186 ACPI_WARN_PREDEFINED((AE_INFO,
187 info->full_pathname,
188 ACPI_WARN_ALWAYS,
189 "Found unexpected NULL package element"));
190
191 status =
192 acpi_ns_repair_null_element(info,
193 expected_btypes,
194 package_index,
195 return_object_ptr);
196 if (ACPI_SUCCESS(status)) {
197 return (AE_OK); /* Repair was successful */
198 }
199 } else {
200 ACPI_WARN_PREDEFINED((AE_INFO,
201 info->full_pathname,
202 ACPI_WARN_ALWAYS,
203 "Missing expected return value"));
204 }
Bob Moored5a36102013-03-08 09:23:03 +0000205
206 return (AE_AML_NO_RETURN_VALUE);
207 }
208 }
209
Bob Moore47e11d52009-12-11 15:01:12 +0800210 if (expected_btypes & ACPI_RTYPE_INTEGER) {
211 status = acpi_ns_convert_to_integer(return_object, &new_object);
212 if (ACPI_SUCCESS(status)) {
213 goto object_repaired;
Bob Mooreb2deadd2009-07-24 10:56:43 +0800214 }
Bob Mooreb2deadd2009-07-24 10:56:43 +0800215 }
Bob Moore47e11d52009-12-11 15:01:12 +0800216 if (expected_btypes & ACPI_RTYPE_STRING) {
217 status = acpi_ns_convert_to_string(return_object, &new_object);
218 if (ACPI_SUCCESS(status)) {
219 goto object_repaired;
220 }
221 }
222 if (expected_btypes & ACPI_RTYPE_BUFFER) {
223 status = acpi_ns_convert_to_buffer(return_object, &new_object);
224 if (ACPI_SUCCESS(status)) {
225 goto object_repaired;
226 }
227 }
228 if (expected_btypes & ACPI_RTYPE_PACKAGE) {
Bob Moore6a99b1c2012-03-21 09:51:39 +0800229 /*
230 * A package is expected. We will wrap the existing object with a
231 * new package object. It is often the case that if a variable-length
232 * package is required, but there is only a single object needed, the
233 * BIOS will return that object instead of wrapping it with a Package
234 * object. Note: after the wrapping, the package will be validated
235 * for correct contents (expected object type or types).
236 */
237 status =
Bob Moore29a241c2013-05-30 10:00:01 +0800238 acpi_ns_wrap_with_package(info, return_object, &new_object);
Bob Moore47e11d52009-12-11 15:01:12 +0800239 if (ACPI_SUCCESS(status)) {
Bob Moore6a99b1c2012-03-21 09:51:39 +0800240 /*
241 * The original object just had its reference count
242 * incremented for being inserted into the new package.
243 */
244 *return_object_ptr = new_object; /* New Package object */
Bob Moore29a241c2013-05-30 10:00:01 +0800245 info->return_flags |= ACPI_OBJECT_REPAIRED;
Bob Moore6a99b1c2012-03-21 09:51:39 +0800246 return (AE_OK);
Bob Moore47e11d52009-12-11 15:01:12 +0800247 }
248 }
249
250 /* We cannot repair this object */
251
252 return (AE_AML_OPERAND_TYPE);
253
Lv Zheng10622bf2013-10-29 09:30:02 +0800254object_repaired:
Bob Mooreb2deadd2009-07-24 10:56:43 +0800255
Bob Moore27526992009-10-13 10:20:33 +0800256 /* Object was successfully repaired */
257
Bob Moore27526992009-10-13 10:20:33 +0800258 if (package_index != ACPI_NOT_PACKAGE_ELEMENT) {
Bob Mooreed7f8bc2017-04-26 16:18:16 +0800259
260 /* Update reference count of new object */
261
Bob Moore29a241c2013-05-30 10:00:01 +0800262 if (!(info->return_flags & ACPI_OBJECT_WRAPPED)) {
Bob Moore6a99b1c2012-03-21 09:51:39 +0800263 new_object->common.reference_count =
264 return_object->common.reference_count;
Bob Moore27526992009-10-13 10:20:33 +0800265 }
266
Bob Moore3a581762009-12-11 15:23:22 +0800267 ACPI_DEBUG_PRINT((ACPI_DB_REPAIR,
Bob Moore6a99b1c2012-03-21 09:51:39 +0800268 "%s: Converted %s to expected %s at Package index %u\n",
Bob Moore29a241c2013-05-30 10:00:01 +0800269 info->full_pathname,
Bob Moore3a581762009-12-11 15:23:22 +0800270 acpi_ut_get_object_type_name(return_object),
271 acpi_ut_get_object_type_name(new_object),
272 package_index));
Bob Moore27526992009-10-13 10:20:33 +0800273 } else {
Bob Moore3a581762009-12-11 15:23:22 +0800274 ACPI_DEBUG_PRINT((ACPI_DB_REPAIR,
275 "%s: Converted %s to expected %s\n",
Bob Moore29a241c2013-05-30 10:00:01 +0800276 info->full_pathname,
Bob Moore3a581762009-12-11 15:23:22 +0800277 acpi_ut_get_object_type_name(return_object),
278 acpi_ut_get_object_type_name(new_object)));
Bob Moore27526992009-10-13 10:20:33 +0800279 }
280
281 /* Delete old object, install the new return object */
282
283 acpi_ut_remove_reference(return_object);
284 *return_object_ptr = new_object;
Bob Moore29a241c2013-05-30 10:00:01 +0800285 info->return_flags |= ACPI_OBJECT_REPAIRED;
Bob Moore27526992009-10-13 10:20:33 +0800286 return (AE_OK);
Bob Mooreb2deadd2009-07-24 10:56:43 +0800287}
Bob Mooree5f69d62009-07-24 11:03:09 +0800288
Bob Moored5a36102013-03-08 09:23:03 +0000289/******************************************************************************
290 *
291 * FUNCTION: acpi_ns_match_simple_repair
292 *
293 * PARAMETERS: node - Namespace node for the method/object
294 * return_btype - Object type that was returned
295 * package_index - Index of object within parent package (if
296 * applicable - ACPI_NOT_PACKAGE_ELEMENT
297 * otherwise)
298 *
299 * RETURN: Pointer to entry in repair table. NULL indicates not found.
300 *
301 * DESCRIPTION: Check an object name against the repairable object list.
302 *
303 *****************************************************************************/
304
305static const struct acpi_simple_repair_info *acpi_ns_match_simple_repair(struct
306 acpi_namespace_node
307 *node,
308 u32
309 return_btype,
310 u32
311 package_index)
312{
313 const struct acpi_simple_repair_info *this_name;
314
315 /* Search info table for a repairable predefined method/object name */
316
317 this_name = acpi_object_repair_info;
318 while (this_name->object_converter) {
Bob Moore5599fb62019-04-08 13:42:24 -0700319 if (ACPI_COMPARE_NAMESEG(node->name.ascii, this_name->name)) {
Bob Moored5a36102013-03-08 09:23:03 +0000320
321 /* Check if we can actually repair this name/type combination */
322
323 if ((return_btype & this_name->unexpected_btypes) &&
Lv Zhengee387402015-12-29 13:58:02 +0800324 (this_name->package_index ==
325 ACPI_ALL_PACKAGE_ELEMENTS
326 || package_index == this_name->package_index)) {
Bob Moored5a36102013-03-08 09:23:03 +0000327 return (this_name);
328 }
329
330 return (NULL);
331 }
Bob Moore1fad8732015-12-29 13:54:36 +0800332
Bob Moored5a36102013-03-08 09:23:03 +0000333 this_name++;
334 }
335
336 return (NULL); /* Name was not found in the repair table */
337}
338
Bob Mooree5f69d62009-07-24 11:03:09 +0800339/*******************************************************************************
340 *
Bob Moore091f4d72010-01-21 09:28:32 +0800341 * FUNCTION: acpi_ns_repair_null_element
342 *
Bob Moore29a241c2013-05-30 10:00:01 +0800343 * PARAMETERS: info - Method execution information block
Bob Moore091f4d72010-01-21 09:28:32 +0800344 * expected_btypes - Object types expected
345 * package_index - Index of object within parent package (if
346 * applicable - ACPI_NOT_PACKAGE_ELEMENT
347 * otherwise)
348 * return_object_ptr - Pointer to the object returned from the
349 * evaluation of a method or object
350 *
351 * RETURN: Status. AE_OK if repair was successful.
352 *
353 * DESCRIPTION: Attempt to repair a NULL element of a returned Package object.
354 *
355 ******************************************************************************/
356
357acpi_status
Lv Zhengf5c1e1c2016-05-05 12:57:53 +0800358acpi_ns_repair_null_element(struct acpi_evaluate_info *info,
Bob Moore091f4d72010-01-21 09:28:32 +0800359 u32 expected_btypes,
360 u32 package_index,
361 union acpi_operand_object **return_object_ptr)
362{
363 union acpi_operand_object *return_object = *return_object_ptr;
364 union acpi_operand_object *new_object;
365
366 ACPI_FUNCTION_NAME(ns_repair_null_element);
367
368 /* No repair needed if return object is non-NULL */
369
370 if (return_object) {
371 return (AE_OK);
372 }
373
374 /*
375 * Attempt to repair a NULL element of a Package object. This applies to
376 * predefined names that return a fixed-length package and each element
377 * is required. It does not apply to variable-length packages where NULL
378 * elements are allowed, especially at the end of the package.
379 */
380 if (expected_btypes & ACPI_RTYPE_INTEGER) {
381
Bob Mooreba494be2012-07-12 09:40:10 +0800382 /* Need an integer - create a zero-value integer */
Bob Moore091f4d72010-01-21 09:28:32 +0800383
Bob Moore150dba32010-07-06 10:35:55 +0800384 new_object = acpi_ut_create_integer_object((u64)0);
Bob Moore091f4d72010-01-21 09:28:32 +0800385 } else if (expected_btypes & ACPI_RTYPE_STRING) {
386
Bob Mooreba494be2012-07-12 09:40:10 +0800387 /* Need a string - create a NULL string */
Bob Moore091f4d72010-01-21 09:28:32 +0800388
389 new_object = acpi_ut_create_string_object(0);
390 } else if (expected_btypes & ACPI_RTYPE_BUFFER) {
391
Bob Mooreba494be2012-07-12 09:40:10 +0800392 /* Need a buffer - create a zero-length buffer */
Bob Moore091f4d72010-01-21 09:28:32 +0800393
394 new_object = acpi_ut_create_buffer_object(0);
395 } else {
396 /* Error for all other expected types */
397
398 return (AE_AML_OPERAND_TYPE);
399 }
400
401 if (!new_object) {
402 return (AE_NO_MEMORY);
403 }
404
405 /* Set the reference count according to the parent Package object */
406
407 new_object->common.reference_count =
Bob Moore29a241c2013-05-30 10:00:01 +0800408 info->parent_package->common.reference_count;
Bob Moore091f4d72010-01-21 09:28:32 +0800409
410 ACPI_DEBUG_PRINT((ACPI_DB_REPAIR,
411 "%s: Converted NULL package element to expected %s at index %u\n",
Bob Moore29a241c2013-05-30 10:00:01 +0800412 info->full_pathname,
Bob Moore091f4d72010-01-21 09:28:32 +0800413 acpi_ut_get_object_type_name(new_object),
414 package_index));
415
416 *return_object_ptr = new_object;
Bob Moore29a241c2013-05-30 10:00:01 +0800417 info->return_flags |= ACPI_OBJECT_REPAIRED;
Bob Moore091f4d72010-01-21 09:28:32 +0800418 return (AE_OK);
419}
420
421/******************************************************************************
422 *
423 * FUNCTION: acpi_ns_remove_null_elements
424 *
Bob Moore29a241c2013-05-30 10:00:01 +0800425 * PARAMETERS: info - Method execution information block
Bob Moore091f4d72010-01-21 09:28:32 +0800426 * package_type - An acpi_return_package_types value
427 * obj_desc - A Package object
428 *
429 * RETURN: None.
430 *
431 * DESCRIPTION: Remove all NULL package elements from packages that contain
Bob Moore0a16d122014-02-26 10:31:18 +0800432 * a variable number of subpackages. For these types of
Bob Moore091f4d72010-01-21 09:28:32 +0800433 * packages, NULL elements can be safely removed.
434 *
435 *****************************************************************************/
436
437void
Bob Moore29a241c2013-05-30 10:00:01 +0800438acpi_ns_remove_null_elements(struct acpi_evaluate_info *info,
Bob Moore091f4d72010-01-21 09:28:32 +0800439 u8 package_type,
440 union acpi_operand_object *obj_desc)
441{
442 union acpi_operand_object **source;
443 union acpi_operand_object **dest;
444 u32 count;
445 u32 new_count;
446 u32 i;
447
448 ACPI_FUNCTION_NAME(ns_remove_null_elements);
449
450 /*
Bob Moore945488b2011-04-13 13:15:58 +0800451 * We can safely remove all NULL elements from these package types:
452 * PTYPE1_VAR packages contain a variable number of simple data types.
Bob Moore0a16d122014-02-26 10:31:18 +0800453 * PTYPE2 packages contain a variable number of subpackages.
Bob Moore091f4d72010-01-21 09:28:32 +0800454 */
455 switch (package_type) {
Bob Moore091f4d72010-01-21 09:28:32 +0800456 case ACPI_PTYPE1_VAR:
Bob Moore091f4d72010-01-21 09:28:32 +0800457 case ACPI_PTYPE2:
458 case ACPI_PTYPE2_COUNT:
459 case ACPI_PTYPE2_PKG_COUNT:
460 case ACPI_PTYPE2_FIXED:
461 case ACPI_PTYPE2_MIN:
462 case ACPI_PTYPE2_REV_FIXED:
Bob Moore7fce7a42011-11-16 14:59:17 +0800463 case ACPI_PTYPE2_FIX_VAR:
Bob Moore091f4d72010-01-21 09:28:32 +0800464 break;
465
466 default:
Bob Mooree34a7812015-05-21 10:30:18 +0800467 case ACPI_PTYPE2_VAR_VAR:
Bob Moore945488b2011-04-13 13:15:58 +0800468 case ACPI_PTYPE1_FIXED:
469 case ACPI_PTYPE1_OPTION:
Bob Moore091f4d72010-01-21 09:28:32 +0800470 return;
471 }
472
473 count = obj_desc->package.count;
474 new_count = count;
475
476 source = obj_desc->package.elements;
477 dest = source;
478
479 /* Examine all elements of the package object, remove nulls */
480
481 for (i = 0; i < count; i++) {
482 if (!*source) {
483 new_count--;
484 } else {
485 *dest = *source;
486 dest++;
487 }
Bob Moore1fad8732015-12-29 13:54:36 +0800488
Bob Moore091f4d72010-01-21 09:28:32 +0800489 source++;
490 }
491
492 /* Update parent package if any null elements were removed */
493
494 if (new_count < count) {
495 ACPI_DEBUG_PRINT((ACPI_DB_REPAIR,
496 "%s: Found and removed %u NULL elements\n",
Bob Moore29a241c2013-05-30 10:00:01 +0800497 info->full_pathname, (count - new_count)));
Bob Moore091f4d72010-01-21 09:28:32 +0800498
499 /* NULL terminate list and update the package count */
500
501 *dest = NULL;
502 obj_desc->package.count = new_count;
503 }
504}
505
506/*******************************************************************************
507 *
Bob Moore6a99b1c2012-03-21 09:51:39 +0800508 * FUNCTION: acpi_ns_wrap_with_package
Bob Mooree5f69d62009-07-24 11:03:09 +0800509 *
Bob Moore29a241c2013-05-30 10:00:01 +0800510 * PARAMETERS: info - Method execution information block
Bob Moore6a99b1c2012-03-21 09:51:39 +0800511 * original_object - Pointer to the object to repair.
512 * obj_desc_ptr - The new package object is returned here
Bob Mooree5f69d62009-07-24 11:03:09 +0800513 *
514 * RETURN: Status, new object in *obj_desc_ptr
515 *
Bob Moore6a99b1c2012-03-21 09:51:39 +0800516 * DESCRIPTION: Repair a common problem with objects that are defined to
517 * return a variable-length Package of sub-objects. If there is
518 * only one sub-object, some BIOS code mistakenly simply declares
519 * the single object instead of a Package with one sub-object.
520 * This function attempts to repair this error by wrapping a
521 * Package object around the original object, creating the
522 * correct and expected Package with one sub-object.
Bob Mooree5f69d62009-07-24 11:03:09 +0800523 *
524 * Names that can be repaired in this manner include:
Bob Moore6a99b1c2012-03-21 09:51:39 +0800525 * _ALR, _CSD, _HPX, _MLS, _PLD, _PRT, _PSS, _TRT, _TSS,
526 * _BCL, _DOD, _FIX, _Sx
Bob Mooree5f69d62009-07-24 11:03:09 +0800527 *
528 ******************************************************************************/
529
530acpi_status
Bob Moore29a241c2013-05-30 10:00:01 +0800531acpi_ns_wrap_with_package(struct acpi_evaluate_info *info,
Bob Moore6a99b1c2012-03-21 09:51:39 +0800532 union acpi_operand_object *original_object,
533 union acpi_operand_object **obj_desc_ptr)
Bob Mooree5f69d62009-07-24 11:03:09 +0800534{
535 union acpi_operand_object *pkg_obj_desc;
536
Bob Moore6a99b1c2012-03-21 09:51:39 +0800537 ACPI_FUNCTION_NAME(ns_wrap_with_package);
Bob Moore3a581762009-12-11 15:23:22 +0800538
Bob Mooree5f69d62009-07-24 11:03:09 +0800539 /*
Bob Moore1fad8732015-12-29 13:54:36 +0800540 * Create the new outer package and populate it. The new
541 * package will have a single element, the lone sub-object.
Bob Mooree5f69d62009-07-24 11:03:09 +0800542 */
543 pkg_obj_desc = acpi_ut_create_package_object(1);
544 if (!pkg_obj_desc) {
545 return (AE_NO_MEMORY);
546 }
547
Bob Moore6a99b1c2012-03-21 09:51:39 +0800548 pkg_obj_desc->package.elements[0] = original_object;
549
550 ACPI_DEBUG_PRINT((ACPI_DB_REPAIR,
551 "%s: Wrapped %s with expected Package object\n",
Bob Moore29a241c2013-05-30 10:00:01 +0800552 info->full_pathname,
Bob Moore6a99b1c2012-03-21 09:51:39 +0800553 acpi_ut_get_object_type_name(original_object)));
Bob Mooree5f69d62009-07-24 11:03:09 +0800554
555 /* Return the new object in the object pointer */
556
557 *obj_desc_ptr = pkg_obj_desc;
Bob Moore29a241c2013-05-30 10:00:01 +0800558 info->return_flags |= ACPI_OBJECT_REPAIRED | ACPI_OBJECT_WRAPPED;
Bob Mooree5f69d62009-07-24 11:03:09 +0800559 return (AE_OK);
560}