Skip to content

Commit 296699d

Browse files
rjwysockiLinus Torvalds
authored andcommitted
Introduce CONFIG_SUSPEND for suspend-to-Ram and standby
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 <rjw@sisk.pl> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent b0cb1a1 commit 296699d

17 files changed

Lines changed: 164 additions & 86 deletions

File tree

‎drivers/acpi/Kconfig‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ config ACPI_PROCFS
6363

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

66+
config ACPI_PROCFS_SLEEP
67+
bool "/proc/acpi/sleep (deprecated)"
68+
depends on PM_SLEEP && ACPI_PROCFS
69+
default n
70+
---help---
71+
Create /proc/acpi/sleep
72+
Deprecated by /sys/power/state
73+
6674
config ACPI_AC
6775
tristate "AC Adapter"
6876
depends on X86

‎drivers/acpi/sleep/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
obj-y := poweroff.o wakeup.o
2-
obj-y += main.o
2+
obj-$(CONFIG_PM_SLEEP) += main.o
33
obj-$(CONFIG_X86) += proc.o
44

55
EXTRA_CFLAGS += $(ACPI_CFLAGS)

‎drivers/acpi/sleep/main.c‎

Lines changed: 50 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121

2222
u8 sleep_states[ACPI_S_STATE_COUNT];
2323

24+
static u32 acpi_target_sleep_state = ACPI_STATE_S0;
25+
26+
#ifdef CONFIG_SUSPEND
2427
static struct pm_ops acpi_pm_ops;
2528

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

3538
static int init_8259A_after_S1;
3639

37-
extern int acpi_sleep_prepare(u32 acpi_state);
38-
extern void acpi_power_off(void);
39-
40-
static u32 acpi_target_sleep_state = ACPI_STATE_S0;
41-
4240
/**
4341
* acpi_pm_set_target - Set the target system sleep state to the state
4442
* associated with given @pm_state, if supported.
@@ -163,21 +161,6 @@ static int acpi_pm_finish(suspend_state_t pm_state)
163161
return 0;
164162
}
165163

166-
int acpi_suspend(u32 acpi_state)
167-
{
168-
suspend_state_t states[] = {
169-
[1] = PM_SUSPEND_STANDBY,
170-
[3] = PM_SUSPEND_MEM,
171-
[5] = PM_SUSPEND_MAX
172-
};
173-
174-
if (acpi_state < 6 && states[acpi_state])
175-
return pm_suspend(states[acpi_state]);
176-
if (acpi_state == 4)
177-
return hibernate();
178-
return -EINVAL;
179-
}
180-
181164
static int acpi_pm_state_valid(suspend_state_t pm_state)
182165
{
183166
u32 acpi_state;
@@ -202,6 +185,27 @@ static struct pm_ops acpi_pm_ops = {
202185
.finish = acpi_pm_finish,
203186
};
204187

188+
/*
189+
* Toshiba fails to preserve interrupts over S1, reinitialization
190+
* of 8259 is needed after S1 resume.
191+
*/
192+
static int __init init_ints_after_s1(struct dmi_system_id *d)
193+
{
194+
printk(KERN_WARNING "%s with broken S1 detected.\n", d->ident);
195+
init_8259A_after_S1 = 1;
196+
return 0;
197+
}
198+
199+
static struct dmi_system_id __initdata acpisleep_dmi_table[] = {
200+
{
201+
.callback = init_ints_after_s1,
202+
.ident = "Toshiba Satellite 4030cdt",
203+
.matches = {DMI_MATCH(DMI_PRODUCT_NAME, "S4030CDT/4.3"),},
204+
},
205+
{},
206+
};
207+
#endif /* CONFIG_SUSPEND */
208+
205209
#ifdef CONFIG_HIBERNATION
206210
static int acpi_hibernation_prepare(void)
207211
{
@@ -256,6 +260,21 @@ static struct hibernation_ops acpi_hibernation_ops = {
256260
};
257261
#endif /* CONFIG_HIBERNATION */
258262

263+
int acpi_suspend(u32 acpi_state)
264+
{
265+
suspend_state_t states[] = {
266+
[1] = PM_SUSPEND_STANDBY,
267+
[3] = PM_SUSPEND_MEM,
268+
[5] = PM_SUSPEND_MAX
269+
};
270+
271+
if (acpi_state < 6 && states[acpi_state])
272+
return pm_suspend(states[acpi_state]);
273+
if (acpi_state == 4)
274+
return hibernate();
275+
return -EINVAL;
276+
}
277+
259278
/**
260279
* acpi_pm_device_sleep_state - return preferred power state of ACPI device
261280
* in the system sleep state given by %acpi_target_sleep_state
@@ -331,39 +350,22 @@ int acpi_pm_device_sleep_state(struct device *dev, int wake, int *d_min_p)
331350
return d_max;
332351
}
333352

334-
/*
335-
* Toshiba fails to preserve interrupts over S1, reinitialization
336-
* of 8259 is needed after S1 resume.
337-
*/
338-
static int __init init_ints_after_s1(struct dmi_system_id *d)
339-
{
340-
printk(KERN_WARNING "%s with broken S1 detected.\n", d->ident);
341-
init_8259A_after_S1 = 1;
342-
return 0;
343-
}
344-
345-
static struct dmi_system_id __initdata acpisleep_dmi_table[] = {
346-
{
347-
.callback = init_ints_after_s1,
348-
.ident = "Toshiba Satellite 4030cdt",
349-
.matches = {DMI_MATCH(DMI_PRODUCT_NAME, "S4030CDT/4.3"),},
350-
},
351-
{},
352-
};
353-
354353
int __init acpi_sleep_init(void)
355354
{
355+
acpi_status status;
356+
u8 type_a, type_b;
357+
#ifdef CONFIG_SUSPEND
356358
int i = 0;
357359

358360
dmi_check_system(acpisleep_dmi_table);
361+
#endif
359362

360363
if (acpi_disabled)
361364
return 0;
362365

366+
#ifdef CONFIG_SUSPEND
363367
printk(KERN_INFO PREFIX "(supports");
364-
for (i = 0; i < ACPI_S_STATE_COUNT; i++) {
365-
acpi_status status;
366-
u8 type_a, type_b;
368+
for (i = ACPI_STATE_S0; i < ACPI_STATE_S4; i++) {
367369
status = acpi_get_sleep_type_data(i, &type_a, &type_b);
368370
if (ACPI_SUCCESS(status)) {
369371
sleep_states[i] = 1;
@@ -373,10 +375,14 @@ int __init acpi_sleep_init(void)
373375
printk(")\n");
374376

375377
pm_set_ops(&acpi_pm_ops);
378+
#endif
376379

377380
#ifdef CONFIG_HIBERNATION
378-
if (sleep_states[ACPI_STATE_S4])
381+
status = acpi_get_sleep_type_data(ACPI_STATE_S4, &type_a, &type_b);
382+
if (ACPI_SUCCESS(status)) {
379383
hibernation_set_ops(&acpi_hibernation_ops);
384+
sleep_states[ACPI_STATE_S4] = 1;
385+
}
380386
#else
381387
sleep_states[ACPI_STATE_S4] = 0;
382388
#endif

‎drivers/acpi/sleep/proc.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*/
2424

2525
ACPI_MODULE_NAME("sleep")
26-
#ifdef CONFIG_ACPI_PROCFS
26+
#ifdef CONFIG_ACPI_PROCFS_SLEEP
2727
static int acpi_system_sleep_seq_show(struct seq_file *seq, void *offset)
2828
{
2929
int i;
@@ -76,7 +76,7 @@ acpi_system_write_sleep(struct file *file,
7676
Done:
7777
return error ? error : count;
7878
}
79-
#endif /* CONFIG_ACPI_PROCFS */
79+
#endif /* CONFIG_ACPI_PROCFS_SLEEP */
8080

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

474-
#ifdef CONFIG_ACPI_PROCFS
474+
#ifdef CONFIG_ACPI_PROCFS_SLEEP
475475
static const struct file_operations acpi_system_sleep_fops = {
476476
.open = acpi_system_sleep_open_fs,
477477
.read = seq_read,
478478
.write = acpi_system_write_sleep,
479479
.llseek = seq_lseek,
480480
.release = single_release,
481481
};
482-
#endif /* CONFIG_ACPI_PROCFS */
482+
#endif /* CONFIG_ACPI_PROCFS_SLEEP */
483483

484484
#ifdef HAVE_ACPI_LEGACY_ALARM
485485
static const struct file_operations acpi_system_alarm_fops = {
@@ -506,7 +506,7 @@ static int __init acpi_sleep_proc_init(void)
506506
if (acpi_disabled)
507507
return 0;
508508

509-
#ifdef CONFIG_ACPI_PROCFS
509+
#ifdef CONFIG_ACPI_PROCFS_SLEEP
510510
/* 'sleep' [R/W] */
511511
entry =
512512
create_proc_entry("sleep", S_IFREG | S_IRUGO | S_IWUSR,

‎drivers/acpi/sleep/sleep.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ extern void acpi_enable_wakeup_device_prep(u8 sleep_state);
66
extern void acpi_enable_wakeup_device(u8 sleep_state);
77
extern void acpi_disable_wakeup_device(u8 sleep_state);
88
extern void acpi_gpe_sleep_prepare(u32 sleep_state);
9+
10+
extern int acpi_sleep_prepare(u32 acpi_state);

‎drivers/base/power/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
obj-y := shutdown.o
2-
obj-$(CONFIG_PM) += main.o suspend.o resume.o sysfs.o
2+
obj-$(CONFIG_PM_SLEEP) += main.o suspend.o resume.o sysfs.o
33
obj-$(CONFIG_PM_TRACE) += trace.o
44

55
ifeq ($(CONFIG_DEBUG_DRIVER),y)

‎drivers/base/power/power.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
extern void device_shutdown(void);
66

77

8-
#ifdef CONFIG_PM
8+
#ifdef CONFIG_PM_SLEEP
99

1010
/*
1111
* main.c
@@ -62,7 +62,7 @@ extern int resume_device(struct device *);
6262
*/
6363
extern int suspend_device(struct device *, pm_message_t);
6464

65-
#else /* CONFIG_PM */
65+
#else /* CONFIG_PM_SLEEP */
6666

6767

6868
static inline int device_pm_add(struct device * dev)

‎include/acpi/acpi_bus.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,16 @@ acpi_handle acpi_get_child(acpi_handle, acpi_integer);
366366
acpi_handle acpi_get_pci_rootbridge_handle(unsigned int, unsigned int);
367367
#define DEVICE_ACPI_HANDLE(dev) ((acpi_handle)((dev)->archdata.acpi_handle))
368368

369+
#ifdef CONFIG_PM_SLEEP
369370
int acpi_pm_device_sleep_state(struct device *, int, int *);
371+
#else /* !CONFIG_PM_SLEEP */
372+
static inline int acpi_pm_device_sleep_state(struct device *d, int w, int *p)
373+
{
374+
if (p)
375+
*p = ACPI_STATE_D0;
376+
return ACPI_STATE_D3;
377+
}
378+
#endif /* !CONFIG_PM_SLEEP */
370379

371380
#endif /* CONFIG_ACPI */
372381

‎include/acpi/acpi_drivers.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ static inline void unregister_hotplug_dock_device(acpi_handle handle)
147147
/*--------------------------------------------------------------------------
148148
Suspend/Resume
149149
-------------------------------------------------------------------------- */
150+
#ifdef CONFIG_PM_SLEEP
150151
extern int acpi_sleep_init(void);
152+
#else
153+
static inline int acpi_sleep_init(void) { return 0; }
154+
#endif
151155

152156
#endif /*__ACPI_DRIVERS_H__*/

‎include/linux/freezer.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
#include <linux/sched.h>
77

8-
#ifdef CONFIG_PM
8+
#ifdef CONFIG_PM_SLEEP
99
/*
1010
* Check if a process has been frozen
1111
*/
@@ -126,7 +126,7 @@ static inline void set_freezable(void)
126126
current->flags &= ~PF_NOFREEZE;
127127
}
128128

129-
#else
129+
#else /* !CONFIG_PM_SLEEP */
130130
static inline int frozen(struct task_struct *p) { return 0; }
131131
static inline int freezing(struct task_struct *p) { return 0; }
132132
static inline void set_freeze_flag(struct task_struct *p) {}
@@ -143,6 +143,6 @@ static inline void freezer_do_not_count(void) {}
143143
static inline void freezer_count(void) {}
144144
static inline int freezer_should_skip(struct task_struct *p) { return 0; }
145145
static inline void set_freezable(void) {}
146-
#endif
146+
#endif /* !CONFIG_PM_SLEEP */
147147

148148
#endif /* FREEZER_H_INCLUDED */

0 commit comments

Comments
 (0)