如何解决在设备树中的节点之间共享变量
我正在尝试找到一种方法来从 node_1 访问此设备树中 node_0 中的变量(请参阅下面的代码):
/ {
amba_pl: amba_pl@0 {
node_0: node@a8000000 {
node_id = <0x0>;
node0State = <0x0>;
};
};
node_1: node@a9000000 {
node1State = <node_0's node0State>;
};
};
};
主要目标是能够在内核模块之间共享状态。我知道我可以在写入节点中 EXPORT_SYMBOL(variable) 然后在读取节点中 extern *variable ,但想看看我是否可以在设备树本身中完成这个。 node_0 将始终是设置 nodeState 的唯一节点,而 node_1 将只读取。这可能吗?
解决方法
您可以存储一个引用包含 node0state
的节点的 phandle:
/ {
amba_pl: amba_pl@0 {
node_0: node@a8000000 {
node_id = <0x0>;
node0State = <0x0>;
};
};
node_1: node@a9000000 {
stateNode = <&node_0>;
};
};
};
在驱动程序代码中,如果 struct device_node *mynode;
引用了 node_1
节点,那么 node0state
phandle 属性引用的另一个节点的 stateNode
属性可以访问为如下:
int rc = 0;
struct device_node *np;
u32 node0state;
np = of_parse_phandle(mynode,"stateNode",0);
if (!np) {
// error node not found
rc = -ENXIO;
goto error1;
}
// Do whatever is needed to read "node0state". Here is an example.
rc = of_property_read_u32(np,"node0state",&node0state);
if (rc) {
// error
of_node_put(np); // decrement reference to the node
goto error2;
}
// Finished with the node.
of_node_put(np); // decrement reference to the node
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。