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