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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
|
/*
* Copyright 2018-2020 NXP
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/
#include <common/debug.h>
#include <plat_gic.h>
#include <plat_common.h>
#include <plat_psci.h>
#ifdef NXP_WARM_BOOT
#include <plat_warm_rst.h>
#endif
#include <platform_def.h>
#if (SOC_CORE_OFF || SOC_CORE_PWR_DWN)
static void __dead2 _no_return_wfi(void)
{
_bl31_dead_wfi:
wfi();
goto _bl31_dead_wfi;
}
#endif
#if (SOC_CORE_RELEASE || SOC_CORE_PWR_DWN)
/* the entry for core warm boot */
static uintptr_t warmboot_entry = (uintptr_t) NULL;
#endif
#if (SOC_CORE_RELEASE)
static int _pwr_domain_on(u_register_t mpidr)
{
int core_pos = plat_core_pos(mpidr);
int rc = PSCI_E_INVALID_PARAMS;
u_register_t core_mask;
if (core_pos >= 0 && core_pos < PLATFORM_CORE_COUNT) {
_soc_set_start_addr(warmboot_entry);
dsb();
isb();
core_mask = (1 << core_pos);
rc = _psci_cpu_on(core_mask);
}
return (rc);
}
#endif
#if (SOC_CORE_OFF)
static void _pwr_domain_off(const psci_power_state_t *target_state)
{
u_register_t core_mask = plat_my_core_mask();
u_register_t core_state = _getCoreState(core_mask);
/* set core state in internal data */
core_state = CORE_OFF_PENDING;
_setCoreState(core_mask, core_state);
_psci_cpu_prep_off(core_mask);
}
#endif
#if (SOC_CORE_OFF || SOC_CORE_PWR_DWN)
static void __dead2 _pwr_down_wfi(const psci_power_state_t *target_state)
{
u_register_t core_mask = plat_my_core_mask();
u_register_t core_state = _getCoreState(core_mask);
switch (core_state) {
#if (SOC_CORE_OFF)
case CORE_OFF_PENDING:
/* set core state in internal data */
core_state = CORE_OFF;
_setCoreState(core_mask, core_state);
/* turn the core off */
_psci_cpu_off_wfi(core_mask, warmboot_entry);
break;
#endif
#if (SOC_CORE_PWR_DWN)
case CORE_PWR_DOWN:
/* power-down the core */
_psci_cpu_pwrdn_wfi(core_mask, warmboot_entry);
break;
#endif
#if (SOC_SYSTEM_PWR_DWN)
case SYS_OFF_PENDING:
/* set core state in internal data */
core_state = SYS_OFF;
_setCoreState(core_mask, core_state);
/* power-down the system */
_psci_sys_pwrdn_wfi(core_mask, warmboot_entry);
break;
#endif
default:
_no_return_wfi();
break;
}
}
#endif
#if (SOC_CORE_RELEASE || SOC_CORE_RESTART)
static void _pwr_domain_wakeup(const psci_power_state_t *target_state)
{
u_register_t core_mask = plat_my_core_mask();
u_register_t core_state = _getCoreState(core_mask);
switch (core_state) {
case CORE_PENDING: /* this core is coming out of reset */
/* soc per cpu setup */
soc_init_percpu();
/* gic per cpu setup */
plat_gic_pcpu_init();
/* set core state in internal data */
core_state = CORE_RELEASED;
_setCoreState(core_mask, core_state);
break;
#if (SOC_CORE_RESTART)
case CORE_WAKEUP:
/* this core is waking up from OFF */
_psci_wakeup(core_mask);
/* set core state in internal data */
core_state = CORE_RELEASED;
_setCoreState(core_mask, core_state);
break;
#endif
}
}
#endif
#if (SOC_CORE_STANDBY)
static void _pwr_cpu_standby(plat_local_state_t cpu_state)
{
u_register_t core_mask = plat_my_core_mask();
u_register_t core_state;
if (cpu_state == PLAT_MAX_RET_STATE) {
/* set core state to standby */
core_state = CORE_STANDBY;
_setCoreState(core_mask, core_state);
_psci_core_entr_stdby(core_mask);
/* when we are here, the core is waking up
* set core state to released
*/
core_state = CORE_RELEASED;
_setCoreState(core_mask, core_state);
}
}
#endif
#if (SOC_CORE_PWR_DWN)
static void _pwr_suspend(const psci_power_state_t *state)
{
u_register_t core_mask = plat_my_core_mask();
u_register_t core_state;
if (state->pwr_domain_state[PLAT_MAX_LVL] == PLAT_MAX_OFF_STATE) {
#if (SOC_SYSTEM_PWR_DWN)
_psci_sys_prep_pwrdn(core_mask);
/* set core state */
core_state = SYS_OFF_PENDING;
_setCoreState(core_mask, core_state);
#endif
} else if (state->pwr_domain_state[PLAT_MAX_LVL]
== PLAT_MAX_RET_STATE) {
#if (SOC_SYSTEM_STANDBY)
_psci_sys_prep_stdby(core_mask);
/* set core state */
core_state = CORE_STANDBY;
_setCoreState(core_mask, core_state);
#endif
}
else if (state->pwr_domain_state[PLAT_CLSTR_LVL] ==
PLAT_MAX_OFF_STATE) {
#if (SOC_CLUSTER_PWR_DWN)
_psci_clstr_prep_pwrdn(core_mask);
/* set core state */
core_state = CORE_PWR_DOWN;
_setCoreState(core_mask, core_state);
#endif
}
else if (state->pwr_domain_state[PLAT_CLSTR_LVL] ==
PLAT_MAX_RET_STATE) {
#if (SOC_CLUSTER_STANDBY)
_psci_clstr_prep_stdby(core_mask);
/* set core state */
core_state = CORE_STANDBY;
_setCoreState(core_mask, core_state);
#endif
}
else if (state->pwr_domain_state[PLAT_CORE_LVL] == PLAT_MAX_OFF_STATE) {
#if (SOC_CORE_PWR_DWN)
/* prep the core for power-down */
_psci_core_prep_pwrdn(core_mask);
/* set core state */
core_state = CORE_PWR_DOWN;
_setCoreState(core_mask, core_state);
#endif
}
else if (state->pwr_domain_state[PLAT_CORE_LVL] == PLAT_MAX_RET_STATE) {
#if (SOC_CORE_STANDBY)
_psci_core_prep_stdby(core_mask);
/* set core state */
core_state = CORE_STANDBY;
_setCoreState(core_mask, core_state);
#endif
}
}
#endif
#if (SOC_CORE_PWR_DWN)
static void _pwr_suspend_finish(const psci_power_state_t *state)
{
u_register_t core_mask = plat_my_core_mask();
u_register_t core_state;
if (state->pwr_domain_state[PLAT_MAX_LVL] == PLAT_MAX_OFF_STATE) {
#if (SOC_SYSTEM_PWR_DWN)
_psci_sys_exit_pwrdn(core_mask);
/* when we are here, the core is back up
* set core state to released
*/
core_state = CORE_RELEASED;
_setCoreState(core_mask, core_state);
#endif
} else if (state->pwr_domain_state[PLAT_MAX_LVL]
== PLAT_MAX_RET_STATE) {
#if (SOC_SYSTEM_STANDBY)
_psci_sys_exit_stdby(core_mask);
/* when we are here, the core is waking up
* set core state to released
*/
core_state = CORE_RELEASED;
_setCoreState(core_mask, core_state);
#endif
}
else if (state->pwr_domain_state[PLAT_CLSTR_LVL] ==
PLAT_MAX_OFF_STATE) {
#if (SOC_CLUSTER_PWR_DWN)
_psci_clstr_exit_pwrdn(core_mask);
/* when we are here, the core is waking up
* set core state to released
*/
core_state = CORE_RELEASED;
_setCoreState(core_mask, core_state);
#endif
}
else if (state->pwr_domain_state[PLAT_CLSTR_LVL] ==
PLAT_MAX_RET_STATE) {
#if (SOC_CLUSTER_STANDBY)
_psci_clstr_exit_stdby(core_mask);
/* when we are here, the core is waking up
* set core state to released
*/
core_state = CORE_RELEASED;
_setCoreState(core_mask, core_state);
#endif
}
else if (state->pwr_domain_state[PLAT_CORE_LVL] == PLAT_MAX_OFF_STATE) {
#if (SOC_CORE_PWR_DWN)
_psci_core_exit_pwrdn(core_mask);
/* when we are here, the core is back up
* set core state to released
*/
core_state = CORE_RELEASED;
_setCoreState(core_mask, core_state);
#endif
}
else if (state->pwr_domain_state[PLAT_CORE_LVL] == PLAT_MAX_RET_STATE) {
#if (SOC_CORE_STANDBY)
_psci_core_exit_stdby(core_mask);
/* when we are here, the core is waking up
* set core state to released
*/
core_state = CORE_RELEASED;
_setCoreState(core_mask, core_state);
#endif
}
}
#endif
#if (SOC_CORE_STANDBY || SOC_CORE_PWR_DWN)
#define PWR_STATE_TYPE_MASK 0x00010000
#define PWR_STATE_TYPE_STNDBY 0x0
#define PWR_STATE_TYPE_PWRDWN 0x00010000
#define PWR_STATE_LVL_MASK 0x03000000
#define PWR_STATE_LVL_CORE 0x0
#define PWR_STATE_LVL_CLSTR 0x01000000
#define PWR_STATE_LVL_SYS 0x02000000
#define PWR_STATE_LVL_MAX 0x03000000
/* turns a requested power state into a target power state
* based on SoC capabilities
*/
static int _pwr_state_validate(uint32_t pwr_state,
psci_power_state_t *state)
{
int stat = PSCI_E_INVALID_PARAMS;
int pwrdn = (pwr_state & PWR_STATE_TYPE_MASK);
int lvl = (pwr_state & PWR_STATE_LVL_MASK);
switch (lvl) {
case PWR_STATE_LVL_MAX:
if (pwrdn && SOC_SYSTEM_PWR_DWN)
state->pwr_domain_state[PLAT_MAX_LVL] =
PLAT_MAX_OFF_STATE;
else if (SOC_SYSTEM_STANDBY)
state->pwr_domain_state[PLAT_MAX_LVL] =
PLAT_MAX_RET_STATE;
/* fallthrough */
case PWR_STATE_LVL_SYS:
if (pwrdn && SOC_SYSTEM_PWR_DWN)
state->pwr_domain_state[PLAT_SYS_LVL] =
PLAT_MAX_OFF_STATE;
else if (SOC_SYSTEM_STANDBY)
state->pwr_domain_state[PLAT_SYS_LVL] =
PLAT_MAX_RET_STATE;
/* fallthrough */
case PWR_STATE_LVL_CLSTR:
if (pwrdn && SOC_CLUSTER_PWR_DWN)
state->pwr_domain_state[PLAT_CLSTR_LVL] =
PLAT_MAX_OFF_STATE;
else if (SOC_CLUSTER_STANDBY)
state->pwr_domain_state[PLAT_CLSTR_LVL] =
PLAT_MAX_RET_STATE;
/* fallthrough */
case PWR_STATE_LVL_CORE:
stat = PSCI_E_SUCCESS;
if (pwrdn && SOC_CORE_PWR_DWN)
state->pwr_domain_state[PLAT_CORE_LVL] =
PLAT_MAX_OFF_STATE;
else if (SOC_CORE_STANDBY)
state->pwr_domain_state[PLAT_CORE_LVL] =
PLAT_MAX_RET_STATE;
break;
}
return (stat);
}
#endif
#if (SOC_SYSTEM_PWR_DWN)
static void _pwr_state_sys_suspend(psci_power_state_t *req_state)
{
/* if we need to have per-SoC settings, then we need to
* extend this by calling into psci_utils.S and from there
* on down to the SoC.S files
*/
req_state->pwr_domain_state[PLAT_MAX_LVL] = PLAT_MAX_OFF_STATE;
req_state->pwr_domain_state[PLAT_SYS_LVL] = PLAT_MAX_OFF_STATE;
req_state->pwr_domain_state[PLAT_CLSTR_LVL] = PLAT_MAX_OFF_STATE;
req_state->pwr_domain_state[PLAT_CORE_LVL] = PLAT_MAX_OFF_STATE;
}
#endif
#if defined(NXP_WARM_BOOT) && (SOC_SYSTEM_RESET2)
static int psci_system_reset2(int is_vendor,
int reset_type,
u_register_t cookie)
{
int ret = 0;
INFO("Executing the sequence of warm reset.\n");
ret = prep_n_execute_warm_reset();
return ret;
}
#endif
static plat_psci_ops_t _psci_pm_ops = {
#if (SOC_SYSTEM_OFF)
.system_off = _psci_system_off,
#endif
#if (SOC_SYSTEM_RESET)
.system_reset = _psci_system_reset,
#endif
#if defined(NXP_WARM_BOOT) && (SOC_SYSTEM_RESET2)
.system_reset2 = psci_system_reset2,
#endif
#if (SOC_CORE_RELEASE || SOC_CORE_RESTART)
/* core released or restarted */
.pwr_domain_on_finish = _pwr_domain_wakeup,
#endif
#if (SOC_CORE_OFF)
/* core shutting down */
.pwr_domain_off = _pwr_domain_off,
#endif
#if (SOC_CORE_OFF || SOC_CORE_PWR_DWN)
.pwr_domain_pwr_down_wfi = _pwr_down_wfi,
#endif
#if (SOC_CORE_STANDBY || SOC_CORE_PWR_DWN)
/* cpu_suspend */
.validate_power_state = _pwr_state_validate,
#if (SOC_CORE_STANDBY)
.cpu_standby = _pwr_cpu_standby,
#endif
#if (SOC_CORE_PWR_DWN)
.pwr_domain_suspend = _pwr_suspend,
.pwr_domain_suspend_finish = _pwr_suspend_finish,
#endif
#endif
#if (SOC_SYSTEM_PWR_DWN)
.get_sys_suspend_power_state = _pwr_state_sys_suspend,
#endif
#if (SOC_CORE_RELEASE)
/* core executing psci_cpu_on */
.pwr_domain_on = _pwr_domain_on
#endif
};
#if (SOC_CORE_RELEASE || SOC_CORE_PWR_DWN)
int plat_setup_psci_ops(uintptr_t sec_entrypoint,
const plat_psci_ops_t **psci_ops)
{
warmboot_entry = sec_entrypoint;
*psci_ops = &_psci_pm_ops;
return 0;
}
#else
int plat_setup_psci_ops(uintptr_t sec_entrypoint,
const plat_psci_ops_t **psci_ops)
{
*psci_ops = &_psci_pm_ops;
return 0;
}
#endif
|