First USB sketch.
[cascardo/kernel/slides/.git] / 12dd / dd
1 %Device Driver Model
2 %Thadeu Cascardo
3
4 # Linux 2.6 Device Driver Model
5
6 * Design and Implementation by GregKH
7 * kobjects
8 * sysfs
9
10 # Buses
11
12 * A way to communicate with device
13 * Interface between Linux and hardware
14 * May allow hotplug of devices
15 * Examples:
16         - USB
17         - PCI
18         - I2C
19         - SPI
20         - ACPI
21         - Platform
22 * /sys/bus/
23
24 # Classes
25
26 * A view of the device
27 * Interface between Linux and user space software
28 * The interface may use character devices and/or sysfs or other interfaces
29 * Specific interface classes:
30         - block devices
31         - network devices
32 * Other classes:
33         - tty
34         - video4linux
35         - input
36         - backlight
37         - rtc
38 * /sys/class/
39
40 # Drivers
41
42 * Implement the communication with the hardware, usually through a bus
43 * Present a view of the device, communicating with user space
44 * Basically, links the bus and the class for a given device model (or a family)
45
46 # Device
47
48 * An object representing a device in the bus or a class device
49 * Establishes an hierarchy through the parent link
50 * A class device usually has a device in the bus as its parent
51
52 # API
53
54 # Classes
55
56 * linux/device.h
57 * struct class
58         - name
59         - owner
60         - dev\\_release
61 * class\\_create(owner, name)
62 * class\\_destroy(class)
63 * class\\_register(class)
64 * class\\_unregister(class)
65
66 # Devices
67
68 * struct device
69         - parent
70         - devt
71         - class
72         - release
73
74 # Devices API
75
76 * device\\_initialize(dev)
77 * get\\_device(dev)
78 * put\\_device(dev)
79 * dev\\_set\\_name(dev, fmt, ...)
80 * dev\\_set\\_drvdata(dev, drvdata)
81 * dev\\_get\\_drvdata(dev)
82
83 # Devices API (cont...)
84
85 * device\\_add(dev)
86 * device\\_del(dev)
87 * device\\_register(dev)
88 * device\\_unregister(dev)
89 * device\\_create(class, parent, devt, drvdata, fmt, ...)
90 * device\\_destroy(class, devt)
91
92 # Attributes
93
94 * struct device\\_attribute
95         - attr
96                 * name
97                 * mode
98         - show
99         - store
100 * ssize\\_t show(dev, attr, char *buf)
101 * ssize\\_t store(dev, attr, char *buf, size\\_t count)
102 * sprintf
103 * strict\\_strtol
104 * strnlen
105
106 # Adding attributes
107
108 * class.dev\\_attrs
109 * device\\_create\\_file(dev, attr)
110 * device\\_remove\\_file(dev, attr)
111
112 # devtmpfs
113
114 * class.devnode
115 * char *devnode(dev, mode\\_t *)
116
117 # Power Management
118
119 * linux/pm.h
120 * dev\\_pm\\_ops
121 * resume
122 * suspend
123
124 # Buses and drivers
125
126 * Buses usually implement their API to create bus drivers
127 * The bus API is what should be used most of the time
128
129 # Bus
130
131 * struct bus\\_type
132         - name
133         - match
134         - probe
135         - remove
136 * bus\\_register
137 * bus\\_unregister
138
139 # Drivers
140
141 * struct device\\_driver
142         - name
143         - bus
144         - owner
145         - probe
146         - remove
147 * driver\\_register
148 * driver\\_unregister
149
150 # PCI
151
152 * linux/pci.h
153 * struct pci\\_driver
154         - name
155         - id\\_table
156         - probe
157         - remove
158 * pci\\_register\\_driver(driver)
159 * pci\\_unregister\\_driver(driver)
160
161 # PCI IDs and device matching
162
163 * struct pci\\_device\\_id
164 * DEFINE\\_PCI\\_DEVICE\\_TABLE
165 * PCI\\_DEVICE
166 * PCI\\_DEVICE\\_CLASS
167 * struct pci\\_device\\_id