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