Commit 9ff30a14 authored by Gerard Marull-Paretas's avatar Gerard Marull-Paretas Committed by Fabio Baltieri
Browse files

init: remove support for devices

Devices no longer use SYS_INIT infrastructure.

Signed-off-by: default avatarGerard Marull-Paretas <gerard@teslabs.com>
parent db747c08
Loading
Loading
Loading
Loading
+10 −97
Changes for include/zephyr/init.h: 10 added lines, 97 removed lines.
Original line number Diff line number Diff line
@@ -42,81 +42,14 @@ extern "C" {
 *   SMP.
 *
 * Initialization priority can take a value in the range of 0 to 99.
 *
 * @note The same infrastructure is used by devices.
 * @{
 */

struct device;

/**
 * @brief Initialization function for init entries.
 *
 * Init entries support both the system initialization and the device
 * APIs. Each API has its own init function signature; hence, we have a
 * union to cover both.
 */
union init_function {
	/**
	 * System initialization function.
	 *
	 * @retval 0 On success
	 * @retval -errno If init fails.
	 */
	int (*sys)(void);
	/**
	 * Device initialization function.
	 *
	 * @param dev Device instance.
	 *
	 * @retval 0 On success
	 * @retval -errno If device initialization fails.
	 */
	int (*dev)(const struct device *dev);
};

/**
 * @brief Structure to store initialization entry information.
 *
 * @internal
 * Init entries need to be defined following these rules:
 *
 * - Their name must be set using Z_INIT_ENTRY_NAME().
 * - They must be placed in a special init section, given by
 *   Z_INIT_ENTRY_SECTION().
 * - They must be aligned, e.g. using Z_DECL_ALIGN().
 *
 * See SYS_INIT_NAMED() for an example.
 * @endinternal
 */
struct init_entry {
	/** Initialization function. */
	union init_function init_fn;
	/**
	 * If the init entry belongs to a device, this fields stores a
	 * reference to it, otherwise it is set to NULL.
	 */
	const struct device *dev;
};
/** System initialization function. */
typedef int (*sys_init_fn_t)(void);

/** @cond INTERNAL_HIDDEN */

/* Helper definitions to evaluate level equality */
#define Z_INIT_EARLY_EARLY		 1
#define Z_INIT_PRE_KERNEL_1_PRE_KERNEL_1 1
#define Z_INIT_PRE_KERNEL_2_PRE_KERNEL_2 1
#define Z_INIT_POST_KERNEL_POST_KERNEL	 1
#define Z_INIT_APPLICATION_APPLICATION	 1
#define Z_INIT_SMP_SMP			 1

/* Init level ordinals */
#define Z_INIT_ORD_EARLY	0
#define Z_INIT_ORD_PRE_KERNEL_1 1
#define Z_INIT_ORD_PRE_KERNEL_2 2
#define Z_INIT_ORD_POST_KERNEL	3
#define Z_INIT_ORD_APPLICATION	4
#define Z_INIT_ORD_SMP		5

/**
 * @brief Obtain init entry name.
 *
@@ -131,29 +64,12 @@ struct init_entry {
 * linker scripts to sort them according to the specified
 * level/priority/sub-priority.
 */
#define Z_INIT_ENTRY_SECTION(level, prio, sub_prio)                           \
	__attribute__((__section__(                                           \
		".z_init_" #level STRINGIFY(prio)"_" STRINGIFY(sub_prio)"_")))
#define Z_INIT_ENTRY_SECTION(level, prio)                                      \
	__attribute__(                                                         \
		(__section__(".z_init_" #level STRINGIFY(prio)"_")))

/** @endcond */

/**
 * @brief Obtain the ordinal for an init level.
 *
 * @param level Init level (EARLY, PRE_KERNEL_1, PRE_KERNEL_2, POST_KERNEL,
 * APPLICATION, SMP).
 *
 * @return Init level ordinal.
 */
#define INIT_LEVEL_ORD(level)                                                  \
	COND_CODE_1(Z_INIT_EARLY_##level, (Z_INIT_ORD_EARLY),                  \
	(COND_CODE_1(Z_INIT_PRE_KERNEL_1_##level, (Z_INIT_ORD_PRE_KERNEL_1),   \
	(COND_CODE_1(Z_INIT_PRE_KERNEL_2_##level, (Z_INIT_ORD_PRE_KERNEL_2),   \
	(COND_CODE_1(Z_INIT_POST_KERNEL_##level, (Z_INIT_ORD_POST_KERNEL),     \
	(COND_CODE_1(Z_INIT_APPLICATION_##level, (Z_INIT_ORD_APPLICATION),     \
	(COND_CODE_1(Z_INIT_SMP_##level, (Z_INIT_ORD_SMP),                     \
	(ZERO_OR_COMPILE_ERROR(0)))))))))))))

/**
 * @brief Register an initialization function.
 *
@@ -180,19 +96,16 @@ struct init_entry {
 * same init function.
 *
 * @param name Unique name for SYS_INIT entry.
 * @param init_fn_ See SYS_INIT().
 * @param init_fn See SYS_INIT().
 * @param level See SYS_INIT().
 * @param prio See SYS_INIT().
 *
 * @see SYS_INIT()
 */
#define SYS_INIT_NAMED(name, init_fn_, level, prio)                            \
	static const Z_DECL_ALIGN(struct init_entry)                           \
		Z_INIT_ENTRY_SECTION(level, prio, 0) __used __noasan           \
		Z_INIT_ENTRY_NAME(name) = {                                    \
			.init_fn = {.sys = (init_fn_)},                        \
			.dev = NULL,                                           \
	}
#define SYS_INIT_NAMED(name, init_fn, level, prio)                             \
	static const Z_DECL_ALIGN(sys_init_fn_t)                               \
		Z_INIT_ENTRY_SECTION(level, prio) __used __noasan              \
		Z_INIT_ENTRY_NAME(name) = init_fn

/** @} */

+11 −11
Changes for kernel/init.c: 11 added lines, 11 removed lines.
Original line number Diff line number Diff line
@@ -61,13 +61,13 @@ static K_KERNEL_PINNED_STACK_ARRAY_DEFINE(z_idle_stacks,
					  CONFIG_IDLE_STACK_SIZE);
#endif /* CONFIG_MULTITHREADING */

extern const struct init_entry __init_start[];
extern const struct init_entry __init_EARLY_start[];
extern const struct init_entry __init_PRE_KERNEL_1_start[];
extern const struct init_entry __init_PRE_KERNEL_2_start[];
extern const struct init_entry __init_POST_KERNEL_start[];
extern const struct init_entry __init_APPLICATION_start[];
extern const struct init_entry __init_end[];
extern const sys_init_fn_t __init_start[];
extern const sys_init_fn_t __init_EARLY_start[];
extern const sys_init_fn_t __init_PRE_KERNEL_1_start[];
extern const sys_init_fn_t __init_PRE_KERNEL_2_start[];
extern const sys_init_fn_t __init_POST_KERNEL_start[];
extern const sys_init_fn_t __init_APPLICATION_start[];
extern const sys_init_fn_t __init_end[];

extern const struct device _device_list_EARLY_start[];
extern const struct device _device_list_PRE_KERNEL_1_start[];
@@ -89,7 +89,7 @@ enum init_level {
};

#ifdef CONFIG_SMP
extern const struct init_entry __init_SMP_start[];
extern const sys_init_fn_t __init_SMP_start[];

extern const struct device _device_list_SMP_start[];
#endif
@@ -266,7 +266,7 @@ static void z_sys_init_run_level(enum init_level level)
		_device_list_end,
	};

	static const struct init_entry *levels[] = {
	static const sys_init_fn_t *levels[] = {
		__init_EARLY_start,
		__init_PRE_KERNEL_1_start,
		__init_PRE_KERNEL_2_start,
@@ -306,8 +306,8 @@ static void z_sys_init_run_level(enum init_level level)
		}
	}

	for (const struct init_entry *entry = levels[level]; entry < levels[level+1]; entry++) {
		(void)entry->init_fn.sys();
	for (const sys_init_fn_t *entry = levels[level]; entry < levels[level+1]; entry++) {
		(void)(*entry)();
	}
}