nsrepair.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814
  1. /******************************************************************************
  2. *
  3. * Module Name: nsrepair - Repair for objects returned by predefined methods
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2013, Intel Corp.
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions, and the following disclaimer,
  15. * without modification.
  16. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  17. * substantially similar to the "NO WARRANTY" disclaimer below
  18. * ("Disclaimer") and any redistribution must be conditioned upon
  19. * including a substantially similar Disclaimer requirement for further
  20. * binary redistribution.
  21. * 3. Neither the names of the above-listed copyright holders nor the names
  22. * of any contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * Alternatively, this software may be distributed under the terms of the
  26. * GNU General Public License ("GPL") version 2 as published by the Free
  27. * Software Foundation.
  28. *
  29. * NO WARRANTY
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  33. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  34. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  36. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  38. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  39. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  40. * POSSIBILITY OF SUCH DAMAGES.
  41. */
  42. #include <acpi/acpi.h>
  43. #include "accommon.h"
  44. #include "acnamesp.h"
  45. #include "acinterp.h"
  46. #include "acpredef.h"
  47. #include "amlresrc.h"
  48. #define _COMPONENT ACPI_NAMESPACE
  49. ACPI_MODULE_NAME("nsrepair")
  50. /*******************************************************************************
  51. *
  52. * This module attempts to repair or convert objects returned by the
  53. * predefined methods to an object type that is expected, as per the ACPI
  54. * specification. The need for this code is dictated by the many machines that
  55. * return incorrect types for the standard predefined methods. Performing these
  56. * conversions here, in one place, eliminates the need for individual ACPI
  57. * device drivers to do the same. Note: Most of these conversions are different
  58. * than the internal object conversion routines used for implicit object
  59. * conversion.
  60. *
  61. * The following conversions can be performed as necessary:
  62. *
  63. * Integer -> String
  64. * Integer -> Buffer
  65. * String -> Integer
  66. * String -> Buffer
  67. * Buffer -> Integer
  68. * Buffer -> String
  69. * Buffer -> Package of Integers
  70. * Package -> Package of one Package
  71. *
  72. * Additional conversions that are available:
  73. * Convert a null return or zero return value to an end_tag descriptor
  74. * Convert an ASCII string to a Unicode buffer
  75. *
  76. * An incorrect standalone object is wrapped with required outer package
  77. *
  78. * Additional possible repairs:
  79. * Required package elements that are NULL replaced by Integer/String/Buffer
  80. *
  81. ******************************************************************************/
  82. /* Local prototypes */
  83. static acpi_status
  84. acpi_ns_convert_to_integer(union acpi_operand_object *original_object,
  85. union acpi_operand_object **return_object);
  86. static acpi_status
  87. acpi_ns_convert_to_string(union acpi_operand_object *original_object,
  88. union acpi_operand_object **return_object);
  89. static acpi_status
  90. acpi_ns_convert_to_buffer(union acpi_operand_object *original_object,
  91. union acpi_operand_object **return_object);
  92. static const struct acpi_simple_repair_info *acpi_ns_match_simple_repair(struct
  93. acpi_namespace_node
  94. *node,
  95. u32
  96. return_btype,
  97. u32
  98. package_index);
  99. /*
  100. * Special but simple repairs for some names.
  101. *
  102. * 2nd argument: Unexpected types that can be repaired
  103. */
  104. static const struct acpi_simple_repair_info acpi_object_repair_info[] = {
  105. {{0, 0, 0, 0}, 0, 0, NULL} /* Table terminator */
  106. };
  107. /*******************************************************************************
  108. *
  109. * FUNCTION: acpi_ns_simple_repair
  110. *
  111. * PARAMETERS: data - Pointer to validation data structure
  112. * expected_btypes - Object types expected
  113. * package_index - Index of object within parent package (if
  114. * applicable - ACPI_NOT_PACKAGE_ELEMENT
  115. * otherwise)
  116. * return_object_ptr - Pointer to the object returned from the
  117. * evaluation of a method or object
  118. *
  119. * RETURN: Status. AE_OK if repair was successful.
  120. *
  121. * DESCRIPTION: Attempt to repair/convert a return object of a type that was
  122. * not expected.
  123. *
  124. ******************************************************************************/
  125. acpi_status
  126. acpi_ns_simple_repair(struct acpi_predefined_data *data,
  127. u32 expected_btypes,
  128. u32 package_index,
  129. union acpi_operand_object **return_object_ptr)
  130. {
  131. union acpi_operand_object *return_object = *return_object_ptr;
  132. union acpi_operand_object *new_object = NULL;
  133. acpi_status status;
  134. const struct acpi_simple_repair_info *predefined;
  135. ACPI_FUNCTION_NAME(ns_simple_repair);
  136. /*
  137. * Special repairs for certain names that are in the repair table.
  138. * Check if this name is in the list of repairable names.
  139. */
  140. predefined = acpi_ns_match_simple_repair(data->node,
  141. data->return_btype,
  142. package_index);
  143. if (predefined) {
  144. if (!return_object) {
  145. ACPI_WARN_PREDEFINED((AE_INFO, data->pathname,
  146. ACPI_WARN_ALWAYS,
  147. "Missing expected return value"));
  148. }
  149. status =
  150. predefined->object_converter(return_object, &new_object);
  151. if (ACPI_FAILURE(status)) {
  152. /* A fatal error occurred during a conversion */
  153. ACPI_EXCEPTION((AE_INFO, status,
  154. "During return object analysis"));
  155. return (status);
  156. }
  157. if (new_object) {
  158. goto object_repaired;
  159. }
  160. }
  161. /*
  162. * Do not perform simple object repair unless the return type is not
  163. * expected.
  164. */
  165. if (data->return_btype & expected_btypes) {
  166. return (AE_OK);
  167. }
  168. /*
  169. * At this point, we know that the type of the returned object was not
  170. * one of the expected types for this predefined name. Attempt to
  171. * repair the object by converting it to one of the expected object
  172. * types for this predefined name.
  173. */
  174. /*
  175. * If there is no return value, check if we require a return value for
  176. * this predefined name. Either one return value is expected, or none,
  177. * for both methods and other objects.
  178. *
  179. * Exit now if there is no return object. Warning if one was expected.
  180. */
  181. if (!return_object) {
  182. if (expected_btypes && (!(expected_btypes & ACPI_RTYPE_NONE))) {
  183. ACPI_WARN_PREDEFINED((AE_INFO, data->pathname,
  184. ACPI_WARN_ALWAYS,
  185. "Missing expected return value"));
  186. return (AE_AML_NO_RETURN_VALUE);
  187. }
  188. }
  189. if (expected_btypes & ACPI_RTYPE_INTEGER) {
  190. status = acpi_ns_convert_to_integer(return_object, &new_object);
  191. if (ACPI_SUCCESS(status)) {
  192. goto object_repaired;
  193. }
  194. }
  195. if (expected_btypes & ACPI_RTYPE_STRING) {
  196. status = acpi_ns_convert_to_string(return_object, &new_object);
  197. if (ACPI_SUCCESS(status)) {
  198. goto object_repaired;
  199. }
  200. }
  201. if (expected_btypes & ACPI_RTYPE_BUFFER) {
  202. status = acpi_ns_convert_to_buffer(return_object, &new_object);
  203. if (ACPI_SUCCESS(status)) {
  204. goto object_repaired;
  205. }
  206. }
  207. if (expected_btypes & ACPI_RTYPE_PACKAGE) {
  208. /*
  209. * A package is expected. We will wrap the existing object with a
  210. * new package object. It is often the case that if a variable-length
  211. * package is required, but there is only a single object needed, the
  212. * BIOS will return that object instead of wrapping it with a Package
  213. * object. Note: after the wrapping, the package will be validated
  214. * for correct contents (expected object type or types).
  215. */
  216. status =
  217. acpi_ns_wrap_with_package(data, return_object, &new_object);
  218. if (ACPI_SUCCESS(status)) {
  219. /*
  220. * The original object just had its reference count
  221. * incremented for being inserted into the new package.
  222. */
  223. *return_object_ptr = new_object; /* New Package object */
  224. data->flags |= ACPI_OBJECT_REPAIRED;
  225. return (AE_OK);
  226. }
  227. }
  228. /* We cannot repair this object */
  229. return (AE_AML_OPERAND_TYPE);
  230. object_repaired:
  231. /* Object was successfully repaired */
  232. if (package_index != ACPI_NOT_PACKAGE_ELEMENT) {
  233. /*
  234. * The original object is a package element. We need to
  235. * decrement the reference count of the original object,
  236. * for removing it from the package.
  237. *
  238. * However, if the original object was just wrapped with a
  239. * package object as part of the repair, we don't need to
  240. * change the reference count.
  241. */
  242. if (!(data->flags & ACPI_OBJECT_WRAPPED)) {
  243. new_object->common.reference_count =
  244. return_object->common.reference_count;
  245. if (return_object->common.reference_count > 1) {
  246. return_object->common.reference_count--;
  247. }
  248. }
  249. ACPI_DEBUG_PRINT((ACPI_DB_REPAIR,
  250. "%s: Converted %s to expected %s at Package index %u\n",
  251. data->pathname,
  252. acpi_ut_get_object_type_name(return_object),
  253. acpi_ut_get_object_type_name(new_object),
  254. package_index));
  255. } else {
  256. ACPI_DEBUG_PRINT((ACPI_DB_REPAIR,
  257. "%s: Converted %s to expected %s\n",
  258. data->pathname,
  259. acpi_ut_get_object_type_name(return_object),
  260. acpi_ut_get_object_type_name(new_object)));
  261. }
  262. /* Delete old object, install the new return object */
  263. acpi_ut_remove_reference(return_object);
  264. *return_object_ptr = new_object;
  265. data->flags |= ACPI_OBJECT_REPAIRED;
  266. return (AE_OK);
  267. }
  268. /******************************************************************************
  269. *
  270. * FUNCTION: acpi_ns_match_simple_repair
  271. *
  272. * PARAMETERS: node - Namespace node for the method/object
  273. * return_btype - Object type that was returned
  274. * package_index - Index of object within parent package (if
  275. * applicable - ACPI_NOT_PACKAGE_ELEMENT
  276. * otherwise)
  277. *
  278. * RETURN: Pointer to entry in repair table. NULL indicates not found.
  279. *
  280. * DESCRIPTION: Check an object name against the repairable object list.
  281. *
  282. *****************************************************************************/
  283. static const struct acpi_simple_repair_info *acpi_ns_match_simple_repair(struct
  284. acpi_namespace_node
  285. *node,
  286. u32
  287. return_btype,
  288. u32
  289. package_index)
  290. {
  291. const struct acpi_simple_repair_info *this_name;
  292. /* Search info table for a repairable predefined method/object name */
  293. this_name = acpi_object_repair_info;
  294. while (this_name->object_converter) {
  295. if (ACPI_COMPARE_NAME(node->name.ascii, this_name->name)) {
  296. /* Check if we can actually repair this name/type combination */
  297. if ((return_btype & this_name->unexpected_btypes) &&
  298. (package_index == this_name->package_index)) {
  299. return (this_name);
  300. }
  301. return (NULL);
  302. }
  303. this_name++;
  304. }
  305. return (NULL); /* Name was not found in the repair table */
  306. }
  307. /*******************************************************************************
  308. *
  309. * FUNCTION: acpi_ns_convert_to_integer
  310. *
  311. * PARAMETERS: original_object - Object to be converted
  312. * return_object - Where the new converted object is returned
  313. *
  314. * RETURN: Status. AE_OK if conversion was successful.
  315. *
  316. * DESCRIPTION: Attempt to convert a String/Buffer object to an Integer.
  317. *
  318. ******************************************************************************/
  319. static acpi_status
  320. acpi_ns_convert_to_integer(union acpi_operand_object *original_object,
  321. union acpi_operand_object **return_object)
  322. {
  323. union acpi_operand_object *new_object;
  324. acpi_status status;
  325. u64 value = 0;
  326. u32 i;
  327. switch (original_object->common.type) {
  328. case ACPI_TYPE_STRING:
  329. /* String-to-Integer conversion */
  330. status = acpi_ut_strtoul64(original_object->string.pointer,
  331. ACPI_ANY_BASE, &value);
  332. if (ACPI_FAILURE(status)) {
  333. return (status);
  334. }
  335. break;
  336. case ACPI_TYPE_BUFFER:
  337. /* Buffer-to-Integer conversion. Max buffer size is 64 bits. */
  338. if (original_object->buffer.length > 8) {
  339. return (AE_AML_OPERAND_TYPE);
  340. }
  341. /* Extract each buffer byte to create the integer */
  342. for (i = 0; i < original_object->buffer.length; i++) {
  343. value |=
  344. ((u64) original_object->buffer.
  345. pointer[i] << (i * 8));
  346. }
  347. break;
  348. default:
  349. return (AE_AML_OPERAND_TYPE);
  350. }
  351. new_object = acpi_ut_create_integer_object(value);
  352. if (!new_object) {
  353. return (AE_NO_MEMORY);
  354. }
  355. *return_object = new_object;
  356. return (AE_OK);
  357. }
  358. /*******************************************************************************
  359. *
  360. * FUNCTION: acpi_ns_convert_to_string
  361. *
  362. * PARAMETERS: original_object - Object to be converted
  363. * return_object - Where the new converted object is returned
  364. *
  365. * RETURN: Status. AE_OK if conversion was successful.
  366. *
  367. * DESCRIPTION: Attempt to convert a Integer/Buffer object to a String.
  368. *
  369. ******************************************************************************/
  370. static acpi_status
  371. acpi_ns_convert_to_string(union acpi_operand_object *original_object,
  372. union acpi_operand_object **return_object)
  373. {
  374. union acpi_operand_object *new_object;
  375. acpi_size length;
  376. acpi_status status;
  377. switch (original_object->common.type) {
  378. case ACPI_TYPE_INTEGER:
  379. /*
  380. * Integer-to-String conversion. Commonly, convert
  381. * an integer of value 0 to a NULL string. The last element of
  382. * _BIF and _BIX packages occasionally need this fix.
  383. */
  384. if (original_object->integer.value == 0) {
  385. /* Allocate a new NULL string object */
  386. new_object = acpi_ut_create_string_object(0);
  387. if (!new_object) {
  388. return (AE_NO_MEMORY);
  389. }
  390. } else {
  391. status =
  392. acpi_ex_convert_to_string(original_object,
  393. &new_object,
  394. ACPI_IMPLICIT_CONVERT_HEX);
  395. if (ACPI_FAILURE(status)) {
  396. return (status);
  397. }
  398. }
  399. break;
  400. case ACPI_TYPE_BUFFER:
  401. /*
  402. * Buffer-to-String conversion. Use a to_string
  403. * conversion, no transform performed on the buffer data. The best
  404. * example of this is the _BIF method, where the string data from
  405. * the battery is often (incorrectly) returned as buffer object(s).
  406. */
  407. length = 0;
  408. while ((length < original_object->buffer.length) &&
  409. (original_object->buffer.pointer[length])) {
  410. length++;
  411. }
  412. /* Allocate a new string object */
  413. new_object = acpi_ut_create_string_object(length);
  414. if (!new_object) {
  415. return (AE_NO_MEMORY);
  416. }
  417. /*
  418. * Copy the raw buffer data with no transform. String is already NULL
  419. * terminated at Length+1.
  420. */
  421. ACPI_MEMCPY(new_object->string.pointer,
  422. original_object->buffer.pointer, length);
  423. break;
  424. default:
  425. return (AE_AML_OPERAND_TYPE);
  426. }
  427. *return_object = new_object;
  428. return (AE_OK);
  429. }
  430. /*******************************************************************************
  431. *
  432. * FUNCTION: acpi_ns_convert_to_buffer
  433. *
  434. * PARAMETERS: original_object - Object to be converted
  435. * return_object - Where the new converted object is returned
  436. *
  437. * RETURN: Status. AE_OK if conversion was successful.
  438. *
  439. * DESCRIPTION: Attempt to convert a Integer/String/Package object to a Buffer.
  440. *
  441. ******************************************************************************/
  442. static acpi_status
  443. acpi_ns_convert_to_buffer(union acpi_operand_object *original_object,
  444. union acpi_operand_object **return_object)
  445. {
  446. union acpi_operand_object *new_object;
  447. acpi_status status;
  448. union acpi_operand_object **elements;
  449. u32 *dword_buffer;
  450. u32 count;
  451. u32 i;
  452. switch (original_object->common.type) {
  453. case ACPI_TYPE_INTEGER:
  454. /*
  455. * Integer-to-Buffer conversion.
  456. * Convert the Integer to a packed-byte buffer. _MAT and other
  457. * objects need this sometimes, if a read has been performed on a
  458. * Field object that is less than or equal to the global integer
  459. * size (32 or 64 bits).
  460. */
  461. status =
  462. acpi_ex_convert_to_buffer(original_object, &new_object);
  463. if (ACPI_FAILURE(status)) {
  464. return (status);
  465. }
  466. break;
  467. case ACPI_TYPE_STRING:
  468. /* String-to-Buffer conversion. Simple data copy */
  469. new_object =
  470. acpi_ut_create_buffer_object(original_object->string.
  471. length);
  472. if (!new_object) {
  473. return (AE_NO_MEMORY);
  474. }
  475. ACPI_MEMCPY(new_object->buffer.pointer,
  476. original_object->string.pointer,
  477. original_object->string.length);
  478. break;
  479. case ACPI_TYPE_PACKAGE:
  480. /*
  481. * This case is often seen for predefined names that must return a
  482. * Buffer object with multiple DWORD integers within. For example,
  483. * _FDE and _GTM. The Package can be converted to a Buffer.
  484. */
  485. /* All elements of the Package must be integers */
  486. elements = original_object->package.elements;
  487. count = original_object->package.count;
  488. for (i = 0; i < count; i++) {
  489. if ((!*elements) ||
  490. ((*elements)->common.type != ACPI_TYPE_INTEGER)) {
  491. return (AE_AML_OPERAND_TYPE);
  492. }
  493. elements++;
  494. }
  495. /* Create the new buffer object to replace the Package */
  496. new_object = acpi_ut_create_buffer_object(ACPI_MUL_4(count));
  497. if (!new_object) {
  498. return (AE_NO_MEMORY);
  499. }
  500. /* Copy the package elements (integers) to the buffer as DWORDs */
  501. elements = original_object->package.elements;
  502. dword_buffer = ACPI_CAST_PTR(u32, new_object->buffer.pointer);
  503. for (i = 0; i < count; i++) {
  504. *dword_buffer = (u32) (*elements)->integer.value;
  505. dword_buffer++;
  506. elements++;
  507. }
  508. break;
  509. default:
  510. return (AE_AML_OPERAND_TYPE);
  511. }
  512. *return_object = new_object;
  513. return (AE_OK);
  514. }
  515. /*******************************************************************************
  516. *
  517. * FUNCTION: acpi_ns_repair_null_element
  518. *
  519. * PARAMETERS: data - Pointer to validation data structure
  520. * expected_btypes - Object types expected
  521. * package_index - Index of object within parent package (if
  522. * applicable - ACPI_NOT_PACKAGE_ELEMENT
  523. * otherwise)
  524. * return_object_ptr - Pointer to the object returned from the
  525. * evaluation of a method or object
  526. *
  527. * RETURN: Status. AE_OK if repair was successful.
  528. *
  529. * DESCRIPTION: Attempt to repair a NULL element of a returned Package object.
  530. *
  531. ******************************************************************************/
  532. acpi_status
  533. acpi_ns_repair_null_element(struct acpi_predefined_data *data,
  534. u32 expected_btypes,
  535. u32 package_index,
  536. union acpi_operand_object **return_object_ptr)
  537. {
  538. union acpi_operand_object *return_object = *return_object_ptr;
  539. union acpi_operand_object *new_object;
  540. ACPI_FUNCTION_NAME(ns_repair_null_element);
  541. /* No repair needed if return object is non-NULL */
  542. if (return_object) {
  543. return (AE_OK);
  544. }
  545. /*
  546. * Attempt to repair a NULL element of a Package object. This applies to
  547. * predefined names that return a fixed-length package and each element
  548. * is required. It does not apply to variable-length packages where NULL
  549. * elements are allowed, especially at the end of the package.
  550. */
  551. if (expected_btypes & ACPI_RTYPE_INTEGER) {
  552. /* Need an integer - create a zero-value integer */
  553. new_object = acpi_ut_create_integer_object((u64)0);
  554. } else if (expected_btypes & ACPI_RTYPE_STRING) {
  555. /* Need a string - create a NULL string */
  556. new_object = acpi_ut_create_string_object(0);
  557. } else if (expected_btypes & ACPI_RTYPE_BUFFER) {
  558. /* Need a buffer - create a zero-length buffer */
  559. new_object = acpi_ut_create_buffer_object(0);
  560. } else {
  561. /* Error for all other expected types */
  562. return (AE_AML_OPERAND_TYPE);
  563. }
  564. if (!new_object) {
  565. return (AE_NO_MEMORY);
  566. }
  567. /* Set the reference count according to the parent Package object */
  568. new_object->common.reference_count =
  569. data->parent_package->common.reference_count;
  570. ACPI_DEBUG_PRINT((ACPI_DB_REPAIR,
  571. "%s: Converted NULL package element to expected %s at index %u\n",
  572. data->pathname,
  573. acpi_ut_get_object_type_name(new_object),
  574. package_index));
  575. *return_object_ptr = new_object;
  576. data->flags |= ACPI_OBJECT_REPAIRED;
  577. return (AE_OK);
  578. }
  579. /******************************************************************************
  580. *
  581. * FUNCTION: acpi_ns_remove_null_elements
  582. *
  583. * PARAMETERS: data - Pointer to validation data structure
  584. * package_type - An acpi_return_package_types value
  585. * obj_desc - A Package object
  586. *
  587. * RETURN: None.
  588. *
  589. * DESCRIPTION: Remove all NULL package elements from packages that contain
  590. * a variable number of sub-packages. For these types of
  591. * packages, NULL elements can be safely removed.
  592. *
  593. *****************************************************************************/
  594. void
  595. acpi_ns_remove_null_elements(struct acpi_predefined_data *data,
  596. u8 package_type,
  597. union acpi_operand_object *obj_desc)
  598. {
  599. union acpi_operand_object **source;
  600. union acpi_operand_object **dest;
  601. u32 count;
  602. u32 new_count;
  603. u32 i;
  604. ACPI_FUNCTION_NAME(ns_remove_null_elements);
  605. /*
  606. * We can safely remove all NULL elements from these package types:
  607. * PTYPE1_VAR packages contain a variable number of simple data types.
  608. * PTYPE2 packages contain a variable number of sub-packages.
  609. */
  610. switch (package_type) {
  611. case ACPI_PTYPE1_VAR:
  612. case ACPI_PTYPE2:
  613. case ACPI_PTYPE2_COUNT:
  614. case ACPI_PTYPE2_PKG_COUNT:
  615. case ACPI_PTYPE2_FIXED:
  616. case ACPI_PTYPE2_MIN:
  617. case ACPI_PTYPE2_REV_FIXED:
  618. case ACPI_PTYPE2_FIX_VAR:
  619. break;
  620. default:
  621. case ACPI_PTYPE1_FIXED:
  622. case ACPI_PTYPE1_OPTION:
  623. return;
  624. }
  625. count = obj_desc->package.count;
  626. new_count = count;
  627. source = obj_desc->package.elements;
  628. dest = source;
  629. /* Examine all elements of the package object, remove nulls */
  630. for (i = 0; i < count; i++) {
  631. if (!*source) {
  632. new_count--;
  633. } else {
  634. *dest = *source;
  635. dest++;
  636. }
  637. source++;
  638. }
  639. /* Update parent package if any null elements were removed */
  640. if (new_count < count) {
  641. ACPI_DEBUG_PRINT((ACPI_DB_REPAIR,
  642. "%s: Found and removed %u NULL elements\n",
  643. data->pathname, (count - new_count)));
  644. /* NULL terminate list and update the package count */
  645. *dest = NULL;
  646. obj_desc->package.count = new_count;
  647. }
  648. }
  649. /*******************************************************************************
  650. *
  651. * FUNCTION: acpi_ns_wrap_with_package
  652. *
  653. * PARAMETERS: data - Pointer to validation data structure
  654. * original_object - Pointer to the object to repair.
  655. * obj_desc_ptr - The new package object is returned here
  656. *
  657. * RETURN: Status, new object in *obj_desc_ptr
  658. *
  659. * DESCRIPTION: Repair a common problem with objects that are defined to
  660. * return a variable-length Package of sub-objects. If there is
  661. * only one sub-object, some BIOS code mistakenly simply declares
  662. * the single object instead of a Package with one sub-object.
  663. * This function attempts to repair this error by wrapping a
  664. * Package object around the original object, creating the
  665. * correct and expected Package with one sub-object.
  666. *
  667. * Names that can be repaired in this manner include:
  668. * _ALR, _CSD, _HPX, _MLS, _PLD, _PRT, _PSS, _TRT, _TSS,
  669. * _BCL, _DOD, _FIX, _Sx
  670. *
  671. ******************************************************************************/
  672. acpi_status
  673. acpi_ns_wrap_with_package(struct acpi_predefined_data *data,
  674. union acpi_operand_object *original_object,
  675. union acpi_operand_object **obj_desc_ptr)
  676. {
  677. union acpi_operand_object *pkg_obj_desc;
  678. ACPI_FUNCTION_NAME(ns_wrap_with_package);
  679. /*
  680. * Create the new outer package and populate it. The new package will
  681. * have a single element, the lone sub-object.
  682. */
  683. pkg_obj_desc = acpi_ut_create_package_object(1);
  684. if (!pkg_obj_desc) {
  685. return (AE_NO_MEMORY);
  686. }
  687. pkg_obj_desc->package.elements[0] = original_object;
  688. ACPI_DEBUG_PRINT((ACPI_DB_REPAIR,
  689. "%s: Wrapped %s with expected Package object\n",
  690. data->pathname,
  691. acpi_ut_get_object_type_name(original_object)));
  692. /* Return the new object in the object pointer */
  693. *obj_desc_ptr = pkg_obj_desc;
  694. data->flags |= ACPI_OBJECT_REPAIRED | ACPI_OBJECT_WRAPPED;
  695. return (AE_OK);
  696. }