utmisc.c 23 KB

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