]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - share/man/man9/DEV_MODULE.9
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / share / man / man9 / DEV_MODULE.9
1 .\" -*- nroff -*-
2 .\"
3 .\" Copyright (c) 2001 Alexander Langer
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 January 19, 2012
32 .Dt DEV_MODULE 9
33 .Os
34 .Sh NAME
35 .Nm DEV_MODULE
36 .Nd device driver module declaration macro
37 .Sh SYNOPSIS
38 .In sys/param.h
39 .In sys/kernel.h
40 .In sys/module.h
41 .In sys/conf.h
42 .Fn DEV_MODULE "name" "modeventhand_t evh" "void *arg"
43 .Sh DESCRIPTION
44 The
45 .Fn DEV_MODULE
46 macro declares a device driver kernel module.
47 It fills in a
48 .Vt moduledata_t
49 structure and then calls
50 .Fn DECLARE_MODULE
51 with the correct args, where
52 .Fa name
53 is the name of the module and
54 .Fa evh
55 (with its argument
56 .Fa arg )
57 is the event handler for the module (refer to
58 .Xr DECLARE_MODULE 9
59 for more information).
60 The event handler is supposed to create the device with
61 .Fn make_dev
62 on load and to destroy it when it is unloaded using
63 .Fn destroy_dev .
64 .Sh EXAMPLES
65 .Bd -literal
66 #include <sys/module.h>
67 #include <sys/conf.h>
68
69 static struct cdevsw foo_devsw = { ... };
70
71 static struct cdev *sdev;
72
73 static int
74 foo_load(module_t mod, int cmd, void *arg)
75 {
76     int err = 0;
77
78     switch (cmd) {
79     case MOD_LOAD:
80         sdev = make_dev(&foo_devsw, 0, UID_ROOT, GID_WHEEL, 0600, "foo");
81         break;          /* Success*/
82
83     case MOD_UNLOAD:
84     case MOD_SHUTDOWN:
85         destroy_dev(sdev);
86         break;          /* Success*/
87
88     default:
89         err = EINVAL;
90         break;
91     }
92
93     return(err);
94 }
95
96 DEV_MODULE(foo, foo_load, NULL);
97 .Ed
98 .Sh SEE ALSO
99 .Xr DECLARE_MODULE 9 ,
100 .Xr destroy_dev 9 ,
101 .Xr make_dev 9 ,
102 .Xr module 9
103 .Sh AUTHORS
104 This manual page was written by
105 .An Alexander Langer Aq alex@FreeBSD.org .