:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[reactos.git] / drivers / bus / acpi / dispatcher / dswscope.c
1 /******************************************************************************
2  *
3  * Module Name: dswscope - Scope stack manipulation
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 "acinterp.h"
29 #include "acdispat.h"
30
31
32 #define _COMPONENT          ACPI_DISPATCHER
33          MODULE_NAME         ("dswscope")
34
35
36 #define STACK_POP(head) head
37
38
39 /****************************************************************************
40  *
41  * FUNCTION:    Acpi_ds_scope_stack_clear
42  *
43  * PARAMETERS:  None
44  *
45  * DESCRIPTION: Pop (and free) everything on the scope stack except the
46  *              root scope object (which remains at the stack top.)
47  *
48  ***************************************************************************/
49
50 void
51 acpi_ds_scope_stack_clear (
52         ACPI_WALK_STATE         *walk_state)
53 {
54         ACPI_GENERIC_STATE      *scope_info;
55
56
57         while (walk_state->scope_info) {
58                 /* Pop a scope off the stack */
59
60                 scope_info = walk_state->scope_info;
61                 walk_state->scope_info = scope_info->scope.next;
62
63                 acpi_cm_delete_generic_state (scope_info);
64         }
65 }
66
67
68 /****************************************************************************
69  *
70  * FUNCTION:    Acpi_ds_scope_stack_push
71  *
72  * PARAMETERS:  *Node,              - Name to be made current
73  *              Type,               - Type of frame being pushed
74  *
75  * DESCRIPTION: Push the current scope on the scope stack, and make the
76  *              passed Node current.
77  *
78  ***************************************************************************/
79
80 ACPI_STATUS
81 acpi_ds_scope_stack_push (
82         ACPI_NAMESPACE_NODE     *node,
83         OBJECT_TYPE_INTERNAL    type,
84         ACPI_WALK_STATE         *walk_state)
85 {
86         ACPI_GENERIC_STATE      *scope_info;
87
88
89         if (!node) {
90                 /*  invalid scope   */
91
92                 REPORT_ERROR (("Ds_scope_stack_push: null scope passed\n"));
93                 return (AE_BAD_PARAMETER);
94         }
95
96         /* Make sure object type is valid */
97
98         if (!acpi_aml_validate_object_type (type)) {
99                 REPORT_WARNING (("Ds_scope_stack_push: type code out of range\n"));
100         }
101
102
103         /* Allocate a new scope object */
104
105         scope_info = acpi_cm_create_generic_state ();
106         if (!scope_info) {
107                 return (AE_NO_MEMORY);
108         }
109
110         /* Init new scope object */
111
112         scope_info->scope.node = node;
113         scope_info->common.value = (u16) type;
114
115         /* Push new scope object onto stack */
116
117         acpi_cm_push_generic_state (&walk_state->scope_info, scope_info);
118
119         return (AE_OK);
120 }
121
122
123 /****************************************************************************
124  *
125  * FUNCTION:    Acpi_ds_scope_stack_pop
126  *
127  * PARAMETERS:  Type                - The type of frame to be found
128  *
129  * DESCRIPTION: Pop the scope stack until a frame of the requested type
130  *              is found.
131  *
132  * RETURN:      Count of frames popped.  If no frame of the requested type
133  *              was found, the count is returned as a negative number and
134  *              the scope stack is emptied (which sets the current scope
135  *              to the root).  If the scope stack was empty at entry, the
136  *              function is a no-op and returns 0.
137  *
138  ***************************************************************************/
139
140 ACPI_STATUS
141 acpi_ds_scope_stack_pop (
142         ACPI_WALK_STATE         *walk_state)
143 {
144         ACPI_GENERIC_STATE      *scope_info;
145
146
147         /*
148          * Pop scope info object off the stack.
149          */
150
151         scope_info = acpi_cm_pop_generic_state (&walk_state->scope_info);
152         if (!scope_info) {
153                 return (AE_STACK_UNDERFLOW);
154         }
155
156         acpi_cm_delete_generic_state (scope_info);
157
158         return (AE_OK);
159 }
160
161