diff options
author | Maximilian Brune <maximilian.brune@9elements.com> | 2024-03-04 15:34:41 +0100 |
---|---|---|
committer | Lean Sheng Tan <sheng.tan@9elements.com> | 2024-05-21 13:44:47 +0000 |
commit | 33079b8174e614b75b81b9dea59baef2dc943e58 (patch) | |
tree | 0a725a0dd90929da17fe44e74644967cd41c56c0 /src/include | |
parent | 25c737d403818a92dfeb06e29ffaf04102d0f260 (diff) |
lib/device_tree: Add some FDT helper functions
This adds some helper functions for FDT, since more and more mainboards
seem to need FDT nowadays. For example our QEMU boards need it in order
to know how much RAM is available. Also all RISC-V boards in our tree
need FDT.
This also adds some tests in order to test said functions.
Signed-off-by: Maximilian Brune <maximilian.brune@9elements.com>
Change-Id: I2fb1d93c5b3e1cb2f7d9584db52bbce3767b63d8
Reviewed-on: https://review.coreboot.org/c/coreboot/+/81081
Reviewed-by: Julius Werner <jwerner@chromium.org>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/device_tree.h | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/include/device_tree.h b/src/include/device_tree.h index e7b79e1a94..6d2d65600f 100644 --- a/src/include/device_tree.h +++ b/src/include/device_tree.h @@ -4,6 +4,7 @@ #ifndef __DEVICE_TREE_H__ #define __DEVICE_TREE_H__ +#include <stdbool.h> #include <stddef.h> #include <stdint.h> #include <commonlib/list.h> @@ -33,6 +34,7 @@ struct fdt_header { #define FDT_TOKEN_BEGIN_NODE 1 #define FDT_TOKEN_END_NODE 2 #define FDT_TOKEN_PROPERTY 3 +#define FDT_TOKEN_NOP 4 #define FDT_TOKEN_END 9 #define FDT_PHANDLE_ILLEGAL 0xdeadbeef @@ -47,6 +49,11 @@ struct fdt_property * Unflattened device tree structures. */ +struct device_tree_region { + u64 addr; + u64 size; +}; + struct device_tree_property { struct fdt_property prop; @@ -91,6 +98,8 @@ struct device_tree * which were consumed reading the requested value. */ +/* Checks if blob points to a valid FDT */ +bool fdt_is_valid(const void *blob); /* Read the property at offset, if any exists. */ int fdt_next_property(const void *blob, uint32_t offset, struct fdt_property *prop); @@ -100,6 +109,26 @@ int fdt_node_name(const void *blob, uint32_t offset, const char **name); void fdt_print_node(const void *blob, uint32_t offset); int fdt_skip_node(const void *blob, uint32_t offset); +/* Read property and put into fdt_prop. Returns offset to property */ +u32 fdt_read_prop(const void *blob, u32 node_offset, const char *prop_name, + struct fdt_property *fdt_prop); +/* Read reg property and save regions inside 'regions'. Returns number of regions read */ +u32 fdt_read_reg_prop(const void *blob, u32 node_offset, u32 addr_cells, u32 size_cells, + struct device_tree_region regions[], size_t regions_count); +/* Find a node by a given path and return the offset */ +u32 fdt_find_node_by_path(const void *blob, const char *path, u32 *addrcp, u32 *sizecp); +/* Find multiple nodes matching a given pattern. Returns number of nodes found */ +size_t fdt_find_subnodes_by_prefix(const void *blob, u32 node_offset, const char *prefix, + u32 *addrcp, u32 *sizecp, u32 results[], size_t results_len); +/* Find a node by a given alias and return its offset */ +u32 fdt_find_node_by_alias(const void *blob, const char *alias_name, + u32 *addr_cells, u32 *size_cells); +/* + * Read the node name into 'name' of the node behind 'node_offset' + * and return total bytes used for name + */ +int fdt_next_node_name(const void *blob, uint32_t node_offset, const char **name); + /* Read a flattened device tree into a hierarchical structure which refers to the contents of the flattened tree in place. Modifying the flat tree invalidates the unflattened one. */ |