目录
框架位置
数据结构及接口
原型实现解析
使用场景
框架位置
相关实现在driversbasesyscore.c中
函数声明在includelinuxsyscore_ops.h中。
依赖宏CONFIG_PM_SLEEP的使能
数据结构及接口
在头文件中,声明了函数原型以及相关结构体:
struct syscore_ops {
struct list_head node;
int (*suspend)(void);
void (*resume)(void);
void (*shutdown)(void);
};
extern void register_syscore_ops(struct syscore_ops *ops);
extern void unregister_syscore_ops(struct syscore_ops *ops);
#ifdef CONFIG_PM_SLEEP
extern int syscore_suspend(void);
extern void syscore_resume(void);
#endif
extern void syscore_shutdown(void);
#endif
原型实现解析
该机制的实现在driversbasesyscore.c中,实现非常简单,不在此过多解析。
实现包括注册和去注册接口,suspend和resume接口,以及shutdown接口,如果需要注册相关实现,首先包含该头文件,然后通过resister来注册自己的syscore回调。
使用场景
Suspend和resume回调会在睡眠唤醒流程的锁中断上下文中进行调用,典型的使用场景包括查询唤醒中断等。
Shutdown回调会在kernel_power_off或者reboot时进行回调,相关实现可以评估是否需要注册shutdown回调函数。



