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