File:  [DragonFly] / src / share / man / man9 / driver.9
Revision 1.2: download - view: text, annotated - select for diffs
Tue Jun 17 04:37:01 2003 UTC (11 years, 2 months ago) by dillon
Branches: MAIN
CVS tags: HEAD
Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids.  Most
ids have been removed from !lint sections and moved into comment sections.

    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: .\" $FreeBSD: src/share/man/man9/driver.9,v 1.3.2.3 2001/08/17 13:08:54 ru Exp $
   30: .\" $DragonFly: src/share/man/man9/driver.9,v 1.2 2003/06/17 04:37:01 dillon Exp $
   31: .\"
   32: .Dd June 16, 1998
   33: .Dt DRIVER 9
   34: .Os
   35: .Sh NAME
   36: .Nm driver
   37: .Nd structure describing a device driver
   38: .Sh SYNOPSIS
   39: .Bd -literal
   40: #include <sys/param.h>
   41: #include <sys/bus.h>
   42: 
   43: static int foo_probe(device_t);
   44: static int foo_attach(device_t);
   45: static int foo_detach(device_t);
   46: static int foo_frob(device_t, int, int);
   47: static int foo_twiddle(device_t, char *);
   48: 
   49: static struct device_method foo_methods[] = {
   50: 	/* Methods from the device interface */
   51: 	DEVMETHOD(device_probe,		foo_probe),
   52: 	DEVMETHOD(device_attach,	foo_attach),
   53: 	DEVMETHOD(device_detach,	foo_detach),
   54: 
   55: 	/* Methods from the bogo interface */
   56: 	DEVMETHOD(bogo_frob,		foo_frob),
   57: 	DEVMETHOD(bogo_twiddle,		foo_twiddle),
   58: 
   59: 	/* Terminate method list */
   60: 	{ 0, 0 }
   61: };
   62: 
   63: static driver_t foo_driver {
   64: 	"foo",
   65: 	foo_methods,
   66: 	DRIVER_TYPE_MISC,
   67: 	sizeof(struct foo_softc),
   68: };
   69: 
   70: static devclass_t foo_devclass;
   71: 
   72: DRIVER_MODULE(foo, bogo, foo_driver, foo_devclass, 0, 0);
   73: .Ed
   74: .Sh DESCRIPTION
   75: Each driver in the kernel is described by a
   76: .Dv driver_t
   77: structure.  The structure contains the name of the device, a pointer
   78: to a list of methods, an indication of the kind of device which the
   79: driver implements and the size of the private data which the driver
   80: needs to associate with a device instance.  Each driver will implement
   81: one or more sets of methods (called interfaces).  The example driver
   82: implements the standard "driver" interface and the fictitious "bogo"
   83: interface.
   84: .Pp
   85: When a driver is registered with the system (by the
   86: .Dv DRIVER_MODULE
   87: macro, see
   88: .Xr DRIVER_MODULE 9 ) ,
   89: it is added to the list of drivers contained in the devclass
   90: of its parent bus type.  For instance all PCI drivers would be
   91: contained in the devclass named "pci" and all ISA drivers would be
   92: in the devclass named "isa".
   93: The reason the drivers are not held in the device object of the parent
   94: bus is to handle multiple instances of a given type of bus.
   95: The
   96: .Dv DRIVER_MODULE
   97: macro will also create the devclass with the name of the driver and
   98: can optionally call extra initialisation code in the driver by
   99: specifying an extra module event handler and argument as the last two
  100: arguments.
  101: .Sh SEE ALSO
  102: .Xr devclass 9 ,
  103: .Xr device 9 ,
  104: .Xr DRIVER_MODULE 9
  105: .Sh AUTHORS
  106: This man page was written by
  107: .An Doug Rabson .