]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - arch/s390/lib/spinlock.c
[PATCH] s390: cleanup Kconfig
[mirror_ubuntu-zesty-kernel.git] / arch / s390 / lib / spinlock.c
CommitLineData
951f22d5
MS
1/*
2 * arch/s390/lib/spinlock.c
3 * Out of line spinlock code.
4 *
5 * S390 version
6 * Copyright (C) 2004 IBM Deutschland Entwicklung GmbH, IBM Corporation
7 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com)
8 */
9
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>
15
16atomic_t spin_retry_counter;
17int spin_retry = 1000;
18
19/**
20 * spin_retry= parameter
21 */
22static int __init spin_retry_setup(char *str)
23{
24 spin_retry = simple_strtoul(str, &str, 0);
25 return 1;
26}
27__setup("spin_retry=", spin_retry_setup);
28
29static inline void
30_diag44(void)
31{
347a8dc3 32#ifdef CONFIG_64BIT
951f22d5
MS
33 if (MACHINE_HAS_DIAG44)
34#endif
35 asm volatile("diag 0,0,0x44");
36}
37
38void
fb1c8f93 39_raw_spin_lock_wait(raw_spinlock_t *lp, unsigned int pc)
951f22d5
MS
40{
41 int count = spin_retry;
42
43 while (1) {
44 if (count-- <= 0) {
45 _diag44();
46 count = spin_retry;
47 }
48 atomic_inc(&spin_retry_counter);
49 if (_raw_compare_and_swap(&lp->lock, 0, pc) == 0)
50 return;
51 }
52}
53EXPORT_SYMBOL(_raw_spin_lock_wait);
54
55int
fb1c8f93 56_raw_spin_trylock_retry(raw_spinlock_t *lp, unsigned int pc)
951f22d5
MS
57{
58 int count = spin_retry;
59
60 while (count-- > 0) {
61 atomic_inc(&spin_retry_counter);
62 if (_raw_compare_and_swap(&lp->lock, 0, pc) == 0)
63 return 1;
64 }
65 return 0;
66}
67EXPORT_SYMBOL(_raw_spin_trylock_retry);
68
69void
fb1c8f93 70_raw_read_lock_wait(raw_rwlock_t *rw)
951f22d5
MS
71{
72 unsigned int old;
73 int count = spin_retry;
74
75 while (1) {
76 if (count-- <= 0) {
77 _diag44();
78 count = spin_retry;
79 }
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;
84 }
85}
86EXPORT_SYMBOL(_raw_read_lock_wait);
87
88int
fb1c8f93 89_raw_read_trylock_retry(raw_rwlock_t *rw)
951f22d5
MS
90{
91 unsigned int old;
92 int count = spin_retry;
93
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;
99 }
100 return 0;
101}
102EXPORT_SYMBOL(_raw_read_trylock_retry);
103
104void
fb1c8f93 105_raw_write_lock_wait(raw_rwlock_t *rw)
951f22d5
MS
106{
107 int count = spin_retry;
108
109 while (1) {
110 if (count-- <= 0) {
111 _diag44();
112 count = spin_retry;
113 }
114 atomic_inc(&spin_retry_counter);
115 if (_raw_compare_and_swap(&rw->lock, 0, 0x80000000) == 0)
116 return;
117 }
118}
119EXPORT_SYMBOL(_raw_write_lock_wait);
120
121int
fb1c8f93 122_raw_write_trylock_retry(raw_rwlock_t *rw)
951f22d5
MS
123{
124 int count = spin_retry;
125
126 while (count-- > 0) {
127 atomic_inc(&spin_retry_counter);
128 if (_raw_compare_and_swap(&rw->lock, 0, 0x80000000) == 0)
129 return 1;
130 }
131 return 0;
132}
133EXPORT_SYMBOL(_raw_write_trylock_retry);