Linux 2.6.13-rc4
[linux-2.6/next.git] / arch / s390 / lib / spinlock.c
blob888b5596c195d5123a24b60099b46f2c6f3634aa
1 /*
2 * arch/s390/lib/spinlock.c
3 * Out of line spinlock code.
5 * S390 version
6 * Copyright (C) 2004 IBM Deutschland Entwicklung GmbH, IBM Corporation
7 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com)
8 */
10 #include <linux/types.h>
11 #include <linux/module.h>
12 #include <linux/spinlock.h>
13 #include <linux/init.h>
14 #include <asm/io.h>
16 atomic_t spin_retry_counter;
17 int spin_retry = 1000;
19 /**
20 * spin_retry= parameter
22 static int __init spin_retry_setup(char *str)
24 spin_retry = simple_strtoul(str, &str, 0);
25 return 1;
27 __setup("spin_retry=", spin_retry_setup);
29 static inline void
30 _diag44(void)
32 #ifdef __s390x__
33 if (MACHINE_HAS_DIAG44)
34 #endif
35 asm volatile("diag 0,0,0x44");
38 void
39 _raw_spin_lock_wait(spinlock_t *lp, unsigned int pc)
41 int count = spin_retry;
43 while (1) {
44 if (count-- <= 0) {
45 _diag44();
46 count = spin_retry;
48 atomic_inc(&spin_retry_counter);
49 if (_raw_compare_and_swap(&lp->lock, 0, pc) == 0)
50 return;
53 EXPORT_SYMBOL(_raw_spin_lock_wait);
55 int
56 _raw_spin_trylock_retry(spinlock_t *lp, unsigned int pc)
58 int count = spin_retry;
60 while (count-- > 0) {
61 atomic_inc(&spin_retry_counter);
62 if (_raw_compare_and_swap(&lp->lock, 0, pc) == 0)
63 return 1;
65 return 0;
67 EXPORT_SYMBOL(_raw_spin_trylock_retry);
69 void
70 _raw_read_lock_wait(rwlock_t *rw)
72 unsigned int old;
73 int count = spin_retry;
75 while (1) {
76 if (count-- <= 0) {
77 _diag44();
78 count = spin_retry;
80 atomic_inc(&spin_retry_counter);
81 old = rw->lock & 0x7fffffffU;
82 if (_raw_compare_and_swap(&rw->lock, old, old + 1) == old)
83 return;
86 EXPORT_SYMBOL(_raw_read_lock_wait);
88 int
89 _raw_read_trylock_retry(rwlock_t *rw)
91 unsigned int old;
92 int count = spin_retry;
94 while (count-- > 0) {
95 atomic_inc(&spin_retry_counter);
96 old = rw->lock & 0x7fffffffU;
97 if (_raw_compare_and_swap(&rw->lock, old, old + 1) == old)
98 return 1;
100 return 0;
102 EXPORT_SYMBOL(_raw_read_trylock_retry);
104 void
105 _raw_write_lock_wait(rwlock_t *rw)
107 int count = spin_retry;
109 while (1) {
110 if (count-- <= 0) {
111 _diag44();
112 count = spin_retry;
114 atomic_inc(&spin_retry_counter);
115 if (_raw_compare_and_swap(&rw->lock, 0, 0x80000000) == 0)
116 return;
119 EXPORT_SYMBOL(_raw_write_lock_wait);
122 _raw_write_trylock_retry(rwlock_t *rw)
124 int count = spin_retry;
126 while (count-- > 0) {
127 atomic_inc(&spin_retry_counter);
128 if (_raw_compare_and_swap(&rw->lock, 0, 0x80000000) == 0)
129 return 1;
131 return 0;
133 EXPORT_SYMBOL(_raw_write_trylock_retry);