xref: /linux/arch/nios2/include/asm/swab.h (revision c17ee635fd3a482b2ad2bf5e269755c2eae5f25e)
1*9b21aa9fSThomas Weißschuh /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2*9b21aa9fSThomas Weißschuh /*
3*9b21aa9fSThomas Weißschuh  * Copyright (C) 2012 Tobias Klauser <tklauser@distanz.ch>
4*9b21aa9fSThomas Weißschuh  * Copyright (C) 2011 Pyramid Technical Consultants, Inc.
5*9b21aa9fSThomas Weißschuh  *
6*9b21aa9fSThomas Weißschuh  * This file is subject to the terms and conditions of the GNU General
7*9b21aa9fSThomas Weißschuh  * Public License. See the file COPYING in the main directory of this
8*9b21aa9fSThomas Weißschuh  * archive for more details.
9*9b21aa9fSThomas Weißschuh  */
10*9b21aa9fSThomas Weißschuh 
11*9b21aa9fSThomas Weißschuh #ifndef _ASM_NIOS2_SWAB_H
12*9b21aa9fSThomas Weißschuh #define _ASM_NIOS2_SWAB_H
13*9b21aa9fSThomas Weißschuh 
14*9b21aa9fSThomas Weißschuh #include <linux/types.h>
15*9b21aa9fSThomas Weißschuh #include <asm-generic/swab.h>
16*9b21aa9fSThomas Weißschuh 
17*9b21aa9fSThomas Weißschuh #ifdef CONFIG_NIOS2_CI_SWAB_SUPPORT
18*9b21aa9fSThomas Weißschuh #ifdef __GNUC__
19*9b21aa9fSThomas Weißschuh 
20*9b21aa9fSThomas Weißschuh #define __nios2_swab(x)		\
21*9b21aa9fSThomas Weißschuh 	__builtin_custom_ini(CONFIG_NIOS2_CI_SWAB_NO, (x))
22*9b21aa9fSThomas Weißschuh 
23*9b21aa9fSThomas Weißschuh static inline __attribute__((const)) __u16 __arch_swab16(__u16 x)
24*9b21aa9fSThomas Weißschuh {
25*9b21aa9fSThomas Weißschuh 	return (__u16) __nios2_swab(((__u32) x) << 16);
26*9b21aa9fSThomas Weißschuh }
27*9b21aa9fSThomas Weißschuh #define __arch_swab16 __arch_swab16
28*9b21aa9fSThomas Weißschuh 
29*9b21aa9fSThomas Weißschuh static inline __attribute__((const)) __u32 __arch_swab32(__u32 x)
30*9b21aa9fSThomas Weißschuh {
31*9b21aa9fSThomas Weißschuh 	return (__u32) __nios2_swab(x);
32*9b21aa9fSThomas Weißschuh }
33*9b21aa9fSThomas Weißschuh #define __arch_swab32 __arch_swab32
34*9b21aa9fSThomas Weißschuh 
35*9b21aa9fSThomas Weißschuh #endif /* __GNUC__ */
36*9b21aa9fSThomas Weißschuh #endif /* CONFIG_NIOS2_CI_SWAB_SUPPORT */
37*9b21aa9fSThomas Weißschuh 
38*9b21aa9fSThomas Weißschuh #endif /* _ASM_NIOS2_SWAB_H */
39