1328459Skevans#ifndef LIBFDT_INTERNAL_H 2328459Skevans#define LIBFDT_INTERNAL_H 3204431Sraj/* 4204431Sraj * libfdt - Flat Device Tree manipulation 5204431Sraj * Copyright (C) 2006 David Gibson, IBM Corporation. 6204431Sraj * 7204431Sraj * libfdt is dual licensed: you can use it either under the terms of 8204431Sraj * the GPL, or the BSD license, at your option. 9204431Sraj * 10204431Sraj * a) This library is free software; you can redistribute it and/or 11204431Sraj * modify it under the terms of the GNU General Public License as 12204431Sraj * published by the Free Software Foundation; either version 2 of the 13204431Sraj * License, or (at your option) any later version. 14204431Sraj * 15204431Sraj * This library is distributed in the hope that it will be useful, 16204431Sraj * but WITHOUT ANY WARRANTY; without even the implied warranty of 17204431Sraj * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18204431Sraj * GNU General Public License for more details. 19204431Sraj * 20204431Sraj * You should have received a copy of the GNU General Public 21204431Sraj * License along with this library; if not, write to the Free 22204431Sraj * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 23204431Sraj * MA 02110-1301 USA 24204431Sraj * 25204431Sraj * Alternatively, 26204431Sraj * 27204431Sraj * b) Redistribution and use in source and binary forms, with or 28204431Sraj * without modification, are permitted provided that the following 29204431Sraj * conditions are met: 30204431Sraj * 31204431Sraj * 1. Redistributions of source code must retain the above 32204431Sraj * copyright notice, this list of conditions and the following 33204431Sraj * disclaimer. 34204431Sraj * 2. Redistributions in binary form must reproduce the above 35204431Sraj * copyright notice, this list of conditions and the following 36204431Sraj * disclaimer in the documentation and/or other materials 37204431Sraj * provided with the distribution. 38204431Sraj * 39204431Sraj * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 40204431Sraj * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 41204431Sraj * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 42204431Sraj * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 43204431Sraj * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 44204431Sraj * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 45204431Sraj * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 46204431Sraj * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 47204431Sraj * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48204431Sraj * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 49204431Sraj * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 50204431Sraj * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 51204431Sraj * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 52204431Sraj */ 53204431Sraj#include <fdt.h> 54204431Sraj 55204431Sraj#define FDT_ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1)) 56204431Sraj#define FDT_TAGALIGN(x) (FDT_ALIGN((x), FDT_TAGSIZE)) 57204431Sraj 58204431Sraj#define FDT_CHECK_HEADER(fdt) \ 59204431Sraj { \ 60328459Skevans int err_; \ 61328459Skevans if ((err_ = fdt_check_header(fdt)) != 0) \ 62328459Skevans return err_; \ 63204431Sraj } 64204431Sraj 65328459Skevansint fdt_check_node_offset_(const void *fdt, int offset); 66328459Skevansint fdt_check_prop_offset_(const void *fdt, int offset); 67328459Skevansconst char *fdt_find_string_(const char *strtab, int tabsize, const char *s); 68328459Skevansint fdt_node_end_offset_(void *fdt, int nodeoffset); 69204431Sraj 70328459Skevansstatic inline const void *fdt_offset_ptr_(const void *fdt, int offset) 71204431Sraj{ 72204431Sraj return (const char *)fdt + fdt_off_dt_struct(fdt) + offset; 73204431Sraj} 74204431Sraj 75328459Skevansstatic inline void *fdt_offset_ptr_w_(void *fdt, int offset) 76204431Sraj{ 77328459Skevans return (void *)(uintptr_t)fdt_offset_ptr_(fdt, offset); 78204431Sraj} 79204431Sraj 80328459Skevansstatic inline const struct fdt_reserve_entry *fdt_mem_rsv_(const void *fdt, int n) 81204431Sraj{ 82204431Sraj const struct fdt_reserve_entry *rsv_table = 83204431Sraj (const struct fdt_reserve_entry *) 84204431Sraj ((const char *)fdt + fdt_off_mem_rsvmap(fdt)); 85204431Sraj 86204431Sraj return rsv_table + n; 87204431Sraj} 88328459Skevansstatic inline struct fdt_reserve_entry *fdt_mem_rsv_w_(void *fdt, int n) 89204431Sraj{ 90328459Skevans return (void *)(uintptr_t)fdt_mem_rsv_(fdt, n); 91204431Sraj} 92204431Sraj 93204431Sraj#define FDT_SW_MAGIC (~FDT_MAGIC) 94204431Sraj 95328459Skevans#endif /* LIBFDT_INTERNAL_H */ 96