1 // Copyright 2021 Espressif Systems (Shanghai) PTE LTD
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #pragma once
16 
17 #include "soc/lldesc.h"
18 #include "esp_private/gdma.h"
19 #include "esp_err.h"
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 /**
26  * @brief Start a GDMA transfer on the shared crypto DMA channel
27  *
28  * @note Will allocate a GDMA channel for AES & SHA if no such channel is already allocated
29  *
30  * @param input Input linked list descriptor
31  * @param output Output linked list descriptor
32  * @param peripheral Crypto peripheral to connect the DMA to, either GDMA_TRIG_PERIPH_AES or
33  *                   GDMA_TRIG_PERIPH_SHA
34  * @return esp_err_t ESP_FAIL if no GDMA channel available
35  */
36 esp_err_t esp_crypto_shared_gdma_start(const lldesc_t *input, const lldesc_t *output, gdma_trigger_peripheral_t peripheral);
37 
38 
39 /**
40  * @brief Frees any shared crypto DMA channel, if esp_crypto_shared_gdma_start is called after
41  *        this, new GDMA channels will be allocated.
42  *
43  * @note Function is meant to be called from user code, and thus takes AES/SHA lock.
44  *       This means this function should not be called from code which already takes these locks,
45  *       i.e. inside our AES/SHA code.
46  *
47  *       If you are continously using AES/SHA (e.g. because of a wifi connection) then it's not recommended
48  *       to use this API. Freeing the channel is mainly for use cases where you are finished with the crypto peripherals
49  *       and need the DMA channel for other peripherals. An example would be doing some processing after disconnecting WiFi
50  */
51 void esp_crypto_shared_gdma_free(void);
52 
53 #ifdef __cplusplus
54 }
55 #endif
56