2 * Copyright 2003-2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 #include <platform/openfirmware/devices.h>
7 #include <platform/openfirmware/openfirmware.h>
8 #include <util/kernel_cpp.h>
13 /** Gets all device types of the specified type by doing a
14 * depth-first search of the OpenFirmware device tree.
15 * If a root != 0 is given, the function only traverses the subtree spanned
16 * by the root (inclusively). Otherwise the whole device tree is searched.
18 * The cookie has to be initialized to zero.
21 of_get_next_device(int *_cookie
, int root
, const char *type
, char *path
,
30 // node is NULL, meaning that this is the initial function call.
31 // If a root was supplied, we take that, otherwise the device tree
38 if (node
== OF_FAILED
)
41 return B_ENTRY_NOT_FOUND
;
43 // We want to visit the root first.
46 next
= of_child(node
);
48 if (next
== OF_FAILED
)
52 // no child node found
54 if (next
== OF_FAILED
)
58 // no peer node found, we are using the device
59 // tree itself as our search stack
61 next
= of_parent(node
);
62 if (next
== OF_FAILED
)
65 if (next
== root
|| next
== 0) {
66 // We have searched the whole device tree
67 return B_ENTRY_NOT_FOUND
;
70 // look into the next tree
76 *_cookie
= node
= next
;
80 if (of_getprop(node
, "device_type", nodeType
, sizeof(nodeType
))
82 || strcmp(nodeType
, type
)
83 || (length
= of_package_to_path(node
, path
, pathSize
- 1))