Software APIs
alert.h
1 // Copyright lowRISC contributors (OpenTitan project).
2 // Licensed under the Apache License, Version 2.0, see LICENSE for details.
3 // SPDX-License-Identifier: Apache-2.0
4 
5 #ifndef OPENTITAN_SW_DEVICE_SILICON_CREATOR_LIB_DRIVERS_ALERT_H_
6 #define OPENTITAN_SW_DEVICE_SILICON_CREATOR_LIB_DRIVERS_ALERT_H_
7 #include <stddef.h>
8 #include <stdint.h>
9 
10 #include "sw/device/silicon_creator/lib/drivers/lifecycle.h"
11 #include "sw/device/silicon_creator/lib/error.h"
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
17 #define ALERT_CLASSES 4
18 
19 /**
20  * Alert Classification Values as stored in the ROM_ALERT_CLASSIFICATION and
21  * ROM_LOCAL_ALERT_CLASSIFICATION fields in OTP.
22  *
23  * Encoding generated with
24  * $ ./util/design/sparse-fsm-encode.py -d 2 -m 5 -n 8 \
25  * -s 3775359077 --language=c
26  *
27  * Minimum Hamming distance: 3
28  * Maximum Hamming distance: 5
29  * Minimum Hamming weight: 3
30  * Maximum Hamming weight: 6
31  */
32 typedef enum AlertClass {
33  /***
34  * Alert class X is a special class which means "not configured"
35  */
36  kAlertClassX = 0x94,
37  kAlertClassA = 0xee,
38  kAlertClassB = 0x64,
39  kAlertClassC = 0xa7,
40  kAlertClassD = 0x32,
41 } alert_class_t;
42 
43 /**
44  * Alert Enable Values as stored in the ROM_ALERT_CLASS_EN field in OTP.
45  *
46  * Encoding generated with
47  * $ ./util/design/sparse-fsm-encode.py -d 5 -m 3 -n 8 \
48  * -s 999796195 --language=c
49  *
50  * Minimum Hamming distance: 5
51  * Maximum Hamming distance: 6
52  * Minimum Hamming weight: 3
53  * Maximum Hamming weight: 4
54  */
55 typedef enum AlertEnable {
56  kAlertEnableNone = 0xa9,
57  kAlertEnableEnabled = 0x07,
58  kAlertEnableLocked = 0xd2,
59 } alert_enable_t;
60 
61 /**
62  * Alert Escalation Policy as stored in the ROM_ALERT_ESCALATION field in OTP.
63  *
64  * Note that each phase implies the prior phases are also enabled.
65  *
66  * Encoding generated with
67  * $ ./util/design/sparse-fsm-encode.py -d 2 -m 5 -n 8 \
68  * -s 3525542881 --language=c
69  *
70  * Minimum Hamming distance: 3
71  * Maximum Hamming distance: 6
72  * Minimum Hamming weight: 3
73  * Maximum Hamming weight: 5
74  */
75 typedef enum AlertEscalate {
76  kAlertEscalateNone = 0xd1,
77  kAlertEscalatePhase0 = 0xb9,
78  kAlertEscalatePhase1 = 0xcb,
79  kAlertEscalatePhase2 = 0x25,
80  kAlertEscalatePhase3 = 0x76,
81 } alert_escalate_t;
82 
83 /**
84  * Alert class configuration struct.
85  */
86 typedef struct AlertClassConfig {
87  /**
88  * Whether or not this alert class enabled.
89  */
90  alert_enable_t enabled;
91  /**
92  * The escalation configuration for this alert class.
93  */
94  alert_escalate_t escalation;
95  /**
96  * The accumlation threshold for this alert class.
97  */
98  uint32_t accum_threshold;
99  /**
100  * The timeout cycles for this alert class.
101  */
102  uint32_t timeout_cycles;
103  /**
104  * The phase cycles for this alert class.
105  */
106  uint32_t phase_cycles[4];
108 
109 /**
110  * Configure a single alert.
111  *
112  * Configures and optionally lock an alert's class configuration.
113  *
114  * @param index: The alert number.
115  * @param cls: Class of the alert.
116  * @param enabled: Whether or not to enable and/or lock the alert.
117  */
119 rom_error_t alert_configure(size_t index, alert_class_t cls,
120  alert_enable_t enabled);
121 
122 /**
123  * Configure a single local alert.
124  *
125  * Configures and optionally lock a local alert's class configuration.
126  *
127  * @param index: The local alert number.
128  * @param cls: Class of the alert.
129  * @param enabled: Whether or not to enable and/or lock the alert.
130  */
132 rom_error_t alert_local_configure(size_t index, alert_class_t cls,
133  alert_enable_t enabled);
134 /**
135  * Configure an alert class.
136  *
137  * Configures an alert class to the specified config.
138  *
139  * @param cls: Class of the alert (alert class X is not permitted here).
140  * @param config: The alert class' configuration.
141  */
143 rom_error_t alert_class_configure(alert_class_t cls,
144  const alert_class_config_t *config);
145 
146 /**
147  * Enable the ping timer mechanism.
148  *
149  * TODO(#23393): Do not call this function in the ROM unless there is an OTP
150  * configuation to control whether or not to enable the ping mechanism.
151  */
153 rom_error_t alert_ping_enable(void);
154 
155 /**
156  * Compute the CRC32 of the configuration registers.
157  *
158  * @return CRC32 of the configuration registers.
159  */
161 uint32_t alert_config_crc32(void);
162 
163 /**
164  * Compare the CRC32 of the configuration registers with the value in OTP.
165  *
166  * This function does not check the CRC32 in TEST_UNLOCKED* life cycle states to
167  * allow a test program to configure the alert handler before transitioning to
168  * other life cycle states.
169  *
170  * @param lc_state Life cycle state of the device.
171  * @return result of the operation.
172  */
174 rom_error_t alert_config_check(lifecycle_state_t lc_state);
175 
176 #ifdef __cplusplus
177 }
178 #endif
179 #endif // OPENTITAN_SW_DEVICE_SILICON_CREATOR_LIB_DRIVERS_ALERT_H_