|
- /*-
- * SPDX-License-Identifier: BSD-4-Clause
- *
- * Copyright (c) 1995 Terrence R. Lambert
- * Copyright 2022 John-Mark Gurney
- * All rights reserved.
- *
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
- * (c) UNIX System Laboratories, Inc.
- * All or some portions of this file are derived from material licensed
- * to the University of California by American Telephone and Telegraph
- * Co. or Unix System Laboratories, Inc. and are reproduced herein with
- * the permission of UNIX System Laboratories, Inc.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)kernel.h 8.3 (Berkeley) 1/21/94
- * $FreeBSD$
- */
-
- /*
- * This system is similar to FreeBSD's SYSINIT(9), but w/ minor
- * modifications.
- */
-
- #ifndef _SYSINIT_H_
- #define _SYSINIT_H_ 1
-
- /* for __WEAK */
- #include <cmsis_compiler.h>
-
- #include <stdint.h>
- #include <linker_set.h>
-
- /* from FreeBSD sys/systm.h */
- #define CTASSERT(x) _Static_assert(x, "compile-time assertion failed")
-
- #define MAKE_SUBORDER(subsys, order) ((uint32_t)((subsys) << 16) | (order))
- #define GET_SUBSYS(x) (((x) >> 16) & 0xffff)
- #define GET_ORDER(x) ((x) & 0xffff)
-
- enum sysinit_sub_id {
- SI_SUB_DUMMY = 0x0000, /* not executed; for linker*/
-
- SI_SUB_HAL = 0x0010, /* Early HAL init */
- SI_SUB_GPIO = 0x0030, /* Early GPIO */
- SI_SUB_USB = 0x0300, /* USB */
- SI_SUB_CONSOLE = 0x0700, /* Setup console/debug prints */
-
- SI_SUB_COPYRIGHT = 0x0800, /* start of when printf works */
-
- SI_SUB_STANDARD = 0x8000, /* standard later initalization */
-
- SI_SUB_LAST = 0xffff /* final initialization */
- };
-
- /*
- * Some enumerated orders; "ANY" sorts last.
- */
- enum sysinit_elem_order {
- SI_ORDER_FIRST = 0x0000, /* first*/
- SI_ORDER_SECOND = 0x0001, /* second*/
- SI_ORDER_THIRD = 0x0002, /* third*/
- SI_ORDER_FOURTH = 0x0003, /* fourth*/
- SI_ORDER_FIFTH = 0x0004, /* fifth*/
- SI_ORDER_SIXTH = 0x0005, /* sixth*/
- SI_ORDER_SEVENTH = 0x0006, /* seventh*/
- SI_ORDER_EIGHTH = 0x0007, /* eighth*/
- SI_ORDER_MIDDLE = 0x1000, /* somewhere in the middle */
- SI_ORDER_ANY = 0xfffe, /* second to last */
- SI_ORDER_LAST = 0xffff /* last*/
- };
-
- typedef void (*sysinit_cfunc_t)(const void *);
-
- struct sysinit {
- uint32_t si_subsys_order;
- sysinit_cfunc_t si_func;
- const void *si_udata;
- };
-
- #define SYSINIT(uniquifier, subsystem, order, func, udata) \
- CTASSERT(((subsystem) & 0xffff) == (subsystem)); \
- CTASSERT(((order) & 0xffff) == (order)); \
- static const struct sysinit uniquifier ## _sys_init = { \
- .si_subsys_order = MAKE_SUBORDER((subsystem), (order)), \
- .si_func = (func), \
- .si_udata = (udata), \
- }; \
- DATA_SET(sysinit_set,uniquifier ## _sys_init)
- #define SYSINIT_VF(uniquifier, subsystem, order, func) \
- SYSINIT(uniquifier, (subsystem), (order), (void (*)(const void *))(func), NULL)
-
- void sysinit_run(void);
-
- #endif /* _SYSINIT_H_ */
|