Initial import from FreeBSD RELENG_4:
[dragonfly.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: src/share/man/man9/DEV_MODULE.9,v 1.1.2.3 2001/12/17 11:30:18 ru Exp $
30 .\"
31 .Dd March 11, 2001
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/module.h
39 .In sys/conf.h
40 .Fn DEV_MODULE "name" "modeventhand_t evh" "void *arg"
41 .Sh DESCRIPTION
42 The
43 .Fn DEV_MODULE
44 macro declares a device driver kernel module.
45 It fills in a
46 .Vt moduledata_t
47 structure and then calls
48 .Fn DECLARE_MODULE
49 with the correct args, where
50 .Fa name
51 is the name of the module and
52 .Fa evh
53 (with its argument
54 .Fa arg )
55 is the event handler for the module (refer to
56 .Xr DECLARE_MODULE 9
57 for more information).
58 The event handler is supposed to create the device with
59 .Fn make_dev
60 on load and to destroy it when it is unloaded using
61 .Fn destroy_dev .
62 .Sh EXAMPLES
63 .Bd -literal
64 #include <sys/module.h>
65 #include <sys/conf.h>
66
67 static struct cdevsw foo_devsw = { ... };
68
69 static dev_t sdev;
70
71 static int
72 foo_load(module_t mod, int cmd, void *arg)
73 {
74     int err = 0;
75
76     switch (cmd) {
77     case MOD_LOAD:
78         sdev = make_dev(&foo_devsw, 0, UID_ROOT, GID_WHEEL, 0600, "foo");
79         break;          /* Success*/
80
81     case MOD_UNLOAD:
82     case MOD_SHUTDOWN:
83         destroy_dev(sdev);
84         break;          /* Success*/
85
86     default:
87         err = EINVAL;
88         break;
89     }
90
91     return(err);
92 }
93
94 DEV_MODULE(foo, foo_load, NULL);
95 .Ed
96 .Sh SEE ALSO
97 .Xr DECLARE_MODULE 9 ,
98 .Xr destroy_dev 9 ,
99 .Xr make_dev 9 ,
100 .Xr module 9
101 .Sh AUTHORS
102 This manual page was written by
103 .An Alexander Langer Aq alex@FreeBSD.org .