7 Device interfaces are the logical interfaces of device classes that correlate
8 directly to userspace interfaces, like device nodes.
10 Each device class may have multiple interfaces through which you can
11 access the same device. An input device may support the mouse interface,
12 the 'evdev' interface, and the touchscreen interface. A SCSI disk would
13 support the disk interface, the SCSI generic interface, and possibly a raw
16 Device interfaces are registered with the class they belong to. As devices
17 are added to the class, they are added to each interface registered with
18 the class. The interface is responsible for determining whether the device
19 supports the interface or not.
25 struct device_interface {
29 struct device_class * devclass;
31 struct list_head node;
32 struct driver_dir_entry dir;
34 int (*add_device)(struct device *);
35 int (*add_device)(struct intf_data *);
38 int interface_register(struct device_interface *);
39 void interface_unregister(struct device_interface *);
42 An interface must specify the device class it belongs to. It is added
43 to that class's list of interfaces on registration.
46 Interfaces can be added to a device class at any time. Whenever it is
47 added, each device in the class is passed to the interface's
48 add_device callback. When an interface is removed, each device is
49 removed from the interface.
54 Once a device is added to a device class, it is added to each
55 interface that is registered with the device class. The class
56 is expected to place a class-specific data structure in
57 struct device::class_data. The interface can use that (along with
58 other fields of struct device) to determine whether or not the driver
59 and/or device support that particular interface.
66 struct list_head node;
67 struct device_interface * intf;
72 int interface_add_data(struct interface_data *);
74 The interface is responsible for allocating and initializing a struct
75 intf_data and calling interface_add_data() to add it to the device's list
76 of interfaces it belongs to. This list will be iterated over when the device
77 is removed from the class (instead of all possible interfaces for a class).
78 This structure should probably be embedded in whatever per-device data
79 structure the interface is allocating anyway.
81 Devices are enumerated within the interface. This happens in interface_add_data()
82 and the enumerated value is stored in the struct intf_data for that device.
86 Each interface is given a directory in the directory of the device
89 Interfaces get a directory in the class's directory as well:
98 When a device is added to the interface, a symlink is created that points
99 to the device's directory in the physical hierarchy:
104 | `-- 1 -> ../../../root/pci0/00:1f.0/usb_bus/00:1f.2-1:0/
106 | `-- usb:usb_mouse -> ../../../bus/drivers/usb_mouse/
108 | `-- 1 -> ../../../root/pci0/00:1f.0/usb_bus/00:1f.2-1:0/
110 `-- 1 -> ../../../root/pci0/00:1f.0/usb_bus/00:1f.2-1:0/
115 A device interface is correlated directly with a userspace interface
116 for a device, specifically a device node. For instance, a SCSI disk
117 exposes at least two interfaces to userspace: the standard SCSI disk
118 interface and the SCSI generic interface. It might also export a raw
121 Many interfaces have a major number associated with them and each
122 device gets a minor number. Or, multiple interfaces might share one
123 major number, and each will receive a range of minor numbers (like in
124 the case of input devices).
126 These major and minor numbers could be stored in the interface
127 structure. Major and minor allocations could happen when the interface
128 is registered with the class, or via a helper function.