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");
29 mmio_region_write32(dma->base_addr, DMA_SRC_ADDR_LO_REG_OFFSET,
30 transaction.source.address & UINT32_MAX);
31 mmio_region_write32(dma->base_addr, DMA_SRC_ADDR_HI_REG_OFFSET,
32 transaction.source.address >> (
sizeof(uint32_t) * 8));
35 mmio_region_write32(dma->base_addr, DMA_DST_ADDR_LO_REG_OFFSET,
36 transaction.destination.address & UINT32_MAX);
38 dma->base_addr, DMA_DST_ADDR_HI_REG_OFFSET,
39 transaction.destination.address >> (
sizeof(uint32_t) * 8));
44 transaction.src_config.wrap);
46 transaction.src_config.increment);
47 mmio_region_write32(dma->base_addr, DMA_SRC_CONFIG_REG_OFFSET, reg);
52 transaction.dst_config.wrap);
54 transaction.dst_config.increment);
55 mmio_region_write32(dma->base_addr, DMA_DST_CONFIG_REG_OFFSET, reg);
60 transaction.source.asid);
62 transaction.destination.asid);
63 mmio_region_write32(dma->base_addr, DMA_ADDR_SPACE_ID_REG_OFFSET, reg);
66 mmio_region_write32(dma->base_addr, DMA_CHUNK_DATA_SIZE_REG_OFFSET,
67 transaction.chunk_size);
68 mmio_region_write32(dma->base_addr, DMA_TOTAL_DATA_SIZE_REG_OFFSET,
69 transaction.total_size);
70 mmio_region_write32(dma->base_addr, DMA_TRANSFER_WIDTH_REG_OFFSET,
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);
93 uint32_t reg = mmio_region_read32(dma->base_addr, DMA_CONTROL_REG_OFFSET);
96 mmio_region_write32(dma->base_addr, DMA_CONTROL_REG_OFFSET, reg);
101 dif_dma_transaction_opcode_t opcode) {
106 uint32_t reg = mmio_region_read32(dma->base_addr, DMA_CONTROL_REG_OFFSET);
110 mmio_region_write32(dma->base_addr, DMA_CONTROL_REG_OFFSET, reg);
119 uint32_t reg = mmio_region_read32(dma->base_addr, DMA_CONTROL_REG_OFFSET);
121 mmio_region_write32(dma->base_addr, DMA_CONTROL_REG_OFFSET, reg);
127 if (dma == NULL || size == 0) {
131 mmio_region_write32(dma->base_addr, DMA_ENABLED_MEMORY_RANGE_BASE_REG_OFFSET,
134 uint32_t end_addr = address + size - 1;
135 mmio_region_write32(dma->base_addr, DMA_ENABLED_MEMORY_RANGE_LIMIT_REG_OFFSET,
138 mmio_region_write32(dma->base_addr, DMA_RANGE_VALID_REG_OFFSET, 1);
145 if (dma == NULL || size == NULL || address == NULL) {
149 *address = mmio_region_read32(dma->base_addr,
150 DMA_ENABLED_MEMORY_RANGE_BASE_REG_OFFSET);
153 *size = mmio_region_read32(dma->base_addr,
154 DMA_ENABLED_MEMORY_RANGE_LIMIT_REG_OFFSET) -
165 mmio_region_write32(dma->base_addr, DMA_RANGE_REGWEN_REG_OFFSET,
166 kMultiBitBool4False);
172 if (dma == NULL || is_locked == NULL) {
176 *is_locked = kMultiBitBool4False ==
177 mmio_region_read32(dma->base_addr, DMA_RANGE_REGWEN_REG_OFFSET);
183 if (dma == NULL || is_valid == NULL) {
187 *is_valid = mmio_region_read32(dma->base_addr, DMA_RANGE_VALID_REG_OFFSET);
193 if (dma == NULL ||
status == NULL) {
196 *
status = mmio_region_read32(dma->base_addr, DMA_STATUS_REG_OFFSET);
206 mmio_region_write32(dma->base_addr, DMA_STATUS_REG_OFFSET,
status);
213 kDifDmaStatusError | kDifDmaStatusError);
217 dif_dma_status_code_t flag) {
225 if (
status & kDifDmaStatusError) {
233 dif_dma_error_code_t *error) {
234 if (dma == NULL || error == NULL) {
237 *error = mmio_region_read32(dma->base_addr, DMA_ERROR_CODE_REG_OFFSET);
243 uint32_t *digest_len) {
244 if (digest_len == NULL) {
248 case kDifDmaSha256Opcode:
251 case kDifDmaSha384Opcode:
254 case kDifDmaSha512Opcode:
265 dif_dma_transaction_opcode_t opcode,
267 if (dma == NULL || digest == NULL) {
274 for (
int i = 0; i < digest_len; ++i) {
275 ptrdiff_t offset = DMA_SHA2_DIGEST_0_REG_OFFSET +
276 (ptrdiff_t)i * (ptrdiff_t)
sizeof(uint32_t);
278 digest[i] = mmio_region_read32(dma->base_addr, offset);
284 uint32_t enable_state) {
288 mmio_region_write32(dma->base_addr, DMA_HANDSHAKE_INTR_ENABLE_REG_OFFSET,
294 uint32_t clear_state) {
298 mmio_region_write32(dma->base_addr, DMA_CLEAR_INTR_SRC_REG_OFFSET,
305 uint32_t clear_irq_bus) {
309 mmio_region_write32(dma->base_addr, DMA_CLEAR_INTR_BUS_REG_OFFSET,
316 uint32_t intr_src_addr) {
320 mmio_region_write32(dma->base_addr,
321 DMA_INTR_SRC_ADDR_0_REG_OFFSET + (ptrdiff_t)idx,
328 uint32_t intr_src_value) {
332 mmio_region_write32(dma->base_addr,
333 DMA_INTR_SRC_WR_VAL_0_REG_OFFSET + (ptrdiff_t)idx,