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