Skip to content

Commit a5fd0d1

Browse files
gmarullfabiobaltieri
authored andcommitted
init: remove the need for a dummy device pointer in SYS_INIT functions
The init infrastructure, found in `init.h`, is currently used by: - `SYS_INIT`: to call functions before `main` - `DEVICE_*`: to initialize devices They are all sorted according to an initialization level + a priority. `SYS_INIT` calls are really orthogonal to devices, however, the required function signature requires a `const struct device *dev` as a first argument. The only reason for that is because the same init machinery is used by devices, so we have something like: ```c struct init_entry { int (*init)(const struct device *dev); /* only set by DEVICE_*, otherwise NULL */ const struct device *dev; } ``` As a result, we end up with such weird/ugly pattern: ```c static int my_init(const struct device *dev) { /* always NULL! add ARG_UNUSED to avoid compiler warning */ ARG_UNUSED(dev); ... } ``` This is really a result of poor internals isolation. This patch proposes a to make init entries more flexible so that they can accept sytem initialization calls like this: ```c static int my_init(void) { ... } ``` This is achieved using a union: ```c union init_function { /* for SYS_INIT, used when init_entry.dev == NULL */ int (*sys)(void); /* for DEVICE*, used when init_entry.dev != NULL */ int (*dev)(const struct device *dev); }; struct init_entry { /* stores init function (either for SYS_INIT or DEVICE*) union init_function init_fn; /* stores device pointer for DEVICE*, NULL for SYS_INIT. Allows * to know which union entry to call. */ const struct device *dev; } ``` This solution **does not increase ROM usage**, and allows to offer clean public APIs for both SYS_INIT and DEVICE*. Note that however, init machinery keeps a coupling with devices. **NOTE**: This is a breaking change! All `SYS_INIT` functions will need to be converted to the new signature. See the script offered in the following commit. Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no> init: convert SYS_INIT functions to the new signature Conversion scripted using scripts/utils/migrate_sys_init.py. Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no> manifest: update projects for SYS_INIT changes Update modules with updated SYS_INIT calls: - hal_ti - lvgl - sof - TraceRecorderSource Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no> tests: devicetree: devices: adjust test Adjust test according to the recently introduced SYS_INIT infrastructure. Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no> tests: kernel: threads: adjust SYS_INIT call Adjust to the new signature: int (*init_fn)(void); Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
1 parent 2a76637 commit a5fd0d1

File tree

413 files changed

+499
-818
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

413 files changed

+499
-818
lines changed

arch/arc/core/arc_smp.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,8 @@ void arch_sched_ipi(void)
145145
}
146146
}
147147

148-
static int arc_smp_init(const struct device *dev)
148+
static int arc_smp_init(void)
149149
{
150-
ARG_UNUSED(dev);
151150
struct arc_connect_bcr bcr;
152151

153152
/* necessary master core init */

arch/arc/core/cache.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,8 @@ int arch_icache_flush_and_invd_range(void *addr, size_t size)
216216
return -ENOTSUP;
217217
}
218218

219-
static int init_dcache(const struct device *unused)
219+
static int init_dcache(void)
220220
{
221-
ARG_UNUSED(unused);
222221

223222
arch_dcache_enable();
224223

arch/arc/core/irq_offload.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,8 @@ void arch_irq_offload(irq_offload_routine_t routine, const void *parameter)
5454
}
5555

5656
/* need to be executed on every core in the system */
57-
int arc_irq_offload_init(const struct device *unused)
57+
int arc_irq_offload_init(void)
5858
{
59-
ARG_UNUSED(unused);
6059

6160
IRQ_CONNECT(IRQ_OFFLOAD_LINE, IRQ_OFFLOAD_PRIO, arc_irq_offload_handler, NULL, 0);
6261

arch/arc/core/mpu/arc_mpu_common_internal.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,8 @@ int arc_core_mpu_buffer_validate(void *addr, size_t size, int write)
238238
* This function provides the default configuration mechanism for the Memory
239239
* Protection Unit (MPU).
240240
*/
241-
static int arc_mpu_init(const struct device *arg)
241+
static int arc_mpu_init(void)
242242
{
243-
ARG_UNUSED(arg);
244243

245244
uint32_t num_regions = get_num_regions();
246245

arch/arc/core/mpu/arc_mpu_v4_internal.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -814,9 +814,8 @@ int arc_core_mpu_buffer_validate(void *addr, size_t size, int write)
814814
* This function provides the default configuration mechanism for the Memory
815815
* Protection Unit (MPU).
816816
*/
817-
static int arc_mpu_init(const struct device *arg)
817+
static int arc_mpu_init(void)
818818
{
819-
ARG_UNUSED(arg);
820819
uint32_t num_regions;
821820
uint32_t i;
822821

arch/arc/core/secureshield/arc_sjli.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static void sjli_table_init(void)
4848
/*
4949
* @brief initialization of secureshield related functions.
5050
*/
51-
static int arc_secureshield_init(const struct device *arg)
51+
static int arc_secureshield_init(void)
5252
{
5353
sjli_table_init();
5454

arch/arm/core/aarch32/cortex_m/debug.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,8 @@ BUILD_ASSERT(!(CONFIG_CORTEX_M_NULL_POINTER_EXCEPTION_PAGE_SIZE &
5858
(CONFIG_CORTEX_M_NULL_POINTER_EXCEPTION_PAGE_SIZE - 1)),
5959
"the size of the partition must be power of 2");
6060

61-
static int z_arm_debug_enable_null_pointer_detection(const struct device *arg)
61+
static int z_arm_debug_enable_null_pointer_detection(void)
6262
{
63-
ARG_UNUSED(arg);
6463

6564
z_arm_dwt_init();
6665
z_arm_dwt_enable_debug_monitor();

arch/arm64/core/smp.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,8 @@ void z_arm64_flush_fpu_ipi(unsigned int cpu)
226226
}
227227
#endif
228228

229-
static int arm64_smp_init(const struct device *dev)
229+
static int arm64_smp_init(void)
230230
{
231-
ARG_UNUSED(dev);
232231

233232
/*
234233
* SGI0 is use for sched ipi, this might be changed to use Kconfig

arch/arm64/core/xen/enlighten.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@ static int xen_map_shared_info(const shared_info_t *shared_page)
4242
return HYPERVISOR_memory_op(XENMEM_add_to_physmap, &xatp);
4343
}
4444

45-
static int xen_enlighten_init(const struct device *dev)
45+
static int xen_enlighten_init(void)
4646
{
47-
ARG_UNUSED(dev);
4847
int ret = 0;
4948
shared_info_t *info = (shared_info_t *) shared_info_buf;
5049

arch/riscv/core/smp.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,8 @@ static void ipi_handler(const void *unused)
118118
#endif
119119
}
120120

121-
static int riscv_smp_init(const struct device *dev)
121+
static int riscv_smp_init(void)
122122
{
123-
ARG_UNUSED(dev);
124123

125124
IRQ_CONNECT(RISCV_MACHINE_SOFT_IRQ, 0, ipi_handler, NULL, 0);
126125
irq_enable(RISCV_MACHINE_SOFT_IRQ);

0 commit comments

Comments
 (0)