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