xref: /freebsd/sys/compat/linuxkpi/common/include/linux/moduleparam.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
1 /*-
2  * Copyright (c) 2010 Isilon Systems, Inc.
3  * Copyright (c) 2010 iX Systems, Inc.
4  * Copyright (c) 2010 Panasas, Inc.
5  * Copyright (c) 2013-2016 Mellanox Technologies, Ltd.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice unmodified, this list of conditions, and the following
13  *    disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 #ifndef	_LINUXKPI_LINUX_MODULEPARAM_H_
30 #define	_LINUXKPI_LINUX_MODULEPARAM_H_
31 
32 #include <sys/types.h>
33 #include <sys/sysctl.h>
34 
35 #include <linux/types.h>
36 
37 #ifndef LINUXKPI_PARAM_PARENT
38 #define	LINUXKPI_PARAM_PARENT	_compat_linuxkpi
39 #endif
40 
41 #ifndef LINUXKPI_PARAM_PREFIX
42 #define	LINUXKPI_PARAM_PREFIX	/* empty prefix is the default */
43 #endif
44 
45 #ifndef LINUXKPI_PARAM_PERM
46 #define	LINUXKPI_PARAM_PERM(perm) (((perm) & 0222) ? CTLFLAG_RWTUN : CTLFLAG_RDTUN)
47 #endif
48 
49 #define	LINUXKPI_PARAM_CONCAT_SUB(a,b,c,d) a##b##c##d
50 #define	LINUXKPI_PARAM_CONCAT(...) LINUXKPI_PARAM_CONCAT_SUB(__VA_ARGS__)
51 #define	LINUXKPI_PARAM_PASS(...) __VA_ARGS__
52 #define	LINUXKPI_PARAM_DESC(name) LINUXKPI_PARAM_CONCAT(linuxkpi_,LINUXKPI_PARAM_PREFIX,name,_desc)
53 #define	LINUXKPI_PARAM_NAME(name) LINUXKPI_PARAM_CONCAT(LINUXKPI_PARAM_PREFIX,name,,)
54 
55 #define	LINUXKPI_PARAM_bool(name, var, perm)				\
56 	extern const char LINUXKPI_PARAM_DESC(name)[];			\
57 	LINUXKPI_PARAM_PASS(SYSCTL_BOOL(LINUXKPI_PARAM_PARENT, OID_AUTO,\
58 	LINUXKPI_PARAM_NAME(name), LINUXKPI_PARAM_PERM(perm), &(var), 0, \
59 	LINUXKPI_PARAM_DESC(name)))
60 
61 #define	LINUXKPI_PARAM_byte(name, var, perm)				\
62 	extern const char LINUXKPI_PARAM_DESC(name)[];			\
63 	LINUXKPI_PARAM_PASS(SYSCTL_U8(LINUXKPI_PARAM_PARENT, OID_AUTO,	\
64 	LINUXKPI_PARAM_NAME(name), LINUXKPI_PARAM_PERM(perm), &(var), 0, \
65 	LINUXKPI_PARAM_DESC(name)))
66 
67 #define	LINUXKPI_PARAM_short(name, var, perm)				\
68 	extern const char LINUXKPI_PARAM_DESC(name)[];			\
69 	LINUXKPI_PARAM_PASS(SYSCTL_S16(LINUXKPI_PARAM_PARENT, OID_AUTO,	\
70 	LINUXKPI_PARAM_NAME(name), LINUXKPI_PARAM_PERM(perm), &(var), 0, \
71 	LINUXKPI_PARAM_DESC(name)))
72 
73 #define	LINUXKPI_PARAM_ushort(name, var, perm)				\
74 	extern const char LINUXKPI_PARAM_DESC(name)[];			\
75 	LINUXKPI_PARAM_PASS(SYSCTL_U16(LINUXKPI_PARAM_PARENT, OID_AUTO,	\
76 	LINUXKPI_PARAM_NAME(name), LINUXKPI_PARAM_PERM(perm), &(var), 0, \
77 	LINUXKPI_PARAM_DESC(name)))
78 
79 #define	LINUXKPI_PARAM_int(name, var, perm)				\
80 	extern const char LINUXKPI_PARAM_DESC(name)[];			\
81 	LINUXKPI_PARAM_PASS(SYSCTL_INT(LINUXKPI_PARAM_PARENT, OID_AUTO,	\
82 	LINUXKPI_PARAM_NAME(name), LINUXKPI_PARAM_PERM(perm), &(var), 0,\
83 	LINUXKPI_PARAM_DESC(name)))
84 
85 #define	LINUXKPI_PARAM_uint(name, var, perm)				\
86 	extern const char LINUXKPI_PARAM_DESC(name)[];			\
87 	LINUXKPI_PARAM_PASS(SYSCTL_UINT(LINUXKPI_PARAM_PARENT, OID_AUTO, \
88 	LINUXKPI_PARAM_NAME(name), LINUXKPI_PARAM_PERM(perm), &(var), 0, \
89 	LINUXKPI_PARAM_DESC(name)))
90 
91 #define	LINUXKPI_PARAM_bint(name, var, perm)				\
92 	LINUXKPI_PARAM_int(name, var, perm)
93 
94 #define	LINUXKPI_PARAM_hexint(name, var, perm)				\
95 	extern const char LINUXKPI_PARAM_DESC(name)[];			\
96 	LINUXKPI_PARAM_PASS(SYSCTL_UINT(LINUXKPI_PARAM_PARENT, OID_AUTO, \
97 	LINUXKPI_PARAM_NAME(name), LINUXKPI_PARAM_PERM(perm), &(var), 0, \
98 	LINUXKPI_PARAM_DESC(name)))
99 
100 #define	LINUXKPI_PARAM_long(name, var, perm)				\
101 	extern const char LINUXKPI_PARAM_DESC(name)[];			\
102 	LINUXKPI_PARAM_PASS(SYSCTL_LONG(LINUXKPI_PARAM_PARENT, OID_AUTO, \
103 	LINUXKPI_PARAM_NAME(name), LINUXKPI_PARAM_PERM(perm), &(var), 0, \
104 	LINUXKPI_PARAM_DESC(name)))
105 
106 #define	LINUXKPI_PARAM_ulong(name, var, perm)				\
107 	extern const char LINUXKPI_PARAM_DESC(name)[];			\
108 	LINUXKPI_PARAM_PASS(SYSCTL_ULONG(LINUXKPI_PARAM_PARENT, OID_AUTO, \
109 	LINUXKPI_PARAM_NAME(name), LINUXKPI_PARAM_PERM(perm), &(var), 0, \
110 	LINUXKPI_PARAM_DESC(name)))
111 
112 #define	LINUXKPI_PARAM_charp(name, var, perm)				\
113 	extern const char LINUXKPI_PARAM_DESC(name)[];			\
114 	LINUXKPI_PARAM_PASS(SYSCTL_STRING(LINUXKPI_PARAM_PARENT, OID_AUTO, \
115 	LINUXKPI_PARAM_NAME(name), LINUXKPI_PARAM_PERM(perm), &(var), 0, \
116 	LINUXKPI_PARAM_DESC(name)))
117 
118 #define	module_param_string(name, str, len, perm)			\
119 	extern const char LINUXKPI_PARAM_DESC(name)[];			\
120 	LINUXKPI_PARAM_PASS(SYSCTL_STRING(LINUXKPI_PARAM_PARENT, OID_AUTO, \
121 	LINUXKPI_PARAM_NAME(name), LINUXKPI_PARAM_PERM(perm), (str), (len), \
122 	LINUXKPI_PARAM_DESC(name)))
123 
124 #define	module_param_named(name, var, type, mode)	\
125 	LINUXKPI_PARAM_##type(name, var, mode)
126 
127 #define	module_param(var, type, mode)	\
128 	LINUXKPI_PARAM_##type(var, var, mode)
129 
130 #define	module_param_named_unsafe(name, var, type, mode) \
131 	LINUXKPI_PARAM_##type(name, var, mode)
132 
133 #define	module_param_unsafe(var, type, mode) \
134 	LINUXKPI_PARAM_##type(var, var, mode)
135 
136 #define	module_param_array(var, type, addr_argc, mode)
137 
138 #define	MODULE_PARM_DESC(name, desc) \
139 	const char LINUXKPI_PARAM_DESC(name)[] = { desc }
140 
141 #define	kernel_param_lock(...) do {} while (0)
142 #define	kernel_param_unlock(...) do {} while (0)
143 
144 SYSCTL_DECL(_compat_linuxkpi);
145 
146 #endif					/* _LINUXKPI_LINUX_MODULEPARAM_H_ */
147