Skip to content

Commit

Permalink
[POWERPC] powermac: disallow pmu sleep notifiers from aborting sleep
Browse files Browse the repository at this point in the history
Tracing through the code, no current PMU sleep notifier can abort sleep.
Since no new PMU sleep notifiers should be added, this patch simplifies the
code and removes the ability to abort sleep.

Signed-off-by: Johannes Berg <[email protected]>
Acked-by: Benjamin Herrenschmidt <[email protected]>
Signed-off-by: Paul Mackerras <[email protected]>
  • Loading branch information
jmberg authored and paulusmack committed Mar 26, 2007
1 parent 17e638b commit 70b52b3
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 88 deletions.
42 changes: 9 additions & 33 deletions drivers/macintosh/adb.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ static int autopoll_devs;
int __adb_probe_sync;

#ifdef CONFIG_PM
static int adb_notify_sleep(struct pmu_sleep_notifier *self, int when);
static void adb_notify_sleep(struct pmu_sleep_notifier *self, int when);
static struct pmu_sleep_notifier adb_sleep_notifier = {
adb_notify_sleep,
SLEEP_LEVEL_ADB,
Expand Down Expand Up @@ -340,11 +340,9 @@ __initcall(adb_init);
/*
* notify clients before sleep and reset bus afterwards
*/
int
void
adb_notify_sleep(struct pmu_sleep_notifier *self, int when)
{
int ret;

switch (when) {
case PBOOK_SLEEP_REQUEST:
adb_got_sleep = 1;
Expand All @@ -353,51 +351,31 @@ adb_notify_sleep(struct pmu_sleep_notifier *self, int when)
/* Stop autopoll */
if (adb_controller->autopoll)
adb_controller->autopoll(0);
ret = blocking_notifier_call_chain(&adb_client_list,
ADB_MSG_POWERDOWN, NULL);
if (ret & NOTIFY_STOP_MASK) {
up(&adb_probe_mutex);
return PBOOK_SLEEP_REFUSE;
}
break;
case PBOOK_SLEEP_REJECT:
if (adb_got_sleep) {
adb_got_sleep = 0;
up(&adb_probe_mutex);
adb_reset_bus();
}
break;

case PBOOK_SLEEP_NOW:
blocking_notifier_call_chain(&adb_client_list,
ADB_MSG_POWERDOWN, NULL);
break;
case PBOOK_WAKE:
adb_got_sleep = 0;
up(&adb_probe_mutex);
adb_reset_bus();
break;
}
return PBOOK_SLEEP_OK;
}
#endif /* CONFIG_PM */

static int
do_adb_reset_bus(void)
{
int ret, nret;
int ret;

if (adb_controller == NULL)
return -ENXIO;

if (adb_controller->autopoll)
adb_controller->autopoll(0);

nret = blocking_notifier_call_chain(&adb_client_list,
ADB_MSG_PRE_RESET, NULL);
if (nret & NOTIFY_STOP_MASK) {
if (adb_controller->autopoll)
adb_controller->autopoll(autopoll_devs);
return -EBUSY;
}
blocking_notifier_call_chain(&adb_client_list,
ADB_MSG_PRE_RESET, NULL);

if (sleepy_trackpad) {
/* Let the trackpad settle down */
Expand Down Expand Up @@ -427,10 +405,8 @@ do_adb_reset_bus(void)
}
up(&adb_handler_sem);

nret = blocking_notifier_call_chain(&adb_client_list,
ADB_MSG_POST_RESET, NULL);
if (nret & NOTIFY_STOP_MASK)
return -EBUSY;
blocking_notifier_call_chain(&adb_client_list,
ADB_MSG_POST_RESET, NULL);

return ret;
}
Expand Down
13 changes: 4 additions & 9 deletions drivers/macintosh/apm_emu.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ static DECLARE_WAIT_QUEUE_HEAD(apm_waitqueue);
static DECLARE_WAIT_QUEUE_HEAD(apm_suspend_waitqueue);
static struct apm_user * user_list;

static int apm_notify_sleep(struct pmu_sleep_notifier *self, int when);
static void apm_notify_sleep(struct pmu_sleep_notifier *self, int when);
static struct pmu_sleep_notifier apm_sleep_notifier = {
apm_notify_sleep,
SLEEP_LEVEL_USERLAND,
Expand Down Expand Up @@ -352,7 +352,7 @@ static int do_open(struct inode * inode, struct file * filp)
* doesn't provide a way to NAK, but this could be added
* here.
*/
static int wait_all_suspend(void)
static void wait_all_suspend(void)
{
DECLARE_WAITQUEUE(wait, current);

Expand All @@ -366,24 +366,19 @@ static int wait_all_suspend(void)
remove_wait_queue(&apm_suspend_waitqueue, &wait);

DBG("apm_emu: wait_all_suspend() - complete !\n");

return 1;
}

static int apm_notify_sleep(struct pmu_sleep_notifier *self, int when)
static void apm_notify_sleep(struct pmu_sleep_notifier *self, int when)
{
switch(when) {
case PBOOK_SLEEP_REQUEST:
queue_event(APM_SYS_SUSPEND, NULL);
if (!wait_all_suspend())
return PBOOK_SLEEP_REFUSE;
wait_all_suspend();
break;
case PBOOK_SLEEP_REJECT:
case PBOOK_WAKE:
queue_event(APM_NORMAL_RESUME, NULL);
break;
}
return PBOOK_SLEEP_OK;
}

#define APM_CRITICAL 10
Expand Down
4 changes: 1 addition & 3 deletions drivers/macintosh/via-pmu-led.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static struct led_classdev pmu_led = {
};

#ifdef CONFIG_PM
static int pmu_led_sleep_call(struct pmu_sleep_notifier *self, int when)
static void pmu_led_sleep_call(struct pmu_sleep_notifier *self, int when)
{
unsigned long flags;

Expand All @@ -99,8 +99,6 @@ static int pmu_led_sleep_call(struct pmu_sleep_notifier *self, int when)
break;
}
spin_unlock_irqrestore(&pmu_blink_lock, flags);

return PBOOK_SLEEP_OK;
}

static struct pmu_sleep_notifier via_pmu_led_sleep_notif = {
Expand Down
36 changes: 6 additions & 30 deletions drivers/macintosh/via-pmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -1769,35 +1769,21 @@ EXPORT_SYMBOL(pmu_unregister_sleep_notifier);
#if defined(CONFIG_PM) && defined(CONFIG_PPC32)

/* Sleep is broadcast last-to-first */
static int
broadcast_sleep(int when, int fallback)
static void broadcast_sleep(int when)
{
int ret = PBOOK_SLEEP_OK;
struct list_head *list;
struct pmu_sleep_notifier *notifier;

for (list = sleep_notifiers.prev; list != &sleep_notifiers;
list = list->prev) {
notifier = list_entry(list, struct pmu_sleep_notifier, list);
ret = notifier->notifier_call(notifier, when);
if (ret != PBOOK_SLEEP_OK) {
printk(KERN_DEBUG "sleep %d rejected by %p (%p)\n",
when, notifier, notifier->notifier_call);
for (; list != &sleep_notifiers; list = list->next) {
notifier = list_entry(list, struct pmu_sleep_notifier, list);
notifier->notifier_call(notifier, fallback);
}
return ret;
}
notifier->notifier_call(notifier, when);
}
return ret;
}

/* Wake is broadcast first-to-last */
static int
broadcast_wake(void)
static void broadcast_wake(void)
{
int ret = PBOOK_SLEEP_OK;
struct list_head *list;
struct pmu_sleep_notifier *notifier;

Expand All @@ -1806,7 +1792,6 @@ broadcast_wake(void)
notifier = list_entry(list, struct pmu_sleep_notifier, list);
notifier->notifier_call(notifier, PBOOK_WAKE);
}
return ret;
}

/*
Expand Down Expand Up @@ -2013,12 +1998,8 @@ pmac_suspend_devices(void)

pm_prepare_console();

/* Notify old-style device drivers & userland */
ret = broadcast_sleep(PBOOK_SLEEP_REQUEST, PBOOK_SLEEP_REJECT);
if (ret != PBOOK_SLEEP_OK) {
printk(KERN_ERR "Sleep rejected by drivers\n");
return -EBUSY;
}
/* Notify old-style device drivers */
broadcast_sleep(PBOOK_SLEEP_REQUEST);

/* Sync the disks. */
/* XXX It would be nice to have some way to ensure that
Expand All @@ -2028,12 +2009,7 @@ pmac_suspend_devices(void)
*/
sys_sync();

/* Sleep can fail now. May not be very robust but useful for debugging */
ret = broadcast_sleep(PBOOK_SLEEP_NOW, PBOOK_WAKE);
if (ret != PBOOK_SLEEP_OK) {
printk(KERN_ERR "Driver sleep failed\n");
return -EBUSY;
}
broadcast_sleep(PBOOK_SLEEP_NOW);

/* Send suspend call to devices, hold the device core's dpm_sem */
ret = device_suspend(PMSG_SUSPEND);
Expand Down
12 changes: 2 additions & 10 deletions include/linux/pmu.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,24 +168,16 @@ extern int pmu_get_model(void);

struct pmu_sleep_notifier
{
int (*notifier_call)(struct pmu_sleep_notifier *self, int when);
void (*notifier_call)(struct pmu_sleep_notifier *self, int when);
int priority;
struct list_head list;
};

/* Code values for calling sleep/wakeup handlers
*
* Note: If a sleep request got cancelled, all drivers will get
* the PBOOK_SLEEP_REJECT, even those who didn't get the PBOOK_SLEEP_REQUEST.
*/
#define PBOOK_SLEEP_REQUEST 1
#define PBOOK_SLEEP_NOW 2
#define PBOOK_SLEEP_REJECT 3
#define PBOOK_WAKE 4

/* Result codes returned by the notifiers */
#define PBOOK_SLEEP_OK 0
#define PBOOK_SLEEP_REFUSE -1
#define PBOOK_WAKE 3

/* priority levels in notifiers */
#define SLEEP_LEVEL_VIDEO 100 /* Video driver (first wake) */
Expand Down
5 changes: 2 additions & 3 deletions sound/oss/dmasound/dmasound_awacs.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ static volatile struct dbdma_cmd *emergency_dbdma_cmd;
/*
* Stuff for restoring after a sleep.
*/
static int awacs_sleep_notify(struct pmu_sleep_notifier *self, int when);
static void awacs_sleep_notify(struct pmu_sleep_notifier *self, int when);
struct pmu_sleep_notifier awacs_sleep_notifier = {
awacs_sleep_notify, SLEEP_LEVEL_SOUND,
};
Expand Down Expand Up @@ -1419,7 +1419,7 @@ load_awacs(void)
* Save state when going to sleep, restore it afterwards.
*/
/* FIXME: sort out disabling/re-enabling of read stuff as well */
static int awacs_sleep_notify(struct pmu_sleep_notifier *self, int when)
static void awacs_sleep_notify(struct pmu_sleep_notifier *self, int when)
{
unsigned long flags;

Expand Down Expand Up @@ -1548,7 +1548,6 @@ static int awacs_sleep_notify(struct pmu_sleep_notifier *self, int when)
spin_unlock_irqrestore(&dmasound.lock, flags);
UNLOCK();
}
return PBOOK_SLEEP_OK;
}
#endif /* CONFIG_PM */

Expand Down

0 comments on commit 70b52b3

Please sign in to comment.