1 #ifndef _ASM_IA64_UNALIGNED_H
2 #define _ASM_IA64_UNALIGNED_H
3 
4 #include <linux/types.h>
5 
6 /*
7  * The main single-value unaligned transfer routines.
8  *
9  * Based on <asm-alpha/unaligned.h>.
10  *
11  * Copyright (C) 1998, 1999, 2003 Hewlett-Packard Co
12  *	David Mosberger-Tang <davidm@hpl.hp.com>
13  */
14 #define get_unaligned(ptr) \
15 	((__typeof__(*(ptr)))ia64_get_unaligned((ptr), sizeof(*(ptr))))
16 
17 #define put_unaligned(x,ptr) \
18 	ia64_put_unaligned((unsigned long)(x), (ptr), sizeof(*(ptr)))
19 
20 struct __una_u64 { __u64 x __attribute__((packed)); };
21 struct __una_u32 { __u32 x __attribute__((packed)); };
22 struct __una_u16 { __u16 x __attribute__((packed)); };
23 
24 static inline unsigned long
__uld8(const unsigned long * addr)25 __uld8 (const unsigned long * addr)
26 {
27 	const struct __una_u64 *ptr = (const struct __una_u64 *) addr;
28 	return ptr->x;
29 }
30 
31 static inline unsigned long
__uld4(const unsigned int * addr)32 __uld4 (const unsigned int * addr)
33 {
34 	const struct __una_u32 *ptr = (const struct __una_u32 *) addr;
35 	return ptr->x;
36 }
37 
38 static inline unsigned long
__uld2(const unsigned short * addr)39 __uld2 (const unsigned short * addr)
40 {
41 	const struct __una_u16 *ptr = (const struct __una_u16 *) addr;
42 	return ptr->x;
43 }
44 
45 static inline void
__ust8(unsigned long val,unsigned long * addr)46 __ust8 (unsigned long val, unsigned long * addr)
47 {
48 	struct __una_u64 *ptr = (struct __una_u64 *) addr;
49 	ptr->x = val;
50 }
51 
52 static inline void
__ust4(unsigned long val,unsigned int * addr)53 __ust4 (unsigned long val, unsigned int * addr)
54 {
55 	struct __una_u32 *ptr = (struct __una_u32 *) addr;
56 	ptr->x = val;
57 }
58 
59 static inline void
__ust2(unsigned long val,unsigned short * addr)60 __ust2 (unsigned long val, unsigned short * addr)
61 {
62 	struct __una_u16 *ptr = (struct __una_u16 *) addr;
63 	ptr->x = val;
64 }
65 
66 
67 /*
68  * This function doesn't actually exist.  The idea is that when someone uses the macros
69  * below with an unsupported size (datatype), the linker will alert us to the problem via
70  * an unresolved reference error.
71  */
72 extern unsigned long ia64_bad_unaligned_access_length (void);
73 
74 #define ia64_get_unaligned(_ptr,size)						\
75 ({										\
76 	const void *__ia64_ptr = (_ptr);					\
77 	unsigned long __ia64_val;						\
78 										\
79 	switch (size) {								\
80 	      case 1:								\
81 		__ia64_val = *(const unsigned char *) __ia64_ptr;		\
82 		break;								\
83 	      case 2:								\
84 		__ia64_val = __uld2((const unsigned short *)__ia64_ptr);	\
85 		break;								\
86 	      case 4:								\
87 		__ia64_val = __uld4((const unsigned int *)__ia64_ptr);		\
88 		break;								\
89 	      case 8:								\
90 		__ia64_val = __uld8((const unsigned long *)__ia64_ptr);		\
91 		break;								\
92 	      default:								\
93 		__ia64_val = ia64_bad_unaligned_access_length();		\
94 	}									\
95 	__ia64_val;								\
96 })
97 
98 #define ia64_put_unaligned(_val,_ptr,size)				\
99 do {									\
100 	const void *__ia64_ptr = (_ptr);				\
101 	unsigned long __ia64_val = (_val);				\
102 									\
103 	switch (size) {							\
104 	      case 1:							\
105 		*(unsigned char *)__ia64_ptr = (__ia64_val);		\
106 	        break;							\
107 	      case 2:							\
108 		__ust2(__ia64_val, (unsigned short *)__ia64_ptr);	\
109 		break;							\
110 	      case 4:							\
111 		__ust4(__ia64_val, (unsigned int *)__ia64_ptr);		\
112 		break;							\
113 	      case 8:							\
114 		__ust8(__ia64_val, (unsigned long *)__ia64_ptr);	\
115 		break;							\
116 	      default:							\
117 	    	ia64_bad_unaligned_access_length();			\
118 	}								\
119 } while (0)
120 
121 #endif /* _ASM_IA64_UNALIGNED_H */
122