xref: /freebsd/share/man/man9/DEV_MODULE.9 (revision 8ddb146abcdf061be9f2c0db7e391697dafad85c)
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
44The
45.Fn DEV_MODULE
46macro declares a device driver kernel module.
47It fills in a
48.Vt moduledata_t
49structure and then calls
50.Fn DECLARE_MODULE
51with the correct args, where
52.Fa name
53is the name of the module and
54.Fa evh
55(with its argument
56.Fa arg )
57is the event handler for the module (refer to
58.Xr DECLARE_MODULE 9
59for more information).
60The event handler is supposed to create the device with
61.Fn make_dev
62on 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
69static struct cdevsw foo_devsw = { ... };
70
71static struct cdev *sdev;
72
73static int
74foo_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
96DEV_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
104This manual page was written by
105.An Alexander Langer Aq Mt alex@FreeBSD.org .
106