Software APIs
dif_flash_ctrl_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
6
7#ifndef OPENTITAN_SW_DEVICE_LIB_DIF_AUTOGEN_DIF_FLASH_CTRL_AUTOGEN_H_
8#define OPENTITAN_SW_DEVICE_LIB_DIF_AUTOGEN_DIF_FLASH_CTRL_AUTOGEN_H_
9
10// THIS FILE HAS BEEN GENERATED, DO NOT EDIT MANUALLY. COMMAND:
11// util/autogen_dif.py -i
12// hw/top_earlgrey/ip_autogen/flash_ctrl/data/flash_ctrl.hjson -o
13// bazel-out/k8-fastbuild/bin/sw/device/lib/dif/autogen
14
15
16/**
17 * @file
18 * @brief <a href="/book/hw/ip/flash_ctrl/">FLASH_CTRL</a> Device Interface Functions
19 */
20
21#include <stdbool.h>
22#include <stdint.h>
23
27#include "hw/top/dt/flash_ctrl.h" // Generated.
28
29#ifdef __cplusplus
30extern "C" {
31#endif // __cplusplus
32
33/**
34 * A handle to flash_ctrl.
35 *
36 * This type should be treated as opaque by users.
37 */
38typedef struct dif_flash_ctrl {
39 /**
40 * The base address for the flash_ctrl hardware registers.
41 */
43 /**
44 * The instance, set to `kDtFlashCtrlCount` if not initialized
45 * through `dif_flash_ctrl_init_from_dt`.
46 */
49
50/**
51 * Creates a new handle for a(n) flash_ctrl peripheral.
52 *
53 * This function does not actuate the hardware.
54 *
55 * @param base_addr The MMIO base address of the flash_ctrl peripheral.
56 * @param[out] flash_ctrl Out param for the initialized handle.
57 * @return The result of the operation.
58 *
59 * DEPRECATED This function exists solely for the transition to
60 * dt-based DIFs and will be removed in the future.
61 */
64 mmio_region_t base_addr,
65 dif_flash_ctrl_t *flash_ctrl);
66
67/**
68 * Creates a new handle for a(n) flash_ctrl peripheral.
69 *
70 * This function does not actuate the hardware.
71 *
72 * @param dt The devicetable description of the device.
73 * @param[out] flash_ctrl Out param for the initialized handle.
74 * @return The result of the operation.
75 */
79 dif_flash_ctrl_t *flash_ctrl);
80
81/**
82 * Get the DT handle from this DIF.
83 *
84 * If this DIF was initialized by `dif_flash_ctrl_init_from_dt(dt, ..)`
85 * then this function will return `dt`. Otherwise it will return an error.
86 *
87 * @param flash_ctrl A flash_ctrl handle.
88 * @param[out] dt DT handle.
89 * @return `kDifBadArg` if the DIF has no DT information, `kDifOk` otherwise.
90 */
93 const dif_flash_ctrl_t *flash_ctrl,
94 dt_flash_ctrl_t *dt);
95
96 /**
97 * A flash_ctrl alert type.
98 */
99 typedef enum dif_flash_ctrl_alert {
100 /**
101 * Flash recoverable errors
102 */
104 /**
105 * Flash standard fatal errors
106 */
108 /**
109 * Flash fatal errors including uncorrectable ECC errors. Note that this alert is not always fatal. The underlying error bits in the !!FAULT_STATUS register remain set until reset, meaning the alert keeps firing. This doesn't hold for !!FAULT_STATUS.PHY_RELBL_ERR and !!FAULT_STATUS.PHY_STORAGE_ERR. To enable firmware dealing with multi-bit ECC and ICV errors during firmware selection and verification, these error bits can be cleared. After passing this stage, it is recommended that firmware classifies the corresponding alert as fatal on the receiver end, i.e, inside the alert handler.
110 */
112 /**
113 * Fatal alert triggered inside the flash primitive, including fatal TL-UL bus integrity faults of the test interface.
114 */
116 /**
117 * Recoverable alert triggered inside the flash primitive.
118 */
121
122 /**
123 * Forces a particular alert, causing it to be escalated as if the hardware
124 * had raised it.
125 *
126 * @param flash_ctrl A flash_ctrl handle.
127 * @param alert The alert to force.
128 * @return The result of the operation.
129 */
132 const dif_flash_ctrl_t *flash_ctrl,
134
135 // DEPRECATED This typedef exists solely for the transition to
136 // dt-based interrupt numbers and will be removed in the future.
137 typedef dt_flash_ctrl_irq_t dif_flash_ctrl_irq_t;
138
139 /**
140 * A flash_ctrl interrupt request type.
141 *
142 * DEPRECATED Use `dt_flash_ctrl_irq_t` instead.
143 * This enumeration exists solely for the transition to
144 * dt-based interrupt numbers and will be removed in the future.
145 *
146 * The following are defines to keep the types consistent with DT.
147 */
148 /**
149 * Program FIFO empty
150 */
151#define kDifFlashCtrlIrqProgEmpty kDtFlashCtrlIrqProgEmpty
152 /**
153 * Program FIFO drained to level
154 */
155#define kDifFlashCtrlIrqProgLvl kDtFlashCtrlIrqProgLvl
156 /**
157 * Read FIFO full
158 */
159#define kDifFlashCtrlIrqRdFull kDtFlashCtrlIrqRdFull
160 /**
161 * Read FIFO filled to level
162 */
163#define kDifFlashCtrlIrqRdLvl kDtFlashCtrlIrqRdLvl
164 /**
165 * Operation complete
166 */
167#define kDifFlashCtrlIrqOpDone kDtFlashCtrlIrqOpDone
168 /**
169 * Correctable error encountered
170 */
171#define kDifFlashCtrlIrqCorrErr kDtFlashCtrlIrqCorrErr
172
173 /**
174 * A snapshot of the state of the interrupts for this IP.
175 *
176 * This is an opaque type, to be used with the `dif_flash_ctrl_irq_get_state()`
177 * and `dif_flash_ctrl_irq_acknowledge_state()` functions.
178 */
180
181 /**
182 * Returns the type of a given interrupt (i.e., event or status) for this IP.
183 *
184 * @param flash_ctrl A flash_ctrl handle.
185 * @param irq An interrupt request.
186 * @param[out] type Out-param for the interrupt type.
187 * @return The result of the operation.
188 */
191 const dif_flash_ctrl_t *flash_ctrl,
192 dif_flash_ctrl_irq_t,
193 dif_irq_type_t *type);
194
195 /**
196 * Returns the state of all interrupts (i.e., pending or not) for this IP.
197 *
198 * @param flash_ctrl A flash_ctrl handle.
199 * @param[out] snapshot Out-param for interrupt state snapshot.
200 * @return The result of the operation.
201 */
204 const dif_flash_ctrl_t *flash_ctrl,
206
207 /**
208 * Returns whether a particular interrupt is currently pending.
209 *
210 * @param flash_ctrl A flash_ctrl handle.
211 * @param irq An interrupt request.
212 * @param[out] is_pending Out-param for whether the interrupt is pending.
213 * @return The result of the operation.
214 */
217 const dif_flash_ctrl_t *flash_ctrl,
218 dif_flash_ctrl_irq_t,
219 bool *is_pending);
220
221 /**
222 * Acknowledges all interrupts that were pending at the time of the state
223 * snapshot.
224 *
225 * @param flash_ctrl A flash_ctrl handle.
226 * @param snapshot Interrupt state snapshot.
227 * @return The result of the operation.
228 */
231 const dif_flash_ctrl_t *flash_ctrl,
233
234 /**
235 * Acknowledges all interrupts, indicating to the hardware that all
236 * interrupts have been successfully serviced.
237 *
238 * @param flash_ctrl A flash_ctrl handle.
239 * @return The result of the operation.
240 */
243 const dif_flash_ctrl_t *flash_ctrl
244 );
245
246 /**
247 * Acknowledges a particular interrupt, indicating to the hardware that it has
248 * been successfully serviced.
249 *
250 * @param flash_ctrl A flash_ctrl handle.
251 * @param irq An interrupt request.
252 * @return The result of the operation.
253 */
256 const dif_flash_ctrl_t *flash_ctrl,
257 dif_flash_ctrl_irq_t);
258
259 /**
260 * Forces a particular interrupt, causing it to be serviced as if hardware had
261 * asserted it.
262 *
263 * @param flash_ctrl A flash_ctrl handle.
264 * @param irq An interrupt request.
265 * @param val Value to be set.
266 * @return The result of the operation.
267 */
270 const dif_flash_ctrl_t *flash_ctrl,
271 dif_flash_ctrl_irq_t,
272 const bool val);
273
274 /**
275 * A snapshot of the enablement state of the interrupts for this IP.
276 *
277 * This is an opaque type, to be used with the
278 * `dif_flash_ctrl_irq_disable_all()` and `dif_flash_ctrl_irq_restore_all()`
279 * functions.
280 */
282
283 /**
284 * Checks whether a particular interrupt is currently enabled or disabled.
285 *
286 * @param flash_ctrl A flash_ctrl handle.
287 * @param irq An interrupt request.
288 * @param[out] state Out-param toggle state of the interrupt.
289 * @return The result of the operation.
290 */
293 const dif_flash_ctrl_t *flash_ctrl,
294 dif_flash_ctrl_irq_t,
295 dif_toggle_t *state);
296
297 /**
298 * Sets whether a particular interrupt is currently enabled or disabled.
299 *
300 * @param flash_ctrl A flash_ctrl handle.
301 * @param irq An interrupt request.
302 * @param state The new toggle state for the interrupt.
303 * @return The result of the operation.
304 */
307 const dif_flash_ctrl_t *flash_ctrl,
308 dif_flash_ctrl_irq_t,
309 dif_toggle_t state);
310
311 /**
312 * Disables all interrupts, optionally snapshotting all enable states for later
313 * restoration.
314 *
315 * @param flash_ctrl A flash_ctrl handle.
316 * @param[out] snapshot Out-param for the snapshot; may be `NULL`.
317 * @return The result of the operation.
318 */
321 const dif_flash_ctrl_t *flash_ctrl,
323
324 /**
325 * Restores interrupts from the given (enable) snapshot.
326 *
327 * @param flash_ctrl A flash_ctrl handle.
328 * @param snapshot A snapshot to restore from.
329 * @return The result of the operation.
330 */
333 const dif_flash_ctrl_t *flash_ctrl,
335
336
337#ifdef __cplusplus
338} // extern "C"
339#endif // __cplusplus
340
341#endif // OPENTITAN_SW_DEVICE_LIB_DIF_AUTOGEN_DIF_FLASH_CTRL_AUTOGEN_H_