In Linux if device drivers are built as loadable kernel modules, then upon inserting the device driver kernel module, the kernel calls the init function of the device driver as pointed out by module_init() macro.
How does this work for device drivers that are statically compiled into the kernel ? How is their init function called ?
The init routine of a built-in driver can still use the
module_init()macro to declare that entry point. Or the driver can usedevice_initcall()when the driver would never be compiled as a loadable module. Or to move its initialization very early in the boot sequence, the driver could usesubsys_initcall().In
include/linux/init.hthe sequence for invoking these init routines is described as:I assume that these subsections for device drivers correspond to the subdirectories within the
driversdirectory of the Linux kernel source tree, and that the link order is recorded in the built-in.o file of each subdirectory indrivers. So during kernel boot the init routine of each built-in driver is eventually executed bydo_initcalls()ininit/main.c.The init routine of the device driver is responsible for probing the system to verify that the HW device actually exists. The driver should not allocate any resources or register any devices when the probe fails.
UPDATE:
Passing the option “initcall_debug” on the kernel command line will cause timing information to be printed to the console for each initcall. initcalls are used to initialize statically linked kernel drivers and subsystems and contribute a significant amount of time to the Linux boot process. The output looks like:
Reference: http://elinux.org/Initcall_Debug