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