]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - share/man/man9/driver.9
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / share / man / man9 / driver.9
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$
30 .\"
31 .Dd June 16, 1998
32 .Dt DRIVER 9
33 .Os
34 .Sh NAME
35 .Nm driver
36 .Nd structure describing a device driver
37 .Sh SYNOPSIS
38 .Bd -literal
39 #include <sys/param.h>
40 #include <sys/bus.h>
41
42 static int foo_probe(device_t);
43 static int foo_attach(device_t);
44 static int foo_detach(device_t);
45 static int foo_frob(device_t, int, int);
46 static int foo_twiddle(device_t, char *);
47
48 static device_method_t foo_methods[] = {
49         /* Methods from the device interface */
50         DEVMETHOD(device_probe,         foo_probe),
51         DEVMETHOD(device_attach,        foo_attach),
52         DEVMETHOD(device_detach,        foo_detach),
53
54         /* Methods from the bogo interface */
55         DEVMETHOD(bogo_frob,            foo_frob),
56         DEVMETHOD(bogo_twiddle,         foo_twiddle),
57
58         /* Terminate method list */
59         { 0, 0 }
60 };
61
62 static driver_t foo_driver {
63         "foo",
64         foo_methods,
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.
76 The structure contains the name of the device, a pointer
77 to a list of methods, an indication of the kind of device which the
78 driver implements and the size of the private data which the driver
79 needs to associate with a device instance.
80 Each driver will implement
81 one or more sets of methods (called interfaces).
82 The example driver
83 implements the standard "driver" interface and the fictitious "bogo"
84 interface.
85 .Pp
86 When a driver is registered with the system (by the
87 .Dv DRIVER_MODULE
88 macro, see
89 .Xr DRIVER_MODULE 9 ) ,
90 it is added to the list of drivers contained in the devclass
91 of its parent bus type.
92 For instance all PCI drivers would be
93 contained in the devclass named "pci" and all ISA drivers would be
94 in the devclass named "isa".
95 The reason the drivers are not held in the device object of the parent
96 bus is to handle multiple instances of a given type of bus.
97 The
98 .Dv DRIVER_MODULE
99 macro will also create the devclass with the name of the driver and
100 can optionally call extra initialisation code in the driver by
101 specifying an extra module event handler and argument as the last two
102 arguments.
103 .Sh SEE ALSO
104 .Xr devclass 9 ,
105 .Xr device 9 ,
106 .Xr DEVICE_ATTACH 9 ,
107 .Xr DEVICE_DETACH 9 ,
108 .Xr DEVICE_IDENTIFY 9 ,
109 .Xr DEVICE_PROBE 9 ,
110 .Xr DEVICE_SHUTDOWN 9 ,
111 .Xr DRIVER_MODULE 9
112 .Sh AUTHORS
113 This manual page was written by
114 .An Doug Rabson .