4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2014, 2015, Intel Corporation.
24 * Author: John L. Hammond <john.hammond@intel.com>
26 #ifndef _LIBCFS_BYTEORDER_H
27 #define _LIBCFS_BYTERODER_H
30 # include <asm/byteorder.h>
31 #else /* __KERNEL__ */
36 # include <byteswap.h>
38 # define __swab16(x) bswap_16(x)
39 # define __swab32(x) bswap_32(x)
40 # define __swab64(x) bswap_64(x)
41 # define __swab16s(x) \
43 *(x) = bswap_16(*(x)); \
45 # define __swab32s(x) \
47 *(x) = bswap_32(*(x)); \
49 # define __swab64s(x) \
51 *(x) = bswap_64(*(x)); \
53 # if __BYTE_ORDER == __LITTLE_ENDIAN
54 # define le16_to_cpu(x) (x)
55 # define cpu_to_le16(x) (x)
56 # define le32_to_cpu(x) (x)
57 # define cpu_to_le32(x) (x)
58 # define le64_to_cpu(x) (x)
59 # define cpu_to_le64(x) (x)
61 # define be16_to_cpu(x) bswap_16(x)
62 # define cpu_to_be16(x) bswap_16(x)
63 # define be32_to_cpu(x) bswap_32(x)
64 # define cpu_to_be32(x) bswap_32(x)
65 # define be64_to_cpu(x) ((__u64)bswap_64(x))
66 # define cpu_to_be64(x) ((__u64)bswap_64(x))
67 # elif __BYTE_ORDER == __BIG_ENDIAN
68 # define le16_to_cpu(x) bswap_16(x)
69 # define cpu_to_le16(x) bswap_16(x)
70 # define le32_to_cpu(x) bswap_32(x)
71 # define cpu_to_le32(x) bswap_32(x)
72 # define le64_to_cpu(x) ((__u64)bswap_64(x))
73 # define cpu_to_le64(x) ((__u64)bswap_64(x))
75 # define be16_to_cpu(x) (x)
76 # define cpu_to_be16(x) (x)
77 # define be32_to_cpu(x) (x)
78 # define cpu_to_be32(x) (x)
79 # define be64_to_cpu(x) (x)
80 # define cpu_to_be64(x) (x)
81 # else /* __BYTE_ORDER == __BIG_ENDIAN */
82 # error "Unknown byte order"
83 # endif /* __BYTE_ORDER != __BIG_ENDIAN */
85 #endif /* !__KERNEL__ */
87 #endif /* _LIBCFS_BYTEORDER_H */