2 .\" Copyright (c) 2014 John Baldwin <jhb@FreeBSD.org>
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
13 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 .Nm devctl_clear_driver ,
41 .Nm devctl_set_driver ,
44 .Nd device control library
50 .Fn devctl_attach "const char *device"
52 .Fn devctl_clear_driver "const char *device" "bool force"
54 .Fn devctl_delete "const char *device" "bool force"
56 .Fn devctl_detach "const char *device" "bool force"
58 .Fn devctl_disable "const char *device" "bool force_detach"
60 .Fn devctl_enable "const char *device"
62 .Fn devctl_freeze "void"
64 .Fn devctl_getpath "const char *device" "const char *locator" "char **buffer"
66 .Fn devctl_rescan "const char *device"
68 .Fn devctl_reset "const char *device" "bool detach"
70 .Fn devctl_resume "const char *device"
72 .Fn devctl_set_driver "const char *device" "const char *driver" "bool force"
74 .Fn devctl_suspend "const char *device"
76 .Fn devctl_thaw "void"
80 library adjusts the state of devices in the kernel's internal device
82 Each control operation accepts a
84 argument that identifies the device to adjust.
87 may be specified as either the name of an existing device or as a
89 The following bus-specific address formats are currently supported:
90 .Bl -tag -offset indent
91 .It Sy pci Ns Fa domain Ns : Ns Fa bus Ns : Ns Fa slot Ns : Ns Fa function
92 A PCI device with the specified
98 .It Sy pci Ns Fa bus Ns : Ns Fa slot Ns : Ns Fa function
99 A PCI device in domain zero with the specified
105 A device with an ACPI handle of
107 The handle must be specified as an absolute path and must begin with a
113 function probes a device and attaches a suitable device driver if one is
118 function detaches a device from its current device driver.
119 The device is left detached until either a new driver for its parent
120 bus is loaded or the device is explicitly probed via
125 the current device driver will be detached even if the device is busy.
129 function deletes a device from the device tree.
134 the device is deleted even if the device is physically present.
138 function disables a device.
139 If the device is currently attached to a device driver,
140 the device driver will be detached from the device,
141 but the device will retain its current name.
145 the current device driver will be detached even if the device is busy.
146 The device will remain disabled and detached until it is explicitly enabled
152 function re-enables a disabled device.
153 The device will probe and attach if a suitable device driver is found.
157 function suspends a device.
158 This may include placing the device in a reduced power state,
159 but any device driver currently attached to the device will remain attached.
163 function resumes a suspended device to a fully working state.
166 .Fn devctl_set_driver
167 function attaches a device driver named
170 If the device is already attached and
173 the request will fail.
174 If the device is already attached and
177 the device will be detached from its current device driver before it is
178 attached to the new device driver.
181 .Fn devctl_clear_driver
182 function resets a device so that it can be attached to any valid device
183 driver rather than only drivers with a previously specified name.
184 This function is used to undo a previous call to
185 .Fn devctl_set_driver .
186 If the device is already attached and
189 the request will fail.
190 If the device is already attached and
193 the device will be detached from its current device driver.
194 After the device's name is reset,
195 it is reprobed and attached to a suitable device driver if one is found.
199 function rescans a bus device checking for devices that have been added or
204 retrieves the path to the
206 from the kernel using the
208 method to construct the path.
211 pointer is updated with an allocated buffer that must be freed with
216 function freezes probe and attach processing initiated in response to
217 drivers being loaded.
221 function resumes (thaws the freeze) probe and attach processing
222 initiated in response to drivers being loaded.
226 function resets the specified device using bus-specific reset method.
229 argument, if true, specifies that the device driver is detached before
230 the reset, and re-attached afterwards.
231 If false, the device is suspended before the reset, and resumed after.
233 .Rv -std devctl_attach devctl_clear_driver devctl_delete devctl_detach \
234 devctl_disable devctl_enable devctl_suspend devctl_rescan devctl_resume \
237 In addition to specific errors noted below,
240 functions may fail for any of the errors described in
245 The device name is too long.
247 No existing device matches the specified name or location.
249 The current process is not permitted to adjust the state of
255 function may fail if:
258 The device is already attached.
260 An internal memory allocation request failed.
262 The device is disabled.
264 No suitable driver for the device could be found,
265 or the driver failed to attach.
270 function may fail if:
273 The current device driver for
275 is busy and cannot detach at this time.
276 Note that some drivers may return this even if
280 The device is not attached to a driver.
282 The current device driver for
284 does not support detaching.
289 function may fail if:
292 The device is already enabled.
294 An internal memory allocation request failed.
296 No suitable driver for the device could be found,
297 or the driver failed to attach.
302 function may fail if:
305 The current device driver for
307 is busy and cannot detach at this time.
308 Note that some drivers may return this even if
312 The device is already disabled.
314 The current device driver for
316 does not support detaching.
321 function may fail if:
324 The device is already suspended.
326 The device to be suspended is the root bus device.
331 function may fail if:
334 The device is not suspended.
336 The device to be resumed is the root bus device.
340 .Fn devctl_set_driver
341 function may fail if:
344 The device is currently attached to a device driver and
348 The current device driver for
350 is busy and cannot detach at this time.
354 argument points outside the process' allocated address space.
356 No device driver with the requested name exists.
358 An internal memory allocation request failed.
360 The device is disabled.
362 The new device driver failed to attach.
366 .Fn devctl_clear_driver
367 function may fail if:
370 The device is currently attached to a device driver and
374 The current device driver for
376 is busy and cannot detach at this time.
378 The device is not configured for a specific device driver name.
380 The device driver chosen after reprobing failed to attach.
385 function may fail if:
388 The device is not attached to a driver.
390 The bus driver does not support rescanning.
395 function may fail if:
398 The device is physically present and
403 is the root device of the device tree.
408 function may fail if:
411 The bus does not implement the reset method.
413 The device failed to respond after the reset in the time limits
418 function may also return errors caused by the attach, detach, suspend,
419 and resume methods of the device driver.
427 library first appeared in
430 If a device is suspended individually via
432 and the entire machine is subsequently suspended,
433 the device will be resumed when the machine resumes.
435 Similarly, if the device is suspended, and
437 is called on the device with
441 the device is resumed by the
444 Or, if the driver for the device is detached manually, and
446 is called on the device with
450 device reset re-attaches the driver.