162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * This file is subject to the terms and conditions of the GNU General Public
362306a36Sopenharmony_ci * License.  See the file "COPYING" in the main directory of this archive
462306a36Sopenharmony_ci * for more details.
562306a36Sopenharmony_ci *
662306a36Sopenharmony_ci * Copyright (C) 2003, 2004 Ralf Baechle
762306a36Sopenharmony_ci */
862306a36Sopenharmony_ci#ifndef __ASM_MACH_GENERIC_MANGLE_PORT_H
962306a36Sopenharmony_ci#define __ASM_MACH_GENERIC_MANGLE_PORT_H
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#include <asm/byteorder.h>
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci#ifdef __BIG_ENDIAN
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_cistatic inline bool __should_swizzle_bits(volatile void *a)
1662306a36Sopenharmony_ci{
1762306a36Sopenharmony_ci	extern const bool octeon_should_swizzle_table[];
1862306a36Sopenharmony_ci	u64 did = ((u64)(uintptr_t)a >> 40) & 0xff;
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci	return octeon_should_swizzle_table[did];
2162306a36Sopenharmony_ci}
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_ci# define __swizzle_addr_b(port)	(port)
2462306a36Sopenharmony_ci# define __swizzle_addr_w(port)	(port)
2562306a36Sopenharmony_ci# define __swizzle_addr_l(port)	(port)
2662306a36Sopenharmony_ci# define __swizzle_addr_q(port)	(port)
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci#else /* __LITTLE_ENDIAN */
2962306a36Sopenharmony_ci
3062306a36Sopenharmony_ci#define __should_swizzle_bits(a)	false
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_cistatic inline bool __should_swizzle_addr(u64 p)
3362306a36Sopenharmony_ci{
3462306a36Sopenharmony_ci	/* boot bus? */
3562306a36Sopenharmony_ci	return ((p >> 40) & 0xff) == 0;
3662306a36Sopenharmony_ci}
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci# define __swizzle_addr_b(port)	\
3962306a36Sopenharmony_ci	(__should_swizzle_addr(port) ? (port) ^ 7 : (port))
4062306a36Sopenharmony_ci# define __swizzle_addr_w(port)	\
4162306a36Sopenharmony_ci	(__should_swizzle_addr(port) ? (port) ^ 6 : (port))
4262306a36Sopenharmony_ci# define __swizzle_addr_l(port)	\
4362306a36Sopenharmony_ci	(__should_swizzle_addr(port) ? (port) ^ 4 : (port))
4462306a36Sopenharmony_ci# define __swizzle_addr_q(port)	(port)
4562306a36Sopenharmony_ci
4662306a36Sopenharmony_ci#endif /* __BIG_ENDIAN */
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_ci# define ioswabb(a, x)		(x)
5062306a36Sopenharmony_ci# define __mem_ioswabb(a, x)	(x)
5162306a36Sopenharmony_ci# define ioswabw(a, x)		(__should_swizzle_bits(a) ?		\
5262306a36Sopenharmony_ci				 le16_to_cpu((__force __le16)(x)) :	\
5362306a36Sopenharmony_ci				 (x))
5462306a36Sopenharmony_ci# define __mem_ioswabw(a, x)	(x)
5562306a36Sopenharmony_ci# define ioswabl(a, x)		(__should_swizzle_bits(a) ?		\
5662306a36Sopenharmony_ci				 le32_to_cpu((__force __le32)(x)) :	\
5762306a36Sopenharmony_ci				 (x))
5862306a36Sopenharmony_ci# define __mem_ioswabl(a, x)	(x)
5962306a36Sopenharmony_ci# define ioswabq(a, x)		(__should_swizzle_bits(a) ?		\
6062306a36Sopenharmony_ci				 le64_to_cpu((__force __le64)(x)) :	\
6162306a36Sopenharmony_ci				 (x))
6262306a36Sopenharmony_ci# define __mem_ioswabq(a, x)	(x)
6362306a36Sopenharmony_ci
6462306a36Sopenharmony_ci#endif /* __ASM_MACH_GENERIC_MANGLE_PORT_H */
65