]> git.karo-electronics.de Git - karo-tx-uboot.git/blob - include/asm-arm/bitops.h
Move __set/clear_bit from ubifs.h to bitops.h
[karo-tx-uboot.git] / include / asm-arm / bitops.h
1 /*
2  * Copyright 1995, Russell King.
3  * Various bits and pieces copyrights include:
4  *  Linus Torvalds (test_bit).
5  *
6  * bit 0 is the LSB of addr; bit 32 is the LSB of (addr+1).
7  *
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.
13  */
14
15 #ifndef __ASM_ARM_BITOPS_H
16 #define __ASM_ARM_BITOPS_H
17
18 #ifdef __KERNEL__
19
20 #define smp_mb__before_clear_bit()      do { } while (0)
21 #define smp_mb__after_clear_bit()       do { } while (0)
22
23 /*
24  * Function prototypes to keep gcc -Wall happy.
25  */
26 extern void set_bit(int nr, volatile void * addr);
27
28 static inline void __set_bit(int nr, volatile void *addr)
29 {
30         ((unsigned char *) addr)[nr >> 3] |= (1U << (nr & 7));
31 }
32 #define __set_bit
33
34 extern void clear_bit(int nr, volatile void * addr);
35
36 static inline void __clear_bit(int nr, volatile void *addr)
37 {
38         ((unsigned char *) addr)[nr >> 3] &= ~(1U << (nr & 7));
39 }
40 #define __clear_bit
41
42 extern void change_bit(int nr, volatile void * addr);
43
44 static inline void __change_bit(int nr, volatile void *addr)
45 {
46         ((unsigned char *) addr)[nr >> 3] ^= (1U << (nr & 7));
47 }
48
49 extern int test_and_set_bit(int nr, volatile void * addr);
50
51 static inline int __test_and_set_bit(int nr, volatile void *addr)
52 {
53         unsigned int mask = 1 << (nr & 7);
54         unsigned int oldval;
55
56         oldval = ((unsigned char *) addr)[nr >> 3];
57         ((unsigned char *) addr)[nr >> 3] = oldval | mask;
58         return oldval & mask;
59 }
60
61 extern int test_and_clear_bit(int nr, volatile void * addr);
62
63 static inline int __test_and_clear_bit(int nr, volatile void *addr)
64 {
65         unsigned int mask = 1 << (nr & 7);
66         unsigned int oldval;
67
68         oldval = ((unsigned char *) addr)[nr >> 3];
69         ((unsigned char *) addr)[nr >> 3] = oldval & ~mask;
70         return oldval & mask;
71 }
72
73 extern int test_and_change_bit(int nr, volatile void * addr);
74
75 static inline int __test_and_change_bit(int nr, volatile void *addr)
76 {
77         unsigned int mask = 1 << (nr & 7);
78         unsigned int oldval;
79
80         oldval = ((unsigned char *) addr)[nr >> 3];
81         ((unsigned char *) addr)[nr >> 3] = oldval ^ mask;
82         return oldval & mask;
83 }
84
85 extern int find_first_zero_bit(void * addr, unsigned size);
86 extern int find_next_zero_bit(void * addr, int size, int offset);
87
88 /*
89  * This routine doesn't need to be atomic.
90  */
91 static inline int test_bit(int nr, const void * addr)
92 {
93     return ((unsigned char *) addr)[nr >> 3] & (1U << (nr & 7));
94 }
95
96 /*
97  * ffz = Find First Zero in word. Undefined if no zero exists,
98  * so code should check against ~0UL first..
99  */
100 static inline unsigned long ffz(unsigned long word)
101 {
102         int k;
103
104         word = ~word;
105         k = 31;
106         if (word & 0x0000ffff) { k -= 16; word <<= 16; }
107         if (word & 0x00ff0000) { k -= 8;  word <<= 8;  }
108         if (word & 0x0f000000) { k -= 4;  word <<= 4;  }
109         if (word & 0x30000000) { k -= 2;  word <<= 2;  }
110         if (word & 0x40000000) { k -= 1; }
111         return k;
112 }
113
114 /*
115  * ffs: find first bit set. This is defined the same way as
116  * the libc and compiler builtin ffs routines, therefore
117  * differs in spirit from the above ffz (man ffs).
118  */
119
120 #define ffs(x) generic_ffs(x)
121
122 /*
123  * hweightN: returns the hamming weight (i.e. the number
124  * of bits set) of a N-bit word
125  */
126
127 #define hweight32(x) generic_hweight32(x)
128 #define hweight16(x) generic_hweight16(x)
129 #define hweight8(x) generic_hweight8(x)
130
131 #define ext2_set_bit                    test_and_set_bit
132 #define ext2_clear_bit                  test_and_clear_bit
133 #define ext2_test_bit                   test_bit
134 #define ext2_find_first_zero_bit        find_first_zero_bit
135 #define ext2_find_next_zero_bit         find_next_zero_bit
136
137 /* Bitmap functions for the minix filesystem. */
138 #define minix_test_and_set_bit(nr,addr) test_and_set_bit(nr,addr)
139 #define minix_set_bit(nr,addr)          set_bit(nr,addr)
140 #define minix_test_and_clear_bit(nr,addr)       test_and_clear_bit(nr,addr)
141 #define minix_test_bit(nr,addr)         test_bit(nr,addr)
142 #define minix_find_first_zero_bit(addr,size)    find_first_zero_bit(addr,size)
143
144 #endif /* __KERNEL__ */
145
146 #endif /* _ARM_BITOPS_H */