总线中的match函数-笔记

嵌入式软件的bus_type 结构中的一个成员 .match 成员,是一个函数。用来在现有的设备驱动中匹配新插入的设备。匹配方式有4种(设备树、ACPI,id_tables, name)。
以platform总线为例,platform_bus_type 实例的match 为 platform_match, 在这里插入图片描述
platform_match 的代码为,很简单的描述4种匹配方式。

static int platform_match(struct device *dev, struct device_driver *drv)
{
   
	struct platform_device *pdev = to_platform_device(dev);
	struct platform_driver *pdrv = to_platform_driver(drv);

	/* When driver_override is set, only bind to the matching driver */
	if (pdev->driver_override)
		return !strcmp(pdev->driver_override, drv->name);

	/* Attempt an OF style match first */
	if (of_driver_match_device(dev, drv))
		return 1;

	/* Then try ACPI style match */
	if (acpi_driver_match_device(dev, drv))
		return 1;

	/* Then try to match against the id table */
	if (pdrv->id_table)
		return platform_match_id(pdrv->id_table, pdev) != NULL;

	/* fall-back to driver name match */
	return (strcmp(pdev->name, drv->name) == 0);
}

本次笔记主要记录 其中的of_driver_match_device 函数的调用关系,以理解设备树匹配的流程,进而理解id_table,name匹配的部分流程。
of_driver_match_device 在设备树中发现有与驱动匹配的设备,就会返回1,进而match函数返回1.
调用关系为:
of_driver_match_device(struct device *dev, const struct device_driver *drv)
|-- of_match_device(struct of_device_id, struct device)
|-- of_match_node(const struct of_device_id , const struct device_node )
|–__of_match_node (const struct of_device_id , const struct device_node )

最终调用 __of_match_node 进行匹配函数的具体执行。该函数会循环对比所有的驱动程序,以选择score 最好的那个驱动作为该设备的驱动。对比程序为 of_device_is_compatible(const struct device_node ,
const char *compat, const char *type, const char *name)
该函数会根据驱动的compatible、type、name三个字段的某种组合,共11 种,返回 score 值。在of_match"_node 中选择最好的 score,它对应的match 即为最优驱动程序。
over。

相关推荐

  1. re模块match函数使用

    2024-02-22 08:34:01       31 阅读
  2. esmatch,term,match_phrase

    2024-02-22 08:34:01       12 阅读
  3. Elasticsearch term、terms 和 match 查询

    2024-02-22 08:34:01       31 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-02-22 08:34:01       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-02-22 08:34:01       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-02-22 08:34:01       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-02-22 08:34:01       18 阅读

热门阅读

  1. yarn常用命令小记

    2024-02-22 08:34:01       27 阅读
  2. 使用多线程常见的架构

    2024-02-22 08:34:01       25 阅读
  3. 深入解析Lambda架构与Kappa架构

    2024-02-22 08:34:01       22 阅读
  4. 蓝桥杯刷题--python-10(2023填空题3)

    2024-02-22 08:34:01       34 阅读
  5. docker搭建Postgresql主备集群

    2024-02-22 08:34:01       27 阅读
  6. js设计模式汇总

    2024-02-22 08:34:01       26 阅读
  7. 突破编程_C++_面试(数组(1))

    2024-02-22 08:34:01       26 阅读
  8. 嵌入式24——IO

    2024-02-22 08:34:01       26 阅读
  9. 计算机网络--物理层练习题

    2024-02-22 08:34:01       28 阅读
  10. MySQL中的高级查询

    2024-02-22 08:34:01       20 阅读