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