13 #include "otbn_regs.h"
16 (1 << OTBN_ERR_BITS_BAD_DATA_ADDR_BIT),
17 "Layout of error bits changed.");
19 (1 << OTBN_ERR_BITS_BAD_INSN_ADDR_BIT),
20 "Layout of error bits changed.");
22 "Layout of error bits changed.");
24 (1 << OTBN_ERR_BITS_ILLEGAL_INSN_BIT),
25 "Layout of error bits changed.");
27 "Layout of error bits changed.");
29 (1 << OTBN_ERR_BITS_IMEM_INTG_VIOLATION_BIT),
30 "Layout of error bits changed.");
32 (1 << OTBN_ERR_BITS_DMEM_INTG_VIOLATION_BIT),
33 "Layout of error bits changed.");
35 (1 << OTBN_ERR_BITS_REG_INTG_VIOLATION_BIT),
36 "Layout of error bits changed.");
38 (1 << OTBN_ERR_BITS_BUS_INTG_VIOLATION_BIT),
39 "Layout of error bits changed.");
41 (1 << OTBN_ERR_BITS_ILLEGAL_BUS_ACCESS_BIT),
42 "Layout of error bits changed.");
44 (1 << OTBN_ERR_BITS_LIFECYCLE_ESCALATION_BIT),
45 "Layout of error bits changed.");
47 (1 << OTBN_ERR_BITS_FATAL_SOFTWARE_BIT),
48 "Layout of error bits changed.");
53 const int kDifOtbnWlenBytes = 256 / 8;
61 static bool check_offset_len(uint32_t offset_bytes,
size_t len_bytes,
64 return (len_bytes %
sizeof(uint32_t) == 0 &&
65 offset_bytes %
sizeof(uint32_t) == 0 &&
66 offset_bytes + len_bytes >= len_bytes &&
67 offset_bytes + len_bytes <= mem_size);
75 mmio_region_write32(otbn->
base_addr, OTBN_INTR_ENABLE_REG_OFFSET, 0);
78 mmio_region_write32(otbn->
base_addr, OTBN_INTR_STATE_REG_OFFSET, 0xFFFFFFFF);
88 mmio_region_write32(otbn->
base_addr, OTBN_CMD_REG_OFFSET, cmd);
95 if (otbn == NULL ||
status == NULL) {
106 if (otbn == NULL || err_bits == NULL) {
110 uint32_t err_bits_raw =
111 mmio_region_read32(otbn->
base_addr, OTBN_ERR_BITS_REG_OFFSET);
113 *err_bits = err_bits_raw;
118 if (otbn == NULL || insn_cnt == NULL) {
122 *insn_cnt = mmio_region_read32(otbn->
base_addr, OTBN_INSN_CNT_REG_OFFSET);
127 uint32_t *checksum) {
128 if (otbn == NULL || checksum == NULL) {
133 mmio_region_read32(otbn->
base_addr, OTBN_LOAD_CHECKSUM_REG_OFFSET);
142 mmio_region_write32(otbn->
base_addr, OTBN_LOAD_CHECKSUM_REG_OFFSET, 0);
148 const void *src,
size_t len_bytes) {
149 if (otbn == NULL || src == NULL ||
150 !check_offset_len(offset_bytes, len_bytes, OTBN_IMEM_SIZE_BYTES)) {
155 otbn->
base_addr, OTBN_IMEM_REG_OFFSET + offset_bytes, src, len_bytes);
161 void *dest,
size_t len_bytes) {
162 if (otbn == NULL || dest == NULL ||
163 !check_offset_len(offset_bytes, len_bytes, OTBN_IMEM_SIZE_BYTES)) {
168 otbn->
base_addr, OTBN_IMEM_REG_OFFSET + offset_bytes, dest, len_bytes);
174 const void *src,
size_t len_bytes) {
175 if (otbn == NULL || src == NULL ||
176 !check_offset_len(offset_bytes, len_bytes, OTBN_DMEM_SIZE_BYTES)) {
181 otbn->
base_addr, OTBN_DMEM_REG_OFFSET + offset_bytes, src, len_bytes);
187 void *dest,
size_t len_bytes) {
188 if (otbn == NULL || dest == NULL ||
189 !check_offset_len(offset_bytes, len_bytes, OTBN_DMEM_SIZE_BYTES)) {
194 otbn->
base_addr, OTBN_DMEM_REG_OFFSET + offset_bytes, dest, len_bytes);
214 mmio_region_write32(otbn->
base_addr, OTBN_CTRL_REG_OFFSET, new_ctrl);
215 if (mmio_region_read32(otbn->
base_addr, OTBN_CTRL_REG_OFFSET) != new_ctrl) {
223 return OTBN_DMEM_SIZE_BYTES;
227 return OTBN_IMEM_SIZE_BYTES;