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