(非常重要)-linux设备模型driver_init


Linux设备子系统初始化

本文介绍的内容是基于Linux3.1源码,并参考了很多网上找来的资料

 

Linux内核的启动的流程如下:

start_kernel->rest_init->kernel_init->do_basic_setup->driver_init

由driver_init函数完成设备驱动子系统的初始化,这里重点分析driver_init函数,该函数通过调用一系列的初始化函数主要完成了设备驱动子系统的一个整体框架;

复制代码
 1 /**
 2  * driver_init - initialize driver model.
 3  *
 4  * Call the driver model init functions to initialize their
 5  * subsystems. Called early from init/main.c.
 6  */
 7 void __init driver_init(void)
 8 {
 9         /* These are the core pieces */
10         devtmpfs_init();
11         devices_init();
12         buses_init();
13         classes_init();
14         firmware_init();
15        hypervisor_init();
16 
17         /* These are also core pieces, but must come after the
18          * core core pieces.
19          */
20         platform_bus_init();
21         system_bus_init();
22         cpu_dev_init();
23         memory_dev_init();
24 }
复制代码

这个函数完成驱动子系统的构建,实现了Linux设备驱动的一个整体框架,接下来就可以真正的添加设备了,接下来逐个介绍这些函数的作用。


1、devtmpfs_int函数:

该函数注册一个名为devtmpfs的文件系统dev_fs_type,这部分和设备驱动子系统的建立关系并不大,这里不多做介绍
复制代码
 1 /*
 2  * Create devtmpfs instance, driver-core devices will add their device
 3  * nodes here.
 4  */
 5 int __init devtmpfs_init(void)
 6 {
 7         int err = register_filesystem(&dev_fs_type);
 8         if (err) {
 9                 printk(KERN_ERR "devtmpfs: unable to register devtmpfs "
10                        "type %i\n", err);
11                 return err;
12        }
13 
14         thread = kthread_run(devtmpfsd, &err, "kdevtmpfs");
15         if (!IS_ERR(thread)) {
16                 wait_for_completion(&setup_done);
17         } else {
18                 err = PTR_ERR(thread);
19                 thread = NULL;
20         }
21 
22         if (err) {
23                 printk(KERN_ERR "devtmpfs: unable to create devtmpfs %i\n", err);
24                 unregister_filesystem(&dev_fs_type);
25                 return err;
26         }
27 
28         printk(KERN_INFO "devtmpfs: initialized\n");
29         return 0;
30 }
  • 0
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值