1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Port on Texas Instruments TMS320C6x architecture
5 * Copyright (C) 2004, 2009, 2010 Texas Instruments Incorporated
6 * Author: Aurelien Jacquiot (aurelien.jacquiot@jaluna.com)
7 * Rewritten for 2.6.3x: Mark Salter <msalter@redhat.com>
9 #ifndef _ASM_C6X_UNALIGNED_H
10 #define _ASM_C6X_UNALIGNED_H
12 #include <linux/swab.h>
13 #include <linux/unaligned/generic.h>
16 * The C64x+ can do unaligned word and dword accesses in hardware
17 * using special load/store instructions.
20 static inline u16
get_unaligned_le16(const void *p
)
23 return _p
[0] | _p
[1] << 8;
26 static inline u16
get_unaligned_be16(const void *p
)
29 return _p
[0] << 8 | _p
[1];
32 static inline void put_unaligned_le16(u16 val
, void *p
)
39 static inline void put_unaligned_be16(u16 val
, void *p
)
46 static inline u32
get_unaligned32(const void *p
)
49 asm (" ldnw .d1t1 *%0,%0\n"
55 static inline void put_unaligned32(u32 val
, void *p
)
57 asm volatile (" stnw .d2t1 %0,*%1\n"
58 : : "a"(val
), "b"(p
) : "memory");
61 static inline u64
get_unaligned64(const void *p
)
64 asm volatile (" ldndw .d1t1 *%1,%0\n"
66 : "=a"(val
) : "a"(p
));
70 static inline void put_unaligned64(u64 val
, const void *p
)
72 asm volatile (" stndw .d2t1 %0,*%1\n"
73 : : "a"(val
), "b"(p
) : "memory");
76 #ifdef CONFIG_CPU_BIG_ENDIAN
78 #define get_unaligned_le32(p) __swab32(get_unaligned32(p))
79 #define get_unaligned_le64(p) __swab64(get_unaligned64(p))
80 #define get_unaligned_be32(p) get_unaligned32(p)
81 #define get_unaligned_be64(p) get_unaligned64(p)
82 #define put_unaligned_le32(v, p) put_unaligned32(__swab32(v), (p))
83 #define put_unaligned_le64(v, p) put_unaligned64(__swab64(v), (p))
84 #define put_unaligned_be32(v, p) put_unaligned32((v), (p))
85 #define put_unaligned_be64(v, p) put_unaligned64((v), (p))
86 #define get_unaligned __get_unaligned_be
87 #define put_unaligned __put_unaligned_be
91 #define get_unaligned_le32(p) get_unaligned32(p)
92 #define get_unaligned_le64(p) get_unaligned64(p)
93 #define get_unaligned_be32(p) __swab32(get_unaligned32(p))
94 #define get_unaligned_be64(p) __swab64(get_unaligned64(p))
95 #define put_unaligned_le32(v, p) put_unaligned32((v), (p))
96 #define put_unaligned_le64(v, p) put_unaligned64((v), (p))
97 #define put_unaligned_be32(v, p) put_unaligned32(__swab32(v), (p))
98 #define put_unaligned_be64(v, p) put_unaligned64(__swab64(v), (p))
99 #define get_unaligned __get_unaligned_le
100 #define put_unaligned __put_unaligned_le
104 #endif /* _ASM_C6X_UNALIGNED_H */