Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * |
| 3 | * Module Name: utmisc - common utility procedures |
| 4 | * |
| 5 | ******************************************************************************/ |
| 6 | |
| 7 | /* |
| 8 | * Copyright (C) 2000 - 2005, R. Byron Moore |
| 9 | * All rights reserved. |
| 10 | * |
| 11 | * Redistribution and use in source and binary forms, with or without |
| 12 | * modification, are permitted provided that the following conditions |
| 13 | * are met: |
| 14 | * 1. Redistributions of source code must retain the above copyright |
| 15 | * notice, this list of conditions, and the following disclaimer, |
| 16 | * without modification. |
| 17 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer |
| 18 | * substantially similar to the "NO WARRANTY" disclaimer below |
| 19 | * ("Disclaimer") and any redistribution must be conditioned upon |
| 20 | * including a substantially similar Disclaimer requirement for further |
| 21 | * binary redistribution. |
| 22 | * 3. Neither the names of the above-listed copyright holders nor the names |
| 23 | * of any contributors may be used to endorse or promote products derived |
| 24 | * from this software without specific prior written permission. |
| 25 | * |
| 26 | * Alternatively, this software may be distributed under the terms of the |
| 27 | * GNU General Public License ("GPL") version 2 as published by the Free |
| 28 | * Software Foundation. |
| 29 | * |
| 30 | * NO WARRANTY |
| 31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 32 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 33 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR |
| 34 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 35 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 36 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 37 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 38 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 39 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 40 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 41 | * POSSIBILITY OF SUCH DAMAGES. |
| 42 | */ |
| 43 | |
| 44 | |
| 45 | #include <acpi/acpi.h> |
| 46 | #include <acpi/acnamesp.h> |
| 47 | |
| 48 | |
| 49 | #define _COMPONENT ACPI_UTILITIES |
| 50 | ACPI_MODULE_NAME ("utmisc") |
| 51 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 52 | |
| 53 | /******************************************************************************* |
| 54 | * |
| 55 | * FUNCTION: acpi_ut_strupr (strupr) |
| 56 | * |
| 57 | * PARAMETERS: src_string - The source string to convert |
| 58 | * |
| 59 | * RETURN: Converted src_string (same as input pointer) |
| 60 | * |
| 61 | * DESCRIPTION: Convert string to uppercase |
| 62 | * |
| 63 | * NOTE: This is not a POSIX function, so it appears here, not in utclib.c |
| 64 | * |
| 65 | ******************************************************************************/ |
| 66 | |
| 67 | char * |
| 68 | acpi_ut_strupr ( |
| 69 | char *src_string) |
| 70 | { |
| 71 | char *string; |
| 72 | |
| 73 | |
| 74 | ACPI_FUNCTION_ENTRY (); |
| 75 | |
| 76 | |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame^] | 77 | if (!src_string) { |
| 78 | return (NULL); |
| 79 | } |
| 80 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 81 | /* Walk entire string, uppercasing the letters */ |
| 82 | |
| 83 | for (string = src_string; *string; string++) { |
| 84 | *string = (char) ACPI_TOUPPER (*string); |
| 85 | } |
| 86 | |
| 87 | return (src_string); |
| 88 | } |
| 89 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | |
| 91 | /******************************************************************************* |
| 92 | * |
| 93 | * FUNCTION: acpi_ut_print_string |
| 94 | * |
| 95 | * PARAMETERS: String - Null terminated ASCII string |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 96 | * max_length - Maximum output length |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | * |
| 98 | * RETURN: None |
| 99 | * |
| 100 | * DESCRIPTION: Dump an ASCII string with support for ACPI-defined escape |
| 101 | * sequences. |
| 102 | * |
| 103 | ******************************************************************************/ |
| 104 | |
| 105 | void |
| 106 | acpi_ut_print_string ( |
| 107 | char *string, |
| 108 | u8 max_length) |
| 109 | { |
| 110 | u32 i; |
| 111 | |
| 112 | |
| 113 | if (!string) { |
| 114 | acpi_os_printf ("<\"NULL STRING PTR\">"); |
| 115 | return; |
| 116 | } |
| 117 | |
| 118 | acpi_os_printf ("\""); |
| 119 | for (i = 0; string[i] && (i < max_length); i++) { |
| 120 | /* Escape sequences */ |
| 121 | |
| 122 | switch (string[i]) { |
| 123 | case 0x07: |
| 124 | acpi_os_printf ("\\a"); /* BELL */ |
| 125 | break; |
| 126 | |
| 127 | case 0x08: |
| 128 | acpi_os_printf ("\\b"); /* BACKSPACE */ |
| 129 | break; |
| 130 | |
| 131 | case 0x0C: |
| 132 | acpi_os_printf ("\\f"); /* FORMFEED */ |
| 133 | break; |
| 134 | |
| 135 | case 0x0A: |
| 136 | acpi_os_printf ("\\n"); /* LINEFEED */ |
| 137 | break; |
| 138 | |
| 139 | case 0x0D: |
| 140 | acpi_os_printf ("\\r"); /* CARRIAGE RETURN*/ |
| 141 | break; |
| 142 | |
| 143 | case 0x09: |
| 144 | acpi_os_printf ("\\t"); /* HORIZONTAL TAB */ |
| 145 | break; |
| 146 | |
| 147 | case 0x0B: |
| 148 | acpi_os_printf ("\\v"); /* VERTICAL TAB */ |
| 149 | break; |
| 150 | |
| 151 | case '\'': /* Single Quote */ |
| 152 | case '\"': /* Double Quote */ |
| 153 | case '\\': /* Backslash */ |
| 154 | acpi_os_printf ("\\%c", (int) string[i]); |
| 155 | break; |
| 156 | |
| 157 | default: |
| 158 | |
| 159 | /* Check for printable character or hex escape */ |
| 160 | |
| 161 | if (ACPI_IS_PRINT (string[i])) |
| 162 | { |
| 163 | /* This is a normal character */ |
| 164 | |
| 165 | acpi_os_printf ("%c", (int) string[i]); |
| 166 | } |
| 167 | else |
| 168 | { |
| 169 | /* All others will be Hex escapes */ |
| 170 | |
| 171 | acpi_os_printf ("\\x%2.2X", (s32) string[i]); |
| 172 | } |
| 173 | break; |
| 174 | } |
| 175 | } |
| 176 | acpi_os_printf ("\""); |
| 177 | |
| 178 | if (i == max_length && string[i]) { |
| 179 | acpi_os_printf ("..."); |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | |
| 184 | /******************************************************************************* |
| 185 | * |
| 186 | * FUNCTION: acpi_ut_dword_byte_swap |
| 187 | * |
| 188 | * PARAMETERS: Value - Value to be converted |
| 189 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 190 | * RETURN: u32 integer with bytes swapped |
| 191 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | * DESCRIPTION: Convert a 32-bit value to big-endian (swap the bytes) |
| 193 | * |
| 194 | ******************************************************************************/ |
| 195 | |
| 196 | u32 |
| 197 | acpi_ut_dword_byte_swap ( |
| 198 | u32 value) |
| 199 | { |
| 200 | union { |
| 201 | u32 value; |
| 202 | u8 bytes[4]; |
| 203 | } out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | union { |
| 205 | u32 value; |
| 206 | u8 bytes[4]; |
| 207 | } in; |
| 208 | |
| 209 | |
| 210 | ACPI_FUNCTION_ENTRY (); |
| 211 | |
| 212 | |
| 213 | in.value = value; |
| 214 | |
| 215 | out.bytes[0] = in.bytes[3]; |
| 216 | out.bytes[1] = in.bytes[2]; |
| 217 | out.bytes[2] = in.bytes[1]; |
| 218 | out.bytes[3] = in.bytes[0]; |
| 219 | |
| 220 | return (out.value); |
| 221 | } |
| 222 | |
| 223 | |
| 224 | /******************************************************************************* |
| 225 | * |
| 226 | * FUNCTION: acpi_ut_set_integer_width |
| 227 | * |
| 228 | * PARAMETERS: Revision From DSDT header |
| 229 | * |
| 230 | * RETURN: None |
| 231 | * |
| 232 | * DESCRIPTION: Set the global integer bit width based upon the revision |
| 233 | * of the DSDT. For Revision 1 and 0, Integers are 32 bits. |
| 234 | * For Revision 2 and above, Integers are 64 bits. Yes, this |
| 235 | * makes a difference. |
| 236 | * |
| 237 | ******************************************************************************/ |
| 238 | |
| 239 | void |
| 240 | acpi_ut_set_integer_width ( |
| 241 | u8 revision) |
| 242 | { |
| 243 | |
| 244 | if (revision <= 1) { |
| 245 | acpi_gbl_integer_bit_width = 32; |
| 246 | acpi_gbl_integer_nybble_width = 8; |
| 247 | acpi_gbl_integer_byte_width = 4; |
| 248 | } |
| 249 | else { |
| 250 | acpi_gbl_integer_bit_width = 64; |
| 251 | acpi_gbl_integer_nybble_width = 16; |
| 252 | acpi_gbl_integer_byte_width = 8; |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | |
| 257 | #ifdef ACPI_DEBUG_OUTPUT |
| 258 | /******************************************************************************* |
| 259 | * |
| 260 | * FUNCTION: acpi_ut_display_init_pathname |
| 261 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 262 | * PARAMETERS: Type - Object type of the node |
| 263 | * obj_handle - Handle whose pathname will be displayed |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | * Path - Additional path string to be appended. |
| 265 | * (NULL if no extra path) |
| 266 | * |
| 267 | * RETURN: acpi_status |
| 268 | * |
| 269 | * DESCRIPTION: Display full pathname of an object, DEBUG ONLY |
| 270 | * |
| 271 | ******************************************************************************/ |
| 272 | |
| 273 | void |
| 274 | acpi_ut_display_init_pathname ( |
| 275 | u8 type, |
| 276 | struct acpi_namespace_node *obj_handle, |
| 277 | char *path) |
| 278 | { |
| 279 | acpi_status status; |
| 280 | struct acpi_buffer buffer; |
| 281 | |
| 282 | |
| 283 | ACPI_FUNCTION_ENTRY (); |
| 284 | |
| 285 | |
| 286 | /* Only print the path if the appropriate debug level is enabled */ |
| 287 | |
| 288 | if (!(acpi_dbg_level & ACPI_LV_INIT_NAMES)) { |
| 289 | return; |
| 290 | } |
| 291 | |
| 292 | /* Get the full pathname to the node */ |
| 293 | |
| 294 | buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER; |
| 295 | status = acpi_ns_handle_to_pathname (obj_handle, &buffer); |
| 296 | if (ACPI_FAILURE (status)) { |
| 297 | return; |
| 298 | } |
| 299 | |
| 300 | /* Print what we're doing */ |
| 301 | |
| 302 | switch (type) { |
| 303 | case ACPI_TYPE_METHOD: |
| 304 | acpi_os_printf ("Executing "); |
| 305 | break; |
| 306 | |
| 307 | default: |
| 308 | acpi_os_printf ("Initializing "); |
| 309 | break; |
| 310 | } |
| 311 | |
| 312 | /* Print the object type and pathname */ |
| 313 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 314 | acpi_os_printf ("%-12s %s", |
| 315 | acpi_ut_get_type_name (type), (char *) buffer.pointer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | |
| 317 | /* Extra path is used to append names like _STA, _INI, etc. */ |
| 318 | |
| 319 | if (path) { |
| 320 | acpi_os_printf (".%s", path); |
| 321 | } |
| 322 | acpi_os_printf ("\n"); |
| 323 | |
| 324 | ACPI_MEM_FREE (buffer.pointer); |
| 325 | } |
| 326 | #endif |
| 327 | |
| 328 | |
| 329 | /******************************************************************************* |
| 330 | * |
| 331 | * FUNCTION: acpi_ut_valid_acpi_name |
| 332 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 333 | * PARAMETERS: Name - The name to be examined |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 335 | * RETURN: TRUE if the name is valid, FALSE otherwise |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | * |
| 337 | * DESCRIPTION: Check for a valid ACPI name. Each character must be one of: |
| 338 | * 1) Upper case alpha |
| 339 | * 2) numeric |
| 340 | * 3) underscore |
| 341 | * |
| 342 | ******************************************************************************/ |
| 343 | |
| 344 | u8 |
| 345 | acpi_ut_valid_acpi_name ( |
| 346 | u32 name) |
| 347 | { |
| 348 | char *name_ptr = (char *) &name; |
| 349 | char character; |
| 350 | acpi_native_uint i; |
| 351 | |
| 352 | |
| 353 | ACPI_FUNCTION_ENTRY (); |
| 354 | |
| 355 | |
| 356 | for (i = 0; i < ACPI_NAME_SIZE; i++) { |
| 357 | character = *name_ptr; |
| 358 | name_ptr++; |
| 359 | |
| 360 | if (!((character == '_') || |
| 361 | (character >= 'A' && character <= 'Z') || |
| 362 | (character >= '0' && character <= '9'))) { |
| 363 | return (FALSE); |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | return (TRUE); |
| 368 | } |
| 369 | |
| 370 | |
| 371 | /******************************************************************************* |
| 372 | * |
| 373 | * FUNCTION: acpi_ut_valid_acpi_character |
| 374 | * |
| 375 | * PARAMETERS: Character - The character to be examined |
| 376 | * |
| 377 | * RETURN: 1 if Character may appear in a name, else 0 |
| 378 | * |
| 379 | * DESCRIPTION: Check for a printable character |
| 380 | * |
| 381 | ******************************************************************************/ |
| 382 | |
| 383 | u8 |
| 384 | acpi_ut_valid_acpi_character ( |
| 385 | char character) |
| 386 | { |
| 387 | |
| 388 | ACPI_FUNCTION_ENTRY (); |
| 389 | |
| 390 | return ((u8) ((character == '_') || |
| 391 | (character >= 'A' && character <= 'Z') || |
| 392 | (character >= '0' && character <= '9'))); |
| 393 | } |
| 394 | |
| 395 | |
| 396 | /******************************************************************************* |
| 397 | * |
| 398 | * FUNCTION: acpi_ut_strtoul64 |
| 399 | * |
| 400 | * PARAMETERS: String - Null terminated string |
| 401 | * Base - Radix of the string: 10, 16, or ACPI_ANY_BASE |
| 402 | * ret_integer - Where the converted integer is returned |
| 403 | * |
| 404 | * RETURN: Status and Converted value |
| 405 | * |
| 406 | * DESCRIPTION: Convert a string into an unsigned value. |
| 407 | * NOTE: Does not support Octal strings, not needed. |
| 408 | * |
| 409 | ******************************************************************************/ |
| 410 | |
| 411 | acpi_status |
| 412 | acpi_ut_strtoul64 ( |
| 413 | char *string, |
| 414 | u32 base, |
| 415 | acpi_integer *ret_integer) |
| 416 | { |
| 417 | u32 this_digit = 0; |
| 418 | acpi_integer return_value = 0; |
| 419 | acpi_integer quotient; |
| 420 | |
| 421 | |
| 422 | ACPI_FUNCTION_TRACE ("ut_stroul64"); |
| 423 | |
| 424 | |
| 425 | if ((!string) || !(*string)) { |
| 426 | goto error_exit; |
| 427 | } |
| 428 | |
| 429 | switch (base) { |
| 430 | case ACPI_ANY_BASE: |
| 431 | case 10: |
| 432 | case 16: |
| 433 | break; |
| 434 | |
| 435 | default: |
| 436 | /* Invalid Base */ |
| 437 | return_ACPI_STATUS (AE_BAD_PARAMETER); |
| 438 | } |
| 439 | |
| 440 | /* Skip over any white space in the buffer */ |
| 441 | |
| 442 | while (ACPI_IS_SPACE (*string) || *string == '\t') { |
| 443 | string++; |
| 444 | } |
| 445 | |
| 446 | /* |
| 447 | * If the input parameter Base is zero, then we need to |
| 448 | * determine if it is decimal or hexadecimal: |
| 449 | */ |
| 450 | if (base == 0) { |
| 451 | if ((*string == '0') && |
| 452 | (ACPI_TOLOWER (*(string + 1)) == 'x')) { |
| 453 | base = 16; |
| 454 | string += 2; |
| 455 | } |
| 456 | else { |
| 457 | base = 10; |
| 458 | } |
| 459 | } |
| 460 | |
| 461 | /* |
| 462 | * For hexadecimal base, skip over the leading |
| 463 | * 0 or 0x, if they are present. |
| 464 | */ |
| 465 | if ((base == 16) && |
| 466 | (*string == '0') && |
| 467 | (ACPI_TOLOWER (*(string + 1)) == 'x')) { |
| 468 | string += 2; |
| 469 | } |
| 470 | |
| 471 | /* Any string left? */ |
| 472 | |
| 473 | if (!(*string)) { |
| 474 | goto error_exit; |
| 475 | } |
| 476 | |
| 477 | /* Main loop: convert the string to a 64-bit integer */ |
| 478 | |
| 479 | while (*string) { |
| 480 | if (ACPI_IS_DIGIT (*string)) { |
| 481 | /* Convert ASCII 0-9 to Decimal value */ |
| 482 | |
| 483 | this_digit = ((u8) *string) - '0'; |
| 484 | } |
| 485 | else { |
| 486 | if (base == 10) { |
| 487 | /* Digit is out of range */ |
| 488 | |
| 489 | goto error_exit; |
| 490 | } |
| 491 | |
| 492 | this_digit = (u8) ACPI_TOUPPER (*string); |
| 493 | if (ACPI_IS_XDIGIT ((char) this_digit)) { |
| 494 | /* Convert ASCII Hex char to value */ |
| 495 | |
| 496 | this_digit = this_digit - 'A' + 10; |
| 497 | } |
| 498 | else { |
| 499 | /* |
| 500 | * We allow non-hex chars, just stop now, same as end-of-string. |
| 501 | * See ACPI spec, string-to-integer conversion. |
| 502 | */ |
| 503 | break; |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | /* Divide the digit into the correct position */ |
| 508 | |
| 509 | (void) acpi_ut_short_divide ((ACPI_INTEGER_MAX - (acpi_integer) this_digit), |
| 510 | base, "ient, NULL); |
| 511 | if (return_value > quotient) { |
| 512 | goto error_exit; |
| 513 | } |
| 514 | |
| 515 | return_value *= base; |
| 516 | return_value += this_digit; |
| 517 | string++; |
| 518 | } |
| 519 | |
| 520 | /* All done, normal exit */ |
| 521 | |
| 522 | *ret_integer = return_value; |
| 523 | return_ACPI_STATUS (AE_OK); |
| 524 | |
| 525 | |
| 526 | error_exit: |
| 527 | /* Base was set/validated above */ |
| 528 | |
| 529 | if (base == 10) { |
| 530 | return_ACPI_STATUS (AE_BAD_DECIMAL_CONSTANT); |
| 531 | } |
| 532 | else { |
| 533 | return_ACPI_STATUS (AE_BAD_HEX_CONSTANT); |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | |
| 538 | /******************************************************************************* |
| 539 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | * FUNCTION: acpi_ut_create_update_state_and_push |
| 541 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 542 | * PARAMETERS: Object - Object to be added to the new state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | * Action - Increment/Decrement |
| 544 | * state_list - List the state will be added to |
| 545 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 546 | * RETURN: Status |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | * |
| 548 | * DESCRIPTION: Create a new state and push it |
| 549 | * |
| 550 | ******************************************************************************/ |
| 551 | |
| 552 | acpi_status |
| 553 | acpi_ut_create_update_state_and_push ( |
| 554 | union acpi_operand_object *object, |
| 555 | u16 action, |
| 556 | union acpi_generic_state **state_list) |
| 557 | { |
| 558 | union acpi_generic_state *state; |
| 559 | |
| 560 | |
| 561 | ACPI_FUNCTION_ENTRY (); |
| 562 | |
| 563 | |
| 564 | /* Ignore null objects; these are expected */ |
| 565 | |
| 566 | if (!object) { |
| 567 | return (AE_OK); |
| 568 | } |
| 569 | |
| 570 | state = acpi_ut_create_update_state (object, action); |
| 571 | if (!state) { |
| 572 | return (AE_NO_MEMORY); |
| 573 | } |
| 574 | |
| 575 | acpi_ut_push_generic_state (state_list, state); |
| 576 | return (AE_OK); |
| 577 | } |
| 578 | |
| 579 | |
| 580 | /******************************************************************************* |
| 581 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | * FUNCTION: acpi_ut_walk_package_tree |
| 583 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 584 | * PARAMETERS: source_object - The package to walk |
| 585 | * target_object - Target object (if package is being copied) |
| 586 | * walk_callback - Called once for each package element |
| 587 | * Context - Passed to the callback function |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | * |
| 589 | * RETURN: Status |
| 590 | * |
| 591 | * DESCRIPTION: Walk through a package |
| 592 | * |
| 593 | ******************************************************************************/ |
| 594 | |
| 595 | acpi_status |
| 596 | acpi_ut_walk_package_tree ( |
| 597 | union acpi_operand_object *source_object, |
| 598 | void *target_object, |
| 599 | acpi_pkg_callback walk_callback, |
| 600 | void *context) |
| 601 | { |
| 602 | acpi_status status = AE_OK; |
| 603 | union acpi_generic_state *state_list = NULL; |
| 604 | union acpi_generic_state *state; |
| 605 | u32 this_index; |
| 606 | union acpi_operand_object *this_source_obj; |
| 607 | |
| 608 | |
| 609 | ACPI_FUNCTION_TRACE ("ut_walk_package_tree"); |
| 610 | |
| 611 | |
| 612 | state = acpi_ut_create_pkg_state (source_object, target_object, 0); |
| 613 | if (!state) { |
| 614 | return_ACPI_STATUS (AE_NO_MEMORY); |
| 615 | } |
| 616 | |
| 617 | while (state) { |
| 618 | /* Get one element of the package */ |
| 619 | |
| 620 | this_index = state->pkg.index; |
| 621 | this_source_obj = (union acpi_operand_object *) |
| 622 | state->pkg.source_object->package.elements[this_index]; |
| 623 | |
| 624 | /* |
| 625 | * Check for: |
| 626 | * 1) An uninitialized package element. It is completely |
| 627 | * legal to declare a package and leave it uninitialized |
| 628 | * 2) Not an internal object - can be a namespace node instead |
| 629 | * 3) Any type other than a package. Packages are handled in else |
| 630 | * case below. |
| 631 | */ |
| 632 | if ((!this_source_obj) || |
| 633 | (ACPI_GET_DESCRIPTOR_TYPE (this_source_obj) != ACPI_DESC_TYPE_OPERAND) || |
| 634 | (ACPI_GET_OBJECT_TYPE (this_source_obj) != ACPI_TYPE_PACKAGE)) { |
| 635 | status = walk_callback (ACPI_COPY_TYPE_SIMPLE, this_source_obj, |
| 636 | state, context); |
| 637 | if (ACPI_FAILURE (status)) { |
| 638 | return_ACPI_STATUS (status); |
| 639 | } |
| 640 | |
| 641 | state->pkg.index++; |
| 642 | while (state->pkg.index >= state->pkg.source_object->package.count) { |
| 643 | /* |
| 644 | * We've handled all of the objects at this level, This means |
| 645 | * that we have just completed a package. That package may |
| 646 | * have contained one or more packages itself. |
| 647 | * |
| 648 | * Delete this state and pop the previous state (package). |
| 649 | */ |
| 650 | acpi_ut_delete_generic_state (state); |
| 651 | state = acpi_ut_pop_generic_state (&state_list); |
| 652 | |
| 653 | /* Finished when there are no more states */ |
| 654 | |
| 655 | if (!state) { |
| 656 | /* |
| 657 | * We have handled all of the objects in the top level |
| 658 | * package just add the length of the package objects |
| 659 | * and exit |
| 660 | */ |
| 661 | return_ACPI_STATUS (AE_OK); |
| 662 | } |
| 663 | |
| 664 | /* |
| 665 | * Go back up a level and move the index past the just |
| 666 | * completed package object. |
| 667 | */ |
| 668 | state->pkg.index++; |
| 669 | } |
| 670 | } |
| 671 | else { |
| 672 | /* This is a subobject of type package */ |
| 673 | |
| 674 | status = walk_callback (ACPI_COPY_TYPE_PACKAGE, this_source_obj, |
| 675 | state, context); |
| 676 | if (ACPI_FAILURE (status)) { |
| 677 | return_ACPI_STATUS (status); |
| 678 | } |
| 679 | |
| 680 | /* |
| 681 | * Push the current state and create a new one |
| 682 | * The callback above returned a new target package object. |
| 683 | */ |
| 684 | acpi_ut_push_generic_state (&state_list, state); |
| 685 | state = acpi_ut_create_pkg_state (this_source_obj, |
| 686 | state->pkg.this_target_obj, 0); |
| 687 | if (!state) { |
| 688 | return_ACPI_STATUS (AE_NO_MEMORY); |
| 689 | } |
| 690 | } |
| 691 | } |
| 692 | |
| 693 | /* We should never get here */ |
| 694 | |
| 695 | return_ACPI_STATUS (AE_AML_INTERNAL); |
| 696 | } |
| 697 | |
| 698 | |
| 699 | /******************************************************************************* |
| 700 | * |
| 701 | * FUNCTION: acpi_ut_generate_checksum |
| 702 | * |
| 703 | * PARAMETERS: Buffer - Buffer to be scanned |
| 704 | * Length - number of bytes to examine |
| 705 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 706 | * RETURN: The generated checksum |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | * |
| 708 | * DESCRIPTION: Generate a checksum on a raw buffer |
| 709 | * |
| 710 | ******************************************************************************/ |
| 711 | |
| 712 | u8 |
| 713 | acpi_ut_generate_checksum ( |
| 714 | u8 *buffer, |
| 715 | u32 length) |
| 716 | { |
| 717 | u32 i; |
| 718 | signed char sum = 0; |
| 719 | |
| 720 | |
| 721 | for (i = 0; i < length; i++) { |
| 722 | sum = (signed char) (sum + buffer[i]); |
| 723 | } |
| 724 | |
| 725 | return ((u8) (0 - sum)); |
| 726 | } |
| 727 | |
| 728 | |
| 729 | /******************************************************************************* |
| 730 | * |
| 731 | * FUNCTION: acpi_ut_get_resource_end_tag |
| 732 | * |
| 733 | * PARAMETERS: obj_desc - The resource template buffer object |
| 734 | * |
| 735 | * RETURN: Pointer to the end tag |
| 736 | * |
| 737 | * DESCRIPTION: Find the END_TAG resource descriptor in a resource template |
| 738 | * |
| 739 | ******************************************************************************/ |
| 740 | |
| 741 | |
| 742 | u8 * |
| 743 | acpi_ut_get_resource_end_tag ( |
| 744 | union acpi_operand_object *obj_desc) |
| 745 | { |
| 746 | u8 buffer_byte; |
| 747 | u8 *buffer; |
| 748 | u8 *end_buffer; |
| 749 | |
| 750 | |
| 751 | buffer = obj_desc->buffer.pointer; |
| 752 | end_buffer = buffer + obj_desc->buffer.length; |
| 753 | |
| 754 | while (buffer < end_buffer) { |
| 755 | buffer_byte = *buffer; |
| 756 | if (buffer_byte & ACPI_RDESC_TYPE_MASK) { |
| 757 | /* Large Descriptor - Length is next 2 bytes */ |
| 758 | |
| 759 | buffer += ((*(buffer+1) | (*(buffer+2) << 8)) + 3); |
| 760 | } |
| 761 | else { |
| 762 | /* Small Descriptor. End Tag will be found here */ |
| 763 | |
| 764 | if ((buffer_byte & ACPI_RDESC_SMALL_MASK) == ACPI_RDESC_TYPE_END_TAG) { |
| 765 | /* Found the end tag descriptor, all done. */ |
| 766 | |
| 767 | return (buffer); |
| 768 | } |
| 769 | |
| 770 | /* Length is in the header */ |
| 771 | |
| 772 | buffer += ((buffer_byte & 0x07) + 1); |
| 773 | } |
| 774 | } |
| 775 | |
| 776 | /* End tag not found */ |
| 777 | |
| 778 | return (NULL); |
| 779 | } |
| 780 | |
| 781 | |
| 782 | /******************************************************************************* |
| 783 | * |
| 784 | * FUNCTION: acpi_ut_report_error |
| 785 | * |
| 786 | * PARAMETERS: module_name - Caller's module name (for error output) |
| 787 | * line_number - Caller's line number (for error output) |
| 788 | * component_id - Caller's component ID (for error output) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | * |
| 790 | * RETURN: None |
| 791 | * |
| 792 | * DESCRIPTION: Print error message |
| 793 | * |
| 794 | ******************************************************************************/ |
| 795 | |
| 796 | void |
| 797 | acpi_ut_report_error ( |
| 798 | char *module_name, |
| 799 | u32 line_number, |
| 800 | u32 component_id) |
| 801 | { |
| 802 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | acpi_os_printf ("%8s-%04d: *** Error: ", module_name, line_number); |
| 804 | } |
| 805 | |
| 806 | |
| 807 | /******************************************************************************* |
| 808 | * |
| 809 | * FUNCTION: acpi_ut_report_warning |
| 810 | * |
| 811 | * PARAMETERS: module_name - Caller's module name (for error output) |
| 812 | * line_number - Caller's line number (for error output) |
| 813 | * component_id - Caller's component ID (for error output) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | * |
| 815 | * RETURN: None |
| 816 | * |
| 817 | * DESCRIPTION: Print warning message |
| 818 | * |
| 819 | ******************************************************************************/ |
| 820 | |
| 821 | void |
| 822 | acpi_ut_report_warning ( |
| 823 | char *module_name, |
| 824 | u32 line_number, |
| 825 | u32 component_id) |
| 826 | { |
| 827 | |
| 828 | acpi_os_printf ("%8s-%04d: *** Warning: ", module_name, line_number); |
| 829 | } |
| 830 | |
| 831 | |
| 832 | /******************************************************************************* |
| 833 | * |
| 834 | * FUNCTION: acpi_ut_report_info |
| 835 | * |
| 836 | * PARAMETERS: module_name - Caller's module name (for error output) |
| 837 | * line_number - Caller's line number (for error output) |
| 838 | * component_id - Caller's component ID (for error output) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | * |
| 840 | * RETURN: None |
| 841 | * |
| 842 | * DESCRIPTION: Print information message |
| 843 | * |
| 844 | ******************************************************************************/ |
| 845 | |
| 846 | void |
| 847 | acpi_ut_report_info ( |
| 848 | char *module_name, |
| 849 | u32 line_number, |
| 850 | u32 component_id) |
| 851 | { |
| 852 | |
| 853 | acpi_os_printf ("%8s-%04d: *** Info: ", module_name, line_number); |
| 854 | } |
| 855 | |
| 856 | |