]>
git.ipfire.org Git - people/ms/u-boot.git/blob - arch/arm/include/asm/bitops.h
2 * Copyright 1995, Russell King.
3 * Various bits and pieces copyrights include:
4 * Linus Torvalds (test_bit).
6 * bit 0 is the LSB of addr; bit 32 is the LSB of (addr+1).
8 * Please note that the code in this file should never be included
9 * from user space. Many of these are not implemented in assembler
10 * since they would be too costly. Also, they require priviledged
11 * instructions (which are not available from user mode) to ensure
12 * that they are atomic.
15 #ifndef __ASM_ARM_BITOPS_H
16 #define __ASM_ARM_BITOPS_H
20 #include <asm/proc/system.h>
22 #define smp_mb__before_clear_bit() do { } while (0)
23 #define smp_mb__after_clear_bit() do { } while (0)
26 * Function prototypes to keep gcc -Wall happy.
28 extern void set_bit(int nr
, volatile void * addr
);
30 extern void clear_bit(int nr
, volatile void * addr
);
32 extern void change_bit(int nr
, volatile void * addr
);
34 static inline void __change_bit(int nr
, volatile void *addr
)
36 unsigned long mask
= BIT_MASK(nr
);
37 unsigned long *p
= ((unsigned long *)addr
) + BIT_WORD(nr
);
42 static inline int __test_and_set_bit(int nr
, volatile void *addr
)
44 unsigned long mask
= BIT_MASK(nr
);
45 unsigned long *p
= ((unsigned long *)addr
) + BIT_WORD(nr
);
46 unsigned long old
= *p
;
49 return (old
& mask
) != 0;
52 static inline int test_and_set_bit(int nr
, volatile void * addr
)
57 local_irq_save(flags
);
58 out
= __test_and_set_bit(nr
, addr
);
59 local_irq_restore(flags
);
64 static inline int __test_and_clear_bit(int nr
, volatile void *addr
)
66 unsigned long mask
= BIT_MASK(nr
);
67 unsigned long *p
= ((unsigned long *)addr
) + BIT_WORD(nr
);
68 unsigned long old
= *p
;
71 return (old
& mask
) != 0;
74 static inline int test_and_clear_bit(int nr
, volatile void * addr
)
79 local_irq_save(flags
);
80 out
= __test_and_clear_bit(nr
, addr
);
81 local_irq_restore(flags
);
86 extern int test_and_change_bit(int nr
, volatile void * addr
);
88 static inline int __test_and_change_bit(int nr
, volatile void *addr
)
90 unsigned long mask
= BIT_MASK(nr
);
91 unsigned long *p
= ((unsigned long *)addr
) + BIT_WORD(nr
);
92 unsigned long old
= *p
;
95 return (old
& mask
) != 0;
98 extern int find_first_zero_bit(void * addr
, unsigned size
);
99 extern int find_next_zero_bit(void * addr
, int size
, int offset
);
102 * This routine doesn't need to be atomic.
104 static inline int test_bit(int nr
, const void * addr
)
106 return ((unsigned char *) addr
)[nr
>> 3] & (1U << (nr
& 7));
109 static inline int __ilog2(unsigned int x
)
111 return generic_fls(x
) - 1;
115 * ffz = Find First Zero in word. Undefined if no zero exists,
116 * so code should check against ~0UL first..
118 static inline unsigned long ffz(unsigned long word
)
124 if (word
& 0x0000ffff) { k
-= 16; word
<<= 16; }
125 if (word
& 0x00ff0000) { k
-= 8; word
<<= 8; }
126 if (word
& 0x0f000000) { k
-= 4; word
<<= 4; }
127 if (word
& 0x30000000) { k
-= 2; word
<<= 2; }
128 if (word
& 0x40000000) { k
-= 1; }
133 * hweightN: returns the hamming weight (i.e. the number
134 * of bits set) of a N-bit word
137 #define hweight32(x) generic_hweight32(x)
138 #define hweight16(x) generic_hweight16(x)
139 #define hweight8(x) generic_hweight8(x)
141 #define ext2_set_bit test_and_set_bit
142 #define ext2_clear_bit test_and_clear_bit
143 #define ext2_test_bit test_bit
144 #define ext2_find_first_zero_bit find_first_zero_bit
145 #define ext2_find_next_zero_bit find_next_zero_bit
147 /* Bitmap functions for the minix filesystem. */
148 #define minix_test_and_set_bit(nr,addr) test_and_set_bit(nr,addr)
149 #define minix_set_bit(nr,addr) set_bit(nr,addr)
150 #define minix_test_and_clear_bit(nr,addr) test_and_clear_bit(nr,addr)
151 #define minix_test_bit(nr,addr) test_bit(nr,addr)
152 #define minix_find_first_zero_bit(addr,size) find_first_zero_bit(addr,size)
154 #endif /* __KERNEL__ */
156 #endif /* _ARM_BITOPS_H */