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