• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2018-2020, ARM Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 /* Helper functions to offer easier navigation of Device Tree Blob */
8 
9 #ifndef FDT_WRAPPERS_H
10 #define FDT_WRAPPERS_H
11 
12 #include <libfdt_env.h>
13 
14 /* Number of cells, given total length in bytes. Each cell is 4 bytes long */
15 #define NCELLS(len) ((len) / 4U)
16 
17 int fdt_read_uint32(const void *dtb, int node, const char *prop_name,
18 		    uint32_t *value);
19 uint32_t fdt_read_uint32_default(const void *dtb, int node,
20 				 const char *prop_name, uint32_t dflt_value);
21 int fdt_read_uint64(const void *dtb, int node, const char *prop_name,
22 		    uint64_t *value);
23 int fdt_read_uint32_array(const void *dtb, int node, const char *prop_name,
24 			  unsigned int cells, uint32_t *value);
25 int fdtw_read_string(const void *dtb, int node, const char *prop,
26 		char *str, size_t size);
27 int fdtw_write_inplace_cells(void *dtb, int node, const char *prop,
28 		unsigned int cells, void *value);
29 int fdtw_read_bytes(const void *dtb, int node, const char *prop,
30 		unsigned int length, void *value);
31 int fdtw_write_inplace_bytes(void *dtb, int node, const char *prop,
32 		unsigned int length, const void *data);
33 int fdt_get_reg_props_by_index(const void *dtb, int node, int index,
34 			       uintptr_t *base, size_t *size);
35 int fdt_get_reg_props_by_name(const void *dtb, int node, const char *name,
36 			      uintptr_t *base, size_t *size);
37 int fdt_get_stdout_node_offset(const void *dtb);
38 
39 uint64_t fdtw_translate_address(const void *dtb, int bus_node,
40 				uint64_t base_address);
41 
fdt_blob_size(const void * dtb)42 static inline uint32_t fdt_blob_size(const void *dtb)
43 {
44 	const uint32_t *dtb_header = dtb;
45 
46 	return fdt32_to_cpu(dtb_header[1]);
47 }
48 
49 #endif /* FDT_WRAPPERS_H */
50