⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 binding.txt

📁 linux 内核源代码
💻 TXT
字号:
Driver BindingDriver binding is the process of associating a device with a devicedriver that can control it. Bus drivers have typically handled thisbecause there have been bus-specific structures to represent thedevices and the drivers. With generic device and device driverstructures, most of the binding can take place using common code.Bus~~~The bus type structure contains a list of all devices that are on that bustype in the system. When device_register is called for a device, it isinserted into the end of this list. The bus object also contains alist of all drivers of that bus type. When driver_register is calledfor a driver, it is inserted at the end of this list. These are thetwo events which trigger driver binding.device_register~~~~~~~~~~~~~~~When a new device is added, the bus's list of drivers is iterated overto find one that supports it. In order to determine that, the deviceID of the device must match one of the device IDs that the driversupports. The format and semantics for comparing IDs is bus-specific. Instead of trying to derive a complex state machine and matchingalgorithm, it is up to the bus driver to provide a callback to comparea device against the IDs of a driver. The bus returns 1 if a match wasfound; 0 otherwise.int match(struct device * dev, struct device_driver * drv);If a match is found, the device's driver field is set to the driverand the driver's probe callback is called. This gives the driver achance to verify that it really does support the hardware, and thatit's in a working state. Device Class~~~~~~~~~~~~Upon the successful completion of probe, the device is registered withthe class to which it belongs. Device drivers belong to one and only oneclass, and that is set in the driver's devclass field. devclass_add_device is called to enumerate the device within the classand actually register it with the class, which happens with theclass's register_dev callback.NOTE: The device class structures and core routines to manipulate themare not in the mainline kernel, so the discussion is still a bitspeculative. Driver~~~~~~When a driver is attached to a device, the device is inserted into thedriver's list of devices. sysfs~~~~~A symlink is created in the bus's 'devices' directory that points tothe device's directory in the physical hierarchy.A symlink is created in the driver's 'devices' directory that pointsto the device's directory in the physical hierarchy.A directory for the device is created in the class's directory. Asymlink is created in that directory that points to the device'sphysical location in the sysfs tree. A symlink can be created (though this isn't done yet) in the device'sphysical directory to either its class directory, or the class'stop-level directory. One can also be created to point to its driver'sdirectory also. driver_register~~~~~~~~~~~~~~~The process is almost identical for when a new driver is added. The bus's list of devices is iterated over to find a match. Devicesthat already have a driver are skipped. All the devices are iteratedover, to bind as many devices as possible to the driver.Removal~~~~~~~When a device is removed, the reference count for it will eventuallygo to 0. When it does, the remove callback of the driver is called. Itis removed from the driver's list of devices and the reference countof the driver is decremented. All symlinks between the two are removed.When a driver is removed, the list of devices that it supports isiterated over, and the driver's remove callback is called for eachone. The device is removed from that list and the symlinks removed. 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -