VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Include/Library/FdtLib.h@ 101291

Last change on this file since 101291 was 101291, checked in by vboxsync, 14 months ago

EFI/FirmwareNew: Make edk2-stable202308 build on all supported platforms (using gcc at least, msvc not tested yet), bugref:4643

  • Property svn:eol-style set to native
File size: 9.2 KB
Line 
1/** @file
2 Flattened Device Tree Library.
3
4 All structure data are in big-endian format.
5 Functions are provided for converting data between
6 little-endian and big-endian.
7 For example:
8 Pushing data to FDT blob needs to convert data to
9 big-endian by CpuToFdt*().
10 Retrieving data from FDT blob needs to convert data to
11 little-endian by Fdt*ToCpu().
12 Refer to FDT specification: https://www.devicetree.org/specifications/
13
14 Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
15 SPDX-License-Identifier: BSD-2-Clause-Patent
16
17**/
18
19#ifndef FDT_LIB_H_
20#define FDT_LIB_H_
21
22/**
23 Flattened Device Tree definition
24
25 The Devicetree Blob (DTB) format is a binary encoding with big-endian.
26 When producing or consuming the blob data, CpuToFdt*() or Fdt*ToCpu()
27 provided by this library may be called to convert data between
28 big-endian and little-endian.
29**/
30typedef struct {
31 UINT32 Magic; /* magic word FDT_MAGIC */
32 UINT32 TotalSize; /* total size of DT block */
33 UINT32 OffsetDtStruct; /* offset to structure */
34 UINT32 OffsetDtStrings; /* offset to strings */
35 UINT32 OffsetMemRsvmap; /* offset to memory reserve map */
36 UINT32 Version; /* format version */
37 UINT32 LastCompVersion; /* last compatible version */
38
39 /* version 2 fields below */
40 UINT32 BootCpuidPhys; /* Which physical CPU id we're
41 booting on */
42 /* version 3 fields below */
43 UINT32 SizeDtStrings; /* size of the strings block */
44
45 /* version 17 fields below */
46 UINT32 SizeDtStruct; /* size of the structure block */
47} FDT_HEADER;
48
49typedef struct {
50 UINT64 Address;
51 UINT64 Size;
52} FDT_RESERVE_ENTRY;
53
54typedef struct {
55 UINT32 Tag;
56 CHAR8 Name[];
57} FDT_NODE_HEADER;
58
59typedef struct {
60 UINT32 Tag;
61 UINT32 Length;
62 UINT32 NameOffset;
63 CHAR8 Data[];
64} FDT_PROPERTY;
65
66/**
67 Convert UINT16 data of the FDT blob to little-endian
68
69 @param[in] Value The value to the blob data.
70
71 @return The value to be converted to little-endian.
72
73**/
74UINT16
75EFIAPI
76Fdt16ToCpu (
77 IN UINT16 Value
78 );
79
80/**
81 Convert UINT16 data to big-endian for aligned with the FDT blob
82
83 @param[in] Value The value to align with the FDT blob.
84
85 @return The value to be converted to big-endian.
86
87**/
88UINT16
89EFIAPI
90CpuToFdt16 (
91 IN UINT16 Value
92 );
93
94/**
95 Convert UINT32 data of the FDT blob to little-endian
96
97 @param[in] Value The value to the blob data.
98
99 @return The value to be converted to little-endian.
100
101**/
102UINT32
103EFIAPI
104Fdt32ToCpu (
105 IN UINT32 Value
106 );
107
108/**
109 Convert UINT32 data to big-endian for aligned with the FDT blob
110
111 @param[in] Value The value to align with the FDT blob.
112
113 @return The value to be converted to big-endian.
114
115**/
116UINT32
117EFIAPI
118CpuToFdt32 (
119 IN UINT32 Value
120 );
121
122/**
123 Convert UINT64 data of the FDT blob to little-endian
124
125 @param[in] Value The value to the blob data.
126
127 @return The value to be converted to little-endian.
128
129**/
130UINT64
131EFIAPI
132Fdt64ToCpu (
133 IN UINT64 Value
134 );
135
136/**
137 Convert UINT64 data to big-endian for aligned with the FDT blob
138
139 @param[in] Value The value to align with the FDT blob.
140
141 @return The value to be converted to big-endian.
142
143**/
144UINT64
145EFIAPI
146CpuToFdt64 (
147 IN UINT64 Value
148 );
149
150/**
151 Verify the header of the Flattened Device Tree
152
153 @param[in] Fdt The pointer to FDT blob.
154
155 @return Zero for successfully, otherwise failed.
156
157**/
158INT32
159EFIAPI
160FdtCheckHeader (
161 IN CONST VOID *Fdt
162 );
163
164/**
165 Create a empty Flattened Device Tree.
166
167 @param[in] Buffer The pointer to allocate a pool for FDT blob.
168 @param[in] BufferSize The BufferSize to the pool size.
169
170 @return Zero for successfully, otherwise failed.
171
172**/
173INT32
174EFIAPI
175FdtCreateEmptyTree (
176 IN VOID *Buffer,
177 IN UINT32 BufferSize
178 );
179
180/**
181 Returns a offset of next node from the given node.
182
183 @param[in] Fdt The pointer to FDT blob.
184 @param[in] Offset The offset to previous node.
185 @param[in] Depth The depth to the level of tree hierarchy.
186
187 @return The offset to next node offset.
188
189**/
190INT32
191EFIAPI
192FdtNextNode (
193 IN CONST VOID *Fdt,
194 IN INT32 Offset,
195 IN INT32 *Depth
196 );
197
198/**
199 Returns a offset of first node under the given node.
200
201 @param[in] Fdt The pointer to FDT blob.
202 @param[in] Offset The offset to previous node.
203
204 @return The offset to next node offset.
205
206**/
207INT32
208EFIAPI
209FdtFirstSubnode (
210 IN CONST VOID *Fdt,
211 IN INT32 Offset
212 );
213
214/**
215 Returns a offset of next node from the given node.
216
217 @param[in] Fdt The pointer to FDT blob.
218 @param[in] Offset The offset to previous node.
219
220 @return The offset to next node offset.
221
222**/
223INT32
224EFIAPI
225FdtNextSubnode (
226 IN CONST VOID *Fdt,
227 IN INT32 Offset
228 );
229
230/**
231 Returns a offset of first node which includes the given name.
232
233 @param[in] Fdt The pointer to FDT blob.
234 @param[in] ParentOffset The offset to the node which start find under.
235 @param[in] Name The name to search the node with the name.
236 @param[in] NameLength The length of the name to check only.
237
238 @return The offset to node offset with given node name.
239
240**/
241INT32
242EFIAPI
243FdtSubnodeOffsetNameLen (
244 IN CONST VOID *Fdt,
245 IN INT32 ParentOffset,
246 IN CONST CHAR8 *Name,
247 IN INT32 NameLength
248 );
249
250/**
251 Returns a offset of first node which includes the given property name and value.
252
253 @param[in] Fdt The pointer to FDT blob.
254 @param[in] StartOffset The offset to the starting node to find.
255 @param[in] PropertyName The property name to search the node including the named property.
256 @param[in] PropertyValue The property value (big-endian) to check the same property value.
257 @param[in] PropertyLength The length of the value in PropertValue.
258
259 @return The offset to node offset with given property.
260
261**/
262INT32
263EFIAPI
264FdtNodeOffsetByPropValue (
265 IN CONST VOID *Fdt,
266 IN INT32 StartOffset,
267 IN CONST CHAR8 *PropertyName,
268 IN CONST VOID *PropertyValue,
269 IN INT32 PropertyLength
270 );
271
272/**
273 Returns a property with the given name from the given node.
274
275 @param[in] Fdt The pointer to FDT blob.
276 @param[in] NodeOffset The offset to the given node.
277 @param[in] Name The name to the property which need be searched
278 @param[in] Length The length to the size of the property found.
279
280 @return The property to the structure of the found property. Since the data
281 come from FDT blob, it's encoding with big-endian.
282
283**/
284CONST FDT_PROPERTY *
285EFIAPI
286FdtGetProperty (
287 IN CONST VOID *Fdt,
288 IN INT32 NodeOffset,
289 IN CONST CHAR8 *Name,
290 IN INT32 *Length
291 );
292
293/**
294 Returns a offset of first property in the given node.
295
296 @param[in] Fdt The pointer to FDT blob.
297 @param[in] NodeOffset The offset to the node which need be searched.
298
299 @return The offset to first property offset in the given node.
300
301**/
302INT32
303EFIAPI
304FdtFirstPropertyOffset (
305 IN CONST VOID *Fdt,
306 IN INT32 NodeOffset
307 );
308
309/**
310 Returns a offset of next property from the given property.
311
312 @param[in] Fdt The pointer to FDT blob.
313 @param[in] Offset The offset to previous property.
314
315 @return The offset to next property offset.
316
317**/
318INT32
319EFIAPI
320FdtNextPropertyOffset (
321 IN CONST VOID *Fdt,
322 IN INT32 Offset
323 );
324
325/**
326 Returns a property from the given offset of the property.
327
328 @param[in] Fdt The pointer to FDT blob.
329 @param[in] Offset The offset to the given offset of the property.
330 @param[in] Length The length to the size of the property found.
331
332 @return The property to the structure of the given property offset.
333
334**/
335CONST FDT_PROPERTY *
336EFIAPI
337FdtGetPropertyByOffset (
338 IN CONST VOID *Fdt,
339 IN INT32 Offset,
340 IN INT32 *Length
341 );
342
343/**
344 Returns a string by the given string offset.
345
346 @param[in] Fdt The pointer to FDT blob.
347 @param[in] StrOffset The offset to the location in the strings block of FDT.
348 @param[in] Length The length to the size of string which need be retrieved.
349
350 @return The string to the given string offset.
351
352**/
353CONST CHAR8 *
354EFIAPI
355FdtGetString (
356 IN CONST VOID *Fdt,
357 IN INT32 StrOffset,
358 IN INT32 *Length OPTIONAL
359 );
360
361/**
362 Add a new node to the FDT.
363
364 @param[in] Fdt The pointer to FDT blob.
365 @param[in] ParentOffset The offset to the node offset which want to add in.
366 @param[in] Name The name to name the node.
367
368 @return The offset to the new node.
369
370**/
371INT32
372EFIAPI
373FdtAddSubnode (
374 IN VOID *Fdt,
375 IN INT32 ParentOffset,
376 IN CONST CHAR8 *Name
377 );
378
379/**
380 Add or modify a property in the given node.
381
382 @param[in] Fdt The pointer to FDT blob.
383 @param[in] NodeOffset The offset to the node offset which want to add in.
384 @param[in] Name The name to name the property.
385 @param[in] Value The value (big-endian) to the property value.
386 @param[in] Length The length to the size of the property.
387
388 @return Zero for successfully, otherwise failed.
389
390**/
391INT32
392EFIAPI
393FdtSetProp (
394 IN VOID *Fdt,
395 IN INT32 NodeOffset,
396 IN CONST CHAR8 *Name,
397 IN CONST VOID *Value,
398 IN UINT32 Length
399 );
400
401#endif /* FDT_LIB_H_ */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette