blob: d26f78b8f214d226de7bf8c1b523257f2956a7e0 [file] [log] [blame]
Ohad Ben-Cohenbd9a4c72011-02-17 09:52:03 -08001/*
2 * Hardware spinlocks internal header
3 *
4 * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com
5 *
6 * Contact: Ohad Ben-Cohen <ohad@wizery.com>
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 __HWSPINLOCK_HWSPINLOCK_H
19#define __HWSPINLOCK_HWSPINLOCK_H
20
21#include <linux/spinlock.h>
22#include <linux/device.h>
23
Ohad Ben-Cohen300bab92011-09-06 15:39:21 +030024struct hwspinlock_device;
25
Ohad Ben-Cohenbd9a4c72011-02-17 09:52:03 -080026/**
27 * struct hwspinlock_ops - platform-specific hwspinlock handlers
28 *
29 * @trylock: make a single attempt to take the lock. returns 0 on
30 * failure and true on success. may _not_ sleep.
31 * @unlock: release the lock. always succeed. may _not_ sleep.
32 * @relax: optional, platform-specific relax handler, called by hwspinlock
33 * core while spinning on a lock, between two successive
34 * invocations of @trylock. may _not_ sleep.
35 */
36struct hwspinlock_ops {
37 int (*trylock)(struct hwspinlock *lock);
38 void (*unlock)(struct hwspinlock *lock);
39 void (*relax)(struct hwspinlock *lock);
40};
41
42/**
43 * struct hwspinlock - this struct represents a single hwspinlock instance
Ohad Ben-Cohen300bab92011-09-06 15:39:21 +030044 * @bank: the hwspinlock_device structure which owns this lock
Ohad Ben-Cohenbd9a4c72011-02-17 09:52:03 -080045 * @lock: initialized and used by hwspinlock core
Ohad Ben-Cohen300bab92011-09-06 15:39:21 +030046 * @priv: private data, owned by the underlying platform-specific hwspinlock drv
Ohad Ben-Cohenbd9a4c72011-02-17 09:52:03 -080047 */
48struct hwspinlock {
Ohad Ben-Cohen300bab92011-09-06 15:39:21 +030049 struct hwspinlock_device *bank;
50 spinlock_t lock;
51 void *priv;
52};
53
54/**
55 * struct hwspinlock_device - a device which usually spans numerous hwspinlocks
56 * @dev: underlying device, will be used to invoke runtime PM api
57 * @ops: platform-specific hwspinlock handlers
58 * @base_id: id index of the first lock in this device
59 * @num_locks: number of locks in this device
60 * @lock: dynamically allocated array of 'struct hwspinlock'
61 */
62struct hwspinlock_device {
Ohad Ben-Cohenbd9a4c72011-02-17 09:52:03 -080063 struct device *dev;
64 const struct hwspinlock_ops *ops;
Ohad Ben-Cohen300bab92011-09-06 15:39:21 +030065 int base_id;
66 int num_locks;
67 struct hwspinlock lock[0];
Ohad Ben-Cohenbd9a4c72011-02-17 09:52:03 -080068};
69
Ohad Ben-Cohen300bab92011-09-06 15:39:21 +030070static inline int hwlock_to_id(struct hwspinlock *hwlock)
71{
72 int local_id = hwlock - &hwlock->bank->lock[0];
73
74 return hwlock->bank->base_id + local_id;
75}
76
Ohad Ben-Cohenbd9a4c72011-02-17 09:52:03 -080077#endif /* __HWSPINLOCK_HWSPINLOCK_H */