Software APIs
dt_clkmgr.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_CLKMGR_H_
8#define OPENTITAN_DT_CLKMGR_H_
9
10#ifdef __cplusplus
11extern "C" {
12#endif // __cplusplus
13
14/**
15 * @file
16 * @brief Device Tables (DT) for IP clkmgr and top darjeeling.
17 *
18 * This file contains the type definitions and global functions of the clkmgr.
19 */
20
21#include "hw/top/dt/dt_api.h"
22#include <stdint.h>
23
24
26
27
28/**
29 * List of instances.
30 */
31typedef enum dt_clkmgr {
32 kDtClkmgrAon = 0, /**< clkmgr_aon */
33 kDtClkmgrFirst = 0, /**< \internal First instance */
34 kDtClkmgrCount = 1, /**< \internal Number of instances */
36
37/**
38 * List of register blocks.
39 *
40 * Register blocks are guaranteed to start at 0 and to be consecutively numbered.
41 */
42typedef enum dt_clkmgr_reg_block {
43 kDtClkmgrRegBlockCore = 0, /**< */
44 kDtClkmgrRegBlockCount = 1, /**< \internal Number of register blocks */
46
47/** Primary register block (associated with the "primary" set of registers that control the IP). */
48static const dt_clkmgr_reg_block_t kDtClkmgrRegBlockPrimary = kDtClkmgrRegBlockCore;
49
50/**
51 * List of memories.
52 *
53 * Memories are guaranteed to start at 0 and to be consecutively numbered.
54 */
55typedef enum dt_clkmgr_memory {
56 kDtClkmgrMemoryCount = 0, /**< \internal Number of memories */
58
59/**
60 * List of Alerts.
61 *
62 * Alerts are guaranteed to be numbered consecutively from 0.
63 */
64typedef enum dt_clkmgr_alert {
65 kDtClkmgrAlertRecovFault = 0, /**< This recoverable alert is triggered when there are measurement errors. */
66 kDtClkmgrAlertFatalFault = 1, /**< This fatal alert is triggered when a fatal TL-UL bus integrity fault is detected. */
67 kDtClkmgrAlertCount = 2, /**< \internal Number of Alerts */
69
70/**
71 * List of clock ports.
72 *
73 * Clock ports are guaranteed to be numbered consecutively from 0.
74 */
75typedef enum dt_clkmgr_clock {
76 kDtClkmgrClockClk = 0, /**< Clock port clk_i */
77 kDtClkmgrClockMain = 1, /**< Clock port clk_main_i */
78 kDtClkmgrClockIo = 2, /**< Clock port clk_io_i */
79 kDtClkmgrClockAon = 3, /**< Clock port clk_aon_i */
80 kDtClkmgrClockCount = 4, /**< \internal Number of clock ports */
82
83/**
84 * List of reset ports.
85 *
86 * Reset ports are guaranteed to be numbered consecutively from 0.
87 */
88typedef enum dt_clkmgr_reset {
89 kDtClkmgrResetRst = 0, /**< Reset port rst_ni */
90 kDtClkmgrResetRoot = 1, /**< Reset port rst_root_ni */
91 kDtClkmgrResetMain = 2, /**< Reset port rst_main_ni */
92 kDtClkmgrResetIo = 3, /**< Reset port rst_io_ni */
93 kDtClkmgrResetAon = 4, /**< Reset port rst_aon_ni */
94 kDtClkmgrResetIoDiv2 = 5, /**< Reset port rst_io_div2_ni */
95 kDtClkmgrResetIoDiv4 = 6, /**< Reset port rst_io_div4_ni */
96 kDtClkmgrResetRootMain = 7, /**< Reset port rst_root_main_ni */
97 kDtClkmgrResetRootIo = 8, /**< Reset port rst_root_io_ni */
98 kDtClkmgrResetRootIoDiv2 = 9, /**< Reset port rst_root_io_div2_ni */
99 kDtClkmgrResetRootIoDiv4 = 10, /**< Reset port rst_root_io_div4_ni */
100 kDtClkmgrResetCount = 11, /**< \internal Number of reset ports */
102
103/**
104 * List of supported hardware features.
105 */
106#define OPENTITAN_CLKMGR_HAS_ENABLE_IO_DIV4 1
107#define OPENTITAN_CLKMGR_HAS_ENABLE_IO_DIV2 1
108#define OPENTITAN_CLKMGR_HAS_HINT_AES 1
109#define OPENTITAN_CLKMGR_HAS_HINT_HMAC 1
110#define OPENTITAN_CLKMGR_HAS_HINT_KMAC 1
111#define OPENTITAN_CLKMGR_HAS_HINT_OTBN 1
112#define OPENTITAN_CLKMGR_HAS_MEAS_CTRL_REGWEN 1
113#define OPENTITAN_CLKMGR_HAS_MEAS_CTRL_IO_DIV4 1
114#define OPENTITAN_CLKMGR_HAS_MEAS_CTRL_MAIN 1
115#define OPENTITAN_CLKMGR_HAS_MEAS_CTRL_RECOV_ERR 1
116#define OPENTITAN_CLKMGR_HAS_LC_EXTCLK_SPEED 1
117#define OPENTITAN_CLKMGR_HAS_SW_EXTCLK_REGWEN 1
118#define OPENTITAN_CLKMGR_HAS_SW_EXTCLK_HIGH_SPEED 1
119#define OPENTITAN_CLKMGR_HAS_SW_EXTCLK_LOW_SPEED 1
120#define OPENTITAN_CLKMGR_HAS_JITTER_REGWEN 1
121#define OPENTITAN_CLKMGR_HAS_JITTER_ENABLE 1
122#define OPENTITAN_CLKMGR_HAS_ALERT_HANDLER_CLOCK_STATUS 1
123
124
125
126/**
127 * Get the clkmgr instance from an instance ID
128 *
129 * For example, `dt_uart_from_instance_id(kDtInstanceIdUart3) == kDtUart3`.
130 *
131 * @param inst_id Instance ID.
132 * @return A clkmgr instance.
133 *
134 * **Note:** This function only makes sense if the instance ID has device type clkmgr,
135 * otherwise the returned value is unspecified.
136 */
138
139/**
140 * Get the instance ID of an instance.
141 *
142 * @param dt Instance of clkmgr.
143 * @return The instance ID of that instance.
144 */
146
147/**
148 * Get the register base address of an instance.
149 *
150 * @param dt Instance of clkmgr.
151 * @param reg_block The register block requested.
152 * @return The register base address of the requested block.
153 */
154uint32_t dt_clkmgr_reg_block(
155 dt_clkmgr_t dt,
156 dt_clkmgr_reg_block_t reg_block);
157
158/**
159 * Get the primary register base address of an instance.
160 *
161 * This is just a convenience function, equivalent to
162 * `dt_clkmgr_reg_block(dt, kDtClkmgrRegBlockCore)`
163 *
164 * @param dt Instance of clkmgr.
165 * @return The register base address of the primary register block.
166 */
167static inline uint32_t dt_clkmgr_primary_reg_block(
168 dt_clkmgr_t dt) {
169 return dt_clkmgr_reg_block(dt, kDtClkmgrRegBlockCore);
170}
171
172/**
173 * Get the base address of a memory.
174 *
175 * @param dt Instance of clkmgr.
176 * @param mem The memory requested.
177 * @return The base address of the requested memory.
178 */
179uint32_t dt_clkmgr_memory_base(
180 dt_clkmgr_t dt,
182
183/**
184 * Get the size of a memory.
185 *
186 * @param dt Instance of clkmgr.
187 * @param mem The memory requested.
188 * @return The size of the requested memory.
189 */
190uint32_t dt_clkmgr_memory_size(
191 dt_clkmgr_t dt,
193
194
195/**
196 * Get the alert ID of a clkmgr alert for a given instance.
197 *
198 * **Note:** This function only makes sense if the instance is connected to the Alert Handler. For any
199 * instances where the instance is not connected, the return value is unspecified.
200 *
201 * @param dt Instance of clkmgr.
202 * @param alert A clkmgr alert.
203 * @return The Alert Handler alert ID of the alert of this instance.
204 */
206 dt_clkmgr_t dt,
207 dt_clkmgr_alert_t alert);
208
209/**
210 * Convert a global alert ID to a local clkmgr alert type.
211 *
212 * @param dt Instance of clkmgr.
213 * @param alert A global alert ID that belongs to this instance.
214 * @return The clkmgr alert, or `kDtClkmgrAlertCount`.
215 *
216 * **Note:** This function assumes that the global alert ID belongs to the
217 * instance of clkmgr passed in parameter. In other words, it must be the case
218 * that `dt_clkmgr_instance_id(dt) == dt_alert_id_to_instance_id(alert)`. Otherwise,
219 * this function will return `kDtClkmgrAlertCount`.
220 */
222 dt_clkmgr_t dt,
223 dt_alert_id_t alert);
224
225
226
227/**
228 * Get the clock signal connected to a clock port of an instance.
229 *
230 * @param dt Instance of clkmgr.
231 * @param clk Clock port.
232 * @return Clock signal.
233 */
235 dt_clkmgr_t dt,
237
238/**
239 * Get the reset signal connected to a reset port of an instance.
240 *
241 * @param dt Instance of clkmgr.
242 * @param rst Reset port.
243 * @return Reset signal.
244 */
246 dt_clkmgr_t dt,
248
249
250
251/**
252 * Get the number of software gateable clocks.
253 *
254 * @param dt Instance of clkmgr.
255 * @return Number of gateable clocks.
256 */
258
259/**
260 * Get the instance ID of a gateable clock.
261 *
262 * The clocks are ordered as they appear in the registers.
263 *
264 * @param dt Instance of clkmgr.
265 * @param idx Index of the gateable clock, between 0 and `dt_clkmgr_sw_clock_count(dt)-1`.
266 * @return Instance ID of the device whose clock is gateable.
267 */
269
270/**
271 * Get the number of software hintable clocks.
272 *
273 * @param dt Instance of clkmgr.
274 * @return Number of hintable clocks.
275 */
277
278/**
279 * Get the instance ID of a hintable clock.
280 *
281 * The clocks sources are ordered as they appear in the registers.
282 *
283 * @param dt Instance of clkmgr.
284 * @param idx Index of the hintable clock, between 0 and `dt_clkmgr_hint_clock_count(dt)-1`.
285 * @return Instance ID of the device whose clock is hintable.
286 */
288
289/**
290 * Description of a measurable clock.
291 *
292 */
293typedef struct dt_clkmgr_measurable_clk {
294 dt_clock_t clock; /**< Clock */
295 uint32_t meas_ctrl_en_off; /**< MEAS_CTRL_EN register offset */
296 bitfield_field32_t meas_ctrl_en_en_field; /**< MEAS_CTRL_EN_EN bitfield */
297 uint32_t meas_ctrl_shadowed_off; /**< CTRL_SHADOWED register offset */
298 bitfield_field32_t meas_ctrl_shadowed_lo_field; /**< CTRL_SHADOWED_LO bitfield */
299 bitfield_field32_t meas_ctrl_shadowed_hi_field; /**< CTRL_SHADOWED_HI bitfield */
301
302
303/**
304 * Get the number of measurable clocks.
305 *
306 * @param dt Instance of clkmgr.
307 * @return Number of measurable clocks.
308 */
310
311/**
312 * Get the description of a measurable clock.
313 *
314 * @param dt Instance of clkmgr.
315 * @param idx Index of the measurable clock, between 0 and
316 * `dt_clkmgr_measurable_clock_count(dt)-1`.
317 * @return Description of the measurable clock.
318 */
320
321
322
323#ifdef __cplusplus
324} // extern "C"
325#endif // __cplusplus
326
327#endif // OPENTITAN_DT_CLKMGR_H_