0001
0002 #ifndef LIBFDT_ENV_H
0003 #define LIBFDT_ENV_H
0004
0005
0006
0007
0008
0009
0010 #include <stdbool.h>
0011 #include <stddef.h>
0012 #include <stdint.h>
0013 #include <stdlib.h>
0014 #include <string.h>
0015 #include <limits.h>
0016
0017 #ifdef __CHECKER__
0018 #define FDT_FORCE __attribute__((force))
0019 #define FDT_BITWISE __attribute__((bitwise))
0020 #else
0021 #define FDT_FORCE
0022 #define FDT_BITWISE
0023 #endif
0024
0025 typedef uint16_t FDT_BITWISE fdt16_t;
0026 typedef uint32_t FDT_BITWISE fdt32_t;
0027 typedef uint64_t FDT_BITWISE fdt64_t;
0028
0029 #define EXTRACT_BYTE(x, n) ((unsigned long long)((uint8_t *)&x)[n])
0030 #define CPU_TO_FDT16(x) ((EXTRACT_BYTE(x, 0) << 8) | EXTRACT_BYTE(x, 1))
0031 #define CPU_TO_FDT32(x) ((EXTRACT_BYTE(x, 0) << 24) | (EXTRACT_BYTE(x, 1) << 16) | \
0032 (EXTRACT_BYTE(x, 2) << 8) | EXTRACT_BYTE(x, 3))
0033 #define CPU_TO_FDT64(x) ((EXTRACT_BYTE(x, 0) << 56) | (EXTRACT_BYTE(x, 1) << 48) | \
0034 (EXTRACT_BYTE(x, 2) << 40) | (EXTRACT_BYTE(x, 3) << 32) | \
0035 (EXTRACT_BYTE(x, 4) << 24) | (EXTRACT_BYTE(x, 5) << 16) | \
0036 (EXTRACT_BYTE(x, 6) << 8) | EXTRACT_BYTE(x, 7))
0037
0038 static inline uint16_t fdt16_to_cpu(fdt16_t x)
0039 {
0040 return (FDT_FORCE uint16_t)CPU_TO_FDT16(x);
0041 }
0042 static inline fdt16_t cpu_to_fdt16(uint16_t x)
0043 {
0044 return (FDT_FORCE fdt16_t)CPU_TO_FDT16(x);
0045 }
0046
0047 static inline uint32_t fdt32_to_cpu(fdt32_t x)
0048 {
0049 return (FDT_FORCE uint32_t)CPU_TO_FDT32(x);
0050 }
0051 static inline fdt32_t cpu_to_fdt32(uint32_t x)
0052 {
0053 return (FDT_FORCE fdt32_t)CPU_TO_FDT32(x);
0054 }
0055
0056 static inline uint64_t fdt64_to_cpu(fdt64_t x)
0057 {
0058 return (FDT_FORCE uint64_t)CPU_TO_FDT64(x);
0059 }
0060 static inline fdt64_t cpu_to_fdt64(uint64_t x)
0061 {
0062 return (FDT_FORCE fdt64_t)CPU_TO_FDT64(x);
0063 }
0064 #undef CPU_TO_FDT64
0065 #undef CPU_TO_FDT32
0066 #undef CPU_TO_FDT16
0067 #undef EXTRACT_BYTE
0068
0069 #ifdef __APPLE__
0070 #include <AvailabilityMacros.h>
0071
0072
0073 # if !defined(MAC_OS_X_VERSION_10_7) || (MAC_OS_X_VERSION_MAX_ALLOWED < \
0074 MAC_OS_X_VERSION_10_7)
0075
0076 #define strnlen fdt_strnlen
0077
0078
0079
0080
0081
0082
0083
0084
0085 static inline size_t fdt_strnlen(const char *string, size_t max_count)
0086 {
0087 const char *p = memchr(string, 0, max_count);
0088 return p ? p - string : max_count;
0089 }
0090
0091 #endif
0092
0093
0094 #endif
0095
0096 #endif