1216615Slstewart/*-
2216615Slstewart * Copyright (c) 2010 Lawrence Stewart <lstewart@freebsd.org>
3216615Slstewart * Copyright (c) 2010 The FreeBSD Foundation
4216615Slstewart * All rights reserved.
5216615Slstewart *
6216615Slstewart * This software was developed by Lawrence Stewart while studying at the Centre
7220560Slstewart * for Advanced Internet Architectures, Swinburne University of Technology, made
8220560Slstewart * possible in part by grants from the FreeBSD Foundation and Cisco University
9220560Slstewart * Research Program Fund at Community Foundation Silicon Valley.
10216615Slstewart *
11216615Slstewart * Portions of this software were developed at the Centre for Advanced
12216615Slstewart * Internet Architectures, Swinburne University of Technology, Melbourne,
13216615Slstewart * Australia by Lawrence Stewart under sponsorship from the FreeBSD Foundation.
14216615Slstewart *
15216615Slstewart * Redistribution and use in source and binary forms, with or without
16216615Slstewart * modification, are permitted provided that the following conditions
17216615Slstewart * are met:
18216615Slstewart * 1. Redistributions of source code must retain the above copyright
19216615Slstewart *    notice, this list of conditions and the following disclaimer.
20216615Slstewart * 2. Redistributions in binary form must reproduce the above copyright
21216615Slstewart *    notice, this list of conditions and the following disclaimer in the
22216615Slstewart *    documentation and/or other materials provided with the distribution.
23216615Slstewart *
24216615Slstewart * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
25216615Slstewart * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26216615Slstewart * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27216615Slstewart * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
28216615Slstewart * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29216615Slstewart * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30216615Slstewart * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31216615Slstewart * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32216615Slstewart * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33216615Slstewart * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34216615Slstewart * SUCH DAMAGE.
35216615Slstewart *
36216615Slstewart * $FreeBSD$
37216615Slstewart */
38216615Slstewart
39216615Slstewart#ifndef _SYS_MODULE_KHELP_H_
40216615Slstewart#define _SYS_MODULE_KHELP_H_
41216615Slstewart
42216615Slstewart/* XXXLAS: Needed for uma related typedefs. */
43216615Slstewart#include <vm/uma.h>
44216615Slstewart
45216615Slstewart/* Helper flags. */
46216615Slstewart#define	HELPER_NEEDS_OSD	0x0001
47216615Slstewart
48216615Slstewartstruct helper {
49216615Slstewart	int (*mod_init) (void);
50216615Slstewart	int (*mod_destroy) (void);
51216615Slstewart#define	HELPER_NAME_MAXLEN 16
52216615Slstewart	char			h_name[HELPER_NAME_MAXLEN];
53216615Slstewart	uma_zone_t		h_zone;
54216615Slstewart	struct hookinfo		*h_hooks;
55216615Slstewart	uint32_t		h_nhooks;
56216615Slstewart	uint32_t		h_classes;
57216615Slstewart	int32_t			h_id;
58216615Slstewart	volatile uint32_t	h_refcount;
59216615Slstewart	uint16_t		h_flags;
60216615Slstewart	TAILQ_ENTRY(helper)	h_next;
61216615Slstewart};
62216615Slstewart
63216615Slstewartstruct khelp_modevent_data {
64216615Slstewart	char			name[HELPER_NAME_MAXLEN];
65216615Slstewart	struct helper		*helper;
66216615Slstewart	struct hookinfo		*hooks;
67216615Slstewart	int			nhooks;
68216615Slstewart	int			uma_zsize;
69216615Slstewart	uma_ctor		umactor;
70216615Slstewart	uma_dtor		umadtor;
71216615Slstewart};
72216615Slstewart
73216615Slstewart#define	KHELP_DECLARE_MOD_UMA(hname, hdata, hhooks, version, size, ctor, dtor) \
74216615Slstewart	static struct khelp_modevent_data kmd_##hname = {		\
75216615Slstewart		.name = #hname,						\
76216615Slstewart		.helper = hdata,					\
77216615Slstewart		.hooks = hhooks,					\
78216615Slstewart		.nhooks = sizeof(hhooks) / sizeof(hhooks[0]),		\
79216615Slstewart		.uma_zsize = size,					\
80216615Slstewart		.umactor = ctor,					\
81216615Slstewart		.umadtor = dtor						\
82216615Slstewart	};								\
83216615Slstewart	static moduledata_t h_##hname = {				\
84216615Slstewart		.name = #hname,						\
85216615Slstewart		.evhand = khelp_modevent,				\
86216615Slstewart		.priv = &kmd_##hname					\
87216615Slstewart	};								\
88251789Slstewart	DECLARE_MODULE(hname, h_##hname, SI_SUB_KLD, SI_ORDER_ANY);	\
89216615Slstewart	MODULE_VERSION(hname, version)
90216615Slstewart
91251682Slstewart#define	KHELP_DECLARE_MOD(hname, hdata, hhooks, version)		\
92251682Slstewart	KHELP_DECLARE_MOD_UMA(hname, hdata, hhooks, version, 0, NULL, NULL)
93251682Slstewart
94216615Slstewartint	khelp_modevent(module_t mod, int type, void *data);
95216615Slstewart
96216615Slstewart#endif /* _SYS_MODULE_KHELP_H_ */
97