aboutsummaryrefslogtreecommitdiffstats
path: root/tools/include/linux/unaligned
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2017-08-04 16:49:38 +0200
committerTakashi Iwai <tiwai@suse.de>2017-08-04 16:50:18 +0200
commit74be62c7cefbf320e0605f3da6639ef80448ff00 (patch)
treeea45fa2e0b343b792a03a66058b26a8d3e736787 /tools/include/linux/unaligned
parentALSA: hda: constify pci_device_id. (diff)
parentMerge tag 'asoc-fix-v4.13-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound into for-linus (diff)
Merge branch 'for-linus' into for-next
Back-merge 4.13-rc devel branch for later development. Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'tools/include/linux/unaligned')
-rw-r--r--tools/include/linux/unaligned/packed_struct.h46
1 files changed, 46 insertions, 0 deletions
diff --git a/tools/include/linux/unaligned/packed_struct.h b/tools/include/linux/unaligned/packed_struct.h
new file mode 100644
index 000000000000..c0d817de4df2
--- /dev/null
+++ b/tools/include/linux/unaligned/packed_struct.h
@@ -0,0 +1,46 @@
+#ifndef _LINUX_UNALIGNED_PACKED_STRUCT_H
+#define _LINUX_UNALIGNED_PACKED_STRUCT_H
+
+#include <linux/kernel.h>
+
+struct __una_u16 { u16 x; } __packed;
+struct __una_u32 { u32 x; } __packed;
+struct __una_u64 { u64 x; } __packed;
+
+static inline u16 __get_unaligned_cpu16(const void *p)
+{
+ const struct __una_u16 *ptr = (const struct __una_u16 *)p;
+ return ptr->x;
+}
+
+static inline u32 __get_unaligned_cpu32(const void *p)
+{
+ const struct __una_u32 *ptr = (const struct __una_u32 *)p;
+ return ptr->x;
+}
+
+static inline u64 __get_unaligned_cpu64(const void *p)
+{
+ const struct __una_u64 *ptr = (const struct __una_u64 *)p;
+ return ptr->x;
+}
+
+static inline void __put_unaligned_cpu16(u16 val, void *p)
+{
+ struct __una_u16 *ptr = (struct __una_u16 *)p;
+ ptr->x = val;
+}
+
+static inline void __put_unaligned_cpu32(u32 val, void *p)
+{
+ struct __una_u32 *ptr = (struct __una_u32 *)p;
+ ptr->x = val;
+}
+
+static inline void __put_unaligned_cpu64(u64 val, void *p)
+{
+ struct __una_u64 *ptr = (struct __una_u64 *)p;
+ ptr->x = val;
+}
+
+#endif /* _LINUX_UNALIGNED_PACKED_STRUCT_H */