为什么 dev.bus 在我的设备中为 NULL?
我试图了解Linux设备/驱动程序模型是如何工作的,为此我编写了一个小模块。这个模块很简单,通过函数dev_get_by_name(&init_net, "eth0")
检索指向struct net_device
(我们称之为netdev)的指针。为什么netdev->dev.bus
的值为NULL
?该指针是否应该代表我的设备所连接的 bus_type
结构?然而,字段netdev->parent->bus
不是NULL
,但它应该代表eth控制器的总线......有什么解释吗?
i'm trying to understand how linux device/driver model works and to do this i've written a little module. This module is simple, retrieves a pointer to a struct net_device
(let's call it netdev) by the function dev_get_by_name(&init_net, "eth0")
. Why the value of netdev->dev.bus
is NULL
? Should that pointer represent the bus_type
structure on which my device is attached? The field netdev->parent->bus
is however not NULL
but it should represent the bus for eth controller...any explanation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为你的 eth 设备,或者更好地说它在内核中的设备“对象”,不是总线,因此它的总线值是未初始化的。但其父设备通常位于总线上,并且父设备知道其所在的总线就足够了,因为两个设备最终在驱动程序初始化期间链接。
让我们看一个例子:这是我在 sysfs 中的 eth0 设备的内容(注意设备字段):
设备的链接是根据驱动程序探测函数的这段代码创建的,其中 netdev 是网络设备,并且pdev 关联的 PCI 设备:
根据文档,这是:
这是我在相应 PCI 设备中的内容,由 SET_NETDEV_DEV 设置(您可以在其中注意到总线字段):
我希望这能够澄清情况。
This is because your eth device, or better said its device "object" in the kernel, is not a bus and thus its bus value is left unitialized. But its parent device usually is on a bus and it is sufficient that the parent device knows the bus it is on, since both device eventually are linked during the driver initialization.
Let's have a look at an example: here is what I have in sysfs for my eth0 device (notice the device field):
The link for the device is created from this code from the driver probe function, where netdev is the network device, and pdev the associated PCI device:
Which according to the documentation is:
And here is what I have in the corresponding PCI device, that was set by SET_NETDEV_DEV (where you can notice the bus field):
I hope this clarifies the situtation.