:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[reactos.git] / drivers / bus / acpi / utils / cmutils.c
1 /*******************************************************************************
2  *
3  * Module Name: cmutils - common utility procedures
4  *              $Revision$
5  *
6  ******************************************************************************/
7
8 /*
9  *  Copyright (C) 2000, 2001 R. Byron Moore
10  *
11  *  This program is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  This program is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24  */
25
26
27 #include "acpi.h"
28 #include "acevents.h"
29 #include "achware.h"
30 #include "acnamesp.h"
31 #include "acinterp.h"
32 #include "amlcode.h"
33 #include "acdebug.h"
34
35
36 #define _COMPONENT          ACPI_UTILITIES
37          MODULE_NAME         ("cmutils")
38
39
40 /*******************************************************************************
41  *
42  * FUNCTION:    Acpi_cm_valid_acpi_name
43  *
44  * PARAMETERS:  Character           - The character to be examined
45  *
46  * RETURN:      1 if Character may appear in a name, else 0
47  *
48  * DESCRIPTION: Check for a valid ACPI name.  Each character must be one of:
49  *              1) Upper case alpha
50  *              2) numeric
51  *              3) underscore
52  *
53  ******************************************************************************/
54
55 u8
56 acpi_cm_valid_acpi_name (
57         u32                     name)
58 {
59         NATIVE_CHAR             *name_ptr = (NATIVE_CHAR *) &name;
60         u32                     i;
61
62
63         for (i = 0; i < ACPI_NAME_SIZE; i++) {
64                 if (!((name_ptr[i] == '_') ||
65                           (name_ptr[i] >= 'A' && name_ptr[i] <= 'Z') ||
66                           (name_ptr[i] >= '0' && name_ptr[i] <= '9'))) {
67                         return (FALSE);
68                 }
69         }
70
71
72         return (TRUE);
73 }
74
75
76 /*******************************************************************************
77  *
78  * FUNCTION:    Acpi_cm_valid_acpi_character
79  *
80  * PARAMETERS:  Character           - The character to be examined
81  *
82  * RETURN:      1 if Character may appear in a name, else 0
83  *
84  * DESCRIPTION: Check for a printable character
85  *
86  ******************************************************************************/
87
88 u8
89 acpi_cm_valid_acpi_character (
90         NATIVE_CHAR             character)
91 {
92
93         return ((u8)   ((character == '_') ||
94                            (character >= 'A' && character <= 'Z') ||
95                            (character >= '0' && character <= '9')));
96 }
97
98
99 /*******************************************************************************
100  *
101  * FUNCTION:    Acpi_cm_mutex_initialize
102  *
103  * PARAMETERS:  None.
104  *
105  * RETURN:      Status
106  *
107  * DESCRIPTION: Create the system mutex objects.
108  *
109  ******************************************************************************/
110
111 ACPI_STATUS
112 acpi_cm_mutex_initialize (
113         void)
114 {
115         u32                     i;
116         ACPI_STATUS             status;
117
118
119         /*
120          * Create each of the predefined mutex objects
121          */
122         for (i = 0; i < NUM_MTX; i++) {
123                 status = acpi_cm_create_mutex (i);
124                 if (ACPI_FAILURE (status)) {
125                         return (status);
126                 }
127         }
128
129         return (AE_OK);
130 }
131
132
133 /*******************************************************************************
134  *
135  * FUNCTION:    Acpi_cm_mutex_terminate
136  *
137  * PARAMETERS:  None.
138  *
139  * RETURN:      None.
140  *
141  * DESCRIPTION: Delete all of the system mutex objects.
142  *
143  ******************************************************************************/
144
145 void
146 acpi_cm_mutex_terminate (
147         void)
148 {
149         u32                     i;
150
151
152         /*
153          * Delete each predefined mutex object
154          */
155         for (i = 0; i < NUM_MTX; i++) {
156                 acpi_cm_delete_mutex (i);
157         }
158
159         return;
160 }
161
162
163 /*******************************************************************************
164  *
165  * FUNCTION:    Acpi_cm_create_mutex
166  *
167  * PARAMETERS:  Mutex_iD        - ID of the mutex to be created
168  *
169  * RETURN:      Status
170  *
171  * DESCRIPTION: Create a mutex object.
172  *
173  ******************************************************************************/
174
175 ACPI_STATUS
176 acpi_cm_create_mutex (
177         ACPI_MUTEX_HANDLE       mutex_id)
178 {
179         ACPI_STATUS             status = AE_OK;
180
181
182         if (mutex_id > MAX_MTX) {
183                 return (AE_BAD_PARAMETER);
184         }
185
186
187         if (!acpi_gbl_acpi_mutex_info[mutex_id].mutex) {
188                 status = acpi_os_create_semaphore (1, 1,
189                                    &acpi_gbl_acpi_mutex_info[mutex_id].mutex);
190                 acpi_gbl_acpi_mutex_info[mutex_id].locked = FALSE;
191                 acpi_gbl_acpi_mutex_info[mutex_id].use_count = 0;
192         }
193
194         return (status);
195 }
196
197
198 /*******************************************************************************
199  *
200  * FUNCTION:    Acpi_cm_delete_mutex
201  *
202  * PARAMETERS:  Mutex_iD        - ID of the mutex to be deleted
203  *
204  * RETURN:      Status
205  *
206  * DESCRIPTION: Delete a mutex object.
207  *
208  ******************************************************************************/
209
210 ACPI_STATUS
211 acpi_cm_delete_mutex (
212         ACPI_MUTEX_HANDLE       mutex_id)
213 {
214         ACPI_STATUS             status;
215
216
217         if (mutex_id > MAX_MTX) {
218                 return (AE_BAD_PARAMETER);
219         }
220
221
222         status = acpi_os_delete_semaphore (acpi_gbl_acpi_mutex_info[mutex_id].mutex);
223
224         acpi_gbl_acpi_mutex_info[mutex_id].mutex = NULL;
225         acpi_gbl_acpi_mutex_info[mutex_id].locked = FALSE;
226
227         return (status);
228 }
229
230
231 /*******************************************************************************
232  *
233  * FUNCTION:    Acpi_cm_acquire_mutex
234  *
235  * PARAMETERS:  Mutex_iD        - ID of the mutex to be acquired
236  *
237  * RETURN:      Status
238  *
239  * DESCRIPTION: Acquire a mutex object.
240  *
241  ******************************************************************************/
242
243 ACPI_STATUS
244 acpi_cm_acquire_mutex (
245         ACPI_MUTEX_HANDLE       mutex_id)
246 {
247         ACPI_STATUS             status;
248         u32                     i;
249         u32                     this_thread_id;
250
251
252         if (mutex_id > MAX_MTX) {
253                 return (AE_BAD_PARAMETER);
254         }
255
256
257         this_thread_id = acpi_os_get_thread_id ();
258
259         /*
260          * Deadlock prevention.  Check if this thread owns any mutexes of value
261          * greater than or equal to this one.  If so, the thread has violated
262          * the mutex ordering rule.  This indicates a coding error somewhere in
263          * the ACPI subsystem code.
264          */
265         for (i = mutex_id; i < MAX_MTX; i++) {
266                 if (acpi_gbl_acpi_mutex_info[i].owner_id == this_thread_id) {
267                         if (i == mutex_id) {
268                                 return (AE_ALREADY_ACQUIRED);
269                         }
270
271                         return (AE_ACQUIRE_DEADLOCK);
272                 }
273         }
274
275
276         status = acpi_os_wait_semaphore (acpi_gbl_acpi_mutex_info[mutex_id].mutex,
277                            1, WAIT_FOREVER);
278
279         if (ACPI_SUCCESS (status)) {
280                 acpi_gbl_acpi_mutex_info[mutex_id].locked = TRUE;
281                 acpi_gbl_acpi_mutex_info[mutex_id].use_count++;
282                 acpi_gbl_acpi_mutex_info[mutex_id].owner_id = this_thread_id;
283         }
284
285         return (status);
286 }
287
288
289 /*******************************************************************************
290  *
291  * FUNCTION:    Acpi_cm_release_mutex
292  *
293  * PARAMETERS:  Mutex_iD        - ID of the mutex to be released
294  *
295  * RETURN:      Status
296  *
297  * DESCRIPTION: Release a mutex object.
298  *
299  ******************************************************************************/
300
301 ACPI_STATUS
302 acpi_cm_release_mutex (
303         ACPI_MUTEX_HANDLE       mutex_id)
304 {
305         ACPI_STATUS             status;
306         u32                     i;
307         u32                     this_thread_id;
308
309
310         if (mutex_id > MAX_MTX) {
311                 return (AE_BAD_PARAMETER);
312         }
313
314
315         /*
316          * Mutex must be acquired in order to release it!
317          */
318         if (!acpi_gbl_acpi_mutex_info[mutex_id].locked) {
319                 return (AE_NOT_ACQUIRED);
320         }
321
322
323         /*
324          * Deadlock prevention.  Check if this thread owns any mutexes of value
325          * greater than this one.  If so, the thread has violated
326          * the mutex ordering rule.  This indicates a coding error somewhere in
327          * the ACPI subsystem code.
328          */
329         this_thread_id = acpi_os_get_thread_id ();
330         for (i = mutex_id; i < MAX_MTX; i++) {
331                 if (acpi_gbl_acpi_mutex_info[i].owner_id == this_thread_id) {
332                         if (i == mutex_id) {
333                                 continue;
334                         }
335
336                         return (AE_RELEASE_DEADLOCK);
337                 }
338         }
339
340         acpi_gbl_acpi_mutex_info[mutex_id].locked = FALSE; /* Mark before unlocking */
341         acpi_gbl_acpi_mutex_info[mutex_id].owner_id = 0;
342
343         status = acpi_os_signal_semaphore (acpi_gbl_acpi_mutex_info[mutex_id].mutex, 1);
344
345
346         return (status);
347 }
348
349
350 /*******************************************************************************
351  *
352  * FUNCTION:    Acpi_cm_create_update_state_and_push
353  *
354  * PARAMETERS:  *Object         - Object to be added to the new state
355  *              Action          - Increment/Decrement
356  *              State_list      - List the state will be added to
357  *
358  * RETURN:      None
359  *
360  * DESCRIPTION: Create a new state and push it
361  *
362  ******************************************************************************/
363
364 ACPI_STATUS
365 acpi_cm_create_update_state_and_push (
366         ACPI_OPERAND_OBJECT     *object,
367         u16                     action,
368         ACPI_GENERIC_STATE      **state_list)
369 {
370         ACPI_GENERIC_STATE       *state;
371
372
373         /* Ignore null objects; these are expected */
374
375         if (!object) {
376                 return (AE_OK);
377         }
378
379         state = acpi_cm_create_update_state (object, action);
380         if (!state) {
381                 return (AE_NO_MEMORY);
382         }
383
384
385         acpi_cm_push_generic_state (state_list, state);
386         return (AE_OK);
387 }
388
389
390 /*******************************************************************************
391  *
392  * FUNCTION:    Acpi_cm_create_pkg_state_and_push
393  *
394  * PARAMETERS:  *Object         - Object to be added to the new state
395  *              Action          - Increment/Decrement
396  *              State_list      - List the state will be added to
397  *
398  * RETURN:      None
399  *
400  * DESCRIPTION: Create a new state and push it
401  *
402  ******************************************************************************/
403
404 ACPI_STATUS
405 acpi_cm_create_pkg_state_and_push (
406         void                    *internal_object,
407         void                    *external_object,
408         u16                     index,
409         ACPI_GENERIC_STATE      **state_list)
410 {
411         ACPI_GENERIC_STATE       *state;
412
413
414         state = acpi_cm_create_pkg_state (internal_object, external_object, index);
415         if (!state) {
416                 return (AE_NO_MEMORY);
417         }
418
419
420         acpi_cm_push_generic_state (state_list, state);
421         return (AE_OK);
422 }
423
424
425 /*******************************************************************************
426  *
427  * FUNCTION:    Acpi_cm_push_generic_state
428  *
429  * PARAMETERS:  List_head           - Head of the state stack
430  *              State               - State object to push
431  *
432  * RETURN:      Status
433  *
434  * DESCRIPTION: Push a state object onto a state stack
435  *
436  ******************************************************************************/
437
438 void
439 acpi_cm_push_generic_state (
440         ACPI_GENERIC_STATE      **list_head,
441         ACPI_GENERIC_STATE      *state)
442 {
443         /* Push the state object onto the front of the list (stack) */
444
445         state->common.next = *list_head;
446         *list_head = state;
447
448         return;
449 }
450
451
452 /*******************************************************************************
453  *
454  * FUNCTION:    Acpi_cm_pop_generic_state
455  *
456  * PARAMETERS:  List_head           - Head of the state stack
457  *
458  * RETURN:      Status
459  *
460  * DESCRIPTION: Pop a state object from a state stack
461  *
462  ******************************************************************************/
463
464 ACPI_GENERIC_STATE *
465 acpi_cm_pop_generic_state (
466         ACPI_GENERIC_STATE      **list_head)
467 {
468         ACPI_GENERIC_STATE      *state;
469
470
471         /* Remove the state object at the head of the list (stack) */
472
473         state = *list_head;
474         if (state) {
475                 /* Update the list head */
476
477                 *list_head = state->common.next;
478         }
479
480         return (state);
481 }
482
483
484 /*******************************************************************************
485  *
486  * FUNCTION:    Acpi_cm_create_generic_state
487  *
488  * PARAMETERS:  None
489  *
490  * RETURN:      Status
491  *
492  * DESCRIPTION: Create a generic state object.  Attempt to obtain one from
493  *              the global state cache;  If none available, create a new one.
494  *
495  ******************************************************************************/
496
497 ACPI_GENERIC_STATE *
498 acpi_cm_create_generic_state (void)
499 {
500         ACPI_GENERIC_STATE      *state;
501
502
503         acpi_cm_acquire_mutex (ACPI_MTX_CACHES);
504
505         acpi_gbl_state_cache_requests++;
506
507         /* Check the cache first */
508
509         if (acpi_gbl_generic_state_cache) {
510                 /* There is an object available, use it */
511
512                 state = acpi_gbl_generic_state_cache;
513                 acpi_gbl_generic_state_cache = state->common.next;
514                 state->common.next = NULL;
515
516                 acpi_gbl_state_cache_hits++;
517                 acpi_gbl_generic_state_cache_depth--;
518
519                 acpi_cm_release_mutex (ACPI_MTX_CACHES);
520
521         }
522
523         else {
524                 /* The cache is empty, create a new object */
525
526                 acpi_cm_release_mutex (ACPI_MTX_CACHES);
527
528                 state = acpi_cm_callocate (sizeof (ACPI_GENERIC_STATE));
529         }
530
531         /* Initialize */
532
533         if (state) {
534                 /* Always zero out the object before init */
535
536                 MEMSET (state, 0, sizeof (ACPI_GENERIC_STATE));
537
538                 state->common.data_type = ACPI_DESC_TYPE_STATE;
539         }
540
541         return (state);
542 }
543
544
545 /*******************************************************************************
546  *
547  * FUNCTION:    Acpi_cm_create_update_state
548  *
549  * PARAMETERS:  Object              - Initial Object to be installed in the
550  *                                    state
551  *              Action              - Update action to be performed
552  *
553  * RETURN:      Status
554  *
555  * DESCRIPTION: Create an "Update State" - a flavor of the generic state used
556  *              to update reference counts and delete complex objects such
557  *              as packages.
558  *
559  ******************************************************************************/
560
561 ACPI_GENERIC_STATE *
562 acpi_cm_create_update_state (
563         ACPI_OPERAND_OBJECT     *object,
564         u16                     action)
565 {
566         ACPI_GENERIC_STATE      *state;
567
568
569         /* Create the generic state object */
570
571         state = acpi_cm_create_generic_state ();
572         if (!state) {
573                 return (NULL);
574         }
575
576         /* Init fields specific to the update struct */
577
578         state->update.object = object;
579         state->update.value  = action;
580
581         return (state);
582 }
583
584
585 /*******************************************************************************
586  *
587  * FUNCTION:    Acpi_cm_create_pkg_state
588  *
589  * PARAMETERS:  Object              - Initial Object to be installed in the
590  *                                    state
591  *              Action              - Update action to be performed
592  *
593  * RETURN:      Status
594  *
595  * DESCRIPTION: Create an "Update State" - a flavor of the generic state used
596  *              to update reference counts and delete complex objects such
597  *              as packages.
598  *
599  ******************************************************************************/
600
601 ACPI_GENERIC_STATE *
602 acpi_cm_create_pkg_state (
603         void                    *internal_object,
604         void                    *external_object,
605         u16                     index)
606 {
607         ACPI_GENERIC_STATE      *state;
608
609
610         /* Create the generic state object */
611
612         state = acpi_cm_create_generic_state ();
613         if (!state) {
614                 return (NULL);
615         }
616
617         /* Init fields specific to the update struct */
618
619         state->pkg.source_object = (ACPI_OPERAND_OBJECT *) internal_object;
620         state->pkg.dest_object  = external_object;
621         state->pkg.index        = index;
622         state->pkg.num_packages = 1;
623
624         return (state);
625 }
626
627
628 /*******************************************************************************
629  *
630  * FUNCTION:    Acpi_cm_create_control_state
631  *
632  * PARAMETERS:  None
633  *
634  * RETURN:      Status
635  *
636  * DESCRIPTION: Create a "Control State" - a flavor of the generic state used
637  *              to support nested IF/WHILE constructs in the AML.
638  *
639  ******************************************************************************/
640
641 ACPI_GENERIC_STATE *
642 acpi_cm_create_control_state (
643         void)
644 {
645         ACPI_GENERIC_STATE      *state;
646
647
648         /* Create the generic state object */
649
650         state = acpi_cm_create_generic_state ();
651         if (!state) {
652                 return (NULL);
653         }
654
655
656         /* Init fields specific to the control struct */
657
658         state->common.state = CONTROL_CONDITIONAL_EXECUTING;
659
660         return (state);
661 }
662
663
664 /*******************************************************************************
665  *
666  * FUNCTION:    Acpi_cm_delete_generic_state
667  *
668  * PARAMETERS:  State               - The state object to be deleted
669  *
670  * RETURN:      Status
671  *
672  * DESCRIPTION: Put a state object back into the global state cache.  The object
673  *              is not actually freed at this time.
674  *
675  ******************************************************************************/
676
677 void
678 acpi_cm_delete_generic_state (
679         ACPI_GENERIC_STATE      *state)
680 {
681
682         /* If cache is full, just free this state object */
683
684         if (acpi_gbl_generic_state_cache_depth >= MAX_STATE_CACHE_DEPTH) {
685                 acpi_cm_free (state);
686         }
687
688         /* Otherwise put this object back into the cache */
689
690         else {
691                 acpi_cm_acquire_mutex (ACPI_MTX_CACHES);
692
693                 /* Clear the state */
694
695                 MEMSET (state, 0, sizeof (ACPI_GENERIC_STATE));
696                 state->common.data_type = ACPI_DESC_TYPE_STATE;
697
698                 /* Put the object at the head of the global cache list */
699
700                 state->common.next = acpi_gbl_generic_state_cache;
701                 acpi_gbl_generic_state_cache = state;
702                 acpi_gbl_generic_state_cache_depth++;
703
704
705                 acpi_cm_release_mutex (ACPI_MTX_CACHES);
706         }
707         return;
708 }
709
710
711 /*******************************************************************************
712  *
713  * FUNCTION:    Acpi_cm_delete_generic_state_cache
714  *
715  * PARAMETERS:  None
716  *
717  * RETURN:      Status
718  *
719  * DESCRIPTION: Purge the global state object cache.  Used during subsystem
720  *              termination.
721  *
722  ******************************************************************************/
723
724 void
725 acpi_cm_delete_generic_state_cache (
726         void)
727 {
728         ACPI_GENERIC_STATE      *next;
729
730
731         /* Traverse the global cache list */
732
733         while (acpi_gbl_generic_state_cache) {
734                 /* Delete one cached state object */
735
736                 next = acpi_gbl_generic_state_cache->common.next;
737                 acpi_cm_free (acpi_gbl_generic_state_cache);
738                 acpi_gbl_generic_state_cache = next;
739                 acpi_gbl_generic_state_cache_depth--;
740         }
741
742         return;
743 }
744
745
746 /*******************************************************************************
747  *
748  * FUNCTION:    Acpi_cm_resolve_package_references
749  *
750  * PARAMETERS:  Obj_desc        - The Package object on which to resolve refs
751  *
752  * RETURN:      Status
753  *
754  * DESCRIPTION: Walk through a package and turn internal references into values
755  *
756  ******************************************************************************/
757
758 ACPI_STATUS
759 acpi_cm_resolve_package_references (
760         ACPI_OPERAND_OBJECT     *obj_desc)
761 {
762         u32                     count;
763         ACPI_OPERAND_OBJECT     *sub_object;
764
765
766         if (obj_desc->common.type != ACPI_TYPE_PACKAGE) {
767                 /* The object must be a package */
768
769                 REPORT_ERROR (("Must resolve Package Refs on a Package\n"));
770                 return(AE_ERROR);
771         }
772
773         /*
774          * TBD: what about nested packages? */
775
776         for (count = 0; count < obj_desc->package.count; count++) {
777                 sub_object = obj_desc->package.elements[count];
778
779                 if (sub_object->common.type == INTERNAL_TYPE_REFERENCE) {
780                         if (sub_object->reference.opcode == AML_ZERO_OP) {
781                                 sub_object->common.type = ACPI_TYPE_INTEGER;
782                                 sub_object->integer.value = 0;
783                         }
784
785                         else if (sub_object->reference.opcode == AML_ONE_OP) {
786                                 sub_object->common.type = ACPI_TYPE_INTEGER;
787                                 sub_object->integer.value = 1;
788                         }
789
790                         else if (sub_object->reference.opcode == AML_ONES_OP) {
791                                 sub_object->common.type = ACPI_TYPE_INTEGER;
792                                 sub_object->integer.value = ACPI_INTEGER_MAX;
793                         }
794                 }
795         }
796
797         return(AE_OK);
798 }
799
800
801 /*******************************************************************************
802  *
803  * FUNCTION:    Acpi_cm_walk_package_tree
804  *
805  * PARAMETERS:  Obj_desc        - The Package object on which to resolve refs
806  *
807  * RETURN:      Status
808  *
809  * DESCRIPTION: Walk through a package
810  *
811  ******************************************************************************/
812
813 ACPI_STATUS
814 acpi_cm_walk_package_tree (
815         ACPI_OPERAND_OBJECT     *source_object,
816         void                    *target_object,
817         ACPI_PKG_CALLBACK       walk_callback,
818         void                    *context)
819 {
820         ACPI_STATUS             status = AE_OK;
821         ACPI_GENERIC_STATE      *state_list = NULL;
822         ACPI_GENERIC_STATE      *state;
823         u32                     this_index;
824         ACPI_OPERAND_OBJECT     *this_source_obj;
825
826
827         state = acpi_cm_create_pkg_state (source_object, target_object, 0);
828         if (!state) {
829                 return (AE_NO_MEMORY);
830         }
831
832         while (state) {
833                 this_index    = state->pkg.index;
834                 this_source_obj = (ACPI_OPERAND_OBJECT *)
835                                   state->pkg.source_object->package.elements[this_index];
836
837                 /*
838                  * Check for
839                  * 1) An uninitialized package element.  It is completely
840                  *      legal to declare a package and leave it uninitialized
841                  * 2) Not an internal object - can be a namespace node instead
842                  * 3) Any type other than a package.  Packages are handled in else
843                  *      case below.
844                  */
845                 if ((!this_source_obj) ||
846                         (!VALID_DESCRIPTOR_TYPE (
847                                         this_source_obj, ACPI_DESC_TYPE_INTERNAL)) ||
848                         (!IS_THIS_OBJECT_TYPE (
849                                         this_source_obj, ACPI_TYPE_PACKAGE))) {
850
851                         status = walk_callback (ACPI_COPY_TYPE_SIMPLE, this_source_obj,
852                                          state, context);
853                         if (ACPI_FAILURE (status)) {
854                                 /* TBD: must delete package created up to this point */
855
856                                 return (status);
857                         }
858
859                         state->pkg.index++;
860                         while (state->pkg.index >= state->pkg.source_object->package.count) {
861                                 /*
862                                  * We've handled all of the objects at this level,  This means
863                                  * that we have just completed a package.  That package may
864                                  * have contained one or more packages itself.
865                                  *
866                                  * Delete this state and pop the previous state (package).
867                                  */
868                                 acpi_cm_delete_generic_state (state);
869                                 state = acpi_cm_pop_generic_state (&state_list);
870
871
872                                 /* Finished when there are no more states */
873
874                                 if (!state) {
875                                         /*
876                                          * We have handled all of the objects in the top level
877                                          * package just add the length of the package objects
878                                          * and exit
879                                          */
880                                         return (AE_OK);
881                                 }
882
883                                 /*
884                                  * Go back up a level and move the index past the just
885                                  * completed package object.
886                                  */
887                                 state->pkg.index++;
888                         }
889                 }
890
891                 else {
892                         /* This is a sub-object of type package */
893
894                         status = walk_callback (ACPI_COPY_TYPE_PACKAGE, this_source_obj,
895                                           state, context);
896                         if (ACPI_FAILURE (status)) {
897                                 /* TBD: must delete package created up to this point */
898
899                                 return (status);
900                         }
901
902
903                         /*
904                          * The callback above returned a new target package object.
905                          */
906
907                         /*
908                          * Push the current state and create a new one
909                          */
910                         acpi_cm_push_generic_state (&state_list, state);
911                         state = acpi_cm_create_pkg_state (this_source_obj,
912                                            state->pkg.this_target_obj, 0);
913                         if (!state) {
914                                 /* TBD: must delete package created up to this point */
915
916                                 return (AE_NO_MEMORY);
917                         }
918                 }
919         }
920
921         /* We should never get here */
922
923         return (AE_AML_INTERNAL);
924
925 }
926
927
928 /*******************************************************************************
929  *
930  * FUNCTION:    _Report_error
931  *
932  * PARAMETERS:  Module_name         - Caller's module name (for error output)
933  *              Line_number         - Caller's line number (for error output)
934  *              Component_id        - Caller's component ID (for error output)
935  *              Message             - Error message to use on failure
936  *
937  * RETURN:      None
938  *
939  * DESCRIPTION: Print error message
940  *
941  ******************************************************************************/
942
943 void
944 _report_error (
945         NATIVE_CHAR             *module_name,
946         u32                     line_number,
947         u32                     component_id)
948 {
949
950
951         acpi_os_printf ("%8s-%04d: *** Error: ", module_name, line_number);
952 }
953
954
955 /*******************************************************************************
956  *
957  * FUNCTION:    _Report_warning
958  *
959  * PARAMETERS:  Module_name         - Caller's module name (for error output)
960  *              Line_number         - Caller's line number (for error output)
961  *              Component_id        - Caller's component ID (for error output)
962  *              Message             - Error message to use on failure
963  *
964  * RETURN:      None
965  *
966  * DESCRIPTION: Print warning message
967  *
968  ******************************************************************************/
969
970 void
971 _report_warning (
972         NATIVE_CHAR             *module_name,
973         u32                     line_number,
974         u32                     component_id)
975 {
976
977         acpi_os_printf ("%8s-%04d: *** Warning: ", module_name, line_number);
978 }
979
980
981 /*******************************************************************************
982  *
983  * FUNCTION:    _Report_info
984  *
985  * PARAMETERS:  Module_name         - Caller's module name (for error output)
986  *              Line_number         - Caller's line number (for error output)
987  *              Component_id        - Caller's component ID (for error output)
988  *              Message             - Error message to use on failure
989  *
990  * RETURN:      None
991  *
992  * DESCRIPTION: Print information message
993  *
994  ******************************************************************************/
995
996 void
997 _report_info (
998         NATIVE_CHAR             *module_name,
999         u32                     line_number,
1000         u32                     component_id)
1001 {
1002
1003         acpi_os_printf ("%8s-%04d: *** Info: ", module_name, line_number);
1004 }
1005
1006