Harvey Harrison | 064106a | 2008-04-29 01:03:27 -0700 | [diff] [blame] | 1 | #ifndef _LINUX_UNALIGNED_ACCESS_OK_H |
| 2 | #define _LINUX_UNALIGNED_ACCESS_OK_H |
| 3 | |
| 4 | #include <linux/kernel.h> |
| 5 | #include <asm/byteorder.h> |
| 6 | |
Denys Vlasenko | e3bde95 | 2016-03-17 14:22:47 -0700 | [diff] [blame] | 7 | static __always_inline u16 get_unaligned_le16(const void *p) |
Harvey Harrison | 064106a | 2008-04-29 01:03:27 -0700 | [diff] [blame] | 8 | { |
| 9 | return le16_to_cpup((__le16 *)p); |
| 10 | } |
| 11 | |
Denys Vlasenko | e3bde95 | 2016-03-17 14:22:47 -0700 | [diff] [blame] | 12 | static __always_inline u32 get_unaligned_le32(const void *p) |
Harvey Harrison | 064106a | 2008-04-29 01:03:27 -0700 | [diff] [blame] | 13 | { |
| 14 | return le32_to_cpup((__le32 *)p); |
| 15 | } |
| 16 | |
Denys Vlasenko | e3bde95 | 2016-03-17 14:22:47 -0700 | [diff] [blame] | 17 | static __always_inline u64 get_unaligned_le64(const void *p) |
Harvey Harrison | 064106a | 2008-04-29 01:03:27 -0700 | [diff] [blame] | 18 | { |
| 19 | return le64_to_cpup((__le64 *)p); |
| 20 | } |
| 21 | |
Denys Vlasenko | e3bde95 | 2016-03-17 14:22:47 -0700 | [diff] [blame] | 22 | static __always_inline u16 get_unaligned_be16(const void *p) |
Harvey Harrison | 064106a | 2008-04-29 01:03:27 -0700 | [diff] [blame] | 23 | { |
| 24 | return be16_to_cpup((__be16 *)p); |
| 25 | } |
| 26 | |
Denys Vlasenko | e3bde95 | 2016-03-17 14:22:47 -0700 | [diff] [blame] | 27 | static __always_inline u32 get_unaligned_be32(const void *p) |
Harvey Harrison | 064106a | 2008-04-29 01:03:27 -0700 | [diff] [blame] | 28 | { |
| 29 | return be32_to_cpup((__be32 *)p); |
| 30 | } |
| 31 | |
Denys Vlasenko | e3bde95 | 2016-03-17 14:22:47 -0700 | [diff] [blame] | 32 | static __always_inline u64 get_unaligned_be64(const void *p) |
Harvey Harrison | 064106a | 2008-04-29 01:03:27 -0700 | [diff] [blame] | 33 | { |
| 34 | return be64_to_cpup((__be64 *)p); |
| 35 | } |
| 36 | |
Denys Vlasenko | e3bde95 | 2016-03-17 14:22:47 -0700 | [diff] [blame] | 37 | static __always_inline void put_unaligned_le16(u16 val, void *p) |
Harvey Harrison | 064106a | 2008-04-29 01:03:27 -0700 | [diff] [blame] | 38 | { |
| 39 | *((__le16 *)p) = cpu_to_le16(val); |
| 40 | } |
| 41 | |
Denys Vlasenko | e3bde95 | 2016-03-17 14:22:47 -0700 | [diff] [blame] | 42 | static __always_inline void put_unaligned_le32(u32 val, void *p) |
Harvey Harrison | 064106a | 2008-04-29 01:03:27 -0700 | [diff] [blame] | 43 | { |
| 44 | *((__le32 *)p) = cpu_to_le32(val); |
| 45 | } |
| 46 | |
Denys Vlasenko | e3bde95 | 2016-03-17 14:22:47 -0700 | [diff] [blame] | 47 | static __always_inline void put_unaligned_le64(u64 val, void *p) |
Harvey Harrison | 064106a | 2008-04-29 01:03:27 -0700 | [diff] [blame] | 48 | { |
| 49 | *((__le64 *)p) = cpu_to_le64(val); |
| 50 | } |
| 51 | |
Denys Vlasenko | e3bde95 | 2016-03-17 14:22:47 -0700 | [diff] [blame] | 52 | static __always_inline void put_unaligned_be16(u16 val, void *p) |
Harvey Harrison | 064106a | 2008-04-29 01:03:27 -0700 | [diff] [blame] | 53 | { |
| 54 | *((__be16 *)p) = cpu_to_be16(val); |
| 55 | } |
| 56 | |
Denys Vlasenko | e3bde95 | 2016-03-17 14:22:47 -0700 | [diff] [blame] | 57 | static __always_inline void put_unaligned_be32(u32 val, void *p) |
Harvey Harrison | 064106a | 2008-04-29 01:03:27 -0700 | [diff] [blame] | 58 | { |
| 59 | *((__be32 *)p) = cpu_to_be32(val); |
| 60 | } |
| 61 | |
Denys Vlasenko | e3bde95 | 2016-03-17 14:22:47 -0700 | [diff] [blame] | 62 | static __always_inline void put_unaligned_be64(u64 val, void *p) |
Harvey Harrison | 064106a | 2008-04-29 01:03:27 -0700 | [diff] [blame] | 63 | { |
| 64 | *((__be64 *)p) = cpu_to_be64(val); |
| 65 | } |
| 66 | |
| 67 | #endif /* _LINUX_UNALIGNED_ACCESS_OK_H */ |