From: Peter Feiner <pfeiner@google.com>
To: kvm@vger.kernel.org, jan.kiszka@siemens.com, drjones@redhat.com,
pbonzini@redhat.com
Cc: pfeiner@google.com
Subject: [kvm-unit-tests v3 2/6] lib: generic bitops.h
Date: Wed, 2 Mar 2016 09:10:53 -0800 [thread overview]
Message-ID: <1456938657-20850-3-git-send-email-pfeiner@google.com> (raw)
In-Reply-To: <1456938657-20850-1-git-send-email-pfeiner@google.com>
Factored out common bitops stuff, just like Linux's
include/linux/bitops.h.
Signed-off-by: Peter Feiner <pfeiner@google.com>
---
lib/arm/asm/bitops.h | 8 ++++----
lib/arm/asm/cpumask.h | 2 +-
lib/arm/bitops.c | 2 +-
lib/arm64/asm/bitops.h | 8 ++++----
lib/bitops.h | 36 ++++++++++++++++++++++++++++++++++++
lib/ppc64/asm/bitops.h | 10 ++++++++++
lib/x86/asm/bitops.h | 14 ++++++++++++++
7 files changed, 70 insertions(+), 10 deletions(-)
create mode 100644 lib/bitops.h
create mode 100644 lib/ppc64/asm/bitops.h
create mode 100644 lib/x86/asm/bitops.h
diff --git a/lib/arm/asm/bitops.h b/lib/arm/asm/bitops.h
index 8049634..d46cc5d 100644
--- a/lib/arm/asm/bitops.h
+++ b/lib/arm/asm/bitops.h
@@ -2,7 +2,6 @@
#define _ASMARM_BITOPS_H_
/*
* Adapated from
- * include/linux/bitops.h
* arch/arm/lib/bitops.h
*
* Copyright (C) 2015, Red Hat Inc, Andrew Jones <drjones@redhat.com>
@@ -10,10 +9,11 @@
* This work is licensed under the terms of the GNU LGPL, version 2.
*/
+#ifndef _BITOPS_H_
+#error only <bitops.h> can be included directly
+#endif
+
#define BITS_PER_LONG 32
-#define BIT(nr) (1UL << (nr))
-#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
-#define BIT_WORD(nr) ((nr) / BITS_PER_LONG)
#define ATOMIC_BITOP(insn, mask, word) \
({ \
diff --git a/lib/arm/asm/cpumask.h b/lib/arm/asm/cpumask.h
index 85b8e4b..6683bb6 100644
--- a/lib/arm/asm/cpumask.h
+++ b/lib/arm/asm/cpumask.h
@@ -8,7 +8,7 @@
* This work is licensed under the terms of the GNU LGPL, version 2.
*/
#include <asm/setup.h>
-#include <asm/bitops.h>
+#include <bitops.h>
#define CPUMASK_NR_LONGS ((NR_CPUS + BITS_PER_LONG - 1) / BITS_PER_LONG)
diff --git a/lib/arm/bitops.c b/lib/arm/bitops.c
index 9ad1121..1f1db93 100644
--- a/lib/arm/bitops.c
+++ b/lib/arm/bitops.c
@@ -6,7 +6,7 @@
*
* This work is licensed under the terms of the GNU LGPL, version 2.
*/
-#include <asm/bitops.h>
+#include <bitops.h>
#include <asm/barrier.h>
#include <asm/mmu.h>
diff --git a/lib/arm64/asm/bitops.h b/lib/arm64/asm/bitops.h
index 3371c60..618468c 100644
--- a/lib/arm64/asm/bitops.h
+++ b/lib/arm64/asm/bitops.h
@@ -2,7 +2,6 @@
#define _ASMARM64_BITOPS_H_
/*
* Adapated from
- * include/linux/bitops.h
* arch/arm64/lib/bitops.S
*
* Copyright (C) 2015, Red Hat Inc, Andrew Jones <drjones@redhat.com>
@@ -10,10 +9,11 @@
* This work is licensed under the terms of the GNU LGPL, version 2.
*/
+#ifndef _BITOPS_H_
+#error only <bitops.h> can be included directly
+#endif
+
#define BITS_PER_LONG 64
-#define BIT(nr) (1UL << (nr))
-#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
-#define BIT_WORD(nr) ((nr) / BITS_PER_LONG)
#define ATOMIC_BITOP(insn, mask, word) \
({ \
diff --git a/lib/bitops.h b/lib/bitops.h
new file mode 100644
index 0000000..9aa847e
--- /dev/null
+++ b/lib/bitops.h
@@ -0,0 +1,36 @@
+#ifndef _BITOPS_H_
+#define _BITOPS_H_
+
+/*
+ * Adapated from
+ * include/linux/bitops.h
+ *
+ * Copyright (C) 2015, Red Hat Inc, Andrew Jones <drjones@redhat.com>
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.
+ */
+
+#define BITS_PER_LONG_LONG 64
+#define BIT(nr) (1UL << (nr))
+#define BIT_ULL(nr) (1ULL << (nr))
+#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
+#define BIT_WORD(nr) ((nr) / BITS_PER_LONG)
+#define BIT_ULL_MASK(nr) (1ULL << ((nr) % BITS_PER_LONG_LONG))
+#define BIT_ULL_WORD(nr) ((nr) / BITS_PER_LONG_LONG)
+#define BITS_PER_BYTE 8
+#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
+
+#include <asm/bitops.h>
+
+/*
+ * Create a contiguous bitmask starting at bit position @l and ending at
+ * position @h. For example
+ * GENMASK_ULL(39, 21) gives us the 64bit vector 0x000000ffffe00000.
+ */
+#define GENMASK(h, l) \
+ (((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
+
+#define GENMASK_ULL(h, l) \
+ (((~0ULL) << (l)) & (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h))))
+
+#endif
diff --git a/lib/ppc64/asm/bitops.h b/lib/ppc64/asm/bitops.h
new file mode 100644
index 0000000..34624b4
--- /dev/null
+++ b/lib/ppc64/asm/bitops.h
@@ -0,0 +1,10 @@
+#ifndef _ASMPPC64_BITOPS_H_
+#define _ASMPPC64_BITOPS_H_
+
+#ifndef _BITOPS_H_
+#error only <bitops.h> can be included directly
+#endif
+
+#define BITS_PER_LONG 64
+
+#endif
diff --git a/lib/x86/asm/bitops.h b/lib/x86/asm/bitops.h
new file mode 100644
index 0000000..eb4aaa9
--- /dev/null
+++ b/lib/x86/asm/bitops.h
@@ -0,0 +1,14 @@
+#ifndef _ASMX86_BITOPS_H_
+#define _ASMX86_BITOPS_H_
+
+#ifndef _BITOPS_H_
+#error only <bitops.h> can be included directly
+#endif
+
+#ifdef __x86_64__
+#define BITS_PER_LONG 64
+#else
+#define BITS_PER_LONG 32
+#endif
+
+#endif
--
2.7.0.rc3.207.g0ac5344
next prev parent reply other threads:[~2016-03-02 17:11 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-01 19:30 [kvm-unit-tests 0/5] Split large EPT mappings properly Peter Feiner
2016-03-01 19:30 ` [kvm-unit-tests 1/5] x86: vmx.h: trivial whitespace fixes Peter Feiner
2016-03-01 19:30 ` [kvm-unit-tests 2/5] x86: vmx: Named constant: EPT_ADDR_MASK Peter Feiner
2016-03-01 21:12 ` Paolo Bonzini
2016-03-01 21:16 ` Peter Feiner
2016-03-01 21:27 ` Jan Kiszka
2016-03-01 21:36 ` Paolo Bonzini
2016-03-01 19:30 ` [kvm-unit-tests 3/5] x86: vmx: Named constant: EPT_LEVEL_SHIFT Peter Feiner
2016-03-01 19:30 ` [kvm-unit-tests 4/5] x86: vmx: split large EPTEs in install_ept_entry Peter Feiner
2016-03-01 19:30 ` [kvm-unit-tests 5/5] x86: vmx: don't explicitly split identity EPT map Peter Feiner
2016-03-01 21:13 ` [kvm-unit-tests 0/5] Split large EPT mappings properly Paolo Bonzini
2016-03-01 22:34 ` [kvm-unit-tests v2 0/6] " Peter Feiner
2016-03-01 22:34 ` [kvm-unit-tests v2 1/6] x86: vmx.h: trivial whitespace fixes Peter Feiner
2016-03-01 22:34 ` [kvm-unit-tests v2 2/6] lib: generic bitops.h Peter Feiner
2016-03-01 22:34 ` [kvm-unit-tests v2 3/6] x86: vmx: Named constant: EPT_ADDR_MASK Peter Feiner
2016-03-02 6:24 ` Jan Kiszka
2016-03-02 8:47 ` Paolo Bonzini
2016-03-02 16:50 ` Peter Feiner
2016-03-01 22:34 ` [kvm-unit-tests v2 4/6] x86: vmx: Named constant: EPT_LEVEL_SHIFT Peter Feiner
2016-03-01 22:34 ` [kvm-unit-tests v2 5/6] x86: vmx: split large EPTEs in install_ept_entry Peter Feiner
2016-03-01 22:34 ` [kvm-unit-tests v2 6/6] x86: vmx: don't explicitly split identity EPT map Peter Feiner
2016-03-02 17:10 ` [kvm-unit-tests v3 0/6] Split large EPT mappings properly Peter Feiner
2016-03-02 17:10 ` [kvm-unit-tests v3 1/6] x86: vmx.h: trivial whitespace fixes Peter Feiner
2016-03-02 17:10 ` Peter Feiner [this message]
2016-03-02 18:13 ` [kvm-unit-tests v3 2/6] lib: generic bitops.h Andrew Jones
2016-03-02 17:10 ` [kvm-unit-tests v3 3/6] x86: vmx: Named constant: EPT_ADDR_MASK Peter Feiner
2016-03-02 17:10 ` [kvm-unit-tests v3 4/6] x86: vmx: Named constant: EPT_LEVEL_SHIFT Peter Feiner
2016-03-02 17:10 ` [kvm-unit-tests v3 5/6] x86: vmx: split large EPTEs in install_ept_entry Peter Feiner
2016-03-02 17:10 ` [kvm-unit-tests v3 6/6] x86: vmx: don't explicitly split identity EPT map Peter Feiner
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=1456938657-20850-3-git-send-email-pfeiner@google.com \
--to=pfeiner@google.com \
--cc=drjones@redhat.com \
--cc=jan.kiszka@siemens.com \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.com \
/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