xref: /freebsd/lib/libdevctl/devctl.3 (revision e05ec081fe81beb79567b82723bd045aa50f19c0)
164de8019SJohn Baldwin.\"
264de8019SJohn Baldwin.\" Copyright (c) 2014 John Baldwin <jhb@FreeBSD.org>
364de8019SJohn Baldwin.\" All rights reserved.
464de8019SJohn Baldwin.\"
564de8019SJohn Baldwin.\" Redistribution and use in source and binary forms, with or without
664de8019SJohn Baldwin.\" modification, are permitted provided that the following conditions
764de8019SJohn Baldwin.\" are met:
864de8019SJohn Baldwin.\" 1. Redistributions of source code must retain the above copyright
964de8019SJohn Baldwin.\"    notice, this list of conditions and the following disclaimer.
1064de8019SJohn Baldwin.\" 2. Redistributions in binary form must reproduce the above copyright
1164de8019SJohn Baldwin.\"    notice, this list of conditions and the following disclaimer in the
1264de8019SJohn Baldwin.\"    documentation and/or other materials provided with the distribution.
1364de8019SJohn Baldwin.\"
1464de8019SJohn Baldwin.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1564de8019SJohn Baldwin.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1664de8019SJohn Baldwin.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1764de8019SJohn Baldwin.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1864de8019SJohn Baldwin.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1964de8019SJohn Baldwin.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2064de8019SJohn Baldwin.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2164de8019SJohn Baldwin.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2264de8019SJohn Baldwin.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2364de8019SJohn Baldwin.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2464de8019SJohn Baldwin.\" SUCH DAMAGE.
2564de8019SJohn Baldwin.\"
2664de8019SJohn Baldwin.\" $FreeBSD$
2764de8019SJohn Baldwin.\"
28*e05ec081SJohn Baldwin.Dd August 29, 2016
2964de8019SJohn Baldwin.Dt DEVCTL 3
3064de8019SJohn Baldwin.Os
3164de8019SJohn Baldwin.Sh NAME
3264de8019SJohn Baldwin.Nm devctl ,
3364de8019SJohn Baldwin.Nm devctl_attach ,
34*e05ec081SJohn Baldwin.Nm devctl_clear_driver ,
3588eb5c50SJohn Baldwin.Nm devctl_delete ,
3664de8019SJohn Baldwin.Nm devctl_detach ,
3764de8019SJohn Baldwin.Nm devctl_disable ,
3864de8019SJohn Baldwin.Nm devctl_enable ,
39a907c691SJohn Baldwin.Nm devctl_rescan ,
4064de8019SJohn Baldwin.Nm devctl_resume ,
410fd00e0cSJohn Baldwin.Nm devctl_set_driver ,
4264de8019SJohn Baldwin.Nm devctl_suspend
4364de8019SJohn Baldwin.Nd device control library
4464de8019SJohn Baldwin.Sh LIBRARY
4564de8019SJohn Baldwin.Lb libdevctl
4664de8019SJohn Baldwin.Sh SYNOPSIS
4764de8019SJohn Baldwin.In devctl.h
4864de8019SJohn Baldwin.Ft int
4964de8019SJohn Baldwin.Fn devctl_attach "const char *device"
5064de8019SJohn Baldwin.Ft int
51*e05ec081SJohn Baldwin.Fn devctl_clear_driver "const char *device" "bool force"
52*e05ec081SJohn Baldwin.Ft int
5388eb5c50SJohn Baldwin.Fn devctl_delete "const char *device" "bool force"
5488eb5c50SJohn Baldwin.Ft int
5564de8019SJohn Baldwin.Fn devctl_detach "const char *device" "bool force"
5664de8019SJohn Baldwin.Ft int
5764de8019SJohn Baldwin.Fn devctl_disable "const char *device" "bool force_detach"
5864de8019SJohn Baldwin.Ft int
5964de8019SJohn Baldwin.Fn devctl_enable "const char *device"
6064de8019SJohn Baldwin.Ft int
61a907c691SJohn Baldwin.Fn devctl_rescan "const char *device"
62a907c691SJohn Baldwin.Ft int
6364de8019SJohn Baldwin.Fn devctl_resume "const char *device"
6464de8019SJohn Baldwin.Ft int
6564de8019SJohn Baldwin.Fn devctl_set_driver "const char *device" "const char *driver" "bool force"
660fd00e0cSJohn Baldwin.Ft int
670fd00e0cSJohn Baldwin.Fn devctl_suspend "const char *device"
6864de8019SJohn Baldwin.Sh DESCRIPTION
6964de8019SJohn BaldwinThe
7064de8019SJohn Baldwin.Nm
7164de8019SJohn Baldwinlibrary adjusts the state of devices in the kernel's internal device
7264de8019SJohn Baldwinhierarchy.
7364de8019SJohn BaldwinEach control operation accepts a
7464de8019SJohn Baldwin.Fa device
7564de8019SJohn Baldwinargument that identifies the device to adjust.
7664de8019SJohn BaldwinThe
7764de8019SJohn Baldwin.Fa device
7864de8019SJohn Baldwinmay be specified as either the name of an existing device or as a
7964de8019SJohn Baldwinbus-specific address.
8064de8019SJohn BaldwinThe following bus-specific address formats are currently supported:
8164de8019SJohn Baldwin.Bl -tag -offset indent
8264de8019SJohn Baldwin.It Sy pci Ns Fa domain Ns : Ns Fa bus Ns : Ns Fa slot Ns : Ns Fa function
8364de8019SJohn BaldwinA PCI device with the specified
8464de8019SJohn Baldwin.Fa domain ,
8564de8019SJohn Baldwin.Fa bus ,
8664de8019SJohn Baldwin.Fa slot ,
8764de8019SJohn Baldwinand
8864de8019SJohn Baldwin.Fa function .
8964de8019SJohn Baldwin.It Sy pci Ns Fa bus Ns : Ns Fa slot Ns : Ns Fa function
9064de8019SJohn BaldwinA PCI device in domain zero with the specified
9164de8019SJohn Baldwin.Fa bus ,
9264de8019SJohn Baldwin.Fa slot ,
9364de8019SJohn Baldwinand
9464de8019SJohn Baldwin.Fa function .
9564de8019SJohn Baldwin.It Fa handle
9664de8019SJohn BaldwinA device with an ACPI handle of
9764de8019SJohn Baldwin.Fa handle .
9864de8019SJohn BaldwinThe handle must be specified as an absolute path and must begin with a
9964de8019SJohn Baldwin.Dq \e .
10064de8019SJohn Baldwin.El
10164de8019SJohn Baldwin.Pp
10264de8019SJohn BaldwinThe
10364de8019SJohn Baldwin.Fn devctl_attach
10464de8019SJohn Baldwinfunction probes a device and attaches a suitable device driver if one is
10564de8019SJohn Baldwinfound.
10664de8019SJohn Baldwin.Pp
10764de8019SJohn BaldwinThe
10864de8019SJohn Baldwin.Fn devctl_detach
10964de8019SJohn Baldwinfunction detaches a device from its current device driver.
11064de8019SJohn BaldwinThe device is left detached until either a new driver for its parent
11164de8019SJohn Baldwinbus is loaded or the device is explicitly probed via
11264de8019SJohn Baldwin.Fn devctl_attach .
11364de8019SJohn BaldwinIf
11464de8019SJohn Baldwin.Fa force
11564de8019SJohn Baldwinis true,
11664de8019SJohn Baldwinthe current device driver will be detached even if the device is busy.
11764de8019SJohn Baldwin.Pp
11864de8019SJohn BaldwinThe
11988eb5c50SJohn Baldwin.Fn devctl_delete
12088eb5c50SJohn Baldwinfunction deletes a device from the device tree.
12188eb5c50SJohn BaldwinNo
12288eb5c50SJohn BaldwinIf
12388eb5c50SJohn Baldwin.Fa force
12488eb5c50SJohn Baldwinis true,
12588eb5c50SJohn Baldwinthe device is deleted even if the device is physically present.
12688eb5c50SJohn Baldwin.Pp
12788eb5c50SJohn BaldwinThe
12864de8019SJohn Baldwin.Fn devctl_disable
12964de8019SJohn Baldwinfunction disables a device.
13064de8019SJohn BaldwinIf the device is currently attached to a device driver,
13164de8019SJohn Baldwinthe device driver will be detached from the device,
13264de8019SJohn Baldwinbut the device will retain its current name.
13364de8019SJohn BaldwinIf
13464de8019SJohn Baldwin.Fa force_detach
13564de8019SJohn Baldwinis true,
13664de8019SJohn Baldwinthe current device driver will be detached even if the device is busy.
13764de8019SJohn BaldwinThe device will remain disabled and detached until it is explicitly enabled
13864de8019SJohn Baldwinvia
13964de8019SJohn Baldwin.Fn devctl_enable .
14064de8019SJohn Baldwin.Pp
14164de8019SJohn BaldwinThe
14264de8019SJohn Baldwin.Fn devctl_enable
14364de8019SJohn Baldwinfunction re-enables a disabled device.
14464de8019SJohn BaldwinThe device will probe and attach if a suitable device driver is found.
14564de8019SJohn Baldwin.Pp
14664de8019SJohn BaldwinThe
14764de8019SJohn Baldwin.Fn devctl_suspend
14864de8019SJohn Baldwinfunction suspends a device.
14964de8019SJohn BaldwinThis may include placing the device in a reduced power state,
15064de8019SJohn Baldwinbut any device driver currently attached to the device will remain attached.
15164de8019SJohn Baldwin.Pp
15264de8019SJohn BaldwinThe
15364de8019SJohn Baldwin.Fn devctl_resume
15464de8019SJohn Baldwinfunction resumes a suspended device to a fully working state.
15564de8019SJohn Baldwin.Pp
15664de8019SJohn BaldwinThe
15764de8019SJohn Baldwin.Fn devctl_set_driver
15864de8019SJohn Baldwinfunction attaches a device driver named
15964de8019SJohn Baldwin.Fa driver
16064de8019SJohn Baldwinto a device.
16164de8019SJohn BaldwinIf the device is already attached and
16264de8019SJohn Baldwin.Fa force
16364de8019SJohn Baldwinis false,
16464de8019SJohn Baldwinthe request will fail.
16564de8019SJohn BaldwinIf the device is already attached and
16664de8019SJohn Baldwin.Fa force
16764de8019SJohn Baldwinis true,
16864de8019SJohn Baldwinthe device will be detached from its current device driver before it is
16964de8019SJohn Baldwinattached to the new device driver.
170a907c691SJohn Baldwin.Pp
171a907c691SJohn BaldwinThe
172*e05ec081SJohn Baldwin.Fn devctl_clear_driver
173*e05ec081SJohn Baldwinfunction resets a device so that it can be attached to any valid device
174*e05ec081SJohn Baldwindriver rather than only drivers with a previously specified name.
175*e05ec081SJohn BaldwinThis function is used to undo a previous call to
176*e05ec081SJohn Baldwin.Fn devctl_set_driver .
177*e05ec081SJohn BaldwinIf the device is already attached and
178*e05ec081SJohn Baldwin.Fa force
179*e05ec081SJohn Baldwinis false,
180*e05ec081SJohn Baldwinthe request will fail.
181*e05ec081SJohn BaldwinIf the device is already attached and
182*e05ec081SJohn Baldwin.Fa force
183*e05ec081SJohn Baldwinis true,
184*e05ec081SJohn Baldwinthe device will be detached from its current device driver.
185*e05ec081SJohn BaldwinAfter the device's name is reset,
186*e05ec081SJohn Baldwinit is reprobed and attached to a suitable device driver if one is found.
187*e05ec081SJohn Baldwin.Pp
188*e05ec081SJohn BaldwinThe
189a907c691SJohn Baldwin.Fn devctl_rescan
190a907c691SJohn Baldwinfunction rescans a bus device checking for devices that have been added or
191a907c691SJohn Baldwinremoved.
19264de8019SJohn Baldwin.Sh RETURN VALUES
193*e05ec081SJohn Baldwin.Rv -std devctl_attach devctl_clear_driver devctl_delete devctl_detach \
194*e05ec081SJohn Baldwindevctl_disable devctl_enable devctl_suspend devctl_rescan devctl_resume \
195*e05ec081SJohn Baldwindevctl_set_driver
19664de8019SJohn Baldwin.Sh ERRORS
19764de8019SJohn BaldwinIn addition to specific errors noted below,
19864de8019SJohn Baldwinall of the
19964de8019SJohn Baldwin.Nm
20064de8019SJohn Baldwinfunctions may fail for any of the errors described in
20164de8019SJohn Baldwin.Xr open 2
20264de8019SJohn Baldwinas well as:
20364de8019SJohn Baldwin.Bl -tag -width Er
20464de8019SJohn Baldwin.It Bq Er EINVAL
20564de8019SJohn BaldwinThe device name is too long.
20664de8019SJohn Baldwin.It Bq Er ENOENT
20764de8019SJohn BaldwinNo existing device matches the specified name or location.
20864de8019SJohn Baldwin.It Bq Er EPERM
20964de8019SJohn BaldwinThe current process is not permitted to adjust the state of
21064de8019SJohn Baldwin.Fa device .
21164de8019SJohn Baldwin.El
21264de8019SJohn Baldwin.Pp
21364de8019SJohn BaldwinThe
21464de8019SJohn Baldwin.Fn devctl_attach
21564de8019SJohn Baldwinfunction may fail if:
21664de8019SJohn Baldwin.Bl -tag -width Er
21764de8019SJohn Baldwin.It Bq Er EBUSY
21864de8019SJohn BaldwinThe device is already attached.
21964de8019SJohn Baldwin.It Bq Er ENOMEM
22064de8019SJohn BaldwinAn internal memory allocation request failed.
22164de8019SJohn Baldwin.It Bq Er ENXIO
22264de8019SJohn BaldwinThe device is disabled.
22364de8019SJohn Baldwin.It Bq Er ENXIO
22464de8019SJohn BaldwinNo suitable driver for the device could be found,
22564de8019SJohn Baldwinor the driver failed to attach.
22664de8019SJohn Baldwin.El
22764de8019SJohn Baldwin.Pp
22864de8019SJohn BaldwinThe
22964de8019SJohn Baldwin.Fn devctl_detach
23064de8019SJohn Baldwinfunction may fail if:
23164de8019SJohn Baldwin.Bl -tag -width Er
23264de8019SJohn Baldwin.It Bq Er EBUSY
23364de8019SJohn BaldwinThe current device driver for
23464de8019SJohn Baldwin.Fa device
23564de8019SJohn Baldwinis busy and cannot detach at this time.
23664de8019SJohn BaldwinNote that some drivers may return this even if
23764de8019SJohn Baldwin.Fa force
23864de8019SJohn Baldwinis true.
23964de8019SJohn Baldwin.It Bq Er ENXIO
24064de8019SJohn BaldwinThe device is not attached to a driver.
24164de8019SJohn Baldwin.It Bq Er ENXIO
24264de8019SJohn BaldwinThe current device driver for
24364de8019SJohn Baldwin.Fa device
24464de8019SJohn Baldwindoes not support detaching.
24564de8019SJohn Baldwin.El
24664de8019SJohn Baldwin.Pp
24764de8019SJohn BaldwinThe
24864de8019SJohn Baldwin.Fn devctl_enable
24964de8019SJohn Baldwinfunction may fail if:
25064de8019SJohn Baldwin.Bl -tag -width Er
25164de8019SJohn Baldwin.It Bq Er EBUSY
25264de8019SJohn BaldwinThe device is already enabled.
25364de8019SJohn Baldwin.It Bq Er ENOMEM
25464de8019SJohn BaldwinAn internal memory allocation request failed.
25564de8019SJohn Baldwin.It Bq Er ENXIO
25664de8019SJohn BaldwinNo suitable driver for the device could be found,
25764de8019SJohn Baldwinor the driver failed to attach.
25864de8019SJohn Baldwin.El
25964de8019SJohn Baldwin.Pp
26064de8019SJohn BaldwinThe
26164de8019SJohn Baldwin.Fn devctl_disable
26264de8019SJohn Baldwinfunction may fail if:
26364de8019SJohn Baldwin.Bl -tag -width Er
26464de8019SJohn Baldwin.It Bq Er EBUSY
26564de8019SJohn BaldwinThe current device driver for
26664de8019SJohn Baldwin.Fa device
26764de8019SJohn Baldwinis busy and cannot detach at this time.
26864de8019SJohn BaldwinNote that some drivers may return this even if
26964de8019SJohn Baldwin.Fa force_detach
27064de8019SJohn Baldwinis true.
27164de8019SJohn Baldwin.It Bq Er ENXIO
27264de8019SJohn BaldwinThe device is already disabled.
27364de8019SJohn Baldwin.It Bq Er ENXIO
27464de8019SJohn BaldwinThe current device driver for
27564de8019SJohn Baldwin.Fa device
27664de8019SJohn Baldwindoes not support detaching.
27764de8019SJohn Baldwin.El
27864de8019SJohn Baldwin.Pp
27964de8019SJohn BaldwinThe
28064de8019SJohn Baldwin.Fn devctl_suspend
28164de8019SJohn Baldwinfunction may fail if:
28264de8019SJohn Baldwin.Bl -tag -width Er
28364de8019SJohn Baldwin.It Bq Er EBUSY
28464de8019SJohn BaldwinThe device is already suspended.
28564de8019SJohn Baldwin.It Bq Er EINVAL
28664de8019SJohn BaldwinThe device to be suspended is the root bus device.
28764de8019SJohn Baldwin.El
28864de8019SJohn Baldwin.Pp
28964de8019SJohn BaldwinThe
29064de8019SJohn Baldwin.Fn devctl_resume
29164de8019SJohn Baldwinfunction may fail if:
29264de8019SJohn Baldwin.Bl -tag -width Er
29364de8019SJohn Baldwin.It Bq Er EINVAL
29464de8019SJohn BaldwinThe device is not suspended.
29564de8019SJohn Baldwin.It Bq Er EINVAL
29664de8019SJohn BaldwinThe device to be resumed is the root bus device.
29764de8019SJohn Baldwin.El
29864de8019SJohn Baldwin.Pp
29964de8019SJohn BaldwinThe
30064de8019SJohn Baldwin.Fn devctl_set_driver
30164de8019SJohn Baldwinfunction may fail if:
30264de8019SJohn Baldwin.Bl -tag -width Er
30364de8019SJohn Baldwin.It Bq Er EBUSY
30464de8019SJohn BaldwinThe device is currently attached to a device driver and
30564de8019SJohn Baldwin.Fa force
30664de8019SJohn Baldwinis false.
30764de8019SJohn Baldwin.It Bq Er EBUSY
30864de8019SJohn BaldwinThe current device driver for
30964de8019SJohn Baldwin.Fa device
31064de8019SJohn Baldwinis busy and cannot detach at this time.
31164de8019SJohn Baldwin.It Bq Er EFAULT
31264de8019SJohn BaldwinThe
31364de8019SJohn Baldwin.Fa driver
31464de8019SJohn Baldwinargument points outside the process' allocated address space.
31564de8019SJohn Baldwin.It Bq Er ENOENT
31664de8019SJohn BaldwinNo device driver with the requested name exists.
31764de8019SJohn Baldwin.It Bq Er ENOMEM
31864de8019SJohn BaldwinAn internal memory allocation request failed.
31964de8019SJohn Baldwin.It Bq Er ENXIO
32064de8019SJohn BaldwinThe device is disabled.
32164de8019SJohn Baldwin.It Bq Er ENXIO
32264de8019SJohn BaldwinThe new device driver failed to attach.
32364de8019SJohn Baldwin.El
324a907c691SJohn Baldwin.Pp
325a907c691SJohn BaldwinThe
326*e05ec081SJohn Baldwin.Fn devctl_clear_driver
327*e05ec081SJohn Baldwinfunction may fail if:
328*e05ec081SJohn Baldwin.Bl -tag -width Er
329*e05ec081SJohn Baldwin.It Bq Er EBUSY
330*e05ec081SJohn BaldwinThe device is currently attached to a device driver and
331*e05ec081SJohn Baldwin.Fa force
332*e05ec081SJohn Baldwinis false.
333*e05ec081SJohn Baldwin.It Bq Er EBUSY
334*e05ec081SJohn BaldwinThe current device driver for
335*e05ec081SJohn Baldwin.Fa device
336*e05ec081SJohn Baldwinis busy and cannot detach at this time.
337*e05ec081SJohn Baldwin.It Bq Er EINVAL
338*e05ec081SJohn BaldwinThe device is not configured for a specific device driver name.
339*e05ec081SJohn Baldwin.It Bq Er ENXIO
340*e05ec081SJohn BaldwinThe device driver chosen after reprobing failed to attach.
341*e05ec081SJohn Baldwin.El
342*e05ec081SJohn Baldwin.Pp
343*e05ec081SJohn BaldwinThe
344a907c691SJohn Baldwin.Fn devctl_rescan
345a907c691SJohn Baldwinfunction may fail if:
346a907c691SJohn Baldwin.Bl -tag -width Er
347a907c691SJohn Baldwin.It Bq Er ENXIO
348a907c691SJohn BaldwinThe device is not attached to a driver.
349a907c691SJohn Baldwin.It Bq Er ENXIO
350a907c691SJohn BaldwinThe bus driver does not support rescanning.
351a907c691SJohn Baldwin.El
35288eb5c50SJohn Baldwin.Pp
35388eb5c50SJohn BaldwinThe
35488eb5c50SJohn Baldwin.Fn devctl_delete
35588eb5c50SJohn Baldwinfunction may fail if:
35688eb5c50SJohn Baldwin.Bl -tag -width Er
35788eb5c50SJohn Baldwin.It Bq Er EBUSY
35888eb5c50SJohn BaldwinThe device is physically present and
35988eb5c50SJohn Baldwin.Fa force
36088eb5c50SJohn Baldwinis false.
36188eb5c50SJohn Baldwin.It Bq Er EINVAL
36288eb5c50SJohn Baldwin.Fa dev
36388eb5c50SJohn Baldwinis the root device of the device tree.
36488eb5c50SJohn Baldwin.El
36564de8019SJohn Baldwin.Sh SEE ALSO
36664de8019SJohn Baldwin.Xr devinfo 3 ,
36764de8019SJohn Baldwin.Xr devstat 3 ,
36864de8019SJohn Baldwin.Xr devctl 8
36964de8019SJohn Baldwin.Sh HISTORY
37064de8019SJohn BaldwinThe
37164de8019SJohn Baldwin.Nm
37264de8019SJohn Baldwinlibrary first appeared in
3730fd00e0cSJohn Baldwin.Fx 10.3 .
37464de8019SJohn Baldwin.Sh BUGS
37564de8019SJohn BaldwinIf a device is suspended individually via
37664de8019SJohn Baldwin.Fn devctl_suspend
37764de8019SJohn Baldwinand the entire machine is subsequently suspended,
37864de8019SJohn Baldwinthe device will be resumed when the machine resumes.
379