1 #ifndef _IPXE_FDT_H
2 #define _IPXE_FDT_H
3 
4 /** @file
5  *
6  * Flattened Device Tree
7  *
8  */
9 
10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11 
12 #include <stdint.h>
13 
14 struct net_device;
15 
16 /** Device tree header */
17 struct fdt_header {
18 	/** Magic signature */
19 	uint32_t magic;
20 	/** Total size of device tree */
21 	uint32_t totalsize;
22 	/** Offset to structure block */
23 	uint32_t off_dt_struct;
24 	/** Offset to strings block */
25 	uint32_t off_dt_strings;
26 	/** Offset to memory reservation block */
27 	uint32_t off_mem_rsvmap;
28 	/** Version of this data structure */
29 	uint32_t version;
30 	/** Lowest version to which this structure is compatible */
31 	uint32_t last_comp_version;
32 	/** Physical ID of the boot CPU */
33 	uint32_t boot_cpuid_phys;
34 	/** Length of string block */
35 	uint32_t size_dt_strings;
36 	/** Length of structure block */
37 	uint32_t size_dt_struct;
38 } __attribute__ (( packed ));
39 
40 /** Magic signature */
41 #define FDT_MAGIC 0xd00dfeed
42 
43 /** Expected device tree version */
44 #define FDT_VERSION 16
45 
46 /** Device tree token */
47 typedef uint32_t fdt_token_t;
48 
49 /** Begin node token */
50 #define FDT_BEGIN_NODE 0x00000001
51 
52 /** End node token */
53 #define FDT_END_NODE 0x00000002
54 
55 /** Property token */
56 #define FDT_PROP 0x00000003
57 
58 /** Property fragment */
59 struct fdt_prop {
60 	/** Data length */
61 	uint32_t len;
62 	/** Name offset */
63 	uint32_t name_off;
64 } __attribute__ (( packed ));
65 
66 /** NOP token */
67 #define FDT_NOP 0x00000004
68 
69 /** End of structure block */
70 #define FDT_END 0x00000009
71 
72 /** Alignment of structure block */
73 #define FDT_STRUCTURE_ALIGN ( sizeof ( fdt_token_t ) )
74 
75 /** A device tree */
76 struct fdt {
77 	/** Tree data */
78 	union {
79 		/** Tree header */
80 		const struct fdt_header *hdr;
81 		/** Raw data */
82 		const void *raw;
83 	};
84 	/** Length of tree */
85 	size_t len;
86 	/** Offset to structure block */
87 	unsigned int structure;
88 	/** Length of structure block */
89 	size_t structure_len;
90 	/** Offset to strings block */
91 	unsigned int strings;
92 	/** Length of strings block */
93 	size_t strings_len;
94 };
95 
96 extern int fdt_path ( const char *path, unsigned int *offset );
97 extern int fdt_alias ( const char *name, unsigned int *offset );
98 extern const char * fdt_string ( unsigned int offset, const char *name );
99 extern int fdt_mac ( unsigned int offset, struct net_device *netdev );
100 extern int register_fdt ( const struct fdt_header *hdr );
101 
102 #endif /* _IPXE_FDT_H */
103