[POWERPC] 83xx: Add the MPC8315E RDB dts
[linux-2.6/zen-sources.git] / include / asm-sh / bitops.h
blobdf805f20b26786a3d74478a0c2fd6e10bf1777e5
1 #ifndef __ASM_SH_BITOPS_H
2 #define __ASM_SH_BITOPS_H
4 #ifdef __KERNEL__
6 #ifndef _LINUX_BITOPS_H
7 #error only <linux/bitops.h> can be included directly
8 #endif
10 #include <asm/system.h>
11 /* For __swab32 */
12 #include <asm/byteorder.h>
14 static inline void set_bit(int nr, volatile void * addr)
16 int mask;
17 volatile unsigned int *a = addr;
18 unsigned long flags;
20 a += nr >> 5;
21 mask = 1 << (nr & 0x1f);
22 local_irq_save(flags);
23 *a |= mask;
24 local_irq_restore(flags);
28 * clear_bit() doesn't provide any barrier for the compiler.
30 #define smp_mb__before_clear_bit() barrier()
31 #define smp_mb__after_clear_bit() barrier()
32 static inline void clear_bit(int nr, volatile void * addr)
34 int mask;
35 volatile unsigned int *a = addr;
36 unsigned long flags;
38 a += nr >> 5;
39 mask = 1 << (nr & 0x1f);
40 local_irq_save(flags);
41 *a &= ~mask;
42 local_irq_restore(flags);
45 static inline void change_bit(int nr, volatile void * addr)
47 int mask;
48 volatile unsigned int *a = addr;
49 unsigned long flags;
51 a += nr >> 5;
52 mask = 1 << (nr & 0x1f);
53 local_irq_save(flags);
54 *a ^= mask;
55 local_irq_restore(flags);
58 static inline int test_and_set_bit(int nr, volatile void * addr)
60 int mask, retval;
61 volatile unsigned int *a = addr;
62 unsigned long flags;
64 a += nr >> 5;
65 mask = 1 << (nr & 0x1f);
66 local_irq_save(flags);
67 retval = (mask & *a) != 0;
68 *a |= mask;
69 local_irq_restore(flags);
71 return retval;
74 static inline int test_and_clear_bit(int nr, volatile void * addr)
76 int mask, retval;
77 volatile unsigned int *a = addr;
78 unsigned long flags;
80 a += nr >> 5;
81 mask = 1 << (nr & 0x1f);
82 local_irq_save(flags);
83 retval = (mask & *a) != 0;
84 *a &= ~mask;
85 local_irq_restore(flags);
87 return retval;
90 static inline int test_and_change_bit(int nr, volatile void * addr)
92 int mask, retval;
93 volatile unsigned int *a = addr;
94 unsigned long flags;
96 a += nr >> 5;
97 mask = 1 << (nr & 0x1f);
98 local_irq_save(flags);
99 retval = (mask & *a) != 0;
100 *a ^= mask;
101 local_irq_restore(flags);
103 return retval;
106 #include <asm-generic/bitops/non-atomic.h>
108 static inline unsigned long ffz(unsigned long word)
110 unsigned long result;
112 __asm__("1:\n\t"
113 "shlr %1\n\t"
114 "bt/s 1b\n\t"
115 " add #1, %0"
116 : "=r" (result), "=r" (word)
117 : "0" (~0L), "1" (word)
118 : "t");
119 return result;
123 * __ffs - find first bit in word.
124 * @word: The word to search
126 * Undefined if no bit exists, so code should check against 0 first.
128 static inline unsigned long __ffs(unsigned long word)
130 unsigned long result;
132 __asm__("1:\n\t"
133 "shlr %1\n\t"
134 "bf/s 1b\n\t"
135 " add #1, %0"
136 : "=r" (result), "=r" (word)
137 : "0" (~0L), "1" (word)
138 : "t");
139 return result;
142 #include <asm-generic/bitops/find.h>
143 #include <asm-generic/bitops/ffs.h>
144 #include <asm-generic/bitops/hweight.h>
145 #include <asm-generic/bitops/lock.h>
146 #include <asm-generic/bitops/sched.h>
147 #include <asm-generic/bitops/ext2-non-atomic.h>
148 #include <asm-generic/bitops/ext2-atomic.h>
149 #include <asm-generic/bitops/minix.h>
150 #include <asm-generic/bitops/fls.h>
151 #include <asm-generic/bitops/fls64.h>
153 #endif /* __KERNEL__ */
155 #endif /* __ASM_SH_BITOPS_H */