1a439fe51SSam Ravnborg /* 2a439fe51SSam Ravnborg * bitops.h: Bit string operations on the Sparc. 3a439fe51SSam Ravnborg * 4a439fe51SSam Ravnborg * Copyright 1995 David S. Miller (davem@caip.rutgers.edu) 5a439fe51SSam Ravnborg * Copyright 1996 Eddie C. Dost (ecd@skynet.be) 6a439fe51SSam Ravnborg * Copyright 2001 Anton Blanchard (anton@samba.org) 7a439fe51SSam Ravnborg */ 8a439fe51SSam Ravnborg 9a439fe51SSam Ravnborg #ifndef _SPARC_BITOPS_H 10a439fe51SSam Ravnborg #define _SPARC_BITOPS_H 11a439fe51SSam Ravnborg 12a439fe51SSam Ravnborg #include <linux/compiler.h> 13a439fe51SSam Ravnborg #include <asm/byteorder.h> 14a439fe51SSam Ravnborg 15a439fe51SSam Ravnborg #ifdef __KERNEL__ 16a439fe51SSam Ravnborg 17a439fe51SSam Ravnborg #ifndef _LINUX_BITOPS_H 18a439fe51SSam Ravnborg #error only <linux/bitops.h> can be included directly 19a439fe51SSam Ravnborg #endif 20a439fe51SSam Ravnborg 21a439fe51SSam Ravnborg extern unsigned long ___set_bit(unsigned long *addr, unsigned long mask); 22a439fe51SSam Ravnborg extern unsigned long ___clear_bit(unsigned long *addr, unsigned long mask); 23a439fe51SSam Ravnborg extern unsigned long ___change_bit(unsigned long *addr, unsigned long mask); 24a439fe51SSam Ravnborg 25a439fe51SSam Ravnborg /* 26a439fe51SSam Ravnborg * Set bit 'nr' in 32-bit quantity at address 'addr' where bit '0' 27a439fe51SSam Ravnborg * is in the highest of the four bytes and bit '31' is the high bit 28a439fe51SSam Ravnborg * within the first byte. Sparc is BIG-Endian. Unless noted otherwise 29a439fe51SSam Ravnborg * all bit-ops return 0 if bit was previously clear and != 0 otherwise. 30a439fe51SSam Ravnborg */ 31a439fe51SSam Ravnborg static inline int test_and_set_bit(unsigned long nr, volatile unsigned long *addr) 32a439fe51SSam Ravnborg { 33a439fe51SSam Ravnborg unsigned long *ADDR, mask; 34a439fe51SSam Ravnborg 35a439fe51SSam Ravnborg ADDR = ((unsigned long *) addr) + (nr >> 5); 36a439fe51SSam Ravnborg mask = 1 << (nr & 31); 37a439fe51SSam Ravnborg 38a439fe51SSam Ravnborg return ___set_bit(ADDR, mask) != 0; 39a439fe51SSam Ravnborg } 40a439fe51SSam Ravnborg 41a439fe51SSam Ravnborg static inline void set_bit(unsigned long nr, volatile unsigned long *addr) 42a439fe51SSam Ravnborg { 43a439fe51SSam Ravnborg unsigned long *ADDR, mask; 44a439fe51SSam Ravnborg 45a439fe51SSam Ravnborg ADDR = ((unsigned long *) addr) + (nr >> 5); 46a439fe51SSam Ravnborg mask = 1 << (nr & 31); 47a439fe51SSam Ravnborg 48a439fe51SSam Ravnborg (void) ___set_bit(ADDR, mask); 49a439fe51SSam Ravnborg } 50a439fe51SSam Ravnborg 51a439fe51SSam Ravnborg static inline int test_and_clear_bit(unsigned long nr, volatile unsigned long *addr) 52a439fe51SSam Ravnborg { 53a439fe51SSam Ravnborg unsigned long *ADDR, mask; 54a439fe51SSam Ravnborg 55a439fe51SSam Ravnborg ADDR = ((unsigned long *) addr) + (nr >> 5); 56a439fe51SSam Ravnborg mask = 1 << (nr & 31); 57a439fe51SSam Ravnborg 58a439fe51SSam Ravnborg return ___clear_bit(ADDR, mask) != 0; 59a439fe51SSam Ravnborg } 60a439fe51SSam Ravnborg 61a439fe51SSam Ravnborg static inline void clear_bit(unsigned long nr, volatile unsigned long *addr) 62a439fe51SSam Ravnborg { 63a439fe51SSam Ravnborg unsigned long *ADDR, mask; 64a439fe51SSam Ravnborg 65a439fe51SSam Ravnborg ADDR = ((unsigned long *) addr) + (nr >> 5); 66a439fe51SSam Ravnborg mask = 1 << (nr & 31); 67a439fe51SSam Ravnborg 68a439fe51SSam Ravnborg (void) ___clear_bit(ADDR, mask); 69a439fe51SSam Ravnborg } 70a439fe51SSam Ravnborg 71a439fe51SSam Ravnborg static inline int test_and_change_bit(unsigned long nr, volatile unsigned long *addr) 72a439fe51SSam Ravnborg { 73a439fe51SSam Ravnborg unsigned long *ADDR, mask; 74a439fe51SSam Ravnborg 75a439fe51SSam Ravnborg ADDR = ((unsigned long *) addr) + (nr >> 5); 76a439fe51SSam Ravnborg mask = 1 << (nr & 31); 77a439fe51SSam Ravnborg 78a439fe51SSam Ravnborg return ___change_bit(ADDR, mask) != 0; 79a439fe51SSam Ravnborg } 80a439fe51SSam Ravnborg 81a439fe51SSam Ravnborg static inline void change_bit(unsigned long nr, volatile unsigned long *addr) 82a439fe51SSam Ravnborg { 83a439fe51SSam Ravnborg unsigned long *ADDR, mask; 84a439fe51SSam Ravnborg 85a439fe51SSam Ravnborg ADDR = ((unsigned long *) addr) + (nr >> 5); 86a439fe51SSam Ravnborg mask = 1 << (nr & 31); 87a439fe51SSam Ravnborg 88a439fe51SSam Ravnborg (void) ___change_bit(ADDR, mask); 89a439fe51SSam Ravnborg } 90a439fe51SSam Ravnborg 91a439fe51SSam Ravnborg #include <asm-generic/bitops/non-atomic.h> 92a439fe51SSam Ravnborg 93a439fe51SSam Ravnborg #define smp_mb__before_clear_bit() do { } while(0) 94a439fe51SSam Ravnborg #define smp_mb__after_clear_bit() do { } while(0) 95a439fe51SSam Ravnborg 96a439fe51SSam Ravnborg #include <asm-generic/bitops/ffz.h> 97a439fe51SSam Ravnborg #include <asm-generic/bitops/__ffs.h> 98a439fe51SSam Ravnborg #include <asm-generic/bitops/sched.h> 99a439fe51SSam Ravnborg #include <asm-generic/bitops/ffs.h> 100a439fe51SSam Ravnborg #include <asm-generic/bitops/fls.h> 101*e8e8e80eSRusty Russell #include <asm-generic/bitops/__fls.h> 102a439fe51SSam Ravnborg #include <asm-generic/bitops/fls64.h> 103a439fe51SSam Ravnborg #include <asm-generic/bitops/hweight.h> 104a439fe51SSam Ravnborg #include <asm-generic/bitops/lock.h> 105a439fe51SSam Ravnborg #include <asm-generic/bitops/find.h> 106a439fe51SSam Ravnborg #include <asm-generic/bitops/ext2-non-atomic.h> 107a439fe51SSam Ravnborg #include <asm-generic/bitops/ext2-atomic.h> 108a439fe51SSam Ravnborg #include <asm-generic/bitops/minix.h> 109a439fe51SSam Ravnborg 110a439fe51SSam Ravnborg #endif /* __KERNEL__ */ 111a439fe51SSam Ravnborg 112a439fe51SSam Ravnborg #endif /* defined(_SPARC_BITOPS_H) */ 113