Gerald Van Baren | c0577a6 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 1 | #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 Meier | 3eaedea | 2013-07-27 01:12:38 +0200 | [diff] [blame] | 6 | * SPDX-License-Identifier: GPL-2.0+ BSD-2-Clause |
Gerald Van Baren | c0577a6 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 7 | */ |
| 8 | #include <fdt.h> |
| 9 | |
David Gibson | 9457d9d | 2008-07-09 14:10:24 +1000 | [diff] [blame] | 10 | #define FDT_ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1)) |
| 11 | #define FDT_TAGALIGN(x) (FDT_ALIGN((x), FDT_TAGSIZE)) |
Gerald Van Baren | c0577a6 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 12 | |
David Gibson | 9457d9d | 2008-07-09 14:10:24 +1000 | [diff] [blame] | 13 | #define FDT_CHECK_HEADER(fdt) \ |
David Gibson | 87c51cb | 2008-02-18 18:06:31 +1100 | [diff] [blame] | 14 | { \ |
| 15 | int err; \ |
| 16 | if ((err = fdt_check_header(fdt)) != 0) \ |
| 17 | return err; \ |
| 18 | } |
| 19 | |
David Gibson | 148a49b | 2008-05-20 17:19:11 +1000 | [diff] [blame] | 20 | int _fdt_check_node_offset(const void *fdt, int offset); |
David Gibson | 7b64da1 | 2010-03-09 17:39:14 +1100 | [diff] [blame] | 21 | int _fdt_check_prop_offset(const void *fdt, int offset); |
Gerald Van Baren | c0577a6 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 22 | const char *_fdt_find_string(const char *strtab, int tabsize, const char *s); |
| 23 | int _fdt_node_end_offset(void *fdt, int nodeoffset); |
| 24 | |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 25 | static inline const void *_fdt_offset_ptr(const void *fdt, int offset) |
| 26 | { |
David Gibson | b4141b8 | 2008-07-07 10:10:48 +1000 | [diff] [blame] | 27 | return (const char *)fdt + fdt_off_dt_struct(fdt) + offset; |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | static inline void *_fdt_offset_ptr_w(void *fdt, int offset) |
| 31 | { |
David Gibson | 870fa47 | 2008-07-07 10:14:15 +1000 | [diff] [blame] | 32 | return (void *)(uintptr_t)_fdt_offset_ptr(fdt, offset); |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | static inline const struct fdt_reserve_entry *_fdt_mem_rsv(const void *fdt, int n) |
| 36 | { |
David Gibson | 870fa47 | 2008-07-07 10:14:15 +1000 | [diff] [blame] | 37 | const struct fdt_reserve_entry *rsv_table = |
| 38 | (const struct fdt_reserve_entry *) |
David Gibson | b4141b8 | 2008-07-07 10:10:48 +1000 | [diff] [blame] | 39 | ((const char *)fdt + fdt_off_mem_rsvmap(fdt)); |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 40 | |
| 41 | return rsv_table + n; |
| 42 | } |
| 43 | static inline struct fdt_reserve_entry *_fdt_mem_rsv_w(void *fdt, int n) |
Gerald Van Baren | c0577a6 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 44 | { |
David Gibson | 870fa47 | 2008-07-07 10:14:15 +1000 | [diff] [blame] | 45 | return (void *)(uintptr_t)_fdt_mem_rsv(fdt, n); |
Gerald Van Baren | c0577a6 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 46 | } |
| 47 | |
David Gibson | 9457d9d | 2008-07-09 14:10:24 +1000 | [diff] [blame] | 48 | #define FDT_SW_MAGIC (~FDT_MAGIC) |
Gerald Van Baren | c0577a6 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 49 | |
| 50 | #endif /* _LIBFDT_INTERNAL_H */ |