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