1*9130ba88SRob Herring #ifndef LIBFDT_INTERNAL_H 2*9130ba88SRob Herring #define LIBFDT_INTERNAL_H 39fffb55fSDavid Gibson /* 49fffb55fSDavid Gibson * libfdt - Flat Device Tree manipulation 59fffb55fSDavid Gibson * Copyright (C) 2006 David Gibson, IBM Corporation. 69fffb55fSDavid Gibson * 79fffb55fSDavid Gibson * libfdt is dual licensed: you can use it either under the terms of 89fffb55fSDavid Gibson * the GPL, or the BSD license, at your option. 99fffb55fSDavid Gibson * 109fffb55fSDavid Gibson * a) This library is free software; you can redistribute it and/or 119fffb55fSDavid Gibson * modify it under the terms of the GNU General Public License as 129fffb55fSDavid Gibson * published by the Free Software Foundation; either version 2 of the 139fffb55fSDavid Gibson * License, or (at your option) any later version. 149fffb55fSDavid Gibson * 159fffb55fSDavid Gibson * This library is distributed in the hope that it will be useful, 169fffb55fSDavid Gibson * but WITHOUT ANY WARRANTY; without even the implied warranty of 179fffb55fSDavid Gibson * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 189fffb55fSDavid Gibson * GNU General Public License for more details. 199fffb55fSDavid Gibson * 209fffb55fSDavid Gibson * You should have received a copy of the GNU General Public 219fffb55fSDavid Gibson * License along with this library; if not, write to the Free 229fffb55fSDavid Gibson * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 239fffb55fSDavid Gibson * MA 02110-1301 USA 249fffb55fSDavid Gibson * 259fffb55fSDavid Gibson * Alternatively, 269fffb55fSDavid Gibson * 279fffb55fSDavid Gibson * b) Redistribution and use in source and binary forms, with or 289fffb55fSDavid Gibson * without modification, are permitted provided that the following 299fffb55fSDavid Gibson * conditions are met: 309fffb55fSDavid Gibson * 319fffb55fSDavid Gibson * 1. Redistributions of source code must retain the above 329fffb55fSDavid Gibson * copyright notice, this list of conditions and the following 339fffb55fSDavid Gibson * disclaimer. 349fffb55fSDavid Gibson * 2. Redistributions in binary form must reproduce the above 359fffb55fSDavid Gibson * copyright notice, this list of conditions and the following 369fffb55fSDavid Gibson * disclaimer in the documentation and/or other materials 379fffb55fSDavid Gibson * provided with the distribution. 389fffb55fSDavid Gibson * 399fffb55fSDavid Gibson * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 409fffb55fSDavid Gibson * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 419fffb55fSDavid Gibson * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 429fffb55fSDavid Gibson * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 439fffb55fSDavid Gibson * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 449fffb55fSDavid Gibson * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 459fffb55fSDavid Gibson * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 469fffb55fSDavid Gibson * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 479fffb55fSDavid Gibson * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 489fffb55fSDavid Gibson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 499fffb55fSDavid Gibson * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 509fffb55fSDavid Gibson * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 519fffb55fSDavid Gibson * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 529fffb55fSDavid Gibson */ 539fffb55fSDavid Gibson #include <fdt.h> 549fffb55fSDavid Gibson 559fffb55fSDavid Gibson #define FDT_ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1)) 569fffb55fSDavid Gibson #define FDT_TAGALIGN(x) (FDT_ALIGN((x), FDT_TAGSIZE)) 579fffb55fSDavid Gibson 589fffb55fSDavid Gibson #define FDT_CHECK_HEADER(fdt) \ 599fffb55fSDavid Gibson { \ 60*9130ba88SRob Herring int err_; \ 61*9130ba88SRob Herring if ((err_ = fdt_check_header(fdt)) != 0) \ 62*9130ba88SRob Herring return err_; \ 639fffb55fSDavid Gibson } 649fffb55fSDavid Gibson 65*9130ba88SRob Herring int fdt_check_node_offset_(const void *fdt, int offset); 66*9130ba88SRob Herring int fdt_check_prop_offset_(const void *fdt, int offset); 67*9130ba88SRob Herring const char *fdt_find_string_(const char *strtab, int tabsize, const char *s); 68*9130ba88SRob Herring int fdt_node_end_offset_(void *fdt, int nodeoffset); 699fffb55fSDavid Gibson 70*9130ba88SRob Herring static inline const void *fdt_offset_ptr_(const void *fdt, int offset) 719fffb55fSDavid Gibson { 729fffb55fSDavid Gibson return (const char *)fdt + fdt_off_dt_struct(fdt) + offset; 739fffb55fSDavid Gibson } 749fffb55fSDavid Gibson 75*9130ba88SRob Herring static inline void *fdt_offset_ptr_w_(void *fdt, int offset) 769fffb55fSDavid Gibson { 77*9130ba88SRob Herring return (void *)(uintptr_t)fdt_offset_ptr_(fdt, offset); 789fffb55fSDavid Gibson } 799fffb55fSDavid Gibson 80*9130ba88SRob Herring static inline const struct fdt_reserve_entry *fdt_mem_rsv_(const void *fdt, int n) 819fffb55fSDavid Gibson { 829fffb55fSDavid Gibson const struct fdt_reserve_entry *rsv_table = 839fffb55fSDavid Gibson (const struct fdt_reserve_entry *) 849fffb55fSDavid Gibson ((const char *)fdt + fdt_off_mem_rsvmap(fdt)); 859fffb55fSDavid Gibson 869fffb55fSDavid Gibson return rsv_table + n; 879fffb55fSDavid Gibson } 88*9130ba88SRob Herring static inline struct fdt_reserve_entry *fdt_mem_rsv_w_(void *fdt, int n) 899fffb55fSDavid Gibson { 90*9130ba88SRob Herring return (void *)(uintptr_t)fdt_mem_rsv_(fdt, n); 919fffb55fSDavid Gibson } 929fffb55fSDavid Gibson 939fffb55fSDavid Gibson #define FDT_SW_MAGIC (~FDT_MAGIC) 949fffb55fSDavid Gibson 95*9130ba88SRob Herring #endif /* LIBFDT_INTERNAL_H */ 96