aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/hwspinlock.txt
diff options
context:
space:
mode:
authorOhad Ben-Cohen <ohad@wizery.com>2011-09-06 08:39:21 -0400
committerOhad Ben-Cohen <ohad@wizery.com>2011-09-21 12:45:34 -0400
commit300bab9770e2bd10262bcc78e7249fdce2c74b38 (patch)
tree5c23d7dce82b96fa177ea7c854de7f4b36992c80 /Documentation/hwspinlock.txt
parentc536abfdf5227987b8a72ff955b64e62fd58fe91 (diff)
hwspinlock/core: register a bank of hwspinlocks in a single API call
Hardware Spinlock devices usually contain numerous locks (known devices today support between 32 to 256 locks). Originally hwspinlock core required drivers to register (and later, when needed, unregister) each lock separately. That worked, but required hwspinlocks drivers to do a bit extra work when they were probed/removed. This patch changes hwspin_lock_{un}register() to allow a bank of hwspinlocks to be {un}registered in a single invocation. A new 'struct hwspinlock_device', which contains an array of 'struct hwspinlock's is now being passed to the core upon registration (so instead of wrapping each struct hwspinlock, a priv member has been added to allow drivers to piggyback their private data with each hwspinlock). While at it, several per-lock members were moved to be per-device: 1. struct device *dev 2. struct hwspinlock_ops *ops In addition, now that the array of locks is handled by the core, there's no reason to maintain a per-lock 'int id' member: the id of the lock anyway equals to its index in the bank's array plus the bank's base_id. Remove this per-lock id member too, and instead use a simple pointers arithmetic to derive it. As a result of this change, hwspinlocks drivers are now simpler and smaller (about %20 code reduction) and the memory footprint of the hwspinlock framework is reduced. Signed-off-by: Ohad Ben-Cohen <ohad@wizery.com>
Diffstat (limited to 'Documentation/hwspinlock.txt')
-rw-r--r--Documentation/hwspinlock.txt58
1 files changed, 39 insertions, 19 deletions
diff --git a/Documentation/hwspinlock.txt b/Documentation/hwspinlock.txt
index 9171f912014..a903ee5e977 100644
--- a/Documentation/hwspinlock.txt
+++ b/Documentation/hwspinlock.txt
@@ -227,42 +227,62 @@ int hwspinlock_example2(void)
227 227
2284. API for implementors 2284. API for implementors
229 229
230 int hwspin_lock_register(struct hwspinlock *hwlock); 230 int hwspin_lock_register(struct hwspinlock_device *bank, struct device *dev,
231 const struct hwspinlock_ops *ops, int base_id, int num_locks);
231 - to be called from the underlying platform-specific implementation, in 232 - to be called from the underlying platform-specific implementation, in
232 order to register a new hwspinlock instance. Should be called from 233 order to register a new hwspinlock device (which is usually a bank of
233 a process context (this function might sleep). 234 numerous locks). Should be called from a process context (this function
235 might sleep).
234 Returns 0 on success, or appropriate error code on failure. 236 Returns 0 on success, or appropriate error code on failure.
235 237
236 struct hwspinlock *hwspin_lock_unregister(unsigned int id); 238 int hwspin_lock_unregister(struct hwspinlock_device *bank);
237 - to be called from the underlying vendor-specific implementation, in order 239 - to be called from the underlying vendor-specific implementation, in order
238 to unregister an existing (and unused) hwspinlock instance. 240 to unregister an hwspinlock device (which is usually a bank of numerous
241 locks).
239 Should be called from a process context (this function might sleep). 242 Should be called from a process context (this function might sleep).
240 Returns the address of hwspinlock on success, or NULL on error (e.g. 243 Returns the address of hwspinlock on success, or NULL on error (e.g.
241 if the hwspinlock is sill in use). 244 if the hwspinlock is sill in use).
242 245
2435. struct hwspinlock 2465. Important structs
244 247
245This struct represents an hwspinlock instance. It is registered by the 248struct hwspinlock_device is a device which usually contains a bank
246underlying hwspinlock implementation using the hwspin_lock_register() API. 249of hardware locks. It is registered by the underlying hwspinlock
250implementation using the hwspin_lock_register() API.
247 251
248/** 252/**
249 * struct hwspinlock - vendor-specific hwspinlock implementation 253 * struct hwspinlock_device - a device which usually spans numerous hwspinlocks
250 * 254 * @dev: underlying device, will be used to invoke runtime PM api
251 * @dev: underlying device, will be used with runtime PM api 255 * @ops: platform-specific hwspinlock handlers
252 * @ops: vendor-specific hwspinlock handlers 256 * @base_id: id index of the first lock in this device
253 * @id: a global, unique, system-wide, index of the lock. 257 * @num_locks: number of locks in this device
254 * @lock: initialized and used by hwspinlock core 258 * @lock: dynamically allocated array of 'struct hwspinlock'
255 */ 259 */
256struct hwspinlock { 260struct hwspinlock_device {
257 struct device *dev; 261 struct device *dev;
258 const struct hwspinlock_ops *ops; 262 const struct hwspinlock_ops *ops;
259 int id; 263 int base_id;
264 int num_locks;
265 struct hwspinlock lock[0];
266};
267
268struct hwspinlock_device contains an array of hwspinlock structs, each
269of which represents a single hardware lock:
270
271/**
272 * struct hwspinlock - this struct represents a single hwspinlock instance
273 * @bank: the hwspinlock_device structure which owns this lock
274 * @lock: initialized and used by hwspinlock core
275 * @priv: private data, owned by the underlying platform-specific hwspinlock drv
276 */
277struct hwspinlock {
278 struct hwspinlock_device *bank;
260 spinlock_t lock; 279 spinlock_t lock;
280 void *priv;
261}; 281};
262 282
263The underlying implementation is responsible to assign the dev, ops and id 283When registering a bank of locks, the hwspinlock driver only needs to
264members. The lock member, OTOH, is initialized and used by the hwspinlock 284set the priv members of the locks. The rest of the members are set and
265core. 285initialized by the hwspinlock core itself.
266 286
2676. Implementation callbacks 2876. Implementation callbacks
268 288