1 /* 2 * This file is subject to the terms and conditions of the GNU General Public 3 * License. See the file "COPYING" in the main directory of this archive 4 * for more details. 5 * 6 * Copyright (C) 2003, 2004 Ralf Baechle 7 */ 8 #ifndef __ASM_MACH_GENERIC_MANGLE_PORT_H 9 #define __ASM_MACH_GENERIC_MANGLE_PORT_H 10 11 #include <asm/byteorder.h> 12 13 #ifdef __BIG_ENDIAN 14 15 # define __swizzle_addr_b(port) (port) 16 # define __swizzle_addr_w(port) (port) 17 # define __swizzle_addr_l(port) (port) 18 # define __swizzle_addr_q(port) (port) 19 20 #else /* __LITTLE_ENDIAN */ 21 22 static inline bool __should_swizzle_addr(unsigned long p) 23 { 24 /* boot bus? */ 25 return ((p >> 40) & 0xff) == 0; 26 } 27 28 # define __swizzle_addr_b(port) \ 29 (__should_swizzle_addr(port) ? (port) ^ 7 : (port)) 30 # define __swizzle_addr_w(port) \ 31 (__should_swizzle_addr(port) ? (port) ^ 6 : (port)) 32 # define __swizzle_addr_l(port) \ 33 (__should_swizzle_addr(port) ? (port) ^ 4 : (port)) 34 # define __swizzle_addr_q(port) (port) 35 36 #endif /* __BIG_ENDIAN */ 37 38 /* 39 * Sane hardware offers swapping of PCI/ISA I/O space accesses in hardware; 40 * less sane hardware forces software to fiddle with this... 41 * 42 * Regardless, if the host bus endianness mismatches that of PCI/ISA, then 43 * you can't have the numerical value of data and byte addresses within 44 * multibyte quantities both preserved at the same time. Hence two 45 * variations of functions: non-prefixed ones that preserve the value 46 * and prefixed ones that preserve byte addresses. The latters are 47 * typically used for moving raw data between a peripheral and memory (cf. 48 * string I/O functions), hence the "__mem_" prefix. 49 */ 50 #if defined(CONFIG_SWAP_IO_SPACE) 51 52 # define ioswabb(a, x) (x) 53 # define __mem_ioswabb(a, x) (x) 54 # define ioswabw(a, x) le16_to_cpu(x) 55 # define __mem_ioswabw(a, x) (x) 56 # define ioswabl(a, x) le32_to_cpu(x) 57 # define __mem_ioswabl(a, x) (x) 58 # define ioswabq(a, x) le64_to_cpu(x) 59 # define __mem_ioswabq(a, x) (x) 60 61 #else 62 63 # define ioswabb(a, x) (x) 64 # define __mem_ioswabb(a, x) (x) 65 # define ioswabw(a, x) (x) 66 # define __mem_ioswabw(a, x) cpu_to_le16(x) 67 # define ioswabl(a, x) (x) 68 # define __mem_ioswabl(a, x) cpu_to_le32(x) 69 # define ioswabq(a, x) (x) 70 # define __mem_ioswabq(a, x) cpu_to_le32(x) 71 72 #endif 73 74 #endif /* __ASM_MACH_GENERIC_MANGLE_PORT_H */ 75