Skip to content

Commit

Permalink
Introduce CONFIG_SUSPEND for suspend-to-Ram and standby
Browse files Browse the repository at this point in the history
Introduce CONFIG_SUSPEND representing the ability to enter system sleep
states, such as the ACPI S3 state, and allow the user to choose SUSPEND
and HIBERNATION independently of each other.

Make HOTPLUG_CPU be selected automatically if SUSPEND or HIBERNATION has
been chosen and the kernel is intended for SMP systems.

Also, introduce CONFIG_PM_SLEEP which is automatically selected if
CONFIG_SUSPEND or CONFIG_HIBERNATION is set and use it to select the
code needed for both suspend and hibernation.

The top-level power management headers and the ACPI code related to
suspend and hibernation are modified to use the new definitions (the
changes in drivers/acpi/sleep/main.c are, mostly, moving code to reduce
the number of ifdefs).

There are many other files in which CONFIG_PM can be replaced with
CONFIG_PM_SLEEP or even with CONFIG_SUSPEND, but they can be updated in
the future.

Signed-off-by: Rafael J. Wysocki <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
rjwysocki authored and Linus Torvalds committed Jul 29, 2007
1 parent b0cb1a1 commit 296699d
Show file tree
Hide file tree
Showing 17 changed files with 164 additions and 86 deletions.
8 changes: 8 additions & 0 deletions drivers/acpi/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ config ACPI_PROCFS

Say N to delete /proc/acpi/ files that have moved to /sys/

config ACPI_PROCFS_SLEEP
bool "/proc/acpi/sleep (deprecated)"
depends on PM_SLEEP && ACPI_PROCFS
default n
---help---
Create /proc/acpi/sleep
Deprecated by /sys/power/state

config ACPI_AC
tristate "AC Adapter"
depends on X86
Expand Down
2 changes: 1 addition & 1 deletion drivers/acpi/sleep/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
obj-y := poweroff.o wakeup.o
obj-y += main.o
obj-$(CONFIG_PM_SLEEP) += main.o
obj-$(CONFIG_X86) += proc.o

EXTRA_CFLAGS += $(ACPI_CFLAGS)
94 changes: 50 additions & 44 deletions drivers/acpi/sleep/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@

u8 sleep_states[ACPI_S_STATE_COUNT];

static u32 acpi_target_sleep_state = ACPI_STATE_S0;

#ifdef CONFIG_SUSPEND
static struct pm_ops acpi_pm_ops;

extern void do_suspend_lowlevel(void);
Expand All @@ -34,11 +37,6 @@ static u32 acpi_suspend_states[] = {

static int init_8259A_after_S1;

extern int acpi_sleep_prepare(u32 acpi_state);
extern void acpi_power_off(void);

static u32 acpi_target_sleep_state = ACPI_STATE_S0;

/**
* acpi_pm_set_target - Set the target system sleep state to the state
* associated with given @pm_state, if supported.
Expand Down Expand Up @@ -163,21 +161,6 @@ static int acpi_pm_finish(suspend_state_t pm_state)
return 0;
}

int acpi_suspend(u32 acpi_state)
{
suspend_state_t states[] = {
[1] = PM_SUSPEND_STANDBY,
[3] = PM_SUSPEND_MEM,
[5] = PM_SUSPEND_MAX
};

if (acpi_state < 6 && states[acpi_state])
return pm_suspend(states[acpi_state]);
if (acpi_state == 4)
return hibernate();
return -EINVAL;
}

static int acpi_pm_state_valid(suspend_state_t pm_state)
{
u32 acpi_state;
Expand All @@ -202,6 +185,27 @@ static struct pm_ops acpi_pm_ops = {
.finish = acpi_pm_finish,
};

/*
* Toshiba fails to preserve interrupts over S1, reinitialization
* of 8259 is needed after S1 resume.
*/
static int __init init_ints_after_s1(struct dmi_system_id *d)
{
printk(KERN_WARNING "%s with broken S1 detected.\n", d->ident);
init_8259A_after_S1 = 1;
return 0;
}

static struct dmi_system_id __initdata acpisleep_dmi_table[] = {
{
.callback = init_ints_after_s1,
.ident = "Toshiba Satellite 4030cdt",
.matches = {DMI_MATCH(DMI_PRODUCT_NAME, "S4030CDT/4.3"),},
},
{},
};
#endif /* CONFIG_SUSPEND */

#ifdef CONFIG_HIBERNATION
static int acpi_hibernation_prepare(void)
{
Expand Down Expand Up @@ -256,6 +260,21 @@ static struct hibernation_ops acpi_hibernation_ops = {
};
#endif /* CONFIG_HIBERNATION */

int acpi_suspend(u32 acpi_state)
{
suspend_state_t states[] = {
[1] = PM_SUSPEND_STANDBY,
[3] = PM_SUSPEND_MEM,
[5] = PM_SUSPEND_MAX
};

if (acpi_state < 6 && states[acpi_state])
return pm_suspend(states[acpi_state]);
if (acpi_state == 4)
return hibernate();
return -EINVAL;
}

/**
* acpi_pm_device_sleep_state - return preferred power state of ACPI device
* in the system sleep state given by %acpi_target_sleep_state
Expand Down Expand Up @@ -331,39 +350,22 @@ int acpi_pm_device_sleep_state(struct device *dev, int wake, int *d_min_p)
return d_max;
}

/*
* Toshiba fails to preserve interrupts over S1, reinitialization
* of 8259 is needed after S1 resume.
*/
static int __init init_ints_after_s1(struct dmi_system_id *d)
{
printk(KERN_WARNING "%s with broken S1 detected.\n", d->ident);
init_8259A_after_S1 = 1;
return 0;
}

static struct dmi_system_id __initdata acpisleep_dmi_table[] = {
{
.callback = init_ints_after_s1,
.ident = "Toshiba Satellite 4030cdt",
.matches = {DMI_MATCH(DMI_PRODUCT_NAME, "S4030CDT/4.3"),},
},
{},
};

int __init acpi_sleep_init(void)
{
acpi_status status;
u8 type_a, type_b;
#ifdef CONFIG_SUSPEND
int i = 0;

dmi_check_system(acpisleep_dmi_table);
#endif

if (acpi_disabled)
return 0;

#ifdef CONFIG_SUSPEND
printk(KERN_INFO PREFIX "(supports");
for (i = 0; i < ACPI_S_STATE_COUNT; i++) {
acpi_status status;
u8 type_a, type_b;
for (i = ACPI_STATE_S0; i < ACPI_STATE_S4; i++) {
status = acpi_get_sleep_type_data(i, &type_a, &type_b);
if (ACPI_SUCCESS(status)) {
sleep_states[i] = 1;
Expand All @@ -373,10 +375,14 @@ int __init acpi_sleep_init(void)
printk(")\n");

pm_set_ops(&acpi_pm_ops);
#endif

#ifdef CONFIG_HIBERNATION
if (sleep_states[ACPI_STATE_S4])
status = acpi_get_sleep_type_data(ACPI_STATE_S4, &type_a, &type_b);
if (ACPI_SUCCESS(status)) {
hibernation_set_ops(&acpi_hibernation_ops);
sleep_states[ACPI_STATE_S4] = 1;
}
#else
sleep_states[ACPI_STATE_S4] = 0;
#endif
Expand Down
10 changes: 5 additions & 5 deletions drivers/acpi/sleep/proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/

ACPI_MODULE_NAME("sleep")
#ifdef CONFIG_ACPI_PROCFS
#ifdef CONFIG_ACPI_PROCFS_SLEEP
static int acpi_system_sleep_seq_show(struct seq_file *seq, void *offset)
{
int i;
Expand Down Expand Up @@ -76,7 +76,7 @@ acpi_system_write_sleep(struct file *file,
Done:
return error ? error : count;
}
#endif /* CONFIG_ACPI_PROCFS */
#endif /* CONFIG_ACPI_PROCFS_SLEEP */

#if defined(CONFIG_RTC_DRV_CMOS) || defined(CONFIG_RTC_DRV_CMOS_MODULE)
/* use /sys/class/rtc/rtcX/wakealarm instead; it's not ACPI-specific */
Expand Down Expand Up @@ -471,15 +471,15 @@ static const struct file_operations acpi_system_wakeup_device_fops = {
.release = single_release,
};

#ifdef CONFIG_ACPI_PROCFS
#ifdef CONFIG_ACPI_PROCFS_SLEEP
static const struct file_operations acpi_system_sleep_fops = {
.open = acpi_system_sleep_open_fs,
.read = seq_read,
.write = acpi_system_write_sleep,
.llseek = seq_lseek,
.release = single_release,
};
#endif /* CONFIG_ACPI_PROCFS */
#endif /* CONFIG_ACPI_PROCFS_SLEEP */

#ifdef HAVE_ACPI_LEGACY_ALARM
static const struct file_operations acpi_system_alarm_fops = {
Expand All @@ -506,7 +506,7 @@ static int __init acpi_sleep_proc_init(void)
if (acpi_disabled)
return 0;

#ifdef CONFIG_ACPI_PROCFS
#ifdef CONFIG_ACPI_PROCFS_SLEEP
/* 'sleep' [R/W] */
entry =
create_proc_entry("sleep", S_IFREG | S_IRUGO | S_IWUSR,
Expand Down
2 changes: 2 additions & 0 deletions drivers/acpi/sleep/sleep.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ extern void acpi_enable_wakeup_device_prep(u8 sleep_state);
extern void acpi_enable_wakeup_device(u8 sleep_state);
extern void acpi_disable_wakeup_device(u8 sleep_state);
extern void acpi_gpe_sleep_prepare(u32 sleep_state);

extern int acpi_sleep_prepare(u32 acpi_state);
2 changes: 1 addition & 1 deletion drivers/base/power/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
obj-y := shutdown.o
obj-$(CONFIG_PM) += main.o suspend.o resume.o sysfs.o
obj-$(CONFIG_PM_SLEEP) += main.o suspend.o resume.o sysfs.o
obj-$(CONFIG_PM_TRACE) += trace.o

ifeq ($(CONFIG_DEBUG_DRIVER),y)
Expand Down
4 changes: 2 additions & 2 deletions drivers/base/power/power.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
extern void device_shutdown(void);


#ifdef CONFIG_PM
#ifdef CONFIG_PM_SLEEP

/*
* main.c
Expand Down Expand Up @@ -62,7 +62,7 @@ extern int resume_device(struct device *);
*/
extern int suspend_device(struct device *, pm_message_t);

#else /* CONFIG_PM */
#else /* CONFIG_PM_SLEEP */


static inline int device_pm_add(struct device * dev)
Expand Down
9 changes: 9 additions & 0 deletions include/acpi/acpi_bus.h
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,16 @@ acpi_handle acpi_get_child(acpi_handle, acpi_integer);
acpi_handle acpi_get_pci_rootbridge_handle(unsigned int, unsigned int);
#define DEVICE_ACPI_HANDLE(dev) ((acpi_handle)((dev)->archdata.acpi_handle))

#ifdef CONFIG_PM_SLEEP
int acpi_pm_device_sleep_state(struct device *, int, int *);
#else /* !CONFIG_PM_SLEEP */
static inline int acpi_pm_device_sleep_state(struct device *d, int w, int *p)
{
if (p)
*p = ACPI_STATE_D0;
return ACPI_STATE_D3;
}
#endif /* !CONFIG_PM_SLEEP */

#endif /* CONFIG_ACPI */

Expand Down
4 changes: 4 additions & 0 deletions include/acpi/acpi_drivers.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ static inline void unregister_hotplug_dock_device(acpi_handle handle)
/*--------------------------------------------------------------------------
Suspend/Resume
-------------------------------------------------------------------------- */
#ifdef CONFIG_PM_SLEEP
extern int acpi_sleep_init(void);
#else
static inline int acpi_sleep_init(void) { return 0; }
#endif

#endif /*__ACPI_DRIVERS_H__*/
6 changes: 3 additions & 3 deletions include/linux/freezer.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include <linux/sched.h>

#ifdef CONFIG_PM
#ifdef CONFIG_PM_SLEEP
/*
* Check if a process has been frozen
*/
Expand Down Expand Up @@ -126,7 +126,7 @@ static inline void set_freezable(void)
current->flags &= ~PF_NOFREEZE;
}

#else
#else /* !CONFIG_PM_SLEEP */
static inline int frozen(struct task_struct *p) { return 0; }
static inline int freezing(struct task_struct *p) { return 0; }
static inline void set_freeze_flag(struct task_struct *p) {}
Expand All @@ -143,6 +143,6 @@ static inline void freezer_do_not_count(void) {}
static inline void freezer_count(void) {}
static inline int freezer_should_skip(struct task_struct *p) { return 0; }
static inline void set_freezable(void) {}
#endif
#endif /* !CONFIG_PM_SLEEP */

#endif /* FREEZER_H_INCLUDED */
15 changes: 11 additions & 4 deletions include/linux/pm.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ struct pm_ops {
int (*finish)(suspend_state_t state);
};

#ifdef CONFIG_SUSPEND
extern struct pm_ops *pm_ops;

/**
Expand Down Expand Up @@ -193,6 +194,12 @@ extern void arch_suspend_disable_irqs(void);
extern void arch_suspend_enable_irqs(void);

extern int pm_suspend(suspend_state_t state);
#else /* !CONFIG_SUSPEND */
#define suspend_valid_only_mem NULL

static inline void pm_set_ops(struct pm_ops *pm_ops) {}
static inline int pm_suspend(suspend_state_t state) { return -ENOSYS; }
#endif /* !CONFIG_SUSPEND */

/*
* Device power management
Expand Down Expand Up @@ -266,7 +273,7 @@ typedef struct pm_message {
struct dev_pm_info {
pm_message_t power_state;
unsigned can_wakeup:1;
#ifdef CONFIG_PM
#ifdef CONFIG_PM_SLEEP
unsigned should_wakeup:1;
struct list_head entry;
#endif
Expand All @@ -276,7 +283,7 @@ extern int device_power_down(pm_message_t state);
extern void device_power_up(void);
extern void device_resume(void);

#ifdef CONFIG_PM
#ifdef CONFIG_PM_SLEEP
extern int device_suspend(pm_message_t state);
extern int device_prepare_suspend(pm_message_t state);

Expand Down Expand Up @@ -306,7 +313,7 @@ static inline int call_platform_enable_wakeup(struct device *dev, int is_on)
return 0;
}

#else /* !CONFIG_PM */
#else /* !CONFIG_PM_SLEEP */

static inline int device_suspend(pm_message_t state)
{
Expand All @@ -323,7 +330,7 @@ static inline int call_platform_enable_wakeup(struct device *dev, int is_on)
return 0;
}

#endif
#endif /* !CONFIG_PM_SLEEP */

/* changes to device_may_wakeup take effect on the next pm state change.
* by default, devices should wakeup if they can.
Expand Down
Loading

0 comments on commit 296699d

Please sign in to comment.