xref: /OK3568_Linux_fs/kernel/arch/mips/include/asm/mach-cavium-octeon/mangle-port.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * This file is subject to the terms and conditions of the GNU General Public
3*4882a593Smuzhiyun  * License.  See the file "COPYING" in the main directory of this archive
4*4882a593Smuzhiyun  * for more details.
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  * Copyright (C) 2003, 2004 Ralf Baechle
7*4882a593Smuzhiyun  */
8*4882a593Smuzhiyun #ifndef __ASM_MACH_GENERIC_MANGLE_PORT_H
9*4882a593Smuzhiyun #define __ASM_MACH_GENERIC_MANGLE_PORT_H
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun #include <asm/byteorder.h>
12*4882a593Smuzhiyun 
13*4882a593Smuzhiyun #ifdef __BIG_ENDIAN
14*4882a593Smuzhiyun 
__should_swizzle_bits(volatile void * a)15*4882a593Smuzhiyun static inline bool __should_swizzle_bits(volatile void *a)
16*4882a593Smuzhiyun {
17*4882a593Smuzhiyun 	extern const bool octeon_should_swizzle_table[];
18*4882a593Smuzhiyun 	u64 did = ((u64)(uintptr_t)a >> 40) & 0xff;
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun 	return octeon_should_swizzle_table[did];
21*4882a593Smuzhiyun }
22*4882a593Smuzhiyun 
23*4882a593Smuzhiyun # define __swizzle_addr_b(port)	(port)
24*4882a593Smuzhiyun # define __swizzle_addr_w(port)	(port)
25*4882a593Smuzhiyun # define __swizzle_addr_l(port)	(port)
26*4882a593Smuzhiyun # define __swizzle_addr_q(port)	(port)
27*4882a593Smuzhiyun 
28*4882a593Smuzhiyun #else /* __LITTLE_ENDIAN */
29*4882a593Smuzhiyun 
30*4882a593Smuzhiyun #define __should_swizzle_bits(a)	false
31*4882a593Smuzhiyun 
__should_swizzle_addr(u64 p)32*4882a593Smuzhiyun static inline bool __should_swizzle_addr(u64 p)
33*4882a593Smuzhiyun {
34*4882a593Smuzhiyun 	/* boot bus? */
35*4882a593Smuzhiyun 	return ((p >> 40) & 0xff) == 0;
36*4882a593Smuzhiyun }
37*4882a593Smuzhiyun 
38*4882a593Smuzhiyun # define __swizzle_addr_b(port)	\
39*4882a593Smuzhiyun 	(__should_swizzle_addr(port) ? (port) ^ 7 : (port))
40*4882a593Smuzhiyun # define __swizzle_addr_w(port)	\
41*4882a593Smuzhiyun 	(__should_swizzle_addr(port) ? (port) ^ 6 : (port))
42*4882a593Smuzhiyun # define __swizzle_addr_l(port)	\
43*4882a593Smuzhiyun 	(__should_swizzle_addr(port) ? (port) ^ 4 : (port))
44*4882a593Smuzhiyun # define __swizzle_addr_q(port)	(port)
45*4882a593Smuzhiyun 
46*4882a593Smuzhiyun #endif /* __BIG_ENDIAN */
47*4882a593Smuzhiyun 
48*4882a593Smuzhiyun 
49*4882a593Smuzhiyun # define ioswabb(a, x)		(x)
50*4882a593Smuzhiyun # define __mem_ioswabb(a, x)	(x)
51*4882a593Smuzhiyun # define ioswabw(a, x)		(__should_swizzle_bits(a) ?		\
52*4882a593Smuzhiyun 				 le16_to_cpu((__force __le16)(x)) :	\
53*4882a593Smuzhiyun 				 (x))
54*4882a593Smuzhiyun # define __mem_ioswabw(a, x)	(x)
55*4882a593Smuzhiyun # define ioswabl(a, x)		(__should_swizzle_bits(a) ?		\
56*4882a593Smuzhiyun 				 le32_to_cpu((__force __le32)(x)) :	\
57*4882a593Smuzhiyun 				 (x))
58*4882a593Smuzhiyun # define __mem_ioswabl(a, x)	(x)
59*4882a593Smuzhiyun # define ioswabq(a, x)		(__should_swizzle_bits(a) ?		\
60*4882a593Smuzhiyun 				 le64_to_cpu((__force __le64)(x)) :	\
61*4882a593Smuzhiyun 				 (x))
62*4882a593Smuzhiyun # define __mem_ioswabq(a, x)	(x)
63*4882a593Smuzhiyun 
64*4882a593Smuzhiyun #endif /* __ASM_MACH_GENERIC_MANGLE_PORT_H */
65