Whamcloud - gitweb
LU-2675 libcfs: add libcfs/byteorder.h 86/11986/2
authorJohn L. Hammond <john.hammond@intel.com>
Wed, 17 Sep 2014 19:24:01 +0000 (14:24 -0500)
committerAndreas Dilger <andreas.dilger@intel.com>
Fri, 24 Oct 2014 18:39:22 +0000 (18:39 +0000)
Move the byte swapping macros out of libcfs/posix/libcfs.h and into a
new header libcfs/byteorder.h which includes asm/byteorder.h for
kernel code or defines the equivalent macros for userspace code.

Signed-off-by: John L. Hammond <john.hammond@intel.com>
Change-Id: I298e4d1dd224ffbb395e0df531b382a8c9e2082f
Reviewed-on: http://review.whamcloud.com/11986
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: James Simmons <uja.ornl@gmail.com>
Reviewed-by: Bob Glossman <bob.glossman@intel.com>
Reviewed-by: Dmitry Eremin <dmitry.eremin@intel.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
libcfs/include/libcfs/Makefile.am
libcfs/include/libcfs/byteorder.h [new file with mode: 0644]
libcfs/include/libcfs/libcfs.h
libcfs/include/libcfs/posix/libcfs.h

index 2244baa..af916b8 100644 (file)
@@ -9,6 +9,7 @@ endif
 
 EXTRA_DIST = \
        bitmap.h \
+       byteorder.h \
        curproc.h \
        err.h \
        libcfs.h \
diff --git a/libcfs/include/libcfs/byteorder.h b/libcfs/include/libcfs/byteorder.h
new file mode 100644 (file)
index 0000000..6643cec
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * GPL HEADER START
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 only,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License version 2 for more details (a copy is included
+ * in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; If not, see
+ * http://www.gnu.org/licenses/gpl-2.0.html
+ *
+ * GPL HEADER END
+ */
+/*
+ * Copyright (c) 2014, Intel Corporation.
+ * Author: John L. Hammond <john.hammond@intel.com>
+ */
+#ifndef _LIBCFS_BYTEORDER_H
+#define _LIBCFS_BYTERODER_H
+
+#ifdef __KERNEL__
+# include <asm/byteorder.h>
+#else /* __KERNEL__ */
+
+# include <endian.h>
+# include <byteswap.h>
+
+# define __swab16(x) bswap_16(x)
+# define __swab32(x) bswap_32(x)
+# define __swab64(x) bswap_64(x)
+# define __swab16s(x)                          \
+       do {                                    \
+               *(x) = bswap_16(*(x));          \
+       } while (0)
+# define __swab32s(x)                          \
+       do {                                    \
+               *(x) = bswap_32(*(x));          \
+       } while (0)
+# define __swab64s(x)                          \
+       do {                                    \
+               *(x) = bswap_64(*(x));          \
+       } while (0)
+# if __BYTE_ORDER == __LITTLE_ENDIAN
+#  define le16_to_cpu(x) (x)
+#  define cpu_to_le16(x) (x)
+#  define le32_to_cpu(x) (x)
+#  define cpu_to_le32(x) (x)
+#  define le64_to_cpu(x) (x)
+#  define cpu_to_le64(x) (x)
+
+#  define be16_to_cpu(x) bswap_16(x)
+#  define cpu_to_be16(x) bswap_16(x)
+#  define be32_to_cpu(x) bswap_32(x)
+#  define cpu_to_be32(x) bswap_32(x)
+#  define be64_to_cpu(x) ((__u64)bswap_64(x))
+#  define cpu_to_be64(x) ((__u64)bswap_64(x))
+# elif __BYTE_ORDER == __BIG_ENDIAN
+#  define le16_to_cpu(x) bswap_16(x)
+#  define cpu_to_le16(x) bswap_16(x)
+#  define le32_to_cpu(x) bswap_32(x)
+#  define cpu_to_le32(x) bswap_32(x)
+#  define le64_to_cpu(x) ((__u64)bswap_64(x))
+#  define cpu_to_le64(x) ((__u64)bswap_64(x))
+
+#  define be16_to_cpu(x) (x)
+#  define cpu_to_be16(x) (x)
+#  define be32_to_cpu(x) (x)
+#  define cpu_to_be32(x) (x)
+#  define be64_to_cpu(x) (x)
+#  define cpu_to_be64(x) (x)
+# else /*  __BYTE_ORDER == __BIG_ENDIAN */
+#  error "Unknown byte order"
+# endif /* __BYTE_ORDER != __BIG_ENDIAN */
+
+#endif /* !__KERNEL__ */
+
+#endif /* _LIBCFS_BYTEORDER_H */
index 5121cb1..343ef86 100644 (file)
@@ -244,6 +244,7 @@ unsigned int cfs_rand(void);
 void cfs_srand(unsigned int, unsigned int);
 void cfs_get_random_bytes(void *buf, int size);
 
+#include <libcfs/byteorder.h>
 #include <libcfs/err.h>
 #include <libcfs/libcfs_debug.h>
 #include <libcfs/libcfs_private.h>
index 37834d3..403861c 100644 (file)
@@ -116,47 +116,6 @@ typedef unsigned long long cfs_cycles_t;
 #define fget(x) NULL
 #define fput(f) do {} while (0)
 
-/* Userpace byte flipping */
-#include <endian.h>
-#include <byteswap.h>
-#define __swab16(x) bswap_16(x)
-#define __swab32(x) bswap_32(x)
-#define __swab64(x) bswap_64(x)
-#define __swab16s(x) do {*(x) = bswap_16(*(x));} while (0)
-#define __swab32s(x) do {*(x) = bswap_32(*(x));} while (0)
-#define __swab64s(x) do {*(x) = bswap_64(*(x));} while (0)
-#if __BYTE_ORDER == __LITTLE_ENDIAN
-# define le16_to_cpu(x) (x)
-# define cpu_to_le16(x) (x)
-# define le32_to_cpu(x) (x)
-# define cpu_to_le32(x) (x)
-# define le64_to_cpu(x) (x)
-# define cpu_to_le64(x) (x)
-
-# define be16_to_cpu(x) bswap_16(x)
-# define cpu_to_be16(x) bswap_16(x)
-# define be32_to_cpu(x) bswap_32(x)
-# define cpu_to_be32(x) bswap_32(x)
-# define be64_to_cpu(x) ((__u64)bswap_64(x))
-# define cpu_to_be64(x) ((__u64)bswap_64(x))
-#elif __BYTE_ORDER == __BIG_ENDIAN
-# define le16_to_cpu(x) bswap_16(x)
-# define cpu_to_le16(x) bswap_16(x)
-# define le32_to_cpu(x) bswap_32(x)
-# define cpu_to_le32(x) bswap_32(x)
-# define le64_to_cpu(x) ((__u64)bswap_64(x))
-# define cpu_to_le64(x) ((__u64)bswap_64(x))
-
-# define be16_to_cpu(x) (x)
-# define cpu_to_be16(x) (x)
-# define be32_to_cpu(x) (x)
-# define cpu_to_be32(x) (x)
-# define be64_to_cpu(x) (x)
-# define cpu_to_be64(x) (x)
-#else /*  __BYTE_ORDER == __BIG_ENDIAN */
-# error "Unknown byte order"
-#endif /* __BYTE_ORDER != __BIG_ENDIAN */
-
 #ifndef THREAD_SIZE /* x86_64 linux has THREAD_SIZE in userspace */
 # define THREAD_SIZE 8192
 #endif /* THREAD_SIZE */