-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add RNG driver #54
Merged
jerome-pouiller
merged 4 commits into
SiliconLabsSoftware:main
from
jerome-pouiller:siwx917-rng
Oct 24, 2024
Merged
Add RNG driver #54
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
39619e3
drivers: entropy: Introduce driver for SiWx917
jerome-pouiller 9527bef
github: workflows: Use same level of indentation
jerome-pouiller 35dd707
github: workflows: Align invocations of twister
jerome-pouiller 47e8a59
github: workflows: Add test for RNG driver
jerome-pouiller File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,5 @@ | ||
# Copyright (c) 2024 Silicon Laboratories Inc. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
zephyr_library_amend() | ||
zephyr_library_sources_ifdef(CONFIG_ENTROPY_SILABS_SIWX917 entropy_silabs_siwx917.c) |
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,8 @@ | ||
# Copyright (c) 2024 Silicon Laboratories Inc. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
if ENTROPY_GENERATOR | ||
|
||
rsource "Kconfig.siwx917" | ||
|
||
endif |
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_SIWX917 | ||
bool "SiWx917 RNG driver" | ||
default y | ||
depends on DT_HAS_SILABS_SIWX917_RNG_ENABLED | ||
select ENTROPY_HAS_DRIVER | ||
help | ||
Enable hardware Random Number Generator embedded on Silicon Labs | ||
SiWx917 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_siwx917_rng | ||
|
||
#include <zephyr/drivers/entropy.h> | ||
|
||
#include "rsi_rom_rng.h" | ||
#include "rsi_rom_clks.h" | ||
|
||
static int siwx917_get_entropy_isr(const struct device *dev, uint8_t *buffer, | ||
uint16_t length, uint32_t flags) | ||
{ | ||
Check notice on line 14 in drivers/entropy/entropy_silabs_siwx917.c GitHub Actions / buildYou may want to run clang-format on this change
|
||
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 siwx917_get_entropy(const struct device *dev, uint8_t *buffer, uint16_t length) | ||
{ | ||
return siwx917_get_entropy_isr(dev, buffer, length, ENTROPY_BUSYWAIT); | ||
} | ||
|
||
static int siwx917_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 const struct entropy_driver_api siwx917_api = { | ||
.get_entropy = siwx917_get_entropy, | ||
.get_entropy_isr = siwx917_get_entropy_isr, | ||
}; | ||
|
||
#define SIWX917_RNG_INIT(idx) \ | ||
DEVICE_DT_INST_DEFINE(idx, siwx917_init, NULL, NULL, (void *)DT_INST_REG_ADDR(idx), \ | ||
PRE_KERNEL_1, CONFIG_ENTROPY_INIT_PRIORITY, &siwx917_api); | ||
Check notice on line 59 in drivers/entropy/entropy_silabs_siwx917.c GitHub Actions / buildYou may want to run clang-format on this change
|
||
|
||
DT_INST_FOREACH_STATUS_OKAY(SIWX917_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
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 SiWx917 chips | ||
|
||
compatible: "silabs,siwx917-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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The API description says: "This call has to be thread safe to satisfy requirements of the random subsystem."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact, I believe
RSI_RNG_GetBytes()
and all the subfunctions (mainlyrng_get_bytes()
) are thread safe. So I didn't keep the spinlock.