drivers/entropy: stm32: fix inter-core race condition
On STM32WB and dual-core STM32H7 MCUs, the RNG peripheral is shared between the cores and its access is protected by a hardware semaphore. Locking was not performed in the current entropy driver, leading to a race condition when multiple cores concurrently used the RNG. This commit implements the necessary logic for locking the HSEM during entropy generation on multi-core STM32 MCUs. It also reconfigures the RNG in case the configuration was changed by the other core, as this can happen e.g on STM32WB MCUs. Signed-off-by: Thomas Altenbach <taltenbach@witekio.com>
This commit is contained in:
parent
e1c441d4c4
commit
cc51031445
2 changed files with 210 additions and 80 deletions
|
@ -129,6 +129,22 @@ static inline void z_stm32_hsem_lock(uint32_t hsem, uint32_t retry)
|
|||
#endif /* CONFIG_SOC_SERIES_STM32WBX || CONFIG_STM32H7_DUAL_CORE || ... */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Try to lock Hardware Semaphore
|
||||
*/
|
||||
static inline int z_stm32_hsem_try_lock(uint32_t hsem)
|
||||
{
|
||||
#if defined(CONFIG_SOC_SERIES_STM32WBX) || defined(CONFIG_STM32H7_DUAL_CORE) \
|
||||
|| defined(CONFIG_SOC_SERIES_STM32MP1X)
|
||||
|
||||
if (LL_HSEM_1StepLock(HSEM, hsem)) {
|
||||
return -EAGAIN;
|
||||
}
|
||||
#endif /* CONFIG_SOC_SERIES_STM32WBX || CONFIG_STM32H7_DUAL_CORE || ... */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Release Hardware Semaphore
|
||||
*/
|
||||
|
@ -140,4 +156,20 @@ static inline void z_stm32_hsem_unlock(uint32_t hsem)
|
|||
#endif /* CONFIG_SOC_SERIES_STM32WBX || CONFIG_STM32H7_DUAL_CORE || ... */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Indicates whether Hardware Semaphore is owned by this core
|
||||
*/
|
||||
static inline bool z_stm32_hsem_is_owned(uint32_t hsem)
|
||||
{
|
||||
bool owned = false;
|
||||
|
||||
#if defined(CONFIG_SOC_SERIES_STM32WBX) || defined(CONFIG_STM32H7_DUAL_CORE) \
|
||||
|| defined(CONFIG_SOC_SERIES_STM32MP1X)
|
||||
|
||||
owned = LL_HSEM_GetCoreId(HSEM, hsem) == LL_HSEM_COREID;
|
||||
#endif /* CONFIG_SOC_SERIES_STM32WBX || CONFIG_STM32H7_DUAL_CORE || ... */
|
||||
|
||||
return owned;
|
||||
}
|
||||
|
||||
#endif /* ZEPHYR_INCLUDE_DRIVERS_HSEM_STM32_HSEM_H_ */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue