blob: 68b98a7e6454952500e54cd6728eb688813836a2 [file] [log] [blame]
Adrian Bunk88278ca2008-05-19 16:53:02 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * bitops.h: Bit string operations on the Sparc.
3 *
4 * Copyright 1995 David S. Miller (davem@caip.rutgers.edu)
5 * Copyright 1996 Eddie C. Dost (ecd@skynet.be)
6 * Copyright 2001 Anton Blanchard (anton@samba.org)
7 */
8
9#ifndef _SPARC_BITOPS_H
10#define _SPARC_BITOPS_H
11
12#include <linux/compiler.h>
13#include <asm/byteorder.h>
14
15#ifdef __KERNEL__
16
Jiri Slaby06245172007-10-18 23:40:26 -070017#ifndef _LINUX_BITOPS_H
18#error only <linux/bitops.h> can be included directly
19#endif
20
David S. Miller8a8b8362006-12-17 16:18:47 -080021extern unsigned long ___set_bit(unsigned long *addr, unsigned long mask);
22extern unsigned long ___clear_bit(unsigned long *addr, unsigned long mask);
23extern unsigned long ___change_bit(unsigned long *addr, unsigned long mask);
24
Linus Torvalds1da177e2005-04-16 15:20:36 -070025/*
26 * Set bit 'nr' in 32-bit quantity at address 'addr' where bit '0'
27 * is in the highest of the four bytes and bit '31' is the high bit
28 * within the first byte. Sparc is BIG-Endian. Unless noted otherwise
29 * all bit-ops return 0 if bit was previously clear and != 0 otherwise.
30 */
31static inline int test_and_set_bit(unsigned long nr, volatile unsigned long *addr)
32{
David S. Miller8a8b8362006-12-17 16:18:47 -080033 unsigned long *ADDR, mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
35 ADDR = ((unsigned long *) addr) + (nr >> 5);
36 mask = 1 << (nr & 31);
37
David S. Miller8a8b8362006-12-17 16:18:47 -080038 return ___set_bit(ADDR, mask) != 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070039}
40
41static inline void set_bit(unsigned long nr, volatile unsigned long *addr)
42{
David S. Miller8a8b8362006-12-17 16:18:47 -080043 unsigned long *ADDR, mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
45 ADDR = ((unsigned long *) addr) + (nr >> 5);
46 mask = 1 << (nr & 31);
47
David S. Miller8a8b8362006-12-17 16:18:47 -080048 (void) ___set_bit(ADDR, mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -070049}
50
51static inline int test_and_clear_bit(unsigned long nr, volatile unsigned long *addr)
52{
David S. Miller8a8b8362006-12-17 16:18:47 -080053 unsigned long *ADDR, mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
55 ADDR = ((unsigned long *) addr) + (nr >> 5);
56 mask = 1 << (nr & 31);
57
David S. Miller8a8b8362006-12-17 16:18:47 -080058 return ___clear_bit(ADDR, mask) != 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059}
60
61static inline void clear_bit(unsigned long nr, volatile unsigned long *addr)
62{
David S. Miller8a8b8362006-12-17 16:18:47 -080063 unsigned long *ADDR, mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
65 ADDR = ((unsigned long *) addr) + (nr >> 5);
66 mask = 1 << (nr & 31);
67
David S. Miller8a8b8362006-12-17 16:18:47 -080068 (void) ___clear_bit(ADDR, mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069}
70
71static inline int test_and_change_bit(unsigned long nr, volatile unsigned long *addr)
72{
David S. Miller8a8b8362006-12-17 16:18:47 -080073 unsigned long *ADDR, mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
75 ADDR = ((unsigned long *) addr) + (nr >> 5);
76 mask = 1 << (nr & 31);
77
David S. Miller8a8b8362006-12-17 16:18:47 -080078 return ___change_bit(ADDR, mask) != 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079}
80
81static inline void change_bit(unsigned long nr, volatile unsigned long *addr)
82{
David S. Miller8a8b8362006-12-17 16:18:47 -080083 unsigned long *ADDR, mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
85 ADDR = ((unsigned long *) addr) + (nr >> 5);
86 mask = 1 << (nr & 31);
87
David S. Miller8a8b8362006-12-17 16:18:47 -080088 (void) ___change_bit(ADDR, mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089}
90
Akinobu Mitad59288b2006-03-26 01:39:39 -080091#include <asm-generic/bitops/non-atomic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
93#define smp_mb__before_clear_bit() do { } while(0)
94#define smp_mb__after_clear_bit() do { } while(0)
95
Akinobu Mitad59288b2006-03-26 01:39:39 -080096#include <asm-generic/bitops/ffz.h>
97#include <asm-generic/bitops/__ffs.h>
98#include <asm-generic/bitops/sched.h>
99#include <asm-generic/bitops/ffs.h>
100#include <asm-generic/bitops/fls.h>
101#include <asm-generic/bitops/fls64.h>
102#include <asm-generic/bitops/hweight.h>
Nick Piggin26333572007-10-18 03:06:39 -0700103#include <asm-generic/bitops/lock.h>
Akinobu Mitad59288b2006-03-26 01:39:39 -0800104#include <asm-generic/bitops/find.h>
105#include <asm-generic/bitops/ext2-non-atomic.h>
106#include <asm-generic/bitops/ext2-atomic.h>
107#include <asm-generic/bitops/minix.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
109#endif /* __KERNEL__ */
110
111#endif /* defined(_SPARC_BITOPS_H) */