TianoCore EDK2 master
Loading...
Searching...
No Matches
FdtLib.h
Go to the documentation of this file.
1
19#ifndef FDT_LIB_H_
20#define FDT_LIB_H_
21
22/* Error codes: informative error codes */
23#define FDT_ERR_NOTFOUND 1
24/* FDT_ERR_NOTFOUND: The requested node or property does not exist */
25#define FDT_ERR_EXISTS 2
26
27/* FDT_ERR_EXISTS: Attempted to create a node or property which
28 * already exists */
29#define FDT_ERR_NOSPACE 3
30
31/* FDT_ERR_NOSPACE: Operation needed to expand the device
32 * tree, but its buffer did not have sufficient space to
33 * contain the expanded tree. Use fdt_open_into() to move the
34 * device tree to a buffer with more space. */
35
36/* Error codes: codes for bad parameters */
37#define FDT_ERR_BADOFFSET 4
38
39/* FDT_ERR_BADOFFSET: Function was passed a structure block
40 * offset which is out-of-bounds, or which points to an
41 * unsuitable part of the structure for the operation. */
42#define FDT_ERR_BADPATH 5
43
44/* FDT_ERR_BADPATH: Function was passed a badly formatted path
45 * (e.g. missing a leading / for a function which requires an
46 * absolute path) */
47#define FDT_ERR_BADPHANDLE 6
48
49/* FDT_ERR_BADPHANDLE: Function was passed an invalid phandle.
50 * This can be caused either by an invalid phandle property
51 * length, or the phandle value was either 0 or -1, which are
52 * not permitted. */
53#define FDT_ERR_BADSTATE 7
54
55/* FDT_ERR_BADSTATE: Function was passed an incomplete device
56 * tree created by the sequential-write functions, which is
57 * not sufficiently complete for the requested operation. */
58
59/* Error codes: codes for bad device tree blobs */
60#define FDT_ERR_TRUNCATED 8
61
62/* FDT_ERR_TRUNCATED: FDT or a sub-block is improperly
63 * terminated (overflows, goes outside allowed bounds, or
64 * isn't properly terminated). */
65#define FDT_ERR_BADMAGIC 9
66
67/* FDT_ERR_BADMAGIC: Given "device tree" appears not to be a
68 * device tree at all - it is missing the flattened device
69 * tree magic number. */
70#define FDT_ERR_BADVERSION 10
71
72/* FDT_ERR_BADVERSION: Given device tree has a version which
73 * can't be handled by the requested operation. For
74 * read-write functions, this may mean that fdt_open_into() is
75 * required to convert the tree to the expected version. */
76#define FDT_ERR_BADSTRUCTURE 11
77
78/* FDT_ERR_BADSTRUCTURE: Given device tree has a corrupt
79 * structure block or other serious error (e.g. misnested
80 * nodes, or subnodes preceding properties). */
81#define FDT_ERR_BADLAYOUT 12
82
83/* FDT_ERR_BADLAYOUT: For read-write functions, the given
84 * device tree has it's sub-blocks in an order that the
85 * function can't handle (memory reserve map, then structure,
86 * then strings). Use fdt_open_into() to reorganize the tree
87 * into a form suitable for the read-write operations. */
88
89/* "Can't happen" error indicating a bug in libfdt */
90#define FDT_ERR_INTERNAL 13
91
92/* FDT_ERR_INTERNAL: libfdt has failed an internal assertion.
93 * Should never be returned, if it is, it indicates a bug in
94 * libfdt itself. */
95
96/* Errors in device tree content */
97#define FDT_ERR_BADNCELLS 14
98
99/* FDT_ERR_BADNCELLS: Device tree has a #address-cells, #size-cells
100 * or similar property with a bad format or value */
101
102#define FDT_ERR_BADVALUE 15
103
104/* FDT_ERR_BADVALUE: Device tree has a property with an unexpected
105 * value. For example: a property expected to contain a string list
106 * is not NUL-terminated within the length of its value. */
107
108#define FDT_ERR_BADOVERLAY 16
109
110/* FDT_ERR_BADOVERLAY: The device tree overlay, while
111 * correctly structured, cannot be applied due to some
112 * unexpected or missing value, property or node. */
113
114#define FDT_ERR_NOPHANDLES 17
115
116/* FDT_ERR_NOPHANDLES: The device tree doesn't have any
117 * phandle available anymore without causing an overflow */
118
119#define FDT_ERR_BADFLAGS 18
120
121/* FDT_ERR_BADFLAGS: The function was passed a flags field that
122 * contains invalid flags or an invalid combination of flags. */
123
124#define FDT_ERR_ALIGNMENT 19
125
126/* FDT_ERR_ALIGNMENT: The device tree base address is not 8-byte
127 * aligned. */
128
129#define FDT_ERR_MAX 19
130
139typedef struct {
140 UINT32 Magic; /* magic word FDT_MAGIC */
141 UINT32 TotalSize; /* total size of DT block */
142 UINT32 OffsetDtStruct; /* offset to structure */
143 UINT32 OffsetDtStrings; /* offset to strings */
144 UINT32 OffsetMemRsvmap; /* offset to memory reserve map */
145 UINT32 Version; /* format version */
146 UINT32 LastCompVersion; /* last compatible version */
147
148 /* version 2 fields below */
149 UINT32 BootCpuidPhys; /* Which physical CPU id we're
150 booting on */
151 /* version 3 fields below */
152 UINT32 SizeDtStrings; /* size of the strings block */
153
154 /* version 17 fields below */
155 UINT32 SizeDtStruct; /* size of the structure block */
156} FDT_HEADER;
157
158typedef struct {
159 UINT64 Address;
160 UINT64 Size;
162
163typedef struct {
164 UINT32 Tag;
165 CHAR8 Name[];
167
168typedef struct {
169 UINT32 Tag;
170 UINT32 Length;
171 UINT32 NameOffset;
172 CHAR8 Data[];
174
175#ifndef FDT_TAGSIZE
176#define FDT_TAGSIZE sizeof(UINT32)
177#endif
178#ifndef FDT_MAX_NCELLS
179#define FDT_MAX_NCELLS 4
180#endif
181
182#define FdtGetHeader(Fdt, Field) \
183 (Fdt32ToCpu (((const FDT_HEADER *)(Fdt))->Field))
184#define FdtTotalSize(Fdt) (FdtGetHeader ((Fdt), TotalSize))
185
186#define FdtForEachSubnode(Node, Fdt, Parent) \
187 for (Node = FdtFirstSubnode (Fdt, Parent); \
188 Node >= 0; \
189 Node = FdtNextSubnode (Fdt, Node))
190
199UINT16
200EFIAPI
202 IN UINT16 Value
203 );
204
213UINT16
214EFIAPI
216 IN UINT16 Value
217 );
218
227UINT32
228EFIAPI
230 IN UINT32 Value
231 );
232
241UINT32
242EFIAPI
244 IN UINT32 Value
245 );
246
255UINT64
256EFIAPI
258 IN UINT64 Value
259 );
260
269UINT64
270EFIAPI
272 IN UINT64 Value
273 );
274
283INT32
284EFIAPI
286 IN CONST VOID *Fdt
287 );
288
299INT32
300EFIAPI
302 IN CONST VOID *Fdt,
303 OUT VOID *Buffer,
304 IN INT32 BufferSize
305 );
306
314INT32
315EFIAPI
316FdtPack (
317 IN OUT VOID *Fdt
318 );
319
329INT32
330EFIAPI
332 IN VOID *Buffer,
333 IN UINT32 BufferSize
334 );
335
345CONST VOID *
346EFIAPI
348 IN CONST VOID *Fdt,
349 IN INT32 Offset,
350 IN UINT32 Length
351 );
352
363INT32
364EFIAPI
366 IN CONST VOID *Fdt,
367 IN INT32 Offset,
368 IN INT32 *Depth
369 );
370
380INT32
381EFIAPI
383 IN CONST VOID *Fdt,
384 IN INT32 Offset
385 );
386
396INT32
397EFIAPI
399 IN CONST VOID *Fdt,
400 IN INT32 Offset
401 );
402
414INT32
415EFIAPI
417 IN CONST VOID *Fdt,
418 IN INT32 ParentOffset,
419 IN CONST CHAR8 *Name,
420 IN INT32 NameLength
421 );
422
431INTN
432EFIAPI
434 IN CONST VOID *Fdt
435 );
436
448INTN
449EFIAPI
451 IN CONST VOID *Fdt,
452 IN INTN Index,
453 OUT UINT64 *Addr,
454 OUT UINT64 *Size
455 );
456
465INT32
466EFIAPI
468 IN CONST VOID *Fdt,
469 IN INT32 NodeOffset
470 );
471
484INT32
485EFIAPI
487 IN CONST VOID *Fdt,
488 IN INT32 StartOffset,
489 IN CONST CHAR8 *PropertyName,
490 IN CONST VOID *PropertyValue,
491 IN INT32 PropertyLength
492 );
493
502INT32
503EFIAPI
505 IN CONST VOID *Fdt,
506 IN UINT32 Phandle
507 );
508
518INT32
519EFIAPI
521 IN CONST CHAR8 *StringList,
522 IN INT32 ListLength,
523 IN CONST CHAR8 *String
524 );
525
539EFIAPI
541 IN CONST VOID *Fdt,
542 IN INT32 NodeOffset,
543 IN CONST CHAR8 *Name,
544 IN INT32 *Length
545 );
546
558CONST CHAR8 *
559EFIAPI
561 IN CONST VOID *Fdt,
562 IN CONST CHAR8 *Name,
563 IN INT32 Length
564 );
565
575INT32
576EFIAPI
578 IN CONST VOID *Fdt,
579 IN INT32 NodeOffset
580 );
581
591INT32
592EFIAPI
594 IN CONST VOID *Fdt,
595 IN INT32 Offset
596 );
597
609EFIAPI
611 IN CONST VOID *Fdt,
612 IN INT32 Offset,
613 IN INT32 *Length
614 );
615
626CONST CHAR8 *
627EFIAPI
629 IN CONST VOID *Fdt,
630 IN INT32 StrOffset,
631 IN INT32 *Length OPTIONAL
632 );
633
644INT32
645EFIAPI
647 IN VOID *Fdt,
648 IN INT32 ParentOffset,
649 IN CONST CHAR8 *Name
650 );
651
664INT32
665EFIAPI
667 IN VOID *Fdt,
668 IN INT32 NodeOffset,
669 IN CONST CHAR8 *Name,
670 IN CONST VOID *Value,
671 IN UINT32 Length
672 );
673
685INT32
686EFIAPI
688 IN VOID *Fdt,
689 IN INT32 NodeOffset,
690 IN CONST CHAR8 *Name,
691 IN UINT64 Value
692 );
693
706INT32
707EFIAPI
709 IN VOID *Fdt,
710 IN INT32 NodeOffset,
711 IN CONST CHAR8 *Name,
712 IN CONST VOID *Value,
713 IN UINT32 Length
714 );
715
729INT32
731 IN OUT VOID *Fdt,
732 IN INT32 NodeOffset,
733 IN CONST CHAR8 *Name
734 );
735
745INT32
746EFIAPI
748 IN CONST VOID *Fdt,
749 IN CONST CHAR8 *Path,
750 IN INT32 NameLength
751 );
752
761INT32
762EFIAPI
764 IN CONST VOID *Fdt,
765 IN CONST CHAR8 *Path
766 );
767
778CONST CHAR8 *
779EFIAPI
781 IN VOID *Fdt,
782 IN INT32 NodeOffset,
783 IN INT32 *Length
784 );
785
795INT32
796EFIAPI
798 IN CONST VOID *Fdt,
799 IN INT32 NodeOffset
800 );
801
811INT32
812EFIAPI
814 IN CONST VOID *Fdt,
815 IN INT32 StartOffset,
816 IN CONST CHAR8 *Compatible
817 );
818
827INT32
828EFIAPI
830 IN CONST VOID *Fdt,
831 IN INT32 NodeOffset
832 );
833
842INT32
843EFIAPI
845 IN CONST VOID *Fdt,
846 IN INT32 NodeOffset
847 );
848
849/* Debug functions. */
850CONST
851CHAR8
852*
853FdtStrerror (
854 IN INT32 ErrVal
855 );
856
857#endif /* FDT_LIB_H_ */
INT64 INTN
INT32 EFIAPI FdtNodeDepth(IN CONST VOID *Fdt, IN INT32 NodeOffset)
Definition: FdtLib.c:749
INT32 FdtDelProp(IN OUT VOID *Fdt, IN INT32 NodeOffset, IN CONST CHAR8 *Name)
Definition: FdtLib.c:670
INT32 EFIAPI FdtAppendProp(IN VOID *Fdt, IN INT32 NodeOffset, IN CONST CHAR8 *Name, IN CONST VOID *Value, IN UINT32 Length)
Definition: FdtLib.c:645
UINT64 EFIAPI CpuToFdt64(IN UINT64 Value)
Definition: FdtLib.c:108
INT32 EFIAPI FdtStringListContains(IN CONST CHAR8 *StringList, IN INT32 ListLength, IN CONST CHAR8 *String)
Definition: FdtLib.c:423
CONST VOID *EFIAPI FdtOffsetPointer(IN CONST VOID *Fdt, IN INT32 Offset, IN UINT32 Length)
Definition: FdtLib.c:199
INT32 EFIAPI FdtNextPropertyOffset(IN CONST VOID *Fdt, IN INT32 Offset)
Definition: FdtLib.c:508
INT32 EFIAPI FdtNodeOffsetByPropertyValue(IN CONST VOID *Fdt, IN INT32 StartOffset, IN CONST CHAR8 *PropertyName, IN CONST VOID *PropertyValue, IN INT32 PropertyLength)
Definition: FdtLib.c:383
INT32 EFIAPI FdtFirstSubnode(IN CONST VOID *Fdt, IN INT32 Offset)
Definition: FdtLib.c:240
CONST FDT_PROPERTY *EFIAPI FdtGetProperty(IN CONST VOID *Fdt, IN INT32 NodeOffset, IN CONST CHAR8 *Name, IN INT32 *Length)
Definition: FdtLib.c:446
UINT64 EFIAPI Fdt64ToCpu(IN UINT64 Value)
Definition: FdtLib.c:91
INT32 EFIAPI FdtOpenInto(IN CONST VOID *Fdt, OUT VOID *Buffer, IN INT32 BufferSize)
Definition: FdtLib.c:163
CONST CHAR8 *EFIAPI FdtGetAliasNameLen(IN CONST VOID *Fdt, IN CONST CHAR8 *Name, IN INT32 Length)
Definition: FdtLib.c:469
CONST CHAR8 *EFIAPI FdtGetString(IN CONST VOID *Fdt, IN INT32 StrOffset, IN INT32 *Length OPTIONAL)
Definition: FdtLib.c:549
INT32 EFIAPI FdtSetProperty(IN VOID *Fdt, IN INT32 NodeOffset, IN CONST CHAR8 *Name, IN CONST VOID *Value, IN UINT32 Length)
Definition: FdtLib.c:593
INT32 EFIAPI FdtPack(IN OUT VOID *Fdt)
Definition: FdtLib.c:181
UINT16 EFIAPI Fdt16ToCpu(IN UINT16 Value)
Definition: FdtLib.c:23
INT32 EFIAPI FdtNodeOffsetByCompatible(IN CONST VOID *Fdt, IN INT32 StartOffset, IN CONST CHAR8 *Compatible)
Definition: FdtLib.c:768
INT32 EFIAPI FdtSetPropU64(IN VOID *Fdt, IN INT32 NodeOffset, IN CONST CHAR8 *Name, IN UINT64 Value)
Definition: FdtLib.c:617
INT32 EFIAPI FdtSubnodeOffsetNameLen(IN CONST VOID *Fdt, IN INT32 ParentOffset, IN CONST CHAR8 *Name, IN INT32 NameLength)
Definition: FdtLib.c:320
INT32 EFIAPI FdtAddressCells(IN CONST VOID *Fdt, IN INT32 NodeOffset)
Definition: FdtLib.c:787
INT32 EFIAPI FdtAddSubnode(IN VOID *Fdt, IN INT32 ParentOffset, IN CONST CHAR8 *Name)
Definition: FdtLib.c:570
UINT16 EFIAPI CpuToFdt16(IN UINT16 Value)
Definition: FdtLib.c:40
INT32 EFIAPI FdtNextNode(IN CONST VOID *Fdt, IN INT32 Offset, IN INT32 *Depth)
Definition: FdtLib.c:220
UINT32 EFIAPI CpuToFdt32(IN UINT32 Value)
Definition: FdtLib.c:74
INT32 EFIAPI FdtCheckHeader(IN CONST VOID *Fdt)
Definition: FdtLib.c:125
INT32 EFIAPI FdtParentOffset(IN CONST VOID *Fdt, IN INT32 NodeOffset)
Definition: FdtLib.c:361
INTN EFIAPI FdtGetNumberOfReserveMapEntries(IN CONST VOID *Fdt)
Definition: FdtLib.c:277
UINT32 EFIAPI Fdt32ToCpu(IN UINT32 Value)
Definition: FdtLib.c:57
INT32 EFIAPI FdtSizeCells(IN CONST VOID *Fdt, IN INT32 NodeOffset)
Definition: FdtLib.c:805
INT32 EFIAPI FdtPathOffset(IN CONST VOID *Fdt, IN CONST CHAR8 *Path)
Definition: FdtLib.c:709
INT32 EFIAPI FdtFirstPropertyOffset(IN CONST VOID *Fdt, IN INT32 NodeOffset)
Definition: FdtLib.c:489
INT32 EFIAPI FdtPathOffsetNameLen(IN CONST VOID *Fdt, IN CONST CHAR8 *Path, IN INT32 NameLength)
Definition: FdtLib.c:690
CONST CHAR8 *EFIAPI FdtGetName(IN VOID *Fdt, IN INT32 NodeOffset, IN INT32 *Length)
Definition: FdtLib.c:729
INT32 EFIAPI FdtNodeOffsetByPhandle(IN CONST VOID *Fdt, IN UINT32 Phandle)
Definition: FdtLib.c:404
INTN EFIAPI FdtGetReserveMapEntry(IN CONST VOID *Fdt, IN INTN Index, OUT UINT64 *Addr, OUT UINT64 *Size)
Definition: FdtLib.c:297
INT32 EFIAPI FdtCreateEmptyTree(IN VOID *Buffer, IN UINT32 BufferSize)
Definition: FdtLib.c:143
INT32 EFIAPI FdtNextSubnode(IN CONST VOID *Fdt, IN INT32 Offset)
Definition: FdtLib.c:259
CONST FDT_PROPERTY *EFIAPI FdtGetPropertyByOffset(IN CONST VOID *Fdt, IN INT32 Offset, IN INT32 *Length)
Definition: FdtLib.c:528
#define CONST
Definition: Base.h:259
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284