Linux设备驱动程序:绑定和解开
我遇到了LWN文章 “手动驱动程序绑定和解开” ,它在其中说明了如何使用sysfs
接口来动态绑定和解开Linux中的驱动程序。该接口确切在内核代码中的确切位置?我认为这是在整个内核中共享的。
I came across the LWN article "Manual driver binding and unbinding", where it explains how to use the sysfs
interface to dynamically bind and unbind drivers in Linux. Where exactly in the kernel code is this interface implemented? I assume this is shared across the whole kernel.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您要查找的功能已实现在此处
驱动程序/base/bus.c
。当您写入
/sys/bus/usb/drivers/usb/bind
isbind_store()
时,该功能被调用的功能,该功能从用户空间传递并使用它找到合适的设备。然后检查驱动程序是否在其ID表中声明对设备的支持,如果这样,则将其绑定到设备。同样,代码> 在同一文件中,通过/sys/bus/usb/drivers/usb/unbind
来处理解除限制。您感兴趣的功能可能是:
bus_find_device_by_name()
来自linux/device/bus.h
bus_find_device()
来自linux/device/device/bus.h
device_driver_attach()
来自
linux/device.h
device_release_driver()
来自linux/device.h
您可以查看设备是否通过 ) 。
请注意,
device_driver_detach()
(在drivers/base/base/cod.c
中使用以实现Unbining)未导出,请使用device> device> device_release_driver()
代替。The functionality you are looking for is implemented here in
drivers/base/bus.c
.The function that gets called when you write to
/sys/bus/usb/drivers/usb/bind
isbind_store()
, which gets the string passed from userspace and uses it to find the appropriate device. Then checks if the driver declares support for the device in its id table, and if so it binds it to the device. Similarly,unbind_store()
in the same file handles unbinding through/sys/bus/usb/drivers/usb/unbind
.The functions you are interested in are probably these:
bus_find_device_by_name()
fromlinux/device/bus.h
bus_find_device()
fromlinux/device/bus.h
device_driver_attach()
fromlinux/device.h
device_release_driver()
fromlinux/device.h
You can see if a device matches a specific driver through
driver->bus->match()
.Note that
device_driver_detach()
(used indrivers/base/bus.c
to implement unbinding) is not exported, usedevice_release_driver()
instead.