devicetree中数据和structdevice有什么关系

总体来说,devicetree与structdevice的关系应该还是在其生成platformdevice的时候,一直传递的structdevice *parent参数。下面先把其源码中传递过程描述如下(仍以At91rm9200为例):

1,

DT_MACHINE_START(at91sam_dt,"Atmel AT91SAM (Device Tree)")

/*Maintainer: Atmel */

.timer =&at91sam926x_timer,

.map_io =at91_map_io,

.init_early =at91_dt_initialize,

.init_irq =at91_dt_init_irq,

.init_machine =at91_dt_device_init,

.dt_compat =at91_dt_board_compat,

MACHINE_END

2,

staticvoid __init at91_dt_device_init(void)

{

of_platform_populate(NULL,of_default_bus_match_table, NULL, NULL);

}

3,

/**

*of_platform_populate() - Populate platform_devices from device treedata

*@root: parent of the first level to probe or NULL for the root of thetree

*@matches: match table, NULL to use the default

*@parent: parent to hook devicesfrom, NULL for toplevel

*

*Similar to of_platform_bus_probe(), this function walks the devicetree

*and creates devices from nodes. It differs in that it follows themodern

*convention of requiring all device nodes to have a 'compatible'property,

*and it is suitable for creating devices which are children of theroot

*node (of_platform_bus_probe will only create children of the rootwhich

*are selected by the @matches argument).

*

*New board support should be using this function instead of

*of_platform_bus_probe().

*

*Returns 0 on success, < 0 on failure.

*/

//从devicetree数据中populateplatform devices。

intof_platform_populate(structdevice_node *root,

conststruct of_device_id *matches,

conststruct of_dev_auxdata *lookup,

structdevice *parent)

{

structdevice_node *child;

intrc = 0;

root= root ? of_node_get(root) : of_find_node_by_path("/");

if(!root)

return-EINVAL;

for_each_child_of_node(root,child) {

//生成platformdevice

rc= of_platform_bus_create(child,matches, lookup, parent,true);

if(rc)

break;

}

of_node_put(root);

returnrc;

}

4,

/**

*of_platform_bus_create() - Create a device for a node and itschildren.

*@bus: device node of the bus to instantiate

*@matches: match table for bus nodes

*@lookup: auxdata table for matching id and platform_data with devicenodes

*@parent: parent for new device, or NULL for top level.

*@strict: require compatible property

*

*Creates a platform_device for the provided device_node, andoptionally

*recursively create devices for all the child nodes.

*/

//为节点和其孩子节点生成一个设备文件。

staticint of_platform_bus_create(structdevice_node *bus,

const struct of_device_id *matches,

const struct of_dev_auxdata *lookup,

struct device *parent, boolstrict)

{

conststruct of_dev_auxdata *auxdata;

structdevice_node *child;

structplatform_device *dev;

constchar *bus_id = NULL;

void*platform_data = NULL;

intrc = 0;

/*Make sure it has a compatible property */

if(strict && (!of_get_property(bus, "compatible",NULL))) {

pr_debug("%s()- skipping %s, no compatible prop\n",

__func__, bus->full_name);

return0;

}

auxdata= of_dev_lookup(lookup, bus);

if(auxdata) {

bus_id= auxdata->name;

platform_data= auxdata->platform_data;

}

if(of_device_is_compatible(bus, "arm,primecell")) {

of_amba_device_create(bus,bus_id, platform_data, parent);

return0;

}

dev= of_platform_device_create_pdata(bus,bus_id, platform_data, parent);

if(!dev || !of_match_node(matches, bus))

return0;

for_each_child_of_node(bus,child) {

pr_debug(" create child: %s\n", child->full_name);

rc= of_platform_bus_create(child, matches, lookup, &dev->dev,strict);

if(rc) {

of_node_put(child);

break;

}

}

returnrc;

}

代码在这儿分了两步走:4.1和4.2。

4.1

staticstruct amba_device *of_amba_device_create(structdevice_node *node,

const char *bus_id,

void *platform_data,

struct device *parent)

{

structamba_device *dev;

constvoid *prop;

inti, ret;

pr_debug("Creatingamba device %s\n", node->full_name);

if(!of_device_is_available(node))

returnNULL;

dev= amba_device_alloc(NULL, 0, 0);

if(!dev)

returnNULL;

/*setup generic device info */

dev->dev.coherent_dma_mask= ~0;

dev->dev.of_node= of_node_get(node);

dev->dev.parent= parent;

dev->dev.platform_data= platform_data;

…...

}

4.2

/**

*of_platform_device_create_pdata - Alloc, initialize and register anof_device

*@np: pointer to node to create device for

*@bus_id: name to assign device

*@platform_data: pointer to populate platform_data pointer with

*@parent: Linux device model parentdevice.

*

*Returns pointer to created platform device, or NULL if a device wasnot

*registered. Unavailable devices will not get registered.

*/

//分配内存,初始化和注册一个of_device

structplatform_device *of_platform_device_create_pdata(

structdevice_node *np,

constchar *bus_id,

void*platform_data,

structdevice *parent)

{

structplatform_device *dev;

if(!of_device_is_available(np))

returnNULL;

dev= of_device_alloc(np,bus_id, parent);

…...

returndev;

}

4.2.1

/**

*of_device_alloc - Allocate and initialize an of_device

*@np: device node to assign to device

*@bus_id: Name to assign to the device. May be null to use defaultname.

*@parent: Parent device.

*/

//分配内存和初始化of_device

structplatform_device *of_device_alloc(structdevice_node *np,

const char *bus_id,

struct device *parent)

{

structplatform_device *dev;

intrc, i, num_reg = 0, num_irq;

structresource *res, temp_res;

dev= platform_device_alloc("", -1);

if(!dev)

returnNULL;

/*count the io and irq resources */

if(of_can_translate_address(np))

while(of_address_to_resource(np, num_reg, &temp_res) == 0)

num_reg++;

num_irq= of_irq_count(np);

/*Populate the resource table */

if(num_irq || num_reg) {

res= kzalloc(sizeof(*res) * (num_irq + num_reg), GFP_KERNEL);

if(!res) {

platform_device_put(dev);

returnNULL;

}

dev->num_resources= num_reg + num_irq;

dev->resource= res;

for(i = 0; i < num_reg; i++, res++) {

rc= of_address_to_resource(np, i, res);

WARN_ON(rc);

}

WARN_ON(of_irq_to_resource_table(np,res, num_irq) != num_irq);

}

dev->dev.of_node= of_node_get(np);

#ifdefined(CONFIG_MICROBLAZE)

dev->dev.dma_mask= &dev->archdata.dma_mask;

#endif

dev->dev.parent= parent;

if(bus_id)

dev_set_name(&dev->dev,"%s", bus_id);

else

of_device_make_bus_id(&dev->dev);

returndev;

}

总的分析:parent参数开始初始化为NULL,其中一直没有赋值,直到最后赋值给platformdevice的dev.parent属性。其中关系耐人寻味。

(DT系列六)devicetree中数据和 struct device有什么关系的更多相关文章

  1. 【转】(DT系列六)devicetree中数据和 struct device有什么关系

    原文网址:http://www.cnblogs.com/biglucky/p/4057499.html devicetree中数据和structdevice有什么关系 总体来说,devicetree与 ...

  2. (DT系列五)Linux kernel 是怎么将 devicetree中的内容生成plateform_device

    Linux kernel 是怎么将 devicetree中的内容生成plateform_device 1,实现场景(以Versatile Express V2M为例说明其过程)以arch/arm/ma ...

  3. 【转】(DT系列五)Linux kernel 是怎么将 devicetree中的内容生成plateform_device

    原文网址:http://www.cnblogs.com/biglucky/p/4057495.html Linux kernel 是怎么将 devicetree中的内容生成plateform_devi ...

  4. (DT系列五)Linux kernel 是怎么将 devicetree中的内容生成plateform_device【转】

    转自:https://blog.csdn.net/lichengtongxiazai/article/details/38942033 Linux kernel 是怎么将 devicetree中的内容 ...

  5. 大数据系列-CDH环境中SOLR入数据

    1       创建集合 SSH远程连接到安装了SOLR的CDH节点. 运行solrctl  instancedir  --generate  /solr/test/GX_SH_TL_TGRYXX_2 ...

  6. Keil MDK STM32系列(六) 基于抽象外设库HAL的ADC模数转换

    Keil MDK STM32系列 Keil MDK STM32系列(一) 基于标准外设库SPL的STM32F103开发 Keil MDK STM32系列(二) 基于标准外设库SPL的STM32F401 ...

  7. SQL Server 2008空间数据应用系列六:基于SQLCRL的空间数据可编程性

    原文:SQL Server 2008空间数据应用系列六:基于SQLCRL的空间数据可编程性 友情提示,您阅读本篇博文的先决条件如下: 1.本文示例基于Microsoft SQL Server 2008 ...

  8. R语言数据分析系列六

    R语言数据分析系列六 -- by comaple.zhang 上一节讲了R语言作图,本节来讲讲当你拿到一个数据集的时候怎样下手分析,数据分析的第一步.探索性数据分析. 统计量,即统计学里面关注的数据集 ...

  9. 【C++自我精讲】基础系列六 PIMPL模式

    [C++自我精讲]基础系列六 PIMPL模式 0 前言 很实用的一种基础模式. 1 PIMPL解释 PIMPL(Private Implementation 或 Pointer to Implemen ...

随机推荐

  1. Hash函数的安全性

    我们为了保证消息的完整性,引进了散列函数,那么散列函数会对安全正造成什么影响呢?这是需要好好研究一番的问题. 三个概念: 1.如果y<>x,且h(x)=h(y),则称为碰撞. 2.对于给定 ...

  2. 设计模式之开篇(C#语法)

    很长时间没有写文章了,前段时间写的C#语法糖分享得到有很多朋友支持,这个也使得我有信心继续分享下去,在这里非常感谢大家!这次开始给大家分享一下设计模式,我个人觉得设计模式也对于我们提高个人技术水平来说 ...

  3. scp 命令使用

    scp 是secure copy的简写,用于在Linux下进行远程拷贝文件的命令,和它类似的命令有cp,不过cp只是在本机进行拷贝不能跨服务器,而且 scp传输是加密的.可能会稍微影响一下速度.当你服 ...

  4. Python3 高级特性

    切片 L[0:3]表示,从索引0开始取,直到索引3为止,但不包括索引3.即索引0,1,2,正好是3个元素. 如果第一个索引是0,还可以省略: >>> L =['Michael', ' ...

  5. cenots 下的 lamp(备份与恢复)

    用 putty连接数据库: mysql -uroot -p密码 create database yourdb DEFAULT CHARACTER SET utf8 COLLATE utf8_chine ...

  6. MAC 终端快捷建

    常用的快捷键: Ctrl + d        删除一个字符,相当于通常的Delete键(命令行若无所有字符,则相当于exit:处理多行标准输入时也表示eof) Ctrl + h        退格删 ...

  7. 在ADO.NET中使用参数化SQL语句访问不同数据库时的差异

    在ADO.NET中经常需要跟各种数据库打交道,在不实用存储过程的情况下,使用参数化SQL语句一定程度上可以防止SQL注入,同时对一些较难赋值的字段(如在SQL Server中Image字段,在Orac ...

  8. We7在政府门户中的应用

    政府门户从传统的信息引导发展到现阶段的服务型门户,不论从角度转变上还是从平台选型上都跟以前有很大的不同,其更注重的是安全.扩展.易用和移动互联网几部分(当然这儿的注重是建立在已有政府门户电子政务三个板 ...

  9. Swift与Objective-C的兼容“黑魔法”:@objc和Dynamic

    Cocoa框架早已烙上了不可磨灭的OC印记,而无数的第三方库都是用OC写成的,这些积累无论是谁都不能小觑.苹果采取了允许开发者在同一个项目中同时使用Swift和OC进行开发的做法,但要想实现互通,又需 ...

  10. REST响应处理

    JAX-RS 2.0 支持4种返回值类型的响应,分别是无返回值.返回Response类实例.返回GenericEntity类实例和返回自定义类实例. 1.在返回值类型是VOID的响应中,其响应实体为空 ...