blob: 9a79fe85ddaf092904cb1c1a421a98fee1dcf696 [file] [log] [blame]
Gerald Van Baren7cd5da02007-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 Meier35084762013-07-27 01:12:38 +02006 * SPDX-License-Identifier: GPL-2.0+ BSD-2-Clause
Gerald Van Baren7cd5da02007-03-31 11:59:59 -04007 */
8#include <fdt.h>
9
David Gibsonfc7758e2008-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 Baren7cd5da02007-03-31 11:59:59 -040012
David Gibsonfc7758e2008-07-09 14:10:24 +100013#define FDT_CHECK_HEADER(fdt) \
David Gibsond0ccb9b2008-02-18 18:06:31 +110014 { \
Simon Glass0596d352014-07-30 03:59:03 -060015 int __err; \
16 if ((__err = fdt_check_header(fdt)) != 0) \
17 return __err; \
David Gibsond0ccb9b2008-02-18 18:06:31 +110018 }
19
David Gibson2f08bfa2008-05-20 17:19:11 +100020int _fdt_check_node_offset(const void *fdt, int offset);
David Gibsond1c63142010-03-09 17:39:14 +110021int _fdt_check_prop_offset(const void *fdt, int offset);
Gerald Van Baren7cd5da02007-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 Gala8d04f022007-10-24 11:04:22 -050025static inline const void *_fdt_offset_ptr(const void *fdt, int offset)
Gerald Van Baren7cd5da02007-03-31 11:59:59 -040026{
David Gibsonef4e8ce2008-07-07 10:10:48 +100027 return (const char *)fdt + fdt_off_dt_struct(fdt) + offset;
Kumar Gala8d04f022007-10-24 11:04:22 -050028}
29
30static inline void *_fdt_offset_ptr_w(void *fdt, int offset)
31{
David Gibsonc6683022008-07-07 10:14:15 +100032 return (void *)(uintptr_t)_fdt_offset_ptr(fdt, offset);
Kumar Gala8d04f022007-10-24 11:04:22 -050033}
34
35static inline const struct fdt_reserve_entry *_fdt_mem_rsv(const void *fdt, int n)
36{
David Gibsonc6683022008-07-07 10:14:15 +100037 const struct fdt_reserve_entry *rsv_table =
38 (const struct fdt_reserve_entry *)
David Gibsonef4e8ce2008-07-07 10:10:48 +100039 ((const char *)fdt + fdt_off_mem_rsvmap(fdt));
Kumar Gala8d04f022007-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)
44{
David Gibsonc6683022008-07-07 10:14:15 +100045 return (void *)(uintptr_t)_fdt_mem_rsv(fdt, n);
Gerald Van Baren7cd5da02007-03-31 11:59:59 -040046}
47
David Gibsonfc7758e2008-07-09 14:10:24 +100048#define FDT_SW_MAGIC (~FDT_MAGIC)
Gerald Van Baren7cd5da02007-03-31 11:59:59 -040049
50#endif /* _LIBFDT_INTERNAL_H */