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