]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - include/asm-mips/bitops.h
PCI PM: Fix pci_prepare_to_sleep
[linux-2.6-omap-h63xx.git] / include / asm-mips / bitops.h
index 899357a72ac4e15faab61c77a89ae20e34e9dcc5..642724734eba3e2dee33fe01cdd7fb12e8648aa9 100644 (file)
@@ -9,6 +9,10 @@
 #ifndef _ASM_BITOPS_H
 #define _ASM_BITOPS_H
 
+#ifndef _LINUX_BITOPS_H
+#error only <linux/bitops.h> can be included directly
+#endif
+
 #include <linux/compiler.h>
 #include <linux/irqflags.h>
 #include <linux/types.h>
@@ -171,6 +175,20 @@ static inline void clear_bit(unsigned long nr, volatile unsigned long *addr)
        }
 }
 
+/*
+ * clear_bit_unlock - Clears a bit in memory
+ * @nr: Bit to clear
+ * @addr: Address to start counting from
+ *
+ * clear_bit() is atomic and implies release semantics before the memory
+ * operation. It can be used for an unlock.
+ */
+static inline void clear_bit_unlock(unsigned long nr, volatile unsigned long *addr)
+{
+       smp_mb__before_clear_bit();
+       clear_bit(nr, addr);
+}
+
 /*
  * change_bit - Toggle a bit in memory
  * @nr: Bit to change
@@ -240,6 +258,8 @@ static inline int test_and_set_bit(unsigned long nr,
        unsigned short bit = nr & SZLONG_MASK;
        unsigned long res;
 
+       smp_llsc_mb();
+
        if (cpu_has_llsc && R10000_LLSC_WAR) {
                unsigned long *m = ((unsigned long *) addr) + (nr >> SZLONG_LOG);
                unsigned long temp;
@@ -294,6 +314,73 @@ static inline int test_and_set_bit(unsigned long nr,
        return res != 0;
 }
 
+/*
+ * test_and_set_bit_lock - Set a bit and return its old value
+ * @nr: Bit to set
+ * @addr: Address to count from
+ *
+ * This operation is atomic and implies acquire ordering semantics
+ * after the memory operation.
+ */
+static inline int test_and_set_bit_lock(unsigned long nr,
+       volatile unsigned long *addr)
+{
+       unsigned short bit = nr & SZLONG_MASK;
+       unsigned long res;
+
+       if (cpu_has_llsc && R10000_LLSC_WAR) {
+               unsigned long *m = ((unsigned long *) addr) + (nr >> SZLONG_LOG);
+               unsigned long temp;
+
+               __asm__ __volatile__(
+               "       .set    mips3                                   \n"
+               "1:     " __LL "%0, %1          # test_and_set_bit      \n"
+               "       or      %2, %0, %3                              \n"
+               "       " __SC  "%2, %1                                 \n"
+               "       beqzl   %2, 1b                                  \n"
+               "       and     %2, %0, %3                              \n"
+               "       .set    mips0                                   \n"
+               : "=&r" (temp), "=m" (*m), "=&r" (res)
+               : "r" (1UL << bit), "m" (*m)
+               : "memory");
+       } else if (cpu_has_llsc) {
+               unsigned long *m = ((unsigned long *) addr) + (nr >> SZLONG_LOG);
+               unsigned long temp;
+
+               __asm__ __volatile__(
+               "       .set    push                                    \n"
+               "       .set    noreorder                               \n"
+               "       .set    mips3                                   \n"
+               "1:     " __LL "%0, %1          # test_and_set_bit      \n"
+               "       or      %2, %0, %3                              \n"
+               "       " __SC  "%2, %1                                 \n"
+               "       beqz    %2, 2f                                  \n"
+               "        and    %2, %0, %3                              \n"
+               "       .subsection 2                                   \n"
+               "2:     b       1b                                      \n"
+               "        nop                                            \n"
+               "       .previous                                       \n"
+               "       .set    pop                                     \n"
+               : "=&r" (temp), "=m" (*m), "=&r" (res)
+               : "r" (1UL << bit), "m" (*m)
+               : "memory");
+       } else {
+               volatile unsigned long *a = addr;
+               unsigned long mask;
+               unsigned long flags;
+
+               a += nr >> SZLONG_LOG;
+               mask = 1UL << bit;
+               raw_local_irq_save(flags);
+               res = (mask & *a);
+               *a |= mask;
+               raw_local_irq_restore(flags);
+       }
+
+       smp_llsc_mb();
+
+       return res != 0;
+}
 /*
  * test_and_clear_bit - Clear a bit and return its old value
  * @nr: Bit to clear
@@ -308,6 +395,8 @@ static inline int test_and_clear_bit(unsigned long nr,
        unsigned short bit = nr & SZLONG_MASK;
        unsigned long res;
 
+       smp_llsc_mb();
+
        if (cpu_has_llsc && R10000_LLSC_WAR) {
                unsigned long *m = ((unsigned long *) addr) + (nr >> SZLONG_LOG);
                unsigned long temp;
@@ -396,6 +485,8 @@ static inline int test_and_change_bit(unsigned long nr,
        unsigned short bit = nr & SZLONG_MASK;
        unsigned long res;
 
+       smp_llsc_mb();
+
        if (cpu_has_llsc && R10000_LLSC_WAR) {
                unsigned long *m = ((unsigned long *) addr) + (nr >> SZLONG_LOG);
                unsigned long temp;
@@ -452,11 +543,28 @@ static inline int test_and_change_bit(unsigned long nr,
 
 #include <asm-generic/bitops/non-atomic.h>
 
+/*
+ * __clear_bit_unlock - Clears a bit in memory
+ * @nr: Bit to clear
+ * @addr: Address to start counting from
+ *
+ * __clear_bit() is non-atomic and implies release semantics before the memory
+ * operation. It can be used for an unlock if no other CPUs can concurrently
+ * modify other bits in the word.
+ */
+static inline void __clear_bit_unlock(unsigned long nr, volatile unsigned long *addr)
+{
+       smp_mb();
+       __clear_bit(nr, addr);
+}
+
+#if defined(CONFIG_CPU_MIPS32) || defined(CONFIG_CPU_MIPS64)
+
 /*
  * Return the bit position (0..63) of the most significant 1 bit in a word
  * Returns -1 if no 1 bit exists
  */
-static inline int __ilog2(unsigned long x)
+static inline unsigned long __fls(unsigned long x)
 {
        int lz;
 
@@ -485,8 +593,6 @@ static inline int __ilog2(unsigned long x)
        return 63 - lz;
 }
 
-#if defined(CONFIG_CPU_MIPS32) || defined(CONFIG_CPU_MIPS64)
-
 /*
  * __ffs - find first bit in word.
  * @word: The word to search
@@ -496,7 +602,7 @@ static inline int __ilog2(unsigned long x)
  */
 static inline unsigned long __ffs(unsigned long word)
 {
-       return __ilog2(word & -word);
+       return __fls(word & -word);
 }
 
 /*
@@ -543,6 +649,7 @@ static inline int ffs(int word)
 #else
 
 #include <asm-generic/bitops/__ffs.h>
+#include <asm-generic/bitops/__fls.h>
 #include <asm-generic/bitops/ffs.h>
 #include <asm-generic/bitops/fls.h>
 #include <asm-generic/bitops/fls64.h>