module.h revision 36849
1/*-
2 * Copyright (c) 1997 Doug Rabson
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 *	$Id: module.h,v 1.2 1997/10/24 05:29:07 jmg Exp $
27 */
28
29#ifndef _SYS_MODULE_H_
30#define _SYS_MODULE_H_
31
32#ifdef KERNEL
33
34typedef enum {
35    MOD_LOAD,
36    MOD_UNLOAD,
37    MOD_SHUTDOWN
38} modeventtype_t;
39
40struct module;
41typedef struct module *module_t;
42
43typedef int (*modeventhand_t)(module_t mod, modeventtype_t what, void *arg);
44
45/*
46 * Struct for registering modules statically via SYSINIT.
47 */
48typedef struct moduledata {
49    char*		name;	/* module name */
50    modeventhand_t	evhand;	/* event handler */
51    void*		priv;	/* extra data */
52} moduledata_t;
53
54#define DECLARE_MODULE(name, data, sub, order) \
55SYSINIT(name##module, sub, order, module_register_init, &data) \
56struct __hack
57
58void module_register_init(void *data);
59int module_register(const char *name, modeventhand_t callback, void *arg);
60module_t module_lookupbyname(const char *name);
61module_t module_lookupbyid(int modid);
62void module_reference(module_t mod);
63void module_release(module_t mod);
64int module_unload(module_t mod);
65int module_getid(module_t mod);
66module_t module_getfnext(module_t mod);
67
68#ifdef MOD_DEBUG
69
70extern int mod_debug;
71#define MOD_DEBUG_REFS	1
72
73#define MOD_DPF(cat, args)					\
74	do {							\
75		if (mod_debug & MOD_DEBUG_##cat) printf args;	\
76	} while (0)
77
78#else
79
80#define MOD_DPF(cat, args)
81
82#endif
83
84#endif /* KERNEL */
85
86#define MAXMODNAME	32
87
88struct module_stat {
89    int		version;	/* set to sizeof(struct module_stat) */
90    char	name[MAXMODNAME];
91    int		refs;
92    int		id;
93};
94
95#ifndef KERNEL
96
97#include <sys/cdefs.h>
98
99__BEGIN_DECLS
100int	modnext(int modid);
101int	modfnext(int modid);
102int	modstat(int modid, struct module_stat* stat);
103int	modfind(char *name);
104__END_DECLS
105
106#endif
107
108#endif	/* !_SYS_MODULE_H_ */
109