18 #define pr_fmt(fmt) "%s: " fmt, __func__
20 #include <linux/kernel.h>
21 #include <linux/module.h>
23 #include <linux/types.h>
34 #define HWSPINLOCK_UNUSED (0)
111 ret = spin_trylock_irq(&hwlock->
lock);
113 ret = spin_trylock(&hwlock->
lock);
120 ret = hwlock->
bank->ops->trylock(hwlock);
125 spin_unlock_irqrestore(&hwlock->
lock, *flags);
127 spin_unlock_irq(&hwlock->
lock);
129 spin_unlock(&hwlock->
lock);
181 unsigned long expire;
202 if (hwlock->
bank->ops->relax)
203 hwlock->
bank->ops->relax(hwlock);
248 hwlock->
bank->ops->unlock(hwlock);
252 spin_unlock_irqrestore(&hwlock->
lock, *flags);
254 spin_unlock_irq(&hwlock->
lock);
256 spin_unlock(&hwlock->
lock);
260 static int hwspin_lock_register_single(
struct hwspinlock *hwlock,
int id)
270 pr_err(
"hwspinlock id %d already exists!\n",
id);
285 static struct hwspinlock *hwspin_lock_unregister_single(
unsigned int id)
295 pr_err(
"hwspinlock %d still in use (or not present)\n",
id);
301 pr_err(
"failed to delete hwspinlock %d\n",
id);
331 if (!bank || !ops || !dev || !num_locks || !ops->
trylock ||
333 pr_err(
"invalid parameters\n");
342 for (
i = 0;
i < num_locks;
i++) {
343 hwlock = &bank->
lock[
i];
348 ret = hwspin_lock_register_single(hwlock, base_id +
i);
357 hwspin_lock_unregister_single(base_id +
i);
379 hwlock = &bank->
lock[
i];
381 tmp = hwspin_lock_unregister_single(bank->
base_id + i);
403 static int __hwspin_lock_request(
struct hwspinlock *hwlock)
410 if (!try_module_get(dev->
driver->owner)) {
411 dev_err(dev,
"%s: can't get owner\n", __func__);
416 ret = pm_runtime_get_sync(dev);
418 dev_err(dev,
"%s: can't power on device\n", __func__);
441 pr_err(
"invalid hwlock\n");
445 return hwlock_to_id(hwlock);
473 pr_warn(
"a free hwspinlock is not available\n");
482 ret = __hwspin_lock_request(hwlock);
515 pr_warn(
"hwspinlock %u does not exist\n",
id);
520 WARN_ON(hwlock_to_id(hwlock) !=
id);
525 pr_warn(
"hwspinlock %u is already in use\n",
id);
531 ret = __hwspin_lock_request(hwlock);
560 pr_err(
"invalid hwlock\n");
564 dev = hwlock->
bank->dev;
571 dev_err(dev,
"%s: hwlock is already free\n", __func__);
578 ret = pm_runtime_put(dev);
589 module_put(dev->
driver->owner);