Blame view

drivers/hwspinlock/hwspinlock_internal.h 2.37 KB
bd9a4c7df   Ohad Ben-Cohen   drivers: hwspinlo...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  /*
   * Hardware spinlocks internal header
   *
   * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com
   *
   * Contact: Ohad Ben-Cohen <ohad@wizery.com>
   *
   * This program is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 as published
   * by the Free Software Foundation.
   *
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
   */
  
  #ifndef __HWSPINLOCK_HWSPINLOCK_H
  #define __HWSPINLOCK_HWSPINLOCK_H
  
  #include <linux/spinlock.h>
  #include <linux/device.h>
300bab977   Ohad Ben-Cohen   hwspinlock/core: ...
23
  struct hwspinlock_device;
bd9a4c7df   Ohad Ben-Cohen   drivers: hwspinlo...
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
  /**
   * struct hwspinlock_ops - platform-specific hwspinlock handlers
   *
   * @trylock: make a single attempt to take the lock. returns 0 on
   *	     failure and true on success. may _not_ sleep.
   * @unlock:  release the lock. always succeed. may _not_ sleep.
   * @relax:   optional, platform-specific relax handler, called by hwspinlock
   *	     core while spinning on a lock, between two successive
   *	     invocations of @trylock. may _not_ sleep.
   */
  struct hwspinlock_ops {
  	int (*trylock)(struct hwspinlock *lock);
  	void (*unlock)(struct hwspinlock *lock);
  	void (*relax)(struct hwspinlock *lock);
  };
  
  /**
   * struct hwspinlock - this struct represents a single hwspinlock instance
300bab977   Ohad Ben-Cohen   hwspinlock/core: ...
42
   * @bank: the hwspinlock_device structure which owns this lock
bd9a4c7df   Ohad Ben-Cohen   drivers: hwspinlo...
43
   * @lock: initialized and used by hwspinlock core
300bab977   Ohad Ben-Cohen   hwspinlock/core: ...
44
   * @priv: private data, owned by the underlying platform-specific hwspinlock drv
bd9a4c7df   Ohad Ben-Cohen   drivers: hwspinlo...
45
46
   */
  struct hwspinlock {
300bab977   Ohad Ben-Cohen   hwspinlock/core: ...
47
48
49
50
51
52
53
54
55
56
57
58
59
60
  	struct hwspinlock_device *bank;
  	spinlock_t lock;
  	void *priv;
  };
  
  /**
   * struct hwspinlock_device - a device which usually spans numerous hwspinlocks
   * @dev: underlying device, will be used to invoke runtime PM api
   * @ops: platform-specific hwspinlock handlers
   * @base_id: id index of the first lock in this device
   * @num_locks: number of locks in this device
   * @lock: dynamically allocated array of 'struct hwspinlock'
   */
  struct hwspinlock_device {
bd9a4c7df   Ohad Ben-Cohen   drivers: hwspinlo...
61
62
  	struct device *dev;
  	const struct hwspinlock_ops *ops;
300bab977   Ohad Ben-Cohen   hwspinlock/core: ...
63
64
65
  	int base_id;
  	int num_locks;
  	struct hwspinlock lock[0];
bd9a4c7df   Ohad Ben-Cohen   drivers: hwspinlo...
66
  };
300bab977   Ohad Ben-Cohen   hwspinlock/core: ...
67
68
69
70
71
72
  static inline int hwlock_to_id(struct hwspinlock *hwlock)
  {
  	int local_id = hwlock - &hwlock->bank->lock[0];
  
  	return hwlock->bank->base_id + local_id;
  }
bd9a4c7df   Ohad Ben-Cohen   drivers: hwspinlo...
73
  #endif /* __HWSPINLOCK_HWSPINLOCK_H */