Paul Mackerras | 40ef8cb | 2005-10-10 22:50:37 +1000 | [diff] [blame] | 1 | /* |
| 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 Mackerras | 40ef8cb | 2005-10-10 22:50:37 +1000 | [diff] [blame] | 15 | #include <linux/kernel.h> |
| 16 | #include <linux/spinlock.h> |
Paul Gortmaker | 4b16f8e | 2011-07-22 18:24:23 -0400 | [diff] [blame] | 17 | #include <linux/export.h> |
Paul Mackerras | 40ef8cb | 2005-10-10 22:50:37 +1000 | [diff] [blame] | 18 | #include <linux/stringify.h> |
Paul Mackerras | 734d652 | 2005-10-31 13:57:01 +1100 | [diff] [blame] | 19 | #include <linux/smp.h> |
Paul Mackerras | 40ef8cb | 2005-10-10 22:50:37 +1000 | [diff] [blame] | 20 | |
| 21 | /* waiting for a spinlock... */ |
Stephen Rothwell | f533927 | 2012-03-15 18:18:00 +0000 | [diff] [blame] | 22 | #if defined(CONFIG_PPC_SPLPAR) |
Paul Mackerras | 40ef8cb | 2005-10-10 22:50:37 +1000 | [diff] [blame] | 23 | #include <asm/hvcall.h> |
Paul Mackerras | 2249ca9 | 2005-11-07 13:18:13 +1100 | [diff] [blame] | 24 | #include <asm/smp.h> |
Paul Mackerras | 40ef8cb | 2005-10-10 22:50:37 +1000 | [diff] [blame] | 25 | |
Thomas Gleixner | 445c895 | 2009-12-02 19:49:50 +0100 | [diff] [blame] | 26 | void __spin_yield(arch_spinlock_t *lock) |
Paul Mackerras | 40ef8cb | 2005-10-10 22:50:37 +1000 | [diff] [blame] | 27 | { |
| 28 | unsigned int lock_value, holder_cpu, yield_count; |
Paul Mackerras | 40ef8cb | 2005-10-10 22:50:37 +1000 | [diff] [blame] | 29 | |
| 30 | lock_value = lock->slock; |
| 31 | if (lock_value == 0) |
| 32 | return; |
| 33 | holder_cpu = lock_value & 0xffff; |
| 34 | BUG_ON(holder_cpu >= NR_CPUS); |
Anton Blanchard | 7ffcf8e | 2013-08-07 02:01:46 +1000 | [diff] [blame] | 35 | yield_count = be32_to_cpu(lppaca_of(holder_cpu).yield_count); |
Paul Mackerras | 40ef8cb | 2005-10-10 22:50:37 +1000 | [diff] [blame] | 36 | if ((yield_count & 1) == 0) |
| 37 | return; /* virtual cpu is currently running */ |
| 38 | rmb(); |
| 39 | if (lock->slock != lock_value) |
| 40 | return; /* something has changed */ |
Stephen Rothwell | f533927 | 2012-03-15 18:18:00 +0000 | [diff] [blame] | 41 | plpar_hcall_norets(H_CONFER, |
| 42 | get_hard_smp_processor_id(holder_cpu), yield_count); |
Paul Mackerras | 40ef8cb | 2005-10-10 22:50:37 +1000 | [diff] [blame] | 43 | } |
Geert Uytterhoeven | 1f8c82a | 2015-03-04 12:56:20 +0100 | [diff] [blame] | 44 | EXPORT_SYMBOL_GPL(__spin_yield); |
Paul Mackerras | 40ef8cb | 2005-10-10 22:50:37 +1000 | [diff] [blame] | 45 | |
| 46 | /* |
| 47 | * Waiting for a read lock or a write lock on a rwlock... |
| 48 | * This turns out to be the same for read and write locks, since |
| 49 | * we only know the holder if it is write-locked. |
| 50 | */ |
Thomas Gleixner | fb3a6bb | 2009-12-03 20:01:19 +0100 | [diff] [blame] | 51 | void __rw_yield(arch_rwlock_t *rw) |
Paul Mackerras | 40ef8cb | 2005-10-10 22:50:37 +1000 | [diff] [blame] | 52 | { |
| 53 | int lock_value; |
| 54 | unsigned int holder_cpu, yield_count; |
Paul Mackerras | 40ef8cb | 2005-10-10 22:50:37 +1000 | [diff] [blame] | 55 | |
| 56 | lock_value = rw->lock; |
| 57 | if (lock_value >= 0) |
| 58 | return; /* no write lock at present */ |
| 59 | holder_cpu = lock_value & 0xffff; |
| 60 | BUG_ON(holder_cpu >= NR_CPUS); |
Anton Blanchard | 7ffcf8e | 2013-08-07 02:01:46 +1000 | [diff] [blame] | 61 | yield_count = be32_to_cpu(lppaca_of(holder_cpu).yield_count); |
Paul Mackerras | 40ef8cb | 2005-10-10 22:50:37 +1000 | [diff] [blame] | 62 | if ((yield_count & 1) == 0) |
| 63 | return; /* virtual cpu is currently running */ |
| 64 | rmb(); |
| 65 | if (rw->lock != lock_value) |
| 66 | return; /* something has changed */ |
Stephen Rothwell | f533927 | 2012-03-15 18:18:00 +0000 | [diff] [blame] | 67 | plpar_hcall_norets(H_CONFER, |
| 68 | get_hard_smp_processor_id(holder_cpu), yield_count); |
Paul Mackerras | 40ef8cb | 2005-10-10 22:50:37 +1000 | [diff] [blame] | 69 | } |
| 70 | #endif |