2 * Spin and read/write lock operations.
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
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.
15 #include <linux/kernel.h>
16 #include <linux/spinlock.h>
17 #include <linux/module.h>
18 #include <linux/stringify.h>
19 #include <linux/smp.h>
21 /* waiting for a spinlock... */
22 #if defined(CONFIG_PPC_SPLPAR) || defined(CONFIG_PPC_ISERIES)
23 #include <asm/hvcall.h>
24 #include <asm/iseries/hv_call.h>
26 #include <asm/firmware.h>
28 void __spin_yield(raw_spinlock_t
*lock
)
30 unsigned int lock_value
, holder_cpu
, yield_count
;
32 lock_value
= lock
->slock
;
35 holder_cpu
= lock_value
& 0xffff;
36 BUG_ON(holder_cpu
>= NR_CPUS
);
37 yield_count
= lppaca
[holder_cpu
].yield_count
;
38 if ((yield_count
& 1) == 0)
39 return; /* virtual cpu is currently running */
41 if (lock
->slock
!= lock_value
)
42 return; /* something has changed */
43 if (firmware_has_feature(FW_FEATURE_ISERIES
))
44 HvCall2(HvCallBaseYieldProcessor
, HvCall_YieldToProc
,
45 ((u64
)holder_cpu
<< 32) | yield_count
);
47 plpar_hcall_norets(H_CONFER
,
48 get_hard_smp_processor_id(holder_cpu
), yield_count
);
52 * Waiting for a read lock or a write lock on a rwlock...
53 * This turns out to be the same for read and write locks, since
54 * we only know the holder if it is write-locked.
56 void __rw_yield(raw_rwlock_t
*rw
)
59 unsigned int holder_cpu
, yield_count
;
61 lock_value
= rw
->lock
;
63 return; /* no write lock at present */
64 holder_cpu
= lock_value
& 0xffff;
65 BUG_ON(holder_cpu
>= NR_CPUS
);
66 yield_count
= lppaca
[holder_cpu
].yield_count
;
67 if ((yield_count
& 1) == 0)
68 return; /* virtual cpu is currently running */
70 if (rw
->lock
!= lock_value
)
71 return; /* something has changed */
72 if (firmware_has_feature(FW_FEATURE_ISERIES
))
73 HvCall2(HvCallBaseYieldProcessor
, HvCall_YieldToProc
,
74 ((u64
)holder_cpu
<< 32) | yield_count
);
76 plpar_hcall_norets(H_CONFER
,
77 get_hard_smp_processor_id(holder_cpu
), yield_count
);
81 void __raw_spin_unlock_wait(raw_spinlock_t
*lock
)
91 EXPORT_SYMBOL(__raw_spin_unlock_wait
);