1 /******************************************************************************
2 *
3 * Module Name: nswalk - Functions for walking the ACPI namespace
4 *
5 *****************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2011, Intel Corp.
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.
148 /* Otherwise, move on to the next peer node */
149
150 NextNode = NextNode->Peer;
151 }
152
153 /* Not found */
154
155 return (NULL);
156 }
157
158
159 /*******************************************************************************
160 *
161 * FUNCTION: AcpiNsWalkNamespace
162 *
163 * PARAMETERS: Type - ACPI_OBJECT_TYPE to search for
164 * StartNode - Handle in namespace where search begins
165 * MaxDepth - Depth to which search is to reach
166 * Flags - Whether to unlock the NS before invoking
167 * the callback routine
168 * PreOrderVisit - Called during tree pre-order visit
169 * when an object of "Type" is found
170 * PostOrderVisit - Called during tree post-order visit
171 * when an object of "Type" is found
172 * Context - Passed to user function(s) above
173 * ReturnValue - from the UserFunction if terminated
174 * early. Otherwise, returns NULL.
175 * RETURNS: Status
176 *
177 * DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
178 * starting (and ending) at the node specified by StartHandle.
179 * The callback function is called whenever a node that matches
180 * the type parameter is found. If the callback function returns
181 * a non-zero value, the search is terminated immediately and
182 * this value is returned to the caller.
183 *
184 * The point of this procedure is to provide a generic namespace
185 * walk routine that can be called from multiple places to
186 * provide multiple services; the callback function(s) can be
187 * tailored to each task, whether it is a print function,
188 * a compare function, etc.
189 *
190 ******************************************************************************/
191
192 ACPI_STATUS
193 AcpiNsWalkNamespace (
194 ACPI_OBJECT_TYPE Type,
195 ACPI_HANDLE StartNode,
196 UINT32 MaxDepth,
197 UINT32 Flags,
198 ACPI_WALK_CALLBACK PreOrderVisit,
199 ACPI_WALK_CALLBACK PostOrderVisit,
200 void *Context,
201 void **ReturnValue)
202 {
203 ACPI_STATUS Status;
204 ACPI_STATUS MutexStatus;
205 ACPI_NAMESPACE_NODE *ChildNode;
206 ACPI_NAMESPACE_NODE *ParentNode;
207 ACPI_OBJECT_TYPE ChildType;
208 UINT32 Level;
209 BOOLEAN NodePreviouslyVisited = FALSE;
210
211
212 ACPI_FUNCTION_TRACE (NsWalkNamespace);
213
214
215 /* Special case for the namespace Root Node */
216
217 if (StartNode == ACPI_ROOT_OBJECT)
218 {
219 StartNode = AcpiGbl_RootNode;
257 }
258
259 /* Type must match requested type */
260
261 else if (ChildType == Type)
262 {
263 /*
264 * Found a matching node, invoke the user callback function.
265 * Unlock the namespace if flag is set.
266 */
267 if (Flags & ACPI_NS_WALK_UNLOCK)
268 {
269 MutexStatus = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
270 if (ACPI_FAILURE (MutexStatus))
271 {
272 return_ACPI_STATUS (MutexStatus);
273 }
274 }
275
276 /*
277 * Invoke the user function, either pre-order or post-order
278 * or both.
279 */
280 if (!NodePreviouslyVisited)
281 {
282 if (PreOrderVisit)
283 {
284 Status = PreOrderVisit (ChildNode, Level,
285 Context, ReturnValue);
286 }
287 }
288 else
289 {
290 if (PostOrderVisit)
291 {
292 Status = PostOrderVisit (ChildNode, Level,
293 Context, ReturnValue);
294 }
295 }
296
297 if (Flags & ACPI_NS_WALK_UNLOCK)
298 {
299 MutexStatus = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
300 if (ACPI_FAILURE (MutexStatus))
301 {
302 return_ACPI_STATUS (MutexStatus);
303 }
304 }
305
306 switch (Status)
307 {
308 case AE_OK:
309 case AE_CTRL_DEPTH:
310
311 /* Just keep going */
312 break;
365 /* No peers, re-visit parent */
366
367 else
368 {
369 /*
370 * No more children of this node (AcpiNsGetNextNode failed), go
371 * back upwards in the namespace tree to the node's parent.
372 */
373 Level--;
374 ChildNode = ParentNode;
375 ParentNode = ParentNode->Parent;
376
377 NodePreviouslyVisited = TRUE;
378 }
379 }
380
381 /* Complete walk, not terminated by user function */
382
383 return_ACPI_STATUS (AE_OK);
384 }
385
386
|
1 /******************************************************************************
2 *
3 * Module Name: nswalk - Functions for walking the ACPI namespace
4 *
5 *****************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2013, Intel Corp.
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.
148 /* Otherwise, move on to the next peer node */
149
150 NextNode = NextNode->Peer;
151 }
152
153 /* Not found */
154
155 return (NULL);
156 }
157
158
159 /*******************************************************************************
160 *
161 * FUNCTION: AcpiNsWalkNamespace
162 *
163 * PARAMETERS: Type - ACPI_OBJECT_TYPE to search for
164 * StartNode - Handle in namespace where search begins
165 * MaxDepth - Depth to which search is to reach
166 * Flags - Whether to unlock the NS before invoking
167 * the callback routine
168 * DescendingCallback - Called during tree descent
169 * when an object of "Type" is found
170 * AscendingCallback - Called during tree ascent
171 * when an object of "Type" is found
172 * Context - Passed to user function(s) above
173 * ReturnValue - from the UserFunction if terminated
174 * early. Otherwise, returns NULL.
175 * RETURNS: Status
176 *
177 * DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
178 * starting (and ending) at the node specified by StartHandle.
179 * The callback function is called whenever a node that matches
180 * the type parameter is found. If the callback function returns
181 * a non-zero value, the search is terminated immediately and
182 * this value is returned to the caller.
183 *
184 * The point of this procedure is to provide a generic namespace
185 * walk routine that can be called from multiple places to
186 * provide multiple services; the callback function(s) can be
187 * tailored to each task, whether it is a print function,
188 * a compare function, etc.
189 *
190 ******************************************************************************/
191
192 ACPI_STATUS
193 AcpiNsWalkNamespace (
194 ACPI_OBJECT_TYPE Type,
195 ACPI_HANDLE StartNode,
196 UINT32 MaxDepth,
197 UINT32 Flags,
198 ACPI_WALK_CALLBACK DescendingCallback,
199 ACPI_WALK_CALLBACK AscendingCallback,
200 void *Context,
201 void **ReturnValue)
202 {
203 ACPI_STATUS Status;
204 ACPI_STATUS MutexStatus;
205 ACPI_NAMESPACE_NODE *ChildNode;
206 ACPI_NAMESPACE_NODE *ParentNode;
207 ACPI_OBJECT_TYPE ChildType;
208 UINT32 Level;
209 BOOLEAN NodePreviouslyVisited = FALSE;
210
211
212 ACPI_FUNCTION_TRACE (NsWalkNamespace);
213
214
215 /* Special case for the namespace Root Node */
216
217 if (StartNode == ACPI_ROOT_OBJECT)
218 {
219 StartNode = AcpiGbl_RootNode;
257 }
258
259 /* Type must match requested type */
260
261 else if (ChildType == Type)
262 {
263 /*
264 * Found a matching node, invoke the user callback function.
265 * Unlock the namespace if flag is set.
266 */
267 if (Flags & ACPI_NS_WALK_UNLOCK)
268 {
269 MutexStatus = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
270 if (ACPI_FAILURE (MutexStatus))
271 {
272 return_ACPI_STATUS (MutexStatus);
273 }
274 }
275
276 /*
277 * Invoke the user function, either descending, ascending,
278 * or both.
279 */
280 if (!NodePreviouslyVisited)
281 {
282 if (DescendingCallback)
283 {
284 Status = DescendingCallback (ChildNode, Level,
285 Context, ReturnValue);
286 }
287 }
288 else
289 {
290 if (AscendingCallback)
291 {
292 Status = AscendingCallback (ChildNode, Level,
293 Context, ReturnValue);
294 }
295 }
296
297 if (Flags & ACPI_NS_WALK_UNLOCK)
298 {
299 MutexStatus = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
300 if (ACPI_FAILURE (MutexStatus))
301 {
302 return_ACPI_STATUS (MutexStatus);
303 }
304 }
305
306 switch (Status)
307 {
308 case AE_OK:
309 case AE_CTRL_DEPTH:
310
311 /* Just keep going */
312 break;
365 /* No peers, re-visit parent */
366
367 else
368 {
369 /*
370 * No more children of this node (AcpiNsGetNextNode failed), go
371 * back upwards in the namespace tree to the node's parent.
372 */
373 Level--;
374 ChildNode = ParentNode;
375 ParentNode = ParentNode->Parent;
376
377 NodePreviouslyVisited = TRUE;
378 }
379 }
380
381 /* Complete walk, not terminated by user function */
382
383 return_ACPI_STATUS (AE_OK);
384 }
|