[英]difference between a pci device driver with “module_pci_driver” and a pci driver with “__init()” but without “module_pci_driver()” in Linux
I have seen in pci device drivers this line我在 pci 设备驱动程序中看到了这一行
module_pci_driver(cp_driver);
But in other pci device drivers this like但在其他 pci 设备驱动程序中
module_init(rtl8139_init_module);
both lines found at the end of driver's .c
file in different drivers在不同驱动程序中驱动程序的
.c
文件末尾的两行
What I know is: I can create a pci device driver with __init
but I can also create a pci device driver without __init
我所知道的是:我可以使用
__init
创建一个 pci 设备驱动程序,但我也可以创建一个没有__init
的 pci 设备驱动程序
ie [Realtek Ethernet has two drivers in Linux source即【瑞昱以太网在Linux源码中有两个驱动
1) 139cp.c (without __init
) 1) 139cp.c (没有
__init
)
2) 8139too.c with __init
]. 2) 8139too.c与
__init
]。
I assume that the main difference between the two is simply that if I have to use a pci device driver right after loading of the driver module with insmod
command so I use an implementation of a device driver with __init
.我假设两者之间的主要区别很简单,如果我必须在使用
insmod
命令加载驱动程序模块后立即使用 pci 设备驱动程序,那么我使用带有__init
的设备驱动程序的实现。
Question On the contrary, if I just want to load the pci device driver but not use it, Then should I create a pci device driver with module_pci_driver()
(So no need to add __init
)?问题相反,如果我只想加载 pci 设备驱动程序而不使用它,那么我应该使用
module_pci_driver()
创建一个 pci 设备驱动程序(所以不需要添加__init
)? And what does it do(module_pci_driver)?它有什么作用(module_pci_driver)? How its different from pci driver with
__init
它与带有
__init
的 pci 驱动程序有何不同
I like to know I may have a misconception anyone please clarify.我想知道我可能有一个误解,请任何人澄清。 Also does the
probe
function of both type of drivers will run when I load the driver with insmod
command?当我使用
insmod
命令加载驱动程序时,两种驱动程序的probe
function 是否也会运行? When?什么时候? if yes than what's the difference since most configuring of device is done in proble function
如果是,那么有什么区别,因为大多数设备配置都是在问题 function 中完成的
To sum up When initialization happens in driver with module_pci_driver(cp_driver);
总结当初始化发生在驱动程序中时
module_pci_driver(cp_driver);
since they dont have __init
implemented.因为他们没有实现
__init
。 What command used使用了什么命令
module_pci_driver()
is a helper meant for drivers that don't do anything special in their module init and exit (ie modules whose init and exit functions just register/unregister). module_pci_driver()
是一个帮助程序,用于在其模块初始化和退出中不做任何特殊操作的驱动程序(即,其初始化和退出函数只是注册/取消注册的模块)。
It generates the init and exit functions for you, reducing some boilerplate.它为您生成 init 和 exit 函数,减少了一些样板文件。
In this specific case, the 8139too driver might do something in addition to registering the driver (in this case, logging the driver name), so isn't using module_pci_driver()
在这种特定情况下,8139too 驱动程序除了注册驱动程序(在这种情况下,记录驱动程序名称)之外可能还会做一些事情,所以不使用
module_pci_driver()
The probe
function is called for existing or new devices that match the ID table and aren't already owned (see How To Write Linux PCI Drivers for details). probe
function 用于匹配 ID 表且尚未拥有的现有或新设备(有关详细信息,请参阅如何编写 Linux PCI 驱动程序)。 It returns a value indicating if the driver will be taking ownership of the device (either 0 or an error code).它返回一个值,指示驱动程序是否将获得设备的所有权(0 或错误代码)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.