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 const void *src,
size_t len_bytes) {
128 if (otbn == NULL || src == NULL ||
129 !check_offset_len(offset_bytes, len_bytes, OTBN_IMEM_SIZE_BYTES)) {
134 otbn->
base_addr, OTBN_IMEM_REG_OFFSET + offset_bytes, src, len_bytes);
140 void *dest,
size_t len_bytes) {
141 if (otbn == NULL || dest == NULL ||
142 !check_offset_len(offset_bytes, len_bytes, OTBN_IMEM_SIZE_BYTES)) {
147 otbn->
base_addr, OTBN_IMEM_REG_OFFSET + offset_bytes, dest, len_bytes);
153 const void *src,
size_t len_bytes) {
154 if (otbn == NULL || src == NULL ||
155 !check_offset_len(offset_bytes, len_bytes, OTBN_DMEM_SIZE_BYTES)) {
160 otbn->
base_addr, OTBN_DMEM_REG_OFFSET + offset_bytes, src, len_bytes);
166 void *dest,
size_t len_bytes) {
167 if (otbn == NULL || dest == NULL ||
168 !check_offset_len(offset_bytes, len_bytes, OTBN_DMEM_SIZE_BYTES)) {
173 otbn->
base_addr, OTBN_DMEM_REG_OFFSET + offset_bytes, dest, len_bytes);
193 mmio_region_write32(otbn->
base_addr, OTBN_CTRL_REG_OFFSET, new_ctrl);
194 if (mmio_region_read32(otbn->
base_addr, OTBN_CTRL_REG_OFFSET) != new_ctrl) {
202 return OTBN_DMEM_SIZE_BYTES;
206 return OTBN_IMEM_SIZE_BYTES;