Skip to content

Commit b443a23

Browse files
committed
[NUC472/M487] Add memory barrier for DMA transfer in AES/DES alter.
1 parent c906790 commit b443a23

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

features/mbedtls/targets/TARGET_NUVOTON/TARGET_M480/aes/aes_alt.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,14 @@ static void __nvt_aes_crypt( mbedtls_aes_context *ctx,
177177
AES_SetDMATransfer(0, (uint32_t)pIn, (uint32_t)pOut, dataSize);
178178

179179
g_AES_done = 0;
180+
/* Ensure memory accesses above are completed before DMA is started
181+
*
182+
* Replacing __DSB() with __DMB() is also OK in this case.
183+
*
184+
* Refer to "multi-master systems" section with DMA in:
185+
* https://static.docs.arm.com/dai0321/a/DAI0321A_programming_guide_memory_barriers_for_m_profile.pdf
186+
*/
187+
__DSB();
180188
AES_Start(0, CRYPTO_DMA_ONE_SHOT);
181189
while (!g_AES_done);
182190

features/mbedtls/targets/TARGET_NUVOTON/TARGET_M480/des/des_alt.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,14 @@ static int mbedtls_des_docrypt(uint16_t keyopt, uint8_t key[3][MBEDTLS_DES_KEY_S
407407

408408
TDES_SetDMATransfer(0, (uint32_t) dmabuf_in, (uint32_t) dmabuf_out, data_len);
409409

410+
/* Ensure memory accesses above are completed before DMA is started
411+
*
412+
* Replacing __DSB() with __DMB() is also OK in this case.
413+
*
414+
* Refer to "multi-master systems" section with DMA in:
415+
* https://static.docs.arm.com/dai0321/a/DAI0321A_programming_guide_memory_barriers_for_m_profile.pdf
416+
*/
417+
__DSB();
410418
/* Start enc/dec */
411419
TDES_Start(0, CRYPTO_DMA_ONE_SHOT);
412420
while (CRPT->TDES_STS & CRPT_TDES_STS_BUSY_Msk);

features/mbedtls/targets/TARGET_NUVOTON/TARGET_NUC472/aes/aes_alt.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,14 @@ static void __nvt_aes_crypt( mbedtls_aes_context *ctx,
177177
AES_SetDMATransfer(0, (uint32_t)pIn, (uint32_t)pOut, dataSize);
178178

179179
g_AES_done = 0;
180+
/* Ensure memory accesses above are completed before DMA is started
181+
*
182+
* Replacing __DSB() with __DMB() is also OK in this case.
183+
*
184+
* Refer to "multi-master systems" section with DMA in:
185+
* https://static.docs.arm.com/dai0321/a/DAI0321A_programming_guide_memory_barriers_for_m_profile.pdf
186+
*/
187+
__DSB();
180188
AES_Start(0, CRYPTO_DMA_ONE_SHOT);
181189
while (!g_AES_done);
182190

features/mbedtls/targets/TARGET_NUVOTON/TARGET_NUC472/des/des_alt.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,14 @@ static int mbedtls_des_docrypt(uint16_t keyopt, uint8_t key[3][MBEDTLS_DES_KEY_S
407407

408408
TDES_SetDMATransfer(0, (uint32_t) dmabuf_in, (uint32_t) dmabuf_out, data_len);
409409

410+
/* Ensure memory accesses above are completed before DMA is started
411+
*
412+
* Replacing __DSB() with __DMB() is also OK in this case.
413+
*
414+
* Refer to "multi-master systems" section with DMA in:
415+
* https://static.docs.arm.com/dai0321/a/DAI0321A_programming_guide_memory_barriers_for_m_profile.pdf
416+
*/
417+
__DSB();
410418
/* Start enc/dec */
411419
TDES_Start(0, CRYPTO_DMA_ONE_SHOT);
412420
while (CRPT->TDES_STS & CRPT_TDES_STS_BUSY_Msk);

0 commit comments

Comments
 (0)