blob: 9a79fe85ddaf092904cb1c1a421a98fee1dcf696 [file] [log] [blame]
Gerald Van Barenc0577a62007-03-31 11:59:59 -04001#ifndef _LIBFDT_INTERNAL_H
2#define _LIBFDT_INTERNAL_H
3/*
4 * libfdt - Flat Device Tree manipulation
5 * Copyright (C) 2006 David Gibson, IBM Corporation.
Roger Meier3eaedea2013-07-27 01:12:38 +02006 * SPDX-License-Identifier: GPL-2.0+ BSD-2-Clause
Gerald Van Barenc0577a62007-03-31 11:59:59 -04007 */
8#include <fdt.h>
9
David Gibson9457d9d2008-07-09 14:10:24 +100010#define FDT_ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
11#define FDT_TAGALIGN(x) (FDT_ALIGN((x), FDT_TAGSIZE))
Gerald Van Barenc0577a62007-03-31 11:59:59 -040012
David Gibson9457d9d2008-07-09 14:10:24 +100013#define FDT_CHECK_HEADER(fdt) \
David Gibson87c51cb2008-02-18 18:06:31 +110014 { \
Simon Glass536774d2014-07-30 03:59:03 -060015 int __err; \
16 if ((__err = fdt_check_header(fdt)) != 0) \
17 return __err; \
David Gibson87c51cb2008-02-18 18:06:31 +110018 }
19
David Gibson148a49b2008-05-20 17:19:11 +100020int _fdt_check_node_offset(const void *fdt, int offset);
David Gibson7b64da12010-03-09 17:39:14 +110021int _fdt_check_prop_offset(const void *fdt, int offset);
Gerald Van Barenc0577a62007-03-31 11:59:59 -040022const char *_fdt_find_string(const char *strtab, int tabsize, const char *s);
23int _fdt_node_end_offset(void *fdt, int nodeoffset);
24
Kumar Galac8ab7052007-10-24 11:04:22 -050025static inline const void *_fdt_offset_ptr(const void *fdt, int offset)
26{
David Gibsonb4141b82008-07-07 10:10:48 +100027 return (const char *)fdt + fdt_off_dt_struct(fdt) + offset;
Kumar Galac8ab7052007-10-24 11:04:22 -050028}
29
30static inline void *_fdt_offset_ptr_w(void *fdt, int offset)
31{
David Gibson870fa472008-07-07 10:14:15 +100032 return (void *)(uintptr_t)_fdt_offset_ptr(fdt, offset);
Kumar Galac8ab7052007-10-24 11:04:22 -050033}
34
35static inline const struct fdt_reserve_entry *_fdt_mem_rsv(const void *fdt, int n)
36{
David Gibson870fa472008-07-07 10:14:15 +100037 const struct fdt_reserve_entry *rsv_table =
38 (const struct fdt_reserve_entry *)
David Gibsonb4141b82008-07-07 10:10:48 +100039 ((const char *)fdt + fdt_off_mem_rsvmap(fdt));
Kumar Galac8ab7052007-10-24 11:04:22 -050040
41 return rsv_table + n;
42}
43static inline struct fdt_reserve_entry *_fdt_mem_rsv_w(void *fdt, int n)
Gerald Van Barenc0577a62007-03-31 11:59:59 -040044{
David Gibson870fa472008-07-07 10:14:15 +100045 return (void *)(uintptr_t)_fdt_mem_rsv(fdt, n);
Gerald Van Barenc0577a62007-03-31 11:59:59 -040046}
47
David Gibson9457d9d2008-07-09 14:10:24 +100048#define FDT_SW_MAGIC (~FDT_MAGIC)
Gerald Van Barenc0577a62007-03-31 11:59:59 -040049
50#endif /* _LIBFDT_INTERNAL_H */