xref: /freebsd/sys/contrib/libfdt/libfdt_env.h (revision 0b3105a37d7adcadcb720112fed4dc4e8040be99)
1 #ifndef _LIBFDT_ENV_H
2 #define _LIBFDT_ENV_H
3 
4 #ifdef _KERNEL
5 #include <sys/cdefs.h>
6 #include <sys/param.h>
7 #include <sys/types.h>
8 #include <sys/systm.h>
9 #include <sys/stdint.h>
10 #else
11 #include <stddef.h>
12 #include <stdint.h>
13 #include <string.h>
14 #endif
15 
16 #define EXTRACT_BYTE(n)	((unsigned long long)((uint8_t *)&x)[n])
17 static inline uint16_t fdt16_to_cpu(uint16_t x)
18 {
19 	return (EXTRACT_BYTE(0) << 8) | EXTRACT_BYTE(1);
20 }
21 #define cpu_to_fdt16(x) fdt16_to_cpu(x)
22 
23 static inline uint32_t fdt32_to_cpu(uint32_t x)
24 {
25 	return (EXTRACT_BYTE(0) << 24) | (EXTRACT_BYTE(1) << 16) | (EXTRACT_BYTE(2) << 8) | EXTRACT_BYTE(3);
26 }
27 #define cpu_to_fdt32(x) fdt32_to_cpu(x)
28 
29 static inline uint64_t fdt64_to_cpu(uint64_t x)
30 {
31 	return (EXTRACT_BYTE(0) << 56) | (EXTRACT_BYTE(1) << 48) | (EXTRACT_BYTE(2) << 40) | (EXTRACT_BYTE(3) << 32)
32 		| (EXTRACT_BYTE(4) << 24) | (EXTRACT_BYTE(5) << 16) | (EXTRACT_BYTE(6) << 8) | EXTRACT_BYTE(7);
33 }
34 #define cpu_to_fdt64(x) fdt64_to_cpu(x)
35 #undef EXTRACT_BYTE
36 
37 #endif /* _LIBFDT_ENV_H */
38