1.\" -*- nroff -*- 2.\" 3.\" Copyright (c) 1998 Doug Rabson 4.\" 5.\" All rights reserved. 6.\" 7.\" This program is free software. 8.\" 9.\" Redistribution and use in source and binary forms, with or without 10.\" modification, are permitted provided that the following conditions 11.\" are met: 12.\" 1. Redistributions of source code must retain the above copyright 13.\" notice, this list of conditions and the following disclaimer. 14.\" 2. Redistributions in binary form must reproduce the above copyright 15.\" notice, this list of conditions and the following disclaimer in the 16.\" documentation and/or other materials provided with the distribution. 17.\" 18.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR 19.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT, 22.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28.\" 29.Dd February 5, 2025 30.Dt DEVICE_PROBE_AND_ATTACH 9 31.Os 32.Sh NAME 33.Nm device_attach , 34.Nm device_detach , 35.Nm device_probe , 36.Nm device_probe_and_attach 37.Nd manage device's connection to a device driver 38.Sh SYNOPSIS 39.In sys/param.h 40.In sys/bus.h 41.Ft int 42.Fn device_attach "device_t dev" 43.Ft int 44.Fn device_detach "device_t dev" 45.Ft int 46.Fn device_probe "device_t dev" 47.Ft int 48.Fn device_probe_and_attach "device_t dev" 49.Sh DESCRIPTION 50These functions manage the relationship between a device and device drivers. 51.Pp 52.Fn device_probe 53invokes the 54.Xr DEVICE_PROBE 9 55method of each suitable driver and to find the driver with the best match for 56.Fa dev . 57If a matching driver is found, 58.Fa dev 59is set to the 60.Dv DS_ALIVE 61state and zero is returned. 62If 63.Fa dev 64is already attached to a device driver or has been disabled via 65.Xr device_disable 9 , 66then it will not be probed and -1 is returned. 67.Pp 68.Fn device_attach 69fully attaches a device driver to 70.Fa dev . 71This function prints a description of the device and invokes the 72.Xr DEVICE_ATTACH 9 73method. 74If the 75.Xr DEVICE_ATTACH 9 76method succeeds, 77.Fa dev 78is set to the 79.Dv DS_ATTACHED 80state and zero is returned. 81If the 82.Xr DEVICE_ATTACH 9 83method fails, 84.Xr BUS_CHILD_DETACHED 9 85is called and an error value is returned. 86.Pp 87If the device name and unit are disabled by a hint, 88.Fn device_attach 89disables the device, demotes it to the 90.Dv DS_NOTPRESENT 91state, 92and returns 93.Dv ENXIO . 94The device retains its device name and unit and can be re-enabled via 95.Xr devctl 8 . 96.Pp 97.Fn device_probe_and_attach 98is a wrapper function around 99.Fn device_probe 100and 101.Fn device_attach 102that fully initialises a device. 103If 104.Fa dev 105is already attached or disabled, 106.Fn device_probe_and_attach 107leaves the device unchanged and returns zero. 108Otherwise, 109.Fn device_probe 110is used to identify a device driver for 111.Fa dev 112and 113.Fn device_attach 114finalizes attaching the driver to 115.Fa dev . 116Device drivers should generally use this function to initialize a device 117rather than direct calls to 118.Fn device_probe 119and 120.Fn device_attach . 121.Pp 122.Fn device_detach 123detaches the device driver from 124.Fa dev . 125This function invokes the 126.Xr DEVICE_DETACH 9 127method to tear down device driver state for 128.Fa dev . 129If the method fails, 130its error value is returned and 131.Fa dev 132remains attached. 133If the method succeeds, 134otherwise, 135.Xr BUS_CHILD_DETACHED 9 136is called, 137the device is set to the 138.Dv DS_NOTPRESENT 139state, 140and zero is returned. 141If a device is busy, 142.Fn device_detach 143fails with 144.Dv EBUSY 145and leaving 146.Fa dev 147unchanged. 148.Sh RETURN VALUES 149Zero is returned on success, otherwise an appropriate error is returned. 150In addition, 151.Fn device_probe 152returns -1 if 153.Fa dev 154is disabled or already attached. 155.Sh SEE ALSO 156.Xr devctl 8 , 157.Xr BUS_CHILD_DETACHED 9 , 158.Xr device 9 , 159.Xr DEVICE_ATTACH 9 , 160.Xr DEVICE_DETACH 9 , 161.Xr DEVICE_PROBE 9 , 162.Xr driver 9 163.Sh AUTHORS 164This manual page was written by 165.An Doug Rabson . 166