xref: /freebsd/lib/libdevctl/devctl.3 (revision 45dc13f1ea17f98ac7b92768814d579ac48bfd04)
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 February 2, 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_resume ,
38.Nm devctl_set_driver ,
39.Nm devctl_suspend
40.Nd device control library
41.Sh LIBRARY
42.Lb libdevctl
43.Sh SYNOPSIS
44.In devctl.h
45.Ft int
46.Fn devctl_attach "const char *device"
47.Ft int
48.Fn devctl_detach "const char *device" "bool force"
49.Ft int
50.Fn devctl_disable "const char *device" "bool force_detach"
51.Ft int
52.Fn devctl_enable "const char *device"
53.Ft int
54.Fn devctl_resume "const char *device"
55.Ft int
56.Fn devctl_set_driver "const char *device" "const char *driver" "bool force"
57.Ft int
58.Fn devctl_suspend "const char *device"
59.Sh DESCRIPTION
60The
61.Nm
62library adjusts the state of devices in the kernel's internal device
63hierarchy.
64Each control operation accepts a
65.Fa device
66argument that identifies the device to adjust.
67The
68.Fa device
69may be specified as either the name of an existing device or as a
70bus-specific address.
71The following bus-specific address formats are currently supported:
72.Bl -tag -offset indent
73.It Sy pci Ns Fa domain Ns : Ns Fa bus Ns : Ns Fa slot Ns : Ns Fa function
74A PCI device with the specified
75.Fa domain ,
76.Fa bus ,
77.Fa slot ,
78and
79.Fa function .
80.It Sy pci Ns Fa bus Ns : Ns Fa slot Ns : Ns Fa function
81A PCI device in domain zero with the specified
82.Fa bus ,
83.Fa slot ,
84and
85.Fa function .
86.It Fa handle
87A device with an ACPI handle of
88.Fa handle .
89The handle must be specified as an absolute path and must begin with a
90.Dq \e .
91.El
92.Pp
93The
94.Fn devctl_attach
95function probes a device and attaches a suitable device driver if one is
96found.
97.Pp
98The
99.Fn devctl_detach
100function detaches a device from its current device driver.
101The device is left detached until either a new driver for its parent
102bus is loaded or the device is explicitly probed via
103.Fn devctl_attach .
104If
105.Fa force
106is true,
107the current device driver will be detached even if the device is busy.
108.Pp
109The
110.Fn devctl_disable
111function disables a device.
112If the device is currently attached to a device driver,
113the device driver will be detached from the device,
114but the device will retain its current name.
115If
116.Fa force_detach
117is true,
118the current device driver will be detached even if the device is busy.
119The device will remain disabled and detached until it is explicitly enabled
120via
121.Fn devctl_enable .
122.Pp
123The
124.Fn devctl_enable
125function re-enables a disabled device.
126The device will probe and attach if a suitable device driver is found.
127.Pp
128The
129.Fn devctl_suspend
130function suspends a device.
131This may include placing the device in a reduced power state,
132but any device driver currently attached to the device will remain attached.
133.Pp
134The
135.Fn devctl_resume
136function resumes a suspended device to a fully working state.
137.Pp
138The
139.Fn devctl_set_driver
140function attaches a device driver named
141.Fa driver
142to a device.
143If the device is already attached and
144.Fa force
145is false,
146the request will fail.
147If the device is already attached and
148.Fa force
149is true,
150the device will be detached from its current device driver before it is
151attached to the new device driver.
152.Sh RETURN VALUES
153.Rv -std devctl_attach devctl_detach devctl_disable devctl_enable \
154devctl_suspend devctl_resume devctl_set_driver
155.Sh ERRORS
156In addition to specific errors noted below,
157all of the
158.Nm
159functions may fail for any of the errors described in
160.Xr open 2
161as well as:
162.Bl -tag -width Er
163.It Bq Er EINVAL
164The device name is too long.
165.It Bq Er ENOENT
166No existing device matches the specified name or location.
167.It Bq Er EPERM
168The current process is not permitted to adjust the state of
169.Fa device .
170.El
171.Pp
172The
173.Fn devctl_attach
174function may fail if:
175.Bl -tag -width Er
176.It Bq Er EBUSY
177The device is already attached.
178.It Bq Er ENOMEM
179An internal memory allocation request failed.
180.It Bq Er ENXIO
181The device is disabled.
182.It Bq Er ENXIO
183No suitable driver for the device could be found,
184or the driver failed to attach.
185.El
186.Pp
187The
188.Fn devctl_detach
189function may fail if:
190.Bl -tag -width Er
191.It Bq Er EBUSY
192The current device driver for
193.Fa device
194is busy and cannot detach at this time.
195Note that some drivers may return this even if
196.Fa force
197is true.
198.It Bq Er ENXIO
199The device is not attached to a driver.
200.It Bq Er ENXIO
201The current device driver for
202.Fa device
203does not support detaching.
204.El
205.Pp
206The
207.Fn devctl_enable
208function may fail if:
209.Bl -tag -width Er
210.It Bq Er EBUSY
211The device is already enabled.
212.It Bq Er ENOMEM
213An internal memory allocation request failed.
214.It Bq Er ENXIO
215No suitable driver for the device could be found,
216or the driver failed to attach.
217.El
218.Pp
219The
220.Fn devctl_disable
221function may fail if:
222.Bl -tag -width Er
223.It Bq Er EBUSY
224The current device driver for
225.Fa device
226is busy and cannot detach at this time.
227Note that some drivers may return this even if
228.Fa force_detach
229is true.
230.It Bq Er ENXIO
231The device is already disabled.
232.It Bq Er ENXIO
233The current device driver for
234.Fa device
235does not support detaching.
236.El
237.Pp
238The
239.Fn devctl_suspend
240function may fail if:
241.Bl -tag -width Er
242.It Bq Er EBUSY
243The device is already suspended.
244.It Bq Er EINVAL
245The device to be suspended is the root bus device.
246.El
247.Pp
248The
249.Fn devctl_resume
250function may fail if:
251.Bl -tag -width Er
252.It Bq Er EINVAL
253The device is not suspended.
254.It Bq Er EINVAL
255The device to be resumed is the root bus device.
256.El
257.Pp
258The
259.Fn devctl_set_driver
260function may fail if:
261.Bl -tag -width Er
262.It Bq Er EBUSY
263The device is currently attached to a device driver and
264.Fa force
265is false.
266.It Bq Er EBUSY
267The current device driver for
268.Fa device
269is busy and cannot detach at this time.
270.It Bq Er EFAULT
271The
272.Fa driver
273argument points outside the process' allocated address space.
274.It Bq Er ENOENT
275No device driver with the requested name exists.
276.It Bq Er ENOMEM
277An internal memory allocation request failed.
278.It Bq Er ENXIO
279The device is disabled.
280.It Bq Er ENXIO
281The new device driver failed to attach.
282.El
283.Sh SEE ALSO
284.Xr devinfo 3 ,
285.Xr devstat 3 ,
286.Xr devctl 8
287.Sh HISTORY
288The
289.Nm
290library first appeared in
291.Fx 10.3 .
292.Sh BUGS
293If a device is suspended individually via
294.Fn devctl_suspend
295and the entire machine is subsequently suspended,
296the device will be resumed when the machine resumes.
297