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 ,
42 .Nm devctl_set_driver ,
45 .Nd device control library
51 .Fn devctl_attach "const char *device"
53 .Fn devctl_clear_driver "const char *device" "bool force"
55 .Fn devctl_delete "const char *device" "bool force"
57 .Fn devctl_detach "const char *device" "bool force"
59 .Fn devctl_disable "const char *device" "bool force_detach"
61 .Fn devctl_enable "const char *device"
63 .Fn devctl_freeze "void"
65 .Fn devctl_rescan "const char *device"
67 .Fn devctl_reset "const char *device" "bool detach"
69 .Fn devctl_resume "const char *device"
71 .Fn devctl_set_driver "const char *device" "const char *driver" "bool force"
73 .Fn devctl_suspend "const char *device"
75 .Fn devctl_thaw "void"
79 library adjusts the state of devices in the kernel's internal device
81 Each control operation accepts a
83 argument that identifies the device to adjust.
86 may be specified as either the name of an existing device or as a
88 The following bus-specific address formats are currently supported:
89 .Bl -tag -offset indent
90 .It Sy pci Ns Fa domain Ns : Ns Fa bus Ns : Ns Fa slot Ns : Ns Fa function
91 A PCI device with the specified
97 .It Sy pci Ns Fa bus Ns : Ns Fa slot Ns : Ns Fa function
98 A PCI device in domain zero with the specified
104 A device with an ACPI handle of
106 The handle must be specified as an absolute path and must begin with a
112 function probes a device and attaches a suitable device driver if one is
117 function detaches a device from its current device driver.
118 The device is left detached until either a new driver for its parent
119 bus is loaded or the device is explicitly probed via
124 the current device driver will be detached even if the device is busy.
128 function deletes a device from the device tree.
133 the device is deleted even if the device is physically present.
137 function disables a device.
138 If the device is currently attached to a device driver,
139 the device driver will be detached from the device,
140 but the device will retain its current name.
144 the current device driver will be detached even if the device is busy.
145 The device will remain disabled and detached until it is explicitly enabled
151 function re-enables a disabled device.
152 The device will probe and attach if a suitable device driver is found.
156 function suspends a device.
157 This may include placing the device in a reduced power state,
158 but any device driver currently attached to the device will remain attached.
162 function resumes a suspended device to a fully working state.
165 .Fn devctl_set_driver
166 function attaches a device driver named
169 If the device is already attached and
172 the request will fail.
173 If the device is already attached and
176 the device will be detached from its current device driver before it is
177 attached to the new device driver.
180 .Fn devctl_clear_driver
181 function resets a device so that it can be attached to any valid device
182 driver rather than only drivers with a previously specified name.
183 This function is used to undo a previous call to
184 .Fn devctl_set_driver .
185 If the device is already attached and
188 the request will fail.
189 If the device is already attached and
192 the device will be detached from its current device driver.
193 After the device's name is reset,
194 it is reprobed and attached to a suitable device driver if one is found.
198 function rescans a bus device checking for devices that have been added or
203 function freezes probe and attach processing initiated in response to
204 drivers being loaded.
208 function resumes (thaws the freeze) probe and attach processing
209 initiated in response to drivers being loaded.
213 function resets the specified device using bus-specific reset method.
216 argument, if true, specifies that the device driver is detached before
217 the reset, and re-attached afterwards.
218 If false, the device is suspended before the reset, and resumed after.
220 .Rv -std devctl_attach devctl_clear_driver devctl_delete devctl_detach \
221 devctl_disable devctl_enable devctl_suspend devctl_rescan devctl_resume \
224 In addition to specific errors noted below,
227 functions may fail for any of the errors described in
232 The device name is too long.
234 No existing device matches the specified name or location.
236 The current process is not permitted to adjust the state of
242 function may fail if:
245 The device is already attached.
247 An internal memory allocation request failed.
249 The device is disabled.
251 No suitable driver for the device could be found,
252 or the driver failed to attach.
257 function may fail if:
260 The current device driver for
262 is busy and cannot detach at this time.
263 Note that some drivers may return this even if
267 The device is not attached to a driver.
269 The current device driver for
271 does not support detaching.
276 function may fail if:
279 The device is already enabled.
281 An internal memory allocation request failed.
283 No suitable driver for the device could be found,
284 or the driver failed to attach.
289 function may fail if:
292 The current device driver for
294 is busy and cannot detach at this time.
295 Note that some drivers may return this even if
299 The device is already disabled.
301 The current device driver for
303 does not support detaching.
308 function may fail if:
311 The device is already suspended.
313 The device to be suspended is the root bus device.
318 function may fail if:
321 The device is not suspended.
323 The device to be resumed is the root bus device.
327 .Fn devctl_set_driver
328 function may fail if:
331 The device is currently attached to a device driver and
335 The current device driver for
337 is busy and cannot detach at this time.
341 argument points outside the process' allocated address space.
343 No device driver with the requested name exists.
345 An internal memory allocation request failed.
347 The device is disabled.
349 The new device driver failed to attach.
353 .Fn devctl_clear_driver
354 function may fail if:
357 The device is currently attached to a device driver and
361 The current device driver for
363 is busy and cannot detach at this time.
365 The device is not configured for a specific device driver name.
367 The device driver chosen after reprobing failed to attach.
372 function may fail if:
375 The device is not attached to a driver.
377 The bus driver does not support rescanning.
382 function may fail if:
385 The device is physically present and
390 is the root device of the device tree.
395 function may fail if:
398 The bus does not implement the reset method.
400 The device failed to respond after the reset in the time limits
405 function may also return errors caused by the attach, detach, suspend,
406 and resume methods of the device driver.
414 library first appeared in
417 If a device is suspended individually via
419 and the entire machine is subsequently suspended,
420 the device will be resumed when the machine resumes.
422 Similarly, if the device is suspended, and
424 is called on the device with
428 the device is resumed by the
431 Or, if the driver for the device is detached manually, and
433 is called on the device with
437 device reset re-attaches the driver.