soc/intel/xeon_sp/spr: Drop microcode constraints
[coreboot2.git] / src / include / device_tree.h
blobe7b79e1a94f11955b80324adcf0c0cdc2c552323
1 /* Taken from depthcharge: src/base/device_tree.h */
2 /* SPDX-License-Identifier: GPL-2.0-or-later */
4 #ifndef __DEVICE_TREE_H__
5 #define __DEVICE_TREE_H__
7 #include <stddef.h>
8 #include <stdint.h>
9 #include <commonlib/list.h>
12 * Flattened device tree structures/constants.
15 struct fdt_header {
16 uint32_t magic;
17 uint32_t totalsize;
18 uint32_t structure_offset;
19 uint32_t strings_offset;
20 uint32_t reserve_map_offset;
22 uint32_t version;
23 uint32_t last_comp_version;
25 uint32_t boot_cpuid_phys;
27 uint32_t strings_size;
28 uint32_t structure_size;
31 #define FDT_HEADER_MAGIC 0xd00dfeed
32 #define FDT_SUPPORTED_VERSION 17
33 #define FDT_TOKEN_BEGIN_NODE 1
34 #define FDT_TOKEN_END_NODE 2
35 #define FDT_TOKEN_PROPERTY 3
36 #define FDT_TOKEN_END 9
37 #define FDT_PHANDLE_ILLEGAL 0xdeadbeef
39 struct fdt_property
41 const char *name;
42 void *data;
43 uint32_t size;
47 * Unflattened device tree structures.
50 struct device_tree_property
52 struct fdt_property prop;
54 struct list_node list_node;
57 struct device_tree_node
59 const char *name;
60 uint32_t phandle;
62 /* List of struct device_tree_property-s. */
63 struct list_node properties;
64 /* List of struct device_tree_nodes. */
65 struct list_node children;
67 struct list_node list_node;
70 struct device_tree_reserve_map_entry
72 uint64_t start;
73 uint64_t size;
75 struct list_node list_node;
78 struct device_tree
80 const void *header;
81 uint32_t header_size;
82 uint32_t max_phandle;
84 struct list_node reserve_map;
86 struct device_tree_node *root;
90 * Flattened device tree functions. These generally return the number of bytes
91 * which were consumed reading the requested value.
94 /* Read the property at offset, if any exists. */
95 int fdt_next_property(const void *blob, uint32_t offset,
96 struct fdt_property *prop);
97 /* Read the name of the node at offset, if any exists. */
98 int fdt_node_name(const void *blob, uint32_t offset, const char **name);
100 void fdt_print_node(const void *blob, uint32_t offset);
101 int fdt_skip_node(const void *blob, uint32_t offset);
103 /* Read a flattened device tree into a hierarchical structure which refers to
104 the contents of the flattened tree in place. Modifying the flat tree
105 invalidates the unflattened one. */
106 struct device_tree *fdt_unflatten(const void *blob);
109 * Unflattened device tree functions.
112 /* Figure out how big a device tree would be if it were flattened. */
113 uint32_t dt_flat_size(const struct device_tree *tree);
114 /* Flatten a device tree into the buffer pointed to by dest. */
115 void dt_flatten(const struct device_tree *tree, void *dest);
116 void dt_print_node(const struct device_tree_node *node);
117 /* Read #address-cells and #size-cells properties from a node. */
118 void dt_read_cell_props(const struct device_tree_node *node, u32 *addrcp,
119 u32 *sizecp);
120 /* Look up or create a node relative to a parent node, through its path
121 represented as an array of strings. */
122 struct device_tree_node *dt_find_node(struct device_tree_node *parent, const char **path,
123 u32 *addrcp, u32 *sizecp, int create);
124 struct device_tree_node *dt_find_node_by_phandle(struct device_tree_node *root,
125 uint32_t phandle);
126 /* Look up or create a node in the tree, through its path
127 represented as a string of '/' separated node names. */
128 struct device_tree_node *dt_find_node_by_path(struct device_tree *tree,
129 const char *path, u32 *addrcp, u32 *sizecp, int create);
130 /* Look up a node through an alias. */
131 struct device_tree_node *dt_find_node_by_alias(struct device_tree *tree,
132 const char *alias);
133 /* Look up a node relative to a parent node, through its compatible string. */
134 struct device_tree_node *dt_find_compat(struct device_tree_node *parent, const char *compatible);
135 /* Look up the next child of a parent node, through its compatible string. It
136 uses child pointer as the marker to find next. */
137 struct device_tree_node *dt_find_next_compat_child(struct device_tree_node *parent,
138 struct device_tree_node *child,
139 const char *compat);
140 /* Look up a node relative to a parent node, through its property value. */
141 struct device_tree_node *dt_find_prop_value(struct device_tree_node *parent, const char *name,
142 void *data, size_t size);
143 /* Write src into *dest as a 'length'-byte big-endian integer. */
144 void dt_write_int(u8 *dest, u64 src, size_t length);
145 /* Delete a property */
146 void dt_delete_prop(struct device_tree_node *node, const char *name);
147 /* Add different kinds of properties to a node, or update existing ones. */
148 void dt_add_bin_prop(struct device_tree_node *node, const char *name,
149 void *data, size_t size);
150 void dt_add_string_prop(struct device_tree_node *node, const char *name,
151 const char *str);
152 void dt_add_u32_prop(struct device_tree_node *node, const char *name, u32 val);
153 void dt_add_u64_prop(struct device_tree_node *node, const char *name, u64 val);
154 void dt_add_reg_prop(struct device_tree_node *node, u64 *addrs, u64 *sizes,
155 int count, u32 addr_cells, u32 size_cells);
156 int dt_set_bin_prop_by_path(struct device_tree *tree, const char *path,
157 void *data, size_t size, int create);
159 void dt_find_bin_prop(const struct device_tree_node *node, const char *name,
160 const void **data, size_t *size);
161 const char *dt_find_string_prop(const struct device_tree_node *node,
162 const char *name);
164 /* Apply an overlay to a base device tree. Ownership of the overlay data passes
165 to the newly combined base tree -- do not free() or access it afterwards! */
166 int dt_apply_overlay(struct device_tree *tree, struct device_tree *overlay);
169 * Fixups to apply to a kernel's device tree before booting it.
172 struct device_tree_fixup
175 * The function which does the fixing.
176 * 0 on success, non-zero on error.
178 int (*fixup)(struct device_tree_fixup *fixup,
179 struct device_tree *tree);
181 struct list_node list_node;
184 extern struct list_node device_tree_fixups;
187 * Function to apply fixups.
188 * 0 on success, non-zero on error.
190 int dt_apply_fixups(struct device_tree *tree);
193 * Init/retrieve the /reserved-memory/ node.
195 struct device_tree_node *dt_init_reserved_memory_node(struct device_tree *tree);
197 #endif /* __DEVICE_TREE_H__ */