2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Copyright 1995, Russell King.
|
|
|
|
* Various bits and pieces copyrights include:
|
|
|
|
* Linus Torvalds (test_bit).
|
|
|
|
* Big endian support: Copyright 2001, Nicolas Pitre
|
|
|
|
* reworked by rmk.
|
|
|
|
*
|
|
|
|
* bit 0 is the LSB of an "unsigned long" quantity.
|
|
|
|
*
|
|
|
|
* Please note that the code in this file should never be included
|
|
|
|
* from user space. Many of these are not implemented in assembler
|
|
|
|
* since they would be too costly. Also, they require privileged
|
|
|
|
* instructions (which are not available from user mode) to ensure
|
|
|
|
* that they are atomic.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __ASM_ARM_BITOPS_H
|
|
|
|
#define __ASM_ARM_BITOPS_H
|
|
|
|
|
|
|
|
#ifdef __KERNEL__
|
|
|
|
|
2007-10-19 06:40:26 +00:00
|
|
|
#ifndef _LINUX_BITOPS_H
|
|
|
|
#error only <linux/bitops.h> can be included directly
|
|
|
|
#endif
|
|
|
|
|
2005-11-16 17:23:57 +00:00
|
|
|
#include <linux/compiler.h>
|
2012-03-28 17:30:01 +00:00
|
|
|
#include <linux/irqflags.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2011-07-19 12:26:54 +00:00
|
|
|
#define smp_mb__before_clear_bit() smp_mb()
|
|
|
|
#define smp_mb__after_clear_bit() smp_mb()
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* These functions are the basis of our bit ops.
|
|
|
|
*
|
|
|
|
* First, the atomic bitops. These use native endian.
|
|
|
|
*/
|
|
|
|
static inline void ____atomic_set_bit(unsigned int bit, volatile unsigned long *p)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
unsigned long mask = 1UL << (bit & 31);
|
|
|
|
|
|
|
|
p += bit >> 5;
|
|
|
|
|
2006-09-21 02:35:20 +00:00
|
|
|
raw_local_irq_save(flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
*p |= mask;
|
2006-09-21 02:35:20 +00:00
|
|
|
raw_local_irq_restore(flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void ____atomic_clear_bit(unsigned int bit, volatile unsigned long *p)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
unsigned long mask = 1UL << (bit & 31);
|
|
|
|
|
|
|
|
p += bit >> 5;
|
|
|
|
|
2006-09-21 02:35:20 +00:00
|
|
|
raw_local_irq_save(flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
*p &= ~mask;
|
2006-09-21 02:35:20 +00:00
|
|
|
raw_local_irq_restore(flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void ____atomic_change_bit(unsigned int bit, volatile unsigned long *p)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
unsigned long mask = 1UL << (bit & 31);
|
|
|
|
|
|
|
|
p += bit >> 5;
|
|
|
|
|
2006-09-21 02:35:20 +00:00
|
|
|
raw_local_irq_save(flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
*p ^= mask;
|
2006-09-21 02:35:20 +00:00
|
|
|
raw_local_irq_restore(flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
____atomic_test_and_set_bit(unsigned int bit, volatile unsigned long *p)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
unsigned int res;
|
|
|
|
unsigned long mask = 1UL << (bit & 31);
|
|
|
|
|
|
|
|
p += bit >> 5;
|
|
|
|
|
2006-09-21 02:35:20 +00:00
|
|
|
raw_local_irq_save(flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
res = *p;
|
|
|
|
*p = res | mask;
|
2006-09-21 02:35:20 +00:00
|
|
|
raw_local_irq_restore(flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2009-07-21 15:08:28 +00:00
|
|
|
return (res & mask) != 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
____atomic_test_and_clear_bit(unsigned int bit, volatile unsigned long *p)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
unsigned int res;
|
|
|
|
unsigned long mask = 1UL << (bit & 31);
|
|
|
|
|
|
|
|
p += bit >> 5;
|
|
|
|
|
2006-09-21 02:35:20 +00:00
|
|
|
raw_local_irq_save(flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
res = *p;
|
|
|
|
*p = res & ~mask;
|
2006-09-21 02:35:20 +00:00
|
|
|
raw_local_irq_restore(flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2009-07-21 15:08:28 +00:00
|
|
|
return (res & mask) != 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
____atomic_test_and_change_bit(unsigned int bit, volatile unsigned long *p)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
unsigned int res;
|
|
|
|
unsigned long mask = 1UL << (bit & 31);
|
|
|
|
|
|
|
|
p += bit >> 5;
|
|
|
|
|
2006-09-21 02:35:20 +00:00
|
|
|
raw_local_irq_save(flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
res = *p;
|
|
|
|
*p = res ^ mask;
|
2006-09-21 02:35:20 +00:00
|
|
|
raw_local_irq_restore(flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2009-07-21 15:08:28 +00:00
|
|
|
return (res & mask) != 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2006-03-26 09:39:19 +00:00
|
|
|
#include <asm-generic/bitops/non-atomic.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* A note about Endian-ness.
|
|
|
|
* -------------------------
|
|
|
|
*
|
|
|
|
* When the ARM is put into big endian mode via CR15, the processor
|
|
|
|
* merely swaps the order of bytes within words, thus:
|
|
|
|
*
|
|
|
|
* ------------ physical data bus bits -----------
|
|
|
|
* D31 ... D24 D23 ... D16 D15 ... D8 D7 ... D0
|
|
|
|
* little byte 3 byte 2 byte 1 byte 0
|
|
|
|
* big byte 0 byte 1 byte 2 byte 3
|
|
|
|
*
|
|
|
|
* This means that reading a 32-bit word at address 0 returns the same
|
|
|
|
* value irrespective of the endian mode bit.
|
|
|
|
*
|
|
|
|
* Peripheral devices should be connected with the data bus reversed in
|
|
|
|
* "Big Endian" mode. ARM Application Note 61 is applicable, and is
|
|
|
|
* available from http://www.arm.com/.
|
|
|
|
*
|
|
|
|
* The following assumes that the data bus connectivity for big endian
|
|
|
|
* mode has been followed.
|
|
|
|
*
|
|
|
|
* Note that bit 0 is defined to be 32-bit word bit 0, not byte 0 bit 0.
|
|
|
|
*/
|
|
|
|
|
2011-01-16 18:02:17 +00:00
|
|
|
/*
|
|
|
|
* Native endian assembly bitops. nr = 0 -> word 0 bit 0.
|
|
|
|
*/
|
|
|
|
extern void _set_bit(int nr, volatile unsigned long * p);
|
|
|
|
extern void _clear_bit(int nr, volatile unsigned long * p);
|
|
|
|
extern void _change_bit(int nr, volatile unsigned long * p);
|
|
|
|
extern int _test_and_set_bit(int nr, volatile unsigned long * p);
|
|
|
|
extern int _test_and_clear_bit(int nr, volatile unsigned long * p);
|
|
|
|
extern int _test_and_change_bit(int nr, volatile unsigned long * p);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Little endian assembly bitops. nr = 0 -> byte 0 bit 0.
|
|
|
|
*/
|
|
|
|
extern int _find_first_zero_bit_le(const void * p, unsigned size);
|
|
|
|
extern int _find_next_zero_bit_le(const void * p, int size, int offset);
|
|
|
|
extern int _find_first_bit_le(const unsigned long *p, unsigned size);
|
|
|
|
extern int _find_next_bit_le(const unsigned long *p, int size, int offset);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Big endian assembly bitops. nr = 0 -> byte 3 bit 0.
|
|
|
|
*/
|
|
|
|
extern int _find_first_zero_bit_be(const void * p, unsigned size);
|
|
|
|
extern int _find_next_zero_bit_be(const void * p, int size, int offset);
|
|
|
|
extern int _find_first_bit_be(const unsigned long *p, unsigned size);
|
|
|
|
extern int _find_next_bit_be(const unsigned long *p, int size, int offset);
|
|
|
|
|
2005-07-28 19:36:26 +00:00
|
|
|
#ifndef CONFIG_SMP
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* The __* form of bitops are non-atomic and may be reordered.
|
|
|
|
*/
|
2011-01-16 18:02:17 +00:00
|
|
|
#define ATOMIC_BITOP(name,nr,p) \
|
|
|
|
(__builtin_constant_p(nr) ? ____atomic_##name(nr, p) : _##name(nr,p))
|
2005-07-28 19:36:26 +00:00
|
|
|
#else
|
2011-01-16 18:02:17 +00:00
|
|
|
#define ATOMIC_BITOP(name,nr,p) _##name(nr,p)
|
2005-07-28 19:36:26 +00:00
|
|
|
#endif
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2011-01-16 18:02:17 +00:00
|
|
|
/*
|
|
|
|
* Native endian atomic definitions.
|
|
|
|
*/
|
|
|
|
#define set_bit(nr,p) ATOMIC_BITOP(set_bit,nr,p)
|
|
|
|
#define clear_bit(nr,p) ATOMIC_BITOP(clear_bit,nr,p)
|
|
|
|
#define change_bit(nr,p) ATOMIC_BITOP(change_bit,nr,p)
|
|
|
|
#define test_and_set_bit(nr,p) ATOMIC_BITOP(test_and_set_bit,nr,p)
|
|
|
|
#define test_and_clear_bit(nr,p) ATOMIC_BITOP(test_and_clear_bit,nr,p)
|
|
|
|
#define test_and_change_bit(nr,p) ATOMIC_BITOP(test_and_change_bit,nr,p)
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#ifndef __ARMEB__
|
|
|
|
/*
|
|
|
|
* These are the little endian, atomic definitions.
|
|
|
|
*/
|
|
|
|
#define find_first_zero_bit(p,sz) _find_first_zero_bit_le(p,sz)
|
|
|
|
#define find_next_zero_bit(p,sz,off) _find_next_zero_bit_le(p,sz,off)
|
|
|
|
#define find_first_bit(p,sz) _find_first_bit_le(p,sz)
|
|
|
|
#define find_next_bit(p,sz,off) _find_next_bit_le(p,sz,off)
|
|
|
|
|
|
|
|
#else
|
|
|
|
/*
|
|
|
|
* These are the big endian, atomic definitions.
|
|
|
|
*/
|
|
|
|
#define find_first_zero_bit(p,sz) _find_first_zero_bit_be(p,sz)
|
|
|
|
#define find_next_zero_bit(p,sz,off) _find_next_zero_bit_be(p,sz,off)
|
|
|
|
#define find_first_bit(p,sz) _find_first_bit_be(p,sz)
|
|
|
|
#define find_next_bit(p,sz,off) _find_next_bit_be(p,sz,off)
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if __LINUX_ARM_ARCH__ < 5
|
|
|
|
|
2006-03-26 09:39:19 +00:00
|
|
|
#include <asm-generic/bitops/ffz.h>
|
2008-12-04 02:59:41 +00:00
|
|
|
#include <asm-generic/bitops/__fls.h>
|
2006-03-26 09:39:19 +00:00
|
|
|
#include <asm-generic/bitops/__ffs.h>
|
|
|
|
#include <asm-generic/bitops/fls.h>
|
|
|
|
#include <asm-generic/bitops/ffs.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
2006-03-26 09:38:59 +00:00
|
|
|
static inline int constant_fls(int x)
|
|
|
|
{
|
|
|
|
int r = 32;
|
|
|
|
|
|
|
|
if (!x)
|
|
|
|
return 0;
|
|
|
|
if (!(x & 0xffff0000u)) {
|
|
|
|
x <<= 16;
|
|
|
|
r -= 16;
|
|
|
|
}
|
|
|
|
if (!(x & 0xff000000u)) {
|
|
|
|
x <<= 8;
|
|
|
|
r -= 8;
|
|
|
|
}
|
|
|
|
if (!(x & 0xf0000000u)) {
|
|
|
|
x <<= 4;
|
|
|
|
r -= 4;
|
|
|
|
}
|
|
|
|
if (!(x & 0xc0000000u)) {
|
|
|
|
x <<= 2;
|
|
|
|
r -= 2;
|
|
|
|
}
|
|
|
|
if (!(x & 0x80000000u)) {
|
|
|
|
x <<= 1;
|
|
|
|
r -= 1;
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* On ARMv5 and above those functions can be implemented around
|
|
|
|
* the clz instruction for much better code efficiency.
|
|
|
|
*/
|
|
|
|
|
2008-07-23 22:35:22 +00:00
|
|
|
static inline int fls(int x)
|
|
|
|
{
|
2008-12-04 02:59:41 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (__builtin_constant_p(x))
|
|
|
|
return constant_fls(x);
|
|
|
|
|
2011-01-12 13:38:52 +00:00
|
|
|
asm("clz\t%0, %1" : "=r" (ret) : "r" (x));
|
2008-12-04 02:59:41 +00:00
|
|
|
ret = 32 - ret;
|
|
|
|
return ret;
|
2008-07-23 22:35:22 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 02:59:41 +00:00
|
|
|
#define __fls(x) (fls(x) - 1)
|
2005-04-16 22:20:36 +00:00
|
|
|
#define ffs(x) ({ unsigned long __t = (x); fls(__t & -__t); })
|
|
|
|
#define __ffs(x) (ffs(x) - 1)
|
|
|
|
#define ffz(x) __ffs( ~(x) )
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2006-03-26 09:39:19 +00:00
|
|
|
#include <asm-generic/bitops/fls64.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-03-26 09:39:19 +00:00
|
|
|
#include <asm-generic/bitops/sched.h>
|
|
|
|
#include <asm-generic/bitops/hweight.h>
|
2007-10-18 10:06:39 +00:00
|
|
|
#include <asm-generic/bitops/lock.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2011-05-26 23:26:11 +00:00
|
|
|
#ifdef __ARMEB__
|
2011-03-23 23:41:57 +00:00
|
|
|
|
|
|
|
static inline int find_first_zero_bit_le(const void *p, unsigned size)
|
|
|
|
{
|
|
|
|
return _find_first_zero_bit_le(p, size);
|
|
|
|
}
|
2011-05-26 23:26:06 +00:00
|
|
|
#define find_first_zero_bit_le find_first_zero_bit_le
|
2011-03-23 23:41:57 +00:00
|
|
|
|
|
|
|
static inline int find_next_zero_bit_le(const void *p, int size, int offset)
|
|
|
|
{
|
|
|
|
return _find_next_zero_bit_le(p, size, offset);
|
|
|
|
}
|
2011-05-26 23:26:06 +00:00
|
|
|
#define find_next_zero_bit_le find_next_zero_bit_le
|
2011-03-23 23:41:57 +00:00
|
|
|
|
|
|
|
static inline int find_next_bit_le(const void *p, int size, int offset)
|
|
|
|
{
|
|
|
|
return _find_next_bit_le(p, size, offset);
|
|
|
|
}
|
2011-05-26 23:26:06 +00:00
|
|
|
#define find_next_bit_le find_next_bit_le
|
2011-03-23 23:41:57 +00:00
|
|
|
|
2011-05-26 23:26:11 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <asm-generic/bitops/le.h>
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Ext2 is defined to use little-endian byte ordering.
|
|
|
|
*/
|
2011-07-26 23:09:04 +00:00
|
|
|
#include <asm-generic/bitops/ext2-atomic-setbit.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#endif /* __KERNEL__ */
|
|
|
|
|
|
|
|
#endif /* _ARM_BITOPS_H */
|