[PATCH] PCI: update Toshiba ohci quirk DMI table
[linux-2.6/mini2440.git] / include / asm-s390 / semaphore.h
blob702cf436698c60e77ee5198600df6ad8506c07c4
1 /*
2 * include/asm-s390/semaphore.h
4 * S390 version
5 * Copyright (C) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation
7 * Derived from "include/asm-i386/semaphore.h"
8 * (C) Copyright 1996 Linus Torvalds
9 */
11 #ifndef _S390_SEMAPHORE_H
12 #define _S390_SEMAPHORE_H
14 #include <asm/system.h>
15 #include <asm/atomic.h>
16 #include <linux/wait.h>
17 #include <linux/rwsem.h>
19 struct semaphore {
21 * Note that any negative value of count is equivalent to 0,
22 * but additionally indicates that some process(es) might be
23 * sleeping on `wait'.
25 atomic_t count;
26 wait_queue_head_t wait;
29 #define __SEMAPHORE_INITIALIZER(name,count) \
30 { ATOMIC_INIT(count), __WAIT_QUEUE_HEAD_INITIALIZER((name).wait) }
32 #define __DECLARE_SEMAPHORE_GENERIC(name,count) \
33 struct semaphore name = __SEMAPHORE_INITIALIZER(name,count)
35 #define DECLARE_MUTEX(name) __DECLARE_SEMAPHORE_GENERIC(name,1)
36 #define DECLARE_MUTEX_LOCKED(name) __DECLARE_SEMAPHORE_GENERIC(name,0)
38 static inline void sema_init (struct semaphore *sem, int val)
40 *sem = (struct semaphore) __SEMAPHORE_INITIALIZER((*sem),val);
43 static inline void init_MUTEX (struct semaphore *sem)
45 sema_init(sem, 1);
48 static inline void init_MUTEX_LOCKED (struct semaphore *sem)
50 sema_init(sem, 0);
53 asmlinkage void __down(struct semaphore * sem);
54 asmlinkage int __down_interruptible(struct semaphore * sem);
55 asmlinkage int __down_trylock(struct semaphore * sem);
56 asmlinkage void __up(struct semaphore * sem);
58 static inline void down(struct semaphore * sem)
60 might_sleep();
61 if (atomic_dec_return(&sem->count) < 0)
62 __down(sem);
65 static inline int down_interruptible(struct semaphore * sem)
67 int ret = 0;
69 might_sleep();
70 if (atomic_dec_return(&sem->count) < 0)
71 ret = __down_interruptible(sem);
72 return ret;
75 static inline int down_trylock(struct semaphore * sem)
77 int old_val, new_val;
80 * This inline assembly atomically implements the equivalent
81 * to the following C code:
82 * old_val = sem->count.counter;
83 * if ((new_val = old_val) > 0)
84 * sem->count.counter = --new_val;
85 * In the ppc code this is called atomic_dec_if_positive.
87 __asm__ __volatile__ (
88 " l %0,0(%3)\n"
89 "0: ltr %1,%0\n"
90 " jle 1f\n"
91 " ahi %1,-1\n"
92 " cs %0,%1,0(%3)\n"
93 " jl 0b\n"
94 "1:"
95 : "=&d" (old_val), "=&d" (new_val), "=m" (sem->count.counter)
96 : "a" (&sem->count.counter), "m" (sem->count.counter)
97 : "cc", "memory" );
98 return old_val <= 0;
101 static inline void up(struct semaphore * sem)
103 if (atomic_inc_return(&sem->count) <= 0)
104 __up(sem);
107 #endif