feat(driver/net): 将网络设备注册到sysfs, 添加设备类属性文件 #919
Merged
+2,136
−583
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
本次PR的主要修改:
全部设备相关:
virtio设备相关
给通过pci probe出来的virtio设备设置了父设备,在pci设备下创建其对应的virtio设备符号链接。如在0000:00:03.0下创建了virtio0的符号链接
但是我不知道mmio probe出来的virtio设备父设备怎么设置,所以给了None值,即不设置其父设备
修改了virtio_net.rs一部分的代码,主要是关于VirtioInterface这个结构体,原先是为其实现了VirtIODevice trait和NetDevice trait。我将其分成两个结构体,分别为VirtIONetDevice实现了VirtIODevice trait以及为VirtioInterface实现了NetDevice trait。参考linux先完成了VirtIONetDevice设备的注册,然后通过VirtIONetDriver的probe()去注册VirtioInterface设备。再将VirtioInterface的父设备设置为将其probe出来的VirtIODevice
实现了VirtIOBus的match_device()方法,这样就不用在virtio设备注册的时候直接手动调用驱动的probe(),而是通过bus_probe_device(),匹配对应的驱动,设置设备驱动并自动调用其probe()
net设备相关:
kobjec相关:主要是DeviceManager,添加了class_dir_create_and_add,在get_device_parent()中被调用,主要是为了判断该设备是否为设备类,然后在其父设备下创建对应的类目录,在该类目录中创建目标为设备的符号链接。如virtio0下的net类目录创建了eth1的符号链接:
对于没有父设备的设备,比如lo,fbcon,tty0等在/sys/devices/virtual下创建类目录,然后链接到设备: