e1000: Add device IDs of blade version of the 82571 quad port
[pv_ops_mirror.git] / arch / s390 / lib / spinlock.c
blob8d76403fcf89b5900f02f6084312049791b8dc4e
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 _raw_yield(void)
29 if (MACHINE_HAS_DIAG44)
30 asm volatile("diag 0,0,0x44");
33 static inline void _raw_yield_cpu(int cpu)
35 if (MACHINE_HAS_DIAG9C)
36 asm volatile("diag %0,0,0x9c"
37 : : "d" (__cpu_logical_map[cpu]));
38 else
39 _raw_yield();
42 void _raw_spin_lock_wait(raw_spinlock_t *lp, unsigned int pc)
44 int count = spin_retry;
45 unsigned int cpu = ~smp_processor_id();
47 while (1) {
48 if (count-- <= 0) {
49 unsigned int owner = lp->owner_cpu;
50 if (owner != 0)
51 _raw_yield_cpu(~owner);
52 count = spin_retry;
54 if (__raw_spin_is_locked(lp))
55 continue;
56 if (_raw_compare_and_swap(&lp->owner_cpu, 0, cpu) == 0) {
57 lp->owner_pc = pc;
58 return;
62 EXPORT_SYMBOL(_raw_spin_lock_wait);
64 int _raw_spin_trylock_retry(raw_spinlock_t *lp, unsigned int pc)
66 unsigned int cpu = ~smp_processor_id();
67 int count;
69 for (count = spin_retry; count > 0; count--) {
70 if (__raw_spin_is_locked(lp))
71 continue;
72 if (_raw_compare_and_swap(&lp->owner_cpu, 0, cpu) == 0) {
73 lp->owner_pc = pc;
74 return 1;
77 return 0;
79 EXPORT_SYMBOL(_raw_spin_trylock_retry);
81 void _raw_spin_relax(raw_spinlock_t *lock)
83 unsigned int cpu = lock->owner_cpu;
84 if (cpu != 0)
85 _raw_yield_cpu(~cpu);
87 EXPORT_SYMBOL(_raw_spin_relax);
89 void _raw_read_lock_wait(raw_rwlock_t *rw)
91 unsigned int old;
92 int count = spin_retry;
94 while (1) {
95 if (count-- <= 0) {
96 _raw_yield();
97 count = spin_retry;
99 if (!__raw_read_can_lock(rw))
100 continue;
101 old = rw->lock & 0x7fffffffU;
102 if (_raw_compare_and_swap(&rw->lock, old, old + 1) == old)
103 return;
106 EXPORT_SYMBOL(_raw_read_lock_wait);
108 int _raw_read_trylock_retry(raw_rwlock_t *rw)
110 unsigned int old;
111 int count = spin_retry;
113 while (count-- > 0) {
114 if (!__raw_read_can_lock(rw))
115 continue;
116 old = rw->lock & 0x7fffffffU;
117 if (_raw_compare_and_swap(&rw->lock, old, old + 1) == old)
118 return 1;
120 return 0;
122 EXPORT_SYMBOL(_raw_read_trylock_retry);
124 void _raw_write_lock_wait(raw_rwlock_t *rw)
126 int count = spin_retry;
128 while (1) {
129 if (count-- <= 0) {
130 _raw_yield();
131 count = spin_retry;
133 if (!__raw_write_can_lock(rw))
134 continue;
135 if (_raw_compare_and_swap(&rw->lock, 0, 0x80000000) == 0)
136 return;
139 EXPORT_SYMBOL(_raw_write_lock_wait);
141 int _raw_write_trylock_retry(raw_rwlock_t *rw)
143 int count = spin_retry;
145 while (count-- > 0) {
146 if (!__raw_write_can_lock(rw))
147 continue;
148 if (_raw_compare_and_swap(&rw->lock, 0, 0x80000000) == 0)
149 return 1;
151 return 0;
153 EXPORT_SYMBOL(_raw_write_trylock_retry);