分类: LINUX
2008-09-11 23:38:47
root@dell-desktop:~# lspci | grep Ethernet
00:19.0 Ethernet controller: Intel Corporation 82566DM-2 Gigabit Network Connection (rev 02)
root@dell-desktop:~# cd /sys/bus/pci/devices/0000:00:19.0
root@dell-desktop:/sys/bus/pci/devices/0000:00:19.0# ll
total 0
-rw-r--r-- 1 root root 4096 2008-09-10 10:07 broken_parity_status
lrwxrwxrwx 1 root root 0 2008-09-10 10:07 bus -> ../../../bus/pci
-r--r--r-- 1 root root 4096 2008-09-08 14:32 class
-rw-r--r-- 1 root root 256 2008-09-10 10:07 config
-r--r--r-- 1 root root 4096 2008-09-08 14:32 device
lrwxrwxrwx 1 root root 0 2008-09-11 23:15 driver -> ../../../bus/pci/drivers/e1000e
-rw------- 1 root root 4096 2008-09-10 10:07 enable
-r--r--r-- 1 root root 4096 2008-09-10 10:07 irq
-r--r--r-- 1 root root 4096 2008-09-10 10:07 local_cpulist
-r--r--r-- 1 root root 4096 2008-09-10 10:07 local_cpus
-r--r--r-- 1 root root 4096 2008-09-10 10:07 modalias
-rw-r--r-- 1 root root 4096 2008-09-10 10:07 msi_bus
lrwxrwxrwx 1 root root 0 2008-09-11 23:15 net:eth0 -> ../../../class/net/eth0
drwxr-xr-x 2 root root 0 2008-09-10 10:07 power
-r--r--r-- 1 root root 4096 2008-09-08 14:32 resource
-rw------- 1 root root 131072 2008-09-10 10:07 resource0
-rw------- 1 root root 4096 2008-09-10 10:07 resource1
-rw------- 1 root root 32 2008-09-10 10:07 resource2
lrwxrwxrwx 1 root root 0 2008-09-08 14:32 subsystem -> ../../../bus/pci
-r--r--r-- 1 root root 4096 2008-09-08 14:32 subsystem_device
-r--r--r-- 1 root root 4096 2008-09-08 14:32 subsystem_vendor
-rw-r--r-- 1 root root 4096 2008-09-08 14:32 uevent
-r--r--r-- 1 root root 4096 2008-09-08 14:32 vendor
可以看到网卡的驱动连接到e1000e上面。
unbind取消设备与驱动的联系:
root@dell-desktop:/sys/bus/pci/drivers/e1000e# echo -n "0000:00:19.0" > unbind
root@dell-desktop:/sys/bus/pci/drivers/e1000e# ll
total 0
--w------- 1 root root 4096 2008-09-11 23:23 bind
lrwxrwxrwx 1 root root 0 2008-09-11 23:23 module -> ../../../../module/e1000e
--w------- 1 root root 4096 2008-09-11 23:23 new_id
--w------- 1 root root 4096 2008-09-11 23:23 uevent
--w------- 1 root root 4096 2008-09-11 23:25 unbind
查看PCI相应的目录:
root@dell-desktop:/sys/bus/pci/devices/0000:00:19.0# ll
total 0
-rw-r--r-- 1 root root 4096 2008-09-10 10:07 broken_parity_status
lrwxrwxrwx 1 root root 0 2008-09-10 10:07 bus -> ../../../bus/pci
-r--r--r-- 1 root root 4096 2008-09-08 14:32 class
-rw-r--r-- 1 root root 256 2008-09-10 10:07 config
-r--r--r-- 1 root root 4096 2008-09-08 14:32 device
-rw------- 1 root root 4096 2008-09-10 10:07 enable
-r--r--r-- 1 root root 4096 2008-09-10 10:07 irq
-r--r--r-- 1 root root 4096 2008-09-10 10:07 local_cpulist
-r--r--r-- 1 root root 4096 2008-09-10 10:07 local_cpus
-r--r--r-- 1 root root 4096 2008-09-10 10:07 modalias
-rw-r--r-- 1 root root 4096 2008-09-10 10:07 msi_bus
drwxr-xr-x 2 root root 0 2008-09-10 10:07 power
-r--r--r-- 1 root root 4096 2008-09-08 14:32 resource
-rw------- 1 root root 131072 2008-09-10 10:07 resource0
-rw------- 1 root root 4096 2008-09-10 10:07 resource1
-rw------- 1 root root 32 2008-09-10 10:07 resource2
lrwxrwxrwx 1 root root 0 2008-09-08 14:32 subsystem -> ../../../bus/pci
-r--r--r-- 1 root root 4096 2008-09-08 14:32 subsystem_device
-r--r--r-- 1 root root 4096 2008-09-08 14:32 subsystem_vendor
-rw-r--r-- 1 root root 4096 2008-09-08 14:32 uevent
-r--r--r-- 1 root root 4096 2008-09-08 14:32 vendor
bind重新将设备与驱动进行帮定
root@dell-desktop:/sys/bus/pci/drivers/e1000e# echo -n "0000:00:19.0" > bind
root@dell-desktop:/sys/bus/pci/drivers/e1000e# ll
total 0
lrwxrwxrwx 1 root root 0 2008-09-11 23:25 0000:00:19.0 -> ../../../../devices/pci0000:00/0000:00:19.0
--w------- 1 root root 4096 2008-09-11 23:25 bind
lrwxrwxrwx 1 root root 0 2008-09-11 23:23 module -> ../../../../module/e1000e
--w------- 1 root root 4096 2008-09-11 23:23 new_id
--w------- 1 root root 4096 2008-09-11 23:23 uevent
--w------- 1 root root 4096 2008-09-11 23:25 unbind
查看PCI相应的目录:
root@dell-desktop:/sys/bus/pci/devices/0000:00:19.0# ll
total 0
-rw-r--r-- 1 root root 4096 2008-09-10 10:07 broken_parity_status
lrwxrwxrwx 1 root root 0 2008-09-10 10:07 bus -> ../../../bus/pci
-r--r--r-- 1 root root 4096 2008-09-08 14:32 class
-rw-r--r-- 1 root root 256 2008-09-10 10:07 config
-r--r--r-- 1 root root 4096 2008-09-08 14:32 device
lrwxrwxrwx 1 root root 0 2008-09-11 23:23 driver -> ../../../bus/pci/drivers/e1000e
-rw------- 1 root root 4096 2008-09-10 10:07 enable
-r--r--r-- 1 root root 4096 2008-09-10 10:07 irq
-r--r--r-- 1 root root 4096 2008-09-10 10:07 local_cpulist
-r--r--r-- 1 root root 4096 2008-09-10 10:07 local_cpus
-r--r--r-- 1 root root 4096 2008-09-10 10:07 modalias
-rw-r--r-- 1 root root 4096 2008-09-10 10:07 msi_bus
lrwxrwxrwx 1 root root 0 2008-09-11 23:23 net:eth0 -> ../../../class/net/eth0
drwxr-xr-x 2 root root 0 2008-09-10 10:07 power
-r--r--r-- 1 root root 4096 2008-09-08 14:32 resource
-rw------- 1 root root 131072 2008-09-10 10:07 resource0
-rw------- 1 root root 4096 2008-09-10 10:07 resource1
-rw------- 1 root root 32 2008-09-10 10:07 resource2
lrwxrwxrwx 1 root root 0 2008-09-08 14:32 subsystem -> ../../../bus/pci
-r--r--r-- 1 root root 4096 2008-09-08 14:32 subsystem_device
-r--r--r-- 1 root root 4096 2008-09-08 14:32 subsystem_vendor
-rw-r--r-- 1 root root 4096 2008-09-08 14:32 uevent
-r--r--r-- 1 root root 4096 2008-09-08 14:32 vendor
正如例子中所示,这个特性可以很方便的在处理相同类型的驱动间切换设备,一些商业版的linux发行版会在他们的内核包里面提供多个版本的驱动。这种手动绑定机制可以允许配置工具选择并设置设备与哪一个驱动进行绑定,允许用户只更新他们想要更新的设备驱动。
为了设备可以与一个驱动成功的进行绑定,需要驱动必须支持这个设备。这就是为什么不能将一个随便的设备与一个随便的驱动进行帮定的原因。