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