1*d18719a4STom Rini #ifndef _LIBFDT_ENV_H 2*d18719a4STom Rini #define _LIBFDT_ENV_H 3*d18719a4STom Rini /* 4*d18719a4STom Rini * libfdt - Flat Device Tree manipulation 5*d18719a4STom Rini * Copyright (C) 2006 David Gibson, IBM Corporation. 6*d18719a4STom Rini * Copyright 2012 Kim Phillips, Freescale Semiconductor. 7*d18719a4STom Rini * 8*d18719a4STom Rini * libfdt is dual licensed: you can use it either under the terms of 9*d18719a4STom Rini * the GPL, or the BSD license, at your option. 10*d18719a4STom Rini * 11*d18719a4STom Rini * a) This library is free software; you can redistribute it and/or 12*d18719a4STom Rini * modify it under the terms of the GNU General Public License as 13*d18719a4STom Rini * published by the Free Software Foundation; either version 2 of the 14*d18719a4STom Rini * License, or (at your option) any later version. 15*d18719a4STom Rini * 16*d18719a4STom Rini * This library is distributed in the hope that it will be useful, 17*d18719a4STom Rini * but WITHOUT ANY WARRANTY; without even the implied warranty of 18*d18719a4STom Rini * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19*d18719a4STom Rini * GNU General Public License for more details. 20*d18719a4STom Rini * 21*d18719a4STom Rini * You should have received a copy of the GNU General Public 22*d18719a4STom Rini * License along with this library; if not, write to the Free 23*d18719a4STom Rini * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 24*d18719a4STom Rini * MA 02110-1301 USA 25*d18719a4STom Rini * 26*d18719a4STom Rini * Alternatively, 27*d18719a4STom Rini * 28*d18719a4STom Rini * b) Redistribution and use in source and binary forms, with or 29*d18719a4STom Rini * without modification, are permitted provided that the following 30*d18719a4STom Rini * conditions are met: 31*d18719a4STom Rini * 32*d18719a4STom Rini * 1. Redistributions of source code must retain the above 33*d18719a4STom Rini * copyright notice, this list of conditions and the following 34*d18719a4STom Rini * disclaimer. 35*d18719a4STom Rini * 2. Redistributions in binary form must reproduce the above 36*d18719a4STom Rini * copyright notice, this list of conditions and the following 37*d18719a4STom Rini * disclaimer in the documentation and/or other materials 38*d18719a4STom Rini * provided with the distribution. 39*d18719a4STom Rini * 40*d18719a4STom Rini * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 41*d18719a4STom Rini * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 42*d18719a4STom Rini * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 43*d18719a4STom Rini * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 44*d18719a4STom Rini * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 45*d18719a4STom Rini * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 46*d18719a4STom Rini * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 47*d18719a4STom Rini * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 48*d18719a4STom Rini * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 49*d18719a4STom Rini * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 50*d18719a4STom Rini * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 51*d18719a4STom Rini * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 52*d18719a4STom Rini * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 53*d18719a4STom Rini */ 54*d18719a4STom Rini 55*d18719a4STom Rini #include <stddef.h> 56*d18719a4STom Rini #include <stdint.h> 57*d18719a4STom Rini #include <stdlib.h> 58*d18719a4STom Rini #include <string.h> 59*d18719a4STom Rini 60*d18719a4STom Rini #ifdef __CHECKER__ 61*d18719a4STom Rini #define __force __attribute__((force)) 62*d18719a4STom Rini #define __bitwise __attribute__((bitwise)) 63*d18719a4STom Rini #else 64*d18719a4STom Rini #define __force 65*d18719a4STom Rini #define __bitwise 66*d18719a4STom Rini #endif 67*d18719a4STom Rini 68*d18719a4STom Rini typedef uint16_t __bitwise fdt16_t; 69*d18719a4STom Rini typedef uint32_t __bitwise fdt32_t; 70*d18719a4STom Rini typedef uint64_t __bitwise fdt64_t; 71*d18719a4STom Rini 72*d18719a4STom Rini #define EXTRACT_BYTE(x, n) ((unsigned long long)((uint8_t *)&x)[n]) 73*d18719a4STom Rini #define CPU_TO_FDT16(x) ((EXTRACT_BYTE(x, 0) << 8) | EXTRACT_BYTE(x, 1)) 74*d18719a4STom Rini #define CPU_TO_FDT32(x) ((EXTRACT_BYTE(x, 0) << 24) | (EXTRACT_BYTE(x, 1) << 16) | \ 75*d18719a4STom Rini (EXTRACT_BYTE(x, 2) << 8) | EXTRACT_BYTE(x, 3)) 76*d18719a4STom Rini #define CPU_TO_FDT64(x) ((EXTRACT_BYTE(x, 0) << 56) | (EXTRACT_BYTE(x, 1) << 48) | \ 77*d18719a4STom Rini (EXTRACT_BYTE(x, 2) << 40) | (EXTRACT_BYTE(x, 3) << 32) | \ 78*d18719a4STom Rini (EXTRACT_BYTE(x, 4) << 24) | (EXTRACT_BYTE(x, 5) << 16) | \ 79*d18719a4STom Rini (EXTRACT_BYTE(x, 6) << 8) | EXTRACT_BYTE(x, 7)) 80*d18719a4STom Rini 81*d18719a4STom Rini static inline uint16_t fdt16_to_cpu(fdt16_t x) 82*d18719a4STom Rini { 83*d18719a4STom Rini return (__force uint16_t)CPU_TO_FDT16(x); 84*d18719a4STom Rini } 85*d18719a4STom Rini static inline fdt16_t cpu_to_fdt16(uint16_t x) 86*d18719a4STom Rini { 87*d18719a4STom Rini return (__force fdt16_t)CPU_TO_FDT16(x); 88*d18719a4STom Rini } 89*d18719a4STom Rini 90*d18719a4STom Rini static inline uint32_t fdt32_to_cpu(fdt32_t x) 91*d18719a4STom Rini { 92*d18719a4STom Rini return (__force uint32_t)CPU_TO_FDT32(x); 93*d18719a4STom Rini } 94*d18719a4STom Rini static inline fdt32_t cpu_to_fdt32(uint32_t x) 95*d18719a4STom Rini { 96*d18719a4STom Rini return (__force fdt32_t)CPU_TO_FDT32(x); 97*d18719a4STom Rini } 98*d18719a4STom Rini 99*d18719a4STom Rini static inline uint64_t fdt64_to_cpu(fdt64_t x) 100*d18719a4STom Rini { 101*d18719a4STom Rini return (__force uint64_t)CPU_TO_FDT64(x); 102*d18719a4STom Rini } 103*d18719a4STom Rini static inline fdt64_t cpu_to_fdt64(uint64_t x) 104*d18719a4STom Rini { 105*d18719a4STom Rini return (__force fdt64_t)CPU_TO_FDT64(x); 106*d18719a4STom Rini } 107*d18719a4STom Rini #undef CPU_TO_FDT64 108*d18719a4STom Rini #undef CPU_TO_FDT32 109*d18719a4STom Rini #undef CPU_TO_FDT16 110*d18719a4STom Rini #undef EXTRACT_BYTE 111*d18719a4STom Rini 112*d18719a4STom Rini #endif /* _LIBFDT_ENV_H */ 113