xref: /freebsd/share/man/man9/DEV_MODULE.9 (revision 1719886f6d08408b834d270c59ffcfd821c8f63a)
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.Dd January 19, 2012
30.Dt DEV_MODULE 9
31.Os
32.Sh NAME
33.Nm DEV_MODULE
34.Nd device driver module declaration macro
35.Sh SYNOPSIS
36.In sys/param.h
37.In sys/kernel.h
38.In sys/module.h
39.In sys/conf.h
40.Fn DEV_MODULE "name" "modeventhand_t evh" "void *arg"
41.Sh DESCRIPTION
42The
43.Fn DEV_MODULE
44macro declares a device driver kernel module.
45It fills in a
46.Vt moduledata_t
47structure and then calls
48.Fn DECLARE_MODULE
49with the correct args, where
50.Fa name
51is the name of the module and
52.Fa evh
53(with its argument
54.Fa arg )
55is the event handler for the module (refer to
56.Xr DECLARE_MODULE 9
57for more information).
58The event handler is supposed to create the device with
59.Fn make_dev
60on 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
67static struct cdevsw foo_devsw = { ... };
68
69static struct cdev *sdev;
70
71static int
72foo_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
94DEV_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
102This manual page was written by
103.An Alexander Langer Aq Mt alex@FreeBSD.org .
104