Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/suspend-2.6

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/suspend-2.6:
PM: Fix PM QOS's user mode interface to work with ASCII input
PM / Hibernate: Update kerneldoc comments in hibernate.c
PM / Hibernate: Remove arch_prepare_suspend()
PM / Hibernate: Update some comments in core hibernate code

+134 -167
-20
arch/frv/include/asm/suspend.h
··· 1 - /* suspend.h: suspension stuff 2 - * 3 - * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved. 4 - * Written by David Howells (dhowells@redhat.com) 5 - * 6 - * This program is free software; you can redistribute it and/or 7 - * modify it under the terms of the GNU General Public License 8 - * as published by the Free Software Foundation; either version 9 - * 2 of the License, or (at your option) any later version. 10 - */ 11 - 12 - #ifndef _ASM_SUSPEND_H 13 - #define _ASM_SUSPEND_H 14 - 15 - static inline int arch_prepare_suspend(void) 16 - { 17 - return 0; 18 - } 19 - 20 - #endif /* _ASM_SUSPEND_H */
-2
arch/mips/include/asm/suspend.h
··· 1 1 #ifndef __ASM_SUSPEND_H 2 2 #define __ASM_SUSPEND_H 3 3 4 - static inline int arch_prepare_suspend(void) { return 0; } 5 - 6 4 /* References to section boundaries */ 7 5 extern const void __nosave_begin, __nosave_end; 8 6
-6
arch/powerpc/include/asm/suspend.h
··· 1 - #ifndef __ASM_POWERPC_SUSPEND_H 2 - #define __ASM_POWERPC_SUSPEND_H 3 - 4 - static inline int arch_prepare_suspend(void) { return 0; } 5 - 6 - #endif /* __ASM_POWERPC_SUSPEND_H */
-1
arch/powerpc/kernel/swsusp.c
··· 10 10 */ 11 11 12 12 #include <linux/sched.h> 13 - #include <asm/suspend.h> 14 13 #include <asm/system.h> 15 14 #include <asm/current.h> 16 15 #include <asm/mmu_context.h>
-10
arch/s390/include/asm/suspend.h
··· 1 - #ifndef __ASM_S390_SUSPEND_H 2 - #define __ASM_S390_SUSPEND_H 3 - 4 - static inline int arch_prepare_suspend(void) 5 - { 6 - return 0; 7 - } 8 - 9 - #endif 10 -
-1
arch/sh/include/asm/suspend.h
··· 3 3 4 4 #ifndef __ASSEMBLY__ 5 5 #include <linux/notifier.h> 6 - static inline int arch_prepare_suspend(void) { return 0; } 7 6 8 7 #include <asm/ptrace.h> 9 8
-1
arch/unicore32/include/asm/suspend.h
··· 14 14 #define __UNICORE_SUSPEND_H__ 15 15 16 16 #ifndef __ASSEMBLY__ 17 - static inline int arch_prepare_suspend(void) { return 0; } 18 17 19 18 #include <asm/ptrace.h> 20 19
-2
arch/x86/include/asm/suspend_32.h
··· 9 9 #include <asm/desc.h> 10 10 #include <asm/i387.h> 11 11 12 - static inline int arch_prepare_suspend(void) { return 0; } 13 - 14 12 /* image of the saved processor state */ 15 13 struct saved_context { 16 14 u16 es, fs, gs, ss;
-5
arch/x86/include/asm/suspend_64.h
··· 9 9 #include <asm/desc.h> 10 10 #include <asm/i387.h> 11 11 12 - static inline int arch_prepare_suspend(void) 13 - { 14 - return 0; 15 - } 16 - 17 12 /* 18 13 * Image of the saved processor state, used by the low level ACPI suspend to 19 14 * RAM code and by the low level hibernation code.
+23 -10
kernel/pm_qos_params.c
··· 40 40 #include <linux/string.h> 41 41 #include <linux/platform_device.h> 42 42 #include <linux/init.h> 43 + #include <linux/kernel.h> 43 44 44 45 #include <linux/uaccess.h> 45 46 ··· 405 404 size_t count, loff_t *f_pos) 406 405 { 407 406 s32 value; 408 - int x; 409 - char ascii_value[11]; 410 407 struct pm_qos_request_list *pm_qos_req; 411 408 412 409 if (count == sizeof(s32)) { 413 410 if (copy_from_user(&value, buf, sizeof(s32))) 414 411 return -EFAULT; 415 - } else if (count == 11) { /* len('0x12345678/0') */ 416 - if (copy_from_user(ascii_value, buf, 11)) 412 + } else if (count <= 11) { /* ASCII perhaps? */ 413 + char ascii_value[11]; 414 + unsigned long int ulval; 415 + int ret; 416 + 417 + if (copy_from_user(ascii_value, buf, count)) 417 418 return -EFAULT; 418 - if (strlen(ascii_value) != 10) 419 + 420 + if (count > 10) { 421 + if (ascii_value[10] == '\n') 422 + ascii_value[10] = '\0'; 423 + else 424 + return -EINVAL; 425 + } else { 426 + ascii_value[count] = '\0'; 427 + } 428 + ret = strict_strtoul(ascii_value, 16, &ulval); 429 + if (ret) { 430 + pr_debug("%s, 0x%lx, 0x%x\n", ascii_value, ulval, ret); 419 431 return -EINVAL; 420 - x = sscanf(ascii_value, "%x", &value); 421 - if (x != 1) 422 - return -EINVAL; 423 - pr_debug("%s, %d, 0x%x\n", ascii_value, x, value); 424 - } else 432 + } 433 + value = (s32)lower_32_bits(ulval); 434 + } else { 425 435 return -EINVAL; 436 + } 426 437 427 438 pm_qos_req = filp->private_data; 428 439 pm_qos_update_request(pm_qos_req, value);
+111 -109
kernel/power/hibernate.c
··· 25 25 #include <linux/gfp.h> 26 26 #include <linux/syscore_ops.h> 27 27 #include <scsi/scsi_scan.h> 28 - #include <asm/suspend.h> 29 28 30 29 #include "power.h" 31 30 ··· 54 55 static const struct platform_hibernation_ops *hibernation_ops; 55 56 56 57 /** 57 - * hibernation_set_ops - set the global hibernate operations 58 - * @ops: the hibernation operations to use in subsequent hibernation transitions 58 + * hibernation_set_ops - Set the global hibernate operations. 59 + * @ops: Hibernation operations to use in subsequent hibernation transitions. 59 60 */ 60 - 61 61 void hibernation_set_ops(const struct platform_hibernation_ops *ops) 62 62 { 63 63 if (ops && !(ops->begin && ops->end && ops->pre_snapshot ··· 113 115 #endif /* !CONFIG_PM_DEBUG */ 114 116 115 117 /** 116 - * platform_begin - tell the platform driver that we're starting 117 - * hibernation 118 + * platform_begin - Call platform to start hibernation. 119 + * @platform_mode: Whether or not to use the platform driver. 118 120 */ 119 - 120 121 static int platform_begin(int platform_mode) 121 122 { 122 123 return (platform_mode && hibernation_ops) ? ··· 123 126 } 124 127 125 128 /** 126 - * platform_end - tell the platform driver that we've entered the 127 - * working state 129 + * platform_end - Call platform to finish transition to the working state. 130 + * @platform_mode: Whether or not to use the platform driver. 128 131 */ 129 - 130 132 static void platform_end(int platform_mode) 131 133 { 132 134 if (platform_mode && hibernation_ops) ··· 133 137 } 134 138 135 139 /** 136 - * platform_pre_snapshot - prepare the machine for hibernation using the 137 - * platform driver if so configured and return an error code if it fails 140 + * platform_pre_snapshot - Call platform to prepare the machine for hibernation. 141 + * @platform_mode: Whether or not to use the platform driver. 142 + * 143 + * Use the platform driver to prepare the system for creating a hibernate image, 144 + * if so configured, and return an error code if that fails. 138 145 */ 139 146 140 147 static int platform_pre_snapshot(int platform_mode) ··· 147 148 } 148 149 149 150 /** 150 - * platform_leave - prepare the machine for switching to the normal mode 151 - * of operation using the platform driver (called with interrupts disabled) 151 + * platform_leave - Call platform to prepare a transition to the working state. 152 + * @platform_mode: Whether or not to use the platform driver. 153 + * 154 + * Use the platform driver prepare to prepare the machine for switching to the 155 + * normal mode of operation. 156 + * 157 + * This routine is called on one CPU with interrupts disabled. 152 158 */ 153 - 154 159 static void platform_leave(int platform_mode) 155 160 { 156 161 if (platform_mode && hibernation_ops) ··· 162 159 } 163 160 164 161 /** 165 - * platform_finish - switch the machine to the normal mode of operation 166 - * using the platform driver (must be called after platform_prepare()) 162 + * platform_finish - Call platform to switch the system to the working state. 163 + * @platform_mode: Whether or not to use the platform driver. 164 + * 165 + * Use the platform driver to switch the machine to the normal mode of 166 + * operation. 167 + * 168 + * This routine must be called after platform_prepare(). 167 169 */ 168 - 169 170 static void platform_finish(int platform_mode) 170 171 { 171 172 if (platform_mode && hibernation_ops) ··· 177 170 } 178 171 179 172 /** 180 - * platform_pre_restore - prepare the platform for the restoration from a 181 - * hibernation image. If the restore fails after this function has been 182 - * called, platform_restore_cleanup() must be called. 173 + * platform_pre_restore - Prepare for hibernate image restoration. 174 + * @platform_mode: Whether or not to use the platform driver. 175 + * 176 + * Use the platform driver to prepare the system for resume from a hibernation 177 + * image. 178 + * 179 + * If the restore fails after this function has been called, 180 + * platform_restore_cleanup() must be called. 183 181 */ 184 - 185 182 static int platform_pre_restore(int platform_mode) 186 183 { 187 184 return (platform_mode && hibernation_ops) ? ··· 193 182 } 194 183 195 184 /** 196 - * platform_restore_cleanup - switch the platform to the normal mode of 197 - * operation after a failing restore. If platform_pre_restore() has been 198 - * called before the failing restore, this function must be called too, 199 - * regardless of the result of platform_pre_restore(). 185 + * platform_restore_cleanup - Switch to the working state after failing restore. 186 + * @platform_mode: Whether or not to use the platform driver. 187 + * 188 + * Use the platform driver to switch the system to the normal mode of operation 189 + * after a failing restore. 190 + * 191 + * If platform_pre_restore() has been called before the failing restore, this 192 + * function must be called too, regardless of the result of 193 + * platform_pre_restore(). 200 194 */ 201 - 202 195 static void platform_restore_cleanup(int platform_mode) 203 196 { 204 197 if (platform_mode && hibernation_ops) ··· 210 195 } 211 196 212 197 /** 213 - * platform_recover - recover the platform from a failure to suspend 214 - * devices. 198 + * platform_recover - Recover from a failure to suspend devices. 199 + * @platform_mode: Whether or not to use the platform driver. 215 200 */ 216 - 217 201 static void platform_recover(int platform_mode) 218 202 { 219 203 if (platform_mode && hibernation_ops && hibernation_ops->recover) ··· 220 206 } 221 207 222 208 /** 223 - * swsusp_show_speed - print the time elapsed between two events. 224 - * @start: Starting event. 225 - * @stop: Final event. 226 - * @nr_pages - number of pages processed between @start and @stop 227 - * @msg - introductory message to print 209 + * swsusp_show_speed - Print time elapsed between two events during hibernation. 210 + * @start: Starting event. 211 + * @stop: Final event. 212 + * @nr_pages: Number of memory pages processed between @start and @stop. 213 + * @msg: Additional diagnostic message to print. 228 214 */ 229 - 230 215 void swsusp_show_speed(struct timeval *start, struct timeval *stop, 231 216 unsigned nr_pages, char *msg) 232 217 { ··· 248 235 } 249 236 250 237 /** 251 - * create_image - freeze devices that need to be frozen with interrupts 252 - * off, create the hibernation image and thaw those devices. Control 253 - * reappears in this routine after a restore. 238 + * create_image - Create a hibernation image. 239 + * @platform_mode: Whether or not to use the platform driver. 240 + * 241 + * Execute device drivers' .freeze_noirq() callbacks, create a hibernation image 242 + * and execute the drivers' .thaw_noirq() callbacks. 243 + * 244 + * Control reappears in this routine after the subsequent restore. 254 245 */ 255 - 256 246 static int create_image(int platform_mode) 257 247 { 258 248 int error; 259 249 260 - error = arch_prepare_suspend(); 261 - if (error) 262 - return error; 263 - 264 - /* At this point, dpm_suspend_start() has been called, but *not* 265 - * dpm_suspend_noirq(). We *must* call dpm_suspend_noirq() now. 266 - * Otherwise, drivers for some devices (e.g. interrupt controllers) 267 - * become desynchronized with the actual state of the hardware 268 - * at resume time, and evil weirdness ensues. 269 - */ 270 250 error = dpm_suspend_noirq(PMSG_FREEZE); 271 251 if (error) { 272 252 printk(KERN_ERR "PM: Some devices failed to power down, " ··· 303 297 304 298 Power_up: 305 299 syscore_resume(); 306 - /* NOTE: dpm_resume_noirq() is just a resume() for devices 307 - * that suspended with irqs off ... no overall powerup. 308 - */ 309 300 310 301 Enable_irqs: 311 302 local_irq_enable(); ··· 320 317 } 321 318 322 319 /** 323 - * hibernation_snapshot - quiesce devices and create the hibernation 324 - * snapshot image. 325 - * @platform_mode - if set, use the platform driver, if available, to 326 - * prepare the platform firmware for the power transition. 320 + * hibernation_snapshot - Quiesce devices and create a hibernation image. 321 + * @platform_mode: If set, use platform driver to prepare for the transition. 327 322 * 328 - * Must be called with pm_mutex held 323 + * This routine must be called with pm_mutex held. 329 324 */ 330 - 331 325 int hibernation_snapshot(int platform_mode) 332 326 { 333 327 pm_message_t msg = PMSG_RECOVER; ··· 384 384 } 385 385 386 386 /** 387 - * resume_target_kernel - prepare devices that need to be suspended with 388 - * interrupts off, restore the contents of highmem that have not been 389 - * restored yet from the image and run the low level code that will restore 390 - * the remaining contents of memory and switch to the just restored target 391 - * kernel. 387 + * resume_target_kernel - Restore system state from a hibernation image. 388 + * @platform_mode: Whether or not to use the platform driver. 389 + * 390 + * Execute device drivers' .freeze_noirq() callbacks, restore the contents of 391 + * highmem that have not been restored yet from the image and run the low-level 392 + * code that will restore the remaining contents of memory and switch to the 393 + * just restored target kernel. 392 394 */ 393 - 394 395 static int resume_target_kernel(bool platform_mode) 395 396 { 396 397 int error; ··· 417 416 if (error) 418 417 goto Enable_irqs; 419 418 420 - /* We'll ignore saved state, but this gets preempt count (etc) right */ 421 419 save_processor_state(); 422 420 error = restore_highmem(); 423 421 if (!error) { 424 422 error = swsusp_arch_resume(); 425 423 /* 426 424 * The code below is only ever reached in case of a failure. 427 - * Otherwise execution continues at place where 428 - * swsusp_arch_suspend() was called 425 + * Otherwise, execution continues at the place where 426 + * swsusp_arch_suspend() was called. 429 427 */ 430 428 BUG_ON(!error); 431 - /* This call to restore_highmem() undos the previous one */ 429 + /* 430 + * This call to restore_highmem() reverts the changes made by 431 + * the previous one. 432 + */ 432 433 restore_highmem(); 433 434 } 434 435 /* 435 436 * The only reason why swsusp_arch_resume() can fail is memory being 436 437 * very tight, so we have to free it as soon as we can to avoid 437 - * subsequent failures 438 + * subsequent failures. 438 439 */ 439 440 swsusp_free(); 440 441 restore_processor_state(); ··· 459 456 } 460 457 461 458 /** 462 - * hibernation_restore - quiesce devices and restore the hibernation 463 - * snapshot image. If successful, control returns in hibernation_snaphot() 464 - * @platform_mode - if set, use the platform driver, if available, to 465 - * prepare the platform firmware for the transition. 459 + * hibernation_restore - Quiesce devices and restore from a hibernation image. 460 + * @platform_mode: If set, use platform driver to prepare for the transition. 466 461 * 467 - * Must be called with pm_mutex held 462 + * This routine must be called with pm_mutex held. If it is successful, control 463 + * reappears in the restored target kernel in hibernation_snaphot(). 468 464 */ 469 - 470 465 int hibernation_restore(int platform_mode) 471 466 { 472 467 int error; ··· 484 483 } 485 484 486 485 /** 487 - * hibernation_platform_enter - enter the hibernation state using the 488 - * platform driver (if available) 486 + * hibernation_platform_enter - Power off the system using the platform driver. 489 487 */ 490 - 491 488 int hibernation_platform_enter(void) 492 489 { 493 490 int error; ··· 556 557 } 557 558 558 559 /** 559 - * power_down - Shut the machine down for hibernation. 560 + * power_down - Shut the machine down for hibernation. 560 561 * 561 - * Use the platform driver, if configured so; otherwise try 562 - * to power off or reboot. 562 + * Use the platform driver, if configured, to put the system into the sleep 563 + * state corresponding to hibernation, or try to power it off or reboot, 564 + * depending on the value of hibernation_mode. 563 565 */ 564 - 565 566 static void power_down(void) 566 567 { 567 568 switch (hibernation_mode) { ··· 598 599 } 599 600 600 601 /** 601 - * hibernate - The granpappy of the built-in hibernation management 602 + * hibernate - Carry out system hibernation, including saving the image. 602 603 */ 603 - 604 604 int hibernate(void) 605 605 { 606 606 int error; ··· 677 679 678 680 679 681 /** 680 - * software_resume - Resume from a saved image. 682 + * software_resume - Resume from a saved hibernation image. 681 683 * 682 - * Called as a late_initcall (so all devices are discovered and 683 - * initialized), we call swsusp to see if we have a saved image or not. 684 - * If so, we quiesce devices, the restore the saved image. We will 685 - * return above (in hibernate() ) if everything goes well. 686 - * Otherwise, we fail gracefully and return to the normally 687 - * scheduled program. 684 + * This routine is called as a late initcall, when all devices have been 685 + * discovered and initialized already. 688 686 * 687 + * The image reading code is called to see if there is a hibernation image 688 + * available for reading. If that is the case, devices are quiesced and the 689 + * contents of memory is restored from the saved image. 690 + * 691 + * If this is successful, control reappears in the restored target kernel in 692 + * hibernation_snaphot() which returns to hibernate(). Otherwise, the routine 693 + * attempts to recover gracefully and make the kernel return to the normal mode 694 + * of operation. 689 695 */ 690 - 691 696 static int software_resume(void) 692 697 { 693 698 int error; ··· 820 819 [HIBERNATION_TESTPROC] = "testproc", 821 820 }; 822 821 823 - /** 824 - * disk - Control hibernation mode 822 + /* 823 + * /sys/power/disk - Control hibernation mode. 825 824 * 826 - * Suspend-to-disk can be handled in several ways. We have a few options 827 - * for putting the system to sleep - using the platform driver (e.g. ACPI 828 - * or other hibernation_ops), powering off the system or rebooting the 829 - * system (for testing) as well as the two test modes. 825 + * Hibernation can be handled in several ways. There are a few different ways 826 + * to put the system into the sleep state: using the platform driver (e.g. ACPI 827 + * or other hibernation_ops), powering it off or rebooting it (for testing 828 + * mostly), or using one of the two available test modes. 830 829 * 831 - * The system can support 'platform', and that is known a priori (and 832 - * encoded by the presence of hibernation_ops). However, the user may 833 - * choose 'shutdown' or 'reboot' as alternatives, as well as one fo the 834 - * test modes, 'test' or 'testproc'. 835 - * 836 - * show() will display what the mode is currently set to. 837 - * store() will accept one of 830 + * The sysfs file /sys/power/disk provides an interface for selecting the 831 + * hibernation mode to use. Reading from this file causes the available modes 832 + * to be printed. There are 5 modes that can be supported: 838 833 * 839 834 * 'platform' 840 835 * 'shutdown' ··· 838 841 * 'test' 839 842 * 'testproc' 840 843 * 841 - * It will only change to 'platform' if the system 842 - * supports it (as determined by having hibernation_ops). 844 + * If a platform hibernation driver is in use, 'platform' will be supported 845 + * and will be used by default. Otherwise, 'shutdown' will be used by default. 846 + * The selected option (i.e. the one corresponding to the current value of 847 + * hibernation_mode) is enclosed by a square bracket. 848 + * 849 + * To select a given hibernation mode it is necessary to write the mode's 850 + * string representation (as returned by reading from /sys/power/disk) back 851 + * into /sys/power/disk. 843 852 */ 844 853 845 854 static ssize_t disk_show(struct kobject *kobj, struct kobj_attribute *attr, ··· 877 874 buf += sprintf(buf, "\n"); 878 875 return buf-start; 879 876 } 880 - 881 877 882 878 static ssize_t disk_store(struct kobject *kobj, struct kobj_attribute *attr, 883 879 const char *buf, size_t n)