Driver initialization sequence __linux in Linux kernel startup

Source: Internet
Author: User

The Linux kernel defines different priority levels for different driver load sequences, as shown in the following macro:

Include/linux/init.h

#define Pure_initcall (FN) __define_initcall ("0", fn,1)
#define Core_initcall (FN) __define_initcall ("1", fn,1)
#define CORE_INITCALL_SYNC (FN) __define_initcall ("1s", fn,1s)
#define Postcore_initcall (FN) __define_initcall ("2", fn,2)
#define POSTCORE_INITCALL_SYNC (FN) __define_initcall ("2s", fn,2s)
#define Arch_initcall (FN) __define_initcall ("3", fn,3)
#define ARCH_INITCALL_SYNC (FN) __define_initcall ("3s", fn,3s)
#define Subsys_initcall (FN) __define_initcall ("4", fn,4)
#define SUBSYS_INITCALL_SYNC (FN) __define_initcall ("4s", fn,4s)
#define Fs_initcall (FN) __define_initcall ("5", fn,5)
#define FS_INITCALL_SYNC (FN) __define_initcall ("5s", fn,5s)
#define Rootfs_initcall (FN) __define_initcall ("Rootfs", Fn,rootfs)
#define Device_initcall (FN) __define_initcall ("6", fn,6)
#define DEVICE_INITCALL_SYNC (FN) __define_initcall ("6s", fn,6s)
#define Late_initcall (FN) __define_initcall ("7", fn,7)
#define LATE_INITCALL_SYNC (FN) __define_initcall ("7s", fn,7s)
#define __initcall (FN) Device_initcall (FN)

By using these macros to define your own driver's function name, you will have a different load-time priority. Wherein, the module_init used in our write drive corresponds to the #define MODULE_INIT (x) __initcall (x); #define __initcall (FN) Device_initcall (FN) Therefore, the driver corresponding to the load priority is 6.

In the different priorities above, the smaller the number, the higher the priority. The priority of the same level of driver, loading sequence is the link process decision, the result is uncertain, we can not go to manually set who first after. The order of driver loading at different levels is priority high and the lower priority is low, which can be determined. So, like we used before in the drive:
Module_init (I2c_dev_init);
Module_init (As352x_afe_init);
Module_init (As352x_afe_i2c_init);

So, everyone is initialized with the same priority, and finally these drivers are loaded in the order that you can view the generated System.map in the root directory:

。。。。。
C00197f4 T __initcall_default_rootfsrootfs
C00197f8 T __INITCALL_TIMER_INIT_SYSFS6
C00197FC T __initcall_clock_dev_init6
。。。

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.