Software APIs
sw
device
lib
dif
autogen
dif_csrng_autogen.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
#ifndef OPENTITAN_SW_DEVICE_LIB_DIF_AUTOGEN_DIF_CSRNG_AUTOGEN_H_
6
#define OPENTITAN_SW_DEVICE_LIB_DIF_AUTOGEN_DIF_CSRNG_AUTOGEN_H_
7
8
// THIS FILE HAS BEEN GENERATED, DO NOT EDIT MANUALLY. COMMAND:
9
// util/make_new_dif.py --mode=regen --only=autogen
10
11
/**
12
* @file
13
* @brief <a href="/book/hw/ip/csrng/">CSRNG</a> Device Interface Functions
14
*/
15
16
#include <
stdbool.h
>
17
#include <
stdint.h
>
18
19
#include "
sw/device/lib/base/macros.h
"
20
#include "
sw/device/lib/base/mmio.h
"
21
#include "
sw/device/lib/dif/dif_base.h
"
22
23
#ifdef __cplusplus
24
extern
"C"
{
25
#endif
// __cplusplus
26
27
/**
28
* A handle to csrng.
29
*
30
* This type should be treated as opaque by users.
31
*/
32
typedef
struct
dif_csrng
{
33
/**
34
* The base address for the csrng hardware registers.
35
*/
36
mmio_region_t
base_addr
;
37
}
dif_csrng_t
;
38
39
/**
40
* Creates a new handle for a(n) csrng peripheral.
41
*
42
* This function does not actuate the hardware.
43
*
44
* @param base_addr The MMIO base address of the csrng peripheral.
45
* @param[out] csrng Out param for the initialized handle.
46
* @return The result of the operation.
47
*/
48
OT_WARN_UNUSED_RESULT
49
dif_result_t
dif_csrng_init
(
mmio_region_t
base_addr,
dif_csrng_t
*csrng);
50
51
/**
52
* A csrng alert type.
53
*/
54
typedef
enum
dif_csrng_alert
{
55
/**
56
* This alert is triggered when a recoverable alert occurs. Check the
57
* !!RECOV_ALERT_STS register to get more information.
58
*/
59
kDifCsrngAlertRecovAlert
= 0,
60
/**
61
* This alert triggers (i) if an illegal state machine state is reached, or
62
* (ii) if an AES fatal alert condition occurs, or (iii) if a fatal integrity
63
* failure is detected on the TL-UL bus.
64
*/
65
kDifCsrngAlertFatalAlert
= 1,
66
}
dif_csrng_alert_t
;
67
68
/**
69
* Forces a particular alert, causing it to be escalated as if the hardware
70
* had raised it.
71
*
72
* @param csrng A csrng handle.
73
* @param alert The alert to force.
74
* @return The result of the operation.
75
*/
76
OT_WARN_UNUSED_RESULT
77
dif_result_t
dif_csrng_alert_force
(
const
dif_csrng_t
*csrng,
78
dif_csrng_alert_t
alert);
79
80
/**
81
* A csrng interrupt request type.
82
*/
83
typedef
enum
dif_csrng_irq
{
84
/**
85
* Asserted when a command request is completed.
86
*/
87
kDifCsrngIrqCsCmdReqDone
= 0,
88
/**
89
* Asserted when a request for entropy has been made.
90
*/
91
kDifCsrngIrqCsEntropyReq
= 1,
92
/**
93
* Asserted when a hardware-attached CSRNG instance encounters a command
94
* exception
95
*/
96
kDifCsrngIrqCsHwInstExc
= 2,
97
/**
98
* Asserted when a FIFO error or a fatal alert occurs. Check the !!ERR_CODE
99
* register to get more information.
100
*/
101
kDifCsrngIrqCsFatalErr
= 3,
102
}
dif_csrng_irq_t
;
103
104
/**
105
* A snapshot of the state of the interrupts for this IP.
106
*
107
* This is an opaque type, to be used with the `dif_csrng_irq_get_state()`
108
* and `dif_csrng_irq_acknowledge_state()` functions.
109
*/
110
typedef
uint32_t
dif_csrng_irq_state_snapshot_t
;
111
112
/**
113
* Returns the type of a given interrupt (i.e., event or status) for this IP.
114
*
115
* @param csrng A csrng handle.
116
* @param irq An interrupt request.
117
* @param[out] type Out-param for the interrupt type.
118
* @return The result of the operation.
119
*/
120
OT_WARN_UNUSED_RESULT
121
dif_result_t
dif_csrng_irq_get_type
(
const
dif_csrng_t
*csrng,
122
dif_csrng_irq_t
irq,
dif_irq_type_t
*type);
123
124
/**
125
* Returns the state of all interrupts (i.e., pending or not) for this IP.
126
*
127
* @param csrng A csrng handle.
128
* @param[out] snapshot Out-param for interrupt state snapshot.
129
* @return The result of the operation.
130
*/
131
OT_WARN_UNUSED_RESULT
132
dif_result_t
dif_csrng_irq_get_state
(
const
dif_csrng_t
*csrng,
133
dif_csrng_irq_state_snapshot_t
*snapshot);
134
135
/**
136
* Returns whether a particular interrupt is currently pending.
137
*
138
* @param csrng A csrng handle.
139
* @param irq An interrupt request.
140
* @param[out] is_pending Out-param for whether the interrupt is pending.
141
* @return The result of the operation.
142
*/
143
OT_WARN_UNUSED_RESULT
144
dif_result_t
dif_csrng_irq_is_pending
(
const
dif_csrng_t
*csrng,
145
dif_csrng_irq_t
irq,
bool
*is_pending);
146
147
/**
148
* Acknowledges all interrupts that were pending at the time of the state
149
* snapshot.
150
*
151
* @param csrng A csrng handle.
152
* @param snapshot Interrupt state snapshot.
153
* @return The result of the operation.
154
*/
155
OT_WARN_UNUSED_RESULT
156
dif_result_t
dif_csrng_irq_acknowledge_state
(
157
const
dif_csrng_t
*csrng,
dif_csrng_irq_state_snapshot_t
snapshot);
158
159
/**
160
* Acknowledges all interrupts, indicating to the hardware that all
161
* interrupts have been successfully serviced.
162
*
163
* @param csrng A csrng handle.
164
* @return The result of the operation.
165
*/
166
OT_WARN_UNUSED_RESULT
167
dif_result_t
dif_csrng_irq_acknowledge_all
(
const
dif_csrng_t
*csrng);
168
169
/**
170
* Acknowledges a particular interrupt, indicating to the hardware that it has
171
* been successfully serviced.
172
*
173
* @param csrng A csrng handle.
174
* @param irq An interrupt request.
175
* @return The result of the operation.
176
*/
177
OT_WARN_UNUSED_RESULT
178
dif_result_t
dif_csrng_irq_acknowledge
(
const
dif_csrng_t
*csrng,
179
dif_csrng_irq_t
irq);
180
181
/**
182
* Forces a particular interrupt, causing it to be serviced as if hardware had
183
* asserted it.
184
*
185
* @param csrng A csrng handle.
186
* @param irq An interrupt request.
187
* @param val Value to be set.
188
* @return The result of the operation.
189
*/
190
OT_WARN_UNUSED_RESULT
191
dif_result_t
dif_csrng_irq_force
(
const
dif_csrng_t
*csrng,
dif_csrng_irq_t
irq,
192
const
bool
val);
193
194
/**
195
* A snapshot of the enablement state of the interrupts for this IP.
196
*
197
* This is an opaque type, to be used with the
198
* `dif_csrng_irq_disable_all()` and `dif_csrng_irq_restore_all()`
199
* functions.
200
*/
201
typedef
uint32_t
dif_csrng_irq_enable_snapshot_t
;
202
203
/**
204
* Checks whether a particular interrupt is currently enabled or disabled.
205
*
206
* @param csrng A csrng handle.
207
* @param irq An interrupt request.
208
* @param[out] state Out-param toggle state of the interrupt.
209
* @return The result of the operation.
210
*/
211
OT_WARN_UNUSED_RESULT
212
dif_result_t
dif_csrng_irq_get_enabled
(
const
dif_csrng_t
*csrng,
213
dif_csrng_irq_t
irq,
214
dif_toggle_t
*state);
215
216
/**
217
* Sets whether a particular interrupt is currently enabled or disabled.
218
*
219
* @param csrng A csrng handle.
220
* @param irq An interrupt request.
221
* @param state The new toggle state for the interrupt.
222
* @return The result of the operation.
223
*/
224
OT_WARN_UNUSED_RESULT
225
dif_result_t
dif_csrng_irq_set_enabled
(
const
dif_csrng_t
*csrng,
226
dif_csrng_irq_t
irq,
dif_toggle_t
state);
227
228
/**
229
* Disables all interrupts, optionally snapshotting all enable states for later
230
* restoration.
231
*
232
* @param csrng A csrng handle.
233
* @param[out] snapshot Out-param for the snapshot; may be `NULL`.
234
* @return The result of the operation.
235
*/
236
OT_WARN_UNUSED_RESULT
237
dif_result_t
dif_csrng_irq_disable_all
(
238
const
dif_csrng_t
*csrng,
dif_csrng_irq_enable_snapshot_t
*snapshot);
239
240
/**
241
* Restores interrupts from the given (enable) snapshot.
242
*
243
* @param csrng A csrng handle.
244
* @param snapshot A snapshot to restore from.
245
* @return The result of the operation.
246
*/
247
OT_WARN_UNUSED_RESULT
248
dif_result_t
dif_csrng_irq_restore_all
(
249
const
dif_csrng_t
*csrng,
const
dif_csrng_irq_enable_snapshot_t
*snapshot);
250
251
#ifdef __cplusplus
252
}
// extern "C"
253
#endif
// __cplusplus
254
255
#endif
// OPENTITAN_SW_DEVICE_LIB_DIF_AUTOGEN_DIF_CSRNG_AUTOGEN_H_
Return to
OpenTitan Documentation