[PATCH v2 09/15] powerpc/boot: define byteswapping routines for little endian

2014-04-24 Thread Cédric Le Goater
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 
---
 arch/powerpc/boot/of.h   |7 +++
 arch/powerpc/boot/swab.h |   29 +
 2 files changed, 36 insertions(+)
 create mode 100644 arch/powerpc/boot/swab.h

diff --git a/arch/powerpc/boot/of.h b/arch/powerpc/boot/of.h
index e1ef620082f7..c8c1750aba0c 100644
--- a/arch/powerpc/boot/of.h
+++ b/arch/powerpc/boot/of.h
@@ -1,6 +1,8 @@
 #ifndef _PPC_BOOT_OF_H_
 #define _PPC_BOOT_OF_H_
 
+#include "swab.h"
+
 typedef void *phandle;
 typedef u32 ihandle;
 
@@ -21,8 +23,13 @@ void of_console_init(void);
 
 typedef u32__be32;
 
+#ifdef __LITTLE_ENDIAN__
+#define cpu_to_be32(x) swab32(x)
+#define be32_to_cpu(x) swab32(x)
+#else
 #define cpu_to_be32(x) (x)
 #define be32_to_cpu(x) (x)
+#endif
 
 #define PROM_ERROR (-1u)
 
diff --git a/arch/powerpc/boot/swab.h b/arch/powerpc/boot/swab.h
new file mode 100644
index ..d0e1431084ca
--- /dev/null
+++ b/arch/powerpc/boot/swab.h
@@ -0,0 +1,29 @@
+#ifndef _PPC_BOOT_SWAB_H_
+#define _PPC_BOOT_SWAB_H_
+
+static inline u16 swab16(u16 x)
+{
+   return  ((x & (u16)0x00ffU) << 8) |
+   ((x & (u16)0xff00U) >> 8);
+}
+
+static inline u32 swab32(u32 x)
+{
+   return  ((x & (u32)0x00ffUL) << 24) |
+   ((x & (u32)0xff00UL) <<  8) |
+   ((x & (u32)0x00ffUL) >>  8) |
+   ((x & (u32)0xff00UL) >> 24);
+}
+
+static inline u64 swab64(u64 x)
+{
+   return  (u64)((x & (u64)0x00ffULL) << 56) |
+   (u64)((x & (u64)0xff00ULL) << 40) |
+   (u64)((x & (u64)0x00ffULL) << 24) |
+   (u64)((x & (u64)0xff00ULL) <<  8) |
+   (u64)((x & (u64)0x00ffULL) >>  8) |
+   (u64)((x & (u64)0xff00ULL) >> 24) |
+   (u64)((x & (u64)0x00ffULL) >> 40) |
+   (u64)((x & (u64)0xff00ULL) >> 56);
+}
+#endif /* _PPC_BOOT_SWAB_H_ */
-- 
1.7.10.4

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH v2 09/15] powerpc/boot: define byteswapping routines for little endian

2014-04-14 Thread Cédric Le Goater
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 
---
 arch/powerpc/boot/of.h   |7 +++
 arch/powerpc/boot/swab.h |   29 +
 2 files changed, 36 insertions(+)
 create mode 100644 arch/powerpc/boot/swab.h

diff --git a/arch/powerpc/boot/of.h b/arch/powerpc/boot/of.h
index e1ef620082f7..c8c1750aba0c 100644
--- a/arch/powerpc/boot/of.h
+++ b/arch/powerpc/boot/of.h
@@ -1,6 +1,8 @@
 #ifndef _PPC_BOOT_OF_H_
 #define _PPC_BOOT_OF_H_
 
+#include "swab.h"
+
 typedef void *phandle;
 typedef u32 ihandle;
 
@@ -21,8 +23,13 @@ void of_console_init(void);
 
 typedef u32__be32;
 
+#ifdef __LITTLE_ENDIAN__
+#define cpu_to_be32(x) swab32(x)
+#define be32_to_cpu(x) swab32(x)
+#else
 #define cpu_to_be32(x) (x)
 #define be32_to_cpu(x) (x)
+#endif
 
 #define PROM_ERROR (-1u)
 
diff --git a/arch/powerpc/boot/swab.h b/arch/powerpc/boot/swab.h
new file mode 100644
index ..d0e1431084ca
--- /dev/null
+++ b/arch/powerpc/boot/swab.h
@@ -0,0 +1,29 @@
+#ifndef _PPC_BOOT_SWAB_H_
+#define _PPC_BOOT_SWAB_H_
+
+static inline u16 swab16(u16 x)
+{
+   return  ((x & (u16)0x00ffU) << 8) |
+   ((x & (u16)0xff00U) >> 8);
+}
+
+static inline u32 swab32(u32 x)
+{
+   return  ((x & (u32)0x00ffUL) << 24) |
+   ((x & (u32)0xff00UL) <<  8) |
+   ((x & (u32)0x00ffUL) >>  8) |
+   ((x & (u32)0xff00UL) >> 24);
+}
+
+static inline u64 swab64(u64 x)
+{
+   return  (u64)((x & (u64)0x00ffULL) << 56) |
+   (u64)((x & (u64)0xff00ULL) << 40) |
+   (u64)((x & (u64)0x00ffULL) << 24) |
+   (u64)((x & (u64)0xff00ULL) <<  8) |
+   (u64)((x & (u64)0x00ffULL) >>  8) |
+   (u64)((x & (u64)0xff00ULL) >> 24) |
+   (u64)((x & (u64)0x00ffULL) >> 40) |
+   (u64)((x & (u64)0xff00ULL) >> 56);
+}
+#endif /* _PPC_BOOT_SWAB_H_ */
-- 
1.7.10.4

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev