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