aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/driver-model/interface.txt
diff options
context:
space:
mode:
Diffstat (limited to 'Documentation/driver-model/interface.txt')
-rw-r--r--Documentation/driver-model/interface.txt129
1 files changed, 129 insertions, 0 deletions
diff --git a/Documentation/driver-model/interface.txt b/Documentation/driver-model/interface.txt
new file mode 100644
index 000000000000..c66912bfe866
--- /dev/null
+++ b/Documentation/driver-model/interface.txt
@@ -0,0 +1,129 @@
1
2Device Interfaces
3
4Introduction
5~~~~~~~~~~~~
6
7Device interfaces are the logical interfaces of device classes that correlate
8directly to userspace interfaces, like device nodes.
9
10Each device class may have multiple interfaces through which you can
11access the same device. An input device may support the mouse interface,
12the 'evdev' interface, and the touchscreen interface. A SCSI disk would
13support the disk interface, the SCSI generic interface, and possibly a raw
14device interface.
15
16Device interfaces are registered with the class they belong to. As devices
17are added to the class, they are added to each interface registered with
18the class. The interface is responsible for determining whether the device
19supports the interface or not.
20
21
22Programming Interface
23~~~~~~~~~~~~~~~~~~~~~
24
25struct device_interface {
26 char * name;
27 rwlock_t lock;
28 u32 devnum;
29 struct device_class * devclass;
30
31 struct list_head node;
32 struct driver_dir_entry dir;
33
34 int (*add_device)(struct device *);
35 int (*add_device)(struct intf_data *);
36};
37
38int interface_register(struct device_interface *);
39void interface_unregister(struct device_interface *);
40
41
42An interface must specify the device class it belongs to. It is added
43to that class's list of interfaces on registration.
44
45
46Interfaces can be added to a device class at any time. Whenever it is
47added, each device in the class is passed to the interface's
48add_device callback. When an interface is removed, each device is
49removed from the interface.
50
51
52Devices
53~~~~~~~
54Once a device is added to a device class, it is added to each
55interface that is registered with the device class. The class
56is expected to place a class-specific data structure in
57struct device::class_data. The interface can use that (along with
58other fields of struct device) to determine whether or not the driver
59and/or device support that particular interface.
60
61
62Data
63~~~~
64
65struct intf_data {
66 struct list_head node;
67 struct device_interface * intf;
68 struct device * dev;
69 u32 intf_num;
70};
71
72int interface_add_data(struct interface_data *);
73
74The interface is responsible for allocating and initializing a struct
75intf_data and calling interface_add_data() to add it to the device's list
76of interfaces it belongs to. This list will be iterated over when the device
77is removed from the class (instead of all possible interfaces for a class).
78This structure should probably be embedded in whatever per-device data
79structure the interface is allocating anyway.
80
81Devices are enumerated within the interface. This happens in interface_add_data()
82and the enumerated value is stored in the struct intf_data for that device.
83
84sysfs
85~~~~~
86Each interface is given a directory in the directory of the device
87class it belongs to:
88
89Interfaces get a directory in the class's directory as well:
90
91 class/
92 `-- input
93 |-- devices
94 |-- drivers
95 |-- mouse
96 `-- evdev
97
98When a device is added to the interface, a symlink is created that points
99to the device's directory in the physical hierarchy:
100
101 class/
102 `-- input
103 |-- devices
104 | `-- 1 -> ../../../root/pci0/00:1f.0/usb_bus/00:1f.2-1:0/
105 |-- drivers
106 | `-- usb:usb_mouse -> ../../../bus/drivers/usb_mouse/
107 |-- mouse
108 | `-- 1 -> ../../../root/pci0/00:1f.0/usb_bus/00:1f.2-1:0/
109 `-- evdev
110 `-- 1 -> ../../../root/pci0/00:1f.0/usb_bus/00:1f.2-1:0/
111
112
113Future Plans
114~~~~~~~~~~~~
115A device interface is correlated directly with a userspace interface
116for a device, specifically a device node. For instance, a SCSI disk
117exposes at least two interfaces to userspace: the standard SCSI disk
118interface and the SCSI generic interface. It might also export a raw
119device interface.
120
121Many interfaces have a major number associated with them and each
122device gets a minor number. Or, multiple interfaces might share one
123major number, and each will receive a range of minor numbers (like in
124the case of input devices).
125
126These major and minor numbers could be stored in the interface
127structure. Major and minor allocations could happen when the interface
128is registered with the class, or via a helper function.
129