iPXE
fdt.h
Go to the documentation of this file.
1#ifndef _IPXE_FDT_H
2#define _IPXE_FDT_H
3
4/** @file
5 *
6 * Flattened Device Tree
7 *
8 */
9
10FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11FILE_SECBOOT ( PERMITTED );
12
13#include <stdint.h>
14#include <ipxe/image.h>
15
16struct net_device;
17
18/** Device tree header */
19struct fdt_header {
20 /** Magic signature */
22 /** Total size of device tree */
24 /** Offset to structure block */
26 /** Offset to strings block */
28 /** Offset to memory reservation block */
30 /** Version of this data structure */
32 /** Lowest version to which this structure is compatible */
34 /** Physical ID of the boot CPU */
36 /** Length of string block */
38 /** Length of structure block */
40} __attribute__ (( packed ));
41
42/** Magic signature */
43#define FDT_MAGIC 0xd00dfeed
44
45/** Expected device tree version */
46#define FDT_VERSION 16
47
48/** Device tree token */
50
51/** Begin node token */
52#define FDT_BEGIN_NODE 0x00000001
53
54/** End node token */
55#define FDT_END_NODE 0x00000002
56
57/** Property token */
58#define FDT_PROP 0x00000003
59
60/** Property fragment */
61struct fdt_prop {
62 /** Data length */
64 /** Name offset */
66} __attribute__ (( packed ));
67
68/** NOP token */
69#define FDT_NOP 0x00000004
70
71/** End of structure block */
72#define FDT_END 0x00000009
73
74/** Alignment of structure block */
75#define FDT_STRUCTURE_ALIGN ( sizeof ( fdt_token_t ) )
76
77/** Maximum alignment of any block */
78#define FDT_MAX_ALIGN 8
79
80/** A memory reservation */
82 /** Starting address */
84 /** Length of reservation */
86} __attribute__ (( packed ));
87
88/** A device tree */
89struct fdt {
90 /** Tree data */
91 union {
92 /** Tree header */
93 struct fdt_header *hdr;
94 /** Raw data */
95 void *raw;
96 };
97 /** Length of tree */
98 size_t len;
99 /** Used length of tree */
100 size_t used;
101 /** Offset to structure block */
102 unsigned int structure;
103 /** Length of structure block */
105 /** Offset to strings block */
106 unsigned int strings;
107 /** Length of strings block */
109 /** Offset to memory reservation block */
110 unsigned int reservations;
111 /** Reallocate device tree
112 *
113 * @v fdt Device tree
114 * @v len New length
115 * @ret rc Return status code
116 */
117 int ( * realloc ) ( struct fdt *fdt, size_t len );
118};
119
120/** A device tree token descriptor */
122 /** Offset within structure block */
123 unsigned int offset;
124 /** Next offset within structure block */
125 unsigned int next;
126 /** Node or property name (if applicable) */
127 const char *name;
128 /** Property data (if applicable) */
129 const void *data;
130 /** Length of property data (if applicable) */
131 size_t len;
132 /** Depth change */
133 int depth;
134};
135
136/** A device tree region cell size specification */
138 /** Number of address cells */
140 /** Number of size cells */
142 /** Number of address cells plus number of size cells */
143 unsigned int stride;
144};
145
146/** Default number of address cells, if not specified */
147#define FDT_DEFAULT_ADDRESS_CELLS 2
148
149/** Default number of size cells, if not specified */
150#define FDT_DEFAULT_SIZE_CELLS 1
151
152extern struct image_tag fdt_image __image_tag;
153extern struct fdt sysfdt;
154
155/**
156 * Get memory reservations
157 *
158 * @v fdt Device tree
159 * @ret rsv Memory reservations
160 */
161static inline const struct fdt_reservation *
163
164 return ( fdt->raw + fdt->reservations );
165}
166
167/** Iterate over memory reservations */
168#define for_each_fdt_reservation( rsv, fdt ) \
169 for ( rsv = fdt_reservations ( (fdt) ) ; \
170 ( (rsv)->start || (rsv)->size ) ; rsv++ )
171
172extern int fdt_describe ( struct fdt *fdt, unsigned int offset,
173 struct fdt_descriptor *desc );
174extern int fdt_parent ( struct fdt *fdt, unsigned int offset,
175 unsigned int *parent );
176extern int fdt_path ( struct fdt *fdt, const char *path,
177 unsigned int *offset );
178extern int fdt_alias ( struct fdt *fdt, const char *name,
179 unsigned int *offset );
180extern const char * fdt_strings ( struct fdt *fdt, unsigned int offset,
181 const char *name, unsigned int *count );
182extern const char * fdt_string ( struct fdt *fdt, unsigned int offset,
183 const char *name );
184extern int fdt_cells ( struct fdt *fdt, unsigned int offset, const char *name,
185 unsigned int index, unsigned int count,
186 uint64_t *value );
187extern int fdt_u64 ( struct fdt *fdt, unsigned int offset, const char *name,
188 uint64_t *value );
189extern int fdt_u32 ( struct fdt *fdt, unsigned int offset, const char *name,
190 uint32_t *value );
191extern uint32_t fdt_phandle ( struct fdt *fdt, unsigned int offset );
192extern void fdt_reg_cells ( struct fdt *fdt, unsigned int offset,
193 struct fdt_reg_cells *regs );
194extern int fdt_parent_reg_cells ( struct fdt *fdt, unsigned int offset,
195 struct fdt_reg_cells *regs );
196extern int fdt_reg_count ( struct fdt *fdt, unsigned int offset,
197 struct fdt_reg_cells *regs );
198extern int fdt_reg_address ( struct fdt *fdt, unsigned int offset,
199 struct fdt_reg_cells *regs, unsigned int index,
200 uint64_t *address );
201extern int fdt_reg_size ( struct fdt *fdt, unsigned int offset,
202 struct fdt_reg_cells *regs, unsigned int index,
203 uint64_t *size );
204extern int fdt_reg ( struct fdt *fdt, unsigned int offset, uint64_t *region );
205extern int fdt_mac ( struct fdt *fdt, unsigned int offset,
206 struct net_device *netdev );
207extern int fdt_parse ( struct fdt *fdt, struct fdt_header *hdr,
208 size_t max_len );
209extern int fdt_create ( struct fdt_header **hdr, const char *cmdline,
210 physaddr_t initrd, size_t initrd_len );
211extern void fdt_remove ( struct fdt_header *hdr );
212
213#endif /* _IPXE_FDT_H */
struct golan_inbox_hdr hdr
Message header.
Definition CIB_PRM.h:0
pseudo_bit_t value[0x00020]
Definition arbel.h:2
unsigned int uint32_t
Definition stdint.h:12
unsigned long physaddr_t
Definition stdint.h:20
unsigned long long uint64_t
Definition stdint.h:13
long index
Definition bigint.h:65
const char * name
Definition ath9k_hw.c:1986
uint16_t offset
Offset to command line.
Definition bzimage.h:3
uint64_t address
Base address.
Definition ena.h:13
struct ena_llq_option desc
Descriptor counts.
Definition ena.h:9
struct fdt sysfdt
The system flattened device tree (if present)
Definition fdt.c:45
static struct net_device * netdev
Definition gdbudp.c:53
uint16_t size
Buffer size.
Definition dwmac.h:3
static unsigned int count
Number of entries.
Definition dwmac.h:220
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:926
Executable images.
#define __image_tag
An image tag.
Definition image.h:184
#define __attribute__(x)
Definition compiler.h:10
int fdt_u64(struct fdt *fdt, unsigned int offset, const char *name, uint64_t *value)
Get 64-bit integer property.
Definition fdt.c:644
int fdt_describe(struct fdt *fdt, unsigned int offset, struct fdt_descriptor *desc)
Describe device tree token.
Definition fdt.c:90
void fdt_remove(struct fdt_header *hdr)
Remove device tree.
Definition fdt.c:1459
int fdt_mac(struct fdt *fdt, unsigned int offset, struct net_device *netdev)
Get MAC address from property.
Definition fdt.c:867
const char * fdt_string(struct fdt *fdt, unsigned int offset, const char *name)
Find string property.
Definition fdt.c:579
uint32_t fdt_phandle(struct fdt *fdt, unsigned int offset)
Get package handle (phandle) property.
Definition fdt.c:690
int fdt_parse(struct fdt *fdt, struct fdt_header *hdr, size_t max_len)
Parse device tree.
Definition fdt.c:904
int fdt_reg(struct fdt *fdt, unsigned int offset, uint64_t *region)
Get unsized single-entry region address.
Definition fdt.c:844
const char * fdt_strings(struct fdt *fdt, unsigned int offset, const char *name, unsigned int *count)
Find strings property.
Definition fdt.c:540
int fdt_reg_count(struct fdt *fdt, unsigned int offset, struct fdt_reg_cells *regs)
Get number of regions.
Definition fdt.c:767
int fdt_u32(struct fdt *fdt, unsigned int offset, const char *name, uint32_t *value)
Get 32-bit integer property.
Definition fdt.c:664
int fdt_cells(struct fdt *fdt, unsigned int offset, const char *name, unsigned int index, unsigned int count, uint64_t *value)
Get integer property.
Definition fdt.c:598
int fdt_reg_size(struct fdt *fdt, unsigned int offset, struct fdt_reg_cells *regs, unsigned int index, uint64_t *size)
Get region size.
Definition fdt.c:818
int fdt_create(struct fdt_header **hdr, const char *cmdline, physaddr_t initrd, size_t initrd_len)
Create device tree.
Definition fdt.c:1408
int fdt_alias(struct fdt *fdt, const char *name, unsigned int *offset)
Find node by alias.
Definition fdt.c:466
int fdt_reg_address(struct fdt *fdt, unsigned int offset, struct fdt_reg_cells *regs, unsigned int index, uint64_t *address)
Get region address.
Definition fdt.c:793
static const struct fdt_reservation * fdt_reservations(struct fdt *fdt)
Get memory reservations.
Definition fdt.h:162
uint32_t fdt_token_t
Device tree token.
Definition fdt.h:49
int fdt_path(struct fdt *fdt, const char *path, unsigned int *offset)
Find node by path.
Definition fdt.c:426
void fdt_reg_cells(struct fdt *fdt, unsigned int offset, struct fdt_reg_cells *regs)
Get region cell size specification.
Definition fdt.c:716
int fdt_parent_reg_cells(struct fdt *fdt, unsigned int offset, struct fdt_reg_cells *regs)
Get parent region cell size specification.
Definition fdt.c:744
int fdt_parent(struct fdt *fdt, unsigned int offset, unsigned int *parent)
Find parent node.
Definition fdt.c:293
uint32_t cmdline
Definition multiboot.h:4
struct i386_regs regs
Definition registers.h:1
#define initrd_len
Definition runtime.c:63
A device tree token descriptor.
Definition fdt.h:121
unsigned int next
Next offset within structure block.
Definition fdt.h:125
const char * name
Node or property name (if applicable)
Definition fdt.h:127
size_t len
Length of property data (if applicable)
Definition fdt.h:131
unsigned int offset
Offset within structure block.
Definition fdt.h:123
int depth
Depth change.
Definition fdt.h:133
const void * data
Property data (if applicable)
Definition fdt.h:129
Device tree header.
Definition fdt.h:19
uint32_t size_dt_strings
Length of string block.
Definition fdt.h:37
uint32_t off_dt_strings
Offset to strings block.
Definition fdt.h:27
uint32_t magic
Magic signature.
Definition fdt.h:21
uint32_t size_dt_struct
Length of structure block.
Definition fdt.h:39
uint32_t last_comp_version
Lowest version to which this structure is compatible.
Definition fdt.h:33
uint32_t off_dt_struct
Offset to structure block.
Definition fdt.h:25
uint32_t off_mem_rsvmap
Offset to memory reservation block.
Definition fdt.h:29
uint32_t version
Version of this data structure.
Definition fdt.h:31
uint32_t totalsize
Total size of device tree.
Definition fdt.h:23
uint32_t boot_cpuid_phys
Physical ID of the boot CPU.
Definition fdt.h:35
Property fragment.
Definition fdt.h:61
uint32_t name_off
Name offset.
Definition fdt.h:65
uint32_t len
Data length.
Definition fdt.h:63
A device tree region cell size specification.
Definition fdt.h:137
unsigned int stride
Number of address cells plus number of size cells.
Definition fdt.h:143
uint32_t address_cells
Number of address cells.
Definition fdt.h:139
uint32_t size_cells
Number of size cells.
Definition fdt.h:141
A memory reservation.
Definition fdt.h:81
uint64_t start
Starting address.
Definition fdt.h:83
uint64_t size
Length of reservation.
Definition fdt.h:85
A device tree.
Definition fdt.h:89
size_t len
Length of tree.
Definition fdt.h:98
size_t structure_len
Length of structure block.
Definition fdt.h:104
int(* realloc)(struct fdt *fdt, size_t len)
Reallocate device tree.
Definition fdt.h:117
size_t strings_len
Length of strings block.
Definition fdt.h:108
void * raw
Raw data.
Definition fdt.h:95
unsigned int strings
Offset to strings block.
Definition fdt.h:106
struct fdt_header * hdr
Tree header.
Definition fdt.h:93
unsigned int structure
Offset to structure block.
Definition fdt.h:102
size_t used
Used length of tree.
Definition fdt.h:100
unsigned int reservations
Offset to memory reservation block.
Definition fdt.h:110
An image tag.
Definition image.h:173
A network device.
Definition netdevice.h:353