linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: tip-bot for Matt Fleming <matt.fleming@intel.com>
To: linux-tip-commits@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, hpa@zytor.com, mingo@redhat.com,
	tglx@linutronix.de, matt.fleming@intel.com
Subject: [tip:x86/build] tools/include: Add byteshift headers for endian access
Date: Tue, 28 Feb 2012 11:23:04 -0800	[thread overview]
Message-ID: <tip-a07f7672d7cf0ff0d6e548a9feb6e0bd016d9c6c@git.kernel.org> (raw)
In-Reply-To: <1330436245-24875-2-git-send-email-matt@console-pimps.org>

Commit-ID:  a07f7672d7cf0ff0d6e548a9feb6e0bd016d9c6c
Gitweb:     http://git.kernel.org/tip/a07f7672d7cf0ff0d6e548a9feb6e0bd016d9c6c
Author:     Matt Fleming <matt.fleming@intel.com>
AuthorDate: Tue, 28 Feb 2012 13:37:20 +0000
Committer:  H. Peter Anvin <hpa@zytor.com>
CommitDate: Tue, 28 Feb 2012 10:22:51 -0800

tools/include: Add byteshift headers for endian access

There are various hostprogs in the kernel that are rolling their own
implementations of {get,put}_unaligned_le*(). Copy the byteshift
headers from include/linux/unaligned so that they can all use a single
implementation.

This requires changing some of the data types to the userspace
exported ones (u32 -> __u32, etc).

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
Link: http://lkml.kernel.org/r/1330436245-24875-2-git-send-email-matt@console-pimps.org
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
---
 tools/include/tools/be_byteshift.h |   70 ++++++++++++++++++++++++++++++++++++
 tools/include/tools/le_byteshift.h |   70 ++++++++++++++++++++++++++++++++++++
 2 files changed, 140 insertions(+), 0 deletions(-)

diff --git a/tools/include/tools/be_byteshift.h b/tools/include/tools/be_byteshift.h
new file mode 100644
index 0000000..f4912e2
--- /dev/null
+++ b/tools/include/tools/be_byteshift.h
@@ -0,0 +1,70 @@
+#ifndef _TOOLS_BE_BYTESHIFT_H
+#define _TOOLS_BE_BYTESHIFT_H
+
+#include <linux/types.h>
+
+static inline __u16 __get_unaligned_be16(const __u8 *p)
+{
+	return p[0] << 8 | p[1];
+}
+
+static inline __u32 __get_unaligned_be32(const __u8 *p)
+{
+	return p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3];
+}
+
+static inline __u64 __get_unaligned_be64(const __u8 *p)
+{
+	return (__u64)__get_unaligned_be32(p) << 32 |
+	       __get_unaligned_be32(p + 4);
+}
+
+static inline void __put_unaligned_be16(__u16 val, __u8 *p)
+{
+	*p++ = val >> 8;
+	*p++ = val;
+}
+
+static inline void __put_unaligned_be32(__u32 val, __u8 *p)
+{
+	__put_unaligned_be16(val >> 16, p);
+	__put_unaligned_be16(val, p + 2);
+}
+
+static inline void __put_unaligned_be64(__u64 val, __u8 *p)
+{
+	__put_unaligned_be32(val >> 32, p);
+	__put_unaligned_be32(val, p + 4);
+}
+
+static inline __u16 get_unaligned_be16(const void *p)
+{
+	return __get_unaligned_be16((const __u8 *)p);
+}
+
+static inline __u32 get_unaligned_be32(const void *p)
+{
+	return __get_unaligned_be32((const __u8 *)p);
+}
+
+static inline __u64 get_unaligned_be64(const void *p)
+{
+	return __get_unaligned_be64((const __u8 *)p);
+}
+
+static inline void put_unaligned_be16(__u16 val, void *p)
+{
+	__put_unaligned_be16(val, p);
+}
+
+static inline void put_unaligned_be32(__u32 val, void *p)
+{
+	__put_unaligned_be32(val, p);
+}
+
+static inline void put_unaligned_be64(__u64 val, void *p)
+{
+	__put_unaligned_be64(val, p);
+}
+
+#endif /* _TOOLS_BE_BYTESHIFT_H */
diff --git a/tools/include/tools/le_byteshift.h b/tools/include/tools/le_byteshift.h
new file mode 100644
index 0000000..c99d45a
--- /dev/null
+++ b/tools/include/tools/le_byteshift.h
@@ -0,0 +1,70 @@
+#ifndef _TOOLS_LE_BYTESHIFT_H
+#define _TOOLS_LE_BYTESHIFT_H
+
+#include <linux/types.h>
+
+static inline __u16 __get_unaligned_le16(const __u8 *p)
+{
+	return p[0] | p[1] << 8;
+}
+
+static inline __u32 __get_unaligned_le32(const __u8 *p)
+{
+	return p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24;
+}
+
+static inline __u64 __get_unaligned_le64(const __u8 *p)
+{
+	return (__u64)__get_unaligned_le32(p + 4) << 32 |
+	       __get_unaligned_le32(p);
+}
+
+static inline void __put_unaligned_le16(__u16 val, __u8 *p)
+{
+	*p++ = val;
+	*p++ = val >> 8;
+}
+
+static inline void __put_unaligned_le32(__u32 val, __u8 *p)
+{
+	__put_unaligned_le16(val >> 16, p + 2);
+	__put_unaligned_le16(val, p);
+}
+
+static inline void __put_unaligned_le64(__u64 val, __u8 *p)
+{
+	__put_unaligned_le32(val >> 32, p + 4);
+	__put_unaligned_le32(val, p);
+}
+
+static inline __u16 get_unaligned_le16(const void *p)
+{
+	return __get_unaligned_le16((const __u8 *)p);
+}
+
+static inline __u32 get_unaligned_le32(const void *p)
+{
+	return __get_unaligned_le32((const __u8 *)p);
+}
+
+static inline __u64 get_unaligned_le64(const void *p)
+{
+	return __get_unaligned_le64((const __u8 *)p);
+}
+
+static inline void put_unaligned_le16(__u16 val, void *p)
+{
+	__put_unaligned_le16(val, p);
+}
+
+static inline void put_unaligned_le32(__u32 val, void *p)
+{
+	__put_unaligned_le32(val, p);
+}
+
+static inline void put_unaligned_le64(__u64 val, void *p)
+{
+	__put_unaligned_le64(val, p);
+}
+
+#endif /* _TOOLS_LE_BYTESHIFT_H */

  reply	other threads:[~2012-02-28 19:23 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-28 13:37 [RFC][PATCH 0/6] Add endian functions to tools/include Matt Fleming
2012-02-28 13:37 ` [RFC][PATCH 1/6] tools/include: Add byteshift headers for endian access Matt Fleming
2012-02-28 19:23   ` tip-bot for Matt Fleming [this message]
2012-02-28 13:37 ` [RFC][PATCH 2/6] x86, relocs: Don't open code put_unaligned_le32() Matt Fleming
2012-02-28 19:23   ` [tip:x86/build] " tip-bot for Matt Fleming
2012-02-28 13:37 ` [RFC][PATCH 3/6] x86, mkpiggy: " Matt Fleming
2012-02-28 19:24   ` [tip:x86/build] " tip-bot for Matt Fleming
2012-02-28 13:37 ` [RFC][PATCH 4/6] x86, boot: Restrict CFLAGS for hostprogs Matt Fleming
2012-02-28 19:25   ` [tip:x86/build] " tip-bot for Matt Fleming
2012-03-22 21:26   ` [tip:x86/urgent] x86, boot: Correct " tip-bot for H. Peter Anvin
2012-02-28 13:37 ` [RFC][PATCH 5/6] x86, efi: Fix endian issues and unaligned accesses Matt Fleming
2012-02-28 19:26   ` [tip:x86/build] " tip-bot for Matt Fleming
2012-02-28 23:52   ` [RFC][PATCH 5/6] " Stephen Rothwell
2012-02-29  0:13     ` Stephen Rothwell
2012-02-29  0:28       ` Stephen Rothwell
2012-02-29  8:04         ` Stephen Rothwell
2012-02-29  7:49       ` [tip:x86/build] x86, tools: Remove unneeded header files from tools/build.c tip-bot for H. Peter Anvin
2012-02-29  7:50       ` [tip:x86/build] x86, build: Fix portability issues when cross-building tip-bot for H. Peter Anvin
2012-02-28 13:37 ` [RFC][PATCH 6/6] USB: ffs-test: Don't duplicate {get,put}_unaligned*() functions Matt Fleming
2012-02-28 17:50   ` H. Peter Anvin
2012-02-28 17:58     ` Greg Kroah-Hartman
2012-02-28 19:25     ` Davidlohr Bueso
2012-02-28 19:27   ` [tip:x86/build] USB: ffs-test: Don't duplicate {get, put}_unaligned*() functions tip-bot for Matt Fleming

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tip-a07f7672d7cf0ff0d6e548a9feb6e0bd016d9c6c@git.kernel.org \
    --to=matt.fleming@intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).