Software APIs
dt_otp_ctrl.c
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/**
8 * @file
9 * @brief Device Tables (DT) for IP otp_ctrl and top darjeeling.
10 */
11
12#include "dt/dt_otp_ctrl.h"
13
14
15#include "otp_ctrl_regs.h"
16
17
18/**
19 * Description of instances.
20 */
21typedef struct dt_desc_otp_ctrl {
22 dt_instance_id_t inst_id; /**< Instance ID */
23 uint32_t base_addr[kDtOtpCtrlRegBlockCount]; /**< Base address of each register block */
24 /**
25 * PLIC ID of the first IRQ of this instance
26 *
27 * This can be `kDtPlicIrqIdNone` if the block is not connected to the PLIC.
28 */
30 /**
31 * Alert ID of the first Alert of this instance.
32 *
33 * This value is undefined if the block is not connected to the Alert Handler.
34 */
36 dt_clock_t clock[kDtOtpCtrlClockCount]; /**< Clock signal connected to each clock port */
37 dt_reset_t reset[kDtOtpCtrlResetCount]; /**< Reset signal connected to each reset port */
38 struct {
39 dt_otp_partition_info_t info[15]; /**< List of SW readable OTP partitions */
40 } sw_readable_partitions; /**< Extension */
42
43
44
45
46static const dt_desc_otp_ctrl_t otp_ctrl_desc[kDtOtpCtrlCount] = {
47 [kDtOtpCtrl] = {
48 .inst_id = kDtInstanceIdOtpCtrl,
49 .base_addr = {
50 [kDtOtpCtrlRegBlockCore] = 0x30130000,
51 },
54 .clock = {
57 },
58 .reset = {
61 },
62 .sw_readable_partitions = {
63 .info = {
64 [kOtpPartitionVendorTest] = {
65 .start_addr = OTP_CTRL_PARAM_VENDOR_TEST_OFFSET,
66 .size = OTP_CTRL_PARAM_VENDOR_TEST_SIZE - OTP_CTRL_PARAM_VENDOR_TEST_DIGEST_SIZE,
67 .digest_addr = OTP_CTRL_VENDOR_TEST_DIGEST_0_REG_OFFSET,
68 .align_mask = 0x3,
69 },
70 [kOtpPartitionCreatorSwCfg] = {
71 .start_addr = OTP_CTRL_PARAM_CREATOR_SW_CFG_OFFSET,
72 .size = OTP_CTRL_PARAM_CREATOR_SW_CFG_SIZE - OTP_CTRL_PARAM_CREATOR_SW_CFG_DIGEST_SIZE,
73 .digest_addr = OTP_CTRL_CREATOR_SW_CFG_DIGEST_0_REG_OFFSET,
74 .align_mask = 0x3,
75 },
76 [kOtpPartitionOwnerSwCfg] = {
77 .start_addr = OTP_CTRL_PARAM_OWNER_SW_CFG_OFFSET,
78 .size = OTP_CTRL_PARAM_OWNER_SW_CFG_SIZE - OTP_CTRL_PARAM_OWNER_SW_CFG_DIGEST_SIZE,
79 .digest_addr = OTP_CTRL_OWNER_SW_CFG_DIGEST_0_REG_OFFSET,
80 .align_mask = 0x3,
81 },
82 [kOtpPartitionRotCreatorAuth] = {
83 .start_addr = OTP_CTRL_PARAM_ROT_CREATOR_AUTH_OFFSET,
84 .size = OTP_CTRL_PARAM_ROT_CREATOR_AUTH_SIZE - OTP_CTRL_PARAM_ROT_CREATOR_AUTH_DIGEST_SIZE,
85 .digest_addr = OTP_CTRL_ROT_CREATOR_AUTH_DIGEST_0_REG_OFFSET,
86 .align_mask = 0x3,
87 },
88 [kOtpPartitionRotOwnerAuthSlot0] = {
89 .start_addr = OTP_CTRL_PARAM_ROT_OWNER_AUTH_SLOT0_OFFSET,
90 .size = OTP_CTRL_PARAM_ROT_OWNER_AUTH_SLOT0_SIZE - OTP_CTRL_PARAM_ROT_OWNER_AUTH_SLOT0_DIGEST_SIZE,
91 .digest_addr = OTP_CTRL_ROT_OWNER_AUTH_SLOT0_DIGEST_0_REG_OFFSET,
92 .align_mask = 0x3,
93 },
94 [kOtpPartitionRotOwnerAuthSlot1] = {
95 .start_addr = OTP_CTRL_PARAM_ROT_OWNER_AUTH_SLOT1_OFFSET,
96 .size = OTP_CTRL_PARAM_ROT_OWNER_AUTH_SLOT1_SIZE - OTP_CTRL_PARAM_ROT_OWNER_AUTH_SLOT1_DIGEST_SIZE,
97 .digest_addr = OTP_CTRL_ROT_OWNER_AUTH_SLOT1_DIGEST_0_REG_OFFSET,
98 .align_mask = 0x3,
99 },
100 [kOtpPartitionPlatIntegAuthSlot0] = {
101 .start_addr = OTP_CTRL_PARAM_PLAT_INTEG_AUTH_SLOT0_OFFSET,
102 .size = OTP_CTRL_PARAM_PLAT_INTEG_AUTH_SLOT0_SIZE - OTP_CTRL_PARAM_PLAT_INTEG_AUTH_SLOT0_DIGEST_SIZE,
103 .digest_addr = OTP_CTRL_PLAT_INTEG_AUTH_SLOT0_DIGEST_0_REG_OFFSET,
104 .align_mask = 0x3,
105 },
106 [kOtpPartitionPlatIntegAuthSlot1] = {
107 .start_addr = OTP_CTRL_PARAM_PLAT_INTEG_AUTH_SLOT1_OFFSET,
108 .size = OTP_CTRL_PARAM_PLAT_INTEG_AUTH_SLOT1_SIZE - OTP_CTRL_PARAM_PLAT_INTEG_AUTH_SLOT1_DIGEST_SIZE,
109 .digest_addr = OTP_CTRL_PLAT_INTEG_AUTH_SLOT1_DIGEST_0_REG_OFFSET,
110 .align_mask = 0x3,
111 },
112 [kOtpPartitionPlatOwnerAuthSlot0] = {
113 .start_addr = OTP_CTRL_PARAM_PLAT_OWNER_AUTH_SLOT0_OFFSET,
114 .size = OTP_CTRL_PARAM_PLAT_OWNER_AUTH_SLOT0_SIZE - OTP_CTRL_PARAM_PLAT_OWNER_AUTH_SLOT0_DIGEST_SIZE,
115 .digest_addr = OTP_CTRL_PLAT_OWNER_AUTH_SLOT0_DIGEST_0_REG_OFFSET,
116 .align_mask = 0x3,
117 },
118 [kOtpPartitionPlatOwnerAuthSlot1] = {
119 .start_addr = OTP_CTRL_PARAM_PLAT_OWNER_AUTH_SLOT1_OFFSET,
120 .size = OTP_CTRL_PARAM_PLAT_OWNER_AUTH_SLOT1_SIZE - OTP_CTRL_PARAM_PLAT_OWNER_AUTH_SLOT1_DIGEST_SIZE,
121 .digest_addr = OTP_CTRL_PLAT_OWNER_AUTH_SLOT1_DIGEST_0_REG_OFFSET,
122 .align_mask = 0x3,
123 },
124 [kOtpPartitionPlatOwnerAuthSlot2] = {
125 .start_addr = OTP_CTRL_PARAM_PLAT_OWNER_AUTH_SLOT2_OFFSET,
126 .size = OTP_CTRL_PARAM_PLAT_OWNER_AUTH_SLOT2_SIZE - OTP_CTRL_PARAM_PLAT_OWNER_AUTH_SLOT2_DIGEST_SIZE,
127 .digest_addr = OTP_CTRL_PLAT_OWNER_AUTH_SLOT2_DIGEST_0_REG_OFFSET,
128 .align_mask = 0x3,
129 },
130 [kOtpPartitionPlatOwnerAuthSlot3] = {
131 .start_addr = OTP_CTRL_PARAM_PLAT_OWNER_AUTH_SLOT3_OFFSET,
132 .size = OTP_CTRL_PARAM_PLAT_OWNER_AUTH_SLOT3_SIZE - OTP_CTRL_PARAM_PLAT_OWNER_AUTH_SLOT3_DIGEST_SIZE,
133 .digest_addr = OTP_CTRL_PLAT_OWNER_AUTH_SLOT3_DIGEST_0_REG_OFFSET,
134 .align_mask = 0x3,
135 },
136 [kOtpPartitionRomPatch] = {
137 .start_addr = OTP_CTRL_PARAM_ROM_PATCH_OFFSET,
138 .size = OTP_CTRL_PARAM_ROM_PATCH_SIZE - OTP_CTRL_PARAM_ROM_PATCH_DIGEST_SIZE,
139 .digest_addr = OTP_CTRL_ROM_PATCH_DIGEST_0_REG_OFFSET,
140 .align_mask = 0x3,
141 },
142 [kOtpPartitionHwCfg0] = {
143 .start_addr = OTP_CTRL_PARAM_HW_CFG0_OFFSET,
144 .size = OTP_CTRL_PARAM_HW_CFG0_SIZE - OTP_CTRL_PARAM_HW_CFG0_DIGEST_SIZE,
145 .digest_addr = OTP_CTRL_HW_CFG0_DIGEST_0_REG_OFFSET,
146 .align_mask = 0x3,
147 },
148 [kOtpPartitionHwCfg1] = {
149 .start_addr = OTP_CTRL_PARAM_HW_CFG1_OFFSET,
150 .size = OTP_CTRL_PARAM_HW_CFG1_SIZE - OTP_CTRL_PARAM_HW_CFG1_DIGEST_SIZE,
151 .digest_addr = OTP_CTRL_HW_CFG1_DIGEST_0_REG_OFFSET,
152 .align_mask = 0x3,
153 },
154 },
155 },
156 },
157};
158
159/**
160 * Return a pointer to the `dt_otp_ctrl_desc_t` structure of the requested
161 * `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
162 * the function) with the provided default value.
163 */
164#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_otp_ctrl_t)0 || (dt) >= kDtOtpCtrlCount) return (default); &otp_ctrl_desc[dt]; })
165
167 if (inst_id >= kDtInstanceIdOtpCtrl && inst_id <= kDtInstanceIdOtpCtrl) {
168 return (dt_otp_ctrl_t)(inst_id - kDtInstanceIdOtpCtrl);
169 }
170 return (dt_otp_ctrl_t)0;
171}
172
177
179 dt_otp_ctrl_t dt,
180 dt_otp_ctrl_reg_block_t reg_block) {
181 // Return a recognizable address in case of wrong argument.
182 return TRY_GET_DT(dt, 0xdeadbeef)->base_addr[reg_block];
183}
184
186 dt_otp_ctrl_t dt,
187 dt_otp_ctrl_irq_t irq) {
188 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, kDtPlicIrqIdNone)->first_irq;
189 if (first_irq == kDtPlicIrqIdNone) {
190 return kDtPlicIrqIdNone;
191 }
192 return (dt_plic_irq_id_t)((uint32_t)first_irq + (uint32_t)irq);
193}
194
196 dt_otp_ctrl_t dt,
197 dt_plic_irq_id_t irq) {
198 dt_otp_ctrl_irq_t count = kDtOtpCtrlIrqCount;
199 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, count)->first_irq;
200 if (first_irq == kDtPlicIrqIdNone) {
201 return count;
202 }
203 if (irq < first_irq || irq >= first_irq + (dt_plic_irq_id_t)count) {
204 return count;
205 }
206 return (dt_otp_ctrl_irq_t)(irq - first_irq);
207}
208
209
211 dt_otp_ctrl_t dt,
212 dt_otp_ctrl_alert_t alert) {
213 return (dt_alert_id_t)((uint32_t)otp_ctrl_desc[dt].first_alert + (uint32_t)alert);
214}
215
217 dt_otp_ctrl_t dt,
218 dt_alert_id_t alert) {
219 dt_otp_ctrl_alert_t count = kDtOtpCtrlAlertCount;
220 if (alert < otp_ctrl_desc[dt].first_alert || alert >= otp_ctrl_desc[dt].first_alert + (dt_alert_id_t)count) {
221 return count;
222 }
223 return (dt_otp_ctrl_alert_t)(alert - otp_ctrl_desc[dt].first_alert);
224}
225
226
227
229 dt_otp_ctrl_t dt,
231 // Return the first clock in case of invalid argument.
232 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
233}
234
236 dt_otp_ctrl_t dt,
238 const dt_otp_ctrl_reset_t count = kDtOtpCtrlResetCount;
239 if (rst >= count) {
240 return kDtResetUnknown;
241 }
242 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
243}
244
245
246
247
250 dt_otp_partition_info_t invalid_part = {
251 .start_addr = 0xdeadbeef,
252 .size = 0x0,
253 .digest_addr = 0xdeadbeef,
254 .align_mask = 0x0,
255 };
256 return TRY_GET_DT(dt, invalid_part)->sw_readable_partitions.info[partition];
257}
258
259
260