123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- #ifndef _BITS_BITOPS_H
- #define _BITS_BITOPS_H
-
-
-
- FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
-
- #include <stdint.h>
-
-
- static inline __attribute__ (( always_inline )) int
- test_and_set_bit ( unsigned int bit, volatile void *bits ) {
- unsigned int index = ( bit / 32 );
- unsigned int offset = ( bit % 32 );
- volatile uint32_t *dword = ( ( ( volatile uint32_t * ) bits ) + index );
- uint32_t mask = ( 1UL << offset );
- uint32_t old;
- uint32_t new;
- uint32_t flag;
-
- __asm__ __volatile__ ( "\n1:\n\t"
- "ldrex %0, %3\n\t"
- "orr %1, %0, %4\n\t"
- "strex %2, %1, %3\n\t"
- "tst %2, %2\n\t"
- "bne 1b\n\t"
- : "=&r" ( old ), "=&r" ( new ), "=&l" ( flag ),
- "+Q" ( *dword )
- : "r" ( mask )
- : "cc" );
-
- return ( old & mask );
- }
-
-
- static inline __attribute__ (( always_inline )) int
- test_and_clear_bit ( unsigned int bit, volatile void *bits ) {
- unsigned int index = ( bit / 32 );
- unsigned int offset = ( bit % 32 );
- volatile uint32_t *dword = ( ( ( volatile uint32_t * ) bits ) + index );
- uint32_t mask = ( 1UL << offset );
- uint32_t old;
- uint32_t new;
- uint32_t flag;
-
- __asm__ __volatile__ ( "\n1:\n\t"
- "ldrex %0, %3\n\t"
- "bic %1, %0, %4\n\t"
- "strex %2, %1, %3\n\t"
- "tst %2, %2\n\t"
- "bne 1b\n\t"
- : "=&r" ( old ), "=&r" ( new ), "=&l" ( flag ),
- "+Q" ( *dword )
- : "r" ( mask )
- : "cc" );
-
- return ( old & mask );
- }
-
-
- static inline __attribute__ (( always_inline )) void
- set_bit ( unsigned int bit, volatile void *bits ) {
-
- test_and_set_bit ( bit, bits );
- }
-
-
- static inline __attribute__ (( always_inline )) void
- clear_bit ( unsigned int bit, volatile void *bits ) {
-
- test_and_clear_bit ( bit, bits );
- }
-
- #endif
|