2 * Copyright 2015 Freescale Semiconductor, Inc.
4 * SPDX-License-Identifier: GPL-2.0+
8 #include <fsl_sec_mon.h>
10 int change_sec_mon_state(u32 initial_state, u32 final_state)
12 struct ccsr_sec_mon_regs *sec_mon_regs = (void *)
13 (CONFIG_SYS_SEC_MON_ADDR);
14 u32 sts = sec_mon_in32(&sec_mon_regs->hp_stat);
17 if ((sts & HPSR_SSM_ST_MASK) != initial_state)
20 if (initial_state == HPSR_SSM_ST_TRUST) {
21 switch (final_state) {
22 case HPSR_SSM_ST_NON_SECURE:
23 printf("SEC_MON state transitioning to Soft Fail.\n");
24 sec_mon_setbits32(&sec_mon_regs->hp_com, HPCOMR_SW_SV);
27 * poll till SEC_MON is in
30 while (((sts & HPSR_SSM_ST_MASK) !=
31 HPSR_SSM_ST_SOFT_FAIL)) {
34 (&sec_mon_regs->hp_stat);
36 if ((sts & HPSR_SSM_ST_MASK) ==
37 HPSR_SSM_ST_SOFT_FAIL)
46 printf("SEC_MON state transition timeout.\n");
52 printf("SEC_MON state transitioning to Non Secure.\n");
53 sec_mon_setbits32(&sec_mon_regs->hp_com, HPCOMR_SSM_ST);
56 * poll till SEC_MON is in
59 while (((sts & HPSR_SSM_ST_MASK) !=
60 HPSR_SSM_ST_NON_SECURE)) {
63 (&sec_mon_regs->hp_stat);
65 if ((sts & HPSR_SSM_ST_MASK) ==
66 HPSR_SSM_ST_NON_SECURE)
75 printf("SEC_MON state transition timeout.\n");
79 case HPSR_SSM_ST_SOFT_FAIL:
80 printf("SEC_MON state transitioning to Soft Fail.\n");
81 sec_mon_setbits32(&sec_mon_regs->hp_com, HPCOMR_SW_FSV);
84 * polling loop till SEC_MON is in
87 while (((sts & HPSR_SSM_ST_MASK) !=
88 HPSR_SSM_ST_SOFT_FAIL)) {
91 (&sec_mon_regs->hp_stat);
93 if ((sts & HPSR_SSM_ST_MASK) ==
94 HPSR_SSM_ST_SOFT_FAIL)
103 printf("SEC_MON state transition timeout.\n");
110 } else if (initial_state == HPSR_SSM_ST_NON_SECURE) {
111 switch (final_state) {
112 case HPSR_SSM_ST_SOFT_FAIL:
113 printf("SEC_MON state transitioning to Soft Fail.\n");
114 sec_mon_setbits32(&sec_mon_regs->hp_com, HPCOMR_SW_FSV);
117 * polling loop till SEC_MON is in
120 while (((sts & HPSR_SSM_ST_MASK) !=
121 HPSR_SSM_ST_SOFT_FAIL)) {
124 (&sec_mon_regs->hp_stat);
126 if ((sts & HPSR_SSM_ST_MASK) ==
127 HPSR_SSM_ST_SOFT_FAIL)
136 printf("SEC_MON state transition timeout.\n");