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 */
45
46#ifndef _SYS_KERNEL_H_
47#define	_SYS_KERNEL_H_
48
49#define      __GNUCLIKE___SECTION 1
50#include <sys/linker_set.h>
51
52/*
53 * Enumerated types for known system startup interfaces.
54 *
55 * Startup occurs in ascending numeric order; the list entries are
56 * sorted prior to attempting startup to guarantee order.  Items
57 * of the same level are arbitrated for order based on the 'order'
58 * element.
59 *
60 * These numbers are arbitrary and are chosen ONLY for ordering; the
61 * enumeration values are explicit rather than implicit to provide
62 * for binary compatibility with inserted elements.
63 *
64 * The SI_SUB_LAST value must have the highest lexical value.
65 */
66enum sysinit_sub_id {
67	SI_SUB_KMEM		= 0x1800000,	/* kernel memory*/
68	SI_SUB_DRIVERS		= 0x3100000,	/* Let Drivers initialize */
69	SI_SUB_CONFIGURE	= 0x3800000,	/* Configure devices */
70	SI_SUB_ROOT_CONF	= 0xb000000,	/* Find root devices */
71	SI_SUB_LAST		= 0xfffffff	/* final initialization */
72};
73
74/*
75 * Some enumerated orders; "ANY" sorts last.
76 */
77enum sysinit_elem_order {
78	SI_ORDER_FIRST		= 0x0000000,	/* first*/
79	SI_ORDER_SECOND		= 0x0000001,	/* second*/
80	SI_ORDER_THIRD		= 0x0000002,	/* third*/
81	SI_ORDER_FOURTH		= 0x0000003,	/* fourth*/
82	SI_ORDER_FIFTH		= 0x0000004,	/* fifth*/
83	SI_ORDER_SIXTH		= 0x0000005,	/* sixth*/
84	SI_ORDER_SEVENTH	= 0x0000006,	/* seventh*/
85	SI_ORDER_EIGHTH		= 0x0000007,	/* eighth*/
86	SI_ORDER_MIDDLE		= 0x1000000,	/* somewhere in the middle */
87	SI_ORDER_ANY		= 0xfffffff	/* last*/
88};
89
90/*
91 * A system initialization call instance
92 *
93 * At the moment there is one instance of sysinit.  We probably do not
94 * want two which is why this code is if'd out, but we definitely want
95 * to discern SYSINIT's which take non-constant data pointers and
96 * SYSINIT's which take constant data pointers,
97 *
98 * The C_* macros take functions expecting const void * arguments
99 * while the non-C_* macros take functions expecting just void * arguments.
100 *
101 * With -Wcast-qual on, the compiler issues warnings:
102 *	- if we pass non-const data or functions taking non-const data
103 *	  to a C_* macro.
104 *
105 *	- if we pass const data to the normal macros
106 *
107 * However, no warning is issued if we pass a function taking const data
108 * through a normal non-const macro.  This is ok because the function is
109 * saying it won't modify the data so we don't care whether the data is
110 * modifiable or not.
111 */
112
113typedef void (*sysinit_nfunc_t)(void *);
114typedef void (*sysinit_cfunc_t)(const void *);
115
116struct sysinit {
117	enum sysinit_sub_id	subsystem;	/* subsystem identifier*/
118	enum sysinit_elem_order	order;		/* init order within subsystem*/
119	sysinit_cfunc_t func;			/* function		*/
120	const void	*udata;			/* multiplexer/argument */
121};
122
123/*
124 * Default: no special processing
125 *
126 * The C_ version of SYSINIT is for data pointers to const
127 * data ( and functions taking data pointers to const data ).
128 * At the moment it is no different from SYSINIT and thus
129 * still results in warnings.
130 *
131 * The casts are necessary to have the compiler produce the
132 * correct warnings when -Wcast-qual is used.
133 *
134 */
135#define	C_SYSINIT(uniquifier, subsystem, order, func, ident)	\
136	static struct sysinit uniquifier ## _sys_init = {	\
137		subsystem,					\
138		order,						\
139		func,						\
140		(ident)						\
141	};							\
142	DATA_SET(sysinit_set,uniquifier ## _sys_init)
143
144#define	SYSINIT(uniquifier, subsystem, order, func, ident)	\
145	C_SYSINIT(uniquifier, subsystem, order,			\
146	(sysinit_cfunc_t)(sysinit_nfunc_t)func, (void *)(ident))
147
148/*
149 * Called on module unload: no special processing
150 */
151#define	C_SYSUNINIT(uniquifier, subsystem, order, func, ident)	\
152	static struct sysinit uniquifier ## _sys_uninit = {	\
153		subsystem,					\
154		order,						\
155		func,						\
156		(ident)						\
157	};							\
158	DATA_SET(sysuninit_set,uniquifier ## _sys_uninit)
159
160#define	SYSUNINIT(uniquifier, subsystem, order, func, ident)	\
161	C_SYSUNINIT(uniquifier, subsystem, order,		\
162	(sysinit_cfunc_t)(sysinit_nfunc_t)func, (void *)(ident))
163#endif /* !_SYS_KERNEL_H_*/
164