blob: 35a0ef932e1ad01b80220dd2e93130d06c9b2dc4 [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
Paul Mackerras40ef8cb2005-10-10 22:50:37 +100015#include <linux/kernel.h>
16#include <linux/spinlock.h>
Paul Gortmaker4b16f8e2011-07-22 18:24:23 -040017#include <linux/export.h>
Paul Mackerras734d6522005-10-31 13:57:01 +110018#include <linux/smp.h>
Paul Mackerras40ef8cb2005-10-10 22:50:37 +100019
20/* waiting for a spinlock... */
Stephen Rothwellf5339272012-03-15 18:18:00 +000021#if defined(CONFIG_PPC_SPLPAR)
Paul Mackerras40ef8cb2005-10-10 22:50:37 +100022#include <asm/hvcall.h>
Paul Mackerras2249ca92005-11-07 13:18:13 +110023#include <asm/smp.h>
Paul Mackerras40ef8cb2005-10-10 22:50:37 +100024
Thomas Gleixner445c8952009-12-02 19:49:50 +010025void __spin_yield(arch_spinlock_t *lock)
Paul Mackerras40ef8cb2005-10-10 22:50:37 +100026{
27 unsigned int lock_value, holder_cpu, yield_count;
Paul Mackerras40ef8cb2005-10-10 22:50:37 +100028
29 lock_value = lock->slock;
30 if (lock_value == 0)
31 return;
32 holder_cpu = lock_value & 0xffff;
33 BUG_ON(holder_cpu >= NR_CPUS);
Anton Blanchard7ffcf8e2013-08-07 02:01:46 +100034 yield_count = be32_to_cpu(lppaca_of(holder_cpu).yield_count);
Paul Mackerras40ef8cb2005-10-10 22:50:37 +100035 if ((yield_count & 1) == 0)
36 return; /* virtual cpu is currently running */
37 rmb();
38 if (lock->slock != lock_value)
39 return; /* something has changed */
Stephen Rothwellf5339272012-03-15 18:18:00 +000040 plpar_hcall_norets(H_CONFER,
41 get_hard_smp_processor_id(holder_cpu), yield_count);
Paul Mackerras40ef8cb2005-10-10 22:50:37 +100042}
Geert Uytterhoeven1f8c82a2015-03-04 12:56:20 +010043EXPORT_SYMBOL_GPL(__spin_yield);
Paul Mackerras40ef8cb2005-10-10 22:50:37 +100044
45/*
46 * Waiting for a read lock or a write lock on a rwlock...
47 * This turns out to be the same for read and write locks, since
48 * we only know the holder if it is write-locked.
49 */
Thomas Gleixnerfb3a6bb2009-12-03 20:01:19 +010050void __rw_yield(arch_rwlock_t *rw)
Paul Mackerras40ef8cb2005-10-10 22:50:37 +100051{
52 int lock_value;
53 unsigned int holder_cpu, yield_count;
Paul Mackerras40ef8cb2005-10-10 22:50:37 +100054
55 lock_value = rw->lock;
56 if (lock_value >= 0)
57 return; /* no write lock at present */
58 holder_cpu = lock_value & 0xffff;
59 BUG_ON(holder_cpu >= NR_CPUS);
Anton Blanchard7ffcf8e2013-08-07 02:01:46 +100060 yield_count = be32_to_cpu(lppaca_of(holder_cpu).yield_count);
Paul Mackerras40ef8cb2005-10-10 22:50:37 +100061 if ((yield_count & 1) == 0)
62 return; /* virtual cpu is currently running */
63 rmb();
64 if (rw->lock != lock_value)
65 return; /* something has changed */
Stephen Rothwellf5339272012-03-15 18:18:00 +000066 plpar_hcall_norets(H_CONFER,
67 get_hard_smp_processor_id(holder_cpu), yield_count);
Paul Mackerras40ef8cb2005-10-10 22:50:37 +100068}
69#endif