2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2015-02-27 04:14:22 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Freescale Semiconductor, Inc.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <fsl_sec_mon.h>
|
2020-05-10 17:40:11 +00:00
|
|
|
#include <linux/delay.h>
|
2015-02-27 04:14:22 +00:00
|
|
|
|
2016-08-31 12:54:15 +00:00
|
|
|
static u32 get_sec_mon_state(void)
|
2015-02-27 04:14:22 +00:00
|
|
|
{
|
|
|
|
struct ccsr_sec_mon_regs *sec_mon_regs = (void *)
|
|
|
|
(CONFIG_SYS_SEC_MON_ADDR);
|
2016-08-31 12:54:15 +00:00
|
|
|
return sec_mon_in32(&sec_mon_regs->hp_stat) & HPSR_SSM_ST_MASK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int set_sec_mon_state_non_sec(void)
|
|
|
|
{
|
|
|
|
u32 sts;
|
2015-02-27 04:14:22 +00:00
|
|
|
int timeout = 10;
|
2016-08-31 12:54:15 +00:00
|
|
|
struct ccsr_sec_mon_regs *sec_mon_regs = (void *)
|
|
|
|
(CONFIG_SYS_SEC_MON_ADDR);
|
2015-02-27 04:14:22 +00:00
|
|
|
|
2016-08-31 12:54:15 +00:00
|
|
|
sts = get_sec_mon_state();
|
2015-02-27 04:14:22 +00:00
|
|
|
|
2016-08-31 12:54:15 +00:00
|
|
|
switch (sts) {
|
|
|
|
/*
|
|
|
|
* If initial state is check or Non-Secure, then set the Software
|
|
|
|
* Security Violation Bit and transition to Non-Secure State.
|
|
|
|
*/
|
|
|
|
case HPSR_SSM_ST_CHECK:
|
|
|
|
printf("SEC_MON state transitioning to Non Secure.\n");
|
|
|
|
sec_mon_setbits32(&sec_mon_regs->hp_com, HPCOMR_SW_SV);
|
2015-02-27 04:14:22 +00:00
|
|
|
|
2016-08-31 12:54:15 +00:00
|
|
|
/* polling loop till SEC_MON is in Non Secure state */
|
|
|
|
while (timeout) {
|
|
|
|
sts = get_sec_mon_state();
|
|
|
|
|
|
|
|
if ((sts & HPSR_SSM_ST_MASK) ==
|
|
|
|
HPSR_SSM_ST_NON_SECURE)
|
|
|
|
break;
|
|
|
|
|
|
|
|
udelay(10);
|
|
|
|
timeout--;
|
|
|
|
}
|
2015-02-27 04:14:22 +00:00
|
|
|
|
2016-08-31 12:54:15 +00:00
|
|
|
if (timeout == 0) {
|
|
|
|
printf("SEC_MON state transition timeout.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If initial state is Trusted, Secure or Soft-Fail, then first set
|
|
|
|
* the Software Security Violation Bit and transition to Soft-Fail
|
|
|
|
* State.
|
|
|
|
*/
|
|
|
|
case HPSR_SSM_ST_TRUST:
|
|
|
|
case HPSR_SSM_ST_SECURE:
|
|
|
|
case HPSR_SSM_ST_SOFT_FAIL:
|
|
|
|
printf("SEC_MON state transitioning to Soft Fail.\n");
|
|
|
|
sec_mon_setbits32(&sec_mon_regs->hp_com, HPCOMR_SW_SV);
|
|
|
|
|
|
|
|
/* polling loop till SEC_MON is in Soft-Fail state */
|
|
|
|
while (timeout) {
|
|
|
|
sts = get_sec_mon_state();
|
|
|
|
|
|
|
|
if ((sts & HPSR_SSM_ST_MASK) ==
|
|
|
|
HPSR_SSM_ST_SOFT_FAIL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
udelay(10);
|
|
|
|
timeout--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (timeout == 0) {
|
|
|
|
printf("SEC_MON state transition timeout.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
timeout = 10;
|
2015-02-27 04:14:22 +00:00
|
|
|
|
2016-08-31 12:54:15 +00:00
|
|
|
/*
|
|
|
|
* If SSM Soft Fail to Non-Secure State Transition
|
|
|
|
* disable is not set, then set SSM_ST bit and
|
|
|
|
* transition to Non-Secure State.
|
|
|
|
*/
|
|
|
|
if ((sec_mon_in32(&sec_mon_regs->hp_com) &
|
|
|
|
HPCOMR_SSM_SFNS_DIS) == 0) {
|
2015-02-27 04:14:22 +00:00
|
|
|
printf("SEC_MON state transitioning to Non Secure.\n");
|
|
|
|
sec_mon_setbits32(&sec_mon_regs->hp_com, HPCOMR_SSM_ST);
|
|
|
|
|
2016-08-31 12:54:15 +00:00
|
|
|
/* polling loop till SEC_MON is in Non Secure*/
|
|
|
|
while (timeout) {
|
|
|
|
sts = get_sec_mon_state();
|
2015-02-27 04:14:22 +00:00
|
|
|
|
2016-08-31 12:54:15 +00:00
|
|
|
if ((sts & HPSR_SSM_ST_MASK) ==
|
|
|
|
HPSR_SSM_ST_NON_SECURE)
|
|
|
|
break;
|
|
|
|
|
|
|
|
udelay(10);
|
|
|
|
timeout--;
|
2015-02-27 04:14:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (timeout == 0) {
|
|
|
|
printf("SEC_MON state transition timeout.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2016-08-31 12:54:15 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("SEC_MON already in Non Secure state.\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2015-02-27 04:14:22 +00:00
|
|
|
|
2016-08-31 12:54:15 +00:00
|
|
|
static int set_sec_mon_state_soft_fail(void)
|
|
|
|
{
|
|
|
|
u32 sts;
|
|
|
|
int timeout = 10;
|
|
|
|
struct ccsr_sec_mon_regs *sec_mon_regs = (void *)
|
|
|
|
(CONFIG_SYS_SEC_MON_ADDR);
|
|
|
|
|
|
|
|
printf("SEC_MON state transitioning to Soft Fail.\n");
|
|
|
|
sec_mon_setbits32(&sec_mon_regs->hp_com, HPCOMR_SW_FSV);
|
|
|
|
|
|
|
|
/* polling loop till SEC_MON is in Soft-Fail state */
|
|
|
|
while (timeout) {
|
|
|
|
sts = get_sec_mon_state();
|
|
|
|
|
|
|
|
if ((sts & HPSR_SSM_ST_MASK) ==
|
|
|
|
HPSR_SSM_ST_SOFT_FAIL)
|
2015-02-27 04:14:22 +00:00
|
|
|
break;
|
2016-08-31 12:54:15 +00:00
|
|
|
|
|
|
|
udelay(10);
|
|
|
|
timeout--;
|
2015-02-27 04:14:22 +00:00
|
|
|
}
|
|
|
|
|
2016-08-31 12:54:15 +00:00
|
|
|
if (timeout == 0) {
|
|
|
|
printf("SEC_MON state transition timeout.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2015-02-27 04:14:22 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2016-08-31 12:54:15 +00:00
|
|
|
|
|
|
|
int set_sec_mon_state(u32 state)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
case HPSR_SSM_ST_NON_SECURE:
|
|
|
|
ret = set_sec_mon_state_non_sec();
|
|
|
|
break;
|
|
|
|
case HPSR_SSM_ST_SOFT_FAIL:
|
|
|
|
ret = set_sec_mon_state_soft_fail();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("SEC_MON state transition not supported.\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|