相关函数位于kernel/power/main.c
使用时需要包含头文件linux/suspend.h
linux 在待机和唤醒时会发出一些事件,通过注册接口可以在接收到这些事件时做些处理。
使用方法:
struct notifier_block verify_pm_notifier; //定义变量
定义处理函数:
<span style="font-size:18px;">static int verify_pm_notifier_func(struct notifier_block *notifier,
unsigned long pm_event,
void *unused)
{
switch (pm_event) {
case PM_HIBERNATION_PREPARE:
case PM_SUSPEND_PREPARE:
verify_pm_suspend();
break;
case PM_POST_RESTORE:
/* Restore from hibernation failed. We need to clean
* up in exactly the same way, so fall through. */
case PM_POST_HIBERNATION:
case PM_POST_SUSPEND:
verify_pm_resume();
break;
case PM_RESTORE_PREPARE:
default:
break;
}
return NOTIFY_DONE;
}</span>
赋值: verify_pm_notifier.notifier_call = verify_pm_notifier_func;
调用接口注册到pm notifier中:
register_pm_notifier(&verify_pm_notifier);