From c4a6999ceec8ac95415de4cb6099182d3f67d1cb Mon Sep 17 00:00:00 2001 From: "John L. Hammond" Date: Wed, 17 Sep 2014 14:24:01 -0500 Subject: [PATCH] LU-2675 libcfs: add libcfs/byteorder.h 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 Change-Id: I298e4d1dd224ffbb395e0df531b382a8c9e2082f Reviewed-on: http://review.whamcloud.com/11986 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: James Simmons Reviewed-by: Bob Glossman Reviewed-by: Dmitry Eremin Reviewed-by: Andreas Dilger --- libcfs/include/libcfs/Makefile.am | 1 + libcfs/include/libcfs/byteorder.h | 85 ++++++++++++++++++++++++++++++++++++ libcfs/include/libcfs/libcfs.h | 1 + libcfs/include/libcfs/posix/libcfs.h | 41 ----------------- 4 files changed, 87 insertions(+), 41 deletions(-) create mode 100644 libcfs/include/libcfs/byteorder.h diff --git a/libcfs/include/libcfs/Makefile.am b/libcfs/include/libcfs/Makefile.am index 2244baa..af916b8 100644 --- a/libcfs/include/libcfs/Makefile.am +++ b/libcfs/include/libcfs/Makefile.am @@ -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 index 0000000..6643cec --- /dev/null +++ b/libcfs/include/libcfs/byteorder.h @@ -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 + */ +#ifndef _LIBCFS_BYTEORDER_H +#define _LIBCFS_BYTERODER_H + +#ifdef __KERNEL__ +# include +#else /* __KERNEL__ */ + +# include +# include + +# 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 */ diff --git a/libcfs/include/libcfs/libcfs.h b/libcfs/include/libcfs/libcfs.h index 5121cb1..343ef86 100644 --- a/libcfs/include/libcfs/libcfs.h +++ b/libcfs/include/libcfs/libcfs.h @@ -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 #include #include #include diff --git a/libcfs/include/libcfs/posix/libcfs.h b/libcfs/include/libcfs/posix/libcfs.h index 37834d3..403861c 100644 --- a/libcfs/include/libcfs/posix/libcfs.h +++ b/libcfs/include/libcfs/posix/libcfs.h @@ -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 -#include -#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 */ -- 1.8.3.1