linux 驱动设备和 dts 匹配过程

linux 设备驱动文件在与 dts 中的设备板级硬件信息匹配的关键字是 compatible 属性。即比较驱动文件中 of_device_id 结构体元素的 .compatible 成员变量和 dts 文件中 node 中 compatible 属性两个字符串。

Rationale:

linux 启动从 lk jump 到 kernel 之后

    函数调用的深度比较深所以图比较长,其中细节部分省略,可以打开具体源码去看。

可以看到最后调用的函数

static inline int of_driver_match_device(struct device *dev,const struct device_driver *drv)
	--->of_match_device(drv->of_match_table, dev) != NULL;
		--->of_match_node(matches, dev->of_node)
			--->__of_match_node(matches, node)
				--->static const struct of_device_id *__of_match_node(const struct             
                       of_device_id *matches,
					   const struct device_node *node)
					{
						const struct of_device_id *best_match = NULL;
						int score, best_score = 0;

						if (!matches)
							return NULL;

						for (; matches->name[0] || matches->type[0] || matches->compatible[0]; matches++) {
                  //此函数将driver的of_match_table->compatible和node中的compatible比较
							score = __of_device_is_compatible(node, matches->compatible,
											  matches->type, matches->name); 
							if (score > best_score) {
								best_match = matches;
								best_score = score;
							}    
						}

						return best_match;
					}

传递到最后__of_device_is_compatible函数将driver的of_match_table->compatible和node中的compatible比较,这个比较不是单纯的比较,是一种加分制。

匹配成功之后会进行probe,如果driver 的 probe 执行不成功(比如硬件问题,或者没有挂载设备),会调用sys系列函数进行驱动卸载。

  • 6
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值