Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1651210

[PATCH V2 22/37] tools include: Add byte-swapping macros to kernel.h

From Adrian Hunter <adrian.hunter@intel.com>
Newsgroups linux.kernel
Subject [PATCH V2 22/37] tools include: Add byte-swapping macros to kernel.h
Date 2017-05-26 10:40 +0200
Message-ID <tLiWT-3x5-47@gated-at.bofh.it> (permalink)
References <tLiNb-3tM-9@gated-at.bofh.it>
Organization Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki

Show all headers | View raw


Add byte-swapping macros to kernel.h

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/include/linux/kernel.h | 35 +++++++++++++++++++++++++++++------
 1 file changed, 29 insertions(+), 6 deletions(-)

diff --git a/tools/include/linux/kernel.h b/tools/include/linux/kernel.h
index 73ccc48126bb..039bb85e4171 100644
--- a/tools/include/linux/kernel.h
+++ b/tools/include/linux/kernel.h
@@ -5,6 +5,8 @@
 #include <stddef.h>
 #include <assert.h>
 #include <linux/compiler.h>
+#include <endian.h>
+#include <byteswap.h>
 
 #ifndef UINT_MAX
 #define UINT_MAX	(~0U)
@@ -67,12 +69,33 @@
 #endif
 #endif
 
-/*
- * Both need more care to handle endianness
- * (Don't use bitmap_copy_le() for now)
- */
-#define cpu_to_le64(x)	(x)
-#define cpu_to_le32(x)	(x)
+#if __BYTE_ORDER == __BIG_ENDIAN
+#define cpu_to_le16 bswap_16
+#define cpu_to_le32 bswap_32
+#define cpu_to_le64 bswap_64
+#define le16_to_cpu bswap_16
+#define le32_to_cpu bswap_32
+#define le64_to_cpu bswap_64
+#define cpu_to_be16
+#define cpu_to_be32
+#define cpu_to_be64
+#define be16_to_cpu
+#define be32_to_cpu
+#define be64_to_cpu
+#else
+#define cpu_to_le16
+#define cpu_to_le32
+#define cpu_to_le64
+#define le16_to_cpu
+#define le32_to_cpu
+#define le64_to_cpu
+#define cpu_to_be16 bswap_16
+#define cpu_to_be32 bswap_32
+#define cpu_to_be64 bswap_64
+#define be16_to_cpu bswap_16
+#define be32_to_cpu bswap_32
+#define be64_to_cpu bswap_64
+#endif
 
 int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
 int scnprintf(char * buf, size_t size, const char * fmt, ...);
-- 
1.9.1

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH V2 00/37] perf intel-pt: Power events and PTWRITE Adrian Hunter <adrian.hunter@intel.com> - 2017-05-26 10:30 +0200
  [PATCH V2 05/37] perf intel-pt: Fix last_ip usage Adrian Hunter <adrian.hunter@intel.com> - 2017-05-26 10:40 +0200
  [PATCH V2 02/37] perf intel-pt: Improve sample timestamp Adrian Hunter <adrian.hunter@intel.com> - 2017-05-26 10:40 +0200
  [PATCH V2 10/37] perf intel-pt: Allow decoding with branch tracing disabled Adrian Hunter <adrian.hunter@intel.com> - 2017-05-26 10:40 +0200
  [PATCH V2 15/37] perf intel-pt: Add decoder support for CBR events Adrian Hunter <adrian.hunter@intel.com> - 2017-05-26 10:40 +0200
  [PATCH V2 13/37] perf intel-pt: Add decoder support for ptwrite and power event packets Adrian Hunter <adrian.hunter@intel.com> - 2017-05-26 10:40 +0200
  [PATCH V2 04/37] perf intel-pt: Ensure IP is zero when state is INTEL_PT_STATE_NO_IP Adrian Hunter <adrian.hunter@intel.com> - 2017-05-26 10:40 +0200
  [PATCH V2 03/37] perf intel-pt: Fix missing stack clear Adrian Hunter <adrian.hunter@intel.com> - 2017-05-26 10:40 +0200
  [PATCH V2 22/37] tools include: Add byte-swapping macros to kernel.h Adrian Hunter <adrian.hunter@intel.com> - 2017-05-26 10:40 +0200
  [PATCH V2 06/37] perf intel-pt: Ensure never to set 'last_ip' when packet 'count' is zero Adrian Hunter <adrian.hunter@intel.com> - 2017-05-26 10:40 +0200

csiph-web