1*4c53e57fSdlg.\" $OpenBSD: autoconf.9,v 1.17 2018/04/18 22:33:18 dlg Exp $ 2f7e52e77Swcobb.\" $NetBSD: autoconf.9,v 1.9 2002/02/13 08:18:35 ross Exp $ 3f7e52e77Swcobb.\" 4f7e52e77Swcobb.\" Copyright (c) 2001 The NetBSD Foundation, Inc. 5f7e52e77Swcobb.\" All rights reserved. 6f7e52e77Swcobb.\" 7f7e52e77Swcobb.\" This code is derived from software contributed to The NetBSD Foundation 8f7e52e77Swcobb.\" by Gregory McGarry. 9f7e52e77Swcobb.\" 10f7e52e77Swcobb.\" Redistribution and use in source and binary forms, with or without 11f7e52e77Swcobb.\" modification, are permitted provided that the following conditions 12f7e52e77Swcobb.\" are met: 13f7e52e77Swcobb.\" 1. Redistributions of source code must retain the above copyright 14f7e52e77Swcobb.\" notice, this list of conditions and the following disclaimer. 15f7e52e77Swcobb.\" 2. Redistributions in binary form must reproduce the above copyright 16f7e52e77Swcobb.\" notice, this list of conditions and the following disclaimer in the 17f7e52e77Swcobb.\" documentation and/or other materials provided with the distribution. 18f7e52e77Swcobb.\" 19f7e52e77Swcobb.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20f7e52e77Swcobb.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21f7e52e77Swcobb.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22f7e52e77Swcobb.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23f7e52e77Swcobb.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24f7e52e77Swcobb.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25f7e52e77Swcobb.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26f7e52e77Swcobb.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27f7e52e77Swcobb.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28f7e52e77Swcobb.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29f7e52e77Swcobb.\" POSSIBILITY OF SUCH DAMAGE. 30f7e52e77Swcobb.\" 31*4c53e57fSdlg.Dd $Mdocdate: April 18 2018 $ 3233378d91Sjmc.Dt CONFIG_SEARCH 9 33f7e52e77Swcobb.Os 34f7e52e77Swcobb.Sh NAME 3533378d91Sjmc.Nm config_search , 3633378d91Sjmc.Nm config_rootsearch , 3733378d91Sjmc.Nm config_found_sm , 3833378d91Sjmc.Nm config_found , 39ef89f9e6Smpi.Nm config_rootfound 40f7e52e77Swcobb.Nd autoconfiguration framework 41f7e52e77Swcobb.Sh SYNOPSIS 42dddd2645Sschwarze.In sys/param.h 43dddd2645Sschwarze.In sys/device.h 44*4c53e57fSdlg.Ft "void *" 45*4c53e57fSdlg.Fn config_search "cfmatch_t func" "struct device *parent" "void *aux" 46*4c53e57fSdlg.Ft "void *" 47*4c53e57fSdlg.Fn config_rootsearch "cfmatch_t func" "char *rootname" "void *aux" 48*4c53e57fSdlg.Ft "struct device *" 49*4c53e57fSdlg.Fo config_found_sm 50*4c53e57fSdlg.Fa "struct device *parent" 51*4c53e57fSdlg.Fa "void *aux" 52*4c53e57fSdlg.Fa "cfprint_t print" 53*4c53e57fSdlg.Fa "cfmatch_t submatch" 54*4c53e57fSdlg.Fc 55*4c53e57fSdlg.Ft "struct device *" 56*4c53e57fSdlg.Fn config_found "struct device *parent" "void *aux" "cfprint_t print" 57*4c53e57fSdlg.Ft "struct device *" 58*4c53e57fSdlg.Fn config_rootfound "char *rootname" "void *aux" 59f7e52e77Swcobb.Sh DESCRIPTION 60f7e52e77SwcobbAutoconfiguration is the process of matching hardware devices with an 61f7e52e77Swcobbappropriate device driver. 62f7e52e77SwcobbIn its most basic form, autoconfiguration consists of the recursive 63df9fa2d9Sjmcprocess of finding and attaching all devices on a bus, including other buses. 64f7e52e77Swcobb.Pp 65f7e52e77SwcobbThe autoconfiguration framework supports 66f7e52e77Swcobb.Em direct configuration 67f7e52e77Swcobbwhere the bus driver can determine the devices present. 68f7e52e77Swcobb.Pp 69f7e52e77SwcobbThe autoconfiguration framework also supports 70f7e52e77Swcobb.Em indirect configuration 71f7e52e77Swcobbwhere the drivers must probe the bus looking for the presence of a device. 72f7e52e77SwcobbDirect configuration is preferred since it can find hardware regardless of 73f7e52e77Swcobbthe presence of proper drivers. 74f7e52e77Swcobb.Pp 75f7e52e77SwcobbThe autoconfiguration process occurs at system bootstrap and is driven by a 76f7e52e77Swcobbtable generated from a 77f7e52e77Swcobb.Do 78f7e52e77Swcobbmachine description 79f7e52e77Swcobb.Dc 80f7e52e77Swcobbfile by 81f7e52e77Swcobb.Xr config 8 . 82f7e52e77SwcobbFor a description of the 83f7e52e77Swcobb.Xr config 8 84f7e52e77Swcobb.Do 85f7e52e77Swcobbdevice definition 86f7e52e77Swcobb.Dc 87f7e52e77Swcobblanguage, see 886e788039Sjmc.Xr files.conf 5 . 89f7e52e77Swcobb.Pp 90f7e52e77SwcobbEach device must have a name consisting of an alphanumeric string that 91f7e52e77Swcobbends with a unit number. 92f7e52e77SwcobbThe unit number identifies an instance of the driver. 93f7e52e77SwcobbDevice data structures are allocated dynamically during autoconfiguration, 94f7e52e77Swcobbgiving a unique address for each instance. 95*4c53e57fSdlg.Ss Indirect Configuration 96f7e52e77SwcobbThe 97f7e52e77Swcobb.Fn config_search 98f7e52e77Swcobbfunction performs indirect configuration of physical devices by iterating 99f7e52e77Swcobbover all potential children, calling the given function 100f7e52e77Swcobb.Fa func 101f7e52e77Swcobbfor each one. 102f7e52e77Swcobb.Pp 103f7e52e77SwcobbThe 104f7e52e77Swcobb.Fn config_rootsearch 105f7e52e77Swcobbfunction finds the root device identified by the string 106f7e52e77Swcobb.Fa rootname , 107f7e52e77Swcobbin a manner similar to 108f7e52e77Swcobb.Fn config_search , 109f7e52e77Swcobbexcept that there is no parent device. 110f7e52e77SwcobbIf 111f7e52e77Swcobb.Fa func 112ef9318c8Sjmcis 113ef9318c8Sjmc.Dv NULL , 114f7e52e77Swcobb.Fn config_search 115f7e52e77Swcobbapplies each child's match function instead. 116f7e52e77SwcobbThe argument 117f7e52e77Swcobb.Fa parent 118f7e52e77Swcobbis the pointer to the parent's device structure. 119f7e52e77SwcobbThe given 120f7e52e77Swcobb.Fa aux 121f7e52e77Swcobbargument describes the device that has been found and is simply passed 122f7e52e77Swcobbon through 123f7e52e77Swcobb.Fa func 124f7e52e77Swcobbto the child. 125f7e52e77Swcobb.Fn config_search 126ef9318c8Sjmcreturns a pointer to the best-matched child or 127ef9318c8Sjmc.Dv NULL 128ef9318c8Sjmcotherwise. 129f7e52e77Swcobb.Pp 130f7e52e77SwcobbThe role of 131f7e52e77Swcobb.Fa func 132f7e52e77Swcobbis to call 133f7e52e77Swcobbthe match function for each device and call 134f7e52e77Swcobb.Fn config_attach 135f7e52e77Swcobbfor any positive matches. 136f7e52e77Swcobb.Bd -literal 137f7e52e77Swcobbtypedef int (*cfmatch_t)(struct device *parent, void *child, void *aux); 138f7e52e77Swcobb.Ed 139f7e52e77Swcobb.Pp 140f7e52e77SwcobbIf 141f7e52e77Swcobb.Fa func 142f7e52e77Swcobbis 143f7e52e77Swcobb.Dv NULL , 144f7e52e77Swcobbthen the parent should record the return value from 145f7e52e77Swcobb.Fn config_search 146f7e52e77Swcobband call 147f7e52e77Swcobb.Fn config_attach 148f7e52e77Swcobbitself. 149f7e52e77Swcobb.Pp 150f7e52e77SwcobbNote that this function is designed so that it can be used to apply an 151f7e52e77Swcobbarbitrary function to all potential children. 152f7e52e77SwcobbIn this case callers may choose to ignore the return value. 153*4c53e57fSdlg.Ss Direct Configuration 154f7e52e77SwcobbThe 155f7e52e77Swcobb.Fn config_found_sm 156f7e52e77Swcobbfunction performs direct configuration on a physical device. 157f7e52e77Swcobb.Fn config_found_sm 158f7e52e77Swcobbis called by the parent and in turn calls the 159f7e52e77Swcobb.Fa submatch 160f7e52e77Swcobbfunction to call the match function as determined by the configuration table. 161f7e52e77SwcobbIf 162f7e52e77Swcobb.Fa submatch 163ef9318c8Sjmcis 164ef9318c8Sjmc.Dv NULL , 165ef9318c8Sjmcthe driver match functions are called directly. 166f7e52e77SwcobbThe argument 167f7e52e77Swcobb.Fa parent 168f7e52e77Swcobbis the pointer to the parent's device structure. 169f7e52e77SwcobbThe given 170f7e52e77Swcobb.Fa aux 171f7e52e77Swcobbargument describes the device that has been found. 172f7e52e77SwcobbThe 173f7e52e77Swcobb.Em softc 174f7e52e77Swcobbstructure for the matched device will be allocated, and the appropriate 175f7e52e77Swcobbdriver attach function will be called. 176f7e52e77Swcobb.Pp 177f7e52e77SwcobbIf the device is matched, the system prints the name of the child and 178f7e52e77Swcobbparent devices, and then calls the 179f7e52e77Swcobb.Fa print 180f7e52e77Swcobbfunction to produce additional information if desired. 181f7e52e77SwcobbIf no driver takes a match, the same 182f7e52e77Swcobb.Fa print 183f7e52e77Swcobbfunction is called to complain. 184f7e52e77SwcobbThe print function is called with the 185f7e52e77Swcobb.Fa aux 186f7e52e77Swcobbargument and, if the matches failed, the full name (including unit 187ef9318c8Sjmcnumber) of the parent device, otherwise 188ef9318c8Sjmc.Dv NULL . 189f7e52e77Swcobb.Bd -literal 190f7e52e77Swcobbtypedef int (*cfprint_t)(void *aux, const char *parentname); 191f7e52e77Swcobb#define QUIET 0 /* print nothing */ 192f7e52e77Swcobb#define UNCONF 1 /* print " not configured" */ 193f7e52e77Swcobb#define UNSUPP 2 /* print " not supported" */ 194f7e52e77Swcobb.Ed 195f7e52e77Swcobb.Pp 196f7e52e77SwcobbTwo special strings, 197f7e52e77Swcobb.Do 198f7e52e77Swcobbnot configured 199f7e52e77Swcobb.Dc 200f7e52e77Swcobband 201f7e52e77Swcobb.Do 202f7e52e77Swcobbunsupported 203f7e52e77Swcobb.Dc 204f7e52e77Swcobbwill be appended automatically to non-driver reports if the return 205f7e52e77Swcobbvalue is 206f7e52e77Swcobb.Dv UNCONF 207f7e52e77Swcobbor 208f7e52e77Swcobb.Dv UNSUPP 209f7e52e77Swcobbrespectively, otherwise the function should return the value 210f7e52e77Swcobb.Dv QUIET . 211f7e52e77Swcobb.Pp 212f7e52e77SwcobbThe 213f7e52e77Swcobb.Fn config_found_sm 214f7e52e77Swcobbfunction returns a pointer to the attached device's 215f7e52e77Swcobb.Em softc 216ef9318c8Sjmcstructure if the device is attached, 217ef9318c8Sjmc.Dv NULL 218ef9318c8Sjmcotherwise. 219f7e52e77SwcobbMost callers can ignore this value, since the system will already have 220f7e52e77Swcobbprinted a diagnostic. 221f7e52e77Swcobb.Pp 222f7e52e77SwcobbThe 223f7e52e77Swcobb.Fn config_found 224f7e52e77Swcobbmacro expands to 225f7e52e77Swcobb.Fn config_found_sm "parent" "aux" "print" "submatch" 226f7e52e77Swcobbwith 227f7e52e77Swcobb.Fa submatch 228f7e52e77Swcobbset to 229f7e52e77Swcobb.Dv NULL 230f7e52e77Swcobband is provided for compatibility with older drivers. 231f7e52e77Swcobb.Pp 232f7e52e77SwcobbThe 233f7e52e77Swcobb.Fn config_rootfound 234f7e52e77Swcobbfunction performs the same operation on the root device identified 235f7e52e77Swcobbby the 236f7e52e77Swcobb.Fa rootname 237f7e52e77Swcobbstring. 238f7e52e77Swcobb.Sh CODE REFERENCES 239f7e52e77SwcobbThe autoconfiguration framework itself is implemented within the file 240f7e52e77Swcobb.Pa sys/kern/subr_autoconf.c . 241f7e52e77SwcobbData structures and function prototypes for the framework are located in 242f7e52e77Swcobb.Pa sys/sys/device.h . 243f7e52e77Swcobb.Sh SEE ALSO 2446794ccc4Stedu.Xr autoconf 4 , 245ef9318c8Sjmc.Xr files.conf 5 , 246c45c5a4eSmpi.Xr config 8 , 247c45c5a4eSmpi.Xr config_attach 9 248f7e52e77Swcobb.Sh HISTORY 249f7e52e77SwcobbAutoconfiguration first appeared in 250f7e52e77Swcobb.Bx 4.1 . 251f7e52e77SwcobbThe autoconfiguration framework was completely revised in 252f7e52e77Swcobb.Bx 4.4 . 253