1 /*- 2 * SPDX-License-Identifier: BSD-4-Clause 3 * 4 * Copyright (c) 1995 Terrence R. Lambert 5 * All rights reserved. 6 * 7 * Copyright (c) 1990, 1993 8 * The Regents of the University of California. All rights reserved. 9 * (c) UNIX System Laboratories, Inc. 10 * All or some portions of this file are derived from material licensed 11 * to the University of California by American Telephone and Telegraph 12 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 13 * the permission of UNIX System Laboratories, Inc. 14 * 15 * Redistribution and use in source and binary forms, with or without 16 * modification, are permitted provided that the following conditions 17 * are met: 18 * 1. Redistributions of source code must retain the above copyright 19 * notice, this list of conditions and the following disclaimer. 20 * 2. Redistributions in binary form must reproduce the above copyright 21 * notice, this list of conditions and the following disclaimer in the 22 * documentation and/or other materials provided with the distribution. 23 * 3. All advertising materials mentioning features or use of this software 24 * must display the following acknowledgement: 25 * This product includes software developed by the University of 26 * California, Berkeley and its contributors. 27 * 4. Neither the name of the University nor the names of its contributors 28 * may be used to endorse or promote products derived from this software 29 * without specific prior written permission. 30 * 31 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 32 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 33 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 34 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 35 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 39 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 40 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 41 * SUCH DAMAGE. 42 * 43 * @(#)kernel.h 8.3 (Berkeley) 1/21/94 44 * $FreeBSD: releng/12.2/sys/sys/kernel.h 358962 2020-03-13 16:52:16Z markj $ 45 */ 46 47 #ifndef _SYS_KERNEL_H_ 48 #define _SYS_KERNEL_H_ 49 50 #define __GNUCLIKE___SECTION 1 51 #include <sys/linker_set.h> 52 53 /* 54 * Enumerated types for known system startup interfaces. 55 * 56 * Startup occurs in ascending numeric order; the list entries are 57 * sorted prior to attempting startup to guarantee order. Items 58 * of the same level are arbitrated for order based on the 'order' 59 * element. 60 * 61 * These numbers are arbitrary and are chosen ONLY for ordering; the 62 * enumeration values are explicit rather than implicit to provide 63 * for binary compatibility with inserted elements. 64 * 65 * The SI_SUB_LAST value must have the highest lexical value. 66 */ 67 enum sysinit_sub_id { 68 SI_SUB_KMEM = 0x1800000, /* kernel memory*/ 69 SI_SUB_DRIVERS = 0x3100000, /* Let Drivers initialize */ 70 SI_SUB_CONFIGURE = 0x3800000, /* Configure devices */ 71 SI_SUB_ROOT_CONF = 0xb000000, /* Find root devices */ 72 SI_SUB_LAST = 0xfffffff /* final initialization */ 73 }; 74 75 76 /* 77 * Some enumerated orders; "ANY" sorts last. 78 */ 79 enum sysinit_elem_order { 80 SI_ORDER_FIRST = 0x0000000, /* first*/ 81 SI_ORDER_SECOND = 0x0000001, /* second*/ 82 SI_ORDER_THIRD = 0x0000002, /* third*/ 83 SI_ORDER_FOURTH = 0x0000003, /* fourth*/ 84 SI_ORDER_FIFTH = 0x0000004, /* fifth*/ 85 SI_ORDER_SIXTH = 0x0000005, /* sixth*/ 86 SI_ORDER_SEVENTH = 0x0000006, /* seventh*/ 87 SI_ORDER_EIGHTH = 0x0000007, /* eighth*/ 88 SI_ORDER_MIDDLE = 0x1000000, /* somewhere in the middle */ 89 SI_ORDER_ANY = 0xfffffff /* last*/ 90 }; 91 92 93 /* 94 * A system initialization call instance 95 * 96 * At the moment there is one instance of sysinit. We probably do not 97 * want two which is why this code is if'd out, but we definitely want 98 * to discern SYSINIT's which take non-constant data pointers and 99 * SYSINIT's which take constant data pointers, 100 * 101 * The C_* macros take functions expecting const void * arguments 102 * while the non-C_* macros take functions expecting just void * arguments. 103 * 104 * With -Wcast-qual on, the compiler issues warnings: 105 * - if we pass non-const data or functions taking non-const data 106 * to a C_* macro. 107 * 108 * - if we pass const data to the normal macros 109 * 110 * However, no warning is issued if we pass a function taking const data 111 * through a normal non-const macro. This is ok because the function is 112 * saying it won't modify the data so we don't care whether the data is 113 * modifiable or not. 114 */ 115 116 typedef void (*sysinit_nfunc_t)(void *); 117 typedef void (*sysinit_cfunc_t)(const void *); 118 119 struct sysinit { 120 enum sysinit_sub_id subsystem; /* subsystem identifier*/ 121 enum sysinit_elem_order order; /* init order within subsystem*/ 122 sysinit_cfunc_t func; /* function */ 123 const void *udata; /* multiplexer/argument */ 124 }; 125 126 /* 127 * Default: no special processing 128 * 129 * The C_ version of SYSINIT is for data pointers to const 130 * data ( and functions taking data pointers to const data ). 131 * At the moment it is no different from SYSINIT and thus 132 * still results in warnings. 133 * 134 * The casts are necessary to have the compiler produce the 135 * correct warnings when -Wcast-qual is used. 136 * 137 */ 138 #define C_SYSINIT(uniquifier, subsystem, order, func, ident) \ 139 static struct sysinit uniquifier ## _sys_init = { \ 140 subsystem, \ 141 order, \ 142 func, \ 143 (ident) \ 144 }; \ 145 DATA_SET(sysinit_set,uniquifier ## _sys_init) 146 147 #define SYSINIT(uniquifier, subsystem, order, func, ident) \ 148 C_SYSINIT(uniquifier, subsystem, order, \ 149 (sysinit_cfunc_t)(sysinit_nfunc_t)func, (void *)(ident)) 150 151 /* 152 * Called on module unload: no special processing 153 */ 154 #define C_SYSUNINIT(uniquifier, subsystem, order, func, ident) \ 155 static struct sysinit uniquifier ## _sys_uninit = { \ 156 subsystem, \ 157 order, \ 158 func, \ 159 (ident) \ 160 }; \ 161 DATA_SET(sysuninit_set,uniquifier ## _sys_uninit) 162 163 #define SYSUNINIT(uniquifier, subsystem, order, func, ident) \ 164 C_SYSUNINIT(uniquifier, subsystem, order, \ 165 (sysinit_cfunc_t)(sysinit_nfunc_t)func, (void *)(ident)) 166 #endif /* !_SYS_KERNEL_H_*/ 167