David Gibson | ede25de | 2006-12-01 15:02:10 +1100 | [diff] [blame] | 1 | #ifndef _LIBFDT_ENV_H |
| 2 | #define _LIBFDT_ENV_H |
| 3 | |
David Gibson | 3da0f9a | 2006-11-27 16:21:28 +1100 | [diff] [blame] | 4 | #include <stddef.h> |
| 5 | #include <stdint.h> |
| 6 | #include <string.h> |
David Gibson | 3da0f9a | 2006-11-27 16:21:28 +1100 | [diff] [blame] | 7 | |
Bert Kenward | 37b167f | 2012-04-10 08:00:15 -0700 | [diff] [blame] | 8 | #define EXTRACT_BYTE(n) ((unsigned long long)((uint8_t *)&x)[n]) |
Anton Staaf | 2cd4c8d | 2011-10-11 10:22:27 -0700 | [diff] [blame] | 9 | static inline uint16_t fdt16_to_cpu(uint16_t x) |
| 10 | { |
Bert Kenward | 37b167f | 2012-04-10 08:00:15 -0700 | [diff] [blame] | 11 | return (EXTRACT_BYTE(0) << 8) | EXTRACT_BYTE(1); |
Anton Staaf | 2cd4c8d | 2011-10-11 10:22:27 -0700 | [diff] [blame] | 12 | } |
| 13 | #define cpu_to_fdt16(x) fdt16_to_cpu(x) |
| 14 | |
David Gibson | cdcb415 | 2008-06-26 11:03:49 +1000 | [diff] [blame] | 15 | static inline uint32_t fdt32_to_cpu(uint32_t x) |
| 16 | { |
Bert Kenward | 37b167f | 2012-04-10 08:00:15 -0700 | [diff] [blame] | 17 | return (EXTRACT_BYTE(0) << 24) | (EXTRACT_BYTE(1) << 16) | (EXTRACT_BYTE(2) << 8) | EXTRACT_BYTE(3); |
David Gibson | cdcb415 | 2008-06-26 11:03:49 +1000 | [diff] [blame] | 18 | } |
| 19 | #define cpu_to_fdt32(x) fdt32_to_cpu(x) |
| 20 | |
| 21 | static inline uint64_t fdt64_to_cpu(uint64_t x) |
| 22 | { |
Bert Kenward | 37b167f | 2012-04-10 08:00:15 -0700 | [diff] [blame] | 23 | 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 Gibson | cdcb415 | 2008-06-26 11:03:49 +1000 | [diff] [blame] | 25 | } |
| 26 | #define cpu_to_fdt64(x) fdt64_to_cpu(x) |
Bert Kenward | 37b167f | 2012-04-10 08:00:15 -0700 | [diff] [blame] | 27 | #undef EXTRACT_BYTE |
David Gibson | 3da0f9a | 2006-11-27 16:21:28 +1100 | [diff] [blame] | 28 | |
David Gibson | ede25de | 2006-12-01 15:02:10 +1100 | [diff] [blame] | 29 | #endif /* _LIBFDT_ENV_H */ |