Repository navigation
Expand file tree
/
Copy pathplatform.c
More file actions
241 lines (202 loc) · 6.3 KB
/
Copy pathplatform.c
File metadata and controls
241 lines (202 loc) · 6.3 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
// SPDX-License-Identifier: BSD-3-Clause
//
// Copyright(c) 2018 Intel Corporation. All rights reserved.
//
// Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
// Keyon Jie <yang.jie@linux.intel.com>
// Rander Wang <rander.wang@intel.com>
// Janusz Jankowski <janusz.jankowski@linux.intel.com>
#include <cavs/version.h>
#include <sof/common.h>
#include <sof/compiler_info.h>
#include <sof/debug/debug.h>
#include <rtos/idc.h>
#include <sof/ipc/common.h>
#include <rtos/timer.h>
#include <sof/fw-ready-metadata.h>
#include <sof/lib/agent.h>
#include <rtos/cache.h>
#include <rtos/clk.h>
#include <sof/lib/cpu.h>
#include <sof/lib/dai.h>
#include <sof/lib/dma.h>
#include <sof/lib/io.h>
#include <sof/lib/mailbox.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/edf_schedule.h>
#include <sof/schedule/ll_schedule.h>
#include <sof/schedule/ll_schedule_domain.h>
#include <sof/trace/trace.h>
#include <ipc/header.h>
#include <ipc/info.h>
#include <kernel/abi.h>
#include <kernel/ext_manifest.h>
#include <sof_versions.h>
#include <errno.h>
#include <stdint.h>
static const struct sof_ipc_fw_ready ready
__section(".fw_ready") = {
.hdr = {
.cmd = SOF_IPC_FW_READY,
.size = sizeof(struct sof_ipc_fw_ready),
},
.version = {
.hdr.size = sizeof(struct sof_ipc_fw_version),
.micro = SOF_MICRO,
.minor = SOF_MINOR,
.major = SOF_MAJOR,
/* opt-in; reproducible build by default */
#if BLD_COUNTERS
.build = SOF_BUILD, /* See version-build-counter.cmake */
.date = __DATE__,
.time = __TIME__,
#else
.build = -1,
.date = "dtermin.\0",
.time = "fwready.\0",
#endif
.tag = SOF_TAG,
.abi_version = SOF_ABI_VERSION,
.src_hash = SOF_SRC_HASH,
},
#if CONFIG_CAVS_IMR_D3_PERSISTENT
.flags = DEBUG_SET_FW_READY_FLAGS | SOF_IPC_INFO_D3_PERSISTENT,
#else
.flags = DEBUG_SET_FW_READY_FLAGS,
#endif
};
#define SRAM_WINDOW_HOST_OFFSET(x) (0x80000 + x * 0x20000)
#if CONFIG_TIGERLAKE
#define CAVS_DEFAULT_RO SHIM_CLKCTL_RHROSCC
#define CAVS_DEFAULT_RO_FOR_MEM SHIM_CLKCTL_OCS_HP_RING
#endif
int platform_boot_complete(uint32_t boot_message)
{
struct ipc_cmd_hdr header;
#if CONFIG_TIGERLAKE
/* TGL specific HW recommended flow */
pm_runtime_get(PM_RUNTIME_DSP, PWRD_BY_HPRO | (CONFIG_CORE_COUNT - 1));
#endif
mailbox_dspbox_write(0, &ready, sizeof(ready));
/* get any IPC specific boot message and optional data */
ipc_boot_complete_msg(&header, SRAM_WINDOW_HOST_OFFSET(0) >> 12);
/* tell host we are ready (IPC4) */
ipc_write(IPC_DIPCIDD, header.ext);
ipc_write(IPC_DIPCIDR, IPC_DIPCIDR_BUSY | header.pri);
return 0;
}
static struct pm_notifier pm_state_notifier = {
.state_exit = cpu_notify_state_exit,
};
/* Runs on the primary core only */
int platform_init(struct sof *sof)
{
int ret;
int i;
/* Turn off memory for all unused cores */
for (i = 0; i < CONFIG_CORE_COUNT; i++)
if (i != PLATFORM_PRIMARY_CORE_ID)
pm_runtime_put(CORE_MEMORY_POW, i);
/* pm runtime already initialized, request the DSP to stay in D0
* until we are allowed to do full power gating (by the IPC req).
*/
pm_runtime_disable(PM_RUNTIME_DSP, 0);
trace_point(TRACE_BOOT_PLATFORM_CLOCK);
platform_clock_init(sof);
trace_point(TRACE_BOOT_PLATFORM_SCHED);
scheduler_init_edf();
/* init low latency timer domain and scheduler */
sof->platform_timer_domain = timer_domain_init(sof->platform_timer, PLATFORM_DEFAULT_CLOCK);
scheduler_init_ll(sof->platform_timer_domain);
/* init the system agent */
trace_point(TRACE_BOOT_PLATFORM_AGENT);
sa_init(sof, CONFIG_SYSTICK_PERIOD);
/* Set CPU to max frequency for booting (single shim_write below) */
trace_point(TRACE_BOOT_PLATFORM_CPU_FREQ);
#if CONFIG_TIGERLAKE
/* prevent DSP Common power gating */
pm_runtime_get(PM_RUNTIME_DSP, PLATFORM_PRIMARY_CORE_ID);
#if CONFIG_DSP_RESIDENCY_COUNTERS
init_dsp_r_state(r0_r_state);
#endif /* CONFIG_DSP_RESIDENCY_COUNTERS */
#endif /* CONFIG_TIGERLAKE */
/* init DMACs */
trace_point(TRACE_BOOT_PLATFORM_DMA);
ret = dmac_init(sof);
if (ret < 0)
return ret;
/* register power states exit notifiers */
pm_notifier_register(&pm_state_notifier);
/* initialize the host IPC mechanisms */
trace_point(TRACE_BOOT_PLATFORM_IPC);
ipc_init(sof);
/* initialize IDC mechanism */
trace_point(TRACE_BOOT_PLATFORM_IDC);
ret = idc_init();
if (ret < 0)
return ret;
/* init DAIs */
trace_point(TRACE_BOOT_PLATFORM_DAI);
ret = dai_init(sof);
if (ret < 0)
return ret;
/* show heap status */
heap_trace_all(1);
return 0;
}
#if CONFIG_CAVS_IMR_D3_PERSISTENT
/* These structs and macros are from from the ROM code header
* on cAVS platforms, please keep them immutable
*/
#define ADSP_IMR_MAGIC_VALUE 0x02468ACE
#define IMR_L1_CACHE_ADDRESS 0xB0000000
struct imr_header {
uint32_t adsp_imr_magic;
uint32_t structure_version;
uint32_t structure_size;
uint32_t imr_state;
uint32_t imr_size;
void *imr_restore_vector;
};
struct imr_state {
struct imr_header header;
uint8_t reserved[0x1000 - sizeof(struct imr_header)];
};
struct imr_layout {
uint8_t css_reserved[0x1000];
struct imr_state imr_state;
};
/* cAVS ROM structs and macros end */
static void imr_layout_update(void *vector)
{
struct imr_layout *imr_layout = (struct imr_layout *)(IMR_L1_CACHE_ADDRESS);
/* update the IMR layout and write it back to uncache memory
* for ROM code usage. The ROM code will read this from IMR
* at the subsequent run and decide (e.g. combine with checking
* if FW_PURGE IPC from host got) if it can use the previous
* IMR FW directly. So this here is only a host->FW->ROM one way
* configuration, no symmetric task need to done in any
* platform_resume() to clear the configuration.
*/
dcache_invalidate_region((__sparse_force void __sparse_cache *)imr_layout,
sizeof(*imr_layout));
imr_layout->imr_state.header.adsp_imr_magic = ADSP_IMR_MAGIC_VALUE;
imr_layout->imr_state.header.imr_restore_vector = vector;
dcache_writeback_region((__sparse_force void __sparse_cache *)imr_layout,
sizeof(*imr_layout));
}
#endif
int platform_context_save(struct sof *sof)
{
ipc_get()->task_mask |= IPC_TASK_POWERDOWN;
#if CONFIG_CAVS_IMR_D3_PERSISTENT
/* Only support IMR restoring on cAVS 1.8 and onward at the moment. */
imr_layout_update((void *)IMR_BOOT_LDR_TEXT_ENTRY_BASE);
#endif
return 0;
}