2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 #ifndef _PEXPERT_DEVICE_TREE_H_
23 #define _PEXPERT_DEVICE_TREE_H_
27 -------------------------------------------------------------------------------
29 -------------------------------------------------------------------------------
32 kDTPathNameSeparator
= '/' /* 0x2F */
36 /* Property Name Definitions (Property Names are C-Strings)*/
38 kDTMaxPropertyNameLength
=31 /* Max length of Property Name (terminator not included) */
41 typedef char DTPropertyNameBuf
[32];
44 /* Entry Name Definitions (Entry Names are C-Strings)*/
46 kDTMaxEntryNameLength
= 31 /* Max length of a C-String Entry Name (terminator not included) */
49 /* length of DTEntryNameBuf = kDTMaxEntryNameLength +1*/
50 typedef char DTEntryNameBuf
[32];
54 typedef struct OpaqueDTEntry
* DTEntry
;
57 typedef struct OpaqueDTEntryIterator
* DTEntryIterator
;
59 /* Property Iterator*/
60 typedef struct OpaqueDTPropertyIterator
* DTPropertyIterator
;
72 Structures for a Flattened Device Tree
75 #define kPropNameLength 32
77 typedef struct DeviceTreeNodeProperty
{
78 char name
[kPropNameLength
]; // NUL terminated property name
79 unsigned long length
; // Length (bytes) of folloing prop value
80 // unsigned long value[1]; // Variable length value of property
81 // Padded to a multiple of a longword?
82 } DeviceTreeNodeProperty
;
84 typedef struct OpaqueDTEntry
{
85 unsigned long nProperties
; // Number of props[] elements (0 => end)
86 unsigned long nChildren
; // Number of children[] elements
87 // DeviceTreeNodeProperty props[];// array size == nProperties
88 // DeviceTreeNode children[]; // array size == nChildren
94 -------------------------------------------------------------------------------
96 -------------------------------------------------------------------------------
99 /* Used to initalize the device tree functions. */
100 /* base is the base address of the flatened device tree */
101 void DTInit(void *base
);
104 -------------------------------------------------------------------------------
106 -------------------------------------------------------------------------------
108 /* Compare two Entry's for equality. */
109 extern int DTEntryIsEqual(const DTEntry ref1
, const DTEntry ref2
);
112 -------------------------------------------------------------------------------
114 -------------------------------------------------------------------------------
118 Find the device tree entry that contains propName=propValue.
119 It currently searches the entire
120 tree. This function should eventually go in DeviceTree.c.
121 Returns: kSuccess = entry was found. Entry is in entryH.
122 kError = entry was not found
124 extern int DTFindEntry(const char *propName
, const char *propValue
, DTEntry
*entryH
);
128 Locates an entry given a specified subroot (searchPoint) and path name. If the
129 searchPoint pointer is NULL, the path name is assumed to be an absolute path
130 name rooted to the root of the device tree.
132 extern int DTLookupEntry(const DTEntry searchPoint
, const char *pathName
, DTEntry
*foundEntry
);
135 -------------------------------------------------------------------------------
137 -------------------------------------------------------------------------------
140 An Entry Iterator maintains three variables that are of interest to clients.
141 First is an "OutermostScope" which defines the outer boundry of the iteration.
142 This is defined by the starting entry and includes that entry plus all of it's
143 embedded entries. Second is a "currentScope" which is the entry the iterator is
144 currently in. And third is a "currentPosition" which is the last entry returned
147 Create Entry Iterator
148 Create the iterator structure. The outermostScope and currentScope of the iterator
149 are set to "startEntry". If "startEntry" = NULL, the outermostScope and
150 currentScope are set to the root entry. The currentPosition for the iterator is
153 extern int DTCreateEntryIterator(const DTEntry startEntry
, DTEntryIterator
*iterator
);
155 /* Dispose Entry Iterator*/
156 extern int DTDisposeEntryIterator(DTEntryIterator iterator
);
160 Move an Entry Iterator into the scope of a specified child entry. The
161 currentScope of the iterator is set to the entry specified in "childEntry". If
162 "childEntry" is nil, the currentScope is set to the entry specified by the
163 currentPosition of the iterator.
165 extern int DTEnterEntry(DTEntryIterator iterator
, DTEntry childEntry
);
169 Move an Entry Iterator out of the current entry back into the scope of it's parent
170 entry. The currentPosition of the iterator is reset to the current entry (the
171 previous currentScope), so the next iteration call will continue where it left off.
172 This position is returned in parameter "currentPosition".
174 extern int DTExitEntry(DTEntryIterator iterator
, DTEntry
*currentPosition
);
178 Iterate and return entries contained within the entry defined by the current
179 scope of the iterator. Entries are returned one at a time. When
180 int == kIterationDone, all entries have been exhausted, and the
181 value of nextEntry will be Nil.
183 extern int DTIterateEntries(DTEntryIterator iterator
, DTEntry
*nextEntry
);
186 Restart Entry Iteration
187 Restart an iteration within the current scope. The iterator is reset such that
188 iteration of the contents of the currentScope entry can be restarted. The
189 outermostScope and currentScope of the iterator are unchanged. The currentPosition
190 for the iterator is set to "nil".
192 extern int DTRestartEntryIteration(DTEntryIterator iterator
);
195 -------------------------------------------------------------------------------
197 -------------------------------------------------------------------------------
200 Get the value of the specified property for the specified entry.
204 extern int DTGetProperty(const DTEntry entry
, const char *propertyName
, void **propertyValue
, int *propertySize
);
207 -------------------------------------------------------------------------------
209 -------------------------------------------------------------------------------
212 Create Property Iterator
213 Create the property iterator structure. The target entry is defined by entry.
216 extern int DTCreatePropertyIterator(const DTEntry entry
,
217 DTPropertyIterator
*iterator
);
219 /* Dispose Property Iterator*/
220 extern int DTDisposePropertyIterator(DTPropertyIterator iterator
);
224 Iterate and return properties for given entry.
225 When int == kIterationDone, all properties have been exhausted.
228 extern int DTIterateProperties(DTPropertyIterator iterator
,
229 char **foundProperty
);
232 Restart Property Iteration
233 Used to re-iterate over a list of properties. The Property Iterator is
234 reset to the beginning of the list of properties for an entry.
237 extern int DTRestartPropertyIteration(DTPropertyIterator iterator
);
240 #endif /* __MWERKS__ */
242 #endif /* _PEXPERT_DEVICE_TREE_H_ */