blob: fe257cfec978366bd83dc8da31ff46299fdba6f5 [file] [log] [blame]
Robin Getz96f10502009-09-24 14:11:24 +00001/*
2 * Copyright 2004-2009 Analog Devices Inc.
3 *
4 * Licensed under the GPL-2 or later.
5 */
6
Bryan Wu1394f032007-05-06 14:50:22 -07007#ifndef _BLACKFIN_BITOPS_H
8#define _BLACKFIN_BITOPS_H
9
Michael Hennerich0f7b4682009-12-22 11:32:06 +000010#include <linux/compiler.h>
11
12#include <asm-generic/bitops/__ffs.h>
13#include <asm-generic/bitops/ffz.h>
14#include <asm-generic/bitops/fls.h>
15#include <asm-generic/bitops/__fls.h>
16#include <asm-generic/bitops/fls64.h>
17#include <asm-generic/bitops/find.h>
Bryan Wu1394f032007-05-06 14:50:22 -070018
Jiri Slaby06245172007-10-18 23:40:26 -070019#ifndef _LINUX_BITOPS_H
20#error only <linux/bitops.h> can be included directly
21#endif
22
Bryan Wu1394f032007-05-06 14:50:22 -070023#include <asm-generic/bitops/sched.h>
Michael Hennerich0f7b4682009-12-22 11:32:06 +000024#include <asm-generic/bitops/ffs.h>
Mike Frysinger97e94c32010-08-13 17:42:39 -040025#include <asm-generic/bitops/const_hweight.h>
Michael Hennerich0f7b4682009-12-22 11:32:06 +000026#include <asm-generic/bitops/lock.h>
Mike Frysinger97e94c32010-08-13 17:42:39 -040027
Akinobu Mita861b5ae2011-03-23 16:42:02 -070028#include <asm-generic/bitops/le.h>
Michael Hennerich0f7b4682009-12-22 11:32:06 +000029#include <asm-generic/bitops/ext2-non-atomic.h>
30#include <asm-generic/bitops/ext2-atomic.h>
31#include <asm-generic/bitops/minix.h>
Bryan Wu1394f032007-05-06 14:50:22 -070032
Michael Hennerich0f7b4682009-12-22 11:32:06 +000033#ifndef CONFIG_SMP
34#include <linux/irqflags.h>
35
36/*
37 * clear_bit may not imply a memory barrier
38 */
39#ifndef smp_mb__before_clear_bit
40#define smp_mb__before_clear_bit() smp_mb()
41#define smp_mb__after_clear_bit() smp_mb()
42#endif
43#include <asm-generic/bitops/atomic.h>
44#include <asm-generic/bitops/non-atomic.h>
45#else
46
47#include <asm/byteorder.h> /* swab32 */
Graf Yang6b3087c2009-01-07 23:14:39 +080048#include <linux/linkage.h>
49
50asmlinkage int __raw_bit_set_asm(volatile unsigned long *addr, int nr);
51
52asmlinkage int __raw_bit_clear_asm(volatile unsigned long *addr, int nr);
53
54asmlinkage int __raw_bit_toggle_asm(volatile unsigned long *addr, int nr);
55
56asmlinkage int __raw_bit_test_set_asm(volatile unsigned long *addr, int nr);
57
58asmlinkage int __raw_bit_test_clear_asm(volatile unsigned long *addr, int nr);
59
60asmlinkage int __raw_bit_test_toggle_asm(volatile unsigned long *addr, int nr);
61
62asmlinkage int __raw_bit_test_asm(const volatile unsigned long *addr, int nr);
63
64static inline void set_bit(int nr, volatile unsigned long *addr)
65{
66 volatile unsigned long *a = addr + (nr >> 5);
67 __raw_bit_set_asm(a, nr & 0x1f);
68}
69
70static inline void clear_bit(int nr, volatile unsigned long *addr)
71{
72 volatile unsigned long *a = addr + (nr >> 5);
73 __raw_bit_clear_asm(a, nr & 0x1f);
74}
75
76static inline void change_bit(int nr, volatile unsigned long *addr)
77{
78 volatile unsigned long *a = addr + (nr >> 5);
79 __raw_bit_toggle_asm(a, nr & 0x1f);
80}
81
82static inline int test_bit(int nr, const volatile unsigned long *addr)
83{
84 volatile const unsigned long *a = addr + (nr >> 5);
85 return __raw_bit_test_asm(a, nr & 0x1f) != 0;
86}
87
88static inline int test_and_set_bit(int nr, volatile unsigned long *addr)
89{
90 volatile unsigned long *a = addr + (nr >> 5);
91 return __raw_bit_test_set_asm(a, nr & 0x1f);
92}
93
94static inline int test_and_clear_bit(int nr, volatile unsigned long *addr)
95{
96 volatile unsigned long *a = addr + (nr >> 5);
97 return __raw_bit_test_clear_asm(a, nr & 0x1f);
98}
99
100static inline int test_and_change_bit(int nr, volatile unsigned long *addr)
101{
102 volatile unsigned long *a = addr + (nr >> 5);
103 return __raw_bit_test_toggle_asm(a, nr & 0x1f);
104}
105
Graf Yang6b3087c2009-01-07 23:14:39 +0800106/*
107 * clear_bit() doesn't provide any barrier for the compiler.
108 */
109#define smp_mb__before_clear_bit() barrier()
110#define smp_mb__after_clear_bit() barrier()
111
Mike Frysinger71a516a2009-09-21 11:51:31 +0000112#define test_bit __skip_test_bit
Mike Frysinger3d150632009-06-13 11:21:51 -0400113#include <asm-generic/bitops/non-atomic.h>
Mike Frysinger71a516a2009-09-21 11:51:31 +0000114#undef test_bit
Bryan Wu1394f032007-05-06 14:50:22 -0700115
Mike Frysinger3d150632009-06-13 11:21:51 -0400116#endif /* CONFIG_SMP */
117
Michael Hennerich0f7b4682009-12-22 11:32:06 +0000118/*
119 * hweightN: returns the hamming weight (i.e. the number
120 * of bits set) of a N-bit word
121 */
122
Mike Frysinger97e94c32010-08-13 17:42:39 -0400123static inline unsigned int __arch_hweight32(unsigned int w)
Michael Hennerich0f7b4682009-12-22 11:32:06 +0000124{
125 unsigned int res;
126
Mike Frysingera13265a2010-06-07 12:22:03 +0000127 __asm__ ("%0.l = ONES %1;"
Michael Hennerich0f7b4682009-12-22 11:32:06 +0000128 "%0 = %0.l (Z);"
129 : "=d" (res) : "d" (w));
130 return res;
131}
132
Mike Frysinger97e94c32010-08-13 17:42:39 -0400133static inline unsigned int __arch_hweight64(__u64 w)
Michael Hennerich0f7b4682009-12-22 11:32:06 +0000134{
Mike Frysinger97e94c32010-08-13 17:42:39 -0400135 return __arch_hweight32((unsigned int)(w >> 32)) +
136 __arch_hweight32((unsigned int)w);
Michael Hennerich0f7b4682009-12-22 11:32:06 +0000137}
138
Mike Frysinger97e94c32010-08-13 17:42:39 -0400139static inline unsigned int __arch_hweight16(unsigned int w)
Michael Hennerich0f7b4682009-12-22 11:32:06 +0000140{
Mike Frysinger97e94c32010-08-13 17:42:39 -0400141 return __arch_hweight32(w & 0xffff);
Michael Hennerich0f7b4682009-12-22 11:32:06 +0000142}
143
Mike Frysinger97e94c32010-08-13 17:42:39 -0400144static inline unsigned int __arch_hweight8(unsigned int w)
Michael Hennerich0f7b4682009-12-22 11:32:06 +0000145{
Mike Frysinger97e94c32010-08-13 17:42:39 -0400146 return __arch_hweight32(w & 0xff);
Michael Hennerich0f7b4682009-12-22 11:32:06 +0000147}
148
Bryan Wu1394f032007-05-06 14:50:22 -0700149#endif /* _BLACKFIN_BITOPS_H */