blob: 86ae2aebf00432f4d681a413febebff79406889d [file] [log] [blame]
Andi Kleeneea62f82012-05-08 13:32:24 +09301/* See include/linux/lglock.h for description */
2#include <linux/module.h>
3#include <linux/lglock.h>
4#include <linux/cpu.h>
5#include <linux/string.h>
6
7/*
8 * Note there is no uninit, so lglocks cannot be defined in
9 * modules (but it's fine to use them from there)
10 * Could be added though, just undo lg_lock_init
11 */
12
13void lg_lock_init(struct lglock *lg, char *name)
14{
15 LOCKDEP_INIT_MAP(&lg->lock_dep_map, name, &lg->lock_key, 0);
16}
17EXPORT_SYMBOL(lg_lock_init);
18
19void lg_local_lock(struct lglock *lg)
20{
21 arch_spinlock_t *lock;
22
23 preempt_disable();
Michel Lespinassec4be9cb2013-07-08 14:23:51 -070024 lock_acquire_shared(&lg->lock_dep_map, 0, 0, NULL, _RET_IP_);
Andi Kleeneea62f82012-05-08 13:32:24 +093025 lock = this_cpu_ptr(lg->lock);
26 arch_spin_lock(lock);
27}
28EXPORT_SYMBOL(lg_local_lock);
29
30void lg_local_unlock(struct lglock *lg)
31{
32 arch_spinlock_t *lock;
33
Michel Lespinassec4be9cb2013-07-08 14:23:51 -070034 lock_release(&lg->lock_dep_map, 1, _RET_IP_);
Andi Kleeneea62f82012-05-08 13:32:24 +093035 lock = this_cpu_ptr(lg->lock);
36 arch_spin_unlock(lock);
37 preempt_enable();
38}
39EXPORT_SYMBOL(lg_local_unlock);
40
41void lg_local_lock_cpu(struct lglock *lg, int cpu)
42{
43 arch_spinlock_t *lock;
44
45 preempt_disable();
Michel Lespinassec4be9cb2013-07-08 14:23:51 -070046 lock_acquire_shared(&lg->lock_dep_map, 0, 0, NULL, _RET_IP_);
Andi Kleeneea62f82012-05-08 13:32:24 +093047 lock = per_cpu_ptr(lg->lock, cpu);
48 arch_spin_lock(lock);
49}
50EXPORT_SYMBOL(lg_local_lock_cpu);
51
52void lg_local_unlock_cpu(struct lglock *lg, int cpu)
53{
54 arch_spinlock_t *lock;
55
Michel Lespinassec4be9cb2013-07-08 14:23:51 -070056 lock_release(&lg->lock_dep_map, 1, _RET_IP_);
Andi Kleeneea62f82012-05-08 13:32:24 +093057 lock = per_cpu_ptr(lg->lock, cpu);
58 arch_spin_unlock(lock);
59 preempt_enable();
60}
61EXPORT_SYMBOL(lg_local_unlock_cpu);
62
63void lg_global_lock(struct lglock *lg)
64{
65 int i;
66
67 preempt_disable();
Michel Lespinassec4be9cb2013-07-08 14:23:51 -070068 lock_acquire_exclusive(&lg->lock_dep_map, 0, 0, NULL, _RET_IP_);
Andi Kleeneea62f82012-05-08 13:32:24 +093069 for_each_possible_cpu(i) {
70 arch_spinlock_t *lock;
71 lock = per_cpu_ptr(lg->lock, i);
72 arch_spin_lock(lock);
73 }
74}
75EXPORT_SYMBOL(lg_global_lock);
76
77void lg_global_unlock(struct lglock *lg)
78{
79 int i;
80
Michel Lespinassec4be9cb2013-07-08 14:23:51 -070081 lock_release(&lg->lock_dep_map, 1, _RET_IP_);
Andi Kleeneea62f82012-05-08 13:32:24 +093082 for_each_possible_cpu(i) {
83 arch_spinlock_t *lock;
84 lock = per_cpu_ptr(lg->lock, i);
85 arch_spin_unlock(lock);
86 }
87 preempt_enable();
88}
89EXPORT_SYMBOL(lg_global_unlock);