1*13222386Sriastradh /* $NetBSD: moduleparam.h,v 1.11 2021/12/19 12:01:48 riastradh Exp $ */ 26cb10275Sriastradh 36cb10275Sriastradh /*- 46cb10275Sriastradh * Copyright (c) 2013 The NetBSD Foundation, Inc. 56cb10275Sriastradh * All rights reserved. 66cb10275Sriastradh * 76cb10275Sriastradh * This code is derived from software contributed to The NetBSD Foundation 86cb10275Sriastradh * by Taylor R. Campbell. 96cb10275Sriastradh * 106cb10275Sriastradh * Redistribution and use in source and binary forms, with or without 116cb10275Sriastradh * modification, are permitted provided that the following conditions 126cb10275Sriastradh * are met: 136cb10275Sriastradh * 1. Redistributions of source code must retain the above copyright 146cb10275Sriastradh * notice, this list of conditions and the following disclaimer. 156cb10275Sriastradh * 2. Redistributions in binary form must reproduce the above copyright 166cb10275Sriastradh * notice, this list of conditions and the following disclaimer in the 176cb10275Sriastradh * documentation and/or other materials provided with the distribution. 186cb10275Sriastradh * 196cb10275Sriastradh * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 206cb10275Sriastradh * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 216cb10275Sriastradh * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 226cb10275Sriastradh * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 236cb10275Sriastradh * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 246cb10275Sriastradh * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 256cb10275Sriastradh * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 266cb10275Sriastradh * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 276cb10275Sriastradh * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 286cb10275Sriastradh * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 296cb10275Sriastradh * POSSIBILITY OF SUCH DAMAGE. 306cb10275Sriastradh */ 316cb10275Sriastradh 326cb10275Sriastradh #ifndef _LINUX_MODULEPARAM_H_ 336cb10275Sriastradh #define _LINUX_MODULEPARAM_H_ 346cb10275Sriastradh 35bf1c1789Schristos #include <sys/types.h> 36bf1c1789Schristos 37bf1c1789Schristos struct linux_module_param_info { 387dfb2147Schristos const char *dname; // Name used for description 397dfb2147Schristos const char *name; // Name for sysctl 407dfb2147Schristos void *ptr; // Pointer to variable value 417dfb2147Schristos int type; // MTYPE_ 427dfb2147Schristos mode_t mode; // 600 (rw) or 400 (r) 43bf1c1789Schristos }; 44bf1c1789Schristos 45bf1c1789Schristos #define MTYPE_int 0 46bf1c1789Schristos #define MTYPE_bool 1 47444a6babSriastradh #define MTYPE_charp 2 48a50eb21cSriastradh #define MTYPE_uint 3 49bf1c1789Schristos 5072d8a0bbSriastradh /* 5172d8a0bbSriastradh * In case of accidental cpp expansion, break glass to raise alarm and 5272d8a0bbSriastradh * reach antizombie chainsaw. 5372d8a0bbSriastradh */ 5472d8a0bbSriastradh #define MTYPE__Bool MTYPE_bool 5572d8a0bbSriastradh 56bf1c1789Schristos #define module_param_named(NAME, VAR, TYPE, MODE) \ 57bf1c1789Schristos static __attribute__((__used__)) struct linux_module_param_info info_ ## NAME = { \ 587dfb2147Schristos .dname = # NAME, \ 59bf1c1789Schristos .name = # VAR, \ 60bf1c1789Schristos .ptr = & VAR, \ 61bf1c1789Schristos .type = MTYPE_ ## TYPE, \ 62bf1c1789Schristos .mode = MODE, \ 63bf1c1789Schristos }; \ 64bf1c1789Schristos __link_set_add_data(linux_module_param_info, info_ ## NAME) 656cb10275Sriastradh 665e5fc3e9Sriastradh #define module_param(VAR, TYPE, MODE) module_param_named(VAR, VAR, TYPE, MODE) 675e5fc3e9Sriastradh #define module_param_unsafe module_param 68740c23c9Sriastradh #define module_param_named_unsafe module_param_named 69*13222386Sriastradh #define module_param_string(VAR, TYPE, SIZE, MODE) \ 70*13222386Sriastradh CTASSERT(1) /* XXX */ 715e5fc3e9Sriastradh 72a4d1edabSriastradh struct linux_module_param_desc { 73a4d1edabSriastradh const char *name; 74a4d1edabSriastradh const char *description; 75a4d1edabSriastradh }; 76a4d1edabSriastradh #define MODULE_PARM_DESC(PARAMETER, DESCRIPTION) \ 77a4d1edabSriastradh static __attribute__((__used__)) \ 78a4d1edabSriastradh const struct linux_module_param_desc PARAMETER ## _desc = { \ 79a4d1edabSriastradh .name = # PARAMETER, \ 80a4d1edabSriastradh .description = DESCRIPTION, \ 81a4d1edabSriastradh }; \ 82a4d1edabSriastradh __link_set_add_rodata(linux_module_param_desc, PARAMETER ## _desc) 83a4d1edabSriastradh 84a4d1edabSriastradh 856cb10275Sriastradh #endif /* _LINUX_MODULEPARAM_H_ */ 86