栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

module

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

module

在Linux设备驱动开发过程中,在定义且初始化好platform_driver结构体变量以后,我们需要向 Linux 内核注册一个 platform 驱动。下面介绍两种方法。

方法一:
int platform_driver_register(struct platform_driver *driver)
// driver:要注册的 platform 驱动。
// 返回值:负数,失败;0,成功。
    

void platform_driver_unregister(struct platform_driver *drv)
// drv:要卸载的 platform 驱动。
// 返回值:无。
    
// 驱动模块加载
static int __init xxx_init(void)
{
	return platform_driver_register(&xxx_driver);
}
module_init(xxx_init);
// 驱动模块卸载 
static void __exit xxx_exit(void)
{
	platform_driver_unregister(&xxx_driver);
}
module_exit(xxx_exit);
方法二:

除了方法一这种传统方法以外, Linux 内核中会大量采用 module_platform_driver 来完成向 Linux 内核注册 platform 驱动的操作。
module_platform_driver 定义在 include/linux/platform_device.h 文件中,如下:

#define module_platform_driver(__platform_driver) 
	module_driver(__platform_driver, platform_driver_register, 
			platform_driver_unregister)

可以看出,module_platform_driver 依赖 module_driver,module_driver 也是一个宏,定义在include/linux/device.h 文件中,内容如下:


#define module_driver(__driver, __register, __unregister, ...) 
static int __init __driver##_init(void) 
{ 
	return __register(&(__driver) , ##__VA_ARGS__); 
} 
module_init(__driver##_init); 
static void __exit __driver##_exit(void) 
{ 
	__unregister(&(__driver) , ##__VA_ARGS__); 
} 
module_exit(__driver##_exit);
module_platform_driver(xxx_driver);

因此方法一就是方法二的展开形式。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/752353.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号