1. 程式人生 > 其它 >linux 驅動裝置和 dts 匹配過程

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系列函式進行驅動解除安裝

原文連結:https://blog.csdn.net/sinat_30545941/article/details/85943787

作者:柒月 出處:https://www.cnblogs.com/Ph-one/ 開源:https://github.com/iqiy/ 站點:https://qiy.net/ Q群 :2122210(嵌入式/機器學習)