# BRCM_VERSION=3
[bcm963xx.git] / kernel / linux / Documentation / power / swsusp.txt
1 From kernel/suspend.c:
2
3  * BIG FAT WARNING *********************************************************
4  *
5  * If you have unsupported (*) devices using DMA...
6  *                              ...say goodbye to your data.
7  *
8  * If you touch anything on disk between suspend and resume...
9  *                              ...kiss your data goodbye.
10  *
11  * If your disk driver does not support suspend... (IDE does)
12  *                              ...you'd better find out how to get along
13  *                                 without your data.
14  *
15  * If you change kernel command line between suspend and resume...
16  *                              ...prepare for nasty fsck or worse.
17  *
18  * (*) pm interface support is needed to make it safe.
19
20 You need to append resume=/dev/your_swap_partition to kernel command
21 line. Then you suspend by echo 4 > /proc/acpi/sleep.
22
23 Pavel's unreliable guide to swsusp mess
24 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25
26 There are currently two versions of swap suspend in the kernel, the old
27 "Pavel's" version in kernel/power/swsusp.c and the new "Patrick's"
28 version in kernel/power/pmdisk.c. They provide the same functionality;
29 the old version looks ugly but was tested, while the new version looks
30 nicer but did not receive so much testing. echo 4 > /proc/acpi/sleep
31 calls the old version, echo disk > /sys/power/state calls the new one.
32
33 [In the future, when the new version is stable enough, two things can
34 happen:
35
36 * the new version is moved into swsusp.c, and swsusp is renamed to swap
37   suspend (Pavel prefers this)
38
39 * pmdisk is kept as is and swsusp.c is removed from the kernel]
40
41
42
43 Article about goals and implementation of Software Suspend for Linux
44 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
45 Author: G\82ábor Kuti
46 Last revised: 2003-10-20 by Pavel Machek
47
48 Idea and goals to achieve
49
50 Nowadays it is common in several laptops that they have a suspend button. It
51 saves the state of the machine to a filesystem or to a partition and switches
52 to standby mode. Later resuming the machine the saved state is loaded back to
53 ram and the machine can continue its work. It has two real benefits. First we
54 save ourselves the time machine goes down and later boots up, energy costs
55 real high when running from batteries. The other gain is that we don't have to
56 interrupt our programs so processes that are calculating something for a long
57 time shouldn't need to be written interruptible.
58
59 Using the code
60
61 You have two ways to use this code. The first one is is with a patched
62 SysVinit (my patch is against 2.76 and available at my home page). You
63 might call 'swsusp' or 'shutdown -z <time>'. Next way is to echo 4 >
64 /proc/acpi/sleep.
65
66 Either way it saves the state of the machine into active swaps and then
67 reboots.  You must explicitly specify the swap partition to resume from with
68 ``resume='' kernel option. If signature is found it loads and restores saved
69 state. If the option ``noresume'' is specified as a boot parameter, it skips
70 the resuming.
71
72 In the meantime while the system is suspended you should not touch any of the
73 hardware!
74
75 About the code
76
77 Things to implement
78 - SMP support. I've done an SMP support but since I don't have access to a kind
79   of this one I cannot test it. Please SMP people test it.  .. Tested it,
80   doesn't work. Had no time to figure out why. There is some mess with
81   interrupts AFAIK..
82 - We should only make a copy of data related to kernel segment, since any
83   process data won't be changed.
84 - Should make more sanity checks. Or are these enough?
85
86 Not so important ideas for implementing
87
88 - If a real time process is running then don't suspend the machine.
89 - Support for adding/removing hardware while suspended?
90 - We should not free pages at the beginning so aggressively, most of them
91   go there anyway..
92
93 Drivers that need support
94 - pc_keyb -- perhaps we can wait for vojtech's input patches
95 - do IDE cdroms need some kind of support?
96 - IDE CD-RW -- how to deal with that?
97
98 Sleep states summary (thanx, Ducrot)
99 ====================================
100
101 In a really perfect world:
102 echo 1 > /proc/acpi/sleep       # for standby
103 echo 2 > /proc/acpi/sleep       # for suspend to ram
104 echo 3 > /proc/acpi/sleep       # for suspend to ram, but with more power conservative
105 echo 4 > /proc/acpi/sleep       # for suspend to disk
106 echo 5 > /proc/acpi/sleep       # for shutdown unfriendly the system
107
108 and perhaps
109 echo 4b > /proc/acpi/sleep      # for suspend to disk via s4bios
110
111
112 FAQ:
113
114 Q: well, suspending a server is IMHO a really stupid thing,
115 but... (Diego Zuccato):
116
117 A: You bought new UPS for your server. How do you install it without
118 bringing machine down? Suspend to disk, rearrange power cables,
119 resume.
120
121 You have your server on UPS. Power died, and UPS is indicating 30
122 seconds to failure. What do you do? Suspend to disk.
123
124 Ethernet card in your server died. You want to replace it. Your
125 server is not hotplug capable. What do you do? Suspend to disk,
126 replace ethernet card, resume. If you are fast your users will not
127 even see broken connections.
128
129
130 Q: Maybe I'm missing something, but why don't the regular I/O paths work?
131
132 A: We do use the regular I/O paths. However we cannot restore the data
133 to its original location as we load it. That would create an
134 inconsistent kernel state which would certainly result in an oops.
135 Instead, we load the image into unused memory and then atomically copy
136 it back to it original location. This implies, of course, a maximum
137 image size of half the amount of memory.
138
139 There are two solutions to this:
140
141 * require half of memory to be free during suspend. That way you can
142 read "new" data onto free spots, then cli and copy
143
144 * assume we had special "polling" ide driver that only uses memory
145 between 0-640KB. That way, I'd have to make sure that 0-640KB is free
146 during suspending, but otherwise it would work...
147
148 suspend2 shares this fundamental limitation, but does not include user
149 data and disk caches into "used memory" by saving them in
150 advance. That means that the limitation goes away in practice.
151
152 Q: Does linux support ACPI S4?
153
154 A: No.
155
156 When swsusp was created, ACPI was not too widespread, so we tried to
157 avoid using ACPI-specific stuff. ACPI also is/was notoriously
158 buggy. These days swsusp works on APM-only i386 machines and even
159 without any power managment at all. Some versions also work on PPC.
160
161 That means that machine does not enter S4 on suspend-to-disk, but
162 simply enters S5. That has few advantages, you can for example boot
163 windows on next boot, and return to your Linux session later. You
164 could even have few different Linuxes on your box (not sharing any
165 partitions), and switch between them.
166
167 It also has disadvantages. On HP nx5000, if you unplug power cord
168 while machine is suspended-to-disk, Linux will fail to notice that.
169
170 Q: My machine doesn't work with ACPI. How can I use swsusp than ?
171
172 A: Do a reboot() syscall with right parameters. Warning: glibc gets in
173 its way, so check with strace:
174
175 reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, 0xd000fce2)
176
177 (Thanks to Peter Osterlund:)
178
179 #include <unistd.h>
180 #include <syscall.h>
181
182 #define LINUX_REBOOT_MAGIC1     0xfee1dead
183 #define LINUX_REBOOT_MAGIC2     672274793
184 #define LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
185
186 int main()
187 {
188     syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2,
189             LINUX_REBOOT_CMD_SW_SUSPEND, 0);
190     return 0;
191 }
192
193 Q: What is 'suspend2'?
194
195 A: suspend2 is 'Software Suspend 2', a forked implementation of
196 suspend-to-disk which is available as separate patches for 2.4 and 2.6
197 kernels from swsusp.sourceforge.net. It includes support for SMP, 4GB
198 highmem and preemption. It also has a extensible architecture that
199 allows for arbitrary transformations on the image (compression,
200 encryption) and arbitrary backends for writing the image (eg to swap
201 or an NFS share[Work In Progress]). Questions regarding suspend2
202 should be sent to the mailing list available through the suspend2
203 website, and not to the Linux Kernel Mailing List. We are working
204 toward merging suspend2 into the mainline kernel.
205
206 Q: Kernel thread must voluntarily freeze itself (call 'refrigerator'). But
207 I found some kernel threads don't do it, and they don't freeze, and
208 so the system can't sleep. Is this a known behavior?
209
210 A: All such kernel threads need to be fixed, one by one. Select place
211 where it is safe to be frozen (no kernel semaphores should be held at
212 that point and it must be safe to sleep there), and add:
213
214             if (current->flags & PF_FREEZE)
215                     refrigerator(PF_FREEZE);
216
217 Q: What is the difference between between "platform", "shutdown" and
218 "firmware" in /sys/power/disk?
219
220 A:
221
222 shutdown: save state in linux, then tell bios to powerdown
223
224 platform: save state in linux, then tell bios to powerdown and blink
225           "suspended led"
226
227 firmware: tell bios to save state itself [needs BIOS-specific suspend
228           partition, and has very little to do with swsusp]
229
230 "platform" is actually right thing to do, but "shutdown" is most
231 reliable.