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