Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

powerpc/boot: Define byteswapping routines for little endian

These are not the most efficient versions of swab but the wrapper does
not do much byte swapping. On a big endian cpu, these routines are
a no-op.

Signed-off-by: Cédric Le Goater <clg@fr.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>

authored by

Cédric Le Goater and committed by
Benjamin Herrenschmidt
98fd433a b636031a

+36
+7
arch/powerpc/boot/of.h
··· 1 1 #ifndef _PPC_BOOT_OF_H_ 2 2 #define _PPC_BOOT_OF_H_ 3 3 4 + #include "swab.h" 5 + 4 6 typedef void *phandle; 5 7 typedef u32 ihandle; 6 8 ··· 23 21 24 22 typedef u32 __be32; 25 23 24 + #ifdef __LITTLE_ENDIAN__ 25 + #define cpu_to_be32(x) swab32(x) 26 + #define be32_to_cpu(x) swab32(x) 27 + #else 26 28 #define cpu_to_be32(x) (x) 27 29 #define be32_to_cpu(x) (x) 30 + #endif 28 31 29 32 #define PROM_ERROR (-1u) 30 33
+29
arch/powerpc/boot/swab.h
··· 1 + #ifndef _PPC_BOOT_SWAB_H_ 2 + #define _PPC_BOOT_SWAB_H_ 3 + 4 + static inline u16 swab16(u16 x) 5 + { 6 + return ((x & (u16)0x00ffU) << 8) | 7 + ((x & (u16)0xff00U) >> 8); 8 + } 9 + 10 + static inline u32 swab32(u32 x) 11 + { 12 + return ((x & (u32)0x000000ffUL) << 24) | 13 + ((x & (u32)0x0000ff00UL) << 8) | 14 + ((x & (u32)0x00ff0000UL) >> 8) | 15 + ((x & (u32)0xff000000UL) >> 24); 16 + } 17 + 18 + static inline u64 swab64(u64 x) 19 + { 20 + return (u64)((x & (u64)0x00000000000000ffULL) << 56) | 21 + (u64)((x & (u64)0x000000000000ff00ULL) << 40) | 22 + (u64)((x & (u64)0x0000000000ff0000ULL) << 24) | 23 + (u64)((x & (u64)0x00000000ff000000ULL) << 8) | 24 + (u64)((x & (u64)0x000000ff00000000ULL) >> 8) | 25 + (u64)((x & (u64)0x0000ff0000000000ULL) >> 24) | 26 + (u64)((x & (u64)0x00ff000000000000ULL) >> 40) | 27 + (u64)((x & (u64)0xff00000000000000ULL) >> 56); 28 + } 29 + #endif /* _PPC_BOOT_SWAB_H_ */