utmisc.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972
  1. /*******************************************************************************
  2. *
  3. * Module Name: utmisc - common utility procedures
  4. *
  5. ******************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2005, R. Byron Moore
  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 <acpi/acnamesp.h>
  44. #define _COMPONENT ACPI_UTILITIES
  45. ACPI_MODULE_NAME ("utmisc")
  46. /*******************************************************************************
  47. *
  48. * FUNCTION: acpi_ut_allocate_owner_id
  49. *
  50. * PARAMETERS: owner_id - Where the new owner ID is returned
  51. *
  52. * RETURN: Status
  53. *
  54. * DESCRIPTION: Allocate a table or method owner ID. The owner ID is used to
  55. * track objects created by the table or method, to be deleted
  56. * when the method exits or the table is unloaded.
  57. *
  58. ******************************************************************************/
  59. acpi_status
  60. acpi_ut_allocate_owner_id (
  61. acpi_owner_id *owner_id)
  62. {
  63. acpi_native_uint i;
  64. acpi_status status;
  65. ACPI_FUNCTION_TRACE ("ut_allocate_owner_id");
  66. /* Mutex for the global ID mask */
  67. status = acpi_ut_acquire_mutex (ACPI_MTX_CACHES);
  68. if (ACPI_FAILURE (status)) {
  69. return_ACPI_STATUS (status);
  70. }
  71. /* Find a free owner ID */
  72. for (i = 0; i < 32; i++) {
  73. if (!(acpi_gbl_owner_id_mask & (1 << i))) {
  74. acpi_gbl_owner_id_mask |= (1 << i);
  75. *owner_id = (acpi_owner_id) (i + 1);
  76. goto exit;
  77. }
  78. }
  79. /*
  80. * If we are here, all owner_ids have been allocated. This probably should
  81. * not happen since the IDs are reused after deallocation. The IDs are
  82. * allocated upon table load (one per table) and method execution, and
  83. * they are released when a table is unloaded or a method completes
  84. * execution.
  85. */
  86. *owner_id = 0;
  87. status = AE_OWNER_ID_LIMIT;
  88. ACPI_REPORT_ERROR ((
  89. "Could not allocate new owner_id (32 max), AE_OWNER_ID_LIMIT\n"));
  90. exit:
  91. (void) acpi_ut_release_mutex (ACPI_MTX_CACHES);
  92. return_ACPI_STATUS (status);
  93. }
  94. /*******************************************************************************
  95. *
  96. * FUNCTION: acpi_ut_release_owner_id
  97. *
  98. * PARAMETERS: owner_id_ptr - Pointer to a previously allocated owner_iD
  99. *
  100. * RETURN: None. No error is returned because we are either exiting a
  101. * control method or unloading a table. Either way, we would
  102. * ignore any error anyway.
  103. *
  104. * DESCRIPTION: Release a table or method owner ID. Valid IDs are 1 - 32
  105. *
  106. ******************************************************************************/
  107. void
  108. acpi_ut_release_owner_id (
  109. acpi_owner_id *owner_id_ptr)
  110. {
  111. acpi_owner_id owner_id = *owner_id_ptr;
  112. acpi_status status;
  113. ACPI_FUNCTION_TRACE ("ut_release_owner_id");
  114. /* Always clear the input owner_id (zero is an invalid ID) */
  115. *owner_id_ptr = 0;
  116. /* Zero is not a valid owner_iD */
  117. if ((owner_id == 0) || (owner_id > 32)) {
  118. ACPI_REPORT_ERROR (("Invalid owner_id: %2.2X\n", owner_id));
  119. return_VOID;
  120. }
  121. /* Mutex for the global ID mask */
  122. status = acpi_ut_acquire_mutex (ACPI_MTX_CACHES);
  123. if (ACPI_FAILURE (status)) {
  124. return_VOID;
  125. }
  126. owner_id--; /* Normalize to zero */
  127. /* Free the owner ID only if it is valid */
  128. if (acpi_gbl_owner_id_mask & (1 << owner_id)) {
  129. acpi_gbl_owner_id_mask ^= (1 << owner_id);
  130. }
  131. (void) acpi_ut_release_mutex (ACPI_MTX_CACHES);
  132. return_VOID;
  133. }
  134. /*******************************************************************************
  135. *
  136. * FUNCTION: acpi_ut_strupr (strupr)
  137. *
  138. * PARAMETERS: src_string - The source string to convert
  139. *
  140. * RETURN: None
  141. *
  142. * DESCRIPTION: Convert string to uppercase
  143. *
  144. * NOTE: This is not a POSIX function, so it appears here, not in utclib.c
  145. *
  146. ******************************************************************************/
  147. void
  148. acpi_ut_strupr (
  149. char *src_string)
  150. {
  151. char *string;
  152. ACPI_FUNCTION_ENTRY ();
  153. if (!src_string) {
  154. return;
  155. }
  156. /* Walk entire string, uppercasing the letters */
  157. for (string = src_string; *string; string++) {
  158. *string = (char) ACPI_TOUPPER (*string);
  159. }
  160. return;
  161. }
  162. /*******************************************************************************
  163. *
  164. * FUNCTION: acpi_ut_print_string
  165. *
  166. * PARAMETERS: String - Null terminated ASCII string
  167. * max_length - Maximum output length
  168. *
  169. * RETURN: None
  170. *
  171. * DESCRIPTION: Dump an ASCII string with support for ACPI-defined escape
  172. * sequences.
  173. *
  174. ******************************************************************************/
  175. void
  176. acpi_ut_print_string (
  177. char *string,
  178. u8 max_length)
  179. {
  180. u32 i;
  181. if (!string) {
  182. acpi_os_printf ("<\"NULL STRING PTR\">");
  183. return;
  184. }
  185. acpi_os_printf ("\"");
  186. for (i = 0; string[i] && (i < max_length); i++) {
  187. /* Escape sequences */
  188. switch (string[i]) {
  189. case 0x07:
  190. acpi_os_printf ("\\a"); /* BELL */
  191. break;
  192. case 0x08:
  193. acpi_os_printf ("\\b"); /* BACKSPACE */
  194. break;
  195. case 0x0C:
  196. acpi_os_printf ("\\f"); /* FORMFEED */
  197. break;
  198. case 0x0A:
  199. acpi_os_printf ("\\n"); /* LINEFEED */
  200. break;
  201. case 0x0D:
  202. acpi_os_printf ("\\r"); /* CARRIAGE RETURN*/
  203. break;
  204. case 0x09:
  205. acpi_os_printf ("\\t"); /* HORIZONTAL TAB */
  206. break;
  207. case 0x0B:
  208. acpi_os_printf ("\\v"); /* VERTICAL TAB */
  209. break;
  210. case '\'': /* Single Quote */
  211. case '\"': /* Double Quote */
  212. case '\\': /* Backslash */
  213. acpi_os_printf ("\\%c", (int) string[i]);
  214. break;
  215. default:
  216. /* Check for printable character or hex escape */
  217. if (ACPI_IS_PRINT (string[i]))
  218. {
  219. /* This is a normal character */
  220. acpi_os_printf ("%c", (int) string[i]);
  221. }
  222. else
  223. {
  224. /* All others will be Hex escapes */
  225. acpi_os_printf ("\\x%2.2X", (s32) string[i]);
  226. }
  227. break;
  228. }
  229. }
  230. acpi_os_printf ("\"");
  231. if (i == max_length && string[i]) {
  232. acpi_os_printf ("...");
  233. }
  234. }
  235. /*******************************************************************************
  236. *
  237. * FUNCTION: acpi_ut_dword_byte_swap
  238. *
  239. * PARAMETERS: Value - Value to be converted
  240. *
  241. * RETURN: u32 integer with bytes swapped
  242. *
  243. * DESCRIPTION: Convert a 32-bit value to big-endian (swap the bytes)
  244. *
  245. ******************************************************************************/
  246. u32
  247. acpi_ut_dword_byte_swap (
  248. u32 value)
  249. {
  250. union {
  251. u32 value;
  252. u8 bytes[4];
  253. } out;
  254. union {
  255. u32 value;
  256. u8 bytes[4];
  257. } in;
  258. ACPI_FUNCTION_ENTRY ();
  259. in.value = value;
  260. out.bytes[0] = in.bytes[3];
  261. out.bytes[1] = in.bytes[2];
  262. out.bytes[2] = in.bytes[1];
  263. out.bytes[3] = in.bytes[0];
  264. return (out.value);
  265. }
  266. /*******************************************************************************
  267. *
  268. * FUNCTION: acpi_ut_set_integer_width
  269. *
  270. * PARAMETERS: Revision From DSDT header
  271. *
  272. * RETURN: None
  273. *
  274. * DESCRIPTION: Set the global integer bit width based upon the revision
  275. * of the DSDT. For Revision 1 and 0, Integers are 32 bits.
  276. * For Revision 2 and above, Integers are 64 bits. Yes, this
  277. * makes a difference.
  278. *
  279. ******************************************************************************/
  280. void
  281. acpi_ut_set_integer_width (
  282. u8 revision)
  283. {
  284. if (revision <= 1) {
  285. acpi_gbl_integer_bit_width = 32;
  286. acpi_gbl_integer_nybble_width = 8;
  287. acpi_gbl_integer_byte_width = 4;
  288. }
  289. else {
  290. acpi_gbl_integer_bit_width = 64;
  291. acpi_gbl_integer_nybble_width = 16;
  292. acpi_gbl_integer_byte_width = 8;
  293. }
  294. }
  295. #ifdef ACPI_DEBUG_OUTPUT
  296. /*******************************************************************************
  297. *
  298. * FUNCTION: acpi_ut_display_init_pathname
  299. *
  300. * PARAMETERS: Type - Object type of the node
  301. * obj_handle - Handle whose pathname will be displayed
  302. * Path - Additional path string to be appended.
  303. * (NULL if no extra path)
  304. *
  305. * RETURN: acpi_status
  306. *
  307. * DESCRIPTION: Display full pathname of an object, DEBUG ONLY
  308. *
  309. ******************************************************************************/
  310. void
  311. acpi_ut_display_init_pathname (
  312. u8 type,
  313. struct acpi_namespace_node *obj_handle,
  314. char *path)
  315. {
  316. acpi_status status;
  317. struct acpi_buffer buffer;
  318. ACPI_FUNCTION_ENTRY ();
  319. /* Only print the path if the appropriate debug level is enabled */
  320. if (!(acpi_dbg_level & ACPI_LV_INIT_NAMES)) {
  321. return;
  322. }
  323. /* Get the full pathname to the node */
  324. buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER;
  325. status = acpi_ns_handle_to_pathname (obj_handle, &buffer);
  326. if (ACPI_FAILURE (status)) {
  327. return;
  328. }
  329. /* Print what we're doing */
  330. switch (type) {
  331. case ACPI_TYPE_METHOD:
  332. acpi_os_printf ("Executing ");
  333. break;
  334. default:
  335. acpi_os_printf ("Initializing ");
  336. break;
  337. }
  338. /* Print the object type and pathname */
  339. acpi_os_printf ("%-12s %s",
  340. acpi_ut_get_type_name (type), (char *) buffer.pointer);
  341. /* Extra path is used to append names like _STA, _INI, etc. */
  342. if (path) {
  343. acpi_os_printf (".%s", path);
  344. }
  345. acpi_os_printf ("\n");
  346. ACPI_MEM_FREE (buffer.pointer);
  347. }
  348. #endif
  349. /*******************************************************************************
  350. *
  351. * FUNCTION: acpi_ut_valid_acpi_name
  352. *
  353. * PARAMETERS: Name - The name to be examined
  354. *
  355. * RETURN: TRUE if the name is valid, FALSE otherwise
  356. *
  357. * DESCRIPTION: Check for a valid ACPI name. Each character must be one of:
  358. * 1) Upper case alpha
  359. * 2) numeric
  360. * 3) underscore
  361. *
  362. ******************************************************************************/
  363. u8
  364. acpi_ut_valid_acpi_name (
  365. u32 name)
  366. {
  367. char *name_ptr = (char *) &name;
  368. char character;
  369. acpi_native_uint i;
  370. ACPI_FUNCTION_ENTRY ();
  371. for (i = 0; i < ACPI_NAME_SIZE; i++) {
  372. character = *name_ptr;
  373. name_ptr++;
  374. if (!((character == '_') ||
  375. (character >= 'A' && character <= 'Z') ||
  376. (character >= '0' && character <= '9'))) {
  377. return (FALSE);
  378. }
  379. }
  380. return (TRUE);
  381. }
  382. /*******************************************************************************
  383. *
  384. * FUNCTION: acpi_ut_valid_acpi_character
  385. *
  386. * PARAMETERS: Character - The character to be examined
  387. *
  388. * RETURN: 1 if Character may appear in a name, else 0
  389. *
  390. * DESCRIPTION: Check for a printable character
  391. *
  392. ******************************************************************************/
  393. u8
  394. acpi_ut_valid_acpi_character (
  395. char character)
  396. {
  397. ACPI_FUNCTION_ENTRY ();
  398. return ((u8) ((character == '_') ||
  399. (character >= 'A' && character <= 'Z') ||
  400. (character >= '0' && character <= '9')));
  401. }
  402. /*******************************************************************************
  403. *
  404. * FUNCTION: acpi_ut_strtoul64
  405. *
  406. * PARAMETERS: String - Null terminated string
  407. * Base - Radix of the string: 10, 16, or ACPI_ANY_BASE
  408. * ret_integer - Where the converted integer is returned
  409. *
  410. * RETURN: Status and Converted value
  411. *
  412. * DESCRIPTION: Convert a string into an unsigned value.
  413. * NOTE: Does not support Octal strings, not needed.
  414. *
  415. ******************************************************************************/
  416. acpi_status
  417. acpi_ut_strtoul64 (
  418. char *string,
  419. u32 base,
  420. acpi_integer *ret_integer)
  421. {
  422. u32 this_digit = 0;
  423. acpi_integer return_value = 0;
  424. acpi_integer quotient;
  425. ACPI_FUNCTION_TRACE ("ut_stroul64");
  426. if ((!string) || !(*string)) {
  427. goto error_exit;
  428. }
  429. switch (base) {
  430. case ACPI_ANY_BASE:
  431. case 10:
  432. case 16:
  433. break;
  434. default:
  435. /* Invalid Base */
  436. return_ACPI_STATUS (AE_BAD_PARAMETER);
  437. }
  438. /* Skip over any white space in the buffer */
  439. while (ACPI_IS_SPACE (*string) || *string == '\t') {
  440. string++;
  441. }
  442. /*
  443. * If the input parameter Base is zero, then we need to
  444. * determine if it is decimal or hexadecimal:
  445. */
  446. if (base == 0) {
  447. if ((*string == '0') &&
  448. (ACPI_TOLOWER (*(string + 1)) == 'x')) {
  449. base = 16;
  450. string += 2;
  451. }
  452. else {
  453. base = 10;
  454. }
  455. }
  456. /*
  457. * For hexadecimal base, skip over the leading
  458. * 0 or 0x, if they are present.
  459. */
  460. if ((base == 16) &&
  461. (*string == '0') &&
  462. (ACPI_TOLOWER (*(string + 1)) == 'x')) {
  463. string += 2;
  464. }
  465. /* Any string left? */
  466. if (!(*string)) {
  467. goto error_exit;
  468. }
  469. /* Main loop: convert the string to a 64-bit integer */
  470. while (*string) {
  471. if (ACPI_IS_DIGIT (*string)) {
  472. /* Convert ASCII 0-9 to Decimal value */
  473. this_digit = ((u8) *string) - '0';
  474. }
  475. else {
  476. if (base == 10) {
  477. /* Digit is out of range */
  478. goto error_exit;
  479. }
  480. this_digit = (u8) ACPI_TOUPPER (*string);
  481. if (ACPI_IS_XDIGIT ((char) this_digit)) {
  482. /* Convert ASCII Hex char to value */
  483. this_digit = this_digit - 'A' + 10;
  484. }
  485. else {
  486. /*
  487. * We allow non-hex chars, just stop now, same as end-of-string.
  488. * See ACPI spec, string-to-integer conversion.
  489. */
  490. break;
  491. }
  492. }
  493. /* Divide the digit into the correct position */
  494. (void) acpi_ut_short_divide ((ACPI_INTEGER_MAX - (acpi_integer) this_digit),
  495. base, &quotient, NULL);
  496. if (return_value > quotient) {
  497. goto error_exit;
  498. }
  499. return_value *= base;
  500. return_value += this_digit;
  501. string++;
  502. }
  503. /* All done, normal exit */
  504. *ret_integer = return_value;
  505. return_ACPI_STATUS (AE_OK);
  506. error_exit:
  507. /* Base was set/validated above */
  508. if (base == 10) {
  509. return_ACPI_STATUS (AE_BAD_DECIMAL_CONSTANT);
  510. }
  511. else {
  512. return_ACPI_STATUS (AE_BAD_HEX_CONSTANT);
  513. }
  514. }
  515. /*******************************************************************************
  516. *
  517. * FUNCTION: acpi_ut_create_update_state_and_push
  518. *
  519. * PARAMETERS: Object - Object to be added to the new state
  520. * Action - Increment/Decrement
  521. * state_list - List the state will be added to
  522. *
  523. * RETURN: Status
  524. *
  525. * DESCRIPTION: Create a new state and push it
  526. *
  527. ******************************************************************************/
  528. acpi_status
  529. acpi_ut_create_update_state_and_push (
  530. union acpi_operand_object *object,
  531. u16 action,
  532. union acpi_generic_state **state_list)
  533. {
  534. union acpi_generic_state *state;
  535. ACPI_FUNCTION_ENTRY ();
  536. /* Ignore null objects; these are expected */
  537. if (!object) {
  538. return (AE_OK);
  539. }
  540. state = acpi_ut_create_update_state (object, action);
  541. if (!state) {
  542. return (AE_NO_MEMORY);
  543. }
  544. acpi_ut_push_generic_state (state_list, state);
  545. return (AE_OK);
  546. }
  547. /*******************************************************************************
  548. *
  549. * FUNCTION: acpi_ut_walk_package_tree
  550. *
  551. * PARAMETERS: source_object - The package to walk
  552. * target_object - Target object (if package is being copied)
  553. * walk_callback - Called once for each package element
  554. * Context - Passed to the callback function
  555. *
  556. * RETURN: Status
  557. *
  558. * DESCRIPTION: Walk through a package
  559. *
  560. ******************************************************************************/
  561. acpi_status
  562. acpi_ut_walk_package_tree (
  563. union acpi_operand_object *source_object,
  564. void *target_object,
  565. acpi_pkg_callback walk_callback,
  566. void *context)
  567. {
  568. acpi_status status = AE_OK;
  569. union acpi_generic_state *state_list = NULL;
  570. union acpi_generic_state *state;
  571. u32 this_index;
  572. union acpi_operand_object *this_source_obj;
  573. ACPI_FUNCTION_TRACE ("ut_walk_package_tree");
  574. state = acpi_ut_create_pkg_state (source_object, target_object, 0);
  575. if (!state) {
  576. return_ACPI_STATUS (AE_NO_MEMORY);
  577. }
  578. while (state) {
  579. /* Get one element of the package */
  580. this_index = state->pkg.index;
  581. this_source_obj = (union acpi_operand_object *)
  582. state->pkg.source_object->package.elements[this_index];
  583. /*
  584. * Check for:
  585. * 1) An uninitialized package element. It is completely
  586. * legal to declare a package and leave it uninitialized
  587. * 2) Not an internal object - can be a namespace node instead
  588. * 3) Any type other than a package. Packages are handled in else
  589. * case below.
  590. */
  591. if ((!this_source_obj) ||
  592. (ACPI_GET_DESCRIPTOR_TYPE (this_source_obj) != ACPI_DESC_TYPE_OPERAND) ||
  593. (ACPI_GET_OBJECT_TYPE (this_source_obj) != ACPI_TYPE_PACKAGE)) {
  594. status = walk_callback (ACPI_COPY_TYPE_SIMPLE, this_source_obj,
  595. state, context);
  596. if (ACPI_FAILURE (status)) {
  597. return_ACPI_STATUS (status);
  598. }
  599. state->pkg.index++;
  600. while (state->pkg.index >= state->pkg.source_object->package.count) {
  601. /*
  602. * We've handled all of the objects at this level, This means
  603. * that we have just completed a package. That package may
  604. * have contained one or more packages itself.
  605. *
  606. * Delete this state and pop the previous state (package).
  607. */
  608. acpi_ut_delete_generic_state (state);
  609. state = acpi_ut_pop_generic_state (&state_list);
  610. /* Finished when there are no more states */
  611. if (!state) {
  612. /*
  613. * We have handled all of the objects in the top level
  614. * package just add the length of the package objects
  615. * and exit
  616. */
  617. return_ACPI_STATUS (AE_OK);
  618. }
  619. /*
  620. * Go back up a level and move the index past the just
  621. * completed package object.
  622. */
  623. state->pkg.index++;
  624. }
  625. }
  626. else {
  627. /* This is a subobject of type package */
  628. status = walk_callback (ACPI_COPY_TYPE_PACKAGE, this_source_obj,
  629. state, context);
  630. if (ACPI_FAILURE (status)) {
  631. return_ACPI_STATUS (status);
  632. }
  633. /*
  634. * Push the current state and create a new one
  635. * The callback above returned a new target package object.
  636. */
  637. acpi_ut_push_generic_state (&state_list, state);
  638. state = acpi_ut_create_pkg_state (this_source_obj,
  639. state->pkg.this_target_obj, 0);
  640. if (!state) {
  641. return_ACPI_STATUS (AE_NO_MEMORY);
  642. }
  643. }
  644. }
  645. /* We should never get here */
  646. return_ACPI_STATUS (AE_AML_INTERNAL);
  647. }
  648. /*******************************************************************************
  649. *
  650. * FUNCTION: acpi_ut_generate_checksum
  651. *
  652. * PARAMETERS: Buffer - Buffer to be scanned
  653. * Length - number of bytes to examine
  654. *
  655. * RETURN: The generated checksum
  656. *
  657. * DESCRIPTION: Generate a checksum on a raw buffer
  658. *
  659. ******************************************************************************/
  660. u8
  661. acpi_ut_generate_checksum (
  662. u8 *buffer,
  663. u32 length)
  664. {
  665. u32 i;
  666. signed char sum = 0;
  667. for (i = 0; i < length; i++) {
  668. sum = (signed char) (sum + buffer[i]);
  669. }
  670. return ((u8) (0 - sum));
  671. }
  672. /*******************************************************************************
  673. *
  674. * FUNCTION: acpi_ut_get_resource_end_tag
  675. *
  676. * PARAMETERS: obj_desc - The resource template buffer object
  677. *
  678. * RETURN: Pointer to the end tag
  679. *
  680. * DESCRIPTION: Find the END_TAG resource descriptor in a resource template
  681. *
  682. ******************************************************************************/
  683. u8 *
  684. acpi_ut_get_resource_end_tag (
  685. union acpi_operand_object *obj_desc)
  686. {
  687. u8 buffer_byte;
  688. u8 *buffer;
  689. u8 *end_buffer;
  690. buffer = obj_desc->buffer.pointer;
  691. end_buffer = buffer + obj_desc->buffer.length;
  692. while (buffer < end_buffer) {
  693. buffer_byte = *buffer;
  694. if (buffer_byte & ACPI_RDESC_TYPE_MASK) {
  695. /* Large Descriptor - Length is next 2 bytes */
  696. buffer += ((*(buffer+1) | (*(buffer+2) << 8)) + 3);
  697. }
  698. else {
  699. /* Small Descriptor. End Tag will be found here */
  700. if ((buffer_byte & ACPI_RDESC_SMALL_MASK) == ACPI_RDESC_TYPE_END_TAG) {
  701. /* Found the end tag descriptor, all done. */
  702. return (buffer);
  703. }
  704. /* Length is in the header */
  705. buffer += ((buffer_byte & 0x07) + 1);
  706. }
  707. }
  708. /* End tag not found */
  709. return (NULL);
  710. }
  711. /*******************************************************************************
  712. *
  713. * FUNCTION: acpi_ut_report_error
  714. *
  715. * PARAMETERS: module_name - Caller's module name (for error output)
  716. * line_number - Caller's line number (for error output)
  717. * component_id - Caller's component ID (for error output)
  718. *
  719. * RETURN: None
  720. *
  721. * DESCRIPTION: Print error message
  722. *
  723. ******************************************************************************/
  724. void
  725. acpi_ut_report_error (
  726. char *module_name,
  727. u32 line_number,
  728. u32 component_id)
  729. {
  730. acpi_os_printf ("%8s-%04d: *** Error: ", module_name, line_number);
  731. }
  732. /*******************************************************************************
  733. *
  734. * FUNCTION: acpi_ut_report_warning
  735. *
  736. * PARAMETERS: module_name - Caller's module name (for error output)
  737. * line_number - Caller's line number (for error output)
  738. * component_id - Caller's component ID (for error output)
  739. *
  740. * RETURN: None
  741. *
  742. * DESCRIPTION: Print warning message
  743. *
  744. ******************************************************************************/
  745. void
  746. acpi_ut_report_warning (
  747. char *module_name,
  748. u32 line_number,
  749. u32 component_id)
  750. {
  751. acpi_os_printf ("%8s-%04d: *** Warning: ", module_name, line_number);
  752. }
  753. /*******************************************************************************
  754. *
  755. * FUNCTION: acpi_ut_report_info
  756. *
  757. * PARAMETERS: module_name - Caller's module name (for error output)
  758. * line_number - Caller's line number (for error output)
  759. * component_id - Caller's component ID (for error output)
  760. *
  761. * RETURN: None
  762. *
  763. * DESCRIPTION: Print information message
  764. *
  765. ******************************************************************************/
  766. void
  767. acpi_ut_report_info (
  768. char *module_name,
  769. u32 line_number,
  770. u32 component_id)
  771. {
  772. acpi_os_printf ("%8s-%04d: *** Info: ", module_name, line_number);
  773. }