1*a322d4c5SAndrew Jones #ifndef _LIBFDT_INTERNAL_H 2*a322d4c5SAndrew Jones #define _LIBFDT_INTERNAL_H 3*a322d4c5SAndrew Jones /* 4*a322d4c5SAndrew Jones * libfdt - Flat Device Tree manipulation 5*a322d4c5SAndrew Jones * Copyright (C) 2006 David Gibson, IBM Corporation. 6*a322d4c5SAndrew Jones * 7*a322d4c5SAndrew Jones * libfdt is dual licensed: you can use it either under the terms of 8*a322d4c5SAndrew Jones * the GPL, or the BSD license, at your option. 9*a322d4c5SAndrew Jones * 10*a322d4c5SAndrew Jones * a) This library is free software; you can redistribute it and/or 11*a322d4c5SAndrew Jones * modify it under the terms of the GNU General Public License as 12*a322d4c5SAndrew Jones * published by the Free Software Foundation; either version 2 of the 13*a322d4c5SAndrew Jones * License, or (at your option) any later version. 14*a322d4c5SAndrew Jones * 15*a322d4c5SAndrew Jones * This library is distributed in the hope that it will be useful, 16*a322d4c5SAndrew Jones * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*a322d4c5SAndrew Jones * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*a322d4c5SAndrew Jones * GNU General Public License for more details. 19*a322d4c5SAndrew Jones * 20*a322d4c5SAndrew Jones * You should have received a copy of the GNU General Public 21*a322d4c5SAndrew Jones * License along with this library; if not, write to the Free 22*a322d4c5SAndrew Jones * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 23*a322d4c5SAndrew Jones * MA 02110-1301 USA 24*a322d4c5SAndrew Jones * 25*a322d4c5SAndrew Jones * Alternatively, 26*a322d4c5SAndrew Jones * 27*a322d4c5SAndrew Jones * b) Redistribution and use in source and binary forms, with or 28*a322d4c5SAndrew Jones * without modification, are permitted provided that the following 29*a322d4c5SAndrew Jones * conditions are met: 30*a322d4c5SAndrew Jones * 31*a322d4c5SAndrew Jones * 1. Redistributions of source code must retain the above 32*a322d4c5SAndrew Jones * copyright notice, this list of conditions and the following 33*a322d4c5SAndrew Jones * disclaimer. 34*a322d4c5SAndrew Jones * 2. Redistributions in binary form must reproduce the above 35*a322d4c5SAndrew Jones * copyright notice, this list of conditions and the following 36*a322d4c5SAndrew Jones * disclaimer in the documentation and/or other materials 37*a322d4c5SAndrew Jones * provided with the distribution. 38*a322d4c5SAndrew Jones * 39*a322d4c5SAndrew Jones * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 40*a322d4c5SAndrew Jones * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 41*a322d4c5SAndrew Jones * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 42*a322d4c5SAndrew Jones * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 43*a322d4c5SAndrew Jones * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 44*a322d4c5SAndrew Jones * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 45*a322d4c5SAndrew Jones * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 46*a322d4c5SAndrew Jones * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 47*a322d4c5SAndrew Jones * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48*a322d4c5SAndrew Jones * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 49*a322d4c5SAndrew Jones * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 50*a322d4c5SAndrew Jones * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 51*a322d4c5SAndrew Jones * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 52*a322d4c5SAndrew Jones */ 53*a322d4c5SAndrew Jones #include <fdt.h> 54*a322d4c5SAndrew Jones 55*a322d4c5SAndrew Jones #define FDT_ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1)) 56*a322d4c5SAndrew Jones #define FDT_TAGALIGN(x) (FDT_ALIGN((x), FDT_TAGSIZE)) 57*a322d4c5SAndrew Jones 58*a322d4c5SAndrew Jones #define FDT_CHECK_HEADER(fdt) \ 59*a322d4c5SAndrew Jones { \ 60*a322d4c5SAndrew Jones int err; \ 61*a322d4c5SAndrew Jones if ((err = fdt_check_header(fdt)) != 0) \ 62*a322d4c5SAndrew Jones return err; \ 63*a322d4c5SAndrew Jones } 64*a322d4c5SAndrew Jones 65*a322d4c5SAndrew Jones int _fdt_check_node_offset(const void *fdt, int offset); 66*a322d4c5SAndrew Jones int _fdt_check_prop_offset(const void *fdt, int offset); 67*a322d4c5SAndrew Jones const char *_fdt_find_string(const char *strtab, int tabsize, const char *s); 68*a322d4c5SAndrew Jones int _fdt_node_end_offset(void *fdt, int nodeoffset); 69*a322d4c5SAndrew Jones 70*a322d4c5SAndrew Jones static inline const void *_fdt_offset_ptr(const void *fdt, int offset) 71*a322d4c5SAndrew Jones { 72*a322d4c5SAndrew Jones return (const char *)fdt + fdt_off_dt_struct(fdt) + offset; 73*a322d4c5SAndrew Jones } 74*a322d4c5SAndrew Jones 75*a322d4c5SAndrew Jones static inline void *_fdt_offset_ptr_w(void *fdt, int offset) 76*a322d4c5SAndrew Jones { 77*a322d4c5SAndrew Jones return (void *)(uintptr_t)_fdt_offset_ptr(fdt, offset); 78*a322d4c5SAndrew Jones } 79*a322d4c5SAndrew Jones 80*a322d4c5SAndrew Jones static inline const struct fdt_reserve_entry *_fdt_mem_rsv(const void *fdt, int n) 81*a322d4c5SAndrew Jones { 82*a322d4c5SAndrew Jones const struct fdt_reserve_entry *rsv_table = 83*a322d4c5SAndrew Jones (const struct fdt_reserve_entry *) 84*a322d4c5SAndrew Jones ((const char *)fdt + fdt_off_mem_rsvmap(fdt)); 85*a322d4c5SAndrew Jones 86*a322d4c5SAndrew Jones return rsv_table + n; 87*a322d4c5SAndrew Jones } 88*a322d4c5SAndrew Jones static inline struct fdt_reserve_entry *_fdt_mem_rsv_w(void *fdt, int n) 89*a322d4c5SAndrew Jones { 90*a322d4c5SAndrew Jones return (void *)(uintptr_t)_fdt_mem_rsv(fdt, n); 91*a322d4c5SAndrew Jones } 92*a322d4c5SAndrew Jones 93*a322d4c5SAndrew Jones #define FDT_SW_MAGIC (~FDT_MAGIC) 94*a322d4c5SAndrew Jones 95*a322d4c5SAndrew Jones #endif /* _LIBFDT_INTERNAL_H */ 96