简体   繁体   English

为什么dev.bus在我的设备中为NULL?

[英]Why dev.bus is NULL in my device?

i'm trying to understand how linux device/driver model works and to do this i've written a little module. 我试图了解linux设备/驱动程序模型是如何工作的,为此,我编写了一个小模块。 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") . 这个模块很简单,通过函数dev_get_by_name(&init_net, "eth0")检索指向struct net_device的指针(我们将其称为dev_get_by_name(&init_net, "eth0") Why the value of netdev->dev.bus is NULL ? 为什么netdev->dev.bus值为NULL Should that pointer represent the bus_type structure on which my device is attached? 该指针是否应该代表我的设备所连接的bus_type结构? The field netdev->parent->bus is however not NULL but it should represent the bus for eth controller...any explanation? 字段netdev->parent->bus但是不是NULL但是它应该代表eth控制器的总线...任何解释吗?

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. 这是因为您的eth设备(或更确切地说是内核中的设备“对象”)不是总线,因此其总线值保持统一。 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): 让我们看一个例子:这是我的eth0设备在sysfs中的内容(请注意设备字段):

$ ll /sys/class/net/eth0/
total 0
-r--r--r-- 1 root root 4096 May 20 11:10 address
-r--r--r-- 1 root root 4096 May 20 11:10 addr_len
-r--r--r-- 1 root root 4096 May 20 11:10 broadcast
-r--r--r-- 1 root root 4096 May 20 11:10 carrier
lrwxrwxrwx 1 root root    0 May 20 11:10 device -> ../../../devices/pci0000:00/0000:00:19.0
-r--r--r-- 1 root root 4096 May 20 11:10 dev_id
-r--r--r-- 1 root root 4096 May 20 11:10 dormant
-r--r--r-- 1 root root 4096 May 20 11:10 features
-rw-r--r-- 1 root root 4096 May 20 11:10 flags
-rw-r--r-- 1 root root 4096 May 20 11:10 ifalias
-r--r--r-- 1 root root 4096 May 20 11:10 ifindex
-r--r--r-- 1 root root 4096 May 20 11:10 iflink
-r--r--r-- 1 root root 4096 May 20 11:10 link_mode
-rw-r--r-- 1 root root 4096 May 20 11:10 mtu
-r--r--r-- 1 root root 4096 May 20 11:10 operstate
drwxr-xr-x 2 root root    0 May 20 11:10 power
drwxr-xr-x 2 root root    0 May 20 11:10 statistics
lrwxrwxrwx 1 root root    0 May 20 11:10 subsystem -> ../../net
-rw-r--r-- 1 root root 4096 May 20 11:10 tx_queue_len
-r--r--r-- 1 root root 4096 May 20 11:10 type
-rw-r--r-- 1 root root 4096 May 20 11:10 uevent

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: 设备的链接是通过驱动程序探测功能的以下代码创建的,其中netdev是网络设备,而pdev是关联的PCI设备:

SET_NETDEV_DEV(netdev, &pdev->dev);

Which according to the documentation is: 根据文档,哪个是:

/* Set the sysfs physical device reference for the network logical device
 * if set prior to registration will cause a symlink during initialization.
 */
#define SET_NETDEV_DEV(net, pdev)   ((net)->dev.parent = (pdev))

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): 这是我在相应的PCI设备中所拥有的,这是由SET_NETDEV_DEV设置的(您可以在其中注意到总线字段):

$ ll /sys/devices/pci0000\:00/0000\:00\:19.0/
total 0
-rw-r--r-- 1 root root   4096 May 20 11:54 broken_parity_status
lrwxrwxrwx 1 root root      0 May 20 11:22 bus -> ../../../bus/pci
-r--r--r-- 1 root root   4096 May 20 11:07 class
-rw-r--r-- 1 root root    256 May 20 11:22 config
-r--r--r-- 1 root root   4096 May 20 11:54 device
lrwxrwxrwx 1 root root      0 May 20 11:22 driver -> ../../../bus/pci/drivers/e1000e
-rw------- 1 root root   4096 May 20 11:22 enable
-r--r--r-- 1 root root   4096 May 20 11:07 irq
-r--r--r-- 1 root root   4096 May 20 11:54 local_cpulist
-r--r--r-- 1 root root   4096 May 20 11:07 local_cpus
-r--r--r-- 1 root root   4096 May 20 11:22 modalias
-rw-r--r-- 1 root root   4096 May 20 11:22 msi_bus
lrwxrwxrwx 1 root root      0 May 20 11:22 net:eth0 -> ../../../class/net/eth0
drwxr-xr-x 2 root root      0 May 20 11:11 power
-r--r--r-- 1 root root   4096 May 20 11:22 resource
-rw------- 1 root root 131072 May 20 11:22 resource0
-rw------- 1 root root   4096 May 20 11:22 resource1
-rw------- 1 root root     32 May 20 11:22 resource2
lrwxrwxrwx 1 root root      0 May 20 11:22 subsystem -> ../../../bus/pci
-r--r--r-- 1 root root   4096 May 20 11:22 subsystem_device
-r--r--r-- 1 root root   4096 May 20 11:22 subsystem_vendor
-rw-r--r-- 1 root root   4096 May 20 11:22 uevent
-r--r--r-- 1 root root   4096 May 20 11:22 vendor

I hope this clarifies the situtation. 我希望这可以澄清这种情况。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 是否可以与 /dev/bus/usb/ 进行串行通信<bus> /<device> - is it possible to do the serial communication with /dev/bus/usb/<bus>/<device> 如何将 /proc/bus/usb/devices 条目映射到 /dev/sdX 设备? - How to map /proc/bus/usb/devices entry to a /dev/sdX device? 如何从struct pci_dev获取总线/设备/号码? - How to get bus/device/number from struct pci_dev? PyUSB:为什么bus.dirname和dev.filename为空字符串? - PyUSB: Why are bus.dirname and dev.filename empty string? 如何通过`lsusb`列出的总线号和设备号在`/dev`中找到设备文件? - How can I find the device file in `/dev` via bus number and device number listed by `lsusb`? 尝试访问嵌入式 ZEDC9F0A5A5D57797BF68E3736474383 上的 USB 设备 [/dev/bus/usb/001/001] 时 Python “[Errno 21] 是一个目录” - Python "[Errno 21] Is a directory" when trying access USB device [/dev/bus/usb/001/001] on embedded Linux device 为什么管道输出到 /dev/null 和 grep 会污染我的 bash 阵列? - Why does piping out to /dev/null and grep, pollute my bash array? / dev / bus / usb未创建/找到 - /dev/bus/usb not created/found 为什么将“&lt; /dev/null”与“bzip2”之类的程序一起使用? - Why Using "< /dev/null" with a program like "bzip2"? 为什么要命令; ls -l file_doesnot_exists &gt; /dev/null 2&gt;&amp;1 正在工作; ls -l 2&gt;&amp;1 file_doesnot_exists &gt; /dev/null 不是 - why the command; ls -l file_doesnot_exists > /dev/null 2>&1 is working while; ls -l 2>&1 file_doesnot_exists > /dev/null is not
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM