History

Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ohad/hwspinlock

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ohad/hwspinlock: hwspinlock: add MAINTAINERS entries hwspinlock/omap: omap_hwspinlock_remove should be __devexit hwspinlock/u8500: add hwspinlock driver hwspinlock/core: register a bank of hwspinlocks in a single API call hwspinlock/core: remove stubs for register/unregister hwspinlock/core: use a mutex to protect the radix tree hwspinlock/core/omap: fix id issues on multiple hwspinlock devices hwspinlock/omap: simplify allocation scheme hwspinlock/core: simplify 'owner' handling hwspinlock/core: simplify Kconfig Fix up trivial conflicts (addition of omap_hwspinlock_pdata, removal of omap_spinlock_latency) in arch/arm/mach-omap2/hwspinlock.c Also, do an "evil merge" to fix a compile error in omap_hsmmc.c which for some reason was reported in the same email thread as the "please pull hwspinlock changes".

Linus Torvalds committed 15 years ago

Commit 3f8ddb02 parents 30307c6 8b37fcf11 files · +516 −226Browse files

Unified · Split

11 files
  1. Documentation/hwspinlock.txt +44 −30
  2. MAINTAINERS +14 −0
  3. arch/arm/mach-omap2/hwspinlock.c +8 −1
  4. drivers/hwspinlock/Kconfig +18 −9
  5. drivers/hwspinlock/Makefile +1 −0
  6. drivers/hwspinlock/hwspinlock_core.c +127 −77
  7. drivers/hwspinlock/hwspinlock_internal.h +28 −12
  8. drivers/hwspinlock/omap_hwspinlock.c +43 −84
  9. drivers/hwspinlock/u8500_hsem.c +198 −0
  10. drivers/mmc/host/omap_hsmmc.c +1 −1
  11. include/linux/hwspinlock.h +34 −12
Documentation/hwspinlock.txt+44−30
@@ -39,23 +39,20 @@ independent, drivers. · 38 unmodified lines
3939 in case an unused hwspinlock isn't available. Users of this
4040 API will usually want to communicate the lock's id to the remote core
4141 before it can be used to achieve synchronization.
42− Can be called from an atomic context (this function will not sleep) but
43− not from within interrupt context.
42+ Should be called from a process context (might sleep).
4443
4544 struct hwspinlock *hwspin_lock_request_specific(unsigned int id);
4645 - assign a specific hwspinlock id and return its address, or NULL
4746 if that hwspinlock is already in use. Usually board code will
4847 be calling this function in order to reserve specific hwspinlock
4948 ids for predefined purposes.
50− Can be called from an atomic context (this function will not sleep) but
51− not from within interrupt context.
49+ Should be called from a process context (might sleep).
5250
5351 int hwspin_lock_free(struct hwspinlock *hwlock);
5452 - free a previously-assigned hwspinlock; returns 0 on success, or an
5553 appropriate error code on failure (e.g. -EINVAL if the hwspinlock
5654 is already free).
57− Can be called from an atomic context (this function will not sleep) but
58− not from within interrupt context.
55+ Should be called from a process context (might sleep).
5956
6057 int hwspin_lock_timeout(struct hwspinlock *hwlock, unsigned int timeout);
6158 - lock a previously-assigned hwspinlock with a timeout limit (specified in
@@ -230,45 +227,62 @@ int hwspinlock_example2(void) · 168 unmodified lines
230227
231228 4. API for implementors
232229
233− 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);
234232 - to be called from the underlying platform-specific implementation, in
235− order to register a new hwspinlock instance. Can be called from an atomic
236− context (this function will not sleep) but not from within interrupt
237− context. Returns 0 on success, or appropriate error code on failure.
233+ order to register a new hwspinlock device (which is usually a bank of
234+ numerous locks). Should be called from a process context (this function
235+ might sleep).
236+ Returns 0 on success, or appropriate error code on failure.
238237
239− struct hwspinlock *hwspin_lock_unregister(unsigned int id);
238+ int hwspin_lock_unregister(struct hwspinlock_device *bank);
240239 - to be called from the underlying vendor-specific implementation, in order
241− to unregister an existing (and unused) hwspinlock instance.
242− Can be called from an atomic context (will not sleep) but not from
243− within interrupt context.
240+ to unregister an hwspinlock device (which is usually a bank of numerous
241+ locks).
242+ Should be called from a process context (this function might sleep).
244243 Returns the address of hwspinlock on success, or NULL on error (e.g.
245244 if the hwspinlock is sill in use).
246245
247−5. struct hwspinlock
246+5. Important structs
248247
249−This struct represents an hwspinlock instance. It is registered by the
250−underlying hwspinlock implementation using the hwspin_lock_register() API.
248+struct hwspinlock_device is a device which usually contains a bank
249+of hardware locks. It is registered by the underlying hwspinlock
250+implementation using the hwspin_lock_register() API.
251251
252252 /**
253− * struct hwspinlock - vendor-specific hwspinlock implementation
254− *
255− * @dev: underlying device, will be used with runtime PM api
256− * @ops: vendor-specific hwspinlock handlers
257− * @id: a global, unique, system-wide, index of the lock.
258− * @lock: initialized and used by hwspinlock core
259− * @owner: underlying implementation module, used to maintain module ref count
253+ * struct hwspinlock_device - a device which usually spans numerous hwspinlocks
254+ * @dev: underlying device, will be used to invoke runtime PM api
255+ * @ops: platform-specific hwspinlock handlers
256+ * @base_id: id index of the first lock in this device
257+ * @num_locks: number of locks in this device
258+ * @lock: dynamically allocated array of 'struct hwspinlock'
260259 */
261−struct hwspinlock {
260+struct hwspinlock_device {
262261 struct device *dev;
263262 const struct hwspinlock_ops *ops;
264− int id;
263+ int base_id;
264+ int num_locks;
265+ struct hwspinlock lock[0];
266+};
267+
268+struct hwspinlock_device contains an array of hwspinlock structs, each
269+of 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+ */
277+struct hwspinlock {
278+ struct hwspinlock_device *bank;
265279 spinlock_t lock;
266− struct module *owner;
280+ void *priv;
267281 };
268282
269−The underlying implementation is responsible to assign the dev, ops, id and
270−owner members. The lock member, OTOH, is initialized and used by the hwspinlock
271−core.
283+When registering a bank of locks, the hwspinlock driver only needs to
284+set the priv members of the locks. The rest of the members are set and
285+initialized by the hwspinlock core itself.
272286
273287 6. Implementation callbacks
274288
MAINTAINERS+14−0
@@ -3018,6 +3018,13 @@ F: Documentation/hw_random.txt · 3017 unmodified lines
30183018 F: drivers/char/hw_random/
30193019 F: include/linux/hw_random.h
30203020
3021+HARDWARE SPINLOCK CORE
3022+M: Ohad Ben-Cohen <ohad@wizery.com>
3023+S: Maintained
3024+F: Documentation/hwspinlock.txt
3025+F: drivers/hwspinlock/hwspinlock_*
3026+F: include/linux/hwspinlock.h
3027+
30213028 HARMONY SOUND DRIVER
30223029 M: Kyle McMartin <kyle@mcmartin.ca>
30233030 L: linux-parisc@vger.kernel.org
@@ -4714,6 +4721,13 @@ S: Maintained · 1690 unmodified lines
47144721 F: drivers/video/omap2/
47154722 F: Documentation/arm/OMAP/DSS
47164723
4724+OMAP HARDWARE SPINLOCK SUPPORT
4725+M: Ohad Ben-Cohen <ohad@wizery.com>
4726+L: linux-omap@vger.kernel.org
4727+S: Maintained
4728+F: drivers/hwspinlock/omap_hwspinlock.c
4729+F: arch/arm/mach-omap2/hwspinlock.c
4730+
47174731 OMAP MMC SUPPORT
47184732 M: Jarkko Lavinen <jarkko.lavinen@nokia.com>
47194733 L: linux-omap@vger.kernel.org
arch/arm/mach-omap2/hwspinlock.c+8−1
@@ -19,10 +19,15 @@ · 18 unmodified lines
1919 #include <linux/kernel.h>
2020 #include <linux/init.h>
2121 #include <linux/err.h>
22+#include <linux/hwspinlock.h>
2223
2324 #include <plat/omap_hwmod.h>
2425 #include <plat/omap_device.h>
2526
27+static struct hwspinlock_pdata omap_hwspinlock_pdata __initdata = {
28+ .base_id = 0,
29+};
30+
2631 int __init hwspinlocks_init(void)
2732 {
2833 int retval = 0;
@@ -40,7 +45,9 @@ int __init hwspinlocks_init(void) · 11 unmodified lines
4045 if (oh == NULL)
4146 return -EINVAL;
4247
43− pdev = omap_device_build(dev_name, 0, oh, NULL, 0, NULL, 0, false);
48+ pdev = omap_device_build(dev_name, 0, oh, &omap_hwspinlock_pdata,
49+ sizeof(struct hwspinlock_pdata),
50+ NULL, 0, false);
4451 if (IS_ERR(pdev)) {
4552 pr_err("Can't build omap_device for %s:%s\n", dev_name,
4653 oh_name);
drivers/hwspinlock/Kconfig+18−9
@@ -2,22 +2,31 @@ · 1 unmodified line
22 # Generic HWSPINLOCK framework
33 #
44
5+# HWSPINLOCK always gets selected by whoever wants it.
56 config HWSPINLOCK
6− tristate "Generic Hardware Spinlock framework"
7− depends on ARCH_OMAP4
8− help
9− Say y here to support the generic hardware spinlock framework.
10− You only need to enable this if you have hardware spinlock module
11− on your system (usually only relevant if your system has remote slave
12− coprocessors).
7+ tristate
138
14− If unsure, say N.
9+menu "Hardware Spinlock drivers"
1510
1611 config HWSPINLOCK_OMAP
1712 tristate "OMAP Hardware Spinlock device"
18− depends on HWSPINLOCK && ARCH_OMAP4
13+ depends on ARCH_OMAP4
14+ select HWSPINLOCK
1915 help
2016 Say y here to support the OMAP Hardware Spinlock device (firstly
2117 introduced in OMAP4).
2218
2319 If unsure, say N.
20+
21+config HSEM_U8500
22+ tristate "STE Hardware Semaphore functionality"
23+ depends on ARCH_U8500
24+ select HWSPINLOCK
25+ help
26+ Say y here to support the STE Hardware Semaphore functionality, which
27+ provides a synchronisation mechanism for the various processor on the
28+ SoC.
29+
30+ If unsure, say N.
31+
32+endmenu
drivers/hwspinlock/Makefile+1−0
@@ -4,3 +4,4 @@ · 3 unmodified lines
44
55 obj-$(CONFIG_HWSPINLOCK) += hwspinlock_core.o
66 obj-$(CONFIG_HWSPINLOCK_OMAP) += omap_hwspinlock.o
7+obj-$(CONFIG_HSEM_U8500) += u8500_hsem.o
drivers/hwspinlock/hwspinlock_core.c+127−77
@@ -26,6 +26,7 @@ · 25 unmodified lines
2626 #include <linux/radix-tree.h>
2727 #include <linux/hwspinlock.h>
2828 #include <linux/pm_runtime.h>
29+#include <linux/mutex.h>
2930
3031 #include "hwspinlock_internal.h"
3132
@@ -52,10 +53,12 @@ · 20 unmodified lines
5253 static RADIX_TREE(hwspinlock_tree, GFP_KERNEL);
5354
5455 /*
55− * Synchronization of access to the tree is achieved using this spinlock,
56+ * Synchronization of access to the tree is achieved using this mutex,
5657 * as the radix-tree API requires that users provide all synchronisation.
58+ * A mutex is needed because we're using non-atomic radix tree allocations.
5759 */
58−static DEFINE_SPINLOCK(hwspinlock_tree_lock);
60+static DEFINE_MUTEX(hwspinlock_tree_lock);
61+
5962
6063 /**
6164 * __hwspin_trylock() - attempt to lock a specific hwspinlock
@@ -114,7 +117,7 @@ int __hwspin_trylock(struct hwspinlock *hwlock, int mode, unsigned long *flags) · 52 unmodified lines
114117 return -EBUSY;
115118
116119 /* try to take the hwspinlock device */
117− ret = hwlock->ops->trylock(hwlock);
120+ ret = hwlock->bank->ops->trylock(hwlock);
118121
119122 /* if hwlock is already taken, undo spin_trylock_* and exit */
120123 if (!ret) {
@@ -196,8 +199,8 @@ int __hwspin_lock_timeout(struct hwspinlock *hwlock, unsigned int to, · 75 unmodified lines
196199 * Allow platform-specific relax handlers to prevent
197200 * hogging the interconnect (no sleeping, though)
198201 */
199− if (hwlock->ops->relax)
200− hwlock->ops->relax(hwlock);
202+ if (hwlock->bank->ops->relax)
203+ hwlock->bank->ops->relax(hwlock);
201204 }
202205
203206 return ret;
@@ -242,7 +245,7 @@ void __hwspin_unlock(struct hwspinlock *hwlock, int mode, unsigned long *flags) · 38 unmodified lines
242245 */
243246 mb();
244247
245− hwlock->ops->unlock(hwlock);
248+ hwlock->bank->ops->unlock(hwlock);
246249
247250 /* Undo the spin_trylock{_irq, _irqsave} called while locking */
248251 if (mode == HWLOCK_IRQSTATE)
@@ -254,68 +257,37 @@ void __hwspin_unlock(struct hwspinlock *hwlock, int mode, unsigned long *flags) · 5 unmodified lines
254257 }
255258 EXPORT_SYMBOL_GPL(__hwspin_unlock);
256259
257−/**
258− * hwspin_lock_register() - register a new hw spinlock
259− * @hwlock: hwspinlock to register.
260− *
261− * This function should be called from the underlying platform-specific
262− * implementation, to register a new hwspinlock instance.
263− *
264− * Can be called from an atomic context (will not sleep) but not from
265− * within interrupt context.
266− *
267− * Returns 0 on success, or an appropriate error code on failure
268− */
269−int hwspin_lock_register(struct hwspinlock *hwlock)
260+static int hwspin_lock_register_single(struct hwspinlock *hwlock, int id)
270261 {
271262 struct hwspinlock *tmp;
272263 int ret;
273264
274− if (!hwlock || !hwlock->ops ||
275− !hwlock->ops->trylock || !hwlock->ops->unlock) {
276− pr_err("invalid parameters\n");
277− return -EINVAL;
278− }
279−
280− spin_lock_init(&hwlock->lock);
281−
282− spin_lock(&hwspinlock_tree_lock);
265+ mutex_lock(&hwspinlock_tree_lock);
283266
284− ret = radix_tree_insert(&hwspinlock_tree, hwlock->id, hwlock);
285− if (ret)
267+ ret = radix_tree_insert(&hwspinlock_tree, id, hwlock);
268+ if (ret) {
269+ if (ret == -EEXIST)
270+ pr_err("hwspinlock id %d already exists!\n", id);
286271 goto out;
272+ }
287273
288274 /* mark this hwspinlock as available */
289− tmp = radix_tree_tag_set(&hwspinlock_tree, hwlock->id,
290− HWSPINLOCK_UNUSED);
275+ tmp = radix_tree_tag_set(&hwspinlock_tree, id, HWSPINLOCK_UNUSED);
291276
292277 /* self-sanity check which should never fail */
293278 WARN_ON(tmp != hwlock);
294279
295280 out:
296− spin_unlock(&hwspinlock_tree_lock);
297− return ret;
281+ mutex_unlock(&hwspinlock_tree_lock);
282+ return 0;
298283 }
299−EXPORT_SYMBOL_GPL(hwspin_lock_register);
300284
301−/**
302− * hwspin_lock_unregister() - unregister an hw spinlock
303− * @id: index of the specific hwspinlock to unregister
304− *
305− * This function should be called from the underlying platform-specific
306− * implementation, to unregister an existing (and unused) hwspinlock.
307− *
308− * Can be called from an atomic context (will not sleep) but not from
309− * within interrupt context.
310− *
311− * Returns the address of hwspinlock @id on success, or NULL on failure
312− */
313−struct hwspinlock *hwspin_lock_unregister(unsigned int id)
285+static struct hwspinlock *hwspin_lock_unregister_single(unsigned int id)
314286 {
315287 struct hwspinlock *hwlock = NULL;
316288 int ret;
317289
318− spin_lock(&hwspinlock_tree_lock);
290+ mutex_lock(&hwspinlock_tree_lock);
319291
320292 /* make sure the hwspinlock is not in use (tag is set) */
321293 ret = radix_tree_tag_get(&hwspinlock_tree, id, HWSPINLOCK_UNUSED);
@@ -331,9 +303,91 @@ struct hwspinlock *hwspin_lock_unregister(unsigned int id) · 9 unmodified lines
331303 }
332304
333305 out:
334− spin_unlock(&hwspinlock_tree_lock);
306+ mutex_unlock(&hwspinlock_tree_lock);
335307 return hwlock;
336308 }
309+
310+/**
311+ * hwspin_lock_register() - register a new hw spinlock device
312+ * @bank: the hwspinlock device, which usually provides numerous hw locks
313+ * @dev: the backing device
314+ * @ops: hwspinlock handlers for this device
315+ * @base_id: id of the first hardware spinlock in this bank
316+ * @num_locks: number of hwspinlocks provided by this device
317+ *
318+ * This function should be called from the underlying platform-specific
319+ * implementation, to register a new hwspinlock device instance.
320+ *
321+ * Should be called from a process context (might sleep)
322+ *
323+ * Returns 0 on success, or an appropriate error code on failure
324+ */
325+int hwspin_lock_register(struct hwspinlock_device *bank, struct device *dev,
326+ const struct hwspinlock_ops *ops, int base_id, int num_locks)
327+{
328+ struct hwspinlock *hwlock;
329+ int ret = 0, i;
330+
331+ if (!bank || !ops || !dev || !num_locks || !ops->trylock ||
332+ !ops->unlock) {
333+ pr_err("invalid parameters\n");
334+ return -EINVAL;
335+ }
336+
337+ bank->dev = dev;
338+ bank->ops = ops;
339+ bank->base_id = base_id;
340+ bank->num_locks = num_locks;
341+
342+ for (i = 0; i < num_locks; i++) {
343+ hwlock = &bank->lock[i];
344+
345+ spin_lock_init(&hwlock->lock);
346+ hwlock->bank = bank;
347+
348+ ret = hwspin_lock_register_single(hwlock, i);
349+ if (ret)
350+ goto reg_failed;
351+ }
352+
353+ return 0;
354+
355+reg_failed:
356+ while (--i >= 0)
357+ hwspin_lock_unregister_single(i);
358+ return ret;
359+}
360+EXPORT_SYMBOL_GPL(hwspin_lock_register);
361+
362+/**
363+ * hwspin_lock_unregister() - unregister an hw spinlock device
364+ * @bank: the hwspinlock device, which usually provides numerous hw locks
365+ *
366+ * This function should be called from the underlying platform-specific
367+ * implementation, to unregister an existing (and unused) hwspinlock.
368+ *
369+ * Should be called from a process context (might sleep)
370+ *
371+ * Returns 0 on success, or an appropriate error code on failure
372+ */
373+int hwspin_lock_unregister(struct hwspinlock_device *bank)
374+{
375+ struct hwspinlock *hwlock, *tmp;
376+ int i;
377+
378+ for (i = 0; i < bank->num_locks; i++) {
379+ hwlock = &bank->lock[i];
380+
381+ tmp = hwspin_lock_unregister_single(bank->base_id + i);
382+ if (!tmp)
383+ return -EBUSY;
384+
385+ /* self-sanity check that should never fail */
386+ WARN_ON(tmp != hwlock);
387+ }
388+
389+ return 0;
390+}
337391 EXPORT_SYMBOL_GPL(hwspin_lock_unregister);
338392
339393 /**
@@ -348,24 +402,25 @@ EXPORT_SYMBOL_GPL(hwspin_lock_unregister); · 8 unmodified lines
348402 */
349403 static int __hwspin_lock_request(struct hwspinlock *hwlock)
350404 {
405+ struct device *dev = hwlock->bank->dev;
351406 struct hwspinlock *tmp;
352407 int ret;
353408
354409 /* prevent underlying implementation from being removed */
355− if (!try_module_get(hwlock->owner)) {
356− dev_err(hwlock->dev, "%s: can't get owner\n", __func__);
410+ if (!try_module_get(dev->driver->owner)) {
411+ dev_err(dev, "%s: can't get owner\n", __func__);
357412 return -EINVAL;
358413 }
359414
360415 /* notify PM core that power is now needed */
361− ret = pm_runtime_get_sync(hwlock->dev);
416+ ret = pm_runtime_get_sync(dev);
362417 if (ret < 0) {
363− dev_err(hwlock->dev, "%s: can't power on device\n", __func__);
418+ dev_err(dev, "%s: can't power on device\n", __func__);
364419 return ret;
365420 }
366421
367422 /* mark hwspinlock as used, should not fail */
368− tmp = radix_tree_tag_clear(&hwspinlock_tree, hwlock->id,
423+ tmp = radix_tree_tag_clear(&hwspinlock_tree, hwlock_to_id(hwlock),
369424 HWSPINLOCK_UNUSED);
370425
371426 /* self-sanity check that should never fail */
@@ -387,7 +442,7 @@ int hwspin_lock_get_id(struct hwspinlock *hwlock) · 15 unmodified lines
387442 return -EINVAL;
388443 }
389444
390− return hwlock->id;
445+ return hwlock_to_id(hwlock);
391446 }
392447 EXPORT_SYMBOL_GPL(hwspin_lock_get_id);
393448
@@ -400,9 +455,7 @@ EXPORT_SYMBOL_GPL(hwspin_lock_get_id); · 6 unmodified lines
400455 * to the remote core before it can be used for synchronization (to get the
401456 * id of a given hwlock, use hwspin_lock_get_id()).
402457 *
403− * Can be called from an atomic context (will not sleep) but not from
404− * within interrupt context (simply because there is no use case for
405− * that yet).
458+ * Should be called from a process context (might sleep)
406459 *
407460 * Returns the address of the assigned hwspinlock, or NULL on error
408461 */
@@ -411,7 +464,7 @@ struct hwspinlock *hwspin_lock_request(void) · 2 unmodified lines
411464 struct hwspinlock *hwlock;
412465 int ret;
413466
414− spin_lock(&hwspinlock_tree_lock);
467+ mutex_lock(&hwspinlock_tree_lock);
415468
416469 /* look for an unused lock */
417470 ret = radix_tree_gang_lookup_tag(&hwspinlock_tree, (void **)&hwlock,
@@ -431,7 +484,7 @@ struct hwspinlock *hwspin_lock_request(void) · 13 unmodified lines
431484 hwlock = NULL;
432485
433486 out:
434− spin_unlock(&hwspinlock_tree_lock);
487+ mutex_unlock(&hwspinlock_tree_lock);
435488 return hwlock;
436489 }
437490 EXPORT_SYMBOL_GPL(hwspin_lock_request);
@@ -445,9 +498,7 @@ EXPORT_SYMBOL_GPL(hwspin_lock_request); · 7 unmodified lines
445498 * Usually early board code will be calling this function in order to
446499 * reserve specific hwspinlock ids for predefined purposes.
447500 *
448− * Can be called from an atomic context (will not sleep) but not from
449− * within interrupt context (simply because there is no use case for
450− * that yet).
501+ * Should be called from a process context (might sleep)
451502 *
452503 * Returns the address of the assigned hwspinlock, or NULL on error
453504 */
@@ -456,7 +507,7 @@ struct hwspinlock *hwspin_lock_request_specific(unsigned int id) · 2 unmodified lines
456507 struct hwspinlock *hwlock;
457508 int ret;
458509
459− spin_lock(&hwspinlock_tree_lock);
510+ mutex_lock(&hwspinlock_tree_lock);
460511
461512 /* make sure this hwspinlock exists */
462513 hwlock = radix_tree_lookup(&hwspinlock_tree, id);
@@ -466,7 +517,7 @@ struct hwspinlock *hwspin_lock_request_specific(unsigned int id) · 3 unmodified lines
466517 }
467518
468519 /* sanity check (this shouldn't happen) */
469− WARN_ON(hwlock->id != id);
520+ WARN_ON(hwlock_to_id(hwlock) != id);
470521
471522 /* make sure this hwspinlock is unused */
472523 ret = radix_tree_tag_get(&hwspinlock_tree, id, HWSPINLOCK_UNUSED);
@@ -482,7 +533,7 @@ struct hwspinlock *hwspin_lock_request_specific(unsigned int id) · 9 unmodified lines
482533 hwlock = NULL;
483534
484535 out:
485− spin_unlock(&hwspinlock_tree_lock);
536+ mutex_unlock(&hwspinlock_tree_lock);
486537 return hwlock;
487538 }
488539 EXPORT_SYMBOL_GPL(hwspin_lock_request_specific);
@@ -495,14 +546,13 @@ EXPORT_SYMBOL_GPL(hwspin_lock_request_specific); · 6 unmodified lines
495546 * Should only be called with an @hwlock that was retrieved from
496547 * an earlier call to omap_hwspin_lock_request{_specific}.
497548 *
498− * Can be called from an atomic context (will not sleep) but not from
499− * within interrupt context (simply because there is no use case for
500− * that yet).
549+ * Should be called from a process context (might sleep)
501550 *
502551 * Returns 0 on success, or an appropriate error code on failure
503552 */
504553 int hwspin_lock_free(struct hwspinlock *hwlock)
505554 {
555+ struct device *dev = hwlock->bank->dev;
506556 struct hwspinlock *tmp;
507557 int ret;
508558
@@ -511,34 +561,34 @@ int hwspin_lock_free(struct hwspinlock *hwlock) · 2 unmodified lines
511561 return -EINVAL;
512562 }
513563
514− spin_lock(&hwspinlock_tree_lock);
564+ mutex_lock(&hwspinlock_tree_lock);
515565
516566 /* make sure the hwspinlock is used */
517− ret = radix_tree_tag_get(&hwspinlock_tree, hwlock->id,
567+ ret = radix_tree_tag_get(&hwspinlock_tree, hwlock_to_id(hwlock),
518568 HWSPINLOCK_UNUSED);
519569 if (ret == 1) {
520− dev_err(hwlock->dev, "%s: hwlock is already free\n", __func__);
570+ dev_err(dev, "%s: hwlock is already free\n", __func__);
521571 dump_stack();
522572 ret = -EINVAL;
523573 goto out;
524574 }
525575
526576 /* notify the underlying device that power is not needed */
527− ret = pm_runtime_put(hwlock->dev);
577+ ret = pm_runtime_put(dev);
528578 if (ret < 0)
529579 goto out;
530580
531581 /* mark this hwspinlock as available */
532− tmp = radix_tree_tag_set(&hwspinlock_tree, hwlock->id,
582+ tmp = radix_tree_tag_set(&hwspinlock_tree, hwlock_to_id(hwlock),
533583 HWSPINLOCK_UNUSED);
534584
535585 /* sanity check (this shouldn't happen) */
536586 WARN_ON(tmp != hwlock);
537587
538− module_put(hwlock->owner);
588+ module_put(dev->driver->owner);
539589
540590 out:
541− spin_unlock(&hwspinlock_tree_lock);
591+ mutex_unlock(&hwspinlock_tree_lock);
542592 return ret;
543593 }
544594 EXPORT_SYMBOL_GPL(hwspin_lock_free);
drivers/hwspinlock/hwspinlock_internal.h+28−12
@@ -21,6 +21,8 @@ · 20 unmodified lines
2121 #include <linux/spinlock.h>
2222 #include <linux/device.h>
2323
24+struct hwspinlock_device;
25+
2426 /**
2527 * struct hwspinlock_ops - platform-specific hwspinlock handlers
2628 *
@@ -39,23 +41,37 @@ struct hwspinlock_ops { · 12 unmodified lines
3941
4042 /**
4143 * struct hwspinlock - this struct represents a single hwspinlock instance
42− *
43− * @dev: underlying device, will be used to invoke runtime PM api
44− * @ops: platform-specific hwspinlock handlers
45− * @id: a global, unique, system-wide, index of the lock.
44+ * @bank: the hwspinlock_device structure which owns this lock
4645 * @lock: initialized and used by hwspinlock core
47− * @owner: underlying implementation module, used to maintain module ref count
48− *
49− * Note: currently simplicity was opted for, but later we can squeeze some
50− * memory bytes by grouping the dev, ops and owner members in a single
51− * per-platform struct, and have all hwspinlocks point at it.
46+ * @priv: private data, owned by the underlying platform-specific hwspinlock drv
5247 */
5348 struct hwspinlock {
49+ 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+ */
62+struct hwspinlock_device {
5463 struct device *dev;
5564 const struct hwspinlock_ops *ops;
56− int id;
57− spinlock_t lock;
58− struct module *owner;
65+ int base_id;
66+ int num_locks;
67+ struct hwspinlock lock[0];
5968 };
6069
70+static 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+
6177 #endif /* __HWSPINLOCK_HWSPINLOCK_H */
drivers/hwspinlock/omap_hwspinlock.c+43−84
@@ -41,33 +41,20 @@ · 40 unmodified lines
4141 #define SPINLOCK_NOTTAKEN (0) /* free */
4242 #define SPINLOCK_TAKEN (1) /* locked */
4343
44−#define to_omap_hwspinlock(lock) \
45− container_of(lock, struct omap_hwspinlock, lock)
46−
47−struct omap_hwspinlock {
48− struct hwspinlock lock;
49− void __iomem *addr;
50−};
51−
52−struct omap_hwspinlock_state {
53− int num_locks; /* Total number of locks in system */
54− void __iomem *io_base; /* Mapped base address */
55−};
56−
5744 static int omap_hwspinlock_trylock(struct hwspinlock *lock)
5845 {
59− struct omap_hwspinlock *omap_lock = to_omap_hwspinlock(lock);
46+ void __iomem *lock_addr = lock->priv;
6047
6148 /* attempt to acquire the lock by reading its value */
62− return (SPINLOCK_NOTTAKEN == readl(omap_lock->addr));
49+ return (SPINLOCK_NOTTAKEN == readl(lock_addr));
6350 }
6451
6552 static void omap_hwspinlock_unlock(struct hwspinlock *lock)
6653 {
67− struct omap_hwspinlock *omap_lock = to_omap_hwspinlock(lock);
54+ void __iomem *lock_addr = lock->priv;
6855
6956 /* release the lock by writing 0 to it */
70− writel(SPINLOCK_NOTTAKEN, omap_lock->addr);
57+ writel(SPINLOCK_NOTTAKEN, lock_addr);
7158 }
7259
7360 /*
@@ -93,26 +80,23 @@ static const struct hwspinlock_ops omap_hwspinlock_ops = { · 19 unmodified lines
9380
9481 static int __devinit omap_hwspinlock_probe(struct platform_device *pdev)
9582 {
96− struct omap_hwspinlock *omap_lock;
97− struct omap_hwspinlock_state *state;
98− struct hwspinlock *lock;
83+ struct hwspinlock_pdata *pdata = pdev->dev.platform_data;
84+ struct hwspinlock_device *bank;
85+ struct hwspinlock *hwlock;
9986 struct resource *res;
10087 void __iomem *io_base;
101− int i, ret;
88+ int num_locks, i, ret;
89+
90+ if (!pdata)
91+ return -ENODEV;
10292
10393 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
10494 if (!res)
10595 return -ENODEV;
10696
107− state = kzalloc(sizeof(*state), GFP_KERNEL);
108− if (!state)
109− return -ENOMEM;
110−
11197 io_base = ioremap(res->start, resource_size(res));
112− if (!io_base) {
113− ret = -ENOMEM;
114− goto free_state;
115− }
98+ if (!io_base)
99+ return -ENOMEM;
116100
117101 /* Determine number of locks */
118102 i = readl(io_base + SYSSTATUS_OFFSET);
@@ -124,10 +108,18 @@ static int __devinit omap_hwspinlock_probe(struct platform_device *pdev) · 5 unmodified lines
124108 goto iounmap_base;
125109 }
126110
127− state->num_locks = i * 32;
128− state->io_base = io_base;
111+ num_locks = i * 32; /* actual number of locks in this device */
112+
113+ bank = kzalloc(sizeof(*bank) + num_locks * sizeof(*hwlock), GFP_KERNEL);
114+ if (!bank) {
115+ ret = -ENOMEM;
116+ goto iounmap_base;
117+ }
118+
119+ platform_set_drvdata(pdev, bank);
129120
130− platform_set_drvdata(pdev, state);
121+ for (i = 0, hwlock = &bank->lock[0]; i < num_locks; i++, hwlock++)
122+ hwlock->priv = io_base + LOCK_BASE_OFFSET + sizeof(u32) * i;
131123
132124 /*
133125 * runtime PM will make sure the clock of this module is
@@ -135,79 +127,46 @@ static int __devinit omap_hwspinlock_probe(struct platform_device *pdev) · 1 unmodified line
135127 */
136128 pm_runtime_enable(&pdev->dev);
137129
138− for (i = 0; i < state->num_locks; i++) {
139− omap_lock = kzalloc(sizeof(*omap_lock), GFP_KERNEL);
140− if (!omap_lock) {
141− ret = -ENOMEM;
142− goto free_locks;
143− }
144−
145− omap_lock->lock.dev = &pdev->dev;
146− omap_lock->lock.owner = THIS_MODULE;
147− omap_lock->lock.id = i;
148− omap_lock->lock.ops = &omap_hwspinlock_ops;
149− omap_lock->addr = io_base + LOCK_BASE_OFFSET + sizeof(u32) * i;
150−
151− ret = hwspin_lock_register(&omap_lock->lock);
152− if (ret) {
153− kfree(omap_lock);
154− goto free_locks;
155− }
156− }
130+ ret = hwspin_lock_register(bank, &pdev->dev, &omap_hwspinlock_ops,
131+ pdata->base_id, num_locks);
132+ if (ret)
133+ goto reg_fail;
157134
158135 return 0;
159136
160−free_locks:
161− while (--i >= 0) {
162− lock = hwspin_lock_unregister(i);
163− /* this should't happen, but let's give our best effort */
164− if (!lock) {
165− dev_err(&pdev->dev, "%s: cleanups failed\n", __func__);
166− continue;
167− }
168− omap_lock = to_omap_hwspinlock(lock);
169− kfree(omap_lock);
170− }
137+reg_fail:
171138 pm_runtime_disable(&pdev->dev);
139+ kfree(bank);
172140 iounmap_base:
173141 iounmap(io_base);
174−free_state:
175− kfree(state);
176142 return ret;
177143 }
178144
179−static int omap_hwspinlock_remove(struct platform_device *pdev)
145+static int __devexit omap_hwspinlock_remove(struct platform_device *pdev)
180146 {
181− struct omap_hwspinlock_state *state = platform_get_drvdata(pdev);
182− struct hwspinlock *lock;
183− struct omap_hwspinlock *omap_lock;
184− int i;
185−
186− for (i = 0; i < state->num_locks; i++) {
187− lock = hwspin_lock_unregister(i);
188− /* this shouldn't happen at this point. if it does, at least
189− * don't continue with the remove */
190− if (!lock) {
191− dev_err(&pdev->dev, "%s: failed on %d\n", __func__, i);
192− return -EBUSY;
193− }
194−
195− omap_lock = to_omap_hwspinlock(lock);
196− kfree(omap_lock);
147+ struct hwspinlock_device *bank = platform_get_drvdata(pdev);
148+ void __iomem *io_base = bank->lock[0].priv - LOCK_BASE_OFFSET;
149+ int ret;
150+
151+ ret = hwspin_lock_unregister(bank);
152+ if (ret) {
153+ dev_err(&pdev->dev, "%s failed: %d\n", __func__, ret);
154+ return ret;
197155 }
198156
199157 pm_runtime_disable(&pdev->dev);
200− iounmap(state->io_base);
201− kfree(state);
158+ iounmap(io_base);
159+ kfree(bank);
202160
203161 return 0;
204162 }
205163
206164 static struct platform_driver omap_hwspinlock_driver = {
207165 .probe = omap_hwspinlock_probe,
208− .remove = omap_hwspinlock_remove,
166+ .remove = __devexit_p(omap_hwspinlock_remove),
209167 .driver = {
210168 .name = "omap_hwspinlock",
169+ .owner = THIS_MODULE,
211170 },
212171 };
213172
drivers/hwspinlock/u8500_hsem.c+198−0
@@ -0,0 +1,198 @@
1+/*
2+ * u8500 HWSEM driver
3+ *
4+ * Copyright (C) 2010-2011 ST-Ericsson
5+ *
6+ * Implements u8500 semaphore handling for protocol 1, no interrupts.
7+ *
8+ * Author: Mathieu Poirier <mathieu.poirier@linaro.org>
9+ * Heavily borrowed from the work of :
10+ * Simon Que <sque@ti.com>
11+ * Hari Kanigeri <h-kanigeri2@ti.com>
12+ * Ohad Ben-Cohen <ohad@wizery.com>
13+ *
14+ * This program is free software; you can redistribute it and/or
15+ * modify it under the terms of the GNU General Public License
16+ * version 2 as published by the Free Software Foundation.
17+ *
18+ * This program is distributed in the hope that it will be useful, but
19+ * WITHOUT ANY WARRANTY; without even the implied warranty of
20+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21+ * General Public License for more details.
22+ */
23+
24+#include <linux/delay.h>
25+#include <linux/io.h>
26+#include <linux/pm_runtime.h>
27+#include <linux/slab.h>
28+#include <linux/spinlock.h>
29+#include <linux/hwspinlock.h>
30+#include <linux/platform_device.h>
31+
32+#include "hwspinlock_internal.h"
33+
34+/*
35+ * Implementation of STE's HSem protocol 1 without interrutps.
36+ * The only masterID we allow is '0x01' to force people to use
37+ * HSems for synchronisation between processors rather than processes
38+ * on the ARM core.
39+ */
40+
41+#define U8500_MAX_SEMAPHORE 32 /* a total of 32 semaphore */
42+#define RESET_SEMAPHORE (0) /* free */
43+
44+/*
45+ * CPU ID for master running u8500 kernel.
46+ * Hswpinlocks should only be used to synchonise operations
47+ * between the Cortex A9 core and the other CPUs. Hence
48+ * forcing the masterID to a preset value.
49+ */
50+#define HSEM_MASTER_ID 0x01
51+
52+#define HSEM_REGISTER_OFFSET 0x08
53+
54+#define HSEM_CTRL_REG 0x00
55+#define HSEM_ICRALL 0x90
56+#define HSEM_PROTOCOL_1 0x01
57+
58+static int u8500_hsem_trylock(struct hwspinlock *lock)
59+{
60+ void __iomem *lock_addr = lock->priv;
61+
62+ writel(HSEM_MASTER_ID, lock_addr);
63+
64+ /* get only first 4 bit and compare to masterID.
65+ * if equal, we have the semaphore, otherwise
66+ * someone else has it.
67+ */
68+ return (HSEM_MASTER_ID == (0x0F & readl(lock_addr)));
69+}
70+
71+static void u8500_hsem_unlock(struct hwspinlock *lock)
72+{
73+ void __iomem *lock_addr = lock->priv;
74+
75+ /* release the lock by writing 0 to it */
76+ writel(RESET_SEMAPHORE, lock_addr);
77+}
78+
79+/*
80+ * u8500: what value is recommended here ?
81+ */
82+static void u8500_hsem_relax(struct hwspinlock *lock)
83+{
84+ ndelay(50);
85+}
86+
87+static const struct hwspinlock_ops u8500_hwspinlock_ops = {
88+ .trylock = u8500_hsem_trylock,
89+ .unlock = u8500_hsem_unlock,
90+ .relax = u8500_hsem_relax,
91+};
92+
93+static int __devinit u8500_hsem_probe(struct platform_device *pdev)
94+{
95+ struct hwspinlock_pdata *pdata = pdev->dev.platform_data;
96+ struct hwspinlock_device *bank;
97+ struct hwspinlock *hwlock;
98+ struct resource *res;
99+ void __iomem *io_base;
100+ int i, ret, num_locks = U8500_MAX_SEMAPHORE;
101+ ulong val;
102+
103+ if (!pdata)
104+ return -ENODEV;
105+
106+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
107+ if (!res)
108+ return -ENODEV;
109+
110+ io_base = ioremap(res->start, resource_size(res));
111+ if (!io_base) {
112+ ret = -ENOMEM;
113+ goto free_state;
114+ }
115+
116+ /* make sure protocol 1 is selected */
117+ val = readl(io_base + HSEM_CTRL_REG);
118+ writel((val & ~HSEM_PROTOCOL_1), io_base + HSEM_CTRL_REG);
119+
120+ /* clear all interrupts */
121+ writel(0xFFFF, io_base + HSEM_ICRALL);
122+
123+ bank = kzalloc(sizeof(*bank) + num_locks * sizeof(*hwlock), GFP_KERNEL);
124+ if (!bank) {
125+ ret = -ENOMEM;
126+ goto iounmap_base;
127+ }
128+
129+ platform_set_drvdata(pdev, bank);
130+
131+ for (i = 0, hwlock = &bank->lock[0]; i < num_locks; i++, hwlock++)
132+ hwlock->priv = io_base + HSEM_REGISTER_OFFSET + sizeof(u32) * i;
133+
134+ /* no pm needed for HSem but required to comply with hwspilock core */
135+ pm_runtime_enable(&pdev->dev);
136+
137+ ret = hwspin_lock_register(bank, &pdev->dev, &u8500_hwspinlock_ops,
138+ pdata->base_id, num_locks);
139+ if (ret)
140+ goto reg_fail;
141+
142+ return 0;
143+
144+reg_fail:
145+ pm_runtime_disable(&pdev->dev);
146+ kfree(bank);
147+iounmap_base:
148+ iounmap(io_base);
149+ return ret;
150+}
151+
152+static int __devexit u8500_hsem_remove(struct platform_device *pdev)
153+{
154+ struct hwspinlock_device *bank = platform_get_drvdata(pdev);
155+ void __iomem *io_base = bank->lock[0].priv - HSEM_REGISTER_OFFSET;
156+ int ret;
157+
158+ /* clear all interrupts */
159+ writel(0xFFFF, io_base + HSEM_ICRALL);
160+
161+ ret = hwspin_lock_unregister(bank);
162+ if (ret) {
163+ dev_err(&pdev->dev, "%s failed: %d\n", __func__, ret);
164+ return ret;
165+ }
166+
167+ pm_runtime_disable(&pdev->dev);
168+ iounmap(io_base);
169+ kfree(bank);
170+
171+ return 0;
172+}
173+
174+static struct platform_driver u8500_hsem_driver = {
175+ .probe = u8500_hsem_probe,
176+ .remove = __devexit_p(u8500_hsem_remove),
177+ .driver = {
178+ .name = "u8500_hsem",
179+ .owner = THIS_MODULE,
180+ },
181+};
182+
183+static int __init u8500_hsem_init(void)
184+{
185+ return platform_driver_register(&u8500_hsem_driver);
186+}
187+/* board init code might need to reserve hwspinlocks for predefined purposes */
188+postcore_initcall(u8500_hsem_init);
189+
190+static void __exit u8500_hsem_exit(void)
191+{
192+ platform_driver_unregister(&u8500_hsem_driver);
193+}
194+module_exit(u8500_hsem_exit);
195+
196+MODULE_LICENSE("GPL v2");
197+MODULE_DESCRIPTION("Hardware Spinlock driver for u8500");
198+MODULE_AUTHOR("Mathieu Poirier <mathieu.poirier@linaro.org>");
drivers/mmc/host/omap_hsmmc.c+1−1
@@ -1270,7 +1270,7 @@ static void omap_hsmmc_protect_card(struct omap_hsmmc_host *host) · 1269 unmodified lines
12701270 }
12711271 } else {
12721272 if (!host->protect_card) {
1273− pr_info"%s: cover is open, "
1273+ pr_info("%s: cover is open, "
12741274 "card is now inaccessible\n",
12751275 mmc_hostname(host->mmc));
12761276 host->protect_card = 1;
include/linux/hwspinlock.h+34−12
@@ -20,17 +20,49 @@ · 19 unmodified lines
2020
2121 #include <linux/err.h>
2222 #include <linux/sched.h>
23+#include <linux/device.h>
2324
2425 /* hwspinlock mode argument */
2526 #define HWLOCK_IRQSTATE 0x01 /* Disable interrupts, save state */
2627 #define HWLOCK_IRQ 0x02 /* Disable interrupts, don't save state */
2728
2829 struct hwspinlock;
30+struct hwspinlock_device;
31+struct hwspinlock_ops;
32+
33+/**
34+ * struct hwspinlock_pdata - platform data for hwspinlock drivers
35+ * @base_id: base id for this hwspinlock device
36+ *
37+ * hwspinlock devices provide system-wide hardware locks that are used
38+ * by remote processors that have no other way to achieve synchronization.
39+ *
40+ * To achieve that, each physical lock must have a system-wide id number
41+ * that is agreed upon, otherwise remote processors can't possibly assume
42+ * they're using the same hardware lock.
43+ *
44+ * Usually boards have a single hwspinlock device, which provides several
45+ * hwspinlocks, and in this case, they can be trivially numbered 0 to
46+ * (num-of-locks - 1).
47+ *
48+ * In case boards have several hwspinlocks devices, a different base id
49+ * should be used for each hwspinlock device (they can't all use 0 as
50+ * a starting id!).
51+ *
52+ * This platform data structure should be used to provide the base id
53+ * for each device (which is trivially 0 when only a single hwspinlock
54+ * device exists). It can be shared between different platforms, hence
55+ * its location.
56+ */
57+struct hwspinlock_pdata {
58+ int base_id;
59+};
2960
3061 #if defined(CONFIG_HWSPINLOCK) || defined(CONFIG_HWSPINLOCK_MODULE)
3162
32−int hwspin_lock_register(struct hwspinlock *lock);
33−struct hwspinlock *hwspin_lock_unregister(unsigned int id);
63+int hwspin_lock_register(struct hwspinlock_device *bank, struct device *dev,
64+ const struct hwspinlock_ops *ops, int base_id, int num_locks);
65+int hwspin_lock_unregister(struct hwspinlock_device *bank);
3466 struct hwspinlock *hwspin_lock_request(void);
3567 struct hwspinlock *hwspin_lock_request_specific(unsigned int id);
3668 int hwspin_lock_free(struct hwspinlock *hwlock);
@@ -94,16 +126,6 @@ static inline int hwspin_lock_get_id(struct hwspinlock *hwlock) · 57 unmodified lines
94126 return 0;
95127 }
96128
97−static inline int hwspin_lock_register(struct hwspinlock *hwlock)
98−{
99− return -ENODEV;
100−}
101−
102−static inline struct hwspinlock *hwspin_lock_unregister(unsigned int id)
103−{
104− return NULL;
105−}
106−
107129 #endif /* !CONFIG_HWSPINLOCK */
108130
109131 /**

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t