xref: /rk3399_ARM-atf/lib/libfdt/libfdt_internal.h (revision 630b011ffd6a83436581af71d770ddd9fe01f747)
1*630b011fSAntonio Nino Diaz #ifndef LIBFDT_INTERNAL_H
2*630b011fSAntonio Nino Diaz #define LIBFDT_INTERNAL_H
3*630b011fSAntonio Nino Diaz /*
4*630b011fSAntonio Nino Diaz  * libfdt - Flat Device Tree manipulation
5*630b011fSAntonio Nino Diaz  * Copyright (C) 2006 David Gibson, IBM Corporation.
6*630b011fSAntonio Nino Diaz  *
7*630b011fSAntonio Nino Diaz  * libfdt is dual licensed: you can use it either under the terms of
8*630b011fSAntonio Nino Diaz  * the GPL, or the BSD license, at your option.
9*630b011fSAntonio Nino Diaz  *
10*630b011fSAntonio Nino Diaz  *  a) This library is free software; you can redistribute it and/or
11*630b011fSAntonio Nino Diaz  *     modify it under the terms of the GNU General Public License as
12*630b011fSAntonio Nino Diaz  *     published by the Free Software Foundation; either version 2 of the
13*630b011fSAntonio Nino Diaz  *     License, or (at your option) any later version.
14*630b011fSAntonio Nino Diaz  *
15*630b011fSAntonio Nino Diaz  *     This library is distributed in the hope that it will be useful,
16*630b011fSAntonio Nino Diaz  *     but WITHOUT ANY WARRANTY; without even the implied warranty of
17*630b011fSAntonio Nino Diaz  *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*630b011fSAntonio Nino Diaz  *     GNU General Public License for more details.
19*630b011fSAntonio Nino Diaz  *
20*630b011fSAntonio Nino Diaz  *     You should have received a copy of the GNU General Public
21*630b011fSAntonio Nino Diaz  *     License along with this library; if not, write to the Free
22*630b011fSAntonio Nino Diaz  *     Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
23*630b011fSAntonio Nino Diaz  *     MA 02110-1301 USA
24*630b011fSAntonio Nino Diaz  *
25*630b011fSAntonio Nino Diaz  * Alternatively,
26*630b011fSAntonio Nino Diaz  *
27*630b011fSAntonio Nino Diaz  *  b) Redistribution and use in source and binary forms, with or
28*630b011fSAntonio Nino Diaz  *     without modification, are permitted provided that the following
29*630b011fSAntonio Nino Diaz  *     conditions are met:
30*630b011fSAntonio Nino Diaz  *
31*630b011fSAntonio Nino Diaz  *     1. Redistributions of source code must retain the above
32*630b011fSAntonio Nino Diaz  *        copyright notice, this list of conditions and the following
33*630b011fSAntonio Nino Diaz  *        disclaimer.
34*630b011fSAntonio Nino Diaz  *     2. Redistributions in binary form must reproduce the above
35*630b011fSAntonio Nino Diaz  *        copyright notice, this list of conditions and the following
36*630b011fSAntonio Nino Diaz  *        disclaimer in the documentation and/or other materials
37*630b011fSAntonio Nino Diaz  *        provided with the distribution.
38*630b011fSAntonio Nino Diaz  *
39*630b011fSAntonio Nino Diaz  *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
40*630b011fSAntonio Nino Diaz  *     CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
41*630b011fSAntonio Nino Diaz  *     INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
42*630b011fSAntonio Nino Diaz  *     MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
43*630b011fSAntonio Nino Diaz  *     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
44*630b011fSAntonio Nino Diaz  *     CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45*630b011fSAntonio Nino Diaz  *     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46*630b011fSAntonio Nino Diaz  *     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47*630b011fSAntonio Nino Diaz  *     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48*630b011fSAntonio Nino Diaz  *     HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
49*630b011fSAntonio Nino Diaz  *     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
50*630b011fSAntonio Nino Diaz  *     OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
51*630b011fSAntonio Nino Diaz  *     EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
52*630b011fSAntonio Nino Diaz  */
53*630b011fSAntonio Nino Diaz #include <fdt.h>
54*630b011fSAntonio Nino Diaz 
55*630b011fSAntonio Nino Diaz #define FDT_ALIGN(x, a)		(((x) + (a) - 1) & ~((a) - 1))
56*630b011fSAntonio Nino Diaz #define FDT_TAGALIGN(x)		(FDT_ALIGN((x), FDT_TAGSIZE))
57*630b011fSAntonio Nino Diaz 
58*630b011fSAntonio Nino Diaz int fdt_ro_probe_(const void *fdt);
59*630b011fSAntonio Nino Diaz #define FDT_RO_PROBE(fdt)			\
60*630b011fSAntonio Nino Diaz 	{ \
61*630b011fSAntonio Nino Diaz 		int err_; \
62*630b011fSAntonio Nino Diaz 		if ((err_ = fdt_ro_probe_(fdt)) != 0)	\
63*630b011fSAntonio Nino Diaz 			return err_; \
64*630b011fSAntonio Nino Diaz 	}
65*630b011fSAntonio Nino Diaz 
66*630b011fSAntonio Nino Diaz int fdt_check_node_offset_(const void *fdt, int offset);
67*630b011fSAntonio Nino Diaz int fdt_check_prop_offset_(const void *fdt, int offset);
68*630b011fSAntonio Nino Diaz const char *fdt_find_string_(const char *strtab, int tabsize, const char *s);
69*630b011fSAntonio Nino Diaz int fdt_node_end_offset_(void *fdt, int nodeoffset);
70*630b011fSAntonio Nino Diaz 
71*630b011fSAntonio Nino Diaz static inline const void *fdt_offset_ptr_(const void *fdt, int offset)
72*630b011fSAntonio Nino Diaz {
73*630b011fSAntonio Nino Diaz 	return (const char *)fdt + fdt_off_dt_struct(fdt) + offset;
74*630b011fSAntonio Nino Diaz }
75*630b011fSAntonio Nino Diaz 
76*630b011fSAntonio Nino Diaz static inline void *fdt_offset_ptr_w_(void *fdt, int offset)
77*630b011fSAntonio Nino Diaz {
78*630b011fSAntonio Nino Diaz 	return (void *)(uintptr_t)fdt_offset_ptr_(fdt, offset);
79*630b011fSAntonio Nino Diaz }
80*630b011fSAntonio Nino Diaz 
81*630b011fSAntonio Nino Diaz static inline const struct fdt_reserve_entry *fdt_mem_rsv_(const void *fdt, int n)
82*630b011fSAntonio Nino Diaz {
83*630b011fSAntonio Nino Diaz 	const struct fdt_reserve_entry *rsv_table =
84*630b011fSAntonio Nino Diaz 		(const struct fdt_reserve_entry *)
85*630b011fSAntonio Nino Diaz 		((const char *)fdt + fdt_off_mem_rsvmap(fdt));
86*630b011fSAntonio Nino Diaz 
87*630b011fSAntonio Nino Diaz 	return rsv_table + n;
88*630b011fSAntonio Nino Diaz }
89*630b011fSAntonio Nino Diaz static inline struct fdt_reserve_entry *fdt_mem_rsv_w_(void *fdt, int n)
90*630b011fSAntonio Nino Diaz {
91*630b011fSAntonio Nino Diaz 	return (void *)(uintptr_t)fdt_mem_rsv_(fdt, n);
92*630b011fSAntonio Nino Diaz }
93*630b011fSAntonio Nino Diaz 
94*630b011fSAntonio Nino Diaz #define FDT_SW_MAGIC		(~FDT_MAGIC)
95*630b011fSAntonio Nino Diaz 
96*630b011fSAntonio Nino Diaz #endif /* LIBFDT_INTERNAL_H */
97