blob: 9eb6bd020dc702d38ebb3f9713881d284e9207f7 [file] [log] [blame]
Suman Annaeebba712018-05-11 12:03:16 -05001/* SPDX-License-Identifier: GPL-2.0 */
Ohad Ben-Cohenbd9a4c72011-02-17 09:52:03 -08002/*
3 * Hardware spinlocks internal header
4 *
5 * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com
6 *
7 * Contact: Ohad Ben-Cohen <ohad@wizery.com>
Ohad Ben-Cohenbd9a4c72011-02-17 09:52:03 -08008 */
9
10#ifndef __HWSPINLOCK_HWSPINLOCK_H
11#define __HWSPINLOCK_HWSPINLOCK_H
12
13#include <linux/spinlock.h>
14#include <linux/device.h>
15
Ohad Ben-Cohen300bab92011-09-06 15:39:21 +030016struct hwspinlock_device;
17
Ohad Ben-Cohenbd9a4c72011-02-17 09:52:03 -080018/**
19 * struct hwspinlock_ops - platform-specific hwspinlock handlers
20 *
21 * @trylock: make a single attempt to take the lock. returns 0 on
22 * failure and true on success. may _not_ sleep.
23 * @unlock: release the lock. always succeed. may _not_ sleep.
24 * @relax: optional, platform-specific relax handler, called by hwspinlock
25 * core while spinning on a lock, between two successive
26 * invocations of @trylock. may _not_ sleep.
27 */
28struct hwspinlock_ops {
29 int (*trylock)(struct hwspinlock *lock);
30 void (*unlock)(struct hwspinlock *lock);
31 void (*relax)(struct hwspinlock *lock);
32};
33
34/**
35 * struct hwspinlock - this struct represents a single hwspinlock instance
Ohad Ben-Cohen300bab92011-09-06 15:39:21 +030036 * @bank: the hwspinlock_device structure which owns this lock
Ohad Ben-Cohenbd9a4c72011-02-17 09:52:03 -080037 * @lock: initialized and used by hwspinlock core
Ohad Ben-Cohen300bab92011-09-06 15:39:21 +030038 * @priv: private data, owned by the underlying platform-specific hwspinlock drv
Ohad Ben-Cohenbd9a4c72011-02-17 09:52:03 -080039 */
40struct hwspinlock {
Ohad Ben-Cohen300bab92011-09-06 15:39:21 +030041 struct hwspinlock_device *bank;
42 spinlock_t lock;
43 void *priv;
44};
45
46/**
47 * struct hwspinlock_device - a device which usually spans numerous hwspinlocks
48 * @dev: underlying device, will be used to invoke runtime PM api
49 * @ops: platform-specific hwspinlock handlers
50 * @base_id: id index of the first lock in this device
51 * @num_locks: number of locks in this device
52 * @lock: dynamically allocated array of 'struct hwspinlock'
53 */
54struct hwspinlock_device {
Ohad Ben-Cohenbd9a4c72011-02-17 09:52:03 -080055 struct device *dev;
56 const struct hwspinlock_ops *ops;
Ohad Ben-Cohen300bab92011-09-06 15:39:21 +030057 int base_id;
58 int num_locks;
59 struct hwspinlock lock[0];
Ohad Ben-Cohenbd9a4c72011-02-17 09:52:03 -080060};
61
Ohad Ben-Cohen300bab92011-09-06 15:39:21 +030062static inline int hwlock_to_id(struct hwspinlock *hwlock)
63{
64 int local_id = hwlock - &hwlock->bank->lock[0];
65
66 return hwlock->bank->base_id + local_id;
67}
68
Ohad Ben-Cohenbd9a4c72011-02-17 09:52:03 -080069#endif /* __HWSPINLOCK_HWSPINLOCK_H */