Gerald Van Baren | 7cd5da0 | 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 | 3508476 | 2013-07-27 01:12:38 +0200 | [diff] [blame] | 6 | * SPDX-License-Identifier: GPL-2.0+ BSD-2-Clause |
Gerald Van Baren | 7cd5da0 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 7 | */ |
| 8 | #include <fdt.h> |
| 9 | |
David Gibson | fc7758e | 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 | 7cd5da0 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 12 | |
David Gibson | fc7758e | 2008-07-09 14:10:24 +1000 | [diff] [blame] | 13 | #define FDT_CHECK_HEADER(fdt) \ |
David Gibson | d0ccb9b | 2008-02-18 18:06:31 +1100 | [diff] [blame] | 14 | { \ |
Simon Glass | 0596d35 | 2014-07-30 03:59:03 -0600 | [diff] [blame] | 15 | int __err; \ |
| 16 | if ((__err = fdt_check_header(fdt)) != 0) \ |
| 17 | return __err; \ |
David Gibson | d0ccb9b | 2008-02-18 18:06:31 +1100 | [diff] [blame] | 18 | } |
| 19 | |
David Gibson | 2f08bfa | 2008-05-20 17:19:11 +1000 | [diff] [blame] | 20 | int _fdt_check_node_offset(const void *fdt, int offset); |
David Gibson | d1c6314 | 2010-03-09 17:39:14 +1100 | [diff] [blame] | 21 | int _fdt_check_prop_offset(const void *fdt, int offset); |
Gerald Van Baren | 7cd5da0 | 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 | 8d04f02 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 25 | static inline const void *_fdt_offset_ptr(const void *fdt, int offset) |
Gerald Van Baren | 7cd5da0 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 26 | { |
David Gibson | ef4e8ce | 2008-07-07 10:10:48 +1000 | [diff] [blame] | 27 | return (const char *)fdt + fdt_off_dt_struct(fdt) + offset; |
Kumar Gala | 8d04f02 | 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 | c668302 | 2008-07-07 10:14:15 +1000 | [diff] [blame] | 32 | return (void *)(uintptr_t)_fdt_offset_ptr(fdt, offset); |
Kumar Gala | 8d04f02 | 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 | c668302 | 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 | ef4e8ce | 2008-07-07 10:10:48 +1000 | [diff] [blame] | 39 | ((const char *)fdt + fdt_off_mem_rsvmap(fdt)); |
Kumar Gala | 8d04f02 | 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) |
| 44 | { |
David Gibson | c668302 | 2008-07-07 10:14:15 +1000 | [diff] [blame] | 45 | return (void *)(uintptr_t)_fdt_mem_rsv(fdt, n); |
Gerald Van Baren | 7cd5da0 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 46 | } |
| 47 | |
David Gibson | fc7758e | 2008-07-09 14:10:24 +1000 | [diff] [blame] | 48 | #define FDT_SW_MAGIC (~FDT_MAGIC) |
Gerald Van Baren | 7cd5da0 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 49 | |
| 50 | #endif /* _LIBFDT_INTERNAL_H */ |