I have seen in pci device drivers this line
module_pci_driver(cp_driver);
But in other pci device drivers this like
module_init(rtl8139_init_module);
both lines found at the end of driver's .c
file in different drivers
What I know is: I can create a pci device driver with __init
but I can also create a pci device driver without __init
i.e. [Realtek Ethernet has two drivers in Linux source
1) 139cp.c (without __init
)
2) 8139too.c with __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
.
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
)? And what does it do(module_pci_driver)? How its different from pci driver with __init
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? When? if yes than what's the difference since most configuring of device is done in proble function
To sum up
When initialization happens in driver with module_pci_driver(cp_driver);
since they dont have __init
implemented. What command used
module_pci_driver()
is a helper meant for drivers that don't do anything special in their module init and exit (i.e. modules whose init and exit functions just register/unregister).
It generates the init and exit functions for you, reducing some boilerplate.
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()
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).
It returns a value indicating if the driver will be taking ownership of the device (either 0 or an error code).