| @@ -1,373 +1,365 @@ | | | @@ -1,373 +1,365 @@ |
1 | .\" $NetBSD: driver.9,v 1.32 2017/11/17 07:42:29 wiz Exp $ | | 1 | .\" $NetBSD: driver.9,v 1.33 2022/02/11 23:19:34 riastradh Exp $ |
2 | .\" | | 2 | .\" |
3 | .\" Copyright (c) 2001 The NetBSD Foundation, Inc. | | 3 | .\" Copyright (c) 2001 The NetBSD Foundation, Inc. |
4 | .\" All rights reserved. | | 4 | .\" All rights reserved. |
5 | .\" | | 5 | .\" |
6 | .\" This code is derived from software contributed to The NetBSD Foundation | | 6 | .\" This code is derived from software contributed to The NetBSD Foundation |
7 | .\" by Gregory McGarry. | | 7 | .\" by Gregory McGarry. |
8 | .\" | | 8 | .\" |
9 | .\" Redistribution and use in source and binary forms, with or without | | 9 | .\" Redistribution and use in source and binary forms, with or without |
10 | .\" modification, are permitted provided that the following conditions | | 10 | .\" modification, are permitted provided that the following conditions |
11 | .\" are met: | | 11 | .\" are met: |
12 | .\" 1. Redistributions of source code must retain the above copyright | | 12 | .\" 1. Redistributions of source code must retain the above copyright |
13 | .\" notice, this list of conditions and the following disclaimer. | | 13 | .\" notice, this list of conditions and the following disclaimer. |
14 | .\" 2. Redistributions in binary form must reproduce the above copyright | | 14 | .\" 2. Redistributions in binary form must reproduce the above copyright |
15 | .\" notice, this list of conditions and the following disclaimer in the | | 15 | .\" notice, this list of conditions and the following disclaimer in the |
16 | .\" documentation and/or other materials provided with the distribution. | | 16 | .\" documentation and/or other materials provided with the distribution. |
17 | .\" | | 17 | .\" |
18 | .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | | 18 | .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS |
19 | .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 19 | .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
20 | .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 20 | .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
21 | .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 21 | .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
22 | .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 22 | .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
23 | .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 23 | .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
24 | .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 24 | .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
25 | .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 25 | .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
26 | .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 26 | .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
27 | .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 27 | .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
28 | .\" POSSIBILITY OF SUCH DAMAGE. | | 28 | .\" POSSIBILITY OF SUCH DAMAGE. |
29 | .\" | | 29 | .\" |
30 | .Dd April 30, 2017 | | 30 | .Dd April 30, 2017 |
31 | .Dt DRIVER 9 | | 31 | .Dt DRIVER 9 |
32 | .Os | | 32 | .Os |
33 | .Sh NAME | | 33 | .Sh NAME |
34 | .Nm driver | | 34 | .Nm driver |
35 | .Nd description of a device driver | | 35 | .Nd description of a device driver |
36 | .Sh SYNOPSIS | | 36 | .Sh SYNOPSIS |
37 | .In sys/param.h | | 37 | .In sys/param.h |
38 | .In sys/device.h | | 38 | .In sys/device.h |
39 | .In sys/errno.h | | 39 | .In sys/errno.h |
40 | .Ft static int | | 40 | .Ft static int |
41 | .Fn foo_match "device_t parent" "cfdata_t match" "void *aux" | | 41 | .Fn foo_match "device_t parent" "cfdata_t match" "void *aux" |
42 | .Ft static void | | 42 | .Ft static void |
43 | .Fn foo_attach "device_t parent" "device_t self" "void *aux" | | 43 | .Fn foo_attach "device_t parent" "device_t self" "void *aux" |
44 | .Ft static int | | 44 | .Ft static int |
45 | .Fn foo_detach "device_t self" "int flags" | | 45 | .Fn foo_detach "device_t self" "int flags" |
46 | .Ft static int | | 46 | .Ft static int |
47 | .Fn foo_activate "device_t self" "enum devact act" | | 47 | .Fn foo_activate "device_t self" "enum devact act" |
48 | .Sh DESCRIPTION | | 48 | .Sh DESCRIPTION |
49 | This page briefly describes the basic | | 49 | This page briefly describes the basic |
50 | .Nx | | 50 | .Nx |
51 | autoconfiguration interface used by device drivers. | | 51 | autoconfiguration interface used by device drivers. |
52 | For a detailed overview of the autoconfiguration framework see | | 52 | For a detailed overview of the autoconfiguration framework see |
53 | .Xr autoconf 9 . | | 53 | .Xr autoconf 9 . |
54 | .Pp | | 54 | .Pp |
55 | Each device driver must present to the system a standard | | 55 | Each device driver must present to the system a standard |
56 | autoconfiguration interface. | | 56 | autoconfiguration interface. |
57 | This interface is provided by the | | 57 | This interface is provided by the |
58 | .Em cfattach | | 58 | .Em cfattach |
59 | structure. | | 59 | structure. |
60 | The interface to the driver is constant and is defined | | 60 | The interface to the driver is constant and is defined |
61 | statically inside the driver. | | 61 | statically inside the driver. |
62 | For example, the interface to driver | | 62 | For example, the interface to driver |
63 | .Dq foo | | 63 | .Dq foo |
64 | is defined with: | | 64 | is defined with: |
65 | .Bd -literal | | 65 | .Bd -literal |
66 | CFATTACH_DECL_NEW(foo, /* driver name */ | | 66 | CFATTACH_DECL_NEW(foo, /* driver name */ |
67 | sizeof(struct foo_softc), /* size of instance data */ | | 67 | sizeof(struct foo_softc), /* size of instance data */ |
68 | foo_match, /* match/probe function */ | | 68 | foo_match, /* match/probe function */ |
69 | foo_attach, /* attach function */ | | 69 | foo_attach, /* attach function */ |
70 | foo_detach, /* detach function */ | | 70 | foo_detach, /* detach function */ |
71 | foo_activate); /* activate function */ | | 71 | foo_activate); /* activate function */ |
72 | .Ed | | 72 | .Ed |
73 | .Pp | | 73 | .Pp |
74 | For each device instance controlled by the driver, the | | 74 | For each device instance controlled by the driver, the |
75 | autoconfiguration framework allocates a block of memory to record | | 75 | autoconfiguration framework allocates a block of memory to record |
76 | device-instance-specific driver variables. | | 76 | device-instance-specific driver variables. |
77 | The size of this memory block is specified by the second argument in the | | 77 | The size of this memory block is specified by the second argument in the |
78 | .Em CFATTACH_DECL | | 78 | .Em CFATTACH_DECL |
79 | macro. | | 79 | macro. |
80 | The memory block is referred to as the driver's | | 80 | The memory block is referred to as the driver's |
81 | .Em softc | | 81 | .Em softc |
82 | structure. | | 82 | structure. |
83 | The | | 83 | The |
84 | .Em softc | | 84 | .Em softc |
85 | structure is only accessed within the driver, so its definition is | | 85 | structure is only accessed within the driver, so its definition is |
86 | local to the driver. | | 86 | local to the driver. |
87 | Nevertheless, the | | 87 | Nevertheless, the |
88 | .Em softc | | 88 | .Em softc |
89 | structure should adopt the standard | | 89 | structure should adopt the standard |
90 | .Nx | | 90 | .Nx |
91 | configuration and naming conventions. | | 91 | configuration and naming conventions. |
92 | For example, the | | 92 | For example, the |
93 | .Em softc | | 93 | .Em softc |
94 | structure for driver | | 94 | structure for driver |
95 | .Dq foo | | 95 | .Dq foo |
96 | is defined with: | | 96 | is defined with: |
97 | .Bd -literal | | 97 | .Bd -literal |
98 | struct foo_softc { | | 98 | struct foo_softc { |
99 | device_t sc_dev; /* generic device info */ | | 99 | device_t sc_dev; /* generic device info */ |
100 | /* device-specific state */ | | 100 | /* device-specific state */ |
101 | }; | | 101 | }; |
102 | .Ed | | 102 | .Ed |
103 | .Pp | | 103 | .Pp |
104 | The autoconfiguration framework mandates that the first member of the | | | |
105 | .Em softc | | | |
106 | structure must be the driver-independent | | | |
107 | .Em device_t . | | | |
108 | Probably its most useful aspect to the driver is that it contains the | | | |
109 | device-instance name | | | |
110 | .Em dv_xname . | | | |
111 | .Pp | | | |
112 | If a driver has character device interfaces accessed from userland, the driver | | 104 | If a driver has character device interfaces accessed from userland, the driver |
113 | must define the | | 105 | must define the |
114 | .Em cdevsw | | 106 | .Em cdevsw |
115 | structure. | | 107 | structure. |
116 | The structure is constant and is defined inside the driver. | | 108 | The structure is constant and is defined inside the driver. |
117 | For example, the | | 109 | For example, the |
118 | .Em cdevsw | | 110 | .Em cdevsw |
119 | structure for driver | | 111 | structure for driver |
120 | .Dq foo | | 112 | .Dq foo |
121 | is defined with: | | 113 | is defined with: |
122 | .Bd -literal | | 114 | .Bd -literal |
123 | const struct cdevsw foo_cdevsw { | | 115 | const struct cdevsw foo_cdevsw { |
124 | int (*d_open)(dev_t, int, int, struct lwp *); | | 116 | int (*d_open)(dev_t, int, int, struct lwp *); |
125 | int (*d_close)(dev_t, int, int, struct lwp *); | | 117 | int (*d_close)(dev_t, int, int, struct lwp *); |
126 | int (*d_read)(dev_t, struct uio *, int); | | 118 | int (*d_read)(dev_t, struct uio *, int); |
127 | int (*d_write)(dev_t, struct uio *, int); | | 119 | int (*d_write)(dev_t, struct uio *, int); |
128 | int (*d_ioctl)(dev_t, u_long, void *, int, struct lwp *); | | 120 | int (*d_ioctl)(dev_t, u_long, void *, int, struct lwp *); |
129 | void (*d_stop)(struct tty *, int); | | 121 | void (*d_stop)(struct tty *, int); |
130 | struct tty *(*d_tty)(dev_t); | | 122 | struct tty *(*d_tty)(dev_t); |
131 | int (*d_poll)(dev_t, int, struct lwp *); | | 123 | int (*d_poll)(dev_t, int, struct lwp *); |
132 | paddr_t (*d_mmap)(dev_t, off_t, int); | | 124 | paddr_t (*d_mmap)(dev_t, off_t, int); |
133 | int (*d_kqfilter)(dev_t, struct knote *); | | 125 | int (*d_kqfilter)(dev_t, struct knote *); |
134 | int d_flag; | | 126 | int d_flag; |
135 | }; | | 127 | }; |
136 | .Ed | | 128 | .Ed |
137 | .Pp | | 129 | .Pp |
138 | The structure variable must be named foo_cdevsw by appending the letters | | 130 | The structure variable must be named foo_cdevsw by appending the letters |
139 | .Dq _cdevsw | | 131 | .Dq _cdevsw |
140 | to the driver's base name. | | 132 | to the driver's base name. |
141 | This convention is mandated by the autoconfiguration framework. | | 133 | This convention is mandated by the autoconfiguration framework. |
142 | .Pp | | 134 | .Pp |
143 | If the driver | | 135 | If the driver |
144 | .Dq foo | | 136 | .Dq foo |
145 | has also block device interfaces, the driver must define the | | 137 | has also block device interfaces, the driver must define the |
146 | .Em bdevsw | | 138 | .Em bdevsw |
147 | structure. | | 139 | structure. |
148 | The structure is constant and is defined inside the driver. | | 140 | The structure is constant and is defined inside the driver. |
149 | For example, the | | 141 | For example, the |
150 | .Em bdevsw | | 142 | .Em bdevsw |
151 | structure for driver | | 143 | structure for driver |
152 | .Dq foo | | 144 | .Dq foo |
153 | is defined with: | | 145 | is defined with: |
154 | .Bd -literal | | 146 | .Bd -literal |
155 | const struct bdevsw foo_bdevsw { | | 147 | const struct bdevsw foo_bdevsw { |
156 | int (*d_open)(dev_t, int, int, struct lwp *); | | 148 | int (*d_open)(dev_t, int, int, struct lwp *); |
157 | int (*d_close)(dev_t, int, int, struct lwp *); | | 149 | int (*d_close)(dev_t, int, int, struct lwp *); |
158 | void (*d_strategy)(struct buf *); | | 150 | void (*d_strategy)(struct buf *); |
159 | int (*d_ioctl)(dev_t, u_long, void *, int, struct lwp *); | | 151 | int (*d_ioctl)(dev_t, u_long, void *, int, struct lwp *); |
160 | int (*d_dump)(dev_t, daddr_t, void *, size_t); | | 152 | int (*d_dump)(dev_t, daddr_t, void *, size_t); |
161 | int (*d_psize)(dev_t); | | 153 | int (*d_psize)(dev_t); |
162 | int d_flag; | | 154 | int d_flag; |
163 | }; | | 155 | }; |
164 | .Ed | | 156 | .Ed |
165 | .Pp | | 157 | .Pp |
166 | The structure variable must be named foo_bdevsw by appending the letters | | 158 | The structure variable must be named foo_bdevsw by appending the letters |
167 | .Dq _bdevsw | | 159 | .Dq _bdevsw |
168 | to the driver's base name. | | 160 | to the driver's base name. |
169 | This convention is mandated by the autoconfiguration framework. | | 161 | This convention is mandated by the autoconfiguration framework. |
170 | .Pp | | 162 | .Pp |
171 | During system bootstrap, the autoconfiguration framework searches the | | 163 | During system bootstrap, the autoconfiguration framework searches the |
172 | system for devices. | | 164 | system for devices. |
173 | For each device driver, its match function is called (via its | | 165 | For each device driver, its match function is called (via its |
174 | .Em cfattach | | 166 | .Em cfattach |
175 | structure) to match the driver with a device instance. | | 167 | structure) to match the driver with a device instance. |
176 | The match function is called with three arguments. | | 168 | The match function is called with three arguments. |
177 | This first argument | | 169 | This first argument |
178 | .Fa parent | | 170 | .Fa parent |
179 | is a pointer to the driver's parent device structure. | | 171 | is a pointer to the driver's parent device structure. |
180 | The second argument | | 172 | The second argument |
181 | .Fa match | | 173 | .Fa match |
182 | is a pointer to a data structure describing the autoconfiguration | | 174 | is a pointer to a data structure describing the autoconfiguration |
183 | framework's understanding of the driver. | | 175 | framework's understanding of the driver. |
184 | Both the | | 176 | Both the |
185 | .Fa parent | | 177 | .Fa parent |
186 | and | | 178 | and |
187 | .Fa match | | 179 | .Fa match |
188 | arguments are ignored by most drivers. | | 180 | arguments are ignored by most drivers. |
189 | The third argument | | 181 | The third argument |
190 | .Fa aux | | 182 | .Fa aux |
191 | contains a pointer to a structure describing a potential | | 183 | contains a pointer to a structure describing a potential |
192 | device-instance. | | 184 | device-instance. |
193 | It is passed to the driver from the parent. | | 185 | It is passed to the driver from the parent. |
194 | The match function would type-cast the | | 186 | The match function would type-cast the |
195 | .Fa aux | | 187 | .Fa aux |
196 | argument to its appropriate attachment structure and use its contents | | 188 | argument to its appropriate attachment structure and use its contents |
197 | to determine whether it supports the device. | | 189 | to determine whether it supports the device. |
198 | Depending on the device hardware, the contents of the attachment | | 190 | Depending on the device hardware, the contents of the attachment |
199 | structure may contain | | 191 | structure may contain |
200 | .Dq locators | | 192 | .Dq locators |
201 | to locate the device instance so that the driver can probe it for its | | 193 | to locate the device instance so that the driver can probe it for its |
202 | identity. | | 194 | identity. |
203 | If the probe process identifies additional device properties, it may | | 195 | If the probe process identifies additional device properties, it may |
204 | modify the members of the attachment structure. | | 196 | modify the members of the attachment structure. |
205 | For these devices, the | | 197 | For these devices, the |
206 | .Nx | | 198 | .Nx |
207 | convention is to | | 199 | convention is to |
208 | call the match routine | | 200 | call the match routine |
209 | .Fn foo_probe | | 201 | .Fn foo_probe |
210 | instead of | | 202 | instead of |
211 | .Fn foo_match | | 203 | .Fn foo_match |
212 | to make this distinction clear. | | 204 | to make this distinction clear. |
213 | Either way, the match function returns a nonzero integer indicating the | | 205 | Either way, the match function returns a nonzero integer indicating the |
214 | confidence of supporting this device and a value of 0 if the driver | | 206 | confidence of supporting this device and a value of 0 if the driver |
215 | doesn't support the device. | | 207 | doesn't support the device. |
216 | Generally, only a single driver exists for a device, so the match | | 208 | Generally, only a single driver exists for a device, so the match |
217 | function returns 1 for a positive match. | | 209 | function returns 1 for a positive match. |
218 | .Pp | | 210 | .Pp |
219 | The autoconfiguration framework will call the attach function | | 211 | The autoconfiguration framework will call the attach function |
220 | (via its | | 212 | (via its |
221 | .Em cfattach | | 213 | .Em cfattach |
222 | structure) | | 214 | structure) |
223 | of the driver which returns the highest value from its match function. | | 215 | of the driver which returns the highest value from its match function. |
224 | The attach function is called with three arguments. | | 216 | The attach function is called with three arguments. |
225 | The attach function performs the necessary process to initialise the | | 217 | The attach function performs the necessary process to initialise the |
226 | device for operation. | | 218 | device for operation. |
227 | The first argument | | 219 | The first argument |
228 | .Fa parent | | 220 | .Fa parent |
229 | is a pointer to the driver's parent device structure. | | 221 | is a pointer to the driver's parent device structure. |
230 | The second argument | | 222 | The second argument |
231 | .Fa self | | 223 | .Fa self |
232 | is a pointer to the driver's device structure. | | 224 | is a pointer to the driver's device structure. |
233 | The device's | | 225 | The device's |
234 | .Em softc | | 226 | .Em softc |
235 | structure can be obtained from it using the | | 227 | structure can be obtained from it using the |
236 | .Fn device_private | | 228 | .Fn device_private |
237 | function (see | | 229 | function (see |
238 | .Xr disk 9 ) . | | 230 | .Xr disk 9 ) . |
239 | The third argument | | 231 | The third argument |
240 | .Fa aux | | 232 | .Fa aux |
241 | is a pointer to the attachment structure. | | 233 | is a pointer to the attachment structure. |
242 | The | | 234 | The |
243 | .Fa parent | | 235 | .Fa parent |
244 | and | | 236 | and |
245 | .Fa aux | | 237 | .Fa aux |
246 | arguments are the same as passed to the match function. | | 238 | arguments are the same as passed to the match function. |
247 | .Pp | | 239 | .Pp |
248 | The driver's attach function is called before system interrupts are | | 240 | The driver's attach function is called before system interrupts are |
249 | enabled. | | 241 | enabled. |
250 | If interrupts are required during initialisation, then the attach | | 242 | If interrupts are required during initialisation, then the attach |
251 | function should make use of | | 243 | function should make use of |
252 | .Fn config_interrupts | | 244 | .Fn config_interrupts |
253 | (see | | 245 | (see |
254 | .Xr autoconf 9 ) . | | 246 | .Xr autoconf 9 ) . |
255 | .Pp | | 247 | .Pp |
256 | Some devices can be removed from the system without requiring a system | | 248 | Some devices can be removed from the system without requiring a system |
257 | reboot. | | 249 | reboot. |
258 | The autoconfiguration framework calls the driver's detach function | | 250 | The autoconfiguration framework calls the driver's detach function |
259 | (via its | | 251 | (via its |
260 | .Em cfattach | | 252 | .Em cfattach |
261 | structure) during device detachment. | | 253 | structure) during device detachment. |
262 | If the device does not support detachment, then the driver does not | | 254 | If the device does not support detachment, then the driver does not |
263 | have to provide a detach function. | | 255 | have to provide a detach function. |
264 | The detach function is used to relinquish resources allocated to the | | 256 | The detach function is used to relinquish resources allocated to the |
265 | driver which are no longer needed. | | 257 | driver which are no longer needed. |
266 | The first argument | | 258 | The first argument |
267 | .Fa self | | 259 | .Fa self |
268 | is a pointer to the driver's device structure. | | 260 | is a pointer to the driver's device structure. |
269 | It is the same structure as passed to the attach function. | | 261 | It is the same structure as passed to the attach function. |
270 | The second argument | | 262 | The second argument |
271 | .Fa flags | | 263 | .Fa flags |
272 | contains detachment flags. | | 264 | contains detachment flags. |
273 | Valid values are | | 265 | Valid values are |
274 | .Dv DETACH_FORCE | | 266 | .Dv DETACH_FORCE |
275 | (force detachment; hardware gone) and | | 267 | (force detachment; hardware gone) and |
276 | .Dv DETACH_QUIET | | 268 | .Dv DETACH_QUIET |
277 | (do not print a notice). | | 269 | (do not print a notice). |
278 | .Pp | | 270 | .Pp |
279 | The autoconfiguration framework may call the driver's activate function | | 271 | The autoconfiguration framework may call the driver's activate function |
280 | to notify the driver of a change in the resources that have been | | 272 | to notify the driver of a change in the resources that have been |
281 | allocated to it. | | 273 | allocated to it. |
282 | For example, an Ethernet driver has to be notified if the network stack | | 274 | For example, an Ethernet driver has to be notified if the network stack |
283 | is being added or removed from the kernel. | | 275 | is being added or removed from the kernel. |
284 | The first argument to the activate function | | 276 | The first argument to the activate function |
285 | .Fa self | | 277 | .Fa self |
286 | is a pointer to the driver's device structure. | | 278 | is a pointer to the driver's device structure. |
287 | It is the same argument as passed to the attach function. | | 279 | It is the same argument as passed to the attach function. |
288 | The second argument | | 280 | The second argument |
289 | .Fa act | | 281 | .Fa act |
290 | describes the action. | | 282 | describes the action. |
291 | Valid actions are | | 283 | Valid actions are |
292 | .Dv DVACT_ACTIVATE | | 284 | .Dv DVACT_ACTIVATE |
293 | (activate the device) and | | 285 | (activate the device) and |
294 | .Dv DVACT_DEACTIVATE | | 286 | .Dv DVACT_DEACTIVATE |
295 | (deactivate the device). | | 287 | (deactivate the device). |
296 | If the action is not supported the activate function should return | | 288 | If the action is not supported the activate function should return |
297 | .Er EOPNOTSUPP . | | 289 | .Er EOPNOTSUPP . |
298 | The | | 290 | The |
299 | .Dv DVACT_DEACTIVATE | | 291 | .Dv DVACT_DEACTIVATE |
300 | call will only be made if the | | 292 | call will only be made if the |
301 | .Dv DVACT_ACTIVATE | | 293 | .Dv DVACT_ACTIVATE |
302 | call was successful. | | 294 | call was successful. |
303 | The activate function is called in interrupt context. | | 295 | The activate function is called in interrupt context. |
304 | .Pp | | 296 | .Pp |
305 | Most drivers will want to make use of interrupt facilities. | | 297 | Most drivers will want to make use of interrupt facilities. |
306 | Interrupt locators provided through the attachment structure should be | | 298 | Interrupt locators provided through the attachment structure should be |
307 | used to establish interrupts within the system. | | 299 | used to establish interrupts within the system. |
308 | Generally, an interrupt interface is provided by the parent. | | 300 | Generally, an interrupt interface is provided by the parent. |
309 | The interface will require a handler and a driver-specific argument | | 301 | The interface will require a handler and a driver-specific argument |
310 | to be specified. | | 302 | to be specified. |
311 | This argument is usually a pointer to the device-instance-specific | | 303 | This argument is usually a pointer to the device-instance-specific |
312 | softc structure. | | 304 | softc structure. |
313 | When a hardware interrupt for the device occurs the handler is called | | 305 | When a hardware interrupt for the device occurs the handler is called |
314 | with the argument. | | 306 | with the argument. |
315 | Interrupt handlers should return 0 for | | 307 | Interrupt handlers should return 0 for |
316 | .Dq interrupt not for me , | | 308 | .Dq interrupt not for me , |
317 | 1 for | | 309 | 1 for |
318 | .Dq I took care of it , | | 310 | .Dq I took care of it , |
319 | or -1 for | | 311 | or -1 for |
320 | .Do | | 312 | .Do |
321 | I guess it was mine, but I wasn't expecting it | | 313 | I guess it was mine, but I wasn't expecting it |
322 | .Dc . | | 314 | .Dc . |
323 | .Pp | | 315 | .Pp |
324 | For a driver to be compiled into the kernel, | | 316 | For a driver to be compiled into the kernel, |
325 | .Xr config 1 | | 317 | .Xr config 1 |
326 | must be aware of its existence. | | 318 | must be aware of its existence. |
327 | This is done by including an entry in files.<bus> in the | | 319 | This is done by including an entry in files.<bus> in the |
328 | directory containing the driver. | | 320 | directory containing the driver. |
329 | For example, the driver | | 321 | For example, the driver |
330 | .Dq foo | | 322 | .Dq foo |
331 | attaching to bus | | 323 | attaching to bus |
332 | .Dq bar | | 324 | .Dq bar |
333 | with dependency on kernel module | | 325 | with dependency on kernel module |
334 | .Dq baz | | 326 | .Dq baz |
335 | has the entry: | | 327 | has the entry: |
336 | .Bd -literal | | 328 | .Bd -literal |
337 | device foo: baz | | 329 | device foo: baz |
338 | attach foo at bar | | 330 | attach foo at bar |
339 | file dev/bar/foo.c foo | | 331 | file dev/bar/foo.c foo |
340 | .Ed | | 332 | .Ed |
341 | .Pp | | 333 | .Pp |
342 | An entry can now be added to the machine description file: | | 334 | An entry can now be added to the machine description file: |
343 | .Bd -literal | | 335 | .Bd -literal |
344 | foo* at bar? | | 336 | foo* at bar? |
345 | .Ed | | 337 | .Ed |
346 | .Pp | | 338 | .Pp |
347 | For device interfaces of a driver to be compiled into the kernel, | | 339 | For device interfaces of a driver to be compiled into the kernel, |
348 | .Xr config 1 | | 340 | .Xr config 1 |
349 | must be aware of its existence. | | 341 | must be aware of its existence. |
350 | This is done by including an entry in majors.<arch>. | | 342 | This is done by including an entry in majors.<arch>. |
351 | For example, the driver | | 343 | For example, the driver |
352 | .Dq foo | | 344 | .Dq foo |
353 | with character device interfaces, a character major device number | | 345 | with character device interfaces, a character major device number |
354 | .Dq cmaj , | | 346 | .Dq cmaj , |
355 | block device interfaces, a block device major number | | 347 | block device interfaces, a block device major number |
356 | .Dq bmaj | | 348 | .Dq bmaj |
357 | and dependency on kernel module | | 349 | and dependency on kernel module |
358 | .Dq baz | | 350 | .Dq baz |
359 | has the entry: | | 351 | has the entry: |
360 | .Bd -literal | | 352 | .Bd -literal |
361 | device-major foo char cmaj block bmaj baz | | 353 | device-major foo char cmaj block bmaj baz |
362 | .Ed | | 354 | .Ed |
363 | .Pp | | 355 | .Pp |
364 | For a detailed description of the machine description file and the | | 356 | For a detailed description of the machine description file and the |
365 | .Dq device definition | | 357 | .Dq device definition |
366 | language see | | 358 | language see |
367 | .Xr config 9 . | | 359 | .Xr config 9 . |
368 | .Sh SEE ALSO | | 360 | .Sh SEE ALSO |
369 | .Xr config 1 , | | 361 | .Xr config 1 , |
370 | .Xr autoconf 9 , | | 362 | .Xr autoconf 9 , |
371 | .Xr config 9 , | | 363 | .Xr config 9 , |
372 | .Xr devsw 9 , | | 364 | .Xr devsw 9 , |
373 | .Xr pmf 9 | | 365 | .Xr pmf 9 |