blob: 49762c6bb0d56f549f090fd98216ababccc75045 [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-atomic.h>
Bryan Wu1394f032007-05-06 14:50:22 -070030
Michael Hennerich0f7b4682009-12-22 11:32:06 +000031#ifndef CONFIG_SMP
32#include <linux/irqflags.h>
33
34/*
35 * clear_bit may not imply a memory barrier
36 */
37#ifndef smp_mb__before_clear_bit
38#define smp_mb__before_clear_bit() smp_mb()
39#define smp_mb__after_clear_bit() smp_mb()
40#endif
41#include <asm-generic/bitops/atomic.h>
42#include <asm-generic/bitops/non-atomic.h>
43#else
44
45#include <asm/byteorder.h> /* swab32 */
Graf Yang6b3087c2009-01-07 23:14:39 +080046#include <linux/linkage.h>
47
48asmlinkage int __raw_bit_set_asm(volatile unsigned long *addr, int nr);
49
50asmlinkage int __raw_bit_clear_asm(volatile unsigned long *addr, int nr);
51
52asmlinkage int __raw_bit_toggle_asm(volatile unsigned long *addr, int nr);
53
54asmlinkage int __raw_bit_test_set_asm(volatile unsigned long *addr, int nr);
55
56asmlinkage int __raw_bit_test_clear_asm(volatile unsigned long *addr, int nr);
57
58asmlinkage int __raw_bit_test_toggle_asm(volatile unsigned long *addr, int nr);
59
60asmlinkage int __raw_bit_test_asm(const volatile unsigned long *addr, int nr);
61
62static inline void set_bit(int nr, volatile unsigned long *addr)
63{
64 volatile unsigned long *a = addr + (nr >> 5);
65 __raw_bit_set_asm(a, nr & 0x1f);
66}
67
68static inline void clear_bit(int nr, volatile unsigned long *addr)
69{
70 volatile unsigned long *a = addr + (nr >> 5);
71 __raw_bit_clear_asm(a, nr & 0x1f);
72}
73
74static inline void change_bit(int nr, volatile unsigned long *addr)
75{
76 volatile unsigned long *a = addr + (nr >> 5);
77 __raw_bit_toggle_asm(a, nr & 0x1f);
78}
79
80static inline int test_bit(int nr, const volatile unsigned long *addr)
81{
82 volatile const unsigned long *a = addr + (nr >> 5);
83 return __raw_bit_test_asm(a, nr & 0x1f) != 0;
84}
85
86static inline int test_and_set_bit(int nr, volatile unsigned long *addr)
87{
88 volatile unsigned long *a = addr + (nr >> 5);
89 return __raw_bit_test_set_asm(a, nr & 0x1f);
90}
91
92static inline int test_and_clear_bit(int nr, volatile unsigned long *addr)
93{
94 volatile unsigned long *a = addr + (nr >> 5);
95 return __raw_bit_test_clear_asm(a, nr & 0x1f);
96}
97
98static inline int test_and_change_bit(int nr, volatile unsigned long *addr)
99{
100 volatile unsigned long *a = addr + (nr >> 5);
101 return __raw_bit_test_toggle_asm(a, nr & 0x1f);
102}
103
Graf Yang6b3087c2009-01-07 23:14:39 +0800104/*
105 * clear_bit() doesn't provide any barrier for the compiler.
106 */
107#define smp_mb__before_clear_bit() barrier()
108#define smp_mb__after_clear_bit() barrier()
109
Mike Frysinger71a516a2009-09-21 11:51:31 +0000110#define test_bit __skip_test_bit
Mike Frysinger3d150632009-06-13 11:21:51 -0400111#include <asm-generic/bitops/non-atomic.h>
Mike Frysinger71a516a2009-09-21 11:51:31 +0000112#undef test_bit
Bryan Wu1394f032007-05-06 14:50:22 -0700113
Mike Frysinger3d150632009-06-13 11:21:51 -0400114#endif /* CONFIG_SMP */
115
Michael Hennerich0f7b4682009-12-22 11:32:06 +0000116/*
117 * hweightN: returns the hamming weight (i.e. the number
118 * of bits set) of a N-bit word
119 */
120
Mike Frysinger97e94c32010-08-13 17:42:39 -0400121static inline unsigned int __arch_hweight32(unsigned int w)
Michael Hennerich0f7b4682009-12-22 11:32:06 +0000122{
123 unsigned int res;
124
Mike Frysingera13265a2010-06-07 12:22:03 +0000125 __asm__ ("%0.l = ONES %1;"
Michael Hennerich0f7b4682009-12-22 11:32:06 +0000126 "%0 = %0.l (Z);"
127 : "=d" (res) : "d" (w));
128 return res;
129}
130
Mike Frysinger97e94c32010-08-13 17:42:39 -0400131static inline unsigned int __arch_hweight64(__u64 w)
Michael Hennerich0f7b4682009-12-22 11:32:06 +0000132{
Mike Frysinger97e94c32010-08-13 17:42:39 -0400133 return __arch_hweight32((unsigned int)(w >> 32)) +
134 __arch_hweight32((unsigned int)w);
Michael Hennerich0f7b4682009-12-22 11:32:06 +0000135}
136
Mike Frysinger97e94c32010-08-13 17:42:39 -0400137static inline unsigned int __arch_hweight16(unsigned int w)
Michael Hennerich0f7b4682009-12-22 11:32:06 +0000138{
Mike Frysinger97e94c32010-08-13 17:42:39 -0400139 return __arch_hweight32(w & 0xffff);
Michael Hennerich0f7b4682009-12-22 11:32:06 +0000140}
141
Mike Frysinger97e94c32010-08-13 17:42:39 -0400142static inline unsigned int __arch_hweight8(unsigned int w)
Michael Hennerich0f7b4682009-12-22 11:32:06 +0000143{
Mike Frysinger97e94c32010-08-13 17:42:39 -0400144 return __arch_hweight32(w & 0xff);
Michael Hennerich0f7b4682009-12-22 11:32:06 +0000145}
146
Bryan Wu1394f032007-05-06 14:50:22 -0700147#endif /* _BLACKFIN_BITOPS_H */