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
33 .Nm devctl_clear_driver ,
43 .Nm devctl_set_driver ,
46 .Nd device control library
52 .Fn devctl_attach "const char *device"
54 .Fn devctl_clear_driver "const char *device" "bool force"
56 .Fn devctl_delete "const char *device" "bool force"
58 .Fn devctl_detach "const char *device" "bool force"
60 .Fn devctl_disable "const char *device" "bool force_detach"
62 .Fn devctl_enable "const char *device"
64 .Fn devctl_freeze "void"
66 .Fn devctl_getpath "const char *device" "const char *locator" "char **buffer"
68 .Fn devctl_rescan "const char *device"
70 .Fn devctl_reset "const char *device" "bool detach"
72 .Fn devctl_resume "const char *device"
74 .Fn devctl_set_driver "const char *device" "const char *driver" "bool force"
76 .Fn devctl_suspend "const char *device"
78 .Fn devctl_thaw "void"
82 library adjusts the state of devices in the kernel's internal device
84 Each control operation accepts a
86 argument that identifies the device to adjust.
89 may be specified as either the name of an existing device or as a
91 The following bus-specific address formats are currently supported:
92 .Bl -tag -offset indent
93 .It Sy pci Ns Fa domain Ns : Ns Fa bus Ns : Ns Fa slot Ns : Ns Fa function
94 A PCI device with the specified
100 .It Sy pci Ns Fa bus Ns : Ns Fa slot Ns : Ns Fa function
101 A PCI device in domain zero with the specified
107 A device with an ACPI handle of
109 The handle must be specified as an absolute path and must begin with a
115 function probes a device and attaches a suitable device driver if one is
120 function detaches a device from its current device driver.
121 The device is left detached until either a new driver for its parent
122 bus is loaded or the device is explicitly probed via
127 the current device driver will be detached even if the device is busy.
131 function deletes a device from the device tree.
136 the device is deleted even if the device is physically present.
140 function disables a device.
141 If the device is currently attached to a device driver,
142 the device driver will be detached from the device,
143 but the device will retain its current name.
147 the current device driver will be detached even if the device is busy.
148 The device will remain disabled and detached until it is explicitly enabled
154 function re-enables a disabled device.
155 The device will probe and attach if a suitable device driver is found.
159 function suspends a device.
160 This may include placing the device in a reduced power state,
161 but any device driver currently attached to the device will remain attached.
165 function resumes a suspended device to a fully working state.
168 .Fn devctl_set_driver
169 function attaches a device driver named
172 If the device is already attached and
175 the request will fail.
176 If the device is already attached and
179 the device will be detached from its current device driver before it is
180 attached to the new device driver.
183 .Fn devctl_clear_driver
184 function resets a device so that it can be attached to any valid device
185 driver rather than only drivers with a previously specified name.
186 This function is used to undo a previous call to
187 .Fn devctl_set_driver .
188 If the device is already attached and
191 the request will fail.
192 If the device is already attached and
195 the device will be detached from its current device driver.
196 After the device's name is reset,
197 it is reprobed and attached to a suitable device driver if one is found.
201 function rescans a bus device checking for devices that have been added or
206 retrieves the path to the
208 from the kernel using the
210 method to construct the path.
213 pointer is updated with an allocated buffer that must be freed with
218 function freezes probe and attach processing initiated in response to
219 drivers being loaded.
223 function resumes (thaws the freeze) probe and attach processing
224 initiated in response to drivers being loaded.
228 function resets the specified device using bus-specific reset method.
231 argument, if true, specifies that the device driver is detached before
232 the reset, and re-attached afterwards.
233 If false, the device is suspended before the reset, and resumed after.
235 .Rv -std devctl_attach devctl_clear_driver devctl_delete devctl_detach \
236 devctl_disable devctl_enable devctl_suspend devctl_rescan devctl_resume \
239 In addition to specific errors noted below,
242 functions may fail for any of the errors described in
247 The device name is too long.
249 No existing device matches the specified name or location.
251 The current process is not permitted to adjust the state of
257 function may fail if:
260 The device is already attached.
262 An internal memory allocation request failed.
264 The device is disabled.
266 No suitable driver for the device could be found,
267 or the driver failed to attach.
272 function may fail if:
275 The current device driver for
277 is busy and cannot detach at this time.
278 Note that some drivers may return this even if
282 The device is not attached to a driver.
284 The current device driver for
286 does not support detaching.
291 function may fail if:
294 The device is already enabled.
296 An internal memory allocation request failed.
298 No suitable driver for the device could be found,
299 or the driver failed to attach.
304 function may fail if:
307 The current device driver for
309 is busy and cannot detach at this time.
310 Note that some drivers may return this even if
314 The device is already disabled.
316 The current device driver for
318 does not support detaching.
323 function may fail if:
326 The device is already suspended.
328 The device to be suspended is the root bus device.
333 function may fail if:
336 The device is not suspended.
338 The device to be resumed is the root bus device.
342 .Fn devctl_set_driver
343 function may fail if:
346 The device is currently attached to a device driver and
350 The current device driver for
352 is busy and cannot detach at this time.
356 argument points outside the process' allocated address space.
358 No device driver with the requested name exists.
360 An internal memory allocation request failed.
362 The device is disabled.
364 The new device driver failed to attach.
368 .Fn devctl_clear_driver
369 function may fail if:
372 The device is currently attached to a device driver and
376 The current device driver for
378 is busy and cannot detach at this time.
380 The device is not configured for a specific device driver name.
382 The device driver chosen after reprobing failed to attach.
387 function may fail if:
390 The device is not attached to a driver.
392 The bus driver does not support rescanning.
397 function may fail if:
400 The device is physically present and
405 is the root device of the device tree.
410 function may fail if:
413 The bus does not implement the reset method.
415 The device failed to respond after the reset in the time limits
420 function may also return errors caused by the attach, detach, suspend,
421 and resume methods of the device driver.
429 library first appeared in
432 If a device is suspended individually via
434 and the entire machine is subsequently suspended,
435 the device will be resumed when the machine resumes.
437 Similarly, if the device is suspended, and
439 is called on the device with
443 the device is resumed by the
446 Or, if the driver for the device is detached manually, and
448 is called on the device with
452 device reset re-attaches the driver.