xref: /freebsd/share/man/man9/DEV_MODULE.9 (revision 8a7314fcb5347f8296a072e0c4f67a9f64303186)
174169a2cSAlexander Langer.\" -*- nroff -*-
274169a2cSAlexander Langer.\"
374169a2cSAlexander Langer.\" Copyright (c) 2001 Alexander Langer
474169a2cSAlexander Langer.\"
574169a2cSAlexander Langer.\" All rights reserved.
674169a2cSAlexander Langer.\"
774169a2cSAlexander Langer.\" This program is free software.
874169a2cSAlexander Langer.\"
974169a2cSAlexander Langer.\" Redistribution and use in source and binary forms, with or without
1074169a2cSAlexander Langer.\" modification, are permitted provided that the following conditions
1174169a2cSAlexander Langer.\" are met:
1274169a2cSAlexander Langer.\" 1. Redistributions of source code must retain the above copyright
1374169a2cSAlexander Langer.\"    notice, this list of conditions and the following disclaimer.
1474169a2cSAlexander Langer.\" 2. Redistributions in binary form must reproduce the above copyright
1574169a2cSAlexander Langer.\"    notice, this list of conditions and the following disclaimer in the
1674169a2cSAlexander Langer.\"    documentation and/or other materials provided with the distribution.
1774169a2cSAlexander Langer.\"
1874169a2cSAlexander Langer.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
1974169a2cSAlexander Langer.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2074169a2cSAlexander Langer.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2174169a2cSAlexander Langer.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
2274169a2cSAlexander Langer.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2374169a2cSAlexander Langer.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2474169a2cSAlexander Langer.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2574169a2cSAlexander Langer.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2674169a2cSAlexander Langer.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2774169a2cSAlexander Langer.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2874169a2cSAlexander Langer.\"
2974169a2cSAlexander Langer.\" $FreeBSD$
3074169a2cSAlexander Langer.\"
315dc6c3a3SEd Schouten.Dd January 19, 2012
3274169a2cSAlexander Langer.Dt DEV_MODULE 9
3374169a2cSAlexander Langer.Os
3474169a2cSAlexander Langer.Sh NAME
3574169a2cSAlexander Langer.Nm DEV_MODULE
3674169a2cSAlexander Langer.Nd device driver module declaration macro
3774169a2cSAlexander Langer.Sh SYNOPSIS
38f16b3c0dSChad David.In sys/param.h
39f16b3c0dSChad David.In sys/kernel.h
4032eef9aeSRuslan Ermilov.In sys/module.h
4132eef9aeSRuslan Ermilov.In sys/conf.h
4274169a2cSAlexander Langer.Fn DEV_MODULE "name" "modeventhand_t evh" "void *arg"
4374169a2cSAlexander Langer.Sh DESCRIPTION
4474169a2cSAlexander LangerThe
4574169a2cSAlexander Langer.Fn DEV_MODULE
4674169a2cSAlexander Langermacro declares a device driver kernel module.
4774169a2cSAlexander LangerIt fills in a
4874169a2cSAlexander Langer.Vt moduledata_t
4974169a2cSAlexander Langerstructure and then calls
5074169a2cSAlexander Langer.Fn DECLARE_MODULE
5174169a2cSAlexander Langerwith the correct args, where
5274169a2cSAlexander Langer.Fa name
5374169a2cSAlexander Langeris the name of the module and
5474169a2cSAlexander Langer.Fa evh
5574169a2cSAlexander Langer(with its argument
5674169a2cSAlexander Langer.Fa arg )
5774169a2cSAlexander Langeris the event handler for the module (refer to
5874169a2cSAlexander Langer.Xr DECLARE_MODULE 9
5974169a2cSAlexander Langerfor more information).
6074169a2cSAlexander LangerThe event handler is supposed to create the device with
6174169a2cSAlexander Langer.Fn make_dev
6274169a2cSAlexander Langeron load and to destroy it when it is unloaded using
6374169a2cSAlexander Langer.Fn destroy_dev .
6474169a2cSAlexander Langer.Sh EXAMPLES
6574169a2cSAlexander Langer.Bd -literal
6674169a2cSAlexander Langer#include <sys/module.h>
6774169a2cSAlexander Langer#include <sys/conf.h>
6874169a2cSAlexander Langer
6974169a2cSAlexander Langerstatic struct cdevsw foo_devsw = { ... };
7074169a2cSAlexander Langer
715dc6c3a3SEd Schoutenstatic struct cdev *sdev;
7274169a2cSAlexander Langer
7374169a2cSAlexander Langerstatic int
7474169a2cSAlexander Langerfoo_load(module_t mod, int cmd, void *arg)
7574169a2cSAlexander Langer{
7674169a2cSAlexander Langer    int err = 0;
7774169a2cSAlexander Langer
7874169a2cSAlexander Langer    switch (cmd) {
7974169a2cSAlexander Langer    case MOD_LOAD:
8074169a2cSAlexander Langer        sdev = make_dev(&foo_devsw, 0, UID_ROOT, GID_WHEEL, 0600, "foo");
8174169a2cSAlexander Langer        break;          /* Success*/
8274169a2cSAlexander Langer
8374169a2cSAlexander Langer    case MOD_UNLOAD:
8474169a2cSAlexander Langer    case MOD_SHUTDOWN:
8574169a2cSAlexander Langer        destroy_dev(sdev);
8674169a2cSAlexander Langer        break;          /* Success*/
8774169a2cSAlexander Langer
8874169a2cSAlexander Langer    default:
8974169a2cSAlexander Langer        err = EINVAL;
9074169a2cSAlexander Langer        break;
9174169a2cSAlexander Langer    }
9274169a2cSAlexander Langer
9374169a2cSAlexander Langer    return(err);
9474169a2cSAlexander Langer}
9574169a2cSAlexander Langer
9674169a2cSAlexander LangerDEV_MODULE(foo, foo_load, NULL);
9774169a2cSAlexander Langer.Ed
9874169a2cSAlexander Langer.Sh SEE ALSO
9974169a2cSAlexander Langer.Xr DECLARE_MODULE 9 ,
1005521ff5aSRuslan Ermilov.Xr destroy_dev 9 ,
10174169a2cSAlexander Langer.Xr make_dev 9 ,
1025521ff5aSRuslan Ermilov.Xr module 9
10374169a2cSAlexander Langer.Sh AUTHORS
10474169a2cSAlexander LangerThis manual page was written by
105*8a7314fcSBaptiste Daroussin.An Alexander Langer Aq Mt alex@FreeBSD.org .
106