utmisc.c 23 KB

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