module.h revision 25537
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$
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_static, &data)
56
57void module_register_static(void *data);
58int module_register(const char *name, modeventhand_t callback, void *arg);
59module_t module_lookupbyname(const char *name);
60module_t module_lookupbyid(int modid);
61void module_reference(module_t mod);
62void module_release(module_t mod);
63int module_unload(module_t mod);
64int module_getid(module_t mod);
65module_t module_getfnext(module_t mod);
66
67#ifdef MOD_DEBUG
68
69extern int mod_debug;
70#define MOD_DEBUG_REFS	1
71
72#define MOD_DPF(cat, args)					\
73	do {							\
74		if (mod_debug & MOD_DEBUG_##cat) printf args;	\
75	} while (0)
76
77#else
78
79#define MOD_DPF(cat, args)
80
81#endif
82
83#endif /* KERNEL */
84
85#define MAXMODNAME	32
86
87struct module_stat {
88    int		version;	/* set to sizeof(struct module_stat) */
89    char	name[MAXMODNAME];
90    int		refs;
91    int		id;
92};
93
94#ifndef KERNEL
95
96#include <sys/cdefs.h>
97
98__BEGIN_DECLS
99int	modnext(int modid);
100int	modfnext(int modid);
101int	modstat(int modid, struct module_stat* stat);
102int	modfind(char *name);
103__END_DECLS
104
105#endif
106
107#endif	/* !_SYS_MODULE_H_ */
108