nxp: psci platform functions used by lib/psci

Signed-off-by: rocket <rod.dorris@nxp.com>
Signed-off-by: Pankaj Gupta <pankaj.gupta@nxp.com>
Change-Id: I9853263ed38fb2a9f04b9dc7d768942e32074719
This commit is contained in:
Pankaj Gupta 2020-12-09 14:02:40 +05:30
parent 044ddf9ea3
commit dd4268a2db
4 changed files with 1772 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,107 @@
/*
* Copyright 2018-2020 NXP
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/
#ifndef PLAT_PSCI_H
#define PLAT_PSCI_H
/* core abort current op */
#define CORE_ABORT_OP 0x1
/* psci power levels - these are actually affinity levels
* in the psci_power_state_t array
*/
#define PLAT_CORE_LVL PSCI_CPU_PWR_LVL
#define PLAT_CLSTR_LVL U(1)
#define PLAT_SYS_LVL U(2)
#define PLAT_MAX_LVL PLAT_SYS_LVL
/* core state */
/* OFF states 0x0 - 0xF */
#define CORE_IN_RESET 0x0
#define CORE_DISABLED 0x1
#define CORE_OFF 0x2
#define CORE_STANDBY 0x3
#define CORE_PWR_DOWN 0x4
#define CORE_WFE 0x6
#define CORE_WFI 0x7
#define CORE_LAST 0x8
#define CORE_OFF_PENDING 0x9
#define CORE_WORKING_INIT 0xA
#define SYS_OFF_PENDING 0xB
#define SYS_OFF 0xC
/* ON states 0x10 - 0x1F */
#define CORE_PENDING 0x10
#define CORE_RELEASED 0x11
#define CORE_WAKEUP 0x12
/* highest off state */
#define CORE_OFF_MAX 0xF
/* lowest on state */
#define CORE_ON_MIN CORE_PENDING
#define DAIF_SET_MASK 0x3C0
#define SCTLR_I_C_M_MASK 0x00001005
#define SCTLR_C_MASK 0x00000004
#define SCTLR_I_MASK 0x00001000
#define CPUACTLR_L1PCTL_MASK 0x0000E000
#define DCSR_RCPM2_BASE 0x20170000
#define CPUECTLR_SMPEN_MASK 0x40
#define CPUECTLR_SMPEN_EN 0x40
#define CPUECTLR_RET_MASK 0x7
#define CPUECTLR_RET_SET 0x2
#define CPUECTLR_TIMER_MASK 0x7
#define CPUECTLR_TIMER_8TICKS 0x2
#define SCR_IRQ_MASK 0x2
#define SCR_FIQ_MASK 0x4
/* pwr mgmt features supported in the soc-specific code:
* value == 0x0, the soc code does not support this feature
* value != 0x0, the soc code supports this feature
*/
#define SOC_CORE_RELEASE 0x1
#define SOC_CORE_RESTART 0x1
#define SOC_CORE_OFF 0x1
#define SOC_CORE_STANDBY 0x1
#define SOC_CORE_PWR_DWN 0x1
#define SOC_CLUSTER_STANDBY 0x1
#define SOC_CLUSTER_PWR_DWN 0x1
#define SOC_SYSTEM_STANDBY 0x1
#define SOC_SYSTEM_PWR_DWN 0x1
#define SOC_SYSTEM_OFF 0x1
#define SOC_SYSTEM_RESET 0x1
#define SOC_SYSTEM_RESET2 0x1
#ifndef __ASSEMBLER__
void __dead2 _psci_system_reset(void);
void __dead2 _psci_system_off(void);
int _psci_cpu_on(u_register_t core_mask);
void _psci_cpu_prep_off(u_register_t core_mask);
void __dead2 _psci_cpu_off_wfi(u_register_t core_mask,
u_register_t wakeup_address);
void __dead2 _psci_cpu_pwrdn_wfi(u_register_t core_mask,
u_register_t wakeup_address);
void __dead2 _psci_sys_pwrdn_wfi(u_register_t core_mask,
u_register_t wakeup_address);
void _psci_wakeup(u_register_t core_mask);
void _psci_core_entr_stdby(u_register_t core_mask);
void _psci_core_prep_stdby(u_register_t core_mask);
void _psci_core_exit_stdby(u_register_t core_mask);
void _psci_core_prep_pwrdn(u_register_t core_mask);
void _psci_core_exit_pwrdn(u_register_t core_mask);
void _psci_clstr_prep_stdby(u_register_t core_mask);
void _psci_clstr_exit_stdby(u_register_t core_mask);
void _psci_clstr_prep_pwrdn(u_register_t core_mask);
void _psci_clstr_exit_pwrdn(u_register_t core_mask);
void _psci_sys_prep_stdby(u_register_t core_mask);
void _psci_sys_exit_stdby(u_register_t core_mask);
void _psci_sys_prep_pwrdn(u_register_t core_mask);
void _psci_sys_exit_pwrdn(u_register_t core_mask);
#endif
#endif /* __PLAT_PSCI_H__ */

View File

@ -0,0 +1,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;
/* intentional fall-thru condition */
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;
/* intentional fall-thru condition */
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;
/* intentional fall-thru condition */
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

View File

@ -0,0 +1,35 @@
#
# Copyright 2018-2020 NXP
#
# SPDX-License-Identifier: BSD-3-Clause
#
#
#------------------------------------------------------------------------------
#
# Select the PSCI files
#
# -----------------------------------------------------------------------------
ifeq (${ADD_PSCI},)
ADD_PSCI := 1
PLAT_PSCI_PATH := $(PLAT_COMMON_PATH)/psci
PSCI_SOURCES := ${PLAT_PSCI_PATH}/plat_psci.c \
${PLAT_PSCI_PATH}/$(ARCH)/psci_utils.S \
plat/common/plat_psci_common.c
PLAT_INCLUDES += -I${PLAT_PSCI_PATH}/include
ifeq (${BL_COMM_PSCI_NEEDED},yes)
BL_COMMON_SOURCES += ${PSCI_SOURCES}
else
ifeq (${BL2_PSCI_NEEDED},yes)
BL2_SOURCES += ${PSCI_SOURCES}
endif
ifeq (${BL31_PSCI_NEEDED},yes)
BL31_SOURCES += ${PSCI_SOURCES}
endif
endif
endif
# -----------------------------------------------------------------------------