blob: 605ba8e9b2e4f879a9c0dcfd24267e8e46d648c3 [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>
25#include <asm-generic/bitops/lock.h>
26#include <asm-generic/bitops/ext2-non-atomic.h>
27#include <asm-generic/bitops/ext2-atomic.h>
28#include <asm-generic/bitops/minix.h>
Bryan Wu1394f032007-05-06 14:50:22 -070029
Michael Hennerich0f7b4682009-12-22 11:32:06 +000030#ifndef CONFIG_SMP
31#include <linux/irqflags.h>
32
33/*
34 * clear_bit may not imply a memory barrier
35 */
36#ifndef smp_mb__before_clear_bit
37#define smp_mb__before_clear_bit() smp_mb()
38#define smp_mb__after_clear_bit() smp_mb()
39#endif
40#include <asm-generic/bitops/atomic.h>
41#include <asm-generic/bitops/non-atomic.h>
42#else
43
44#include <asm/byteorder.h> /* swab32 */
Graf Yang6b3087c2009-01-07 23:14:39 +080045#include <linux/linkage.h>
46
47asmlinkage int __raw_bit_set_asm(volatile unsigned long *addr, int nr);
48
49asmlinkage int __raw_bit_clear_asm(volatile unsigned long *addr, int nr);
50
51asmlinkage int __raw_bit_toggle_asm(volatile unsigned long *addr, int nr);
52
53asmlinkage int __raw_bit_test_set_asm(volatile unsigned long *addr, int nr);
54
55asmlinkage int __raw_bit_test_clear_asm(volatile unsigned long *addr, int nr);
56
57asmlinkage int __raw_bit_test_toggle_asm(volatile unsigned long *addr, int nr);
58
59asmlinkage int __raw_bit_test_asm(const volatile unsigned long *addr, int nr);
60
61static inline void set_bit(int nr, volatile unsigned long *addr)
62{
63 volatile unsigned long *a = addr + (nr >> 5);
64 __raw_bit_set_asm(a, nr & 0x1f);
65}
66
67static inline void clear_bit(int nr, volatile unsigned long *addr)
68{
69 volatile unsigned long *a = addr + (nr >> 5);
70 __raw_bit_clear_asm(a, nr & 0x1f);
71}
72
73static inline void change_bit(int nr, volatile unsigned long *addr)
74{
75 volatile unsigned long *a = addr + (nr >> 5);
76 __raw_bit_toggle_asm(a, nr & 0x1f);
77}
78
79static inline int test_bit(int nr, const volatile unsigned long *addr)
80{
81 volatile const unsigned long *a = addr + (nr >> 5);
82 return __raw_bit_test_asm(a, nr & 0x1f) != 0;
83}
84
85static inline int test_and_set_bit(int nr, volatile unsigned long *addr)
86{
87 volatile unsigned long *a = addr + (nr >> 5);
88 return __raw_bit_test_set_asm(a, nr & 0x1f);
89}
90
91static inline int test_and_clear_bit(int nr, volatile unsigned long *addr)
92{
93 volatile unsigned long *a = addr + (nr >> 5);
94 return __raw_bit_test_clear_asm(a, nr & 0x1f);
95}
96
97static inline int test_and_change_bit(int nr, volatile unsigned long *addr)
98{
99 volatile unsigned long *a = addr + (nr >> 5);
100 return __raw_bit_test_toggle_asm(a, nr & 0x1f);
101}
102
Graf Yang6b3087c2009-01-07 23:14:39 +0800103/*
104 * clear_bit() doesn't provide any barrier for the compiler.
105 */
106#define smp_mb__before_clear_bit() barrier()
107#define smp_mb__after_clear_bit() barrier()
108
Mike Frysinger3d150632009-06-13 11:21:51 -0400109#include <asm-generic/bitops/non-atomic.h>
Bryan Wu1394f032007-05-06 14:50:22 -0700110
Mike Frysinger3d150632009-06-13 11:21:51 -0400111#endif /* CONFIG_SMP */
112
Michael Hennerich0f7b4682009-12-22 11:32:06 +0000113/*
114 * hweightN: returns the hamming weight (i.e. the number
115 * of bits set) of a N-bit word
116 */
117
118static inline unsigned int hweight32(unsigned int w)
119{
120 unsigned int res;
121
122 __asm__ ("%0.l = ONES %0;"
123 "%0 = %0.l (Z);"
124 : "=d" (res) : "d" (w));
125 return res;
126}
127
128static inline unsigned int hweight64(__u64 w)
129{
130 return hweight32((unsigned int)(w >> 32)) + hweight32((unsigned int)w);
131}
132
133static inline unsigned int hweight16(unsigned int w)
134{
135 return hweight32(w & 0xffff);
136}
137
138static inline unsigned int hweight8(unsigned int w)
139{
140 return hweight32(w & 0xff);
141}
142
Bryan Wu1394f032007-05-06 14:50:22 -0700143#endif /* _BLACKFIN_BITOPS_H */