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