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: src/share/man/man9/DEV_MODULE.9,v 1.1.2.3 2001/12/17 11:30:18 ru Exp $ 30.\" $DragonFly: src/share/man/man9/DEV_MODULE.9,v 1.2 2003/06/17 04:37:01 dillon Exp $ 31.\" 32.Dd March 11, 2001 33.Dt DEV_MODULE 9 34.Os 35.Sh NAME 36.Nm DEV_MODULE 37.Nd device driver module declaration macro 38.Sh SYNOPSIS 39.In sys/module.h 40.In sys/conf.h 41.Fn DEV_MODULE "name" "modeventhand_t evh" "void *arg" 42.Sh DESCRIPTION 43The 44.Fn DEV_MODULE 45macro declares a device driver kernel module. 46It fills in a 47.Vt moduledata_t 48structure and then calls 49.Fn DECLARE_MODULE 50with the correct args, where 51.Fa name 52is the name of the module and 53.Fa evh 54(with its argument 55.Fa arg ) 56is the event handler for the module (refer to 57.Xr DECLARE_MODULE 9 58for more information). 59The event handler is supposed to create the device with 60.Fn make_dev 61on load and to destroy it when it is unloaded using 62.Fn destroy_dev . 63.Sh EXAMPLES 64.Bd -literal 65#include <sys/module.h> 66#include <sys/conf.h> 67 68static struct cdevsw foo_devsw = { ... }; 69 70static dev_t sdev; 71 72static int 73foo_load(module_t mod, int cmd, void *arg) 74{ 75 int err = 0; 76 77 switch (cmd) { 78 case MOD_LOAD: 79 sdev = make_dev(&foo_devsw, 0, UID_ROOT, GID_WHEEL, 0600, "foo"); 80 break; /* Success*/ 81 82 case MOD_UNLOAD: 83 case MOD_SHUTDOWN: 84 destroy_dev(sdev); 85 break; /* Success*/ 86 87 default: 88 err = EINVAL; 89 break; 90 } 91 92 return(err); 93} 94 95DEV_MODULE(foo, foo_load, NULL); 96.Ed 97.Sh SEE ALSO 98.Xr DECLARE_MODULE 9 , 99.Xr destroy_dev 9 , 100.Xr make_dev 9 , 101.Xr module 9 102.Sh AUTHORS 103This manual page was written by 104.An Alexander Langer Aq alex@FreeBSD.org . 105