summaryrefslogtreecommitdiff
path: root/static/freebsd/man9/DEV_MODULE.9 4.html
blob: 5acd33df094eb62ef373b6ff8384e7dd7a5dff8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<table class="head">
  <tr>
    <td class="head-ltitle">DEV_MODULE(9)</td>
    <td class="head-vol">Kernel Developer's Manual</td>
    <td class="head-rtitle">DEV_MODULE(9)</td>
  </tr>
</table>
<div class="manual-text">
<section class="Sh">
<h1 class="Sh" id="NAME"><a class="permalink" href="#NAME">NAME</a></h1>
<p class="Pp"><code class="Nm">DEV_MODULE</code> &#x2014;
    <span class="Nd">device driver module declaration macro</span></p>
</section>
<section class="Sh">
<h1 class="Sh" id="SYNOPSIS"><a class="permalink" href="#SYNOPSIS">SYNOPSIS</a></h1>
<p class="Pp"><code class="In">#include
    &lt;<a class="In">sys/param.h</a>&gt;</code>
  <br/>
  <code class="In">#include &lt;<a class="In">sys/kernel.h</a>&gt;</code>
  <br/>
  <code class="In">#include &lt;<a class="In">sys/module.h</a>&gt;</code>
  <br/>
  <code class="In">#include &lt;<a class="In">sys/conf.h</a>&gt;</code></p>
<p class="Pp"><code class="Fn">DEV_MODULE</code>(<var class="Fa" style="white-space: nowrap;">name</var>,
    <var class="Fa" style="white-space: nowrap;">modeventhand_t evh</var>,
    <var class="Fa" style="white-space: nowrap;">void *arg</var>);</p>
</section>
<section class="Sh">
<h1 class="Sh" id="DESCRIPTION"><a class="permalink" href="#DESCRIPTION">DESCRIPTION</a></h1>
<p class="Pp">The
    <a class="permalink" href="#DEV_MODULE"><code class="Fn" id="DEV_MODULE">DEV_MODULE</code></a>()
    macro declares a device driver kernel module. It fills in a
    <var class="Vt">moduledata_t</var> structure and then calls
    <a class="permalink" href="#DECLARE_MODULE"><code class="Fn" id="DECLARE_MODULE">DECLARE_MODULE</code></a>()
    with the correct args, where <var class="Fa">name</var> is the name of the
    module and <var class="Fa">evh</var> (with its argument
    <var class="Fa">arg</var>) is the event handler for the module (refer to
    <a class="Xr">DECLARE_MODULE(9)</a> for more information). The event handler
    is supposed to create the device with
    <a class="permalink" href="#make_dev"><code class="Fn" id="make_dev">make_dev</code></a>()
    on load and to destroy it when it is unloaded using
    <a class="permalink" href="#destroy_dev"><code class="Fn" id="destroy_dev">destroy_dev</code></a>().</p>
</section>
<section class="Sh">
<h1 class="Sh" id="EXAMPLES"><a class="permalink" href="#EXAMPLES">EXAMPLES</a></h1>
<div class="Bd Li">
<pre>#include &lt;sys/module.h&gt;
#include &lt;sys/conf.h&gt;

static struct cdevsw foo_devsw = { ... };

static struct cdev *sdev;

static int
foo_load(module_t mod, int cmd, void *arg)
{
    int err = 0;

    switch (cmd) {
    case MOD_LOAD:
        sdev = make_dev(&amp;foo_devsw, 0, UID_ROOT, GID_WHEEL, 0600, &quot;foo&quot;);
        break;          /* Success*/

    case MOD_UNLOAD:
    case MOD_SHUTDOWN:
        destroy_dev(sdev);
        break;          /* Success*/

    default:
        err = EINVAL;
        break;
    }

    return(err);
}

DEV_MODULE(foo, foo_load, NULL);</pre>
</div>
</section>
<section class="Sh">
<h1 class="Sh" id="SEE_ALSO"><a class="permalink" href="#SEE_ALSO">SEE
  ALSO</a></h1>
<p class="Pp"><a class="Xr">DECLARE_MODULE(9)</a>,
    <a class="Xr">destroy_dev(9)</a>, <a class="Xr">make_dev(9)</a>,
    <a class="Xr">module(9)</a></p>
</section>
<section class="Sh">
<h1 class="Sh" id="AUTHORS"><a class="permalink" href="#AUTHORS">AUTHORS</a></h1>
<p class="Pp">This manual page was written by <span class="An">Alexander
    Langer</span>
    &lt;<a class="Mt" href="mailto:alex@FreeBSD.org">alex@FreeBSD.org</a>&gt;.</p>
</section>
</div>
<table class="foot">
  <tr>
    <td class="foot-date">January 19, 2012</td>
    <td class="foot-os">FreeBSD 15.0</td>
  </tr>
</table>