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.\" 28e05ec081SJohn 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 , 34e05ec081SJohn 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 , 39*5fa29797SWarner Losh.Nm devctl_freeze , 40a907c691SJohn Baldwin.Nm devctl_rescan , 4164de8019SJohn Baldwin.Nm devctl_resume , 420fd00e0cSJohn Baldwin.Nm devctl_set_driver , 43*5fa29797SWarner Losh.Nm devctl_suspend , 44*5fa29797SWarner Losh.Nm devctl_thaw 4564de8019SJohn Baldwin.Nd device control library 4664de8019SJohn Baldwin.Sh LIBRARY 4764de8019SJohn Baldwin.Lb libdevctl 4864de8019SJohn Baldwin.Sh SYNOPSIS 4964de8019SJohn Baldwin.In devctl.h 5064de8019SJohn Baldwin.Ft int 5164de8019SJohn Baldwin.Fn devctl_attach "const char *device" 5264de8019SJohn Baldwin.Ft int 53e05ec081SJohn Baldwin.Fn devctl_clear_driver "const char *device" "bool force" 54e05ec081SJohn Baldwin.Ft int 5588eb5c50SJohn Baldwin.Fn devctl_delete "const char *device" "bool force" 5688eb5c50SJohn Baldwin.Ft int 5764de8019SJohn Baldwin.Fn devctl_detach "const char *device" "bool force" 5864de8019SJohn Baldwin.Ft int 5964de8019SJohn Baldwin.Fn devctl_disable "const char *device" "bool force_detach" 6064de8019SJohn Baldwin.Ft int 6164de8019SJohn Baldwin.Fn devctl_enable "const char *device" 6264de8019SJohn Baldwin.Ft int 63*5fa29797SWarner Losh.Fn devctl_freeze "void" 64*5fa29797SWarner Losh.Ft int 65a907c691SJohn Baldwin.Fn devctl_rescan "const char *device" 66a907c691SJohn Baldwin.Ft int 6764de8019SJohn Baldwin.Fn devctl_resume "const char *device" 6864de8019SJohn Baldwin.Ft int 6964de8019SJohn Baldwin.Fn devctl_set_driver "const char *device" "const char *driver" "bool force" 700fd00e0cSJohn Baldwin.Ft int 710fd00e0cSJohn Baldwin.Fn devctl_suspend "const char *device" 72*5fa29797SWarner Losh.Ft int 73*5fa29797SWarner Losh.Fn devctl_thaw "void" 7464de8019SJohn Baldwin.Sh DESCRIPTION 7564de8019SJohn BaldwinThe 7664de8019SJohn Baldwin.Nm 7764de8019SJohn Baldwinlibrary adjusts the state of devices in the kernel's internal device 7864de8019SJohn Baldwinhierarchy. 7964de8019SJohn BaldwinEach control operation accepts a 8064de8019SJohn Baldwin.Fa device 8164de8019SJohn Baldwinargument that identifies the device to adjust. 8264de8019SJohn BaldwinThe 8364de8019SJohn Baldwin.Fa device 8464de8019SJohn Baldwinmay be specified as either the name of an existing device or as a 8564de8019SJohn Baldwinbus-specific address. 8664de8019SJohn BaldwinThe following bus-specific address formats are currently supported: 8764de8019SJohn Baldwin.Bl -tag -offset indent 8864de8019SJohn Baldwin.It Sy pci Ns Fa domain Ns : Ns Fa bus Ns : Ns Fa slot Ns : Ns Fa function 8964de8019SJohn BaldwinA PCI device with the specified 9064de8019SJohn Baldwin.Fa domain , 9164de8019SJohn Baldwin.Fa bus , 9264de8019SJohn Baldwin.Fa slot , 9364de8019SJohn Baldwinand 9464de8019SJohn Baldwin.Fa function . 9564de8019SJohn Baldwin.It Sy pci Ns Fa bus Ns : Ns Fa slot Ns : Ns Fa function 9664de8019SJohn BaldwinA PCI device in domain zero with the specified 9764de8019SJohn Baldwin.Fa bus , 9864de8019SJohn Baldwin.Fa slot , 9964de8019SJohn Baldwinand 10064de8019SJohn Baldwin.Fa function . 10164de8019SJohn Baldwin.It Fa handle 10264de8019SJohn BaldwinA device with an ACPI handle of 10364de8019SJohn Baldwin.Fa handle . 10464de8019SJohn BaldwinThe handle must be specified as an absolute path and must begin with a 10564de8019SJohn Baldwin.Dq \e . 10664de8019SJohn Baldwin.El 10764de8019SJohn Baldwin.Pp 10864de8019SJohn BaldwinThe 10964de8019SJohn Baldwin.Fn devctl_attach 11064de8019SJohn Baldwinfunction probes a device and attaches a suitable device driver if one is 11164de8019SJohn Baldwinfound. 11264de8019SJohn Baldwin.Pp 11364de8019SJohn BaldwinThe 11464de8019SJohn Baldwin.Fn devctl_detach 11564de8019SJohn Baldwinfunction detaches a device from its current device driver. 11664de8019SJohn BaldwinThe device is left detached until either a new driver for its parent 11764de8019SJohn Baldwinbus is loaded or the device is explicitly probed via 11864de8019SJohn Baldwin.Fn devctl_attach . 11964de8019SJohn BaldwinIf 12064de8019SJohn Baldwin.Fa force 12164de8019SJohn Baldwinis true, 12264de8019SJohn Baldwinthe current device driver will be detached even if the device is busy. 12364de8019SJohn Baldwin.Pp 12464de8019SJohn BaldwinThe 12588eb5c50SJohn Baldwin.Fn devctl_delete 12688eb5c50SJohn Baldwinfunction deletes a device from the device tree. 12788eb5c50SJohn BaldwinNo 12888eb5c50SJohn BaldwinIf 12988eb5c50SJohn Baldwin.Fa force 13088eb5c50SJohn Baldwinis true, 13188eb5c50SJohn Baldwinthe device is deleted even if the device is physically present. 13288eb5c50SJohn Baldwin.Pp 13388eb5c50SJohn BaldwinThe 13464de8019SJohn Baldwin.Fn devctl_disable 13564de8019SJohn Baldwinfunction disables a device. 13664de8019SJohn BaldwinIf the device is currently attached to a device driver, 13764de8019SJohn Baldwinthe device driver will be detached from the device, 13864de8019SJohn Baldwinbut the device will retain its current name. 13964de8019SJohn BaldwinIf 14064de8019SJohn Baldwin.Fa force_detach 14164de8019SJohn Baldwinis true, 14264de8019SJohn Baldwinthe current device driver will be detached even if the device is busy. 14364de8019SJohn BaldwinThe device will remain disabled and detached until it is explicitly enabled 14464de8019SJohn Baldwinvia 14564de8019SJohn Baldwin.Fn devctl_enable . 14664de8019SJohn Baldwin.Pp 14764de8019SJohn BaldwinThe 14864de8019SJohn Baldwin.Fn devctl_enable 14964de8019SJohn Baldwinfunction re-enables a disabled device. 15064de8019SJohn BaldwinThe device will probe and attach if a suitable device driver is found. 15164de8019SJohn Baldwin.Pp 15264de8019SJohn BaldwinThe 15364de8019SJohn Baldwin.Fn devctl_suspend 15464de8019SJohn Baldwinfunction suspends a device. 15564de8019SJohn BaldwinThis may include placing the device in a reduced power state, 15664de8019SJohn Baldwinbut any device driver currently attached to the device will remain attached. 15764de8019SJohn Baldwin.Pp 15864de8019SJohn BaldwinThe 15964de8019SJohn Baldwin.Fn devctl_resume 16064de8019SJohn Baldwinfunction resumes a suspended device to a fully working state. 16164de8019SJohn Baldwin.Pp 16264de8019SJohn BaldwinThe 16364de8019SJohn Baldwin.Fn devctl_set_driver 16464de8019SJohn Baldwinfunction attaches a device driver named 16564de8019SJohn Baldwin.Fa driver 16664de8019SJohn Baldwinto a device. 16764de8019SJohn BaldwinIf the device is already attached and 16864de8019SJohn Baldwin.Fa force 16964de8019SJohn Baldwinis false, 17064de8019SJohn Baldwinthe request will fail. 17164de8019SJohn BaldwinIf the device is already attached and 17264de8019SJohn Baldwin.Fa force 17364de8019SJohn Baldwinis true, 17464de8019SJohn Baldwinthe device will be detached from its current device driver before it is 17564de8019SJohn Baldwinattached to the new device driver. 176a907c691SJohn Baldwin.Pp 177a907c691SJohn BaldwinThe 178e05ec081SJohn Baldwin.Fn devctl_clear_driver 179e05ec081SJohn Baldwinfunction resets a device so that it can be attached to any valid device 180e05ec081SJohn Baldwindriver rather than only drivers with a previously specified name. 181e05ec081SJohn BaldwinThis function is used to undo a previous call to 182e05ec081SJohn Baldwin.Fn devctl_set_driver . 183e05ec081SJohn BaldwinIf the device is already attached and 184e05ec081SJohn Baldwin.Fa force 185e05ec081SJohn Baldwinis false, 186e05ec081SJohn Baldwinthe request will fail. 187e05ec081SJohn BaldwinIf the device is already attached and 188e05ec081SJohn Baldwin.Fa force 189e05ec081SJohn Baldwinis true, 190e05ec081SJohn Baldwinthe device will be detached from its current device driver. 191e05ec081SJohn BaldwinAfter the device's name is reset, 192e05ec081SJohn Baldwinit is reprobed and attached to a suitable device driver if one is found. 193e05ec081SJohn Baldwin.Pp 194e05ec081SJohn BaldwinThe 195a907c691SJohn Baldwin.Fn devctl_rescan 196a907c691SJohn Baldwinfunction rescans a bus device checking for devices that have been added or 197a907c691SJohn Baldwinremoved. 198*5fa29797SWarner Losh.Pp 199*5fa29797SWarner LoshThe 200*5fa29797SWarner Losh.Fn devctl_freeze 201*5fa29797SWarner Loshfunction freezes probe and attach processing initiated in response to 202*5fa29797SWarner Loshdrivers being loaded. 203*5fa29797SWarner Losh.Pp 204*5fa29797SWarner LoshThe 205*5fa29797SWarner Losh.Fn devctl_thaw 206*5fa29797SWarner Loshfunction resumes (thaws the freeze) probe and attach processing 207*5fa29797SWarner Loshinitiated in response to drivers being loaded. 20864de8019SJohn Baldwin.Sh RETURN VALUES 209e05ec081SJohn Baldwin.Rv -std devctl_attach devctl_clear_driver devctl_delete devctl_detach \ 210e05ec081SJohn Baldwindevctl_disable devctl_enable devctl_suspend devctl_rescan devctl_resume \ 211e05ec081SJohn Baldwindevctl_set_driver 21264de8019SJohn Baldwin.Sh ERRORS 21364de8019SJohn BaldwinIn addition to specific errors noted below, 21464de8019SJohn Baldwinall of the 21564de8019SJohn Baldwin.Nm 21664de8019SJohn Baldwinfunctions may fail for any of the errors described in 21764de8019SJohn Baldwin.Xr open 2 21864de8019SJohn Baldwinas well as: 21964de8019SJohn Baldwin.Bl -tag -width Er 22064de8019SJohn Baldwin.It Bq Er EINVAL 22164de8019SJohn BaldwinThe device name is too long. 22264de8019SJohn Baldwin.It Bq Er ENOENT 22364de8019SJohn BaldwinNo existing device matches the specified name or location. 22464de8019SJohn Baldwin.It Bq Er EPERM 22564de8019SJohn BaldwinThe current process is not permitted to adjust the state of 22664de8019SJohn Baldwin.Fa device . 22764de8019SJohn Baldwin.El 22864de8019SJohn Baldwin.Pp 22964de8019SJohn BaldwinThe 23064de8019SJohn Baldwin.Fn devctl_attach 23164de8019SJohn Baldwinfunction may fail if: 23264de8019SJohn Baldwin.Bl -tag -width Er 23364de8019SJohn Baldwin.It Bq Er EBUSY 23464de8019SJohn BaldwinThe device is already attached. 23564de8019SJohn Baldwin.It Bq Er ENOMEM 23664de8019SJohn BaldwinAn internal memory allocation request failed. 23764de8019SJohn Baldwin.It Bq Er ENXIO 23864de8019SJohn BaldwinThe device is disabled. 23964de8019SJohn Baldwin.It Bq Er ENXIO 24064de8019SJohn BaldwinNo suitable driver for the device could be found, 24164de8019SJohn Baldwinor the driver failed to attach. 24264de8019SJohn Baldwin.El 24364de8019SJohn Baldwin.Pp 24464de8019SJohn BaldwinThe 24564de8019SJohn Baldwin.Fn devctl_detach 24664de8019SJohn Baldwinfunction may fail if: 24764de8019SJohn Baldwin.Bl -tag -width Er 24864de8019SJohn Baldwin.It Bq Er EBUSY 24964de8019SJohn BaldwinThe current device driver for 25064de8019SJohn Baldwin.Fa device 25164de8019SJohn Baldwinis busy and cannot detach at this time. 25264de8019SJohn BaldwinNote that some drivers may return this even if 25364de8019SJohn Baldwin.Fa force 25464de8019SJohn Baldwinis true. 25564de8019SJohn Baldwin.It Bq Er ENXIO 25664de8019SJohn BaldwinThe device is not attached to a driver. 25764de8019SJohn Baldwin.It Bq Er ENXIO 25864de8019SJohn BaldwinThe current device driver for 25964de8019SJohn Baldwin.Fa device 26064de8019SJohn Baldwindoes not support detaching. 26164de8019SJohn Baldwin.El 26264de8019SJohn Baldwin.Pp 26364de8019SJohn BaldwinThe 26464de8019SJohn Baldwin.Fn devctl_enable 26564de8019SJohn Baldwinfunction may fail if: 26664de8019SJohn Baldwin.Bl -tag -width Er 26764de8019SJohn Baldwin.It Bq Er EBUSY 26864de8019SJohn BaldwinThe device is already enabled. 26964de8019SJohn Baldwin.It Bq Er ENOMEM 27064de8019SJohn BaldwinAn internal memory allocation request failed. 27164de8019SJohn Baldwin.It Bq Er ENXIO 27264de8019SJohn BaldwinNo suitable driver for the device could be found, 27364de8019SJohn Baldwinor the driver failed to attach. 27464de8019SJohn Baldwin.El 27564de8019SJohn Baldwin.Pp 27664de8019SJohn BaldwinThe 27764de8019SJohn Baldwin.Fn devctl_disable 27864de8019SJohn Baldwinfunction may fail if: 27964de8019SJohn Baldwin.Bl -tag -width Er 28064de8019SJohn Baldwin.It Bq Er EBUSY 28164de8019SJohn BaldwinThe current device driver for 28264de8019SJohn Baldwin.Fa device 28364de8019SJohn Baldwinis busy and cannot detach at this time. 28464de8019SJohn BaldwinNote that some drivers may return this even if 28564de8019SJohn Baldwin.Fa force_detach 28664de8019SJohn Baldwinis true. 28764de8019SJohn Baldwin.It Bq Er ENXIO 28864de8019SJohn BaldwinThe device is already disabled. 28964de8019SJohn Baldwin.It Bq Er ENXIO 29064de8019SJohn BaldwinThe current device driver for 29164de8019SJohn Baldwin.Fa device 29264de8019SJohn Baldwindoes not support detaching. 29364de8019SJohn Baldwin.El 29464de8019SJohn Baldwin.Pp 29564de8019SJohn BaldwinThe 29664de8019SJohn Baldwin.Fn devctl_suspend 29764de8019SJohn Baldwinfunction may fail if: 29864de8019SJohn Baldwin.Bl -tag -width Er 29964de8019SJohn Baldwin.It Bq Er EBUSY 30064de8019SJohn BaldwinThe device is already suspended. 30164de8019SJohn Baldwin.It Bq Er EINVAL 30264de8019SJohn BaldwinThe device to be suspended is the root bus device. 30364de8019SJohn Baldwin.El 30464de8019SJohn Baldwin.Pp 30564de8019SJohn BaldwinThe 30664de8019SJohn Baldwin.Fn devctl_resume 30764de8019SJohn Baldwinfunction may fail if: 30864de8019SJohn Baldwin.Bl -tag -width Er 30964de8019SJohn Baldwin.It Bq Er EINVAL 31064de8019SJohn BaldwinThe device is not suspended. 31164de8019SJohn Baldwin.It Bq Er EINVAL 31264de8019SJohn BaldwinThe device to be resumed is the root bus device. 31364de8019SJohn Baldwin.El 31464de8019SJohn Baldwin.Pp 31564de8019SJohn BaldwinThe 31664de8019SJohn Baldwin.Fn devctl_set_driver 31764de8019SJohn Baldwinfunction may fail if: 31864de8019SJohn Baldwin.Bl -tag -width Er 31964de8019SJohn Baldwin.It Bq Er EBUSY 32064de8019SJohn BaldwinThe device is currently attached to a device driver and 32164de8019SJohn Baldwin.Fa force 32264de8019SJohn Baldwinis false. 32364de8019SJohn Baldwin.It Bq Er EBUSY 32464de8019SJohn BaldwinThe current device driver for 32564de8019SJohn Baldwin.Fa device 32664de8019SJohn Baldwinis busy and cannot detach at this time. 32764de8019SJohn Baldwin.It Bq Er EFAULT 32864de8019SJohn BaldwinThe 32964de8019SJohn Baldwin.Fa driver 33064de8019SJohn Baldwinargument points outside the process' allocated address space. 33164de8019SJohn Baldwin.It Bq Er ENOENT 33264de8019SJohn BaldwinNo device driver with the requested name exists. 33364de8019SJohn Baldwin.It Bq Er ENOMEM 33464de8019SJohn BaldwinAn internal memory allocation request failed. 33564de8019SJohn Baldwin.It Bq Er ENXIO 33664de8019SJohn BaldwinThe device is disabled. 33764de8019SJohn Baldwin.It Bq Er ENXIO 33864de8019SJohn BaldwinThe new device driver failed to attach. 33964de8019SJohn Baldwin.El 340a907c691SJohn Baldwin.Pp 341a907c691SJohn BaldwinThe 342e05ec081SJohn Baldwin.Fn devctl_clear_driver 343e05ec081SJohn Baldwinfunction may fail if: 344e05ec081SJohn Baldwin.Bl -tag -width Er 345e05ec081SJohn Baldwin.It Bq Er EBUSY 346e05ec081SJohn BaldwinThe device is currently attached to a device driver and 347e05ec081SJohn Baldwin.Fa force 348e05ec081SJohn Baldwinis false. 349e05ec081SJohn Baldwin.It Bq Er EBUSY 350e05ec081SJohn BaldwinThe current device driver for 351e05ec081SJohn Baldwin.Fa device 352e05ec081SJohn Baldwinis busy and cannot detach at this time. 353e05ec081SJohn Baldwin.It Bq Er EINVAL 354e05ec081SJohn BaldwinThe device is not configured for a specific device driver name. 355e05ec081SJohn Baldwin.It Bq Er ENXIO 356e05ec081SJohn BaldwinThe device driver chosen after reprobing failed to attach. 357e05ec081SJohn Baldwin.El 358e05ec081SJohn Baldwin.Pp 359e05ec081SJohn BaldwinThe 360a907c691SJohn Baldwin.Fn devctl_rescan 361a907c691SJohn Baldwinfunction may fail if: 362a907c691SJohn Baldwin.Bl -tag -width Er 363a907c691SJohn Baldwin.It Bq Er ENXIO 364a907c691SJohn BaldwinThe device is not attached to a driver. 365a907c691SJohn Baldwin.It Bq Er ENXIO 366a907c691SJohn BaldwinThe bus driver does not support rescanning. 367a907c691SJohn Baldwin.El 36888eb5c50SJohn Baldwin.Pp 36988eb5c50SJohn BaldwinThe 37088eb5c50SJohn Baldwin.Fn devctl_delete 37188eb5c50SJohn Baldwinfunction may fail if: 37288eb5c50SJohn Baldwin.Bl -tag -width Er 37388eb5c50SJohn Baldwin.It Bq Er EBUSY 37488eb5c50SJohn BaldwinThe device is physically present and 37588eb5c50SJohn Baldwin.Fa force 37688eb5c50SJohn Baldwinis false. 37788eb5c50SJohn Baldwin.It Bq Er EINVAL 37888eb5c50SJohn Baldwin.Fa dev 37988eb5c50SJohn Baldwinis the root device of the device tree. 38088eb5c50SJohn Baldwin.El 38164de8019SJohn Baldwin.Sh SEE ALSO 38264de8019SJohn Baldwin.Xr devinfo 3 , 38364de8019SJohn Baldwin.Xr devstat 3 , 38464de8019SJohn Baldwin.Xr devctl 8 38564de8019SJohn Baldwin.Sh HISTORY 38664de8019SJohn BaldwinThe 38764de8019SJohn Baldwin.Nm 38864de8019SJohn Baldwinlibrary first appeared in 3890fd00e0cSJohn Baldwin.Fx 10.3 . 39064de8019SJohn Baldwin.Sh BUGS 39164de8019SJohn BaldwinIf a device is suspended individually via 39264de8019SJohn Baldwin.Fn devctl_suspend 39364de8019SJohn Baldwinand the entire machine is subsequently suspended, 39464de8019SJohn Baldwinthe device will be resumed when the machine resumes. 395