3 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
5 * @APPLE_LICENSE_HEADER_START@
7 * The contents of this file constitute Original Code as defined in and
8 * are subject to the Apple Public Source License Version 1.1 (the
9 * "License"). You may not use this file except in compliance with the
10 * License. Please obtain a copy of the License at
11 * http://www.apple.com/publicsource and read it before using this file.
13 * This Original Code and all software distributed under the License are
14 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
18 * License for the specific language governing rights and limitations
21 * @APPLE_LICENSE_HEADER_END@
23 #ifndef _PEXPERT_DEVICE_TREE_H_
24 #define _PEXPERT_DEVICE_TREE_H_
26 #include <sys/appleapiopts.h>
28 #ifdef __APPLE_API_PRIVATE
35 -------------------------------------------------------------------------------
37 -------------------------------------------------------------------------------
40 kDTPathNameSeparator
= '/' /* 0x2F */
44 /* Property Name Definitions (Property Names are C-Strings)*/
46 kDTMaxPropertyNameLength
=31 /* Max length of Property Name (terminator not included) */
49 typedef char DTPropertyNameBuf
[32];
52 /* Entry Name Definitions (Entry Names are C-Strings)*/
54 kDTMaxEntryNameLength
= 31 /* Max length of a C-String Entry Name (terminator not included) */
57 /* length of DTEntryNameBuf = kDTMaxEntryNameLength +1*/
58 typedef char DTEntryNameBuf
[32];
62 typedef struct OpaqueDTEntry
* DTEntry
;
65 typedef struct OpaqueDTEntryIterator
* DTEntryIterator
;
67 /* Property Iterator*/
68 typedef struct OpaqueDTPropertyIterator
* DTPropertyIterator
;
80 Structures for a Flattened Device Tree
83 #define kPropNameLength 32
85 typedef struct DeviceTreeNodeProperty
{
86 char name
[kPropNameLength
]; // NUL terminated property name
87 unsigned long length
; // Length (bytes) of folloing prop value
88 // unsigned long value[1]; // Variable length value of property
89 // Padded to a multiple of a longword?
90 } DeviceTreeNodeProperty
;
92 typedef struct OpaqueDTEntry
{
93 unsigned long nProperties
; // Number of props[] elements (0 => end)
94 unsigned long nChildren
; // Number of children[] elements
95 // DeviceTreeNodeProperty props[];// array size == nProperties
96 // DeviceTreeNode children[]; // array size == nChildren
102 -------------------------------------------------------------------------------
104 -------------------------------------------------------------------------------
107 /* Used to initalize the device tree functions. */
108 /* base is the base address of the flatened device tree */
109 void DTInit(void *base
);
112 -------------------------------------------------------------------------------
114 -------------------------------------------------------------------------------
116 /* Compare two Entry's for equality. */
117 extern int DTEntryIsEqual(const DTEntry ref1
, const DTEntry ref2
);
120 -------------------------------------------------------------------------------
122 -------------------------------------------------------------------------------
126 Find the device tree entry that contains propName=propValue.
127 It currently searches the entire
128 tree. This function should eventually go in DeviceTree.c.
129 Returns: kSuccess = entry was found. Entry is in entryH.
130 kError = entry was not found
132 extern int DTFindEntry(const char *propName
, const char *propValue
, DTEntry
*entryH
);
136 Locates an entry given a specified subroot (searchPoint) and path name. If the
137 searchPoint pointer is NULL, the path name is assumed to be an absolute path
138 name rooted to the root of the device tree.
140 extern int DTLookupEntry(const DTEntry searchPoint
, const char *pathName
, DTEntry
*foundEntry
);
143 -------------------------------------------------------------------------------
145 -------------------------------------------------------------------------------
148 An Entry Iterator maintains three variables that are of interest to clients.
149 First is an "OutermostScope" which defines the outer boundry of the iteration.
150 This is defined by the starting entry and includes that entry plus all of it's
151 embedded entries. Second is a "currentScope" which is the entry the iterator is
152 currently in. And third is a "currentPosition" which is the last entry returned
155 Create Entry Iterator
156 Create the iterator structure. The outermostScope and currentScope of the iterator
157 are set to "startEntry". If "startEntry" = NULL, the outermostScope and
158 currentScope are set to the root entry. The currentPosition for the iterator is
161 extern int DTCreateEntryIterator(const DTEntry startEntry
, DTEntryIterator
*iterator
);
163 /* Dispose Entry Iterator*/
164 extern int DTDisposeEntryIterator(DTEntryIterator iterator
);
168 Move an Entry Iterator into the scope of a specified child entry. The
169 currentScope of the iterator is set to the entry specified in "childEntry". If
170 "childEntry" is nil, the currentScope is set to the entry specified by the
171 currentPosition of the iterator.
173 extern int DTEnterEntry(DTEntryIterator iterator
, DTEntry childEntry
);
177 Move an Entry Iterator out of the current entry back into the scope of it's parent
178 entry. The currentPosition of the iterator is reset to the current entry (the
179 previous currentScope), so the next iteration call will continue where it left off.
180 This position is returned in parameter "currentPosition".
182 extern int DTExitEntry(DTEntryIterator iterator
, DTEntry
*currentPosition
);
186 Iterate and return entries contained within the entry defined by the current
187 scope of the iterator. Entries are returned one at a time. When
188 int == kIterationDone, all entries have been exhausted, and the
189 value of nextEntry will be Nil.
191 extern int DTIterateEntries(DTEntryIterator iterator
, DTEntry
*nextEntry
);
194 Restart Entry Iteration
195 Restart an iteration within the current scope. The iterator is reset such that
196 iteration of the contents of the currentScope entry can be restarted. The
197 outermostScope and currentScope of the iterator are unchanged. The currentPosition
198 for the iterator is set to "nil".
200 extern int DTRestartEntryIteration(DTEntryIterator iterator
);
203 -------------------------------------------------------------------------------
205 -------------------------------------------------------------------------------
208 Get the value of the specified property for the specified entry.
212 extern int DTGetProperty(const DTEntry entry
, const char *propertyName
, void **propertyValue
, int *propertySize
);
215 -------------------------------------------------------------------------------
217 -------------------------------------------------------------------------------
220 Create Property Iterator
221 Create the property iterator structure. The target entry is defined by entry.
224 extern int DTCreatePropertyIterator(const DTEntry entry
,
225 DTPropertyIterator
*iterator
);
227 /* Dispose Property Iterator*/
228 extern int DTDisposePropertyIterator(DTPropertyIterator iterator
);
232 Iterate and return properties for given entry.
233 When int == kIterationDone, all properties have been exhausted.
236 extern int DTIterateProperties(DTPropertyIterator iterator
,
237 char **foundProperty
);
240 Restart Property Iteration
241 Used to re-iterate over a list of properties. The Property Iterator is
242 reset to the beginning of the list of properties for an entry.
245 extern int DTRestartPropertyIteration(DTPropertyIterator iterator
);
251 #endif /* __MWERKS__ */
253 #endif /* __APPLE_API_PRIVATE */
255 #endif /* _PEXPERT_DEVICE_TREE_H_ */