xref: /rk3399_ARM-atf/include/common/fdt_wrappers.h (revision 7ad6d362016a875eaee0d227365b74acd464050b)
1e5674e1fSSoby Mathew /*
20a2ab6e6SAlexei Fedorov  * Copyright (c) 2018-2020, 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 
12e5674e1fSSoby Mathew /* Number of cells, given total length in bytes. Each cell is 4 bytes long */
1381542c00SAntonio Nino Diaz #define NCELLS(len) ((len) / 4U)
14e5674e1fSSoby Mathew 
15ff4e6c35SAndre Przywara int fdt_read_uint32(const void *dtb, int node, const char *prop_name,
16ff4e6c35SAndre Przywara 		    uint32_t *value);
17be858cffSAndre Przywara uint32_t fdt_read_uint32_default(const void *dtb, int node,
18be858cffSAndre Przywara 				 const char *prop_name, uint32_t dflt_value);
19ff4e6c35SAndre Przywara int fdt_read_uint64(const void *dtb, int node, const char *prop_name,
20ff4e6c35SAndre Przywara 		    uint64_t *value);
216e3a89f4SAndre Przywara int fdt_read_uint32_array(const void *dtb, int node, const char *prop_name,
226e3a89f4SAndre Przywara 			  unsigned int cells, uint32_t *value);
2327473620SAntonio Nino Diaz int fdtw_read_string(const void *dtb, int node, const char *prop,
2427473620SAntonio Nino Diaz 		char *str, size_t size);
25e5674e1fSSoby Mathew int fdtw_write_inplace_cells(void *dtb, int node, const char *prop,
26e5674e1fSSoby Mathew 		unsigned int cells, void *value);
270a2ab6e6SAlexei Fedorov int fdtw_read_bytes(const void *dtb, int node, const char *prop,
280a2ab6e6SAlexei Fedorov 		unsigned int length, void *value);
290a2ab6e6SAlexei Fedorov int fdtw_write_inplace_bytes(void *dtb, int node, const char *prop,
300a2ab6e6SAlexei Fedorov 		unsigned int length, const void *data);
31364ad245SAndre Przywara int fdt_get_reg_props_by_index(const void *dtb, int node, int index,
32364ad245SAndre Przywara 			       uintptr_t *base, size_t *size);
33*7ad6d362SAndre Przywara int fdt_get_reg_props_by_name(const void *dtb, int node, const char *name,
34*7ad6d362SAndre Przywara 			      uintptr_t *base, size_t *size);
3527473620SAntonio Nino Diaz 
36c3cf06f1SAntonio Nino Diaz #endif /* FDT_WRAPPERS_H */
37