13 static_assert(kDifDmaOpentitanInternalBus ==
14 DMA_ADDR_SPACE_ID_DST_ASID_VALUE_OT_ADDR,
15 "Address Space ID mismatches with value defined in HW");
16 static_assert(kDifDmaSoCControlRegisterBus ==
17 DMA_ADDR_SPACE_ID_DST_ASID_VALUE_SOC_ADDR,
18 "Address Space ID mismatches with value defined in HW");
19 static_assert(kDifDmaSoCSystemBus == DMA_ADDR_SPACE_ID_DST_ASID_VALUE_SYS_ADDR_,
20 "Address Space ID mismatches with value defined in HW");
28 mmio_region_write32(dma->
base_addr, DMA_SRC_ADDR_LO_REG_OFFSET,
29 transaction.source.address & UINT32_MAX);
30 mmio_region_write32(dma->
base_addr, DMA_SRC_ADDR_HI_REG_OFFSET,
31 transaction.source.address >> (
sizeof(uint32_t) * 8));
33 mmio_region_write32(dma->
base_addr, DMA_DST_ADDR_LO_REG_OFFSET,
34 transaction.destination.address & UINT32_MAX);
36 dma->
base_addr, DMA_DST_ADDR_HI_REG_OFFSET,
37 transaction.destination.address >> (
sizeof(uint32_t) * 8));
41 transaction.source.asid);
43 transaction.destination.asid);
44 mmio_region_write32(dma->
base_addr, DMA_ADDR_SPACE_ID_REG_OFFSET, reg);
46 mmio_region_write32(dma->
base_addr, DMA_CHUNK_DATA_SIZE_REG_OFFSET,
47 transaction.chunk_size);
48 mmio_region_write32(dma->
base_addr, DMA_TOTAL_DATA_SIZE_REG_OFFSET,
49 transaction.total_size);
50 mmio_region_write32(dma->
base_addr, DMA_TRANSFER_WIDTH_REG_OFFSET,
62 uint32_t reg = mmio_region_read32(dma->
base_addr, DMA_CONTROL_REG_OFFSET);
66 handshake.fifo_auto_increment);
68 reg, DMA_CONTROL_MEMORY_BUFFER_AUTO_INCREMENT_ENABLE_BIT,
69 handshake.memory_auto_increment);
71 handshake.direction_from_mem_to_fifo);
72 mmio_region_write32(dma->
base_addr, DMA_CONTROL_REG_OFFSET, reg);
81 uint32_t reg = mmio_region_read32(dma->
base_addr, DMA_CONTROL_REG_OFFSET);
84 mmio_region_write32(dma->
base_addr, DMA_CONTROL_REG_OFFSET, reg);
89 dif_dma_transaction_opcode_t opcode) {
94 uint32_t reg = mmio_region_read32(dma->
base_addr, DMA_CONTROL_REG_OFFSET);
98 mmio_region_write32(dma->
base_addr, DMA_CONTROL_REG_OFFSET, reg);
107 uint32_t reg = mmio_region_read32(dma->
base_addr, DMA_CONTROL_REG_OFFSET);
109 mmio_region_write32(dma->
base_addr, DMA_CONTROL_REG_OFFSET, reg);
115 if (dma == NULL || size == 0) {
119 mmio_region_write32(dma->
base_addr, DMA_ENABLED_MEMORY_RANGE_BASE_REG_OFFSET,
122 uint32_t end_addr = address + size - 1;
123 mmio_region_write32(dma->
base_addr, DMA_ENABLED_MEMORY_RANGE_LIMIT_REG_OFFSET,
126 mmio_region_write32(dma->
base_addr, DMA_RANGE_VALID_REG_OFFSET, 1);
133 if (dma == NULL || size == NULL || address == NULL) {
137 *address = mmio_region_read32(dma->
base_addr,
138 DMA_ENABLED_MEMORY_RANGE_BASE_REG_OFFSET);
141 *size = mmio_region_read32(dma->
base_addr,
142 DMA_ENABLED_MEMORY_RANGE_LIMIT_REG_OFFSET) -
153 mmio_region_write32(dma->
base_addr, DMA_RANGE_REGWEN_REG_OFFSET,
154 kMultiBitBool4False);
160 if (dma == NULL || is_locked == NULL) {
164 *is_locked = kMultiBitBool4False ==
165 mmio_region_read32(dma->
base_addr, DMA_RANGE_REGWEN_REG_OFFSET);
171 if (dma == NULL || is_valid == NULL) {
175 *is_valid = mmio_region_read32(dma->
base_addr, DMA_RANGE_VALID_REG_OFFSET);
181 if (dma == NULL ||
status == NULL) {
201 kDifDmaStatusError | kDifDmaStatusError);
205 dif_dma_status_code_t flag) {
213 if (
status & kDifDmaStatusError) {
221 dif_dma_error_code_t *error) {
222 if (dma == NULL || error == NULL) {
225 *error = mmio_region_read32(dma->
base_addr, DMA_ERROR_CODE_REG_OFFSET);
231 uint32_t *digest_len) {
232 if (digest_len == NULL) {
236 case kDifDmaSha256Opcode:
239 case kDifDmaSha384Opcode:
242 case kDifDmaSha512Opcode:
253 dif_dma_transaction_opcode_t opcode,
255 if (dma == NULL || digest == NULL) {
262 for (
int i = 0; i < digest_len; ++i) {
263 ptrdiff_t offset = DMA_SHA2_DIGEST_0_REG_OFFSET +
264 (ptrdiff_t)i * (ptrdiff_t)
sizeof(uint32_t);
266 digest[i] = mmio_region_read32(dma->
base_addr, offset);
272 uint32_t enable_state) {
276 mmio_region_write32(dma->
base_addr, DMA_HANDSHAKE_INTR_ENABLE_REG_OFFSET,
282 uint32_t clear_state) {
286 mmio_region_write32(dma->
base_addr, DMA_CLEAR_INTR_SRC_REG_OFFSET,
293 uint32_t clear_irq_bus) {
297 mmio_region_write32(dma->
base_addr, DMA_CLEAR_INTR_BUS_REG_OFFSET,
304 uint32_t intr_src_addr) {
309 DMA_INTR_SRC_ADDR_0_REG_OFFSET + (ptrdiff_t)idx,
316 uint32_t intr_src_value) {
321 DMA_INTR_SRC_WR_VAL_0_REG_OFFSET + (ptrdiff_t)idx,