moduleparam.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _LINUX_MODULE_PARAMS_H
  3. #define _LINUX_MODULE_PARAMS_H
  4. /* (C) Copyright 2001, 2002 Rusty Russell IBM Corporation */
  5. #include <linux/init.h>
  6. #include <linux/stringify.h>
  7. #include <linux/kernel.h>
  8. /* You can override this manually, but generally this should match the
  9. module name. */
  10. #ifdef MODULE
  11. #define MODULE_PARAM_PREFIX /* empty */
  12. #define __MODULE_INFO_PREFIX /* empty */
  13. #else
  14. #define MODULE_PARAM_PREFIX KBUILD_MODNAME "."
  15. /* We cannot use MODULE_PARAM_PREFIX because some modules override it. */
  16. #define __MODULE_INFO_PREFIX KBUILD_MODNAME "."
  17. #endif
  18. /* Chosen so that structs with an unsigned long line up. */
  19. #define MAX_PARAM_PREFIX_LEN (64 - sizeof(unsigned long))
  20. #define __MODULE_INFO(tag, name, info) \
  21. static const char __UNIQUE_ID(name)[] \
  22. __used __section(".modinfo") __aligned(1) \
  23. = __MODULE_INFO_PREFIX __stringify(tag) "=" info
  24. #define __MODULE_PARM_TYPE(name, _type) \
  25. __MODULE_INFO(parmtype, name##type, #name ":" _type)
  26. /* One for each parameter, describing how to use it. Some files do
  27. multiple of these per line, so can't just use MODULE_INFO. */
  28. #define MODULE_PARM_DESC(_parm, desc) \
  29. __MODULE_INFO(parm, _parm, #_parm ":" desc)
  30. struct kernel_param;
  31. /*
  32. * Flags available for kernel_param_ops
  33. *
  34. * NOARG - the parameter allows for no argument (foo instead of foo=1)
  35. */
  36. enum {
  37. KERNEL_PARAM_OPS_FL_NOARG = (1 << 0)
  38. };
  39. struct kernel_param_ops {
  40. /* How the ops should behave */
  41. unsigned int flags;
  42. /* Returns 0, or -errno. arg is in kp->arg. */
  43. int (*set)(const char *val, const struct kernel_param *kp);
  44. /* Returns length written or -errno. Buffer is 4k (ie. be short!) */
  45. int (*get)(char *buffer, const struct kernel_param *kp);
  46. /* Optional function to free kp->arg when module unloaded. */
  47. void (*free)(void *arg);
  48. };
  49. /*
  50. * Flags available for kernel_param
  51. *
  52. * UNSAFE - the parameter is dangerous and setting it will taint the kernel
  53. * HWPARAM - Hardware param not permitted in lockdown mode
  54. */
  55. enum {
  56. KERNEL_PARAM_FL_UNSAFE = (1 << 0),
  57. KERNEL_PARAM_FL_HWPARAM = (1 << 1),
  58. };
  59. struct kernel_param {
  60. const char *name;
  61. struct module *mod;
  62. const struct kernel_param_ops *ops;
  63. const u16 perm;
  64. s8 level;
  65. u8 flags;
  66. union {
  67. void *arg;
  68. const struct kparam_string *str;
  69. const struct kparam_array *arr;
  70. };
  71. };
  72. extern const struct kernel_param __start___param[], __stop___param[];
  73. /* Special one for strings we want to copy into */
  74. struct kparam_string {
  75. unsigned int maxlen;
  76. char *string;
  77. };
  78. /* Special one for arrays */
  79. struct kparam_array
  80. {
  81. unsigned int max;
  82. unsigned int elemsize;
  83. unsigned int *num;
  84. const struct kernel_param_ops *ops;
  85. void *elem;
  86. };
  87. /**
  88. * module_param - typesafe helper for a module/cmdline parameter
  89. * @name: the variable to alter, and exposed parameter name.
  90. * @type: the type of the parameter
  91. * @perm: visibility in sysfs.
  92. *
  93. * @name becomes the module parameter, or (prefixed by KBUILD_MODNAME and a
  94. * ".") the kernel commandline parameter. Note that - is changed to _, so
  95. * the user can use "foo-bar=1" even for variable "foo_bar".
  96. *
  97. * @perm is 0 if the variable is not to appear in sysfs, or 0444
  98. * for world-readable, 0644 for root-writable, etc. Note that if it
  99. * is writable, you may need to use kernel_param_lock() around
  100. * accesses (esp. charp, which can be kfreed when it changes).
  101. *
  102. * The @type is simply pasted to refer to a param_ops_##type and a
  103. * param_check_##type: for convenience many standard types are provided but
  104. * you can create your own by defining those variables.
  105. *
  106. * Standard types are:
  107. * byte, hexint, short, ushort, int, uint, long, ulong
  108. * charp: a character pointer
  109. * bool: a bool, values 0/1, y/n, Y/N.
  110. * invbool: the above, only sense-reversed (N = true).
  111. */
  112. #define module_param(name, type, perm) \
  113. module_param_named(name, name, type, perm)
  114. /**
  115. * module_param_unsafe - same as module_param but taints kernel
  116. * @name: the variable to alter, and exposed parameter name.
  117. * @type: the type of the parameter
  118. * @perm: visibility in sysfs.
  119. */
  120. #define module_param_unsafe(name, type, perm) \
  121. module_param_named_unsafe(name, name, type, perm)
  122. /**
  123. * module_param_named - typesafe helper for a renamed module/cmdline parameter
  124. * @name: a valid C identifier which is the parameter name.
  125. * @value: the actual lvalue to alter.
  126. * @type: the type of the parameter
  127. * @perm: visibility in sysfs.
  128. *
  129. * Usually it's a good idea to have variable names and user-exposed names the
  130. * same, but that's harder if the variable must be non-static or is inside a
  131. * structure. This allows exposure under a different name.
  132. */
  133. #define module_param_named(name, value, type, perm) \
  134. param_check_##type(name, &(value)); \
  135. module_param_cb(name, &param_ops_##type, &value, perm); \
  136. __MODULE_PARM_TYPE(name, #type)
  137. /**
  138. * module_param_named_unsafe - same as module_param_named but taints kernel
  139. * @name: a valid C identifier which is the parameter name.
  140. * @value: the actual lvalue to alter.
  141. * @type: the type of the parameter
  142. * @perm: visibility in sysfs.
  143. */
  144. #define module_param_named_unsafe(name, value, type, perm) \
  145. param_check_##type(name, &(value)); \
  146. module_param_cb_unsafe(name, &param_ops_##type, &value, perm); \
  147. __MODULE_PARM_TYPE(name, #type)
  148. /**
  149. * module_param_cb - general callback for a module/cmdline parameter
  150. * @name: a valid C identifier which is the parameter name.
  151. * @ops: the set & get operations for this parameter.
  152. * @arg: args for @ops
  153. * @perm: visibility in sysfs.
  154. *
  155. * The ops can have NULL set or get functions.
  156. */
  157. #define module_param_cb(name, ops, arg, perm) \
  158. __module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, -1, 0)
  159. #define module_param_cb_unsafe(name, ops, arg, perm) \
  160. __module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, -1, \
  161. KERNEL_PARAM_FL_UNSAFE)
  162. #define __level_param_cb(name, ops, arg, perm, level) \
  163. __module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, level, 0)
  164. /**
  165. * core_param_cb - general callback for a module/cmdline parameter
  166. * to be evaluated before core initcall level
  167. * @name: a valid C identifier which is the parameter name.
  168. * @ops: the set & get operations for this parameter.
  169. * @arg: args for @ops
  170. * @perm: visibility in sysfs.
  171. *
  172. * The ops can have NULL set or get functions.
  173. */
  174. #define core_param_cb(name, ops, arg, perm) \
  175. __level_param_cb(name, ops, arg, perm, 1)
  176. /**
  177. * postcore_param_cb - general callback for a module/cmdline parameter
  178. * to be evaluated before postcore initcall level
  179. * @name: a valid C identifier which is the parameter name.
  180. * @ops: the set & get operations for this parameter.
  181. * @arg: args for @ops
  182. * @perm: visibility in sysfs.
  183. *
  184. * The ops can have NULL set or get functions.
  185. */
  186. #define postcore_param_cb(name, ops, arg, perm) \
  187. __level_param_cb(name, ops, arg, perm, 2)
  188. /**
  189. * arch_param_cb - general callback for a module/cmdline parameter
  190. * to be evaluated before arch initcall level
  191. * @name: a valid C identifier which is the parameter name.
  192. * @ops: the set & get operations for this parameter.
  193. * @arg: args for @ops
  194. * @perm: visibility in sysfs.
  195. *
  196. * The ops can have NULL set or get functions.
  197. */
  198. #define arch_param_cb(name, ops, arg, perm) \
  199. __level_param_cb(name, ops, arg, perm, 3)
  200. /**
  201. * subsys_param_cb - general callback for a module/cmdline parameter
  202. * to be evaluated before subsys initcall level
  203. * @name: a valid C identifier which is the parameter name.
  204. * @ops: the set & get operations for this parameter.
  205. * @arg: args for @ops
  206. * @perm: visibility in sysfs.
  207. *
  208. * The ops can have NULL set or get functions.
  209. */
  210. #define subsys_param_cb(name, ops, arg, perm) \
  211. __level_param_cb(name, ops, arg, perm, 4)
  212. /**
  213. * fs_param_cb - general callback for a module/cmdline parameter
  214. * to be evaluated before fs initcall level
  215. * @name: a valid C identifier which is the parameter name.
  216. * @ops: the set & get operations for this parameter.
  217. * @arg: args for @ops
  218. * @perm: visibility in sysfs.
  219. *
  220. * The ops can have NULL set or get functions.
  221. */
  222. #define fs_param_cb(name, ops, arg, perm) \
  223. __level_param_cb(name, ops, arg, perm, 5)
  224. /**
  225. * device_param_cb - general callback for a module/cmdline parameter
  226. * to be evaluated before device initcall level
  227. * @name: a valid C identifier which is the parameter name.
  228. * @ops: the set & get operations for this parameter.
  229. * @arg: args for @ops
  230. * @perm: visibility in sysfs.
  231. *
  232. * The ops can have NULL set or get functions.
  233. */
  234. #define device_param_cb(name, ops, arg, perm) \
  235. __level_param_cb(name, ops, arg, perm, 6)
  236. /**
  237. * late_param_cb - general callback for a module/cmdline parameter
  238. * to be evaluated before late initcall level
  239. * @name: a valid C identifier which is the parameter name.
  240. * @ops: the set & get operations for this parameter.
  241. * @arg: args for @ops
  242. * @perm: visibility in sysfs.
  243. *
  244. * The ops can have NULL set or get functions.
  245. */
  246. #define late_param_cb(name, ops, arg, perm) \
  247. __level_param_cb(name, ops, arg, perm, 7)
  248. /* On alpha, ia64 and ppc64 relocations to global data cannot go into
  249. read-only sections (which is part of respective UNIX ABI on these
  250. platforms). So 'const' makes no sense and even causes compile failures
  251. with some compilers. */
  252. #if defined(CONFIG_ALPHA) || defined(CONFIG_IA64) || defined(CONFIG_PPC64)
  253. #define __moduleparam_const
  254. #else
  255. #define __moduleparam_const const
  256. #endif
  257. /* This is the fundamental function for registering boot/module
  258. parameters. */
  259. #define __module_param_call(prefix, name, ops, arg, perm, level, flags) \
  260. /* Default value instead of permissions? */ \
  261. static const char __param_str_##name[] = prefix #name; \
  262. static struct kernel_param __moduleparam_const __param_##name \
  263. __used __section("__param") \
  264. __aligned(__alignof__(struct kernel_param)) \
  265. = { __param_str_##name, THIS_MODULE, ops, \
  266. VERIFY_OCTAL_PERMISSIONS(perm), level, flags, { arg } }
  267. /* Obsolete - use module_param_cb() */
  268. #define module_param_call(name, _set, _get, arg, perm) \
  269. static const struct kernel_param_ops __param_ops_##name = \
  270. { .flags = 0, .set = _set, .get = _get }; \
  271. __module_param_call(MODULE_PARAM_PREFIX, \
  272. name, &__param_ops_##name, arg, perm, -1, 0)
  273. #ifdef CONFIG_SYSFS
  274. extern void kernel_param_lock(struct module *mod);
  275. extern void kernel_param_unlock(struct module *mod);
  276. #else
  277. static inline void kernel_param_lock(struct module *mod)
  278. {
  279. }
  280. static inline void kernel_param_unlock(struct module *mod)
  281. {
  282. }
  283. #endif
  284. #ifndef MODULE
  285. /**
  286. * core_param - define a historical core kernel parameter.
  287. * @name: the name of the cmdline and sysfs parameter (often the same as var)
  288. * @var: the variable
  289. * @type: the type of the parameter
  290. * @perm: visibility in sysfs
  291. *
  292. * core_param is just like module_param(), but cannot be modular and
  293. * doesn't add a prefix (such as "printk."). This is for compatibility
  294. * with __setup(), and it makes sense as truly core parameters aren't
  295. * tied to the particular file they're in.
  296. */
  297. #define core_param(name, var, type, perm) \
  298. param_check_##type(name, &(var)); \
  299. __module_param_call("", name, &param_ops_##type, &var, perm, -1, 0)
  300. /**
  301. * core_param_unsafe - same as core_param but taints kernel
  302. * @name: the name of the cmdline and sysfs parameter (often the same as var)
  303. * @var: the variable
  304. * @type: the type of the parameter
  305. * @perm: visibility in sysfs
  306. */
  307. #define core_param_unsafe(name, var, type, perm) \
  308. param_check_##type(name, &(var)); \
  309. __module_param_call("", name, &param_ops_##type, &var, perm, \
  310. -1, KERNEL_PARAM_FL_UNSAFE)
  311. #endif /* !MODULE */
  312. /**
  313. * module_param_string - a char array parameter
  314. * @name: the name of the parameter
  315. * @string: the string variable
  316. * @len: the maximum length of the string, incl. terminator
  317. * @perm: visibility in sysfs.
  318. *
  319. * This actually copies the string when it's set (unlike type charp).
  320. * @len is usually just sizeof(string).
  321. */
  322. #define module_param_string(name, string, len, perm) \
  323. static const struct kparam_string __param_string_##name \
  324. = { len, string }; \
  325. __module_param_call(MODULE_PARAM_PREFIX, name, \
  326. &param_ops_string, \
  327. .str = &__param_string_##name, perm, -1, 0);\
  328. __MODULE_PARM_TYPE(name, "string")
  329. /**
  330. * parameq - checks if two parameter names match
  331. * @name1: parameter name 1
  332. * @name2: parameter name 2
  333. *
  334. * Returns true if the two parameter names are equal.
  335. * Dashes (-) are considered equal to underscores (_).
  336. */
  337. extern bool parameq(const char *name1, const char *name2);
  338. /**
  339. * parameqn - checks if two parameter names match
  340. * @name1: parameter name 1
  341. * @name2: parameter name 2
  342. * @n: the length to compare
  343. *
  344. * Similar to parameq(), except it compares @n characters.
  345. */
  346. extern bool parameqn(const char *name1, const char *name2, size_t n);
  347. /* Called on module insert or kernel boot */
  348. extern char *parse_args(const char *name,
  349. char *args,
  350. const struct kernel_param *params,
  351. unsigned num,
  352. s16 level_min,
  353. s16 level_max,
  354. void *arg,
  355. int (*unknown)(char *param, char *val,
  356. const char *doing, void *arg));
  357. /* Called by module remove. */
  358. #ifdef CONFIG_SYSFS
  359. extern void destroy_params(const struct kernel_param *params, unsigned num);
  360. #else
  361. static inline void destroy_params(const struct kernel_param *params,
  362. unsigned num)
  363. {
  364. }
  365. #endif /* !CONFIG_SYSFS */
  366. /* All the helper functions */
  367. /* The macros to do compile-time type checking stolen from Jakub
  368. Jelinek, who IIRC came up with this idea for the 2.4 module init code. */
  369. #define __param_check(name, p, type) \
  370. static inline type __always_unused *__check_##name(void) { return(p); }
  371. extern const struct kernel_param_ops param_ops_byte;
  372. extern int param_set_byte(const char *val, const struct kernel_param *kp);
  373. extern int param_get_byte(char *buffer, const struct kernel_param *kp);
  374. #define param_check_byte(name, p) __param_check(name, p, unsigned char)
  375. extern const struct kernel_param_ops param_ops_short;
  376. extern int param_set_short(const char *val, const struct kernel_param *kp);
  377. extern int param_get_short(char *buffer, const struct kernel_param *kp);
  378. #define param_check_short(name, p) __param_check(name, p, short)
  379. extern const struct kernel_param_ops param_ops_ushort;
  380. extern int param_set_ushort(const char *val, const struct kernel_param *kp);
  381. extern int param_get_ushort(char *buffer, const struct kernel_param *kp);
  382. #define param_check_ushort(name, p) __param_check(name, p, unsigned short)
  383. extern const struct kernel_param_ops param_ops_int;
  384. extern int param_set_int(const char *val, const struct kernel_param *kp);
  385. extern int param_get_int(char *buffer, const struct kernel_param *kp);
  386. #define param_check_int(name, p) __param_check(name, p, int)
  387. extern const struct kernel_param_ops param_ops_uint;
  388. extern int param_set_uint(const char *val, const struct kernel_param *kp);
  389. extern int param_get_uint(char *buffer, const struct kernel_param *kp);
  390. int param_set_uint_minmax(const char *val, const struct kernel_param *kp,
  391. unsigned int min, unsigned int max);
  392. #define param_check_uint(name, p) __param_check(name, p, unsigned int)
  393. extern const struct kernel_param_ops param_ops_long;
  394. extern int param_set_long(const char *val, const struct kernel_param *kp);
  395. extern int param_get_long(char *buffer, const struct kernel_param *kp);
  396. #define param_check_long(name, p) __param_check(name, p, long)
  397. extern const struct kernel_param_ops param_ops_ulong;
  398. extern int param_set_ulong(const char *val, const struct kernel_param *kp);
  399. extern int param_get_ulong(char *buffer, const struct kernel_param *kp);
  400. #define param_check_ulong(name, p) __param_check(name, p, unsigned long)
  401. extern const struct kernel_param_ops param_ops_ullong;
  402. extern int param_set_ullong(const char *val, const struct kernel_param *kp);
  403. extern int param_get_ullong(char *buffer, const struct kernel_param *kp);
  404. #define param_check_ullong(name, p) __param_check(name, p, unsigned long long)
  405. extern const struct kernel_param_ops param_ops_hexint;
  406. extern int param_set_hexint(const char *val, const struct kernel_param *kp);
  407. extern int param_get_hexint(char *buffer, const struct kernel_param *kp);
  408. #define param_check_hexint(name, p) param_check_uint(name, p)
  409. extern const struct kernel_param_ops param_ops_charp;
  410. extern int param_set_charp(const char *val, const struct kernel_param *kp);
  411. extern int param_get_charp(char *buffer, const struct kernel_param *kp);
  412. extern void param_free_charp(void *arg);
  413. #define param_check_charp(name, p) __param_check(name, p, char *)
  414. /* We used to allow int as well as bool. We're taking that away! */
  415. extern const struct kernel_param_ops param_ops_bool;
  416. extern int param_set_bool(const char *val, const struct kernel_param *kp);
  417. extern int param_get_bool(char *buffer, const struct kernel_param *kp);
  418. #define param_check_bool(name, p) __param_check(name, p, bool)
  419. extern const struct kernel_param_ops param_ops_bool_enable_only;
  420. extern int param_set_bool_enable_only(const char *val,
  421. const struct kernel_param *kp);
  422. /* getter is the same as for the regular bool */
  423. #define param_check_bool_enable_only param_check_bool
  424. extern const struct kernel_param_ops param_ops_invbool;
  425. extern int param_set_invbool(const char *val, const struct kernel_param *kp);
  426. extern int param_get_invbool(char *buffer, const struct kernel_param *kp);
  427. #define param_check_invbool(name, p) __param_check(name, p, bool)
  428. /* An int, which can only be set like a bool (though it shows as an int). */
  429. extern const struct kernel_param_ops param_ops_bint;
  430. extern int param_set_bint(const char *val, const struct kernel_param *kp);
  431. #define param_get_bint param_get_int
  432. #define param_check_bint param_check_int
  433. /**
  434. * module_param_array - a parameter which is an array of some type
  435. * @name: the name of the array variable
  436. * @type: the type, as per module_param()
  437. * @nump: optional pointer filled in with the number written
  438. * @perm: visibility in sysfs
  439. *
  440. * Input and output are as comma-separated values. Commas inside values
  441. * don't work properly (eg. an array of charp).
  442. *
  443. * ARRAY_SIZE(@name) is used to determine the number of elements in the
  444. * array, so the definition must be visible.
  445. */
  446. #define module_param_array(name, type, nump, perm) \
  447. module_param_array_named(name, name, type, nump, perm)
  448. /**
  449. * module_param_array_named - renamed parameter which is an array of some type
  450. * @name: a valid C identifier which is the parameter name
  451. * @array: the name of the array variable
  452. * @type: the type, as per module_param()
  453. * @nump: optional pointer filled in with the number written
  454. * @perm: visibility in sysfs
  455. *
  456. * This exposes a different name than the actual variable name. See
  457. * module_param_named() for why this might be necessary.
  458. */
  459. #define module_param_array_named(name, array, type, nump, perm) \
  460. param_check_##type(name, &(array)[0]); \
  461. static const struct kparam_array __param_arr_##name \
  462. = { .max = ARRAY_SIZE(array), .num = nump, \
  463. .ops = &param_ops_##type, \
  464. .elemsize = sizeof(array[0]), .elem = array }; \
  465. __module_param_call(MODULE_PARAM_PREFIX, name, \
  466. &param_array_ops, \
  467. .arr = &__param_arr_##name, \
  468. perm, -1, 0); \
  469. __MODULE_PARM_TYPE(name, "array of " #type)
  470. enum hwparam_type {
  471. hwparam_ioport, /* Module parameter configures an I/O port */
  472. hwparam_iomem, /* Module parameter configures an I/O mem address */
  473. hwparam_ioport_or_iomem, /* Module parameter could be either, depending on other option */
  474. hwparam_irq, /* Module parameter configures an IRQ */
  475. hwparam_dma, /* Module parameter configures a DMA channel */
  476. hwparam_dma_addr, /* Module parameter configures a DMA buffer address */
  477. hwparam_other, /* Module parameter configures some other value */
  478. };
  479. /**
  480. * module_param_hw_named - A parameter representing a hw parameters
  481. * @name: a valid C identifier which is the parameter name.
  482. * @value: the actual lvalue to alter.
  483. * @type: the type of the parameter
  484. * @hwtype: what the value represents (enum hwparam_type)
  485. * @perm: visibility in sysfs.
  486. *
  487. * Usually it's a good idea to have variable names and user-exposed names the
  488. * same, but that's harder if the variable must be non-static or is inside a
  489. * structure. This allows exposure under a different name.
  490. */
  491. #define module_param_hw_named(name, value, type, hwtype, perm) \
  492. param_check_##type(name, &(value)); \
  493. __module_param_call(MODULE_PARAM_PREFIX, name, \
  494. &param_ops_##type, &value, \
  495. perm, -1, \
  496. KERNEL_PARAM_FL_HWPARAM | (hwparam_##hwtype & 0)); \
  497. __MODULE_PARM_TYPE(name, #type)
  498. #define module_param_hw(name, type, hwtype, perm) \
  499. module_param_hw_named(name, name, type, hwtype, perm)
  500. /**
  501. * module_param_hw_array - A parameter representing an array of hw parameters
  502. * @name: the name of the array variable
  503. * @type: the type, as per module_param()
  504. * @hwtype: what the value represents (enum hwparam_type)
  505. * @nump: optional pointer filled in with the number written
  506. * @perm: visibility in sysfs
  507. *
  508. * Input and output are as comma-separated values. Commas inside values
  509. * don't work properly (eg. an array of charp).
  510. *
  511. * ARRAY_SIZE(@name) is used to determine the number of elements in the
  512. * array, so the definition must be visible.
  513. */
  514. #define module_param_hw_array(name, type, hwtype, nump, perm) \
  515. param_check_##type(name, &(name)[0]); \
  516. static const struct kparam_array __param_arr_##name \
  517. = { .max = ARRAY_SIZE(name), .num = nump, \
  518. .ops = &param_ops_##type, \
  519. .elemsize = sizeof(name[0]), .elem = name }; \
  520. __module_param_call(MODULE_PARAM_PREFIX, name, \
  521. &param_array_ops, \
  522. .arr = &__param_arr_##name, \
  523. perm, -1, \
  524. KERNEL_PARAM_FL_HWPARAM | (hwparam_##hwtype & 0)); \
  525. __MODULE_PARM_TYPE(name, "array of " #type)
  526. extern const struct kernel_param_ops param_array_ops;
  527. extern const struct kernel_param_ops param_ops_string;
  528. extern int param_set_copystring(const char *val, const struct kernel_param *);
  529. extern int param_get_string(char *buffer, const struct kernel_param *kp);
  530. /* for exporting parameters in /sys/module/.../parameters */
  531. struct module;
  532. #if defined(CONFIG_SYSFS) && defined(CONFIG_MODULES)
  533. extern int module_param_sysfs_setup(struct module *mod,
  534. const struct kernel_param *kparam,
  535. unsigned int num_params);
  536. extern void module_param_sysfs_remove(struct module *mod);
  537. #else
  538. static inline int module_param_sysfs_setup(struct module *mod,
  539. const struct kernel_param *kparam,
  540. unsigned int num_params)
  541. {
  542. return 0;
  543. }
  544. static inline void module_param_sysfs_remove(struct module *mod)
  545. { }
  546. #endif
  547. #endif /* _LINUX_MODULE_PARAMS_H */