forked from thesofproject/sof
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.c
More file actions
317 lines (258 loc) · 7.47 KB
/
init.c
File metadata and controls
317 lines (258 loc) · 7.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
// SPDX-License-Identifier: BSD-3-Clause
//
// Copyright(c) 2016 Intel Corporation. All rights reserved.
//
// Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
/*
* Generic DSP initialisation. This calls architecture and platform specific
* initialisation functions.
*/
#include <sof/debug/panic.h>
#include <rtos/interrupt.h>
#include <sof/init.h>
#include <sof/lib/cpu.h>
#include <sof/lib/memory.h>
#include <sof/lib/mm_heap.h>
#include <sof/lib/notifier.h>
#include <sof/lib/pm_runtime.h>
#include <rtos/wait.h>
#include <sof/platform.h>
#include <sof/schedule/task.h>
#include <sof/sof.h>
#include <sof/trace/trace.h>
#include <sof/drivers/idc.h>
#include <sof/schedule/schedule.h>
#include <sof/schedule/edf_schedule.h>
#include <sof/schedule/ll_schedule.h>
#include <sof/schedule/ll_schedule_domain.h>
#include <ipc/trace.h>
#if CONFIG_IPC_MAJOR_4
#include <ipc4/fw_reg.h>
#endif
#ifdef CONFIG_ZEPHYR_LOG
#include <zephyr/logging/log_ctrl.h>
#include <user/abi_dbg.h>
#include <sof_versions.h>
#include <version.h>
#endif
LOG_MODULE_REGISTER(init, CONFIG_SOF_LOG_LEVEL);
/* main firmware context */
static struct sof sof;
struct sof *sof_get(void)
{
return &sof;
}
#if CONFIG_NO_SECONDARY_CORE_ROM
/**
* \brief This function will unpack lpsram text sections from AltBootManifest
created in linker script.
AltBootManifest structure:
- number of entries
and for each entry:
- source pointer
- destination pointer
- size
*/
static inline void lp_sram_unpack(void)
{
extern uintptr_t _loader_storage_manifest_start;
uint32_t *src, *dst;
uint32_t size, i;
uint32_t *ptr = (uint32_t *)&_loader_storage_manifest_start;
uint32_t entries = *ptr++;
for (i = 0; i < entries; i++) {
src = (uint32_t *)*ptr++;
dst = (uint32_t *)*ptr++;
size = *ptr++;
memcpy_s(dst, size, src, size);
dcache_writeback_region((__sparse_force void __sparse_cache *)dst, size);
}
}
#endif
#if CONFIG_MULTICORE
#ifndef __ZEPHYR__
static int check_restore(void)
{
struct idc *idc = *idc_get();
struct task *task = *task_main_get();
struct notify *notifier = *arch_notify_get();
struct schedulers *schedulers = *arch_schedulers_get();
/* check whether basic core structures has been already allocated. If they
* are available in memory, it means that this is not cold boot and memory
* has not been powered off.
*/
if (!idc || !task || !notifier || !schedulers)
return 0;
return 1;
}
static int secondary_core_restore(void)
{
int err;
trace_point(TRACE_BOOT_PLATFORM_IRQ);
/* initialize interrupts */
platform_interrupt_init();
/* As the memory was not turned of in D0->D0ix and basic structures are
* already allocated, in restore process (D0ix->D0) we have only to
* register and enable required interrupts (it is done in
* schedulers_restore() and idc_restore()).
*/
/* restore schedulers i.e. register and enable scheduler interrupts */
trace_point(TRACE_BOOT_PLATFORM_SCHED);
err = schedulers_restore();
if (err < 0)
return err;
/* restore idc i.e. register and enable idc interrupts */
trace_point(TRACE_BOOT_PLATFORM_IDC);
err = idc_restore();
if (err < 0)
return err;
trace_point(TRACE_BOOT_PLATFORM);
/* In restore case (D0ix->D0 flow) we do not have to invoke here
* schedule_task(*task_main_get(), 0, UINT64_MAX) as it is done in
* cold boot process (see end of secondary_core_init() function),
* because in restore case memory has not been powered off and task_main
* is already added into scheduler list.
*/
while (1)
wait_for_interrupt(0);
}
#endif
int secondary_core_init(struct sof *sof)
{
int err;
struct ll_schedule_domain *dma_domain;
#ifndef __ZEPHYR__
/* init architecture */
trace_point(TRACE_BOOT_ARCH);
err = arch_init();
if (err < 0)
sof_panic(SOF_IPC_PANIC_ARCH);
/* check whether we are in a cold boot process or not (e.g. D0->D0ix
* flow when primary core disables all secondary cores). If not, we do
* not have allocate basic structures like e.g. schedulers, notifier,
* because they have been already allocated. In that case we have to
* register and enable required interrupts.
*/
if (check_restore())
return secondary_core_restore();
#endif
trace_point(TRACE_BOOT_SYS_NOTIFIER);
init_system_notify(sof);
#ifndef __ZEPHYR__
/* interrupts need to be initialized before any usage */
trace_point(TRACE_BOOT_PLATFORM_IRQ);
platform_interrupt_init();
scheduler_init_edf();
#endif
trace_point(TRACE_BOOT_PLATFORM_SCHED);
scheduler_init_ll(timer_domain_get());
dma_domain = dma_domain_get();
if (dma_domain)
scheduler_init_ll(dma_domain);
/* initialize IDC mechanism */
trace_point(TRACE_BOOT_PLATFORM_IDC);
err = idc_init();
if (err < 0)
return err;
trace_point(TRACE_BOOT_PLATFORM);
#ifndef __ZEPHYR__
/* task initialized in edf_scheduler_init */
schedule_task(*task_main_get(), 0, UINT64_MAX);
#endif
return err;
}
#endif
static void print_version_banner(void)
{
/*
* Non-Zephyr builds emit the version banner in DMA-trace
* init and this is done at a later time as otherwise the
* banner would be lost. With Zephyr logging subsystem in use,
* we can simply print the banner at boot.
*
* META_QUOTE(SOF_SRC_HASH) is part of the format string so it
* is part of log dictionary meta data and does not go to
* the firmware binary (in case dictionary logging is used).
* The value printed to log will be different from
* SOF_SRC_HASH in case of mismatch.
*/
#ifdef CONFIG_ZEPHYR_LOG
LOG_INF("FW ABI 0x%x DBG ABI 0x%x tags SOF:" SOF_GIT_TAG " zephyr:" \
META_QUOTE(BUILD_VERSION) " src hash 0x%08x (ref hash " \
META_QUOTE(SOF_SRC_HASH) ")",
SOF_ABI_VERSION, SOF_ABI_DBG_VERSION, SOF_SRC_HASH);
#endif
}
#ifdef CONFIG_ZEPHYR_LOG
static log_timestamp_t default_get_timestamp(void)
{
return IS_ENABLED(CONFIG_LOG_TIMESTAMP_64BIT) ?
sys_clock_tick_get() : k_cycle_get_32();
}
#endif
static int primary_core_init(int argc, char *argv[], struct sof *sof)
{
/* setup context */
sof->argc = argc;
sof->argv = argv;
#ifndef __ZEPHYR__
/* init architecture */
trace_point(TRACE_BOOT_ARCH);
if (arch_init() < 0)
sof_panic(SOF_IPC_PANIC_ARCH);
/* initialise system services */
trace_point(TRACE_BOOT_SYS_HEAP);
platform_init_memmap(sof);
init_heap(sof);
interrupt_init(sof);
#endif /* __ZEPHYR__ */
#ifdef CONFIG_ZEPHYR_LOG
log_set_timestamp_func(default_get_timestamp,
sys_clock_hw_cycles_per_sec());
#endif
#if CONFIG_TRACE
trace_point(TRACE_BOOT_SYS_TRACES);
trace_init(sof);
#endif
print_version_banner();
trace_point(TRACE_BOOT_SYS_NOTIFIER);
init_system_notify(sof);
trace_point(TRACE_BOOT_SYS_POWER);
pm_runtime_init(sof);
/* init the platform */
if (platform_init(sof) < 0)
sof_panic(SOF_IPC_PANIC_PLATFORM);
#if CONFIG_IPC_MAJOR_4
/* Set current abi version of the IPC4 FwRegisters layout */
size_t ipc4_abi_ver_offset = offsetof(struct ipc4_fw_registers, abi_ver);
mailbox_sw_reg_write(ipc4_abi_ver_offset, IPC4_FW_REGS_ABI_VER);
#endif
trace_point(TRACE_BOOT_PLATFORM);
#if CONFIG_NO_SECONDARY_CORE_ROM
lp_sram_unpack();
#endif
/* should not return, except with Zephyr */
return task_main_start(sof);
}
#ifndef __ZEPHYR__
int main(int argc, char *argv[])
{
int err = 0;
trace_point(TRACE_BOOT_START);
if (cpu_get_id() == PLATFORM_PRIMARY_CORE_ID)
err = primary_core_init(argc, argv, &sof);
#if CONFIG_MULTICORE
else
err = secondary_core_init(&sof);
#endif
/* should never get here */
sof_panic(SOF_IPC_PANIC_TASK);
return err;
}
#else
int sof_main(int argc, char *argv[])
{
trace_point(TRACE_BOOT_START);
return primary_core_init(argc, argv, &sof);
}
#endif