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
16
#include "
sw/device/lib/base/mmio.h
"
17
#include "
sw/device/lib/dif/dif_base.h
"
18
19
#include "sw/device/lib/dif/autogen/dif_acc_autogen.h"
20
21
#ifdef __cplusplus
22
extern
"C"
{
23
#endif
// __cplusplus
24
25
/**
26
* ACC commands.
27
*/
28
typedef
enum
dif_acc_cmd
{
29
kDifAccCmdExecute = 0xd8,
30
kDifAccCmdSecWipeDmem = 0xc3,
31
kDifAccCmdSecWipeImem = 0x1e,
32
}
dif_acc_cmd_t
;
33
34
/**
35
* ACC status.
36
*/
37
typedef
enum
dif_acc_status
{
38
kDifAccStatusIdle = 0x00,
39
kDifAccStatusBusyExecute = 0x01,
40
kDifAccStatusBusySecWipeDmem = 0x02,
41
kDifAccStatusBusySecWipeImem = 0x03,
42
kDifAccStatusBusySecWipeInt = 0x04,
43
kDifAccStatusLocked = 0xFF,
44
}
dif_acc_status_t
;
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
*/
53
typedef
enum
dif_acc_err_bits
{
54
kDifAccErrBitsNoError = 0,
55
/** A BAD_DATA_ADDR error was observed. */
56
kDifAccErrBitsBadDataAddr
= (1 << 0),
57
/** A BAD_INSN_ADDR error was observed. */
58
kDifAccErrBitsBadInsnAddr
= (1 << 1),
59
/** A CALL_STACK error was observed. */
60
kDifAccErrBitsCallStack
= (1 << 2),
61
/** An ILLEGAL_INSN error was observed. */
62
kDifAccErrBitsIllegalInsn
= (1 << 3),
63
/** A LOOP error was observed. */
64
kDifAccErrBitsLoop
= (1 << 4),
65
/** A RND_FIPS_CHECK_FAIL error was observed. */
66
kDifAccErrBitsRndFipsChkFail
= (1 << 7),
67
/** A IMEM_INTG_VIOLATION error was observed. */
68
kDifAccErrBitsImemIntgViolation
= (1 << 16),
69
/** A DMEM_INTG_VIOLATION error was observed. */
70
kDifAccErrBitsDmemIntgViolation
= (1 << 17),
71
/** A REG_INTG_VIOLATION error was observed. */
72
kDifAccErrBitsRegIntgViolation
= (1 << 18),
73
/** A BUS_INTG_VIOLATION error was observed. */
74
kDifAccErrBitsBusIntgViolation
= (1 << 19),
75
/** A BAD_INTERNAL_STATE error was observed. */
76
kDifAccErrBitsBadInternalState
= (1 << 20),
77
/** An ILLEGAL_BUS_ACCESS error was observed. */
78
kDifAccErrBitsIllegalBusAccess
= (1 << 21),
79
/** A LIFECYCLE_ESCALATION error was observed. */
80
kDifAccErrBitsLifecycleEscalation
= (1 << 22),
81
/** A FATAL_SOFTWARE error was observed. */
82
kDifAccErrBitsFatalSoftware
= (1 << 23),
83
}
dif_acc_err_bits_t
;
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
*/
94
OT_WARN_UNUSED_RESULT
95
dif_result_t
dif_acc_reset
(
const
dif_acc_t
*acc);
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
*/
104
OT_WARN_UNUSED_RESULT
105
dif_result_t
dif_acc_write_cmd
(
const
dif_acc_t
*acc,
dif_acc_cmd_t
cmd);
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
*/
114
OT_WARN_UNUSED_RESULT
115
dif_result_t
dif_acc_get_status
(
const
dif_acc_t
*acc,
dif_acc_status_t
*
status
);
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
*/
124
OT_WARN_UNUSED_RESULT
125
dif_result_t
dif_acc_get_err_bits
(
const
dif_acc_t
*acc,
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
*/
139
OT_WARN_UNUSED_RESULT
140
dif_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
*/
151
OT_WARN_UNUSED_RESULT
152
dif_result_t
dif_acc_get_load_checksum
(
const
dif_acc_t
*acc,
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
*/
163
OT_WARN_UNUSED_RESULT
164
dif_result_t
dif_acc_clear_load_checksum
(
const
dif_acc_t
*acc);
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
*/
177
OT_WARN_UNUSED_RESULT
178
dif_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
*/
192
OT_WARN_UNUSED_RESULT
193
dif_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
*/
207
OT_WARN_UNUSED_RESULT
208
dif_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
*/
222
OT_WARN_UNUSED_RESULT
223
dif_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
*/
237
OT_WARN_UNUSED_RESULT
238
dif_result_t
dif_acc_set_ctrl_software_errs_fatal
(
const
dif_acc_t
*acc,
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
*/
247
size_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
*/
255
size_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_
sw
device
lib
dif
dif_acc.h
Generated by
1.13.2