3 .\" Copyright (c) 1998 Doug Rabson
5 .\" All rights reserved.
7 .\" This program is free software.
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
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.
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.
36 .Nd structure describing a device driver
39 #include <sys/param.h>
40 #include <sys/kernel.h>
42 #include <sys/module.h>
44 static int foo_probe(device_t);
45 static int foo_attach(device_t);
46 static int foo_detach(device_t);
47 static int foo_frob(device_t, int, int);
48 static int foo_twiddle(device_t, char *);
50 static device_method_t foo_methods[] = {
51 /* Methods from the device interface */
52 DEVMETHOD(device_probe, foo_probe),
53 DEVMETHOD(device_attach, foo_attach),
54 DEVMETHOD(device_detach, foo_detach),
56 /* Methods from the bogo interface */
57 DEVMETHOD(bogo_frob, foo_frob),
58 DEVMETHOD(bogo_twiddle, foo_twiddle),
60 /* Terminate method list */
64 static driver_t foo_driver = {
66 .methods = foo_methods,
67 .size = sizeof(struct foo_softc)
70 static devclass_t foo_devclass;
72 DRIVER_MODULE(foo, bogo, foo_driver, foo_devclass, NULL, NULL);
75 Each driver in the kernel is described by a
78 The structure contains the name of the device, a pointer
79 to a list of methods, an indication of the kind of device which the
80 driver implements and the size of the private data which the driver
81 needs to associate with a device instance.
82 Each driver will implement
83 one or more sets of methods (called interfaces).
85 implements the standard "driver" interface and the fictitious "bogo"
88 When a driver is registered with the system (by the
91 .Xr DRIVER_MODULE 9 ) ,
92 it is added to the list of drivers contained in the devclass
93 of its parent bus type.
94 For instance all PCI drivers would be
95 contained in the devclass named "pci" and all ISA drivers would be
96 in the devclass named "isa".
97 The reason the drivers are not held in the device object of the parent
98 bus is to handle multiple instances of a given type of bus.
101 macro will also create the devclass with the name of the driver and
102 can optionally call extra initialisation code in the driver by
103 specifying an extra module event handler and argument as the last two
108 .Xr DEVICE_ATTACH 9 ,
109 .Xr DEVICE_DETACH 9 ,
110 .Xr DEVICE_IDENTIFY 9 ,
112 .Xr DEVICE_SHUTDOWN 9 ,
115 This manual page was written by