blob: 35bd03c41dd19727601e15f9169bc8807f50fb75 [file] [log] [blame]
Paul Mackerras40ef8cb2005-10-10 22:50:37 +10001/*
2 * Spin and read/write lock operations.
3 *
4 * Copyright (C) 2001-2004 Paul Mackerras <paulus@au.ibm.com>, IBM
5 * Copyright (C) 2001 Anton Blanchard <anton@au.ibm.com>, IBM
6 * Copyright (C) 2002 Dave Engebretsen <engebret@us.ibm.com>, IBM
7 * Rework to support virtual processors
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version
12 * 2 of the License, or (at your option) any later version.
13 */
14
15#include <linux/config.h>
16#include <linux/kernel.h>
17#include <linux/spinlock.h>
18#include <linux/module.h>
19#include <linux/stringify.h>
Paul Mackerras734d6522005-10-31 13:57:01 +110020#include <linux/smp.h>
Paul Mackerras40ef8cb2005-10-10 22:50:37 +100021
22/* waiting for a spinlock... */
23#if defined(CONFIG_PPC_SPLPAR) || defined(CONFIG_PPC_ISERIES)
24#include <asm/hvcall.h>
Kelly Daly1da44032005-11-01 16:59:20 +110025#include <asm/iseries/hv_call.h>
Paul Mackerras2249ca92005-11-07 13:18:13 +110026#include <asm/smp.h>
Paul Mackerras40ef8cb2005-10-10 22:50:37 +100027
28void __spin_yield(raw_spinlock_t *lock)
29{
30 unsigned int lock_value, holder_cpu, yield_count;
31 struct paca_struct *holder_paca;
32
33 lock_value = lock->slock;
34 if (lock_value == 0)
35 return;
36 holder_cpu = lock_value & 0xffff;
37 BUG_ON(holder_cpu >= NR_CPUS);
38 holder_paca = &paca[holder_cpu];
39 yield_count = holder_paca->lppaca.yield_count;
40 if ((yield_count & 1) == 0)
41 return; /* virtual cpu is currently running */
42 rmb();
43 if (lock->slock != lock_value)
44 return; /* something has changed */
45#ifdef CONFIG_PPC_ISERIES
46 HvCall2(HvCallBaseYieldProcessor, HvCall_YieldToProc,
47 ((u64)holder_cpu << 32) | yield_count);
48#else
49 plpar_hcall_norets(H_CONFER, get_hard_smp_processor_id(holder_cpu),
50 yield_count);
51#endif
52}
53
54/*
55 * Waiting for a read lock or a write lock on a rwlock...
56 * This turns out to be the same for read and write locks, since
57 * we only know the holder if it is write-locked.
58 */
59void __rw_yield(raw_rwlock_t *rw)
60{
61 int lock_value;
62 unsigned int holder_cpu, yield_count;
63 struct paca_struct *holder_paca;
64
65 lock_value = rw->lock;
66 if (lock_value >= 0)
67 return; /* no write lock at present */
68 holder_cpu = lock_value & 0xffff;
69 BUG_ON(holder_cpu >= NR_CPUS);
70 holder_paca = &paca[holder_cpu];
71 yield_count = holder_paca->lppaca.yield_count;
72 if ((yield_count & 1) == 0)
73 return; /* virtual cpu is currently running */
74 rmb();
75 if (rw->lock != lock_value)
76 return; /* something has changed */
77#ifdef CONFIG_PPC_ISERIES
78 HvCall2(HvCallBaseYieldProcessor, HvCall_YieldToProc,
79 ((u64)holder_cpu << 32) | yield_count);
80#else
81 plpar_hcall_norets(H_CONFER, get_hard_smp_processor_id(holder_cpu),
82 yield_count);
83#endif
84}
85#endif
86
87void __raw_spin_unlock_wait(raw_spinlock_t *lock)
88{
89 while (lock->slock) {
90 HMT_low();
91 if (SHARED_PROCESSOR)
92 __spin_yield(lock);
93 }
94 HMT_medium();
95}
96
97EXPORT_SYMBOL(__raw_spin_unlock_wait);