blob: c81b714e0a969d6deea0f745051057f046438a9f [file] [log] [blame]
// Copyright 2022 Google LLC.
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0
#include "sw/device/lib/dif/dif_dma.h"
#include <stddef.h>
#include "dma_regs.h" // Generated.
#include "sw/device/lib/base/bitfield.h"
#include "sw/device/lib/base/macros.h"
#include "sw/device/lib/dif/dif_base.h"
dif_result_t dif_dma_read_config(const dif_dma_t *dma, uint32_t *config) {
if (dma == NULL) {
return kDifBadArg;
}
*config = mmio_region_read32(dma->base_addr, DMA_CONFIG_INFO_REG_OFFSET);
return kDifOk;
}
dif_result_t dif_dma_enable_loop(const dif_dma_t *dma) {
if (dma == NULL) {
return kDifBadArg;
}
uint32_t reg = mmio_region_read32(dma->base_addr, DMA_CTRL_REG_OFFSET);
mmio_region_write32(
dma->base_addr, DMA_CTRL_REG_OFFSET,
reg | 1 << DMA_CTRL_WTR_LOOP_BIT | 1 << DMA_CTRL_RDR_LOOP_BIT);
return kDifOk;
}
dif_result_t dif_dma_begin(const dif_dma_t *dma) {
if (dma == NULL) {
return kDifBadArg;
}
uint32_t reg = mmio_region_read32(dma->base_addr, DMA_CTRL_REG_OFFSET);
mmio_region_write32(
dma->base_addr, DMA_CTRL_REG_OFFSET,
reg | 1 << DMA_CTRL_WTR_START_BIT | 1 << DMA_CTRL_RDR_START_BIT |
1 << DMA_CTRL_WTR_SYNC_DIS_BIT | 1 << DMA_CTRL_RDR_SYNC_DIS_BIT);
return kDifOk;
}
dif_result_t dif_dma_configure_reader(const dif_dma_t *dma, uint32_t start_addr,
uint32_t line_length, uint32_t line_count,
uint32_t line_stride) {
if (dma == NULL) {
return kDifBadArg;
}
mmio_region_write32(dma->base_addr, DMA_RDR_START_ADDR_REG_OFFSET,
start_addr);
mmio_region_write32(dma->base_addr, DMA_RDR_LENGTH_REG_OFFSET, line_length);
mmio_region_write32(dma->base_addr, DMA_RDR_LINE_CNT_REG_OFFSET, line_count);
mmio_region_write32(dma->base_addr, DMA_RDR_STRIDE_REG_OFFSET, line_stride);
return kDifOk;
}
dif_result_t dif_dma_configure_writer(const dif_dma_t *dma, uint32_t start_addr,
uint32_t line_length, uint32_t line_count,
uint32_t line_stride) {
if (dma == NULL) {
return kDifBadArg;
}
mmio_region_write32(dma->base_addr, DMA_WTR_START_ADDR_REG_OFFSET,
start_addr);
mmio_region_write32(dma->base_addr, DMA_WTR_LENGTH_REG_OFFSET, line_length);
mmio_region_write32(dma->base_addr, DMA_WTR_LINE_CNT_REG_OFFSET, line_count);
mmio_region_write32(dma->base_addr, DMA_WTR_STRIDE_REG_OFFSET, line_stride);
return kDifOk;
}