xref: /rk3399_ARM-atf/include/common/fdt_wrappers.h (revision 2d9ea360350303e37a8dd39f3599ac88aaef0ff9)
1e5674e1fSSoby Mathew /*
2d13dbb6fSDavid Horstmann  * Copyright (c) 2018-2021, ARM Limited and Contributors. All rights reserved.
3e5674e1fSSoby Mathew  *
4e5674e1fSSoby Mathew  * SPDX-License-Identifier: BSD-3-Clause
5e5674e1fSSoby Mathew  */
6e5674e1fSSoby Mathew 
7e5674e1fSSoby Mathew /* Helper functions to offer easier navigation of Device Tree Blob */
8e5674e1fSSoby Mathew 
9c3cf06f1SAntonio Nino Diaz #ifndef FDT_WRAPPERS_H
10c3cf06f1SAntonio Nino Diaz #define FDT_WRAPPERS_H
11e5674e1fSSoby Mathew 
125a430c02SAndre Przywara #include <libfdt_env.h>
135a430c02SAndre Przywara 
14e5674e1fSSoby Mathew /* Number of cells, given total length in bytes. Each cell is 4 bytes long */
1581542c00SAntonio Nino Diaz #define NCELLS(len) ((len) / 4U)
16e5674e1fSSoby Mathew 
17ff4e6c35SAndre Przywara int fdt_read_uint32(const void *dtb, int node, const char *prop_name,
18ff4e6c35SAndre Przywara 		    uint32_t *value);
19be858cffSAndre Przywara uint32_t fdt_read_uint32_default(const void *dtb, int node,
20be858cffSAndre Przywara 				 const char *prop_name, uint32_t dflt_value);
21ff4e6c35SAndre Przywara int fdt_read_uint64(const void *dtb, int node, const char *prop_name,
22ff4e6c35SAndre Przywara 		    uint64_t *value);
236e3a89f4SAndre Przywara int fdt_read_uint32_array(const void *dtb, int node, const char *prop_name,
246e3a89f4SAndre Przywara 			  unsigned int cells, uint32_t *value);
2527473620SAntonio Nino Diaz int fdtw_read_string(const void *dtb, int node, const char *prop,
2627473620SAntonio Nino Diaz 		char *str, size_t size);
27d13dbb6fSDavid Horstmann int fdtw_read_uuid(const void *dtb, int node, const char *prop,
28d13dbb6fSDavid Horstmann 		   unsigned int length, uint8_t *uuid);
29e5674e1fSSoby Mathew int fdtw_write_inplace_cells(void *dtb, int node, const char *prop,
30e5674e1fSSoby Mathew 		unsigned int cells, void *value);
310a2ab6e6SAlexei Fedorov int fdtw_read_bytes(const void *dtb, int node, const char *prop,
320a2ab6e6SAlexei Fedorov 		unsigned int length, void *value);
330a2ab6e6SAlexei Fedorov int fdtw_write_inplace_bytes(void *dtb, int node, const char *prop,
340a2ab6e6SAlexei Fedorov 		unsigned int length, const void *data);
35364ad245SAndre Przywara int fdt_get_reg_props_by_index(const void *dtb, int node, int index,
36364ad245SAndre Przywara 			       uintptr_t *base, size_t *size);
377ad6d362SAndre Przywara int fdt_get_reg_props_by_name(const void *dtb, int node, const char *name,
387ad6d362SAndre Przywara 			      uintptr_t *base, size_t *size);
3960e2e27dSAndre Przywara int fdt_get_stdout_node_offset(const void *dtb);
4027473620SAntonio Nino Diaz 
41447870bfSMadhukar Pappireddy uint64_t fdtw_translate_address(const void *dtb, int bus_node,
42447870bfSMadhukar Pappireddy 				uint64_t base_address);
43447870bfSMadhukar Pappireddy 
44*2d9ea360SChris Kay int fdtw_for_each_cpu(const void *fdt,
45*2d9ea360SChris Kay 		      int (*callback)(const void *dtb, int node, uintptr_t mpidr));
46*2d9ea360SChris Kay 
475a430c02SAndre Przywara static inline uint32_t fdt_blob_size(const void *dtb)
485a430c02SAndre Przywara {
495a430c02SAndre Przywara 	const uint32_t *dtb_header = dtb;
505a430c02SAndre Przywara 
515a430c02SAndre Przywara 	return fdt32_to_cpu(dtb_header[1]);
525a430c02SAndre Przywara }
535a430c02SAndre Przywara 
54ff766148SLaurent Carlier #define fdt_for_each_compatible_node(dtb, node, compatible_str)       \
55ff766148SLaurent Carlier for (node = fdt_node_offset_by_compatible(dtb, -1, compatible_str);   \
56ff766148SLaurent Carlier      node >= 0;                                                       \
57ff766148SLaurent Carlier      node = fdt_node_offset_by_compatible(dtb, node, compatible_str))
58ff766148SLaurent Carlier 
59c3cf06f1SAntonio Nino Diaz #endif /* FDT_WRAPPERS_H */
60