Commit 65d54894 authored by Paul Walmsley's avatar Paul Walmsley Committed by Tony Lindgren

mach-omap2/powerdomain.c: convert rwsem to rwlock

The generic rwsem implementation of down_read() and down_write() does not
save and restore interrupt state.  This causes powerdomain code to
inadvertently enable interrupts early in the boot process, causing
init/main.c to complain.   This patch converts powerdomain locking to
r-w spinlocks instead.

I'm also curious to know if this fixes the BeagleBoard boot problem.
Signed-off-by: default avatarPaul Walmsley <paul@pwsan.com>
Signed-off-by: default avatarTony Lindgren <tony@atomide.com>
parent a59e04f0
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/rwsem.h> #include <linux/spinlock.h>
#include <linux/list.h> #include <linux/list.h>
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/err.h> #include <linux/err.h>
...@@ -38,10 +38,10 @@ ...@@ -38,10 +38,10 @@
static LIST_HEAD(pwrdm_list); static LIST_HEAD(pwrdm_list);
/* /*
* pwrdm_rwsem protects pwrdm_list add and del ops - also reused to * pwrdm_rwlock protects pwrdm_list add and del ops - also reused to
* protect pwrdm_clkdms[] during clkdm add/del ops * protect pwrdm_clkdms[] during clkdm add/del ops
*/ */
static DECLARE_RWSEM(pwrdm_rwsem); static DEFINE_RWLOCK(pwrdm_rwlock);
/* Private functions */ /* Private functions */
...@@ -131,6 +131,7 @@ void pwrdm_init(struct powerdomain **pwrdm_list) ...@@ -131,6 +131,7 @@ void pwrdm_init(struct powerdomain **pwrdm_list)
*/ */
int pwrdm_register(struct powerdomain *pwrdm) int pwrdm_register(struct powerdomain *pwrdm)
{ {
unsigned long flags;
int ret = -EINVAL; int ret = -EINVAL;
if (!pwrdm) if (!pwrdm)
...@@ -139,7 +140,7 @@ int pwrdm_register(struct powerdomain *pwrdm) ...@@ -139,7 +140,7 @@ int pwrdm_register(struct powerdomain *pwrdm)
if (!omap_chip_is(pwrdm->omap_chip)) if (!omap_chip_is(pwrdm->omap_chip))
return -EINVAL; return -EINVAL;
down_write(&pwrdm_rwsem); write_lock_irqsave(&pwrdm_rwlock, flags);
if (_pwrdm_lookup(pwrdm->name)) { if (_pwrdm_lookup(pwrdm->name)) {
ret = -EEXIST; ret = -EEXIST;
goto pr_unlock; goto pr_unlock;
...@@ -151,7 +152,7 @@ int pwrdm_register(struct powerdomain *pwrdm) ...@@ -151,7 +152,7 @@ int pwrdm_register(struct powerdomain *pwrdm)
ret = 0; ret = 0;
pr_unlock: pr_unlock:
up_write(&pwrdm_rwsem); write_unlock_irqrestore(&pwrdm_rwlock, flags);
return ret; return ret;
} }
...@@ -165,12 +166,14 @@ pr_unlock: ...@@ -165,12 +166,14 @@ pr_unlock:
*/ */
int pwrdm_unregister(struct powerdomain *pwrdm) int pwrdm_unregister(struct powerdomain *pwrdm)
{ {
unsigned long flags;
if (!pwrdm) if (!pwrdm)
return -EINVAL; return -EINVAL;
down_write(&pwrdm_rwsem); write_lock_irqsave(&pwrdm_rwlock, flags);
list_del(&pwrdm->node); list_del(&pwrdm->node);
up_write(&pwrdm_rwsem); write_unlock_irqrestore(&pwrdm_rwlock, flags);
pr_debug("powerdomain: unregistered %s\n", pwrdm->name); pr_debug("powerdomain: unregistered %s\n", pwrdm->name);
...@@ -187,13 +190,14 @@ int pwrdm_unregister(struct powerdomain *pwrdm) ...@@ -187,13 +190,14 @@ int pwrdm_unregister(struct powerdomain *pwrdm)
struct powerdomain *pwrdm_lookup(const char *name) struct powerdomain *pwrdm_lookup(const char *name)
{ {
struct powerdomain *pwrdm; struct powerdomain *pwrdm;
unsigned long flags;
if (!name) if (!name)
return NULL; return NULL;
down_read(&pwrdm_rwsem); read_lock_irqsave(&pwrdm_rwlock, flags);
pwrdm = _pwrdm_lookup(name); pwrdm = _pwrdm_lookup(name);
up_read(&pwrdm_rwsem); read_unlock_irqrestore(&pwrdm_rwlock, flags);
return pwrdm; return pwrdm;
} }
...@@ -204,7 +208,7 @@ struct powerdomain *pwrdm_lookup(const char *name) ...@@ -204,7 +208,7 @@ struct powerdomain *pwrdm_lookup(const char *name)
* *
* Call the supplied function for each registered powerdomain. The * Call the supplied function for each registered powerdomain. The
* callback function can return anything but 0 to bail out early from * callback function can return anything but 0 to bail out early from
* the iterator. The callback function is called with the pwrdm_rwsem * the iterator. The callback function is called with the pwrdm_rwlock
* held for reading, so no powerdomain structure manipulation * held for reading, so no powerdomain structure manipulation
* functions should be called from the callback, although hardware * functions should be called from the callback, although hardware
* powerdomain control functions are fine. Returns the last return * powerdomain control functions are fine. Returns the last return
...@@ -215,18 +219,19 @@ struct powerdomain *pwrdm_lookup(const char *name) ...@@ -215,18 +219,19 @@ struct powerdomain *pwrdm_lookup(const char *name)
int pwrdm_for_each(int (*fn)(struct powerdomain *pwrdm)) int pwrdm_for_each(int (*fn)(struct powerdomain *pwrdm))
{ {
struct powerdomain *temp_pwrdm; struct powerdomain *temp_pwrdm;
unsigned long flags;
int ret = 0; int ret = 0;
if (!fn) if (!fn)
return -EINVAL; return -EINVAL;
down_read(&pwrdm_rwsem); read_lock_irqsave(&pwrdm_rwlock, flags);
list_for_each_entry(temp_pwrdm, &pwrdm_list, node) { list_for_each_entry(temp_pwrdm, &pwrdm_list, node) {
ret = (*fn)(temp_pwrdm); ret = (*fn)(temp_pwrdm);
if (ret) if (ret)
break; break;
} }
up_read(&pwrdm_rwsem); read_unlock_irqrestore(&pwrdm_rwlock, flags);
return ret; return ret;
} }
...@@ -243,6 +248,7 @@ int pwrdm_for_each(int (*fn)(struct powerdomain *pwrdm)) ...@@ -243,6 +248,7 @@ int pwrdm_for_each(int (*fn)(struct powerdomain *pwrdm))
*/ */
int pwrdm_add_clkdm(struct powerdomain *pwrdm, struct clockdomain *clkdm) int pwrdm_add_clkdm(struct powerdomain *pwrdm, struct clockdomain *clkdm)
{ {
unsigned long flags;
int i; int i;
int ret = -EINVAL; int ret = -EINVAL;
...@@ -252,7 +258,7 @@ int pwrdm_add_clkdm(struct powerdomain *pwrdm, struct clockdomain *clkdm) ...@@ -252,7 +258,7 @@ int pwrdm_add_clkdm(struct powerdomain *pwrdm, struct clockdomain *clkdm)
pr_debug("powerdomain: associating clockdomain %s with powerdomain " pr_debug("powerdomain: associating clockdomain %s with powerdomain "
"%s\n", clkdm->name, pwrdm->name); "%s\n", clkdm->name, pwrdm->name);
down_write(&pwrdm_rwsem); write_lock_irqsave(&pwrdm_rwlock, flags);
for (i = 0; i < PWRDM_MAX_CLKDMS; i++) { for (i = 0; i < PWRDM_MAX_CLKDMS; i++) {
if (!pwrdm->pwrdm_clkdms[i]) if (!pwrdm->pwrdm_clkdms[i])
...@@ -278,7 +284,7 @@ int pwrdm_add_clkdm(struct powerdomain *pwrdm, struct clockdomain *clkdm) ...@@ -278,7 +284,7 @@ int pwrdm_add_clkdm(struct powerdomain *pwrdm, struct clockdomain *clkdm)
ret = 0; ret = 0;
pac_exit: pac_exit:
up_write(&pwrdm_rwsem); write_unlock_irqrestore(&pwrdm_rwlock, flags);
return ret; return ret;
} }
...@@ -295,6 +301,7 @@ pac_exit: ...@@ -295,6 +301,7 @@ pac_exit:
*/ */
int pwrdm_del_clkdm(struct powerdomain *pwrdm, struct clockdomain *clkdm) int pwrdm_del_clkdm(struct powerdomain *pwrdm, struct clockdomain *clkdm)
{ {
unsigned long flags;
int ret = -EINVAL; int ret = -EINVAL;
int i; int i;
...@@ -304,7 +311,7 @@ int pwrdm_del_clkdm(struct powerdomain *pwrdm, struct clockdomain *clkdm) ...@@ -304,7 +311,7 @@ int pwrdm_del_clkdm(struct powerdomain *pwrdm, struct clockdomain *clkdm)
pr_debug("powerdomain: dissociating clockdomain %s from powerdomain " pr_debug("powerdomain: dissociating clockdomain %s from powerdomain "
"%s\n", clkdm->name, pwrdm->name); "%s\n", clkdm->name, pwrdm->name);
down_write(&pwrdm_rwsem); write_lock_irqsave(&pwrdm_rwlock, flags);
for (i = 0; i < PWRDM_MAX_CLKDMS; i++) for (i = 0; i < PWRDM_MAX_CLKDMS; i++)
if (pwrdm->pwrdm_clkdms[i] == clkdm) if (pwrdm->pwrdm_clkdms[i] == clkdm)
...@@ -322,7 +329,7 @@ int pwrdm_del_clkdm(struct powerdomain *pwrdm, struct clockdomain *clkdm) ...@@ -322,7 +329,7 @@ int pwrdm_del_clkdm(struct powerdomain *pwrdm, struct clockdomain *clkdm)
ret = 0; ret = 0;
pdc_exit: pdc_exit:
up_write(&pwrdm_rwsem); write_unlock_irqrestore(&pwrdm_rwlock, flags);
return ret; return ret;
} }
...@@ -335,7 +342,7 @@ pdc_exit: ...@@ -335,7 +342,7 @@ pdc_exit:
* Call the supplied function for each clockdomain in the powerdomain * Call the supplied function for each clockdomain in the powerdomain
* 'pwrdm'. The callback function can return anything but 0 to bail * 'pwrdm'. The callback function can return anything but 0 to bail
* out early from the iterator. The callback function is called with * out early from the iterator. The callback function is called with
* the pwrdm_rwsem held for reading, so no powerdomain structure * the pwrdm_rwlock held for reading, so no powerdomain structure
* manipulation functions should be called from the callback, although * manipulation functions should be called from the callback, although
* hardware powerdomain control functions are fine. Returns -EINVAL * hardware powerdomain control functions are fine. Returns -EINVAL
* if presented with invalid pointers; or passes along the last return * if presented with invalid pointers; or passes along the last return
...@@ -346,18 +353,19 @@ int pwrdm_for_each_clkdm(struct powerdomain *pwrdm, ...@@ -346,18 +353,19 @@ int pwrdm_for_each_clkdm(struct powerdomain *pwrdm,
int (*fn)(struct powerdomain *pwrdm, int (*fn)(struct powerdomain *pwrdm,
struct clockdomain *clkdm)) struct clockdomain *clkdm))
{ {
unsigned long flags;
int ret = 0; int ret = 0;
int i; int i;
if (!fn) if (!fn)
return -EINVAL; return -EINVAL;
down_read(&pwrdm_rwsem); read_lock_irqsave(&pwrdm_rwlock, flags);
for (i = 0; i < PWRDM_MAX_CLKDMS && !ret; i++) for (i = 0; i < PWRDM_MAX_CLKDMS && !ret; i++)
ret = (*fn)(pwrdm, pwrdm->pwrdm_clkdms[i]); ret = (*fn)(pwrdm, pwrdm->pwrdm_clkdms[i]);
up_read(&pwrdm_rwsem); read_unlock_irqrestore(&pwrdm_rwlock, flags);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment