libfdt_internal.h revision 9537:ad5b3252dcc6
1/*
2 * libfdt - Flat Device Tree manipulation
3 * Copyright (C) 2006 David Gibson, IBM Corporation.
4 *
5 *     Redistribution and use in source and binary forms, with or
6 *     without modification, are permitted provided that the following
7 *     conditions are met:
8 *
9 *     1. Redistributions of source code must retain the above
10 *        copyright notice, this list of conditions and the following
11 *        disclaimer.
12 *     2. Redistributions in binary form must reproduce the above
13 *        copyright notice, this list of conditions and the following
14 *        disclaimer in the documentation and/or other materials
15 *        provided with the distribution.
16 *
17 *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
18 *     CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
19 *     INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20 *     MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 *     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
22 *     CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 *     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 *     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 *     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 *     HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 *     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28 *     OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
29 *     EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31#ifndef _LIBFDT_INTERNAL_H
32#define _LIBFDT_INTERNAL_H
33
34#include <fdt.h>
35
36#define FDT_ALIGN(x, a)		(((x) + (a) - 1) & ~((a) - 1))
37#define FDT_TAGALIGN(x)		(FDT_ALIGN((x), FDT_TAGSIZE))
38
39#define FDT_CHECK_HEADER(fdt) \
40        { \
41                int err; \
42                if ((err = fdt_check_header(fdt)) != 0) \
43                        return err; \
44        }
45
46int _fdt_check_node_offset(const void *fdt, int offset);
47int _fdt_check_prop_offset(const void *fdt, int offset);
48const char *_fdt_find_string(const char *strtab, int tabsize, const char *s);
49int _fdt_node_end_offset(void *fdt, int nodeoffset);
50
51static inline const void *_fdt_offset_ptr(const void *fdt, int offset)
52{
53        return (const char *)fdt + fdt_off_dt_struct(fdt) + offset;
54}
55
56static inline void *_fdt_offset_ptr_w(void *fdt, int offset)
57{
58        return (void *)(uintptr_t)_fdt_offset_ptr(fdt, offset);
59}
60
61static inline const struct fdt_reserve_entry *_fdt_mem_rsv(const void *fdt, int n)
62{
63        const struct fdt_reserve_entry *rsv_table =
64                (const struct fdt_reserve_entry *)
65                ((const char *)fdt + fdt_off_mem_rsvmap(fdt));
66
67        return rsv_table + n;
68}
69static inline struct fdt_reserve_entry *_fdt_mem_rsv_w(void *fdt, int n)
70{
71        return (void *)(uintptr_t)_fdt_mem_rsv(fdt, n);
72}
73
74#define FDT_SW_MAGIC		(~FDT_MAGIC)
75
76#endif /* _LIBFDT_INTERNAL_H */
77