Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef _S390_BYTEORDER_H |
| 2 | #define _S390_BYTEORDER_H |
| 3 | |
| 4 | /* |
| 5 | * include/asm-s390/byteorder.h |
| 6 | * |
| 7 | * S390 version |
| 8 | * Copyright (C) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation |
| 9 | * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com) |
| 10 | */ |
| 11 | |
| 12 | #include <asm/types.h> |
| 13 | |
Harvey Harrison | 64253ac | 2008-12-25 13:39:20 +0100 | [diff] [blame] | 14 | #define __BIG_ENDIAN |
| 15 | |
| 16 | #ifndef __s390x__ |
| 17 | # define __SWAB_64_THRU_32__ |
| 18 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
| 20 | #ifdef __s390x__ |
Harvey Harrison | 64253ac | 2008-12-25 13:39:20 +0100 | [diff] [blame] | 21 | static inline __u64 __arch_swab64p(const __u64 *x) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | { |
| 23 | __u64 result; |
| 24 | |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 25 | asm volatile("lrvg %0,%1" : "=d" (result) : "m" (*x)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | return result; |
| 27 | } |
Harvey Harrison | 64253ac | 2008-12-25 13:39:20 +0100 | [diff] [blame] | 28 | #define __arch_swab64p __arch_swab64p |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
Harvey Harrison | 64253ac | 2008-12-25 13:39:20 +0100 | [diff] [blame] | 30 | static inline __u64 __arch_swab64(__u64 x) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | { |
| 32 | __u64 result; |
| 33 | |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 34 | asm volatile("lrvgr %0,%1" : "=d" (result) : "d" (x)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | return result; |
| 36 | } |
Harvey Harrison | 64253ac | 2008-12-25 13:39:20 +0100 | [diff] [blame] | 37 | #define __arch_swab64 __arch_swab64 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
Harvey Harrison | 64253ac | 2008-12-25 13:39:20 +0100 | [diff] [blame] | 39 | static inline void __arch_swab64s(__u64 *x) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | { |
Harvey Harrison | 64253ac | 2008-12-25 13:39:20 +0100 | [diff] [blame] | 41 | *x = __arch_swab64p(x); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | } |
Harvey Harrison | 64253ac | 2008-12-25 13:39:20 +0100 | [diff] [blame] | 43 | #define __arch_swab64s __arch_swab64s |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #endif /* __s390x__ */ |
| 45 | |
Harvey Harrison | 64253ac | 2008-12-25 13:39:20 +0100 | [diff] [blame] | 46 | static inline __u32 __arch_swab32p(const __u32 *x) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | { |
| 48 | __u32 result; |
| 49 | |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 50 | asm volatile( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #ifndef __s390x__ |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 52 | " icm %0,8,3(%1)\n" |
| 53 | " icm %0,4,2(%1)\n" |
| 54 | " icm %0,2,1(%1)\n" |
| 55 | " ic %0,0(%1)" |
| 56 | : "=&d" (result) : "a" (x), "m" (*x) : "cc"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | #else /* __s390x__ */ |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 58 | " lrv %0,%1" |
| 59 | : "=d" (result) : "m" (*x)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | #endif /* __s390x__ */ |
| 61 | return result; |
| 62 | } |
Harvey Harrison | 64253ac | 2008-12-25 13:39:20 +0100 | [diff] [blame] | 63 | #define __arch_swab32p __arch_swab32p |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
Harvey Harrison | 64253ac | 2008-12-25 13:39:20 +0100 | [diff] [blame] | 65 | #ifdef __s390x__ |
| 66 | static inline __u32 __arch_swab32(__u32 x) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | __u32 result; |
| 69 | |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 70 | asm volatile("lrvr %0,%1" : "=d" (result) : "d" (x)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | return result; |
Harvey Harrison | 64253ac | 2008-12-25 13:39:20 +0100 | [diff] [blame] | 72 | } |
| 73 | #define __arch_swab32 __arch_swab32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | #endif /* __s390x__ */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
Harvey Harrison | 64253ac | 2008-12-25 13:39:20 +0100 | [diff] [blame] | 76 | static inline __u16 __arch_swab16p(const __u16 *x) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | { |
| 78 | __u16 result; |
| 79 | |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 80 | asm volatile( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | #ifndef __s390x__ |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 82 | " icm %0,2,1(%1)\n" |
| 83 | " ic %0,0(%1)\n" |
| 84 | : "=&d" (result) : "a" (x), "m" (*x) : "cc"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | #else /* __s390x__ */ |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 86 | " lrvh %0,%1" |
| 87 | : "=d" (result) : "m" (*x)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | #endif /* __s390x__ */ |
| 89 | return result; |
| 90 | } |
Harvey Harrison | 64253ac | 2008-12-25 13:39:20 +0100 | [diff] [blame] | 91 | #define __arch_swab16p __arch_swab16p |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | |
Harvey Harrison | 64253ac | 2008-12-25 13:39:20 +0100 | [diff] [blame] | 93 | #include <linux/byteorder.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | |
| 95 | #endif /* _S390_BYTEORDER_H */ |