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