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 earlgrey.
10 */
11
12#include "hw/top/dt/dt_otp_ctrl.h"
13
14
15#include "hw/top/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 reg_addr[kDtOtpCtrlRegBlockCount]; /**< Base address of each register block */
24 uint32_t mem_addr[kDtOtpCtrlMemoryCount]; /**< Base address of each memory */
25 uint32_t mem_size[kDtOtpCtrlMemoryCount]; /**< Size in bytes of each memory */
26 /**
27 * PLIC ID of the first IRQ of this instance
28 *
29 * This can be `kDtPlicIrqIdNone` if the block is not connected to the PLIC.
30 */
32 /**
33 * Alert ID of the first Alert of this instance.
34 *
35 * This value is undefined if the block is not connected to the Alert Handler.
36 */
38 dt_clock_t clock[kDtOtpCtrlClockCount]; /**< Clock signal connected to each clock port */
39 dt_reset_t reset[kDtOtpCtrlResetCount]; /**< Reset signal connected to each reset port */
40 struct {
41 dt_otp_partition_info_t info[7]; /**< List of SW readable OTP partitions */
42 } sw_readable_partitions; /**< Extension */
44
45
46
47
48static const dt_desc_otp_ctrl_t otp_ctrl_desc[kDtOtpCtrlCount] = {
49 [kDtOtpCtrl] = {
50 .inst_id = kDtInstanceIdOtpCtrl,
51 .reg_addr = {
52 [kDtOtpCtrlRegBlockCore] = 0x40130000,
53 },
54 .mem_addr = {
55 },
56 .mem_size = {
57 },
60 .clock = {
63 },
64 .reset = {
67 },
68 .sw_readable_partitions = {
69 .info = {
70 [kOtpPartitionVendorTest] = {
71 .start_addr = OTP_CTRL_PARAM_VENDOR_TEST_OFFSET,
72 .size = OTP_CTRL_PARAM_VENDOR_TEST_SIZE - OTP_CTRL_PARAM_VENDOR_TEST_DIGEST_SIZE,
73 .digest_addr = OTP_CTRL_VENDOR_TEST_DIGEST_0_REG_OFFSET,
74 .align_mask = 0x3,
75 },
76 [kOtpPartitionCreatorSwCfg] = {
77 .start_addr = OTP_CTRL_PARAM_CREATOR_SW_CFG_OFFSET,
78 .size = OTP_CTRL_PARAM_CREATOR_SW_CFG_SIZE - OTP_CTRL_PARAM_CREATOR_SW_CFG_DIGEST_SIZE,
79 .digest_addr = OTP_CTRL_CREATOR_SW_CFG_DIGEST_0_REG_OFFSET,
80 .align_mask = 0x3,
81 },
82 [kOtpPartitionOwnerSwCfg] = {
83 .start_addr = OTP_CTRL_PARAM_OWNER_SW_CFG_OFFSET,
84 .size = OTP_CTRL_PARAM_OWNER_SW_CFG_SIZE - OTP_CTRL_PARAM_OWNER_SW_CFG_DIGEST_SIZE,
85 .digest_addr = OTP_CTRL_OWNER_SW_CFG_DIGEST_0_REG_OFFSET,
86 .align_mask = 0x3,
87 },
88 [kOtpPartitionRotCreatorAuthCodesign] = {
89 .start_addr = OTP_CTRL_PARAM_ROT_CREATOR_AUTH_CODESIGN_OFFSET,
90 .size = OTP_CTRL_PARAM_ROT_CREATOR_AUTH_CODESIGN_SIZE - OTP_CTRL_PARAM_ROT_CREATOR_AUTH_CODESIGN_DIGEST_SIZE,
91 .digest_addr = OTP_CTRL_ROT_CREATOR_AUTH_CODESIGN_DIGEST_0_REG_OFFSET,
92 .align_mask = 0x3,
93 },
94 [kOtpPartitionRotCreatorAuthState] = {
95 .start_addr = OTP_CTRL_PARAM_ROT_CREATOR_AUTH_STATE_OFFSET,
96 .size = OTP_CTRL_PARAM_ROT_CREATOR_AUTH_STATE_SIZE - OTP_CTRL_PARAM_ROT_CREATOR_AUTH_STATE_DIGEST_SIZE,
97 .digest_addr = OTP_CTRL_ROT_CREATOR_AUTH_STATE_DIGEST_0_REG_OFFSET,
98 .align_mask = 0x3,
99 },
100 [kOtpPartitionHwCfg0] = {
101 .start_addr = OTP_CTRL_PARAM_HW_CFG0_OFFSET,
102 .size = OTP_CTRL_PARAM_HW_CFG0_SIZE - OTP_CTRL_PARAM_HW_CFG0_DIGEST_SIZE,
103 .digest_addr = OTP_CTRL_HW_CFG0_DIGEST_0_REG_OFFSET,
104 .align_mask = 0x3,
105 },
106 [kOtpPartitionHwCfg1] = {
107 .start_addr = OTP_CTRL_PARAM_HW_CFG1_OFFSET,
108 .size = OTP_CTRL_PARAM_HW_CFG1_SIZE - OTP_CTRL_PARAM_HW_CFG1_DIGEST_SIZE,
109 .digest_addr = OTP_CTRL_HW_CFG1_DIGEST_0_REG_OFFSET,
110 .align_mask = 0x3,
111 },
112 },
113 },
114 },
115};
116
117/**
118 * Return a pointer to the `dt_otp_ctrl_desc_t` structure of the requested
119 * `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
120 * the function) with the provided default value.
121 */
122#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_otp_ctrl_t)0 || (dt) >= kDtOtpCtrlCount) return (default); &otp_ctrl_desc[dt]; })
123
125 if (inst_id >= kDtInstanceIdOtpCtrl && inst_id <= kDtInstanceIdOtpCtrl) {
126 return (dt_otp_ctrl_t)(inst_id - kDtInstanceIdOtpCtrl);
127 }
128 return (dt_otp_ctrl_t)0;
129}
130
135
137 dt_otp_ctrl_t dt,
138 dt_otp_ctrl_reg_block_t reg_block) {
139 // Return a recognizable address in case of wrong argument.
140 return TRY_GET_DT(dt, 0xdeadbeef)->reg_addr[reg_block];
141}
142
144 dt_otp_ctrl_t dt,
146 // Return a recognizable address in case of wrong argument.
147 return TRY_GET_DT(dt, 0xdeadbeef)->mem_addr[mem];
148}
149
151 dt_otp_ctrl_t dt,
153 // Return an empty size in case of wrong argument.
154 return TRY_GET_DT(dt, 0)->mem_size[mem];
155}
156
158 dt_otp_ctrl_t dt,
159 dt_otp_ctrl_irq_t irq) {
160 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, kDtPlicIrqIdNone)->first_irq;
161 if (first_irq == kDtPlicIrqIdNone) {
162 return kDtPlicIrqIdNone;
163 }
164 return (dt_plic_irq_id_t)((uint32_t)first_irq + (uint32_t)irq);
165}
166
168 dt_otp_ctrl_t dt,
169 dt_plic_irq_id_t irq) {
170 dt_otp_ctrl_irq_t count = kDtOtpCtrlIrqCount;
171 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, count)->first_irq;
172 if (first_irq == kDtPlicIrqIdNone) {
173 return count;
174 }
175 if (irq < first_irq || irq >= first_irq + (dt_plic_irq_id_t)count) {
176 return count;
177 }
178 return (dt_otp_ctrl_irq_t)(irq - first_irq);
179}
180
181
183 dt_otp_ctrl_t dt,
184 dt_otp_ctrl_alert_t alert) {
185 return (dt_alert_id_t)((uint32_t)otp_ctrl_desc[dt].first_alert + (uint32_t)alert);
186}
187
189 dt_otp_ctrl_t dt,
190 dt_alert_id_t alert) {
191 dt_otp_ctrl_alert_t count = kDtOtpCtrlAlertCount;
192 if (alert < otp_ctrl_desc[dt].first_alert || alert >= otp_ctrl_desc[dt].first_alert + (dt_alert_id_t)count) {
193 return count;
194 }
195 return (dt_otp_ctrl_alert_t)(alert - otp_ctrl_desc[dt].first_alert);
196}
197
198
199
201 dt_otp_ctrl_t dt,
203 // Return the first clock in case of invalid argument.
204 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
205}
206
208 dt_otp_ctrl_t dt,
210 const dt_otp_ctrl_reset_t count = kDtOtpCtrlResetCount;
211 if (rst >= count) {
212 return kDtResetUnknown;
213 }
214 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
215}
216
217
218
219
222 dt_otp_partition_info_t invalid_part = {
223 .start_addr = 0xdeadbeef,
224 .size = 0x0,
225 .digest_addr = 0xdeadbeef,
226 .align_mask = 0x0,
227 };
228 return TRY_GET_DT(dt, invalid_part)->sw_readable_partitions.info[partition];
229}
230
231
232