[platform]linux platform device/driver(一)--Driver是如何找到对应的device
1.platform device是怎么"自动"关联到platform driver上的?
转向linux driver有些时间了,前段时间碰到个问题,在Linux kernel 3.10的drivers/tty/serial/imx.c中,注册driver的时候调用platform_driver_register(&serial_imx_driver),serial_imx_driver类型为platform_driver, serial_imx_driver中有个成员变量probe,在driver注册时会调用这个函数,但是probe这个函数的参数是platform_device,而在imx.c中没有出现platform_device类型的任何变量,问题就此产生了,platform_device这个参数到底是从什么地方传进来的,内容又是什么,什么时候赋值的?
2.设备、总线、驱动三者如何关联起来?
后来查阅了相关资料,大体上的意思是,在linux2.6内核以后,设备和驱动的结构划分为设备、总线、驱动,设备和驱动分别挂在总线上,而他们可以通过name来进行匹配(还有其他的方式),二者绑定有两种方式:一种是先安装driver,后挂载设备;另一种则是先挂载设备,然后安装driver。但二者都是后面动作的会在总线上搜索与自己name项相同的设备或者driver进行匹配,也即完成绑定。
3.代码中的实现
在imx.c中,由于平台是3.10,所以使用DTS,设备都是预先挂载了如串口0/1/2/3..., 后面安装驱动时,会调用上述说到的platform_driver_register(&serial_imx_driver),在驱动注册过程中会对进行匹配设备,一旦匹配到某个device,就会调用probe进行初始化,这个probe的参量platform_device也就有来源了。具体可以参考下面的调用过程:
do_basic_setup()->driver_init()->platform_bus_init()->...初始化platform bus(虚拟总线)
设备向内核注册的时候platform_device_register()->platform_device_add()->...内核把设备挂在虚拟的platform bus下
驱动注册的时候platform_driver_register()->driver_register()->bus_add_driver()->driver_attach()->bus_for_each_dev()对每个挂在虚拟的platform bus的设备作__driver_attach()->driver_probe_device()->drv->bus->match()==platform_match()->比较strncmp(pdev->name, drv->name, BUS_ID_SIZE),如果相符就调用platform_drv_probe()->driver->probe(),如果probe成功则设备与驱动成功绑定.
代码如下:在执行到driver_attach的时候platform_device还没出现:
int driver_attach(struct device_driver *drv)
{
return bus_for_each_dev(drv->bus, NULL, drv, __driver_attach);
}
EXPORT_SYMBOL_GPL(driver_attach);
这一步开始出现了,县初始化device list,然后通过next_device来遍历节点的属性,调用fn也即__driver_attach,dev也是从next_device中获取device指针。
int bus_for_each_dev(struct bus_type *bus, struct device *start,
void *data, int (*fn)(struct device *, void *))
{
struct klist_iter i;
struct device *dev;
int error = ; if (!bus || !bus->p)
return -EINVAL; klist_iter_init_node(&bus->p->klist_devices, &i,
(start ? &start->p->knode_bus : NULL));
while ((dev = next_device(&i)) && !error)
error = fn(dev, data);
klist_iter_exit(&i);
return error;
}
EXPORT_SYMBOL_GPL(bus_for_each_dev);
以上只是简单理解,还是没有深入进去,所以很多原理说不清楚,希望能有时间静下心好好研究研究,如:
1. 设备、驱动、总线三者设计理念,结构模式
2. 设备、驱动先后挂到总线上的机制
3. linux2.6之前、linux2.6、linux2.6之后,驱动、设备在这些版本中的变迁,如platform的出现,dts的出现等
[platform]linux platform device/driver(一)--Driver是如何找到对应的device的更多相关文章
- [platform]linux platform device/driver(三)--Platform Device和Platform_driver注册过程之代码对比
转自:http://blog.csdn.net/thl789/article/details/6723350 Linux 2.6的设备驱动模型中,所有的device都是通过Bus相连.device_r ...
- [platform]linux platform device/driver(二)--Platform Device和Platform_driver注册过程之详细代码
转自:http://www.cnblogs.com/haimeng2010/p/3582403.html 目录: 1.platform_device注册过程 2.platform_driver注册过程 ...
- Linux Platform Device and Driver
从 Linux 2.6 起引入了一套新的驱动管理和注册机制 :Platform_device 和 Platform_driver . Linux 中大部分的设备驱动,都可以使用这套机制 , 设备用 P ...
- Linux kernel驱动相关抽象概念及其实现 之“bus,device,driver”
bus,device,driver三个很重要的概念贯穿Linux内核驱动架构,特转载一篇博文: (转载自http://blog.csdn.net/gdt_a20/article/details/642 ...
- Linux platform设备简介
Technorati 标签: Linux platform Linux在2.6内核中,针对一系列设备驱动,提供新的管理框架,成为platform机制,推出的目的,在于隔离驱动的资源和实现,使得 ...
- Linux Platform驱动模型(二) _驱动方法
在Linux设备树语法详解和Linux Platform驱动模型(一) _设备信息中我们讨论了设备信息的写法,本文主要讨论平台总线中另外一部分-驱动方法,将试图回答下面几个问题: 如何填充platfo ...
- Linux Regulator Framework(2)_regulator driver
转自蜗窝科技:http://www.wowotech.net/pm_subsystem/regulator_driver.html 说实话,这篇好难懂啊... 1. 前言 本文从regulator d ...
- [中英对照]Device Drivers in User Space: A Case for Network Device Driver | 用户态设备驱动: 以网卡驱动为例
前文初步介绍了Linux用户态设备驱动,本文将介绍一个典型的案例.Again, 如对Linux用户态设备驱动程序开发感兴趣,请阅读本文,否则请飘过. Device Drivers in User Sp ...
- Linux Platform驱动模型(二) _驱动方法【转】
转自:http://www.cnblogs.com/xiaojiang1025/archive/2017/02/06/6367910.html 在Linux设备树语法详解和Linux Platform ...
随机推荐
- javabean实现serializable有什么用?为什么数据库持久就Bean实现这个接口?
Java的"对象序列化"能让你将一个实现了Serializable接口的对象转换成一组byte,这样日后要用这个对象时候,你就能把这些byte数据恢复出来,并据此重新构建那个对象了 ...
- HDU 4686 矩阵快速幂 Arc of Dream
由式子的性质发现都是线性的,考虑构造矩阵,先有式子,a[i] = ax * a[i-1] + ay; b[i] = bx*b[i-1] +by; a[i]*b[i] = ax*bx*a[i-1]*b[ ...
- numpy常用函数
numpy.ndarray.astype 更改np.array的类型.
- leetcode 40 Combination Sum II --- java
Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in ...
- Codeforces378 D Kostya the Sculptor(贪心)(逻辑)
Kostya the Sculptor time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- zf2 中 new Express 的用法
在使用联表查询时,如查联表条件有多个也可以,但是连接条件在zf2中会自动给列加``符号,所以要加像id = 1 这样的,他自动给1加``就无示执行了,这时候可以使用new Express(''),他里 ...
- 《笨办法学Python》
习题一 第一个程序 print "Hello World!" print "Hello Evilxr" print "I like typing th ...
- 论文笔记之:Active Object Localization with Deep Reinforcement Learning
Active Object Localization with Deep Reinforcement Learning ICCV 2015 最近Deep Reinforcement Learning算 ...
- JAVA 新闻
Oracle已对Java失去兴趣?Java社区能否扭转乾坤? http://news.cnblogs.com/n/549566/ http://mp.weixin.qq.com/s?__biz=MjM ...
- Oracle DBWR,LGWR,CKPT,ARCH 触发条件 总结
一. DBWR写磁盘数据触发条件 1. 当进程在辅助LRU链表和主LRU链表上扫描以查找可以覆盖的buffer header[空闲缓冲区]时,如果已经扫描的buffer header的数量到达一定的 ...