Pavona Software APIs
dif_acc.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_DIF_ACC_H_
6#define OPENTITAN_SW_DEVICE_LIB_DIF_DIF_ACC_H_
7
8/**
9 * @file
10 * @brief <a href="/book/hw/ip/acc/">ACC</a> Device Interface Functions.
11 */
12
13#include <stddef.h>
14#include <stdint.h>
15
18
19#include "sw/device/lib/dif/autogen/dif_acc_autogen.h"
20
21#ifdef __cplusplus
22extern "C" {
23#endif // __cplusplus
24
25/**
26 * ACC commands.
27 */
28typedef enum dif_acc_cmd {
29 kDifAccCmdExecute = 0xd8,
30 kDifAccCmdSecWipeDmem = 0xc3,
31 kDifAccCmdSecWipeImem = 0x1e,
33
34/**
35 * ACC status.
36 */
37typedef enum dif_acc_status {
38 kDifAccStatusIdle = 0x00,
39 kDifAccStatusBusyExecute = 0x01,
40 kDifAccStatusBusySecWipeDmem = 0x02,
41 kDifAccStatusBusySecWipeImem = 0x03,
42 kDifAccStatusBusySecWipeInt = 0x04,
43 kDifAccStatusLocked = 0xFF,
45
46/**
47 * ACC Errors.
48 *
49 * ACC uses a bitfield to indicate which errors have been seen. Multiple errors
50 * can be seen at the same time. This enum gives the individual bits that may be
51 * set for different errors.
52 */
53typedef enum dif_acc_err_bits {
54 kDifAccErrBitsNoError = 0,
55 /** A BAD_DATA_ADDR error was observed. */
57 /** A BAD_INSN_ADDR error was observed. */
59 /** A CALL_STACK error was observed. */
61 /** An ILLEGAL_INSN error was observed. */
63 /** A LOOP error was observed. */
65 /** A RND_FIPS_CHECK_FAIL error was observed. */
67 /** A IMEM_INTG_VIOLATION error was observed. */
69 /** A DMEM_INTG_VIOLATION error was observed. */
71 /** A REG_INTG_VIOLATION error was observed. */
73 /** A BUS_INTG_VIOLATION error was observed. */
75 /** A BAD_INTERNAL_STATE error was observed. */
77 /** An ILLEGAL_BUS_ACCESS error was observed. */
79 /** A LIFECYCLE_ESCALATION error was observed. */
81 /** A FATAL_SOFTWARE error was observed. */
84
85/**
86 * Reset ACC device.
87 *
88 * Resets the given ACC device by setting its configuration registers to
89 * reset values. Disables interrupts, output, and input filter.
90 *
91 * @param acc ACC instance.
92 * @return The result of the operation.
93 */
96
97/**
98 * Start an operation by issuing a command.
99 *
100 * @param acc ACC instance.
101 * @param cmd The command.
102 * @return The result of the operation.
103 */
106
107/**
108 * Gets the current status of ACC.
109 *
110 * @param acc ACC instance.
111 * @param[out] status ACC status.
112 * @return The result of the operation.
113 */
116
117/**
118 * Get the error bits set by the device if the operation failed.
119 *
120 * @param acc ACC instance.
121 * @param[out] err_bits The error bits returned by the hardware.
122 * @return The result of the operation.
123 */
126 dif_acc_err_bits_t *err_bits);
127
128/**
129 * Gets the number of executed ACC instructions.
130 *
131 * Gets the number of instructions executed so far in the current ACC run if
132 * there is one. Otherwise, gets the number executed in total in the previous
133 * ACC run.
134 *
135 * @param acc ACC instance.
136 * @param[out] insn_cnt The number of instructions executed by ACC.
137 * @return The result of the operation.
138 */
140dif_result_t dif_acc_get_insn_cnt(const dif_acc_t *acc, uint32_t *insn_cnt);
141
142/**
143 * Gets the content of the load checksum register.
144 *
145 * Gets the 32-bit CRC checksum of data written to memory.
146 *
147 * @param acc ACC instance.
148 * @param[out] insn_cnt The number of instructions executed by ACC.
149 * @return The result of the operation.
150 */
153 uint32_t *insn_cnt);
154
155/**
156 * Clears the load checksum register.
157 *
158 * Writes 0 to the load checksum register to clear it.
159 *
160 * @param acc ACC instance.
161 * @return The result of the operation.
162 */
165
166/**
167 * Write an ACC application into its instruction memory (IMEM).
168 *
169 * Only 32b-aligned 32b word accesses are allowed.
170 *
171 * @param acc ACC instance.
172 * @param offset_bytes the byte offset in IMEM the first word is written to.
173 * @param src the main memory location to start reading from.
174 * @param len_bytes number of bytes to copy.
175 * @return The result of the operation.
176 */
178dif_result_t dif_acc_imem_write(const dif_acc_t *acc, uint32_t offset_bytes,
179 const void *src, size_t len_bytes);
180
181/**
182 * Read from ACC's instruction memory (IMEM).
183 *
184 * Only 32b-aligned 32b word accesses are allowed.
185 *
186 * @param acc ACC instance
187 * @param offset_bytes the byte offset in IMEM the first word is read from.
188 * @param[out] dest the main memory location to copy the data to (preallocated).
189 * @param len_bytes number of bytes to copy.
190 * @return The result of the operation.
191 */
193dif_result_t dif_acc_imem_read(const dif_acc_t *acc, uint32_t offset_bytes,
194 void *dest, size_t len_bytes);
195
196/**
197 * Write to ACC's data memory (DMEM).
198 *
199 * Only 32b-aligned 32b word accesses are allowed.
200 *
201 * @param acc ACC instance.
202 * @param offset_bytes the byte offset in DMEM the first word is written to.
203 * @param src the main memory location to start reading from.
204 * @param len_bytes number of bytes to copy.
205 * @return The result of the operation.
206 */
208dif_result_t dif_acc_dmem_write(const dif_acc_t *acc, uint32_t offset_bytes,
209 const void *src, size_t len_bytes);
210
211/**
212 * Read from ACC's data memory (DMEM).
213 *
214 * Only 32b-aligned 32b word accesses are allowed.
215 *
216 * @param acc ACC instance
217 * @param offset_bytes the byte offset in DMEM the first word is read from.
218 * @param[out] dest the main memory location to copy the data to (preallocated).
219 * @param len_bytes number of bytes to copy.
220 * @return The result of the operation.
221 */
223dif_result_t dif_acc_dmem_read(const dif_acc_t *acc, uint32_t offset_bytes,
224 void *dest, size_t len_bytes);
225
226/**
227 * Sets the software errors are fatal bit in the control register.
228 *
229 * When set any software error becomes a fatal error. The bit can only be
230 * changed when the ACC status is IDLE.
231 *
232 * @param acc ACC instance.
233 * @param enable Enable or disable whether software errors are fatal.
234 * @return The result of the operation, `kDifUnavailable` is returned when the
235 * requested change cannot be made.
236 */
239 bool enable);
240
241/**
242 * Get the size of ACC's data memory in bytes.
243 *
244 * @param acc ACC instance.
245 * @return data memory size in bytes.
246 */
247size_t dif_acc_get_dmem_size_bytes(const dif_acc_t *acc);
248
249/**
250 * Get the size of ACC's instruction memory in bytes.
251 *
252 * @param acc ACC instance.
253 * @return instruction memory size in bytes.
254 */
255size_t dif_acc_get_imem_size_bytes(const dif_acc_t *acc);
256
257#ifdef __cplusplus
258} // extern "C"
259#endif // __cplusplus
260
261#endif // OPENTITAN_SW_DEVICE_LIB_DIF_DIF_ACC_H_