linux kernel driver_init()


linux kernel driver_init()

Linux version 3.4.39

/* init/main.c */
asmlinkage void __init start_kernel(void)
    |
    ...
    /* Do the rest non-__init'ed, we're now alive */
	rest_init();
        |
        ...
        kernel_thread(kernel_init, NULL, CLONE_FS | CLONE_SIGHAND);
        ...
        pid = kernel_thread(kthreadd, NULL, CLONE_FS | CLONE_FILES);
        ...
        /* Call into cpu_idle with preempt disabled */
	    cpu_idle(); /* idle process, pid:0 */

static int __init kernel_init(void * unused)
    |
    ...
    /*
    * Ok, the machine is now initialized. None of the devices
    * have been touched yet, but the CPU subsystem is up and
    * running, and memory and process management works.
    *
    * Now we can finally start doing some real work..
    */
    static void __init do_basic_setup(void)
    {
	    cpuset_init_smp();
	    usermodehelper_init();
	    shmem_init();
	    driver_init();
	    init_irq_proc();
	    do_ctors();
	    usermodehelper_enable();
	    do_initcalls();
    }
    ...
    init_post()
        |
        run_init_process(); /* init prcess, pid:1 */
    ...

int kthreadd(void *unused) {
    /* kthreadd process, pid:2 */
}

/* drivers/base/init.c */
#include <linux/memory.h>

#include "base.h"

/**
 * driver_init - initialize driver model.
 *
 * Call the driver model init functions to initialize their
 * subsystems. Called early from init/main.c.
 */
void __init driver_init(void)
{
	/* These are the core pieces */
	devtmpfs_init();
	devices_init();
	buses_init();
	classes_init();
	firmware_init();
	hypervisor_init();

	/* These are also core pieces, but must come after the
	 * core core pieces.
	 */
	platform_bus_init();
	cpu_dev_init();
	memory_dev_init();
}

static void __init do_initcalls(void)
{
	int level;

    for (level = 0; level < ARRAY_SIZE(initcall_levels) - 1; level++)
	    do_initcall_level(level);
}

Author: Yangkai Wang
wang_yangkai@163.com
Coding in 2021/05/06


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM