Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
hwspinlock.h
Go to the documentation of this file.
1 /*
2  * Hardware spinlock public header
3  *
4  * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com
5  *
6  * Contact: Ohad Ben-Cohen <[email protected]>
7  *
8  * This program is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU General Public License version 2 as published
10  * by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  */
17 
18 #ifndef __LINUX_HWSPINLOCK_H
19 #define __LINUX_HWSPINLOCK_H
20 
21 #include <linux/err.h>
22 #include <linux/sched.h>
23 
24 /* hwspinlock mode argument */
25 #define HWLOCK_IRQSTATE 0x01 /* Disable interrupts, save state */
26 #define HWLOCK_IRQ 0x02 /* Disable interrupts, don't save state */
27 
28 struct device;
29 struct hwspinlock;
30 struct hwspinlock_device;
31 struct hwspinlock_ops;
32 
58  int base_id;
59 };
60 
61 #if defined(CONFIG_HWSPINLOCK) || defined(CONFIG_HWSPINLOCK_MODULE)
62 
63 int hwspin_lock_register(struct hwspinlock_device *bank, struct device *dev,
64  const struct hwspinlock_ops *ops, int base_id, int num_locks);
66 struct hwspinlock *hwspin_lock_request(void);
67 struct hwspinlock *hwspin_lock_request_specific(unsigned int id);
68 int hwspin_lock_free(struct hwspinlock *hwlock);
69 int hwspin_lock_get_id(struct hwspinlock *hwlock);
70 int __hwspin_lock_timeout(struct hwspinlock *, unsigned int, int,
71  unsigned long *);
72 int __hwspin_trylock(struct hwspinlock *, int, unsigned long *);
73 void __hwspin_unlock(struct hwspinlock *, int, unsigned long *);
74 
75 #else /* !CONFIG_HWSPINLOCK */
76 
77 /*
78  * We don't want these functions to fail if CONFIG_HWSPINLOCK is not
79  * enabled. We prefer to silently succeed in this case, and let the
80  * code path get compiled away. This way, if CONFIG_HWSPINLOCK is not
81  * required on a given setup, users will still work.
82  *
83  * The only exception is hwspin_lock_register/hwspin_lock_unregister, with which
84  * we _do_ want users to fail (no point in registering hwspinlock instances if
85  * the framework is not available).
86  *
87  * Note: ERR_PTR(-ENODEV) will still be considered a success for NULL-checking
88  * users. Others, which care, can still check this with IS_ERR.
89  */
90 static inline struct hwspinlock *hwspin_lock_request(void)
91 {
92  return ERR_PTR(-ENODEV);
93 }
94 
95 static inline struct hwspinlock *hwspin_lock_request_specific(unsigned int id)
96 {
97  return ERR_PTR(-ENODEV);
98 }
99 
100 static inline int hwspin_lock_free(struct hwspinlock *hwlock)
101 {
102  return 0;
103 }
104 
105 static inline
106 int __hwspin_lock_timeout(struct hwspinlock *hwlock, unsigned int to,
107  int mode, unsigned long *flags)
108 {
109  return 0;
110 }
111 
112 static inline
113 int __hwspin_trylock(struct hwspinlock *hwlock, int mode, unsigned long *flags)
114 {
115  return 0;
116 }
117 
118 static inline
119 void __hwspin_unlock(struct hwspinlock *hwlock, int mode, unsigned long *flags)
120 {
121 }
122 
123 static inline int hwspin_lock_get_id(struct hwspinlock *hwlock)
124 {
125  return 0;
126 }
127 
128 #endif /* !CONFIG_HWSPINLOCK */
129 
146 static inline
147 int hwspin_trylock_irqsave(struct hwspinlock *hwlock, unsigned long *flags)
148 {
149  return __hwspin_trylock(hwlock, HWLOCK_IRQSTATE, flags);
150 }
151 
166 static inline int hwspin_trylock_irq(struct hwspinlock *hwlock)
167 {
168  return __hwspin_trylock(hwlock, HWLOCK_IRQ, NULL);
169 }
170 
186 static inline int hwspin_trylock(struct hwspinlock *hwlock)
187 {
188  return __hwspin_trylock(hwlock, 0, NULL);
189 }
190 
209 static inline int hwspin_lock_timeout_irqsave(struct hwspinlock *hwlock,
210  unsigned int to, unsigned long *flags)
211 {
212  return __hwspin_lock_timeout(hwlock, to, HWLOCK_IRQSTATE, flags);
213 }
214 
232 static inline
233 int hwspin_lock_timeout_irq(struct hwspinlock *hwlock, unsigned int to)
234 {
235  return __hwspin_lock_timeout(hwlock, to, HWLOCK_IRQ, NULL);
236 }
237 
257 static inline
258 int hwspin_lock_timeout(struct hwspinlock *hwlock, unsigned int to)
259 {
260  return __hwspin_lock_timeout(hwlock, to, 0, NULL);
261 }
262 
275 static inline void hwspin_unlock_irqrestore(struct hwspinlock *hwlock,
276  unsigned long *flags)
277 {
278  __hwspin_unlock(hwlock, HWLOCK_IRQSTATE, flags);
279 }
280 
292 static inline void hwspin_unlock_irq(struct hwspinlock *hwlock)
293 {
294  __hwspin_unlock(hwlock, HWLOCK_IRQ, NULL);
295 }
296 
308 static inline void hwspin_unlock(struct hwspinlock *hwlock)
309 {
310  __hwspin_unlock(hwlock, 0, NULL);
311 }
312 
313 #endif /* __LINUX_HWSPINLOCK_H */