From 22a843aa9294c3bd7dfe511a7f7d4df547f5728c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vidar=20Lilleb=C3=B8?= Date: Tue, 23 Apr 2024 13:42:57 +0200 Subject: [PATCH] cracen: Basic thread-safety MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Makes cracen driver entry points callable from multiple threads. Signed-off-by: Vidar Lillebø --- .../silexpk/target/baremetal_ba414e_with_ik/pk_baremetal.c | 4 ++++ .../cracen/sxsymcrypt/src/platform/baremetal/cmdma_hw.c | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/subsys/nrf_security/src/drivers/cracen/silexpk/target/baremetal_ba414e_with_ik/pk_baremetal.c b/subsys/nrf_security/src/drivers/cracen/silexpk/target/baremetal_ba414e_with_ik/pk_baremetal.c index 992830d7b54c..e09c49e6b209 100644 --- a/subsys/nrf_security/src/drivers/cracen/silexpk/target/baremetal_ba414e_with_ik/pk_baremetal.c +++ b/subsys/nrf_security/src/drivers/cracen/silexpk/target/baremetal_ba414e_with_ik/pk_baremetal.c @@ -51,6 +51,8 @@ struct sx_pk_cnx { struct sx_pk_cnx silex_pk_engine; +K_MUTEX_DEFINE(cracen_mutex_asymmetric); + bool ba414ep_is_busy(sx_pk_req *req) { return (bool)(sx_pk_rdreg(&req->regs, PK_REG_STATUS) & PK_BUSY_MASK_BA414EP); @@ -178,6 +180,7 @@ struct sx_pk_acq_req sx_pk_acquire_req(const struct sx_pk_cmd_def *cmd) { struct sx_pk_acq_req req = {NULL, SX_OK}; + k_mutex_lock(&cracen_mutex_asymmetric, K_FOREVER); req.req = &silex_pk_engine.instance; req.req->cmd = cmd; req.req->cnx = &silex_pk_engine; @@ -214,6 +217,7 @@ void sx_pk_release_req(sx_pk_req *req) cracen_release(); req->cmd = NULL; req->userctxt = NULL; + k_mutex_unlock(&cracen_mutex_asymmetric); } struct sx_regs *sx_pk_get_regs(void) diff --git a/subsys/nrf_security/src/drivers/cracen/sxsymcrypt/src/platform/baremetal/cmdma_hw.c b/subsys/nrf_security/src/drivers/cracen/sxsymcrypt/src/platform/baremetal/cmdma_hw.c index e841f57baf60..7f28e4cc9b9e 100644 --- a/subsys/nrf_security/src/drivers/cracen/sxsymcrypt/src/platform/baremetal/cmdma_hw.c +++ b/subsys/nrf_security/src/drivers/cracen/sxsymcrypt/src/platform/baremetal/cmdma_hw.c @@ -11,6 +11,7 @@ #include "../../cmdma.h" #include #include +#include /* Enable interrupts showing that an operation finished or aborted. * For that, we're interested in : @@ -21,9 +22,12 @@ */ #define CMDMA_INTMASK_EN ((1 << 2) | (1 << 5) | (1 << 4)) +K_MUTEX_DEFINE(cracen_mutex_symmetric); + void sx_hw_reserve(struct sx_dmactl *dma) { cracen_acquire(); + k_mutex_lock(&cracen_mutex_symmetric, K_FOREVER); dma->hw_acquired = true; /* Enable CryptoMaster interrupts. */ @@ -39,6 +43,7 @@ void sx_cmdma_release_hw(struct sx_dmactl *dma) { if (dma->hw_acquired) { cracen_release(); + k_mutex_unlock(&cracen_mutex_symmetric); dma->hw_acquired = false; } }