当前位置:网站首页>aliases node analysis
aliases node analysis
2022-08-10 05:10:00 【Four Seasons Sail】
There is a node called aliases in the device tree:
/{#address-cells = <1>;#size-cells = <1>;aliases {fimc0 = &fimc0;fimc1 = &fimc1;fimc2 = &fimc2;i2c0 = &i2c0;i2c1 = &i2c1;i2c2 = &i2c2; };......};This node will be parsed when the Linux kernel starts:
start_kernelsetup_archunflatten_device_treeof_alias_scanvoid of_alias_scan(void * (*dt_alloc)(u64 size, u64 align)){struct property *pp;/* Find the device_node corresponding to the /aliases node */of_aliases = of_find_node_by_path("/aliases");/* Find the device_node corresponding to the /chosen node */of_chosen = of_find_node_by_path("/chosen");/* If there is no /chosen, find the /[email protected] node */if (of_chosen == NULL)of_chosen = of_find_node_by_path("/[email protected]");/* Traverse the properties of the /aliases node */for_each_property_of_node(of_aliases, pp) {const char *start = pp->name; // the name of the propertyconst char *end = start + strlen(start); // end of name, *end is '\0'struct device_node *np;struct alias_prop *ap;int id, len;/* Skip those we do not want to proceed *//* Ignore attributes whose names are name, phandle, linux, phandle */if (!strcmp(pp->name, "name") ||!strcmp(pp->name, "phandle") ||!strcmp(pp->name, "linux,phandle"))continue;/* Get the node corresponding to this value according to the value of the attribute *//* For example, this property, fimc2 = "/soc/camera/[email protected]" to find the node through the path */np = of_find_node_by_path(pp->value);if (!np)continue;/* Normally an attribute name is fimc1, i2c0, so, here is to point the end pointer to the position in front of the number,* Such as the address of the c character of fimc2 */while (isdigit(*(end-1)) && end > start)end--;len = end - start; /* this len is the length of the name minus numbers *//* Convert the number after the end string into a number and copy it to the id, such as fimc2, number 2 */if (kstrtoint(end, 10, &id) < 0)continue;/* Allocate an alias_prop with enough space for the stem *//* Allocate memory, the multi-allocated "len+1" is used to store the name of stem */ap = dt_alloc(sizeof(*ap) + len + 1, __alignof__(*ap));if (!ap)continue;memset(ap, 0, sizeof(*ap) + len + 1);ap->alias = start; /* ap->alias points to the string "fimc2 */of_alias_add(ap, np, id, start, len);}}static void of_alias_add(struct alias_prop *ap, struct device_node *np,int id, const char *stem, int stem_len){ap->np = np; // np is the node device_node corresponding to "/soc/camera/[email protected]";"ap->id = id; // The value of id is 2, which represents the device serial number, which is used when using//Since stem_len is the length of the name minus the number, ap->stem is assigned the value "fimc"strncpy(ap->stem, stem, stem_len);ap->stem[stem_len] = 0;list_add_tail(&ap->link, &aliases_lookup); //Add this ap to the global aliases_lookup listpr_debug("adding DT alias:%s: stem=%s id=%i node=%pOF\n",ap->alias, ap->stem, ap->id, np);}When registering the i2c controller:
int i2c_add_adapter(struct i2c_adapter *adapter){struct device *dev = &adapter->dev;int id;if (dev->of_node) {//Get the id of alias_prop corresponding to this device_node.If i2c2 = &i2c2; node is used as an example, the id obtained here is 2id = of_alias_get_id(dev->of_node, "i2c");if (id >= 0) {adapter->nr = id;return __i2c_add_numbered_adapter(adapter);}}id = idr_alloc(&i2c_adapter_idr, adapter,__i2c_first_dynamic_bus_num, 0, GFP_KERNEL);adapter->nr = id;return i2c_register_adapter(adapter);}int of_alias_get_id(struct device_node *np, const char *stem){struct alias_prop *app;int id = -ENODEV;mutex_lock(&of_mutex);/* Traverse the global linked list aliases_lookup */list_for_each_entry(app, &aliases_lookup, link) {/* find alias_prop whose stem is "i2c" */if (strcmp(app->stem, stem) != 0)continue;/* All i2c-controlled stems are called "i2c", so make sure the device nodes are consistent */if (np == app->np) {id = app->id; /* Finally return the number name found */break;}}mutex_unlock(&of_mutex);return id;}From the above analysis, we can see the role of the alias node:
For example, there are multiple i2c controllers on the SoC, and alias is equivalent to assigning a unique number to each i2c controller. For example, the alias corresponding to i2c2 above is i2c2, then this number is 2, and it will be available in /dev in the futureBelow you see a device node named i2c-2.
Reference documents:
边栏推荐
猜你喜欢

线性模型中的高级特征选择技术——基于R

Flutter development: error The following assertion was thrown resolving an image codec: Solution for Unable to...

2022G3 Boiler Water Treatment Exam Mock 100 Questions and Mock Exam

小影科技IPO被终止:年营收3.85亿 五岳与达晨是股东

leetcode每天5题-Day12

干货 | 查资料利器:线上图书馆

What is the relationship between legal representative and shareholders?

【论文笔记】Prototypical Contrast Adaptation for Domain Adaptive Semantic Segmentation

2022 T Elevator Repair Exam Questions and Mock Exams

【LeetCode】41、 缺失的第一个正数
随机推荐
An article to master the entire JVM, JVM ultra-detailed analysis!!!
基于BP神经网络的多因素房屋价格预测matlab仿真
【LeetCode】41. The first missing positive number
2022 R2 transportable pressure vessel filling operation examination question bank simulation platform
Rpc interface stress test
oracle cdc时,设置并行度2插槽数1,最终任务只有一个tm,是不是因为oracle不支持并发
RK3568处理器体验小记
leetcode每天5题-Day11
Joomla漏洞复现
成为黑客不得不学的语言,看完觉得你们还可吗?
SQLSERVER 2008 parses data in Json format
Big guys, mysql cdc (2.2.1 and previous versions) sometimes has this situation since savepoint, is there anything wrong?
Arduino框架下合宙ESP32C3 +1.8“tft 网络时钟
Thread.sleep, Thread.yield 作用解释
Abstract problem methodology
Pulsar中游标的工作原理
RadiAnt DICOM Viewer 2022.1 Crack
Become a language that hackers have to learn. Do you think it's okay after reading it?
十年架构五年生活-06 离职的冲动
深度梳理:防止模型过拟合的方法汇总