1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 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> 8 */ 9 10 #ifndef __HWSPINLOCK_HWSPINLOCK_H 11 #define __HWSPINLOCK_HWSPINLOCK_H 12 13 #include <linux/spinlock.h> 14 #include <linux/device.h> 15 16 struct hwspinlock_device; 17 18 /** 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 * @bust: optional, platform-specific bust handler, called by hwspinlock 25 * core to bust a specific lock. 26 * @relax: optional, platform-specific relax handler, called by hwspinlock 27 * core while spinning on a lock, between two successive 28 * invocations of @trylock. may _not_ sleep. 29 */ 30 struct hwspinlock_ops { 31 int (*trylock)(struct hwspinlock *lock); 32 void (*unlock)(struct hwspinlock *lock); 33 int (*bust)(struct hwspinlock *lock, unsigned int id); 34 void (*relax)(struct hwspinlock *lock); 35 }; 36 37 /** 38 * struct hwspinlock - this struct represents a single hwspinlock instance 39 * @bank: the hwspinlock_device structure which owns this lock 40 * @lock: initialized and used by hwspinlock core 41 * @priv: private data, owned by the underlying platform-specific hwspinlock drv 42 */ 43 struct hwspinlock { 44 struct hwspinlock_device *bank; 45 spinlock_t lock; 46 void *priv; 47 }; 48 49 /** 50 * struct hwspinlock_device - a device which usually spans numerous hwspinlocks 51 * @dev: underlying device, will be used to invoke runtime PM api 52 * @ops: platform-specific hwspinlock handlers 53 * @base_id: id index of the first lock in this device 54 * @num_locks: number of locks in this device 55 * @lock: dynamically allocated array of 'struct hwspinlock' 56 */ 57 struct hwspinlock_device { 58 struct device *dev; 59 const struct hwspinlock_ops *ops; 60 int base_id; 61 int num_locks; 62 struct hwspinlock lock[]; 63 }; 64 65 static inline int hwlock_to_id(struct hwspinlock *hwlock) 66 { 67 int local_id = hwlock - &hwlock->bank->lock[0]; 68 69 return hwlock->bank->base_id + local_id; 70 } 71 72 #endif /* __HWSPINLOCK_HWSPINLOCK_H */ 73