2002-10-14 17:43:14 +04:00
|
|
|
.\" $NetBSD: autoconf.9,v 1.13 2002/10/14 13:43:15 wiz Exp $
|
2001-07-01 08:11:13 +04:00
|
|
|
.\"
|
2002-10-13 04:52:50 +04:00
|
|
|
.\" Copyright (c) 2001, 2002 The NetBSD Foundation, Inc.
|
2001-07-01 08:11:13 +04:00
|
|
|
.\" All rights reserved.
|
|
|
|
.\"
|
|
|
|
.\" This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
.\" by Gregory McGarry.
|
|
|
|
.\"
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
|
|
.\" 3. All advertising materials mentioning features or use of this software
|
|
|
|
.\" must display the following acknowledgement:
|
|
|
|
.\" This product includes software developed by the NetBSD
|
|
|
|
.\" Foundation, Inc. and its contributors.
|
|
|
|
.\" 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
.\" contributors may be used to endorse or promote products derived
|
|
|
|
.\" from this software without specific prior written permission.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
2001-09-04 06:51:15 +04:00
|
|
|
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
2001-07-01 08:11:13 +04:00
|
|
|
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
.\" POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
.\"
|
2002-10-13 04:52:50 +04:00
|
|
|
.Dd October 5, 2002
|
2001-07-01 08:11:13 +04:00
|
|
|
.Dt AUTOCONF 9
|
|
|
|
.Os
|
|
|
|
.Sh NAME
|
|
|
|
.Nm autoconf ,
|
|
|
|
.Nm config_search ,
|
|
|
|
.Nm config_found_sm ,
|
|
|
|
.Nm config_found ,
|
2002-10-05 09:39:35 +04:00
|
|
|
.Nm config_match ,
|
2001-07-01 08:11:13 +04:00
|
|
|
.Nm config_attach ,
|
|
|
|
.Nm config_detach ,
|
|
|
|
.Nm config_activate ,
|
|
|
|
.Nm config_deactivate ,
|
|
|
|
.Nm config_defer ,
|
|
|
|
.Nm config_interrupts ,
|
|
|
|
.Nm config_pending_incr ,
|
|
|
|
.Nm config_pending_decr
|
|
|
|
.Nd autoconfiguration framework
|
|
|
|
.Sh SYNOPSIS
|
2002-02-13 11:17:26 +03:00
|
|
|
.Fd #include \*[Lt]sys/param.h\*[Gt]
|
|
|
|
.Fd #include \*[Lt]sys/device.h\*[Gt]
|
|
|
|
.Fd #include \*[Lt]sys/error.h\*[Gt]
|
2001-07-01 08:11:13 +04:00
|
|
|
.Ft struct cfdata *
|
|
|
|
.Fn config_search "cfmatch_t func" "struct device *parent" "void *aux"
|
|
|
|
.Ft struct device *
|
|
|
|
.Fn config_found_sm "struct device *parent" "void *aux" "cfprint_t print" \
|
|
|
|
"cfmatch_t submatch"
|
|
|
|
.Ft struct device *
|
|
|
|
.Fn config_found "struct device *parent" "void *aux" "cfprint_t print"
|
2002-10-05 09:39:35 +04:00
|
|
|
.Ft int
|
|
|
|
.Fn config_match "struct device *parent" "struct cfdata *cf" "void *aux"
|
2001-07-01 08:11:13 +04:00
|
|
|
.Ft struct device *
|
|
|
|
.Fn config_attach "struct device *parent" "struct cfdata *cf" "void *aux" \
|
2001-09-05 09:37:41 +04:00
|
|
|
"cfprint_t print"
|
2001-07-01 08:11:13 +04:00
|
|
|
.Ft int
|
|
|
|
.Fn config_detach "struct device *dev" "int flags"
|
|
|
|
.Ft int
|
|
|
|
.Fn config_activate "struct device *dev"
|
|
|
|
.Ft int
|
|
|
|
.Fn config_deactivate "struct device *dev"
|
|
|
|
.Ft int
|
|
|
|
.Fn config_defer "struct device *dev" "void (*func)(struct device *)"
|
|
|
|
.Ft void
|
|
|
|
.Fn config_interrupts "struct device *dev" "void (*func)(struct device *)"
|
|
|
|
.Ft void
|
|
|
|
.Fn config_pending_incr
|
|
|
|
.Ft void
|
|
|
|
.Fn config_pending_decr
|
|
|
|
.Sh DESCRIPTION
|
|
|
|
Autoconfiguration is the process of matching hardware devices with an
|
2002-10-13 04:52:50 +04:00
|
|
|
appropriate device driver.
|
|
|
|
In its most basic form, autoconfiguration consists of the recursive process
|
|
|
|
of finding and attaching all devices on a bus, including other busses.
|
2001-07-01 08:11:13 +04:00
|
|
|
.Pp
|
|
|
|
The autoconfiguration framework supports
|
|
|
|
.Em direct configuration
|
2002-10-13 04:52:50 +04:00
|
|
|
where the bus driver can determine the devices present.
|
|
|
|
The autoconfiguration framework also supports
|
2001-07-01 08:11:13 +04:00
|
|
|
.Em indirect configuration
|
2002-04-02 18:14:45 +04:00
|
|
|
where the drivers must probe the bus looking for the presence of a device.
|
2001-07-01 08:11:13 +04:00
|
|
|
Direct configuration is preferred since it can find hardware
|
|
|
|
regardless of the presence of proper drivers.
|
|
|
|
.Pp
|
|
|
|
The autoconfiguration process occurs at system bootstrap and is driven
|
|
|
|
by a table generated from a
|
|
|
|
.Do
|
2001-12-13 22:29:32 +03:00
|
|
|
machine description
|
2001-07-01 08:11:13 +04:00
|
|
|
.Dc
|
|
|
|
file by
|
|
|
|
.Xr config 8 .
|
|
|
|
For a description of the
|
|
|
|
.Xr config 8
|
|
|
|
.Do
|
2001-12-13 22:29:32 +03:00
|
|
|
device definition
|
2001-07-01 08:11:13 +04:00
|
|
|
.Dc
|
|
|
|
language, see
|
|
|
|
.Xr config 9 .
|
|
|
|
.Pp
|
|
|
|
Each device must have a name consisting of an alphanumeric string that
|
2002-10-13 04:52:50 +04:00
|
|
|
ends with a unit number.
|
|
|
|
The unit number identifies an instance of the driver.
|
|
|
|
Device data structures are allocated dynamically during
|
2001-07-01 08:11:13 +04:00
|
|
|
autoconfiguration, giving a unique address for each instance.
|
|
|
|
.Sh FUNCTIONS
|
|
|
|
.Bl -tag -width compact
|
|
|
|
.It Fn config_search "func" "parent" "aux"
|
|
|
|
Performs indirect configuration of physical devices.
|
|
|
|
.Fn config_search
|
|
|
|
iterates over all potential children, calling the given
|
|
|
|
function
|
|
|
|
.Fa func
|
2002-10-13 04:52:50 +04:00
|
|
|
for each one.
|
|
|
|
If
|
2001-07-01 08:11:13 +04:00
|
|
|
.Fa func
|
2002-10-13 04:52:50 +04:00
|
|
|
is
|
|
|
|
.Dv NULL ,
|
2001-07-01 08:11:13 +04:00
|
|
|
.Fn config_search
|
2002-10-13 04:52:50 +04:00
|
|
|
applies each child's match function instead.
|
|
|
|
The argument
|
2001-07-01 08:11:13 +04:00
|
|
|
.Fa parent
|
2002-10-13 04:52:50 +04:00
|
|
|
is the pointer to the parent's device structure.
|
|
|
|
The given
|
2001-07-01 08:11:13 +04:00
|
|
|
.Fa aux
|
|
|
|
argument describes the device that has been found and is simply passed
|
|
|
|
on through
|
|
|
|
.Fa func
|
|
|
|
to the child.
|
|
|
|
.Fn config_search
|
2002-10-13 04:52:50 +04:00
|
|
|
returns a pointer to the best-matched child or
|
|
|
|
.Dv NULL
|
|
|
|
otherwise.
|
2001-07-01 08:11:13 +04:00
|
|
|
.Pp
|
|
|
|
The role of
|
|
|
|
.Fa func
|
|
|
|
is to call
|
|
|
|
the match function for each device and call
|
2001-09-05 09:37:41 +04:00
|
|
|
.Fn config_attach
|
2002-10-13 04:52:50 +04:00
|
|
|
for any positive matches.
|
|
|
|
If
|
2001-07-01 08:11:13 +04:00
|
|
|
.Fa func
|
2002-10-13 04:52:50 +04:00
|
|
|
is
|
|
|
|
.Dv NULL ,
|
|
|
|
then the parent should record the return value from
|
2001-07-01 08:11:13 +04:00
|
|
|
.Fn config_search
|
|
|
|
and call
|
|
|
|
.Fn config_attach
|
|
|
|
itself.
|
|
|
|
.Pp
|
|
|
|
Note that this function is designed so that it can be used to apply an
|
2002-10-13 04:52:50 +04:00
|
|
|
arbitrary function to all potential children.
|
|
|
|
In this case callers may choose to ignore the return value.
|
2001-07-01 08:11:13 +04:00
|
|
|
.It Fn config_found_sm "parent" "aux" "print" "submatch"
|
|
|
|
Performs direct configuration on a physical device.
|
|
|
|
.Fn config_found_sm
|
|
|
|
is called by the parent and in turn calls the
|
|
|
|
.Fa submatch
|
|
|
|
function to call the match function as
|
2002-10-13 04:52:50 +04:00
|
|
|
determined by the configuration table.
|
|
|
|
If
|
2001-07-01 08:11:13 +04:00
|
|
|
.Fa submatch
|
2002-10-13 04:52:50 +04:00
|
|
|
is
|
|
|
|
.Dv NULL ,
|
|
|
|
the driver match functions are called directly.
|
|
|
|
The argument
|
2001-07-01 08:11:13 +04:00
|
|
|
.Fa parent
|
2002-10-13 04:52:50 +04:00
|
|
|
is the pointer to the parent's device structure.
|
|
|
|
The given
|
2001-07-01 08:11:13 +04:00
|
|
|
.Fa aux
|
2002-10-13 04:52:50 +04:00
|
|
|
argument describes the device that has been found.
|
|
|
|
The
|
2001-07-01 08:11:13 +04:00
|
|
|
.Em softc
|
|
|
|
structure for the matched device will be allocated, and the
|
2002-10-13 04:52:50 +04:00
|
|
|
appropriate driver attach function will be called.
|
|
|
|
If the device is matched, the system prints the name of the child and
|
|
|
|
parent devices, and then calls the
|
2001-07-01 08:11:13 +04:00
|
|
|
.Fa print
|
2002-10-13 04:52:50 +04:00
|
|
|
function to produce additional information if desired.
|
|
|
|
If no driver takes a match, the same
|
2001-07-01 08:11:13 +04:00
|
|
|
.Fa print
|
2002-10-13 04:52:50 +04:00
|
|
|
function is called to complain.
|
|
|
|
The print function is called with the
|
2001-07-01 08:11:13 +04:00
|
|
|
.Fa aux
|
|
|
|
argument and, if the matches failed, the full name (including unit
|
2002-10-13 04:52:50 +04:00
|
|
|
number) of the parent device, otherwise
|
|
|
|
.Dv NULL .
|
|
|
|
The
|
2001-07-01 08:11:13 +04:00
|
|
|
.Fa print
|
|
|
|
function must return an integer value.
|
|
|
|
.Pp
|
|
|
|
Two special strings,
|
|
|
|
.Do
|
2002-10-14 17:43:14 +04:00
|
|
|
not configured
|
2001-07-01 08:11:13 +04:00
|
|
|
.Dc
|
|
|
|
and
|
|
|
|
.Do
|
2002-10-14 17:43:14 +04:00
|
|
|
unsupported
|
2001-07-01 08:11:13 +04:00
|
|
|
.Dc
|
|
|
|
will be appended automatically to non-driver reports if the return
|
2001-09-05 09:37:41 +04:00
|
|
|
value is UNCONF or UNSUPP respectively; otherwise the function should
|
2001-09-04 06:51:15 +04:00
|
|
|
return the value QUIET.
|
2001-07-01 08:11:13 +04:00
|
|
|
.Pp
|
|
|
|
.Fn config_found_sm
|
2001-09-14 01:41:01 +04:00
|
|
|
returns a pointer to the attached device's
|
|
|
|
.Em softc
|
2002-10-13 04:52:50 +04:00
|
|
|
structure if the device is attached,
|
|
|
|
.Dv NULL
|
|
|
|
otherwise.
|
|
|
|
Most callers can ignore this value, since the system will already have
|
|
|
|
printed a diagnostic.
|
2001-07-01 08:11:13 +04:00
|
|
|
.It Fn config_found "parent" "aux" "print"
|
|
|
|
This function is equivalent to calling
|
|
|
|
.Fn config_found_sm "parent" "aux" "print" "submatch"
|
2001-08-17 10:22:46 +04:00
|
|
|
with
|
|
|
|
.Fa submatch
|
2002-10-13 04:52:50 +04:00
|
|
|
set to
|
|
|
|
.Dv NULL
|
|
|
|
and is provided for compatibility with older drivers.
|
2002-10-05 09:39:35 +04:00
|
|
|
.It Fn config_match "parent" "cf" "aux"
|
2002-10-13 04:52:50 +04:00
|
|
|
Match a device.
|
|
|
|
Invokes the drivers match function according to the
|
|
|
|
configuration table.
|
|
|
|
The
|
2002-10-05 09:39:35 +04:00
|
|
|
.Fn config_match
|
|
|
|
function returns a nonzero integer indicating the confidence of
|
|
|
|
supporting this device and a value of 0 if the driver doesn't support
|
|
|
|
the device.
|
2001-07-01 08:11:13 +04:00
|
|
|
.It Fn config_attach "parent" "cf" "aux" "print"
|
2002-10-13 04:52:50 +04:00
|
|
|
Attach a found device.
|
|
|
|
Allocates the memory for the
|
2001-07-01 08:11:13 +04:00
|
|
|
.Em softc
|
|
|
|
structure and calls the drivers attach function according to the
|
|
|
|
configuration table.
|
2001-09-14 01:41:01 +04:00
|
|
|
If successful,
|
|
|
|
.Fn config_attach
|
|
|
|
returns the
|
|
|
|
.Em softc .
|
2002-10-13 04:52:50 +04:00
|
|
|
If unsuccessful, it returns
|
|
|
|
.Dv NULL .
|
2001-07-01 08:11:13 +04:00
|
|
|
.It Fn config_detach "dev" "flags"
|
2002-10-13 04:52:50 +04:00
|
|
|
Called by the parent to detach the child device.
|
|
|
|
The second argument
|
2001-07-01 08:11:13 +04:00
|
|
|
.Em flags
|
2002-10-13 04:52:50 +04:00
|
|
|
contains detachment flags.
|
|
|
|
Valid values are DETACH_FORCE (force detachment (e.g., because of hardware
|
|
|
|
removal)) and DETACH_QUIET (do not print a notice).
|
2001-07-01 08:11:13 +04:00
|
|
|
.Fn config_detach
|
|
|
|
returns zero if successful and an error code otherwise.
|
2001-10-18 23:35:25 +04:00
|
|
|
.Fn config_detach
|
|
|
|
is always called from a thread context, allowing
|
|
|
|
.Xr sleep 9
|
|
|
|
to be called while the device detaches itself.
|
2001-07-01 08:11:13 +04:00
|
|
|
.It Fn config_activate "dev"
|
|
|
|
Called by the parent to activate the child device
|
|
|
|
.Fa dev .
|
2001-10-18 23:35:25 +04:00
|
|
|
It is called to activate resources and initialise other kernel
|
|
|
|
subsystems (such as the network subsystem).
|
|
|
|
.Fn config_activate
|
2002-04-02 18:14:45 +04:00
|
|
|
is called from interrupt context after the device has been attached.
|
2001-07-01 08:11:13 +04:00
|
|
|
.It Fn config_deactivate "dev"
|
|
|
|
Called by the parent to deactivate the child device
|
|
|
|
.Fa dev .
|
2001-10-18 23:35:25 +04:00
|
|
|
.Fn config_deactivate
|
|
|
|
is called from interrupt context to immediately relinquish resources
|
|
|
|
and notify dependent kernel subsystems that the device is about to be
|
2002-10-13 04:52:50 +04:00
|
|
|
detached.
|
|
|
|
At some later point
|
2001-10-18 23:35:25 +04:00
|
|
|
.Fn config_detach
|
|
|
|
will be called to finalise the removal of the device.
|
2001-07-01 08:11:13 +04:00
|
|
|
.It Fn config_defer "dev" "func"
|
|
|
|
Called by the child to defer the remainder of its configuration until
|
2002-10-13 04:52:50 +04:00
|
|
|
all its parent's devices have been attached.
|
|
|
|
At this point, the function
|
2001-07-01 08:11:13 +04:00
|
|
|
.Fa func
|
|
|
|
is called with the argument
|
|
|
|
.Fa dev .
|
|
|
|
.It Fn config_interrupts "struct device *dev" "void (*func)(struct device *)"
|
|
|
|
Called by the child to defer the remainder of its configuration until
|
2002-10-13 04:52:50 +04:00
|
|
|
interrupts are enabled.
|
|
|
|
At this point, the function
|
2001-07-01 08:11:13 +04:00
|
|
|
.Fa func
|
|
|
|
is called with the argument
|
|
|
|
.Fa dev .
|
|
|
|
.It Fn config_pending_incr
|
|
|
|
Increment the
|
|
|
|
.Va config_pending
|
2002-10-13 04:52:50 +04:00
|
|
|
semaphore.
|
|
|
|
It is used to account for deferred configurations before
|
2001-09-05 09:37:41 +04:00
|
|
|
mounting the root file system.
|
2001-07-01 08:11:13 +04:00
|
|
|
.It Fn config_pending_decr
|
|
|
|
Decrement the
|
|
|
|
.Va config_pending
|
2002-10-13 04:52:50 +04:00
|
|
|
semaphore.
|
|
|
|
It is used to account for deferred configurations before
|
2001-09-05 09:37:41 +04:00
|
|
|
mounting the root file system.
|
2001-07-01 08:11:13 +04:00
|
|
|
.El
|
|
|
|
.Sh CODE REFERENCES
|
|
|
|
This section describes places within the
|
|
|
|
.Nx
|
|
|
|
source tree where actual code implementing or utilising the
|
2002-10-13 04:52:50 +04:00
|
|
|
autoconfiguration framework can be found.
|
|
|
|
All pathnames are relative to
|
2001-07-01 08:11:13 +04:00
|
|
|
.Pa /usr/src .
|
|
|
|
.Pp
|
|
|
|
The autoconfiguration framework itself is implemented within the file
|
|
|
|
.Pa sys/kern/subr_autoconf.c .
|
|
|
|
Data structures and function prototypes for the framework are located in
|
|
|
|
.Pa sys/sys/device.h .
|
|
|
|
.Sh SEE ALSO
|
|
|
|
.Xr config 8 ,
|
|
|
|
.Xr config 9 ,
|
2001-09-05 09:37:41 +04:00
|
|
|
.Xr driver 9
|
2001-07-01 08:11:13 +04:00
|
|
|
.Sh HISTORY
|
|
|
|
Autoconfiguration first appeared in
|
|
|
|
.Bx 4.1 .
|
|
|
|
The autoconfiguration framework was completely revised in
|
|
|
|
.Bx 4.4 .
|
2001-10-18 23:35:25 +04:00
|
|
|
The detach and activate/deactivate interfaces appeared in
|
2001-07-01 08:11:13 +04:00
|
|
|
.Nx 1.5 .
|