2 * Copyright 2015 Freescale Semiconductor, Inc.
4 * SPDX-License-Identifier: GPL-2.0+
8 #include <fsl_sec_mon.h>
10 static u32 get_sec_mon_state(void)
12 struct ccsr_sec_mon_regs *sec_mon_regs = (void *)
13 (CONFIG_SYS_SEC_MON_ADDR);
14 return sec_mon_in32(&sec_mon_regs->hp_stat) & HPSR_SSM_ST_MASK;
17 static int set_sec_mon_state_non_sec(void)
21 struct ccsr_sec_mon_regs *sec_mon_regs = (void *)
22 (CONFIG_SYS_SEC_MON_ADDR);
24 sts = get_sec_mon_state();
28 * If initial state is check or Non-Secure, then set the Software
29 * Security Violation Bit and transition to Non-Secure State.
31 case HPSR_SSM_ST_CHECK:
32 printf("SEC_MON state transitioning to Non Secure.\n");
33 sec_mon_setbits32(&sec_mon_regs->hp_com, HPCOMR_SW_SV);
35 /* polling loop till SEC_MON is in Non Secure state */
37 sts = get_sec_mon_state();
39 if ((sts & HPSR_SSM_ST_MASK) ==
40 HPSR_SSM_ST_NON_SECURE)
48 printf("SEC_MON state transition timeout.\n");
54 * If initial state is Trusted, Secure or Soft-Fail, then first set
55 * the Software Security Violation Bit and transition to Soft-Fail
58 case HPSR_SSM_ST_TRUST:
59 case HPSR_SSM_ST_SECURE:
60 case HPSR_SSM_ST_SOFT_FAIL:
61 printf("SEC_MON state transitioning to Soft Fail.\n");
62 sec_mon_setbits32(&sec_mon_regs->hp_com, HPCOMR_SW_SV);
64 /* polling loop till SEC_MON is in Soft-Fail state */
66 sts = get_sec_mon_state();
68 if ((sts & HPSR_SSM_ST_MASK) ==
69 HPSR_SSM_ST_SOFT_FAIL)
77 printf("SEC_MON state transition timeout.\n");
84 * If SSM Soft Fail to Non-Secure State Transition
85 * disable is not set, then set SSM_ST bit and
86 * transition to Non-Secure State.
88 if ((sec_mon_in32(&sec_mon_regs->hp_com) &
89 HPCOMR_SSM_SFNS_DIS) == 0) {
90 printf("SEC_MON state transitioning to Non Secure.\n");
91 sec_mon_setbits32(&sec_mon_regs->hp_com, HPCOMR_SSM_ST);
93 /* polling loop till SEC_MON is in Non Secure*/
95 sts = get_sec_mon_state();
97 if ((sts & HPSR_SSM_ST_MASK) ==
98 HPSR_SSM_ST_NON_SECURE)
106 printf("SEC_MON state transition timeout.\n");
112 printf("SEC_MON already in Non Secure state.\n");
118 static int set_sec_mon_state_soft_fail(void)
122 struct ccsr_sec_mon_regs *sec_mon_regs = (void *)
123 (CONFIG_SYS_SEC_MON_ADDR);
125 printf("SEC_MON state transitioning to Soft Fail.\n");
126 sec_mon_setbits32(&sec_mon_regs->hp_com, HPCOMR_SW_FSV);
128 /* polling loop till SEC_MON is in Soft-Fail state */
130 sts = get_sec_mon_state();
132 if ((sts & HPSR_SSM_ST_MASK) ==
133 HPSR_SSM_ST_SOFT_FAIL)
141 printf("SEC_MON state transition timeout.\n");
147 int set_sec_mon_state(u32 state)
152 case HPSR_SSM_ST_NON_SECURE:
153 ret = set_sec_mon_state_non_sec();
155 case HPSR_SSM_ST_SOFT_FAIL:
156 ret = set_sec_mon_state_soft_fail();
159 printf("SEC_MON state transition not supported.\n");