OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [include/] [asm-sparc/] [semaphore.h] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1275 phoenix
#ifndef _SPARC_SEMAPHORE_H
2
#define _SPARC_SEMAPHORE_H
3
 
4
/* Dinky, good for nothing, just barely irq safe, Sparc semaphores. */
5
 
6
#ifdef __KERNEL__
7
 
8
#include <asm/atomic.h>
9
#include <linux/wait.h>
10
#include <linux/rwsem.h>
11
 
12
struct semaphore {
13
        atomic_t count;
14
        int sleepers;
15
        wait_queue_head_t wait;
16
#if WAITQUEUE_DEBUG
17
        long __magic;
18
#endif
19
};
20
 
21
#if WAITQUEUE_DEBUG
22
# define __SEM_DEBUG_INIT(name) \
23
                , (long)&(name).__magic
24
#else
25
# define __SEM_DEBUG_INIT(name)
26
#endif
27
 
28
#define __SEMAPHORE_INITIALIZER(name,count) \
29
{ ATOMIC_INIT(count), 0, __WAIT_QUEUE_HEAD_INITIALIZER((name).wait) \
30
        __SEM_DEBUG_INIT(name) }
31
 
32
#define __MUTEX_INITIALIZER(name) \
33
        __SEMAPHORE_INITIALIZER(name,1)
34
 
35
#define __DECLARE_SEMAPHORE_GENERIC(name,count) \
36
        struct semaphore name = __SEMAPHORE_INITIALIZER(name,count)
37
 
38
#define DECLARE_MUTEX(name) __DECLARE_SEMAPHORE_GENERIC(name,1)
39
#define DECLARE_MUTEX_LOCKED(name) __DECLARE_SEMAPHORE_GENERIC(name,0)
40
 
41
static inline void sema_init (struct semaphore *sem, int val)
42
{
43
        atomic_set(&sem->count, val);
44
        sem->sleepers = 0;
45
        init_waitqueue_head(&sem->wait);
46
#if WAITQUEUE_DEBUG
47
        sem->__magic = (long)&sem->__magic;
48
#endif
49
}
50
 
51
static inline void init_MUTEX (struct semaphore *sem)
52
{
53
        sema_init(sem, 1);
54
}
55
 
56
static inline void init_MUTEX_LOCKED (struct semaphore *sem)
57
{
58
        sema_init(sem, 0);
59
}
60
 
61
extern void __down(struct semaphore * sem);
62
extern int __down_interruptible(struct semaphore * sem);
63
extern int __down_trylock(struct semaphore * sem);
64
extern void __up(struct semaphore * sem);
65
 
66
static inline void down(struct semaphore * sem)
67
{
68
        register volatile int *ptr asm("g1");
69
        register int increment asm("g2");
70
 
71
#if WAITQUEUE_DEBUG
72
        CHECK_MAGIC(sem->__magic);
73
#endif
74
 
75
        ptr = &(sem->count.counter);
76
        increment = 1;
77
 
78
        __asm__ __volatile__(
79
        "mov    %%o7, %%g4\n\t"
80
        "call   ___atomic_sub\n\t"
81
        " add   %%o7, 8, %%o7\n\t"
82
        "tst    %%g2\n\t"
83
        "bl     2f\n\t"
84
        " nop\n"
85
        "1:\n\t"
86
        ".subsection 2\n"
87
        "2:\n\t"
88
        "save   %%sp, -64, %%sp\n\t"
89
        "mov    %%g1, %%l1\n\t"
90
        "mov    %%g5, %%l5\n\t"
91
        "call   %3\n\t"
92
        " mov   %%g1, %%o0\n\t"
93
        "mov    %%l1, %%g1\n\t"
94
        "ba     1b\n\t"
95
        " restore %%l5, %%g0, %%g5\n\t"
96
        ".previous\n"
97
        : "=&r" (increment)
98
        : "0" (increment), "r" (ptr), "i" (__down)
99
        : "g3", "g4", "g7", "memory", "cc");
100
}
101
 
102
static inline int down_interruptible(struct semaphore * sem)
103
{
104
        register volatile int *ptr asm("g1");
105
        register int increment asm("g2");
106
 
107
#if WAITQUEUE_DEBUG
108
        CHECK_MAGIC(sem->__magic);
109
#endif
110
 
111
        ptr = &(sem->count.counter);
112
        increment = 1;
113
 
114
        __asm__ __volatile__(
115
        "mov    %%o7, %%g4\n\t"
116
        "call   ___atomic_sub\n\t"
117
        " add   %%o7, 8, %%o7\n\t"
118
        "tst    %%g2\n\t"
119
        "bl     2f\n\t"
120
        " clr   %%g2\n"
121
        "1:\n\t"
122
        ".subsection 2\n"
123
        "2:\n\t"
124
        "save   %%sp, -64, %%sp\n\t"
125
        "mov    %%g1, %%l1\n\t"
126
        "mov    %%g5, %%l5\n\t"
127
        "call   %3\n\t"
128
        " mov   %%g1, %%o0\n\t"
129
        "mov    %%l1, %%g1\n\t"
130
        "mov    %%l5, %%g5\n\t"
131
        "ba     1b\n\t"
132
        " restore %%o0, %%g0, %%g2\n\t"
133
        ".previous\n"
134
        : "=&r" (increment)
135
        : "0" (increment), "r" (ptr), "i" (__down_interruptible)
136
        : "g3", "g4", "g7", "memory", "cc");
137
 
138
        return increment;
139
}
140
 
141
static inline int down_trylock(struct semaphore * sem)
142
{
143
        register volatile int *ptr asm("g1");
144
        register int increment asm("g2");
145
 
146
#if WAITQUEUE_DEBUG
147
        CHECK_MAGIC(sem->__magic);
148
#endif
149
 
150
        ptr = &(sem->count.counter);
151
        increment = 1;
152
 
153
        __asm__ __volatile__(
154
        "mov    %%o7, %%g4\n\t"
155
        "call   ___atomic_sub\n\t"
156
        " add   %%o7, 8, %%o7\n\t"
157
        "tst    %%g2\n\t"
158
        "bl     2f\n\t"
159
        " clr   %%g2\n"
160
        "1:\n\t"
161
        ".subsection 2\n"
162
        "2:\n\t"
163
        "save   %%sp, -64, %%sp\n\t"
164
        "mov    %%g1, %%l1\n\t"
165
        "mov    %%g5, %%l5\n\t"
166
        "call   %3\n\t"
167
        " mov   %%g1, %%o0\n\t"
168
        "mov    %%l1, %%g1\n\t"
169
        "mov    %%l5, %%g5\n\t"
170
        "ba     1b\n\t"
171
        " restore %%o0, %%g0, %%g2\n\t"
172
        ".previous\n"
173
        : "=&r" (increment)
174
        : "0" (increment), "r" (ptr), "i" (__down_trylock)
175
        : "g3", "g4", "g7", "memory", "cc");
176
 
177
        return increment;
178
}
179
 
180
static inline void up(struct semaphore * sem)
181
{
182
        register volatile int *ptr asm("g1");
183
        register int increment asm("g2");
184
 
185
#if WAITQUEUE_DEBUG
186
        CHECK_MAGIC(sem->__magic);
187
#endif
188
 
189
        ptr = &(sem->count.counter);
190
        increment = 1;
191
 
192
        __asm__ __volatile__(
193
        "mov    %%o7, %%g4\n\t"
194
        "call   ___atomic_add\n\t"
195
        " add   %%o7, 8, %%o7\n\t"
196
        "tst    %%g2\n\t"
197
        "ble    2f\n\t"
198
        " nop\n"
199
        "1:\n\t"
200
        ".subsection 2\n"
201
        "2:\n\t"
202
        "save   %%sp, -64, %%sp\n\t"
203
        "mov    %%g1, %%l1\n\t"
204
        "mov    %%g5, %%l5\n\t"
205
        "call   %3\n\t"
206
        " mov   %%g1, %%o0\n\t"
207
        "mov    %%l1, %%g1\n\t"
208
        "ba     1b\n\t"
209
        " restore %%l5, %%g0, %%g5\n\t"
210
        ".previous\n"
211
        : "=&r" (increment)
212
        : "0" (increment), "r" (ptr), "i" (__up)
213
        : "g3", "g4", "g7", "memory", "cc");
214
}
215
 
216
static inline int sem_getcount(struct semaphore *sem)
217
{
218
        return atomic_read(&sem->count);
219
}
220
 
221
#endif /* __KERNEL__ */
222
 
223
#endif /* !(_SPARC_SEMAPHORE_H) */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.