1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2020-2026 The FreeBSD Foundation 5 * 6 * This software was developed by Björn Zeeb under sponsorship from 7 * the FreeBSD Foundation. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following 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 AND CONTRIBUTORS ``AS IS'' AND 19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 */ 30 31 #ifndef _LINUXKPI_LINUX_KCONFIG_H_ 32 #define _LINUXKPI_LINUX_KCONFIG_H_ 33 34 /* -------------------------------------------------------------------------- */ 35 #include "opt_linuxkpi.h" 36 37 /* 38 * LinuxKPI internals are here as this file is globally included for everything 39 * compiled with LinuxKPI. 40 */ 41 42 /* 43 * Do not tell witness to ignore locks if debugging and witness are enabled. 44 * This helps debugging and hopefully also long-term code quality. 45 */ 46 #if defined(LINUXKPI_DEBUG) && defined(WITNESS) 47 #define _LKPI_MTX_NOWITNESS (0) 48 #define _LKPI_RW_NOWITNESS (0) 49 #define _LKPI_SX_NOWITNESS (0) 50 #define WITNESS_ALL /* Get better lock names. */ 51 #else 52 #define _LKPI_MTX_NOWITNESS MTX_NOWITNESS 53 #define _LKPI_RW_NOWITNESS RW_NOWITNESS 54 #define _LKPI_SX_NOWITNESS SX_NOWITNESS 55 #endif 56 57 58 59 /* -------------------------------------------------------------------------- */ 60 61 /* 62 * Checking if an option is defined would be easy if we could do CPP inside CPP. 63 * The defined case whether -Dxxx or -Dxxx=1 are easy to deal with. In either 64 * case the defined value is "1". A more general -Dxxx=<c> case will require 65 * more effort to deal with all possible "true" values. Hope we do not have 66 * to do this as well. 67 * The real problem is the undefined case. To avoid this problem we do the 68 * concat/varargs trick: "yyy" ## xxx can make two arguments if xxx is "1" 69 * by having a #define for yyy_1 which is "ignore,". 70 * Otherwise we will just get "yyy". 71 * Need to be careful about variable substitutions in macros though. 72 * This way we make a (true, false) problem a (don't care, true, false) or a 73 * (don't care true, false). Then we can use a variadic macro to only select 74 * the always well known and defined argument #2. And that seems to be 75 * exactly what we need. Use 1 for true and 0 for false to also allow 76 * #if IS_*() checks pre-compiler checks which do not like #if true. 77 */ 78 #define ___XAB_1 dontcare, 79 #define ___IS_XAB(_ignore, _x, ...) (_x) 80 #define __IS_XAB(_x) ___IS_XAB(_x 1, 0) 81 #define _IS_XAB(_x) __IS_XAB(__CONCAT(___XAB_, _x)) 82 83 /* This is if CONFIG_ccc=y. */ 84 #define IS_BUILTIN(_x) _IS_XAB(_x) 85 /* This is if CONFIG_ccc=m. */ 86 #define IS_MODULE(_x) _IS_XAB(_x ## _MODULE) 87 /* This is if CONFIG_ccc is compiled in(=y) or a module(=m). */ 88 #define IS_ENABLED(_x) (IS_BUILTIN(_x) || IS_MODULE(_x)) 89 /* 90 * This is weird case. If the CONFIG_ccc is builtin (=y) this returns true; 91 * or if the CONFIG_ccc is a module (=m) and the caller is built as a module 92 * (-DMODULE defined) this returns true, but if the callers is not a module 93 * (-DMODULE not defined, which means caller is BUILTIN) then it returns 94 * false. In other words, a module can reach the kernel, a module can reach 95 * a module, but the kernel cannot reach a module, and code never compiled 96 * cannot be reached either. 97 * XXX -- I'd hope the module-to-module case would be handled by a proper 98 * module dependency definition (MODULE_DEPEND() in FreeBSD). 99 */ 100 #define IS_REACHABLE(_x) (IS_BUILTIN(_x) || \ 101 (IS_MODULE(_x) && IS_BUILTIN(MODULE))) 102 103 /* 104 * On Linux, the CONFIG_PGTABLE_LEVELS value is defined by the config/build 105 * system. Here, we take the per-architecture default value defined in 106 * `arch/$ARCH/Kconfig` files upstream. 107 */ 108 #if defined(__amd64__) 109 110 #define CONFIG_PGTABLE_LEVELS 4 111 112 #elif defined(__aarch64__) 113 114 #define CONFIG_PGTABLE_LEVELS 4 115 116 #elif defined(__i386__) 117 118 #define CONFIG_PGTABLE_LEVELS 2 119 120 #elif defined(__powerpc__) 121 122 #if defined(__powerpc64__) 123 #define CONFIG_PGTABLE_LEVELS 4 124 #else 125 #define CONFIG_PGTABLE_LEVELS 2 126 #endif 127 128 #elif defined(__riscv) 129 130 #if defined(__riscv_xlen) && __riscv_xlen == 64 131 #define CONFIG_PGTABLE_LEVELS 5 132 #else 133 #define CONFIG_PGTABLE_LEVELS 2 134 #endif 135 136 #endif 137 138 #endif /* _LINUXKPI_LINUX_KCONFIG_H_ */ 139