~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/Documentation/driver-api/driver-model/binding.rst

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 ==============
  2 Driver Binding
  3 ==============
  4 
  5 Driver binding is the process of associating a device with a device
  6 driver that can control it. Bus drivers have typically handled this
  7 because there have been bus-specific structures to represent the
  8 devices and the drivers. With generic device and device driver
  9 structures, most of the binding can take place using common code.
 10 
 11 
 12 Bus
 13 ~~~
 14 
 15 The bus type structure contains a list of all devices that are on that bus
 16 type in the system. When device_register is called for a device, it is
 17 inserted into the end of this list. The bus object also contains a
 18 list of all drivers of that bus type. When driver_register is called
 19 for a driver, it is inserted at the end of this list. These are the
 20 two events which trigger driver binding.
 21 
 22 
 23 device_register
 24 ~~~~~~~~~~~~~~~
 25 
 26 When a new device is added, the bus's list of drivers is iterated over
 27 to find one that supports it. In order to determine that, the device
 28 ID of the device must match one of the device IDs that the driver
 29 supports. The format and semantics for comparing IDs is bus-specific.
 30 Instead of trying to derive a complex state machine and matching
 31 algorithm, it is up to the bus driver to provide a callback to compare
 32 a device against the IDs of a driver. The bus returns 1 if a match was
 33 found; 0 otherwise.
 34 
 35 int match(struct device * dev, struct device_driver * drv);
 36 
 37 If a match is found, the device's driver field is set to the driver
 38 and the driver's probe callback is called. This gives the driver a
 39 chance to verify that it really does support the hardware, and that
 40 it's in a working state.
 41 
 42 Device Class
 43 ~~~~~~~~~~~~
 44 
 45 Upon the successful completion of probe, the device is registered with
 46 the class to which it belongs. Device drivers belong to one and only one
 47 class, and that is set in the driver's devclass field.
 48 devclass_add_device is called to enumerate the device within the class
 49 and actually register it with the class, which happens with the
 50 class's register_dev callback.
 51 
 52 
 53 Driver
 54 ~~~~~~
 55 
 56 When a driver is attached to a device, the device is inserted into the
 57 driver's list of devices.
 58 
 59 
 60 sysfs
 61 ~~~~~
 62 
 63 A symlink is created in the bus's 'devices' directory that points to
 64 the device's directory in the physical hierarchy.
 65 
 66 A symlink is created in the driver's 'devices' directory that points
 67 to the device's directory in the physical hierarchy.
 68 
 69 A directory for the device is created in the class's directory. A
 70 symlink is created in that directory that points to the device's
 71 physical location in the sysfs tree.
 72 
 73 A symlink can be created (though this isn't done yet) in the device's
 74 physical directory to either its class directory, or the class's
 75 top-level directory. One can also be created to point to its driver's
 76 directory also.
 77 
 78 
 79 driver_register
 80 ~~~~~~~~~~~~~~~
 81 
 82 The process is almost identical for when a new driver is added.
 83 The bus's list of devices is iterated over to find a match. Devices
 84 that already have a driver are skipped. All the devices are iterated
 85 over, to bind as many devices as possible to the driver.
 86 
 87 
 88 Removal
 89 ~~~~~~~
 90 
 91 When a device is removed, the reference count for it will eventually
 92 go to 0. When it does, the remove callback of the driver is called. It
 93 is removed from the driver's list of devices and the reference count
 94 of the driver is decremented. All symlinks between the two are removed.
 95 
 96 When a driver is removed, the list of devices that it supports is
 97 iterated over, and the driver's remove callback is called for each
 98 one. The device is removed from that list and the symlinks removed.

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php