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