1 /*
2  * Copyright (c) 2021-2023, The TrustedFirmware-M Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #include "cc3xx_engine_state.h"
9 #include "cc3xx_dev.h"
10 
11 enum cc3xx_engine_t cc3xx_engine_in_use = CC3XX_ENGINE_NONE;
12 
cc3xx_lowlevel_set_engine(enum cc3xx_engine_t engine)13 void cc3xx_lowlevel_set_engine(enum cc3xx_engine_t engine)
14 {
15     /* Wait for the crypto engine to be ready */
16     while (P_CC3XX->cc_ctl.crypto_busy) {}
17 
18     /* Set the crypto engine to the requested engine */
19     P_CC3XX->cc_ctl.crypto_ctl = engine;
20 
21     /* crypto_ctl is WO, so mirror the state */
22     cc3xx_engine_in_use = engine;
23 
24     /* Wait for the crypto engine to be ready */
25     while (P_CC3XX->cc_ctl.crypto_busy) {}
26 }
27