···11+#ifndef __ASM_SH_BITOPS_OP32_H22+#define __ASM_SH_BITOPS_OP32_H33+44+/*55+ * The bit modifying instructions on SH-2A are only capable of working66+ * with a 3-bit immediate, which signifies the shift position for the bit77+ * being worked on.88+ */99+#if defined(__BIG_ENDIAN)1010+#define BITOP_LE_SWIZZLE ((BITS_PER_LONG-1) & ~0x7)1111+#define BYTE_NUMBER(nr) ((nr ^ BITOP_LE_SWIZZLE) / BITS_PER_BYTE)1212+#define BYTE_OFFSET(nr) ((nr ^ BITOP_LE_SWIZZLE) % BITS_PER_BYTE)1313+#else1414+#define BYTE_NUMBER(nr) ((nr) / BITS_PER_BYTE)1515+#define BYTE_OFFSET(nr) ((nr) % BITS_PER_BYTE)1616+#endif1717+1818+#define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))1919+2020+static inline void __set_bit(int nr, volatile unsigned long *addr)2121+{2222+ if (IS_IMMEDIATE(nr)) {2323+ __asm__ __volatile__ (2424+ "bset.b %1, @(%O2,%0) ! __set_bit\n\t"2525+ : "+r" (addr)2626+ : "i" (BYTE_OFFSET(nr)), "i" (BYTE_NUMBER(nr))2727+ : "t", "memory"2828+ );2929+ } else {3030+ unsigned long mask = BIT_MASK(nr);3131+ unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);3232+3333+ *p |= mask;3434+ }3535+}3636+3737+static inline void __clear_bit(int nr, volatile unsigned long *addr)3838+{3939+ if (IS_IMMEDIATE(nr)) {4040+ __asm__ __volatile__ (4141+ "bclr.b %1, @(%O2,%0) ! __clear_bit\n\t"4242+ : "+r" (addr)4343+ : "i" (BYTE_OFFSET(nr)),4444+ "i" (BYTE_NUMBER(nr))4545+ : "t", "memory"4646+ );4747+ } else {4848+ unsigned long mask = BIT_MASK(nr);4949+ unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);5050+5151+ *p &= ~mask;5252+ }5353+}5454+5555+/**5656+ * __change_bit - Toggle a bit in memory5757+ * @nr: the bit to change5858+ * @addr: the address to start counting from5959+ *6060+ * Unlike change_bit(), this function is non-atomic and may be reordered.6161+ * If it's called on the same region of memory simultaneously, the effect6262+ * may be that only one operation succeeds.6363+ */6464+static inline void __change_bit(int nr, volatile unsigned long *addr)6565+{6666+ if (IS_IMMEDIATE(nr)) {6767+ __asm__ __volatile__ (6868+ "bxor.b %1, @(%O2,%0) ! __change_bit\n\t"6969+ : "+r" (addr)7070+ : "i" (BYTE_OFFSET(nr)),7171+ "i" (BYTE_NUMBER(nr))7272+ : "t", "memory"7373+ );7474+ } else {7575+ unsigned long mask = BIT_MASK(nr);7676+ unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);7777+7878+ *p ^= mask;7979+ }8080+}8181+8282+/**8383+ * __test_and_set_bit - Set a bit and return its old value8484+ * @nr: Bit to set8585+ * @addr: Address to count from8686+ *8787+ * This operation is non-atomic and can be reordered.8888+ * If two examples of this operation race, one can appear to succeed8989+ * but actually fail. You must protect multiple accesses with a lock.9090+ */9191+static inline int __test_and_set_bit(int nr, volatile unsigned long *addr)9292+{9393+ unsigned long mask = BIT_MASK(nr);9494+ unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);9595+ unsigned long old = *p;9696+9797+ *p = old | mask;9898+ return (old & mask) != 0;9999+}100100+101101+/**102102+ * __test_and_clear_bit - Clear a bit and return its old value103103+ * @nr: Bit to clear104104+ * @addr: Address to count from105105+ *106106+ * This operation is non-atomic and can be reordered.107107+ * If two examples of this operation race, one can appear to succeed108108+ * but actually fail. You must protect multiple accesses with a lock.109109+ */110110+static inline int __test_and_clear_bit(int nr, volatile unsigned long *addr)111111+{112112+ unsigned long mask = BIT_MASK(nr);113113+ unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);114114+ unsigned long old = *p;115115+116116+ *p = old & ~mask;117117+ return (old & mask) != 0;118118+}119119+120120+/* WARNING: non atomic and it can be reordered! */121121+static inline int __test_and_change_bit(int nr,122122+ volatile unsigned long *addr)123123+{124124+ unsigned long mask = BIT_MASK(nr);125125+ unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);126126+ unsigned long old = *p;127127+128128+ *p = old ^ mask;129129+ return (old & mask) != 0;130130+}131131+132132+/**133133+ * test_bit - Determine whether a bit is set134134+ * @nr: bit number to test135135+ * @addr: Address to start counting from136136+ */137137+static inline int test_bit(int nr, const volatile unsigned long *addr)138138+{139139+ return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1)));140140+}141141+142142+#endif /* __ASM_SH_BITOPS_OP32_H */