Merge branch 'suspend' of git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux-acpi-2.6

* 'suspend' of git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux-acpi-2.6: (38 commits)
suspend: cleanup reference to swsusp_pg_dir[]
PM: Remove obsolete /sys/devices/.../power/state docs
Hibernation: Invoke suspend notifications after console switch
Suspend: Invoke suspend notifications after console switch
Suspend: Clean up suspend_64.c
Suspend: Add config option to disable the freezer if architecture wants that
ACPI: Print message before calling _PTS
ACPI hibernation: Call _PTS before suspending devices
Hibernation: Introduce begin() and end() callbacks
ACPI suspend: Call _PTS before suspending devices
ACPI: Separate disabling of GPEs from _PTS
ACPI: Separate invocations of _GTS and _BFS from _PTS and _WAK
Suspend: Introduce begin() and end() callbacks
suspend: fix ia64 allmodconfig build
ACPI: clear GPE earily in resume to avoid warning
Suspend: Clean up Kconfig (V2)
Hibernation: Clean up Kconfig (V2)
Hibernation: Update messages
Suspend: Use common prefix in messages
Hibernation: Remove unnecessary variable declaration
...

+1032 -505
+5
Documentation/kernel-parameters.txt
··· 168 168 acpi_irq_isa= [HW,ACPI] If irq_balance, mark listed IRQs used by ISA 169 169 Format: <irq>,<irq>... 170 170 171 + acpi_new_pts_ordering [HW,ACPI] 172 + Enforce the ACPI 2.0 ordering of the _PTS control 173 + method wrt putting devices into low power states 174 + default: pre ACPI 2.0 ordering of _PTS 175 + 171 176 acpi_no_auto_ssdt [HW,ACPI] Disable automatic loading of SSDT 172 177 173 178 acpi_os_name= [HW,ACPI] Tell ACPI BIOS the name of the OS
+155 -57
Documentation/power/basic-pm-debugging.txt
··· 1 - Debugging suspend and resume 1 + Debugging hibernation and suspend 2 2 (C) 2007 Rafael J. Wysocki <rjw@sisk.pl>, GPL 3 3 4 - 1. Testing suspend to disk (STD) 4 + 1. Testing hibernation (aka suspend to disk or STD) 5 5 6 - To verify that the STD works, you can try to suspend in the "reboot" mode: 6 + To check if hibernation works, you can try to hibernate in the "reboot" mode: 7 7 8 8 # echo reboot > /sys/power/disk 9 9 # echo disk > /sys/power/state 10 10 11 - and the system should suspend, reboot, resume and get back to the command prompt 12 - where you have started the transition. If that happens, the STD is most likely 13 - to work correctly, but you need to repeat the test at least a couple of times in 14 - a row for confidence. This is necessary, because some problems only show up on 15 - a second attempt at suspending and resuming the system. You should also test 16 - the "platform" and "shutdown" modes of suspend: 11 + and the system should create a hibernation image, reboot, resume and get back to 12 + the command prompt where you have started the transition. If that happens, 13 + hibernation is most likely to work correctly. Still, you need to repeat the 14 + test at least a couple of times in a row for confidence. [This is necessary, 15 + because some problems only show up on a second attempt at suspending and 16 + resuming the system.] Moreover, hibernating in the "reboot" and "shutdown" 17 + modes causes the PM core to skip some platform-related callbacks which on ACPI 18 + systems might be necessary to make hibernation work. Thus, if you machine fails 19 + to hibernate or resume in the "reboot" mode, you should try the "platform" mode: 17 20 18 21 # echo platform > /sys/power/disk 19 22 # echo disk > /sys/power/state 20 23 21 - or 24 + which is the default and recommended mode of hibernation. 25 + 26 + Unfortunately, the "platform" mode of hibernation does not work on some systems 27 + with broken BIOSes. In such cases the "shutdown" mode of hibernation might 28 + work: 22 29 23 30 # echo shutdown > /sys/power/disk 24 31 # echo disk > /sys/power/state 25 32 26 - in which cases you will have to press the power button to make the system 27 - resume. If that does not work, you will need to identify what goes wrong. 33 + (it is similar to the "reboot" mode, but it requires you to press the power 34 + button to make the system resume). 28 35 29 - a) Test mode of STD 36 + If neither "platform" nor "shutdown" hibernation mode works, you will need to 37 + identify what goes wrong. 30 38 31 - To verify if there are any drivers that cause problems you can run the STD 32 - in the test mode: 39 + a) Test modes of hibernation 33 40 34 - # echo test > /sys/power/disk 41 + To find out why hibernation fails on your system, you can use a special testing 42 + facility available if the kernel is compiled with CONFIG_PM_DEBUG set. Then, 43 + there is the file /sys/power/pm_test that can be used to make the hibernation 44 + core run in a test mode. There are 5 test modes available: 45 + 46 + freezer 47 + - test the freezing of processes 48 + 49 + devices 50 + - test the freezing of processes and suspending of devices 51 + 52 + platform 53 + - test the freezing of processes, suspending of devices and platform 54 + global control methods(*) 55 + 56 + processors 57 + - test the freezing of processes, suspending of devices, platform 58 + global control methods(*) and the disabling of nonboot CPUs 59 + 60 + core 61 + - test the freezing of processes, suspending of devices, platform global 62 + control methods(*), the disabling of nonboot CPUs and suspending of 63 + platform/system devices 64 + 65 + (*) the platform global control methods are only available on ACPI systems 66 + and are only tested if the hibernation mode is set to "platform" 67 + 68 + To use one of them it is necessary to write the corresponding string to 69 + /sys/power/pm_test (eg. "devices" to test the freezing of processes and 70 + suspending devices) and issue the standard hibernation commands. For example, 71 + to use the "devices" test mode along with the "platform" mode of hibernation, 72 + you should do the following: 73 + 74 + # echo devices > /sys/power/pm_test 75 + # echo platform > /sys/power/disk 35 76 # echo disk > /sys/power/state 36 77 37 - in which case the system should freeze tasks, suspend devices, disable nonboot 38 - CPUs (if any), wait for 5 seconds, enable nonboot CPUs, resume devices, thaw 39 - tasks and return to your command prompt. If that fails, most likely there is 40 - a driver that fails to either suspend or resume (in the latter case the system 41 - may hang or be unstable after the test, so please take that into consideration). 42 - To find this driver, you can carry out a binary search according to the rules: 78 + Then, the kernel will try to freeze processes, suspend devices, wait 5 seconds, 79 + resume devices and thaw processes. If "platform" is written to 80 + /sys/power/pm_test , then after suspending devices the kernel will additionally 81 + invoke the global control methods (eg. ACPI global control methods) used to 82 + prepare the platform firmware for hibernation. Next, it will wait 5 seconds and 83 + invoke the platform (eg. ACPI) global methods used to cancel hibernation etc. 84 + 85 + Writing "none" to /sys/power/pm_test causes the kernel to switch to the normal 86 + hibernation/suspend operations. Also, when open for reading, /sys/power/pm_test 87 + contains a space-separated list of all available tests (including "none" that 88 + represents the normal functionality) in which the current test level is 89 + indicated by square brackets. 90 + 91 + Generally, as you can see, each test level is more "invasive" than the previous 92 + one and the "core" level tests the hardware and drivers as deeply as possible 93 + without creating a hibernation image. Obviously, if the "devices" test fails, 94 + the "platform" test will fail as well and so on. Thus, as a rule of thumb, you 95 + should try the test modes starting from "freezer", through "devices", "platform" 96 + and "processors" up to "core" (repeat the test on each level a couple of times 97 + to make sure that any random factors are avoided). 98 + 99 + If the "freezer" test fails, there is a task that cannot be frozen (in that case 100 + it usually is possible to identify the offending task by analysing the output of 101 + dmesg obtained after the failing test). Failure at this level usually means 102 + that there is a problem with the tasks freezer subsystem that should be 103 + reported. 104 + 105 + If the "devices" test fails, most likely there is a driver that cannot suspend 106 + or resume its device (in the latter case the system may hang or become unstable 107 + after the test, so please take that into consideration). To find this driver, 108 + you can carry out a binary search according to the rules: 43 109 - if the test fails, unload a half of the drivers currently loaded and repeat 44 110 (that would probably involve rebooting the system, so always note what drivers 45 111 have been loaded before the test), ··· 113 47 recently and repeat. 114 48 115 49 Once you have found the failing driver (there can be more than just one of 116 - them), you have to unload it every time before the STD transition. In that case 117 - please make sure to report the problem with the driver. 50 + them), you have to unload it every time before hibernation. In that case please 51 + make sure to report the problem with the driver. 118 52 119 - It is also possible that a cycle can still fail after you have unloaded 120 - all modules. In that case, you would want to look in your kernel configuration 121 - for the drivers that can be compiled as modules (testing again with them as 122 - modules), and possibly also try boot time options such as "noapic" or "noacpi". 53 + It is also possible that the "devices" test will still fail after you have 54 + unloaded all modules. In that case, you may want to look in your kernel 55 + configuration for the drivers that can be compiled as modules (and test again 56 + with these drivers compiled as modules). You may also try to use some special 57 + kernel command line options such as "noapic", "noacpi" or even "acpi=off". 58 + 59 + If the "platform" test fails, there is a problem with the handling of the 60 + platform (eg. ACPI) firmware on your system. In that case the "platform" mode 61 + of hibernation is not likely to work. You can try the "shutdown" mode, but that 62 + is rather a poor man's workaround. 63 + 64 + If the "processors" test fails, the disabling/enabling of nonboot CPUs does not 65 + work (of course, this only may be an issue on SMP systems) and the problem 66 + should be reported. In that case you can also try to switch the nonboot CPUs 67 + off and on using the /sys/devices/system/cpu/cpu*/online sysfs attributes and 68 + see if that works. 69 + 70 + If the "core" test fails, which means that suspending of the system/platform 71 + devices has failed (these devices are suspended on one CPU with interrupts off), 72 + the problem is most probably hardware-related and serious, so it should be 73 + reported. 74 + 75 + A failure of any of the "platform", "processors" or "core" tests may cause your 76 + system to hang or become unstable, so please beware. Such a failure usually 77 + indicates a serious problem that very well may be related to the hardware, but 78 + please report it anyway. 123 79 124 80 b) Testing minimal configuration 125 81 126 - If the test mode of STD works, you can boot the system with "init=/bin/bash" 127 - and attempt to suspend in the "reboot", "shutdown" and "platform" modes. If 128 - that does not work, there probably is a problem with a driver statically 129 - compiled into the kernel and you can try to compile more drivers as modules, 130 - so that they can be tested individually. Otherwise, there is a problem with a 131 - modular driver and you can find it by loading a half of the modules you normally 132 - use and binary searching in accordance with the algorithm: 82 + If all of the hibernation test modes work, you can boot the system with the 83 + "init=/bin/bash" command line parameter and attempt to hibernate in the 84 + "reboot", "shutdown" and "platform" modes. If that does not work, there 85 + probably is a problem with a driver statically compiled into the kernel and you 86 + can try to compile more drivers as modules, so that they can be tested 87 + individually. Otherwise, there is a problem with a modular driver and you can 88 + find it by loading a half of the modules you normally use and binary searching 89 + in accordance with the algorithm: 133 90 - if there are n modules loaded and the attempt to suspend and resume fails, 134 91 unload n/2 of the modules and try again (that would probably involve rebooting 135 92 the system), ··· 160 71 load n/2 modules more and try again. 161 72 162 73 Again, if you find the offending module(s), it(they) must be unloaded every time 163 - before the STD transition, and please report the problem with it(them). 74 + before hibernation, and please report the problem with it(them). 164 75 165 76 c) Advanced debugging 166 77 167 - In case the STD does not work on your system even in the minimal configuration 168 - and compiling more drivers as modules is not practical or some modules cannot 169 - be unloaded, you can use one of the more advanced debugging techniques to find 170 - the problem. First, if there is a serial port in your box, you can boot the 171 - kernel with the 'no_console_suspend' parameter and try to log kernel 172 - messages using the serial console. This may provide you with some information 173 - about the reasons of the suspend (resume) failure. Alternatively, it may be 174 - possible to use a FireWire port for debugging with firescope 175 - (ftp://ftp.firstfloor.org/pub/ak/firescope/). On i386 it is also possible to 78 + In case that hibernation does not work on your system even in the minimal 79 + configuration and compiling more drivers as modules is not practical or some 80 + modules cannot be unloaded, you can use one of the more advanced debugging 81 + techniques to find the problem. First, if there is a serial port in your box, 82 + you can boot the kernel with the 'no_console_suspend' parameter and try to log 83 + kernel messages using the serial console. This may provide you with some 84 + information about the reasons of the suspend (resume) failure. Alternatively, 85 + it may be possible to use a FireWire port for debugging with firescope 86 + (ftp://ftp.firstfloor.org/pub/ak/firescope/). On x86 it is also possible to 176 87 use the PM_TRACE mechanism documented in Documentation/s2ram.txt . 177 88 178 89 2. Testing suspend to RAM (STR) ··· 180 91 To verify that the STR works, it is generally more convenient to use the s2ram 181 92 tool available from http://suspend.sf.net and documented at 182 93 http://en.opensuse.org/s2ram . However, before doing that it is recommended to 183 - carry out the procedure described in section 1. 94 + carry out STR testing using the facility described in section 1. 184 95 185 - Assume you have resolved the problems with the STD and you have found some 186 - failing drivers. These drivers are also likely to fail during the STR or 187 - during the resume, so it is better to unload them every time before the STR 188 - transition. Now, you can follow the instructions at 189 - http://en.opensuse.org/s2ram to test the system, but if it does not work 190 - "out of the box", you may need to boot it with "init=/bin/bash" and test 191 - s2ram in the minimal configuration. In that case, you may be able to search 192 - for failing drivers by following the procedure analogous to the one described in 193 - 1b). If you find some failing drivers, you will have to unload them every time 194 - before the STR transition (ie. before you run s2ram), and please report the 195 - problems with them. 96 + Namely, after writing "freezer", "devices", "platform", "processors", or "core" 97 + into /sys/power/pm_test (available if the kernel is compiled with 98 + CONFIG_PM_DEBUG set) the suspend code will work in the test mode corresponding 99 + to given string. The STR test modes are defined in the same way as for 100 + hibernation, so please refer to Section 1 for more information about them. In 101 + particular, the "core" test allows you to test everything except for the actual 102 + invocation of the platform firmware in order to put the system into the sleep 103 + state. 104 + 105 + Among other things, the testing with the help of /sys/power/pm_test may allow 106 + you to identify drivers that fail to suspend or resume their devices. They 107 + should be unloaded every time before an STR transition. 108 + 109 + Next, you can follow the instructions at http://en.opensuse.org/s2ram to test 110 + the system, but if it does not work "out of the box", you may need to boot it 111 + with "init=/bin/bash" and test s2ram in the minimal configuration. In that 112 + case, you may be able to search for failing drivers by following the procedure 113 + analogous to the one described in section 1. If you find some failing drivers, 114 + you will have to unload them every time before an STR transition (ie. before 115 + you run s2ram), and please report the problems with them.
-49
Documentation/power/devices.txt
··· 502 502 to shift to lower voltage settings and reduce the power cost of executing 503 503 a given number of instructions. (Without voltage adjustment, it's rare 504 504 for cpufreq to save much power; the cost-per-instruction must go down.) 505 - 506 - 507 - /sys/devices/.../power/state files 508 - ================================== 509 - For now you can also test some of this functionality using sysfs. 510 - 511 - DEPRECATED: USE "power/state" ONLY FOR DRIVER TESTING, AND 512 - AVOID USING dev->power.power_state IN DRIVERS. 513 - 514 - THESE WILL BE REMOVED. IF THE "power/state" FILE GETS REPLACED, 515 - IT WILL BECOME SOMETHING COUPLED TO THE BUS OR DRIVER. 516 - 517 - In each device's directory, there is a 'power' directory, which contains 518 - at least a 'state' file. The value of this field is effectively boolean, 519 - PM_EVENT_ON or PM_EVENT_SUSPEND. 520 - 521 - * Reading from this file displays a value corresponding to 522 - the power.power_state.event field. All nonzero values are 523 - displayed as "2", corresponding to a low power state; zero 524 - is displayed as "0", corresponding to normal operation. 525 - 526 - * Writing to this file initiates a transition using the 527 - specified event code number; only '0', '2', and '3' are 528 - accepted (without a newline); '2' and '3' are both 529 - mapped to PM_EVENT_SUSPEND. 530 - 531 - On writes, the PM core relies on that recorded event code and the device/bus 532 - capabilities to determine whether it uses a partial suspend() or resume() 533 - sequence to change things so that the recorded event corresponds to the 534 - numeric parameter. 535 - 536 - - If the bus requires the irqs-disabled suspend_late()/resume_early() 537 - phases, writes fail because those operations are not supported here. 538 - 539 - - If the recorded value is the expected value, nothing is done. 540 - 541 - - If the recorded value is nonzero, the device is partially resumed, 542 - using the bus.resume() and/or class.resume() methods. 543 - 544 - - If the target value is nonzero, the device is partially suspended, 545 - using the class.suspend() and/or bus.suspend() methods and the 546 - PM_EVENT_SUSPEND message. 547 - 548 - Drivers have no way to tell whether their suspend() and resume() calls 549 - have come through the sysfs power/state file or as part of entering a 550 - system sleep state, except that when accessed through sysfs the normal 551 - parent/child sequencing rules are ignored. Drivers (such as bus, bridge, 552 - or hub drivers) which expose child devices may need to enforce those rules 553 - on their own.
+17 -13
Documentation/power/drivers-testing.txt
··· 6 6 Unfortunately, to effectively test the support for the system-wide suspend and 7 7 resume transitions in a driver, it is necessary to suspend and resume a fully 8 8 functional system with this driver loaded. Moreover, that should be done 9 - several times, preferably several times in a row, and separately for the suspend 10 - to disk (STD) and the suspend to RAM (STR) transitions, because each of these 11 - cases involves different ordering of operations and different interactions with 9 + several times, preferably several times in a row, and separately for hibernation 10 + (aka suspend to disk or STD) and suspend to RAM (STR), because each of these 11 + cases involves slightly different operations and different interactions with 12 12 the machine's BIOS. 13 13 14 14 Of course, for this purpose the test system has to be known to suspend and ··· 22 22 Once you have resolved the suspend/resume-related problems with your test system 23 23 without the new driver, you are ready to test it: 24 24 25 - a) Build the driver as a module, load it and try the STD in the test mode (see: 26 - Documents/power/basic-pm-debugging.txt, 1a)). 25 + a) Build the driver as a module, load it and try the test modes of hibernation 26 + (see: Documents/power/basic-pm-debugging.txt, 1). 27 27 28 - b) Load the driver and attempt to suspend to disk in the "reboot", "shutdown" 29 - and "platform" modes (see: Documents/power/basic-pm-debugging.txt, 1). 28 + b) Load the driver and attempt to hibernate in the "reboot", "shutdown" and 29 + "platform" modes (see: Documents/power/basic-pm-debugging.txt, 1). 30 30 31 - c) Compile the driver directly into the kernel and try the STD in the test mode. 31 + c) Compile the driver directly into the kernel and try the test modes of 32 + hibernation. 32 33 33 - d) Attempt to suspend to disk with the driver compiled directly into the kernel 34 - in the "reboot", "shutdown" and "platform" modes. 34 + d) Attempt to hibernate with the driver compiled directly into the kernel 35 + in the "reboot", "shutdown" and "platform" modes. 35 36 36 - e) Attempt to suspend to RAM using the s2ram tool with the driver loaded (see: 37 - Documents/power/basic-pm-debugging.txt, 2). As far as the STR tests are 38 - concerned, it should not matter whether or not the driver is built as a module. 37 + e) Try the test modes of suspend (see: Documents/power/basic-pm-debugging.txt, 38 + 2). [As far as the STR tests are concerned, it should not matter whether or 39 + not the driver is built as a module.] 40 + 41 + f) Attempt to suspend to RAM using the s2ram tool with the driver loaded 42 + (see: Documents/power/basic-pm-debugging.txt, 2). 39 43 40 44 Each of the above tests should be repeated several times and the STD tests 41 45 should be mixed with the STR tests. If any of them fails, the driver cannot be
+8
Documentation/power/notifiers.txt
··· 28 28 hibernation. Device drivers' .resume() callbacks have 29 29 been executed and tasks have been thawed. 30 30 31 + PM_RESTORE_PREPARE The system is going to restore a hibernation image. 32 + If all goes well the restored kernel will issue a 33 + PM_POST_HIBERNATION notification. 34 + 35 + PM_POST_RESTORE An error occurred during the hibernation restore. 36 + Device drivers' .resume() callbacks have been executed 37 + and tasks have been thawed. 38 + 31 39 PM_SUSPEND_PREPARE The system is preparing for a suspend. 32 40 33 41 PM_POST_SUSPEND The system has just resumed or an error occured during
+29 -53
Documentation/power/userland-swsusp.txt
··· 14 14 15 15 The interface consists of a character device providing the open(), 16 16 release(), read(), and write() operations as well as several ioctl() 17 - commands defined in kernel/power/power.h. The major and minor 17 + commands defined in include/linux/suspend_ioctls.h . The major and minor 18 18 numbers of the device are, respectively, 10 and 231, and they can 19 19 be read from /sys/class/misc/snapshot/dev. 20 20 ··· 27 27 The ioctl() commands recognized by the device are: 28 28 29 29 SNAPSHOT_FREEZE - freeze user space processes (the current process is 30 - not frozen); this is required for SNAPSHOT_ATOMIC_SNAPSHOT 30 + not frozen); this is required for SNAPSHOT_CREATE_IMAGE 31 31 and SNAPSHOT_ATOMIC_RESTORE to succeed 32 32 33 33 SNAPSHOT_UNFREEZE - thaw user space processes frozen by SNAPSHOT_FREEZE 34 34 35 - SNAPSHOT_ATOMIC_SNAPSHOT - create a snapshot of the system memory; the 35 + SNAPSHOT_CREATE_IMAGE - create a snapshot of the system memory; the 36 36 last argument of ioctl() should be a pointer to an int variable, 37 37 the value of which will indicate whether the call returned after 38 38 creating the snapshot (1) or after restoring the system memory state 39 39 from it (0) (after resume the system finds itself finishing the 40 - SNAPSHOT_ATOMIC_SNAPSHOT ioctl() again); after the snapshot 40 + SNAPSHOT_CREATE_IMAGE ioctl() again); after the snapshot 41 41 has been created the read() operation can be used to transfer 42 42 it out of the kernel 43 43 ··· 49 49 50 50 SNAPSHOT_FREE - free memory allocated for the snapshot image 51 51 52 - SNAPSHOT_SET_IMAGE_SIZE - set the preferred maximum size of the image 52 + SNAPSHOT_PREF_IMAGE_SIZE - set the preferred maximum size of the image 53 53 (the kernel will do its best to ensure the image size will not exceed 54 54 this number, but if it turns out to be impossible, the kernel will 55 55 create the smallest image possible) 56 56 57 - SNAPSHOT_AVAIL_SWAP - return the amount of available swap in bytes (the last 58 - argument should be a pointer to an unsigned int variable that will 57 + SNAPSHOT_GET_IMAGE_SIZE - return the actual size of the hibernation image 58 + 59 + SNAPSHOT_AVAIL_SWAP_SIZE - return the amount of available swap in bytes (the 60 + last argument should be a pointer to an unsigned int variable that will 59 61 contain the result if the call is successful). 60 62 61 - SNAPSHOT_GET_SWAP_PAGE - allocate a swap page from the resume partition 63 + SNAPSHOT_ALLOC_SWAP_PAGE - allocate a swap page from the resume partition 62 64 (the last argument should be a pointer to a loff_t variable that 63 65 will contain the swap page offset if the call is successful) 64 66 65 - SNAPSHOT_FREE_SWAP_PAGES - free all swap pages allocated with 66 - SNAPSHOT_GET_SWAP_PAGE 67 - 68 - SNAPSHOT_SET_SWAP_FILE - set the resume partition (the last ioctl() argument 69 - should specify the device's major and minor numbers in the old 70 - two-byte format, as returned by the stat() function in the .st_rdev 71 - member of the stat structure) 67 + SNAPSHOT_FREE_SWAP_PAGES - free all swap pages allocated by 68 + SNAPSHOT_ALLOC_SWAP_PAGE 72 69 73 70 SNAPSHOT_SET_SWAP_AREA - set the resume partition and the offset (in <PAGE_SIZE> 74 71 units) from the beginning of the partition at which the swap header is 75 72 located (the last ioctl() argument should point to a struct 76 - resume_swap_area, as defined in kernel/power/power.h, containing the 77 - resume device specification, as for the SNAPSHOT_SET_SWAP_FILE ioctl(), 78 - and the offset); for swap partitions the offset is always 0, but it is 79 - different to zero for swap files (please see 80 - Documentation/swsusp-and-swap-files.txt for details). 81 - The SNAPSHOT_SET_SWAP_AREA ioctl() is considered as a replacement for 82 - SNAPSHOT_SET_SWAP_FILE which is regarded as obsolete. It is 83 - recommended to always use this call, because the code to set the resume 84 - partition may be removed from future kernels 73 + resume_swap_area, as defined in kernel/power/suspend_ioctls.h, 74 + containing the resume device specification and the offset); for swap 75 + partitions the offset is always 0, but it is different from zero for 76 + swap files (see Documentation/swsusp-and-swap-files.txt for details). 77 + 78 + SNAPSHOT_PLATFORM_SUPPORT - enable/disable the hibernation platform support, 79 + depending on the argument value (enable, if the argument is nonzero) 80 + 81 + SNAPSHOT_POWER_OFF - make the kernel transition the system to the hibernation 82 + state (eg. ACPI S4) using the platform (eg. ACPI) driver 85 83 86 84 SNAPSHOT_S2RAM - suspend to RAM; using this call causes the kernel to 87 85 immediately enter the suspend-to-RAM state, so this call must always ··· 90 92 to disk, and then the system is suspended to RAM (this makes it possible 91 93 to resume the system from RAM if there's enough battery power or restore 92 94 its state on the basis of the saved suspend image otherwise) 93 - 94 - SNAPSHOT_PMOPS - enable the usage of the hibernation_ops->prepare, 95 - hibernate_ops->enter and hibernation_ops->finish methods (the in-kernel 96 - swsusp knows these as the "platform method") which are needed on many 97 - machines to (among others) speed up the resume by letting the BIOS skip 98 - some steps or to let the system recognise the correct state of the 99 - hardware after the resume (in particular on many machines this ensures 100 - that unplugged AC adapters get correctly detected and that kacpid does 101 - not run wild after the resume). The last ioctl() argument can take one 102 - of the three values, defined in kernel/power/power.h: 103 - PMOPS_PREPARE - make the kernel carry out the 104 - hibernation_ops->prepare() operation 105 - PMOPS_ENTER - make the kernel power off the system by calling 106 - hibernation_ops->enter() 107 - PMOPS_FINISH - make the kernel carry out the 108 - hibernation_ops->finish() operation 109 - Note that the actual constants are misnamed because they surface 110 - internal kernel implementation details that have changed. 111 95 112 96 The device's read() operation can be used to transfer the snapshot image from 113 97 the kernel. It has the following limitations: ··· 102 122 into the kernel. It has the same limitations as the read() operation. 103 123 104 124 The release() operation frees all memory allocated for the snapshot image 105 - and all swap pages allocated with SNAPSHOT_GET_SWAP_PAGE (if any). 125 + and all swap pages allocated with SNAPSHOT_ALLOC_SWAP_PAGE (if any). 106 126 Thus it is not necessary to use either SNAPSHOT_FREE or 107 127 SNAPSHOT_FREE_SWAP_PAGES before closing the device (in fact it will also 108 128 unfreeze user space processes frozen by SNAPSHOT_UNFREEZE if they are ··· 113 133 partition, or a swap file as storage space (if a swap file is used, the resume 114 134 partition is the partition that holds this file). However, this is not really 115 135 required, as they can use, for example, a special (blank) suspend partition or 116 - a file on a partition that is unmounted before SNAPSHOT_ATOMIC_SNAPSHOT and 136 + a file on a partition that is unmounted before SNAPSHOT_CREATE_IMAGE and 117 137 mounted afterwards. 118 138 119 - These utilities SHOULD NOT make any assumptions regarding the ordering of 120 - data within the snapshot image, except for the image header that MAY be 121 - assumed to start with an swsusp_info structure, as specified in 122 - kernel/power/power.h. This structure MAY be used by the userland utilities 123 - to obtain some information about the snapshot image, such as the size 124 - of the snapshot image, including the metadata and the header itself, 125 - contained in the .size member of swsusp_info. 139 + These utilities MUST NOT make any assumptions regarding the ordering of 140 + data within the snapshot image. The contents of the image are entirely owned 141 + by the kernel and its structure may be changed in future kernel releases. 126 142 127 143 The snapshot image MUST be written to the kernel unaltered (ie. all of the image 128 144 data, metadata and header MUST be written in _exactly_ the same amount, form ··· 135 159 The suspending and resuming utilities MUST lock themselves in memory, 136 160 preferrably using mlockall(), before calling SNAPSHOT_FREEZE. 137 161 138 - The suspending utility MUST check the value stored by SNAPSHOT_ATOMIC_SNAPSHOT 162 + The suspending utility MUST check the value stored by SNAPSHOT_CREATE_IMAGE 139 163 in the memory location pointed to by the last argument of ioctl() and proceed 140 164 in accordance with it: 141 165 1. If the value is 1 (ie. the system memory snapshot has just been ··· 149 173 image has been saved. 150 174 (b) The suspending utility SHOULD NOT attempt to perform any 151 175 file system operations (including reads) on the file systems 152 - that were mounted before SNAPSHOT_ATOMIC_SNAPSHOT has been 176 + that were mounted before SNAPSHOT_CREATE_IMAGE has been 153 177 called. However, it MAY mount a file system that was not 154 178 mounted at that time and perform some operations on it (eg. 155 179 use it for saving the image).
+3
arch/arm/Kconfig
··· 1030 1030 1031 1031 source "kernel/power/Kconfig" 1032 1032 1033 + config ARCH_SUSPEND_POSSIBLE 1034 + def_bool y 1035 + 1033 1036 endmenu 1034 1037 1035 1038 source "net/Kconfig"
+13 -4
arch/arm/mach-at91/pm.c
··· 52 52 /* 53 53 * Called after processes are frozen, but before we shutdown devices. 54 54 */ 55 - static int at91_pm_set_target(suspend_state_t state) 55 + static int at91_pm_begin(suspend_state_t state) 56 56 { 57 57 target_state = state; 58 58 return 0; ··· 202 202 return 0; 203 203 } 204 204 205 + /* 206 + * Called right prior to thawing processes. 207 + */ 208 + static void at91_pm_end(void) 209 + { 210 + target_state = PM_SUSPEND_ON; 211 + } 212 + 205 213 206 214 static struct platform_suspend_ops at91_pm_ops ={ 207 - .valid = at91_pm_valid_state, 208 - .set_target = at91_pm_set_target, 209 - .enter = at91_pm_enter, 215 + .valid = at91_pm_valid_state, 216 + .begin = at91_pm_begin, 217 + .enter = at91_pm_enter, 218 + .end = at91_pm_end, 210 219 }; 211 220 212 221 static int __init at91_pm_init(void)
+4
arch/blackfin/Kconfig
··· 898 898 menu "Power management options" 899 899 source "kernel/power/Kconfig" 900 900 901 + config ARCH_SUSPEND_POSSIBLE 902 + def_bool y 903 + depends on !SMP 904 + 901 905 choice 902 906 prompt "Select PM Wakeup Event Source" 903 907 default PM_WAKEUP_GPIO_BY_SIC_IWR
+5
arch/frv/Kconfig
··· 352 352 # should probably wait a while. 353 353 354 354 menu "Power management options" 355 + 356 + config ARCH_SUSPEND_POSSIBLE 357 + def_bool y 358 + depends on !SMP 359 + 355 360 source kernel/power/Kconfig 356 361 endmenu 357 362
+4
arch/mips/Kconfig
··· 2081 2081 2082 2082 menu "Power management options" 2083 2083 2084 + config ARCH_SUSPEND_POSSIBLE 2085 + def_bool y 2086 + depends on !SMP 2087 + 2084 2088 source "kernel/power/Kconfig" 2085 2089 2086 2090 endmenu
+20 -2
arch/powerpc/Kconfig
··· 151 151 config REDBOOT 152 152 bool 153 153 154 - config PPC64_SWSUSP 154 + config HIBERNATE_32 155 155 bool 156 - depends on PPC64 && (BROKEN || (PPC_PMAC64 && EXPERIMENTAL)) 156 + depends on (PPC_PMAC && !SMP) || BROKEN 157 157 default y 158 + 159 + config HIBERNATE_64 160 + bool 161 + depends on BROKEN || (PPC_PMAC64 && EXPERIMENTAL) 162 + default y 163 + 164 + config ARCH_HIBERNATION_POSSIBLE 165 + bool 166 + depends on (PPC64 && HIBERNATE_64) || (PPC32 && HIBERNATE_32) 167 + default y 168 + 169 + config ARCH_SUSPEND_POSSIBLE 170 + def_bool y 171 + depends on ADB_PMU || PPC_EFIKA || PPC_LITE5200 158 172 159 173 config PPC_DCR_NATIVE 160 174 bool ··· 405 391 most cases you will need to specify the root device here. 406 392 407 393 if !44x || BROKEN 394 + config ARCH_WANTS_FREEZER_CONTROL 395 + def_bool y 396 + depends on ADB_PMU 397 + 408 398 source kernel/power/Kconfig 409 399 endif 410 400
+8 -2
arch/powerpc/platforms/52xx/lite5200_pm.c
··· 31 31 } 32 32 } 33 33 34 - static int lite5200_pm_set_target(suspend_state_t state) 34 + static int lite5200_pm_begin(suspend_state_t state) 35 35 { 36 36 if (lite5200_pm_valid(state)) { 37 37 lite5200_pm_target_state = state; ··· 219 219 mpc52xx_pm_finish(); 220 220 } 221 221 222 + static void lite5200_pm_end(void) 223 + { 224 + lite5200_pm_target_state = PM_SUSPEND_ON; 225 + } 226 + 222 227 static struct platform_suspend_ops lite5200_pm_ops = { 223 228 .valid = lite5200_pm_valid, 224 - .set_target = lite5200_pm_set_target, 229 + .begin = lite5200_pm_begin, 225 230 .prepare = lite5200_pm_prepare, 226 231 .enter = lite5200_pm_enter, 227 232 .finish = lite5200_pm_finish, 233 + .end = lite5200_pm_end, 228 234 }; 229 235 230 236 int __init lite5200_pm_init(void)
+4
arch/sh/Kconfig
··· 882 882 menu "Power management options (EXPERIMENTAL)" 883 883 depends on EXPERIMENTAL && SYS_SUPPORTS_PM 884 884 885 + config ARCH_SUSPEND_POSSIBLE 886 + def_bool y 887 + depends on !SMP 888 + 885 889 source kernel/power/Kconfig 886 890 887 891 endmenu
+8
arch/x86/Kconfig
··· 112 112 113 113 select HAVE_KVM 114 114 115 + config ARCH_HIBERNATION_POSSIBLE 116 + def_bool y 117 + depends on !SMP || !X86_VOYAGER 118 + 119 + config ARCH_SUSPEND_POSSIBLE 120 + def_bool y 121 + depends on !X86_VOYAGER 122 + 115 123 config ZONE_DMA32 116 124 bool 117 125 default X86_64
+6 -2
arch/x86/kernel/suspend_64.c
··· 140 140 int cpu = smp_processor_id(); 141 141 struct tss_struct *t = &per_cpu(init_tss, cpu); 142 142 143 - set_tss_desc(cpu,t); /* This just modifies memory; should not be necessary. But... This is necessary, because 386 hardware has concept of busy TSS or some similar stupidity. */ 143 + /* 144 + * This just modifies memory; should not be necessary. But... This 145 + * is necessary, because 386 hardware has concept of busy TSS or some 146 + * similar stupidity. 147 + */ 148 + set_tss_desc(cpu, t); 144 149 145 150 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9; 146 151 ··· 165 160 loaddebug(&current->thread, 6); 166 161 loaddebug(&current->thread, 7); 167 162 } 168 - 169 163 } 170 164 171 165 #ifdef CONFIG_HIBERNATION
+5 -5
arch/x86/mm/init_32.c
··· 423 423 paravirt_pagetable_setup_done(pgd_base); 424 424 } 425 425 426 - #if defined(CONFIG_HIBERNATION) || defined(CONFIG_ACPI) 426 + #ifdef CONFIG_ACPI_SLEEP 427 427 /* 428 - * Swap suspend & friends need this for resume because things like the intel-agp 428 + * ACPI suspend needs this for resume, because things like the intel-agp 429 429 * driver might have split up a kernel 4MB mapping. 430 430 */ 431 - char __nosavedata swsusp_pg_dir[PAGE_SIZE] 431 + char swsusp_pg_dir[PAGE_SIZE] 432 432 __attribute__ ((aligned(PAGE_SIZE))); 433 433 434 434 static inline void save_pg_dir(void) 435 435 { 436 436 memcpy(swsusp_pg_dir, swapper_pg_dir, PAGE_SIZE); 437 437 } 438 - #else 438 + #else /* !CONFIG_ACPI_SLEEP */ 439 439 static inline void save_pg_dir(void) 440 440 { 441 441 } 442 - #endif 442 + #endif /* !CONFIG_ACPI_SLEEP */ 443 443 444 444 void zap_low_mappings(void) 445 445 {
+57 -22
drivers/acpi/hardware/hwsleep.c
··· 192 192 arg.type = ACPI_TYPE_INTEGER; 193 193 arg.integer.value = sleep_state; 194 194 195 - /* Run the _PTS and _GTS methods */ 195 + /* Run the _PTS method */ 196 196 197 197 status = acpi_evaluate_object(NULL, METHOD_NAME__PTS, &arg_list, NULL); 198 - if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { 199 - return_ACPI_STATUS(status); 200 - } 201 - 202 - status = acpi_evaluate_object(NULL, METHOD_NAME__GTS, &arg_list, NULL); 203 198 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { 204 199 return_ACPI_STATUS(status); 205 200 } ··· 229 234 "While executing method _SST")); 230 235 } 231 236 232 - /* Disable/Clear all GPEs */ 233 - 234 - status = acpi_hw_disable_all_gpes(); 235 - 236 237 return_ACPI_STATUS(status); 237 238 } 238 239 ··· 253 262 struct acpi_bit_register_info *sleep_type_reg_info; 254 263 struct acpi_bit_register_info *sleep_enable_reg_info; 255 264 u32 in_value; 265 + struct acpi_object_list arg_list; 266 + union acpi_object arg; 256 267 acpi_status status; 257 268 258 269 ACPI_FUNCTION_TRACE(acpi_enter_sleep_state); ··· 297 304 298 305 status = acpi_hw_enable_all_wakeup_gpes(); 299 306 if (ACPI_FAILURE(status)) { 307 + return_ACPI_STATUS(status); 308 + } 309 + 310 + /* Execute the _GTS method */ 311 + 312 + arg_list.count = 1; 313 + arg_list.pointer = &arg; 314 + arg.type = ACPI_TYPE_INTEGER; 315 + arg.integer.value = sleep_state; 316 + 317 + status = acpi_evaluate_object(NULL, METHOD_NAME__GTS, &arg_list, NULL); 318 + if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { 300 319 return_ACPI_STATUS(status); 301 320 } 302 321 ··· 478 473 479 474 /******************************************************************************* 480 475 * 481 - * FUNCTION: acpi_leave_sleep_state 476 + * FUNCTION: acpi_leave_sleep_state_prep 482 477 * 483 - * PARAMETERS: sleep_state - Which sleep state we just exited 478 + * PARAMETERS: sleep_state - Which sleep state we are exiting 484 479 * 485 480 * RETURN: Status 486 481 * 487 - * DESCRIPTION: Perform OS-independent ACPI cleanup after a sleep 488 - * Called with interrupts ENABLED. 482 + * DESCRIPTION: Perform the first state of OS-independent ACPI cleanup after a 483 + * sleep. 484 + * Called with interrupts DISABLED. 489 485 * 490 486 ******************************************************************************/ 491 - acpi_status acpi_leave_sleep_state(u8 sleep_state) 487 + acpi_status acpi_leave_sleep_state_prep(u8 sleep_state) 492 488 { 493 489 struct acpi_object_list arg_list; 494 490 union acpi_object arg; ··· 499 493 u32 PM1Acontrol; 500 494 u32 PM1Bcontrol; 501 495 502 - ACPI_FUNCTION_TRACE(acpi_leave_sleep_state); 496 + ACPI_FUNCTION_TRACE(acpi_leave_sleep_state_prep); 503 497 504 498 /* 505 499 * Set SLP_TYPE and SLP_EN to state S0. ··· 546 540 } 547 541 } 548 542 543 + /* Execute the _BFS method */ 544 + 545 + arg_list.count = 1; 546 + arg_list.pointer = &arg; 547 + arg.type = ACPI_TYPE_INTEGER; 548 + arg.integer.value = sleep_state; 549 + 550 + status = acpi_evaluate_object(NULL, METHOD_NAME__BFS, &arg_list, NULL); 551 + if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { 552 + ACPI_EXCEPTION((AE_INFO, status, "During Method _BFS")); 553 + } 554 + 555 + return_ACPI_STATUS(status); 556 + } 557 + 558 + /******************************************************************************* 559 + * 560 + * FUNCTION: acpi_leave_sleep_state 561 + * 562 + * PARAMETERS: sleep_state - Which sleep state we just exited 563 + * 564 + * RETURN: Status 565 + * 566 + * DESCRIPTION: Perform OS-independent ACPI cleanup after a sleep 567 + * Called with interrupts ENABLED. 568 + * 569 + ******************************************************************************/ 570 + acpi_status acpi_leave_sleep_state(u8 sleep_state) 571 + { 572 + struct acpi_object_list arg_list; 573 + union acpi_object arg; 574 + acpi_status status; 575 + 576 + ACPI_FUNCTION_TRACE(acpi_leave_sleep_state); 577 + 549 578 /* Ensure enter_sleep_state_prep -> enter_sleep_state ordering */ 550 579 551 580 acpi_gbl_sleep_type_a = ACPI_SLEEP_TYPE_INVALID; ··· 597 556 status = acpi_evaluate_object(NULL, METHOD_NAME__SST, &arg_list, NULL); 598 557 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { 599 558 ACPI_EXCEPTION((AE_INFO, status, "During Method _SST")); 600 - } 601 - 602 - arg.integer.value = sleep_state; 603 - status = acpi_evaluate_object(NULL, METHOD_NAME__BFS, &arg_list, NULL); 604 - if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { 605 - ACPI_EXCEPTION((AE_INFO, status, "During Method _BFS")); 606 559 } 607 560 608 561 /*
+108 -21
drivers/acpi/sleep/main.c
··· 26 26 27 27 #ifdef CONFIG_PM_SLEEP 28 28 static u32 acpi_target_sleep_state = ACPI_STATE_S0; 29 + static bool acpi_sleep_finish_wake_up; 30 + 31 + /* 32 + * ACPI 2.0 and later want us to execute _PTS after suspending devices, so we 33 + * allow the user to request that behavior by using the 'acpi_new_pts_ordering' 34 + * kernel command line option that causes the following variable to be set. 35 + */ 36 + static bool new_pts_ordering; 37 + 38 + static int __init acpi_new_pts_ordering(char *str) 39 + { 40 + new_pts_ordering = true; 41 + return 1; 42 + } 43 + __setup("acpi_new_pts_ordering", acpi_new_pts_ordering); 29 44 #endif 30 45 31 - int acpi_sleep_prepare(u32 acpi_state) 46 + static int acpi_sleep_prepare(u32 acpi_state) 32 47 { 33 48 #ifdef CONFIG_ACPI_SLEEP 34 49 /* do we have a wakeup address for S2 and S3? */ ··· 59 44 ACPI_FLUSH_CPU_CACHE(); 60 45 acpi_enable_wakeup_device_prep(acpi_state); 61 46 #endif 47 + printk(KERN_INFO PREFIX "Preparing to enter system sleep state S%d\n", 48 + acpi_state); 62 49 acpi_enter_sleep_state_prep(acpi_state); 63 50 return 0; 64 51 } ··· 80 63 static int init_8259A_after_S1; 81 64 82 65 /** 83 - * acpi_pm_set_target - Set the target system sleep state to the state 66 + * acpi_pm_begin - Set the target system sleep state to the state 84 67 * associated with given @pm_state, if supported. 85 68 */ 86 69 87 - static int acpi_pm_set_target(suspend_state_t pm_state) 70 + static int acpi_pm_begin(suspend_state_t pm_state) 88 71 { 89 72 u32 acpi_state = acpi_suspend_states[pm_state]; 90 73 int error = 0; 91 74 92 75 if (sleep_states[acpi_state]) { 93 76 acpi_target_sleep_state = acpi_state; 77 + if (new_pts_ordering) 78 + return 0; 79 + 80 + error = acpi_sleep_prepare(acpi_state); 81 + if (error) 82 + acpi_target_sleep_state = ACPI_STATE_S0; 83 + else 84 + acpi_sleep_finish_wake_up = true; 94 85 } else { 95 86 printk(KERN_ERR "ACPI does not support this state: %d\n", 96 87 pm_state); ··· 116 91 117 92 static int acpi_pm_prepare(void) 118 93 { 119 - int error = acpi_sleep_prepare(acpi_target_sleep_state); 94 + if (new_pts_ordering) { 95 + int error = acpi_sleep_prepare(acpi_target_sleep_state); 120 96 121 - if (error) 122 - acpi_target_sleep_state = ACPI_STATE_S0; 97 + if (error) { 98 + acpi_target_sleep_state = ACPI_STATE_S0; 99 + return error; 100 + } 101 + acpi_sleep_finish_wake_up = true; 102 + } 123 103 124 - return error; 104 + return ACPI_SUCCESS(acpi_hw_disable_all_gpes()) ? 0 : -EFAULT; 125 105 } 126 106 127 107 /** ··· 150 120 if (acpi_state == ACPI_STATE_S3) { 151 121 int error = acpi_save_state_mem(); 152 122 153 - if (error) { 154 - acpi_target_sleep_state = ACPI_STATE_S0; 123 + if (error) 155 124 return error; 156 - } 157 125 } 158 126 159 127 local_irq_save(flags); ··· 167 139 break; 168 140 } 169 141 142 + /* Reprogram control registers and execute _BFS */ 143 + acpi_leave_sleep_state_prep(acpi_state); 144 + 170 145 /* ACPI 3.0 specs (P62) says that it's the responsabilty 171 146 * of the OSPM to clear the status bit [ implying that the 172 147 * POWER_BUTTON event should not reach userspace ] 173 148 */ 174 149 if (ACPI_SUCCESS(status) && (acpi_state == ACPI_STATE_S3)) 175 150 acpi_clear_event(ACPI_EVENT_POWER_BUTTON); 151 + 152 + /* 153 + * Disable and clear GPE status before interrupt is enabled. Some GPEs 154 + * (like wakeup GPE) haven't handler, this can avoid such GPE misfire. 155 + * acpi_leave_sleep_state will reenable specific GPEs later 156 + */ 157 + acpi_hw_disable_all_gpes(); 176 158 177 159 local_irq_restore(flags); 178 160 printk(KERN_DEBUG "Back to C!\n"); ··· 195 157 } 196 158 197 159 /** 198 - * acpi_pm_finish - Finish up suspend sequence. 160 + * acpi_pm_finish - Instruct the platform to leave a sleep state. 199 161 * 200 162 * This is called after we wake back up (or if entering the sleep state 201 163 * failed). ··· 212 174 acpi_set_firmware_waking_vector((acpi_physical_address) 0); 213 175 214 176 acpi_target_sleep_state = ACPI_STATE_S0; 177 + acpi_sleep_finish_wake_up = false; 215 178 216 179 #ifdef CONFIG_X86 217 180 if (init_8259A_after_S1) { ··· 220 181 init_8259A(0); 221 182 } 222 183 #endif 184 + } 185 + 186 + /** 187 + * acpi_pm_end - Finish up suspend sequence. 188 + */ 189 + 190 + static void acpi_pm_end(void) 191 + { 192 + /* 193 + * This is necessary in case acpi_pm_finish() is not called directly 194 + * during a failing transition to a sleep state. 195 + */ 196 + if (acpi_sleep_finish_wake_up) 197 + acpi_pm_finish(); 223 198 } 224 199 225 200 static int acpi_pm_state_valid(suspend_state_t pm_state) ··· 254 201 255 202 static struct platform_suspend_ops acpi_pm_ops = { 256 203 .valid = acpi_pm_state_valid, 257 - .set_target = acpi_pm_set_target, 204 + .begin = acpi_pm_begin, 258 205 .prepare = acpi_pm_prepare, 259 206 .enter = acpi_pm_enter, 260 207 .finish = acpi_pm_finish, 208 + .end = acpi_pm_end, 261 209 }; 262 210 263 211 /* ··· 283 229 #endif /* CONFIG_SUSPEND */ 284 230 285 231 #ifdef CONFIG_HIBERNATION 286 - static int acpi_hibernation_start(void) 232 + static int acpi_hibernation_begin(void) 287 233 { 234 + int error; 235 + 288 236 acpi_target_sleep_state = ACPI_STATE_S4; 289 - return 0; 237 + if (new_pts_ordering) 238 + return 0; 239 + 240 + error = acpi_sleep_prepare(ACPI_STATE_S4); 241 + if (error) 242 + acpi_target_sleep_state = ACPI_STATE_S0; 243 + else 244 + acpi_sleep_finish_wake_up = true; 245 + 246 + return error; 290 247 } 291 248 292 249 static int acpi_hibernation_prepare(void) 293 250 { 294 - return acpi_sleep_prepare(ACPI_STATE_S4); 251 + if (new_pts_ordering) { 252 + int error = acpi_sleep_prepare(ACPI_STATE_S4); 253 + 254 + if (error) { 255 + acpi_target_sleep_state = ACPI_STATE_S0; 256 + return error; 257 + } 258 + acpi_sleep_finish_wake_up = true; 259 + } 260 + 261 + return ACPI_SUCCESS(acpi_hw_disable_all_gpes()) ? 0 : -EFAULT; 295 262 } 296 263 297 264 static int acpi_hibernation_enter(void) ··· 326 251 acpi_enable_wakeup_device(ACPI_STATE_S4); 327 252 /* This shouldn't return. If it returns, we have a problem */ 328 253 status = acpi_enter_sleep_state(ACPI_STATE_S4); 254 + /* Reprogram control registers and execute _BFS */ 255 + acpi_leave_sleep_state_prep(ACPI_STATE_S4); 329 256 local_irq_restore(flags); 330 257 331 258 return ACPI_SUCCESS(status) ? 0 : -EFAULT; ··· 340 263 * enable it here. 341 264 */ 342 265 acpi_enable(); 266 + /* Reprogram control registers and execute _BFS */ 267 + acpi_leave_sleep_state_prep(ACPI_STATE_S4); 343 268 } 344 269 345 270 static void acpi_hibernation_finish(void) 346 271 { 347 - /* 348 - * If ACPI is not enabled by the BIOS and the boot kernel, we need to 349 - * enable it here. 350 - */ 351 - acpi_enable(); 352 272 acpi_disable_wakeup_device(ACPI_STATE_S4); 353 273 acpi_leave_sleep_state(ACPI_STATE_S4); 354 274 ··· 353 279 acpi_set_firmware_waking_vector((acpi_physical_address) 0); 354 280 355 281 acpi_target_sleep_state = ACPI_STATE_S0; 282 + acpi_sleep_finish_wake_up = false; 283 + } 284 + 285 + static void acpi_hibernation_end(void) 286 + { 287 + /* 288 + * This is necessary in case acpi_hibernation_finish() is not called 289 + * directly during a failing transition to the sleep state. 290 + */ 291 + if (acpi_sleep_finish_wake_up) 292 + acpi_hibernation_finish(); 356 293 } 357 294 358 295 static int acpi_hibernation_pre_restore(void) ··· 381 296 } 382 297 383 298 static struct platform_hibernation_ops acpi_hibernation_ops = { 384 - .start = acpi_hibernation_start, 299 + .begin = acpi_hibernation_begin, 300 + .end = acpi_hibernation_end, 385 301 .pre_snapshot = acpi_hibernation_prepare, 386 302 .finish = acpi_hibernation_finish, 387 303 .prepare = acpi_hibernation_prepare, ··· 489 403 { 490 404 /* Prepare to power off the system */ 491 405 acpi_sleep_prepare(ACPI_STATE_S5); 406 + acpi_hw_disable_all_gpes(); 492 407 } 493 408 494 409 static void acpi_power_off(void)
-2
drivers/acpi/sleep/sleep.h
··· 5 5 extern void acpi_enable_wakeup_device_prep(u8 sleep_state); 6 6 extern void acpi_enable_wakeup_device(u8 sleep_state); 7 7 extern void acpi_disable_wakeup_device(u8 sleep_state); 8 - 9 - extern int acpi_sleep_prepare(u32 acpi_state);
+1 -1
drivers/base/power/Makefile
··· 1 1 obj-$(CONFIG_PM) += sysfs.o 2 2 obj-$(CONFIG_PM_SLEEP) += main.o 3 - obj-$(CONFIG_PM_TRACE) += trace.o 3 + obj-$(CONFIG_PM_TRACE_RTC) += trace.o 4 4 5 5 ccflags-$(CONFIG_DEBUG_DRIVER) := -DDEBUG 6 6 ccflags-$(CONFIG_PM_VERBOSE) += -DDEBUG
+2
include/acpi/acpixf.h
··· 335 335 336 336 acpi_status asmlinkage acpi_enter_sleep_state_s4bios(void); 337 337 338 + acpi_status acpi_leave_sleep_state_prep(u8 sleep_state); 339 + 338 340 acpi_status acpi_leave_sleep_state(u8 sleep_state); 339 341 340 342 #endif /* __ACXFACE_H__ */
+1
include/linux/Kbuild
··· 143 143 header-y += sockios.h 144 144 header-y += som.h 145 145 header-y += sound.h 146 + header-y += suspend_ioctls.h 146 147 header-y += taskstats.h 147 148 header-y += telephony.h 148 149 header-y += termios.h
+2
include/linux/notifier.h
··· 228 228 #define PM_POST_HIBERNATION 0x0002 /* Hibernation finished */ 229 229 #define PM_SUSPEND_PREPARE 0x0003 /* Going to suspend the system */ 230 230 #define PM_POST_SUSPEND 0x0004 /* Suspend finished */ 231 + #define PM_RESTORE_PREPARE 0x0005 /* Going to restore a saved image */ 232 + #define PM_POST_RESTORE 0x0006 /* Restore failed */ 231 233 232 234 /* Console keyboard events. 233 235 * Note: KBD_KEYCODE is always sent before KBD_UNBOUND_KEYCODE, KBD_UNICODE and
+29 -27
include/linux/suspend.h
··· 38 38 * There is the %suspend_valid_only_mem function available that can be 39 39 * assigned to this if the platform only supports mem sleep. 40 40 * 41 - * @set_target: Tell the platform which system sleep state is going to be 42 - * entered. 43 - * @set_target() is executed right prior to suspending devices. The 44 - * information conveyed to the platform code by @set_target() should be 45 - * disregarded by the platform as soon as @finish() is executed and if 46 - * @prepare() fails. If @set_target() fails (ie. returns nonzero), 41 + * @begin: Initialise a transition to given system sleep state. 42 + * @begin() is executed right prior to suspending devices. The information 43 + * conveyed to the platform code by @begin() should be disregarded by it as 44 + * soon as @end() is executed. If @begin() fails (ie. returns nonzero), 47 45 * @prepare(), @enter() and @finish() will not be called by the PM core. 48 46 * This callback is optional. However, if it is implemented, the argument 49 - * passed to @enter() is meaningless and should be ignored. 47 + * passed to @enter() is redundant and should be ignored. 50 48 * 51 49 * @prepare: Prepare the platform for entering the system sleep state indicated 52 - * by @set_target(). 50 + * by @begin(). 53 51 * @prepare() is called right after devices have been suspended (ie. the 54 52 * appropriate .suspend() method has been executed for each device) and 55 53 * before the nonboot CPUs are disabled (it is executed with IRQs enabled). ··· 55 57 * error code otherwise, in which case the system cannot enter the desired 56 58 * sleep state (@enter() and @finish() will not be called in that case). 57 59 * 58 - * @enter: Enter the system sleep state indicated by @set_target() or 59 - * represented by the argument if @set_target() is not implemented. 60 + * @enter: Enter the system sleep state indicated by @begin() or represented by 61 + * the argument if @begin() is not implemented. 60 62 * This callback is mandatory. It returns 0 on success or a negative 61 63 * error code otherwise, in which case the system cannot enter the desired 62 64 * sleep state. ··· 67 69 * This callback is optional, but should be implemented by the platforms 68 70 * that implement @prepare(). If implemented, it is always called after 69 71 * @enter() (even if @enter() fails). 72 + * 73 + * @end: Called by the PM core right after resuming devices, to indicate to 74 + * the platform that the system has returned to the working state or 75 + * the transition to the sleep state has been aborted. 76 + * This callback is optional, but should be implemented by the platforms 77 + * that implement @begin(), but platforms implementing @begin() should 78 + * also provide a @end() which cleans up transitions aborted before 79 + * @enter(). 70 80 */ 71 81 struct platform_suspend_ops { 72 82 int (*valid)(suspend_state_t state); 73 - int (*set_target)(suspend_state_t state); 83 + int (*begin)(suspend_state_t state); 74 84 int (*prepare)(void); 75 85 int (*enter)(suspend_state_t state); 76 86 void (*finish)(void); 87 + void (*end)(void); 77 88 }; 78 89 79 90 #ifdef CONFIG_SUSPEND ··· 136 129 /** 137 130 * struct platform_hibernation_ops - hibernation platform support 138 131 * 139 - * The methods in this structure allow a platform to override the default 140 - * mechanism of shutting down the machine during a hibernation transition. 132 + * The methods in this structure allow a platform to carry out special 133 + * operations required by it during a hibernation transition. 141 134 * 142 - * All three methods must be assigned. 135 + * All the methods below must be implemented. 143 136 * 144 - * @start: Tell the platform driver that we're starting hibernation. 137 + * @begin: Tell the platform driver that we're starting hibernation. 145 138 * Called right after shrinking memory and before freezing devices. 139 + * 140 + * @end: Called by the PM core right after resuming devices, to indicate to 141 + * the platform that the system has returned to the working state. 146 142 * 147 143 * @pre_snapshot: Prepare the platform for creating the hibernation image. 148 144 * Called right after devices have been frozen and before the nonboot ··· 181 171 * thawing devices (runs with IRQs on). 182 172 */ 183 173 struct platform_hibernation_ops { 184 - int (*start)(void); 174 + int (*begin)(void); 175 + void (*end)(void); 185 176 int (*pre_snapshot)(void); 186 177 void (*finish)(void); 187 178 int (*prepare)(void); ··· 224 213 void restore_processor_state(void); 225 214 226 215 /* kernel/power/main.c */ 227 - extern struct blocking_notifier_head pm_chain_head; 228 - 229 - static inline int register_pm_notifier(struct notifier_block *nb) 230 - { 231 - return blocking_notifier_chain_register(&pm_chain_head, nb); 232 - } 233 - 234 - static inline int unregister_pm_notifier(struct notifier_block *nb) 235 - { 236 - return blocking_notifier_chain_unregister(&pm_chain_head, nb); 237 - } 216 + extern int register_pm_notifier(struct notifier_block *nb); 217 + extern int unregister_pm_notifier(struct notifier_block *nb); 238 218 239 219 #define pm_notifier(fn, pri) { \ 240 220 static struct notifier_block fn##_nb = \
+32
include/linux/suspend_ioctls.h
··· 1 + #ifndef _LINUX_SUSPEND_IOCTLS_H 2 + #define _LINUX_SUSPEND_IOCTLS_H 3 + 4 + /* 5 + * This structure is used to pass the values needed for the identification 6 + * of the resume swap area from a user space to the kernel via the 7 + * SNAPSHOT_SET_SWAP_AREA ioctl 8 + */ 9 + struct resume_swap_area { 10 + loff_t offset; 11 + u_int32_t dev; 12 + } __attribute__((packed)); 13 + 14 + #define SNAPSHOT_IOC_MAGIC '3' 15 + #define SNAPSHOT_FREEZE _IO(SNAPSHOT_IOC_MAGIC, 1) 16 + #define SNAPSHOT_UNFREEZE _IO(SNAPSHOT_IOC_MAGIC, 2) 17 + #define SNAPSHOT_ATOMIC_RESTORE _IO(SNAPSHOT_IOC_MAGIC, 4) 18 + #define SNAPSHOT_FREE _IO(SNAPSHOT_IOC_MAGIC, 5) 19 + #define SNAPSHOT_FREE_SWAP_PAGES _IO(SNAPSHOT_IOC_MAGIC, 9) 20 + #define SNAPSHOT_S2RAM _IO(SNAPSHOT_IOC_MAGIC, 11) 21 + #define SNAPSHOT_SET_SWAP_AREA _IOW(SNAPSHOT_IOC_MAGIC, 13, \ 22 + struct resume_swap_area) 23 + #define SNAPSHOT_GET_IMAGE_SIZE _IOR(SNAPSHOT_IOC_MAGIC, 14, loff_t) 24 + #define SNAPSHOT_PLATFORM_SUPPORT _IO(SNAPSHOT_IOC_MAGIC, 15) 25 + #define SNAPSHOT_POWER_OFF _IO(SNAPSHOT_IOC_MAGIC, 16) 26 + #define SNAPSHOT_CREATE_IMAGE _IOW(SNAPSHOT_IOC_MAGIC, 17, int) 27 + #define SNAPSHOT_PREF_IMAGE_SIZE _IO(SNAPSHOT_IOC_MAGIC, 18) 28 + #define SNAPSHOT_AVAIL_SWAP_SIZE _IOR(SNAPSHOT_IOC_MAGIC, 19, loff_t) 29 + #define SNAPSHOT_ALLOC_SWAP_PAGE _IOR(SNAPSHOT_IOC_MAGIC, 20, loff_t) 30 + #define SNAPSHOT_IOC_MAXNR 20 31 + 32 + #endif /* _LINUX_SUSPEND_IOCTLS_H */
+35 -30
kernel/power/Kconfig
··· 44 44 ---help--- 45 45 This option enables verbose messages from the Power Management code. 46 46 47 + config CAN_PM_TRACE 48 + def_bool y 49 + depends on PM_DEBUG && PM_SLEEP && EXPERIMENTAL 50 + 47 51 config PM_TRACE 52 + bool 53 + help 54 + This enables code to save the last PM event point across 55 + reboot. The architecture needs to support this, x86 for 56 + example does by saving things in the RTC, see below. 57 + 58 + The architecture specific code must provide the extern 59 + functions from <linux/resume-trace.h> as well as the 60 + <asm/resume-trace.h> header with a TRACE_RESUME() macro. 61 + 62 + The way the information is presented is architecture- 63 + dependent, x86 will print the information during a 64 + late_initcall. 65 + 66 + config PM_TRACE_RTC 48 67 bool "Suspend/resume event tracing" 49 - depends on PM_DEBUG && X86 && PM_SLEEP && EXPERIMENTAL 68 + depends on CAN_PM_TRACE 69 + depends on X86 70 + select PM_TRACE 50 71 default n 51 72 ---help--- 52 73 This enables some cheesy code to save the last PM event point in the ··· 84 63 85 64 config PM_SLEEP_SMP 86 65 bool 87 - depends on SUSPEND_SMP_POSSIBLE || HIBERNATION_SMP_POSSIBLE 66 + depends on SMP 67 + depends on ARCH_SUSPEND_POSSIBLE || ARCH_HIBERNATION_POSSIBLE 88 68 depends on PM_SLEEP 89 69 select HOTPLUG_CPU 90 70 default y ··· 95 73 depends on SUSPEND || HIBERNATION 96 74 default y 97 75 98 - config SUSPEND_UP_POSSIBLE 99 - bool 100 - depends on (X86 && !X86_VOYAGER) || PPC || ARM || BLACKFIN || MIPS \ 101 - || SUPERH || FRV 102 - depends on !SMP 103 - default y 104 - 105 - config SUSPEND_SMP_POSSIBLE 106 - bool 107 - depends on (X86 && !X86_VOYAGER) \ 108 - || (PPC && (PPC_PSERIES || PPC_PMAC)) || ARM 109 - depends on SMP 110 - default y 111 - 112 76 config SUSPEND 113 77 bool "Suspend to RAM and standby" 114 - depends on PM 115 - depends on SUSPEND_UP_POSSIBLE || SUSPEND_SMP_POSSIBLE 78 + depends on PM && ARCH_SUSPEND_POSSIBLE 116 79 default y 117 80 ---help--- 118 81 Allow the system to enter sleep states in which main memory is 119 82 powered and thus its contents are preserved, such as the 120 - suspend-to-RAM state (i.e. the ACPI S3 state). 83 + suspend-to-RAM state (e.g. the ACPI S3 state). 121 84 122 - config HIBERNATION_UP_POSSIBLE 123 - bool 124 - depends on X86 || PPC64_SWSUSP || PPC32 125 - depends on !SMP 85 + config SUSPEND_FREEZER 86 + bool "Enable freezer for suspend to RAM/standby" \ 87 + if ARCH_WANTS_FREEZER_CONTROL || BROKEN 88 + depends on SUSPEND 126 89 default y 90 + help 91 + This allows you to turn off the freezer for suspend. If this is 92 + done, no tasks are frozen for suspend to RAM/standby. 127 93 128 - config HIBERNATION_SMP_POSSIBLE 129 - bool 130 - depends on (X86 && !X86_VOYAGER) || PPC64_SWSUSP 131 - depends on SMP 132 - default y 94 + Turning OFF this setting is NOT recommended! If in doubt, say Y. 133 95 134 96 config HIBERNATION 135 97 bool "Hibernation (aka 'suspend to disk')" 136 - depends on PM && SWAP 137 - depends on HIBERNATION_UP_POSSIBLE || HIBERNATION_SMP_POSSIBLE 98 + depends on PM && SWAP && ARCH_HIBERNATION_POSSIBLE 138 99 ---help--- 139 100 Enable the suspend to disk (STD) functionality, which is usually 140 101 called "hibernation" in user interfaces. STD checkpoints the
+155 -49
kernel/power/disk.c
··· 54 54 55 55 void hibernation_set_ops(struct platform_hibernation_ops *ops) 56 56 { 57 - if (ops && !(ops->start && ops->pre_snapshot && ops->finish 58 - && ops->prepare && ops->enter && ops->pre_restore 57 + if (ops && !(ops->begin && ops->end && ops->pre_snapshot 58 + && ops->prepare && ops->finish && ops->enter && ops->pre_restore 59 59 && ops->restore_cleanup)) { 60 60 WARN_ON(1); 61 61 return; ··· 70 70 mutex_unlock(&pm_mutex); 71 71 } 72 72 73 + #ifdef CONFIG_PM_DEBUG 74 + static void hibernation_debug_sleep(void) 75 + { 76 + printk(KERN_INFO "hibernation debug: Waiting for 5 seconds.\n"); 77 + mdelay(5000); 78 + } 79 + 80 + static int hibernation_testmode(int mode) 81 + { 82 + if (hibernation_mode == mode) { 83 + hibernation_debug_sleep(); 84 + return 1; 85 + } 86 + return 0; 87 + } 88 + 89 + static int hibernation_test(int level) 90 + { 91 + if (pm_test_level == level) { 92 + hibernation_debug_sleep(); 93 + return 1; 94 + } 95 + return 0; 96 + } 97 + #else /* !CONFIG_PM_DEBUG */ 98 + static int hibernation_testmode(int mode) { return 0; } 99 + static int hibernation_test(int level) { return 0; } 100 + #endif /* !CONFIG_PM_DEBUG */ 101 + 73 102 /** 74 - * platform_start - tell the platform driver that we're starting 103 + * platform_begin - tell the platform driver that we're starting 75 104 * hibernation 76 105 */ 77 106 78 - static int platform_start(int platform_mode) 107 + static int platform_begin(int platform_mode) 79 108 { 80 109 return (platform_mode && hibernation_ops) ? 81 - hibernation_ops->start() : 0; 110 + hibernation_ops->begin() : 0; 111 + } 112 + 113 + /** 114 + * platform_end - tell the platform driver that we've entered the 115 + * working state 116 + */ 117 + 118 + static void platform_end(int platform_mode) 119 + { 120 + if (platform_mode && hibernation_ops) 121 + hibernation_ops->end(); 82 122 } 83 123 84 124 /** ··· 202 162 */ 203 163 error = device_power_down(PMSG_FREEZE); 204 164 if (error) { 205 - printk(KERN_ERR "Some devices failed to power down, " 206 - KERN_ERR "aborting suspend\n"); 165 + printk(KERN_ERR "PM: Some devices failed to power down, " 166 + "aborting hibernation\n"); 207 167 goto Enable_irqs; 208 168 } 209 169 170 + if (hibernation_test(TEST_CORE)) 171 + goto Power_up; 172 + 173 + in_suspend = 1; 210 174 save_processor_state(); 211 175 error = swsusp_arch_suspend(); 212 176 if (error) 213 - printk(KERN_ERR "Error %d while creating the image\n", error); 177 + printk(KERN_ERR "PM: Error %d creating hibernation image\n", 178 + error); 214 179 /* Restore control flow magically appears here */ 215 180 restore_processor_state(); 216 181 if (!in_suspend) 217 182 platform_leave(platform_mode); 183 + Power_up: 218 184 /* NOTE: device_power_up() is just a resume() for devices 219 185 * that suspended with irqs off ... no overall powerup. 220 186 */ ··· 248 202 if (error) 249 203 return error; 250 204 251 - error = platform_start(platform_mode); 205 + error = platform_begin(platform_mode); 252 206 if (error) 253 - return error; 207 + goto Close; 254 208 255 209 suspend_console(); 256 210 error = device_suspend(PMSG_FREEZE); 257 211 if (error) 258 212 goto Resume_console; 259 213 260 - error = platform_pre_snapshot(platform_mode); 261 - if (error) 214 + if (hibernation_test(TEST_DEVICES)) 262 215 goto Resume_devices; 216 + 217 + error = platform_pre_snapshot(platform_mode); 218 + if (error || hibernation_test(TEST_PLATFORM)) 219 + goto Finish; 263 220 264 221 error = disable_nonboot_cpus(); 265 222 if (!error) { 266 - if (hibernation_mode != HIBERNATION_TEST) { 267 - in_suspend = 1; 268 - error = create_image(platform_mode); 269 - /* Control returns here after successful restore */ 270 - } else { 271 - printk("swsusp debug: Waiting for 5 seconds.\n"); 272 - mdelay(5000); 273 - } 223 + if (hibernation_test(TEST_CPUS)) 224 + goto Enable_cpus; 225 + 226 + if (hibernation_testmode(HIBERNATION_TEST)) 227 + goto Enable_cpus; 228 + 229 + error = create_image(platform_mode); 230 + /* Control returns here after successful restore */ 274 231 } 232 + Enable_cpus: 275 233 enable_nonboot_cpus(); 276 - Resume_devices: 234 + Finish: 277 235 platform_finish(platform_mode); 236 + Resume_devices: 278 237 device_resume(); 279 238 Resume_console: 280 239 resume_console(); 240 + Close: 241 + platform_end(platform_mode); 242 + return error; 243 + } 244 + 245 + /** 246 + * resume_target_kernel - prepare devices that need to be suspended with 247 + * interrupts off, restore the contents of highmem that have not been 248 + * restored yet from the image and run the low level code that will restore 249 + * the remaining contents of memory and switch to the just restored target 250 + * kernel. 251 + */ 252 + 253 + static int resume_target_kernel(void) 254 + { 255 + int error; 256 + 257 + local_irq_disable(); 258 + error = device_power_down(PMSG_PRETHAW); 259 + if (error) { 260 + printk(KERN_ERR "PM: Some devices failed to power down, " 261 + "aborting resume\n"); 262 + goto Enable_irqs; 263 + } 264 + /* We'll ignore saved state, but this gets preempt count (etc) right */ 265 + save_processor_state(); 266 + error = restore_highmem(); 267 + if (!error) { 268 + error = swsusp_arch_resume(); 269 + /* 270 + * The code below is only ever reached in case of a failure. 271 + * Otherwise execution continues at place where 272 + * swsusp_arch_suspend() was called 273 + */ 274 + BUG_ON(!error); 275 + /* This call to restore_highmem() undos the previous one */ 276 + restore_highmem(); 277 + } 278 + /* 279 + * The only reason why swsusp_arch_resume() can fail is memory being 280 + * very tight, so we have to free it as soon as we can to avoid 281 + * subsequent failures 282 + */ 283 + swsusp_free(); 284 + restore_processor_state(); 285 + touch_softlockup_watchdog(); 286 + device_power_up(); 287 + Enable_irqs: 288 + local_irq_enable(); 281 289 return error; 282 290 } 283 291 ··· 358 258 if (!error) { 359 259 error = disable_nonboot_cpus(); 360 260 if (!error) 361 - error = swsusp_resume(); 261 + error = resume_target_kernel(); 362 262 enable_nonboot_cpus(); 363 263 } 364 264 platform_restore_cleanup(platform_mode); ··· 386 286 * hibernation_ops->finish() before saving the image, so we should let 387 287 * the firmware know that we're going to enter the sleep state after all 388 288 */ 389 - error = hibernation_ops->start(); 289 + error = hibernation_ops->begin(); 390 290 if (error) 391 - return error; 291 + goto Close; 392 292 393 293 suspend_console(); 394 294 error = device_suspend(PMSG_SUSPEND); ··· 422 322 device_resume(); 423 323 Resume_console: 424 324 resume_console(); 325 + Close: 326 + hibernation_ops->end(); 425 327 return error; 426 328 } 427 329 ··· 454 352 * Valid image is on the disk, if we continue we risk serious data 455 353 * corruption after resume. 456 354 */ 457 - printk(KERN_CRIT "Please power me down manually\n"); 355 + printk(KERN_CRIT "PM: Please power down manually\n"); 458 356 while(1); 459 - } 460 - 461 - static void unprepare_processes(void) 462 - { 463 - thaw_processes(); 464 - pm_restore_console(); 465 357 } 466 358 467 359 static int prepare_processes(void) 468 360 { 469 361 int error = 0; 470 362 471 - pm_prepare_console(); 472 363 if (freeze_processes()) { 473 364 error = -EBUSY; 474 - unprepare_processes(); 365 + thaw_processes(); 475 366 } 476 367 return error; 477 368 } ··· 484 389 goto Unlock; 485 390 } 486 391 392 + pm_prepare_console(); 487 393 error = pm_notifier_call_chain(PM_HIBERNATION_PREPARE); 488 394 if (error) 489 395 goto Exit; ··· 494 398 if (error) 495 399 goto Exit; 496 400 497 - printk("Syncing filesystems ... "); 401 + printk(KERN_INFO "PM: Syncing filesystems ... "); 498 402 sys_sync(); 499 403 printk("done.\n"); 500 404 ··· 502 406 if (error) 503 407 goto Finish; 504 408 505 - if (hibernation_mode == HIBERNATION_TESTPROC) { 506 - printk("swsusp debug: Waiting for 5 seconds.\n"); 507 - mdelay(5000); 409 + if (hibernation_test(TEST_FREEZER)) 508 410 goto Thaw; 509 - } 411 + 412 + if (hibernation_testmode(HIBERNATION_TESTPROC)) 413 + goto Thaw; 414 + 510 415 error = hibernation_snapshot(hibernation_mode == HIBERNATION_PLATFORM); 511 416 if (in_suspend && !error) { 512 417 unsigned int flags = 0; ··· 524 427 swsusp_free(); 525 428 } 526 429 Thaw: 527 - unprepare_processes(); 430 + thaw_processes(); 528 431 Finish: 529 432 free_basic_memory_bitmaps(); 530 433 Exit: 531 434 pm_notifier_call_chain(PM_POST_HIBERNATION); 435 + pm_restore_console(); 532 436 atomic_inc(&snapshot_device_available); 533 437 Unlock: 534 438 mutex_unlock(&pm_mutex); ··· 571 473 return -ENOENT; 572 474 } 573 475 swsusp_resume_device = name_to_dev_t(resume_file); 574 - pr_debug("swsusp: Resume From Partition %s\n", resume_file); 476 + pr_debug("PM: Resume from partition %s\n", resume_file); 575 477 } else { 576 - pr_debug("swsusp: Resume From Partition %d:%d\n", 577 - MAJOR(swsusp_resume_device), MINOR(swsusp_resume_device)); 478 + pr_debug("PM: Resume from partition %d:%d\n", 479 + MAJOR(swsusp_resume_device), 480 + MINOR(swsusp_resume_device)); 578 481 } 579 482 580 483 if (noresume) { 581 484 /** 582 - * FIXME: If noresume is specified, we need to find the partition 583 - * and reset it back to normal swap space. 485 + * FIXME: If noresume is specified, we need to find the 486 + * partition and reset it back to normal swap space. 584 487 */ 585 488 mutex_unlock(&pm_mutex); 586 489 return 0; 587 490 } 588 491 589 - pr_debug("PM: Checking swsusp image.\n"); 492 + pr_debug("PM: Checking hibernation image.\n"); 590 493 error = swsusp_check(); 591 494 if (error) 592 495 goto Unlock; ··· 597 498 error = -EBUSY; 598 499 goto Unlock; 599 500 } 501 + 502 + pm_prepare_console(); 503 + error = pm_notifier_call_chain(PM_RESTORE_PREPARE); 504 + if (error) 505 + goto Finish; 600 506 601 507 error = create_basic_memory_bitmaps(); 602 508 if (error) ··· 614 510 goto Done; 615 511 } 616 512 617 - pr_debug("PM: Reading swsusp image.\n"); 513 + pr_debug("PM: Reading hibernation image.\n"); 618 514 619 515 error = swsusp_read(&flags); 620 516 if (!error) ··· 622 518 623 519 printk(KERN_ERR "PM: Restore failed, recovering.\n"); 624 520 swsusp_free(); 625 - unprepare_processes(); 521 + thaw_processes(); 626 522 Done: 627 523 free_basic_memory_bitmaps(); 628 524 Finish: 525 + pm_notifier_call_chain(PM_POST_RESTORE); 526 + pm_restore_console(); 629 527 atomic_inc(&snapshot_device_available); 630 528 /* For success case, the suspend path will release the lock */ 631 529 Unlock: ··· 742 636 error = -EINVAL; 743 637 744 638 if (!error) 745 - pr_debug("PM: suspend-to-disk mode set to '%s'\n", 639 + pr_debug("PM: Hibernation mode set to '%s'\n", 746 640 hibernation_modes[mode]); 747 641 mutex_unlock(&pm_mutex); 748 642 return error ? error : n; ··· 774 668 mutex_lock(&pm_mutex); 775 669 swsusp_resume_device = res; 776 670 mutex_unlock(&pm_mutex); 777 - printk("Attempting manual resume\n"); 671 + printk(KERN_INFO "PM: Starting manual resume from disk\n"); 778 672 noresume = 0; 779 673 software_resume(); 780 674 ret = n;
+145 -26
kernel/power/main.c
··· 24 24 25 25 #include "power.h" 26 26 27 - BLOCKING_NOTIFIER_HEAD(pm_chain_head); 28 - 29 27 DEFINE_MUTEX(pm_mutex); 30 28 31 29 unsigned int pm_flags; 32 30 EXPORT_SYMBOL(pm_flags); 31 + 32 + #ifdef CONFIG_PM_SLEEP 33 + 34 + /* Routines for PM-transition notifications */ 35 + 36 + static BLOCKING_NOTIFIER_HEAD(pm_chain_head); 37 + 38 + int register_pm_notifier(struct notifier_block *nb) 39 + { 40 + return blocking_notifier_chain_register(&pm_chain_head, nb); 41 + } 42 + EXPORT_SYMBOL_GPL(register_pm_notifier); 43 + 44 + int unregister_pm_notifier(struct notifier_block *nb) 45 + { 46 + return blocking_notifier_chain_unregister(&pm_chain_head, nb); 47 + } 48 + EXPORT_SYMBOL_GPL(unregister_pm_notifier); 49 + 50 + int pm_notifier_call_chain(unsigned long val) 51 + { 52 + return (blocking_notifier_call_chain(&pm_chain_head, val, NULL) 53 + == NOTIFY_BAD) ? -EINVAL : 0; 54 + } 55 + 56 + #ifdef CONFIG_PM_DEBUG 57 + int pm_test_level = TEST_NONE; 58 + 59 + static int suspend_test(int level) 60 + { 61 + if (pm_test_level == level) { 62 + printk(KERN_INFO "suspend debug: Waiting for 5 seconds.\n"); 63 + mdelay(5000); 64 + return 1; 65 + } 66 + return 0; 67 + } 68 + 69 + static const char * const pm_tests[__TEST_AFTER_LAST] = { 70 + [TEST_NONE] = "none", 71 + [TEST_CORE] = "core", 72 + [TEST_CPUS] = "processors", 73 + [TEST_PLATFORM] = "platform", 74 + [TEST_DEVICES] = "devices", 75 + [TEST_FREEZER] = "freezer", 76 + }; 77 + 78 + static ssize_t pm_test_show(struct kobject *kobj, struct kobj_attribute *attr, 79 + char *buf) 80 + { 81 + char *s = buf; 82 + int level; 83 + 84 + for (level = TEST_FIRST; level <= TEST_MAX; level++) 85 + if (pm_tests[level]) { 86 + if (level == pm_test_level) 87 + s += sprintf(s, "[%s] ", pm_tests[level]); 88 + else 89 + s += sprintf(s, "%s ", pm_tests[level]); 90 + } 91 + 92 + if (s != buf) 93 + /* convert the last space to a newline */ 94 + *(s-1) = '\n'; 95 + 96 + return (s - buf); 97 + } 98 + 99 + static ssize_t pm_test_store(struct kobject *kobj, struct kobj_attribute *attr, 100 + const char *buf, size_t n) 101 + { 102 + const char * const *s; 103 + int level; 104 + char *p; 105 + int len; 106 + int error = -EINVAL; 107 + 108 + p = memchr(buf, '\n', n); 109 + len = p ? p - buf : n; 110 + 111 + mutex_lock(&pm_mutex); 112 + 113 + level = TEST_FIRST; 114 + for (s = &pm_tests[level]; level <= TEST_MAX; s++, level++) 115 + if (*s && len == strlen(*s) && !strncmp(buf, *s, len)) { 116 + pm_test_level = level; 117 + error = 0; 118 + break; 119 + } 120 + 121 + mutex_unlock(&pm_mutex); 122 + 123 + return error ? error : n; 124 + } 125 + 126 + power_attr(pm_test); 127 + #else /* !CONFIG_PM_DEBUG */ 128 + static inline int suspend_test(int level) { return 0; } 129 + #endif /* !CONFIG_PM_DEBUG */ 130 + 131 + #endif /* CONFIG_PM_SLEEP */ 33 132 34 133 #ifdef CONFIG_SUSPEND 35 134 ··· 175 76 if (!suspend_ops || !suspend_ops->enter) 176 77 return -EPERM; 177 78 79 + pm_prepare_console(); 80 + 178 81 error = pm_notifier_call_chain(PM_SUSPEND_PREPARE); 179 82 if (error) 180 83 goto Finish; 181 84 182 - pm_prepare_console(); 183 - 184 - if (freeze_processes()) { 85 + if (suspend_freeze_processes()) { 185 86 error = -EAGAIN; 186 87 goto Thaw; 187 88 } ··· 199 100 return 0; 200 101 201 102 Thaw: 202 - thaw_processes(); 203 - pm_restore_console(); 103 + suspend_thaw_processes(); 204 104 Finish: 205 105 pm_notifier_call_chain(PM_POST_SUSPEND); 106 + pm_restore_console(); 206 107 return error; 207 108 } 208 109 ··· 232 133 BUG_ON(!irqs_disabled()); 233 134 234 135 if ((error = device_power_down(PMSG_SUSPEND))) { 235 - printk(KERN_ERR "Some devices failed to power down\n"); 136 + printk(KERN_ERR "PM: Some devices failed to power down\n"); 236 137 goto Done; 237 138 } 238 - error = suspend_ops->enter(state); 139 + 140 + if (!suspend_test(TEST_CORE)) 141 + error = suspend_ops->enter(state); 142 + 239 143 device_power_up(); 240 144 Done: 241 145 arch_suspend_enable_irqs(); ··· 247 145 } 248 146 249 147 /** 250 - * suspend_devices_and_enter - suspend devices and enter the desired system sleep 251 - * state. 148 + * suspend_devices_and_enter - suspend devices and enter the desired system 149 + * sleep state. 252 150 * @state: state to enter 253 151 */ 254 152 int suspend_devices_and_enter(suspend_state_t state) ··· 258 156 if (!suspend_ops) 259 157 return -ENOSYS; 260 158 261 - if (suspend_ops->set_target) { 262 - error = suspend_ops->set_target(state); 159 + if (suspend_ops->begin) { 160 + error = suspend_ops->begin(state); 263 161 if (error) 264 - return error; 162 + goto Close; 265 163 } 266 164 suspend_console(); 267 165 error = device_suspend(PMSG_SUSPEND); 268 166 if (error) { 269 - printk(KERN_ERR "Some devices failed to suspend\n"); 167 + printk(KERN_ERR "PM: Some devices failed to suspend\n"); 270 168 goto Resume_console; 271 169 } 170 + 171 + if (suspend_test(TEST_DEVICES)) 172 + goto Resume_devices; 173 + 272 174 if (suspend_ops->prepare) { 273 175 error = suspend_ops->prepare(); 274 176 if (error) 275 177 goto Resume_devices; 276 178 } 179 + 180 + if (suspend_test(TEST_PLATFORM)) 181 + goto Finish; 182 + 277 183 error = disable_nonboot_cpus(); 278 - if (!error) 184 + if (!error && !suspend_test(TEST_CPUS)) 279 185 suspend_enter(state); 280 186 281 187 enable_nonboot_cpus(); 188 + Finish: 282 189 if (suspend_ops->finish) 283 190 suspend_ops->finish(); 284 191 Resume_devices: 285 192 device_resume(); 286 193 Resume_console: 287 194 resume_console(); 195 + Close: 196 + if (suspend_ops->end) 197 + suspend_ops->end(); 288 198 return error; 289 199 } 290 200 ··· 308 194 */ 309 195 static void suspend_finish(void) 310 196 { 311 - thaw_processes(); 312 - pm_restore_console(); 197 + suspend_thaw_processes(); 313 198 pm_notifier_call_chain(PM_POST_SUSPEND); 199 + pm_restore_console(); 314 200 } 315 201 316 202 ··· 352 238 if (!mutex_trylock(&pm_mutex)) 353 239 return -EBUSY; 354 240 355 - printk("Syncing filesystems ... "); 241 + printk(KERN_INFO "PM: Syncing filesystems ... "); 356 242 sys_sync(); 357 243 printk("done.\n"); 358 244 359 245 pr_debug("PM: Preparing system for %s sleep\n", pm_states[state]); 360 - if ((error = suspend_prepare())) 246 + error = suspend_prepare(); 247 + if (error) 361 248 goto Unlock; 249 + 250 + if (suspend_test(TEST_FREEZER)) 251 + goto Finish; 362 252 363 253 pr_debug("PM: Entering %s sleep\n", pm_states[state]); 364 254 error = suspend_devices_and_enter(state); 365 255 256 + Finish: 366 257 pr_debug("PM: Finishing wakeup.\n"); 367 258 suspend_finish(); 368 259 Unlock: ··· 488 369 } 489 370 490 371 power_attr(pm_trace); 372 + #endif /* CONFIG_PM_TRACE */ 491 373 492 374 static struct attribute * g[] = { 493 375 &state_attr.attr, 376 + #ifdef CONFIG_PM_TRACE 494 377 &pm_trace_attr.attr, 378 + #endif 379 + #if defined(CONFIG_PM_SLEEP) && defined(CONFIG_PM_DEBUG) 380 + &pm_test_attr.attr, 381 + #endif 495 382 NULL, 496 383 }; 497 - #else 498 - static struct attribute * g[] = { 499 - &state_attr.attr, 500 - NULL, 501 - }; 502 - #endif /* CONFIG_PM_TRACE */ 503 384 504 385 static struct attribute_group attr_group = { 505 386 .attrs = g,
+53 -37
kernel/power/power.h
··· 1 1 #include <linux/suspend.h> 2 + #include <linux/suspend_ioctls.h> 2 3 #include <linux/utsname.h> 4 + #include <linux/freezer.h> 3 5 4 6 struct swsusp_info { 5 7 struct new_utsname uts; ··· 130 128 #define data_of(handle) ((handle).buffer + (handle).buf_offset) 131 129 132 130 extern unsigned int snapshot_additional_pages(struct zone *zone); 131 + extern unsigned long snapshot_get_image_size(void); 133 132 extern int snapshot_read_next(struct snapshot_handle *handle, size_t count); 134 133 extern int snapshot_write_next(struct snapshot_handle *handle, size_t count); 135 134 extern void snapshot_write_finalize(struct snapshot_handle *handle); 136 135 extern int snapshot_image_loaded(struct snapshot_handle *handle); 137 - 138 - /* 139 - * This structure is used to pass the values needed for the identification 140 - * of the resume swap area from a user space to the kernel via the 141 - * SNAPSHOT_SET_SWAP_AREA ioctl 142 - */ 143 - struct resume_swap_area { 144 - loff_t offset; 145 - u_int32_t dev; 146 - } __attribute__((packed)); 147 - 148 - #define SNAPSHOT_IOC_MAGIC '3' 149 - #define SNAPSHOT_FREEZE _IO(SNAPSHOT_IOC_MAGIC, 1) 150 - #define SNAPSHOT_UNFREEZE _IO(SNAPSHOT_IOC_MAGIC, 2) 151 - #define SNAPSHOT_ATOMIC_SNAPSHOT _IOW(SNAPSHOT_IOC_MAGIC, 3, void *) 152 - #define SNAPSHOT_ATOMIC_RESTORE _IO(SNAPSHOT_IOC_MAGIC, 4) 153 - #define SNAPSHOT_FREE _IO(SNAPSHOT_IOC_MAGIC, 5) 154 - #define SNAPSHOT_SET_IMAGE_SIZE _IOW(SNAPSHOT_IOC_MAGIC, 6, unsigned long) 155 - #define SNAPSHOT_AVAIL_SWAP _IOR(SNAPSHOT_IOC_MAGIC, 7, void *) 156 - #define SNAPSHOT_GET_SWAP_PAGE _IOR(SNAPSHOT_IOC_MAGIC, 8, void *) 157 - #define SNAPSHOT_FREE_SWAP_PAGES _IO(SNAPSHOT_IOC_MAGIC, 9) 158 - #define SNAPSHOT_SET_SWAP_FILE _IOW(SNAPSHOT_IOC_MAGIC, 10, unsigned int) 159 - #define SNAPSHOT_S2RAM _IO(SNAPSHOT_IOC_MAGIC, 11) 160 - #define SNAPSHOT_PMOPS _IOW(SNAPSHOT_IOC_MAGIC, 12, unsigned int) 161 - #define SNAPSHOT_SET_SWAP_AREA _IOW(SNAPSHOT_IOC_MAGIC, 13, \ 162 - struct resume_swap_area) 163 - #define SNAPSHOT_IOC_MAXNR 13 164 - 165 - #define PMOPS_PREPARE 1 166 - #define PMOPS_ENTER 2 167 - #define PMOPS_FINISH 3 168 136 169 137 /* If unset, the snapshot device cannot be open. */ 170 138 extern atomic_t snapshot_device_available; ··· 153 181 extern int swsusp_check(void); 154 182 extern int swsusp_shrink_memory(void); 155 183 extern void swsusp_free(void); 156 - extern int swsusp_resume(void); 157 184 extern int swsusp_read(unsigned int *flags_p); 158 185 extern int swsusp_write(unsigned int flags); 159 186 extern void swsusp_close(void); ··· 172 201 } 173 202 #endif /* !CONFIG_SUSPEND */ 174 203 175 - /* kernel/power/common.c */ 176 - extern struct blocking_notifier_head pm_chain_head; 204 + #ifdef CONFIG_PM_SLEEP 205 + /* kernel/power/main.c */ 206 + extern int pm_notifier_call_chain(unsigned long val); 207 + #endif 177 208 178 - static inline int pm_notifier_call_chain(unsigned long val) 209 + #ifdef CONFIG_HIGHMEM 210 + unsigned int count_highmem_pages(void); 211 + int restore_highmem(void); 212 + #else 213 + static inline unsigned int count_highmem_pages(void) { return 0; } 214 + static inline int restore_highmem(void) { return 0; } 215 + #endif 216 + 217 + /* 218 + * Suspend test levels 219 + */ 220 + enum { 221 + /* keep first */ 222 + TEST_NONE, 223 + TEST_CORE, 224 + TEST_CPUS, 225 + TEST_PLATFORM, 226 + TEST_DEVICES, 227 + TEST_FREEZER, 228 + /* keep last */ 229 + __TEST_AFTER_LAST 230 + }; 231 + 232 + #define TEST_FIRST TEST_NONE 233 + #define TEST_MAX (__TEST_AFTER_LAST - 1) 234 + 235 + extern int pm_test_level; 236 + 237 + #ifdef CONFIG_SUSPEND_FREEZER 238 + static inline int suspend_freeze_processes(void) 179 239 { 180 - return (blocking_notifier_call_chain(&pm_chain_head, val, NULL) 181 - == NOTIFY_BAD) ? -EINVAL : 0; 240 + return freeze_processes(); 182 241 } 242 + 243 + static inline void suspend_thaw_processes(void) 244 + { 245 + thaw_processes(); 246 + } 247 + #else 248 + static inline int suspend_freeze_processes(void) 249 + { 250 + return 0; 251 + } 252 + 253 + static inline void suspend_thaw_processes(void) 254 + { 255 + } 256 + #endif
+18 -13
kernel/power/snapshot.c
··· 635 635 region->end_pfn = end_pfn; 636 636 list_add_tail(&region->list, &nosave_regions); 637 637 Report: 638 - printk("swsusp: Registered nosave memory region: %016lx - %016lx\n", 638 + printk(KERN_INFO "PM: Registered nosave memory: %016lx - %016lx\n", 639 639 start_pfn << PAGE_SHIFT, end_pfn << PAGE_SHIFT); 640 640 } 641 641 ··· 704 704 list_for_each_entry(region, &nosave_regions, list) { 705 705 unsigned long pfn; 706 706 707 - printk("swsusp: Marking nosave pages: %016lx - %016lx\n", 707 + pr_debug("PM: Marking nosave pages: %016lx - %016lx\n", 708 708 region->start_pfn << PAGE_SHIFT, 709 709 region->end_pfn << PAGE_SHIFT); 710 710 ··· 749 749 free_pages_map = bm2; 750 750 mark_nosave_pages(forbidden_pages_map); 751 751 752 - printk("swsusp: Basic memory bitmaps created\n"); 752 + pr_debug("PM: Basic memory bitmaps created\n"); 753 753 754 754 return 0; 755 755 ··· 784 784 memory_bm_free(bm2, PG_UNSAFE_CLEAR); 785 785 kfree(bm2); 786 786 787 - printk("swsusp: Basic memory bitmaps freed\n"); 787 + pr_debug("PM: Basic memory bitmaps freed\n"); 788 788 } 789 789 790 790 /** ··· 872 872 } 873 873 #else 874 874 static inline void *saveable_highmem_page(unsigned long pfn) { return NULL; } 875 - static inline unsigned int count_highmem_pages(void) { return 0; } 876 875 #endif /* CONFIG_HIGHMEM */ 877 876 878 877 /** ··· 1088 1089 } 1089 1090 1090 1091 nr_pages += count_pages_for_highmem(nr_highmem); 1091 - pr_debug("swsusp: Normal pages needed: %u + %u + %u, available pages: %u\n", 1092 + pr_debug("PM: Normal pages needed: %u + %u + %u, available pages: %u\n", 1092 1093 nr_pages, PAGES_FOR_IO, meta, free); 1093 1094 1094 1095 return free > nr_pages + PAGES_FOR_IO + meta; ··· 1201 1202 { 1202 1203 unsigned int nr_pages, nr_highmem; 1203 1204 1204 - printk("swsusp: critical section: \n"); 1205 + printk(KERN_INFO "PM: Creating hibernation image: \n"); 1205 1206 1206 1207 drain_local_pages(); 1207 1208 nr_pages = count_data_pages(); 1208 1209 nr_highmem = count_highmem_pages(); 1209 - printk("swsusp: Need to copy %u pages\n", nr_pages + nr_highmem); 1210 + printk(KERN_INFO "PM: Need to copy %u pages\n", nr_pages + nr_highmem); 1210 1211 1211 1212 if (!enough_free_mem(nr_pages, nr_highmem)) { 1212 - printk(KERN_ERR "swsusp: Not enough free memory\n"); 1213 + printk(KERN_ERR "PM: Not enough free memory\n"); 1213 1214 return -ENOMEM; 1214 1215 } 1215 1216 1216 1217 if (swsusp_alloc(&orig_bm, &copy_bm, nr_pages, nr_highmem)) { 1217 - printk(KERN_ERR "swsusp: Memory allocation failed\n"); 1218 + printk(KERN_ERR "PM: Memory allocation failed\n"); 1218 1219 return -ENOMEM; 1219 1220 } 1220 1221 ··· 1234 1235 nr_copy_pages = nr_pages; 1235 1236 nr_meta_pages = DIV_ROUND_UP(nr_pages * sizeof(long), PAGE_SIZE); 1236 1237 1237 - printk("swsusp: critical section: done (%d pages copied)\n", nr_pages); 1238 + printk(KERN_INFO "PM: Hibernation image created (%d pages copied)\n", 1239 + nr_pages); 1238 1240 1239 1241 return 0; 1240 1242 } ··· 1264 1264 } 1265 1265 #endif /* CONFIG_ARCH_HIBERNATION_HEADER */ 1266 1266 1267 + unsigned long snapshot_get_image_size(void) 1268 + { 1269 + return nr_copy_pages + nr_meta_pages + 1; 1270 + } 1271 + 1267 1272 static int init_header(struct swsusp_info *info) 1268 1273 { 1269 1274 memset(info, 0, sizeof(struct swsusp_info)); 1270 1275 info->num_physpages = num_physpages; 1271 1276 info->image_pages = nr_copy_pages; 1272 - info->pages = nr_copy_pages + nr_meta_pages + 1; 1277 + info->pages = snapshot_get_image_size(); 1273 1278 info->size = info->pages; 1274 1279 info->size <<= PAGE_SHIFT; 1275 1280 return init_header_complete(info); ··· 1434 1429 if (!reason && info->num_physpages != num_physpages) 1435 1430 reason = "memory size"; 1436 1431 if (reason) { 1437 - printk(KERN_ERR "swsusp: Resume mismatch: %s\n", reason); 1432 + printk(KERN_ERR "PM: Image mismatch: %s\n", reason); 1438 1433 return -EPERM; 1439 1434 } 1440 1435 return 0;
+17 -16
kernel/power/swap.c
··· 28 28 29 29 #include "power.h" 30 30 31 - extern char resume_file[]; 32 - 33 31 #define SWSUSP_SIG "S1SUSPEND" 34 32 35 33 struct swsusp_header { ··· 71 73 bio->bi_end_io = end_swap_bio_read; 72 74 73 75 if (bio_add_page(bio, page, PAGE_SIZE, 0) < PAGE_SIZE) { 74 - printk("swsusp: ERROR: adding page to bio at %ld\n", page_off); 76 + printk(KERN_ERR "PM: Adding page to bio failed at %ld\n", 77 + page_off); 75 78 bio_put(bio); 76 79 return -EFAULT; 77 80 } ··· 152 153 error = bio_write_page(swsusp_resume_block, 153 154 swsusp_header, NULL); 154 155 } else { 155 - printk(KERN_ERR "swsusp: Swap header not found!\n"); 156 + printk(KERN_ERR "PM: Swap header not found!\n"); 156 157 error = -ENODEV; 157 158 } 158 159 return error; ··· 324 325 struct timeval start; 325 326 struct timeval stop; 326 327 327 - printk("Saving image data pages (%u pages) ... ", nr_to_write); 328 + printk(KERN_INFO "PM: Saving image data pages (%u pages) ... ", 329 + nr_to_write); 328 330 m = nr_to_write / 100; 329 331 if (!m) 330 332 m = 1; ··· 365 365 { 366 366 unsigned int free_swap = count_swap_pages(root_swap, 1); 367 367 368 - pr_debug("swsusp: free swap pages: %u\n", free_swap); 368 + pr_debug("PM: Free swap pages: %u\n", free_swap); 369 369 return free_swap > nr_pages + PAGES_FOR_IO; 370 370 } 371 371 ··· 388 388 389 389 error = swsusp_swap_check(); 390 390 if (error) { 391 - printk(KERN_ERR "swsusp: Cannot find swap device, try " 391 + printk(KERN_ERR "PM: Cannot find swap device, try " 392 392 "swapon -a.\n"); 393 393 return error; 394 394 } ··· 402 402 } 403 403 header = (struct swsusp_info *)data_of(snapshot); 404 404 if (!enough_swap(header->pages)) { 405 - printk(KERN_ERR "swsusp: Not enough free swap\n"); 405 + printk(KERN_ERR "PM: Not enough free swap\n"); 406 406 error = -ENOSPC; 407 407 goto out; 408 408 } ··· 417 417 418 418 if (!error) { 419 419 flush_swap_writer(&handle); 420 - printk("S"); 420 + printk(KERN_INFO "PM: S"); 421 421 error = mark_swapfiles(start, flags); 422 422 printk("|\n"); 423 423 } ··· 507 507 int err2; 508 508 unsigned nr_pages; 509 509 510 - printk("Loading image data pages (%u pages) ... ", nr_to_read); 510 + printk(KERN_INFO "PM: Loading image data pages (%u pages) ... ", 511 + nr_to_read); 511 512 m = nr_to_read / 100; 512 513 if (!m) 513 514 m = 1; ··· 559 558 560 559 *flags_p = swsusp_header->flags; 561 560 if (IS_ERR(resume_bdev)) { 562 - pr_debug("swsusp: block device not initialised\n"); 561 + pr_debug("PM: Image device not initialised\n"); 563 562 return PTR_ERR(resume_bdev); 564 563 } 565 564 ··· 578 577 blkdev_put(resume_bdev); 579 578 580 579 if (!error) 581 - pr_debug("swsusp: Reading resume file was successful\n"); 580 + pr_debug("PM: Image successfully loaded\n"); 582 581 else 583 - pr_debug("swsusp: Error %d resuming\n", error); 582 + pr_debug("PM: Error %d resuming\n", error); 584 583 return error; 585 584 } 586 585 ··· 612 611 if (error) 613 612 blkdev_put(resume_bdev); 614 613 else 615 - pr_debug("swsusp: Signature found, resuming\n"); 614 + pr_debug("PM: Signature found, resuming\n"); 616 615 } else { 617 616 error = PTR_ERR(resume_bdev); 618 617 } 619 618 620 619 if (error) 621 - pr_debug("swsusp: Error %d check for resume file\n", error); 620 + pr_debug("PM: Error %d checking image file\n", error); 622 621 623 622 return error; 624 623 } ··· 630 629 void swsusp_close(void) 631 630 { 632 631 if (IS_ERR(resume_bdev)) { 633 - pr_debug("swsusp: block device not initialised\n"); 632 + pr_debug("PM: Image device not initialised\n"); 634 633 return; 635 634 } 636 635
+3 -45
kernel/power/swsusp.c
··· 64 64 65 65 int in_suspend __nosavedata = 0; 66 66 67 - #ifdef CONFIG_HIGHMEM 68 - unsigned int count_highmem_pages(void); 69 - int restore_highmem(void); 70 - #else 71 - static inline int restore_highmem(void) { return 0; } 72 - static inline unsigned int count_highmem_pages(void) { return 0; } 73 - #endif 74 - 75 67 /** 76 68 * The following functions are used for tracing the allocated 77 69 * swap pages, so that they can be freed in case of an error. ··· 188 196 centisecs = 1; /* avoid div-by-zero */ 189 197 k = nr_pages * (PAGE_SIZE / 1024); 190 198 kps = (k * 100) / centisecs; 191 - printk("%s %d kbytes in %d.%02d seconds (%d.%02d MB/s)\n", msg, k, 199 + printk(KERN_INFO "PM: %s %d kbytes in %d.%02d seconds (%d.%02d MB/s)\n", 200 + msg, k, 192 201 centisecs / 100, centisecs % 100, 193 202 kps / 1000, (kps % 1000) / 10); 194 203 } ··· 220 227 char *p = "-\\|/"; 221 228 struct timeval start, stop; 222 229 223 - printk("Shrinking memory... "); 230 + printk(KERN_INFO "PM: Shrinking memory... "); 224 231 do_gettimeofday(&start); 225 232 do { 226 233 long size, highmem_size; ··· 261 268 swsusp_show_speed(&start, &stop, pages, "Freed"); 262 269 263 270 return 0; 264 - } 265 - 266 - int swsusp_resume(void) 267 - { 268 - int error; 269 - 270 - local_irq_disable(); 271 - /* NOTE: device_power_down() is just a suspend() with irqs off; 272 - * it has no special "power things down" semantics 273 - */ 274 - if (device_power_down(PMSG_PRETHAW)) 275 - printk(KERN_ERR "Some devices failed to power down, very bad\n"); 276 - /* We'll ignore saved state, but this gets preempt count (etc) right */ 277 - save_processor_state(); 278 - error = restore_highmem(); 279 - if (!error) { 280 - error = swsusp_arch_resume(); 281 - /* The code below is only ever reached in case of a failure. 282 - * Otherwise execution continues at place where 283 - * swsusp_arch_suspend() was called 284 - */ 285 - BUG_ON(!error); 286 - /* This call to restore_highmem() undos the previous one */ 287 - restore_highmem(); 288 - } 289 - /* The only reason why swsusp_arch_resume() can fail is memory being 290 - * very tight, so we have to free it as soon as we can to avoid 291 - * subsequent failures 292 - */ 293 - swsusp_free(); 294 - restore_processor_state(); 295 - touch_softlockup_watchdog(); 296 - device_power_up(); 297 - local_irq_enable(); 298 - return error; 299 271 }
+80 -29
kernel/power/user.c
··· 28 28 29 29 #include "power.h" 30 30 31 + /* 32 + * NOTE: The SNAPSHOT_SET_SWAP_FILE and SNAPSHOT_PMOPS ioctls are obsolete and 33 + * will be removed in the future. They are only preserved here for 34 + * compatibility with existing userland utilities. 35 + */ 36 + #define SNAPSHOT_SET_SWAP_FILE _IOW(SNAPSHOT_IOC_MAGIC, 10, unsigned int) 37 + #define SNAPSHOT_PMOPS _IOW(SNAPSHOT_IOC_MAGIC, 12, unsigned int) 38 + 39 + #define PMOPS_PREPARE 1 40 + #define PMOPS_ENTER 2 41 + #define PMOPS_FINISH 3 42 + 43 + /* 44 + * NOTE: The following ioctl definitions are wrong and have been replaced with 45 + * correct ones. They are only preserved here for compatibility with existing 46 + * userland utilities and will be removed in the future. 47 + */ 48 + #define SNAPSHOT_ATOMIC_SNAPSHOT _IOW(SNAPSHOT_IOC_MAGIC, 3, void *) 49 + #define SNAPSHOT_SET_IMAGE_SIZE _IOW(SNAPSHOT_IOC_MAGIC, 6, unsigned long) 50 + #define SNAPSHOT_AVAIL_SWAP _IOR(SNAPSHOT_IOC_MAGIC, 7, void *) 51 + #define SNAPSHOT_GET_SWAP_PAGE _IOR(SNAPSHOT_IOC_MAGIC, 8, void *) 52 + 53 + 31 54 #define SNAPSHOT_MINOR 231 32 55 33 56 static struct snapshot_data { ··· 59 36 int mode; 60 37 char frozen; 61 38 char ready; 62 - char platform_suspend; 39 + char platform_support; 63 40 } snapshot_state; 64 41 65 42 atomic_t snapshot_device_available = ATOMIC_INIT(1); ··· 67 44 static int snapshot_open(struct inode *inode, struct file *filp) 68 45 { 69 46 struct snapshot_data *data; 47 + int error; 70 48 71 49 if (!atomic_add_unless(&snapshot_device_available, -1, 0)) 72 50 return -EBUSY; ··· 88 64 data->swap = swsusp_resume_device ? 89 65 swap_type_of(swsusp_resume_device, 0, NULL) : -1; 90 66 data->mode = O_RDONLY; 67 + error = pm_notifier_call_chain(PM_RESTORE_PREPARE); 68 + if (error) 69 + pm_notifier_call_chain(PM_POST_RESTORE); 91 70 } else { 92 71 data->swap = -1; 93 72 data->mode = O_WRONLY; 73 + error = pm_notifier_call_chain(PM_HIBERNATION_PREPARE); 74 + if (error) 75 + pm_notifier_call_chain(PM_POST_HIBERNATION); 76 + } 77 + if (error) { 78 + atomic_inc(&snapshot_device_available); 79 + return error; 94 80 } 95 81 data->frozen = 0; 96 82 data->ready = 0; 97 - data->platform_suspend = 0; 83 + data->platform_support = 0; 98 84 99 85 return 0; 100 86 } ··· 122 88 thaw_processes(); 123 89 mutex_unlock(&pm_mutex); 124 90 } 91 + pm_notifier_call_chain(data->mode == O_WRONLY ? 92 + PM_POST_HIBERNATION : PM_POST_RESTORE); 125 93 atomic_inc(&snapshot_device_available); 126 94 return 0; 127 95 } ··· 169 133 { 170 134 int error = 0; 171 135 struct snapshot_data *data; 172 - loff_t avail; 136 + loff_t size; 173 137 sector_t offset; 174 138 175 139 if (_IOC_TYPE(cmd) != SNAPSHOT_IOC_MAGIC) ··· 187 151 if (data->frozen) 188 152 break; 189 153 mutex_lock(&pm_mutex); 190 - error = pm_notifier_call_chain(PM_HIBERNATION_PREPARE); 191 - if (!error) { 192 - printk("Syncing filesystems ... "); 193 - sys_sync(); 194 - printk("done.\n"); 154 + printk("Syncing filesystems ... "); 155 + sys_sync(); 156 + printk("done.\n"); 195 157 196 - error = freeze_processes(); 197 - if (error) 198 - thaw_processes(); 199 - } 158 + error = freeze_processes(); 200 159 if (error) 201 - pm_notifier_call_chain(PM_POST_HIBERNATION); 160 + thaw_processes(); 202 161 mutex_unlock(&pm_mutex); 203 162 if (!error) 204 163 data->frozen = 1; ··· 204 173 break; 205 174 mutex_lock(&pm_mutex); 206 175 thaw_processes(); 207 - pm_notifier_call_chain(PM_POST_HIBERNATION); 208 176 mutex_unlock(&pm_mutex); 209 177 data->frozen = 0; 210 178 break; 211 179 180 + case SNAPSHOT_CREATE_IMAGE: 212 181 case SNAPSHOT_ATOMIC_SNAPSHOT: 213 182 if (data->mode != O_RDONLY || !data->frozen || data->ready) { 214 183 error = -EPERM; 215 184 break; 216 185 } 217 - error = hibernation_snapshot(data->platform_suspend); 186 + error = hibernation_snapshot(data->platform_support); 218 187 if (!error) 219 - error = put_user(in_suspend, (unsigned int __user *)arg); 188 + error = put_user(in_suspend, (int __user *)arg); 220 189 if (!error) 221 190 data->ready = 1; 222 191 break; ··· 228 197 error = -EPERM; 229 198 break; 230 199 } 231 - error = hibernation_restore(data->platform_suspend); 200 + error = hibernation_restore(data->platform_support); 232 201 break; 233 202 234 203 case SNAPSHOT_FREE: ··· 237 206 data->ready = 0; 238 207 break; 239 208 209 + case SNAPSHOT_PREF_IMAGE_SIZE: 240 210 case SNAPSHOT_SET_IMAGE_SIZE: 241 211 image_size = arg; 242 212 break; 243 213 244 - case SNAPSHOT_AVAIL_SWAP: 245 - avail = count_swap_pages(data->swap, 1); 246 - avail <<= PAGE_SHIFT; 247 - error = put_user(avail, (loff_t __user *)arg); 214 + case SNAPSHOT_GET_IMAGE_SIZE: 215 + if (!data->ready) { 216 + error = -ENODATA; 217 + break; 218 + } 219 + size = snapshot_get_image_size(); 220 + size <<= PAGE_SHIFT; 221 + error = put_user(size, (loff_t __user *)arg); 248 222 break; 249 223 224 + case SNAPSHOT_AVAIL_SWAP_SIZE: 225 + case SNAPSHOT_AVAIL_SWAP: 226 + size = count_swap_pages(data->swap, 1); 227 + size <<= PAGE_SHIFT; 228 + error = put_user(size, (loff_t __user *)arg); 229 + break; 230 + 231 + case SNAPSHOT_ALLOC_SWAP_PAGE: 250 232 case SNAPSHOT_GET_SWAP_PAGE: 251 233 if (data->swap < 0 || data->swap >= MAX_SWAPFILES) { 252 234 error = -ENODEV; ··· 268 224 offset = alloc_swapdev_block(data->swap); 269 225 if (offset) { 270 226 offset <<= PAGE_SHIFT; 271 - error = put_user(offset, (sector_t __user *)arg); 227 + error = put_user(offset, (loff_t __user *)arg); 272 228 } else { 273 229 error = -ENOSPC; 274 230 } ··· 282 238 free_all_swap_pages(data->swap); 283 239 break; 284 240 285 - case SNAPSHOT_SET_SWAP_FILE: 241 + case SNAPSHOT_SET_SWAP_FILE: /* This ioctl is deprecated */ 286 242 if (!swsusp_swap_in_use()) { 287 243 /* 288 244 * User space encodes device types as two-byte values, ··· 319 275 mutex_unlock(&pm_mutex); 320 276 break; 321 277 322 - case SNAPSHOT_PMOPS: 278 + case SNAPSHOT_PLATFORM_SUPPORT: 279 + data->platform_support = !!arg; 280 + break; 281 + 282 + case SNAPSHOT_POWER_OFF: 283 + if (data->platform_support) 284 + error = hibernation_platform_enter(); 285 + break; 286 + 287 + case SNAPSHOT_PMOPS: /* This ioctl is deprecated */ 323 288 error = -EINVAL; 324 289 325 290 switch (arg) { 326 291 327 292 case PMOPS_PREPARE: 328 - data->platform_suspend = 1; 293 + data->platform_support = 1; 329 294 error = 0; 330 295 break; 331 296 332 297 case PMOPS_ENTER: 333 - if (data->platform_suspend) 298 + if (data->platform_support) 334 299 error = hibernation_platform_enter(); 335 - 336 300 break; 337 301 338 302 case PMOPS_FINISH: 339 - if (data->platform_suspend) 303 + if (data->platform_support) 340 304 error = 0; 341 - 342 305 break; 343 306 344 307 default: