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 
10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11 FILE_SECBOOT ( PERMITTED );
12 
13 #include <stdint.h>
14 #include <ipxe/image.h>
15 
16 struct net_device;
17 
18 /** Device tree header */
19 struct 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 */
61 struct 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 */
89 struct 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 */
108  size_t strings_len;
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 
152 extern struct image_tag fdt_image __image_tag;
153 extern struct fdt sysfdt;
154 
155 /**
156  * Get memory reservations
157  *
158  * @v fdt Device tree
159  * @ret rsv Memory reservations
160  */
161 static inline const struct fdt_reservation *
162 fdt_reservations ( struct fdt *fdt ) {
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 
172 extern int fdt_describe ( struct fdt *fdt, unsigned int offset,
173  struct fdt_descriptor *desc );
174 extern int fdt_parent ( struct fdt *fdt, unsigned int offset,
175  unsigned int *parent );
176 extern int fdt_path ( struct fdt *fdt, const char *path,
177  unsigned int *offset );
178 extern int fdt_alias ( struct fdt *fdt, const char *name,
179  unsigned int *offset );
180 extern const char * fdt_strings ( struct fdt *fdt, unsigned int offset,
181  const char *name, unsigned int *count );
182 extern const char * fdt_string ( struct fdt *fdt, unsigned int offset,
183  const char *name );
184 extern int fdt_cells ( struct fdt *fdt, unsigned int offset, const char *name,
185  unsigned int index, unsigned int count,
186  uint64_t *value );
187 extern int fdt_u64 ( struct fdt *fdt, unsigned int offset, const char *name,
188  uint64_t *value );
189 extern int fdt_u32 ( struct fdt *fdt, unsigned int offset, const char *name,
190  uint32_t *value );
191 extern uint32_t fdt_phandle ( struct fdt *fdt, unsigned int offset );
192 extern void fdt_reg_cells ( struct fdt *fdt, unsigned int offset,
193  struct fdt_reg_cells *regs );
194 extern int fdt_parent_reg_cells ( struct fdt *fdt, unsigned int offset,
195  struct fdt_reg_cells *regs );
196 extern int fdt_reg_count ( struct fdt *fdt, unsigned int offset,
197  struct fdt_reg_cells *regs );
198 extern int fdt_reg_address ( struct fdt *fdt, unsigned int offset,
199  struct fdt_reg_cells *regs, unsigned int index,
200  uint64_t *address );
201 extern int fdt_reg_size ( struct fdt *fdt, unsigned int offset,
202  struct fdt_reg_cells *regs, unsigned int index,
203  uint64_t *size );
204 extern int fdt_reg ( struct fdt *fdt, unsigned int offset, uint64_t *region );
205 extern int fdt_mac ( struct fdt *fdt, unsigned int offset,
206  struct net_device *netdev );
207 extern int fdt_parse ( struct fdt *fdt, struct fdt_header *hdr,
208  size_t max_len );
209 extern int fdt_create ( struct fdt_header **hdr, const char *cmdline,
210  physaddr_t initrd, size_t initrd_len );
211 extern void fdt_remove ( struct fdt_header *hdr );
212 
213 #endif /* _IPXE_FDT_H */
#define __attribute__(x)
Definition: compiler.h:10
const char * name
Definition: ath9k_hw.c:1986
const char * name
Node or property name (if applicable)
Definition: fdt.h:127
int depth
Depth change.
Definition: fdt.h:133
A memory reservation.
Definition: fdt.h:81
unsigned int reservations
Offset to memory reservation block.
Definition: fdt.h:110
unsigned int next
Next offset within structure block.
Definition: fdt.h:125
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_create(struct fdt_header **hdr, const char *cmdline, physaddr_t initrd, size_t initrd_len)
Create device tree.
Definition: fdt.c:1408
An image tag.
Definition: image.h:173
int(* realloc)(struct fdt *fdt, size_t len)
Reallocate device tree.
Definition: fdt.h:117
static const struct fdt_reservation * fdt_reservations(struct fdt *fdt)
Get memory reservations.
Definition: fdt.h:162
size_t len
Length of tree.
Definition: fdt.h:98
Device tree header.
Definition: fdt.h:19
struct golan_inbox_hdr hdr
Message header.
Definition: CIB_PRM.h:28
uint64_t address
Base address.
Definition: ena.h:24
void * raw
Raw data.
Definition: fdt.h:95
uint16_t size
Buffer size.
Definition: dwmac.h:14
void fdt_remove(struct fdt_header *hdr)
Remove device tree.
Definition: fdt.c:1459
A device tree region cell size specification.
Definition: fdt.h:137
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
long index
Definition: bigint.h:65
unsigned long long uint64_t
Definition: stdint.h:13
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_reg(struct fdt *fdt, unsigned int offset, uint64_t *region)
Get unsized single-entry region address.
Definition: fdt.c:844
size_t strings_len
Length of strings block.
Definition: fdt.h:108
uint32_t fdt_token_t
Device tree token.
Definition: fdt.h:49
const char * fdt_string(struct fdt *fdt, unsigned int offset, const char *name)
Find string property.
Definition: fdt.c:579
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
struct fdt_header * hdr
Tree header.
Definition: fdt.h:93
uint32_t off_dt_struct
Offset to structure block.
Definition: fdt.h:25
int fdt_u32(struct fdt *fdt, unsigned int offset, const char *name, uint32_t *value)
Get 32-bit integer property.
Definition: fdt.c:664
struct image_tag fdt_image __image_tag
The downloaded flattened device tree tag.
Definition: fdt.c:48
uint32_t len
Data length.
Definition: fdt.h:63
uint32_t address_cells
Number of address cells.
Definition: fdt.h:139
uint32_t magic
Magic signature.
Definition: fdt.h:21
int fdt_u64(struct fdt *fdt, unsigned int offset, const char *name, uint64_t *value)
Get 64-bit integer property.
Definition: fdt.c:644
uint32_t version
Version of this data structure.
Definition: fdt.h:31
struct ena_llq_option desc
Descriptor counts.
Definition: ena.h:20
unsigned int stride
Number of address cells plus number of size cells.
Definition: fdt.h:143
uint32_t off_dt_strings
Offset to strings block.
Definition: fdt.h:27
int fdt_alias(struct fdt *fdt, const char *name, unsigned int *offset)
Find node by alias.
Definition: fdt.c:466
Executable images.
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
static struct net_device * netdev
Definition: gdbudp.c:52
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
static unsigned int count
Number of entries.
Definition: dwmac.h:225
uint32_t last_comp_version
Lowest version to which this structure is compatible.
Definition: fdt.h:33
uint32_t size_cells
Number of size cells.
Definition: fdt.h:141
size_t len
Length of property data (if applicable)
Definition: fdt.h:131
unsigned int structure
Offset to structure block.
Definition: fdt.h:102
uint64_t size
Length of reservation.
Definition: fdt.h:85
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_parent(struct fdt *fdt, unsigned int offset, unsigned int *parent)
Find parent node.
Definition: fdt.c:293
uint32_t size_dt_strings
Length of string block.
Definition: fdt.h:37
Property fragment.
Definition: fdt.h:61
A network device.
Definition: netdevice.h:353
size_t used
Used length of tree.
Definition: fdt.h:100
uint32_t off_mem_rsvmap
Offset to memory reservation block.
Definition: fdt.h:29
unsigned int uint32_t
Definition: stdint.h:12
struct i386_regs regs
Definition: registers.h:15
size_t structure_len
Length of structure block.
Definition: fdt.h:104
unsigned long physaddr_t
Definition: stdint.h:20
int fdt_path(struct fdt *fdt, const char *path, unsigned int *offset)
Find node by path.
Definition: fdt.c:426
uint32_t boot_cpuid_phys
Physical ID of the boot CPU.
Definition: fdt.h:35
A device tree.
Definition: fdt.h:89
uint32_t size_dt_struct
Length of structure block.
Definition: fdt.h:39
unsigned int offset
Offset within structure block.
Definition: fdt.h:123
uint32_t totalsize
Total size of device tree.
Definition: fdt.h:23
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
uint32_t name_off
Name offset.
Definition: fdt.h:65
int fdt_describe(struct fdt *fdt, unsigned int offset, struct fdt_descriptor *desc)
Describe device tree token.
Definition: fdt.c:90
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
uint64_t start
Starting address.
Definition: fdt.h:83
int fdt_parse(struct fdt *fdt, struct fdt_header *hdr, size_t max_len)
Parse device tree.
Definition: fdt.c:904
int fdt_mac(struct fdt *fdt, unsigned int offset, struct net_device *netdev)
Get MAC address from property.
Definition: fdt.c:867
A device tree token descriptor.
Definition: fdt.h:121
uint16_t offset
Offset to command line.
Definition: bzimage.h:8
FILE_SECBOOT(PERMITTED)
uint32_t cmdline
Definition: multiboot.h:16
struct fdt sysfdt
The system flattened device tree (if present)
Definition: fdt.c:45
const void * data
Property data (if applicable)
Definition: fdt.h:129
uint32_t fdt_phandle(struct fdt *fdt, unsigned int offset)
Get package handle (phandle) property.
Definition: fdt.c:690
unsigned int strings
Offset to strings block.
Definition: fdt.h:106
#define initrd_len
Definition: runtime.c:63