1 /* SPDX-License-Identifier: GPL-2.0-only */ 1 2 3 #ifndef __ASM_GENERIC_BITOPS_GENERIC_NON_ATOMI 4 #define __ASM_GENERIC_BITOPS_GENERIC_NON_ATOMI 5 6 #include <linux/bits.h> 7 #include <asm/barrier.h> 8 9 #ifndef _LINUX_BITOPS_H 10 #error only <linux/bitops.h> can be included d 11 #endif 12 13 /* 14 * Generic definitions for bit operations, sho 15 * directly. 16 */ 17 18 /** 19 * generic___set_bit - Set a bit in memory 20 * @nr: the bit to set 21 * @addr: the address to start counting from 22 * 23 * Unlike set_bit(), this function is non-atom 24 * If it's called on the same region of memory 25 * may be that only one operation succeeds. 26 */ 27 static __always_inline void 28 generic___set_bit(unsigned long nr, volatile u 29 { 30 unsigned long mask = BIT_MASK(nr); 31 unsigned long *p = ((unsigned long *)a 32 33 *p |= mask; 34 } 35 36 static __always_inline void 37 generic___clear_bit(unsigned long nr, volatile 38 { 39 unsigned long mask = BIT_MASK(nr); 40 unsigned long *p = ((unsigned long *)a 41 42 *p &= ~mask; 43 } 44 45 /** 46 * generic___change_bit - Toggle a bit in memo 47 * @nr: the bit to change 48 * @addr: the address to start counting from 49 * 50 * Unlike change_bit(), this function is non-a 51 * If it's called on the same region of memory 52 * may be that only one operation succeeds. 53 */ 54 static __always_inline void 55 generic___change_bit(unsigned long nr, volatil 56 { 57 unsigned long mask = BIT_MASK(nr); 58 unsigned long *p = ((unsigned long *)a 59 60 *p ^= mask; 61 } 62 63 /** 64 * generic___test_and_set_bit - Set a bit and 65 * @nr: Bit to set 66 * @addr: Address to count from 67 * 68 * This operation is non-atomic and can be reo 69 * If two examples of this operation race, one 70 * but actually fail. You must protect multip 71 */ 72 static __always_inline bool 73 generic___test_and_set_bit(unsigned long nr, v 74 { 75 unsigned long mask = BIT_MASK(nr); 76 unsigned long *p = ((unsigned long *)a 77 unsigned long old = *p; 78 79 *p = old | mask; 80 return (old & mask) != 0; 81 } 82 83 /** 84 * generic___test_and_clear_bit - Clear a bit 85 * @nr: Bit to clear 86 * @addr: Address to count from 87 * 88 * This operation is non-atomic and can be reo 89 * If two examples of this operation race, one 90 * but actually fail. You must protect multip 91 */ 92 static __always_inline bool 93 generic___test_and_clear_bit(unsigned long nr, 94 { 95 unsigned long mask = BIT_MASK(nr); 96 unsigned long *p = ((unsigned long *)a 97 unsigned long old = *p; 98 99 *p = old & ~mask; 100 return (old & mask) != 0; 101 } 102 103 /* WARNING: non atomic and it can be reordered 104 static __always_inline bool 105 generic___test_and_change_bit(unsigned long nr 106 { 107 unsigned long mask = BIT_MASK(nr); 108 unsigned long *p = ((unsigned long *)a 109 unsigned long old = *p; 110 111 *p = old ^ mask; 112 return (old & mask) != 0; 113 } 114 115 /** 116 * generic_test_bit - Determine whether a bit 117 * @nr: bit number to test 118 * @addr: Address to start counting from 119 */ 120 static __always_inline bool 121 generic_test_bit(unsigned long nr, const volat 122 { 123 /* 124 * Unlike the bitops with the '__' pre 125 * so `volatile` must always stay here 126 * `Documentation/atomic_bitops.txt` f 127 */ 128 return 1UL & (addr[BIT_WORD(nr)] >> (n 129 } 130 131 /** 132 * generic_test_bit_acquire - Determine, with 133 * @nr: bit number to test 134 * @addr: Address to start counting from 135 */ 136 static __always_inline bool 137 generic_test_bit_acquire(unsigned long nr, con 138 { 139 unsigned long *p = ((unsigned long *)a 140 return 1UL & (smp_load_acquire(p) >> ( 141 } 142 143 /* 144 * const_*() definitions provide good compile- 145 * the passed arguments can be resolved at com 146 */ 147 #define const___set_bit generi 148 #define const___clear_bit generi 149 #define const___change_bit generi 150 #define const___test_and_set_bit generi 151 #define const___test_and_clear_bit generi 152 #define const___test_and_change_bit generi 153 #define const_test_bit_acquire generi 154 155 /** 156 * const_test_bit - Determine whether a bit is 157 * @nr: bit number to test 158 * @addr: Address to start counting from 159 * 160 * A version of generic_test_bit() which disca 161 * allow a compiler to optimize code harder. N 162 * for testing compile-time constants, e.g. by 163 * directly from "regular" code. 164 */ 165 static __always_inline bool 166 const_test_bit(unsigned long nr, const volatil 167 { 168 const unsigned long *p = (const unsign 169 unsigned long mask = BIT_MASK(nr); 170 unsigned long val = *p; 171 172 return !!(val & mask); 173 } 174 175 #endif /* __ASM_GENERIC_BITOPS_GENERIC_NON_ATO 176
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.