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