Skip to content

Commit

Permalink
cracen: Basic thread-safety
Browse files Browse the repository at this point in the history
Makes cracen driver entry points callable from multiple threads.

Signed-off-by: Vidar Lillebø <[email protected]>
  • Loading branch information
vili-nordic authored and rlubos committed Apr 25, 2024
1 parent ff1bbbe commit 22a843a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "../../cmdma.h"
#include <security/cracen.h>
#include <cracen/statuscodes.h>
#include <zephyr/kernel.h>

/* Enable interrupts showing that an operation finished or aborted.
* For that, we're interested in :
Expand All @@ -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. */
Expand All @@ -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;
}
}

0 comments on commit 22a843a

Please sign in to comment.