Patchwork endian.h: add macros for le16/le32 to cpu endianess conversion

login
register
about
Submitter Daniel Mack
Date 2009-10-05 02:44:46
Message ID <1254710688-9069-5-git-send-email-daniel@caiaq.de>
Download mbox | patch
Permalink /patch/339/
State Not Applicable
Headers show

Comments

Daniel Mack - 2009-10-05 02:44:46
Signed-off-by: Daniel Mack <daniel@caiaq.de>
---
 include/i386/arch/endian.h    |   11 +++++++++++
 include/powerpc/arch/endian.h |   14 ++++++++++++--
 2 files changed, 23 insertions(+), 2 deletions(-)

Patch

diff --git a/include/i386/arch/endian.h b/include/i386/arch/endian.h
index a50ac1f..743787f 100644
--- a/include/i386/arch/endian.h
+++ b/include/i386/arch/endian.h
@@ -38,4 +38,15 @@ 
 		(( (in) & 0xFF0000) >> 8) | (( (in) & 0xFF000000) >> 24))
 
 #define ntohll(in) (((u64) ntohl( (in) & 0xFFFFFFFF) << 32) | ((u64) ntohl( (in) >> 32))) 
+
+#define cpu_to_le16(in) (in)
+#define cpu_to_le32(in) (in)
+#define cpu_to_be16(in) ntohw(in)
+#define cpu_to_be32(in) ntohl(in)
+
+#define le16_to_cpu(in) (in)
+#define le32_to_cpu(in) (in)
+#define be16_to_cpu(in) ntohw(in)
+#define be32_to_cpu(in) ntohl(in)
+
 #endif
diff --git a/include/powerpc/arch/endian.h b/include/powerpc/arch/endian.h
index 8ffad70..1cc7c57 100644
--- a/include/powerpc/arch/endian.h
+++ b/include/powerpc/arch/endian.h
@@ -33,9 +33,19 @@ 
 #include <arch/types.h>
 
 #define ntohw(in) (in)
-
 #define ntohl(in) (in)
-
 #define ntohll(in) (in)
 
+#define cpu_to_le16(in) ((( (in) & 0xFF) << 8) | (( (in) & 0xFF00) >> 8))
+#define cpu_to_le32(in) ((( (in) & 0xFF) << 24) | (( (in) & 0xFF00) << 8) | \
+		(( (in) & 0xFF0000) >> 8) | (( (in) & 0xFF000000) >> 24))
+
+#define cpu_to_be16(in) (in)
+#define cpu_to_be32(in) (in)
+
+#define le16_to_cpu(in) cpu_to_le16(in)
+#define le32_to_cpu(in) cpu_to_le32(in)
+#define be16_to_cpu(in) (in)
+#define be32_to_cpu(in) (in)
+
 #endif