module.h revision 25537
125537Sdfr/*- 225537Sdfr * Copyright (c) 1997 Doug Rabson 325537Sdfr * All rights reserved. 425537Sdfr * 525537Sdfr * Redistribution and use in source and binary forms, with or without 625537Sdfr * modification, are permitted provided that the following conditions 725537Sdfr * are met: 825537Sdfr * 1. Redistributions of source code must retain the above copyright 925537Sdfr * notice, this list of conditions and the following disclaimer. 1025537Sdfr * 2. Redistributions in binary form must reproduce the above copyright 1125537Sdfr * notice, this list of conditions and the following disclaimer in the 1225537Sdfr * documentation and/or other materials provided with the distribution. 1325537Sdfr * 1425537Sdfr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1525537Sdfr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1625537Sdfr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1725537Sdfr * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1825537Sdfr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1925537Sdfr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2025537Sdfr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2125537Sdfr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2225537Sdfr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2325537Sdfr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2425537Sdfr * SUCH DAMAGE. 2525537Sdfr * 2625537Sdfr * $Id$ 2725537Sdfr */ 2825537Sdfr 2925537Sdfr#ifndef _SYS_MODULE_H_ 3025537Sdfr#define _SYS_MODULE_H_ 3125537Sdfr 3225537Sdfr#ifdef KERNEL 3325537Sdfr 3425537Sdfrtypedef enum { 3525537Sdfr MOD_LOAD, 3625537Sdfr MOD_UNLOAD, 3725537Sdfr MOD_SHUTDOWN 3825537Sdfr} modeventtype_t; 3925537Sdfr 4025537Sdfrstruct module; 4125537Sdfrtypedef struct module *module_t; 4225537Sdfr 4325537Sdfrtypedef int (*modeventhand_t)(module_t mod, modeventtype_t what, void *arg); 4425537Sdfr 4525537Sdfr/* 4625537Sdfr * Struct for registering modules statically via SYSINIT. 4725537Sdfr */ 4825537Sdfrtypedef struct moduledata { 4925537Sdfr char* name; /* module name */ 5025537Sdfr modeventhand_t evhand; /* event handler */ 5125537Sdfr void* priv; /* extra data */ 5225537Sdfr} moduledata_t; 5325537Sdfr 5425537Sdfr#define DECLARE_MODULE(name, data, sub, order) \ 5525537SdfrSYSINIT(name##module, sub, order, module_register_static, &data) 5625537Sdfr 5725537Sdfrvoid module_register_static(void *data); 5825537Sdfrint module_register(const char *name, modeventhand_t callback, void *arg); 5925537Sdfrmodule_t module_lookupbyname(const char *name); 6025537Sdfrmodule_t module_lookupbyid(int modid); 6125537Sdfrvoid module_reference(module_t mod); 6225537Sdfrvoid module_release(module_t mod); 6325537Sdfrint module_unload(module_t mod); 6425537Sdfrint module_getid(module_t mod); 6525537Sdfrmodule_t module_getfnext(module_t mod); 6625537Sdfr 6725537Sdfr#ifdef MOD_DEBUG 6825537Sdfr 6925537Sdfrextern int mod_debug; 7025537Sdfr#define MOD_DEBUG_REFS 1 7125537Sdfr 7225537Sdfr#define MOD_DPF(cat, args) \ 7325537Sdfr do { \ 7425537Sdfr if (mod_debug & MOD_DEBUG_##cat) printf args; \ 7525537Sdfr } while (0) 7625537Sdfr 7725537Sdfr#else 7825537Sdfr 7925537Sdfr#define MOD_DPF(cat, args) 8025537Sdfr 8125537Sdfr#endif 8225537Sdfr 8325537Sdfr#endif /* KERNEL */ 8425537Sdfr 8525537Sdfr#define MAXMODNAME 32 8625537Sdfr 8725537Sdfrstruct module_stat { 8825537Sdfr int version; /* set to sizeof(struct module_stat) */ 8925537Sdfr char name[MAXMODNAME]; 9025537Sdfr int refs; 9125537Sdfr int id; 9225537Sdfr}; 9325537Sdfr 9425537Sdfr#ifndef KERNEL 9525537Sdfr 9625537Sdfr#include <sys/cdefs.h> 9725537Sdfr 9825537Sdfr__BEGIN_DECLS 9925537Sdfrint modnext(int modid); 10025537Sdfrint modfnext(int modid); 10125537Sdfrint modstat(int modid, struct module_stat* stat); 10225537Sdfrint modfind(char *name); 10325537Sdfr__END_DECLS 10425537Sdfr 10525537Sdfr#endif 10625537Sdfr 10725537Sdfr#endif /* !_SYS_MODULE_H_ */ 108