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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [uclinux/] [uClinux-2.0.x/] [include/] [asm-m68knommu/] [semaphore.h] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 199 simons
#ifndef _M68K_SEMAPHORE_H
2
#define _M68K_SEMAPHORE_H
3
 
4
#include <linux/linkage.h>
5
 
6
/*
7
 * SMP- and interrupt-safe semaphores..
8
 *
9
 * (C) Copyright 1996 Linus Torvalds
10
 *
11
 * m68k version by Andreas Schwab
12
 */
13
 
14
struct semaphore {
15
        int count;
16
        int waking;
17
        int lock;                       /* to make waking testing atomic */
18
        struct wait_queue * wait;
19
};
20
 
21
#define MUTEX ((struct semaphore) { 1, 0, 0, NULL })
22
#define MUTEX_LOCKED ((struct semaphore) { 0, 0, 0, NULL })
23
 
24
asmlinkage void __down_failed(void /* special register calling convention */);
25
asmlinkage int  __down_failed_interruptible(void);  /* params in registers */
26
asmlinkage void __up_wakeup(void /* special register calling convention */);
27
 
28
extern void __down(struct semaphore * sem);
29
extern void __up(struct semaphore * sem);
30
 
31
/*
32
 * This is ugly, but we want the default case to fall through.
33
 * "down_failed" is a special asm handler that calls the C
34
 * routine that actually waits. See arch/m68k/lib/semaphore.S
35
 */
36
extern inline void down(struct semaphore * sem)
37
{
38
        register struct semaphore *sem1 __asm__ ("%a1") = sem;
39
        __asm__ __volatile__(
40
                "| atomic down operation\n\t"
41
                "lea %%pc@(1f),%%a0\n\t"
42
                "subql #1,%0@\n\t"
43
                "jmi " SYMBOL_NAME_STR(__down_failed) "\n"
44
                "1:"
45
                : /* no outputs */
46
                : "a" (sem1)
47
                : "%a0", "memory");
48
}
49
 
50
 
51
/*
52
 * This version waits in interruptible state so that the waiting
53
 * process can be killed.  The down_failed_interruptible routine
54
 * returns negative for signalled and zero for semaphore acquired.
55
 */
56
extern inline int down_interruptible(struct semaphore * sem)
57
{
58
        register int ret __asm__ ("%d0");
59
        register struct semaphore *sem1 __asm__ ("%a1") = sem;
60
        __asm__ __volatile__(
61
                "| atomic down operation\n\t"
62
                "lea %%pc@(1f),%%a0\n\t"
63
                "subql #1,%1@\n\t"
64
                "jmi " SYMBOL_NAME_STR(__down_failed_interruptible) "\n"
65
                "clrl %0\n"
66
                "1:"
67
                : "=d" (ret)
68
                : "a" (sem1)
69
                : "%a0", "memory");
70
        return(ret);
71
}
72
 
73
 
74
/*
75
 * Primitives to spin on a lock.  Needed only for SMP version ... so
76
 * somebody should start playing with one of those Sony NeWS stations.
77
 */
78
extern inline void get_buzz_lock(int *lock_ptr)
79
{
80
#ifdef __SMP__
81
        while (xchg(lock_ptr,1) != 0) ;
82
#endif
83
}
84
 
85
extern inline void give_buzz_lock(int *lock_ptr)
86
{
87
#ifdef __SMP__
88
        *lock_ptr = 0 ;
89
#endif
90
}
91
 
92
 
93
/*
94
 * Note! This is subtle. We jump to wake people up only if
95
 * the semaphore was negative (== somebody was waiting on it).
96
 * The default case (no contention) will result in NO
97
 * jumps for both down() and up().
98
 */
99
extern inline void up(struct semaphore * sem)
100
{
101
        register struct semaphore *sem1 __asm__ ("%a1") = sem;
102
        __asm__ __volatile__(
103
                "| atomic up operation\n\t"
104
                "lea %%pc@(1f),%%a0\n\t"
105
                "addql #1,%0@\n\t"
106
                "jle " SYMBOL_NAME_STR(__up_wakeup) "\n"
107
                "1:"
108
                : /* no outputs */
109
                : "a" (sem1)
110
                : "%a0", "memory");
111
}
112
 
113
#endif

powered by: WebSVN 2.1.0

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