Skip to content

Commit 7083ea7

Browse files
committed
CC3XX: DMA: Remap both addresses just before triggering DMA
So that both DIN and DOUT addresses are remapped in the same function making it easier to follow DMA operations Signed-off-by: Antonio de Angelis <antonio.deangelis@arm.com> Change-Id: Iad6f1d31f952c46a5d8c214cf8b5b5ad1f7bb9ed
1 parent 4989e29 commit 7083ea7

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

platform/ext/target/arm/drivers/cc3xx/low_level_driver/include/cc3xx_dma.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,19 @@ void cc3xx_lowlevel_dma_copy_data_from_rng_sram(void* dest,
152152
* cc3xx_dma_flush_buffer must be called to ensure all data
153153
* is processed.
154154
*
155+
* @note The \p buf pointer can be remapped to a different address
156+
* before being programmed on the DMA engine in case the system
157+
* memory map exports different interfaces to the same memory
158+
* location, in case of the CPU and the DMA engine respectively
159+
*
155160
* @param[in] buf The pointer to copy data from.
156161
* @param[in] length The size of the data.
157162
* @param[in] write_output Whether the data should be output from the engine.
158163
*
159164
* @return CC3XX_ERR_SUCCESS on success, another cc3xx_err_t on
160165
* error.
161166
*/
162-
cc3xx_err_t cc3xx_lowlevel_dma_buffered_input_data(const void* buf, size_t length,
167+
cc3xx_err_t cc3xx_lowlevel_dma_buffered_input_data(const void *buf, size_t length,
163168
bool write_output);
164169

165170
/**
@@ -186,11 +191,16 @@ void cc3xx_lowlevel_dma_set_buffer_size(size_t size);
186191
* @brief Set the DMA output location. This controls where the
187192
* DMA will output to after input is started.
188193
*
194+
* @note The \p buf pointer can be remapped to a different address
195+
* before being programmed on the DMA engine in case the system
196+
* memory map exports different interfaces to the same memory
197+
* location, in case of the CPU and the DMA engine respectively
198+
*
189199
* @param[out] buf The pointer to output to.
190200
* @param[in] length The size of the output location. The DMA will not copy
191201
* more data than this to the pointer.
192202
*/
193-
void cc3xx_lowlevel_dma_set_output(void* buf, size_t length);
203+
void cc3xx_lowlevel_dma_set_output(void *buf, size_t length);
194204

195205
/**
196206
* @brief Uninitialize the DMA.

platform/ext/target/arm/drivers/cc3xx/low_level_driver/src/cc3xx_dma.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -160,20 +160,20 @@ static void process_data(const void *buf, size_t length)
160160
P_CC3XX->host_rgf.host_rgf_icr |= 0xFF0U;
161161

162162
if (dma_state.block_buf_needs_output) {
163-
uintptr_t output_addr = dma_state.output_addr;
163+
const uintptr_t remap_output_addr = remap_addr(dma_state.output_addr);
164164
#ifdef CC3XX_CONFIG_DMA_BURST_RESTRICTED_ENABLE
165165
/* Force single transactions for restricted addresses */
166-
if (is_addr_burst_restricted(output_addr)) {
166+
if (is_addr_burst_restricted(remap_output_addr)) {
167167
P_CC3XX->ahb.ahbm_singles = 0x1UL;
168168
} else {
169169
P_CC3XX->ahb.ahbm_singles = 0x0UL;
170170
}
171171
#endif /* CC3XX_CONFIG_DMA_BURST_RESTRICTED_ENABLE */
172172

173-
assert(!((output_addr == NULL) && (length != 0)));
173+
assert(!((remap_output_addr == (uintptr_t)NULL) && (length != 0)));
174174

175175
/* Set the data target */
176-
P_CC3XX->dout.dst_lli_word0 = output_addr;
176+
P_CC3XX->dout.dst_lli_word0 = remap_output_addr;
177177
/* And the length */
178178
P_CC3XX->dout.dst_lli_word1 = length;
179179

@@ -185,7 +185,7 @@ static void process_data(const void *buf, size_t length)
185185
* set up an MPU covering the input and output regions so they can be
186186
* marked as SHAREABLE (which is not currently implemented).
187187
*/
188-
SCB_CleanInvalidateDCache_by_Addr((volatile void *)output_addr, length);
188+
SCB_CleanInvalidateDCache_by_Addr((volatile void *)remap_output_addr, length);
189189
#endif /* CC3XX_CONFIG_DMA_CACHE_FLUSH_ENABLE */
190190

191191
dma_state.output_addr += length;
@@ -194,7 +194,7 @@ static void process_data(const void *buf, size_t length)
194194

195195
if (dma_state.input_src == CC3XX_DMA_INPUT_SRC_CPU_MEM) {
196196
/* remap the address, particularly for TCMs */
197-
const uintptr_t remapped_buf = remap_addr((uintptr_t)buf);
197+
const uintptr_t remapped_buf = remap_addr((uintptr_t)buf);
198198
#ifdef CC3XX_CONFIG_DMA_CACHE_FLUSH_ENABLE
199199
/* Flush the input data. Note that this is only enough to avoid cache
200200
* issues if the CPU is in a busy-wait loop while the access completes.
@@ -351,10 +351,9 @@ void cc3xx_lowlevel_dma_set_buffer_size(size_t size) {
351351
assert(size <= CC3XX_DMA_BLOCK_BUF_MAX_SIZE);
352352
}
353353

354-
void cc3xx_lowlevel_dma_set_output(void* buf, size_t length)
354+
void cc3xx_lowlevel_dma_set_output(void *buf, size_t length)
355355
{
356-
/* remap the address, particularly for TCMs */
357-
dma_state.output_addr = remap_addr((uintptr_t)buf);
356+
dma_state.output_addr = (uintptr_t)buf;
358357
dma_state.output_size = length;
359358
}
360359

0 commit comments

Comments
 (0)