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