HPM SDK
HPMicro Software Development Kit
hpm_psec_drv.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021 HPMicro
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #ifndef HPM_PSEC_DRV_H
9 #define HPM_PSEC_DRV_H
10 #include "hpm_common.h"
11 #include "hpm_psec_regs.h"
12 
13 typedef enum psec_lifecycle {
23 
24 typedef enum batt_sec_state {
30 
31 typedef enum psec_state {
37 
38 enum {
40 };
41 
42 #define PSEC_PSECURE_STATE_MASK \
43  (0xFU << PSEC_SECURE_STATE_PMIC_INS_SHIFT)
44 #define PSEC_BATT_SECURE_STATE_MASK \
45  (0xFU << PSEC_SECURE_STATE_BATT_INS_SHIFT)
46 
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 
52 {
54 }
55 
57 {
58  if (state == psec_state_secure) {
61  }
62  } else if (state == psec_state_non_secure) {
65  }
66  }
68  | (1U << (PSEC_SECURE_STATE_PMIC_INS_SHIFT + state));
69  return status_success;
70 }
71 
72 static inline void psec_allow_psecure_state_restart(PSEC_Type *ptr, bool allow)
73 {
77 }
78 
79 static inline void psec_lock_psecure_state_restart(PSEC_Type *ptr, bool lock)
80 {
84 }
85 
86 static inline void psec_pmic_rom_secrets_present(PSEC_Type *ptr, bool presented)
87 {
89  & ~PSEC_SECURE_STATE_CONFIG_ROM_SECRETS_MASK)
90  | PSEC_SECURE_STATE_CONFIG_ROM_SECRETS_SET(presented);
91 }
92 
93 static inline void psec_psec_secure_state_config(PSEC_Type *ptr,
94  bool rom_secrets_presented,
95  bool allow_secure_state_restart,
96  bool lock_secure_state_restart)
97 {
98  ptr->SECURE_STATE_CONFIG = PSEC_SECURE_STATE_CONFIG_ROM_SECRETS_SET(rom_secrets_presented)
99  | PSEC_SECURE_STATE_CONFIG_ALLOW_RESTART_SET(allow_secure_state_restart)
100  | PSEC_SECURE_STATE_CONFIG_LOCK_SET(lock_secure_state_restart);
101 }
102 
104  uint32_t violation_setting,
105  bool lock)
106 {
111  | PSEC_VIOLATION_CONFIG_NSC_VIO_CFG_SET(violation_setting);
112 }
113 
114 static inline void psec_psecure_violation_config(PSEC_Type *ptr,
115  uint32_t violation_setting,
116  bool lock)
117 {
122  | PSEC_VIOLATION_CONFIG_SEC_VIO_CFG_SET(violation_setting);
123 }
124 
126  uint32_t violation_setting,
127  bool lock)
128 {
129  ptr->ESCALATE_CONFIG = (ptr->ESCALATE_CONFIG
133  | PSEC_ESCALATE_CONFIG_NSC_VIO_CFG_SET(violation_setting);
134 }
135 
136 static inline void psec_psecure_escalate_config(PSEC_Type *ptr,
137  uint32_t violation_setting,
138  bool lock)
139 {
140  ptr->ESCALATE_CONFIG = (ptr->ESCALATE_CONFIG
144  | PSEC_ESCALATE_CONFIG_SEC_VIO_CFG_SET(violation_setting);
145 }
146 
147 static inline uint32_t psec_get_pmic_status(PSEC_Type *ptr)
148 {
149  return ptr->EVENT;
150 }
151 
153 {
155 }
156 
158 {
159  if (state == batt_sec_state_secure) {
162  }
163  } else if (state == batt_sec_state_non_secure) {
166  }
167  }
169  | (1U << (PSEC_SECURE_STATE_BATT_INS_SHIFT + state));
170  return status_success;
171 }
172 
173 static inline void psec_allow_batt_secure_state_restart(PSEC_Type *ptr, bool allow)
174 {
178 }
179 
180 static inline void psec_lock_batt_secure_state_restart(PSEC_Type *ptr, bool lock)
181 {
185 }
186 
187 static inline void psec_batt_rom_secrets_present(PSEC_Type *ptr, bool presented)
188 {
190  & ~PSEC_SECURE_STATE_CONFIG_ROM_SECRETS_MASK)
191  | PSEC_SECURE_STATE_CONFIG_ROM_SECRETS_SET(presented);
192 }
193 
195  bool rom_secrets_presented,
196  bool allow_secure_state_restart,
197  bool lock_secure_state_restart)
198 {
199  ptr->SECURE_STATE_CONFIG = PSEC_SECURE_STATE_CONFIG_ROM_SECRETS_SET(rom_secrets_presented)
200  | PSEC_SECURE_STATE_CONFIG_ALLOW_RESTART_SET(allow_secure_state_restart)
201  | PSEC_SECURE_STATE_CONFIG_LOCK_SET(lock_secure_state_restart);
202 }
203 
205  uint32_t violation_setting,
206  bool lock)
207 {
212  | PSEC_VIOLATION_CONFIG_NSC_VIO_CFG_SET(violation_setting);
213 }
214 
216  uint32_t violation_setting,
217  bool lock)
218 {
223  | PSEC_VIOLATION_CONFIG_SEC_VIO_CFG_SET(violation_setting);
224 }
225 
227  uint32_t violation_setting,
228  bool lock)
229 {
230  ptr->ESCALATE_CONFIG = (ptr->ESCALATE_CONFIG
234  | PSEC_ESCALATE_CONFIG_NSC_VIO_CFG_SET(violation_setting);
235 }
236 
238  uint32_t violation_setting,
239  bool lock)
240 {
241  ptr->ESCALATE_CONFIG = (ptr->ESCALATE_CONFIG
245  | PSEC_ESCALATE_CONFIG_SEC_VIO_CFG_SET(violation_setting);
246 }
247 
248 static inline uint32_t psec_get_batt_status(PSEC_Type *ptr)
249 {
250  return ptr->EVENT;
251 }
252 #ifdef __cplusplus
253 }
254 #endif
255 
256 #endif /* HPM_PSEC_DRV_H */
257 
#define PSEC_SECURE_STATE_PMIC_INS_SHIFT
Definition: hpm_psec_regs.h:89
#define PSEC_SECURE_STATE_CONFIG_LOCK_SET(x)
Definition: hpm_psec_regs.h:103
#define PSEC_SECURE_STATE_ALLOW_NSC_GET(x)
Definition: hpm_psec_regs.h:32
#define PSEC_VIOLATION_CONFIG_SEC_VIO_CFG_MASK
Definition: hpm_psec_regs.h:162
#define PSEC_ESCALATE_CONFIG_LOCK_SEC_MASK
Definition: hpm_psec_regs.h:199
#define PSEC_VIOLATION_CONFIG_NSC_VIO_CFG_SET(x)
Definition: hpm_psec_regs.h:140
#define PSEC_ESCALATE_CONFIG_NSC_VIO_CFG_SET(x)
Definition: hpm_psec_regs.h:189
#define PSEC_ESCALATE_CONFIG_NSC_VIO_CFG_MASK
Definition: hpm_psec_regs.h:187
#define PSEC_VIOLATION_CONFIG_LOCK_NSC_SET(x)
Definition: hpm_psec_regs.h:128
#define PSEC_ESCALATE_CONFIG_LOCK_NSC_SET(x)
Definition: hpm_psec_regs.h:177
#define PSEC_ESCALATE_CONFIG_SEC_VIO_CFG_MASK
Definition: hpm_psec_regs.h:211
#define PSEC_SECURE_STATE_CONFIG_ALLOW_RESTART_MASK
Definition: hpm_psec_regs.h:113
#define PSEC_VIOLATION_CONFIG_SEC_VIO_CFG_SET(x)
Definition: hpm_psec_regs.h:164
#define PSEC_LIFECYCLE_LIFECYCLE_GET(x)
Definition: hpm_psec_regs.h:260
#define PSEC_SECURE_STATE_CONFIG_ALLOW_RESTART_SET(x)
Definition: hpm_psec_regs.h:115
#define PSEC_VIOLATION_CONFIG_LOCK_SEC_MASK
Definition: hpm_psec_regs.h:150
#define PSEC_ESCALATE_CONFIG_SEC_VIO_CFG_SET(x)
Definition: hpm_psec_regs.h:213
#define PSEC_SECURE_STATE_ALLOW_SEC_GET(x)
Definition: hpm_psec_regs.h:43
#define PSEC_VIOLATION_CONFIG_LOCK_NSC_MASK
Definition: hpm_psec_regs.h:126
#define PSEC_ESCALATE_CONFIG_LOCK_NSC_MASK
Definition: hpm_psec_regs.h:175
#define PSEC_ESCALATE_CONFIG_LOCK_SEC_SET(x)
Definition: hpm_psec_regs.h:201
#define PSEC_SECURE_STATE_CONFIG_LOCK_MASK
Definition: hpm_psec_regs.h:101
#define PSEC_VIOLATION_CONFIG_NSC_VIO_CFG_MASK
Definition: hpm_psec_regs.h:138
#define PSEC_VIOLATION_CONFIG_LOCK_SEC_SET(x)
Definition: hpm_psec_regs.h:152
uint32_t hpm_stat_t
Definition: hpm_common.h:123
#define MAKE_STATUS(group, code)
Definition: hpm_common.h:132
@ status_success
Definition: hpm_common.h:177
static void psec_lock_psecure_state_restart(PSEC_Type *ptr, bool lock)
Definition: hpm_psec_drv.h:79
static psec_lifecycle_t psec_get_batt_lifecycle(PSEC_Type *ptr)
Definition: hpm_psec_drv.h:152
@ status_psec_switch_state_not_allowed
Definition: hpm_psec_drv.h:39
static void psec_psecure_escalate_config(PSEC_Type *ptr, uint32_t violation_setting, bool lock)
Definition: hpm_psec_drv.h:136
static hpm_stat_t psec_switch_batt_state(PSEC_Type *ptr, batt_sec_state_t state)
Definition: hpm_psec_drv.h:157
static void psec_batt_non_secure_escalate_config(PSEC_Type *ptr, uint32_t violation_setting, bool lock)
Definition: hpm_psec_drv.h:226
static void psec_batt_secure_escalate_config(PSEC_Type *ptr, uint32_t violation_setting, bool lock)
Definition: hpm_psec_drv.h:237
static void psec_pmic_non_secure_violation_config(PSEC_Type *ptr, uint32_t violation_setting, bool lock)
Definition: hpm_psec_drv.h:103
#define PSEC_PSECURE_STATE_MASK
Definition: hpm_psec_drv.h:42
static void psec_batt_rom_secrets_present(PSEC_Type *ptr, bool presented)
Definition: hpm_psec_drv.h:187
static void psec_allow_batt_secure_state_restart(PSEC_Type *ptr, bool allow)
Definition: hpm_psec_drv.h:173
static void psec_batt_non_secure_violation_config(PSEC_Type *ptr, uint32_t violation_setting, bool lock)
Definition: hpm_psec_drv.h:204
static void psec_pmic_rom_secrets_present(PSEC_Type *ptr, bool presented)
Definition: hpm_psec_drv.h:86
enum psec_state psec_state_t
static uint32_t psec_get_batt_status(PSEC_Type *ptr)
Definition: hpm_psec_drv.h:248
static void psec_batt_secure_violation_config(PSEC_Type *ptr, uint32_t violation_setting, bool lock)
Definition: hpm_psec_drv.h:215
static void psec_lock_batt_secure_state_restart(PSEC_Type *ptr, bool lock)
Definition: hpm_psec_drv.h:180
static void psec_psec_secure_state_config(PSEC_Type *ptr, bool rom_secrets_presented, bool allow_secure_state_restart, bool lock_secure_state_restart)
Definition: hpm_psec_drv.h:93
enum psec_lifecycle psec_lifecycle_t
psec_state
Definition: hpm_psec_drv.h:31
@ psec_state_non_secure
Definition: hpm_psec_drv.h:34
@ psec_state_ins
Definition: hpm_psec_drv.h:32
@ psec_state_fail
Definition: hpm_psec_drv.h:35
@ psec_state_secure
Definition: hpm_psec_drv.h:33
static uint32_t psec_get_pmic_status(PSEC_Type *ptr)
Definition: hpm_psec_drv.h:147
static hpm_stat_t psec_switch_pmic_state(PSEC_Type *ptr, psec_state_t state)
Definition: hpm_psec_drv.h:56
psec_lifecycle
Definition: hpm_psec_drv.h:13
@ psec_lifecycle_secucre
Definition: hpm_psec_drv.h:17
@ psec_lifecycle_scribe
Definition: hpm_psec_drv.h:20
@ psec_lifecycle_no_return
Definition: hpm_psec_drv.h:19
@ psec_lifecycle_nonsecucre
Definition: hpm_psec_drv.h:16
@ psec_lifecycle_unknown
Definition: hpm_psec_drv.h:14
@ psec_lifecycle_return
Definition: hpm_psec_drv.h:18
@ psec_lifecycle_debate
Definition: hpm_psec_drv.h:21
@ psec_lifecycle_create
Definition: hpm_psec_drv.h:15
static void psec_pmic_non_secure_escalate_config(PSEC_Type *ptr, uint32_t violation_setting, bool lock)
Definition: hpm_psec_drv.h:125
static void psec_allow_psecure_state_restart(PSEC_Type *ptr, bool allow)
Definition: hpm_psec_drv.h:72
#define PSEC_BATT_SECURE_STATE_MASK
Definition: hpm_psec_drv.h:44
batt_sec_state
Definition: hpm_psec_drv.h:24
@ batt_sec_state_non_secure
Definition: hpm_psec_drv.h:27
@ batt_sec_state_ins
Definition: hpm_psec_drv.h:25
@ batt_sec_state_fail
Definition: hpm_psec_drv.h:28
@ batt_sec_state_secure
Definition: hpm_psec_drv.h:26
enum batt_sec_state batt_sec_state_t
static void psec_psecure_violation_config(PSEC_Type *ptr, uint32_t violation_setting, bool lock)
Definition: hpm_psec_drv.h:114
static psec_lifecycle_t psec_get_pmic_lifecycle(PSEC_Type *ptr)
Definition: hpm_psec_drv.h:51
static void psec_batt_set_secure_state_config(PSEC_Type *ptr, bool rom_secrets_presented, bool allow_secure_state_restart, bool lock_secure_state_restart)
Definition: hpm_psec_drv.h:194
Definition: hpm_psec_regs.h:12
__RW uint32_t ESCALATE_CONFIG
Definition: hpm_psec_regs.h:16
__R uint32_t EVENT
Definition: hpm_psec_regs.h:17
__RW uint32_t SECURE_STATE_CONFIG
Definition: hpm_psec_regs.h:14
__RW uint32_t VIOLATION_CONFIG
Definition: hpm_psec_regs.h:15
__RW uint32_t SECURE_STATE
Definition: hpm_psec_regs.h:13
__R uint32_t LIFECYCLE
Definition: hpm_psec_regs.h:18