blob: 213d7fb81c4218ba516bbbf59fa35b1f36d1b6ad [file] [log] [blame]
David Gibsoned95d742008-08-07 12:24:17 +10001#ifndef _LIBFDT_ENV_H
2#define _LIBFDT_ENV_H
3
4#include <stddef.h>
5#include <stdint.h>
6#include <string.h>
7
Stephen Warrencd296722012-09-28 21:25:59 +00008#define EXTRACT_BYTE(n) ((unsigned long long)((uint8_t *)&x)[n])
9static inline uint16_t fdt16_to_cpu(uint16_t x)
10{
11 return (EXTRACT_BYTE(0) << 8) | EXTRACT_BYTE(1);
12}
13#define cpu_to_fdt16(x) fdt16_to_cpu(x)
14
David Gibsoned95d742008-08-07 12:24:17 +100015static inline uint32_t fdt32_to_cpu(uint32_t x)
16{
Stephen Warrencd296722012-09-28 21:25:59 +000017 return (EXTRACT_BYTE(0) << 24) | (EXTRACT_BYTE(1) << 16) | (EXTRACT_BYTE(2) << 8) | EXTRACT_BYTE(3);
David Gibsoned95d742008-08-07 12:24:17 +100018}
19#define cpu_to_fdt32(x) fdt32_to_cpu(x)
20
21static inline uint64_t fdt64_to_cpu(uint64_t x)
22{
Stephen Warrencd296722012-09-28 21:25:59 +000023 return (EXTRACT_BYTE(0) << 56) | (EXTRACT_BYTE(1) << 48) | (EXTRACT_BYTE(2) << 40) | (EXTRACT_BYTE(3) << 32)
24 | (EXTRACT_BYTE(4) << 24) | (EXTRACT_BYTE(5) << 16) | (EXTRACT_BYTE(6) << 8) | EXTRACT_BYTE(7);
David Gibsoned95d742008-08-07 12:24:17 +100025}
26#define cpu_to_fdt64(x) fdt64_to_cpu(x)
Stephen Warrencd296722012-09-28 21:25:59 +000027#undef EXTRACT_BYTE
David Gibsoned95d742008-08-07 12:24:17 +100028
29#endif /* _LIBFDT_ENV_H */