From: Jan Kiszka <[email protected]>

Most parts are shared, so no point in duplicating them.

Signed-off-by: Jan Kiszka <[email protected]>
---
 .../arch/{arm => arm-common}/include/asm/bitops.h  | 31 ++-------------------
 hypervisor/arch/arm/include/asm/bitops.h           | 32 +++-------------------
 hypervisor/arch/arm64/include/asm/bitops.h         | 31 ++-------------------
 3 files changed, 9 insertions(+), 85 deletions(-)
 copy hypervisor/arch/{arm => arm-common}/include/asm/bitops.h (59%)

diff --git a/hypervisor/arch/arm/include/asm/bitops.h 
b/hypervisor/arch/arm-common/include/asm/bitops.h
similarity index 59%
copy from hypervisor/arch/arm/include/asm/bitops.h
copy to hypervisor/arch/arm-common/include/asm/bitops.h
index a0c4e9dd..808c9a0f 100644
--- a/hypervisor/arch/arm/include/asm/bitops.h
+++ b/hypervisor/arch/arm-common/include/asm/bitops.h
@@ -2,9 +2,11 @@
  * Jailhouse, a Linux-based partitioning hypervisor
  *
  * Copyright (c) Siemens AG, 2013-2020
+ * Copyright (c) ARM Limited, 2014
  *
  * Authors:
  *  Jan Kiszka <[email protected]>
+ *  Jean-Philippe Brucker <[email protected]>
  *
  * This work is licensed under the terms of the GNU GPL, version 2.  See
  * the COPYING file in the top-level directory.
@@ -17,38 +19,11 @@ test_bit(unsigned int nr, const volatile unsigned long 
*addr)
                (addr[nr / BITS_PER_LONG])) != 0;
 }
 
-static inline int atomic_test_and_set_bit(int nr, volatile unsigned long *addr)
-{
-       unsigned long ret, val, test;
-
-       /* word-align */
-       addr = (unsigned long *)((u32)addr & ~0x3) + nr / BITS_PER_LONG;
-       nr %= BITS_PER_LONG;
-
-       /* Load the cacheline in exclusive state */
-       asm volatile (
-               ".arch_extension mp\n\t"
-               "pldw %0\n\t"
-               : "+Qo" (*(volatile unsigned long *)addr));
-       do {
-               asm volatile (
-                       "ldrex  %1, %3\n\t"
-                       "ands   %2, %1, %4\n\t"
-                       "it     eq\n\t"
-                       "orreq  %1, %4\n\t"
-                       "strex  %0, %1, %3\n\t"
-                       : "=r" (ret), "=r" (val), "=r" (test),
-                         "+Qo" (*(volatile unsigned long *)addr)
-                       : "r" (1 << nr));
-       } while (ret);
-
-       return !!(test);
-}
-
 /* Count leading zeroes */
 static inline unsigned long clz(unsigned long word)
 {
        unsigned long val;
+
        asm volatile ("clz %0, %1" : "=r" (val) : "r" (word));
        return val;
 }
diff --git a/hypervisor/arch/arm/include/asm/bitops.h 
b/hypervisor/arch/arm/include/asm/bitops.h
index a0c4e9dd..67aee781 100644
--- a/hypervisor/arch/arm/include/asm/bitops.h
+++ b/hypervisor/arch/arm/include/asm/bitops.h
@@ -2,20 +2,18 @@
  * Jailhouse, a Linux-based partitioning hypervisor
  *
  * Copyright (c) Siemens AG, 2013-2020
+ * Copyright (c) ARM Limited, 2014
  *
  * Authors:
  *  Jan Kiszka <[email protected]>
+ *  Jean-Philippe Brucker <[email protected]>
  *
  * This work is licensed under the terms of the GNU GPL, version 2.  See
  * the COPYING file in the top-level directory.
  */
 
-static inline __attribute__((always_inline)) int
-test_bit(unsigned int nr, const volatile unsigned long *addr)
-{
-       return ((1UL << (nr % BITS_PER_LONG)) &
-               (addr[nr / BITS_PER_LONG])) != 0;
-}
+/* also include from arm-common */
+#include_next <asm/bitops.h>
 
 static inline int atomic_test_and_set_bit(int nr, volatile unsigned long *addr)
 {
@@ -44,25 +42,3 @@ static inline int atomic_test_and_set_bit(int nr, volatile 
unsigned long *addr)
 
        return !!(test);
 }
-
-/* Count leading zeroes */
-static inline unsigned long clz(unsigned long word)
-{
-       unsigned long val;
-       asm volatile ("clz %0, %1" : "=r" (val) : "r" (word));
-       return val;
-}
-
-/* Returns the position of the least significant 1, MSB=31, LSB=0*/
-static inline unsigned long ffsl(unsigned long word)
-{
-       if (!word)
-               return 0;
-       asm volatile ("rbit %0, %0" : "+r" (word));
-       return clz(word);
-}
-
-static inline unsigned long ffzl(unsigned long word)
-{
-       return ffsl(~word);
-}
diff --git a/hypervisor/arch/arm64/include/asm/bitops.h 
b/hypervisor/arch/arm64/include/asm/bitops.h
index 3de2a24d..a4878e0e 100644
--- a/hypervisor/arch/arm64/include/asm/bitops.h
+++ b/hypervisor/arch/arm64/include/asm/bitops.h
@@ -11,12 +11,8 @@
  * the COPYING file in the top-level directory.
  */
 
-static inline __attribute__((always_inline)) int
-test_bit(unsigned int nr, const volatile unsigned long *addr)
-{
-       return ((1UL << (nr % BITS_PER_LONG)) &
-               (addr[nr / BITS_PER_LONG])) != 0;
-}
+/* also include from arm-common */
+#include_next <asm/bitops.h>
 
 static inline int atomic_test_and_set_bit(int nr, volatile unsigned long *addr)
 {
@@ -47,26 +43,3 @@ static inline int atomic_test_and_set_bit(int nr, volatile 
unsigned long *addr)
        } while (ret);
        return !!(test);
 }
-
-/* Count leading zeroes */
-static inline unsigned long clz(unsigned long word)
-{
-       unsigned long val;
-
-       asm volatile ("clz %0, %1" : "=r" (val) : "r" (word));
-       return val;
-}
-
-/* Returns the position of the least significant 1, MSB=63, LSB=0*/
-static inline unsigned long ffsl(unsigned long word)
-{
-       if (!word)
-               return 0;
-       asm volatile ("rbit %0, %0" : "+r" (word));
-       return clz(word);
-}
-
-static inline unsigned long ffzl(unsigned long word)
-{
-       return ffsl(~word);
-}
-- 
2.16.4

-- 
You received this message because you are subscribed to the Google Groups 
"Jailhouse" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jailhouse-dev/ca7123a5c58d6e698c5349f29dfbac9a44e5e459.1581930651.git.jan.kiszka%40siemens.com.

Reply via email to