wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 1 | /* |
| 2 | * bitops.h: Bit string operations on the m68k |
| 3 | */ |
| 4 | |
| 5 | #ifndef _M68K_BITOPS_H |
| 6 | #define _M68K_BITOPS_H |
| 7 | |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 8 | #include <asm/byteorder.h> |
Fabio Estevam | c38be38 | 2015-11-05 12:43:26 -0200 | [diff] [blame] | 9 | #include <asm-generic/bitops/fls.h> |
| 10 | #include <asm-generic/bitops/__fls.h> |
| 11 | #include <asm-generic/bitops/fls64.h> |
| 12 | #include <asm-generic/bitops/__ffs.h> |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 13 | |
| 14 | extern void set_bit(int nr, volatile void *addr); |
| 15 | extern void clear_bit(int nr, volatile void *addr); |
| 16 | extern void change_bit(int nr, volatile void *addr); |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 17 | extern int test_and_clear_bit(int nr, volatile void *addr); |
| 18 | extern int test_and_change_bit(int nr, volatile void *addr); |
| 19 | |
TsiChungLiew | ec8468f | 2007-08-05 04:31:18 -0500 | [diff] [blame] | 20 | #ifdef __KERNEL__ |
| 21 | |
Alison Wang | fd54d53 | 2012-03-25 19:18:49 +0000 | [diff] [blame] | 22 | |
Måns Rullgård | 4dc3970 | 2015-11-06 12:44:01 +0000 | [diff] [blame] | 23 | static inline int test_bit(int nr, __const__ volatile void *addr) |
TsiChungLiew | ec8468f | 2007-08-05 04:31:18 -0500 | [diff] [blame] | 24 | { |
Alison Wang | fd54d53 | 2012-03-25 19:18:49 +0000 | [diff] [blame] | 25 | __const__ unsigned int *p = (__const__ unsigned int *) addr; |
TsiChungLiew | ec8468f | 2007-08-05 04:31:18 -0500 | [diff] [blame] | 26 | |
Alison Wang | fd54d53 | 2012-03-25 19:18:49 +0000 | [diff] [blame] | 27 | return (p[nr >> 5] & (1UL << (nr & 31))) != 0; |
TsiChungLiew | ec8468f | 2007-08-05 04:31:18 -0500 | [diff] [blame] | 28 | } |
Alison Wang | fd54d53 | 2012-03-25 19:18:49 +0000 | [diff] [blame] | 29 | |
Måns Rullgård | 4dc3970 | 2015-11-06 12:44:01 +0000 | [diff] [blame] | 30 | static inline int test_and_set_bit(int nr, volatile void *vaddr) |
Alison Wang | fd54d53 | 2012-03-25 19:18:49 +0000 | [diff] [blame] | 31 | { |
| 32 | char retval; |
| 33 | |
| 34 | volatile char *p = &((volatile char *)vaddr)[(nr^31) >> 3]; |
| 35 | __asm__ __volatile__ ("bset %2,(%4); sne %0" |
| 36 | : "=d" (retval), "=m" (*p) |
| 37 | : "di" (nr & 7), "m" (*p), "a" (p)); |
| 38 | |
| 39 | return retval; |
| 40 | } |
| 41 | |
TsiChungLiew | ec8468f | 2007-08-05 04:31:18 -0500 | [diff] [blame] | 42 | #define __ffs(x) (ffs(x) - 1) |
Alison Wang | fd54d53 | 2012-03-25 19:18:49 +0000 | [diff] [blame] | 43 | |
| 44 | /* |
| 45 | * * hweightN: returns the hamming weight (i.e. the number |
| 46 | * * of bits set) of a N-bit word |
| 47 | * */ |
| 48 | |
| 49 | #define hweight32(x) generic_hweight32(x) |
| 50 | #define hweight16(x) generic_hweight16(x) |
| 51 | #define hweight8(x) generic_hweight8(x) |
TsiChungLiew | ec8468f | 2007-08-05 04:31:18 -0500 | [diff] [blame] | 52 | |
| 53 | #endif /* __KERNEL__ */ |
| 54 | |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 55 | #endif /* _M68K_BITOPS_H */ |