Hibernation: Introduce system_entering_hibernation

Introduce boolean function system_entering_hibernation() returning
'true' during the last phase of hibernation, in which devices are
being put into low power states and the sleep state (for example,
ACPI S4) is finally entered.

Some device drivers need such a function to check if the system is
in the final phase of hibernation. In particular, some SATA drivers
are going to use it for blacklisting systems in which the disks
should not be spun down during the last phase of hibernation (the
BIOS will do that anyway).

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Signed-off-by: Jeff Garzik <jgarzik@redhat.com>

authored by Rafael J. Wysocki and committed by Jeff Garzik abfe2d7b f3b8436a

+12
+2
include/linux/suspend.h
··· 237 extern void hibernate_nvs_free(void); 238 extern void hibernate_nvs_save(void); 239 extern void hibernate_nvs_restore(void); 240 #else /* CONFIG_HIBERNATION */ 241 static inline int swsusp_page_is_forbidden(struct page *p) { return 0; } 242 static inline void swsusp_set_page_free(struct page *p) {} ··· 253 static inline void hibernate_nvs_free(void) {} 254 static inline void hibernate_nvs_save(void) {} 255 static inline void hibernate_nvs_restore(void) {} 256 #endif /* CONFIG_HIBERNATION */ 257 258 #ifdef CONFIG_PM_SLEEP
··· 237 extern void hibernate_nvs_free(void); 238 extern void hibernate_nvs_save(void); 239 extern void hibernate_nvs_restore(void); 240 + extern bool system_entering_hibernation(void); 241 #else /* CONFIG_HIBERNATION */ 242 static inline int swsusp_page_is_forbidden(struct page *p) { return 0; } 243 static inline void swsusp_set_page_free(struct page *p) {} ··· 252 static inline void hibernate_nvs_free(void) {} 253 static inline void hibernate_nvs_save(void) {} 254 static inline void hibernate_nvs_restore(void) {} 255 + static inline bool system_entering_hibernation(void) { return false; } 256 #endif /* CONFIG_HIBERNATION */ 257 258 #ifdef CONFIG_PM_SLEEP
+10
kernel/power/disk.c
··· 71 mutex_unlock(&pm_mutex); 72 } 73 74 #ifdef CONFIG_PM_DEBUG 75 static void hibernation_debug_sleep(void) 76 { ··· 419 if (error) 420 goto Close; 421 422 suspend_console(); 423 error = device_suspend(PMSG_HIBERNATE); 424 if (error) { ··· 454 Finish: 455 hibernation_ops->finish(); 456 Resume_devices: 457 device_resume(PMSG_RESTORE); 458 resume_console(); 459 Close:
··· 71 mutex_unlock(&pm_mutex); 72 } 73 74 + static bool entering_platform_hibernation; 75 + 76 + bool system_entering_hibernation(void) 77 + { 78 + return entering_platform_hibernation; 79 + } 80 + EXPORT_SYMBOL(system_entering_hibernation); 81 + 82 #ifdef CONFIG_PM_DEBUG 83 static void hibernation_debug_sleep(void) 84 { ··· 411 if (error) 412 goto Close; 413 414 + entering_platform_hibernation = true; 415 suspend_console(); 416 error = device_suspend(PMSG_HIBERNATE); 417 if (error) { ··· 445 Finish: 446 hibernation_ops->finish(); 447 Resume_devices: 448 + entering_platform_hibernation = false; 449 device_resume(PMSG_RESTORE); 450 resume_console(); 451 Close: