forked from zephyrproject-rtos/zephyr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
drivers: entropy: Introduce SiWx91x entropy driver
Support for random number generator is required for most of the cryptographic operations, including support for WiFi and TLS. This driver has been tested with tests/drivers/entropy: *** Booting Zephyr OS build v3.7.0-4339-g1ec5ce05f9f8 *** Running TESTSUITE entropy_api =================================================================== START - test_entropy_get_entropy random device is 0x8217298, name is rng@45090000 0x93 0x3e 0xf1 0x68 0xd4 0x22 0xbf 0x4d 0xad PASS - test_entropy_get_entropy in 0.012 seconds =================================================================== TESTSUITE entropy_api succeeded ------ TESTSUITE SUMMARY START ------ SUITE PASS - 100.00% [entropy_api]: pass = 1, fail = 0, skip = 0 ... - PASS - [entropy_api.test_entropy_get_entropy] duration = 0.01 ... ------ TESTSUITE SUMMARY END ------ =================================================================== RunID: d1547c805699201af769cb01331efcce PROJECT EXECUTION SUCCESSFUL Co-authored-by: Tibor Laczko <[email protected]> Signed-off-by: Tibor Laczko <[email protected]> Signed-off-by: Jérôme Pouiller <[email protected]>
- Loading branch information
Showing
6 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Copyright (c) 2024 Silicon Laboratories Inc. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
config ENTROPY_SILABS_SIWX91X | ||
bool "SiWx91x RNG driver" | ||
default y | ||
depends on DT_HAS_SILABS_SIWX91X_RNG_ENABLED | ||
select ENTROPY_HAS_DRIVER | ||
help | ||
Enable hardware Random Number Generator embedded on Silicon Labs | ||
SiWx91x chips. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright (c) 2024 Silicon Laboratories Inc. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
#define DT_DRV_COMPAT silabs_siwx91x_rng | ||
|
||
#include <zephyr/drivers/entropy.h> | ||
|
||
#include "rsi_rom_rng.h" | ||
#include "rsi_rom_clks.h" | ||
|
||
static int siwx91x_get_entropy_isr(const struct device *dev, uint8_t *buffer, | ||
uint16_t length, uint32_t flags) | ||
{ | ||
uint32_t u32_count = length / sizeof(uint32_t); | ||
uint32_t u8_count = u32_count * sizeof(uint32_t); | ||
uint32_t u8_remainder = length - u8_count; | ||
uint32_t swap_space; | ||
|
||
if (!(flags & ENTROPY_BUSYWAIT)) { | ||
return -ENOTSUP; | ||
} | ||
RSI_RNG_GetBytes((void *)dev->config, (uint32_t *)buffer, u32_count); | ||
if (length % sizeof(uint32_t)) { | ||
RSI_RNG_GetBytes((void *)dev->config, &swap_space, 1); | ||
memcpy(buffer + u8_count, &swap_space, u8_remainder); | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
static int siwx91x_get_entropy(const struct device *dev, uint8_t *buffer, uint16_t length) | ||
{ | ||
return siwx91x_get_entropy_isr(dev, buffer, length, ENTROPY_BUSYWAIT); | ||
} | ||
|
||
static int siwx91x_init(const struct device *dev) | ||
{ | ||
int ret; | ||
|
||
ret = RSI_CLK_PeripheralClkEnable1(M4CLK, HWRNG_PCLK_ENABLE); | ||
if (ret) { | ||
return -EIO; | ||
} | ||
ret = RSI_RNG_Start((void *)dev->config, RSI_RNG_TRUE_RANDOM); | ||
if (ret) { | ||
return -EIO; | ||
} | ||
return 0; | ||
} | ||
|
||
static DEVICE_API(entropy, siwx91x_api) = { | ||
.get_entropy = siwx91x_get_entropy, | ||
.get_entropy_isr = siwx91x_get_entropy_isr, | ||
}; | ||
|
||
#define SIWX91X_RNG_INIT(idx) \ | ||
DEVICE_DT_INST_DEFINE(idx, siwx91x_init, NULL, NULL, (void *)DT_INST_REG_ADDR(idx), \ | ||
PRE_KERNEL_1, CONFIG_ENTROPY_INIT_PRIORITY, &siwx91x_api); | ||
|
||
DT_INST_FOREACH_STATUS_OKAY(SIWX91X_RNG_INIT) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Copyright (c) 2024 Silicon Laboratories Inc. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
description: Hardware Random Number Generator embedded on Silabs SiWx91x chips | ||
|
||
compatible: "silabs,siwx91x-rng" | ||
|
||
include: base.yaml | ||
|
||
properties: | ||
reg: | ||
required: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters