forked from espressif/esp-idf
feat(ds): use RCC atomic block to enable/reset the DS peripheral
This commit is contained in:
@@ -266,7 +266,11 @@ static void ds_acquire_enable(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
periph_module_enable(PERIPH_SHA_MODULE);
|
periph_module_enable(PERIPH_SHA_MODULE);
|
||||||
periph_module_enable(PERIPH_DS_MODULE);
|
|
||||||
|
DS_RCC_ATOMIC() {
|
||||||
|
ds_ll_enable_bus_clock(true);
|
||||||
|
ds_ll_reset_register();
|
||||||
|
}
|
||||||
|
|
||||||
hmac_hal_start();
|
hmac_hal_start();
|
||||||
}
|
}
|
||||||
@@ -275,7 +279,10 @@ static void ds_disable_release(void)
|
|||||||
{
|
{
|
||||||
ds_hal_finish();
|
ds_hal_finish();
|
||||||
|
|
||||||
periph_module_disable(PERIPH_DS_MODULE);
|
DS_RCC_ATOMIC() {
|
||||||
|
ds_ll_enable_bus_clock(false);
|
||||||
|
}
|
||||||
|
|
||||||
periph_module_disable(PERIPH_SHA_MODULE);
|
periph_module_disable(PERIPH_SHA_MODULE);
|
||||||
|
|
||||||
HMAC_RCC_ATOMIC() {
|
HMAC_RCC_ATOMIC() {
|
||||||
|
@@ -18,6 +18,7 @@
|
|||||||
#include "soc/system_reg.h"
|
#include "soc/system_reg.h"
|
||||||
|
|
||||||
#if !CONFIG_IDF_TARGET_ESP32S2
|
#if !CONFIG_IDF_TARGET_ESP32S2
|
||||||
|
#include "hal/ds_ll.h"
|
||||||
#include "hal/hmac_hal.h"
|
#include "hal/hmac_hal.h"
|
||||||
#include "hal/hmac_ll.h"
|
#include "hal/hmac_ll.h"
|
||||||
#include "esp_private/periph_ctrl.h"
|
#include "esp_private/periph_ctrl.h"
|
||||||
@@ -75,7 +76,11 @@ esp_err_t esp_hmac_calculate(hmac_key_id_t key_id,
|
|||||||
}
|
}
|
||||||
|
|
||||||
periph_module_enable(PERIPH_SHA_MODULE);
|
periph_module_enable(PERIPH_SHA_MODULE);
|
||||||
periph_module_enable(PERIPH_DS_MODULE);
|
|
||||||
|
DS_RCC_ATOMIC() {
|
||||||
|
ds_ll_enable_bus_clock(true);
|
||||||
|
ds_ll_reset_register();
|
||||||
|
}
|
||||||
|
|
||||||
hmac_hal_start();
|
hmac_hal_start();
|
||||||
|
|
||||||
@@ -137,7 +142,10 @@ esp_err_t esp_hmac_calculate(hmac_key_id_t key_id,
|
|||||||
// Read back result (bit swapped)
|
// Read back result (bit swapped)
|
||||||
hmac_hal_read_result_256(hmac);
|
hmac_hal_read_result_256(hmac);
|
||||||
|
|
||||||
periph_module_disable(PERIPH_DS_MODULE);
|
DS_RCC_ATOMIC() {
|
||||||
|
ds_ll_enable_bus_clock(false);
|
||||||
|
}
|
||||||
|
|
||||||
periph_module_disable(PERIPH_SHA_MODULE);
|
periph_module_disable(PERIPH_SHA_MODULE);
|
||||||
|
|
||||||
HMAC_RCC_ATOMIC() {
|
HMAC_RCC_ATOMIC() {
|
||||||
|
@@ -17,10 +17,12 @@ extern "C" {
|
|||||||
#define MPI_RCC_ATOMIC()
|
#define MPI_RCC_ATOMIC()
|
||||||
#define ECC_RCC_ATOMIC()
|
#define ECC_RCC_ATOMIC()
|
||||||
#define HMAC_RCC_ATOMIC()
|
#define HMAC_RCC_ATOMIC()
|
||||||
|
#define DS_RCC_ATOMIC()
|
||||||
#else /* !SOC_RCC_IS_INDEPENDENT */
|
#else /* !SOC_RCC_IS_INDEPENDENT */
|
||||||
#define MPI_RCC_ATOMIC() PERIPH_RCC_ATOMIC()
|
#define MPI_RCC_ATOMIC() PERIPH_RCC_ATOMIC()
|
||||||
#define ECC_RCC_ATOMIC() PERIPH_RCC_ATOMIC()
|
#define ECC_RCC_ATOMIC() PERIPH_RCC_ATOMIC()
|
||||||
#define HMAC_RCC_ATOMIC() PERIPH_RCC_ATOMIC()
|
#define HMAC_RCC_ATOMIC() PERIPH_RCC_ATOMIC()
|
||||||
|
#define DS_RCC_ATOMIC() PERIPH_RCC_ATOMIC()
|
||||||
#endif /* SOC_RCC_IS_INDEPENDENT */
|
#endif /* SOC_RCC_IS_INDEPENDENT */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@@ -17,12 +17,40 @@
|
|||||||
|
|
||||||
#include "soc/hwcrypto_reg.h"
|
#include "soc/hwcrypto_reg.h"
|
||||||
#include "soc/soc_caps.h"
|
#include "soc/soc_caps.h"
|
||||||
|
#include "soc/system_struct.h"
|
||||||
#include "hal/ds_types.h"
|
#include "hal/ds_types.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Enable the bus clock for Digital Signature peripheral module
|
||||||
|
*
|
||||||
|
* @param true to enable the module, false to disable the module
|
||||||
|
*/
|
||||||
|
static inline void ds_ll_enable_bus_clock(bool enable)
|
||||||
|
{
|
||||||
|
SYSTEM.perip_clk_en1.reg_crypto_ds_clk_en = enable;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// use a macro to wrap the function, force the caller to use it in a critical section
|
||||||
|
/// the critical section needs to declare the __DECLARE_RCC_ATOMIC_ENV variable in advance
|
||||||
|
#define ds_ll_enable_bus_clock(...) (void)__DECLARE_RCC_ATOMIC_ENV; ds_ll_enable_bus_clock(__VA_ARGS__)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Reset the Digital Signature peripheral module
|
||||||
|
*/
|
||||||
|
static inline void ds_ll_reset_register(void)
|
||||||
|
{
|
||||||
|
SYSTEM.perip_rst_en1.reg_crypto_ds_rst = 1;
|
||||||
|
SYSTEM.perip_rst_en1.reg_crypto_ds_rst = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// use a macro to wrap the function, force the caller to use it in a critical section
|
||||||
|
/// the critical section needs to declare the __DECLARE_RCC_ATOMIC_ENV variable in advance
|
||||||
|
#define ds_ll_reset_register(...) (void)__DECLARE_RCC_ATOMIC_ENV; ds_ll_reset_register(__VA_ARGS__)
|
||||||
|
|
||||||
static inline void ds_ll_start(void)
|
static inline void ds_ll_start(void)
|
||||||
{
|
{
|
||||||
REG_WRITE(DS_SET_START_REG, 1);
|
REG_WRITE(DS_SET_START_REG, 1);
|
||||||
|
@@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
#include "soc/hwcrypto_reg.h"
|
#include "soc/hwcrypto_reg.h"
|
||||||
#include "soc/soc_caps.h"
|
#include "soc/soc_caps.h"
|
||||||
|
#include "soc/pcr_struct.h"
|
||||||
#include "hal/ds_types.h"
|
#include "hal/ds_types.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -24,6 +25,25 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Enable the bus clock for Digital Signature peripheral module
|
||||||
|
*
|
||||||
|
* @param true to enable the module, false to disable the module
|
||||||
|
*/
|
||||||
|
static inline void ds_ll_enable_bus_clock(bool enable)
|
||||||
|
{
|
||||||
|
PCR.ds_conf.ds_clk_en = enable;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Reset the Digital Signature peripheral module
|
||||||
|
*/
|
||||||
|
static inline void ds_ll_reset_register(void)
|
||||||
|
{
|
||||||
|
PCR.ds_conf.ds_rst_en = 1;
|
||||||
|
PCR.ds_conf.ds_rst_en = 0;
|
||||||
|
}
|
||||||
|
|
||||||
static inline void ds_ll_start(void)
|
static inline void ds_ll_start(void)
|
||||||
{
|
{
|
||||||
REG_WRITE(DS_SET_START_REG, 1);
|
REG_WRITE(DS_SET_START_REG, 1);
|
||||||
|
@@ -17,12 +17,32 @@
|
|||||||
|
|
||||||
#include "soc/hwcrypto_reg.h"
|
#include "soc/hwcrypto_reg.h"
|
||||||
#include "soc/soc_caps.h"
|
#include "soc/soc_caps.h"
|
||||||
|
#include "soc/pcr_struct.h"
|
||||||
#include "hal/ds_types.h"
|
#include "hal/ds_types.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Enable the bus clock for Digital Signature peripheral module
|
||||||
|
*
|
||||||
|
* @param true to enable the module, false to disable the module
|
||||||
|
*/
|
||||||
|
static inline void ds_ll_enable_bus_clock(bool enable)
|
||||||
|
{
|
||||||
|
PCR.ds_conf.ds_clk_en = enable;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Reset the Digital Signature peripheral module
|
||||||
|
*/
|
||||||
|
static inline void ds_ll_reset_register(void)
|
||||||
|
{
|
||||||
|
PCR.ds_conf.ds_rst_en = 1;
|
||||||
|
PCR.ds_conf.ds_rst_en = 0;
|
||||||
|
}
|
||||||
|
|
||||||
static inline void ds_ll_start(void)
|
static inline void ds_ll_start(void)
|
||||||
{
|
{
|
||||||
REG_WRITE(DS_SET_START_REG, 1);
|
REG_WRITE(DS_SET_START_REG, 1);
|
||||||
|
@@ -16,6 +16,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "soc/hwcrypto_reg.h"
|
#include "soc/hwcrypto_reg.h"
|
||||||
|
#include "soc/hp_sys_clkrst_struct.h"
|
||||||
#include "soc/soc_caps.h"
|
#include "soc/soc_caps.h"
|
||||||
#include "hal/ds_types.h"
|
#include "hal/ds_types.h"
|
||||||
|
|
||||||
@@ -24,6 +25,35 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Enable the bus clock for DS peripheral module
|
||||||
|
*
|
||||||
|
* @param true to enable the module, false to disable the module
|
||||||
|
*/
|
||||||
|
static inline void ds_ll_enable_bus_clock(bool enable)
|
||||||
|
{
|
||||||
|
HP_SYS_CLKRST.peri_clk_ctrl25.reg_crypto_ds_clk_en = enable;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// use a macro to wrap the function, force the caller to use it in a critical section
|
||||||
|
/// the critical section needs to declare the __DECLARE_RCC_ATOMIC_ENV variable in advance
|
||||||
|
#define ds_ll_enable_bus_clock(...) (void)__DECLARE_RCC_ATOMIC_ENV; ds_ll_enable_bus_clock(__VA_ARGS__)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Reset the DS peripheral module
|
||||||
|
*/
|
||||||
|
static inline void ds_ll_reset_register(void)
|
||||||
|
{
|
||||||
|
HP_SYS_CLKRST.hp_rst_en2.reg_rst_en_ds = 1;
|
||||||
|
HP_SYS_CLKRST.hp_rst_en2.reg_rst_en_ds = 0;
|
||||||
|
HP_SYS_CLKRST.hp_rst_en2.reg_rst_en_crypto = 1;
|
||||||
|
HP_SYS_CLKRST.hp_rst_en2.reg_rst_en_crypto = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// use a macro to wrap the function, force the caller to use it in a critical section
|
||||||
|
/// the critical section needs to declare the __DECLARE_RCC_ATOMIC_ENV variable in advance
|
||||||
|
#define ds_ll_reset_register(...) (void)__DECLARE_RCC_ATOMIC_ENV; ds_ll_reset_register(__VA_ARGS__)
|
||||||
|
|
||||||
static inline void ds_ll_start(void)
|
static inline void ds_ll_start(void)
|
||||||
{
|
{
|
||||||
REG_WRITE(DS_SET_START_REG, 1);
|
REG_WRITE(DS_SET_START_REG, 1);
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2020-2023 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@@ -12,12 +12,40 @@
|
|||||||
|
|
||||||
#include "soc/hwcrypto_reg.h"
|
#include "soc/hwcrypto_reg.h"
|
||||||
#include "soc/soc_caps.h"
|
#include "soc/soc_caps.h"
|
||||||
|
#include "soc/system_struct.h"
|
||||||
#include "hal/ds_types.h"
|
#include "hal/ds_types.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Enable the bus clock for Digital Signature peripheral module
|
||||||
|
*
|
||||||
|
* @param true to enable the module, false to disable the module
|
||||||
|
*/
|
||||||
|
static inline void ds_ll_enable_bus_clock(bool enable)
|
||||||
|
{
|
||||||
|
SYSTEM.perip_clk_en1.crypto_ds_clk_en = enable;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// use a macro to wrap the function, force the caller to use it in a critical section
|
||||||
|
/// the critical section needs to declare the __DECLARE_RCC_ATOMIC_ENV variable in advance
|
||||||
|
#define ds_ll_enable_bus_clock(...) (void)__DECLARE_RCC_ATOMIC_ENV; ds_ll_enable_bus_clock(__VA_ARGS__)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Reset the Digital Signature peripheral module
|
||||||
|
*/
|
||||||
|
static inline void ds_ll_reset_register(void)
|
||||||
|
{
|
||||||
|
SYSTEM.perip_rst_en1.crypto_ds_rst = 1;
|
||||||
|
SYSTEM.perip_rst_en1.crypto_ds_rst = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// use a macro to wrap the function, force the caller to use it in a critical section
|
||||||
|
/// the critical section needs to declare the __DECLARE_RCC_ATOMIC_ENV variable in advance
|
||||||
|
#define ds_ll_reset_register(...) (void)__DECLARE_RCC_ATOMIC_ENV; ds_ll_reset_register(__VA_ARGS__)
|
||||||
|
|
||||||
static inline void ds_ll_start(void)
|
static inline void ds_ll_start(void)
|
||||||
{
|
{
|
||||||
REG_WRITE(DS_SET_START_REG, 1);
|
REG_WRITE(DS_SET_START_REG, 1);
|
||||||
|
@@ -139,20 +139,28 @@ static void ds_acquire_enable(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
periph_module_enable(PERIPH_SHA_MODULE);
|
periph_module_enable(PERIPH_SHA_MODULE);
|
||||||
periph_module_enable(PERIPH_DS_MODULE);
|
|
||||||
|
DS_RCC_ATOMIC() {
|
||||||
|
ds_ll_enable_bus_clock(true);
|
||||||
|
ds_ll_reset_register();
|
||||||
|
}
|
||||||
|
|
||||||
hmac_hal_start();
|
hmac_hal_start();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ds_disable_release(void)
|
static void ds_disable_release(void)
|
||||||
{
|
{
|
||||||
ds_hal_finish();
|
ds_hal_finish();
|
||||||
periph_module_disable(PERIPH_DS_MODULE);
|
|
||||||
|
DS_RCC_ATOMIC() {
|
||||||
|
ds_ll_enable_bus_clock(false);
|
||||||
|
}
|
||||||
|
|
||||||
periph_module_disable(PERIPH_SHA_MODULE);
|
periph_module_disable(PERIPH_SHA_MODULE);
|
||||||
|
|
||||||
HMAC_RCC_ATOMIC() {
|
HMAC_RCC_ATOMIC() {
|
||||||
hmac_ll_enable_bus_clock(false);
|
hmac_ll_enable_bus_clock(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -41,6 +41,7 @@ static esp_err_t hmac_jtag_disable(void)
|
|||||||
|
|
||||||
#include "hal/hmac_hal.h"
|
#include "hal/hmac_hal.h"
|
||||||
#include "hal/hmac_ll.h"
|
#include "hal/hmac_ll.h"
|
||||||
|
#include "hal/ds_ll.h"
|
||||||
#include "esp_private/periph_ctrl.h"
|
#include "esp_private/periph_ctrl.h"
|
||||||
|
|
||||||
#define SHA256_BLOCK_SZ 64
|
#define SHA256_BLOCK_SZ 64
|
||||||
@@ -78,7 +79,11 @@ static esp_err_t hmac_calculate(hmac_key_id_t key_id, const void *message, size_
|
|||||||
}
|
}
|
||||||
|
|
||||||
periph_module_enable(PERIPH_SHA_MODULE);
|
periph_module_enable(PERIPH_SHA_MODULE);
|
||||||
periph_module_enable(PERIPH_DS_MODULE);
|
|
||||||
|
DS_RCC_ATOMIC() {
|
||||||
|
ds_ll_enable_bus_clock(true);
|
||||||
|
ds_ll_reset_register();
|
||||||
|
}
|
||||||
|
|
||||||
hmac_hal_start();
|
hmac_hal_start();
|
||||||
|
|
||||||
@@ -130,7 +135,10 @@ static esp_err_t hmac_calculate(hmac_key_id_t key_id, const void *message, size_
|
|||||||
|
|
||||||
hmac_hal_read_result_256(hmac);
|
hmac_hal_read_result_256(hmac);
|
||||||
|
|
||||||
periph_module_disable(PERIPH_DS_MODULE);
|
DS_RCC_ATOMIC() {
|
||||||
|
ds_ll_enable_bus_clock(false);
|
||||||
|
}
|
||||||
|
|
||||||
periph_module_disable(PERIPH_SHA_MODULE);
|
periph_module_disable(PERIPH_SHA_MODULE);
|
||||||
|
|
||||||
HMAC_RCC_ATOMIC() {
|
HMAC_RCC_ATOMIC() {
|
||||||
|
Reference in New Issue
Block a user