xref: /dragonfly/share/man/man9/driver.9 (revision 92fc8b5c)
1.\" Copyright (c) 1998 Doug Rabson
2.\"
3.\" All rights reserved.
4.\"
5.\" This program is free software.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
17.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
20.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26.\"
27.\" $FreeBSD: src/share/man/man9/driver.9,v 1.3.2.3 2001/08/17 13:08:54 ru Exp $
28.\" $DragonFly: src/share/man/man9/driver.9,v 1.3 2004/06/01 11:36:53 hmp Exp $
29.\"
30.Dd June 16, 1998
31.Dt DRIVER 9
32.Os
33.Sh NAME
34.Nm driver
35.Nd structure describing a device driver
36.Sh SYNOPSIS
37.Bd -literal
38#include <sys/param.h>
39#include <sys/bus.h>
40#include <sys/kernel.h>
41#include <sys/module.h>
42
43static int foo_probe(device_t);
44static int foo_attach(device_t);
45static int foo_detach(device_t);
46static int foo_frob(device_t, int, int);
47static int foo_twiddle(device_t, char *);
48
49struct foo_softc {
50};
51
52static device_method_t foo_methods[] = {
53	/* Methods from the device interface */
54	DEVMETHOD(device_probe,		foo_probe),
55	DEVMETHOD(device_attach,	foo_attach),
56	DEVMETHOD(device_detach,	foo_detach),
57
58	/* Methods from the bogo interface */
59	DEVMETHOD(bogo_frob,		foo_frob),
60	DEVMETHOD(bogo_twiddle,		foo_twiddle),
61
62	/* Terminate method list */
63	{ 0, 0 }
64};
65
66static driver_t foo_driver = {
67	"foo",
68	foo_methods,
69	sizeof(struct foo_softc)
70};
71
72static devclass_t foo_devclass;
73
74DRIVER_MODULE(foo, bogo, foo_driver, foo_devclass, 0, 0);
75.Ed
76.Sh DESCRIPTION
77Each driver in the kernel is described by a
78.Vt driver_t
79structure.  The structure contains the name of the device, a pointer
80to a list of methods, an indication of the kind of device which the
81driver implements and the size of the private data which the driver
82needs to associate with a device instance.  Each driver will implement
83one or more sets of methods (called interfaces).  The example driver
84implements the standard "driver" interface and the fictitious "bogo"
85interface.
86.Pp
87When a driver is registered with the system (by the
88.Dv DRIVER_MODULE
89macro, see
90.Xr DRIVER_MODULE 9 ) ,
91it is added to the list of drivers contained in the devclass
92of its parent bus type.  For instance all PCI drivers would be
93contained in the devclass named "pci" and all ISA drivers would be
94in the devclass named "isa".
95The reason the drivers are not held in the device object of the parent
96bus is to handle multiple instances of a given type of bus.
97The
98.Dv DRIVER_MODULE
99macro will also create the devclass with the name of the driver and
100can optionally call extra initialisation code in the driver by
101specifying an extra module event handler and argument as the last two
102arguments.
103.Sh SEE ALSO
104.Xr devclass 9 ,
105.Xr device 9 ,
106.Xr DRIVER_MODULE 9
107.Sh AUTHORS
108This man page was written by
109.An Doug Rabson .
110