1 /* SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) */
2 #ifndef LIBFDT_INTERNAL_H
3 #define LIBFDT_INTERNAL_H
4 /*
5  * libfdt - Flat Device Tree manipulation
6  * Copyright (C) 2006 David Gibson, IBM Corporation.
7  */
8 #include <fdt.h>
9 
10 #define FDT_ALIGN(x, a)		(((x) + (a) - 1) & ~((a) - 1))
11 #define FDT_TAGALIGN(x)		(FDT_ALIGN((x), FDT_TAGSIZE))
12 
13 int fdt_ro_probe_(const void *fdt);
14 #define FDT_RO_PROBE(fdt)					\
15 	{							\
16 		int totalsize_;					\
17 		if ((totalsize_ = fdt_ro_probe_(fdt)) < 0)	\
18 			return totalsize_;			\
19 	}
20 
21 int fdt_check_node_offset_(const void *fdt, int offset);
22 int fdt_check_prop_offset_(const void *fdt, int offset);
23 const char *fdt_find_string_(const char *strtab, int tabsize, const char *s);
24 int fdt_node_end_offset_(void *fdt, int nodeoffset);
25 
fdt_offset_ptr_(const void * fdt,int offset)26 static inline const void *fdt_offset_ptr_(const void *fdt, int offset)
27 {
28 	return (const char *)fdt + fdt_off_dt_struct(fdt) + offset;
29 }
30 
fdt_offset_ptr_w_(void * fdt,int offset)31 static inline void *fdt_offset_ptr_w_(void *fdt, int offset)
32 {
33 	return (void *)(uintptr_t)fdt_offset_ptr_(fdt, offset);
34 }
35 
fdt_mem_rsv_(const void * fdt,int n)36 static inline const struct fdt_reserve_entry *fdt_mem_rsv_(const void *fdt, int n)
37 {
38 	const struct fdt_reserve_entry *rsv_table =
39 		(const struct fdt_reserve_entry *)
40 		((const char *)fdt + fdt_off_mem_rsvmap(fdt));
41 
42 	return rsv_table + n;
43 }
fdt_mem_rsv_w_(void * fdt,int n)44 static inline struct fdt_reserve_entry *fdt_mem_rsv_w_(void *fdt, int n)
45 {
46 	return (void *)(uintptr_t)fdt_mem_rsv_(fdt, n);
47 }
48 
49 #define FDT_SW_MAGIC		(~FDT_MAGIC)
50 
51 #endif /* LIBFDT_INTERNAL_H */
52