Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef __ASM_SH_BITOPS_H |
| 2 | #define __ASM_SH_BITOPS_H |
| 3 | |
| 4 | #ifdef __KERNEL__ |
| 5 | #include <asm/system.h> |
| 6 | /* For __swab32 */ |
| 7 | #include <asm/byteorder.h> |
| 8 | |
Paul Mundt | e4c2cfe | 2006-09-27 12:31:01 +0900 | [diff] [blame^] | 9 | static inline void set_bit(int nr, volatile void * addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | { |
| 11 | int mask; |
| 12 | volatile unsigned int *a = addr; |
| 13 | unsigned long flags; |
| 14 | |
| 15 | a += nr >> 5; |
| 16 | mask = 1 << (nr & 0x1f); |
| 17 | local_irq_save(flags); |
| 18 | *a |= mask; |
| 19 | local_irq_restore(flags); |
| 20 | } |
| 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | /* |
| 23 | * clear_bit() doesn't provide any barrier for the compiler. |
| 24 | */ |
| 25 | #define smp_mb__before_clear_bit() barrier() |
| 26 | #define smp_mb__after_clear_bit() barrier() |
Paul Mundt | e4c2cfe | 2006-09-27 12:31:01 +0900 | [diff] [blame^] | 27 | static inline void clear_bit(int nr, volatile void * addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | { |
| 29 | int mask; |
| 30 | volatile unsigned int *a = addr; |
| 31 | unsigned long flags; |
| 32 | |
| 33 | a += nr >> 5; |
| 34 | mask = 1 << (nr & 0x1f); |
| 35 | local_irq_save(flags); |
| 36 | *a &= ~mask; |
| 37 | local_irq_restore(flags); |
| 38 | } |
| 39 | |
Paul Mundt | e4c2cfe | 2006-09-27 12:31:01 +0900 | [diff] [blame^] | 40 | static inline void change_bit(int nr, volatile void * addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | { |
| 42 | int mask; |
| 43 | volatile unsigned int *a = addr; |
| 44 | unsigned long flags; |
| 45 | |
| 46 | a += nr >> 5; |
| 47 | mask = 1 << (nr & 0x1f); |
| 48 | local_irq_save(flags); |
| 49 | *a ^= mask; |
| 50 | local_irq_restore(flags); |
| 51 | } |
| 52 | |
Paul Mundt | e4c2cfe | 2006-09-27 12:31:01 +0900 | [diff] [blame^] | 53 | static inline int test_and_set_bit(int nr, volatile void * addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | { |
| 55 | int mask, retval; |
| 56 | volatile unsigned int *a = addr; |
| 57 | unsigned long flags; |
| 58 | |
| 59 | a += nr >> 5; |
| 60 | mask = 1 << (nr & 0x1f); |
| 61 | local_irq_save(flags); |
| 62 | retval = (mask & *a) != 0; |
| 63 | *a |= mask; |
| 64 | local_irq_restore(flags); |
| 65 | |
| 66 | return retval; |
| 67 | } |
| 68 | |
Paul Mundt | e4c2cfe | 2006-09-27 12:31:01 +0900 | [diff] [blame^] | 69 | static inline int test_and_clear_bit(int nr, volatile void * addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | { |
| 71 | int mask, retval; |
| 72 | volatile unsigned int *a = addr; |
| 73 | unsigned long flags; |
| 74 | |
| 75 | a += nr >> 5; |
| 76 | mask = 1 << (nr & 0x1f); |
| 77 | local_irq_save(flags); |
| 78 | retval = (mask & *a) != 0; |
| 79 | *a &= ~mask; |
| 80 | local_irq_restore(flags); |
| 81 | |
| 82 | return retval; |
| 83 | } |
| 84 | |
Paul Mundt | e4c2cfe | 2006-09-27 12:31:01 +0900 | [diff] [blame^] | 85 | static inline int test_and_change_bit(int nr, volatile void * addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | { |
| 87 | int mask, retval; |
| 88 | volatile unsigned int *a = addr; |
| 89 | unsigned long flags; |
| 90 | |
| 91 | a += nr >> 5; |
| 92 | mask = 1 << (nr & 0x1f); |
| 93 | local_irq_save(flags); |
| 94 | retval = (mask & *a) != 0; |
| 95 | *a ^= mask; |
| 96 | local_irq_restore(flags); |
| 97 | |
| 98 | return retval; |
| 99 | } |
| 100 | |
Akinobu Mita | e2268c7 | 2006-03-26 01:39:35 -0800 | [diff] [blame] | 101 | #include <asm-generic/bitops/non-atomic.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | |
Paul Mundt | e4c2cfe | 2006-09-27 12:31:01 +0900 | [diff] [blame^] | 103 | static inline unsigned long ffz(unsigned long word) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | { |
| 105 | unsigned long result; |
| 106 | |
| 107 | __asm__("1:\n\t" |
| 108 | "shlr %1\n\t" |
| 109 | "bt/s 1b\n\t" |
| 110 | " add #1, %0" |
| 111 | : "=r" (result), "=r" (word) |
| 112 | : "0" (~0L), "1" (word) |
| 113 | : "t"); |
| 114 | return result; |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * __ffs - find first bit in word. |
| 119 | * @word: The word to search |
| 120 | * |
| 121 | * Undefined if no bit exists, so code should check against 0 first. |
| 122 | */ |
Paul Mundt | e4c2cfe | 2006-09-27 12:31:01 +0900 | [diff] [blame^] | 123 | static inline unsigned long __ffs(unsigned long word) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | { |
| 125 | unsigned long result; |
| 126 | |
| 127 | __asm__("1:\n\t" |
| 128 | "shlr %1\n\t" |
| 129 | "bf/s 1b\n\t" |
| 130 | " add #1, %0" |
| 131 | : "=r" (result), "=r" (word) |
| 132 | : "0" (~0L), "1" (word) |
| 133 | : "t"); |
| 134 | return result; |
| 135 | } |
| 136 | |
Akinobu Mita | e2268c7 | 2006-03-26 01:39:35 -0800 | [diff] [blame] | 137 | #include <asm-generic/bitops/find.h> |
| 138 | #include <asm-generic/bitops/ffs.h> |
| 139 | #include <asm-generic/bitops/hweight.h> |
| 140 | #include <asm-generic/bitops/sched.h> |
| 141 | #include <asm-generic/bitops/ext2-non-atomic.h> |
| 142 | #include <asm-generic/bitops/ext2-atomic.h> |
| 143 | #include <asm-generic/bitops/minix.h> |
| 144 | #include <asm-generic/bitops/fls.h> |
| 145 | #include <asm-generic/bitops/fls64.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | |
| 147 | #endif /* __KERNEL__ */ |
| 148 | |
| 149 | #endif /* __ASM_SH_BITOPS_H */ |