]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libdevctl/devctl.3
Add a new rescan method to the bus interface.
[FreeBSD/FreeBSD.git] / lib / libdevctl / devctl.3
1 .\"
2 .\" Copyright (c) 2014 John Baldwin <jhb@FreeBSD.org>
3 .\" All rights reserved.
4 .\"
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
7 .\" are met:
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\"    notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\"    notice, this list of conditions and the following disclaimer in the
12 .\"    documentation and/or other materials provided with the distribution.
13 .\"
14 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 .\" SUCH DAMAGE.
25 .\"
26 .\" $FreeBSD$
27 .\"
28 .Dd April 27, 2016
29 .Dt DEVCTL 3
30 .Os
31 .Sh NAME
32 .Nm devctl ,
33 .Nm devctl_attach ,
34 .Nm devctl_detach ,
35 .Nm devctl_disable ,
36 .Nm devctl_enable ,
37 .Nm devctl_rescan ,
38 .Nm devctl_resume ,
39 .Nm devctl_set_driver ,
40 .Nm devctl_suspend
41 .Nd device control library
42 .Sh LIBRARY
43 .Lb libdevctl
44 .Sh SYNOPSIS
45 .In devctl.h
46 .Ft int
47 .Fn devctl_attach "const char *device"
48 .Ft int
49 .Fn devctl_detach "const char *device" "bool force"
50 .Ft int
51 .Fn devctl_disable "const char *device" "bool force_detach"
52 .Ft int
53 .Fn devctl_enable "const char *device"
54 .Ft int
55 .Fn devctl_rescan "const char *device"
56 .Ft int
57 .Fn devctl_resume "const char *device"
58 .Ft int
59 .Fn devctl_set_driver "const char *device" "const char *driver" "bool force"
60 .Ft int
61 .Fn devctl_suspend "const char *device"
62 .Sh DESCRIPTION
63 The
64 .Nm
65 library adjusts the state of devices in the kernel's internal device
66 hierarchy.
67 Each control operation accepts a
68 .Fa device
69 argument that identifies the device to adjust.
70 The
71 .Fa device
72 may be specified as either the name of an existing device or as a
73 bus-specific address.
74 The following bus-specific address formats are currently supported:
75 .Bl -tag -offset indent
76 .It Sy pci Ns Fa domain Ns : Ns Fa bus Ns : Ns Fa slot Ns : Ns Fa function
77 A PCI device with the specified
78 .Fa domain ,
79 .Fa bus ,
80 .Fa slot ,
81 and
82 .Fa function .
83 .It Sy pci Ns Fa bus Ns : Ns Fa slot Ns : Ns Fa function
84 A PCI device in domain zero with the specified
85 .Fa bus ,
86 .Fa slot ,
87 and
88 .Fa function .
89 .It Fa handle
90 A device with an ACPI handle of
91 .Fa handle .
92 The handle must be specified as an absolute path and must begin with a
93 .Dq \e .
94 .El
95 .Pp
96 The
97 .Fn devctl_attach
98 function probes a device and attaches a suitable device driver if one is
99 found.
100 .Pp
101 The
102 .Fn devctl_detach
103 function detaches a device from its current device driver.
104 The device is left detached until either a new driver for its parent
105 bus is loaded or the device is explicitly probed via
106 .Fn devctl_attach .
107 If
108 .Fa force
109 is true,
110 the current device driver will be detached even if the device is busy.
111 .Pp
112 The
113 .Fn devctl_disable
114 function disables a device.
115 If the device is currently attached to a device driver,
116 the device driver will be detached from the device,
117 but the device will retain its current name.
118 If
119 .Fa force_detach
120 is true,
121 the current device driver will be detached even if the device is busy.
122 The device will remain disabled and detached until it is explicitly enabled
123 via
124 .Fn devctl_enable .
125 .Pp
126 The
127 .Fn devctl_enable
128 function re-enables a disabled device.
129 The device will probe and attach if a suitable device driver is found.
130 .Pp
131 The
132 .Fn devctl_suspend
133 function suspends a device.
134 This may include placing the device in a reduced power state,
135 but any device driver currently attached to the device will remain attached.
136 .Pp
137 The
138 .Fn devctl_resume
139 function resumes a suspended device to a fully working state.
140 .Pp
141 The
142 .Fn devctl_set_driver
143 function attaches a device driver named
144 .Fa driver
145 to a device.
146 If the device is already attached and
147 .Fa force
148 is false,
149 the request will fail.
150 If the device is already attached and
151 .Fa force
152 is true,
153 the device will be detached from its current device driver before it is
154 attached to the new device driver.
155 .Pp
156 The
157 .Fn devctl_rescan
158 function rescans a bus device checking for devices that have been added or
159 removed.
160 .Sh RETURN VALUES
161 .Rv -std devctl_attach devctl_detach devctl_disable devctl_enable \
162 devctl_suspend devctl_rescan devctl_resume devctl_set_driver
163 .Sh ERRORS
164 In addition to specific errors noted below,
165 all of the
166 .Nm
167 functions may fail for any of the errors described in
168 .Xr open 2
169 as well as:
170 .Bl -tag -width Er
171 .It Bq Er EINVAL
172 The device name is too long.
173 .It Bq Er ENOENT
174 No existing device matches the specified name or location.
175 .It Bq Er EPERM
176 The current process is not permitted to adjust the state of
177 .Fa device .
178 .El
179 .Pp
180 The
181 .Fn devctl_attach
182 function may fail if:
183 .Bl -tag -width Er
184 .It Bq Er EBUSY
185 The device is already attached.
186 .It Bq Er ENOMEM
187 An internal memory allocation request failed.
188 .It Bq Er ENXIO
189 The device is disabled.
190 .It Bq Er ENXIO
191 No suitable driver for the device could be found,
192 or the driver failed to attach.
193 .El
194 .Pp
195 The
196 .Fn devctl_detach
197 function may fail if:
198 .Bl -tag -width Er
199 .It Bq Er EBUSY
200 The current device driver for
201 .Fa device
202 is busy and cannot detach at this time.
203 Note that some drivers may return this even if
204 .Fa force
205 is true.
206 .It Bq Er ENXIO
207 The device is not attached to a driver.
208 .It Bq Er ENXIO
209 The current device driver for
210 .Fa device
211 does not support detaching.
212 .El
213 .Pp
214 The
215 .Fn devctl_enable
216 function may fail if:
217 .Bl -tag -width Er
218 .It Bq Er EBUSY
219 The device is already enabled.
220 .It Bq Er ENOMEM
221 An internal memory allocation request failed.
222 .It Bq Er ENXIO
223 No suitable driver for the device could be found,
224 or the driver failed to attach.
225 .El
226 .Pp
227 The
228 .Fn devctl_disable
229 function may fail if:
230 .Bl -tag -width Er
231 .It Bq Er EBUSY
232 The current device driver for
233 .Fa device
234 is busy and cannot detach at this time.
235 Note that some drivers may return this even if
236 .Fa force_detach
237 is true.
238 .It Bq Er ENXIO
239 The device is already disabled.
240 .It Bq Er ENXIO
241 The current device driver for
242 .Fa device
243 does not support detaching.
244 .El
245 .Pp
246 The
247 .Fn devctl_suspend
248 function may fail if:
249 .Bl -tag -width Er
250 .It Bq Er EBUSY
251 The device is already suspended.
252 .It Bq Er EINVAL
253 The device to be suspended is the root bus device.
254 .El
255 .Pp
256 The
257 .Fn devctl_resume
258 function may fail if:
259 .Bl -tag -width Er
260 .It Bq Er EINVAL
261 The device is not suspended.
262 .It Bq Er EINVAL
263 The device to be resumed is the root bus device.
264 .El
265 .Pp
266 The
267 .Fn devctl_set_driver
268 function may fail if:
269 .Bl -tag -width Er
270 .It Bq Er EBUSY
271 The device is currently attached to a device driver and
272 .Fa force
273 is false.
274 .It Bq Er EBUSY
275 The current device driver for
276 .Fa device
277 is busy and cannot detach at this time.
278 .It Bq Er EFAULT
279 The
280 .Fa driver
281 argument points outside the process' allocated address space.
282 .It Bq Er ENOENT
283 No device driver with the requested name exists.
284 .It Bq Er ENOMEM
285 An internal memory allocation request failed.
286 .It Bq Er ENXIO
287 The device is disabled.
288 .It Bq Er ENXIO
289 The new device driver failed to attach.
290 .El
291 .Pp
292 The
293 .Fn devctl_rescan
294 function may fail if:
295 .Bl -tag -width Er
296 .It Bq Er ENXIO
297 The device is not attached to a driver.
298 .It Bq Er ENXIO
299 The bus driver does not support rescanning.
300 .El
301 .Sh SEE ALSO
302 .Xr devinfo 3 ,
303 .Xr devstat 3 ,
304 .Xr devctl 8
305 .Sh HISTORY
306 The
307 .Nm
308 library first appeared in
309 .Fx 10.3 .
310 .Sh BUGS
311 If a device is suspended individually via
312 .Fn devctl_suspend
313 and the entire machine is subsequently suspended,
314 the device will be resumed when the machine resumes.