Print this page
acpica-unix2-20130823
PANKOVs restructure
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/intel/io/acpica/namespace/nswalk.c
+++ new/usr/src/common/acpica/components/namespace/nswalk.c
1 1 /******************************************************************************
2 2 *
3 3 * Module Name: nswalk - Functions for walking the ACPI namespace
4 4 *
5 5 *****************************************************************************/
6 6
7 7 /*
8 - * Copyright (C) 2000 - 2011, Intel Corp.
8 + * Copyright (C) 2000 - 2013, Intel Corp.
9 9 * All rights reserved.
10 10 *
11 11 * Redistribution and use in source and binary forms, with or without
12 12 * modification, are permitted provided that the following conditions
13 13 * are met:
14 14 * 1. Redistributions of source code must retain the above copyright
15 15 * notice, this list of conditions, and the following disclaimer,
16 16 * without modification.
17 17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 18 * substantially similar to the "NO WARRANTY" disclaimer below
19 19 * ("Disclaimer") and any redistribution must be conditioned upon
20 20 * including a substantially similar Disclaimer requirement for further
21 21 * binary redistribution.
22 22 * 3. Neither the names of the above-listed copyright holders nor the names
23 23 * of any contributors may be used to endorse or promote products derived
24 24 * from this software without specific prior written permission.
25 25 *
26 26 * Alternatively, this software may be distributed under the terms of the
27 27 * GNU General Public License ("GPL") version 2 as published by the Free
28 28 * Software Foundation.
29 29 *
30 30 * NO WARRANTY
31 31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 41 * POSSIBILITY OF SUCH DAMAGES.
42 42 */
43 43
44 44
45 45 #define __NSWALK_C__
46 46
47 47 #include "acpi.h"
48 48 #include "accommon.h"
49 49 #include "acnamesp.h"
50 50
51 51
52 52 #define _COMPONENT ACPI_NAMESPACE
53 53 ACPI_MODULE_NAME ("nswalk")
54 54
55 55
56 56 /*******************************************************************************
57 57 *
↓ open down ↓ |
39 lines elided |
↑ open up ↑ |
58 58 * FUNCTION: AcpiNsGetNextNode
59 59 *
60 60 * PARAMETERS: ParentNode - Parent node whose children we are
61 61 * getting
62 62 * ChildNode - Previous child that was found.
63 63 * The NEXT child will be returned
64 64 *
65 65 * RETURN: ACPI_NAMESPACE_NODE - Pointer to the NEXT child or NULL if
66 66 * none is found.
67 67 *
68 - * DESCRIPTION: Return the next peer node within the namespace. If Handle
69 - * is valid, Scope is ignored. Otherwise, the first node
68 + * DESCRIPTION: Return the next peer node within the namespace. If Handle
69 + * is valid, Scope is ignored. Otherwise, the first node
70 70 * within Scope is returned.
71 71 *
72 72 ******************************************************************************/
73 73
74 74 ACPI_NAMESPACE_NODE *
75 75 AcpiNsGetNextNode (
76 76 ACPI_NAMESPACE_NODE *ParentNode,
77 77 ACPI_NAMESPACE_NODE *ChildNode)
78 78 {
79 79 ACPI_FUNCTION_ENTRY ();
80 80
81 81
82 82 if (!ChildNode)
83 83 {
84 84 /* It's really the parent's _scope_ that we want */
85 85
86 86 return (ParentNode->Child);
87 87 }
88 88
89 89 /* Otherwise just return the next peer */
90 90
91 91 return (ChildNode->Peer);
92 92 }
93 93
94 94
95 95 /*******************************************************************************
96 96 *
97 97 * FUNCTION: AcpiNsGetNextNodeTyped
↓ open down ↓ |
18 lines elided |
↑ open up ↑ |
98 98 *
99 99 * PARAMETERS: Type - Type of node to be searched for
100 100 * ParentNode - Parent node whose children we are
101 101 * getting
102 102 * ChildNode - Previous child that was found.
103 103 * The NEXT child will be returned
104 104 *
105 105 * RETURN: ACPI_NAMESPACE_NODE - Pointer to the NEXT child or NULL if
106 106 * none is found.
107 107 *
108 - * DESCRIPTION: Return the next peer node within the namespace. If Handle
109 - * is valid, Scope is ignored. Otherwise, the first node
108 + * DESCRIPTION: Return the next peer node within the namespace. If Handle
109 + * is valid, Scope is ignored. Otherwise, the first node
110 110 * within Scope is returned.
111 111 *
112 112 ******************************************************************************/
113 113
114 114 ACPI_NAMESPACE_NODE *
115 115 AcpiNsGetNextNodeTyped (
116 116 ACPI_OBJECT_TYPE Type,
117 117 ACPI_NAMESPACE_NODE *ParentNode,
118 118 ACPI_NAMESPACE_NODE *ChildNode)
119 119 {
120 120 ACPI_NAMESPACE_NODE *NextNode = NULL;
121 121
122 122
123 123 ACPI_FUNCTION_ENTRY ();
124 124
125 125
126 126 NextNode = AcpiNsGetNextNode (ParentNode, ChildNode);
127 127
128 128 /* If any type is OK, we are done */
129 129
130 130 if (Type == ACPI_TYPE_ANY)
131 131 {
132 132 /* NextNode is NULL if we are at the end-of-list */
133 133
134 134 return (NextNode);
135 135 }
136 136
137 137 /* Must search for the node -- but within this scope only */
138 138
139 139 while (NextNode)
140 140 {
141 141 /* If type matches, we are done */
142 142
143 143 if (NextNode->Type == Type)
144 144 {
145 145 return (NextNode);
146 146 }
147 147
148 148 /* Otherwise, move on to the next peer node */
149 149
150 150 NextNode = NextNode->Peer;
151 151 }
152 152
153 153 /* Not found */
154 154
155 155 return (NULL);
156 156 }
157 157
↓ open down ↓ |
38 lines elided |
↑ open up ↑ |
158 158
159 159 /*******************************************************************************
160 160 *
161 161 * FUNCTION: AcpiNsWalkNamespace
162 162 *
163 163 * PARAMETERS: Type - ACPI_OBJECT_TYPE to search for
164 164 * StartNode - Handle in namespace where search begins
165 165 * MaxDepth - Depth to which search is to reach
166 166 * Flags - Whether to unlock the NS before invoking
167 167 * the callback routine
168 - * PreOrderVisit - Called during tree pre-order visit
168 + * DescendingCallback - Called during tree descent
169 169 * when an object of "Type" is found
170 - * PostOrderVisit - Called during tree post-order visit
170 + * AscendingCallback - Called during tree ascent
171 171 * when an object of "Type" is found
172 172 * Context - Passed to user function(s) above
173 173 * ReturnValue - from the UserFunction if terminated
174 174 * early. Otherwise, returns NULL.
175 175 * RETURNS: Status
176 176 *
177 177 * DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
178 178 * starting (and ending) at the node specified by StartHandle.
179 179 * The callback function is called whenever a node that matches
180 180 * the type parameter is found. If the callback function returns
181 181 * a non-zero value, the search is terminated immediately and
182 182 * this value is returned to the caller.
183 183 *
184 184 * The point of this procedure is to provide a generic namespace
185 185 * walk routine that can be called from multiple places to
186 186 * provide multiple services; the callback function(s) can be
187 187 * tailored to each task, whether it is a print function,
↓ open down ↓ |
7 lines elided |
↑ open up ↑ |
188 188 * a compare function, etc.
189 189 *
190 190 ******************************************************************************/
191 191
192 192 ACPI_STATUS
193 193 AcpiNsWalkNamespace (
194 194 ACPI_OBJECT_TYPE Type,
195 195 ACPI_HANDLE StartNode,
196 196 UINT32 MaxDepth,
197 197 UINT32 Flags,
198 - ACPI_WALK_CALLBACK PreOrderVisit,
199 - ACPI_WALK_CALLBACK PostOrderVisit,
198 + ACPI_WALK_CALLBACK DescendingCallback,
199 + ACPI_WALK_CALLBACK AscendingCallback,
200 200 void *Context,
201 201 void **ReturnValue)
202 202 {
203 203 ACPI_STATUS Status;
204 204 ACPI_STATUS MutexStatus;
205 205 ACPI_NAMESPACE_NODE *ChildNode;
206 206 ACPI_NAMESPACE_NODE *ParentNode;
207 207 ACPI_OBJECT_TYPE ChildType;
208 208 UINT32 Level;
209 209 BOOLEAN NodePreviouslyVisited = FALSE;
210 210
211 211
212 212 ACPI_FUNCTION_TRACE (NsWalkNamespace);
213 213
214 214
215 215 /* Special case for the namespace Root Node */
216 216
217 217 if (StartNode == ACPI_ROOT_OBJECT)
218 218 {
219 219 StartNode = AcpiGbl_RootNode;
220 220 }
221 221
222 222 /* Null child means "get first node" */
223 223
224 224 ParentNode = StartNode;
225 225 ChildNode = AcpiNsGetNextNode (ParentNode, NULL);
226 226 ChildType = ACPI_TYPE_ANY;
227 227 Level = 1;
228 228
229 229 /*
230 230 * Traverse the tree of nodes until we bubble back up to where we
231 231 * started. When Level is zero, the loop is done because we have
232 232 * bubbled up to (and passed) the original parent handle (StartEntry)
233 233 */
234 234 while (Level > 0 && ChildNode)
235 235 {
236 236 Status = AE_OK;
237 237
238 238 /* Found next child, get the type if we are not searching for ANY */
239 239
240 240 if (Type != ACPI_TYPE_ANY)
241 241 {
242 242 ChildType = ChildNode->Type;
243 243 }
244 244
245 245 /*
246 246 * Ignore all temporary namespace nodes (created during control
247 247 * method execution) unless told otherwise. These temporary nodes
248 248 * can cause a race condition because they can be deleted during
249 249 * the execution of the user function (if the namespace is
250 250 * unlocked before invocation of the user function.) Only the
251 251 * debugger namespace dump will examine the temporary nodes.
252 252 */
253 253 if ((ChildNode->Flags & ANOBJ_TEMPORARY) &&
254 254 !(Flags & ACPI_NS_WALK_TEMP_NODES))
255 255 {
256 256 Status = AE_CTRL_DEPTH;
257 257 }
258 258
259 259 /* Type must match requested type */
260 260
261 261 else if (ChildType == Type)
262 262 {
263 263 /*
264 264 * Found a matching node, invoke the user callback function.
265 265 * Unlock the namespace if flag is set.
266 266 */
↓ open down ↓ |
57 lines elided |
↑ open up ↑ |
267 267 if (Flags & ACPI_NS_WALK_UNLOCK)
268 268 {
269 269 MutexStatus = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
270 270 if (ACPI_FAILURE (MutexStatus))
271 271 {
272 272 return_ACPI_STATUS (MutexStatus);
273 273 }
274 274 }
275 275
276 276 /*
277 - * Invoke the user function, either pre-order or post-order
277 + * Invoke the user function, either descending, ascending,
278 278 * or both.
279 279 */
280 280 if (!NodePreviouslyVisited)
281 281 {
282 - if (PreOrderVisit)
282 + if (DescendingCallback)
283 283 {
284 - Status = PreOrderVisit (ChildNode, Level,
284 + Status = DescendingCallback (ChildNode, Level,
285 285 Context, ReturnValue);
286 286 }
287 287 }
288 288 else
289 289 {
290 - if (PostOrderVisit)
290 + if (AscendingCallback)
291 291 {
292 - Status = PostOrderVisit (ChildNode, Level,
292 + Status = AscendingCallback (ChildNode, Level,
293 293 Context, ReturnValue);
294 294 }
295 295 }
296 296
297 297 if (Flags & ACPI_NS_WALK_UNLOCK)
298 298 {
299 299 MutexStatus = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
300 300 if (ACPI_FAILURE (MutexStatus))
301 301 {
302 302 return_ACPI_STATUS (MutexStatus);
303 303 }
304 304 }
305 305
306 306 switch (Status)
307 307 {
308 308 case AE_OK:
309 309 case AE_CTRL_DEPTH:
310 310
311 311 /* Just keep going */
312 312 break;
313 313
314 314 case AE_CTRL_TERMINATE:
315 315
316 316 /* Exit now, with OK status */
317 317
318 318 return_ACPI_STATUS (AE_OK);
319 319
↓ open down ↓ |
17 lines elided |
↑ open up ↑ |
320 320 default:
321 321
322 322 /* All others are valid exceptions */
323 323
324 324 return_ACPI_STATUS (Status);
325 325 }
326 326 }
327 327
328 328 /*
329 329 * Depth first search: Attempt to go down another level in the
330 - * namespace if we are allowed to. Don't go any further if we have
330 + * namespace if we are allowed to. Don't go any further if we have
331 331 * reached the caller specified maximum depth or if the user
332 332 * function has specified that the maximum depth has been reached.
333 333 */
334 334 if (!NodePreviouslyVisited &&
335 335 (Level < MaxDepth) &&
336 336 (Status != AE_CTRL_DEPTH))
337 337 {
338 338 if (ChildNode->Child)
339 339 {
340 340 /* There is at least one child of this node, visit it */
341 341
342 342 Level++;
343 343 ParentNode = ChildNode;
344 344 ChildNode = AcpiNsGetNextNode (ParentNode, NULL);
345 345 continue;
346 346 }
347 347 }
348 348
349 349 /* No more children, re-visit this node */
350 350
351 351 if (!NodePreviouslyVisited)
352 352 {
353 353 NodePreviouslyVisited = TRUE;
354 354 continue;
355 355 }
356 356
357 357 /* No more children, visit peers */
358 358
359 359 ChildNode = AcpiNsGetNextNode (ParentNode, ChildNode);
360 360 if (ChildNode)
361 361 {
362 362 NodePreviouslyVisited = FALSE;
363 363 }
364 364
365 365 /* No peers, re-visit parent */
366 366
367 367 else
368 368 {
369 369 /*
370 370 * No more children of this node (AcpiNsGetNextNode failed), go
371 371 * back upwards in the namespace tree to the node's parent.
372 372 */
373 373 Level--;
374 374 ChildNode = ParentNode;
↓ open down ↓ |
34 lines elided |
↑ open up ↑ |
375 375 ParentNode = ParentNode->Parent;
376 376
377 377 NodePreviouslyVisited = TRUE;
378 378 }
379 379 }
380 380
381 381 /* Complete walk, not terminated by user function */
382 382
383 383 return_ACPI_STATUS (AE_OK);
384 384 }
385 -
386 -
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX