Software APIs
otp_ctrl.h
Go to the documentation of this file.
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// Device table API auto-generated by `dtgen`
6
7#ifndef OPENTITAN_DT_OTP_CTRL_H_
8#define OPENTITAN_DT_OTP_CTRL_H_
9
10#ifdef __cplusplus
11extern "C" {
12#endif // __cplusplus
13
14/**
15 * @file
16 * @brief Device Tables (DT) for IP otp_ctrl and top earlgrey.
17 *
18 * This file contains the type definitions and global functions of the otp_ctrl.
19 */
20
21#include "hw/top/dt/api.h"
22#include <stdint.h>
23
24
25
26
27
28/**
29 * List of instances.
30 */
31typedef enum dt_otp_ctrl {
32 kDtOtpCtrlFirst = 0, /**< First instance */
33 kDtOtpCtrl = 0, /**< otp_ctrl */
35
36enum {
37 kDtOtpCtrlCount = 1, /**< Number of instances */
38};
39
40
41/**
42 * List of register blocks.
43 *
44 * Register blocks are guaranteed to start at 0 and to be consecutively numbered.
45 */
47 kDtOtpCtrlRegBlockCore = 0, /**< */
49
50enum {
51 kDtOtpCtrlRegBlockCount = 1, /**< Number of register blocks */
52};
53
54
55/** Primary register block (associated with the "primary" set of registers that control the IP). */
56static const dt_otp_ctrl_reg_block_t kDtOtpCtrlRegBlockPrimary = kDtOtpCtrlRegBlockCore;
57
58/**
59 * List of IRQs.
60 *
61 * IRQs are guaranteed to be numbered consecutively from 0.
62 */
63typedef enum dt_otp_ctrl_irq {
64 kDtOtpCtrlIrqOtpOperationDone = 0, /**< A direct access command or digest calculation operation has completed. */
65 kDtOtpCtrlIrqOtpError = 1, /**< An error has occurred in the OTP controller. Check the !!ERR_CODE register to get more information. */
67
68enum {
69 kDtOtpCtrlIrqCount = 2, /**< Number of IRQs */
70};
71
72
73/**
74 * List of Alerts.
75 *
76 * Alerts are guaranteed to be numbered consecutively from 0.
77 */
78typedef enum dt_otp_ctrl_alert {
79 kDtOtpCtrlAlertFatalMacroError = 0, /**< This alert triggers if hardware detects an uncorrectable error during an OTP transaction, for example an uncorrectable ECC error in the OTP array. */
80 kDtOtpCtrlAlertFatalCheckError = 1, /**< This alert triggers if any of the background checks fails. This includes the digest checks and concurrent ECC checks in the buffer registers. */
81 kDtOtpCtrlAlertFatalBusIntegError = 2, /**< This fatal alert is triggered when a fatal TL-UL bus integrity fault is detected. */
82 kDtOtpCtrlAlertFatalPrimOtpAlert = 3, /**< Fatal alert triggered inside the OTP primitive, including fatal TL-UL bus integrity faults of the test interface. */
83 kDtOtpCtrlAlertRecovPrimOtpAlert = 4, /**< Recoverable alert triggered inside the OTP primitive. */
85
86enum {
87 kDtOtpCtrlAlertCount = 5, /**< Number of Alerts */
88};
89
90
91/**
92 * List of clock ports.
93 *
94 * Clock ports are guaranteed to be numbered consecutively from 0.
95 */
96typedef enum dt_otp_ctrl_clock {
97 kDtOtpCtrlClockClk = 0, /**< Clock port clk_i */
98 kDtOtpCtrlClockEdn = 1, /**< Clock port clk_edn_i */
100
101enum {
102 kDtOtpCtrlClockCount = 2, /**< Number of clock ports */
103};
104
105
106/**
107 * List of reset ports.
108 *
109 * Reset ports are guaranteed to be numbered consecutively from 0.
110 */
111typedef enum dt_otp_ctrl_reset {
112 kDtOtpCtrlResetRst = 0, /**< Reset port rst_ni */
113 kDtOtpCtrlResetEdn = 1, /**< Reset port rst_edn_ni */
115
116enum {
117 kDtOtpCtrlResetCount = 2, /**< Number of reset ports */
118};
119
120
121/**
122 * List of supported hardware features.
123 */
124#define OPENTITAN_OTP_CTRL_HAS_PARTITION_VENDOR_TEST 1
125#define OPENTITAN_OTP_CTRL_HAS_PARTITION_CREATOR_SW_CFG 1
126#define OPENTITAN_OTP_CTRL_HAS_PARTITION_OWNER_SW_CFG 1
127#define OPENTITAN_OTP_CTRL_HAS_INIT 1
128#define OPENTITAN_OTP_CTRL_HAS_ENTROPY_READ 1
129#define OPENTITAN_OTP_CTRL_HAS_KEY_DERIVATION 1
130#define OPENTITAN_OTP_CTRL_HAS_PROGRAM 1
131#define OPENTITAN_OTP_CTRL_HAS_PARTITION_SECRET0 1
132#define OPENTITAN_OTP_CTRL_HAS_PARTITION_SECRET1 1
133#define OPENTITAN_OTP_CTRL_HAS_PARTITION_SECRET2 1
134#define OPENTITAN_OTP_CTRL_HAS_PARTITION_LIFE_CYCLE 1
135#define OPENTITAN_OTP_CTRL_HAS_PARTITIONS_FEATURE_READ_LOCK 1
136#define OPENTITAN_OTP_CTRL_HAS_PARTITIONS_FEATURE_WRITE_LOCK 1
137#define OPENTITAN_OTP_CTRL_HAS_ERROR_HANDLING_RECOVERABLE 1
138#define OPENTITAN_OTP_CTRL_HAS_ERROR_HANDLING_FATAL 1
139#define OPENTITAN_OTP_CTRL_HAS_BACKGROUND_CHECK_CHECK_TIMEOUT 1
140#define OPENTITAN_OTP_CTRL_HAS_BACKGROUND_CHECK_INTEGRITY_CHECK_PERIOD 1
141#define OPENTITAN_OTP_CTRL_HAS_BACKGROUND_CHECK_CONSISTENCY_CHECK_PERIOD 1
142
143
144
145/**
146 * Get the otp_ctrl instance from an instance ID
147 *
148 * For example, `dt_uart_from_instance_id(kDtInstanceIdUart3) == kDtUart3`.
149 *
150 * @param inst_id Instance ID.
151 * @return A otp_ctrl instance.
152 *
153 * **Note:** This function only makes sense if the instance ID has device type otp_ctrl,
154 * otherwise the returned value is unspecified.
155 */
157
158/**
159 * Get the instance ID of an instance.
160 *
161 * @param dt Instance of otp_ctrl.
162 * @return The instance ID of that instance.
163 */
165
166/**
167 * Get the register base address of an instance.
168 *
169 * @param dt Instance of otp_ctrl.
170 * @param reg_block The register block requested.
171 * @return The register base address of the requested block.
172 */
173uint32_t dt_otp_ctrl_reg_block(
174 dt_otp_ctrl_t dt,
175 dt_otp_ctrl_reg_block_t reg_block);
176
177/**
178 * Get the primary register base address of an instance.
179 *
180 * This is just a convenience function, equivalent to
181 * `dt_otp_ctrl_reg_block(dt, kDtOtpCtrlRegBlockCore)`
182 *
183 * @param dt Instance of otp_ctrl.
184 * @return The register base address of the primary register block.
185 */
186static inline uint32_t dt_otp_ctrl_primary_reg_block(
187 dt_otp_ctrl_t dt) {
188 return dt_otp_ctrl_reg_block(dt, kDtOtpCtrlRegBlockCore);
189}
190
191/**
192 * Get the PLIC ID of a otp_ctrl IRQ for a given instance.
193 *
194 * If the instance is not connected to the PLIC, this function
195 * will return `kDtPlicIrqIdNone`.
196 *
197 * @param dt Instance of otp_ctrl.
198 * @param irq A otp_ctrl IRQ.
199 * @return The PLIC ID of the IRQ of this instance.
200 */
202 dt_otp_ctrl_t dt,
204
205/**
206 * Convert a global IRQ ID to a local otp_ctrl IRQ type.
207 *
208 * @param dt Instance of otp_ctrl.
209 * @param irq A PLIC ID that belongs to this instance.
210 * @return The otp_ctrl IRQ, or `kDtOtpCtrlIrqCount`.
211 *
212 * **Note:** This function assumes that the PLIC ID belongs to the instance
213 * of otp_ctrl passed in parameter. In other words, it must be the case that
214 * `dt_otp_ctrl_instance_id(dt) == dt_plic_id_to_instance_id(irq)`. Otherwise, this function
215 * will return `kDtOtpCtrlIrqCount`.
216 */
218 dt_otp_ctrl_t dt,
219 dt_plic_irq_id_t irq);
220
221
222/**
223 * Get the alert ID of a otp_ctrl alert for a given instance.
224 *
225 * **Note:** This function only makes sense if the instance is connected to the Alert Handler. For any
226 * instances where the instance is not connected, the return value is unspecified.
227 *
228 * @param dt Instance of otp_ctrl.
229 * @param alert A otp_ctrl alert.
230 * @return The Alert Handler alert ID of the alert of this instance.
231 */
233 dt_otp_ctrl_t dt,
234 dt_otp_ctrl_alert_t alert);
235
236/**
237 * Convert a global alert ID to a local otp_ctrl alert type.
238 *
239 * @param dt Instance of otp_ctrl.
240 * @param alert A global alert ID that belongs to this instance.
241 * @return The otp_ctrl alert, or `kDtOtpCtrlAlertCount`.
242 *
243 * **Note:** This function assumes that the global alert ID belongs to the
244 * instance of otp_ctrl passed in parameter. In other words, it must be the case
245 * that `dt_otp_ctrl_instance_id(dt) == dt_alert_id_to_instance_id(alert)`. Otherwise,
246 * this function will return `kDtOtpCtrlAlertCount`.
247 */
249 dt_otp_ctrl_t dt,
250 dt_alert_id_t alert);
251
252
253
254/**
255 * Get the clock signal connected to a clock port of an instance.
256 *
257 * @param dt Instance of otp_ctrl.
258 * @param clk Clock port.
259 * @return Clock signal.
260 */
262 dt_otp_ctrl_t dt,
264
265/**
266 * Get the reset signal connected to a reset port of an instance.
267 *
268 * @param dt Instance of otp_ctrl.
269 * @param rst Reset port.
270 * @return Reset signal.
271 */
273 dt_otp_ctrl_t dt,
275
276
277
278/**
279 * Description of an OTP partition.
280 *
281 */
282typedef struct dt_otp_partition_info {
283 uint32_t start_addr; /**< The absolute OTP address at which this partition starts */
284 size_t size; /**< Size (in bytes) of the partition, excluding the digest field */
285 uint32_t digest_reg_offset; /**< The OTP digest CSR (where the digest is buffered) offset for this partition. */
286 uint32_t align_mask; /**< The alignment mask for this partition */
288
289
290/**
291 * SW readable OTP partition identifier.
292 */
293typedef enum otp_partition {
294 kOtpPartitionVendorTest = 0, /**< */
295 kOtpPartitionCreatorSwCfg = 1, /**< */
296 kOtpPartitionOwnerSwCfg = 2, /**< */
297 kOtpPartitionRotCreatorAuthCodesign = 3, /**< */
298 kOtpPartitionRotCreatorAuthState = 4, /**< */
299 kOtpPartitionHwCfg0 = 5, /**< */
300 kOtpPartitionHwCfg1 = 6, /**< */
301 kOtpPartitionCount = 7, /**< \internal */
303
304/**
305 * Get a SW readable OTP partition information.
306 *
307 * @param dt Instance of otp_ctrl.
308 * @param partition OTP partition identifier.
309 * @return OTP partition information.
310 */
313
314
315
316#ifdef __cplusplus
317} // extern "C"
318#endif // __cplusplus
319
320#endif // OPENTITAN_DT_OTP_CTRL_H_