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