1997-05-07 16:05:47 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1997 Doug Rabson
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
1999-08-28 01:08:13 +00:00
|
|
|
* $FreeBSD$
|
1997-05-07 16:05:47 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _SYS_MODULE_H_
|
|
|
|
#define _SYS_MODULE_H_
|
|
|
|
|
2000-04-29 13:19:31 +00:00
|
|
|
/*
|
|
|
|
* Module metadata types
|
|
|
|
*/
|
|
|
|
#define MDT_DEPEND 1 /* argument is a module name */
|
|
|
|
#define MDT_MODULE 2 /* module declaration */
|
|
|
|
#define MDT_VERSION 3 /* module version(s) */
|
|
|
|
|
|
|
|
#define MDT_STRUCT_VERSION 1 /* version of metadata structure */
|
|
|
|
#define MDT_SETNAME "modmetadata_set"
|
|
|
|
|
1998-11-14 21:58:51 +00:00
|
|
|
typedef enum modeventtype {
|
2002-02-28 08:01:49 +00:00
|
|
|
MOD_LOAD,
|
|
|
|
MOD_UNLOAD,
|
|
|
|
MOD_SHUTDOWN
|
1997-05-07 16:05:47 +00:00
|
|
|
} modeventtype_t;
|
|
|
|
|
2002-02-28 08:01:49 +00:00
|
|
|
typedef struct module *module_t;
|
|
|
|
typedef int (*modeventhand_t)(module_t, int /* modeventtype_t */, void *);
|
1997-05-07 16:05:47 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Struct for registering modules statically via SYSINIT.
|
|
|
|
*/
|
|
|
|
typedef struct moduledata {
|
2002-02-28 08:01:49 +00:00
|
|
|
const char *name; /* module name */
|
|
|
|
modeventhand_t evhand; /* event handler */
|
|
|
|
void *priv; /* extra data */
|
1997-05-07 16:05:47 +00:00
|
|
|
} moduledata_t;
|
|
|
|
|
1999-01-09 14:59:50 +00:00
|
|
|
/*
|
2002-02-28 08:01:49 +00:00
|
|
|
* A module can use this to report module specific data to the user via
|
|
|
|
* kldstat(2).
|
1999-01-09 14:59:50 +00:00
|
|
|
*/
|
|
|
|
typedef union modspecific {
|
2002-02-28 08:01:49 +00:00
|
|
|
int intval;
|
|
|
|
u_int uintval;
|
|
|
|
long longval;
|
|
|
|
u_long ulongval;
|
1999-01-09 14:59:50 +00:00
|
|
|
} modspecific_t;
|
|
|
|
|
2000-04-29 13:19:31 +00:00
|
|
|
/*
|
|
|
|
* Module dependency declarartion
|
|
|
|
*/
|
|
|
|
struct mod_depend {
|
2002-02-28 08:01:49 +00:00
|
|
|
int md_ver_minimum;
|
|
|
|
int md_ver_preferred;
|
|
|
|
int md_ver_maximum;
|
2000-04-29 13:19:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Module version declaration
|
|
|
|
*/
|
|
|
|
struct mod_version {
|
2002-02-28 08:01:49 +00:00
|
|
|
int mv_version;
|
2000-04-29 13:19:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct mod_metadata {
|
2002-02-28 08:01:49 +00:00
|
|
|
int md_version; /* structure version MDTV_* */
|
|
|
|
int md_type; /* type of entry MDT_* */
|
|
|
|
void *md_data; /* specific data */
|
|
|
|
const char *md_cval; /* common string label */
|
2000-04-29 13:19:31 +00:00
|
|
|
};
|
|
|
|
|
2002-02-28 08:01:49 +00:00
|
|
|
#ifdef _KERNEL
|
1998-10-09 23:05:45 +00:00
|
|
|
|
2000-04-29 13:19:31 +00:00
|
|
|
#include <sys/linker_set.h>
|
|
|
|
|
2002-02-28 08:01:49 +00:00
|
|
|
#define MODULE_METADATA(uniquifier, type, data, cval) \
|
|
|
|
static struct mod_metadata _mod_metadata##uniquifier = { \
|
|
|
|
MDT_STRUCT_VERSION, \
|
|
|
|
type, \
|
|
|
|
data, \
|
|
|
|
cval \
|
|
|
|
}; \
|
|
|
|
DATA_SET(modmetadata_set, _mod_metadata##uniquifier)
|
|
|
|
|
|
|
|
#define MODULE_DEPEND(module, mdepend, vmin, vpref, vmax) \
|
|
|
|
static struct mod_depend _##module##_depend_on_##mdepend = { \
|
|
|
|
vmin, \
|
|
|
|
vpref, \
|
|
|
|
vmax \
|
|
|
|
}; \
|
|
|
|
MODULE_METADATA(_md_##module##_on_##mdepend, MDT_DEPEND, \
|
|
|
|
&_##module##_depend_on_##mdepend, #mdepend)
|
|
|
|
|
|
|
|
#define DECLARE_MODULE(name, data, sub, order) \
|
|
|
|
MODULE_METADATA(_md_##name, MDT_MODULE, &data, #name); \
|
|
|
|
SYSINIT(name##module, sub, order, module_register_init, &data) \
|
|
|
|
struct __hack
|
|
|
|
|
|
|
|
#define MODULE_VERSION(module, version) \
|
|
|
|
static struct mod_version _##module##_version = { \
|
|
|
|
version \
|
|
|
|
}; \
|
|
|
|
MODULE_METADATA(_##module##_version, MDT_VERSION, \
|
|
|
|
&_##module##_version, #module)
|
|
|
|
|
2002-03-18 07:45:30 +00:00
|
|
|
extern struct sx modules_sx;
|
|
|
|
|
|
|
|
#define MOD_XLOCK sx_xlock(&modules_sx)
|
|
|
|
#define MOD_SLOCK sx_slock(&modules_sx)
|
|
|
|
#define MOD_XUNLOCK sx_xunlock(&modules_sx)
|
|
|
|
#define MOD_SUNLOCK sx_sunlock(&modules_sx)
|
|
|
|
#define MOD_LOCK_ASSERT sx_assert(&modules_sx, SX_LOCKED)
|
|
|
|
#define MOD_XLOCK_ASSERT sx_assert(&modules_sx, SX_XLOCKED)
|
|
|
|
|
1999-05-08 13:01:59 +00:00
|
|
|
struct linker_file;
|
1997-05-07 16:05:47 +00:00
|
|
|
|
2002-02-28 08:01:49 +00:00
|
|
|
void module_register_init(const void *);
|
|
|
|
int module_register(const struct moduledata *, struct linker_file *);
|
|
|
|
module_t module_lookupbyname(const char *);
|
|
|
|
module_t module_lookupbyid(int);
|
|
|
|
void module_reference(module_t);
|
|
|
|
void module_release(module_t);
|
|
|
|
int module_unload(module_t);
|
|
|
|
int module_getid(module_t);
|
|
|
|
module_t module_getfnext(module_t);
|
|
|
|
void module_setspecific(module_t, modspecific_t *);
|
|
|
|
|
|
|
|
#ifdef MOD_DEBUG
|
1997-05-07 16:05:47 +00:00
|
|
|
extern int mod_debug;
|
2002-02-28 08:01:49 +00:00
|
|
|
#define MOD_DEBUG_REFS 1
|
1997-05-07 16:05:47 +00:00
|
|
|
|
2002-03-01 07:05:45 +00:00
|
|
|
#define MOD_DPF(cat, args) do { \
|
2002-02-28 08:01:49 +00:00
|
|
|
if (mod_debug & MOD_DEBUG_##cat) \
|
|
|
|
printf(args); \
|
|
|
|
} while (0)
|
1997-05-07 16:05:47 +00:00
|
|
|
|
2002-02-28 08:01:49 +00:00
|
|
|
#else /* !MOD_DEBUG */
|
1997-05-07 16:05:47 +00:00
|
|
|
|
2002-02-28 08:01:49 +00:00
|
|
|
#define MOD_DPF(cat, args)
|
1997-05-07 16:05:47 +00:00
|
|
|
#endif
|
2002-02-28 08:01:49 +00:00
|
|
|
#endif /* _KERNEL */
|
1997-05-07 16:05:47 +00:00
|
|
|
|
2002-02-28 08:01:49 +00:00
|
|
|
#define MAXMODNAME 32
|
1997-05-07 16:05:47 +00:00
|
|
|
|
|
|
|
struct module_stat {
|
2002-02-28 08:01:49 +00:00
|
|
|
int version; /* set to sizeof(struct module_stat) */
|
|
|
|
char name[MAXMODNAME];
|
|
|
|
int refs;
|
|
|
|
int id;
|
|
|
|
modspecific_t data;
|
1997-05-07 16:05:47 +00:00
|
|
|
};
|
|
|
|
|
1999-12-29 04:46:21 +00:00
|
|
|
#ifndef _KERNEL
|
1997-05-07 16:05:47 +00:00
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
|
|
|
|
__BEGIN_DECLS
|
2001-09-09 14:57:17 +00:00
|
|
|
int modnext(int _modid);
|
|
|
|
int modfnext(int _modid);
|
2002-02-28 08:01:49 +00:00
|
|
|
int modstat(int _modid, struct module_stat *_stat);
|
2001-09-09 14:57:17 +00:00
|
|
|
int modfind(const char *_name);
|
1997-05-07 16:05:47 +00:00
|
|
|
__END_DECLS
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* !_SYS_MODULE_H_ */
|