xref: /freebsd-src/sys/contrib/libfdt/libfdt_internal.h (revision 6780e684d49034610f82bea5d3bfb04d42e91628)
1*6780e684SKyle Evans #ifndef LIBFDT_INTERNAL_H
2*6780e684SKyle Evans #define LIBFDT_INTERNAL_H
321fdc27aSRafal Jaworowski /*
421fdc27aSRafal Jaworowski  * libfdt - Flat Device Tree manipulation
521fdc27aSRafal Jaworowski  * Copyright (C) 2006 David Gibson, IBM Corporation.
621fdc27aSRafal Jaworowski  *
721fdc27aSRafal Jaworowski  * libfdt is dual licensed: you can use it either under the terms of
821fdc27aSRafal Jaworowski  * the GPL, or the BSD license, at your option.
921fdc27aSRafal Jaworowski  *
1021fdc27aSRafal Jaworowski  *  a) This library is free software; you can redistribute it and/or
1121fdc27aSRafal Jaworowski  *     modify it under the terms of the GNU General Public License as
1221fdc27aSRafal Jaworowski  *     published by the Free Software Foundation; either version 2 of the
1321fdc27aSRafal Jaworowski  *     License, or (at your option) any later version.
1421fdc27aSRafal Jaworowski  *
1521fdc27aSRafal Jaworowski  *     This library is distributed in the hope that it will be useful,
1621fdc27aSRafal Jaworowski  *     but WITHOUT ANY WARRANTY; without even the implied warranty of
1721fdc27aSRafal Jaworowski  *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1821fdc27aSRafal Jaworowski  *     GNU General Public License for more details.
1921fdc27aSRafal Jaworowski  *
2021fdc27aSRafal Jaworowski  *     You should have received a copy of the GNU General Public
2121fdc27aSRafal Jaworowski  *     License along with this library; if not, write to the Free
2221fdc27aSRafal Jaworowski  *     Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
2321fdc27aSRafal Jaworowski  *     MA 02110-1301 USA
2421fdc27aSRafal Jaworowski  *
2521fdc27aSRafal Jaworowski  * Alternatively,
2621fdc27aSRafal Jaworowski  *
2721fdc27aSRafal Jaworowski  *  b) Redistribution and use in source and binary forms, with or
2821fdc27aSRafal Jaworowski  *     without modification, are permitted provided that the following
2921fdc27aSRafal Jaworowski  *     conditions are met:
3021fdc27aSRafal Jaworowski  *
3121fdc27aSRafal Jaworowski  *     1. Redistributions of source code must retain the above
3221fdc27aSRafal Jaworowski  *        copyright notice, this list of conditions and the following
3321fdc27aSRafal Jaworowski  *        disclaimer.
3421fdc27aSRafal Jaworowski  *     2. Redistributions in binary form must reproduce the above
3521fdc27aSRafal Jaworowski  *        copyright notice, this list of conditions and the following
3621fdc27aSRafal Jaworowski  *        disclaimer in the documentation and/or other materials
3721fdc27aSRafal Jaworowski  *        provided with the distribution.
3821fdc27aSRafal Jaworowski  *
3921fdc27aSRafal Jaworowski  *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
4021fdc27aSRafal Jaworowski  *     CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
4121fdc27aSRafal Jaworowski  *     INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
4221fdc27aSRafal Jaworowski  *     MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
4321fdc27aSRafal Jaworowski  *     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
4421fdc27aSRafal Jaworowski  *     CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
4521fdc27aSRafal Jaworowski  *     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
4621fdc27aSRafal Jaworowski  *     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
4721fdc27aSRafal Jaworowski  *     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
4821fdc27aSRafal Jaworowski  *     HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
4921fdc27aSRafal Jaworowski  *     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
5021fdc27aSRafal Jaworowski  *     OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
5121fdc27aSRafal Jaworowski  *     EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5221fdc27aSRafal Jaworowski  */
5321fdc27aSRafal Jaworowski #include <fdt.h>
5421fdc27aSRafal Jaworowski 
5521fdc27aSRafal Jaworowski #define FDT_ALIGN(x, a)		(((x) + (a) - 1) & ~((a) - 1))
5621fdc27aSRafal Jaworowski #define FDT_TAGALIGN(x)		(FDT_ALIGN((x), FDT_TAGSIZE))
5721fdc27aSRafal Jaworowski 
5821fdc27aSRafal Jaworowski #define FDT_CHECK_HEADER(fdt) \
5921fdc27aSRafal Jaworowski 	{ \
60*6780e684SKyle Evans 		int err_; \
61*6780e684SKyle Evans 		if ((err_ = fdt_check_header(fdt)) != 0) \
62*6780e684SKyle Evans 			return err_; \
6321fdc27aSRafal Jaworowski 	}
6421fdc27aSRafal Jaworowski 
65*6780e684SKyle Evans int fdt_check_node_offset_(const void *fdt, int offset);
66*6780e684SKyle Evans int fdt_check_prop_offset_(const void *fdt, int offset);
67*6780e684SKyle Evans const char *fdt_find_string_(const char *strtab, int tabsize, const char *s);
68*6780e684SKyle Evans int fdt_node_end_offset_(void *fdt, int nodeoffset);
6921fdc27aSRafal Jaworowski 
fdt_offset_ptr_(const void * fdt,int offset)70*6780e684SKyle Evans static inline const void *fdt_offset_ptr_(const void *fdt, int offset)
7121fdc27aSRafal Jaworowski {
7221fdc27aSRafal Jaworowski 	return (const char *)fdt + fdt_off_dt_struct(fdt) + offset;
7321fdc27aSRafal Jaworowski }
7421fdc27aSRafal Jaworowski 
fdt_offset_ptr_w_(void * fdt,int offset)75*6780e684SKyle Evans static inline void *fdt_offset_ptr_w_(void *fdt, int offset)
7621fdc27aSRafal Jaworowski {
77*6780e684SKyle Evans 	return (void *)(uintptr_t)fdt_offset_ptr_(fdt, offset);
7821fdc27aSRafal Jaworowski }
7921fdc27aSRafal Jaworowski 
fdt_mem_rsv_(const void * fdt,int n)80*6780e684SKyle Evans static inline const struct fdt_reserve_entry *fdt_mem_rsv_(const void *fdt, int n)
8121fdc27aSRafal Jaworowski {
8221fdc27aSRafal Jaworowski 	const struct fdt_reserve_entry *rsv_table =
8321fdc27aSRafal Jaworowski 		(const struct fdt_reserve_entry *)
8421fdc27aSRafal Jaworowski 		((const char *)fdt + fdt_off_mem_rsvmap(fdt));
8521fdc27aSRafal Jaworowski 
8621fdc27aSRafal Jaworowski 	return rsv_table + n;
8721fdc27aSRafal Jaworowski }
fdt_mem_rsv_w_(void * fdt,int n)88*6780e684SKyle Evans static inline struct fdt_reserve_entry *fdt_mem_rsv_w_(void *fdt, int n)
8921fdc27aSRafal Jaworowski {
90*6780e684SKyle Evans 	return (void *)(uintptr_t)fdt_mem_rsv_(fdt, n);
9121fdc27aSRafal Jaworowski }
9221fdc27aSRafal Jaworowski 
9321fdc27aSRafal Jaworowski #define FDT_SW_MAGIC		(~FDT_MAGIC)
9421fdc27aSRafal Jaworowski 
95*6780e684SKyle Evans #endif /* LIBFDT_INTERNAL_H */
96