[ARM] 3684/1: ARM: Convert l7200 to generic irq handling
[linux-2.6/kvm.git] / arch / s390 / lib / spinlock.c
blobb9b7958a226a75a5787129404b1eb525c95832b4
1 /*
2 * arch/s390/lib/spinlock.c
3 * Out of line spinlock code.
5 * Copyright (C) IBM Corp. 2004, 2006
6 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com)
7 */
9 #include <linux/types.h>
10 #include <linux/module.h>
11 #include <linux/spinlock.h>
12 #include <linux/init.h>
13 #include <asm/io.h>
15 int spin_retry = 1000;
17 /**
18 * spin_retry= parameter
20 static int __init spin_retry_setup(char *str)
22 spin_retry = simple_strtoul(str, &str, 0);
23 return 1;
25 __setup("spin_retry=", spin_retry_setup);
27 static inline void
28 _diag44(void)
30 #ifdef CONFIG_64BIT
31 if (MACHINE_HAS_DIAG44)
32 #endif
33 asm volatile("diag 0,0,0x44");
36 void
37 _raw_spin_lock_wait(raw_spinlock_t *lp, unsigned int pc)
39 int count = spin_retry;
41 while (1) {
42 if (count-- <= 0) {
43 _diag44();
44 count = spin_retry;
46 if (__raw_spin_is_locked(lp))
47 continue;
48 if (_raw_compare_and_swap(&lp->lock, 0, pc) == 0)
49 return;
52 EXPORT_SYMBOL(_raw_spin_lock_wait);
54 int
55 _raw_spin_trylock_retry(raw_spinlock_t *lp, unsigned int pc)
57 int count = spin_retry;
59 while (count-- > 0) {
60 if (__raw_spin_is_locked(lp))
61 continue;
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(raw_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 if (!__raw_read_can_lock(rw))
81 continue;
82 old = rw->lock & 0x7fffffffU;
83 if (_raw_compare_and_swap(&rw->lock, old, old + 1) == old)
84 return;
87 EXPORT_SYMBOL(_raw_read_lock_wait);
89 int
90 _raw_read_trylock_retry(raw_rwlock_t *rw)
92 unsigned int old;
93 int count = spin_retry;
95 while (count-- > 0) {
96 if (!__raw_read_can_lock(rw))
97 continue;
98 old = rw->lock & 0x7fffffffU;
99 if (_raw_compare_and_swap(&rw->lock, old, old + 1) == old)
100 return 1;
102 return 0;
104 EXPORT_SYMBOL(_raw_read_trylock_retry);
106 void
107 _raw_write_lock_wait(raw_rwlock_t *rw)
109 int count = spin_retry;
111 while (1) {
112 if (count-- <= 0) {
113 _diag44();
114 count = spin_retry;
116 if (!__raw_write_can_lock(rw))
117 continue;
118 if (_raw_compare_and_swap(&rw->lock, 0, 0x80000000) == 0)
119 return;
122 EXPORT_SYMBOL(_raw_write_lock_wait);
125 _raw_write_trylock_retry(raw_rwlock_t *rw)
127 int count = spin_retry;
129 while (count-- > 0) {
130 if (!__raw_write_can_lock(rw))
131 continue;
132 if (_raw_compare_and_swap(&rw->lock, 0, 0x80000000) == 0)
133 return 1;
135 return 0;
137 EXPORT_SYMBOL(_raw_write_trylock_retry);