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