1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2015 Freescale Semiconductor, Inc.
7 #include <fsl_sec_mon.h>
9 static u32 get_sec_mon_state(void)
11 struct ccsr_sec_mon_regs *sec_mon_regs = (void *)
12 (CONFIG_SYS_SEC_MON_ADDR);
13 return sec_mon_in32(&sec_mon_regs->hp_stat) & HPSR_SSM_ST_MASK;
16 static int set_sec_mon_state_non_sec(void)
20 struct ccsr_sec_mon_regs *sec_mon_regs = (void *)
21 (CONFIG_SYS_SEC_MON_ADDR);
23 sts = get_sec_mon_state();
27 * If initial state is check or Non-Secure, then set the Software
28 * Security Violation Bit and transition to Non-Secure State.
30 case HPSR_SSM_ST_CHECK:
31 printf("SEC_MON state transitioning to Non Secure.\n");
32 sec_mon_setbits32(&sec_mon_regs->hp_com, HPCOMR_SW_SV);
34 /* polling loop till SEC_MON is in Non Secure state */
36 sts = get_sec_mon_state();
38 if ((sts & HPSR_SSM_ST_MASK) ==
39 HPSR_SSM_ST_NON_SECURE)
47 printf("SEC_MON state transition timeout.\n");
53 * If initial state is Trusted, Secure or Soft-Fail, then first set
54 * the Software Security Violation Bit and transition to Soft-Fail
57 case HPSR_SSM_ST_TRUST:
58 case HPSR_SSM_ST_SECURE:
59 case HPSR_SSM_ST_SOFT_FAIL:
60 printf("SEC_MON state transitioning to Soft Fail.\n");
61 sec_mon_setbits32(&sec_mon_regs->hp_com, HPCOMR_SW_SV);
63 /* polling loop till SEC_MON is in Soft-Fail state */
65 sts = get_sec_mon_state();
67 if ((sts & HPSR_SSM_ST_MASK) ==
68 HPSR_SSM_ST_SOFT_FAIL)
76 printf("SEC_MON state transition timeout.\n");
83 * If SSM Soft Fail to Non-Secure State Transition
84 * disable is not set, then set SSM_ST bit and
85 * transition to Non-Secure State.
87 if ((sec_mon_in32(&sec_mon_regs->hp_com) &
88 HPCOMR_SSM_SFNS_DIS) == 0) {
89 printf("SEC_MON state transitioning to Non Secure.\n");
90 sec_mon_setbits32(&sec_mon_regs->hp_com, HPCOMR_SSM_ST);
92 /* polling loop till SEC_MON is in Non Secure*/
94 sts = get_sec_mon_state();
96 if ((sts & HPSR_SSM_ST_MASK) ==
97 HPSR_SSM_ST_NON_SECURE)
105 printf("SEC_MON state transition timeout.\n");
111 printf("SEC_MON already in Non Secure state.\n");
117 static int set_sec_mon_state_soft_fail(void)
121 struct ccsr_sec_mon_regs *sec_mon_regs = (void *)
122 (CONFIG_SYS_SEC_MON_ADDR);
124 printf("SEC_MON state transitioning to Soft Fail.\n");
125 sec_mon_setbits32(&sec_mon_regs->hp_com, HPCOMR_SW_FSV);
127 /* polling loop till SEC_MON is in Soft-Fail state */
129 sts = get_sec_mon_state();
131 if ((sts & HPSR_SSM_ST_MASK) ==
132 HPSR_SSM_ST_SOFT_FAIL)
140 printf("SEC_MON state transition timeout.\n");
146 int set_sec_mon_state(u32 state)
151 case HPSR_SSM_ST_NON_SECURE:
152 ret = set_sec_mon_state_non_sec();
154 case HPSR_SSM_ST_SOFT_FAIL:
155 ret = set_sec_mon_state_soft_fail();
158 printf("SEC_MON state transition not supported.\n");