Subject: Re: HowTo write hw driver
To: None <>
From: Hubert Feyrer <>
List: tech-kern
Date: 10/16/2001 00:55:00
On Mon, 15 Oct 2001 wrote:
> [jkunz@MissSophie jkunz]$ man 9 autoconf
> man: no entry for autoconf in the manual.
> Or is there one in -current?

Yes, see below. The description for config_(de)activate activation could
be somewhat more detailled, though.

 - Hubert

miyu% nroff -man /usr/cvs/src-current/share/man/man9/autoconf.9
AUTOCONF(9)                  NetBSD Kernel Manual                  AUTOCONF(9)

     autoconf, config_search, config_found_sm, config_found, config_attach,
     config_detach, config_activate, config_deactivate, config_defer,
     config_interrupts, config_pending_incr, config_pending_decr - autoconfig-
     uration framework

     #include <sys/param.h>
     #include <sys/device.h>
     #include <sys/error.h>

     struct cfdata *
     config_search(cfmatch_t func, struct device *parent, void *aux);

     struct device *
     config_found_sm(struct device *parent, void *aux, cfprint_t print,
             cfmatch_t submatch);

     struct device *
     config_found(struct device *parent, void *aux, cfprint_t print);

     struct device *
     config_attach(struct device *parent, struct cfdata *cf, void *aux,
             cfprint_t print);

     config_detach(struct device *dev, int flags);

     config_activate(struct device *dev);

     config_deactivate(struct device *dev);

     config_defer(struct device *dev, void (*func)(struct device *));

     config_interrupts(struct device *dev, void (*func)(struct device *));



     Autoconfiguration is the process of matching hardware devices with an ap-
     propriate device driver.  In its most basic form, autoconfiguration con-
     sists of the recursive process of finding and attaching all devices on a
     bus, including other busses.

     The autoconfiguration framework supports direct configuration where the
     bus driver can determine the devices present.  The autoconfiguration
     framework also supports indirect configuration where the drivers must
     probe the bus looking the presence of a device.  Direct configuration is
     preferred since it can find hardware regardless of the presence of proper

     The autoconfiguration process occurs at system bootstrap and is driven by
     a table generated from a ``device definition'' file by config(8).  For a
     description of the config(8) ``machine description'' language, see

     Each device must have a name consisting of an alphanumeric string that
     ends with a unit number.  The unit number identifies an instance of the
     driver.  Device data structures are allocated dynamically during autocon-
     figuration, giving a unique address for each instance.

     config_search(func, parent, aux)
              Performs indirect configuration of physical devices.
              config_search() iterates over all potential children, calling
              the given function func for each one.  If func is NULL,
              config_search() applies each child's match function instead.
              The argument parent is the pointer to the parent's device struc-
              ture.  The given aux argument describes the device that has been
              found and is simply passed on through func to the child.
              config_search() returns a pointer to the best-matched child or
              NULL otherwise.

              The role of func is to call the match function for each device
              and call config_attach() for any positive matches.  If func is
              NULL, then the parent should record the return value from
              config_search() and call config_attach() itself.

              Note that this function is designed so that it can be used to
              apply an arbitrary function to all potential children.  In this
              case callers may choose to ignore the return value.

     config_found_sm(parent, aux, print, submatch)
              Performs direct configuration on a physical device.
              config_found_sm() is called by the parent and in turn calls the
              submatch function to call the match function as determined by
              the configuration table.  If submatch is NULL, the driver match
              functions are called directly.  The argument parent is the
              pointer to the parent's device structure.  The given aux argu-
              ment describes the device that has been found.  The softc struc-
              ture for the matched device will be allocated, and the appropri-
              ate driver attach function will be called.  If the device is
              matched, the system prints the name of the child and parent de-
              vices, and then calls the print function to produce addition in-
              formation if desired.  If no driver takes a match, the same
              print function is called to complain.  The print function is
              called with the aux argument and, if the matches failed, the
              full name (including unit number) of the parent device, other-
              wise NULL.  The print function must return an integer value.

              Two special strings, `` not configured'' and `` unsupported''
              will be appended automatically to non-driver reports if the re-
              turn value is UNCONF or UNSUPP respectively; otherwise the func-
              tion should return the value QUIET.

              config_found_sm() returns a pointer to the attached device's
              softc structure if the device is attached, NULL otherwise.  Most
              callers can ignore this value, since the system will already
              have printed a diagnostic.

     config_found(parent, aux, print)
              This function is equivalent to calling config_found_sm(parent,
              aux, print, submatch) with submatch set to NULL and is provided
              for compatibility with older drivers.

     config_attach(parent, cf, aux, print)
              Attach a found device.  Allocates the memory for the softc
              structure and calls the drivers attach function according to the
              configuration table.  If successful, config_attach() returns the
              softc.  If unsuccessful, it returns NULL.

     config_detach(dev, flags)
              Called by the parent to detach the child device.  The second ar-
              gument flags contains detachment flags.  Valid values are DE-
              TACH_FORCE (force detachment (eg. because of hardware removal)
              and DETACH_QUIET (do not print a notice).  config_detach() re-
              turns zero if successful and an error code otherwise.

              Called by the parent to activate the child device dev.

              Called by the parent to deactivate the child device dev.

     config_defer(dev, func)
              Called by the child to defer the remainder of its configuration
              until all its parent's devices have been attached.  At this
              point, the function func is called with the argument dev.

     config_interrupts(struct device *dev, void (*func)(struct device *))
              Called by the child to defer the remainder of its configuration
              until interrupts are enabled.  At this point, the function func
              is called with the argument dev.

              Increment the config_pending semaphore.  It is used to account
              for deferred configurations before mounting the root file sys-

              Decrement the config_pending semaphore.  It is used to account
              for deferred configurations before mounting the root file sys-

     This section describes places within the NetBSD source tree where actual
     code implementing or utilising the autoconfiguration framework can be
     found.  All pathnames are relative to /usr/src.

     The autoconfiguration framework itself is implemented within the file
     sys/kern/subr_autoconf.c.  Data structures and function prototypes for
     the framework are located in sys/sys/device.h.

     config(8), config(9), driver(9)

     Autoconfiguration first appeared in 4.1BSD.  The autoconfiguration frame-
     work was completely revised in 4.4BSD.  The detach and activate inter-
     faces appeared in NetBSD 1.5.

NetBSD 1.5.2                     June 17, 2001                               3

 - Hubert
Want to get a clue on IPv6 but don't know where to start? Try this:
* Basics ->
* Setup  -> 
Of course with your #1 IPv6 ready operating system ->