1 /* 2 * Copyright 1995, Russell King. 3 * Various bits and pieces copyrights include: 4 * Linus Torvalds (test_bit). 5 * Big endian support: Copyright 2001, Nicolas Pitre 6 * reworked by rmk. 7 */ 8 9 #ifndef _ARM_BITOPS_H 10 #define _ARM_BITOPS_H 11 12 #include <xen/macros.h> 13 14 #include <asm/asm_defns.h> 15 16 /* 17 * Non-atomic bit manipulation. 18 * 19 * Implemented using atomics to be interrupt safe. Could alternatively 20 * implement with local interrupt masking. 21 */ 22 #define __set_bit(n,p) set_bit(n,p) 23 #define __clear_bit(n,p) clear_bit(n,p) 24 25 #define ADDR (*(volatile int *) addr) 26 #define CONST_ADDR (*(const volatile int *) addr) 27 28 #if defined(CONFIG_ARM_32) 29 # include <asm/arm32/bitops.h> 30 #elif defined(CONFIG_ARM_64) 31 # include <asm/arm64/bitops.h> 32 #else 33 # error "unknown ARM variant" 34 #endif 35 36 /* 37 * Atomic bitops 38 * 39 * The helpers below *should* only be used on memory shared between 40 * trusted threads or we know the memory cannot be accessed by another 41 * thread. 42 */ 43 44 void set_bit(int nr, volatile void *p); 45 void clear_bit(int nr, volatile void *p); 46 void change_bit(int nr, volatile void *p); 47 int test_and_set_bit(int nr, volatile void *p); 48 int test_and_clear_bit(int nr, volatile void *p); 49 int test_and_change_bit(int nr, volatile void *p); 50 51 void clear_mask16(uint16_t mask, volatile void *p); 52 53 /* 54 * The helpers below may fail to update the memory if the action takes 55 * too long. 56 * 57 * @max_try: Maximum number of iterations 58 * 59 * The helpers will return true when the update has succeeded (i.e no 60 * timeout) and false if the update has failed. 61 */ 62 bool set_bit_timeout(int nr, volatile void *p, unsigned int max_try); 63 bool clear_bit_timeout(int nr, volatile void *p, unsigned int max_try); 64 bool change_bit_timeout(int nr, volatile void *p, unsigned int max_try); 65 bool test_and_set_bit_timeout(int nr, volatile void *p, 66 int *oldbit, unsigned int max_try); 67 bool test_and_clear_bit_timeout(int nr, volatile void *p, 68 int *oldbit, unsigned int max_try); 69 bool test_and_change_bit_timeout(int nr, volatile void *p, 70 int *oldbit, unsigned int max_try); 71 bool clear_mask16_timeout(uint16_t mask, volatile void *p, 72 unsigned int max_try); 73 74 #define arch_ffs(x) ((x) ? 1 + __builtin_ctz(x) : 0) 75 #define arch_ffsl(x) ((x) ? 1 + __builtin_ctzl(x) : 0) 76 #define arch_fls(x) ((x) ? BITS_PER_INT - __builtin_clz(x) : 0) 77 #define arch_flsl(x) ((x) ? BITS_PER_LONG - __builtin_clzl(x) : 0) 78 79 #endif /* _ARM_BITOPS_H */ 80 /* 81 * Local variables: 82 * mode: C 83 * c-file-style: "BSD" 84 * c-basic-offset: 4 85 * indent-tabs-mode: nil 86 * End: 87 */ 88