Root/target/linux/ubicom32/files/arch/ubicom32/include/asm/bitops.h

1/*
2 * arch/ubicom32/include/asm/bitops.h
3 * Bit manipulation definitions for Ubicom32 architecture.
4 *
5 * (C) Copyright 2009, Ubicom, Inc.
6 *
7 * This file is part of the Ubicom32 Linux Kernel Port.
8 *
9 * The Ubicom32 Linux Kernel Port is free software: you can redistribute
10 * it and/or modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation, either version 2 of the
12 * License, or (at your option) any later version.
13 *
14 * The Ubicom32 Linux Kernel Port is distributed in the hope that it
15 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
16 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
17 * the GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with the Ubicom32 Linux Kernel Port. If not,
21 * see <http://www.gnu.org/licenses/>.
22 *
23 * Ubicom32 implementation derived from (with many thanks):
24 * arch/m68knommu
25 * arch/blackfin
26 * arch/parisc
27 */
28#ifndef _ASM_UBICOM32_BITOPS_H
29#define _ASM_UBICOM32_BITOPS_H
30
31/*
32 * Copyright 1992, Linus Torvalds.
33 */
34
35#include <linux/compiler.h>
36#include <asm/byteorder.h> /* swab32 */
37
38#ifdef __KERNEL__
39
40#ifndef _LINUX_BITOPS_H
41#error only <linux/bitops.h> can be included directly
42#endif
43
44#include <asm-generic/bitops/ffs.h>
45#include <asm-generic/bitops/__ffs.h>
46
47#include <asm-generic/bitops/sched.h>
48#include <asm-generic/bitops/ffz.h>
49
50#include <asm/ubicom32-common.h>
51
52static inline void set_bit(int bit, volatile unsigned long *p)
53{
54    unsigned long mask = 1UL << (bit & 31);
55
56    p += bit >> 5;
57
58    __atomic_lock_acquire();
59    *p |= mask;
60    __atomic_lock_release();
61}
62
63static inline void clear_bit(int bit, volatile unsigned long *p)
64{
65    unsigned long mask = 1UL << (bit & 31);
66
67    p += bit >> 5;
68
69    __atomic_lock_acquire();
70    *p &= ~mask;
71    __atomic_lock_release();
72}
73
74/*
75 * clear_bit() doesn't provide any barrier for the compiler.
76 */
77#define smp_mb__before_clear_bit() barrier()
78#define smp_mb__after_clear_bit() barrier()
79
80static inline void change_bit(int bit, volatile unsigned long *p)
81{
82    unsigned long mask = 1UL << (bit & 31);
83
84    p += bit >> 5;
85
86    __atomic_lock_acquire();
87    *p ^= mask;
88    __atomic_lock_release();
89}
90
91static inline int test_and_set_bit(int bit, volatile unsigned long *p)
92{
93    unsigned int res;
94    unsigned long mask = 1UL << (bit & 31);
95
96    p += bit >> 5;
97
98    __atomic_lock_acquire();
99    res = *p;
100    *p = res | mask;
101    __atomic_lock_release();
102
103    return res & mask;
104}
105
106static inline int test_and_clear_bit(int bit, volatile unsigned long *p)
107{
108    unsigned int res;
109    unsigned long mask = 1UL << (bit & 31);
110
111    p += bit >> 5;
112
113    __atomic_lock_acquire();
114    res = *p;
115    *p = res & ~mask;
116    __atomic_lock_release();
117
118    return res & mask;
119}
120
121static inline int test_and_change_bit(int bit, volatile unsigned long *p)
122{
123    unsigned int res;
124    unsigned long mask = 1UL << (bit & 31);
125
126    p += bit >> 5;
127
128    __atomic_lock_acquire();
129    res = *p;
130    *p = res ^ mask;
131    __atomic_lock_release();
132
133    return res & mask;
134}
135
136#include <asm-generic/bitops/non-atomic.h>
137
138/*
139 * This routine doesn't need to be atomic.
140 */
141static inline int __constant_test_bit(int nr, const volatile unsigned long *addr)
142{
143    return ((1UL << (nr & 31)) & (((const volatile unsigned int *) addr)[nr >> 5])) != 0;
144}
145
146static inline int __test_bit(int nr, const volatile unsigned long *addr)
147{
148    int * a = (int *) addr;
149    int mask;
150
151    a += nr >> 5;
152    mask = 1 << (nr & 0x1f);
153    return ((mask & *a) != 0);
154}
155
156#define test_bit(nr,addr) (__builtin_constant_p(nr) ? __constant_test_bit((nr),(addr)) : __test_bit((nr),(addr)))
157
158#include <asm-generic/bitops/find.h>
159#include <asm-generic/bitops/hweight.h>
160#include <asm-generic/bitops/lock.h>
161
162#include <asm-generic/bitops/ext2-non-atomic.h>
163#include <asm-generic/bitops/ext2-atomic.h>
164#include <asm-generic/bitops/minix.h>
165
166#endif /* __KERNEL__ */
167
168#include <asm-generic/bitops/fls.h>
169#include <asm-generic/bitops/__fls.h>
170#include <asm-generic/bitops/fls64.h>
171
172#endif /* _ASM_UBICOM32_BITOPS_H */
173

Archive Download this file



interactive